From ab5d1b2c65d2034feae338a93f5a3885166d266b Mon Sep 17 00:00:00 2001 From: Dejian Yang Date: Fri, 26 Jan 2024 14:08:03 +0800 Subject: [PATCH] add leetcode evaluation --- .gitignore | 3 +- .../LeetCode/data/20240121-Jul-zh.jsonl | 180 +++++ Evaluation/LeetCode/data/20240121-Jul.jsonl | 180 +++++ Evaluation/LeetCode/evaluate_leetcode.py | 86 +++ Evaluation/LeetCode/human_eval/__init__.py | 0 Evaluation/LeetCode/human_eval/data.py | 49 ++ Evaluation/LeetCode/human_eval/evaluation.py | 304 ++++++++ Evaluation/LeetCode/human_eval/execution.py | 731 ++++++++++++++++++ Evaluation/LeetCode/readme.md | 48 ++ Evaluation/LeetCode/vllm_inference.py | 84 ++ 10 files changed, 1664 insertions(+), 1 deletion(-) create mode 100644 Evaluation/LeetCode/data/20240121-Jul-zh.jsonl create mode 100644 Evaluation/LeetCode/data/20240121-Jul.jsonl create mode 100644 Evaluation/LeetCode/evaluate_leetcode.py create mode 100644 Evaluation/LeetCode/human_eval/__init__.py create mode 100644 Evaluation/LeetCode/human_eval/data.py create mode 100644 Evaluation/LeetCode/human_eval/evaluation.py create mode 100644 Evaluation/LeetCode/human_eval/execution.py create mode 100644 Evaluation/LeetCode/readme.md create mode 100644 Evaluation/LeetCode/vllm_inference.py diff --git a/.gitignore b/.gitignore index 2cb1128..a5fb0cc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ __pycache__/ -Evaluation/MBPP/eval_instruct.sh \ No newline at end of file +Evaluation/MBPP/eval_instruct.sh +Evaluation/LeetCode/output/ \ No newline at end of file diff --git a/Evaluation/LeetCode/data/20240121-Jul-zh.jsonl b/Evaluation/LeetCode/data/20240121-Jul-zh.jsonl new file mode 100644 index 0000000..1c781ba --- /dev/null +++ b/Evaluation/LeetCode/data/20240121-Jul-zh.jsonl @@ -0,0 +1,180 @@ +{"task_id": "weekly-contest-381-minimum-number-of-pushes-to-type-word-i", "url": "https://leetcode.com/problems/minimum-number-of-pushes-to-type-word-i", "title": "minimum-number-of-pushes-to-type-word-i", "meta": {"questionId": "3275", "questionFrontendId": "3014", "title": "Minimum Number of Pushes to Type Word I", "titleSlug": "minimum-number-of-pushes-to-type-word-i", "isPaidOnly": false, "difficulty": "Easy", "likes": 39, "dislikes": 7, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个字符串 word,由 不同 小写英文字母组成。\n电话键盘上的按键与 不同 小写英文字母集合相映射,可以通过按压按键来组成单词。例如,按键 2 对应 [\"a\",\"b\",\"c\"],我们需要按一次键来输入 \"a\",按两次键来输入 \"b\",按三次键来输入 \"c\"。\n现在允许你将编号为 2 到 9 的按键重新映射到 不同 字母集合。每个按键可以映射到 任意数量 的字母,但每个字母 必须 恰好 映射到 一个 按键上。你需要找到输入字符串 word 所需的 最少 按键次数。\n返回重新映射按键后输入 word 所需的 最少 按键次数。\n下面给出了一种电话键盘上字母到按键的映射作为示例。注意 1,*,# 和 0 不 对应任何字母。\n\n\n示例 1:\n\n\n输入:word = \"abcde\"\n输出:5\n解释:图片中给出的重新映射方案的输入成本最小。\n\"a\" -> 在按键 2 上按一次\n\"b\" -> 在按键 3 上按一次\n\"c\" -> 在按键 4 上按一次\n\"d\" -> 在按键 5 上按一次\n\"e\" -> 在按键 6 上按一次\n总成本为 1 + 1 + 1 + 1 + 1 = 5 。\n可以证明不存在其他成本更低的映射方案。\n\n示例 2:\n\n\n输入:word = \"xycdefghij\"\n输出:12\n解释:图片中给出的重新映射方案的输入成本最小。\n\"x\" -> 在按键 2 上按一次\n\"y\" -> 在按键 2 上按两次\n\"c\" -> 在按键 3 上按一次\n\"d\" -> 在按键 3 上按两次\n\"e\" -> 在按键 4 上按一次\n\"f\" -> 在按键 5 上按一次\n\"g\" -> 在按键 6 上按一次\n\"h\" -> 在按键 7 上按一次\n\"i\" -> 在按键 8 上按一次\n\"j\" -> 在按键 9 上按一次\n总成本为 1 + 2 + 1 + 2 + 1 + 1 + 1 + 1 + 1 + 1 = 12 。\n可以证明不存在其他成本更低的映射方案。\n\n\n提示:\n\n1 <= word.length <= 26\nword 仅由小写英文字母组成。\nword 中的所有字母互不相同。\n\"\"\"\nclass Solution:\n def minimumPushes(self, word: str) -> int:\n ", "prompt_sft": "给你一个字符串 word,由 不同 小写英文字母组成。\n电话键盘上的按键与 不同 小写英文字母集合相映射,可以通过按压按键来组成单词。例如,按键 2 对应 [\"a\",\"b\",\"c\"],我们需要按一次键来输入 \"a\",按两次键来输入 \"b\",按三次键来输入 \"c\"。\n现在允许你将编号为 2 到 9 的按键重新映射到 不同 字母集合。每个按键可以映射到 任意数量 的字母,但每个字母 必须 恰好 映射到 一个 按键上。你需要找到输入字符串 word 所需的 最少 按键次数。\n返回重新映射按键后输入 word 所需的 最少 按键次数。\n下面给出了一种电话键盘上字母到按键的映射作为示例。注意 1,*,# 和 0 不 对应任何字母。\n\n\n示例 1:\n\n\n输入:word = \"abcde\"\n输出:5\n解释:图片中给出的重新映射方案的输入成本最小。\n\"a\" -> 在按键 2 上按一次\n\"b\" -> 在按键 3 上按一次\n\"c\" -> 在按键 4 上按一次\n\"d\" -> 在按键 5 上按一次\n\"e\" -> 在按键 6 上按一次\n总成本为 1 + 1 + 1 + 1 + 1 = 5 。\n可以证明不存在其他成本更低的映射方案。\n\n示例 2:\n\n\n输入:word = \"xycdefghij\"\n输出:12\n解释:图片中给出的重新映射方案的输入成本最小。\n\"x\" -> 在按键 2 上按一次\n\"y\" -> 在按键 2 上按两次\n\"c\" -> 在按键 3 上按一次\n\"d\" -> 在按键 3 上按两次\n\"e\" -> 在按键 4 上按一次\n\"f\" -> 在按键 5 上按一次\n\"g\" -> 在按键 6 上按一次\n\"h\" -> 在按键 7 上按一次\n\"i\" -> 在按键 8 上按一次\n\"j\" -> 在按键 9 上按一次\n总成本为 1 + 2 + 1 + 2 + 1 + 1 + 1 + 1 + 1 + 1 = 12 。\n可以证明不存在其他成本更低的映射方案。\n\n\n提示:\n\n1 <= word.length <= 26\nword 仅由小写英文字母组成。\nword 中的所有字母互不相同。\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def minimumPushes(self, word: str) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"word\": \"abcde\" }\nassert my_solution.minimumPushes(**test_input) == 5\n\ntest_input = { \"word\": \"xycdefghij\" }\nassert my_solution.minimumPushes(**test_input) == 12\n\ntest_input = { \"word\": \"b\" }\nassert my_solution.minimumPushes(**test_input) == 1\n\ntest_input = { \"word\": \"d\" }\nassert my_solution.minimumPushes(**test_input) == 1\n\ntest_input = { \"word\": \"e\" }\nassert my_solution.minimumPushes(**test_input) == 1\n\ntest_input = { \"word\": \"f\" }\nassert my_solution.minimumPushes(**test_input) == 1\n\ntest_input = { \"word\": \"g\" }\nassert my_solution.minimumPushes(**test_input) == 1\n\ntest_input = { \"word\": \"h\" }\nassert my_solution.minimumPushes(**test_input) == 1\n\ntest_input = { \"word\": \"i\" }\nassert my_solution.minimumPushes(**test_input) == 1\n\ntest_input = { \"word\": \"k\" }\nassert my_solution.minimumPushes(**test_input) == 1\n\ntest_input = { \"word\": \"n\" }\nassert my_solution.minimumPushes(**test_input) == 1\n\ntest_input = { \"word\": \"o\" }\nassert my_solution.minimumPushes(**test_input) == 1\n\ntest_input = { \"word\": \"q\" }\nassert my_solution.minimumPushes(**test_input) == 1\n\ntest_input = { \"word\": \"u\" }\nassert my_solution.minimumPushes(**test_input) == 1\n\ntest_input = { \"word\": \"v\" }\nassert my_solution.minimumPushes(**test_input) == 1\n\ntest_input = { \"word\": \"w\" }\nassert my_solution.minimumPushes(**test_input) == 1\n\ntest_input = { \"word\": \"x\" }\nassert my_solution.minimumPushes(**test_input) == 1\n\ntest_input = { \"word\": \"bc\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"cu\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"dl\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"dn\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"ev\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"gn\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"gq\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"hu\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"jr\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"ln\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"lz\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"mv\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"mw\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"sw\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"wz\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"amw\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"bco\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"btx\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"cgp\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"cjq\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"clu\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"clx\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"crs\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"csz\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"dfp\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"htv\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"iwz\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"kux\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"nsv\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"svz\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"cfos\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"demr\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"dimo\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"dnpt\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"dorz\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"fgkn\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"fimn\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"hior\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"jkpy\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"jluv\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"knpv\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"kopu\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"lmpt\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"ltuw\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"qwxz\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"abhoz\" }\nassert my_solution.minimumPushes(**test_input) == 5\n\ntest_input = { \"word\": \"aejwx\" }\nassert my_solution.minimumPushes(**test_input) == 5\n\ntest_input = { \"word\": \"agjnr\" }\nassert my_solution.minimumPushes(**test_input) == 5\n\ntest_input = { \"word\": \"aikmu\" }\nassert my_solution.minimumPushes(**test_input) == 5\n\ntest_input = { \"word\": \"ajkmv\" }\nassert my_solution.minimumPushes(**test_input) == 5\n\ntest_input = { \"word\": \"cflvx\" }\nassert my_solution.minimumPushes(**test_input) == 5\n\ntest_input = { \"word\": \"dhstu\" }\nassert my_solution.minimumPushes(**test_input) == 5\n\ntest_input = { \"word\": \"djmnx\" }\nassert my_solution.minimumPushes(**test_input) == 5\n\ntest_input = { \"word\": \"dlovx\" }\nassert my_solution.minimumPushes(**test_input) == 5\n\ntest_input = { \"word\": \"eglqy\" }\nassert my_solution.minimumPushes(**test_input) == 5\n\ntest_input = { \"word\": \"ejntw\" }\nassert my_solution.minimumPushes(**test_input) == 5\n\ntest_input = { \"word\": \"ekrsz\" }\nassert my_solution.minimumPushes(**test_input) == 5\n\ntest_input = { \"word\": \"fopuz\" }\nassert my_solution.minimumPushes(**test_input) == 5\n\ntest_input = { \"word\": \"jlnvz\" }\nassert my_solution.minimumPushes(**test_input) == 5\n\ntest_input = { \"word\": \"jnstu\" }\nassert my_solution.minimumPushes(**test_input) == 5\n\ntest_input = { \"word\": \"afikno\" }\nassert my_solution.minimumPushes(**test_input) == 6\n\ntest_input = { \"word\": \"almsyz\" }\nassert my_solution.minimumPushes(**test_input) == 6\n\ntest_input = { \"word\": \"bcehov\" }\nassert my_solution.minimumPushes(**test_input) == 6\n\ntest_input = { \"word\": \"bdmprt\" }\nassert my_solution.minimumPushes(**test_input) == 6\n\ntest_input = { \"word\": \"bfhmnu\" }\nassert my_solution.minimumPushes(**test_input) == 6\n\ntest_input = { \"word\": \"bfhpty\" }\nassert my_solution.minimumPushes(**test_input) == 6\n\ntest_input = { \"word\": \"bfjstu\" }\nassert my_solution.minimumPushes(**test_input) == 6\n\ntest_input = { \"word\": \"cdfjmw\" }\nassert my_solution.minimumPushes(**test_input) == 6\n\ntest_input = { \"word\": \"dfilps\" }\nassert my_solution.minimumPushes(**test_input) == 6\n\ntest_input = { \"word\": \"dmswyz\" }\nassert my_solution.minimumPushes(**test_input) == 6\n\ntest_input = { \"word\": \"dpqruw\" }\nassert my_solution.minimumPushes(**test_input) == 6\n\ntest_input = { \"word\": \"fhmprz\" }\nassert my_solution.minimumPushes(**test_input) == 6\n\ntest_input = { \"word\": \"gjqrvy\" }\nassert my_solution.minimumPushes(**test_input) == 6\n\ntest_input = { \"word\": \"ijopsv\" }\nassert my_solution.minimumPushes(**test_input) == 6\n\ntest_input = { \"word\": \"lmqrtz\" }\nassert my_solution.minimumPushes(**test_input) == 6\n\ntest_input = { \"word\": \"bxnqpha\" }\nassert my_solution.minimumPushes(**test_input) == 7\n\ntest_input = { \"word\": \"ekbfqat\" }\nassert my_solution.minimumPushes(**test_input) == 7\n\ntest_input = { \"word\": \"esoizcx\" }\nassert my_solution.minimumPushes(**test_input) == 7\n\ntest_input = { \"word\": \"fmteczo\" }\nassert my_solution.minimumPushes(**test_input) == 7\n\ntest_input = { \"word\": \"lrywetm\" }\nassert my_solution.minimumPushes(**test_input) == 7\n\ntest_input = { \"word\": \"lvbornx\" }\nassert my_solution.minimumPushes(**test_input) == 7\n\ntest_input = { \"word\": \"pesmonc\" }\nassert my_solution.minimumPushes(**test_input) == 7\n\ntest_input = { \"word\": \"pudymjw\" }\nassert my_solution.minimumPushes(**test_input) == 7", "start_time": 1705804200} +{"task_id": "weekly-contest-381-count-the-number-of-houses-at-a-certain-distance-i", "url": "https://leetcode.com/problems/count-the-number-of-houses-at-a-certain-distance-i", "title": "count-the-number-of-houses-at-a-certain-distance-i", "meta": {"questionId": "3271", "questionFrontendId": "3015", "title": "Count the Number of Houses at a Certain Distance I", "titleSlug": "count-the-number-of-houses-at-a-certain-distance-i", "isPaidOnly": false, "difficulty": "Medium", "likes": 62, "dislikes": 7, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你三个 正整数 n 、x 和 y 。\n在城市中,存在编号从 1 到 n 的房屋,由 n 条街道相连。对所有 1 <= i < n ,都存在一条街道连接编号为 i 的房屋与编号为 i + 1 的房屋。另存在一条街道连接编号为 x 的房屋与编号为 y 的房屋。\n对于每个 k(1 <= k <= n),你需要找出所有满足要求的 房屋对 [house1, house2] ,即从 house1 到 house2 需要经过的 最少 街道数为 k 。\n返回一个下标从 1 开始且长度为 n 的数组 result ,其中 result[k] 表示所有满足要求的房屋对的数量,即从一个房屋到另一个房屋需要经过的 最少 街道数为 k 。\n注意,x 与 y 可以 相等 。\n\n示例 1:\n\n\n输入:n = 3, x = 1, y = 3\n输出:[6,0,0]\n解释:让我们检视每个房屋对\n- 对于房屋对 (1, 2),可以直接从房屋 1 到房屋 2。\n- 对于房屋对 (2, 1),可以直接从房屋 2 到房屋 1。\n- 对于房屋对 (1, 3),可以直接从房屋 1 到房屋 3。\n- 对于房屋对 (3, 1),可以直接从房屋 3 到房屋 1。\n- 对于房屋对 (2, 3),可以直接从房屋 2 到房屋 3。\n- 对于房屋对 (3, 2),可以直接从房屋 3 到房屋 2。\n\n示例 2:\n\n\n输入:n = 5, x = 2, y = 4\n输出:[10,8,2,0,0]\n解释:对于每个距离 k ,满足要求的房屋对如下:\n- 对于 k == 1,满足要求的房屋对有 (1, 2), (2, 1), (2, 3), (3, 2), (2, 4), (4, 2), (3, 4), (4, 3), (4, 5), 以及 (5, 4)。\n- 对于 k == 2,满足要求的房屋对有 (1, 3), (3, 1), (1, 4), (4, 1), (2, 5), (5, 2), (3, 5), 以及 (5, 3)。\n- 对于 k == 3,满足要求的房屋对有 (1, 5),以及 (5, 1) 。\n- 对于 k == 4 和 k == 5,不存在满足要求的房屋对。\n\n示例 3:\n\n\n输入:n = 4, x = 1, y = 1\n输出:[6,4,2,0]\n解释:对于每个距离 k ,满足要求的房屋对如下:\n- 对于 k == 1,满足要求的房屋对有 (1, 2), (2, 1), (2, 3), (3, 2), (3, 4), 以及 (4, 3)。\n- 对于 k == 2,满足要求的房屋对有 (1, 3), (3, 1), (2, 4), 以及 (4, 2)。\n- 对于 k == 3,满足要求的房屋对有 (1, 4), 以及 (4, 1)。\n- 对于 k == 4,不存在满足要求的房屋对。\n\n\n提示:\n\n2 <= n <= 100\n1 <= x, y <= n\n\"\"\"\nclass Solution:\n def countOfPairs(self, n: int, x: int, y: int) -> List[int]:\n ", "prompt_sft": "给你三个 正整数 n 、x 和 y 。\n在城市中,存在编号从 1 到 n 的房屋,由 n 条街道相连。对所有 1 <= i < n ,都存在一条街道连接编号为 i 的房屋与编号为 i + 1 的房屋。另存在一条街道连接编号为 x 的房屋与编号为 y 的房屋。\n对于每个 k(1 <= k <= n),你需要找出所有满足要求的 房屋对 [house1, house2] ,即从 house1 到 house2 需要经过的 最少 街道数为 k 。\n返回一个下标从 1 开始且长度为 n 的数组 result ,其中 result[k] 表示所有满足要求的房屋对的数量,即从一个房屋到另一个房屋需要经过的 最少 街道数为 k 。\n注意,x 与 y 可以 相等 。\n\n示例 1:\n\n\n输入:n = 3, x = 1, y = 3\n输出:[6,0,0]\n解释:让我们检视每个房屋对\n- 对于房屋对 (1, 2),可以直接从房屋 1 到房屋 2。\n- 对于房屋对 (2, 1),可以直接从房屋 2 到房屋 1。\n- 对于房屋对 (1, 3),可以直接从房屋 1 到房屋 3。\n- 对于房屋对 (3, 1),可以直接从房屋 3 到房屋 1。\n- 对于房屋对 (2, 3),可以直接从房屋 2 到房屋 3。\n- 对于房屋对 (3, 2),可以直接从房屋 3 到房屋 2。\n\n示例 2:\n\n\n输入:n = 5, x = 2, y = 4\n输出:[10,8,2,0,0]\n解释:对于每个距离 k ,满足要求的房屋对如下:\n- 对于 k == 1,满足要求的房屋对有 (1, 2), (2, 1), (2, 3), (3, 2), (2, 4), (4, 2), (3, 4), (4, 3), (4, 5), 以及 (5, 4)。\n- 对于 k == 2,满足要求的房屋对有 (1, 3), (3, 1), (1, 4), (4, 1), (2, 5), (5, 2), (3, 5), 以及 (5, 3)。\n- 对于 k == 3,满足要求的房屋对有 (1, 5),以及 (5, 1) 。\n- 对于 k == 4 和 k == 5,不存在满足要求的房屋对。\n\n示例 3:\n\n\n输入:n = 4, x = 1, y = 1\n输出:[6,4,2,0]\n解释:对于每个距离 k ,满足要求的房屋对如下:\n- 对于 k == 1,满足要求的房屋对有 (1, 2), (2, 1), (2, 3), (3, 2), (3, 4), 以及 (4, 3)。\n- 对于 k == 2,满足要求的房屋对有 (1, 3), (3, 1), (2, 4), 以及 (4, 2)。\n- 对于 k == 3,满足要求的房屋对有 (1, 4), 以及 (4, 1)。\n- 对于 k == 4,不存在满足要求的房屋对。\n\n\n提示:\n\n2 <= n <= 100\n1 <= x, y <= n\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def countOfPairs(self, n: int, x: int, y: int) -> List[int]:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"n\": 3, \"x\": 1, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [6,0,0]\n\ntest_input = { \"n\": 5, \"x\": 2, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [10,8,2,0,0]\n\ntest_input = { \"n\": 4, \"x\": 1, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [6,4,2,0]\n\ntest_input = { \"n\": 2, \"x\": 1, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [2,0]\n\ntest_input = { \"n\": 2, \"x\": 1, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [2,0]\n\ntest_input = { \"n\": 2, \"x\": 2, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [2,0]\n\ntest_input = { \"n\": 2, \"x\": 2, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [2,0]\n\ntest_input = { \"n\": 3, \"x\": 1, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [4,2,0]\n\ntest_input = { \"n\": 3, \"x\": 1, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [4,2,0]\n\ntest_input = { \"n\": 3, \"x\": 2, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [4,2,0]\n\ntest_input = { \"n\": 3, \"x\": 2, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [4,2,0]\n\ntest_input = { \"n\": 3, \"x\": 2, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [4,2,0]\n\ntest_input = { \"n\": 3, \"x\": 3, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [6,0,0]\n\ntest_input = { \"n\": 3, \"x\": 3, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [4,2,0]\n\ntest_input = { \"n\": 3, \"x\": 3, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [4,2,0]\n\ntest_input = { \"n\": 4, \"x\": 1, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [6,4,2,0]\n\ntest_input = { \"n\": 4, \"x\": 1, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [8,4,0,0]\n\ntest_input = { \"n\": 4, \"x\": 1, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [8,4,0,0]\n\ntest_input = { \"n\": 4, \"x\": 2, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [6,4,2,0]\n\ntest_input = { \"n\": 4, \"x\": 2, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [6,4,2,0]\n\ntest_input = { \"n\": 4, \"x\": 2, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [6,4,2,0]\n\ntest_input = { \"n\": 4, \"x\": 2, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [8,4,0,0]\n\ntest_input = { \"n\": 4, \"x\": 3, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [8,4,0,0]\n\ntest_input = { \"n\": 4, \"x\": 3, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [6,4,2,0]\n\ntest_input = { \"n\": 4, \"x\": 3, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [6,4,2,0]\n\ntest_input = { \"n\": 4, \"x\": 3, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [6,4,2,0]\n\ntest_input = { \"n\": 4, \"x\": 4, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [8,4,0,0]\n\ntest_input = { \"n\": 4, \"x\": 4, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [8,4,0,0]\n\ntest_input = { \"n\": 4, \"x\": 4, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [6,4,2,0]\n\ntest_input = { \"n\": 4, \"x\": 4, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [6,4,2,0]\n\ntest_input = { \"n\": 5, \"x\": 1, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [8,6,4,2,0]\n\ntest_input = { \"n\": 5, \"x\": 1, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [8,6,4,2,0]\n\ntest_input = { \"n\": 5, \"x\": 1, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [10,6,4,0,0]\n\ntest_input = { \"n\": 5, \"x\": 1, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [10,8,2,0,0]\n\ntest_input = { \"n\": 5, \"x\": 1, \"y\": 5 }\nassert my_solution.countOfPairs(**test_input) == [10,10,0,0,0]\n\ntest_input = { \"n\": 5, \"x\": 2, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [8,6,4,2,0]\n\ntest_input = { \"n\": 5, \"x\": 2, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [8,6,4,2,0]\n\ntest_input = { \"n\": 5, \"x\": 2, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [8,6,4,2,0]\n\ntest_input = { \"n\": 5, \"x\": 2, \"y\": 5 }\nassert my_solution.countOfPairs(**test_input) == [10,8,2,0,0]\n\ntest_input = { \"n\": 5, \"x\": 3, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [10,6,4,0,0]\n\ntest_input = { \"n\": 5, \"x\": 3, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [8,6,4,2,0]\n\ntest_input = { \"n\": 5, \"x\": 3, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [8,6,4,2,0]\n\ntest_input = { \"n\": 5, \"x\": 3, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [8,6,4,2,0]\n\ntest_input = { \"n\": 5, \"x\": 3, \"y\": 5 }\nassert my_solution.countOfPairs(**test_input) == [10,6,4,0,0]\n\ntest_input = { \"n\": 5, \"x\": 4, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [10,8,2,0,0]\n\ntest_input = { \"n\": 5, \"x\": 4, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [10,8,2,0,0]\n\ntest_input = { \"n\": 5, \"x\": 4, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [8,6,4,2,0]\n\ntest_input = { \"n\": 5, \"x\": 4, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [8,6,4,2,0]\n\ntest_input = { \"n\": 5, \"x\": 4, \"y\": 5 }\nassert my_solution.countOfPairs(**test_input) == [8,6,4,2,0]\n\ntest_input = { \"n\": 5, \"x\": 5, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [10,10,0,0,0]\n\ntest_input = { \"n\": 5, \"x\": 5, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [10,8,2,0,0]\n\ntest_input = { \"n\": 5, \"x\": 5, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [10,6,4,0,0]\n\ntest_input = { \"n\": 5, \"x\": 5, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [8,6,4,2,0]\n\ntest_input = { \"n\": 5, \"x\": 5, \"y\": 5 }\nassert my_solution.countOfPairs(**test_input) == [8,6,4,2,0]\n\ntest_input = { \"n\": 6, \"x\": 1, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [10,8,6,4,2,0]\n\ntest_input = { \"n\": 6, \"x\": 1, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [10,8,6,4,2,0]\n\ntest_input = { \"n\": 6, \"x\": 1, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [12,8,6,4,0,0]\n\ntest_input = { \"n\": 6, \"x\": 1, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [12,10,6,2,0,0]\n\ntest_input = { \"n\": 6, \"x\": 1, \"y\": 5 }\nassert my_solution.countOfPairs(**test_input) == [12,14,4,0,0,0]\n\ntest_input = { \"n\": 6, \"x\": 1, \"y\": 6 }\nassert my_solution.countOfPairs(**test_input) == [12,12,6,0,0,0]\n\ntest_input = { \"n\": 6, \"x\": 2, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [10,8,6,4,2,0]\n\ntest_input = { \"n\": 6, \"x\": 2, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [10,8,6,4,2,0]\n\ntest_input = { \"n\": 6, \"x\": 2, \"y\": 5 }\nassert my_solution.countOfPairs(**test_input) == [12,12,6,0,0,0]\n\ntest_input = { \"n\": 6, \"x\": 2, \"y\": 6 }\nassert my_solution.countOfPairs(**test_input) == [12,14,4,0,0,0]\n\ntest_input = { \"n\": 6, \"x\": 3, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [12,8,6,4,0,0]\n\ntest_input = { \"n\": 6, \"x\": 3, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [10,8,6,4,2,0]\n\ntest_input = { \"n\": 6, \"x\": 3, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [10,8,6,4,2,0]\n\ntest_input = { \"n\": 6, \"x\": 3, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [10,8,6,4,2,0]\n\ntest_input = { \"n\": 6, \"x\": 3, \"y\": 5 }\nassert my_solution.countOfPairs(**test_input) == [12,10,6,2,0,0]\n\ntest_input = { \"n\": 6, \"x\": 3, \"y\": 6 }\nassert my_solution.countOfPairs(**test_input) == [12,10,6,2,0,0]\n\ntest_input = { \"n\": 6, \"x\": 4, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [12,10,6,2,0,0]\n\ntest_input = { \"n\": 6, \"x\": 4, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [12,10,6,2,0,0]\n\ntest_input = { \"n\": 6, \"x\": 4, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [10,8,6,4,2,0]\n\ntest_input = { \"n\": 6, \"x\": 4, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [10,8,6,4,2,0]\n\ntest_input = { \"n\": 6, \"x\": 4, \"y\": 6 }\nassert my_solution.countOfPairs(**test_input) == [12,8,6,4,0,0]\n\ntest_input = { \"n\": 6, \"x\": 5, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [12,14,4,0,0,0]\n\ntest_input = { \"n\": 6, \"x\": 5, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [12,12,6,0,0,0]\n\ntest_input = { \"n\": 6, \"x\": 5, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [12,10,6,2,0,0]\n\ntest_input = { \"n\": 6, \"x\": 5, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [10,8,6,4,2,0]\n\ntest_input = { \"n\": 6, \"x\": 5, \"y\": 5 }\nassert my_solution.countOfPairs(**test_input) == [10,8,6,4,2,0]\n\ntest_input = { \"n\": 6, \"x\": 5, \"y\": 6 }\nassert my_solution.countOfPairs(**test_input) == [10,8,6,4,2,0]\n\ntest_input = { \"n\": 6, \"x\": 6, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [12,12,6,0,0,0]\n\ntest_input = { \"n\": 6, \"x\": 6, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [12,14,4,0,0,0]\n\ntest_input = { \"n\": 6, \"x\": 6, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [12,10,6,2,0,0]\n\ntest_input = { \"n\": 6, \"x\": 6, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [12,8,6,4,0,0]\n\ntest_input = { \"n\": 6, \"x\": 6, \"y\": 5 }\nassert my_solution.countOfPairs(**test_input) == [10,8,6,4,2,0]\n\ntest_input = { \"n\": 6, \"x\": 6, \"y\": 6 }\nassert my_solution.countOfPairs(**test_input) == [10,8,6,4,2,0]\n\ntest_input = { \"n\": 7, \"x\": 1, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [12,10,8,6,4,2,0]\n\ntest_input = { \"n\": 7, \"x\": 1, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [14,10,8,6,4,0,0]\n\ntest_input = { \"n\": 7, \"x\": 1, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [14,12,8,6,2,0,0]\n\ntest_input = { \"n\": 7, \"x\": 1, \"y\": 5 }\nassert my_solution.countOfPairs(**test_input) == [14,16,8,4,0,0,0]\n\ntest_input = { \"n\": 7, \"x\": 1, \"y\": 6 }\nassert my_solution.countOfPairs(**test_input) == [14,16,10,2,0,0,0]\n\ntest_input = { \"n\": 7, \"x\": 1, \"y\": 7 }\nassert my_solution.countOfPairs(**test_input) == [14,14,14,0,0,0,0]\n\ntest_input = { \"n\": 7, \"x\": 2, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [12,10,8,6,4,2,0]\n\ntest_input = { \"n\": 7, \"x\": 2, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [12,10,8,6,4,2,0]\n\ntest_input = { \"n\": 7, \"x\": 2, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [12,10,8,6,4,2,0]\n\ntest_input = { \"n\": 7, \"x\": 2, \"y\": 7 }\nassert my_solution.countOfPairs(**test_input) == [14,16,10,2,0,0,0]\n\ntest_input = { \"n\": 7, \"x\": 3, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [14,10,8,6,4,0,0]\n\ntest_input = { \"n\": 7, \"x\": 3, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [12,10,8,6,4,2,0]\n\ntest_input = { \"n\": 7, \"x\": 3, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [12,10,8,6,4,2,0]", "start_time": 1705804200} +{"task_id": "weekly-contest-381-minimum-number-of-pushes-to-type-word-ii", "url": "https://leetcode.com/problems/minimum-number-of-pushes-to-type-word-ii", "title": "minimum-number-of-pushes-to-type-word-ii", "meta": {"questionId": "3276", "questionFrontendId": "3016", "title": "Minimum Number of Pushes to Type Word II", "titleSlug": "minimum-number-of-pushes-to-type-word-ii", "isPaidOnly": false, "difficulty": "Medium", "likes": 59, "dislikes": 2, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个字符串 word,由 不同 小写英文字母组成。\n电话键盘上的按键与 不同 小写英文字母集合相映射,可以通过按压按键来组成单词。例如,按键 2 对应 [\"a\",\"b\",\"c\"],我们需要按一次键来输入 \"a\",按两次键来输入 \"b\",按三次键来输入 \"c\"。\n现在允许你将编号为 2 到 9 的按键重新映射到 不同 字母集合。每个按键可以映射到 任意数量 的字母,但每个字母 必须 恰好 映射到 一个 按键上。你需要找到输入字符串 word 所需的 最少 按键次数。\n返回重新映射按键后输入 word 所需的 最少 按键次数。\n下面给出了一种电话键盘上字母到按键的映射作为示例。注意 1,*,# 和 0 不 对应任何字母。\n\n\n示例 1:\n\n\n输入:word = \"abcde\"\n输出:5\n解释:图片中给出的重新映射方案的输入成本最小。\n\"a\" -> 在按键 2 上按一次\n\"b\" -> 在按键 3 上按一次\n\"c\" -> 在按键 4 上按一次\n\"d\" -> 在按键 5 上按一次\n\"e\" -> 在按键 6 上按一次\n总成本为 1 + 1 + 1 + 1 + 1 = 5 。\n可以证明不存在其他成本更低的映射方案。\n\n示例 2:\n\n\n输入:word = \"xyzxyzxyzxyz\"\n输出:12\n解释:图片中给出的重新映射方案的输入成本最小。\n\"x\" -> 在按键 2 上按一次\n\"y\" -> 在按键 3 上按一次\n\"z\" -> 在按键 4 上按一次\n总成本为 1 * 4 + 1 * 4 + 1 * 4 = 12 。\n可以证明不存在其他成本更低的映射方案。\n注意按键 9 没有映射到任何字母:不必让每个按键都存在与之映射的字母,但是每个字母都必须映射到按键上。\n\n示例 3:\n\n\n输入:word = \"aabbccddeeffgghhiiiiii\"\n输出:24\n解释:图片中给出的重新映射方案的输入成本最小。\n\"a\" -> 在按键 2 上按一次\n\"b\" -> 在按键 3 上按一次\n\"c\" -> 在按键 4 上按一次\n\"d\" -> 在按键 5 上按一次\n\"e\" -> 在按键 6 上按一次\n\"f\" -> 在按键 7 上按一次\n\"g\" -> 在按键 8 上按一次\n\"h\" -> 在按键 9 上按两次\n\"i\" -> 在按键 9 上按一次\n总成本为 1 * 2 + 1 * 2 + 1 * 2 + 1 * 2 + 1 * 2 + 1 * 2 + 1 * 2 + 2 * 2 + 6 * 1 = 24 。\n可以证明不存在其他成本更低的映射方案。\n\n\n提示:\n\n1 <= word.length <= 105\nword 仅由小写英文字母组成。\n\"\"\"\nclass Solution:\n def minimumPushes(self, word: str) -> int:\n ", "prompt_sft": "给你一个字符串 word,由 不同 小写英文字母组成。\n电话键盘上的按键与 不同 小写英文字母集合相映射,可以通过按压按键来组成单词。例如,按键 2 对应 [\"a\",\"b\",\"c\"],我们需要按一次键来输入 \"a\",按两次键来输入 \"b\",按三次键来输入 \"c\"。\n现在允许你将编号为 2 到 9 的按键重新映射到 不同 字母集合。每个按键可以映射到 任意数量 的字母,但每个字母 必须 恰好 映射到 一个 按键上。你需要找到输入字符串 word 所需的 最少 按键次数。\n返回重新映射按键后输入 word 所需的 最少 按键次数。\n下面给出了一种电话键盘上字母到按键的映射作为示例。注意 1,*,# 和 0 不 对应任何字母。\n\n\n示例 1:\n\n\n输入:word = \"abcde\"\n输出:5\n解释:图片中给出的重新映射方案的输入成本最小。\n\"a\" -> 在按键 2 上按一次\n\"b\" -> 在按键 3 上按一次\n\"c\" -> 在按键 4 上按一次\n\"d\" -> 在按键 5 上按一次\n\"e\" -> 在按键 6 上按一次\n总成本为 1 + 1 + 1 + 1 + 1 = 5 。\n可以证明不存在其他成本更低的映射方案。\n\n示例 2:\n\n\n输入:word = \"xyzxyzxyzxyz\"\n输出:12\n解释:图片中给出的重新映射方案的输入成本最小。\n\"x\" -> 在按键 2 上按一次\n\"y\" -> 在按键 3 上按一次\n\"z\" -> 在按键 4 上按一次\n总成本为 1 * 4 + 1 * 4 + 1 * 4 = 12 。\n可以证明不存在其他成本更低的映射方案。\n注意按键 9 没有映射到任何字母:不必让每个按键都存在与之映射的字母,但是每个字母都必须映射到按键上。\n\n示例 3:\n\n\n输入:word = \"aabbccddeeffgghhiiiiii\"\n输出:24\n解释:图片中给出的重新映射方案的输入成本最小。\n\"a\" -> 在按键 2 上按一次\n\"b\" -> 在按键 3 上按一次\n\"c\" -> 在按键 4 上按一次\n\"d\" -> 在按键 5 上按一次\n\"e\" -> 在按键 6 上按一次\n\"f\" -> 在按键 7 上按一次\n\"g\" -> 在按键 8 上按一次\n\"h\" -> 在按键 9 上按两次\n\"i\" -> 在按键 9 上按一次\n总成本为 1 * 2 + 1 * 2 + 1 * 2 + 1 * 2 + 1 * 2 + 1 * 2 + 1 * 2 + 2 * 2 + 6 * 1 = 24 。\n可以证明不存在其他成本更低的映射方案。\n\n\n提示:\n\n1 <= word.length <= 105\nword 仅由小写英文字母组成。\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def minimumPushes(self, word: str) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"word\": \"abcde\" }\nassert my_solution.minimumPushes(**test_input) == 5\n\ntest_input = { \"word\": \"xyzxyzxyzxyz\" }\nassert my_solution.minimumPushes(**test_input) == 12\n\ntest_input = { \"word\": \"aabbccddeeffgghhiiiiii\" }\nassert my_solution.minimumPushes(**test_input) == 24\n\ntest_input = { \"word\": \"a\" }\nassert my_solution.minimumPushes(**test_input) == 1\n\ntest_input = { \"word\": \"f\" }\nassert my_solution.minimumPushes(**test_input) == 1\n\ntest_input = { \"word\": \"h\" }\nassert my_solution.minimumPushes(**test_input) == 1\n\ntest_input = { \"word\": \"i\" }\nassert my_solution.minimumPushes(**test_input) == 1\n\ntest_input = { \"word\": \"l\" }\nassert my_solution.minimumPushes(**test_input) == 1\n\ntest_input = { \"word\": \"o\" }\nassert my_solution.minimumPushes(**test_input) == 1\n\ntest_input = { \"word\": \"q\" }\nassert my_solution.minimumPushes(**test_input) == 1\n\ntest_input = { \"word\": \"s\" }\nassert my_solution.minimumPushes(**test_input) == 1\n\ntest_input = { \"word\": \"t\" }\nassert my_solution.minimumPushes(**test_input) == 1\n\ntest_input = { \"word\": \"u\" }\nassert my_solution.minimumPushes(**test_input) == 1\n\ntest_input = { \"word\": \"x\" }\nassert my_solution.minimumPushes(**test_input) == 1\n\ntest_input = { \"word\": \"y\" }\nassert my_solution.minimumPushes(**test_input) == 1\n\ntest_input = { \"word\": \"z\" }\nassert my_solution.minimumPushes(**test_input) == 1\n\ntest_input = { \"word\": \"at\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"aw\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"bd\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"bs\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"ck\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"de\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"ex\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"fy\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"fz\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"hu\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"ir\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"iz\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"km\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"lr\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"lu\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"mz\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"ng\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"nu\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"oo\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"qc\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"rv\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"se\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"up\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"wb\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"xg\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"yg\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"zv\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"abx\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"amw\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"bem\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"bhs\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"blg\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"bwq\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"cku\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"cmo\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"cnr\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"dgh\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"dmh\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"dqf\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"eys\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"fff\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"foz\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"fqw\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"fsh\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"gjz\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"gpx\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"gqu\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"jcc\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"nmu\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"pzm\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"rdz\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"rvy\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"rya\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"sbn\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"szd\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"tbd\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"uqk\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"vbh\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"vgr\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"vxy\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"xbp\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"yex\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"ynx\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"yuv\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"zih\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"acpy\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"ainw\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"aluw\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"ayfb\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"bbmr\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"bgta\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"bitn\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"bwif\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"bwrz\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"cdcl\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"dglo\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"dxng\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"earx\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"feig\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"fgjk\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"flmd\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"fnfp\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"glms\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"glou\" }\nassert my_solution.minimumPushes(**test_input) == 4", "start_time": 1705804200} +{"task_id": "weekly-contest-381-count-the-number-of-houses-at-a-certain-distance-ii", "url": "https://leetcode.com/problems/count-the-number-of-houses-at-a-certain-distance-ii", "title": "count-the-number-of-houses-at-a-certain-distance-ii", "meta": {"questionId": "3310", "questionFrontendId": "3017", "title": "Count the Number of Houses at a Certain Distance II", "titleSlug": "count-the-number-of-houses-at-a-certain-distance-ii", "isPaidOnly": false, "difficulty": "Hard", "likes": 27, "dislikes": 12, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你三个 正整数 n 、x 和 y 。\n在城市中,存在编号从 1 到 n 的房屋,由 n 条街道相连。对所有 1 <= i < n ,都存在一条街道连接编号为 i 的房屋与编号为 i + 1 的房屋。另存在一条街道连接编号为 x 的房屋与编号为 y 的房屋。\n对于每个 k(1 <= k <= n),你需要找出所有满足要求的 房屋对 [house1, house2] ,即从 house1 到 house2 需要经过的 最少 街道数为 k 。\n返回一个下标从 1 开始且长度为 n 的数组 result ,其中 result[k] 表示所有满足要求的房屋对的数量,即从一个房屋到另一个房屋需要经过的 最少 街道数为 k 。\n注意,x 与 y 可以 相等 。\n\n示例 1:\n\n\n输入:n = 3, x = 1, y = 3\n输出:[6,0,0]\n解释:让我们检视每个房屋对\n- 对于房屋对 (1, 2),可以直接从房屋 1 到房屋 2。\n- 对于房屋对 (2, 1),可以直接从房屋 2 到房屋 1。\n- 对于房屋对 (1, 3),可以直接从房屋 1 到房屋 3。\n- 对于房屋对 (3, 1),可以直接从房屋 3 到房屋 1。\n- 对于房屋对 (2, 3),可以直接从房屋 2 到房屋 3。\n- 对于房屋对 (3, 2),可以直接从房屋 3 到房屋 2。\n\n示例 2:\n\n\n输入:n = 5, x = 2, y = 4\n输出:[10,8,2,0,0]\n解释:对于每个距离 k ,满足要求的房屋对如下:\n- 对于 k == 1,满足要求的房屋对有 (1, 2), (2, 1), (2, 3), (3, 2), (2, 4), (4, 2), (3, 4), (4, 3), (4, 5), 以及 (5, 4)。\n- 对于 k == 2,满足要求的房屋对有 (1, 3), (3, 1), (1, 4), (4, 1), (2, 5), (5, 2), (3, 5), 以及 (5, 3)。\n- 对于 k == 3,满足要求的房屋对有 (1, 5),以及 (5, 1) 。\n- 对于 k == 4 和 k == 5,不存在满足要求的房屋对。\n\n示例 3:\n\n\n输入:n = 4, x = 1, y = 1\n输出:[6,4,2,0]\n解释:对于每个距离 k ,满足要求的房屋对如下:\n- 对于 k == 1,满足要求的房屋对有 (1, 2), (2, 1), (2, 3), (3, 2), (3, 4), 以及 (4, 3)。\n- 对于 k == 2,满足要求的房屋对有 (1, 3), (3, 1), (2, 4), 以及 (4, 2)。\n- 对于 k == 3,满足要求的房屋对有 (1, 4), 以及 (4, 1)。\n- 对于 k == 4,不存在满足要求的房屋对。\n\n\n提示:\n\n2 <= n <= 105\n1 <= x, y <= n\n\"\"\"\nclass Solution:\n def countOfPairs(self, n: int, x: int, y: int) -> List[int]:\n ", "prompt_sft": "给你三个 正整数 n 、x 和 y 。\n在城市中,存在编号从 1 到 n 的房屋,由 n 条街道相连。对所有 1 <= i < n ,都存在一条街道连接编号为 i 的房屋与编号为 i + 1 的房屋。另存在一条街道连接编号为 x 的房屋与编号为 y 的房屋。\n对于每个 k(1 <= k <= n),你需要找出所有满足要求的 房屋对 [house1, house2] ,即从 house1 到 house2 需要经过的 最少 街道数为 k 。\n返回一个下标从 1 开始且长度为 n 的数组 result ,其中 result[k] 表示所有满足要求的房屋对的数量,即从一个房屋到另一个房屋需要经过的 最少 街道数为 k 。\n注意,x 与 y 可以 相等 。\n\n示例 1:\n\n\n输入:n = 3, x = 1, y = 3\n输出:[6,0,0]\n解释:让我们检视每个房屋对\n- 对于房屋对 (1, 2),可以直接从房屋 1 到房屋 2。\n- 对于房屋对 (2, 1),可以直接从房屋 2 到房屋 1。\n- 对于房屋对 (1, 3),可以直接从房屋 1 到房屋 3。\n- 对于房屋对 (3, 1),可以直接从房屋 3 到房屋 1。\n- 对于房屋对 (2, 3),可以直接从房屋 2 到房屋 3。\n- 对于房屋对 (3, 2),可以直接从房屋 3 到房屋 2。\n\n示例 2:\n\n\n输入:n = 5, x = 2, y = 4\n输出:[10,8,2,0,0]\n解释:对于每个距离 k ,满足要求的房屋对如下:\n- 对于 k == 1,满足要求的房屋对有 (1, 2), (2, 1), (2, 3), (3, 2), (2, 4), (4, 2), (3, 4), (4, 3), (4, 5), 以及 (5, 4)。\n- 对于 k == 2,满足要求的房屋对有 (1, 3), (3, 1), (1, 4), (4, 1), (2, 5), (5, 2), (3, 5), 以及 (5, 3)。\n- 对于 k == 3,满足要求的房屋对有 (1, 5),以及 (5, 1) 。\n- 对于 k == 4 和 k == 5,不存在满足要求的房屋对。\n\n示例 3:\n\n\n输入:n = 4, x = 1, y = 1\n输出:[6,4,2,0]\n解释:对于每个距离 k ,满足要求的房屋对如下:\n- 对于 k == 1,满足要求的房屋对有 (1, 2), (2, 1), (2, 3), (3, 2), (3, 4), 以及 (4, 3)。\n- 对于 k == 2,满足要求的房屋对有 (1, 3), (3, 1), (2, 4), 以及 (4, 2)。\n- 对于 k == 3,满足要求的房屋对有 (1, 4), 以及 (4, 1)。\n- 对于 k == 4,不存在满足要求的房屋对。\n\n\n提示:\n\n2 <= n <= 105\n1 <= x, y <= n\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def countOfPairs(self, n: int, x: int, y: int) -> List[int]:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"n\": 3, \"x\": 1, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [6,0,0]\n\ntest_input = { \"n\": 5, \"x\": 2, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [10,8,2,0,0]\n\ntest_input = { \"n\": 4, \"x\": 1, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [6,4,2,0]\n\ntest_input = { \"n\": 2, \"x\": 1, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [2,0]\n\ntest_input = { \"n\": 2, \"x\": 1, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [2,0]\n\ntest_input = { \"n\": 2, \"x\": 2, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [2,0]\n\ntest_input = { \"n\": 2, \"x\": 2, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [2,0]\n\ntest_input = { \"n\": 3, \"x\": 1, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [4,2,0]\n\ntest_input = { \"n\": 3, \"x\": 1, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [4,2,0]\n\ntest_input = { \"n\": 3, \"x\": 2, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [4,2,0]\n\ntest_input = { \"n\": 3, \"x\": 2, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [4,2,0]\n\ntest_input = { \"n\": 3, \"x\": 2, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [4,2,0]\n\ntest_input = { \"n\": 3, \"x\": 3, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [6,0,0]\n\ntest_input = { \"n\": 3, \"x\": 3, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [4,2,0]\n\ntest_input = { \"n\": 3, \"x\": 3, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [4,2,0]\n\ntest_input = { \"n\": 4, \"x\": 1, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [6,4,2,0]\n\ntest_input = { \"n\": 4, \"x\": 1, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [8,4,0,0]\n\ntest_input = { \"n\": 4, \"x\": 1, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [8,4,0,0]\n\ntest_input = { \"n\": 4, \"x\": 2, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [6,4,2,0]\n\ntest_input = { \"n\": 4, \"x\": 2, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [6,4,2,0]\n\ntest_input = { \"n\": 4, \"x\": 2, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [6,4,2,0]\n\ntest_input = { \"n\": 4, \"x\": 2, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [8,4,0,0]\n\ntest_input = { \"n\": 4, \"x\": 3, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [8,4,0,0]\n\ntest_input = { \"n\": 4, \"x\": 3, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [6,4,2,0]\n\ntest_input = { \"n\": 4, \"x\": 3, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [6,4,2,0]\n\ntest_input = { \"n\": 4, \"x\": 3, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [6,4,2,0]\n\ntest_input = { \"n\": 4, \"x\": 4, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [8,4,0,0]\n\ntest_input = { \"n\": 4, \"x\": 4, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [8,4,0,0]\n\ntest_input = { \"n\": 4, \"x\": 4, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [6,4,2,0]\n\ntest_input = { \"n\": 4, \"x\": 4, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [6,4,2,0]\n\ntest_input = { \"n\": 5, \"x\": 1, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [8,6,4,2,0]\n\ntest_input = { \"n\": 5, \"x\": 1, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [10,6,4,0,0]\n\ntest_input = { \"n\": 5, \"x\": 2, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [8,6,4,2,0]\n\ntest_input = { \"n\": 5, \"x\": 2, \"y\": 5 }\nassert my_solution.countOfPairs(**test_input) == [10,8,2,0,0]\n\ntest_input = { \"n\": 5, \"x\": 3, \"y\": 5 }\nassert my_solution.countOfPairs(**test_input) == [10,6,4,0,0]\n\ntest_input = { \"n\": 5, \"x\": 4, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [10,8,2,0,0]\n\ntest_input = { \"n\": 5, \"x\": 4, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [8,6,4,2,0]\n\ntest_input = { \"n\": 5, \"x\": 5, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [10,6,4,0,0]\n\ntest_input = { \"n\": 5, \"x\": 5, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [8,6,4,2,0]\n\ntest_input = { \"n\": 5, \"x\": 5, \"y\": 5 }\nassert my_solution.countOfPairs(**test_input) == [8,6,4,2,0]\n\ntest_input = { \"n\": 6, \"x\": 1, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [12,10,6,2,0,0]\n\ntest_input = { \"n\": 6, \"x\": 1, \"y\": 5 }\nassert my_solution.countOfPairs(**test_input) == [12,14,4,0,0,0]\n\ntest_input = { \"n\": 6, \"x\": 1, \"y\": 6 }\nassert my_solution.countOfPairs(**test_input) == [12,12,6,0,0,0]\n\ntest_input = { \"n\": 6, \"x\": 3, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [10,8,6,4,2,0]\n\ntest_input = { \"n\": 6, \"x\": 3, \"y\": 5 }\nassert my_solution.countOfPairs(**test_input) == [12,10,6,2,0,0]\n\ntest_input = { \"n\": 6, \"x\": 4, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [10,8,6,4,2,0]\n\ntest_input = { \"n\": 6, \"x\": 4, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [10,8,6,4,2,0]\n\ntest_input = { \"n\": 6, \"x\": 4, \"y\": 5 }\nassert my_solution.countOfPairs(**test_input) == [10,8,6,4,2,0]\n\ntest_input = { \"n\": 6, \"x\": 4, \"y\": 6 }\nassert my_solution.countOfPairs(**test_input) == [12,8,6,4,0,0]\n\ntest_input = { \"n\": 6, \"x\": 5, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [12,12,6,0,0,0]\n\ntest_input = { \"n\": 6, \"x\": 5, \"y\": 5 }\nassert my_solution.countOfPairs(**test_input) == [10,8,6,4,2,0]\n\ntest_input = { \"n\": 6, \"x\": 6, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [12,14,4,0,0,0]\n\ntest_input = { \"n\": 6, \"x\": 6, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [12,8,6,4,0,0]\n\ntest_input = { \"n\": 6, \"x\": 6, \"y\": 5 }\nassert my_solution.countOfPairs(**test_input) == [10,8,6,4,2,0]\n\ntest_input = { \"n\": 6, \"x\": 6, \"y\": 6 }\nassert my_solution.countOfPairs(**test_input) == [10,8,6,4,2,0]\n\ntest_input = { \"n\": 7, \"x\": 1, \"y\": 7 }\nassert my_solution.countOfPairs(**test_input) == [14,14,14,0,0,0,0]\n\ntest_input = { \"n\": 7, \"x\": 2, \"y\": 6 }\nassert my_solution.countOfPairs(**test_input) == [14,18,10,0,0,0,0]\n\ntest_input = { \"n\": 7, \"x\": 3, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [12,10,8,6,4,2,0]\n\ntest_input = { \"n\": 7, \"x\": 3, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [12,10,8,6,4,2,0]\n\ntest_input = { \"n\": 7, \"x\": 3, \"y\": 6 }\nassert my_solution.countOfPairs(**test_input) == [14,14,10,4,0,0,0]\n\ntest_input = { \"n\": 7, \"x\": 4, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [12,10,8,6,4,2,0]\n\ntest_input = { \"n\": 7, \"x\": 4, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [12,10,8,6,4,2,0]\n\ntest_input = { \"n\": 7, \"x\": 4, \"y\": 7 }\nassert my_solution.countOfPairs(**test_input) == [14,12,8,6,2,0,0]\n\ntest_input = { \"n\": 7, \"x\": 5, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [14,12,10,4,2,0,0]\n\ntest_input = { \"n\": 7, \"x\": 5, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [12,10,8,6,4,2,0]\n\ntest_input = { \"n\": 7, \"x\": 5, \"y\": 7 }\nassert my_solution.countOfPairs(**test_input) == [14,10,8,6,4,0,0]\n\ntest_input = { \"n\": 7, \"x\": 6, \"y\": 6 }\nassert my_solution.countOfPairs(**test_input) == [12,10,8,6,4,2,0]\n\ntest_input = { \"n\": 7, \"x\": 6, \"y\": 7 }\nassert my_solution.countOfPairs(**test_input) == [12,10,8,6,4,2,0]\n\ntest_input = { \"n\": 7, \"x\": 7, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [14,12,8,6,2,0,0]\n\ntest_input = { \"n\": 8, \"x\": 1, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [14,12,10,8,6,4,2,0]\n\ntest_input = { \"n\": 8, \"x\": 2, \"y\": 7 }\nassert my_solution.countOfPairs(**test_input) == [16,20,16,4,0,0,0,0]\n\ntest_input = { \"n\": 8, \"x\": 3, \"y\": 5 }\nassert my_solution.countOfPairs(**test_input) == [16,14,12,8,4,2,0,0]\n\ntest_input = { \"n\": 8, \"x\": 3, \"y\": 6 }\nassert my_solution.countOfPairs(**test_input) == [16,16,14,8,2,0,0,0]\n\ntest_input = { \"n\": 8, \"x\": 4, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [14,12,10,8,6,4,2,0]\n\ntest_input = { \"n\": 8, \"x\": 4, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [14,12,10,8,6,4,2,0]\n\ntest_input = { \"n\": 8, \"x\": 4, \"y\": 8 }\nassert my_solution.countOfPairs(**test_input) == [16,18,10,8,4,0,0,0]\n\ntest_input = { \"n\": 8, \"x\": 5, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [16,14,12,8,4,2,0,0]\n\ntest_input = { \"n\": 8, \"x\": 5, \"y\": 7 }\nassert my_solution.countOfPairs(**test_input) == [16,14,10,8,6,2,0,0]\n\ntest_input = { \"n\": 8, \"x\": 6, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [16,16,14,8,2,0,0,0]\n\ntest_input = { \"n\": 8, \"x\": 6, \"y\": 7 }\nassert my_solution.countOfPairs(**test_input) == [14,12,10,8,6,4,2,0]\n\ntest_input = { \"n\": 8, \"x\": 6, \"y\": 8 }\nassert my_solution.countOfPairs(**test_input) == [16,12,10,8,6,4,0,0]\n\ntest_input = { \"n\": 8, \"x\": 7, \"y\": 8 }\nassert my_solution.countOfPairs(**test_input) == [14,12,10,8,6,4,2,0]\n\ntest_input = { \"n\": 8, \"x\": 8, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [16,16,16,8,0,0,0,0]\n\ntest_input = { \"n\": 8, \"x\": 8, \"y\": 7 }\nassert my_solution.countOfPairs(**test_input) == [14,12,10,8,6,4,2,0]\n\ntest_input = { \"n\": 8, \"x\": 8, \"y\": 8 }\nassert my_solution.countOfPairs(**test_input) == [14,12,10,8,6,4,2,0]\n\ntest_input = { \"n\": 9, \"x\": 1, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [18,14,12,10,8,6,4,0,0]\n\ntest_input = { \"n\": 9, \"x\": 4, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [16,14,12,10,8,6,4,2,0]\n\ntest_input = { \"n\": 9, \"x\": 4, \"y\": 6 }\nassert my_solution.countOfPairs(**test_input) == [18,16,14,12,6,4,2,0,0]\n\ntest_input = { \"n\": 9, \"x\": 4, \"y\": 9 }\nassert my_solution.countOfPairs(**test_input) == [18,20,16,10,6,2,0,0,0]\n\ntest_input = { \"n\": 9, \"x\": 5, \"y\": 5 }\nassert my_solution.countOfPairs(**test_input) == [16,14,12,10,8,6,4,2,0]\n\ntest_input = { \"n\": 9, \"x\": 5, \"y\": 9 }\nassert my_solution.countOfPairs(**test_input) == [18,20,12,10,8,4,0,0,0]\n\ntest_input = { \"n\": 9, \"x\": 6, \"y\": 7 }\nassert my_solution.countOfPairs(**test_input) == [16,14,12,10,8,6,4,2,0]\n\ntest_input = { \"n\": 9, \"x\": 7, \"y\": 7 }\nassert my_solution.countOfPairs(**test_input) == [16,14,12,10,8,6,4,2,0]\n\ntest_input = { \"n\": 9, \"x\": 8, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [18,22,16,10,6,0,0,0,0]\n\ntest_input = { \"n\": 9, \"x\": 8, \"y\": 6 }\nassert my_solution.countOfPairs(**test_input) == [18,16,12,10,8,6,2,0,0]\n\ntest_input = { \"n\": 9, \"x\": 8, \"y\": 7 }\nassert my_solution.countOfPairs(**test_input) == [16,14,12,10,8,6,4,2,0]\n\ntest_input = { \"n\": 9, \"x\": 8, \"y\": 9 }\nassert my_solution.countOfPairs(**test_input) == [16,14,12,10,8,6,4,2,0]\n\ntest_input = { \"n\": 9, \"x\": 9, \"y\": 5 }\nassert my_solution.countOfPairs(**test_input) == [18,20,12,10,8,4,0,0,0]\n\ntest_input = { \"n\": 9, \"x\": 9, \"y\": 7 }\nassert my_solution.countOfPairs(**test_input) == [18,14,12,10,8,6,4,0,0]\n\ntest_input = { \"n\": 9, \"x\": 9, \"y\": 8 }\nassert my_solution.countOfPairs(**test_input) == [16,14,12,10,8,6,4,2,0]", "start_time": 1705804200} +{"task_id": "biweekly-contest-122-divide-an-array-into-subarrays-with-minimum-cost-i", "url": "https://leetcode.com/problems/divide-an-array-into-subarrays-with-minimum-cost-i", "title": "divide-an-array-into-subarrays-with-minimum-cost-i", "meta": {"questionId": "3263", "questionFrontendId": "3010", "title": "Divide an Array Into Subarrays With Minimum Cost I", "titleSlug": "divide-an-array-into-subarrays-with-minimum-cost-i", "isPaidOnly": false, "difficulty": "Easy", "likes": 40, "dislikes": 2, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个长度为 n的整数数组nums。\n一个数组的 代价是它的 第一个元素。比方说,[1,2,3]的代价是1,[3,4,1]的代价是3。\n你需要将nums分成3个连续且没有交集的子数组。\n请你返回这些子数组的 最小代价总和。\n\n示例 1:\n\n输入:nums = [1,2,3,12]\n输出:6\n解释:最佳分割成 3 个子数组的方案是:[1] ,[2] 和 [3,12] ,总代价为 1 + 2 + 3 = 6 。\n其他得到 3 个子数组的方案是:\n- [1] ,[2,3] 和 [12] ,总代价是 1 + 2 + 12 = 15 。\n- [1,2] ,[3] 和 [12] ,总代价是 1 + 3 + 12 = 16 。\n\n示例 2:\n\n输入:nums = [5,4,3]\n输出:12\n解释:最佳分割成 3 个子数组的方案是:[5] ,[4] 和 [3] ,总代价为 5 + 4 + 3 = 12 。\n12 是所有分割方案里的最小总代价。\n\n示例 3:\n\n输入:nums = [10,3,1,1]\n输出:12\n解释:最佳分割成 3 个子数组的方案是:[10,3] ,[1] 和 [1] ,总代价为 10 + 1 + 1 = 12 。\n12 是所有分割方案里的最小总代价。\n\n\n提示:\n\n3 <= n <= 50\n1 <= nums[i] <= 50\n\"\"\"\nclass Solution:\n def minimumCost(self, nums: List[int]) -> int:\n ", "prompt_sft": "给你一个长度为 n的整数数组nums。\n一个数组的 代价是它的 第一个元素。比方说,[1,2,3]的代价是1,[3,4,1]的代价是3。\n你需要将nums分成3个连续且没有交集的子数组。\n请你返回这些子数组的 最小代价总和。\n\n示例 1:\n\n输入:nums = [1,2,3,12]\n输出:6\n解释:最佳分割成 3 个子数组的方案是:[1] ,[2] 和 [3,12] ,总代价为 1 + 2 + 3 = 6 。\n其他得到 3 个子数组的方案是:\n- [1] ,[2,3] 和 [12] ,总代价是 1 + 2 + 12 = 15 。\n- [1,2] ,[3] 和 [12] ,总代价是 1 + 3 + 12 = 16 。\n\n示例 2:\n\n输入:nums = [5,4,3]\n输出:12\n解释:最佳分割成 3 个子数组的方案是:[5] ,[4] 和 [3] ,总代价为 5 + 4 + 3 = 12 。\n12 是所有分割方案里的最小总代价。\n\n示例 3:\n\n输入:nums = [10,3,1,1]\n输出:12\n解释:最佳分割成 3 个子数组的方案是:[10,3] ,[1] 和 [1] ,总代价为 10 + 1 + 1 = 12 。\n12 是所有分割方案里的最小总代价。\n\n\n提示:\n\n3 <= n <= 50\n1 <= nums[i] <= 50\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def minimumCost(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,2,3,12] }\nassert my_solution.minimumCost(**test_input) == 6\n\ntest_input = { \"nums\": [5,4,3] }\nassert my_solution.minimumCost(**test_input) == 12\n\ntest_input = { \"nums\": [10,3,1,1] }\nassert my_solution.minimumCost(**test_input) == 12\n\ntest_input = { \"nums\": [1,1,1] }\nassert my_solution.minimumCost(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,2] }\nassert my_solution.minimumCost(**test_input) == 4\n\ntest_input = { \"nums\": [1,1,3] }\nassert my_solution.minimumCost(**test_input) == 5\n\ntest_input = { \"nums\": [1,1,4] }\nassert my_solution.minimumCost(**test_input) == 6\n\ntest_input = { \"nums\": [1,1,5] }\nassert my_solution.minimumCost(**test_input) == 7\n\ntest_input = { \"nums\": [1,2,1] }\nassert my_solution.minimumCost(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,2] }\nassert my_solution.minimumCost(**test_input) == 5\n\ntest_input = { \"nums\": [1,2,3] }\nassert my_solution.minimumCost(**test_input) == 6\n\ntest_input = { \"nums\": [1,2,4] }\nassert my_solution.minimumCost(**test_input) == 7\n\ntest_input = { \"nums\": [1,2,5] }\nassert my_solution.minimumCost(**test_input) == 8\n\ntest_input = { \"nums\": [1,3,1] }\nassert my_solution.minimumCost(**test_input) == 5\n\ntest_input = { \"nums\": [1,3,2] }\nassert my_solution.minimumCost(**test_input) == 6\n\ntest_input = { \"nums\": [1,3,3] }\nassert my_solution.minimumCost(**test_input) == 7\n\ntest_input = { \"nums\": [1,3,4] }\nassert my_solution.minimumCost(**test_input) == 8\n\ntest_input = { \"nums\": [1,3,5] }\nassert my_solution.minimumCost(**test_input) == 9\n\ntest_input = { \"nums\": [1,4,1] }\nassert my_solution.minimumCost(**test_input) == 6\n\ntest_input = { \"nums\": [1,4,2] }\nassert my_solution.minimumCost(**test_input) == 7\n\ntest_input = { \"nums\": [1,4,3] }\nassert my_solution.minimumCost(**test_input) == 8\n\ntest_input = { \"nums\": [1,4,4] }\nassert my_solution.minimumCost(**test_input) == 9\n\ntest_input = { \"nums\": [1,4,5] }\nassert my_solution.minimumCost(**test_input) == 10\n\ntest_input = { \"nums\": [1,5,1] }\nassert my_solution.minimumCost(**test_input) == 7\n\ntest_input = { \"nums\": [1,5,2] }\nassert my_solution.minimumCost(**test_input) == 8\n\ntest_input = { \"nums\": [1,5,3] }\nassert my_solution.minimumCost(**test_input) == 9\n\ntest_input = { \"nums\": [1,5,4] }\nassert my_solution.minimumCost(**test_input) == 10\n\ntest_input = { \"nums\": [1,5,5] }\nassert my_solution.minimumCost(**test_input) == 11\n\ntest_input = { \"nums\": [2,1,1] }\nassert my_solution.minimumCost(**test_input) == 4\n\ntest_input = { \"nums\": [2,1,2] }\nassert my_solution.minimumCost(**test_input) == 5\n\ntest_input = { \"nums\": [2,1,3] }\nassert my_solution.minimumCost(**test_input) == 6\n\ntest_input = { \"nums\": [2,1,4] }\nassert my_solution.minimumCost(**test_input) == 7\n\ntest_input = { \"nums\": [2,1,5] }\nassert my_solution.minimumCost(**test_input) == 8\n\ntest_input = { \"nums\": [2,2,1] }\nassert my_solution.minimumCost(**test_input) == 5\n\ntest_input = { \"nums\": [2,2,2] }\nassert my_solution.minimumCost(**test_input) == 6\n\ntest_input = { \"nums\": [2,2,3] }\nassert my_solution.minimumCost(**test_input) == 7\n\ntest_input = { \"nums\": [2,2,4] }\nassert my_solution.minimumCost(**test_input) == 8\n\ntest_input = { \"nums\": [2,2,5] }\nassert my_solution.minimumCost(**test_input) == 9\n\ntest_input = { \"nums\": [2,3,1] }\nassert my_solution.minimumCost(**test_input) == 6\n\ntest_input = { \"nums\": [2,3,2] }\nassert my_solution.minimumCost(**test_input) == 7\n\ntest_input = { \"nums\": [2,3,3] }\nassert my_solution.minimumCost(**test_input) == 8\n\ntest_input = { \"nums\": [2,3,4] }\nassert my_solution.minimumCost(**test_input) == 9\n\ntest_input = { \"nums\": [2,3,5] }\nassert my_solution.minimumCost(**test_input) == 10\n\ntest_input = { \"nums\": [2,4,1] }\nassert my_solution.minimumCost(**test_input) == 7\n\ntest_input = { \"nums\": [2,4,2] }\nassert my_solution.minimumCost(**test_input) == 8\n\ntest_input = { \"nums\": [2,4,3] }\nassert my_solution.minimumCost(**test_input) == 9\n\ntest_input = { \"nums\": [2,4,4] }\nassert my_solution.minimumCost(**test_input) == 10\n\ntest_input = { \"nums\": [2,4,5] }\nassert my_solution.minimumCost(**test_input) == 11\n\ntest_input = { \"nums\": [2,5,1] }\nassert my_solution.minimumCost(**test_input) == 8\n\ntest_input = { \"nums\": [2,5,2] }\nassert my_solution.minimumCost(**test_input) == 9\n\ntest_input = { \"nums\": [2,5,3] }\nassert my_solution.minimumCost(**test_input) == 10\n\ntest_input = { \"nums\": [2,5,4] }\nassert my_solution.minimumCost(**test_input) == 11\n\ntest_input = { \"nums\": [2,5,5] }\nassert my_solution.minimumCost(**test_input) == 12\n\ntest_input = { \"nums\": [3,1,1] }\nassert my_solution.minimumCost(**test_input) == 5\n\ntest_input = { \"nums\": [3,1,2] }\nassert my_solution.minimumCost(**test_input) == 6\n\ntest_input = { \"nums\": [3,1,3] }\nassert my_solution.minimumCost(**test_input) == 7\n\ntest_input = { \"nums\": [3,1,4] }\nassert my_solution.minimumCost(**test_input) == 8\n\ntest_input = { \"nums\": [3,1,5] }\nassert my_solution.minimumCost(**test_input) == 9\n\ntest_input = { \"nums\": [3,2,1] }\nassert my_solution.minimumCost(**test_input) == 6\n\ntest_input = { \"nums\": [3,2,2] }\nassert my_solution.minimumCost(**test_input) == 7\n\ntest_input = { \"nums\": [3,2,3] }\nassert my_solution.minimumCost(**test_input) == 8\n\ntest_input = { \"nums\": [3,2,4] }\nassert my_solution.minimumCost(**test_input) == 9\n\ntest_input = { \"nums\": [3,2,5] }\nassert my_solution.minimumCost(**test_input) == 10\n\ntest_input = { \"nums\": [3,3,1] }\nassert my_solution.minimumCost(**test_input) == 7\n\ntest_input = { \"nums\": [3,3,2] }\nassert my_solution.minimumCost(**test_input) == 8\n\ntest_input = { \"nums\": [3,3,3] }\nassert my_solution.minimumCost(**test_input) == 9\n\ntest_input = { \"nums\": [3,3,4] }\nassert my_solution.minimumCost(**test_input) == 10\n\ntest_input = { \"nums\": [3,3,5] }\nassert my_solution.minimumCost(**test_input) == 11\n\ntest_input = { \"nums\": [3,4,1] }\nassert my_solution.minimumCost(**test_input) == 8\n\ntest_input = { \"nums\": [3,4,2] }\nassert my_solution.minimumCost(**test_input) == 9\n\ntest_input = { \"nums\": [3,4,3] }\nassert my_solution.minimumCost(**test_input) == 10\n\ntest_input = { \"nums\": [3,4,4] }\nassert my_solution.minimumCost(**test_input) == 11\n\ntest_input = { \"nums\": [3,4,5] }\nassert my_solution.minimumCost(**test_input) == 12\n\ntest_input = { \"nums\": [3,5,1] }\nassert my_solution.minimumCost(**test_input) == 9\n\ntest_input = { \"nums\": [3,5,2] }\nassert my_solution.minimumCost(**test_input) == 10\n\ntest_input = { \"nums\": [3,5,3] }\nassert my_solution.minimumCost(**test_input) == 11\n\ntest_input = { \"nums\": [3,5,4] }\nassert my_solution.minimumCost(**test_input) == 12\n\ntest_input = { \"nums\": [3,5,5] }\nassert my_solution.minimumCost(**test_input) == 13\n\ntest_input = { \"nums\": [4,1,1] }\nassert my_solution.minimumCost(**test_input) == 6\n\ntest_input = { \"nums\": [4,1,2] }\nassert my_solution.minimumCost(**test_input) == 7\n\ntest_input = { \"nums\": [4,1,3] }\nassert my_solution.minimumCost(**test_input) == 8\n\ntest_input = { \"nums\": [4,1,4] }\nassert my_solution.minimumCost(**test_input) == 9\n\ntest_input = { \"nums\": [4,1,5] }\nassert my_solution.minimumCost(**test_input) == 10\n\ntest_input = { \"nums\": [4,2,1] }\nassert my_solution.minimumCost(**test_input) == 7\n\ntest_input = { \"nums\": [4,2,2] }\nassert my_solution.minimumCost(**test_input) == 8\n\ntest_input = { \"nums\": [4,2,3] }\nassert my_solution.minimumCost(**test_input) == 9\n\ntest_input = { \"nums\": [4,2,4] }\nassert my_solution.minimumCost(**test_input) == 10\n\ntest_input = { \"nums\": [4,2,5] }\nassert my_solution.minimumCost(**test_input) == 11\n\ntest_input = { \"nums\": [4,3,1] }\nassert my_solution.minimumCost(**test_input) == 8\n\ntest_input = { \"nums\": [4,3,2] }\nassert my_solution.minimumCost(**test_input) == 9\n\ntest_input = { \"nums\": [4,3,3] }\nassert my_solution.minimumCost(**test_input) == 10\n\ntest_input = { \"nums\": [4,3,4] }\nassert my_solution.minimumCost(**test_input) == 11\n\ntest_input = { \"nums\": [4,3,5] }\nassert my_solution.minimumCost(**test_input) == 12\n\ntest_input = { \"nums\": [4,4,1] }\nassert my_solution.minimumCost(**test_input) == 9\n\ntest_input = { \"nums\": [4,4,2] }\nassert my_solution.minimumCost(**test_input) == 10\n\ntest_input = { \"nums\": [4,4,3] }\nassert my_solution.minimumCost(**test_input) == 11\n\ntest_input = { \"nums\": [4,4,4] }\nassert my_solution.minimumCost(**test_input) == 12\n\ntest_input = { \"nums\": [4,4,5] }\nassert my_solution.minimumCost(**test_input) == 13\n\ntest_input = { \"nums\": [4,5,1] }\nassert my_solution.minimumCost(**test_input) == 10\n\ntest_input = { \"nums\": [4,5,2] }\nassert my_solution.minimumCost(**test_input) == 11", "start_time": 1705761000} +{"task_id": "biweekly-contest-122-find-if-array-can-be-sorted", "url": "https://leetcode.com/problems/find-if-array-can-be-sorted", "title": "find-if-array-can-be-sorted", "meta": {"questionId": "3291", "questionFrontendId": "3011", "title": "Find if Array Can Be Sorted", "titleSlug": "find-if-array-can-be-sorted", "isPaidOnly": false, "difficulty": "Medium", "likes": 52, "dislikes": 7, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0开始且全是 正整数的数组nums。\n一次 操作中,如果两个 相邻元素在二进制下数位为 1的数目 相同,那么你可以将这两个元素交换。你可以执行这个操作 任意次(也可以 0 次)。\n如果你可以使数组变有序,请你返回true ,否则返回false。\n\n示例 1:\n\n输入:nums = [8,4,2,30,15]\n输出:true\n解释:我们先观察每个元素的二进制表示。 2 ,4 和 8 分别都只有一个数位为 1 ,分别为 \"10\" ,\"100\" 和 \"1000\" 。15 和 30 分别有 4 个数位为 1 :\"1111\" 和 \"11110\" 。\n我们可以通过 4 个操作使数组有序:\n- 交换 nums[0] 和 nums[1] 。8 和 4 分别只有 1 个数位为 1 。数组变为 [4,8,2,30,15] 。\n- 交换 nums[1] 和 nums[2] 。8 和 2 分别只有 1 个数位为 1 。数组变为 [4,2,8,30,15] 。\n- 交换 nums[0] 和 nums[1] 。4 和 2 分别只有 1 个数位为 1 。数组变为 [2,4,8,30,15] 。\n- 交换 nums[3] 和 nums[4] 。30 和 15 分别有 4 个数位为 1 ,数组变为 [2,4,8,15,30] 。\n数组变成有序的,所以我们返回 true 。\n注意我们还可以通过其他的操作序列使数组变得有序。\n\n示例 2:\n\n输入:nums = [1,2,3,4,5]\n输出:true\n解释:数组已经是有序的,所以我们返回 true 。\n\n示例 3:\n\n输入:nums = [3,16,8,4,2]\n输出:false\n解释:无法通过操作使数组变为有序。\n\n\n提示:\n\n1 <= nums.length <= 100\n1 <= nums[i] <= 28\n\"\"\"\nclass Solution:\n def canSortArray(self, nums: List[int]) -> bool:\n ", "prompt_sft": "给你一个下标从 0开始且全是 正整数的数组nums。\n一次 操作中,如果两个 相邻元素在二进制下数位为 1的数目 相同,那么你可以将这两个元素交换。你可以执行这个操作 任意次(也可以 0 次)。\n如果你可以使数组变有序,请你返回true ,否则返回false。\n\n示例 1:\n\n输入:nums = [8,4,2,30,15]\n输出:true\n解释:我们先观察每个元素的二进制表示。 2 ,4 和 8 分别都只有一个数位为 1 ,分别为 \"10\" ,\"100\" 和 \"1000\" 。15 和 30 分别有 4 个数位为 1 :\"1111\" 和 \"11110\" 。\n我们可以通过 4 个操作使数组有序:\n- 交换 nums[0] 和 nums[1] 。8 和 4 分别只有 1 个数位为 1 。数组变为 [4,8,2,30,15] 。\n- 交换 nums[1] 和 nums[2] 。8 和 2 分别只有 1 个数位为 1 。数组变为 [4,2,8,30,15] 。\n- 交换 nums[0] 和 nums[1] 。4 和 2 分别只有 1 个数位为 1 。数组变为 [2,4,8,30,15] 。\n- 交换 nums[3] 和 nums[4] 。30 和 15 分别有 4 个数位为 1 ,数组变为 [2,4,8,15,30] 。\n数组变成有序的,所以我们返回 true 。\n注意我们还可以通过其他的操作序列使数组变得有序。\n\n示例 2:\n\n输入:nums = [1,2,3,4,5]\n输出:true\n解释:数组已经是有序的,所以我们返回 true 。\n\n示例 3:\n\n输入:nums = [3,16,8,4,2]\n输出:false\n解释:无法通过操作使数组变为有序。\n\n\n提示:\n\n1 <= nums.length <= 100\n1 <= nums[i] <= 28\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def canSortArray(self, nums: List[int]) -> bool:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [8,4,2,30,15] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [1,2,3,4,5] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [1] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [4] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [3,16,8,4,2] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [7] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [10] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [20,16] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [18] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [21,17] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [30] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [26,10] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [1,2] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [2,28,9] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [2,17] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [18,3,8] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [31,18,23] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [75,34,30] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [107,76,52] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [125,92,159] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [136,256,10] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [160,247,127] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [187,4,32] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [197,171,144] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [214,200,176] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [222,191,39] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [24,12] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [225,163,64] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [128,128] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [229,253,127] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [1,2,3] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [1,256,64] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [6,6,192] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [239,83,71] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [6,96,20] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [247,153,90] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [256,255,255] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [1,201,251,191] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [4,157,191,127] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [8,8,2] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [10,34,130] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [12,19,1,11] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [10,91,127] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [15,8,21,25] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [17,25,4,27] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [10,130,206] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [14,183,251] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [29,20,17,4] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [15,147,174] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [16,245,125] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [32,12,25,19] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [22,21,26] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [23,30,32] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [24,72,160] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [33,223,239] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [35,143,127,254] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [55,147,16,8] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [34,52,104] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [100,104,96,144] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [129,70,126,253] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [129,162,158,253] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [145,127,55,43] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [36,177,244] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [159,111,124,233] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [36,213,236] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [175,231,27,92] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [205,234,127,223] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [215,10,8,256] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [223,127,172,210] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [38,221,224] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [41,14,50] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [41,79,239] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [44,124,247] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [225,201,121,103] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [232,45,175,231] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [250,131,50,46] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [254,249,173,163] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [255,255,214,229] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [256,151,141,15] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [47,205,182] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [48,64,251] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [51,253,254] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [53,172,195] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [57,127,251] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [4,98,210,79,254] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [59,31,236] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [8,5,103,247,235] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [8,74,170,254,132] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [8,148,182,62,255] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [62,153,210] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [64,93,253] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [9,28,18,26,11] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [12,208,240,216,139] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [13,21,23,13,32] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [16,24,13,46,156] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [16,192,71,31,239] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [64,195,203] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [65,254,239] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [17,11,5,20,8] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [23,12,22,29,20] }\nassert my_solution.canSortArray(**test_input) == False", "start_time": 1705761000} +{"task_id": "biweekly-contest-122-minimize-length-of-array-using-operations", "url": "https://leetcode.com/problems/minimize-length-of-array-using-operations", "title": "minimize-length-of-array-using-operations", "meta": {"questionId": "3244", "questionFrontendId": "3012", "title": "Minimize Length of Array Using Operations", "titleSlug": "minimize-length-of-array-using-operations", "isPaidOnly": false, "difficulty": "Medium", "likes": 79, "dislikes": 30, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0开始的整数数组nums,它只包含 正整数。\n你的任务是通过进行以下操作任意次(可以是 0 次)最小化nums的长度:\n\n在 nums中选择 两个不同的下标i和j,满足nums[i] > 0且nums[j] > 0。\n将结果nums[i] % nums[j]插入nums的结尾。\n将 nums中下标为i和j的元素删除。\n\n请你返回一个整数,它表示进行任意次操作以后nums的 最小长度。\n\n示例 1:\n\n输入:nums = [1,4,3,1]\n输出:1\n解释:使数组长度最小的一种方法是:\n操作 1 :选择下标 2 和 1 ,插入 nums[2] % nums[1] 到数组末尾,得到 [1,4,3,1,3] ,然后删除下标为 2 和 1 的元素。\nnums 变为 [1,1,3] 。\n操作 2 :选择下标 1 和 2 ,插入 nums[1] % nums[2] 到数组末尾,得到 [1,1,3,1] ,然后删除下标为 1 和 2 的元素。\nnums 变为 [1,1] 。\n操作 3 :选择下标 1 和 0 ,插入 nums[1] % nums[0] 到数组末尾,得到 [1,1,0] ,然后删除下标为 1 和 0 的元素。\nnums 变为 [0] 。\nnums 的长度无法进一步减小,所以答案为 1 。\n1 是可以得到的最小长度。\n示例 2:\n\n输入:nums = [5,5,5,10,5]\n输出:2\n解释:使数组长度最小的一种方法是:\n操作 1 :选择下标 0 和 3 ,插入 nums[0] % nums[3] 到数组末尾,得到 [5,5,5,10,5,5] ,然后删除下标为 0 和 3 的元素。\nnums 变为 [5,5,5,5] 。\n操作 2 :选择下标 2 和 3 ,插入 nums[2] % nums[3] 到数组末尾,得到 [5,5,5,5,0] ,然后删除下标为 2 和 3 的元素。\nnums 变为 [5,5,0] 。\n操作 3 :选择下标 0 和 1 ,插入 nums[0] % nums[1] 到数组末尾,得到 [5,5,0,0] ,然后删除下标为 0 和 1 的元素。\nnums 变为 [0,0] 。\nnums 的长度无法进一步减小,所以答案为 2 。\n2 是可以得到的最小长度。\n示例 3:\n\n输入:nums = [2,3,4]\n输出:1\n解释:使数组长度最小的一种方法是:\n操作 1 :选择下标 1 和 2 ,插入 nums[1] % nums[2] 到数组末尾,得到 [2,3,4,3] ,然后删除下标为 1 和 2 的元素。\nnums 变为 [2,3] 。\n操作 2 :选择下标 1 和 0 ,插入 nums[1] % nums[0] 到数组末尾,得到 [2,3,1] ,然后删除下标为 1 和 0 的元素。\nnums 变为 [1] 。\nnums 的长度无法进一步减小,所以答案为 1 。\n1 是可以得到的最小长度。\n\n提示:\n\n1 <= nums.length <= 105\n1 <= nums[i] <= 109\n\"\"\"\nclass Solution:\n def minimumArrayLength(self, nums: List[int]) -> int:\n ", "prompt_sft": "给你一个下标从 0开始的整数数组nums,它只包含 正整数。\n你的任务是通过进行以下操作任意次(可以是 0 次)最小化nums的长度:\n\n在 nums中选择 两个不同的下标i和j,满足nums[i] > 0且nums[j] > 0。\n将结果nums[i] % nums[j]插入nums的结尾。\n将 nums中下标为i和j的元素删除。\n\n请你返回一个整数,它表示进行任意次操作以后nums的 最小长度。\n\n示例 1:\n\n输入:nums = [1,4,3,1]\n输出:1\n解释:使数组长度最小的一种方法是:\n操作 1 :选择下标 2 和 1 ,插入 nums[2] % nums[1] 到数组末尾,得到 [1,4,3,1,3] ,然后删除下标为 2 和 1 的元素。\nnums 变为 [1,1,3] 。\n操作 2 :选择下标 1 和 2 ,插入 nums[1] % nums[2] 到数组末尾,得到 [1,1,3,1] ,然后删除下标为 1 和 2 的元素。\nnums 变为 [1,1] 。\n操作 3 :选择下标 1 和 0 ,插入 nums[1] % nums[0] 到数组末尾,得到 [1,1,0] ,然后删除下标为 1 和 0 的元素。\nnums 变为 [0] 。\nnums 的长度无法进一步减小,所以答案为 1 。\n1 是可以得到的最小长度。\n示例 2:\n\n输入:nums = [5,5,5,10,5]\n输出:2\n解释:使数组长度最小的一种方法是:\n操作 1 :选择下标 0 和 3 ,插入 nums[0] % nums[3] 到数组末尾,得到 [5,5,5,10,5,5] ,然后删除下标为 0 和 3 的元素。\nnums 变为 [5,5,5,5] 。\n操作 2 :选择下标 2 和 3 ,插入 nums[2] % nums[3] 到数组末尾,得到 [5,5,5,5,0] ,然后删除下标为 2 和 3 的元素。\nnums 变为 [5,5,0] 。\n操作 3 :选择下标 0 和 1 ,插入 nums[0] % nums[1] 到数组末尾,得到 [5,5,0,0] ,然后删除下标为 0 和 1 的元素。\nnums 变为 [0,0] 。\nnums 的长度无法进一步减小,所以答案为 2 。\n2 是可以得到的最小长度。\n示例 3:\n\n输入:nums = [2,3,4]\n输出:1\n解释:使数组长度最小的一种方法是:\n操作 1 :选择下标 1 和 2 ,插入 nums[1] % nums[2] 到数组末尾,得到 [2,3,4,3] ,然后删除下标为 1 和 2 的元素。\nnums 变为 [2,3] 。\n操作 2 :选择下标 1 和 0 ,插入 nums[1] % nums[0] 到数组末尾,得到 [2,3,1] ,然后删除下标为 1 和 0 的元素。\nnums 变为 [1] 。\nnums 的长度无法进一步减小,所以答案为 1 。\n1 是可以得到的最小长度。\n\n提示:\n\n1 <= nums.length <= 105\n1 <= nums[i] <= 109\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def minimumArrayLength(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,4,3,1] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [5,5,5,10,5] }\nassert my_solution.minimumArrayLength(**test_input) == 2\n\ntest_input = { \"nums\": [2,3,4] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [1] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [3] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [6] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [1,4] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [1,5] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [2,4] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [3,4] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [5,3] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [6,9] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [8,2] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [9,9] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [9,10] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,5] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [2,1,1] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [2,7,10] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [2,9,5] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [3,2,1] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [3,2,7] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [3,3,1] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [4,1,3] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [4,4,4] }\nassert my_solution.minimumArrayLength(**test_input) == 2\n\ntest_input = { \"nums\": [5,1,5] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [5,5,5] }\nassert my_solution.minimumArrayLength(**test_input) == 2\n\ntest_input = { \"nums\": [6,5,1] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [8,4,5] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [9,2,2] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,3,2] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [1,3,1,7] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [1,5,5,4] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [1,8,7,2] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [2,2,1,1] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [2,7,10,1] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [2,10,1,7] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [4,2,3,5] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [4,4,1,1] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [5,3,10,10] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [6,3,4,4] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [6,5,2,10] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [7,2,5,9] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [1,3,4,4,3] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [4,1,7,10,1] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [4,3,1,4,3] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [4,6,2,6,4] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [6,10,6,3,3] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [1,4,5,4,5,1] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [1,6,6,9,5,7] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [2,1,2,5,3,1] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [2,2,4,4,2,1] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [3,5,2,5,5,2] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [4,1,4,4,5,1] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [4,3,1,2,5,2] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [4,8,8,7,6,8] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [5,2,2,2,9,10] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [7,3,2,4,3,10] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [7,5,6,6,7,3] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [8,3,9,4,5,8] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [2,5,4,3,5,5,4] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [4,5,5,1,2,5,2] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [4,8,7,4,9,3,9] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [5,3,5,7,9,10,10] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [7,1,9,3,9,2,6] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [7,10,1,8,6,1,2] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [9,1,10,7,3,9,7] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [10,10,3,9,8,3,5] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [10,10,4,8,5,2,6] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [1,5,2,10,4,5,10,1] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [2,1,3,3,3,3,1,4] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [2,2,7,4,5,5,1,2] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [2,4,5,5,3,5,2,4] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [2,10,6,7,7,2,3,4] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [3,3,2,2,4,2,3,3] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [3,4,3,4,1,1,1,2] }\nassert my_solution.minimumArrayLength(**test_input) == 2\n\ntest_input = { \"nums\": [3,4,4,3,5,4,5,5] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [3,6,7,7,6,9,1,6] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [5,1,1,1,1,5,5,5] }\nassert my_solution.minimumArrayLength(**test_input) == 2\n\ntest_input = { \"nums\": [6,7,5,5,3,6,1,8] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [8,5,4,5,4,7,6,10] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [8,10,4,6,7,9,2,1] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [2,6,3,8,9,10,9,3,10] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [4,2,2,1,3,1,5,3,3] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [4,4,5,1,2,1,1,1,2] }\nassert my_solution.minimumArrayLength(**test_input) == 2\n\ntest_input = { \"nums\": [4,5,3,5,5,4,4,2,1] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [5,1,5,1,1,5,4,3,3] }\nassert my_solution.minimumArrayLength(**test_input) == 2\n\ntest_input = { \"nums\": [5,1,5,3,3,2,2,4,4] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [6,4,5,7,9,10,10,6,9] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [6,5,6,4,9,8,8,3,7] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [9,7,6,10,1,8,5,4,2] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [9,10,1,6,4,10,1,3,4] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [10,5,4,8,4,3,7,10,3] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,1,2,2,2,5,5,1,3] }\nassert my_solution.minimumArrayLength(**test_input) == 2\n\ntest_input = { \"nums\": [4,5,1,8,2,7,2,7,7,6] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [7,1,3,10,1,4,5,2,9,7] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [7,2,2,9,5,6,6,10,2,3] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [7,7,3,6,8,10,3,7,6,9] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [1,4,5,8,9,3,1,4,7,4,5] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [4,10,3,8,9,5,7,6,9,10,10] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [5,9,3,9,3,10,1,1,6,3,10] }\nassert my_solution.minimumArrayLength(**test_input) == 1", "start_time": 1705761000} +{"task_id": "biweekly-contest-122-divide-an-array-into-subarrays-with-minimum-cost-ii", "url": "https://leetcode.com/problems/divide-an-array-into-subarrays-with-minimum-cost-ii", "title": "divide-an-array-into-subarrays-with-minimum-cost-ii", "meta": {"questionId": "3260", "questionFrontendId": "3013", "title": "Divide an Array Into Subarrays With Minimum Cost II", "titleSlug": "divide-an-array-into-subarrays-with-minimum-cost-ii", "isPaidOnly": false, "difficulty": "Hard", "likes": 54, "dislikes": 2, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0开始长度为 n的整数数组nums和两个 正整数k 和dist。\n一个数组的 代价是数组中的 第一个元素。比方说,[1,2,3]的代价为1,[3,4,1]的代价为3。\n你需要将 nums分割成 k个 连续且互不相交的子数组,满足 第二个子数组与第 k个子数组中第一个元素的下标距离 不超过dist。换句话说,如果你将nums分割成子数组nums[0..(i1 - 1)], nums[i1..(i2 - 1)], ..., nums[ik-1..(n - 1)],那么它需要满足ik-1 - i1 <= dist。\n请你返回这些子数组的 最小总代价。\n\n示例 1:\n\n输入:nums = [1,3,2,6,4,2], k = 3, dist = 3\n输出:5\n解释:将数组分割成 3 个子数组的最优方案是:[1,3] ,[2,6,4] 和 [2] 。这是一个合法分割,因为 ik-1 - i1 等于 5 - 2 = 3 ,等于 dist 。总代价为 nums[0] + nums[2] + nums[5] ,也就是 1 + 2 + 2 = 5 。\n5 是分割成 3 个子数组的最小总代价。\n\n示例 2:\n\n输入:nums = [10,1,2,2,2,1], k = 4, dist = 3\n输出:15\n解释:将数组分割成 4 个子数组的最优方案是:[10] ,[1] ,[2] 和 [2,2,1] 。这是一个合法分割,因为 ik-1 - i1 等于 3 - 1 = 2 ,小于 dist 。总代价为 nums[0] + nums[1] + nums[2] + nums[3] ,也就是 10 + 1 + 2 + 2 = 15 。\n分割 [10] ,[1] ,[2,2,2] 和 [1] 不是一个合法分割,因为 ik-1 和 i1 的差为 5 - 1 = 4 ,大于 dist 。\n15 是分割成 4 个子数组的最小总代价。\n\n示例 3:\n\n输入:nums = [10,8,18,9], k = 3, dist = 1\n输出:36\n解释:将数组分割成 4 个子数组的最优方案是:[10] ,[8] 和 [18,9] 。这是一个合法分割,因为 ik-1 - i1 等于 2 - 1 = 1 ,等于 dist 。总代价为 nums[0] + nums[1] + nums[2] ,也就是 10 + 8 + 18 = 36 。\n分割 [10] ,[8,18] 和 [9] 不是一个合法分割,因为 ik-1 和 i1 的差为 3 - 1 = 2 ,大于 dist 。\n36 是分割成 3 个子数组的最小总代价。\n\n\n提示:\n\n3 <= n <= 105\n1 <= nums[i] <= 109\n3 <= k <= n\nk - 2 <= dist <= n - 2\n\"\"\"\nclass Solution:\n def minimumCost(self, nums: List[int], k: int, dist: int) -> int:\n ", "prompt_sft": "给你一个下标从 0开始长度为 n的整数数组nums和两个 正整数k 和dist。\n一个数组的 代价是数组中的 第一个元素。比方说,[1,2,3]的代价为1,[3,4,1]的代价为3。\n你需要将 nums分割成 k个 连续且互不相交的子数组,满足 第二个子数组与第 k个子数组中第一个元素的下标距离 不超过dist。换句话说,如果你将nums分割成子数组nums[0..(i1 - 1)], nums[i1..(i2 - 1)], ..., nums[ik-1..(n - 1)],那么它需要满足ik-1 - i1 <= dist。\n请你返回这些子数组的 最小总代价。\n\n示例 1:\n\n输入:nums = [1,3,2,6,4,2], k = 3, dist = 3\n输出:5\n解释:将数组分割成 3 个子数组的最优方案是:[1,3] ,[2,6,4] 和 [2] 。这是一个合法分割,因为 ik-1 - i1 等于 5 - 2 = 3 ,等于 dist 。总代价为 nums[0] + nums[2] + nums[5] ,也就是 1 + 2 + 2 = 5 。\n5 是分割成 3 个子数组的最小总代价。\n\n示例 2:\n\n输入:nums = [10,1,2,2,2,1], k = 4, dist = 3\n输出:15\n解释:将数组分割成 4 个子数组的最优方案是:[10] ,[1] ,[2] 和 [2,2,1] 。这是一个合法分割,因为 ik-1 - i1 等于 3 - 1 = 2 ,小于 dist 。总代价为 nums[0] + nums[1] + nums[2] + nums[3] ,也就是 10 + 1 + 2 + 2 = 15 。\n分割 [10] ,[1] ,[2,2,2] 和 [1] 不是一个合法分割,因为 ik-1 和 i1 的差为 5 - 1 = 4 ,大于 dist 。\n15 是分割成 4 个子数组的最小总代价。\n\n示例 3:\n\n输入:nums = [10,8,18,9], k = 3, dist = 1\n输出:36\n解释:将数组分割成 4 个子数组的最优方案是:[10] ,[8] 和 [18,9] 。这是一个合法分割,因为 ik-1 - i1 等于 2 - 1 = 1 ,等于 dist 。总代价为 nums[0] + nums[1] + nums[2] ,也就是 10 + 8 + 18 = 36 。\n分割 [10] ,[8,18] 和 [9] 不是一个合法分割,因为 ik-1 和 i1 的差为 3 - 1 = 2 ,大于 dist 。\n36 是分割成 3 个子数组的最小总代价。\n\n\n提示:\n\n3 <= n <= 105\n1 <= nums[i] <= 109\n3 <= k <= n\nk - 2 <= dist <= n - 2\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def minimumCost(self, nums: List[int], k: int, dist: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,3,2,6,4,2], \"k\": 3, \"dist\": 3 }\nassert my_solution.minimumCost(**test_input) == 5\n\ntest_input = { \"nums\": [10,1,2,2,2,1], \"k\": 4, \"dist\": 3 }\nassert my_solution.minimumCost(**test_input) == 15\n\ntest_input = { \"nums\": [10,8,18,9], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 36\n\ntest_input = { \"nums\": [1,1,1], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,3], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 5\n\ntest_input = { \"nums\": [1,2,2], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 5\n\ntest_input = { \"nums\": [1,2,5], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 8\n\ntest_input = { \"nums\": [1,4,4], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 9\n\ntest_input = { \"nums\": [2,2,1], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 5\n\ntest_input = { \"nums\": [2,3,2], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 7\n\ntest_input = { \"nums\": [2,5,4], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 11\n\ntest_input = { \"nums\": [3,1,2], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 6\n\ntest_input = { \"nums\": [3,1,3], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 7\n\ntest_input = { \"nums\": [3,2,2], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 7\n\ntest_input = { \"nums\": [3,3,2], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 8\n\ntest_input = { \"nums\": [3,4,1], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 8\n\ntest_input = { \"nums\": [3,5,3], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 11\n\ntest_input = { \"nums\": [4,1,4], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 9\n\ntest_input = { \"nums\": [4,1,5], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 10\n\ntest_input = { \"nums\": [4,2,1], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 7\n\ntest_input = { \"nums\": [4,2,2], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 8\n\ntest_input = { \"nums\": [4,2,4], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 10\n\ntest_input = { \"nums\": [4,2,5], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 11\n\ntest_input = { \"nums\": [4,3,1], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 8\n\ntest_input = { \"nums\": [4,3,2], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 9\n\ntest_input = { \"nums\": [4,5,3], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 12\n\ntest_input = { \"nums\": [5,2,1], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 8\n\ntest_input = { \"nums\": [5,3,5], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 13\n\ntest_input = { \"nums\": [50,50,50], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 150\n\ntest_input = { \"nums\": [1,5,3,6], \"k\": 3, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 9\n\ntest_input = { \"nums\": [1,5,3,7], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 9\n\ntest_input = { \"nums\": [1,5,3,7], \"k\": 3, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 9\n\ntest_input = { \"nums\": [1,5,3,8], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 9\n\ntest_input = { \"nums\": [1,5,3,8], \"k\": 3, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 9\n\ntest_input = { \"nums\": [1,5,4,6], \"k\": 4, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 16\n\ntest_input = { \"nums\": [1,6,3,5], \"k\": 3, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 9\n\ntest_input = { \"nums\": [1,6,3,8], \"k\": 3, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 10\n\ntest_input = { \"nums\": [1,6,4,5], \"k\": 4, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 16\n\ntest_input = { \"nums\": [1,7,4,6], \"k\": 4, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 18\n\ntest_input = { \"nums\": [1,7,4,8], \"k\": 4, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 20\n\ntest_input = { \"nums\": [1,8,3,8], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 12\n\ntest_input = { \"nums\": [1,8,4,7], \"k\": 4, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 20\n\ntest_input = { \"nums\": [2,5,3,8], \"k\": 3, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 10\n\ntest_input = { \"nums\": [2,5,4,7], \"k\": 4, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 18\n\ntest_input = { \"nums\": [2,5,4,8], \"k\": 4, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 19\n\ntest_input = { \"nums\": [2,6,3,5], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 10\n\ntest_input = { \"nums\": [2,6,3,6], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 11\n\ntest_input = { \"nums\": [2,6,4,5], \"k\": 4, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 17\n\ntest_input = { \"nums\": [2,6,4,7], \"k\": 4, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 19\n\ntest_input = { \"nums\": [2,6,4,8], \"k\": 4, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 20\n\ntest_input = { \"nums\": [2,7,3,5], \"k\": 3, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 10\n\ntest_input = { \"nums\": [2,7,3,8], \"k\": 3, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 12\n\ntest_input = { \"nums\": [2,7,4,6], \"k\": 4, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 19\n\ntest_input = { \"nums\": [2,8,3,5], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 10\n\ntest_input = { \"nums\": [2,8,4,5], \"k\": 4, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 19\n\ntest_input = { \"nums\": [3,5,3,5], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 11\n\ntest_input = { \"nums\": [3,5,3,5], \"k\": 3, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 11\n\ntest_input = { \"nums\": [3,5,3,8], \"k\": 3, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 11\n\ntest_input = { \"nums\": [3,5,4,7], \"k\": 4, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 19\n\ntest_input = { \"nums\": [3,6,3,5], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 11\n\ntest_input = { \"nums\": [3,6,3,7], \"k\": 3, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 12\n\ntest_input = { \"nums\": [3,6,3,8], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 12\n\ntest_input = { \"nums\": [3,6,4,5], \"k\": 4, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 18\n\ntest_input = { \"nums\": [3,7,3,5], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 11\n\ntest_input = { \"nums\": [3,7,3,5], \"k\": 3, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 11\n\ntest_input = { \"nums\": [3,7,3,6], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 12\n\ntest_input = { \"nums\": [3,7,3,8], \"k\": 3, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 13\n\ntest_input = { \"nums\": [3,7,4,7], \"k\": 4, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 21\n\ntest_input = { \"nums\": [3,8,3,5], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 11\n\ntest_input = { \"nums\": [3,8,4,6], \"k\": 4, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 21\n\ntest_input = { \"nums\": [4,5,3,5], \"k\": 3, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 12\n\ntest_input = { \"nums\": [4,5,3,6], \"k\": 3, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 12\n\ntest_input = { \"nums\": [4,5,3,8], \"k\": 3, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 12\n\ntest_input = { \"nums\": [4,5,4,5], \"k\": 4, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 18\n\ntest_input = { \"nums\": [4,6,3,6], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 13\n\ntest_input = { \"nums\": [4,6,3,7], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 13\n\ntest_input = { \"nums\": [4,6,4,5], \"k\": 4, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 19\n\ntest_input = { \"nums\": [4,6,4,8], \"k\": 4, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 22\n\ntest_input = { \"nums\": [4,7,3,6], \"k\": 3, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 13\n\ntest_input = { \"nums\": [4,7,4,5], \"k\": 4, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 20\n\ntest_input = { \"nums\": [4,7,4,7], \"k\": 4, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 22\n\ntest_input = { \"nums\": [4,8,3,5], \"k\": 3, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 12\n\ntest_input = { \"nums\": [4,8,3,6], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 13\n\ntest_input = { \"nums\": [4,8,3,7], \"k\": 3, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 14\n\ntest_input = { \"nums\": [4,8,4,6], \"k\": 4, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 22\n\ntest_input = { \"nums\": [4,8,4,8], \"k\": 4, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 24\n\ntest_input = { \"nums\": [1,5,6,6,3,7,2], \"k\": 6, \"dist\": 5 }\nassert my_solution.minimumCost(**test_input) == 23\n\ntest_input = { \"nums\": [1,6,4,6,2,9,11], \"k\": 4, \"dist\": 3 }\nassert my_solution.minimumCost(**test_input) == 13\n\ntest_input = { \"nums\": [1,6,4,7,9,6,1], \"k\": 4, \"dist\": 4 }\nassert my_solution.minimumCost(**test_input) == 12\n\ntest_input = { \"nums\": [1,6,5,6,4,9,11], \"k\": 5, \"dist\": 5 }\nassert my_solution.minimumCost(**test_input) == 22\n\ntest_input = { \"nums\": [1,6,5,7,8,7,5], \"k\": 5, \"dist\": 4 }\nassert my_solution.minimumCost(**test_input) == 25\n\ntest_input = { \"nums\": [1,6,5,8,11,10,6], \"k\": 5, \"dist\": 3 }\nassert my_solution.minimumCost(**test_input) == 31\n\ntest_input = { \"nums\": [1,6,6,8,4,8,7], \"k\": 6, \"dist\": 4 }\nassert my_solution.minimumCost(**test_input) == 33\n\ntest_input = { \"nums\": [1,7,6,8,5,10,10], \"k\": 6, \"dist\": 5 }\nassert my_solution.minimumCost(**test_input) == 37\n\ntest_input = { \"nums\": [1,8,3,8,11,11,10], \"k\": 3, \"dist\": 5 }\nassert my_solution.minimumCost(**test_input) == 12\n\ntest_input = { \"nums\": [1,8,4,7,11,1,8], \"k\": 4, \"dist\": 4 }\nassert my_solution.minimumCost(**test_input) == 13\n\ntest_input = { \"nums\": [1,8,6,5,6,12,12], \"k\": 6, \"dist\": 5 }\nassert my_solution.minimumCost(**test_input) == 38\n\ntest_input = { \"nums\": [1,8,6,6,12,5,2], \"k\": 6, \"dist\": 5 }\nassert my_solution.minimumCost(**test_input) == 28\n\ntest_input = { \"nums\": [2,5,3,5,7,4,3], \"k\": 3, \"dist\": 3 }\nassert my_solution.minimumCost(**test_input) == 9\n\ntest_input = { \"nums\": [2,5,4,6,6,1,3], \"k\": 4, \"dist\": 5 }\nassert my_solution.minimumCost(**test_input) == 10", "start_time": 1705761000} +{"task_id": "weekly-contest-380-count-elements-with-maximum-frequency", "url": "https://leetcode.com/problems/count-elements-with-maximum-frequency", "title": "count-elements-with-maximum-frequency", "meta": {"questionId": "3242", "questionFrontendId": "3005", "title": "Count Elements With Maximum Frequency", "titleSlug": "count-elements-with-maximum-frequency", "isPaidOnly": false, "difficulty": "Easy", "likes": 47, "dislikes": 2, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个由 正整数 组成的数组 nums 。\n返回数组 nums 中所有具有 最大 频率的元素的 总频率 。\n元素的 频率 是指该元素在数组中出现的次数。\n\n示例 1:\n\n输入:nums = [1,2,2,3,1,4]\n输出:4\n解释:元素 1 和 2 的频率为 2 ,是数组中的最大频率。\n因此具有最大频率的元素在数组中的数量是 4 。\n\n示例 2:\n\n输入:nums = [1,2,3,4,5]\n输出:5\n解释:数组中的所有元素的频率都为 1 ,是最大频率。\n因此具有最大频率的元素在数组中的数量是 5 。\n\n\n提示:\n\n1 <= nums.length <= 100\n1 <= nums[i] <= 100\n\"\"\"\nclass Solution:\n def maxFrequencyElements(self, nums: List[int]) -> int:\n ", "prompt_sft": "给你一个由 正整数 组成的数组 nums 。\n返回数组 nums 中所有具有 最大 频率的元素的 总频率 。\n元素的 频率 是指该元素在数组中出现的次数。\n\n示例 1:\n\n输入:nums = [1,2,2,3,1,4]\n输出:4\n解释:元素 1 和 2 的频率为 2 ,是数组中的最大频率。\n因此具有最大频率的元素在数组中的数量是 4 。\n\n示例 2:\n\n输入:nums = [1,2,3,4,5]\n输出:5\n解释:数组中的所有元素的频率都为 1 ,是最大频率。\n因此具有最大频率的元素在数组中的数量是 5 。\n\n\n提示:\n\n1 <= nums.length <= 100\n1 <= nums[i] <= 100\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def maxFrequencyElements(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,2,2,3,1,4] }\nassert my_solution.maxFrequencyElements(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,3,4,5] }\nassert my_solution.maxFrequencyElements(**test_input) == 5\n\ntest_input = { \"nums\": [15] }\nassert my_solution.maxFrequencyElements(**test_input) == 1\n\ntest_input = { \"nums\": [10,12,11,9,6,19,11] }\nassert my_solution.maxFrequencyElements(**test_input) == 2\n\ntest_input = { \"nums\": [2,12,17,18,11] }\nassert my_solution.maxFrequencyElements(**test_input) == 5\n\ntest_input = { \"nums\": [19,19,19,20,19,8,19] }\nassert my_solution.maxFrequencyElements(**test_input) == 5\n\ntest_input = { \"nums\": [1,1,1,1] }\nassert my_solution.maxFrequencyElements(**test_input) == 4\n\ntest_input = { \"nums\": [10,1,12,10,10,19,10] }\nassert my_solution.maxFrequencyElements(**test_input) == 4\n\ntest_input = { \"nums\": [1,1,1,20,6,1] }\nassert my_solution.maxFrequencyElements(**test_input) == 4\n\ntest_input = { \"nums\": [17,17] }\nassert my_solution.maxFrequencyElements(**test_input) == 2\n\ntest_input = { \"nums\": [6,13,15,15,11,6,7,12,4,11] }\nassert my_solution.maxFrequencyElements(**test_input) == 6\n\ntest_input = { \"nums\": [1,2] }\nassert my_solution.maxFrequencyElements(**test_input) == 2\n\ntest_input = { \"nums\": [14,14,17] }\nassert my_solution.maxFrequencyElements(**test_input) == 2\n\ntest_input = { \"nums\": [17,17,2,12,20,17,12] }\nassert my_solution.maxFrequencyElements(**test_input) == 3\n\ntest_input = { \"nums\": [3,9,11,11,20] }\nassert my_solution.maxFrequencyElements(**test_input) == 2\n\ntest_input = { \"nums\": [8,15,8,11,8,13,12,11,8] }\nassert my_solution.maxFrequencyElements(**test_input) == 4\n\ntest_input = { \"nums\": [17,8,17,19,17,13,17,17,17,5] }\nassert my_solution.maxFrequencyElements(**test_input) == 6\n\ntest_input = { \"nums\": [11] }\nassert my_solution.maxFrequencyElements(**test_input) == 1\n\ntest_input = { \"nums\": [5] }\nassert my_solution.maxFrequencyElements(**test_input) == 1\n\ntest_input = { \"nums\": [4,4,10] }\nassert my_solution.maxFrequencyElements(**test_input) == 2\n\ntest_input = { \"nums\": [15,13,2,16,2,5,1,18,8,16] }\nassert my_solution.maxFrequencyElements(**test_input) == 4\n\ntest_input = { \"nums\": [1,17,12,7,17,3] }\nassert my_solution.maxFrequencyElements(**test_input) == 2\n\ntest_input = { \"nums\": [8,2,8,6,1,1] }\nassert my_solution.maxFrequencyElements(**test_input) == 4\n\ntest_input = { \"nums\": [3,9,7,9] }\nassert my_solution.maxFrequencyElements(**test_input) == 2\n\ntest_input = { \"nums\": [20,20,20,5,12,20,9,16] }\nassert my_solution.maxFrequencyElements(**test_input) == 4\n\ntest_input = { \"nums\": [2,14,3,8,16,4,4,3] }\nassert my_solution.maxFrequencyElements(**test_input) == 4\n\ntest_input = { \"nums\": [6,12,3,3,11,2] }\nassert my_solution.maxFrequencyElements(**test_input) == 2\n\ntest_input = { \"nums\": [5,2,13,19,15,20] }\nassert my_solution.maxFrequencyElements(**test_input) == 6\n\ntest_input = { \"nums\": [2,13,13] }\nassert my_solution.maxFrequencyElements(**test_input) == 2\n\ntest_input = { \"nums\": [4,5] }\nassert my_solution.maxFrequencyElements(**test_input) == 2\n\ntest_input = { \"nums\": [20,20,15,20,20,20] }\nassert my_solution.maxFrequencyElements(**test_input) == 5\n\ntest_input = { \"nums\": [16,16,16,16,1,10,16,9] }\nassert my_solution.maxFrequencyElements(**test_input) == 5\n\ntest_input = { \"nums\": [5,3,5,8,5,3,5,15] }\nassert my_solution.maxFrequencyElements(**test_input) == 4\n\ntest_input = { \"nums\": [17] }\nassert my_solution.maxFrequencyElements(**test_input) == 1\n\ntest_input = { \"nums\": [2,2,3,3,9] }\nassert my_solution.maxFrequencyElements(**test_input) == 4\n\ntest_input = { \"nums\": [5,11,4,2] }\nassert my_solution.maxFrequencyElements(**test_input) == 4\n\ntest_input = { \"nums\": [13,13,7] }\nassert my_solution.maxFrequencyElements(**test_input) == 2\n\ntest_input = { \"nums\": [2,15,10,10,10,4,13] }\nassert my_solution.maxFrequencyElements(**test_input) == 3\n\ntest_input = { \"nums\": [3,7,1] }\nassert my_solution.maxFrequencyElements(**test_input) == 3\n\ntest_input = { \"nums\": [19,6,19,19,19,19,19] }\nassert my_solution.maxFrequencyElements(**test_input) == 6\n\ntest_input = { \"nums\": [15,3,12,4,9,14,10] }\nassert my_solution.maxFrequencyElements(**test_input) == 7\n\ntest_input = { \"nums\": [1,19,12,1,12,12,1,6] }\nassert my_solution.maxFrequencyElements(**test_input) == 6\n\ntest_input = { \"nums\": [17,7,3,3,6,5,6,2] }\nassert my_solution.maxFrequencyElements(**test_input) == 4\n\ntest_input = { \"nums\": [12,4,2,9,17,14,1,12,6] }\nassert my_solution.maxFrequencyElements(**test_input) == 2\n\ntest_input = { \"nums\": [16,11] }\nassert my_solution.maxFrequencyElements(**test_input) == 2\n\ntest_input = { \"nums\": [11,11,11,11,10,11,3,11,11] }\nassert my_solution.maxFrequencyElements(**test_input) == 7\n\ntest_input = { \"nums\": [16,4,20,10,12] }\nassert my_solution.maxFrequencyElements(**test_input) == 5\n\ntest_input = { \"nums\": [3,11,3,11] }\nassert my_solution.maxFrequencyElements(**test_input) == 4\n\ntest_input = { \"nums\": [13,9,13,13,13,13,2,13] }\nassert my_solution.maxFrequencyElements(**test_input) == 6\n\ntest_input = { \"nums\": [2,8,9,4,3] }\nassert my_solution.maxFrequencyElements(**test_input) == 5\n\ntest_input = { \"nums\": [19,6,9,12,12] }\nassert my_solution.maxFrequencyElements(**test_input) == 2\n\ntest_input = { \"nums\": [20] }\nassert my_solution.maxFrequencyElements(**test_input) == 1\n\ntest_input = { \"nums\": [1,11] }\nassert my_solution.maxFrequencyElements(**test_input) == 2\n\ntest_input = { \"nums\": [6,4,7,19,20,10,13,14] }\nassert my_solution.maxFrequencyElements(**test_input) == 8\n\ntest_input = { \"nums\": [16,8,5] }\nassert my_solution.maxFrequencyElements(**test_input) == 3\n\ntest_input = { \"nums\": [15,15,4,7,15,15,15,15,15,7] }\nassert my_solution.maxFrequencyElements(**test_input) == 7\n\ntest_input = { \"nums\": [5,20] }\nassert my_solution.maxFrequencyElements(**test_input) == 2\n\ntest_input = { \"nums\": [13] }\nassert my_solution.maxFrequencyElements(**test_input) == 1\n\ntest_input = { \"nums\": [7,15,13,18,3,11,13,7,1,13] }\nassert my_solution.maxFrequencyElements(**test_input) == 3\n\ntest_input = { \"nums\": [17,5,17,5,5] }\nassert my_solution.maxFrequencyElements(**test_input) == 3\n\ntest_input = { \"nums\": [4,5,3,5] }\nassert my_solution.maxFrequencyElements(**test_input) == 2\n\ntest_input = { \"nums\": [11,2] }\nassert my_solution.maxFrequencyElements(**test_input) == 2\n\ntest_input = { \"nums\": [1,17,17,20,2,2] }\nassert my_solution.maxFrequencyElements(**test_input) == 4\n\ntest_input = { \"nums\": [2,5,2,2] }\nassert my_solution.maxFrequencyElements(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,1,3,8,1] }\nassert my_solution.maxFrequencyElements(**test_input) == 4\n\ntest_input = { \"nums\": [1,19,19,5,14,13,1,20,6] }\nassert my_solution.maxFrequencyElements(**test_input) == 4\n\ntest_input = { \"nums\": [19,12,8,20,3,1,12,17] }\nassert my_solution.maxFrequencyElements(**test_input) == 2\n\ntest_input = { \"nums\": [7,15,1,1,6,3] }\nassert my_solution.maxFrequencyElements(**test_input) == 2\n\ntest_input = { \"nums\": [8,8,8,3,8,8,3] }\nassert my_solution.maxFrequencyElements(**test_input) == 5\n\ntest_input = { \"nums\": [5,1,2,2,2,1,1] }\nassert my_solution.maxFrequencyElements(**test_input) == 6\n\ntest_input = { \"nums\": [12,13,6] }\nassert my_solution.maxFrequencyElements(**test_input) == 3\n\ntest_input = { \"nums\": [18,12,8,2,16,19] }\nassert my_solution.maxFrequencyElements(**test_input) == 6\n\ntest_input = { \"nums\": [15,10,2,18,11,14,9] }\nassert my_solution.maxFrequencyElements(**test_input) == 7\n\ntest_input = { \"nums\": [19,17,9,13,1,13] }\nassert my_solution.maxFrequencyElements(**test_input) == 2\n\ntest_input = { \"nums\": [4,12,15,1,4,4,2] }\nassert my_solution.maxFrequencyElements(**test_input) == 3\n\ntest_input = { \"nums\": [16,16,16,8] }\nassert my_solution.maxFrequencyElements(**test_input) == 3\n\ntest_input = { \"nums\": [2] }\nassert my_solution.maxFrequencyElements(**test_input) == 1\n\ntest_input = { \"nums\": [13,15,1] }\nassert my_solution.maxFrequencyElements(**test_input) == 3\n\ntest_input = { \"nums\": [10,10,5,16,17,6,18] }\nassert my_solution.maxFrequencyElements(**test_input) == 2\n\ntest_input = { \"nums\": [3,2,14,2,18,7] }\nassert my_solution.maxFrequencyElements(**test_input) == 2\n\ntest_input = { \"nums\": [16,16,3] }\nassert my_solution.maxFrequencyElements(**test_input) == 2\n\ntest_input = { \"nums\": [1,8,10,11,8,15] }\nassert my_solution.maxFrequencyElements(**test_input) == 2\n\ntest_input = { \"nums\": [8,19,2,7,5,6,3,4] }\nassert my_solution.maxFrequencyElements(**test_input) == 8\n\ntest_input = { \"nums\": [9] }\nassert my_solution.maxFrequencyElements(**test_input) == 1\n\ntest_input = { \"nums\": [13,6,13,10] }\nassert my_solution.maxFrequencyElements(**test_input) == 2\n\ntest_input = { \"nums\": [14,13,14,4,4,14] }\nassert my_solution.maxFrequencyElements(**test_input) == 3\n\ntest_input = { \"nums\": [9,9,1,9,9,1] }\nassert my_solution.maxFrequencyElements(**test_input) == 4\n\ntest_input = { \"nums\": [14,4,11,14,14,4,4] }\nassert my_solution.maxFrequencyElements(**test_input) == 6\n\ntest_input = { \"nums\": [4,20,20,4,1] }\nassert my_solution.maxFrequencyElements(**test_input) == 4\n\ntest_input = { \"nums\": [5,11,8,3,11,11,11] }\nassert my_solution.maxFrequencyElements(**test_input) == 4\n\ntest_input = { \"nums\": [3,2,18,5] }\nassert my_solution.maxFrequencyElements(**test_input) == 4\n\ntest_input = { \"nums\": [3,8,20,7,16,20,18,13] }\nassert my_solution.maxFrequencyElements(**test_input) == 2\n\ntest_input = { \"nums\": [19,9,16,4,10,3,18] }\nassert my_solution.maxFrequencyElements(**test_input) == 7\n\ntest_input = { \"nums\": [11,2,2,3,19,3,11,2,14,1] }\nassert my_solution.maxFrequencyElements(**test_input) == 3\n\ntest_input = { \"nums\": [19,14,11,7,19,1,11,2,16] }\nassert my_solution.maxFrequencyElements(**test_input) == 4\n\ntest_input = { \"nums\": [18,15,3,2,8,12,19,14,12] }\nassert my_solution.maxFrequencyElements(**test_input) == 2\n\ntest_input = { \"nums\": [5,6,11,9,5,5,5] }\nassert my_solution.maxFrequencyElements(**test_input) == 4\n\ntest_input = { \"nums\": [8,4,4,12,8,1] }\nassert my_solution.maxFrequencyElements(**test_input) == 4\n\ntest_input = { \"nums\": [9,1,9,9,3] }\nassert my_solution.maxFrequencyElements(**test_input) == 3\n\ntest_input = { \"nums\": [18] }\nassert my_solution.maxFrequencyElements(**test_input) == 1", "start_time": 1705199400} +{"task_id": "weekly-contest-380-find-beautiful-indices-in-the-given-array-i", "url": "https://leetcode.com/problems/find-beautiful-indices-in-the-given-array-i", "title": "find-beautiful-indices-in-the-given-array-i", "meta": {"questionId": "3245", "questionFrontendId": "3006", "title": "Find Beautiful Indices in the Given Array I", "titleSlug": "find-beautiful-indices-in-the-given-array-i", "isPaidOnly": false, "difficulty": "Medium", "likes": 91, "dislikes": 21, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0 开始的字符串 s 、字符串 a 、字符串 b 和一个整数 k 。\n如果下标 i 满足以下条件,则认为它是一个 美丽下标:\n\n0 <= i <= s.length - a.length\ns[i..(i + a.length - 1)] == a\n存在下标 j 使得:\n\t\n0 <= j <= s.length - b.length\ns[j..(j + b.length - 1)] == b\n|j - i| <= k\n\n\n\n以数组形式按 从小到大排序 返回美丽下标。\n\n示例 1:\n\n输入:s = \"isawsquirrelnearmysquirrelhouseohmy\", a = \"my\", b = \"squirrel\", k = 15\n输出:[16,33]\n解释:存在 2 个美丽下标:[16,33]。\n- 下标 16 是美丽下标,因为 s[16..17] == \"my\" ,且存在下标 4 ,满足 s[4..11] == \"squirrel\" 且 |16 - 4| <= 15 。\n- 下标 33 是美丽下标,因为 s[33..34] == \"my\" ,且存在下标 18 ,满足 s[18..25] == \"squirrel\" 且 |33 - 18| <= 15 。\n因此返回 [16,33] 作为结果。\n\n示例 2:\n\n输入:s = \"abcd\", a = \"a\", b = \"a\", k = 4\n输出:[0]\n解释:存在 1 个美丽下标:[0]。\n- 下标 0 是美丽下标,因为 s[0..0] == \"a\" ,且存在下标 0 ,满足 s[0..0] == \"a\" 且 |0 - 0| <= 4 。\n因此返回 [0] 作为结果。\n\n\n提示:\n\n1 <= k <= s.length <= 105\n1 <= a.length, b.length <= 10\ns、a、和 b 只包含小写英文字母。\n\"\"\"\nclass Solution:\n def beautifulIndices(self, s: str, a: str, b: str, k: int) -> List[int]:\n ", "prompt_sft": "给你一个下标从 0 开始的字符串 s 、字符串 a 、字符串 b 和一个整数 k 。\n如果下标 i 满足以下条件,则认为它是一个 美丽下标:\n\n0 <= i <= s.length - a.length\ns[i..(i + a.length - 1)] == a\n存在下标 j 使得:\n\t\n0 <= j <= s.length - b.length\ns[j..(j + b.length - 1)] == b\n|j - i| <= k\n\n\n\n以数组形式按 从小到大排序 返回美丽下标。\n\n示例 1:\n\n输入:s = \"isawsquirrelnearmysquirrelhouseohmy\", a = \"my\", b = \"squirrel\", k = 15\n输出:[16,33]\n解释:存在 2 个美丽下标:[16,33]。\n- 下标 16 是美丽下标,因为 s[16..17] == \"my\" ,且存在下标 4 ,满足 s[4..11] == \"squirrel\" 且 |16 - 4| <= 15 。\n- 下标 33 是美丽下标,因为 s[33..34] == \"my\" ,且存在下标 18 ,满足 s[18..25] == \"squirrel\" 且 |33 - 18| <= 15 。\n因此返回 [16,33] 作为结果。\n\n示例 2:\n\n输入:s = \"abcd\", a = \"a\", b = \"a\", k = 4\n输出:[0]\n解释:存在 1 个美丽下标:[0]。\n- 下标 0 是美丽下标,因为 s[0..0] == \"a\" ,且存在下标 0 ,满足 s[0..0] == \"a\" 且 |0 - 0| <= 4 。\n因此返回 [0] 作为结果。\n\n\n提示:\n\n1 <= k <= s.length <= 105\n1 <= a.length, b.length <= 10\ns、a、和 b 只包含小写英文字母。\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def beautifulIndices(self, s: str, a: str, b: str, k: int) -> List[int]:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"s\": \"isawsquirrelnearmysquirrelhouseohmy\", \"a\": \"my\", \"b\": \"squirrel\", \"k\": 15 }\nassert my_solution.beautifulIndices(**test_input) == [16,33]\n\ntest_input = { \"s\": \"abcd\", \"a\": \"a\", \"b\": \"a\", \"k\": 4 }\nassert my_solution.beautifulIndices(**test_input) == [0]\n\ntest_input = { \"s\": \"sqgrt\", \"a\": \"rt\", \"b\": \"sq\", \"k\": 3 }\nassert my_solution.beautifulIndices(**test_input) == [3]\n\ntest_input = { \"s\": \"mquz\", \"a\": \"tklr\", \"b\": \"caz\", \"k\": 4 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"wl\", \"a\": \"xjigt\", \"b\": \"wl\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"bavgoc\", \"a\": \"ba\", \"b\": \"c\", \"k\": 6 }\nassert my_solution.beautifulIndices(**test_input) == [0]\n\ntest_input = { \"s\": \"xpcp\", \"a\": \"yxnod\", \"b\": \"xpc\", \"k\": 4 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"lahhnlwx\", \"a\": \"hhnlw\", \"b\": \"ty\", \"k\": 6 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"dexgscgecd\", \"a\": \"gscge\", \"b\": \"d\", \"k\": 6 }\nassert my_solution.beautifulIndices(**test_input) == [3]\n\ntest_input = { \"s\": \"vjrao\", \"a\": \"vjr\", \"b\": \"yxpsw\", \"k\": 5 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"oo\", \"a\": \"swhup\", \"b\": \"o\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"bxlzgxc\", \"a\": \"ducf\", \"b\": \"xlzgx\", \"k\": 3 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"wetlgztzm\", \"a\": \"box\", \"b\": \"wetl\", \"k\": 4 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"ocmm\", \"a\": \"m\", \"b\": \"oc\", \"k\": 3 }\nassert my_solution.beautifulIndices(**test_input) == [2,3]\n\ntest_input = { \"s\": \"goxmox\", \"a\": \"gibs\", \"b\": \"ox\", \"k\": 6 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"kzlrqzldvy\", \"a\": \"zl\", \"b\": \"tfsr\", \"k\": 9 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"qhd\", \"a\": \"hd\", \"b\": \"od\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"bozpeh\", \"a\": \"bozp\", \"b\": \"vrjn\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"ggfsg\", \"a\": \"gfsg\", \"b\": \"g\", \"k\": 4 }\nassert my_solution.beautifulIndices(**test_input) == [1]\n\ntest_input = { \"s\": \"fape\", \"a\": \"vq\", \"b\": \"ap\", \"k\": 4 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"isitbenom\", \"a\": \"pmng\", \"b\": \"itben\", \"k\": 5 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"gw\", \"a\": \"ln\", \"b\": \"gw\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"jhu\", \"a\": \"sio\", \"b\": \"xnx\", \"k\": 3 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"elcklvcvdg\", \"a\": \"lck\", \"b\": \"e\", \"k\": 5 }\nassert my_solution.beautifulIndices(**test_input) == [1]\n\ntest_input = { \"s\": \"subsu\", \"a\": \"tdo\", \"b\": \"su\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"jqcdc\", \"a\": \"c\", \"b\": \"d\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == [2,4]\n\ntest_input = { \"s\": \"hhvc\", \"a\": \"gfwo\", \"b\": \"hh\", \"k\": 4 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"tyoq\", \"a\": \"vhjit\", \"b\": \"yoq\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"rtbp\", \"a\": \"migjb\", \"b\": \"es\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"gkkstqvl\", \"a\": \"gkkst\", \"b\": \"xszl\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"bc\", \"a\": \"spzk\", \"b\": \"wsick\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"gyalx\", \"a\": \"neet\", \"b\": \"rbhl\", \"k\": 3 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"qo\", \"a\": \"agt\", \"b\": \"xrh\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"rinzbrrr\", \"a\": \"nzb\", \"b\": \"r\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == [2]\n\ntest_input = { \"s\": \"tjly\", \"a\": \"j\", \"b\": \"n\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"frkxslnnn\", \"a\": \"rkxsl\", \"b\": \"n\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"cffczbccc\", \"a\": \"ff\", \"b\": \"c\", \"k\": 9 }\nassert my_solution.beautifulIndices(**test_input) == [1]\n\ntest_input = { \"s\": \"uiddqbeoaw\", \"a\": \"iddq\", \"b\": \"rlr\", \"k\": 6 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"fh\", \"a\": \"ywab\", \"b\": \"qcjyl\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"gdbm\", \"a\": \"gdbm\", \"b\": \"uefwm\", \"k\": 3 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"bpcwswu\", \"a\": \"zi\", \"b\": \"pcwsw\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"dh\", \"a\": \"jmcds\", \"b\": \"nytk\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"qjgckhiif\", \"a\": \"hiif\", \"b\": \"jgc\", \"k\": 4 }\nassert my_solution.beautifulIndices(**test_input) == [5]\n\ntest_input = { \"s\": \"qyixufgyk\", \"a\": \"y\", \"b\": \"ixuf\", \"k\": 5 }\nassert my_solution.beautifulIndices(**test_input) == [1,7]\n\ntest_input = { \"s\": \"wiwiwinwio\", \"a\": \"hm\", \"b\": \"wi\", \"k\": 8 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"ffnlge\", \"a\": \"bjt\", \"b\": \"pavkr\", \"k\": 6 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"rj\", \"a\": \"m\", \"b\": \"umg\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"bkgqxl\", \"a\": \"yufy\", \"b\": \"kgq\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"hhcwp\", \"a\": \"sixek\", \"b\": \"cwp\", \"k\": 4 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"czr\", \"a\": \"cz\", \"b\": \"wxxql\", \"k\": 3 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"tdbnme\", \"a\": \"t\", \"b\": \"dbnme\", \"k\": 4 }\nassert my_solution.beautifulIndices(**test_input) == [0]\n\ntest_input = { \"s\": \"px\", \"a\": \"acgz\", \"b\": \"jaxel\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"wfa\", \"a\": \"fyntx\", \"b\": \"a\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"ixfkxfld\", \"a\": \"ixfk\", \"b\": \"urkke\", \"k\": 6 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"kmjvlkjy\", \"a\": \"gll\", \"b\": \"vlk\", \"k\": 6 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"bsbsvnmvnm\", \"a\": \"vnm\", \"b\": \"bs\", \"k\": 7 }\nassert my_solution.beautifulIndices(**test_input) == [4,7]\n\ntest_input = { \"s\": \"uzqauzqw\", \"a\": \"uzq\", \"b\": \"psnso\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"fsvkche\", \"a\": \"yot\", \"b\": \"svkc\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"cwwzmfzz\", \"a\": \"fnlgc\", \"b\": \"cwwzm\", \"k\": 6 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"profguo\", \"a\": \"o\", \"b\": \"oyzje\", \"k\": 6 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"ckbdnw\", \"a\": \"djpc\", \"b\": \"ckbdn\", \"k\": 5 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"ankfahcorr\", \"a\": \"r\", \"b\": \"kfah\", \"k\": 7 }\nassert my_solution.beautifulIndices(**test_input) == [8,9]\n\ntest_input = { \"s\": \"ahjzfg\", \"a\": \"hjzf\", \"b\": \"zs\", \"k\": 6 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"eueuau\", \"a\": \"u\", \"b\": \"e\", \"k\": 3 }\nassert my_solution.beautifulIndices(**test_input) == [1,3,5]\n\ntest_input = { \"s\": \"etuwwhwljf\", \"a\": \"uwwh\", \"b\": \"efcuq\", \"k\": 3 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"vvjhgg\", \"a\": \"g\", \"b\": \"kj\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"igytmsmsgx\", \"a\": \"msmsg\", \"b\": \"gyt\", \"k\": 3 }\nassert my_solution.beautifulIndices(**test_input) == [4]\n\ntest_input = { \"s\": \"cheoeo\", \"a\": \"eo\", \"b\": \"y\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"gqzf\", \"a\": \"cgpdn\", \"b\": \"zf\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"zapqwtmx\", \"a\": \"apqwt\", \"b\": \"m\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"klxtee\", \"a\": \"e\", \"b\": \"klx\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"xa\", \"a\": \"gzsj\", \"b\": \"oooq\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"gxoxqgxoxq\", \"a\": \"gxoxq\", \"b\": \"x\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == [0,5]\n\ntest_input = { \"s\": \"lsuo\", \"a\": \"d\", \"b\": \"uo\", \"k\": 3 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"yhi\", \"a\": \"ph\", \"b\": \"yhi\", \"k\": 3 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"cj\", \"a\": \"j\", \"b\": \"em\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"clxzclxz\", \"a\": \"ge\", \"b\": \"clxz\", \"k\": 5 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"gjtcpyiniv\", \"a\": \"cpyi\", \"b\": \"hjvtq\", \"k\": 9 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"kyrvedszzo\", \"a\": \"rve\", \"b\": \"y\", \"k\": 3 }\nassert my_solution.beautifulIndices(**test_input) == [2]\n\ntest_input = { \"s\": \"makolbcrme\", \"a\": \"qlhpf\", \"b\": \"akol\", \"k\": 9 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"vgxshd\", \"a\": \"vgx\", \"b\": \"en\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"wfvxfzut\", \"a\": \"wfv\", \"b\": \"ut\", \"k\": 6 }\nassert my_solution.beautifulIndices(**test_input) == [0]\n\ntest_input = { \"s\": \"xxtxxuftxt\", \"a\": \"tx\", \"b\": \"x\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == [2,7]\n\ntest_input = { \"s\": \"cwtybs\", \"a\": \"wgfez\", \"b\": \"cwty\", \"k\": 4 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"opnkctux\", \"a\": \"op\", \"b\": \"nkctu\", \"k\": 5 }\nassert my_solution.beautifulIndices(**test_input) == [0]\n\ntest_input = { \"s\": \"swswmcsksw\", \"a\": \"mcsk\", \"b\": \"sw\", \"k\": 4 }\nassert my_solution.beautifulIndices(**test_input) == [4]\n\ntest_input = { \"s\": \"qqnb\", \"a\": \"q\", \"b\": \"q\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == [0,1]\n\ntest_input = { \"s\": \"tt\", \"a\": \"t\", \"b\": \"q\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"lllclbii\", \"a\": \"l\", \"b\": \"i\", \"k\": 7 }\nassert my_solution.beautifulIndices(**test_input) == [0,1,2,4]\n\ntest_input = { \"s\": \"oanyzue\", \"a\": \"yzu\", \"b\": \"oan\", \"k\": 5 }\nassert my_solution.beautifulIndices(**test_input) == [3]\n\ntest_input = { \"s\": \"opmfgzthj\", \"a\": \"opmf\", \"b\": \"g\", \"k\": 9 }\nassert my_solution.beautifulIndices(**test_input) == [0]\n\ntest_input = { \"s\": \"uiddidde\", \"a\": \"idd\", \"b\": \"sal\", \"k\": 7 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"gzzau\", \"a\": \"za\", \"b\": \"rwu\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"srpxqurxx\", \"a\": \"nsr\", \"b\": \"x\", \"k\": 3 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"sxaono\", \"a\": \"jy\", \"b\": \"xaon\", \"k\": 6 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"acxtjiova\", \"a\": \"acx\", \"b\": \"tjiov\", \"k\": 3 }\nassert my_solution.beautifulIndices(**test_input) == [0]\n\ntest_input = { \"s\": \"iltazkww\", \"a\": \"k\", \"b\": \"z\", \"k\": 6 }\nassert my_solution.beautifulIndices(**test_input) == [5]\n\ntest_input = { \"s\": \"ltxbhpi\", \"a\": \"cjfbb\", \"b\": \"ltxb\", \"k\": 5 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"gysgysh\", \"a\": \"gys\", \"b\": \"qzvae\", \"k\": 5 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"zypvgt\", \"a\": \"zypv\", \"b\": \"ljxni\", \"k\": 4 }\nassert my_solution.beautifulIndices(**test_input) == []", "start_time": 1705199400} +{"task_id": "weekly-contest-380-maximum-number-that-sum-of-the-prices-is-less-than-or-equal-to-k", "url": "https://leetcode.com/problems/maximum-number-that-sum-of-the-prices-is-less-than-or-equal-to-k", "title": "maximum-number-that-sum-of-the-prices-is-less-than-or-equal-to-k", "meta": {"questionId": "3240", "questionFrontendId": "3007", "title": "Maximum Number That Sum of the Prices Is Less Than or Equal to K", "titleSlug": "maximum-number-that-sum-of-the-prices-is-less-than-or-equal-to-k", "isPaidOnly": false, "difficulty": "Medium", "likes": 125, "dislikes": 74, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个整数k和一个整数x。\n令 s为整数num的下标从 1开始的二进制表示。我们说一个整数num的 价值是满足i % x == 0 且s[i]是 设置位的 i的数目。\n请你返回最大整数num,满足从 1到 num的所有整数的 价值和小于等于 k。\n注意:\n\n一个整数二进制表示下 设置位是值为 1的数位。\n一个整数的二进制表示下标从右到左编号,比方说如果s == 11100,那么s[4] == 1 且s[2] == 0。\n\n\n示例 1:\n\n输入:k = 9, x = 1\n输出:6\n解释:数字 1 ,2 ,3 ,4 ,5 和 6 二进制表示分别为 \"1\" ,\"10\" ,\"11\" ,\"100\" ,\"101\" 和 \"110\" 。\n由于 x 等于 1 ,每个数字的价值分别为所有设置位的数目。\n这些数字的所有设置位数目总数是 9 ,所以前 6 个数字的价值和为 9 。\n所以答案为 6 。\n示例 2:\n\n输入:k = 7, x = 2\n输出:9\n解释:由于 x 等于 2 ,我们检查每个数字的偶数位。\n2 和 3 在二进制表示下的第二个数位为设置位,所以它们的价值和为 2 。\n6 和 7 在二进制表示下的第二个数位为设置位,所以它们的价值和为 2 。\n8 和 9 在二进制表示下的第四个数位为设置位但第二个数位不是设置位,所以它们的价值和为 2 。\n数字 1 ,4 和 5 在二进制下偶数位都不是设置位,所以它们的价值和为 0 。\n10 在二进制表示下的第二个数位和第四个数位都是设置位,所以它的价值为 2 。\n前 9 个数字的价值和为 6 。\n前 10 个数字的价值和为 8,超过了 k = 7 ,所以答案为 9 。\n\n提示:\n\n1 <= k <= 1015\n1 <= x <= 8\n\"\"\"\nclass Solution:\n def findMaximumNumber(self, k: int, x: int) -> int:\n ", "prompt_sft": "给你一个整数k和一个整数x。\n令 s为整数num的下标从 1开始的二进制表示。我们说一个整数num的 价值是满足i % x == 0 且s[i]是 设置位的 i的数目。\n请你返回最大整数num,满足从 1到 num的所有整数的 价值和小于等于 k。\n注意:\n\n一个整数二进制表示下 设置位是值为 1的数位。\n一个整数的二进制表示下标从右到左编号,比方说如果s == 11100,那么s[4] == 1 且s[2] == 0。\n\n\n示例 1:\n\n输入:k = 9, x = 1\n输出:6\n解释:数字 1 ,2 ,3 ,4 ,5 和 6 二进制表示分别为 \"1\" ,\"10\" ,\"11\" ,\"100\" ,\"101\" 和 \"110\" 。\n由于 x 等于 1 ,每个数字的价值分别为所有设置位的数目。\n这些数字的所有设置位数目总数是 9 ,所以前 6 个数字的价值和为 9 。\n所以答案为 6 。\n示例 2:\n\n输入:k = 7, x = 2\n输出:9\n解释:由于 x 等于 2 ,我们检查每个数字的偶数位。\n2 和 3 在二进制表示下的第二个数位为设置位,所以它们的价值和为 2 。\n6 和 7 在二进制表示下的第二个数位为设置位,所以它们的价值和为 2 。\n8 和 9 在二进制表示下的第四个数位为设置位但第二个数位不是设置位,所以它们的价值和为 2 。\n数字 1 ,4 和 5 在二进制下偶数位都不是设置位,所以它们的价值和为 0 。\n10 在二进制表示下的第二个数位和第四个数位都是设置位,所以它的价值为 2 。\n前 9 个数字的价值和为 6 。\n前 10 个数字的价值和为 8,超过了 k = 7 ,所以答案为 9 。\n\n提示:\n\n1 <= k <= 1015\n1 <= x <= 8\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def findMaximumNumber(self, k: int, x: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"k\": 9, \"x\": 1 }\nassert my_solution.findMaximumNumber(**test_input) == 6\n\ntest_input = { \"k\": 7, \"x\": 2 }\nassert my_solution.findMaximumNumber(**test_input) == 9\n\ntest_input = { \"k\": 19, \"x\": 6 }\nassert my_solution.findMaximumNumber(**test_input) == 50\n\ntest_input = { \"k\": 57, \"x\": 4 }\nassert my_solution.findMaximumNumber(**test_input) == 120\n\ntest_input = { \"k\": 58, \"x\": 5 }\nassert my_solution.findMaximumNumber(**test_input) == 121\n\ntest_input = { \"k\": 60, \"x\": 8 }\nassert my_solution.findMaximumNumber(**test_input) == 187\n\ntest_input = { \"k\": 72, \"x\": 5 }\nassert my_solution.findMaximumNumber(**test_input) == 151\n\ntest_input = { \"k\": 81, \"x\": 6 }\nassert my_solution.findMaximumNumber(**test_input) == 176\n\ntest_input = { \"k\": 83, \"x\": 1 }\nassert my_solution.findMaximumNumber(**test_input) == 33\n\ntest_input = { \"k\": 83, \"x\": 7 }\nassert my_solution.findMaximumNumber(**test_input) == 210\n\ntest_input = { \"k\": 116, \"x\": 5 }\nassert my_solution.findMaximumNumber(**test_input) == 243\n\ntest_input = { \"k\": 157, \"x\": 6 }\nassert my_solution.findMaximumNumber(**test_input) == 316\n\ntest_input = { \"k\": 201, \"x\": 3 }\nassert my_solution.findMaximumNumber(**test_input) == 212\n\ntest_input = { \"k\": 268, \"x\": 6 }\nassert my_solution.findMaximumNumber(**test_input) == 555\n\ntest_input = { \"k\": 281, \"x\": 5 }\nassert my_solution.findMaximumNumber(**test_input) == 531\n\ntest_input = { \"k\": 283, \"x\": 3 }\nassert my_solution.findMaximumNumber(**test_input) == 274\n\ntest_input = { \"k\": 309, \"x\": 4 }\nassert my_solution.findMaximumNumber(**test_input) == 364\n\ntest_input = { \"k\": 363, \"x\": 7 }\nassert my_solution.findMaximumNumber(**test_input) == 746\n\ntest_input = { \"k\": 409, \"x\": 2 }\nassert my_solution.findMaximumNumber(**test_input) == 220\n\ntest_input = { \"k\": 456, \"x\": 7 }\nassert my_solution.findMaximumNumber(**test_input) == 967\n\ntest_input = { \"k\": 466, \"x\": 3 }\nassert my_solution.findMaximumNumber(**test_input) == 365\n\ntest_input = { \"k\": 500, \"x\": 3 }\nassert my_solution.findMaximumNumber(**test_input) == 379\n\ntest_input = { \"k\": 513, \"x\": 1 }\nassert my_solution.findMaximumNumber(**test_input) == 148\n\ntest_input = { \"k\": 521, \"x\": 8 }\nassert my_solution.findMaximumNumber(**test_input) == 1160\n\ntest_input = { \"k\": 540, \"x\": 4 }\nassert my_solution.findMaximumNumber(**test_input) == 571\n\ntest_input = { \"k\": 545, \"x\": 1 }\nassert my_solution.findMaximumNumber(**test_input) == 156\n\ntest_input = { \"k\": 579, \"x\": 1 }\nassert my_solution.findMaximumNumber(**test_input) == 165\n\ntest_input = { \"k\": 584, \"x\": 1 }\nassert my_solution.findMaximumNumber(**test_input) == 166\n\ntest_input = { \"k\": 589, \"x\": 3 }\nassert my_solution.findMaximumNumber(**test_input) == 427\n\ntest_input = { \"k\": 599, \"x\": 6 }\nassert my_solution.findMaximumNumber(**test_input) == 1206\n\ntest_input = { \"k\": 632, \"x\": 2 }\nassert my_solution.findMaximumNumber(**test_input) == 346\n\ntest_input = { \"k\": 692, \"x\": 3 }\nassert my_solution.findMaximumNumber(**test_input) == 481\n\ntest_input = { \"k\": 701, \"x\": 7 }\nassert my_solution.findMaximumNumber(**test_input) == 1404\n\ntest_input = { \"k\": 704, \"x\": 4 }\nassert my_solution.findMaximumNumber(**test_input) == 727\n\ntest_input = { \"k\": 731, \"x\": 7 }\nassert my_solution.findMaximumNumber(**test_input) == 1498\n\ntest_input = { \"k\": 781, \"x\": 1 }\nassert my_solution.findMaximumNumber(**test_input) == 210\n\ntest_input = { \"k\": 782, \"x\": 7 }\nassert my_solution.findMaximumNumber(**test_input) == 1613\n\ntest_input = { \"k\": 808, \"x\": 6 }\nassert my_solution.findMaximumNumber(**test_input) == 1639\n\ntest_input = { \"k\": 814, \"x\": 7 }\nassert my_solution.findMaximumNumber(**test_input) == 1645\n\ntest_input = { \"k\": 818, \"x\": 1 }\nassert my_solution.findMaximumNumber(**test_input) == 218\n\ntest_input = { \"k\": 821, \"x\": 2 }\nassert my_solution.findMaximumNumber(**test_input) == 433\n\ntest_input = { \"k\": 829, \"x\": 6 }\nassert my_solution.findMaximumNumber(**test_input) == 1660\n\ntest_input = { \"k\": 865, \"x\": 7 }\nassert my_solution.findMaximumNumber(**test_input) == 1760\n\ntest_input = { \"k\": 874, \"x\": 6 }\nassert my_solution.findMaximumNumber(**test_input) == 1769\n\ntest_input = { \"k\": 879, \"x\": 1 }\nassert my_solution.findMaximumNumber(**test_input) == 230\n\ntest_input = { \"k\": 879, \"x\": 3 }\nassert my_solution.findMaximumNumber(**test_input) == 628\n\ntest_input = { \"k\": 898, \"x\": 8 }\nassert my_solution.findMaximumNumber(**test_input) == 1921\n\ntest_input = { \"k\": 902, \"x\": 3 }\nassert my_solution.findMaximumNumber(**test_input) == 653\n\ntest_input = { \"k\": 905, \"x\": 8 }\nassert my_solution.findMaximumNumber(**test_input) == 1928\n\ntest_input = { \"k\": 937, \"x\": 8 }\nassert my_solution.findMaximumNumber(**test_input) == 1960\n\ntest_input = { \"k\": 957, \"x\": 3 }\nassert my_solution.findMaximumNumber(**test_input) == 701\n\ntest_input = { \"k\": 973, \"x\": 1 }\nassert my_solution.findMaximumNumber(**test_input) == 247\n\ntest_input = { \"k\": 978, \"x\": 3 }\nassert my_solution.findMaximumNumber(**test_input) == 737\n\ntest_input = { \"k\": 991, \"x\": 5 }\nassert my_solution.findMaximumNumber(**test_input) == 1006\n\ntest_input = { \"k\": 1029, \"x\": 3 }\nassert my_solution.findMaximumNumber(**test_input) == 771\n\ntest_input = { \"k\": 1065, \"x\": 6 }\nassert my_solution.findMaximumNumber(**test_input) == 2083\n\ntest_input = { \"k\": 1086, \"x\": 3 }\nassert my_solution.findMaximumNumber(**test_input) == 805\n\ntest_input = { \"k\": 1105, \"x\": 1 }\nassert my_solution.findMaximumNumber(**test_input) == 280\n\ntest_input = { \"k\": 1113, \"x\": 3 }\nassert my_solution.findMaximumNumber(**test_input) == 815\n\ntest_input = { \"k\": 1143, \"x\": 4 }\nassert my_solution.findMaximumNumber(**test_input) == 1190\n\ntest_input = { \"k\": 1148, \"x\": 2 }\nassert my_solution.findMaximumNumber(**test_input) == 564\n\ntest_input = { \"k\": 1150, \"x\": 7 }\nassert my_solution.findMaximumNumber(**test_input) == 2301\n\ntest_input = { \"k\": 1156, \"x\": 3 }\nassert my_solution.findMaximumNumber(**test_input) == 835\n\ntest_input = { \"k\": 1171, \"x\": 7 }\nassert my_solution.findMaximumNumber(**test_input) == 2386\n\ntest_input = { \"k\": 1172, \"x\": 1 }\nassert my_solution.findMaximumNumber(**test_input) == 297\n\ntest_input = { \"k\": 1227, \"x\": 7 }\nassert my_solution.findMaximumNumber(**test_input) == 2506\n\ntest_input = { \"k\": 1236, \"x\": 8 }\nassert my_solution.findMaximumNumber(**test_input) == 2515\n\ntest_input = { \"k\": 1270, \"x\": 5 }\nassert my_solution.findMaximumNumber(**test_input) == 1525\n\ntest_input = { \"k\": 1274, \"x\": 6 }\nassert my_solution.findMaximumNumber(**test_input) == 2220\n\ntest_input = { \"k\": 1281, \"x\": 6 }\nassert my_solution.findMaximumNumber(**test_input) == 2223\n\ntest_input = { \"k\": 1282, \"x\": 6 }\nassert my_solution.findMaximumNumber(**test_input) == 2224\n\ntest_input = { \"k\": 1288, \"x\": 5 }\nassert my_solution.findMaximumNumber(**test_input) == 1543\n\ntest_input = { \"k\": 1376, \"x\": 6 }\nassert my_solution.findMaximumNumber(**test_input) == 2287\n\ntest_input = { \"k\": 1393, \"x\": 7 }\nassert my_solution.findMaximumNumber(**test_input) == 2800\n\ntest_input = { \"k\": 1415, \"x\": 4 }\nassert my_solution.findMaximumNumber(**test_input) == 1454\n\ntest_input = { \"k\": 1446, \"x\": 7 }\nassert my_solution.findMaximumNumber(**test_input) == 2917\n\ntest_input = { \"k\": 1459, \"x\": 1 }\nassert my_solution.findMaximumNumber(**test_input) == 358\n\ntest_input = { \"k\": 1520, \"x\": 3 }\nassert my_solution.findMaximumNumber(**test_input) == 1017\n\ntest_input = { \"k\": 1539, \"x\": 6 }\nassert my_solution.findMaximumNumber(**test_input) == 2400\n\ntest_input = { \"k\": 1545, \"x\": 7 }\nassert my_solution.findMaximumNumber(**test_input) == 3144\n\ntest_input = { \"k\": 1573, \"x\": 5 }\nassert my_solution.findMaximumNumber(**test_input) == 1732\n\ntest_input = { \"k\": 1588, \"x\": 8 }\nassert my_solution.findMaximumNumber(**test_input) == 3251\n\ntest_input = { \"k\": 1590, \"x\": 7 }\nassert my_solution.findMaximumNumber(**test_input) == 3189\n\ntest_input = { \"k\": 1617, \"x\": 7 }\nassert my_solution.findMaximumNumber(**test_input) == 3280\n\ntest_input = { \"k\": 1633, \"x\": 6 }\nassert my_solution.findMaximumNumber(**test_input) == 2463\n\ntest_input = { \"k\": 1634, \"x\": 7 }\nassert my_solution.findMaximumNumber(**test_input) == 3297\n\ntest_input = { \"k\": 1687, \"x\": 2 }\nassert my_solution.findMaximumNumber(**test_input) == 741\n\ntest_input = { \"k\": 1731, \"x\": 6 }\nassert my_solution.findMaximumNumber(**test_input) == 2528\n\ntest_input = { \"k\": 1750, \"x\": 5 }\nassert my_solution.findMaximumNumber(**test_input) == 1850\n\ntest_input = { \"k\": 1751, \"x\": 7 }\nassert my_solution.findMaximumNumber(**test_input) == 3542\n\ntest_input = { \"k\": 1760, \"x\": 8 }\nassert my_solution.findMaximumNumber(**test_input) == 3551\n\ntest_input = { \"k\": 1782, \"x\": 8 }\nassert my_solution.findMaximumNumber(**test_input) == 3573\n\ntest_input = { \"k\": 1787, \"x\": 2 }\nassert my_solution.findMaximumNumber(**test_input) == 766\n\ntest_input = { \"k\": 1851, \"x\": 2 }\nassert my_solution.findMaximumNumber(**test_input) == 797\n\ntest_input = { \"k\": 1856, \"x\": 2 }\nassert my_solution.findMaximumNumber(**test_input) == 799\n\ntest_input = { \"k\": 1874, \"x\": 8 }\nassert my_solution.findMaximumNumber(**test_input) == 3793\n\ntest_input = { \"k\": 1893, \"x\": 7 }\nassert my_solution.findMaximumNumber(**test_input) == 3812\n\ntest_input = { \"k\": 1900, \"x\": 1 }\nassert my_solution.findMaximumNumber(**test_input) == 444\n\ntest_input = { \"k\": 1900, \"x\": 7 }\nassert my_solution.findMaximumNumber(**test_input) == 3819\n\ntest_input = { \"k\": 1902, \"x\": 3 }\nassert my_solution.findMaximumNumber(**test_input) == 1336", "start_time": 1705199400} +{"task_id": "weekly-contest-380-find-beautiful-indices-in-the-given-array-ii", "url": "https://leetcode.com/problems/find-beautiful-indices-in-the-given-array-ii", "title": "find-beautiful-indices-in-the-given-array-ii", "meta": {"questionId": "3303", "questionFrontendId": "3008", "title": "Find Beautiful Indices in the Given Array II", "titleSlug": "find-beautiful-indices-in-the-given-array-ii", "isPaidOnly": false, "difficulty": "Hard", "likes": 101, "dislikes": 9, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0开始的字符串s、字符串a、字符串b和一个整数k。\n如果下标 i满足以下条件,则认为它是一个 美丽下标:\n\n0 <= i <= s.length - a.length\ns[i..(i + a.length - 1)] == a\n存在下标j使得:\n\t\n0 <= j <= s.length - b.length\ns[j..(j + b.length - 1)] == b\n|j - i| <= k\n\n\n\n以数组形式按从小到大排序返回美丽下标。\n\n示例 1:\n\n输入:s = \"isawsquirrelnearmysquirrelhouseohmy\", a = \"my\", b = \"squirrel\", k = 15\n输出:[16,33]\n解释:存在 2 个美丽下标:[16,33]。\n- 下标 16 是美丽下标,因为 s[16..17] == \"my\" ,且存在下标 4 ,满足 s[4..11] == \"squirrel\" 且 |16 - 4| <= 15 。\n- 下标 33 是美丽下标,因为 s[33..34] == \"my\" ,且存在下标 18 ,满足 s[18..25] == \"squirrel\" 且 |33 - 18| <= 15 。\n因此返回 [16,33] 作为结果。\n示例 2:\n\n输入:s = \"abcd\", a = \"a\", b = \"a\", k = 4\n输出:[0]\n解释:存在 1 个美丽下标:[0]。\n- 下标 0 是美丽下标,因为 s[0..0] == \"a\" ,且存在下标 0 ,满足 s[0..0] == \"a\" 且 |0 - 0| <= 4 。\n因此返回 [0] 作为结果。\n\n提示:\n\n1 <= k <= s.length <= 5 * 105\n1 <= a.length, b.length <= 5 * 105\ns、a、和b只包含小写英文字母。\n\"\"\"\nclass Solution:\n def beautifulIndices(self, s: str, a: str, b: str, k: int) -> List[int]:\n ", "prompt_sft": "给你一个下标从 0开始的字符串s、字符串a、字符串b和一个整数k。\n如果下标 i满足以下条件,则认为它是一个 美丽下标:\n\n0 <= i <= s.length - a.length\ns[i..(i + a.length - 1)] == a\n存在下标j使得:\n\t\n0 <= j <= s.length - b.length\ns[j..(j + b.length - 1)] == b\n|j - i| <= k\n\n\n\n以数组形式按从小到大排序返回美丽下标。\n\n示例 1:\n\n输入:s = \"isawsquirrelnearmysquirrelhouseohmy\", a = \"my\", b = \"squirrel\", k = 15\n输出:[16,33]\n解释:存在 2 个美丽下标:[16,33]。\n- 下标 16 是美丽下标,因为 s[16..17] == \"my\" ,且存在下标 4 ,满足 s[4..11] == \"squirrel\" 且 |16 - 4| <= 15 。\n- 下标 33 是美丽下标,因为 s[33..34] == \"my\" ,且存在下标 18 ,满足 s[18..25] == \"squirrel\" 且 |33 - 18| <= 15 。\n因此返回 [16,33] 作为结果。\n示例 2:\n\n输入:s = \"abcd\", a = \"a\", b = \"a\", k = 4\n输出:[0]\n解释:存在 1 个美丽下标:[0]。\n- 下标 0 是美丽下标,因为 s[0..0] == \"a\" ,且存在下标 0 ,满足 s[0..0] == \"a\" 且 |0 - 0| <= 4 。\n因此返回 [0] 作为结果。\n\n提示:\n\n1 <= k <= s.length <= 5 * 105\n1 <= a.length, b.length <= 5 * 105\ns、a、和b只包含小写英文字母。\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def beautifulIndices(self, s: str, a: str, b: str, k: int) -> List[int]:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"s\": \"isawsquirrelnearmysquirrelhouseohmy\", \"a\": \"my\", \"b\": \"squirrel\", \"k\": 15 }\nassert my_solution.beautifulIndices(**test_input) == [16,33]\n\ntest_input = { \"s\": \"abcd\", \"a\": \"a\", \"b\": \"a\", \"k\": 4 }\nassert my_solution.beautifulIndices(**test_input) == [0]\n\ntest_input = { \"s\": \"a\", \"a\": \"a\", \"b\": \"a\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == [0]\n\ntest_input = { \"s\": \"aba\", \"a\": \"a\", \"b\": \"a\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == [0,2]\n\ntest_input = { \"s\": \"nvnvt\", \"a\": \"eq\", \"b\": \"nv\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"npearbvede\", \"a\": \"myqpb\", \"b\": \"pearb\", \"k\": 9 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"vatevavakz\", \"a\": \"va\", \"b\": \"lbda\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"ithhi\", \"a\": \"t\", \"b\": \"hhi\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == [1]\n\ntest_input = { \"s\": \"osuv\", \"a\": \"osuv\", \"b\": \"wrn\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"dc\", \"a\": \"dreec\", \"b\": \"dc\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"jajrfw\", \"a\": \"rf\", \"b\": \"j\", \"k\": 3 }\nassert my_solution.beautifulIndices(**test_input) == [3]\n\ntest_input = { \"s\": \"zcvx\", \"a\": \"kfdvv\", \"b\": \"tru\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"wltmqbxt\", \"a\": \"mqbxt\", \"b\": \"lt\", \"k\": 7 }\nassert my_solution.beautifulIndices(**test_input) == [3]\n\ntest_input = { \"s\": \"gggsytwgzg\", \"a\": \"sytwg\", \"b\": \"g\", \"k\": 4 }\nassert my_solution.beautifulIndices(**test_input) == [3]\n\ntest_input = { \"s\": \"diive\", \"a\": \"viw\", \"b\": \"lqqdn\", \"k\": 4 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"ss\", \"a\": \"omkdt\", \"b\": \"s\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"hfzoxcm\", \"a\": \"hfzo\", \"b\": \"ipelr\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"xllimtmil\", \"a\": \"imt\", \"b\": \"iwqx\", \"k\": 5 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"vdyl\", \"a\": \"i\", \"b\": \"ir\", \"k\": 4 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"ouwpaz\", \"a\": \"mxre\", \"b\": \"pa\", \"k\": 5 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"vlxgolxgoi\", \"a\": \"xf\", \"b\": \"lxgo\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"pnb\", \"a\": \"cx\", \"b\": \"pn\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"owhixi\", \"a\": \"hixi\", \"b\": \"anlc\", \"k\": 6 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"lrtsi\", \"a\": \"lrts\", \"b\": \"i\", \"k\": 3 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"tpyq\", \"a\": \"sa\", \"b\": \"py\", \"k\": 4 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"imxclscgz\", \"a\": \"iujc\", \"b\": \"mxcls\", \"k\": 7 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"sc\", \"a\": \"fc\", \"b\": \"th\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"tgs\", \"a\": \"ldy\", \"b\": \"tgs\", \"k\": 3 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"ssaeqzzvvg\", \"a\": \"ssa\", \"b\": \"z\", \"k\": 5 }\nassert my_solution.beautifulIndices(**test_input) == [0]\n\ntest_input = { \"s\": \"zchdy\", \"a\": \"zch\", \"b\": \"dm\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"youob\", \"a\": \"y\", \"b\": \"o\", \"k\": 5 }\nassert my_solution.beautifulIndices(**test_input) == [0]\n\ntest_input = { \"s\": \"snwj\", \"a\": \"snwj\", \"b\": \"ry\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"rneq\", \"a\": \"ynprc\", \"b\": \"yts\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"vxqf\", \"a\": \"tcnzs\", \"b\": \"qf\", \"k\": 4 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"avnzbrpb\", \"a\": \"yzfgy\", \"b\": \"cfri\", \"k\": 5 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"de\", \"a\": \"segs\", \"b\": \"bvdhs\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"ulgzs\", \"a\": \"eiib\", \"b\": \"ulgz\", \"k\": 4 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"tw\", \"a\": \"ypf\", \"b\": \"svl\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"sotqbvds\", \"a\": \"uoj\", \"b\": \"s\", \"k\": 6 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"oexy\", \"a\": \"e\", \"b\": \"a\", \"k\": 3 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"sywgismky\", \"a\": \"sywgi\", \"b\": \"t\", \"k\": 4 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"onwawarwa\", \"a\": \"wa\", \"b\": \"r\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == [4,7]\n\ntest_input = { \"s\": \"xpuldtpxpu\", \"a\": \"vkhl\", \"b\": \"xpu\", \"k\": 5 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"dg\", \"a\": \"amhb\", \"b\": \"aqwcf\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"spro\", \"a\": \"spro\", \"b\": \"lytwu\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"gfjuakm\", \"a\": \"fj\", \"b\": \"jytnd\", \"k\": 5 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"so\", \"a\": \"kkhvu\", \"b\": \"rukp\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"zwedfgnra\", \"a\": \"dfgn\", \"b\": \"zwe\", \"k\": 9 }\nassert my_solution.beautifulIndices(**test_input) == [3]\n\ntest_input = { \"s\": \"nipetnupg\", \"a\": \"n\", \"b\": \"ipet\", \"k\": 7 }\nassert my_solution.beautifulIndices(**test_input) == [0,5]\n\ntest_input = { \"s\": \"xckrhkrnfe\", \"a\": \"xc\", \"b\": \"kr\", \"k\": 9 }\nassert my_solution.beautifulIndices(**test_input) == [0]\n\ntest_input = { \"s\": \"xibrjp\", \"a\": \"ibr\", \"b\": \"bpfuf\", \"k\": 6 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"cj\", \"a\": \"x\", \"b\": \"dea\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"xfejay\", \"a\": \"xfej\", \"b\": \"koc\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"ijkqk\", \"a\": \"nzxwn\", \"b\": \"vqk\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"dqa\", \"a\": \"qj\", \"b\": \"norvy\", \"k\": 3 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"vbgvuo\", \"a\": \"u\", \"b\": \"rewjx\", \"k\": 4 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"uw\", \"a\": \"flap\", \"b\": \"lowqe\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"xoi\", \"a\": \"vefut\", \"b\": \"x\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"qzfsogwd\", \"a\": \"qzfs\", \"b\": \"txsdv\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"yalimlim\", \"a\": \"lim\", \"b\": \"bwi\", \"k\": 8 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"mjvosrhrip\", \"a\": \"jzz\", \"b\": \"vo\", \"k\": 4 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"dyswswiz\", \"a\": \"tib\", \"b\": \"dysws\", \"k\": 7 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"ftyhkld\", \"a\": \"tyh\", \"b\": \"znru\", \"k\": 5 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"adubkehe\", \"a\": \"kdtxl\", \"b\": \"dubke\", \"k\": 7 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"svpbvld\", \"a\": \"d\", \"b\": \"svpbv\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"rmiwdb\", \"a\": \"rmiw\", \"b\": \"xgwcv\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"arikarikox\", \"a\": \"o\", \"b\": \"arik\", \"k\": 8 }\nassert my_solution.beautifulIndices(**test_input) == [8]\n\ntest_input = { \"s\": \"cigzky\", \"a\": \"cigz\", \"b\": \"tu\", \"k\": 5 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"hjlllm\", \"a\": \"l\", \"b\": \"h\", \"k\": 6 }\nassert my_solution.beautifulIndices(**test_input) == [2,3,4]\n\ntest_input = { \"s\": \"xiyebjzdbv\", \"a\": \"iqku\", \"b\": \"yebjz\", \"k\": 5 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"qrmogc\", \"a\": \"g\", \"b\": \"rm\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"lagopphhnl\", \"a\": \"gopph\", \"b\": \"hnl\", \"k\": 8 }\nassert my_solution.beautifulIndices(**test_input) == [2]\n\ntest_input = { \"s\": \"xkggxk\", \"a\": \"xk\", \"b\": \"g\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == [0,4]\n\ntest_input = { \"s\": \"cdvr\", \"a\": \"iemxd\", \"b\": \"dt\", \"k\": 4 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"swuaumom\", \"a\": \"swuau\", \"b\": \"m\", \"k\": 8 }\nassert my_solution.beautifulIndices(**test_input) == [0]\n\ntest_input = { \"s\": \"qftqft\", \"a\": \"o\", \"b\": \"qft\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"bc\", \"a\": \"ucfx\", \"b\": \"lzgx\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"egzttzmtot\", \"a\": \"boxwe\", \"b\": \"t\", \"k\": 9 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"agbx\", \"a\": \"a\", \"b\": \"tw\", \"k\": 3 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"fkm\", \"a\": \"gu\", \"b\": \"fkm\", \"k\": 3 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"lt\", \"a\": \"z\", \"b\": \"lt\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"qkddvykd\", \"a\": \"kd\", \"b\": \"tprs\", \"k\": 8 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"vndnqdehvr\", \"a\": \"dnqd\", \"b\": \"ybboz\", \"k\": 8 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"lpnltfewly\", \"a\": \"few\", \"b\": \"l\", \"k\": 6 }\nassert my_solution.beautifulIndices(**test_input) == [5]\n\ntest_input = { \"s\": \"lgioimioim\", \"a\": \"imsfs\", \"b\": \"ioim\", \"k\": 10 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"jhucel\", \"a\": \"iox\", \"b\": \"nx\", \"k\": 5 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"vdgtlvls\", \"a\": \"lvl\", \"b\": \"cu\", \"k\": 4 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"buyryryrjq\", \"a\": \"yr\", \"b\": \"u\", \"k\": 9 }\nassert my_solution.beautifulIndices(**test_input) == [2,4,6]\n\ntest_input = { \"s\": \"fwohvc\", \"a\": \"agagg\", \"b\": \"fwoh\", \"k\": 4 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"tjityoib\", \"a\": \"vh\", \"b\": \"jityo\", \"k\": 3 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"tssjrbpsck\", \"a\": \"ssjr\", \"b\": \"sc\", \"k\": 10 }\nassert my_solution.beautifulIndices(**test_input) == [1]\n\ntest_input = { \"s\": \"aqxv\", \"a\": \"t\", \"b\": \"x\", \"k\": 4 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"zw\", \"a\": \"l\", \"b\": \"c\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"cbccekck\", \"a\": \"c\", \"b\": \"k\", \"k\": 6 }\nassert my_solution.beautifulIndices(**test_input) == [0,2,3,6]\n\ntest_input = { \"s\": \"angkytf\", \"a\": \"ngk\", \"b\": \"ytf\", \"k\": 7 }\nassert my_solution.beautifulIndices(**test_input) == [1]\n\ntest_input = { \"s\": \"oloxjjjqj\", \"a\": \"olox\", \"b\": \"j\", \"k\": 7 }\nassert my_solution.beautifulIndices(**test_input) == [0]\n\ntest_input = { \"s\": \"zbriomnn\", \"a\": \"omn\", \"b\": \"zbr\", \"k\": 6 }\nassert my_solution.beautifulIndices(**test_input) == [4]\n\ntest_input = { \"s\": \"ydmlx\", \"a\": \"tu\", \"b\": \"dml\", \"k\": 5 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"lnoffflno\", \"a\": \"lno\", \"b\": \"f\", \"k\": 3 }\nassert my_solution.beautifulIndices(**test_input) == [0,6]\n\ntest_input = { \"s\": \"hwayzb\", \"a\": \"fc\", \"b\": \"hway\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []", "start_time": 1705199400} +{"task_id": "weekly-contest-379-maximum-area-of-longest-diagonal-rectangle", "url": "https://leetcode.com/problems/maximum-area-of-longest-diagonal-rectangle", "title": "maximum-area-of-longest-diagonal-rectangle", "meta": {"questionId": "3251", "questionFrontendId": "10035", "title": "Maximum Area of Longest Diagonal Rectangle", "titleSlug": "maximum-area-of-longest-diagonal-rectangle", "isPaidOnly": false, "difficulty": "Easy", "likes": 38, "dislikes": 7, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0 开始的二维整数数组 dimensions。\n对于所有下标 i(0 <= i < dimensions.length),dimensions[i][0] 表示矩形 i 的长度,而 dimensions[i][1] 表示矩形 i 的宽度。\n返回对角线最 长 的矩形的 面积 。如果存在多个对角线长度相同的矩形,返回面积最 大 的矩形的面积。\n\n示例 1:\n\n输入:dimensions = [[9,3],[8,6]]\n输出:48\n解释:\n下标 = 0,长度 = 9,宽度 = 3。对角线长度 = sqrt(9 * 9 + 3 * 3) = sqrt(90) ≈ 9.487。\n下标 = 1,长度 = 8,宽度 = 6。对角线长度 = sqrt(8 * 8 + 6 * 6) = sqrt(100) = 10。\n因此,下标为 1 的矩形对角线更长,所以返回面积 = 8 * 6 = 48。\n\n示例 2:\n\n输入:dimensions = [[3,4],[4,3]]\n输出:12\n解释:两个矩形的对角线长度相同,为 5,所以最大面积 = 12。\n\n\n提示:\n\n1 <= dimensions.length <= 100\ndimensions[i].length == 2\n1 <= dimensions[i][0], dimensions[i][1] <= 100\n\"\"\"\nclass Solution:\n def areaOfMaxDiagonal(self, dimensions: List[List[int]]) -> int:\n ", "prompt_sft": "给你一个下标从 0 开始的二维整数数组 dimensions。\n对于所有下标 i(0 <= i < dimensions.length),dimensions[i][0] 表示矩形 i 的长度,而 dimensions[i][1] 表示矩形 i 的宽度。\n返回对角线最 长 的矩形的 面积 。如果存在多个对角线长度相同的矩形,返回面积最 大 的矩形的面积。\n\n示例 1:\n\n输入:dimensions = [[9,3],[8,6]]\n输出:48\n解释:\n下标 = 0,长度 = 9,宽度 = 3。对角线长度 = sqrt(9 * 9 + 3 * 3) = sqrt(90) ≈ 9.487。\n下标 = 1,长度 = 8,宽度 = 6。对角线长度 = sqrt(8 * 8 + 6 * 6) = sqrt(100) = 10。\n因此,下标为 1 的矩形对角线更长,所以返回面积 = 8 * 6 = 48。\n\n示例 2:\n\n输入:dimensions = [[3,4],[4,3]]\n输出:12\n解释:两个矩形的对角线长度相同,为 5,所以最大面积 = 12。\n\n\n提示:\n\n1 <= dimensions.length <= 100\ndimensions[i].length == 2\n1 <= dimensions[i][0], dimensions[i][1] <= 100\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def areaOfMaxDiagonal(self, dimensions: List[List[int]]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"dimensions\": [[9,3],[8,6]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 48\n\ntest_input = { \"dimensions\": [[3,4],[4,3]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 12\n\ntest_input = { \"dimensions\": [[4,10],[4,9],[9,3],[10,8]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 80\n\ntest_input = { \"dimensions\": [[2,6],[5,1],[3,10],[8,4]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 30\n\ntest_input = { \"dimensions\": [[3,7],[2,10],[3,4],[9,9],[5,10]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 81\n\ntest_input = { \"dimensions\": [[10,4]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 40\n\ntest_input = { \"dimensions\": [[9,9],[1,8],[10,5],[2,8],[6,3],[7,1]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 81\n\ntest_input = { \"dimensions\": [[10,3],[5,9],[8,3]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 30\n\ntest_input = { \"dimensions\": [[2,7],[3,2],[3,3],[10,4],[5,3],[8,10],[8,8],[4,7]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 80\n\ntest_input = { \"dimensions\": [[1,10],[3,10],[4,4],[2,6],[6,3],[6,4],[9,1],[6,1],[2,3]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 30\n\ntest_input = { \"dimensions\": [[4,7],[10,10],[3,7],[9,1],[5,7],[3,9],[10,4],[4,8]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 100\n\ntest_input = { \"dimensions\": [[1,1],[6,8],[6,9],[7,2],[6,8],[1,3],[3,1],[1,9]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 54\n\ntest_input = { \"dimensions\": [[6,6],[1,3],[8,10],[10,1],[3,10],[7,7],[10,8]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 80\n\ntest_input = { \"dimensions\": [[6,5],[8,6],[2,10],[8,1],[9,2],[3,5],[3,5]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 20\n\ntest_input = { \"dimensions\": [[5,1],[4,9],[9,1],[5,8],[2,9],[3,2],[10,10],[5,2]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 100\n\ntest_input = { \"dimensions\": [[8,3],[9,10],[7,7],[6,5],[6,9],[9,10],[5,10]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 90\n\ntest_input = { \"dimensions\": [[6,10],[8,6],[10,1],[7,10],[10,10],[9,5]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 100\n\ntest_input = { \"dimensions\": [[9,5],[9,2],[2,2],[8,9],[5,7],[8,10],[3,5]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 80\n\ntest_input = { \"dimensions\": [[3,9],[9,5]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 45\n\ntest_input = { \"dimensions\": [[10,10],[5,5],[3,2],[2,6],[3,1],[10,7],[4,8],[7,9],[9,9],[1,2]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 100\n\ntest_input = { \"dimensions\": [[2,3],[3,5],[2,1]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 15\n\ntest_input = { \"dimensions\": [[4,4],[7,7]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 49\n\ntest_input = { \"dimensions\": [[7,5],[9,6],[9,4],[5,7],[2,6],[10,3],[9,9],[9,4],[8,2]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 81\n\ntest_input = { \"dimensions\": [[5,1],[9,1],[7,1],[7,1],[3,1],[10,7],[9,1],[7,2],[4,6],[3,6]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 70\n\ntest_input = { \"dimensions\": [[8,4],[7,4],[1,5],[7,8],[5,6],[5,2]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 56\n\ntest_input = { \"dimensions\": [[5,10],[3,7],[8,6],[8,6],[5,9],[10,5],[7,8],[1,9],[2,5],[6,6]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 50\n\ntest_input = { \"dimensions\": [[9,4]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 36\n\ntest_input = { \"dimensions\": [[7,6],[2,8],[9,6],[1,10],[5,1]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 54\n\ntest_input = { \"dimensions\": [[4,2],[1,6],[2,1],[4,10],[10,1],[7,5],[8,3]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 40\n\ntest_input = { \"dimensions\": [[1,4]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 4\n\ntest_input = { \"dimensions\": [[9,4],[6,7]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 36\n\ntest_input = { \"dimensions\": [[7,5]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 35\n\ntest_input = { \"dimensions\": [[1,9],[9,7],[8,4],[6,6],[7,8],[4,6],[7,4],[9,9],[9,8],[8,8]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 81\n\ntest_input = { \"dimensions\": [[3,8],[6,3],[5,2],[3,7],[1,3],[9,8],[4,2],[3,8]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 72\n\ntest_input = { \"dimensions\": [[5,4],[2,4],[8,5],[8,4],[1,2],[6,4]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 40\n\ntest_input = { \"dimensions\": [[7,2],[4,6]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 14\n\ntest_input = { \"dimensions\": [[8,10],[5,2],[4,9]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 80\n\ntest_input = { \"dimensions\": [[9,2],[5,6],[4,2]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 18\n\ntest_input = { \"dimensions\": [[3,8],[2,9],[7,7],[1,5],[1,1]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 49\n\ntest_input = { \"dimensions\": [[6,2],[8,2],[6,8],[7,6],[1,2],[6,8],[10,9],[2,8]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 90\n\ntest_input = { \"dimensions\": [[3,8],[4,1],[5,2],[2,6],[4,9],[10,6],[6,10],[3,4],[6,6],[4,3]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 60\n\ntest_input = { \"dimensions\": [[5,5],[3,8],[2,8]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 24\n\ntest_input = { \"dimensions\": [[8,1],[5,8],[3,8]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 40\n\ntest_input = { \"dimensions\": [[2,8],[8,1],[7,10],[5,7],[2,4],[3,10],[2,10],[7,10],[5,6]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 70\n\ntest_input = { \"dimensions\": [[3,10],[1,3],[10,5],[5,9]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 50\n\ntest_input = { \"dimensions\": [[10,6],[4,3]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 60\n\ntest_input = { \"dimensions\": [[7,8],[8,6],[10,10],[6,7],[7,10]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 100\n\ntest_input = { \"dimensions\": [[7,2],[7,3],[4,6],[4,4],[7,8],[2,4]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 56\n\ntest_input = { \"dimensions\": [[4,7],[3,1],[1,10],[4,2],[4,10],[8,8]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 64\n\ntest_input = { \"dimensions\": [[1,8],[4,3],[7,7],[10,6],[5,5],[1,3],[9,1],[8,3],[3,2],[5,8]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 60\n\ntest_input = { \"dimensions\": [[6,7],[1,7],[5,10],[10,1],[8,3]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 50\n\ntest_input = { \"dimensions\": [[3,5],[2,7],[4,4],[4,9],[7,6],[2,4],[5,2]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 36\n\ntest_input = { \"dimensions\": [[8,8],[6,10],[6,6]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 60\n\ntest_input = { \"dimensions\": [[10,2],[3,3],[5,9],[3,7]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 45\n\ntest_input = { \"dimensions\": [[4,3],[4,1],[8,9],[10,1],[2,7],[7,7],[9,3],[8,6],[1,5],[8,3]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 72\n\ntest_input = { \"dimensions\": [[6,8],[2,3],[4,9],[1,1]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 48\n\ntest_input = { \"dimensions\": [[1,6],[2,10],[1,5],[9,3],[9,1],[2,2]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 20\n\ntest_input = { \"dimensions\": [[6,5],[7,10],[1,2],[10,3],[4,2],[4,8],[5,10],[5,9]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 70\n\ntest_input = { \"dimensions\": [[1,2],[1,2],[2,4],[9,9],[3,8],[3,9],[2,3]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 81\n\ntest_input = { \"dimensions\": [[4,4],[6,1],[1,10],[10,7],[10,5]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 70\n\ntest_input = { \"dimensions\": [[3,2],[2,8],[10,9],[9,8],[2,2],[9,1]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 90\n\ntest_input = { \"dimensions\": [[4,10],[9,6],[4,10],[6,7],[2,3],[7,9],[9,2],[1,9]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 63\n\ntest_input = { \"dimensions\": [[7,4],[10,2],[10,8],[4,9],[4,9],[10,3],[5,4],[4,5],[10,6],[3,9]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 80\n\ntest_input = { \"dimensions\": [[2,5],[7,4],[5,3],[2,4],[3,10],[3,5],[4,5],[4,4],[6,5]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 30\n\ntest_input = { \"dimensions\": [[3,2],[7,10],[8,10],[7,4],[6,1]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 80\n\ntest_input = { \"dimensions\": [[3,8],[4,5],[3,8]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 24\n\ntest_input = { \"dimensions\": [[6,8],[9,9],[1,7]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 81\n\ntest_input = { \"dimensions\": [[8,1],[7,5]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 35\n\ntest_input = { \"dimensions\": [[10,6],[5,1],[9,5],[5,7],[5,8],[6,5],[8,3]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 60\n\ntest_input = { \"dimensions\": [[8,6]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 48\n\ntest_input = { \"dimensions\": [[5,2],[5,9],[9,5],[5,5],[8,6]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 45\n\ntest_input = { \"dimensions\": [[7,8],[9,9],[3,5],[8,1],[1,3],[8,2],[8,6]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 81\n\ntest_input = { \"dimensions\": [[3,10],[6,8],[4,5],[8,1],[7,2],[9,8],[3,7],[3,3],[9,10]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 90\n\ntest_input = { \"dimensions\": [[1,1],[8,7],[4,6],[5,2],[5,9]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 56\n\ntest_input = { \"dimensions\": [[6,2],[8,4],[8,6],[2,10],[6,1],[9,8],[10,8],[10,10],[5,9]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 100\n\ntest_input = { \"dimensions\": [[10,2],[9,7],[4,2],[8,6],[9,10],[10,7],[7,5],[5,10],[5,9]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 90\n\ntest_input = { \"dimensions\": [[1,4],[7,2],[2,6],[7,7]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 49\n\ntest_input = { \"dimensions\": [[2,5],[10,10],[4,4]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 100\n\ntest_input = { \"dimensions\": [[2,10],[10,4],[3,9],[6,10],[2,10],[10,1],[4,1]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 60\n\ntest_input = { \"dimensions\": [[3,6],[5,4],[9,5],[6,2],[4,4],[7,2],[6,7]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 45\n\ntest_input = { \"dimensions\": [[1,1],[1,7]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 7\n\ntest_input = { \"dimensions\": [[1,2],[8,8]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 64\n\ntest_input = { \"dimensions\": [[3,7]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 21\n\ntest_input = { \"dimensions\": [[6,7],[1,5],[10,9],[10,2]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 90\n\ntest_input = { \"dimensions\": [[7,8]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 56\n\ntest_input = { \"dimensions\": [[2,6],[10,3],[10,5],[1,9],[5,2],[9,10],[7,2],[7,7],[1,10]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 90\n\ntest_input = { \"dimensions\": [[3,4],[8,2],[9,3],[2,9],[6,5],[10,5],[4,1],[8,7],[3,9]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 50\n\ntest_input = { \"dimensions\": [[7,6],[6,8],[5,7],[1,1],[4,5],[6,10],[9,3],[4,4]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 60\n\ntest_input = { \"dimensions\": [[1,3],[2,4],[4,9],[10,9],[3,9],[7,5],[2,3],[10,7],[2,3],[1,5]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 90\n\ntest_input = { \"dimensions\": [[1,8],[6,10],[4,8],[3,8],[4,3]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 60\n\ntest_input = { \"dimensions\": [[6,5],[3,10],[8,7],[10,10],[2,8],[5,8],[10,8],[9,10],[2,8],[8,9]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 100\n\ntest_input = { \"dimensions\": [[1,6],[8,3],[6,1],[2,10],[2,5],[3,8]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 20\n\ntest_input = { \"dimensions\": [[7,2],[3,8],[10,10],[7,1],[6,8],[6,7],[10,6],[4,6],[5,7],[10,4]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 100\n\ntest_input = { \"dimensions\": [[9,6]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 54\n\ntest_input = { \"dimensions\": [[8,2],[7,6],[1,4],[1,6],[4,8],[10,9],[9,4],[1,5]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 90\n\ntest_input = { \"dimensions\": [[7,3],[2,5],[7,1],[10,7],[7,4],[8,1]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 70\n\ntest_input = { \"dimensions\": [[9,2]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 18\n\ntest_input = { \"dimensions\": [[9,2],[7,2],[2,7]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 18\n\ntest_input = { \"dimensions\": [[2,8],[10,6],[8,10],[9,9]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 80\n\ntest_input = { \"dimensions\": [[3,3]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 9", "start_time": 1704594600} +{"task_id": "weekly-contest-379-minimum-moves-to-capture-the-queen", "url": "https://leetcode.com/problems/minimum-moves-to-capture-the-queen", "title": "minimum-moves-to-capture-the-queen", "meta": {"questionId": "3270", "questionFrontendId": "10036", "title": "Minimum Moves to Capture The Queen", "titleSlug": "minimum-moves-to-capture-the-queen", "isPaidOnly": false, "difficulty": "Medium", "likes": 71, "dislikes": 115, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n现有一个下标从 0 开始的 8 x 8 棋盘,上面有 3 枚棋子。\n给你 6 个整数 a 、b 、c 、d 、e 和 f ,其中:\n\n(a, b) 表示白色车的位置。\n(c, d) 表示白色象的位置。\n(e, f) 表示黑皇后的位置。\n\n假定你只能移动白色棋子,返回捕获黑皇后所需的最少移动次数。\n请注意:\n\n车可以向垂直或水平方向移动任意数量的格子,但不能跳过其他棋子。\n象可以沿对角线方向移动任意数量的格子,但不能跳过其他棋子。\n如果车或象能移向皇后所在的格子,则认为它们可以捕获皇后。\n皇后不能移动。\n\n\n示例 1:\n\n\n输入:a = 1, b = 1, c = 8, d = 8, e = 2, f = 3\n输出:2\n解释:将白色车先移动到 (1, 3) ,然后移动到 (2, 3) 来捕获黑皇后,共需移动 2 次。\n由于起始时没有任何棋子正在攻击黑皇后,要想捕获黑皇后,移动次数不可能少于 2 次。\n\n示例 2:\n\n\n输入:a = 5, b = 3, c = 3, d = 4, e = 5, f = 2\n输出:1\n解释:可以通过以下任一方式移动 1 次捕获黑皇后:\n- 将白色车移动到 (5, 2) 。\n- 将白色象移动到 (5, 2) 。\n\n\n提示:\n\n1 <= a, b, c, d, e, f <= 8\n两枚棋子不会同时出现在同一个格子上。\n\"\"\"\nclass Solution:\n def minMovesToCaptureTheQueen(self, a: int, b: int, c: int, d: int, e: int, f: int) -> int:\n ", "prompt_sft": "现有一个下标从 0 开始的 8 x 8 棋盘,上面有 3 枚棋子。\n给你 6 个整数 a 、b 、c 、d 、e 和 f ,其中:\n\n(a, b) 表示白色车的位置。\n(c, d) 表示白色象的位置。\n(e, f) 表示黑皇后的位置。\n\n假定你只能移动白色棋子,返回捕获黑皇后所需的最少移动次数。\n请注意:\n\n车可以向垂直或水平方向移动任意数量的格子,但不能跳过其他棋子。\n象可以沿对角线方向移动任意数量的格子,但不能跳过其他棋子。\n如果车或象能移向皇后所在的格子,则认为它们可以捕获皇后。\n皇后不能移动。\n\n\n示例 1:\n\n\n输入:a = 1, b = 1, c = 8, d = 8, e = 2, f = 3\n输出:2\n解释:将白色车先移动到 (1, 3) ,然后移动到 (2, 3) 来捕获黑皇后,共需移动 2 次。\n由于起始时没有任何棋子正在攻击黑皇后,要想捕获黑皇后,移动次数不可能少于 2 次。\n\n示例 2:\n\n\n输入:a = 5, b = 3, c = 3, d = 4, e = 5, f = 2\n输出:1\n解释:可以通过以下任一方式移动 1 次捕获黑皇后:\n- 将白色车移动到 (5, 2) 。\n- 将白色象移动到 (5, 2) 。\n\n\n提示:\n\n1 <= a, b, c, d, e, f <= 8\n两枚棋子不会同时出现在同一个格子上。\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def minMovesToCaptureTheQueen(self, a: int, b: int, c: int, d: int, e: int, f: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"a\": 1, \"b\": 1, \"c\": 8, \"d\": 8, \"e\": 2, \"f\": 3 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 5, \"b\": 3, \"c\": 3, \"d\": 4, \"e\": 5, \"f\": 2 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 4, \"b\": 3, \"c\": 3, \"d\": 4, \"e\": 5, \"f\": 2 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 1, \"b\": 1, \"c\": 1, \"d\": 4, \"e\": 1, \"f\": 8 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 4, \"b\": 3, \"c\": 3, \"d\": 4, \"e\": 2, \"f\": 5 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 8, \"b\": 4, \"c\": 7, \"d\": 5, \"e\": 5, \"f\": 5 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 1, \"b\": 8, \"c\": 4, \"d\": 3, \"e\": 2, \"f\": 7 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 1, \"b\": 6, \"c\": 3, \"d\": 3, \"e\": 5, \"f\": 6 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 5, \"b\": 3, \"c\": 6, \"d\": 6, \"e\": 6, \"f\": 4 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 5, \"b\": 1, \"c\": 6, \"d\": 6, \"e\": 2, \"f\": 7 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 8, \"b\": 4, \"c\": 8, \"d\": 8, \"e\": 7, \"f\": 7 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 5, \"b\": 1, \"c\": 6, \"d\": 5, \"e\": 3, \"f\": 7 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 5, \"b\": 2, \"c\": 8, \"d\": 6, \"e\": 7, \"f\": 4 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 1, \"b\": 1, \"c\": 8, \"d\": 2, \"e\": 4, \"f\": 1 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 3, \"b\": 1, \"c\": 1, \"d\": 1, \"e\": 2, \"f\": 5 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 8, \"b\": 5, \"c\": 2, \"d\": 4, \"e\": 5, \"f\": 7 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 8, \"b\": 1, \"c\": 5, \"d\": 8, \"e\": 1, \"f\": 7 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 4, \"b\": 6, \"c\": 6, \"d\": 2, \"e\": 1, \"f\": 4 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 7, \"b\": 5, \"c\": 7, \"d\": 6, \"e\": 2, \"f\": 8 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 8, \"b\": 6, \"c\": 3, \"d\": 2, \"e\": 6, \"f\": 8 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 3, \"b\": 3, \"c\": 8, \"d\": 1, \"e\": 2, \"f\": 5 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 4, \"b\": 5, \"c\": 6, \"d\": 1, \"e\": 4, \"f\": 7 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 7, \"b\": 2, \"c\": 2, \"d\": 8, \"e\": 7, \"f\": 3 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 3, \"b\": 8, \"c\": 2, \"d\": 7, \"e\": 1, \"f\": 4 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 3, \"b\": 5, \"c\": 5, \"d\": 3, \"e\": 1, \"f\": 8 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 2, \"b\": 2, \"c\": 7, \"d\": 4, \"e\": 3, \"f\": 1 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 4, \"b\": 3, \"c\": 1, \"d\": 5, \"e\": 5, \"f\": 3 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 7, \"b\": 5, \"c\": 2, \"d\": 5, \"e\": 6, \"f\": 3 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 1, \"b\": 7, \"c\": 8, \"d\": 1, \"e\": 3, \"f\": 4 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 8, \"b\": 6, \"c\": 6, \"d\": 4, \"e\": 1, \"f\": 2 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 7, \"b\": 8, \"c\": 4, \"d\": 4, \"e\": 3, \"f\": 6 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 8, \"b\": 4, \"c\": 7, \"d\": 7, \"e\": 4, \"f\": 4 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 5, \"b\": 7, \"c\": 4, \"d\": 2, \"e\": 3, \"f\": 8 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 6, \"b\": 1, \"c\": 7, \"d\": 8, \"e\": 8, \"f\": 7 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 3, \"b\": 7, \"c\": 7, \"d\": 6, \"e\": 7, \"f\": 4 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 7, \"b\": 3, \"c\": 6, \"d\": 4, \"e\": 6, \"f\": 7 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 5, \"b\": 7, \"c\": 1, \"d\": 1, \"e\": 5, \"f\": 6 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 6, \"b\": 8, \"c\": 5, \"d\": 8, \"e\": 5, \"f\": 3 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 4, \"b\": 2, \"c\": 3, \"d\": 7, \"e\": 6, \"f\": 1 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 3, \"b\": 2, \"c\": 6, \"d\": 1, \"e\": 6, \"f\": 2 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 5, \"b\": 4, \"c\": 6, \"d\": 7, \"e\": 1, \"f\": 8 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 7, \"b\": 6, \"c\": 2, \"d\": 3, \"e\": 3, \"f\": 4 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 7, \"b\": 6, \"c\": 2, \"d\": 1, \"e\": 2, \"f\": 6 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 5, \"b\": 8, \"c\": 6, \"d\": 5, \"e\": 6, \"f\": 1 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 6, \"b\": 2, \"c\": 6, \"d\": 7, \"e\": 5, \"f\": 4 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 7, \"b\": 5, \"c\": 4, \"d\": 4, \"e\": 7, \"f\": 4 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 6, \"b\": 1, \"c\": 4, \"d\": 4, \"e\": 2, \"f\": 2 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 3, \"b\": 4, \"c\": 1, \"d\": 8, \"e\": 3, \"f\": 7 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 7, \"b\": 7, \"c\": 1, \"d\": 6, \"e\": 3, \"f\": 1 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 6, \"b\": 8, \"c\": 2, \"d\": 2, \"e\": 3, \"f\": 5 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 5, \"b\": 5, \"c\": 3, \"d\": 7, \"e\": 5, \"f\": 3 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 7, \"b\": 3, \"c\": 5, \"d\": 3, \"e\": 8, \"f\": 5 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 7, \"b\": 4, \"c\": 1, \"d\": 4, \"e\": 7, \"f\": 8 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 6, \"b\": 3, \"c\": 7, \"d\": 3, \"e\": 4, \"f\": 4 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 1, \"b\": 4, \"c\": 6, \"d\": 7, \"e\": 4, \"f\": 4 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 4, \"b\": 5, \"c\": 6, \"d\": 8, \"e\": 2, \"f\": 1 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 5, \"b\": 6, \"c\": 5, \"d\": 7, \"e\": 8, \"f\": 3 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 5, \"b\": 1, \"c\": 8, \"d\": 2, \"e\": 1, \"f\": 3 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 1, \"b\": 2, \"c\": 8, \"d\": 3, \"e\": 2, \"f\": 2 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 1, \"b\": 7, \"c\": 5, \"d\": 5, \"e\": 4, \"f\": 3 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 4, \"b\": 3, \"c\": 7, \"d\": 8, \"e\": 1, \"f\": 5 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 8, \"b\": 7, \"c\": 6, \"d\": 8, \"e\": 6, \"f\": 1 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 4, \"b\": 3, \"c\": 4, \"d\": 7, \"e\": 7, \"f\": 6 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 8, \"b\": 4, \"c\": 6, \"d\": 6, \"e\": 2, \"f\": 1 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 8, \"b\": 2, \"c\": 6, \"d\": 4, \"e\": 1, \"f\": 4 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 3, \"b\": 5, \"c\": 3, \"d\": 2, \"e\": 1, \"f\": 4 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 3, \"b\": 6, \"c\": 1, \"d\": 3, \"e\": 3, \"f\": 7 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 1, \"b\": 1, \"c\": 7, \"d\": 6, \"e\": 4, \"f\": 3 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 1, \"b\": 8, \"c\": 7, \"d\": 2, \"e\": 6, \"f\": 1 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 5, \"b\": 8, \"c\": 4, \"d\": 5, \"e\": 7, \"f\": 4 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 8, \"b\": 3, \"c\": 8, \"d\": 8, \"e\": 5, \"f\": 3 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 7, \"b\": 2, \"c\": 8, \"d\": 1, \"e\": 4, \"f\": 3 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 3, \"b\": 5, \"c\": 8, \"d\": 7, \"e\": 6, \"f\": 1 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 5, \"b\": 5, \"c\": 2, \"d\": 2, \"e\": 1, \"f\": 1 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 1, \"b\": 8, \"c\": 8, \"d\": 4, \"e\": 4, \"f\": 7 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 3, \"b\": 6, \"c\": 7, \"d\": 6, \"e\": 8, \"f\": 8 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 5, \"b\": 6, \"c\": 3, \"d\": 7, \"e\": 3, \"f\": 6 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 1, \"b\": 5, \"c\": 3, \"d\": 4, \"e\": 7, \"f\": 4 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 5, \"b\": 6, \"c\": 2, \"d\": 2, \"e\": 5, \"f\": 8 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 7, \"b\": 3, \"c\": 2, \"d\": 6, \"e\": 3, \"f\": 4 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 5, \"b\": 4, \"c\": 6, \"d\": 5, \"e\": 5, \"f\": 8 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 1, \"b\": 1, \"c\": 2, \"d\": 4, \"e\": 5, \"f\": 4 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 4, \"b\": 5, \"c\": 5, \"d\": 4, \"e\": 2, \"f\": 4 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 6, \"b\": 5, \"c\": 6, \"d\": 2, \"e\": 2, \"f\": 2 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 1, \"b\": 5, \"c\": 4, \"d\": 2, \"e\": 8, \"f\": 1 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 1, \"b\": 1, \"c\": 2, \"d\": 5, \"e\": 8, \"f\": 1 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 4, \"b\": 8, \"c\": 3, \"d\": 8, \"e\": 8, \"f\": 5 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 1, \"b\": 8, \"c\": 4, \"d\": 7, \"e\": 5, \"f\": 6 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 5, \"b\": 5, \"c\": 3, \"d\": 6, \"e\": 8, \"f\": 8 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 1, \"b\": 2, \"c\": 3, \"d\": 1, \"e\": 2, \"f\": 4 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 1, \"b\": 8, \"c\": 6, \"d\": 3, \"e\": 2, \"f\": 8 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 6, \"b\": 1, \"c\": 8, \"d\": 8, \"e\": 7, \"f\": 3 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 7, \"b\": 8, \"c\": 6, \"d\": 1, \"e\": 4, \"f\": 2 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 1, \"b\": 6, \"c\": 4, \"d\": 2, \"e\": 8, \"f\": 5 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 1, \"b\": 4, \"c\": 2, \"d\": 5, \"e\": 5, \"f\": 4 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 4, \"b\": 4, \"c\": 3, \"d\": 2, \"e\": 6, \"f\": 7 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 8, \"b\": 3, \"c\": 6, \"d\": 7, \"e\": 4, \"f\": 6 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 2, \"b\": 5, \"c\": 1, \"d\": 1, \"e\": 8, \"f\": 4 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 7, \"b\": 8, \"c\": 1, \"d\": 4, \"e\": 5, \"f\": 1 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 5, \"b\": 5, \"c\": 2, \"d\": 1, \"e\": 1, \"f\": 1 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2", "start_time": 1704594600} +{"task_id": "weekly-contest-379-maximum-size-of-a-set-after-removals", "url": "https://leetcode.com/problems/maximum-size-of-a-set-after-removals", "title": "maximum-size-of-a-set-after-removals", "meta": {"questionId": "3228", "questionFrontendId": "10037", "title": "Maximum Size of a Set After Removals", "titleSlug": "maximum-size-of-a-set-after-removals", "isPaidOnly": false, "difficulty": "Medium", "likes": 116, "dislikes": 11, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你两个下标从 0 开始的整数数组 nums1 和 nums2 ,它们的长度都是偶数 n 。\n你必须从 nums1 中移除 n / 2 个元素,同时从 nums2 中也移除 n / 2 个元素。移除之后,你将 nums1 和 nums2 中剩下的元素插入到集合 s 中。\n返回集合 s可能的 最多 包含多少元素。\n\n示例 1:\n\n输入:nums1 = [1,2,1,2], nums2 = [1,1,1,1]\n输出:2\n解释:从 nums1 和 nums2 中移除两个 1 。移除后,数组变为 nums1 = [2,2] 和 nums2 = [1,1] 。因此,s = {1,2} 。\n可以证明,在移除之后,集合 s 最多可以包含 2 个元素。\n\n示例 2:\n\n输入:nums1 = [1,2,3,4,5,6], nums2 = [2,3,2,3,2,3]\n输出:5\n解释:从 nums1 中移除 2、3 和 6 ,同时从 nums2 中移除两个 3 和一个 2 。移除后,数组变为 nums1 = [1,4,5] 和 nums2 = [2,3,2] 。因此,s = {1,2,3,4,5} 。\n可以证明,在移除之后,集合 s 最多可以包含 5 个元素。 \n\n示例 3:\n\n输入:nums1 = [1,1,2,2,3,3], nums2 = [4,4,5,5,6,6]\n输出:6\n解释:从 nums1 中移除 1、2 和 3 ,同时从 nums2 中移除 4、5 和 6 。移除后,数组变为 nums1 = [1,2,3] 和 nums2 = [4,5,6] 。因此,s = {1,2,3,4,5,6} 。\n可以证明,在移除之后,集合 s 最多可以包含 6 个元素。 \n\n提示:\n\nn == nums1.length == nums2.length\n1 <= n <= 2 * 104\nn是偶数。\n1 <= nums1[i], nums2[i] <= 109\n\"\"\"\nclass Solution:\n def maximumSetSize(self, nums1: List[int], nums2: List[int]) -> int:\n ", "prompt_sft": "给你两个下标从 0 开始的整数数组 nums1 和 nums2 ,它们的长度都是偶数 n 。\n你必须从 nums1 中移除 n / 2 个元素,同时从 nums2 中也移除 n / 2 个元素。移除之后,你将 nums1 和 nums2 中剩下的元素插入到集合 s 中。\n返回集合 s可能的 最多 包含多少元素。\n\n示例 1:\n\n输入:nums1 = [1,2,1,2], nums2 = [1,1,1,1]\n输出:2\n解释:从 nums1 和 nums2 中移除两个 1 。移除后,数组变为 nums1 = [2,2] 和 nums2 = [1,1] 。因此,s = {1,2} 。\n可以证明,在移除之后,集合 s 最多可以包含 2 个元素。\n\n示例 2:\n\n输入:nums1 = [1,2,3,4,5,6], nums2 = [2,3,2,3,2,3]\n输出:5\n解释:从 nums1 中移除 2、3 和 6 ,同时从 nums2 中移除两个 3 和一个 2 。移除后,数组变为 nums1 = [1,4,5] 和 nums2 = [2,3,2] 。因此,s = {1,2,3,4,5} 。\n可以证明,在移除之后,集合 s 最多可以包含 5 个元素。 \n\n示例 3:\n\n输入:nums1 = [1,1,2,2,3,3], nums2 = [4,4,5,5,6,6]\n输出:6\n解释:从 nums1 中移除 1、2 和 3 ,同时从 nums2 中移除 4、5 和 6 。移除后,数组变为 nums1 = [1,2,3] 和 nums2 = [4,5,6] 。因此,s = {1,2,3,4,5,6} 。\n可以证明,在移除之后,集合 s 最多可以包含 6 个元素。 \n\n提示:\n\nn == nums1.length == nums2.length\n1 <= n <= 2 * 104\nn是偶数。\n1 <= nums1[i], nums2[i] <= 109\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def maximumSetSize(self, nums1: List[int], nums2: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums1\": [1,2,1,2], \"nums2\": [1,1,1,1] }\nassert my_solution.maximumSetSize(**test_input) == 2\n\ntest_input = { \"nums1\": [1,2,3,4,5,6], \"nums2\": [2,3,2,3,2,3] }\nassert my_solution.maximumSetSize(**test_input) == 5\n\ntest_input = { \"nums1\": [1,1,2,2,3,3], \"nums2\": [4,4,5,5,6,6] }\nassert my_solution.maximumSetSize(**test_input) == 6\n\ntest_input = { \"nums1\": [1,2,1,1], \"nums2\": [1,2,3,4] }\nassert my_solution.maximumSetSize(**test_input) == 4\n\ntest_input = { \"nums1\": [1,1,1,1], \"nums2\": [12,23,41,9] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [12,23,41,9], \"nums2\": [1,1,1,1] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [9,8,4,7], \"nums2\": [5,5,9,5] }\nassert my_solution.maximumSetSize(**test_input) == 4\n\ntest_input = { \"nums1\": [8,9], \"nums2\": [4,3] }\nassert my_solution.maximumSetSize(**test_input) == 2\n\ntest_input = { \"nums1\": [7,1], \"nums2\": [6,10] }\nassert my_solution.maximumSetSize(**test_input) == 2\n\ntest_input = { \"nums1\": [10,3], \"nums2\": [5,6] }\nassert my_solution.maximumSetSize(**test_input) == 2\n\ntest_input = { \"nums1\": [3,6], \"nums2\": [6,6] }\nassert my_solution.maximumSetSize(**test_input) == 2\n\ntest_input = { \"nums1\": [5,1], \"nums2\": [6,6] }\nassert my_solution.maximumSetSize(**test_input) == 2\n\ntest_input = { \"nums1\": [10,7], \"nums2\": [8,4] }\nassert my_solution.maximumSetSize(**test_input) == 2\n\ntest_input = { \"nums1\": [10,8,7,9], \"nums2\": [7,9,9,5] }\nassert my_solution.maximumSetSize(**test_input) == 4\n\ntest_input = { \"nums1\": [1,10,6,5], \"nums2\": [3,7,10,10] }\nassert my_solution.maximumSetSize(**test_input) == 4\n\ntest_input = { \"nums1\": [5,2,8,6], \"nums2\": [7,4,1,1] }\nassert my_solution.maximumSetSize(**test_input) == 4\n\ntest_input = { \"nums1\": [2,4,1,4], \"nums2\": [10,2,4,10] }\nassert my_solution.maximumSetSize(**test_input) == 4\n\ntest_input = { \"nums1\": [5,7], \"nums2\": [3,1] }\nassert my_solution.maximumSetSize(**test_input) == 2\n\ntest_input = { \"nums1\": [1,10,1,2], \"nums2\": [9,5,8,5] }\nassert my_solution.maximumSetSize(**test_input) == 4\n\ntest_input = { \"nums1\": [9,4], \"nums2\": [5,7] }\nassert my_solution.maximumSetSize(**test_input) == 2\n\ntest_input = { \"nums1\": [1,5,10,8], \"nums2\": [1,7,4,10] }\nassert my_solution.maximumSetSize(**test_input) == 4\n\ntest_input = { \"nums1\": [6,6,2,9], \"nums2\": [1,4,10,7] }\nassert my_solution.maximumSetSize(**test_input) == 4\n\ntest_input = { \"nums1\": [7,10], \"nums2\": [6,10] }\nassert my_solution.maximumSetSize(**test_input) == 2\n\ntest_input = { \"nums1\": [8,8], \"nums2\": [6,3] }\nassert my_solution.maximumSetSize(**test_input) == 2\n\ntest_input = { \"nums1\": [6,8], \"nums2\": [9,3] }\nassert my_solution.maximumSetSize(**test_input) == 2\n\ntest_input = { \"nums1\": [3,8,1,9], \"nums2\": [2,5,4,5] }\nassert my_solution.maximumSetSize(**test_input) == 4\n\ntest_input = { \"nums1\": [6,1,4,7], \"nums2\": [10,7,2,2] }\nassert my_solution.maximumSetSize(**test_input) == 4\n\ntest_input = { \"nums1\": [8,7,9,3], \"nums2\": [10,3,8,2] }\nassert my_solution.maximumSetSize(**test_input) == 4\n\ntest_input = { \"nums1\": [1,4,5,9], \"nums2\": [2,5,2,7] }\nassert my_solution.maximumSetSize(**test_input) == 4\n\ntest_input = { \"nums1\": [3,5], \"nums2\": [5,3] }\nassert my_solution.maximumSetSize(**test_input) == 2\n\ntest_input = { \"nums1\": [1,10,8,2], \"nums2\": [2,9,10,7] }\nassert my_solution.maximumSetSize(**test_input) == 4\n\ntest_input = { \"nums1\": [3,9], \"nums2\": [1,4] }\nassert my_solution.maximumSetSize(**test_input) == 2\n\ntest_input = { \"nums1\": [1,5], \"nums2\": [10,5] }\nassert my_solution.maximumSetSize(**test_input) == 2\n\ntest_input = { \"nums1\": [7,5], \"nums2\": [2,10] }\nassert my_solution.maximumSetSize(**test_input) == 2\n\ntest_input = { \"nums1\": [6,10], \"nums2\": [3,1] }\nassert my_solution.maximumSetSize(**test_input) == 2\n\ntest_input = { \"nums1\": [9,8,1,3], \"nums2\": [4,9,8,6] }\nassert my_solution.maximumSetSize(**test_input) == 4\n\ntest_input = { \"nums1\": [4,1], \"nums2\": [9,9] }\nassert my_solution.maximumSetSize(**test_input) == 2\n\ntest_input = { \"nums1\": [10,7], \"nums2\": [10,8] }\nassert my_solution.maximumSetSize(**test_input) == 2\n\ntest_input = { \"nums1\": [4,4,3,9], \"nums2\": [6,8,4,7] }\nassert my_solution.maximumSetSize(**test_input) == 4\n\ntest_input = { \"nums1\": [4,10,4,9], \"nums2\": [5,7,4,2] }\nassert my_solution.maximumSetSize(**test_input) == 4\n\ntest_input = { \"nums1\": [8,6], \"nums2\": [1,7] }\nassert my_solution.maximumSetSize(**test_input) == 2\n\ntest_input = { \"nums1\": [9,8,10,7], \"nums2\": [3,7,7,6] }\nassert my_solution.maximumSetSize(**test_input) == 4\n\ntest_input = { \"nums1\": [4,10,9,10], \"nums2\": [9,7,3,6] }\nassert my_solution.maximumSetSize(**test_input) == 4\n\ntest_input = { \"nums1\": [6,7], \"nums2\": [5,7] }\nassert my_solution.maximumSetSize(**test_input) == 2\n\ntest_input = { \"nums1\": [1,1,10,5], \"nums2\": [6,6,8,5] }\nassert my_solution.maximumSetSize(**test_input) == 4\n\ntest_input = { \"nums1\": [5,3,4,2], \"nums2\": [10,3,7,10] }\nassert my_solution.maximumSetSize(**test_input) == 4\n\ntest_input = { \"nums1\": [1,3], \"nums2\": [9,2] }\nassert my_solution.maximumSetSize(**test_input) == 2\n\ntest_input = { \"nums1\": [6,1,6,2], \"nums2\": [5,4,6,7] }\nassert my_solution.maximumSetSize(**test_input) == 4\n\ntest_input = { \"nums1\": [9,9], \"nums2\": [8,7] }\nassert my_solution.maximumSetSize(**test_input) == 2\n\ntest_input = { \"nums1\": [6,2,9,3], \"nums2\": [10,3,4,7] }\nassert my_solution.maximumSetSize(**test_input) == 4\n\ntest_input = { \"nums1\": [6,2,10,1], \"nums2\": [9,2,6,5] }\nassert my_solution.maximumSetSize(**test_input) == 4\n\ntest_input = { \"nums1\": [6,5,6,1], \"nums2\": [6,2,6,9] }\nassert my_solution.maximumSetSize(**test_input) == 4\n\ntest_input = { \"nums1\": [10,5,4,7], \"nums2\": [5,4,4,9] }\nassert my_solution.maximumSetSize(**test_input) == 4\n\ntest_input = { \"nums1\": [7,10,4,6], \"nums2\": [1,4,4,2] }\nassert my_solution.maximumSetSize(**test_input) == 4\n\ntest_input = { \"nums1\": [3,4], \"nums2\": [1,8] }\nassert my_solution.maximumSetSize(**test_input) == 2\n\ntest_input = { \"nums1\": [7,7], \"nums2\": [7,1] }\nassert my_solution.maximumSetSize(**test_input) == 2\n\ntest_input = { \"nums1\": [1,1,2,2,1,1], \"nums2\": [1,3,2,2,2,1] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [3,3,3,2,1,2,1,2], \"nums2\": [1,2,3,2,2,3,3,1] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [1,3,3,2], \"nums2\": [2,2,1,3] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [1,1,1,3,3,3,1,1], \"nums2\": [3,2,3,2,3,3,3,3] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [3,3,1,1,3,2], \"nums2\": [2,2,1,1,2,2] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [2,3,2,3,3,1], \"nums2\": [2,3,1,2,1,1] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [1,1,3,3,1,3,3,3], \"nums2\": [2,3,1,3,1,1,1,3] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [2,3,2,2,1,3,1,1], \"nums2\": [3,1,2,2,3,1,2,2] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [2,2,2,3,1,1,3,3], \"nums2\": [3,1,3,1,2,3,2,2] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [3,3,1,3,2,2,3,1], \"nums2\": [3,1,2,3,1,3,2,1] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [1,1,1,2,1,1,1,1,1,2], \"nums2\": [3,1,3,3,1,1,3,2,1,3] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [3,2,2,3], \"nums2\": [1,1,1,3] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [2,3,3,1,2,1,2,2], \"nums2\": [1,2,2,1,2,1,2,2] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [1,2,1,3,2,3], \"nums2\": [3,3,1,1,3,3] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [1,3,1,3,3,3,3,2,2,2], \"nums2\": [2,1,3,2,2,3,3,1,1,3] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [1,3,1,1,2,2,1,1], \"nums2\": [2,3,3,1,3,2,3,2] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [2,3,2,2,2,2,1,2], \"nums2\": [3,1,2,3,3,1,2,1] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [3,3,2,1,2,3], \"nums2\": [2,1,1,3,2,2] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [1,3,1,2,1,1,2,3], \"nums2\": [1,2,2,3,2,3,3,3] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [1,1,1,3,1,2,1,1], \"nums2\": [2,3,3,2,3,3,1,1] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [3,1,3,3,2,2,2,3,1,1], \"nums2\": [1,1,2,1,3,3,1,3,2,1] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [1,1,1,2,3,2,1,1], \"nums2\": [2,1,2,2,2,1,3,3] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [2,1,3,2,2,2,2,2], \"nums2\": [1,3,3,2,2,2,3,1] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [1,3,1,1], \"nums2\": [1,3,1,2] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [1,3,3,1,3,2], \"nums2\": [2,1,3,2,2,2] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [3,2,3,3,2,2], \"nums2\": [1,3,1,3,1,1] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [1,3,1,3,2,3], \"nums2\": [2,1,1,1,2,3] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [1,1,3,1,3,1], \"nums2\": [3,3,1,2,2,1] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [2,2,2,2,2,3,1,3], \"nums2\": [2,3,3,2,1,2,3,1] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [1,3,1,2,3,1], \"nums2\": [3,3,2,2,1,3] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [2,1,2,2,1,3], \"nums2\": [1,1,1,3,2,3] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [2,2,1,2,1,3,3,1], \"nums2\": [3,1,3,1,1,3,3,1] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [3,1,3,3,2,3], \"nums2\": [1,3,3,2,2,1] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [3,2,1,3,3,2], \"nums2\": [1,1,3,3,1,2] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [2,1,3,2,3,3], \"nums2\": [2,2,2,3,2,1] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [3,3,3,1,2,2,3,1], \"nums2\": [3,1,2,3,2,3,2,1] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [3,1,3,1,2,1,2,2,2,2], \"nums2\": [2,1,3,1,1,1,2,2,1,3] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [1,2,2,1,3,3], \"nums2\": [1,1,1,3,2,2] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [2,1,2,3], \"nums2\": [3,2,3,2] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [3,1,2,2], \"nums2\": [2,1,1,1] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [2,2,3,2], \"nums2\": [2,1,3,3] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [3,3,2,1,3,3,2,3], \"nums2\": [3,1,2,3,2,2,1,3] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [3,3,3,1,2,2], \"nums2\": [1,3,1,2,2,3] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [3,1,1,3,1,1,3,2], \"nums2\": [3,2,3,3,3,1,2,3] }\nassert my_solution.maximumSetSize(**test_input) == 3", "start_time": 1704594600} +{"task_id": "weekly-contest-379-maximize-the-number-of-partitions-after-operations", "url": "https://leetcode.com/problems/maximize-the-number-of-partitions-after-operations", "title": "maximize-the-number-of-partitions-after-operations", "meta": {"questionId": "3233", "questionFrontendId": "10038", "title": "Maximize the Number of Partitions After Operations", "titleSlug": "maximize-the-number-of-partitions-after-operations", "isPaidOnly": false, "difficulty": "Hard", "likes": 41, "dislikes": 11, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0 开始的字符串s和一个整数k。\n你需要执行以下分割操作,直到字符串s变为空:\n\n选择s的最长前缀,该前缀最多包含k个不同字符。\n删除这个前缀,并将分割数量加一。如果有剩余字符,它们在s中保持原来的顺序。\n\n执行操作之 前 ,你可以将s中至多一处 下标的对应字符更改为另一个小写英文字母。\n在最优选择情形下改变至多一处下标对应字符后,用整数表示并返回操作结束时得到的最大分割数量。\n\n示例 1:\n\n输入:s = \"accca\", k = 2\n输出:3\n解释:在此示例中,为了最大化得到的分割数量,可以将 s[2] 改为 'b'。\ns 变为 \"acbca\"。\n按照以下方式执行操作,直到 s 变为空:\n- 选择最长且至多包含 2 个不同字符的前缀,\"acbca\"。\n- 删除该前缀,s 变为 \"bca\"。现在分割数量为 1。\n- 选择最长且至多包含 2 个不同字符的前缀,\"bca\"。\n- 删除该前缀,s 变为 \"a\"。现在分割数量为 2。\n- 选择最长且至多包含 2 个不同字符的前缀,\"a\"。\n- 删除该前缀,s 变为空。现在分割数量为 3。\n因此,答案是 3。\n可以证明,分割数量不可能超过 3。\n示例 2:\n\n输入:s = \"aabaab\", k = 3\n输出:1\n解释:在此示例中,为了最大化得到的分割数量,可以保持 s 不变。\n按照以下方式执行操作,直到 s 变为空: \n- 选择最长且至多包含 3 个不同字符的前缀,\"aabaab\"。\n- 删除该前缀,s 变为空。现在分割数量为 1。\n因此,答案是 1。\n可以证明,分割数量不可能超过 1。\n示例 3:\n\n输入:s = \"xxyz\", k = 1\n输出:4\n解释:在此示例中,为了最大化得到的分割数量,可以将 s[1] 改为 'a'。\ns 变为 \"xayz\"。\n按照以下方式执行操作,直到 s 变为空:\n- 选择最长且至多包含 1 个不同字符的前缀,\"xayz\"。\n- 删除该前缀,s 变为 \"ayz\"。现在分割数量为 1。\n- 选择最长且至多包含 1 个不同字符的前缀,\"ayz\"。\n- 删除该前缀,s 变为 \"yz\",现在分割数量为 2。\n- 选择最长且至多包含 1 个不同字符的前缀,\"yz\"。\n- 删除该前缀,s 变为 \"z\"。现在分割数量为 3。\n- 选择最且至多包含 1 个不同字符的前缀,\"z\"。\n- 删除该前缀,s 变为空。现在分割数量为 4。\n因此,答案是 4。\n可以证明,分割数量不可能超过 4。\n\n提示:\n\n1 <= s.length <= 104\ns只包含小写英文字母。\n1 <= k <= 26\n\"\"\"\nclass Solution:\n def maxPartitionsAfterOperations(self, s: str, k: int) -> int:\n ", "prompt_sft": "给你一个下标从 0 开始的字符串s和一个整数k。\n你需要执行以下分割操作,直到字符串s变为空:\n\n选择s的最长前缀,该前缀最多包含k个不同字符。\n删除这个前缀,并将分割数量加一。如果有剩余字符,它们在s中保持原来的顺序。\n\n执行操作之 前 ,你可以将s中至多一处 下标的对应字符更改为另一个小写英文字母。\n在最优选择情形下改变至多一处下标对应字符后,用整数表示并返回操作结束时得到的最大分割数量。\n\n示例 1:\n\n输入:s = \"accca\", k = 2\n输出:3\n解释:在此示例中,为了最大化得到的分割数量,可以将 s[2] 改为 'b'。\ns 变为 \"acbca\"。\n按照以下方式执行操作,直到 s 变为空:\n- 选择最长且至多包含 2 个不同字符的前缀,\"acbca\"。\n- 删除该前缀,s 变为 \"bca\"。现在分割数量为 1。\n- 选择最长且至多包含 2 个不同字符的前缀,\"bca\"。\n- 删除该前缀,s 变为 \"a\"。现在分割数量为 2。\n- 选择最长且至多包含 2 个不同字符的前缀,\"a\"。\n- 删除该前缀,s 变为空。现在分割数量为 3。\n因此,答案是 3。\n可以证明,分割数量不可能超过 3。\n示例 2:\n\n输入:s = \"aabaab\", k = 3\n输出:1\n解释:在此示例中,为了最大化得到的分割数量,可以保持 s 不变。\n按照以下方式执行操作,直到 s 变为空: \n- 选择最长且至多包含 3 个不同字符的前缀,\"aabaab\"。\n- 删除该前缀,s 变为空。现在分割数量为 1。\n因此,答案是 1。\n可以证明,分割数量不可能超过 1。\n示例 3:\n\n输入:s = \"xxyz\", k = 1\n输出:4\n解释:在此示例中,为了最大化得到的分割数量,可以将 s[1] 改为 'a'。\ns 变为 \"xayz\"。\n按照以下方式执行操作,直到 s 变为空:\n- 选择最长且至多包含 1 个不同字符的前缀,\"xayz\"。\n- 删除该前缀,s 变为 \"ayz\"。现在分割数量为 1。\n- 选择最长且至多包含 1 个不同字符的前缀,\"ayz\"。\n- 删除该前缀,s 变为 \"yz\",现在分割数量为 2。\n- 选择最长且至多包含 1 个不同字符的前缀,\"yz\"。\n- 删除该前缀,s 变为 \"z\"。现在分割数量为 3。\n- 选择最且至多包含 1 个不同字符的前缀,\"z\"。\n- 删除该前缀,s 变为空。现在分割数量为 4。\n因此,答案是 4。\n可以证明,分割数量不可能超过 4。\n\n提示:\n\n1 <= s.length <= 104\ns只包含小写英文字母。\n1 <= k <= 26\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def maxPartitionsAfterOperations(self, s: str, k: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"s\": \"accca\", \"k\": 2 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 3\n\ntest_input = { \"s\": \"aabaab\", \"k\": 3 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"xxyz\", \"k\": 1 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 4\n\ntest_input = { \"s\": \"c\", \"k\": 3 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"c\", \"k\": 5 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"h\", \"k\": 17 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"p\", \"k\": 13 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"ab\", \"k\": 5 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"ba\", \"k\": 1 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 2\n\ntest_input = { \"s\": \"ba\", \"k\": 3 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"ca\", \"k\": 1 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 2\n\ntest_input = { \"s\": \"fh\", \"k\": 8 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"abb\", \"k\": 1 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 3\n\ntest_input = { \"s\": \"aca\", \"k\": 2 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 2\n\ntest_input = { \"s\": \"acb\", \"k\": 2 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 2\n\ntest_input = { \"s\": \"acb\", \"k\": 4 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"bab\", \"k\": 3 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"cba\", \"k\": 1 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 3\n\ntest_input = { \"s\": \"cbb\", \"k\": 5 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"cca\", \"k\": 5 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"fjz\", \"k\": 11 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"jxg\", \"k\": 23 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"xfj\", \"k\": 5 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"abcc\", \"k\": 4 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"acab\", \"k\": 1 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 4\n\ntest_input = { \"s\": \"altj\", \"k\": 5 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"baac\", \"k\": 3 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 2\n\ntest_input = { \"s\": \"baca\", \"k\": 2 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 2\n\ntest_input = { \"s\": \"bbkk\", \"k\": 3 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"cbcc\", \"k\": 4 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"toqm\", \"k\": 14 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"yhbo\", \"k\": 9 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"aaabc\", \"k\": 1 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 5\n\ntest_input = { \"s\": \"accba\", \"k\": 3 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 2\n\ntest_input = { \"s\": \"bcbab\", \"k\": 1 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 5\n\ntest_input = { \"s\": \"bccaa\", \"k\": 5 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"caaaa\", \"k\": 3 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"cacaa\", \"k\": 4 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"cacac\", \"k\": 1 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 5\n\ntest_input = { \"s\": \"cbbab\", \"k\": 5 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"ccacb\", \"k\": 5 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"ccbba\", \"k\": 5 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"yhqlp\", \"k\": 4 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 2\n\ntest_input = { \"s\": \"aabaaa\", \"k\": 5 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"acbabb\", \"k\": 1 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 6\n\ntest_input = { \"s\": \"bbaaab\", \"k\": 4 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"bbbcca\", \"k\": 4 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"bbcaab\", \"k\": 4 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"cacbaa\", \"k\": 1 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 6\n\ntest_input = { \"s\": \"hnhdfs\", \"k\": 5 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 2\n\ntest_input = { \"s\": \"nihnrq\", \"k\": 1 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 6\n\ntest_input = { \"s\": \"odxttm\", \"k\": 19 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"uxqozq\", \"k\": 11 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"aabcaac\", \"k\": 5 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"aabcacc\", \"k\": 2 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 3\n\ntest_input = { \"s\": \"abbaaca\", \"k\": 2 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 3\n\ntest_input = { \"s\": \"baacaac\", \"k\": 3 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 2\n\ntest_input = { \"s\": \"baacbaa\", \"k\": 5 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"baacccb\", \"k\": 1 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 6\n\ntest_input = { \"s\": \"baccacb\", \"k\": 3 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 3\n\ntest_input = { \"s\": \"baccccb\", \"k\": 2 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 3\n\ntest_input = { \"s\": \"bcbbccb\", \"k\": 2 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 3\n\ntest_input = { \"s\": \"cbbcaab\", \"k\": 4 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"ccabbaa\", \"k\": 2 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 3\n\ntest_input = { \"s\": \"cccabcc\", \"k\": 3 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 2\n\ntest_input = { \"s\": \"tmdhzhy\", \"k\": 26 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"abhujxlb\", \"k\": 13 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"acabcbcb\", \"k\": 5 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"acbcbcac\", \"k\": 2 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 4\n\ntest_input = { \"s\": \"adklnsqm\", \"k\": 13 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"bababaca\", \"k\": 4 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"bcacbaaa\", \"k\": 2 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 4\n\ntest_input = { \"s\": \"bcccbacc\", \"k\": 5 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"aaaabcccb\", \"k\": 1 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 6\n\ntest_input = { \"s\": \"acabcaacc\", \"k\": 2 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 4\n\ntest_input = { \"s\": \"bcbbabcaa\", \"k\": 4 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"bccaabcaa\", \"k\": 2 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 4\n\ntest_input = { \"s\": \"cbcabbcca\", \"k\": 4 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"ccbaabbba\", \"k\": 2 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 4\n\ntest_input = { \"s\": \"aaaaabbcab\", \"k\": 5 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"aababbbbca\", \"k\": 4 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"aabbbbccab\", \"k\": 1 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 7\n\ntest_input = { \"s\": \"abbcbbcbba\", \"k\": 1 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 8\n\ntest_input = { \"s\": \"abcbbaccbb\", \"k\": 5 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"acabacccac\", \"k\": 5 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"acbbcacbab\", \"k\": 5 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"bbaccabbac\", \"k\": 4 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"bbbbcbcbbc\", \"k\": 2 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 3\n\ntest_input = { \"s\": \"bsoefqekpl\", \"k\": 6 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 2\n\ntest_input = { \"s\": \"caacccbcac\", \"k\": 3 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 2\n\ntest_input = { \"s\": \"cccacccbcb\", \"k\": 2 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 3\n\ntest_input = { \"s\": \"vwfyagymtp\", \"k\": 20 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"abaaccbaaaa\", \"k\": 2 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 4\n\ntest_input = { \"s\": \"abcccaccccc\", \"k\": 2 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 3\n\ntest_input = { \"s\": \"cbbbccaacaa\", \"k\": 3 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 2\n\ntest_input = { \"s\": \"ccaaabaaaaa\", \"k\": 2 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 3\n\ntest_input = { \"s\": \"wcmgarcruky\", \"k\": 10 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"yyogqjsswyn\", \"k\": 17 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"aaaccccbbbca\", \"k\": 1 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 7\n\ntest_input = { \"s\": \"baaccaabaccc\", \"k\": 5 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1", "start_time": 1704594600} +{"task_id": "biweekly-contest-121-smallest-missing-integer-greater-than-sequential-prefix-sum", "url": "https://leetcode.com/problems/smallest-missing-integer-greater-than-sequential-prefix-sum", "title": "smallest-missing-integer-greater-than-sequential-prefix-sum", "meta": {"questionId": "3236", "questionFrontendId": "10031", "title": "Smallest Missing Integer Greater Than Sequential Prefix Sum", "titleSlug": "smallest-missing-integer-greater-than-sequential-prefix-sum", "isPaidOnly": false, "difficulty": "Easy", "likes": 41, "dislikes": 122, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0开始的整数数组nums。\n如果一个前缀nums[0..i]满足对于1 <= j <= i的所有元素都有nums[j] = nums[j - 1] + 1,那么我们称这个前缀是一个 顺序前缀 。特殊情况是,只包含nums[0]的前缀也是一个 顺序前缀 。\n请你返回 nums中没有出现过的 最小整数x,满足x大于等于最长 顺序前缀的和。\n\n示例 1:\n\n输入:nums = [1,2,3,2,5]\n输出:6\n解释:nums 的最长顺序前缀是 [1,2,3] ,和为 6 ,6 不在数组中,所以 6 是大于等于最长顺序前缀和的最小整数。\n\n示例 2:\n\n输入:nums = [3,4,5,1,12,14,13]\n输出:15\n解释:nums 的最长顺序前缀是 [3,4,5] ,和为 12 ,12、13 和 14 都在数组中,但 15 不在,所以 15 是大于等于最长顺序前缀和的最小整数。\n\n\n提示:\n\n1 <= nums.length <= 50\n1 <= nums[i] <= 50\n\"\"\"\nclass Solution:\n def missingInteger(self, nums: List[int]) -> int:\n ", "prompt_sft": "给你一个下标从 0开始的整数数组nums。\n如果一个前缀nums[0..i]满足对于1 <= j <= i的所有元素都有nums[j] = nums[j - 1] + 1,那么我们称这个前缀是一个 顺序前缀 。特殊情况是,只包含nums[0]的前缀也是一个 顺序前缀 。\n请你返回 nums中没有出现过的 最小整数x,满足x大于等于最长 顺序前缀的和。\n\n示例 1:\n\n输入:nums = [1,2,3,2,5]\n输出:6\n解释:nums 的最长顺序前缀是 [1,2,3] ,和为 6 ,6 不在数组中,所以 6 是大于等于最长顺序前缀和的最小整数。\n\n示例 2:\n\n输入:nums = [3,4,5,1,12,14,13]\n输出:15\n解释:nums 的最长顺序前缀是 [3,4,5] ,和为 12 ,12、13 和 14 都在数组中,但 15 不在,所以 15 是大于等于最长顺序前缀和的最小整数。\n\n\n提示:\n\n1 <= nums.length <= 50\n1 <= nums[i] <= 50\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def missingInteger(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,2,3,2,5] }\nassert my_solution.missingInteger(**test_input) == 6\n\ntest_input = { \"nums\": [3,4,5,1,12,14,13] }\nassert my_solution.missingInteger(**test_input) == 15\n\ntest_input = { \"nums\": [29,30,31,32,33,34,35,36,37] }\nassert my_solution.missingInteger(**test_input) == 297\n\ntest_input = { \"nums\": [19,20,21,22] }\nassert my_solution.missingInteger(**test_input) == 82\n\ntest_input = { \"nums\": [18,19,20,21,22,23,24,25,26,27,28,9] }\nassert my_solution.missingInteger(**test_input) == 253\n\ntest_input = { \"nums\": [4,5,6,7,8,8,9,4,3,2,7] }\nassert my_solution.missingInteger(**test_input) == 30\n\ntest_input = { \"nums\": [38] }\nassert my_solution.missingInteger(**test_input) == 39\n\ntest_input = { \"nums\": [1] }\nassert my_solution.missingInteger(**test_input) == 2\n\ntest_input = { \"nums\": [11,12,13] }\nassert my_solution.missingInteger(**test_input) == 36\n\ntest_input = { \"nums\": [47,48,49,5,3] }\nassert my_solution.missingInteger(**test_input) == 144\n\ntest_input = { \"nums\": [23,24,25,4,5,1] }\nassert my_solution.missingInteger(**test_input) == 72\n\ntest_input = { \"nums\": [8,9,10,10,7,8] }\nassert my_solution.missingInteger(**test_input) == 27\n\ntest_input = { \"nums\": [31,32,33,34,10,8,7,9,7,9,9,5,10,1] }\nassert my_solution.missingInteger(**test_input) == 130\n\ntest_input = { \"nums\": [17,18,19,20,21,22,3,7,10,10] }\nassert my_solution.missingInteger(**test_input) == 117\n\ntest_input = { \"nums\": [6,7,8,9,10,8,6,7,4,1] }\nassert my_solution.missingInteger(**test_input) == 40\n\ntest_input = { \"nums\": [46,8,2,4,1,4,10,2,4,10,2,5,7,3,1] }\nassert my_solution.missingInteger(**test_input) == 47\n\ntest_input = { \"nums\": [37,1,2,9,5,8,5,2,9,4] }\nassert my_solution.missingInteger(**test_input) == 38\n\ntest_input = { \"nums\": [31,32,33,34,1] }\nassert my_solution.missingInteger(**test_input) == 130\n\ntest_input = { \"nums\": [45,46,47,48,49,10,8,1,7,4,10,10,6,6,2] }\nassert my_solution.missingInteger(**test_input) == 235\n\ntest_input = { \"nums\": [13,10,7,5,7,10,6,10,2] }\nassert my_solution.missingInteger(**test_input) == 14\n\ntest_input = { \"nums\": [32,33,34,35,36,37,38,39,40,41,42,43,44,8,6] }\nassert my_solution.missingInteger(**test_input) == 494\n\ntest_input = { \"nums\": [24,8,9] }\nassert my_solution.missingInteger(**test_input) == 25\n\ntest_input = { \"nums\": [47,48,49,9,3,8,1,9,2,5,4,5,9] }\nassert my_solution.missingInteger(**test_input) == 144\n\ntest_input = { \"nums\": [4,5,6,7,8,9,4,7,10,7,2] }\nassert my_solution.missingInteger(**test_input) == 39\n\ntest_input = { \"nums\": [28,29] }\nassert my_solution.missingInteger(**test_input) == 57\n\ntest_input = { \"nums\": [40,41,42,3,8,2,7,1,4] }\nassert my_solution.missingInteger(**test_input) == 123\n\ntest_input = { \"nums\": [17,18,19,20,21,22,23,24,25,26,27,9,2,5] }\nassert my_solution.missingInteger(**test_input) == 242\n\ntest_input = { \"nums\": [43,44] }\nassert my_solution.missingInteger(**test_input) == 87\n\ntest_input = { \"nums\": [19,20,5,3,10] }\nassert my_solution.missingInteger(**test_input) == 39\n\ntest_input = { \"nums\": [5] }\nassert my_solution.missingInteger(**test_input) == 6\n\ntest_input = { \"nums\": [14,15] }\nassert my_solution.missingInteger(**test_input) == 29\n\ntest_input = { \"nums\": [47,48,49] }\nassert my_solution.missingInteger(**test_input) == 144\n\ntest_input = { \"nums\": [10] }\nassert my_solution.missingInteger(**test_input) == 11\n\ntest_input = { \"nums\": [39] }\nassert my_solution.missingInteger(**test_input) == 40\n\ntest_input = { \"nums\": [11,12,13,14,15,7,5,2,10,5,6] }\nassert my_solution.missingInteger(**test_input) == 65\n\ntest_input = { \"nums\": [3,4,5,7,9,8,1,3,4,9] }\nassert my_solution.missingInteger(**test_input) == 12\n\ntest_input = { \"nums\": [29,30,31,32,33,34,35,36,37,38,39,40,41] }\nassert my_solution.missingInteger(**test_input) == 455\n\ntest_input = { \"nums\": [24,25,26,27,28,29,30,31,32,33,34,35,6,4,1] }\nassert my_solution.missingInteger(**test_input) == 354\n\ntest_input = { \"nums\": [7,8,9,10,11,12,13,14,15] }\nassert my_solution.missingInteger(**test_input) == 99\n\ntest_input = { \"nums\": [39,40,41,42,43,44,45,8,10,4] }\nassert my_solution.missingInteger(**test_input) == 294\n\ntest_input = { \"nums\": [36,37,6,8] }\nassert my_solution.missingInteger(**test_input) == 73\n\ntest_input = { \"nums\": [27,28,29,30] }\nassert my_solution.missingInteger(**test_input) == 114\n\ntest_input = { \"nums\": [34,35,5,7] }\nassert my_solution.missingInteger(**test_input) == 69\n\ntest_input = { \"nums\": [9,8,6,1] }\nassert my_solution.missingInteger(**test_input) == 10\n\ntest_input = { \"nums\": [36,37,38,39,8,10,7] }\nassert my_solution.missingInteger(**test_input) == 150\n\ntest_input = { \"nums\": [28,29,6] }\nassert my_solution.missingInteger(**test_input) == 57\n\ntest_input = { \"nums\": [14,15,16,17,18,19,20,10,9,10,9,7,3,6] }\nassert my_solution.missingInteger(**test_input) == 119\n\ntest_input = { \"nums\": [27,28,29,5] }\nassert my_solution.missingInteger(**test_input) == 84\n\ntest_input = { \"nums\": [42,43,44,45,46,47,48] }\nassert my_solution.missingInteger(**test_input) == 315\n\ntest_input = { \"nums\": [2,3,4,5,6,7,8,9,10,11,1,10,5,6] }\nassert my_solution.missingInteger(**test_input) == 65\n\ntest_input = { \"nums\": [32,33,34,35,36,37,5,8,5,3,4,2,10,3,7] }\nassert my_solution.missingInteger(**test_input) == 207\n\ntest_input = { \"nums\": [24,25,26,27,28,29,30,31,32,33,1,3,9] }\nassert my_solution.missingInteger(**test_input) == 285\n\ntest_input = { \"nums\": [48,49] }\nassert my_solution.missingInteger(**test_input) == 97\n\ntest_input = { \"nums\": [46,47,6,7,1] }\nassert my_solution.missingInteger(**test_input) == 93\n\ntest_input = { \"nums\": [32,33,34,35,36,37,38,39,40] }\nassert my_solution.missingInteger(**test_input) == 324\n\ntest_input = { \"nums\": [40,41,42,43,44,45,6] }\nassert my_solution.missingInteger(**test_input) == 255\n\ntest_input = { \"nums\": [5,6,7,8,9,10,11,12,13,14,15,16,17,18,9] }\nassert my_solution.missingInteger(**test_input) == 161\n\ntest_input = { \"nums\": [39,40,41,3,4,7,10,6,2,10,1,9] }\nassert my_solution.missingInteger(**test_input) == 120\n\ntest_input = { \"nums\": [17,18] }\nassert my_solution.missingInteger(**test_input) == 35\n\ntest_input = { \"nums\": [41,42,43,44,45,46,5,6] }\nassert my_solution.missingInteger(**test_input) == 261\n\ntest_input = { \"nums\": [6] }\nassert my_solution.missingInteger(**test_input) == 7\n\ntest_input = { \"nums\": [46,47,48,49,50,7] }\nassert my_solution.missingInteger(**test_input) == 240\n\ntest_input = { \"nums\": [17,18,19,20,21,22,23,24,25,26,4,7,5,4,4] }\nassert my_solution.missingInteger(**test_input) == 215\n\ntest_input = { \"nums\": [40,41,42,43,44,45,46,4,6] }\nassert my_solution.missingInteger(**test_input) == 301\n\ntest_input = { \"nums\": [13,4,2,2,3,4,1,8,3,7,7,7,1,6,3] }\nassert my_solution.missingInteger(**test_input) == 14\n\ntest_input = { \"nums\": [4,5,6,7,8,9,10,11,12,13,14,15,16,6,8] }\nassert my_solution.missingInteger(**test_input) == 130\n\ntest_input = { \"nums\": [12,10] }\nassert my_solution.missingInteger(**test_input) == 13\n\ntest_input = { \"nums\": [17,18,19,20,21,5,3,7,10,5,3,7,3,5,3] }\nassert my_solution.missingInteger(**test_input) == 95\n\ntest_input = { \"nums\": [38,39,40,41,42,43,44,45,5,7,9,9,4,1] }\nassert my_solution.missingInteger(**test_input) == 332\n\ntest_input = { \"nums\": [32,33,34,35] }\nassert my_solution.missingInteger(**test_input) == 134\n\ntest_input = { \"nums\": [33,34,7,3,4,4] }\nassert my_solution.missingInteger(**test_input) == 67\n\ntest_input = { \"nums\": [33,34,35,36,37,38,39,40,41,42,43,44,45,46,47] }\nassert my_solution.missingInteger(**test_input) == 600\n\ntest_input = { \"nums\": [14,9,6,9,7,9,10,4,9,9,4,4] }\nassert my_solution.missingInteger(**test_input) == 15\n\ntest_input = { \"nums\": [18,19,20,21,22,23,24,25,26,6,8,2,1] }\nassert my_solution.missingInteger(**test_input) == 198\n\ntest_input = { \"nums\": [19,20,21,7,9] }\nassert my_solution.missingInteger(**test_input) == 60\n\ntest_input = { \"nums\": [19,20,21,10,1,8,2,1] }\nassert my_solution.missingInteger(**test_input) == 60\n\ntest_input = { \"nums\": [1,2,3,9,2,10,8,3,10,2] }\nassert my_solution.missingInteger(**test_input) == 6\n\ntest_input = { \"nums\": [48,10] }\nassert my_solution.missingInteger(**test_input) == 49\n\ntest_input = { \"nums\": [20,21,22,23,24,25,5] }\nassert my_solution.missingInteger(**test_input) == 135\n\ntest_input = { \"nums\": [40,41,42,43,3,4,10,3,7,8,9,1,5] }\nassert my_solution.missingInteger(**test_input) == 166\n\ntest_input = { \"nums\": [21,22,23,24,25,26,27,8] }\nassert my_solution.missingInteger(**test_input) == 168\n\ntest_input = { \"nums\": [2,3,4,5,6,4] }\nassert my_solution.missingInteger(**test_input) == 20\n\ntest_input = { \"nums\": [9,10,11,12,13,14,15,16,17,4] }\nassert my_solution.missingInteger(**test_input) == 117\n\ntest_input = { \"nums\": [25,26,27,28,29,6,8] }\nassert my_solution.missingInteger(**test_input) == 135\n\ntest_input = { \"nums\": [16,17,18,19,20,21,22,23,24,25,6] }\nassert my_solution.missingInteger(**test_input) == 205\n\ntest_input = { \"nums\": [7,8,9,10,11,12] }\nassert my_solution.missingInteger(**test_input) == 57\n\ntest_input = { \"nums\": [32,9,2,6,4,1,4,3,5] }\nassert my_solution.missingInteger(**test_input) == 33\n\ntest_input = { \"nums\": [1,4,3] }\nassert my_solution.missingInteger(**test_input) == 2\n\ntest_input = { \"nums\": [34,35,36,37,38,39,1,9,3,3,10,7,1] }\nassert my_solution.missingInteger(**test_input) == 219\n\ntest_input = { \"nums\": [37,7,6,4,3,1,10,8,7,2,6] }\nassert my_solution.missingInteger(**test_input) == 38\n\ntest_input = { \"nums\": [32] }\nassert my_solution.missingInteger(**test_input) == 33\n\ntest_input = { \"nums\": [25,26,27,4] }\nassert my_solution.missingInteger(**test_input) == 78\n\ntest_input = { \"nums\": [31,32,33,8,5,3,7,2] }\nassert my_solution.missingInteger(**test_input) == 96\n\ntest_input = { \"nums\": [38,39,40,41,42,43,44,45,1] }\nassert my_solution.missingInteger(**test_input) == 332\n\ntest_input = { \"nums\": [35,36,3,10] }\nassert my_solution.missingInteger(**test_input) == 71\n\ntest_input = { \"nums\": [31,32,33,34,35,7,6,1,9] }\nassert my_solution.missingInteger(**test_input) == 165\n\ntest_input = { \"nums\": [47,48,49,2,2] }\nassert my_solution.missingInteger(**test_input) == 144\n\ntest_input = { \"nums\": [3,4,5,6,7,8,9,10,11,10,1] }\nassert my_solution.missingInteger(**test_input) == 63\n\ntest_input = { \"nums\": [50] }\nassert my_solution.missingInteger(**test_input) == 51\n\ntest_input = { \"nums\": [14,15,16,17,7,10,3,10] }\nassert my_solution.missingInteger(**test_input) == 62", "start_time": 1704551400} +{"task_id": "biweekly-contest-121-minimum-number-of-operations-to-make-array-xor-equal-to-k", "url": "https://leetcode.com/problems/minimum-number-of-operations-to-make-array-xor-equal-to-k", "title": "minimum-number-of-operations-to-make-array-xor-equal-to-k", "meta": {"questionId": "3249", "questionFrontendId": "10032", "title": "Minimum Number of Operations to Make Array XOR Equal to K", "titleSlug": "minimum-number-of-operations-to-make-array-xor-equal-to-k", "isPaidOnly": false, "difficulty": "Medium", "likes": 56, "dislikes": 4, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0开始的整数数组nums和一个正整数k。\n你可以对数组执行以下操作 任意次:\n\n选择数组里的 任意一个元素,并将它的二进制表示翻转一个数位,翻转数位表示将0 变成1或者将 1变成 0。\n\n你的目标是让数组里 所有元素的按位异或和得到 k,请你返回达成这一目标的 最少操作次数。\n注意,你也可以将一个数的前导 0 翻转。比方说,数字(101)2翻转第四个数位,得到(1101)2。\n\n示例 1:\n\n输入:nums = [2,1,3,4], k = 1\n输出:2\n解释:我们可以执行以下操作:\n- 选择下标为 2 的元素,也就是 3 == (011)2,我们翻转第一个数位得到 (010)2 == 2 。数组变为 [2,1,2,4] 。\n- 选择下标为 0 的元素,也就是 2 == (010)2 ,我们翻转第三个数位得到 (110)2 == 6 。数组变为 [6,1,2,4] 。\n最终数组的所有元素异或和为 (6 XOR 1 XOR 2 XOR 4) == 1 == k 。\n无法用少于 2 次操作得到异或和等于 k 。\n\n示例 2:\n\n输入:nums = [2,0,2,0], k = 0\n输出:0\n解释:数组所有元素的异或和为 (2 XOR 0 XOR 2 XOR 0) == 0 == k 。所以不需要进行任何操作。\n\n\n提示:\n\n1 <= nums.length <= 105\n0 <= nums[i] <= 106\n0 <= k <= 106\n\"\"\"\nclass Solution:\n def minOperations(self, nums: List[int], k: int) -> int:\n ", "prompt_sft": "给你一个下标从 0开始的整数数组nums和一个正整数k。\n你可以对数组执行以下操作 任意次:\n\n选择数组里的 任意一个元素,并将它的二进制表示翻转一个数位,翻转数位表示将0 变成1或者将 1变成 0。\n\n你的目标是让数组里 所有元素的按位异或和得到 k,请你返回达成这一目标的 最少操作次数。\n注意,你也可以将一个数的前导 0 翻转。比方说,数字(101)2翻转第四个数位,得到(1101)2。\n\n示例 1:\n\n输入:nums = [2,1,3,4], k = 1\n输出:2\n解释:我们可以执行以下操作:\n- 选择下标为 2 的元素,也就是 3 == (011)2,我们翻转第一个数位得到 (010)2 == 2 。数组变为 [2,1,2,4] 。\n- 选择下标为 0 的元素,也就是 2 == (010)2 ,我们翻转第三个数位得到 (110)2 == 6 。数组变为 [6,1,2,4] 。\n最终数组的所有元素异或和为 (6 XOR 1 XOR 2 XOR 4) == 1 == k 。\n无法用少于 2 次操作得到异或和等于 k 。\n\n示例 2:\n\n输入:nums = [2,0,2,0], k = 0\n输出:0\n解释:数组所有元素的异或和为 (2 XOR 0 XOR 2 XOR 0) == 0 == k 。所以不需要进行任何操作。\n\n\n提示:\n\n1 <= nums.length <= 105\n0 <= nums[i] <= 106\n0 <= k <= 106\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def minOperations(self, nums: List[int], k: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [2,1,3,4], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [2,0,2,0], \"k\": 0 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [4], \"k\": 7 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [3,13,9,8,5,18,11,10], \"k\": 13 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [9,7,9,14,8,6], \"k\": 12 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [13,9,10,16,11,8,1], \"k\": 17 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [12,14], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [18,18], \"k\": 20 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [3,5,1,1], \"k\": 19 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [7,0,0,0], \"k\": 8 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [13,15,19,18,2,9,18,11,0,7], \"k\": 6 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [9,15,19,15,10,15,14,0,2,5], \"k\": 20 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [19,4,19,6,3,19,14,4,16,12], \"k\": 4 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [2,10,5,5,12,3,14,6,11,14], \"k\": 3 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [11,20], \"k\": 10 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [10,12,5,3,16,0], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [0,4,4,7,14,13], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [16,2,20,13,15,20,13], \"k\": 16 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [19,11,11,0,16,2,2,0,9], \"k\": 4 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [10,17,19,8,15], \"k\": 19 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [8,17,7,18], \"k\": 6 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [10,20], \"k\": 7 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [11,14,5,9,19,3,1], \"k\": 10 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [19,13,16], \"k\": 4 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [12,18,13,2,1,5,8,5,8,6], \"k\": 7 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [15], \"k\": 9 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [8,5,4,5,13,18], \"k\": 0 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [9,18], \"k\": 3 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [6,9,15,17,16], \"k\": 19 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [14,0,17], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [12,1,14,13], \"k\": 4 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [4,10,6,10,10,16], \"k\": 18 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [2,11,6,12,2,15,4,8,11], \"k\": 3 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [7,3,12,5,1,12,8], \"k\": 11 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [11,14,18,14,6,18,4,16,20,5], \"k\": 16 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [20,2,6,0,7], \"k\": 20 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [9,18,19,16,8,11,15], \"k\": 14 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [0,3,20,0,15,7,17,4], \"k\": 3 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [15,6], \"k\": 8 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [2,7,13,16,2,2], \"k\": 15 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [2,12,11,11,2,12], \"k\": 17 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [10,8,10], \"k\": 11 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,10,2,13], \"k\": 0 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,20,4,19,12,18,5,3,11,8], \"k\": 14 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [16,12,12], \"k\": 20 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [2,1,7,3,4,9], \"k\": 6 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [20,0,19,14,7,0], \"k\": 18 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [0,15,9,1,15], \"k\": 11 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [9,11,8,20,10], \"k\": 0 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [2,10,2,14,7,13,4,9,2], \"k\": 20 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [7,12,8], \"k\": 14 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [20,11,5,8,1,8,4,16], \"k\": 7 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [8,2,19,9,8], \"k\": 9 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [17], \"k\": 8 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [19,6], \"k\": 13 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [12,3,20,19], \"k\": 4 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [4,10,18,17,20,6,4], \"k\": 10 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [8,6,12,6,6], \"k\": 4 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [18,12,9,18,12,12,1], \"k\": 12 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [14,4,0,18,18,8,4,9], \"k\": 17 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [7,16,16,6], \"k\": 19 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [7,16,2,13,0,17,16], \"k\": 18 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [3,17,4,2,3,9], \"k\": 12 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [13,14,9,19,5,13], \"k\": 8 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [4,15,10,15,11,1,3,5,18,13], \"k\": 16 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [9,7,8], \"k\": 11 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [7,4,6,20,9,9,6,6], \"k\": 10 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [1,9,13,19,19,0,16,20,4], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [20,3,9,6,5,8], \"k\": 20 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [11,20,5,16,15,11,8], \"k\": 11 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [12,10,16,18,17,4,2,19,17,2], \"k\": 19 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [15,2], \"k\": 10 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [13,3,10,2,9,13,5,11,5], \"k\": 20 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [20,12,9,3,2,11], \"k\": 13 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [3,19,0,18,6], \"k\": 15 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [12,6], \"k\": 18 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [10,11,12,6,10,1,15], \"k\": 8 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [12,8,1,16,6,12], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [11,5,9], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [2,7], \"k\": 6 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [20,1], \"k\": 8 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [9], \"k\": 16 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [9,5,7,11,8,18,5,1,4], \"k\": 8 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,8,7,19,3,20,13,9,10], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [19,18,6], \"k\": 8 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [19,12,3,18,12,19,5,20], \"k\": 0 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [6,18,12,9,20], \"k\": 13 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [19,5,5,7,4,7,15], \"k\": 7 }\nassert my_solution.minOperations(**test_input) == 5\n\ntest_input = { \"nums\": [17,7,19], \"k\": 18 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [14,13,3,15,18,20,2,9,3], \"k\": 14 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [16,10,3,2,3,19], \"k\": 4 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [2,0,8], \"k\": 18 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [19,5,5,12,20,2,10,17], \"k\": 12 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [6,0,0,1,15,9,19,12], \"k\": 6 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [8,16,13,8,18,9,16,16,19,11], \"k\": 12 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [3,7,6,7,4,3,2], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [0,2,9], \"k\": 10 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [14,10,16,9,6,13,11,13,11,16], \"k\": 20 }\nassert my_solution.minOperations(**test_input) == 5\n\ntest_input = { \"nums\": [13,19,0,12,11,10,11,2,6], \"k\": 7 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [6,1,4,9,1,7,11,15,15,0], \"k\": 8 }\nassert my_solution.minOperations(**test_input) == 4", "start_time": 1704551400} +{"task_id": "biweekly-contest-121-minimum-number-of-operations-to-make-x-and-y-equal", "url": "https://leetcode.com/problems/minimum-number-of-operations-to-make-x-and-y-equal", "title": "minimum-number-of-operations-to-make-x-and-y-equal", "meta": {"questionId": "3239", "questionFrontendId": "10033", "title": "Minimum Number of Operations to Make X and Y Equal", "titleSlug": "minimum-number-of-operations-to-make-x-and-y-equal", "isPaidOnly": false, "difficulty": "Medium", "likes": 103, "dislikes": 19, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你两个正整数x 和y。\n一次操作中,你可以执行以下四种操作之一:\n\n如果 x是 11的倍数,将x除以11。\n如果 x是 5的倍数,将 x除以 5。\n将x 减1。\n将x加1。\n\n请你返回让 x和 y相等的 最少操作次数。\n\n示例 1:\n\n输入:x = 26, y = 1\n输出:3\n解释:我们可以通过以下操作将 26 变为 1 :\n1. 将 x 减 1\n2. 将 x 除以 5\n3. 将 x 除以 5\n将 26 变为 1 最少需要 3 次操作。\n\n示例 2:\n\n输入:x = 54, y = 2\n输出:4\n解释:我们可以通过以下操作将 54 变为 2 :\n1. 将 x 加 1\n2. 将 x 除以 11\n3. 将 x 除以 5\n4. 将 x 加 1\n将 54 变为 2 最少需要 4 次操作。\n\n示例 3:\n\n输入:x = 25, y = 30\n输出:5\n解释:我们可以通过以下操作将 25 变为 30 :\n1. 将 x 加 1\n2. 将 x 加 1\n3. 将 x 加 1\n4. 将 x 加 1\n5. 将 x 加 1\n将 25 变为 30 最少需要 5 次操作。\n\n\n提示:\n\n1 <= x, y <= 104\n\"\"\"\nclass Solution:\n def minimumOperationsToMakeEqual(self, x: int, y: int) -> int:\n ", "prompt_sft": "给你两个正整数x 和y。\n一次操作中,你可以执行以下四种操作之一:\n\n如果 x是 11的倍数,将x除以11。\n如果 x是 5的倍数,将 x除以 5。\n将x 减1。\n将x加1。\n\n请你返回让 x和 y相等的 最少操作次数。\n\n示例 1:\n\n输入:x = 26, y = 1\n输出:3\n解释:我们可以通过以下操作将 26 变为 1 :\n1. 将 x 减 1\n2. 将 x 除以 5\n3. 将 x 除以 5\n将 26 变为 1 最少需要 3 次操作。\n\n示例 2:\n\n输入:x = 54, y = 2\n输出:4\n解释:我们可以通过以下操作将 54 变为 2 :\n1. 将 x 加 1\n2. 将 x 除以 11\n3. 将 x 除以 5\n4. 将 x 加 1\n将 54 变为 2 最少需要 4 次操作。\n\n示例 3:\n\n输入:x = 25, y = 30\n输出:5\n解释:我们可以通过以下操作将 25 变为 30 :\n1. 将 x 加 1\n2. 将 x 加 1\n3. 将 x 加 1\n4. 将 x 加 1\n5. 将 x 加 1\n将 25 变为 30 最少需要 5 次操作。\n\n\n提示:\n\n1 <= x, y <= 104\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def minimumOperationsToMakeEqual(self, x: int, y: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"x\": 26, \"y\": 1 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 3\n\ntest_input = { \"x\": 54, \"y\": 2 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 4\n\ntest_input = { \"x\": 25, \"y\": 30 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 5\n\ntest_input = { \"x\": 1, \"y\": 1 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 0\n\ntest_input = { \"x\": 1, \"y\": 2 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 1\n\ntest_input = { \"x\": 1, \"y\": 3 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 2\n\ntest_input = { \"x\": 1, \"y\": 4 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 3\n\ntest_input = { \"x\": 1, \"y\": 5 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 4\n\ntest_input = { \"x\": 1, \"y\": 6 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 5\n\ntest_input = { \"x\": 1, \"y\": 7 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 6\n\ntest_input = { \"x\": 1, \"y\": 8 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 7\n\ntest_input = { \"x\": 1, \"y\": 9 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 8\n\ntest_input = { \"x\": 1, \"y\": 10 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 9\n\ntest_input = { \"x\": 1, \"y\": 11 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 10\n\ntest_input = { \"x\": 1, \"y\": 12 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 11\n\ntest_input = { \"x\": 1, \"y\": 13 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 12\n\ntest_input = { \"x\": 1, \"y\": 14 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 13\n\ntest_input = { \"x\": 1, \"y\": 15 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 14\n\ntest_input = { \"x\": 1, \"y\": 16 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 15\n\ntest_input = { \"x\": 1, \"y\": 17 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 16\n\ntest_input = { \"x\": 1, \"y\": 18 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 17\n\ntest_input = { \"x\": 1, \"y\": 19 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 18\n\ntest_input = { \"x\": 1, \"y\": 20 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 19\n\ntest_input = { \"x\": 1, \"y\": 21 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 20\n\ntest_input = { \"x\": 1, \"y\": 22 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 21\n\ntest_input = { \"x\": 1, \"y\": 23 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 22\n\ntest_input = { \"x\": 1, \"y\": 24 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 23\n\ntest_input = { \"x\": 1, \"y\": 25 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 24\n\ntest_input = { \"x\": 2, \"y\": 1 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 1\n\ntest_input = { \"x\": 2, \"y\": 2 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 0\n\ntest_input = { \"x\": 2, \"y\": 3 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 1\n\ntest_input = { \"x\": 2, \"y\": 4 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 2\n\ntest_input = { \"x\": 2, \"y\": 5 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 3\n\ntest_input = { \"x\": 2, \"y\": 6 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 4\n\ntest_input = { \"x\": 2, \"y\": 7 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 5\n\ntest_input = { \"x\": 2, \"y\": 8 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 6\n\ntest_input = { \"x\": 2, \"y\": 9 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 7\n\ntest_input = { \"x\": 2, \"y\": 10 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 8\n\ntest_input = { \"x\": 2, \"y\": 11 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 9\n\ntest_input = { \"x\": 2, \"y\": 12 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 10\n\ntest_input = { \"x\": 2, \"y\": 13 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 11\n\ntest_input = { \"x\": 2, \"y\": 14 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 12\n\ntest_input = { \"x\": 2, \"y\": 15 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 13\n\ntest_input = { \"x\": 2, \"y\": 16 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 14\n\ntest_input = { \"x\": 2, \"y\": 17 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 15\n\ntest_input = { \"x\": 2, \"y\": 18 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 16\n\ntest_input = { \"x\": 2, \"y\": 19 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 17\n\ntest_input = { \"x\": 2, \"y\": 20 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 18\n\ntest_input = { \"x\": 2, \"y\": 21 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 19\n\ntest_input = { \"x\": 2, \"y\": 22 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 20\n\ntest_input = { \"x\": 2, \"y\": 23 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 21\n\ntest_input = { \"x\": 2, \"y\": 24 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 22\n\ntest_input = { \"x\": 2, \"y\": 25 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 23\n\ntest_input = { \"x\": 3, \"y\": 1 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 2\n\ntest_input = { \"x\": 3, \"y\": 2 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 1\n\ntest_input = { \"x\": 3, \"y\": 3 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 0\n\ntest_input = { \"x\": 3, \"y\": 4 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 1\n\ntest_input = { \"x\": 3, \"y\": 5 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 2\n\ntest_input = { \"x\": 3, \"y\": 6 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 3\n\ntest_input = { \"x\": 3, \"y\": 7 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 4\n\ntest_input = { \"x\": 3, \"y\": 8 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 5\n\ntest_input = { \"x\": 3, \"y\": 9 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 6\n\ntest_input = { \"x\": 3, \"y\": 10 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 7\n\ntest_input = { \"x\": 3, \"y\": 11 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 8\n\ntest_input = { \"x\": 3, \"y\": 12 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 9\n\ntest_input = { \"x\": 3, \"y\": 13 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 10\n\ntest_input = { \"x\": 3, \"y\": 14 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 11\n\ntest_input = { \"x\": 3, \"y\": 15 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 12\n\ntest_input = { \"x\": 3, \"y\": 16 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 13\n\ntest_input = { \"x\": 3, \"y\": 17 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 14\n\ntest_input = { \"x\": 3, \"y\": 18 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 15\n\ntest_input = { \"x\": 3, \"y\": 19 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 16\n\ntest_input = { \"x\": 3, \"y\": 20 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 17\n\ntest_input = { \"x\": 3, \"y\": 21 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 18\n\ntest_input = { \"x\": 3, \"y\": 22 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 19\n\ntest_input = { \"x\": 3, \"y\": 23 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 20\n\ntest_input = { \"x\": 3, \"y\": 24 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 21\n\ntest_input = { \"x\": 3, \"y\": 25 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 22\n\ntest_input = { \"x\": 4, \"y\": 1 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 2\n\ntest_input = { \"x\": 4, \"y\": 2 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 2\n\ntest_input = { \"x\": 4, \"y\": 3 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 1\n\ntest_input = { \"x\": 4, \"y\": 4 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 0\n\ntest_input = { \"x\": 4, \"y\": 5 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 1\n\ntest_input = { \"x\": 4, \"y\": 6 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 2\n\ntest_input = { \"x\": 4, \"y\": 7 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 3\n\ntest_input = { \"x\": 4, \"y\": 8 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 4\n\ntest_input = { \"x\": 4, \"y\": 9 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 5\n\ntest_input = { \"x\": 4, \"y\": 10 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 6\n\ntest_input = { \"x\": 4, \"y\": 11 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 7\n\ntest_input = { \"x\": 4, \"y\": 12 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 8\n\ntest_input = { \"x\": 4, \"y\": 13 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 9\n\ntest_input = { \"x\": 4, \"y\": 14 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 10\n\ntest_input = { \"x\": 4, \"y\": 15 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 11\n\ntest_input = { \"x\": 4, \"y\": 16 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 12\n\ntest_input = { \"x\": 4, \"y\": 17 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 13\n\ntest_input = { \"x\": 4, \"y\": 18 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 14\n\ntest_input = { \"x\": 4, \"y\": 19 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 15\n\ntest_input = { \"x\": 4, \"y\": 20 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 16\n\ntest_input = { \"x\": 4, \"y\": 21 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 17\n\ntest_input = { \"x\": 4, \"y\": 22 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 18", "start_time": 1704551400} +{"task_id": "biweekly-contest-121-count-the-number-of-powerful-integers", "url": "https://leetcode.com/problems/count-the-number-of-powerful-integers", "title": "count-the-number-of-powerful-integers", "meta": {"questionId": "3243", "questionFrontendId": "10034", "title": "Count the Number of Powerful Integers", "titleSlug": "count-the-number-of-powerful-integers", "isPaidOnly": false, "difficulty": "Hard", "likes": 53, "dislikes": 1, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你三个整数start,finish和limit。同时给你一个下标从0开始的字符串s,表示一个 正整数。\n如果一个 正整数x 末尾部分是s(换句话说,s是 x的 后缀),且 x中的每个数位至多是 limit,那么我们称 x是 强大的。\n请你返回区间[start..finish]内强大整数的总数目。\n如果一个字符串 x是 y中某个下标开始(包括0),到下标为y.length - 1结束的子字符串,那么我们称x是y的一个后缀。比方说,25是5125的一个后缀,但不是512的后缀。\n\n示例 1:\n\n输入:start = 1, finish = 6000, limit = 4, s = \"124\"\n输出:5\n解释:区间 [1..6000] 内的强大数字为 124 ,1124 ,2124 ,3124 和 4124 。这些整数的各个数位都 <= 4 且 \"124\" 是它们的后缀。注意 5124 不是强大整数,因为第一个数位 5 大于 4 。\n这个区间内总共只有这 5 个强大整数。\n\n示例 2:\n\n输入:start = 15, finish = 215, limit = 6, s = \"10\"\n输出:2\n解释:区间 [15..215] 内的强大整数为 110 和 210 。这些整数的各个数位都 <= 6 且 \"10\" 是它们的后缀。\n这个区间总共只有这 2 个强大整数。\n\n示例 3:\n\n输入:start = 1000, finish = 2000, limit = 4, s = \"3000\"\n输出:0\n解释:区间 [1000..2000] 内的整数都小于 3000 ,所以 \"3000\" 不可能是这个区间内任何整数的后缀。\n\n\n提示:\n\n1 <= start <= finish <= 1015\n1 <= limit <= 9\n1 <= s.length <= floor(log10(finish)) + 1\ns数位中每个数字都小于等于limit。\ns不包含任何前导 0 。\n\"\"\"\nclass Solution:\n def numberOfPowerfulInt(self, start: int, finish: int, limit: int, s: str) -> int:\n ", "prompt_sft": "给你三个整数start,finish和limit。同时给你一个下标从0开始的字符串s,表示一个 正整数。\n如果一个 正整数x 末尾部分是s(换句话说,s是 x的 后缀),且 x中的每个数位至多是 limit,那么我们称 x是 强大的。\n请你返回区间[start..finish]内强大整数的总数目。\n如果一个字符串 x是 y中某个下标开始(包括0),到下标为y.length - 1结束的子字符串,那么我们称x是y的一个后缀。比方说,25是5125的一个后缀,但不是512的后缀。\n\n示例 1:\n\n输入:start = 1, finish = 6000, limit = 4, s = \"124\"\n输出:5\n解释:区间 [1..6000] 内的强大数字为 124 ,1124 ,2124 ,3124 和 4124 。这些整数的各个数位都 <= 4 且 \"124\" 是它们的后缀。注意 5124 不是强大整数,因为第一个数位 5 大于 4 。\n这个区间内总共只有这 5 个强大整数。\n\n示例 2:\n\n输入:start = 15, finish = 215, limit = 6, s = \"10\"\n输出:2\n解释:区间 [15..215] 内的强大整数为 110 和 210 。这些整数的各个数位都 <= 6 且 \"10\" 是它们的后缀。\n这个区间总共只有这 2 个强大整数。\n\n示例 3:\n\n输入:start = 1000, finish = 2000, limit = 4, s = \"3000\"\n输出:0\n解释:区间 [1000..2000] 内的整数都小于 3000 ,所以 \"3000\" 不可能是这个区间内任何整数的后缀。\n\n\n提示:\n\n1 <= start <= finish <= 1015\n1 <= limit <= 9\n1 <= s.length <= floor(log10(finish)) + 1\ns数位中每个数字都小于等于limit。\ns不包含任何前导 0 。\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def numberOfPowerfulInt(self, start: int, finish: int, limit: int, s: str) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"start\": 1, \"finish\": 6000, \"limit\": 4, \"s\": \"124\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 5\n\ntest_input = { \"start\": 15, \"finish\": 215, \"limit\": 6, \"s\": \"10\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 2\n\ntest_input = { \"start\": 1000, \"finish\": 2000, \"limit\": 4, \"s\": \"3000\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 0\n\ntest_input = { \"start\": 141, \"finish\": 148, \"limit\": 9, \"s\": \"9\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 0\n\ntest_input = { \"start\": 1, \"finish\": 971, \"limit\": 9, \"s\": \"17\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 10\n\ntest_input = { \"start\": 1, \"finish\": 971, \"limit\": 9, \"s\": \"27\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 10\n\ntest_input = { \"start\": 1, \"finish\": 971, \"limit\": 9, \"s\": \"41\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 10\n\ntest_input = { \"start\": 1, \"finish\": 971, \"limit\": 9, \"s\": \"47\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 10\n\ntest_input = { \"start\": 1, \"finish\": 971, \"limit\": 9, \"s\": \"61\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 10\n\ntest_input = { \"start\": 1, \"finish\": 971, \"limit\": 9, \"s\": \"66\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 10\n\ntest_input = { \"start\": 1, \"finish\": 971, \"limit\": 9, \"s\": \"71\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 10\n\ntest_input = { \"start\": 1, \"finish\": 971, \"limit\": 9, \"s\": \"72\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 9\n\ntest_input = { \"start\": 20, \"finish\": 1159, \"limit\": 5, \"s\": \"20\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 8\n\ntest_input = { \"start\": 20, \"finish\": 1159, \"limit\": 5, \"s\": \"24\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 8\n\ntest_input = { \"start\": 20, \"finish\": 1159, \"limit\": 5, \"s\": \"32\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 8\n\ntest_input = { \"start\": 20, \"finish\": 1159, \"limit\": 5, \"s\": \"33\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 8\n\ntest_input = { \"start\": 20, \"finish\": 1159, \"limit\": 5, \"s\": \"40\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 8\n\ntest_input = { \"start\": 20, \"finish\": 1159, \"limit\": 5, \"s\": \"41\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 8\n\ntest_input = { \"start\": 20, \"finish\": 1159, \"limit\": 5, \"s\": \"42\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 8\n\ntest_input = { \"start\": 20, \"finish\": 1159, \"limit\": 5, \"s\": \"43\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 8\n\ntest_input = { \"start\": 20, \"finish\": 1159, \"limit\": 5, \"s\": \"44\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 8\n\ntest_input = { \"start\": 1300, \"finish\": 1400, \"limit\": 5, \"s\": \"245\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 0\n\ntest_input = { \"start\": 3, \"finish\": 1429, \"limit\": 5, \"s\": \"11\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 11\n\ntest_input = { \"start\": 3, \"finish\": 1429, \"limit\": 5, \"s\": \"12\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 11\n\ntest_input = { \"start\": 3, \"finish\": 1429, \"limit\": 5, \"s\": \"13\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 11\n\ntest_input = { \"start\": 3, \"finish\": 1429, \"limit\": 5, \"s\": \"14\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 11\n\ntest_input = { \"start\": 3, \"finish\": 1429, \"limit\": 5, \"s\": \"20\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 11\n\ntest_input = { \"start\": 3, \"finish\": 1429, \"limit\": 5, \"s\": \"21\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 11\n\ntest_input = { \"start\": 3, \"finish\": 1429, \"limit\": 5, \"s\": \"34\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 10\n\ntest_input = { \"start\": 3, \"finish\": 1429, \"limit\": 5, \"s\": \"40\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 10\n\ntest_input = { \"start\": 3, \"finish\": 1429, \"limit\": 5, \"s\": \"43\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 10\n\ntest_input = { \"start\": 15, \"finish\": 1440, \"limit\": 5, \"s\": \"11\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 10\n\ntest_input = { \"start\": 15, \"finish\": 1440, \"limit\": 5, \"s\": \"12\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 10\n\ntest_input = { \"start\": 15, \"finish\": 1440, \"limit\": 5, \"s\": \"14\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 10\n\ntest_input = { \"start\": 15, \"finish\": 1440, \"limit\": 5, \"s\": \"21\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 11\n\ntest_input = { \"start\": 15, \"finish\": 1440, \"limit\": 5, \"s\": \"23\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 11\n\ntest_input = { \"start\": 15, \"finish\": 1440, \"limit\": 5, \"s\": \"31\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 11\n\ntest_input = { \"start\": 15, \"finish\": 1440, \"limit\": 5, \"s\": \"34\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 11\n\ntest_input = { \"start\": 15, \"finish\": 1440, \"limit\": 5, \"s\": \"42\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 10\n\ntest_input = { \"start\": 10, \"finish\": 1844, \"limit\": 5, \"s\": \"12\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 12\n\ntest_input = { \"start\": 10, \"finish\": 1844, \"limit\": 5, \"s\": \"20\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 12\n\ntest_input = { \"start\": 10, \"finish\": 1844, \"limit\": 5, \"s\": \"24\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 12\n\ntest_input = { \"start\": 10, \"finish\": 1844, \"limit\": 5, \"s\": \"30\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 12\n\ntest_input = { \"start\": 10, \"finish\": 1844, \"limit\": 5, \"s\": \"33\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 12\n\ntest_input = { \"start\": 10, \"finish\": 1844, \"limit\": 5, \"s\": \"40\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 12\n\ntest_input = { \"start\": 10, \"finish\": 1844, \"limit\": 5, \"s\": \"42\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 12\n\ntest_input = { \"start\": 10, \"finish\": 1844, \"limit\": 5, \"s\": \"44\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 12\n\ntest_input = { \"start\": 16, \"finish\": 1848, \"limit\": 5, \"s\": \"11\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 11\n\ntest_input = { \"start\": 16, \"finish\": 1848, \"limit\": 5, \"s\": \"13\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 11\n\ntest_input = { \"start\": 16, \"finish\": 1848, \"limit\": 5, \"s\": \"14\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 11\n\ntest_input = { \"start\": 16, \"finish\": 1848, \"limit\": 5, \"s\": \"22\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 12\n\ntest_input = { \"start\": 16, \"finish\": 1848, \"limit\": 5, \"s\": \"30\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 12\n\ntest_input = { \"start\": 16, \"finish\": 1848, \"limit\": 5, \"s\": \"33\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 12\n\ntest_input = { \"start\": 16, \"finish\": 1848, \"limit\": 5, \"s\": \"43\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 12\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"1\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 162\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"10\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"100\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 2\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"11\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"12\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"13\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"14\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"15\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"16\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"17\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"18\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"2\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 162\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"20\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"21\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"22\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"23\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"24\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"25\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"26\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"27\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"28\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"3\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 162\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"30\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"31\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"32\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"33\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"34\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"35\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"36\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"37\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"38\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"4\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 162\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"40\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"41\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"42\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"43\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"44\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"45\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"46\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"47\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"48\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"5\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 162\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"50\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"51\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"52\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"53\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18", "start_time": 1704551400} +{"task_id": "weekly-contest-378-check-if-bitwise-or-has-trailing-zeros", "url": "https://leetcode.com/problems/check-if-bitwise-or-has-trailing-zeros", "title": "check-if-bitwise-or-has-trailing-zeros", "meta": {"questionId": "3246", "questionFrontendId": "2980", "title": "Check if Bitwise OR Has Trailing Zeros", "titleSlug": "check-if-bitwise-or-has-trailing-zeros", "isPaidOnly": false, "difficulty": "Easy", "likes": 68, "dislikes": 5, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个 正整数 数组 nums 。\n你需要检查是否可以从数组中选出 两个或更多 元素,满足这些元素的按位或运算( OR)结果的二进制表示中 至少 存在一个尾随零。\n例如,数字 5 的二进制表示是 \"101\",不存在尾随零,而数字 4 的二进制表示是 \"100\",存在两个尾随零。\n如果可以选择两个或更多元素,其按位或运算结果存在尾随零,返回 true;否则,返回 false 。\n\n示例 1:\n\n输入:nums = [1,2,3,4,5]\n输出:true\n解释:如果选择元素 2 和 4,按位或运算结果是 6,二进制表示为 \"110\" ,存在一个尾随零。\n\n示例 2:\n\n输入:nums = [2,4,8,16]\n输出:true\n解释:如果选择元素 2 和 4,按位或运算结果是 6,二进制表示为 \"110\",存在一个尾随零。\n其他按位或运算结果存在尾随零的可能选择方案包括:(2, 8), (2, 16), (4, 8), (4, 16), (8, 16), (2, 4, 8), (2, 4, 16), (2, 8, 16), (4, 8, 16), 以及 (2, 4, 8, 16) 。\n\n示例 3:\n\n输入:nums = [1,3,5,7,9]\n输出:false\n解释:不存在按位或运算结果存在尾随零的选择方案。\n\n\n提示:\n\n2 <= nums.length <= 100\n1 <= nums[i] <= 100\n\"\"\"\nclass Solution:\n def hasTrailingZeros(self, nums: List[int]) -> bool:\n ", "prompt_sft": "给你一个 正整数 数组 nums 。\n你需要检查是否可以从数组中选出 两个或更多 元素,满足这些元素的按位或运算( OR)结果的二进制表示中 至少 存在一个尾随零。\n例如,数字 5 的二进制表示是 \"101\",不存在尾随零,而数字 4 的二进制表示是 \"100\",存在两个尾随零。\n如果可以选择两个或更多元素,其按位或运算结果存在尾随零,返回 true;否则,返回 false 。\n\n示例 1:\n\n输入:nums = [1,2,3,4,5]\n输出:true\n解释:如果选择元素 2 和 4,按位或运算结果是 6,二进制表示为 \"110\" ,存在一个尾随零。\n\n示例 2:\n\n输入:nums = [2,4,8,16]\n输出:true\n解释:如果选择元素 2 和 4,按位或运算结果是 6,二进制表示为 \"110\",存在一个尾随零。\n其他按位或运算结果存在尾随零的可能选择方案包括:(2, 8), (2, 16), (4, 8), (4, 16), (8, 16), (2, 4, 8), (2, 4, 16), (2, 8, 16), (4, 8, 16), 以及 (2, 4, 8, 16) 。\n\n示例 3:\n\n输入:nums = [1,3,5,7,9]\n输出:false\n解释:不存在按位或运算结果存在尾随零的选择方案。\n\n\n提示:\n\n2 <= nums.length <= 100\n1 <= nums[i] <= 100\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def hasTrailingZeros(self, nums: List[int]) -> bool:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,2,3,4,5] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [1,3,5,7,9] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [1,2] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [2,4,8,16] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [1,3] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [1,7] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [3,3] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [3,4] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [2,2] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [4,8] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [4,32] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [6,2] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [6,8] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [3,9] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [4,3] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [5,6] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [7,9] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [8,2] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [8,4] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [7,10] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [9,73] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [8,8] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [10,5] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [11,17] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [19,11] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [19,35] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [19,51] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [21,61] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [23,21] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [25,25] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [10,2] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [12,8] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [27,77] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [16,4] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [16,8] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [16,16] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [16,32] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [29,13] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [37,69] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [39,53] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [24,32] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [32,32] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [42,9] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [45,24] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [64,16] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [49,23] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [4,6,4] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [8,16,4] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [57,27] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [8,16,16] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [10,4,6] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [12,8,8] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [63,47] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [67,69] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [69,87] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [16,8,4] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [77,49] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [89,31] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [1,3,4] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [1,5,3] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [1,7,9] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [3,69,59] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [16,16,16] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [6,5,5] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [7,77,9] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [9,77,51] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [16,32,8] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [16,32,16] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [10,1,9] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [10,7,5] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [11,23,27] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [15,13,63] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [21,27,79] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [23,23,47] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [35,91,15] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [32,4,16] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [32,8,48] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [33,40,84] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [41,83,53] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [64,48,6] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [75,34,58] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [3,8,2,3] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [43,15,41] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [43,65,79] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [47,7,19] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [4,6,1,1] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [4,10,1,7] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [49,73,81] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [6,3,10,6] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [6,4,2,8] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [6,12,12,24] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [7,2,4,4] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [8,6,4,32] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [8,12,16,2] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [12,64,16,8] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [16,4,8,16] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [51,33,25] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [16,8,64,4] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [16,16,12,8] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [51,43,9] }\nassert my_solution.hasTrailingZeros(**test_input) == False", "start_time": 1703989800} +{"task_id": "weekly-contest-378-find-longest-special-substring-that-occurs-thrice-i", "url": "https://leetcode.com/problems/find-longest-special-substring-that-occurs-thrice-i", "title": "find-longest-special-substring-that-occurs-thrice-i", "meta": {"questionId": "3267", "questionFrontendId": "2981", "title": "Find Longest Special Substring That Occurs Thrice I", "titleSlug": "find-longest-special-substring-that-occurs-thrice-i", "isPaidOnly": false, "difficulty": "Medium", "likes": 112, "dislikes": 6, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个仅由小写英文字母组成的字符串 s 。\n如果一个字符串仅由单一字符组成,那么它被称为 特殊 字符串。例如,字符串 \"abc\" 不是特殊字符串,而字符串 \"ddd\"、\"zz\" 和 \"f\" 是特殊字符串。\n返回在 s 中出现 至少三次 的 最长特殊子字符串 的长度,如果不存在出现至少三次的特殊子字符串,则返回 -1 。\n子字符串 是字符串中的一个连续 非空 字符序列。\n\n示例 1:\n\n输入:s = \"aaaa\"\n输出:2\n解释:出现三次的最长特殊子字符串是 \"aa\" :子字符串 \"aaaa\"、\"aaaa\" 和 \"aaaa\"。\n可以证明最大长度是 2 。\n\n示例 2:\n\n输入:s = \"abcdef\"\n输出:-1\n解释:不存在出现至少三次的特殊子字符串。因此返回 -1 。\n\n示例 3:\n\n输入:s = \"abcaba\"\n输出:1\n解释:出现三次的最长特殊子字符串是 \"a\" :子字符串 \"abcaba\"、\"abcaba\" 和 \"abcaba\"。\n可以证明最大长度是 1 。\n\n\n提示:\n\n3 <= s.length <= 50\ns 仅由小写英文字母组成。\n\"\"\"\nclass Solution:\n def maximumLength(self, s: str) -> int:\n ", "prompt_sft": "给你一个仅由小写英文字母组成的字符串 s 。\n如果一个字符串仅由单一字符组成,那么它被称为 特殊 字符串。例如,字符串 \"abc\" 不是特殊字符串,而字符串 \"ddd\"、\"zz\" 和 \"f\" 是特殊字符串。\n返回在 s 中出现 至少三次 的 最长特殊子字符串 的长度,如果不存在出现至少三次的特殊子字符串,则返回 -1 。\n子字符串 是字符串中的一个连续 非空 字符序列。\n\n示例 1:\n\n输入:s = \"aaaa\"\n输出:2\n解释:出现三次的最长特殊子字符串是 \"aa\" :子字符串 \"aaaa\"、\"aaaa\" 和 \"aaaa\"。\n可以证明最大长度是 2 。\n\n示例 2:\n\n输入:s = \"abcdef\"\n输出:-1\n解释:不存在出现至少三次的特殊子字符串。因此返回 -1 。\n\n示例 3:\n\n输入:s = \"abcaba\"\n输出:1\n解释:出现三次的最长特殊子字符串是 \"a\" :子字符串 \"abcaba\"、\"abcaba\" 和 \"abcaba\"。\n可以证明最大长度是 1 。\n\n\n提示:\n\n3 <= s.length <= 50\ns 仅由小写英文字母组成。\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def maximumLength(self, s: str) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"s\": \"aaaa\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"abcdef\" }\nassert my_solution.maximumLength(**test_input) == -1\n\ntest_input = { \"s\": \"abcaba\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"abcccccdddd\" }\nassert my_solution.maximumLength(**test_input) == 3\n\ntest_input = { \"s\": \"aaa\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"acc\" }\nassert my_solution.maximumLength(**test_input) == -1\n\ntest_input = { \"s\": \"cab\" }\nassert my_solution.maximumLength(**test_input) == -1\n\ntest_input = { \"s\": \"cad\" }\nassert my_solution.maximumLength(**test_input) == -1\n\ntest_input = { \"s\": \"cbc\" }\nassert my_solution.maximumLength(**test_input) == -1\n\ntest_input = { \"s\": \"ccc\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"dca\" }\nassert my_solution.maximumLength(**test_input) == -1\n\ntest_input = { \"s\": \"ddd\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"fff\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"ggg\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"hhh\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"kkk\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"lll\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"ooo\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"ppp\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"qqq\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"rrr\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"xxx\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"yyy\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"aaau\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"affe\" }\nassert my_solution.maximumLength(**test_input) == -1\n\ntest_input = { \"s\": \"agae\" }\nassert my_solution.maximumLength(**test_input) == -1\n\ntest_input = { \"s\": \"aiii\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"bbbb\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"bbbz\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"bddd\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"beee\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"bnnn\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"bsss\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"bxxx\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"cafc\" }\nassert my_solution.maximumLength(**test_input) == -1\n\ntest_input = { \"s\": \"ccag\" }\nassert my_solution.maximumLength(**test_input) == -1\n\ntest_input = { \"s\": \"cfff\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"dddd\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"dsss\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"eccc\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"eeew\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"gfdc\" }\nassert my_solution.maximumLength(**test_input) == -1\n\ntest_input = { \"s\": \"giii\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"hhhn\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"hyyy\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"iiii\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"jiii\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"jjjj\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"kbbb\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"kddd\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"looo\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"nnnn\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"oaaa\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"osss\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"pppp\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"pppw\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"qqqc\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"qqqo\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"qqqq\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"reee\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"rzzz\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"thhh\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"tttt\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"unnn\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"uuuu\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"uyyy\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"vddd\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"vfff\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"vvvv\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"wbbb\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"wqqq\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"wwwg\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"xxxk\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"xxxx\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"zfff\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"ammmm\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"aqqqu\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"axxxx\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"bahhh\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"bbbbz\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"bbccc\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"biaei\" }\nassert my_solution.maximumLength(**test_input) == -1\n\ntest_input = { \"s\": \"bjjjj\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"cccll\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"ceaaa\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"cjlll\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"crqqq\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"cyyyy\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"ddddj\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"ddddt\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"dkkkk\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"eefff\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"efage\" }\nassert my_solution.maximumLength(**test_input) == -1\n\ntest_input = { \"s\": \"epppp\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"fafff\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"ffbbb\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"ffffr\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"gcgbf\" }\nassert my_solution.maximumLength(**test_input) == -1\n\ntest_input = { \"s\": \"gcooo\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"gfgec\" }\nassert my_solution.maximumLength(**test_input) == -1", "start_time": 1703989800} +{"task_id": "weekly-contest-378-find-longest-special-substring-that-occurs-thrice-ii", "url": "https://leetcode.com/problems/find-longest-special-substring-that-occurs-thrice-ii", "title": "find-longest-special-substring-that-occurs-thrice-ii", "meta": {"questionId": "3266", "questionFrontendId": "2982", "title": "Find Longest Special Substring That Occurs Thrice II", "titleSlug": "find-longest-special-substring-that-occurs-thrice-ii", "isPaidOnly": false, "difficulty": "Medium", "likes": 172, "dislikes": 17, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个仅由小写英文字母组成的字符串 s 。\n如果一个字符串仅由单一字符组成,那么它被称为 特殊 字符串。例如,字符串 \"abc\" 不是特殊字符串,而字符串 \"ddd\"、\"zz\" 和 \"f\" 是特殊字符串。\n返回在 s 中出现 至少三次 的 最长特殊子字符串 的长度,如果不存在出现至少三次的特殊子字符串,则返回 -1 。\n子字符串 是字符串中的一个连续 非空 字符序列。\n\n示例 1:\n\n输入:s = \"aaaa\"\n输出:2\n解释:出现三次的最长特殊子字符串是 \"aa\" :子字符串 \"aaaa\"、\"aaaa\" 和 \"aaaa\"。\n可以证明最大长度是 2 。\n\n示例 2:\n\n输入:s = \"abcdef\"\n输出:-1\n解释:不存在出现至少三次的特殊子字符串。因此返回 -1 。\n\n示例 3:\n\n输入:s = \"abcaba\"\n输出:1\n解释:出现三次的最长特殊子字符串是 \"a\" :子字符串 \"abcaba\"、\"abcaba\" 和 \"abcaba\"。\n可以证明最大长度是 1 。\n\n\n提示:\n\n3 <= s.length <= 5 * 105\ns 仅由小写英文字母组成。\n\"\"\"\nclass Solution:\n def maximumLength(self, s: str) -> int:\n ", "prompt_sft": "给你一个仅由小写英文字母组成的字符串 s 。\n如果一个字符串仅由单一字符组成,那么它被称为 特殊 字符串。例如,字符串 \"abc\" 不是特殊字符串,而字符串 \"ddd\"、\"zz\" 和 \"f\" 是特殊字符串。\n返回在 s 中出现 至少三次 的 最长特殊子字符串 的长度,如果不存在出现至少三次的特殊子字符串,则返回 -1 。\n子字符串 是字符串中的一个连续 非空 字符序列。\n\n示例 1:\n\n输入:s = \"aaaa\"\n输出:2\n解释:出现三次的最长特殊子字符串是 \"aa\" :子字符串 \"aaaa\"、\"aaaa\" 和 \"aaaa\"。\n可以证明最大长度是 2 。\n\n示例 2:\n\n输入:s = \"abcdef\"\n输出:-1\n解释:不存在出现至少三次的特殊子字符串。因此返回 -1 。\n\n示例 3:\n\n输入:s = \"abcaba\"\n输出:1\n解释:出现三次的最长特殊子字符串是 \"a\" :子字符串 \"abcaba\"、\"abcaba\" 和 \"abcaba\"。\n可以证明最大长度是 1 。\n\n\n提示:\n\n3 <= s.length <= 5 * 105\ns 仅由小写英文字母组成。\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def maximumLength(self, s: str) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"s\": \"aaaa\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"abcdef\" }\nassert my_solution.maximumLength(**test_input) == -1\n\ntest_input = { \"s\": \"abcaba\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"abcccccdddd\" }\nassert my_solution.maximumLength(**test_input) == 3\n\ntest_input = { \"s\": \"acd\" }\nassert my_solution.maximumLength(**test_input) == -1\n\ntest_input = { \"s\": \"bad\" }\nassert my_solution.maximumLength(**test_input) == -1\n\ntest_input = { \"s\": \"bbc\" }\nassert my_solution.maximumLength(**test_input) == -1\n\ntest_input = { \"s\": \"ccc\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"cda\" }\nassert my_solution.maximumLength(**test_input) == -1\n\ntest_input = { \"s\": \"dab\" }\nassert my_solution.maximumLength(**test_input) == -1\n\ntest_input = { \"s\": \"ddd\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"eee\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"fff\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"hhh\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"jjj\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"kkk\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"lll\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"mmm\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"nnn\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"ooo\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"ppp\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"qqq\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"rrr\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"sss\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"vvv\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"yyy\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"aaaj\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"aada\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"accc\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"auuu\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"azzz\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"bbbb\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"bbbr\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"bccc\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"brrr\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"cccc\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"clll\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"dbac\" }\nassert my_solution.maximumLength(**test_input) == -1\n\ntest_input = { \"s\": \"dddd\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"dddr\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"dddu\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"dzzz\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"eeee\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"efda\" }\nassert my_solution.maximumLength(**test_input) == -1\n\ntest_input = { \"s\": \"efdc\" }\nassert my_solution.maximumLength(**test_input) == -1\n\ntest_input = { \"s\": \"ekkk\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"ggge\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"gggp\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"gggr\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"gggy\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"guuu\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"hwww\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"hxxx\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"jjjj\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"jjjk\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"kkkk\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"lllm\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"lttt\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"mwww\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"nnnd\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"nnni\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"oooe\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"oooh\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"oooo\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"oooq\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"paaa\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"pggg\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"qooo\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"rrrr\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"smmm\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"thhh\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"tttt\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"uuuu\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"vppp\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"xqqq\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"xxxj\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"ysss\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"zzzz\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"aaaak\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"bbbjj\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"bbvvv\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"bfooo\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"buooo\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"cffff\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"cirrr\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"cwwwv\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"ddhhh\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"deeee\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"deiii\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"dtttk\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"eeeeq\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"eeekk\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"eesss\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"euuuu\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"euylz\" }\nassert my_solution.maximumLength(**test_input) == -1\n\ntest_input = { \"s\": \"fffhh\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"fpddd\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"gcccn\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"gtwww\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"hcfff\" }\nassert my_solution.maximumLength(**test_input) == 1", "start_time": 1703989800} +{"task_id": "weekly-contest-378-palindrome-rearrangement-queries", "url": "https://leetcode.com/problems/palindrome-rearrangement-queries", "title": "palindrome-rearrangement-queries", "meta": {"questionId": "3203", "questionFrontendId": "2983", "title": "Palindrome Rearrangement Queries", "titleSlug": "palindrome-rearrangement-queries", "isPaidOnly": false, "difficulty": "Hard", "likes": 73, "dislikes": 23, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个长度为 偶数n,下标从 0开始的字符串s。\n同时给你一个下标从 0开始的二维整数数组queries,其中queries[i] = [ai, bi, ci, di]。\n对于每个查询i,你需要执行以下操作:\n\n将下标在范围0 <= ai <= bi < n / 2内的子字符串s[ai:bi]中的字符重新排列。\n将下标在范围 n / 2 <= ci <= di < n内的 子字符串s[ci:di]中的字符重新排列。\n\n对于每个查询,你的任务是判断执行操作后能否让 s变成一个 回文串 。\n每个查询与其他查询都是 独立的。\n请你返回一个下标从 0开始的数组answer,如果第i个查询执行操作后,可以将s变为一个回文串,那么answer[i] =true,否则为false。\n\n子字符串指的是一个字符串中一段连续的字符序列。\ns[x:y]表示 s中从下标 x到 y且两个端点 都包含的子字符串。\n\n\n示例 1:\n\n输入:s = \"abcabc\", queries = [[1,1,3,5],[0,2,5,5]]\n输出:[true,true]\n解释:这个例子中,有 2 个查询:\n第一个查询:\n- a0 = 1, b0 = 1, c0 = 3, d0 = 5\n- 你可以重新排列 s[1:1] => abcabc 和 s[3:5] => abcabc。\n- 为了让 s 变为回文串,s[3:5] 可以重新排列得到 => abccba 。\n- 现在 s 是一个回文串。所以 answer[0] = true 。\n第二个查询:\n- a1 = 0, b1 = 2, c1 = 5, d1 = 5.\n- 你可以重新排列 s[0:2] => abcabc 和 s[5:5] => abcabc。\n- 为了让 s 变为回文串,s[0:2] 可以重新排列得到 => cbaabc 。\n- 现在 s 是一个回文串,所以 answer[1] = true 。\n\n示例 2:\n\n输入:s = \"abbcdecbba\", queries = [[0,2,7,9]]\n输出:[false]\n解释:这个示例中,只有一个查询。\na0 = 0, b0 = 2, c0 = 7, d0 = 9.\n你可以重新排列 s[0:2] => abbcdecbba 和 s[7:9] => abbcdecbba。\n无法通过重新排列这些子字符串使 s 变为一个回文串,因为 s[3:6] 不是一个回文串。\n所以 answer[0] = false 。\n示例 3:\n\n输入:s = \"acbcab\", queries = [[1,2,4,5]]\n输出:[true]\n解释:这个示例中,只有一个查询。\na0 = 1, b0 = 2, c0 = 4, d0 = 5.\n你可以重新排列 s[1:2] => acbcab 和 s[4:5] => acbcab。\n为了让 s 变为回文串,s[1:2] 可以重新排列得到 => abccab。\n然后 s[4:5] 重新排列得到 abccba。\n现在 s 是一个回文串,所以 answer[0] = true 。\n\n提示:\n\n2 <= n == s.length <= 105\n1 <= queries.length <= 105\nqueries[i].length == 4\nai == queries[i][0], bi == queries[i][1]\nci == queries[i][2], di == queries[i][3]\n0 <= ai <= bi < n / 2\nn / 2 <= ci <= di < n \nn是一个偶数。\ns 只包含小写英文字母。\n\"\"\"\nclass Solution:\n def canMakePalindromeQueries(self, s: str, queries: List[List[int]]) -> List[bool]:\n ", "prompt_sft": "给你一个长度为 偶数n,下标从 0开始的字符串s。\n同时给你一个下标从 0开始的二维整数数组queries,其中queries[i] = [ai, bi, ci, di]。\n对于每个查询i,你需要执行以下操作:\n\n将下标在范围0 <= ai <= bi < n / 2内的子字符串s[ai:bi]中的字符重新排列。\n将下标在范围 n / 2 <= ci <= di < n内的 子字符串s[ci:di]中的字符重新排列。\n\n对于每个查询,你的任务是判断执行操作后能否让 s变成一个 回文串 。\n每个查询与其他查询都是 独立的。\n请你返回一个下标从 0开始的数组answer,如果第i个查询执行操作后,可以将s变为一个回文串,那么answer[i] =true,否则为false。\n\n子字符串指的是一个字符串中一段连续的字符序列。\ns[x:y]表示 s中从下标 x到 y且两个端点 都包含的子字符串。\n\n\n示例 1:\n\n输入:s = \"abcabc\", queries = [[1,1,3,5],[0,2,5,5]]\n输出:[true,true]\n解释:这个例子中,有 2 个查询:\n第一个查询:\n- a0 = 1, b0 = 1, c0 = 3, d0 = 5\n- 你可以重新排列 s[1:1] => abcabc 和 s[3:5] => abcabc。\n- 为了让 s 变为回文串,s[3:5] 可以重新排列得到 => abccba 。\n- 现在 s 是一个回文串。所以 answer[0] = true 。\n第二个查询:\n- a1 = 0, b1 = 2, c1 = 5, d1 = 5.\n- 你可以重新排列 s[0:2] => abcabc 和 s[5:5] => abcabc。\n- 为了让 s 变为回文串,s[0:2] 可以重新排列得到 => cbaabc 。\n- 现在 s 是一个回文串,所以 answer[1] = true 。\n\n示例 2:\n\n输入:s = \"abbcdecbba\", queries = [[0,2,7,9]]\n输出:[false]\n解释:这个示例中,只有一个查询。\na0 = 0, b0 = 2, c0 = 7, d0 = 9.\n你可以重新排列 s[0:2] => abbcdecbba 和 s[7:9] => abbcdecbba。\n无法通过重新排列这些子字符串使 s 变为一个回文串,因为 s[3:6] 不是一个回文串。\n所以 answer[0] = false 。\n示例 3:\n\n输入:s = \"acbcab\", queries = [[1,2,4,5]]\n输出:[true]\n解释:这个示例中,只有一个查询。\na0 = 1, b0 = 2, c0 = 4, d0 = 5.\n你可以重新排列 s[1:2] => acbcab 和 s[4:5] => acbcab。\n为了让 s 变为回文串,s[1:2] 可以重新排列得到 => abccab。\n然后 s[4:5] 重新排列得到 abccba。\n现在 s 是一个回文串,所以 answer[0] = true 。\n\n提示:\n\n2 <= n == s.length <= 105\n1 <= queries.length <= 105\nqueries[i].length == 4\nai == queries[i][0], bi == queries[i][1]\nci == queries[i][2], di == queries[i][3]\n0 <= ai <= bi < n / 2\nn / 2 <= ci <= di < n \nn是一个偶数。\ns 只包含小写英文字母。\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def canMakePalindromeQueries(self, s: str, queries: List[List[int]]) -> List[bool]:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"s\": \"abcabc\", \"queries\": [[1,1,3,5],[0,2,5,5]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True,True]\n\ntest_input = { \"s\": \"abbcdecbba\", \"queries\": [[0,2,7,9]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False]\n\ntest_input = { \"s\": \"acbcab\", \"queries\": [[1,2,4,5]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True]\n\ntest_input = { \"s\": \"bcdbdc\", \"queries\": [[1,2,3,3]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False]\n\ntest_input = { \"s\": \"bb\", \"queries\": [[0,0,1,1]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True]\n\ntest_input = { \"s\": \"eoquueqo\", \"queries\": [[3,3,6,6]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False]\n\ntest_input = { \"s\": \"dd\", \"queries\": [[0,0,1,1]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True]\n\ntest_input = { \"s\": \"ceddceddcc\", \"queries\": [[0,1,6,8]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False]\n\ntest_input = { \"s\": \"bdbd\", \"queries\": [[0,0,2,3]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True]\n\ntest_input = { \"s\": \"eeee\", \"queries\": [[0,1,2,3]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True]\n\ntest_input = { \"s\": \"deebdeeddb\", \"queries\": [[1,2,5,7]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False]\n\ntest_input = { \"s\": \"xwaswsxwaw\", \"queries\": [[1,3,5,6]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False]\n\ntest_input = { \"s\": \"askloakosala\", \"queries\": [[2,4,7,10]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False]\n\ntest_input = { \"s\": \"bbccbb\", \"queries\": [[0,1,4,5]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True]\n\ntest_input = { \"s\": \"djaypzjpyzad\", \"queries\": [[0,3,7,8]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False]\n\ntest_input = { \"s\": \"ajvnbnznjnzbva\", \"queries\": [[5,6,10,11]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False]\n\ntest_input = { \"s\": \"vbeptwzvtwpzbe\", \"queries\": [[3,6,10,11]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False]\n\ntest_input = { \"s\": \"cababc\", \"queries\": [[1,2,3,4]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True]\n\ntest_input = { \"s\": \"cbbbbc\", \"queries\": [[1,1,5,5]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True]\n\ntest_input = { \"s\": \"qupzexxhqxpzhxeu\", \"queries\": [[2,4,8,12]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False]\n\ntest_input = { \"s\": \"cdbdbc\", \"queries\": [[1,2,3,3]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True]\n\ntest_input = { \"s\": \"odaxusaweuasuoeudxwa\", \"queries\": [[0,5,10,14]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False]\n\ntest_input = { \"s\": \"ujfscqolkwjucoswlkfq\", \"queries\": [[1,9,17,18]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False]\n\ntest_input = { \"s\": \"ceacea\", \"queries\": [[0,2,3,5]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True]\n\ntest_input = { \"s\": \"bnjzcgmnecxxbmnjngxzecxc\", \"queries\": [[8,9,19,22]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False]\n\ntest_input = { \"s\": \"daeaed\", \"queries\": [[0,2,3,3]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True]\n\ntest_input = { \"s\": \"ddaadd\", \"queries\": [[0,2,3,4]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True]\n\ntest_input = { \"s\": \"ddedde\", \"queries\": [[0,2,4,5]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True]\n\ntest_input = { \"s\": \"pmzwetzhzursuhmeswpzrztz\", \"queries\": [[4,6,16,17]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False]\n\ntest_input = { \"s\": \"qcryjkdzmqyoojzrckymdqyq\", \"queries\": [[2,8,21,22]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False]\n\ntest_input = { \"s\": \"qdltkndnclarncadtqnlldkr\", \"queries\": [[3,4,15,16]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False]\n\ntest_input = { \"s\": \"ecbbce\", \"queries\": [[0,1,3,5]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True]\n\ntest_input = { \"s\": \"eczecz\", \"queries\": [[0,0,3,5]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True]\n\ntest_input = { \"s\": \"etuouqokbalafokfbuqaaoetlu\", \"queries\": [[3,11,21,23]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False]\n\ntest_input = { \"s\": \"mpepem\", \"queries\": [[0,2,3,4]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True]\n\ntest_input = { \"s\": \"nbpechkpmudbsenphdmsbbupck\", \"queries\": [[6,7,18,19]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False]\n\ntest_input = { \"s\": \"bccacacb\", \"queries\": [[3,3,4,7]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True]\n\ntest_input = { \"s\": \"stgjtzqwgkuadjgqugkwdtzast\", \"queries\": [[5,10,13,23]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False]\n\ntest_input = { \"s\": \"qiyikbayvhkcgxyaqckgxkhivbyi\", \"queries\": [[5,12,17,24]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False]\n\ntest_input = { \"s\": \"ceedceed\", \"queries\": [[0,1,4,7]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True]\n\ntest_input = { \"s\": \"rcguwczbjhjhgqrggqcbwjzhjuch\", \"queries\": [[5,7,16,20]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False]\n\ntest_input = { \"s\": \"ckwbnmqmtzbixrrkixbtbqzmnwmc\", \"queries\": [[1,9,15,24]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True]\n\ntest_input = { \"s\": \"riirxzxuqpspoiixpirsoxrzpiuq\", \"queries\": [[1,6,14,21]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False]\n\ntest_input = { \"s\": \"geettndnusqufidtqdfgtsieenundu\", \"queries\": [[6,8,19,23]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False]\n\ntest_input = { \"s\": \"bb\", \"queries\": [[0,0,1,1],[0,0,1,1]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True,True]\n\ntest_input = { \"s\": \"cc\", \"queries\": [[0,0,1,1],[0,0,1,1]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True,True]\n\ntest_input = { \"s\": \"dd\", \"queries\": [[0,0,1,1],[0,0,1,1]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True,True]\n\ntest_input = { \"s\": \"ee\", \"queries\": [[0,0,1,1],[0,0,1,1]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True,True]\n\ntest_input = { \"s\": \"aeae\", \"queries\": [[1,1,2,3],[1,1,3,3]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True,False]\n\ntest_input = { \"s\": \"eaae\", \"queries\": [[0,1,3,3],[0,0,2,3]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True,True]\n\ntest_input = { \"s\": \"eded\", \"queries\": [[0,1,2,3],[1,1,2,3]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True,True]\n\ntest_input = { \"s\": \"lrlr\", \"queries\": [[0,1,2,3],[0,0,2,2]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True,False]\n\ntest_input = { \"s\": \"dbaabd\", \"queries\": [[0,1,5,5],[1,2,4,5]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True,True]\n\ntest_input = { \"s\": \"dcbcbd\", \"queries\": [[0,1,4,4],[0,2,3,4]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,True]\n\ntest_input = { \"s\": \"hykkyh\", \"queries\": [[0,0,3,4],[1,2,3,4]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True,True]\n\ntest_input = { \"s\": \"lvrvrl\", \"queries\": [[2,2,4,5],[0,2,3,4]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,True]\n\ntest_input = { \"s\": \"adceaecd\", \"queries\": [[3,3,5,5],[0,1,4,6]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,True]\n\ntest_input = { \"s\": \"baadadba\", \"queries\": [[1,2,4,5],[0,2,4,5]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,True]\n\ntest_input = { \"s\": \"bceaabec\", \"queries\": [[1,3,4,7],[0,2,6,6]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True,True]\n\ntest_input = { \"s\": \"ifchcifh\", \"queries\": [[1,2,5,6],[1,1,4,6]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,False]\n\ntest_input = { \"s\": \"adeeeeeaed\", \"queries\": [[2,4,7,9],[3,4,8,8]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True,False]\n\ntest_input = { \"s\": \"aedbdbddea\", \"queries\": [[4,4,7,8],[2,2,8,9]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,False]\n\ntest_input = { \"s\": \"caeaaaaaec\", \"queries\": [[0,2,5,8],[0,0,5,9]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True,True]\n\ntest_input = { \"s\": \"dbaccccdba\", \"queries\": [[4,4,6,7],[2,3,8,9]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,False]\n\ntest_input = { \"s\": \"deabadabea\", \"queries\": [[0,3,7,9],[0,2,5,7]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,True]\n\ntest_input = { \"s\": \"eddeededee\", \"queries\": [[0,3,6,9],[0,0,6,9]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,False]\n\ntest_input = { \"s\": \"eedbbedebb\", \"queries\": [[2,2,6,7],[2,2,5,6]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,False]\n\ntest_input = { \"s\": \"gvtkakgvat\", \"queries\": [[1,2,7,7],[2,3,7,9]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,False]\n\ntest_input = { \"s\": \"bzvvicviczbv\", \"queries\": [[1,2,7,8],[1,4,7,8]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,False]\n\ntest_input = { \"s\": \"ljccjajcljac\", \"queries\": [[2,4,6,10],[3,5,7,9]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,False]\n\ntest_input = { \"s\": \"rxvzvezvrvxe\", \"queries\": [[1,4,8,10],[3,3,10,11]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,False]\n\ntest_input = { \"s\": \"amgpelwpmlaewg\", \"queries\": [[3,4,7,9],[0,6,7,10]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,True]\n\ntest_input = { \"s\": \"leubdglmbglleudm\", \"queries\": [[1,3,9,14],[2,6,13,14]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,False]\n\ntest_input = { \"s\": \"ooxuznriuzrooixn\", \"queries\": [[1,3,10,12],[1,4,9,13]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,False]\n\ntest_input = { \"s\": \"nlaonaphinpnalohai\", \"queries\": [[2,5,13,13],[2,7,9,14]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,False]\n\ntest_input = { \"s\": \"rujokutobuttlysjusrtltuobkoytu\", \"queries\": [[5,6,18,23],[10,13,15,26]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,False]\n\ntest_input = { \"s\": \"bb\", \"queries\": [[0,0,1,1],[0,0,1,1],[0,0,1,1]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True,True,True]\n\ntest_input = { \"s\": \"cc\", \"queries\": [[0,0,1,1],[0,0,1,1],[0,0,1,1]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True,True,True]\n\ntest_input = { \"s\": \"dbdb\", \"queries\": [[0,0,2,2],[1,1,3,3],[0,1,2,3]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,False,True]\n\ntest_input = { \"s\": \"ebbe\", \"queries\": [[0,1,3,3],[1,1,2,2],[0,0,2,3]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True,True,True]\n\ntest_input = { \"s\": \"acacaa\", \"queries\": [[0,1,5,5],[1,1,4,4],[1,2,3,4]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,False,True]\n\ntest_input = { \"s\": \"bbaabb\", \"queries\": [[0,1,4,5],[0,2,3,5],[2,2,5,5]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True,True,True]\n\ntest_input = { \"s\": \"bbebbe\", \"queries\": [[0,1,3,5],[2,2,4,5],[0,1,5,5]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True,False,False]\n\ntest_input = { \"s\": \"ddaadd\", \"queries\": [[1,1,4,4],[0,0,4,4],[0,2,3,5]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True,True,True]\n\ntest_input = { \"s\": \"nlhhln\", \"queries\": [[2,2,4,5],[1,2,5,5],[2,2,3,3]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True,True,True]\n\ntest_input = { \"s\": \"zbebez\", \"queries\": [[0,2,5,5],[1,1,3,5],[0,2,4,5]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True,True,True]\n\ntest_input = { \"s\": \"cbcbbcbc\", \"queries\": [[0,2,7,7],[1,2,4,7],[0,2,4,5]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True,True,True]\n\ntest_input = { \"s\": \"deceecde\", \"queries\": [[3,3,6,7],[1,2,4,5],[2,3,7,7]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True,False,False]\n\ntest_input = { \"s\": \"fydyfyyd\", \"queries\": [[0,2,4,6],[1,3,4,7],[2,3,6,7]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True,True,False]\n\ntest_input = { \"s\": \"dccabcdbca\", \"queries\": [[1,3,5,8],[2,4,7,7],[0,2,6,9]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,False,False]\n\ntest_input = { \"s\": \"eacbdeacbd\", \"queries\": [[4,4,8,9],[3,4,7,9],[0,0,6,8]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,False,False]\n\ntest_input = { \"s\": \"eddaaedada\", \"queries\": [[0,1,7,8],[0,1,7,8],[0,3,7,9]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,False,False]\n\ntest_input = { \"s\": \"vvsbgsvgbv\", \"queries\": [[0,1,6,9],[2,3,8,9],[0,0,6,7]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,False,False]\n\ntest_input = { \"s\": \"sukesivksseuiv\", \"queries\": [[2,3,11,13],[5,5,7,13],[2,5,8,13]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,True,False]\n\ntest_input = { \"s\": \"pbcjpsfxwtbcfjwpsptx\", \"queries\": [[0,4,13,13],[5,5,15,18],[2,3,13,18]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,False,False]\n\ntest_input = { \"s\": \"natvhtruvwyutyvvnarhwt\", \"queries\": [[5,7,14,21],[0,8,11,19],[2,8,11,14]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,False,False]\n\ntest_input = { \"s\": \"yjsjywxbriejyxieysrwbj\", \"queries\": [[4,5,15,19],[1,9,12,17],[3,6,12,18]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,False,False]\n\ntest_input = { \"s\": \"ellaghdbmazdallhmegabddz\", \"queries\": [[4,6,13,19],[4,11,17,17],[7,10,13,16]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,False,False]\n\ntest_input = { \"s\": \"wcfnhuaulqxbuuxafcwhnbql\", \"queries\": [[5,11,13,18],[7,8,18,21],[3,6,21,23]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,False,False]\n\ntest_input = { \"s\": \"qyioinjmvpgpropimvqiygrnjp\", \"queries\": [[1,4,15,25],[1,8,19,22],[4,9,18,23]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,False,False]", "start_time": 1703989800} +{"task_id": "weekly-contest-377-minimum-number-game", "url": "https://leetcode.com/problems/minimum-number-game", "title": "minimum-number-game", "meta": {"questionId": "3226", "questionFrontendId": "2974", "title": "Minimum Number Game", "titleSlug": "minimum-number-game", "isPaidOnly": false, "difficulty": "Easy", "likes": 38, "dislikes": 2, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n你有一个下标从 0 开始、长度为 偶数 的整数数组 nums ,同时还有一个空数组 arr 。Alice 和 Bob 决定玩一个游戏,游戏中每一轮 Alice 和 Bob 都会各自执行一次操作。游戏规则如下:\n\n每一轮,Alice 先从 nums 中移除一个 最小 元素,然后 Bob 执行同样的操作。\n接着,Bob 会将移除的元素添加到数组 arr 中,然后 Alice 也执行同样的操作。\n游戏持续进行,直到 nums 变为空。\n\n返回结果数组 arr 。\n\n示例 1:\n\n输入:nums = [5,4,2,3]\n输出:[3,2,5,4]\n解释:第一轮,Alice 先移除 2 ,然后 Bob 移除 3 。然后 Bob 先将 3 添加到 arr 中,接着 Alice 再将 2 添加到 arr 中。于是 arr = [3,2] 。\n第二轮开始时,nums = [5,4] 。Alice 先移除 4 ,然后 Bob 移除 5 。接着他们都将元素添加到 arr 中,arr 变为 [3,2,5,4] 。\n\n示例 2:\n\n输入:nums = [2,5]\n输出:[5,2]\n解释:第一轮,Alice 先移除 2 ,然后 Bob 移除 5 。然后 Bob 先将 5 添加到 arr 中,接着 Alice 再将 2 添加到 arr 中。于是 arr = [5,2] 。\n\n\n提示:\n\n1 <= nums.length <= 100\n1 <= nums[i] <= 100\nnums.length % 2 == 0\n\"\"\"\nclass Solution:\n def numberGame(self, nums: List[int]) -> List[int]:\n ", "prompt_sft": "你有一个下标从 0 开始、长度为 偶数 的整数数组 nums ,同时还有一个空数组 arr 。Alice 和 Bob 决定玩一个游戏,游戏中每一轮 Alice 和 Bob 都会各自执行一次操作。游戏规则如下:\n\n每一轮,Alice 先从 nums 中移除一个 最小 元素,然后 Bob 执行同样的操作。\n接着,Bob 会将移除的元素添加到数组 arr 中,然后 Alice 也执行同样的操作。\n游戏持续进行,直到 nums 变为空。\n\n返回结果数组 arr 。\n\n示例 1:\n\n输入:nums = [5,4,2,3]\n输出:[3,2,5,4]\n解释:第一轮,Alice 先移除 2 ,然后 Bob 移除 3 。然后 Bob 先将 3 添加到 arr 中,接着 Alice 再将 2 添加到 arr 中。于是 arr = [3,2] 。\n第二轮开始时,nums = [5,4] 。Alice 先移除 4 ,然后 Bob 移除 5 。接着他们都将元素添加到 arr 中,arr 变为 [3,2,5,4] 。\n\n示例 2:\n\n输入:nums = [2,5]\n输出:[5,2]\n解释:第一轮,Alice 先移除 2 ,然后 Bob 移除 5 。然后 Bob 先将 5 添加到 arr 中,接着 Alice 再将 2 添加到 arr 中。于是 arr = [5,2] 。\n\n\n提示:\n\n1 <= nums.length <= 100\n1 <= nums[i] <= 100\nnums.length % 2 == 0\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def numberGame(self, nums: List[int]) -> List[int]:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [5,4,2,3] }\nassert my_solution.numberGame(**test_input) == [3,2,5,4]\n\ntest_input = { \"nums\": [2,5] }\nassert my_solution.numberGame(**test_input) == [5,2]\n\ntest_input = { \"nums\": [4,4,3,8] }\nassert my_solution.numberGame(**test_input) == [4,3,8,4]\n\ntest_input = { \"nums\": [2,5,3,8] }\nassert my_solution.numberGame(**test_input) == [3,2,8,5]\n\ntest_input = { \"nums\": [2,7,9,6,4,6] }\nassert my_solution.numberGame(**test_input) == [4,2,6,6,9,7]\n\ntest_input = { \"nums\": [18,26,37,46,13,33,39,1,37,16] }\nassert my_solution.numberGame(**test_input) == [13,1,18,16,33,26,37,37,46,39]\n\ntest_input = { \"nums\": [17,2,4,11,14,18] }\nassert my_solution.numberGame(**test_input) == [4,2,14,11,18,17]\n\ntest_input = { \"nums\": [20,30,12,3,11,17,32,12] }\nassert my_solution.numberGame(**test_input) == [11,3,12,12,20,17,32,30]\n\ntest_input = { \"nums\": [9,32,6,11,11,39,18,29,44,29] }\nassert my_solution.numberGame(**test_input) == [9,6,11,11,29,18,32,29,44,39]\n\ntest_input = { \"nums\": [7,2,3,4] }\nassert my_solution.numberGame(**test_input) == [3,2,7,4]\n\ntest_input = { \"nums\": [8,7,1,3] }\nassert my_solution.numberGame(**test_input) == [3,1,8,7]\n\ntest_input = { \"nums\": [2,6,6,6] }\nassert my_solution.numberGame(**test_input) == [6,2,6,6]\n\ntest_input = { \"nums\": [1,2] }\nassert my_solution.numberGame(**test_input) == [2,1]\n\ntest_input = { \"nums\": [4,1,1,3] }\nassert my_solution.numberGame(**test_input) == [1,1,4,3]\n\ntest_input = { \"nums\": [13,12,18,11,15,28,26,2] }\nassert my_solution.numberGame(**test_input) == [11,2,13,12,18,15,28,26]\n\ntest_input = { \"nums\": [14,30,29,3,23,21,26,23] }\nassert my_solution.numberGame(**test_input) == [14,3,23,21,26,23,30,29]\n\ntest_input = { \"nums\": [1,1] }\nassert my_solution.numberGame(**test_input) == [1,1]\n\ntest_input = { \"nums\": [2,1] }\nassert my_solution.numberGame(**test_input) == [2,1]\n\ntest_input = { \"nums\": [12,1,28,23,2,31,11,26] }\nassert my_solution.numberGame(**test_input) == [2,1,12,11,26,23,31,28]\n\ntest_input = { \"nums\": [21,11,37,1,40,50,49,45,28,47] }\nassert my_solution.numberGame(**test_input) == [11,1,28,21,40,37,47,45,50,49]\n\ntest_input = { \"nums\": [25,22,31,7,30,9,9,18] }\nassert my_solution.numberGame(**test_input) == [9,7,18,9,25,22,31,30]\n\ntest_input = { \"nums\": [2,4,10,9,16,9] }\nassert my_solution.numberGame(**test_input) == [4,2,9,9,16,10]\n\ntest_input = { \"nums\": [5,2,3,5] }\nassert my_solution.numberGame(**test_input) == [3,2,5,5]\n\ntest_input = { \"nums\": [6,44,37,6,28,44,30,36,25,24] }\nassert my_solution.numberGame(**test_input) == [6,6,25,24,30,28,37,36,44,44]\n\ntest_input = { \"nums\": [17,10,6,14,10,18] }\nassert my_solution.numberGame(**test_input) == [10,6,14,10,18,17]\n\ntest_input = { \"nums\": [40,24,23,29,37,26,39,34,39,23] }\nassert my_solution.numberGame(**test_input) == [23,23,26,24,34,29,39,37,40,39]\n\ntest_input = { \"nums\": [2,2] }\nassert my_solution.numberGame(**test_input) == [2,2]\n\ntest_input = { \"nums\": [33,5,31,43,48,18,31,11,19,8] }\nassert my_solution.numberGame(**test_input) == [8,5,18,11,31,19,33,31,48,43]\n\ntest_input = { \"nums\": [37,46,42,19,10,8,43,10,40,13] }\nassert my_solution.numberGame(**test_input) == [10,8,13,10,37,19,42,40,46,43]\n\ntest_input = { \"nums\": [2,19,8,22,1,27,29,7] }\nassert my_solution.numberGame(**test_input) == [2,1,8,7,22,19,29,27]\n\ntest_input = { \"nums\": [2,3,2,3] }\nassert my_solution.numberGame(**test_input) == [2,2,3,3]\n\ntest_input = { \"nums\": [1,4,7,14,8,14] }\nassert my_solution.numberGame(**test_input) == [4,1,8,7,14,14]\n\ntest_input = { \"nums\": [28,47,36,34,19,7,40,46,33,43] }\nassert my_solution.numberGame(**test_input) == [19,7,33,28,36,34,43,40,47,46]\n\ntest_input = { \"nums\": [29,41,20,22,16,27,22,44,10,47] }\nassert my_solution.numberGame(**test_input) == [16,10,22,20,27,22,41,29,47,44]\n\ntest_input = { \"nums\": [14,6,40,19,47,46,34,27,28,10] }\nassert my_solution.numberGame(**test_input) == [10,6,19,14,28,27,40,34,47,46]\n\ntest_input = { \"nums\": [42,43,50,43,36,26,16,12,3,2] }\nassert my_solution.numberGame(**test_input) == [3,2,16,12,36,26,43,42,50,43]\n\ntest_input = { \"nums\": [1,7,24,24,23,32,28,2] }\nassert my_solution.numberGame(**test_input) == [2,1,23,7,24,24,32,28]\n\ntest_input = { \"nums\": [20,19,16,16,19,29,21,5] }\nassert my_solution.numberGame(**test_input) == [16,5,19,16,20,19,29,21]\n\ntest_input = { \"nums\": [20,9,29,29,17,39,27,44,1,8] }\nassert my_solution.numberGame(**test_input) == [8,1,17,9,27,20,29,29,44,39]\n\ntest_input = { \"nums\": [14,11,12,18,9,15] }\nassert my_solution.numberGame(**test_input) == [11,9,14,12,18,15]\n\ntest_input = { \"nums\": [17,22,2,35,15,19,25,5,33,44] }\nassert my_solution.numberGame(**test_input) == [5,2,17,15,22,19,33,25,44,35]\n\ntest_input = { \"nums\": [22,3,26,15,1,5,14,28] }\nassert my_solution.numberGame(**test_input) == [3,1,14,5,22,15,28,26]\n\ntest_input = { \"nums\": [5,24,3,2,17,9,2,4] }\nassert my_solution.numberGame(**test_input) == [2,2,4,3,9,5,24,17]\n\ntest_input = { \"nums\": [2,6,4,7] }\nassert my_solution.numberGame(**test_input) == [4,2,7,6]\n\ntest_input = { \"nums\": [1,33,29,21,25,14,26,35,34,30] }\nassert my_solution.numberGame(**test_input) == [14,1,25,21,29,26,33,30,35,34]\n\ntest_input = { \"nums\": [50,25,42,41,16,23,47,31,23,16] }\nassert my_solution.numberGame(**test_input) == [16,16,23,23,31,25,42,41,50,47]\n\ntest_input = { \"nums\": [31,31,31,12,24,17,11,3,33,13] }\nassert my_solution.numberGame(**test_input) == [11,3,13,12,24,17,31,31,33,31]\n\ntest_input = { \"nums\": [8,3,2,7] }\nassert my_solution.numberGame(**test_input) == [3,2,8,7]\n\ntest_input = { \"nums\": [8,2,8,6] }\nassert my_solution.numberGame(**test_input) == [6,2,8,8]\n\ntest_input = { \"nums\": [4,15,16,2,12,7] }\nassert my_solution.numberGame(**test_input) == [4,2,12,7,16,15]\n\ntest_input = { \"nums\": [5,4,2,4] }\nassert my_solution.numberGame(**test_input) == [4,2,5,4]\n\ntest_input = { \"nums\": [17,13,7,12,19,15,6,22] }\nassert my_solution.numberGame(**test_input) == [7,6,13,12,17,15,22,19]\n\ntest_input = { \"nums\": [2,15,12,16,12,13] }\nassert my_solution.numberGame(**test_input) == [12,2,13,12,16,15]\n\ntest_input = { \"nums\": [3,15,18,16,6,7] }\nassert my_solution.numberGame(**test_input) == [6,3,15,7,18,16]\n\ntest_input = { \"nums\": [4,7,11,6,11,8] }\nassert my_solution.numberGame(**test_input) == [6,4,8,7,11,11]\n\ntest_input = { \"nums\": [1,7,24,23,16,21,9,11] }\nassert my_solution.numberGame(**test_input) == [7,1,11,9,21,16,24,23]\n\ntest_input = { \"nums\": [6,3,10,16,15,6] }\nassert my_solution.numberGame(**test_input) == [6,3,10,6,16,15]\n\ntest_input = { \"nums\": [17,9,1,29,30,5,31,26] }\nassert my_solution.numberGame(**test_input) == [5,1,17,9,29,26,31,30]\n\ntest_input = { \"nums\": [3,6,4,14,9,15] }\nassert my_solution.numberGame(**test_input) == [4,3,9,6,15,14]\n\ntest_input = { \"nums\": [37,38,24,15,12,1,37,19,38,11] }\nassert my_solution.numberGame(**test_input) == [11,1,15,12,24,19,37,37,38,38]\n\ntest_input = { \"nums\": [17,3,8,12,6,9] }\nassert my_solution.numberGame(**test_input) == [6,3,9,8,17,12]\n\ntest_input = { \"nums\": [32,23,27,32,24,26,24,27] }\nassert my_solution.numberGame(**test_input) == [24,23,26,24,27,27,32,32]\n\ntest_input = { \"nums\": [15,16,26,6,5,9,22,14] }\nassert my_solution.numberGame(**test_input) == [6,5,14,9,16,15,26,22]\n\ntest_input = { \"nums\": [14,21,13,10,2,16,14,30] }\nassert my_solution.numberGame(**test_input) == [10,2,14,13,16,14,30,21]\n\ntest_input = { \"nums\": [1,6,30,1,13,25,18,1] }\nassert my_solution.numberGame(**test_input) == [1,1,6,1,18,13,30,25]\n\ntest_input = { \"nums\": [32,12,17,32,11,25,22,18,10,1] }\nassert my_solution.numberGame(**test_input) == [10,1,12,11,18,17,25,22,32,32]\n\ntest_input = { \"nums\": [2,8,5,6] }\nassert my_solution.numberGame(**test_input) == [5,2,8,6]\n\ntest_input = { \"nums\": [27,3,10,25,10,7,15,16] }\nassert my_solution.numberGame(**test_input) == [7,3,10,10,16,15,27,25]\n\ntest_input = { \"nums\": [5,18,19,25,13,21,16,7] }\nassert my_solution.numberGame(**test_input) == [7,5,16,13,19,18,25,21]\n\ntest_input = { \"nums\": [8,6,6,8] }\nassert my_solution.numberGame(**test_input) == [6,6,8,8]\n\ntest_input = { \"nums\": [23,15,39,9,19,10,6,9,33,28] }\nassert my_solution.numberGame(**test_input) == [9,6,10,9,19,15,28,23,39,33]\n\ntest_input = { \"nums\": [16,42,47,16,31,39,8,26,50,33] }\nassert my_solution.numberGame(**test_input) == [16,8,26,16,33,31,42,39,50,47]\n\ntest_input = { \"nums\": [4,31,9,2,4,28,28,12] }\nassert my_solution.numberGame(**test_input) == [4,2,9,4,28,12,31,28]\n\ntest_input = { \"nums\": [9,5,8,11,4,7] }\nassert my_solution.numberGame(**test_input) == [5,4,8,7,11,9]\n\ntest_input = { \"nums\": [44,2,23,3,7,2,36,33,7,21] }\nassert my_solution.numberGame(**test_input) == [2,2,7,3,21,7,33,23,44,36]\n\ntest_input = { \"nums\": [19,9,4,7,29,22,50,28,2,40] }\nassert my_solution.numberGame(**test_input) == [4,2,9,7,22,19,29,28,50,40]\n\ntest_input = { \"nums\": [4,5,5,5] }\nassert my_solution.numberGame(**test_input) == [5,4,5,5]\n\ntest_input = { \"nums\": [42,6,44,47,11,6,30,38,41,43] }\nassert my_solution.numberGame(**test_input) == [6,6,30,11,41,38,43,42,47,44]\n\ntest_input = { \"nums\": [28,4,47,1,7,35,10,10,5,8] }\nassert my_solution.numberGame(**test_input) == [4,1,7,5,10,8,28,10,47,35]\n\ntest_input = { \"nums\": [12,20,14,46,22,1,42,50,47,47] }\nassert my_solution.numberGame(**test_input) == [12,1,20,14,42,22,47,46,50,47]\n\ntest_input = { \"nums\": [37,13,1,38,28,46,18,22,12,7] }\nassert my_solution.numberGame(**test_input) == [7,1,13,12,22,18,37,28,46,38]\n\ntest_input = { \"nums\": [36,41,5,33,5,30,33,31,6,45] }\nassert my_solution.numberGame(**test_input) == [5,5,30,6,33,31,36,33,45,41]\n\ntest_input = { \"nums\": [13,50,42,24,47,41,8,26,34,3] }\nassert my_solution.numberGame(**test_input) == [8,3,24,13,34,26,42,41,50,47]\n\ntest_input = { \"nums\": [24,39,26,46,47,9,33,6,33,40] }\nassert my_solution.numberGame(**test_input) == [9,6,26,24,33,33,40,39,47,46]\n\ntest_input = { \"nums\": [14,13,17,14,12,15,6,32] }\nassert my_solution.numberGame(**test_input) == [12,6,14,13,15,14,32,17]\n\ntest_input = { \"nums\": [46,50,35,11,14,44,17,45,23,34] }\nassert my_solution.numberGame(**test_input) == [14,11,23,17,35,34,45,44,50,46]\n\ntest_input = { \"nums\": [8,27,19,7,10,12,14,50,45,14] }\nassert my_solution.numberGame(**test_input) == [8,7,12,10,14,14,27,19,50,45]\n\ntest_input = { \"nums\": [9,8,5,7,10,9] }\nassert my_solution.numberGame(**test_input) == [7,5,9,8,10,9]\n\ntest_input = { \"nums\": [5,5,3,7] }\nassert my_solution.numberGame(**test_input) == [5,3,7,5]\n\ntest_input = { \"nums\": [26,21,7,13,3,10,9,15] }\nassert my_solution.numberGame(**test_input) == [7,3,10,9,15,13,26,21]\n\ntest_input = { \"nums\": [8,5,8,3] }\nassert my_solution.numberGame(**test_input) == [5,3,8,8]\n\ntest_input = { \"nums\": [18,1,16,18,13,3] }\nassert my_solution.numberGame(**test_input) == [3,1,16,13,18,18]\n\ntest_input = { \"nums\": [25,2,17,26,17,20,19,24] }\nassert my_solution.numberGame(**test_input) == [17,2,19,17,24,20,26,25]\n\ntest_input = { \"nums\": [24,1,18,25,29,17,9,3] }\nassert my_solution.numberGame(**test_input) == [3,1,17,9,24,18,29,25]\n\ntest_input = { \"nums\": [23,17,18,18,18,30,8,19] }\nassert my_solution.numberGame(**test_input) == [17,8,18,18,19,18,30,23]\n\ntest_input = { \"nums\": [12,13,13,18,5,16] }\nassert my_solution.numberGame(**test_input) == [12,5,13,13,18,16]\n\ntest_input = { \"nums\": [19,4,11,7,24,12,24,14] }\nassert my_solution.numberGame(**test_input) == [7,4,12,11,19,14,24,24]\n\ntest_input = { \"nums\": [28,11,11,29,18,2,6,32] }\nassert my_solution.numberGame(**test_input) == [6,2,11,11,28,18,32,29]\n\ntest_input = { \"nums\": [12,17,3,31,15,18,18,2] }\nassert my_solution.numberGame(**test_input) == [3,2,15,12,18,17,31,18]\n\ntest_input = { \"nums\": [24,6,21,30,29,8,23,18] }\nassert my_solution.numberGame(**test_input) == [8,6,21,18,24,23,30,29]", "start_time": 1703385000} +{"task_id": "weekly-contest-377-maximum-square-area-by-removing-fences-from-a-field", "url": "https://leetcode.com/problems/maximum-square-area-by-removing-fences-from-a-field", "title": "maximum-square-area-by-removing-fences-from-a-field", "meta": {"questionId": "3250", "questionFrontendId": "2975", "title": "Maximum Square Area by Removing Fences From a Field", "titleSlug": "maximum-square-area-by-removing-fences-from-a-field", "isPaidOnly": false, "difficulty": "Medium", "likes": 67, "dislikes": 68, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n有一个大型的 (m - 1) x (n - 1) 矩形田地,其两个对角分别是 (1, 1) 和 (m, n) ,田地内部有一些水平栅栏和垂直栅栏,分别由数组 hFences 和 vFences 给出。\n水平栅栏为坐标 (hFences[i], 1) 到 (hFences[i], n),垂直栅栏为坐标 (1, vFences[i]) 到 (m, vFences[i]) 。\n返回通过 移除 一些栅栏(可能不移除)所能形成的最大面积的 正方形 田地的面积,或者如果无法形成正方形田地则返回 -1。\n由于答案可能很大,所以请返回结果对 109 + 7 取余 后的值。\n注意:田地外围两个水平栅栏(坐标 (1, 1) 到 (1, n) 和坐标 (m, 1) 到 (m, n) )以及两个垂直栅栏(坐标 (1, 1) 到 (m, 1) 和坐标 (1, n) 到 (m, n) )所包围。这些栅栏 不能 被移除。\n\n示例 1:\n\n\n输入:m = 4, n = 3, hFences = [2,3], vFences = [2]\n输出:4\n解释:移除位于 2 的水平栅栏和位于 2 的垂直栅栏将得到一个面积为 4 的正方形田地。\n\n示例 2:\n\n\n输入:m = 6, n = 7, hFences = [2], vFences = [4]\n输出:-1\n解释:可以证明无法通过移除栅栏形成正方形田地。\n\n\n提示:\n\n3 <= m, n <= 109\n1 <= hFences.length, vFences.length <= 600\n1 < hFences[i] < m\n1 < vFences[i] < n\nhFences 和 vFences 中的元素是唯一的。\n\"\"\"\nclass Solution:\n def maximizeSquareArea(self, m: int, n: int, hFences: List[int], vFences: List[int]) -> int:\n ", "prompt_sft": "有一个大型的 (m - 1) x (n - 1) 矩形田地,其两个对角分别是 (1, 1) 和 (m, n) ,田地内部有一些水平栅栏和垂直栅栏,分别由数组 hFences 和 vFences 给出。\n水平栅栏为坐标 (hFences[i], 1) 到 (hFences[i], n),垂直栅栏为坐标 (1, vFences[i]) 到 (m, vFences[i]) 。\n返回通过 移除 一些栅栏(可能不移除)所能形成的最大面积的 正方形 田地的面积,或者如果无法形成正方形田地则返回 -1。\n由于答案可能很大,所以请返回结果对 109 + 7 取余 后的值。\n注意:田地外围两个水平栅栏(坐标 (1, 1) 到 (1, n) 和坐标 (m, 1) 到 (m, n) )以及两个垂直栅栏(坐标 (1, 1) 到 (m, 1) 和坐标 (1, n) 到 (m, n) )所包围。这些栅栏 不能 被移除。\n\n示例 1:\n\n\n输入:m = 4, n = 3, hFences = [2,3], vFences = [2]\n输出:4\n解释:移除位于 2 的水平栅栏和位于 2 的垂直栅栏将得到一个面积为 4 的正方形田地。\n\n示例 2:\n\n\n输入:m = 6, n = 7, hFences = [2], vFences = [4]\n输出:-1\n解释:可以证明无法通过移除栅栏形成正方形田地。\n\n\n提示:\n\n3 <= m, n <= 109\n1 <= hFences.length, vFences.length <= 600\n1 < hFences[i] < m\n1 < vFences[i] < n\nhFences 和 vFences 中的元素是唯一的。\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def maximizeSquareArea(self, m: int, n: int, hFences: List[int], vFences: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"m\": 4, \"n\": 3, \"hFences\": [2,3], \"vFences\": [2] }\nassert my_solution.maximizeSquareArea(**test_input) == 4\n\ntest_input = { \"m\": 6, \"n\": 7, \"hFences\": [2], \"vFences\": [4] }\nassert my_solution.maximizeSquareArea(**test_input) == -1\n\ntest_input = { \"m\": 4, \"n\": 4, \"hFences\": [2], \"vFences\": [2,3] }\nassert my_solution.maximizeSquareArea(**test_input) == 9\n\ntest_input = { \"m\": 8, \"n\": 5, \"hFences\": [5,4], \"vFences\": [4] }\nassert my_solution.maximizeSquareArea(**test_input) == 16\n\ntest_input = { \"m\": 4, \"n\": 5, \"hFences\": [2], \"vFences\": [4] }\nassert my_solution.maximizeSquareArea(**test_input) == 9\n\ntest_input = { \"m\": 5, \"n\": 6, \"hFences\": [4,2,3], \"vFences\": [4,5] }\nassert my_solution.maximizeSquareArea(**test_input) == 16\n\ntest_input = { \"m\": 3, \"n\": 9, \"hFences\": [2], \"vFences\": [8,6,5,4] }\nassert my_solution.maximizeSquareArea(**test_input) == 4\n\ntest_input = { \"m\": 6, \"n\": 4, \"hFences\": [3], \"vFences\": [3,2] }\nassert my_solution.maximizeSquareArea(**test_input) == 9\n\ntest_input = { \"m\": 7, \"n\": 4, \"hFences\": [2,3,6,5], \"vFences\": [3,2] }\nassert my_solution.maximizeSquareArea(**test_input) == 9\n\ntest_input = { \"m\": 8, \"n\": 8, \"hFences\": [2,3,6,7], \"vFences\": [6,5,7,4,2,3] }\nassert my_solution.maximizeSquareArea(**test_input) == 49\n\ntest_input = { \"m\": 9, \"n\": 9, \"hFences\": [2,4], \"vFences\": [6,4,2] }\nassert my_solution.maximizeSquareArea(**test_input) == 64\n\ntest_input = { \"m\": 7, \"n\": 7, \"hFences\": [4,3], \"vFences\": [2,6] }\nassert my_solution.maximizeSquareArea(**test_input) == 36\n\ntest_input = { \"m\": 4, \"n\": 6, \"hFences\": [2], \"vFences\": [3,4,2] }\nassert my_solution.maximizeSquareArea(**test_input) == 9\n\ntest_input = { \"m\": 8, \"n\": 6, \"hFences\": [7,5,2,4,3], \"vFences\": [5,3] }\nassert my_solution.maximizeSquareArea(**test_input) == 25\n\ntest_input = { \"m\": 9, \"n\": 3, \"hFences\": [7,4,5], \"vFences\": [2] }\nassert my_solution.maximizeSquareArea(**test_input) == 4\n\ntest_input = { \"m\": 4, \"n\": 3, \"hFences\": [3], \"vFences\": [2] }\nassert my_solution.maximizeSquareArea(**test_input) == 4\n\ntest_input = { \"m\": 4, \"n\": 3, \"hFences\": [3,2], \"vFences\": [2] }\nassert my_solution.maximizeSquareArea(**test_input) == 4\n\ntest_input = { \"m\": 8, \"n\": 6, \"hFences\": [6,4,3,7,2,5], \"vFences\": [5,3,4,2] }\nassert my_solution.maximizeSquareArea(**test_input) == 25\n\ntest_input = { \"m\": 8, \"n\": 8, \"hFences\": [6,3,7,5], \"vFences\": [6,2,7] }\nassert my_solution.maximizeSquareArea(**test_input) == 49\n\ntest_input = { \"m\": 5, \"n\": 5, \"hFences\": [4,3], \"vFences\": [4] }\nassert my_solution.maximizeSquareArea(**test_input) == 16\n\ntest_input = { \"m\": 5, \"n\": 3, \"hFences\": [4], \"vFences\": [2] }\nassert my_solution.maximizeSquareArea(**test_input) == 1\n\ntest_input = { \"m\": 7, \"n\": 9, \"hFences\": [5], \"vFences\": [2,7,6,8,3] }\nassert my_solution.maximizeSquareArea(**test_input) == 36\n\ntest_input = { \"m\": 8, \"n\": 6, \"hFences\": [5,4,6,7,3], \"vFences\": [5,3] }\nassert my_solution.maximizeSquareArea(**test_input) == 25\n\ntest_input = { \"m\": 9, \"n\": 7, \"hFences\": [6,4,7,5,8], \"vFences\": [6,4,2,3] }\nassert my_solution.maximizeSquareArea(**test_input) == 36\n\ntest_input = { \"m\": 6, \"n\": 7, \"hFences\": [5], \"vFences\": [5,3,6] }\nassert my_solution.maximizeSquareArea(**test_input) == 25\n\ntest_input = { \"m\": 3, \"n\": 3, \"hFences\": [2], \"vFences\": [2] }\nassert my_solution.maximizeSquareArea(**test_input) == 4\n\ntest_input = { \"m\": 7, \"n\": 8, \"hFences\": [4,6,2,5,3], \"vFences\": [3,5,2,4,7] }\nassert my_solution.maximizeSquareArea(**test_input) == 36\n\ntest_input = { \"m\": 3, \"n\": 5, \"hFences\": [2], \"vFences\": [4,2] }\nassert my_solution.maximizeSquareArea(**test_input) == 4\n\ntest_input = { \"m\": 4, \"n\": 3, \"hFences\": [2], \"vFences\": [2] }\nassert my_solution.maximizeSquareArea(**test_input) == 4\n\ntest_input = { \"m\": 9, \"n\": 3, \"hFences\": [3], \"vFences\": [2] }\nassert my_solution.maximizeSquareArea(**test_input) == 4\n\ntest_input = { \"m\": 6, \"n\": 7, \"hFences\": [4,2,3,5], \"vFences\": [3,5,6] }\nassert my_solution.maximizeSquareArea(**test_input) == 25\n\ntest_input = { \"m\": 8, \"n\": 4, \"hFences\": [6,3,2,4,7,5], \"vFences\": [2,3] }\nassert my_solution.maximizeSquareArea(**test_input) == 9\n\ntest_input = { \"m\": 4, \"n\": 4, \"hFences\": [2], \"vFences\": [2] }\nassert my_solution.maximizeSquareArea(**test_input) == 9\n\ntest_input = { \"m\": 3, \"n\": 6, \"hFences\": [2], \"vFences\": [4,3,5] }\nassert my_solution.maximizeSquareArea(**test_input) == 4\n\ntest_input = { \"m\": 8, \"n\": 6, \"hFences\": [5], \"vFences\": [4,2,5] }\nassert my_solution.maximizeSquareArea(**test_input) == 16\n\ntest_input = { \"m\": 9, \"n\": 9, \"hFences\": [5,4,2], \"vFences\": [8,4,3,5,6] }\nassert my_solution.maximizeSquareArea(**test_input) == 64\n\ntest_input = { \"m\": 5, \"n\": 9, \"hFences\": [3,2,4], \"vFences\": [7,6,5] }\nassert my_solution.maximizeSquareArea(**test_input) == 16\n\ntest_input = { \"m\": 5, \"n\": 5, \"hFences\": [4,3,2], \"vFences\": [3,4,2] }\nassert my_solution.maximizeSquareArea(**test_input) == 16\n\ntest_input = { \"m\": 7, \"n\": 4, \"hFences\": [5,2,4], \"vFences\": [3] }\nassert my_solution.maximizeSquareArea(**test_input) == 9\n\ntest_input = { \"m\": 8, \"n\": 5, \"hFences\": [4,6,2,3], \"vFences\": [4] }\nassert my_solution.maximizeSquareArea(**test_input) == 16\n\ntest_input = { \"m\": 9, \"n\": 5, \"hFences\": [6], \"vFences\": [3] }\nassert my_solution.maximizeSquareArea(**test_input) == -1\n\ntest_input = { \"m\": 9, \"n\": 4, \"hFences\": [2,8,3,7,4,6,5], \"vFences\": [2,3] }\nassert my_solution.maximizeSquareArea(**test_input) == 9\n\ntest_input = { \"m\": 5, \"n\": 8, \"hFences\": [2,3,4], \"vFences\": [3,5,6,4] }\nassert my_solution.maximizeSquareArea(**test_input) == 16\n\ntest_input = { \"m\": 9, \"n\": 6, \"hFences\": [7,3,4,5,8,2], \"vFences\": [5,3,2,4] }\nassert my_solution.maximizeSquareArea(**test_input) == 25\n\ntest_input = { \"m\": 5, \"n\": 4, \"hFences\": [4], \"vFences\": [2] }\nassert my_solution.maximizeSquareArea(**test_input) == 9\n\ntest_input = { \"m\": 9, \"n\": 6, \"hFences\": [2,5], \"vFences\": [5,2] }\nassert my_solution.maximizeSquareArea(**test_input) == 16\n\ntest_input = { \"m\": 6, \"n\": 9, \"hFences\": [4,5,2], \"vFences\": [5,7,8,2,3,6] }\nassert my_solution.maximizeSquareArea(**test_input) == 25\n\ntest_input = { \"m\": 4, \"n\": 5, \"hFences\": [2], \"vFences\": [2] }\nassert my_solution.maximizeSquareArea(**test_input) == 9\n\ntest_input = { \"m\": 9, \"n\": 6, \"hFences\": [2,4], \"vFences\": [5,3] }\nassert my_solution.maximizeSquareArea(**test_input) == 25\n\ntest_input = { \"m\": 4, \"n\": 7, \"hFences\": [2], \"vFences\": [4,3,6,2,5] }\nassert my_solution.maximizeSquareArea(**test_input) == 9\n\ntest_input = { \"m\": 8, \"n\": 3, \"hFences\": [3,2,5], \"vFences\": [2] }\nassert my_solution.maximizeSquareArea(**test_input) == 4\n\ntest_input = { \"m\": 6, \"n\": 8, \"hFences\": [4,2,3,5], \"vFences\": [7,4,5,6] }\nassert my_solution.maximizeSquareArea(**test_input) == 25\n\ntest_input = { \"m\": 3, \"n\": 5, \"hFences\": [2], \"vFences\": [3] }\nassert my_solution.maximizeSquareArea(**test_input) == 4\n\ntest_input = { \"m\": 8, \"n\": 8, \"hFences\": [2,5,6], \"vFences\": [3,7,4,2,5] }\nassert my_solution.maximizeSquareArea(**test_input) == 49\n\ntest_input = { \"m\": 8, \"n\": 7, \"hFences\": [3,4,7], \"vFences\": [2,6,3,4] }\nassert my_solution.maximizeSquareArea(**test_input) == 36\n\ntest_input = { \"m\": 7, \"n\": 4, \"hFences\": [3,6,5], \"vFences\": [2] }\nassert my_solution.maximizeSquareArea(**test_input) == 9\n\ntest_input = { \"m\": 5, \"n\": 6, \"hFences\": [2,3], \"vFences\": [3,2,5] }\nassert my_solution.maximizeSquareArea(**test_input) == 16\n\ntest_input = { \"m\": 6, \"n\": 7, \"hFences\": [5], \"vFences\": [4,2,5,6] }\nassert my_solution.maximizeSquareArea(**test_input) == 25\n\ntest_input = { \"m\": 8, \"n\": 8, \"hFences\": [4,5,2,7], \"vFences\": [5,3,4,2,7,6] }\nassert my_solution.maximizeSquareArea(**test_input) == 49\n\ntest_input = { \"m\": 7, \"n\": 9, \"hFences\": [6,3,4], \"vFences\": [8,6,2] }\nassert my_solution.maximizeSquareArea(**test_input) == 36\n\ntest_input = { \"m\": 7, \"n\": 4, \"hFences\": [3,4,6], \"vFences\": [3,2] }\nassert my_solution.maximizeSquareArea(**test_input) == 9\n\ntest_input = { \"m\": 6, \"n\": 8, \"hFences\": [5,4,3], \"vFences\": [5,7,3,2,6,4] }\nassert my_solution.maximizeSquareArea(**test_input) == 25\n\ntest_input = { \"m\": 8, \"n\": 9, \"hFences\": [2,3,4,7,6,5], \"vFences\": [3,7,8] }\nassert my_solution.maximizeSquareArea(**test_input) == 49\n\ntest_input = { \"m\": 3, \"n\": 4, \"hFences\": [2], \"vFences\": [2,3] }\nassert my_solution.maximizeSquareArea(**test_input) == 4\n\ntest_input = { \"m\": 9, \"n\": 9, \"hFences\": [8,5,6,2,7], \"vFences\": [8,6,4,2] }\nassert my_solution.maximizeSquareArea(**test_input) == 64\n\ntest_input = { \"m\": 7, \"n\": 6, \"hFences\": [4,5], \"vFences\": [5,3] }\nassert my_solution.maximizeSquareArea(**test_input) == 16\n\ntest_input = { \"m\": 5, \"n\": 4, \"hFences\": [2], \"vFences\": [3] }\nassert my_solution.maximizeSquareArea(**test_input) == 9\n\ntest_input = { \"m\": 5, \"n\": 5, \"hFences\": [3], \"vFences\": [3,4,2] }\nassert my_solution.maximizeSquareArea(**test_input) == 16\n\ntest_input = { \"m\": 9, \"n\": 7, \"hFences\": [3], \"vFences\": [3,2,5,4] }\nassert my_solution.maximizeSquareArea(**test_input) == 36\n\ntest_input = { \"m\": 8, \"n\": 6, \"hFences\": [4], \"vFences\": [5,2,3] }\nassert my_solution.maximizeSquareArea(**test_input) == 16\n\ntest_input = { \"m\": 6, \"n\": 9, \"hFences\": [3,4,2], \"vFences\": [3,2,8] }\nassert my_solution.maximizeSquareArea(**test_input) == 25\n\ntest_input = { \"m\": 7, \"n\": 6, \"hFences\": [3,6,5,2,4], \"vFences\": [2,3,5,4] }\nassert my_solution.maximizeSquareArea(**test_input) == 25\n\ntest_input = { \"m\": 7, \"n\": 3, \"hFences\": [5,3,6,4], \"vFences\": [2] }\nassert my_solution.maximizeSquareArea(**test_input) == 4\n\ntest_input = { \"m\": 4, \"n\": 7, \"hFences\": [3], \"vFences\": [2] }\nassert my_solution.maximizeSquareArea(**test_input) == 1\n\ntest_input = { \"m\": 3, \"n\": 7, \"hFences\": [2], \"vFences\": [4,3,2,6,5] }\nassert my_solution.maximizeSquareArea(**test_input) == 4\n\ntest_input = { \"m\": 5, \"n\": 9, \"hFences\": [2,4], \"vFences\": [4,7] }\nassert my_solution.maximizeSquareArea(**test_input) == 9\n\ntest_input = { \"m\": 5, \"n\": 9, \"hFences\": [4,2], \"vFences\": [8,7,3,2,6,4] }\nassert my_solution.maximizeSquareArea(**test_input) == 16\n\ntest_input = { \"m\": 3, \"n\": 8, \"hFences\": [2], \"vFences\": [3,7,2,5,4] }\nassert my_solution.maximizeSquareArea(**test_input) == 4\n\ntest_input = { \"m\": 4, \"n\": 7, \"hFences\": [2,3], \"vFences\": [4,2] }\nassert my_solution.maximizeSquareArea(**test_input) == 9\n\ntest_input = { \"m\": 8, \"n\": 9, \"hFences\": [7,6,3,2,5,4], \"vFences\": [3,2,6] }\nassert my_solution.maximizeSquareArea(**test_input) == 49\n\ntest_input = { \"m\": 7, \"n\": 8, \"hFences\": [6], \"vFences\": [5] }\nassert my_solution.maximizeSquareArea(**test_input) == -1\n\ntest_input = { \"m\": 9, \"n\": 7, \"hFences\": [2,7,8,5], \"vFences\": [6,3] }\nassert my_solution.maximizeSquareArea(**test_input) == 36\n\ntest_input = { \"m\": 9, \"n\": 9, \"hFences\": [4,7,2,5,8,6], \"vFences\": [7,6,4,5,8,2,3] }\nassert my_solution.maximizeSquareArea(**test_input) == 64\n\ntest_input = { \"m\": 7, \"n\": 7, \"hFences\": [6,3,2,5], \"vFences\": [6,3] }\nassert my_solution.maximizeSquareArea(**test_input) == 36\n\ntest_input = { \"m\": 7, \"n\": 7, \"hFences\": [5], \"vFences\": [2,3,6] }\nassert my_solution.maximizeSquareArea(**test_input) == 36\n\ntest_input = { \"m\": 4, \"n\": 9, \"hFences\": [3], \"vFences\": [4,3,7,6,8,5,2] }\nassert my_solution.maximizeSquareArea(**test_input) == 9\n\ntest_input = { \"m\": 4, \"n\": 5, \"hFences\": [2,3], \"vFences\": [3,4] }\nassert my_solution.maximizeSquareArea(**test_input) == 9\n\ntest_input = { \"m\": 3, \"n\": 7, \"hFences\": [2], \"vFences\": [3,6] }\nassert my_solution.maximizeSquareArea(**test_input) == 4\n\ntest_input = { \"m\": 4, \"n\": 9, \"hFences\": [3,2], \"vFences\": [4,6] }\nassert my_solution.maximizeSquareArea(**test_input) == 9\n\ntest_input = { \"m\": 9, \"n\": 9, \"hFences\": [5], \"vFences\": [6,5,2,7,3,8] }\nassert my_solution.maximizeSquareArea(**test_input) == 64\n\ntest_input = { \"m\": 5, \"n\": 6, \"hFences\": [3,4,2], \"vFences\": [5,3,2] }\nassert my_solution.maximizeSquareArea(**test_input) == 16\n\ntest_input = { \"m\": 5, \"n\": 6, \"hFences\": [3,2], \"vFences\": [5] }\nassert my_solution.maximizeSquareArea(**test_input) == 16\n\ntest_input = { \"m\": 5, \"n\": 5, \"hFences\": [3,4], \"vFences\": [3,2,4] }\nassert my_solution.maximizeSquareArea(**test_input) == 16\n\ntest_input = { \"m\": 9, \"n\": 5, \"hFences\": [7,5,8], \"vFences\": [4,2,3] }\nassert my_solution.maximizeSquareArea(**test_input) == 16\n\ntest_input = { \"m\": 3, \"n\": 6, \"hFences\": [2], \"vFences\": [2,5,4] }\nassert my_solution.maximizeSquareArea(**test_input) == 4\n\ntest_input = { \"m\": 5, \"n\": 9, \"hFences\": [4,2,3], \"vFences\": [8,3,5,6,4,2] }\nassert my_solution.maximizeSquareArea(**test_input) == 16\n\ntest_input = { \"m\": 4, \"n\": 7, \"hFences\": [3,2], \"vFences\": [5] }\nassert my_solution.maximizeSquareArea(**test_input) == 4\n\ntest_input = { \"m\": 6, \"n\": 9, \"hFences\": [4,2], \"vFences\": [3,4,7,2] }\nassert my_solution.maximizeSquareArea(**test_input) == 25\n\ntest_input = { \"m\": 6, \"n\": 5, \"hFences\": [4], \"vFences\": [3,2] }\nassert my_solution.maximizeSquareArea(**test_input) == 9\n\ntest_input = { \"m\": 8, \"n\": 5, \"hFences\": [6,7,4,5,2], \"vFences\": [4] }\nassert my_solution.maximizeSquareArea(**test_input) == 16", "start_time": 1703385000} +{"task_id": "weekly-contest-377-minimum-cost-to-convert-string-i", "url": "https://leetcode.com/problems/minimum-cost-to-convert-string-i", "title": "minimum-cost-to-convert-string-i", "meta": {"questionId": "3235", "questionFrontendId": "2976", "title": "Minimum Cost to Convert String I", "titleSlug": "minimum-cost-to-convert-string-i", "isPaidOnly": false, "difficulty": "Medium", "likes": 93, "dislikes": 4, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你两个下标从 0 开始的字符串 source 和 target ,它们的长度均为 n 并且由 小写 英文字母组成。\n另给你两个下标从 0 开始的字符数组 original 和 changed ,以及一个整数数组 cost ,其中 cost[i] 代表将字符 original[i] 更改为字符 changed[i] 的成本。\n你从字符串 source 开始。在一次操作中,如果 存在 任意 下标 j 满足 cost[j] == z 、original[j] == x 以及 changed[j] == y 。你就可以选择字符串中的一个字符 x 并以 z 的成本将其更改为字符 y 。\n返回将字符串 source 转换为字符串 target 所需的 最小 成本。如果不可能完成转换,则返回 -1 。\n注意,可能存在下标 i 、j 使得 original[j] == original[i] 且 changed[j] == changed[i] 。\n\n示例 1:\n\n输入:source = \"abcd\", target = \"acbe\", original = [\"a\",\"b\",\"c\",\"c\",\"e\",\"d\"], changed = [\"b\",\"c\",\"b\",\"e\",\"b\",\"e\"], cost = [2,5,5,1,2,20]\n输出:28\n解释:将字符串 \"abcd\" 转换为字符串 \"acbe\" :\n- 更改下标 1 处的值 'b' 为 'c' ,成本为 5 。\n- 更改下标 2 处的值 'c' 为 'e' ,成本为 1 。\n- 更改下标 2 处的值 'e' 为 'b' ,成本为 2 。\n- 更改下标 3 处的值 'd' 为 'e' ,成本为 20 。\n产生的总成本是 5 + 1 + 2 + 20 = 28 。\n可以证明这是可能的最小成本。\n\n示例 2:\n\n输入:source = \"aaaa\", target = \"bbbb\", original = [\"a\",\"c\"], changed = [\"c\",\"b\"], cost = [1,2]\n输出:12\n解释:要将字符 'a' 更改为 'b':\n- 将字符 'a' 更改为 'c',成本为 1 \n- 将字符 'c' 更改为 'b',成本为 2 \n产生的总成本是 1 + 2 = 3。\n将所有 'a' 更改为 'b',产生的总成本是 3 * 4 = 12 。\n\n示例 3:\n\n输入:source = \"abcd\", target = \"abce\", original = [\"a\"], changed = [\"e\"], cost = [10000]\n输出:-1\n解释:无法将 source 字符串转换为 target 字符串,因为下标 3 处的值无法从 'd' 更改为 'e' 。\n\n\n提示:\n\n1 <= source.length == target.length <= 105\nsource、target 均由小写英文字母组成\n1 <= cost.length== original.length == changed.length <= 2000\noriginal[i]、changed[i] 是小写英文字母\n1 <= cost[i] <= 106\noriginal[i] != changed[i]\n\"\"\"\nclass Solution:\n def minimumCost(self, source: str, target: str, original: List[str], changed: List[str], cost: List[int]) -> int:\n ", "prompt_sft": "给你两个下标从 0 开始的字符串 source 和 target ,它们的长度均为 n 并且由 小写 英文字母组成。\n另给你两个下标从 0 开始的字符数组 original 和 changed ,以及一个整数数组 cost ,其中 cost[i] 代表将字符 original[i] 更改为字符 changed[i] 的成本。\n你从字符串 source 开始。在一次操作中,如果 存在 任意 下标 j 满足 cost[j] == z 、original[j] == x 以及 changed[j] == y 。你就可以选择字符串中的一个字符 x 并以 z 的成本将其更改为字符 y 。\n返回将字符串 source 转换为字符串 target 所需的 最小 成本。如果不可能完成转换,则返回 -1 。\n注意,可能存在下标 i 、j 使得 original[j] == original[i] 且 changed[j] == changed[i] 。\n\n示例 1:\n\n输入:source = \"abcd\", target = \"acbe\", original = [\"a\",\"b\",\"c\",\"c\",\"e\",\"d\"], changed = [\"b\",\"c\",\"b\",\"e\",\"b\",\"e\"], cost = [2,5,5,1,2,20]\n输出:28\n解释:将字符串 \"abcd\" 转换为字符串 \"acbe\" :\n- 更改下标 1 处的值 'b' 为 'c' ,成本为 5 。\n- 更改下标 2 处的值 'c' 为 'e' ,成本为 1 。\n- 更改下标 2 处的值 'e' 为 'b' ,成本为 2 。\n- 更改下标 3 处的值 'd' 为 'e' ,成本为 20 。\n产生的总成本是 5 + 1 + 2 + 20 = 28 。\n可以证明这是可能的最小成本。\n\n示例 2:\n\n输入:source = \"aaaa\", target = \"bbbb\", original = [\"a\",\"c\"], changed = [\"c\",\"b\"], cost = [1,2]\n输出:12\n解释:要将字符 'a' 更改为 'b':\n- 将字符 'a' 更改为 'c',成本为 1 \n- 将字符 'c' 更改为 'b',成本为 2 \n产生的总成本是 1 + 2 = 3。\n将所有 'a' 更改为 'b',产生的总成本是 3 * 4 = 12 。\n\n示例 3:\n\n输入:source = \"abcd\", target = \"abce\", original = [\"a\"], changed = [\"e\"], cost = [10000]\n输出:-1\n解释:无法将 source 字符串转换为 target 字符串,因为下标 3 处的值无法从 'd' 更改为 'e' 。\n\n\n提示:\n\n1 <= source.length == target.length <= 105\nsource、target 均由小写英文字母组成\n1 <= cost.length== original.length == changed.length <= 2000\noriginal[i]、changed[i] 是小写英文字母\n1 <= cost[i] <= 106\noriginal[i] != changed[i]\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def minimumCost(self, source: str, target: str, original: List[str], changed: List[str], cost: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"source\": \"abcd\", \"target\": \"acbe\", \"original\": [\"a\",\"b\",\"c\",\"c\",\"e\",\"d\"], \"changed\": [\"b\",\"c\",\"b\",\"e\",\"b\",\"e\"], \"cost\": [2,5,5,1,2,20] }\nassert my_solution.minimumCost(**test_input) == 28\n\ntest_input = { \"source\": \"aaaa\", \"target\": \"bbbb\", \"original\": [\"a\",\"c\"], \"changed\": [\"c\",\"b\"], \"cost\": [1,2] }\nassert my_solution.minimumCost(**test_input) == 12\n\ntest_input = { \"source\": \"abcd\", \"target\": \"abce\", \"original\": [\"a\"], \"changed\": [\"e\"], \"cost\": [10000] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"aaaabadaaa\", \"target\": \"dbdadddbad\", \"original\": [\"c\",\"a\",\"c\",\"a\",\"a\",\"b\",\"b\",\"b\",\"d\",\"d\",\"c\"], \"changed\": [\"a\",\"c\",\"b\",\"d\",\"b\",\"c\",\"a\",\"d\",\"c\",\"b\",\"d\"], \"cost\": [7,8,11,9,7,6,4,6,9,5,9] }\nassert my_solution.minimumCost(**test_input) == 56\n\ntest_input = { \"source\": \"aaadbdcdac\", \"target\": \"cdbabaddba\", \"original\": [\"a\",\"c\",\"b\",\"d\",\"b\",\"a\",\"c\"], \"changed\": [\"c\",\"a\",\"d\",\"b\",\"c\",\"b\",\"d\"], \"cost\": [7,2,1,3,6,1,7] }\nassert my_solution.minimumCost(**test_input) == 39\n\ntest_input = { \"source\": \"aababdaacb\", \"target\": \"bcdcdcbdcb\", \"original\": [\"a\",\"d\",\"d\",\"a\",\"c\",\"b\",\"c\",\"a\",\"c\",\"d\",\"b\",\"b\"], \"changed\": [\"b\",\"c\",\"b\",\"d\",\"a\",\"a\",\"b\",\"c\",\"d\",\"a\",\"c\",\"d\"], \"cost\": [11,4,3,2,7,11,7,6,9,2,1,7] }\nassert my_solution.minimumCost(**test_input) == 42\n\ntest_input = { \"source\": \"aababdbddc\", \"target\": \"adcbbbcdba\", \"original\": [\"a\",\"d\",\"b\",\"a\",\"d\",\"c\",\"d\",\"b\"], \"changed\": [\"b\",\"a\",\"d\",\"c\",\"c\",\"a\",\"b\",\"a\"], \"cost\": [10,6,8,3,6,10,8,6] }\nassert my_solution.minimumCost(**test_input) == 72\n\ntest_input = { \"source\": \"aabbcabbdb\", \"target\": \"acddbabbdd\", \"original\": [\"c\",\"d\",\"c\",\"a\",\"d\",\"c\",\"a\",\"d\",\"b\",\"a\",\"b\"], \"changed\": [\"d\",\"b\",\"a\",\"c\",\"c\",\"b\",\"b\",\"a\",\"d\",\"d\",\"c\"], \"cost\": [5,3,8,10,9,7,8,7,5,1,10] }\nassert my_solution.minimumCost(**test_input) == 32\n\ntest_input = { \"source\": \"aabbddccbc\", \"target\": \"abbbaabaca\", \"original\": [\"a\",\"b\",\"c\",\"b\",\"a\",\"d\"], \"changed\": [\"d\",\"c\",\"b\",\"d\",\"b\",\"b\"], \"cost\": [3,8,7,6,7,10] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"aabdbaabaa\", \"target\": \"bdaacabcab\", \"original\": [\"b\",\"d\",\"d\",\"a\",\"c\",\"c\",\"a\",\"d\",\"a\",\"b\"], \"changed\": [\"c\",\"c\",\"b\",\"d\",\"b\",\"d\",\"b\",\"a\",\"c\",\"a\"], \"cost\": [9,1,7,9,2,1,3,8,8,2] }\nassert my_solution.minimumCost(**test_input) == 43\n\ntest_input = { \"source\": \"aacacaaccd\", \"target\": \"dadaacaabd\", \"original\": [\"c\",\"c\",\"a\",\"a\",\"d\",\"b\",\"d\",\"d\"], \"changed\": [\"b\",\"d\",\"d\",\"b\",\"b\",\"c\",\"c\",\"a\"], \"cost\": [7,8,9,11,4,6,9,10] }\nassert my_solution.minimumCost(**test_input) == 77\n\ntest_input = { \"source\": \"aacbabbacc\", \"target\": \"adbdbcbdaa\", \"original\": [\"c\",\"b\",\"a\",\"b\",\"a\",\"c\",\"d\",\"c\",\"d\"], \"changed\": [\"b\",\"c\",\"b\",\"d\",\"d\",\"a\",\"b\",\"d\",\"c\"], \"cost\": [2,6,7,4,7,4,3,5,6] }\nassert my_solution.minimumCost(**test_input) == 41\n\ntest_input = { \"source\": \"aacbbabdad\", \"target\": \"ddadcababd\", \"original\": [\"d\",\"b\",\"c\",\"a\",\"b\",\"c\",\"d\",\"c\",\"b\",\"a\",\"a\"], \"changed\": [\"c\",\"d\",\"d\",\"b\",\"c\",\"b\",\"b\",\"a\",\"a\",\"c\",\"d\"], \"cost\": [7,10,4,2,7,4,4,4,6,2,8] }\nassert my_solution.minimumCost(**test_input) == 45\n\ntest_input = { \"source\": \"aacbbbbcab\", \"target\": \"cdacdcddac\", \"original\": [\"b\",\"d\",\"c\",\"c\",\"b\",\"a\"], \"changed\": [\"c\",\"c\",\"b\",\"a\",\"a\",\"d\"], \"cost\": [4,7,9,11,3,4] }\nassert my_solution.minimumCost(**test_input) == 67\n\ntest_input = { \"source\": \"aacbcabcad\", \"target\": \"bbcadddcdd\", \"original\": [\"b\",\"a\",\"d\",\"a\",\"b\",\"c\",\"a\",\"d\",\"d\",\"b\"], \"changed\": [\"d\",\"b\",\"b\",\"d\",\"c\",\"a\",\"c\",\"c\",\"a\",\"a\"], \"cost\": [7,7,9,8,6,3,8,2,1,5] }\nassert my_solution.minimumCost(**test_input) == 53\n\ntest_input = { \"source\": \"aacbdbcdca\", \"target\": \"bbbdbcaacd\", \"original\": [\"a\",\"c\",\"b\",\"d\",\"d\",\"a\",\"c\",\"d\"], \"changed\": [\"c\",\"b\",\"c\",\"c\",\"b\",\"d\",\"d\",\"a\"], \"cost\": [9,5,4,1,2,4,7,1] }\nassert my_solution.minimumCost(**test_input) == 47\n\ntest_input = { \"source\": \"aadbbcdbbd\", \"target\": \"badddbdbac\", \"original\": [\"c\",\"d\",\"c\",\"d\",\"b\",\"a\"], \"changed\": [\"b\",\"b\",\"a\",\"a\",\"a\",\"d\"], \"cost\": [11,4,7,8,5,2] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"aadbccbddd\", \"target\": \"cacdbabadc\", \"original\": [\"d\",\"b\",\"c\",\"d\",\"a\",\"a\",\"c\",\"b\"], \"changed\": [\"c\",\"c\",\"b\",\"b\",\"b\",\"d\",\"a\",\"a\"], \"cost\": [5,8,7,2,4,7,1,5] }\nassert my_solution.minimumCost(**test_input) == 46\n\ntest_input = { \"source\": \"aadbddcabd\", \"target\": \"bdcdccbada\", \"original\": [\"d\",\"a\",\"a\",\"b\",\"d\",\"b\"], \"changed\": [\"b\",\"c\",\"d\",\"c\",\"a\",\"d\"], \"cost\": [6,10,5,8,11,4] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"aaddadccad\", \"target\": \"cbaaadbcba\", \"original\": [\"c\",\"a\",\"a\",\"d\",\"c\",\"c\",\"b\",\"b\",\"a\",\"d\"], \"changed\": [\"a\",\"c\",\"d\",\"c\",\"d\",\"b\",\"d\",\"c\",\"b\",\"b\"], \"cost\": [1,10,2,8,9,1,9,10,5,1] }\nassert my_solution.minimumCost(**test_input) == 44\n\ntest_input = { \"source\": \"aaddadcdba\", \"target\": \"caaaccbbca\", \"original\": [\"b\",\"b\",\"c\",\"d\",\"b\",\"c\",\"a\",\"a\"], \"changed\": [\"a\",\"d\",\"d\",\"a\",\"c\",\"b\",\"c\",\"b\"], \"cost\": [11,7,10,8,7,5,10,10] }\nassert my_solution.minimumCost(**test_input) == 84\n\ntest_input = { \"source\": \"abaacbbcaa\", \"target\": \"bdbdbcbdcd\", \"original\": [\"d\",\"a\",\"d\",\"a\",\"b\",\"b\"], \"changed\": [\"a\",\"d\",\"b\",\"b\",\"a\",\"c\"], \"cost\": [10,9,8,11,4,11] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"abacaadcba\", \"target\": \"cadbadcdbd\", \"original\": [\"b\",\"d\",\"c\",\"a\",\"b\",\"d\",\"b\"], \"changed\": [\"a\",\"b\",\"b\",\"b\",\"c\",\"a\",\"d\"], \"cost\": [9,10,6,2,7,10,9] }\nassert my_solution.minimumCost(**test_input) == 89\n\ntest_input = { \"source\": \"abacbadadc\", \"target\": \"aabbdaaccb\", \"original\": [\"d\",\"a\",\"b\",\"d\",\"a\",\"a\",\"c\",\"b\",\"c\",\"c\",\"d\",\"b\"], \"changed\": [\"c\",\"b\",\"a\",\"a\",\"d\",\"c\",\"b\",\"c\",\"d\",\"a\",\"b\",\"d\"], \"cost\": [2,10,3,6,4,1,5,5,11,4,2,1] }\nassert my_solution.minimumCost(**test_input) == 28\n\ntest_input = { \"source\": \"abadbbabcd\", \"target\": \"cdcbdddcbb\", \"original\": [\"d\",\"d\",\"b\",\"a\",\"c\",\"c\",\"c\",\"a\"], \"changed\": [\"c\",\"a\",\"a\",\"c\",\"b\",\"d\",\"a\",\"d\"], \"cost\": [2,10,11,7,6,11,7,1] }\nassert my_solution.minimumCost(**test_input) == 79\n\ntest_input = { \"source\": \"abadcadacc\", \"target\": \"cbabaddcba\", \"original\": [\"a\",\"d\",\"a\",\"b\",\"c\",\"a\",\"d\",\"b\",\"b\",\"d\",\"c\",\"c\"], \"changed\": [\"b\",\"b\",\"d\",\"d\",\"a\",\"c\",\"a\",\"c\",\"a\",\"c\",\"d\",\"b\"], \"cost\": [7,6,11,11,8,10,4,11,2,3,11,7] }\nassert my_solution.minimumCost(**test_input) == 60\n\ntest_input = { \"source\": \"abadcdadac\", \"target\": \"baddbccdac\", \"original\": [\"d\",\"c\",\"d\",\"c\",\"b\",\"a\"], \"changed\": [\"b\",\"b\",\"c\",\"a\",\"d\",\"d\"], \"cost\": [8,5,9,1,10,2] }\nassert my_solution.minimumCost(**test_input) == 57\n\ntest_input = { \"source\": \"abbaadacba\", \"target\": \"cdbbcadddd\", \"original\": [\"d\",\"a\",\"d\",\"c\",\"b\",\"b\",\"c\",\"d\",\"c\",\"a\",\"a\"], \"changed\": [\"a\",\"c\",\"c\",\"d\",\"a\",\"d\",\"a\",\"b\",\"b\",\"d\",\"b\"], \"cost\": [8,3,5,8,3,9,3,4,11,4,9] }\nassert my_solution.minimumCost(**test_input) == 50\n\ntest_input = { \"source\": \"abbaddaacd\", \"target\": \"ccbbaccacc\", \"original\": [\"d\",\"d\",\"a\",\"b\",\"c\",\"b\"], \"changed\": [\"a\",\"c\",\"c\",\"d\",\"b\",\"c\"], \"cost\": [9,8,2,8,3,1] }\nassert my_solution.minimumCost(**test_input) == 35\n\ntest_input = { \"source\": \"abbbcabddb\", \"target\": \"bbccdbbadc\", \"original\": [\"c\",\"d\",\"c\",\"a\",\"b\",\"d\",\"d\",\"a\",\"b\",\"b\"], \"changed\": [\"d\",\"a\",\"b\",\"c\",\"c\",\"b\",\"c\",\"d\",\"a\",\"d\"], \"cost\": [3,6,9,4,9,6,9,6,10,7] }\nassert my_solution.minimumCost(**test_input) == 60\n\ntest_input = { \"source\": \"abbbcbabab\", \"target\": \"abcacbaddd\", \"original\": [\"b\",\"c\",\"a\",\"c\",\"a\",\"d\",\"d\",\"c\"], \"changed\": [\"a\",\"b\",\"d\",\"a\",\"b\",\"b\",\"c\",\"d\"], \"cost\": [11,5,8,1,7,7,1,2] }\nassert my_solution.minimumCost(**test_input) == 77\n\ntest_input = { \"source\": \"abbcaccabb\", \"target\": \"ddddddcacc\", \"original\": [\"a\",\"b\",\"c\",\"b\",\"a\",\"c\",\"c\"], \"changed\": [\"c\",\"c\",\"d\",\"a\",\"d\",\"a\",\"b\"], \"cost\": [2,6,10,11,9,7,3] }\nassert my_solution.minimumCost(**test_input) == 82\n\ntest_input = { \"source\": \"abbcaccdba\", \"target\": \"accadababc\", \"original\": [\"d\",\"a\",\"a\",\"c\",\"b\",\"d\"], \"changed\": [\"c\",\"d\",\"b\",\"a\",\"a\",\"b\"], \"cost\": [7,4,10,11,5,5] }\nassert my_solution.minimumCost(**test_input) == 99\n\ntest_input = { \"source\": \"abbdaccada\", \"target\": \"acddaccddc\", \"original\": [\"b\",\"b\",\"c\",\"a\",\"d\",\"a\",\"d\"], \"changed\": [\"a\",\"c\",\"b\",\"b\",\"b\",\"c\",\"c\"], \"cost\": [4,9,3,1,11,3,3] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"abcabdaddb\", \"target\": \"dcbadaaacc\", \"original\": [\"d\",\"b\",\"a\",\"a\",\"c\",\"c\"], \"changed\": [\"c\",\"c\",\"d\",\"b\",\"b\",\"a\"], \"cost\": [3,3,9,3,7,6] }\nassert my_solution.minimumCost(**test_input) == 61\n\ntest_input = { \"source\": \"abcadcabaa\", \"target\": \"bbbdddcaba\", \"original\": [\"b\",\"d\",\"c\",\"d\",\"a\",\"c\",\"b\",\"b\"], \"changed\": [\"c\",\"b\",\"a\",\"a\",\"c\",\"b\",\"d\",\"a\"], \"cost\": [1,8,4,3,8,3,11,5] }\nassert my_solution.minimumCost(**test_input) == 74\n\ntest_input = { \"source\": \"abccabacaa\", \"target\": \"aaabacbcbb\", \"original\": [\"c\",\"c\",\"d\",\"a\",\"d\",\"b\",\"c\",\"b\",\"d\",\"a\"], \"changed\": [\"b\",\"a\",\"a\",\"b\",\"b\",\"d\",\"d\",\"a\",\"c\",\"c\"], \"cost\": [9,10,8,6,9,10,2,6,6,8] }\nassert my_solution.minimumCost(**test_input) == 57\n\ntest_input = { \"source\": \"abdaababbb\", \"target\": \"dbdadabadc\", \"original\": [\"a\",\"c\",\"c\",\"b\",\"d\",\"a\",\"b\"], \"changed\": [\"c\",\"a\",\"b\",\"c\",\"b\",\"b\",\"d\"], \"cost\": [3,4,6,1,8,11,6] }\nassert my_solution.minimumCost(**test_input) == 56\n\ntest_input = { \"source\": \"abdbaaacaa\", \"target\": \"abbbccccad\", \"original\": [\"a\",\"a\",\"c\",\"b\",\"d\",\"d\",\"b\"], \"changed\": [\"d\",\"b\",\"b\",\"a\",\"a\",\"b\",\"c\"], \"cost\": [3,10,7,2,5,7,3] }\nassert my_solution.minimumCost(**test_input) == 49\n\ntest_input = { \"source\": \"abdcbdbccc\", \"target\": \"dbbcdcabba\", \"original\": [\"c\",\"c\",\"d\",\"b\",\"a\",\"c\",\"a\",\"d\",\"b\",\"d\",\"a\",\"b\"], \"changed\": [\"d\",\"a\",\"b\",\"d\",\"c\",\"b\",\"b\",\"a\",\"c\",\"c\",\"d\",\"a\"], \"cost\": [9,5,9,6,5,5,5,10,7,7,3,6] }\nassert my_solution.minimumCost(**test_input) == 46\n\ntest_input = { \"source\": \"acabbbdbdb\", \"target\": \"accbccbbab\", \"original\": [\"b\",\"d\",\"c\",\"d\",\"b\",\"c\"], \"changed\": [\"a\",\"a\",\"a\",\"c\",\"d\",\"d\"], \"cost\": [7,7,10,9,7,1] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"acadadccbb\", \"target\": \"dcaaabbbdd\", \"original\": [\"a\",\"c\",\"c\",\"a\",\"d\",\"b\",\"b\",\"d\",\"b\",\"a\"], \"changed\": [\"d\",\"d\",\"b\",\"b\",\"c\",\"d\",\"a\",\"a\",\"c\",\"c\"], \"cost\": [1,2,1,4,9,4,8,5,11,7] }\nassert my_solution.minimumCost(**test_input) == 25\n\ntest_input = { \"source\": \"acadbbcdcb\", \"target\": \"bcacabdcdd\", \"original\": [\"a\",\"b\",\"d\",\"b\",\"b\",\"c\",\"a\"], \"changed\": [\"d\",\"c\",\"c\",\"a\",\"d\",\"b\",\"b\"], \"cost\": [3,6,3,10,11,3,6] }\nassert my_solution.minimumCost(**test_input) == 61\n\ntest_input = { \"source\": \"acaddccaad\", \"target\": \"daacadcdda\", \"original\": [\"c\",\"c\",\"a\",\"b\",\"b\",\"a\",\"b\",\"d\",\"c\",\"a\",\"d\"], \"changed\": [\"a\",\"b\",\"b\",\"d\",\"a\",\"d\",\"c\",\"b\",\"d\",\"c\",\"c\"], \"cost\": [10,8,4,8,3,1,2,8,11,8,6] }\nassert my_solution.minimumCost(**test_input) == 52\n\ntest_input = { \"source\": \"acbbabcaac\", \"target\": \"bdcbaadcab\", \"original\": [\"d\",\"c\",\"a\",\"c\",\"b\",\"a\",\"a\",\"b\",\"c\",\"d\"], \"changed\": [\"a\",\"a\",\"d\",\"d\",\"c\",\"c\",\"b\",\"a\",\"b\",\"c\"], \"cost\": [9,11,8,6,11,11,1,1,9,9] }\nassert my_solution.minimumCost(**test_input) == 45\n\ntest_input = { \"source\": \"accabbadbc\", \"target\": \"adbbccbcbd\", \"original\": [\"a\",\"c\",\"a\",\"d\",\"b\",\"a\",\"c\",\"c\",\"b\",\"b\"], \"changed\": [\"c\",\"d\",\"b\",\"c\",\"d\",\"d\",\"b\",\"a\",\"c\",\"a\"], \"cost\": [7,10,9,3,2,5,1,8,11,2] }\nassert my_solution.minimumCost(**test_input) == 36\n\ntest_input = { \"source\": \"accabbdddd\", \"target\": \"cacdccbcad\", \"original\": [\"c\",\"a\",\"d\",\"b\",\"d\",\"c\",\"a\",\"b\",\"b\",\"c\",\"d\"], \"changed\": [\"d\",\"b\",\"a\",\"d\",\"c\",\"a\",\"d\",\"a\",\"c\",\"b\",\"b\"], \"cost\": [11,6,6,4,7,11,2,7,7,7,2] }\nassert my_solution.minimumCost(**test_input) == 51\n\ntest_input = { \"source\": \"accbaadbdb\", \"target\": \"baccbaacbb\", \"original\": [\"b\",\"b\",\"a\",\"d\",\"d\",\"a\",\"c\"], \"changed\": [\"a\",\"d\",\"d\",\"b\",\"a\",\"c\",\"a\"], \"cost\": [9,11,6,7,4,2,2] }\nassert my_solution.minimumCost(**test_input) == 61\n\ntest_input = { \"source\": \"accbddaaab\", \"target\": \"baddbaabbd\", \"original\": [\"a\",\"b\",\"c\",\"d\",\"d\",\"b\",\"d\",\"b\"], \"changed\": [\"b\",\"a\",\"a\",\"b\",\"a\",\"c\",\"c\",\"d\"], \"cost\": [6,3,4,6,1,6,10,6] }\nassert my_solution.minimumCost(**test_input) == 57\n\ntest_input = { \"source\": \"acccbcdccb\", \"target\": \"bdadccdbad\", \"original\": [\"a\",\"b\",\"c\",\"c\",\"a\",\"d\",\"d\"], \"changed\": [\"b\",\"c\",\"a\",\"d\",\"c\",\"a\",\"c\"], \"cost\": [8,1,1,9,3,10,4] }\nassert my_solution.minimumCost(**test_input) == 48\n\ntest_input = { \"source\": \"accccbccda\", \"target\": \"daadbbcaac\", \"original\": [\"a\",\"c\",\"a\",\"a\",\"d\",\"d\"], \"changed\": [\"c\",\"d\",\"d\",\"b\",\"b\",\"c\"], \"cost\": [3,6,6,10,9,8] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"acdacbdadb\", \"target\": \"aacccbbacd\", \"original\": [\"b\",\"b\",\"a\",\"a\",\"d\",\"c\"], \"changed\": [\"d\",\"a\",\"b\",\"d\",\"a\",\"a\"], \"cost\": [6,1,9,6,8,11] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"acdbcdadbd\", \"target\": \"daaadaaadd\", \"original\": [\"c\",\"a\",\"b\",\"b\",\"b\",\"d\",\"a\"], \"changed\": [\"d\",\"c\",\"d\",\"c\",\"a\",\"b\",\"d\"], \"cost\": [3,9,4,6,1,9,3] }\nassert my_solution.minimumCost(**test_input) == 54\n\ntest_input = { \"source\": \"acddadcbca\", \"target\": \"ddaabaaaac\", \"original\": [\"b\",\"d\",\"c\",\"a\",\"b\",\"d\",\"c\",\"b\",\"d\",\"c\",\"a\"], \"changed\": [\"c\",\"a\",\"b\",\"c\",\"d\",\"c\",\"a\",\"a\",\"b\",\"d\",\"d\"], \"cost\": [7,8,2,10,1,7,8,1,1,11,4] }\nassert my_solution.minimumCost(**test_input) == 35\n\ntest_input = { \"source\": \"adaadcaddd\", \"target\": \"cdddbdccad\", \"original\": [\"c\",\"c\",\"c\",\"d\",\"b\",\"a\",\"d\"], \"changed\": [\"d\",\"a\",\"b\",\"b\",\"d\",\"b\",\"c\"], \"cost\": [10,9,2,2,7,1,10] }\nassert my_solution.minimumCost(**test_input) == 92\n\ntest_input = { \"source\": \"adaaddacba\", \"target\": \"aabbddbbdd\", \"original\": [\"c\",\"b\",\"a\",\"b\",\"c\",\"b\"], \"changed\": [\"b\",\"c\",\"b\",\"a\",\"d\",\"d\"], \"cost\": [10,7,7,6,8,5] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"adacdcdacd\", \"target\": \"ccbabbbbdc\", \"original\": [\"a\",\"b\",\"c\",\"a\",\"d\",\"b\",\"a\",\"c\"], \"changed\": [\"c\",\"d\",\"d\",\"d\",\"a\",\"c\",\"b\",\"a\"], \"cost\": [4,3,1,1,6,4,10,6] }\nassert my_solution.minimumCost(**test_input) == 99\n\ntest_input = { \"source\": \"adadbabcdd\", \"target\": \"abbcdcbdba\", \"original\": [\"c\",\"d\",\"b\",\"a\",\"c\",\"b\",\"a\"], \"changed\": [\"d\",\"b\",\"d\",\"b\",\"b\",\"a\",\"c\"], \"cost\": [11,10,6,1,5,3,8] }\nassert my_solution.minimumCost(**test_input) == 80\n\ntest_input = { \"source\": \"adadcabbda\", \"target\": \"cabadddccc\", \"original\": [\"c\",\"a\",\"b\",\"b\",\"a\",\"d\",\"d\"], \"changed\": [\"b\",\"d\",\"d\",\"c\",\"b\",\"c\",\"b\"], \"cost\": [7,2,8,4,4,4,7] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"adbaabacdc\", \"target\": \"bccbbadcdc\", \"original\": [\"c\",\"b\",\"b\",\"d\",\"c\",\"a\",\"b\"], \"changed\": [\"b\",\"a\",\"c\",\"a\",\"a\",\"d\",\"d\"], \"cost\": [5,2,6,1,7,7,1] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"adbadbaacb\", \"target\": \"bccdbdccab\", \"original\": [\"d\",\"a\",\"c\",\"b\",\"c\",\"d\",\"a\",\"b\",\"c\",\"b\",\"a\",\"d\"], \"changed\": [\"a\",\"c\",\"b\",\"c\",\"a\",\"b\",\"b\",\"d\",\"d\",\"a\",\"d\",\"c\"], \"cost\": [3,7,7,9,2,9,10,2,9,5,11,8] }\nassert my_solution.minimumCost(**test_input) == 65\n\ntest_input = { \"source\": \"adbcdaddda\", \"target\": \"cbdccabcbc\", \"original\": [\"c\",\"a\",\"d\",\"d\",\"b\",\"b\",\"b\"], \"changed\": [\"a\",\"c\",\"c\",\"a\",\"d\",\"c\",\"a\"], \"cost\": [8,5,5,10,10,3,9] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"adcacaaabb\", \"target\": \"daaadadcbb\", \"original\": [\"d\",\"b\",\"a\",\"a\",\"d\",\"c\",\"b\",\"b\",\"d\",\"c\",\"c\",\"a\"], \"changed\": [\"b\",\"c\",\"d\",\"c\",\"c\",\"a\",\"a\",\"d\",\"a\",\"b\",\"d\",\"b\"], \"cost\": [2,3,2,4,5,9,11,3,10,1,9,2] }\nassert my_solution.minimumCost(**test_input) == 31\n\ntest_input = { \"source\": \"adcbbbdada\", \"target\": \"cdaabadcdc\", \"original\": [\"a\",\"a\",\"b\",\"c\",\"d\",\"b\",\"d\"], \"changed\": [\"c\",\"d\",\"c\",\"d\",\"a\",\"a\",\"c\"], \"cost\": [11,11,2,8,5,7,5] }\nassert my_solution.minimumCost(**test_input) == 60\n\ntest_input = { \"source\": \"adccbabbca\", \"target\": \"dcdbbdabba\", \"original\": [\"a\",\"d\",\"d\",\"b\",\"c\",\"b\",\"a\"], \"changed\": [\"c\",\"b\",\"c\",\"c\",\"a\",\"d\",\"d\"], \"cost\": [5,10,10,1,6,7,7] }\nassert my_solution.minimumCost(**test_input) == 90\n\ntest_input = { \"source\": \"adcdcbacab\", \"target\": \"acddaddadc\", \"original\": [\"b\",\"d\",\"c\",\"d\",\"c\",\"d\",\"b\",\"c\",\"a\",\"a\",\"a\",\"b\"], \"changed\": [\"a\",\"b\",\"b\",\"c\",\"a\",\"a\",\"d\",\"d\",\"c\",\"b\",\"d\",\"c\"], \"cost\": [2,11,11,9,1,3,6,9,6,4,8,5] }\nassert my_solution.minimumCost(**test_input) == 47\n\ntest_input = { \"source\": \"addbaccbbd\", \"target\": \"cabdcdadcc\", \"original\": [\"b\",\"d\",\"d\",\"d\",\"c\",\"b\",\"a\",\"c\",\"c\"], \"changed\": [\"a\",\"c\",\"a\",\"b\",\"b\",\"d\",\"d\",\"a\",\"d\"], \"cost\": [10,11,5,6,10,1,4,8,8] }\nassert my_solution.minimumCost(**test_input) == 82\n\ntest_input = { \"source\": \"addbacdaac\", \"target\": \"abddcadbcb\", \"original\": [\"d\",\"a\",\"c\",\"b\",\"a\",\"c\",\"a\",\"d\",\"c\",\"d\",\"b\"], \"changed\": [\"c\",\"c\",\"b\",\"d\",\"d\",\"d\",\"b\",\"b\",\"a\",\"a\",\"c\"], \"cost\": [9,2,9,4,11,6,10,3,7,2,5] }\nassert my_solution.minimumCost(**test_input) == 37\n\ntest_input = { \"source\": \"addbcccdcb\", \"target\": \"cbbdbddacb\", \"original\": [\"d\",\"c\",\"a\",\"a\",\"b\",\"b\",\"c\"], \"changed\": [\"c\",\"d\",\"b\",\"d\",\"d\",\"c\",\"b\"], \"cost\": [2,6,4,3,7,7,8] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"addcadccaa\", \"target\": \"dbbcaccabc\", \"original\": [\"a\",\"b\",\"d\",\"b\",\"d\",\"a\",\"c\",\"b\",\"a\",\"c\"], \"changed\": [\"c\",\"d\",\"a\",\"c\",\"b\",\"b\",\"d\",\"a\",\"d\",\"a\"], \"cost\": [8,11,5,1,11,4,3,8,11,4] }\nassert my_solution.minimumCost(**test_input) == 49\n\ntest_input = { \"source\": \"addcdbdadb\", \"target\": \"bcabdcccbd\", \"original\": [\"b\",\"b\",\"a\",\"c\",\"d\",\"a\",\"b\",\"c\",\"a\"], \"changed\": [\"a\",\"c\",\"c\",\"a\",\"a\",\"b\",\"d\",\"b\",\"d\"], \"cost\": [2,4,8,8,3,5,2,7,2] }\nassert my_solution.minimumCost(**test_input) == 59\n\ntest_input = { \"source\": \"adddbbdbdb\", \"target\": \"cdbadcaccc\", \"original\": [\"b\",\"c\",\"c\",\"b\",\"a\",\"c\",\"b\",\"a\",\"a\",\"d\",\"d\"], \"changed\": [\"d\",\"a\",\"b\",\"a\",\"b\",\"d\",\"c\",\"c\",\"d\",\"a\",\"c\"], \"cost\": [1,1,1,8,6,9,3,6,5,3,10] }\nassert my_solution.minimumCost(**test_input) == 40\n\ntest_input = { \"source\": \"adddccacca\", \"target\": \"cdcdcccdac\", \"original\": [\"d\",\"c\",\"a\",\"d\",\"b\",\"b\",\"b\",\"a\",\"d\",\"a\",\"c\",\"c\"], \"changed\": [\"c\",\"a\",\"c\",\"a\",\"d\",\"a\",\"c\",\"b\",\"b\",\"d\",\"d\",\"b\"], \"cost\": [7,7,6,10,1,1,11,5,3,2,10,3] }\nassert my_solution.minimumCost(**test_input) == 33\n\ntest_input = { \"source\": \"baacbbcdaa\", \"target\": \"abdbdbbabd\", \"original\": [\"c\",\"d\",\"c\",\"b\",\"a\",\"c\",\"b\",\"d\",\"b\"], \"changed\": [\"d\",\"c\",\"b\",\"a\",\"d\",\"a\",\"d\",\"a\",\"c\"], \"cost\": [9,5,5,2,9,4,5,3,6] }\nassert my_solution.minimumCost(**test_input) == 76\n\ntest_input = { \"source\": \"baadcdabbc\", \"target\": \"acbccadccd\", \"original\": [\"b\",\"b\",\"a\",\"a\",\"a\",\"d\",\"d\",\"d\",\"c\",\"c\",\"b\"], \"changed\": [\"c\",\"a\",\"c\",\"b\",\"d\",\"c\",\"a\",\"b\",\"b\",\"d\",\"d\"], \"cost\": [8,6,5,10,11,1,1,6,3,1,4] }\nassert my_solution.minimumCost(**test_input) == 37\n\ntest_input = { \"source\": \"baadcdabda\", \"target\": \"abdbcdaaca\", \"original\": [\"b\",\"b\",\"c\",\"d\",\"d\",\"a\",\"c\"], \"changed\": [\"d\",\"a\",\"a\",\"b\",\"c\",\"b\",\"d\"], \"cost\": [11,8,7,3,10,4,1] }\nassert my_solution.minimumCost(**test_input) == 48\n\ntest_input = { \"source\": \"babababdba\", \"target\": \"ccdaaabbac\", \"original\": [\"c\",\"d\",\"b\",\"a\",\"d\",\"a\",\"b\"], \"changed\": [\"b\",\"a\",\"d\",\"c\",\"c\",\"d\",\"c\"], \"cost\": [8,5,6,2,8,6,8] }\nassert my_solution.minimumCost(**test_input) == 55\n\ntest_input = { \"source\": \"babbacabba\", \"target\": \"adacccdcba\", \"original\": [\"c\",\"d\",\"d\",\"d\",\"c\",\"b\",\"b\",\"b\",\"a\"], \"changed\": [\"a\",\"b\",\"c\",\"a\",\"d\",\"a\",\"c\",\"d\",\"c\"], \"cost\": [1,1,8,3,2,2,11,8,3] }\nassert my_solution.minimumCost(**test_input) == 27\n\ntest_input = { \"source\": \"babbadbabc\", \"target\": \"ccdabbcbba\", \"original\": [\"a\",\"c\",\"d\",\"a\",\"b\",\"d\",\"b\",\"b\"], \"changed\": [\"b\",\"d\",\"c\",\"d\",\"a\",\"a\",\"c\",\"d\"], \"cost\": [3,3,1,4,4,8,2,9] }\nassert my_solution.minimumCost(**test_input) == 46\n\ntest_input = { \"source\": \"bacbddaacb\", \"target\": \"dcdaaadcda\", \"original\": [\"a\",\"d\",\"a\",\"a\",\"d\",\"c\",\"b\",\"c\",\"c\",\"b\"], \"changed\": [\"d\",\"c\",\"c\",\"b\",\"b\",\"b\",\"a\",\"a\",\"d\",\"c\"], \"cost\": [8,5,1,10,8,6,2,1,6,8] }\nassert my_solution.minimumCost(**test_input) == 46\n\ntest_input = { \"source\": \"baccbbcdcb\", \"target\": \"cabadbbacc\", \"original\": [\"c\",\"a\",\"c\",\"b\",\"c\",\"d\",\"a\",\"b\",\"d\",\"b\"], \"changed\": [\"a\",\"b\",\"b\",\"a\",\"d\",\"b\",\"c\",\"d\",\"c\",\"c\"], \"cost\": [4,4,2,11,9,9,1,4,6,1] }\nassert my_solution.minimumCost(**test_input) == 24\n\ntest_input = { \"source\": \"bacdbbcdba\", \"target\": \"cdcdddbbcd\", \"original\": [\"d\",\"a\",\"c\",\"b\",\"d\",\"a\",\"b\",\"c\",\"b\",\"c\",\"d\"], \"changed\": [\"c\",\"c\",\"a\",\"d\",\"b\",\"b\",\"a\",\"d\",\"c\",\"b\",\"a\"], \"cost\": [3,8,4,6,5,8,6,2,1,6,2] }\nassert my_solution.minimumCost(**test_input) == 39\n\ntest_input = { \"source\": \"bacdbccabb\", \"target\": \"caaccdbaac\", \"original\": [\"c\",\"d\",\"d\",\"a\",\"d\",\"c\"], \"changed\": [\"d\",\"b\",\"a\",\"b\",\"c\",\"a\"], \"cost\": [8,4,4,4,3,6] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"bacddacdba\", \"target\": \"bcbbaacdda\", \"original\": [\"b\",\"c\",\"c\",\"d\",\"d\",\"b\",\"b\",\"d\",\"a\",\"a\",\"c\",\"a\"], \"changed\": [\"a\",\"b\",\"d\",\"b\",\"a\",\"c\",\"d\",\"c\",\"c\",\"d\",\"a\",\"b\"], \"cost\": [5,6,7,4,4,8,8,6,8,3,6,11] }\nassert my_solution.minimumCost(**test_input) == 30\n\ntest_input = { \"source\": \"badaabbaba\", \"target\": \"caadbcadcd\", \"original\": [\"b\",\"c\",\"a\",\"c\",\"d\",\"a\",\"b\",\"d\",\"d\",\"b\",\"c\"], \"changed\": [\"c\",\"a\",\"d\",\"b\",\"a\",\"c\",\"d\",\"c\",\"b\",\"a\",\"d\"], \"cost\": [4,8,6,3,1,8,3,8,3,6,9] }\nassert my_solution.minimumCost(**test_input) == 44\n\ntest_input = { \"source\": \"badabbbbac\", \"target\": \"dacaabbcaa\", \"original\": [\"d\",\"b\",\"a\",\"d\",\"c\",\"b\",\"d\",\"c\",\"a\",\"c\",\"a\"], \"changed\": [\"b\",\"c\",\"d\",\"c\",\"a\",\"d\",\"a\",\"d\",\"c\",\"b\",\"b\"], \"cost\": [11,5,9,7,11,11,7,9,6,11,5] }\nassert my_solution.minimumCost(**test_input) == 50\n\ntest_input = { \"source\": \"badaccbdbd\", \"target\": \"dbbdacaaab\", \"original\": [\"b\",\"d\",\"b\",\"c\",\"b\",\"d\",\"a\",\"d\",\"a\",\"a\",\"c\",\"c\"], \"changed\": [\"d\",\"a\",\"a\",\"a\",\"c\",\"b\",\"d\",\"c\",\"b\",\"c\",\"d\",\"b\"], \"cost\": [3,9,3,11,11,6,2,11,11,2,11,1] }\nassert my_solution.minimumCost(**test_input) == 39\n\ntest_input = { \"source\": \"badadcccba\", \"target\": \"bbdbababcc\", \"original\": [\"c\",\"c\",\"a\",\"d\",\"d\",\"d\"], \"changed\": [\"a\",\"d\",\"b\",\"a\",\"b\",\"c\"], \"cost\": [1,3,2,2,4,4] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"badbbbccdb\", \"target\": \"bbbabbccbd\", \"original\": [\"a\",\"c\",\"a\",\"c\",\"d\",\"c\",\"d\",\"b\",\"d\",\"b\",\"a\"], \"changed\": [\"c\",\"b\",\"d\",\"d\",\"c\",\"a\",\"b\",\"d\",\"a\",\"c\",\"b\"], \"cost\": [5,4,5,3,4,4,6,3,8,11,4] }\nassert my_solution.minimumCost(**test_input) == 30\n\ntest_input = { \"source\": \"badcbccabc\", \"target\": \"bdcaacbcad\", \"original\": [\"d\",\"d\",\"c\",\"d\",\"a\",\"b\",\"c\",\"a\"], \"changed\": [\"a\",\"c\",\"d\",\"b\",\"b\",\"a\",\"b\",\"d\"], \"cost\": [1,5,4,5,11,10,8,11] }\nassert my_solution.minimumCost(**test_input) == 69\n\ntest_input = { \"source\": \"badcbdddcd\", \"target\": \"cdcbaddadc\", \"original\": [\"c\",\"b\",\"c\",\"d\",\"a\",\"b\",\"b\",\"d\",\"a\",\"c\",\"a\",\"d\"], \"changed\": [\"a\",\"c\",\"b\",\"a\",\"c\",\"d\",\"a\",\"b\",\"d\",\"d\",\"b\",\"c\"], \"cost\": [3,2,8,9,11,5,11,11,9,2,8,1] }\nassert my_solution.minimumCost(**test_input) == 32\n\ntest_input = { \"source\": \"baddbcbdbd\", \"target\": \"acdbcadabd\", \"original\": [\"a\",\"b\",\"b\",\"c\",\"a\",\"a\",\"b\",\"d\",\"c\",\"d\",\"d\"], \"changed\": [\"c\",\"a\",\"d\",\"d\",\"b\",\"d\",\"c\",\"c\",\"b\",\"b\",\"a\"], \"cost\": [9,10,5,4,1,5,7,8,11,9,8] }\nassert my_solution.minimumCost(**test_input) == 59\n\ntest_input = { \"source\": \"baddbdacad\", \"target\": \"cadaccbbab\", \"original\": [\"b\",\"a\",\"d\",\"a\",\"c\",\"b\",\"d\",\"c\",\"a\",\"d\"], \"changed\": [\"d\",\"b\",\"b\",\"d\",\"a\",\"c\",\"a\",\"b\",\"c\",\"c\"], \"cost\": [3,5,6,7,2,4,4,2,3,9] }\nassert my_solution.minimumCost(**test_input) == 32\n\ntest_input = { \"source\": \"bbacdcdcda\", \"target\": \"cbadabbdcb\", \"original\": [\"a\",\"d\",\"b\",\"c\",\"b\",\"c\",\"d\",\"a\",\"d\"], \"changed\": [\"b\",\"c\",\"d\",\"a\",\"a\",\"b\",\"b\",\"d\",\"a\"], \"cost\": [11,6,2,8,5,7,5,8,9] }\nassert my_solution.minimumCost(**test_input) == 64\n\ntest_input = { \"source\": \"bbadbbabbb\", \"target\": \"cbaaddaddc\", \"original\": [\"d\",\"a\",\"b\",\"c\",\"d\",\"c\",\"b\"], \"changed\": [\"b\",\"d\",\"c\",\"b\",\"c\",\"d\",\"d\"], \"cost\": [4,10,1,11,7,1,11] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"bbadcbcbbc\", \"target\": \"aaaccbccbb\", \"original\": [\"b\",\"d\",\"b\",\"d\",\"a\",\"c\",\"c\",\"a\",\"b\"], \"changed\": [\"c\",\"a\",\"a\",\"b\",\"b\",\"a\",\"b\",\"c\",\"d\"], \"cost\": [8,5,9,4,1,10,1,11,4] }\nassert my_solution.minimumCost(**test_input) == 39\n\ntest_input = { \"source\": \"bbbadaccbb\", \"target\": \"dadcaccadb\", \"original\": [\"a\",\"d\",\"d\",\"d\",\"c\",\"b\",\"c\",\"b\",\"c\",\"b\"], \"changed\": [\"d\",\"b\",\"c\",\"a\",\"b\",\"d\",\"d\",\"c\",\"a\",\"a\"], \"cost\": [10,1,4,6,4,1,10,3,1,6] }\nassert my_solution.minimumCost(**test_input) == 41\n\ntest_input = { \"source\": \"bbbadcbadb\", \"target\": \"aacbdcddcd\", \"original\": [\"a\",\"d\",\"d\",\"c\",\"a\",\"b\",\"c\",\"b\"], \"changed\": [\"d\",\"b\",\"a\",\"a\",\"c\",\"c\",\"b\",\"d\"], \"cost\": [3,1,1,9,1,2,1,2] }\nassert my_solution.minimumCost(**test_input) == 19\n\ntest_input = { \"source\": \"bbbbabbcbc\", \"target\": \"adacababac\", \"original\": [\"a\",\"c\",\"a\",\"b\",\"b\",\"d\",\"d\",\"a\",\"d\",\"b\",\"c\"], \"changed\": [\"d\",\"b\",\"c\",\"c\",\"d\",\"a\",\"b\",\"b\",\"c\",\"a\",\"d\"], \"cost\": [7,9,9,7,3,2,6,8,11,5,8] }\nassert my_solution.minimumCost(**test_input) == 39\n\ntest_input = { \"source\": \"bbbbdacbcd\", \"target\": \"cbadccdaaa\", \"original\": [\"d\",\"a\",\"c\",\"b\",\"d\",\"c\",\"a\",\"d\",\"b\",\"a\"], \"changed\": [\"c\",\"c\",\"b\",\"c\",\"a\",\"d\",\"d\",\"b\",\"d\",\"b\"], \"cost\": [2,9,11,3,6,11,6,4,5,5] }\nassert my_solution.minimumCost(**test_input) == 74", "start_time": 1703385000} +{"task_id": "weekly-contest-377-minimum-cost-to-convert-string-ii", "url": "https://leetcode.com/problems/minimum-cost-to-convert-string-ii", "title": "minimum-cost-to-convert-string-ii", "meta": {"questionId": "3238", "questionFrontendId": "2977", "title": "Minimum Cost to Convert String II", "titleSlug": "minimum-cost-to-convert-string-ii", "isPaidOnly": false, "difficulty": "Hard", "likes": 40, "dislikes": 36, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你两个下标从 0 开始的字符串 source 和 target ,它们的长度均为 n 并且由 小写 英文字母组成。\n另给你两个下标从 0 开始的字符串数组 original 和 changed ,以及一个整数数组 cost ,其中 cost[i] 代表将字符串 original[i] 更改为字符串 changed[i] 的成本。\n你从字符串 source 开始。在一次操作中,如果 存在 任意 下标 j 满足 cost[j] == z 、original[j] == x 以及 changed[j] == y ,你就可以选择字符串中的 子串 x 并以 z 的成本将其更改为 y 。 你可以执行 任意数量 的操作,但是任两次操作必须满足 以下两个 条件 之一 :\n\n在两次操作中选择的子串分别是 source[a..b] 和 source[c..d] ,满足 b < c 或 d < a 。换句话说,两次操作中选择的下标 不相交 。\n在两次操作中选择的子串分别是 source[a..b] 和 source[c..d] ,满足 a == c 且 b == d 。换句话说,两次操作中选择的下标 相同 。\n\n返回将字符串 source 转换为字符串 target 所需的 最小 成本。如果不可能完成转换,则返回 -1 。\n注意,可能存在下标 i 、j 使得 original[j] == original[i] 且 changed[j] == changed[i] 。\n\n示例 1:\n\n输入:source = \"abcd\", target = \"acbe\", original = [\"a\",\"b\",\"c\",\"c\",\"e\",\"d\"], changed = [\"b\",\"c\",\"b\",\"e\",\"b\",\"e\"], cost = [2,5,5,1,2,20]\n输出:28\n解释:将 \"abcd\" 转换为 \"acbe\",执行以下操作:\n- 将子串 source[1..1] 从 \"b\" 改为 \"c\" ,成本为 5 。\n- 将子串 source[2..2] 从 \"c\" 改为 \"e\" ,成本为 1 。\n- 将子串 source[2..2] 从 \"e\" 改为 \"b\" ,成本为 2 。\n- 将子串 source[3..3] 从 \"d\" 改为 \"e\" ,成本为 20 。\n产生的总成本是 5 + 1 + 2 + 20 = 28 。 \n可以证明这是可能的最小成本。\n\n示例 2:\n\n输入:source = \"abcdefgh\", target = \"acdeeghh\", original = [\"bcd\",\"fgh\",\"thh\"], changed = [\"cde\",\"thh\",\"ghh\"], cost = [1,3,5]\n输出:9\n解释:将 \"abcdefgh\" 转换为 \"acdeeghh\",执行以下操作:\n- 将子串 source[1..3] 从 \"bcd\" 改为 \"cde\" ,成本为 1 。\n- 将子串 source[5..7] 从 \"fgh\" 改为 \"thh\" ,成本为 3 。可以执行此操作,因为下标 [5,7] 与第一次操作选中的下标不相交。\n- 将子串 source[5..7] 从 \"thh\" 改为 \"ghh\" ,成本为 5 。可以执行此操作,因为下标 [5,7] 与第一次操作选中的下标不相交,且与第二次操作选中的下标相同。\n产生的总成本是 1 + 3 + 5 = 9 。\n可以证明这是可能的最小成本。\n\n示例 3:\n\n输入:source = \"abcdefgh\", target = \"addddddd\", original = [\"bcd\",\"defgh\"], changed = [\"ddd\",\"ddddd\"], cost = [100,1578]\n输出:-1\n解释:无法将 \"abcdefgh\" 转换为 \"addddddd\" 。\n如果选择子串 source[1..3] 执行第一次操作,以将 \"abcdefgh\" 改为 \"adddefgh\" ,你无法选择子串 source[3..7] 执行第二次操作,因为两次操作有一个共用下标 3 。\n如果选择子串 source[3..7] 执行第一次操作,以将 \"abcdefgh\" 改为 \"abcddddd\" ,你无法选择子串 source[1..3] 执行第二次操作,因为两次操作有一个共用下标 3 。\n\n\n提示:\n\n1 <= source.length == target.length <= 1000\nsource、target 均由小写英文字母组成\n1 <= cost.length == original.length == changed.length <= 100\n1 <= original[i].length == changed[i].length <= source.length\noriginal[i]、changed[i] 均由小写英文字母组成\noriginal[i] != changed[i]\n1 <= cost[i] <= 106\n\"\"\"\nclass Solution:\n def minimumCost(self, source: str, target: str, original: List[str], changed: List[str], cost: List[int]) -> int:\n ", "prompt_sft": "给你两个下标从 0 开始的字符串 source 和 target ,它们的长度均为 n 并且由 小写 英文字母组成。\n另给你两个下标从 0 开始的字符串数组 original 和 changed ,以及一个整数数组 cost ,其中 cost[i] 代表将字符串 original[i] 更改为字符串 changed[i] 的成本。\n你从字符串 source 开始。在一次操作中,如果 存在 任意 下标 j 满足 cost[j] == z 、original[j] == x 以及 changed[j] == y ,你就可以选择字符串中的 子串 x 并以 z 的成本将其更改为 y 。 你可以执行 任意数量 的操作,但是任两次操作必须满足 以下两个 条件 之一 :\n\n在两次操作中选择的子串分别是 source[a..b] 和 source[c..d] ,满足 b < c 或 d < a 。换句话说,两次操作中选择的下标 不相交 。\n在两次操作中选择的子串分别是 source[a..b] 和 source[c..d] ,满足 a == c 且 b == d 。换句话说,两次操作中选择的下标 相同 。\n\n返回将字符串 source 转换为字符串 target 所需的 最小 成本。如果不可能完成转换,则返回 -1 。\n注意,可能存在下标 i 、j 使得 original[j] == original[i] 且 changed[j] == changed[i] 。\n\n示例 1:\n\n输入:source = \"abcd\", target = \"acbe\", original = [\"a\",\"b\",\"c\",\"c\",\"e\",\"d\"], changed = [\"b\",\"c\",\"b\",\"e\",\"b\",\"e\"], cost = [2,5,5,1,2,20]\n输出:28\n解释:将 \"abcd\" 转换为 \"acbe\",执行以下操作:\n- 将子串 source[1..1] 从 \"b\" 改为 \"c\" ,成本为 5 。\n- 将子串 source[2..2] 从 \"c\" 改为 \"e\" ,成本为 1 。\n- 将子串 source[2..2] 从 \"e\" 改为 \"b\" ,成本为 2 。\n- 将子串 source[3..3] 从 \"d\" 改为 \"e\" ,成本为 20 。\n产生的总成本是 5 + 1 + 2 + 20 = 28 。 \n可以证明这是可能的最小成本。\n\n示例 2:\n\n输入:source = \"abcdefgh\", target = \"acdeeghh\", original = [\"bcd\",\"fgh\",\"thh\"], changed = [\"cde\",\"thh\",\"ghh\"], cost = [1,3,5]\n输出:9\n解释:将 \"abcdefgh\" 转换为 \"acdeeghh\",执行以下操作:\n- 将子串 source[1..3] 从 \"bcd\" 改为 \"cde\" ,成本为 1 。\n- 将子串 source[5..7] 从 \"fgh\" 改为 \"thh\" ,成本为 3 。可以执行此操作,因为下标 [5,7] 与第一次操作选中的下标不相交。\n- 将子串 source[5..7] 从 \"thh\" 改为 \"ghh\" ,成本为 5 。可以执行此操作,因为下标 [5,7] 与第一次操作选中的下标不相交,且与第二次操作选中的下标相同。\n产生的总成本是 1 + 3 + 5 = 9 。\n可以证明这是可能的最小成本。\n\n示例 3:\n\n输入:source = \"abcdefgh\", target = \"addddddd\", original = [\"bcd\",\"defgh\"], changed = [\"ddd\",\"ddddd\"], cost = [100,1578]\n输出:-1\n解释:无法将 \"abcdefgh\" 转换为 \"addddddd\" 。\n如果选择子串 source[1..3] 执行第一次操作,以将 \"abcdefgh\" 改为 \"adddefgh\" ,你无法选择子串 source[3..7] 执行第二次操作,因为两次操作有一个共用下标 3 。\n如果选择子串 source[3..7] 执行第一次操作,以将 \"abcdefgh\" 改为 \"abcddddd\" ,你无法选择子串 source[1..3] 执行第二次操作,因为两次操作有一个共用下标 3 。\n\n\n提示:\n\n1 <= source.length == target.length <= 1000\nsource、target 均由小写英文字母组成\n1 <= cost.length == original.length == changed.length <= 100\n1 <= original[i].length == changed[i].length <= source.length\noriginal[i]、changed[i] 均由小写英文字母组成\noriginal[i] != changed[i]\n1 <= cost[i] <= 106\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def minimumCost(self, source: str, target: str, original: List[str], changed: List[str], cost: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"source\": \"abcd\", \"target\": \"acbe\", \"original\": [\"a\",\"b\",\"c\",\"c\",\"e\",\"d\"], \"changed\": [\"b\",\"c\",\"b\",\"e\",\"b\",\"e\"], \"cost\": [2,5,5,1,2,20] }\nassert my_solution.minimumCost(**test_input) == 28\n\ntest_input = { \"source\": \"abcdefgh\", \"target\": \"acdeeghh\", \"original\": [\"bcd\",\"fgh\",\"thh\"], \"changed\": [\"cde\",\"thh\",\"ghh\"], \"cost\": [1,3,5] }\nassert my_solution.minimumCost(**test_input) == 9\n\ntest_input = { \"source\": \"abcdefgh\", \"target\": \"addddddd\", \"original\": [\"bcd\",\"defgh\"], \"changed\": [\"ddd\",\"ddddd\"], \"cost\": [100,1578] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"a\", \"target\": \"b\", \"original\": [\"a\"], \"changed\": [\"b\"], \"cost\": [1] }\nassert my_solution.minimumCost(**test_input) == 1\n\ntest_input = { \"source\": \"a\", \"target\": \"c\", \"original\": [\"a\",\"b\",\"a\",\"a\"], \"changed\": [\"b\",\"c\",\"c\",\"c\"], \"cost\": [1,2,10,1] }\nassert my_solution.minimumCost(**test_input) == 1\n\ntest_input = { \"source\": \"a\", \"target\": \"d\", \"original\": [\"a\"], \"changed\": [\"b\"], \"cost\": [1] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"ajhpd\", \"target\": \"djjdc\", \"original\": [\"hpd\",\"iyk\",\"qzd\",\"hpi\",\"aic\",\"znh\",\"cea\",\"fug\",\"wir\",\"kwu\",\"yjo\",\"rzi\",\"a\",\"n\",\"f\",\"q\",\"u\",\"w\",\"x\",\"i\",\"x\",\"s\",\"o\",\"u\"], \"changed\": [\"iyk\",\"qzd\",\"hpi\",\"aic\",\"znh\",\"cea\",\"fug\",\"wir\",\"kwu\",\"yjo\",\"rzi\",\"jdc\",\"n\",\"f\",\"q\",\"u\",\"w\",\"x\",\"i\",\"x\",\"s\",\"o\",\"u\",\"d\"], \"cost\": [80257,95140,96349,89449,81714,5859,96734,96109,41211,99975,57611,32644,82896,22164,99889,98061,95403,90922,64031,94558,58418,99717,96588,88286] }\nassert my_solution.minimumCost(**test_input) == 1264348\n\ntest_input = { \"source\": \"bzshh\", \"target\": \"mlosr\", \"original\": [\"shh\",\"wbs\",\"hup\",\"sab\",\"csp\",\"tel\",\"mhq\",\"ezp\",\"eap\",\"fqb\",\"iea\",\"cej\",\"b\",\"v\",\"g\",\"e\",\"d\",\"x\",\"q\",\"v\",\"g\",\"x\",\"u\",\"m\",\"u\",\"q\",\"z\",\"q\",\"n\",\"p\"], \"changed\": [\"wbs\",\"hup\",\"sab\",\"csp\",\"tel\",\"mhq\",\"ezp\",\"eap\",\"fqb\",\"iea\",\"cej\",\"osr\",\"v\",\"g\",\"e\",\"d\",\"x\",\"q\",\"v\",\"g\",\"x\",\"u\",\"m\",\"u\",\"q\",\"m\",\"q\",\"n\",\"p\",\"l\"], \"cost\": [69565,82190,75322,85502,89675,98424,86521,85852,32285,99465,82356,97775,30173,88276,82158,40971,75361,65284,89814,68219,44777,95082,99781,99072,74513,49667,99719,93132,99203,54171] }\nassert my_solution.minimumCost(**test_input) == 1589277\n\ntest_input = { \"source\": \"fjybg\", \"target\": \"apyyt\", \"original\": [\"bg\",\"xr\",\"cc\",\"ip\",\"vq\",\"po\",\"ym\",\"rh\",\"vw\",\"lf\",\"lo\",\"ee\",\"qv\",\"yr\",\"f\",\"w\",\"i\",\"u\",\"g\",\"a\",\"e\",\"f\",\"s\",\"r\",\"p\",\"j\",\"o\",\"g\",\"i\",\"u\"], \"changed\": [\"xr\",\"cc\",\"ip\",\"vq\",\"po\",\"ym\",\"rh\",\"vw\",\"lf\",\"lo\",\"ee\",\"qv\",\"yr\",\"yt\",\"w\",\"i\",\"u\",\"g\",\"a\",\"e\",\"f\",\"s\",\"r\",\"p\",\"a\",\"o\",\"g\",\"i\",\"u\",\"p\"], \"cost\": [97733,90086,87125,85361,75644,46301,21616,79538,52507,95884,79353,61127,58665,96031,95035,12116,41158,91096,47819,88522,25493,80186,66981,87597,56691,86820,89031,99954,41271,39699] }\nassert my_solution.minimumCost(**test_input) == 1628332\n\ntest_input = { \"source\": \"htkdz\", \"target\": \"oaqaw\", \"original\": [\"kdz\",\"yyv\",\"cde\",\"oks\",\"fzu\",\"hkm\",\"dmb\",\"arh\",\"lix\",\"eij\",\"ksv\",\"t\",\"u\",\"f\",\"w\",\"b\",\"u\",\"v\",\"h\",\"o\",\"b\",\"o\",\"p\",\"z\",\"h\",\"w\",\"t\",\"p\",\"x\",\"y\"], \"changed\": [\"yyv\",\"cde\",\"oks\",\"fzu\",\"hkm\",\"dmb\",\"arh\",\"lix\",\"eij\",\"ksv\",\"qaw\",\"u\",\"f\",\"w\",\"b\",\"u\",\"v\",\"h\",\"o\",\"b\",\"o\",\"p\",\"z\",\"a\",\"w\",\"t\",\"p\",\"x\",\"y\",\"o\"], \"cost\": [90243,86765,84893,80924,85915,42672,99995,99429,88069,84925,71184,54929,83245,72750,87238,30151,58657,94445,98330,90683,83980,96513,75536,95212,79301,74556,94836,94781,76273,86147] }\nassert my_solution.minimumCost(**test_input) == 1278928\n\ntest_input = { \"source\": \"iktgh\", \"target\": \"srwcg\", \"original\": [\"h\",\"e\",\"y\",\"g\",\"q\",\"y\",\"t\",\"n\",\"r\",\"e\",\"i\",\"x\",\"iktg\",\"xwgv\",\"ddrp\",\"saxt\",\"rvdq\",\"moiy\",\"loln\",\"bkgj\",\"jjgi\",\"vatf\"], \"changed\": [\"e\",\"y\",\"g\",\"q\",\"y\",\"t\",\"n\",\"r\",\"e\",\"i\",\"x\",\"g\",\"xwgv\",\"ddrp\",\"saxt\",\"rvdq\",\"moiy\",\"loln\",\"bkgj\",\"jjgi\",\"vatf\",\"srwc\"], \"cost\": [70839,75691,55903,82637,97906,86576,92197,74464,86638,61531,80041,52732,96361,39766,74988,59857,69068,89990,74293,82838,37650,26885] }\nassert my_solution.minimumCost(**test_input) == 854129\n\ntest_input = { \"source\": \"imbin\", \"target\": \"dmhjv\", \"original\": [\"bin\",\"pwo\",\"fwt\",\"xwi\",\"xal\",\"uqt\",\"lmp\",\"erq\",\"kac\",\"dgv\",\"qgh\",\"rei\",\"nbx\",\"i\",\"u\",\"b\",\"v\",\"c\",\"q\",\"p\",\"f\",\"q\",\"v\",\"t\",\"n\",\"b\"], \"changed\": [\"pwo\",\"fwt\",\"xwi\",\"xal\",\"uqt\",\"lmp\",\"erq\",\"kac\",\"dgv\",\"qgh\",\"rei\",\"nbx\",\"hjv\",\"u\",\"b\",\"v\",\"c\",\"q\",\"p\",\"f\",\"q\",\"v\",\"t\",\"n\",\"b\",\"d\"], \"cost\": [47307,30907,64949,35735,84284,83424,69858,92113,51405,69242,97014,91471,78165,92733,79709,99573,78055,20529,85549,90496,60896,75354,50630,49094,41380,46980] }\nassert my_solution.minimumCost(**test_input) == 1115296\n\ntest_input = { \"source\": \"jegbx\", \"target\": \"ezhfc\", \"original\": [\"egbx\",\"hrbf\",\"twne\",\"snjd\",\"ysrf\",\"qzqg\",\"rcll\",\"ekvz\",\"inpr\",\"frxs\",\"xcww\",\"unsw\",\"vdug\",\"ycvs\",\"j\",\"v\",\"j\",\"y\",\"n\",\"q\",\"w\",\"a\",\"z\",\"g\",\"b\",\"d\"], \"changed\": [\"hrbf\",\"twne\",\"snjd\",\"ysrf\",\"qzqg\",\"rcll\",\"ekvz\",\"inpr\",\"frxs\",\"xcww\",\"unsw\",\"vdug\",\"ycvs\",\"zhfc\",\"v\",\"j\",\"y\",\"n\",\"q\",\"w\",\"a\",\"z\",\"g\",\"b\",\"d\",\"e\"], \"cost\": [50682,89150,91153,85032,97960,96862,81138,86570,77628,45200,44955,70845,99254,80325,91331,95349,84374,94177,53994,94284,79531,92353,60384,100000,93152,19787] }\nassert my_solution.minimumCost(**test_input) == 1868790\n\ntest_input = { \"source\": \"jpyjj\", \"target\": \"jqnfp\", \"original\": [\"j\",\"i\",\"q\",\"u\",\"y\",\"w\",\"d\",\"a\",\"h\",\"s\",\"i\",\"y\",\"w\",\"pyj\",\"qng\",\"lrn\",\"nrm\",\"tvn\",\"fei\",\"fpj\",\"qlw\",\"lrb\",\"ufu\",\"kll\",\"nqp\"], \"changed\": [\"i\",\"q\",\"u\",\"y\",\"w\",\"d\",\"a\",\"h\",\"s\",\"i\",\"y\",\"w\",\"p\",\"qng\",\"lrn\",\"nrm\",\"tvn\",\"fei\",\"fpj\",\"qlw\",\"lrb\",\"ufu\",\"kll\",\"nqp\",\"qnf\"], \"cost\": [62657,90954,55348,88767,87756,55487,49700,51801,94877,81661,99027,91814,62872,25235,62153,96875,12009,85321,68993,75866,72888,96411,78568,83975,60456] }\nassert my_solution.minimumCost(**test_input) == 1131062\n\ntest_input = { \"source\": \"nialx\", \"target\": \"qvqfl\", \"original\": [\"x\",\"r\",\"a\",\"x\",\"c\",\"w\",\"s\",\"a\",\"n\",\"e\",\"q\",\"p\",\"v\",\"k\",\"o\",\"ial\",\"qzu\",\"owr\",\"kyq\",\"ukk\",\"gpq\",\"jdp\",\"dus\",\"eng\",\"btu\",\"cbp\"], \"changed\": [\"r\",\"a\",\"x\",\"c\",\"w\",\"s\",\"a\",\"l\",\"e\",\"q\",\"p\",\"v\",\"k\",\"o\",\"q\",\"qzu\",\"owr\",\"kyq\",\"ukk\",\"gpq\",\"jdp\",\"dus\",\"eng\",\"btu\",\"cbp\",\"vqf\"], \"cost\": [64196,95812,96987,40860,41507,99365,99208,53062,44440,65136,95625,86166,61798,84228,92555,97678,97576,19742,92989,98167,68457,82411,39923,81778,87792,7523] }\nassert my_solution.minimumCost(**test_input) == 1096682\n\ntest_input = { \"source\": \"pagpe\", \"target\": \"xacng\", \"original\": [\"gpe\",\"owt\",\"wyv\",\"eba\",\"xgp\",\"uny\",\"ibc\",\"usb\",\"mzj\",\"wdo\",\"lyc\",\"eof\",\"oci\",\"p\",\"e\",\"p\",\"u\",\"h\",\"w\",\"i\",\"l\"], \"changed\": [\"owt\",\"wyv\",\"eba\",\"xgp\",\"uny\",\"ibc\",\"usb\",\"mzj\",\"wdo\",\"lyc\",\"eof\",\"oci\",\"cng\",\"e\",\"p\",\"u\",\"h\",\"w\",\"i\",\"l\",\"x\"], \"cost\": [56193,92982,90717,67407,91949,77752,88841,43278,51149,43646,99585,41038,84989,57688,64474,96532,77511,37031,90895,62831,87342] }\nassert my_solution.minimumCost(**test_input) == 1381668\n\ntest_input = { \"source\": \"aaabbebbbhbbbbebaaeh\", \"target\": \"hhbebebbahhhehhbbhee\", \"original\": [\"a\",\"b\",\"b\",\"b\",\"e\",\"a\",\"h\"], \"changed\": [\"b\",\"e\",\"a\",\"h\",\"h\",\"h\",\"e\"], \"cost\": [9,8,5,9,3,7,9] }\nassert my_solution.minimumCost(**test_input) == 99\n\ntest_input = { \"source\": \"abbbeebebehbbhhhbeab\", \"target\": \"aehebehebaeaebbaahhb\", \"original\": [\"b\",\"b\",\"e\",\"e\",\"h\",\"h\",\"h\",\"b\",\"e\",\"a\"], \"changed\": [\"e\",\"h\",\"b\",\"a\",\"e\",\"b\",\"a\",\"a\",\"h\",\"h\"], \"cost\": [10,2,9,10,7,8,10,10,6,9] }\nassert my_solution.minimumCost(**test_input) == 118\n\ntest_input = { \"source\": \"abebbeeeahhbahaehaab\", \"target\": \"eebhheeahaahbaebaaea\", \"original\": [\"a\",\"b\",\"e\",\"a\",\"h\",\"a\",\"e\",\"b\"], \"changed\": [\"e\",\"h\",\"a\",\"h\",\"a\",\"b\",\"b\",\"a\"], \"cost\": [6,8,5,10,10,10,10,8] }\nassert my_solution.minimumCost(**test_input) == 149\n\ntest_input = { \"source\": \"aeaaebhbhehbeehbehea\", \"target\": \"babehheaaeebeebahhba\", \"original\": [\"a\",\"e\",\"a\",\"e\",\"b\",\"h\",\"b\",\"h\",\"h\",\"e\"], \"changed\": [\"b\",\"a\",\"e\",\"h\",\"h\",\"e\",\"a\",\"a\",\"b\",\"b\"], \"cost\": [8,6,3,8,7,9,9,10,10,5] }\nassert my_solution.minimumCost(**test_input) == 109\n\ntest_input = { \"source\": \"aeehhhaeebhhbeabeeha\", \"target\": \"haaeaabeeeheehbaehha\", \"original\": [\"a\",\"e\",\"h\",\"a\",\"h\",\"b\",\"e\",\"b\"], \"changed\": [\"h\",\"a\",\"a\",\"b\",\"e\",\"e\",\"h\",\"a\"], \"cost\": [7,9,10,7,8,9,8,8] }\nassert my_solution.minimumCost(**test_input) == 117\n\ntest_input = { \"source\": \"ahhebhhbbhbebaeehbbh\", \"target\": \"hbebaeebebhabeehahhb\", \"original\": [\"a\",\"h\",\"h\",\"b\",\"b\",\"e\",\"a\",\"e\",\"h\",\"b\"], \"changed\": [\"h\",\"b\",\"e\",\"a\",\"e\",\"a\",\"e\",\"h\",\"a\",\"h\"], \"cost\": [4,8,2,8,9,9,9,8,9,6] }\nassert my_solution.minimumCost(**test_input) == 116\n\ntest_input = { \"source\": \"babhbaaabbabehhhaaea\", \"target\": \"aabhhaebehbaehahbahb\", \"original\": [\"b\",\"b\",\"a\",\"a\",\"e\"], \"changed\": [\"a\",\"h\",\"e\",\"b\",\"h\"], \"cost\": [2,10,8,4,6] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"bbaaaebhhbehaaaabbab\", \"target\": \"aebahaaabheebbaehbbb\", \"original\": [\"b\",\"b\",\"a\",\"e\",\"h\",\"h\",\"a\",\"a\",\"b\"], \"changed\": [\"a\",\"e\",\"h\",\"a\",\"a\",\"b\",\"b\",\"e\",\"h\"], \"cost\": [6,8,3,10,10,7,7,9,10] }\nassert my_solution.minimumCost(**test_input) == 120\n\ntest_input = { \"source\": \"bbabeehehhbhbhbbaabb\", \"target\": \"heaabheabehhahhabhhe\", \"original\": [\"b\",\"b\",\"b\",\"e\",\"h\",\"e\",\"h\",\"a\",\"a\"], \"changed\": [\"h\",\"e\",\"a\",\"b\",\"e\",\"a\",\"b\",\"b\",\"h\"], \"cost\": [7,6,5,9,7,3,10,10,6] }\nassert my_solution.minimumCost(**test_input) == 116\n\ntest_input = { \"source\": \"bbhbahbbbabhbbbbbhaa\", \"target\": \"aheebebehaeheehhbahh\", \"original\": [\"b\",\"b\",\"h\",\"b\",\"a\",\"a\"], \"changed\": [\"a\",\"h\",\"e\",\"e\",\"b\",\"h\"], \"cost\": [3,5,9,9,5,10] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"beeeaehhbbbaeaeebabh\", \"target\": \"ahehaahaaehhabaehbah\", \"original\": [\"b\",\"e\",\"e\",\"h\",\"b\",\"a\",\"a\"], \"changed\": [\"a\",\"h\",\"a\",\"a\",\"h\",\"h\",\"b\"], \"cost\": [3,5,5,10,1,7,2] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"bhabahbhabaahbhahabb\", \"target\": \"ehbbhehbbhebaeeheebe\", \"original\": [\"a\",\"a\",\"h\",\"b\",\"h\",\"a\"], \"changed\": [\"b\",\"h\",\"e\",\"h\",\"b\",\"e\"], \"cost\": [9,10,5,10,10,8] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"bhhbaaahheaebehhabeh\", \"target\": \"bbhebbeeahahhbeabeba\", \"original\": [\"h\",\"b\",\"h\",\"h\",\"e\",\"b\",\"e\",\"a\"], \"changed\": [\"b\",\"e\",\"e\",\"a\",\"h\",\"h\",\"b\",\"b\"], \"cost\": [2,8,8,8,10,7,5,7] }\nassert my_solution.minimumCost(**test_input) == 131\n\ntest_input = { \"source\": \"eaabhhahhhehbabaabae\", \"target\": \"bebaehabeehehbehhahh\", \"original\": [\"a\",\"a\",\"b\",\"h\",\"h\",\"b\",\"a\",\"e\"], \"changed\": [\"e\",\"b\",\"a\",\"e\",\"b\",\"e\",\"h\",\"h\"], \"cost\": [9,9,9,8,6,4,7,10] }\nassert my_solution.minimumCost(**test_input) == 158\n\ntest_input = { \"source\": \"ebbaebeheabhheeeaeaa\", \"target\": \"eehbhebhheeabehbebea\", \"original\": [\"b\",\"a\",\"e\",\"e\",\"h\",\"h\",\"a\"], \"changed\": [\"e\",\"b\",\"h\",\"b\",\"a\",\"b\",\"e\"], \"cost\": [6,9,10,7,7,7,9] }\nassert my_solution.minimumCost(**test_input) == 135\n\ntest_input = { \"source\": \"ebbhbheeaeaeeahehahh\", \"target\": \"ehhebhahhhhheaaaaahb\", \"original\": [\"b\",\"h\",\"e\",\"a\",\"h\",\"e\",\"h\"], \"changed\": [\"h\",\"e\",\"h\",\"h\",\"a\",\"a\",\"b\"], \"cost\": [10,7,10,8,10,3,9] }\nassert my_solution.minimumCost(**test_input) == 108\n\ntest_input = { \"source\": \"eebhehaabeaaaaheheha\", \"target\": \"abbbaeaebbhabehbabbb\", \"original\": [\"e\",\"h\",\"e\",\"h\",\"a\",\"a\",\"a\",\"h\"], \"changed\": [\"b\",\"b\",\"a\",\"e\",\"h\",\"b\",\"e\",\"a\"], \"cost\": [10,10,10,8,9,6,10,10] }\nassert my_solution.minimumCost(**test_input) == 139\n\ntest_input = { \"source\": \"eeeaehbabbebhhaehaha\", \"target\": \"hehbbahabhhababeeeeh\", \"original\": [\"e\",\"a\",\"e\",\"h\",\"b\",\"h\",\"h\",\"a\",\"a\"], \"changed\": [\"h\",\"b\",\"b\",\"a\",\"h\",\"b\",\"e\",\"e\",\"h\"], \"cost\": [3,9,4,8,9,10,6,10,6] }\nassert my_solution.minimumCost(**test_input) == 120\n\ntest_input = { \"source\": \"eeehababeeeheebeehah\", \"target\": \"hhhabbbbahhehhhbhbab\", \"original\": [\"e\",\"h\",\"a\",\"e\",\"h\",\"b\",\"e\"], \"changed\": [\"h\",\"a\",\"b\",\"a\",\"e\",\"h\",\"b\"], \"cost\": [7,8,6,10,10,10,9] }\nassert my_solution.minimumCost(**test_input) == 143\n\ntest_input = { \"source\": \"eehhhbbhebeeehahaaae\", \"target\": \"bahaeebhbhhebbbahbhh\", \"original\": [\"e\",\"h\",\"b\",\"b\",\"e\",\"e\",\"h\",\"a\",\"h\",\"a\"], \"changed\": [\"a\",\"e\",\"e\",\"h\",\"h\",\"b\",\"b\",\"b\",\"a\",\"h\"], \"cost\": [9,9,9,5,3,8,10,2,2,1] }\nassert my_solution.minimumCost(**test_input) == 69\n\ntest_input = { \"source\": \"ehaaeabaebaehbbhbhbe\", \"target\": \"baheeebehhebhbeebbbe\", \"original\": [\"e\",\"h\",\"a\",\"a\",\"e\",\"b\",\"b\",\"h\"], \"changed\": [\"b\",\"a\",\"h\",\"e\",\"h\",\"h\",\"e\",\"e\"], \"cost\": [8,8,4,10,7,10,10,10] }\nassert my_solution.minimumCost(**test_input) == 123\n\ntest_input = { \"source\": \"ehaehehbeebaebaeebeb\", \"target\": \"eehhebaheaheahhhbeaa\", \"original\": [\"h\",\"e\",\"b\",\"e\",\"a\",\"a\",\"e\",\"b\",\"b\"], \"changed\": [\"e\",\"h\",\"h\",\"a\",\"e\",\"h\",\"b\",\"e\",\"a\"], \"cost\": [9,8,8,10,10,10,3,10,9] }\nassert my_solution.minimumCost(**test_input) == 162\n\ntest_input = { \"source\": \"ehbahbbaabhbabahbbhh\", \"target\": \"ahbhbehbahaehhaaehhh\", \"original\": [\"a\",\"b\",\"h\"], \"changed\": [\"h\",\"h\",\"a\"], \"cost\": [9,9,2] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"ehbeabbhhebhbahbhbab\", \"target\": \"hhbaaebbaaabhhbehhae\", \"original\": [\"e\",\"e\",\"b\",\"h\",\"b\",\"a\",\"b\"], \"changed\": [\"h\",\"a\",\"a\",\"b\",\"h\",\"h\",\"e\"], \"cost\": [3,8,10,7,5,10,10] }\nassert my_solution.minimumCost(**test_input) == 117\n\ntest_input = { \"source\": \"hbhheeehehbbhbbehaae\", \"target\": \"aebhbheehbbbhabbhebh\", \"original\": [\"h\",\"b\",\"h\",\"e\",\"h\",\"e\",\"a\",\"a\"], \"changed\": [\"a\",\"e\",\"b\",\"h\",\"e\",\"b\",\"e\",\"b\"], \"cost\": [3,9,8,10,7,8,4,9] }\nassert my_solution.minimumCost(**test_input) == 116\n\ntest_input = { \"source\": \"hebeebhhhhabaaheabbh\", \"target\": \"aeheabaeaaeababeheae\", \"original\": [\"h\",\"b\",\"h\",\"a\",\"b\",\"a\",\"h\",\"a\",\"b\"], \"changed\": [\"a\",\"h\",\"e\",\"e\",\"a\",\"b\",\"b\",\"h\",\"e\"], \"cost\": [10,6,8,10,10,5,10,10,2] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"hebhhaaaahbehahebaba\", \"target\": \"ahhabehbahehhahaehhh\", \"original\": [\"h\",\"b\",\"h\",\"a\",\"a\",\"b\",\"e\",\"e\"], \"changed\": [\"a\",\"h\",\"b\",\"e\",\"h\",\"e\",\"h\",\"a\"], \"cost\": [6,6,10,9,7,10,10,7] }\nassert my_solution.minimumCost(**test_input) == 128\n\ntest_input = { \"source\": \"hheahabebabhehahaahe\", \"target\": \"eaahbbbaehhhahhhebhe\", \"original\": [\"h\",\"h\",\"e\",\"a\",\"a\",\"b\",\"a\"], \"changed\": [\"e\",\"a\",\"a\",\"b\",\"h\",\"h\",\"e\"], \"cost\": [3,10,10,8,10,10,10] }\nassert my_solution.minimumCost(**test_input) == 140\n\ntest_input = { \"source\": \"hhebabehhhhbehaahbhh\", \"target\": \"ehhabeahaheaabbehhbe\", \"original\": [\"h\",\"e\",\"b\",\"a\",\"b\",\"e\",\"h\",\"h\",\"b\"], \"changed\": [\"e\",\"h\",\"a\",\"b\",\"e\",\"a\",\"a\",\"b\",\"h\"], \"cost\": [5,3,9,10,10,6,9,5,10] }\nassert my_solution.minimumCost(**test_input) == 127\n\ntest_input = { \"source\": \"hhhbbbhhaeabhheaehea\", \"target\": \"bebhhaeheahhebbeeahb\", \"original\": [\"h\",\"h\",\"b\",\"a\",\"e\",\"a\",\"e\",\"h\",\"e\",\"a\"], \"changed\": [\"b\",\"e\",\"h\",\"e\",\"a\",\"h\",\"b\",\"a\",\"h\",\"b\"], \"cost\": [10,6,8,9,6,8,10,5,8,9] }\nassert my_solution.minimumCost(**test_input) == 149\n\ntest_input = { \"source\": \"anrlqxdnlqcxqdlsceokwgrzkakyqw\", \"target\": \"fxynzghpiexaarjuaepxxpaudqipxx\", \"original\": [\"a\",\"n\",\"r\",\"l\",\"q\",\"x\",\"d\",\"n\",\"l\",\"q\",\"d\",\"s\",\"k\",\"w\",\"g\",\"z\",\"k\",\"a\",\"k\",\"q\"], \"changed\": [\"f\",\"x\",\"y\",\"n\",\"z\",\"g\",\"h\",\"p\",\"i\",\"a\",\"r\",\"u\",\"x\",\"x\",\"p\",\"u\",\"d\",\"q\",\"i\",\"x\"], \"cost\": [78,19,91,27,96,16,95,100,38,99,99,94,82,75,71,100,96,88,78,89] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"ayvhtgqvcputvzdksluictwibnvlxx\", \"target\": \"pssmcmkjyqniiyiiubwghwldxptuix\", \"original\": [\"a\",\"h\",\"t\",\"g\",\"v\",\"c\",\"t\",\"v\",\"z\",\"d\",\"k\",\"s\",\"l\",\"u\",\"i\",\"c\",\"w\",\"b\",\"v\",\"l\",\"x\"], \"changed\": [\"p\",\"m\",\"c\",\"m\",\"j\",\"y\",\"i\",\"i\",\"y\",\"i\",\"i\",\"u\",\"b\",\"w\",\"g\",\"h\",\"l\",\"x\",\"t\",\"u\",\"i\"], \"cost\": [82,77,100,95,86,34,77,38,90,31,97,96,77,32,79,87,72,65,100,98,56] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"bdkgumfyqsosetnboawzhflcfkhryb\", \"target\": \"rqwqiefmafkzmataueoobbfkkxsung\", \"original\": [\"b\",\"d\",\"k\",\"g\",\"u\",\"m\",\"y\",\"q\",\"s\",\"o\",\"s\",\"e\",\"t\",\"o\",\"z\",\"h\",\"l\",\"c\",\"f\",\"k\",\"h\",\"r\",\"y\",\"b\"], \"changed\": [\"r\",\"q\",\"w\",\"q\",\"i\",\"e\",\"m\",\"a\",\"f\",\"k\",\"z\",\"m\",\"a\",\"u\",\"o\",\"b\",\"f\",\"k\",\"k\",\"x\",\"s\",\"u\",\"n\",\"g\"], \"cost\": [97,97,72,71,84,96,81,53,85,81,85,48,82,47,54,79,63,94,86,66,96,39,80,82] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"dmhqhwozzfespijaadiwceabbxlfgd\", \"target\": \"owmyowokqacnhwmaellbhcnoodviac\", \"original\": [\"d\",\"m\",\"h\",\"h\",\"z\",\"z\",\"f\",\"s\",\"p\",\"a\",\"d\",\"i\",\"w\",\"c\",\"a\",\"b\",\"x\",\"l\",\"g\",\"d\"], \"changed\": [\"o\",\"w\",\"m\",\"o\",\"k\",\"q\",\"a\",\"n\",\"h\",\"e\",\"l\",\"l\",\"b\",\"h\",\"n\",\"o\",\"d\",\"v\",\"a\",\"c\"], \"cost\": [100,55,84,66,97,92,86,86,98,78,71,100,89,74,77,15,59,59,87,86] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"erjbgdadefwtaydgneprfphalkagce\", \"target\": \"uzslvcynelwivxyzvhlpoxeulnguvi\", \"original\": [\"e\",\"r\",\"j\",\"b\",\"g\",\"d\",\"a\",\"d\",\"f\",\"t\",\"a\",\"y\",\"d\",\"g\",\"e\",\"p\",\"r\",\"f\",\"h\",\"a\",\"k\",\"g\",\"c\",\"e\"], \"changed\": [\"u\",\"z\",\"s\",\"l\",\"v\",\"c\",\"y\",\"n\",\"l\",\"i\",\"v\",\"x\",\"y\",\"z\",\"h\",\"l\",\"p\",\"o\",\"e\",\"u\",\"n\",\"u\",\"v\",\"i\"], \"cost\": [36,100,100,98,99,90,98,93,29,80,37,98,82,84,94,97,86,97,73,96,73,92,94,57] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"gsolujonrufkcbigtjvpsgwtcaafjk\", \"target\": \"niymoyhbyicgjgcjkqkonhcgyqvhwr\", \"original\": [\"g\",\"s\",\"o\",\"j\",\"o\",\"n\",\"u\",\"b\",\"i\",\"g\",\"t\",\"j\",\"v\",\"p\",\"s\",\"g\",\"t\",\"c\",\"a\",\"a\",\"j\"], \"changed\": [\"n\",\"i\",\"y\",\"y\",\"h\",\"b\",\"i\",\"g\",\"c\",\"j\",\"k\",\"q\",\"k\",\"o\",\"n\",\"h\",\"g\",\"y\",\"q\",\"v\",\"w\"], \"cost\": [90,91,99,100,97,95,72,56,85,55,96,77,65,21,38,18,54,91,90,99,87] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"haqgciljqjmplyboytkbvzvncembca\", \"target\": \"vxjxtxjkvyfvnkfbcfxzwjgmvflduz\", \"original\": [\"a\",\"q\",\"g\",\"c\",\"i\",\"l\",\"j\",\"q\",\"j\",\"p\",\"l\",\"b\",\"y\",\"t\",\"b\",\"z\",\"n\",\"c\",\"e\",\"m\",\"c\",\"a\"], \"changed\": [\"x\",\"j\",\"x\",\"t\",\"x\",\"j\",\"k\",\"v\",\"y\",\"v\",\"n\",\"f\",\"c\",\"f\",\"z\",\"j\",\"m\",\"v\",\"f\",\"l\",\"u\",\"z\"], \"cost\": [92,99,90,100,86,49,32,98,72,80,87,87,54,56,93,19,94,81,94,98,76,94] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"jdsusoktswdtjkwuawzxxxruaybamd\", \"target\": \"ycnwpqplsmumuzggvekrmgtjxxdqwd\", \"original\": [\"j\",\"s\",\"u\",\"s\",\"k\",\"t\",\"d\",\"t\",\"j\",\"w\",\"u\",\"a\",\"w\",\"z\",\"x\",\"x\",\"r\",\"u\",\"y\",\"b\",\"m\"], \"changed\": [\"y\",\"n\",\"w\",\"p\",\"p\",\"l\",\"u\",\"m\",\"u\",\"g\",\"g\",\"v\",\"e\",\"k\",\"r\",\"g\",\"t\",\"j\",\"x\",\"d\",\"w\"], \"cost\": [40,97,100,79,39,99,59,49,84,95,90,82,87,22,95,90,76,70,66,96,92] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"nwukaumgrqigiynrvteerkcwheiiim\", \"target\": \"nkimfbwdsbbbpccfepohlvxapvgxlg\", \"original\": [\"w\",\"k\",\"u\",\"m\",\"r\",\"q\",\"g\",\"i\",\"y\",\"n\",\"r\",\"v\",\"t\",\"e\",\"e\",\"r\",\"k\",\"h\",\"e\",\"i\",\"i\",\"i\",\"m\"], \"changed\": [\"k\",\"m\",\"b\",\"w\",\"s\",\"b\",\"b\",\"p\",\"c\",\"c\",\"f\",\"e\",\"p\",\"o\",\"h\",\"l\",\"v\",\"p\",\"v\",\"g\",\"x\",\"l\",\"g\"], \"cost\": [63,94,50,93,100,95,99,92,100,28,98,73,80,99,73,77,84,98,64,87,98,60,85] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"ovtbwsxlxgefyzlwgslddghfjyvyif\", \"target\": \"iobyykxbenmagxgftwubmkrxuvhaxq\", \"original\": [\"v\",\"t\",\"s\",\"l\",\"x\",\"g\",\"e\",\"f\",\"y\",\"z\",\"l\",\"g\",\"s\",\"l\",\"d\",\"d\",\"g\",\"h\",\"f\",\"j\",\"y\",\"v\",\"i\",\"f\"], \"changed\": [\"o\",\"b\",\"k\",\"b\",\"e\",\"n\",\"m\",\"a\",\"g\",\"x\",\"g\",\"t\",\"w\",\"u\",\"b\",\"m\",\"k\",\"r\",\"x\",\"u\",\"v\",\"h\",\"x\",\"q\"], \"cost\": [95,63,97,83,95,93,81,95,100,83,63,99,97,94,45,100,38,99,18,81,39,73,92,24] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"pkluljeraiornkwyxkowpqlpeemdha\", \"target\": \"ckwzwedmdxrkbtgrhrpozwvzwijlri\", \"original\": [\"p\",\"l\",\"u\",\"e\",\"a\",\"i\",\"r\",\"n\",\"k\",\"w\",\"y\",\"x\",\"k\",\"o\",\"w\",\"p\",\"q\",\"l\",\"e\",\"e\",\"m\"], \"changed\": [\"c\",\"w\",\"z\",\"d\",\"d\",\"x\",\"k\",\"b\",\"t\",\"g\",\"r\",\"h\",\"r\",\"p\",\"o\",\"z\",\"w\",\"v\",\"w\",\"i\",\"j\"], \"cost\": [95,88,96,84,49,86,39,68,64,84,99,96,83,46,95,84,74,64,95,83,67] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"qxzlstqdqpfgswlrztsnnclfnsaajc\", \"target\": \"hgjeamofjdcawvbdmwczbctphfupgl\", \"original\": [\"q\",\"x\",\"z\",\"l\",\"s\",\"t\",\"q\",\"q\",\"p\",\"g\",\"l\",\"r\",\"z\",\"t\",\"n\",\"n\",\"f\",\"n\",\"s\",\"a\",\"a\",\"j\",\"c\"], \"changed\": [\"h\",\"g\",\"j\",\"e\",\"a\",\"m\",\"o\",\"j\",\"d\",\"a\",\"b\",\"d\",\"m\",\"w\",\"z\",\"b\",\"p\",\"h\",\"f\",\"u\",\"p\",\"g\",\"l\"], \"cost\": [91,10,86,97,98,76,100,96,97,59,95,97,67,93,84,64,55,81,97,69,99,81,81] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"sozjzrckkcytmscpjjhbkzsfgofzml\", \"target\": \"xjwgnxzbukkqwtocdtjeglsxkjhfsg\", \"original\": [\"s\",\"o\",\"z\",\"j\",\"z\",\"r\",\"k\",\"k\",\"s\",\"j\",\"j\",\"h\",\"b\",\"k\",\"z\",\"f\",\"g\",\"f\",\"z\",\"m\",\"l\"], \"changed\": [\"x\",\"j\",\"w\",\"g\",\"n\",\"x\",\"b\",\"u\",\"t\",\"d\",\"t\",\"j\",\"e\",\"g\",\"l\",\"x\",\"k\",\"h\",\"f\",\"s\",\"g\"], \"cost\": [92,100,97,100,21,93,47,100,50,44,84,84,50,90,64,83,55,75,73,42,89] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"tahngidhiduqtsaimwqhjfkoyvubhx\", \"target\": \"xsglbaliykddukogzcfpchirxnzdlp\", \"original\": [\"t\",\"a\",\"h\",\"n\",\"g\",\"i\",\"d\",\"h\",\"i\",\"d\",\"u\",\"q\",\"t\",\"s\",\"a\",\"i\",\"m\",\"w\",\"q\",\"h\",\"f\",\"k\",\"o\",\"v\",\"b\",\"h\",\"x\"], \"changed\": [\"x\",\"s\",\"g\",\"l\",\"b\",\"a\",\"l\",\"i\",\"y\",\"k\",\"d\",\"d\",\"u\",\"k\",\"o\",\"g\",\"z\",\"c\",\"f\",\"p\",\"h\",\"i\",\"r\",\"n\",\"d\",\"l\",\"p\"], \"cost\": [26,97,84,85,78,59,98,50,91,100,98,7,96,96,73,82,23,96,59,75,87,79,69,95,41,87,100] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"tqamxbehkpaapskhicnkuyyzkvjxfl\", \"target\": \"jlykiobovnobxxwnevqcluhcfmutqu\", \"original\": [\"t\",\"q\",\"a\",\"m\",\"x\",\"b\",\"e\",\"h\",\"k\",\"p\",\"p\",\"s\",\"h\",\"i\",\"n\",\"k\",\"u\",\"y\",\"y\",\"z\",\"v\",\"x\",\"l\"], \"changed\": [\"j\",\"l\",\"y\",\"k\",\"i\",\"o\",\"b\",\"o\",\"v\",\"n\",\"x\",\"x\",\"n\",\"e\",\"q\",\"c\",\"l\",\"u\",\"h\",\"c\",\"m\",\"t\",\"u\"], \"cost\": [68,73,57,37,99,81,75,93,100,88,50,93,89,96,88,85,70,36,71,77,54,65,94] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"ujdbivstmdpnnpnnpggqiwankpoyfw\", \"target\": \"grttiosznxkzeapbsjcisymwaetxcl\", \"original\": [\"u\",\"d\",\"b\",\"v\",\"t\",\"m\",\"p\",\"n\",\"n\",\"p\",\"n\",\"n\",\"p\",\"g\",\"q\",\"i\",\"w\",\"a\",\"n\",\"p\",\"o\",\"f\"], \"changed\": [\"g\",\"t\",\"t\",\"o\",\"z\",\"n\",\"k\",\"z\",\"e\",\"a\",\"p\",\"b\",\"s\",\"c\",\"i\",\"s\",\"y\",\"m\",\"w\",\"e\",\"t\",\"c\"], \"cost\": [100,99,62,99,77,64,56,90,46,94,75,99,87,90,75,83,78,49,100,87,75,20] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"wqomlunjedgsdmdmcwohbxmkeqayxa\", \"target\": \"pojjjjzfsrvrhezcdbinplekiwhllb\", \"original\": [\"w\",\"o\",\"m\",\"l\",\"u\",\"n\",\"e\",\"d\",\"d\",\"m\",\"d\",\"m\",\"c\",\"o\",\"h\",\"b\",\"x\",\"e\",\"a\",\"y\"], \"changed\": [\"p\",\"j\",\"j\",\"j\",\"j\",\"z\",\"s\",\"r\",\"h\",\"e\",\"z\",\"c\",\"d\",\"i\",\"n\",\"p\",\"l\",\"i\",\"h\",\"l\"], \"cost\": [91,91,51,66,89,97,95,89,72,58,98,65,99,63,58,42,89,79,52,42] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"yzflltfyomcnxhwfxcijnsxotwgcuy\", \"target\": \"pwdaiitmmlwdyhwpcrhcnncughvchb\", \"original\": [\"y\",\"l\",\"l\",\"f\",\"y\",\"o\",\"c\",\"n\",\"x\",\"f\",\"i\",\"j\",\"s\",\"x\",\"o\",\"t\",\"w\",\"g\",\"u\",\"y\"], \"changed\": [\"p\",\"a\",\"i\",\"t\",\"m\",\"m\",\"w\",\"d\",\"y\",\"p\",\"h\",\"c\",\"n\",\"c\",\"u\",\"g\",\"h\",\"v\",\"h\",\"b\"], \"cost\": [84,87,90,88,64,80,95,59,96,76,100,93,72,50,97,79,60,90,72,67] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"zchjedhjmkrzqkqnywdgxakcdmsdwg\", \"target\": \"cbftcpgezcgjguefrieolevyaadkgb\", \"original\": [\"z\",\"c\",\"h\",\"j\",\"e\",\"m\",\"k\",\"r\",\"z\",\"q\",\"k\",\"q\",\"n\",\"y\",\"w\",\"d\",\"x\",\"k\",\"c\",\"m\",\"s\",\"d\",\"w\",\"g\"], \"changed\": [\"c\",\"b\",\"f\",\"t\",\"c\",\"z\",\"c\",\"g\",\"j\",\"g\",\"u\",\"e\",\"f\",\"r\",\"i\",\"e\",\"l\",\"v\",\"y\",\"a\",\"d\",\"k\",\"g\",\"b\"], \"cost\": [57,94,71,85,53,96,97,43,93,65,76,93,94,100,81,85,62,100,34,99,95,85,77,68] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"zpxcysgujcbbcgbqqofookukkotwij\", \"target\": \"dfxsvtmexhdnfhbdrcdgqlajddteph\", \"original\": [\"z\",\"s\",\"g\",\"u\",\"j\",\"c\",\"g\",\"q\",\"o\",\"f\",\"k\",\"u\",\"k\",\"o\",\"w\",\"j\"], \"changed\": [\"d\",\"t\",\"m\",\"e\",\"x\",\"f\",\"h\",\"r\",\"c\",\"d\",\"l\",\"a\",\"j\",\"d\",\"e\",\"h\"], \"cost\": [75,28,71,70,92,88,82,82,80,91,97,93,77,14,68,75] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"bavusatavvvuubavsauavubtusubsvtsvsbttbvs\", \"target\": \"ssauttbvssatusutusbattuttsutabubutuasvuu\", \"original\": [\"b\",\"a\",\"v\",\"s\",\"t\",\"a\",\"v\",\"a\",\"v\",\"s\",\"u\",\"u\",\"b\",\"s\",\"v\",\"t\",\"s\",\"b\",\"t\",\"b\"], \"changed\": [\"s\",\"s\",\"a\",\"t\",\"b\",\"v\",\"s\",\"u\",\"t\",\"u\",\"b\",\"t\",\"t\",\"a\",\"b\",\"u\",\"b\",\"u\",\"a\",\"v\"], \"cost\": [948,467,690,969,300,877,924,924,791,724,809,652,388,592,772,829,912,679,751,529] }\nassert my_solution.minimumCost(**test_input) == 27579\n\ntest_input = { \"source\": \"bbvstvuatvbasbbsvsuvvuvvauutttvtsuavsvua\", \"target\": \"buvbtutbsbuttbtvabbuvubvbvabsbattutvbvvu\", \"original\": [\"b\",\"s\",\"v\",\"u\",\"a\",\"t\",\"v\",\"a\",\"s\",\"u\",\"u\",\"u\",\"t\",\"v\",\"a\"], \"changed\": [\"u\",\"b\",\"u\",\"t\",\"b\",\"s\",\"b\",\"t\",\"v\",\"b\",\"v\",\"a\",\"b\",\"a\",\"u\"], \"cost\": [795,956,694,238,665,894,519,867,887,715,845,16,942,429,282] }\nassert my_solution.minimumCost(**test_input) == 22249\n\ntest_input = { \"source\": \"busbsusauusbbasssutaauttavbbabtbustvubtv\", \"target\": \"vuabutaustubbbsbabbusavsttbtubavsabuvvbt\", \"original\": [\"b\",\"s\",\"u\",\"s\",\"a\",\"u\",\"s\",\"t\",\"a\",\"u\",\"t\",\"t\",\"v\",\"b\",\"v\"], \"changed\": [\"v\",\"u\",\"t\",\"a\",\"u\",\"s\",\"b\",\"b\",\"s\",\"a\",\"v\",\"s\",\"t\",\"t\",\"u\"], \"cost\": [927,992,291,999,989,996,318,196,155,948,375,845,960,949,250] }\nassert my_solution.minimumCost(**test_input) == 24291\n\ntest_input = { \"source\": \"buuasstsvvvvtsaavstbvubtbstbussbavsvvvbt\", \"target\": \"utsabasvssauvuvavvbstbbaauvvvtvtbastatua\", \"original\": [\"b\",\"u\",\"u\",\"s\",\"s\",\"v\",\"v\",\"t\",\"b\",\"u\",\"b\",\"s\",\"t\",\"b\",\"u\",\"b\",\"a\",\"v\"], \"changed\": [\"u\",\"t\",\"s\",\"b\",\"v\",\"s\",\"a\",\"b\",\"s\",\"b\",\"a\",\"u\",\"v\",\"v\",\"v\",\"t\",\"b\",\"t\"], \"cost\": [935,827,806,951,298,554,896,852,759,853,530,891,942,944,464,952,882,887] }\nassert my_solution.minimumCost(**test_input) == 31617\n\ntest_input = { \"source\": \"bvbsstasaabvubbaabvbsbsttuvvuutsabbaubau\", \"target\": \"sbuutvuttaubsbbsaatbvsbtsvutuutvtabaubat\", \"original\": [\"b\",\"b\",\"s\",\"t\",\"a\",\"u\",\"a\",\"v\",\"s\",\"s\",\"v\"], \"changed\": [\"s\",\"u\",\"t\",\"v\",\"u\",\"s\",\"s\",\"t\",\"v\",\"b\",\"u\"], \"cost\": [985,604,940,913,910,765,729,905,848,793,468] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"satuaabaavaauussvsvssavtuuvbttassbtususv\", \"target\": \"ababsttvsabvuvaatuvtsvtsasbaatavuauvvstv\", \"original\": [\"s\",\"u\",\"a\",\"a\",\"a\",\"v\",\"a\",\"u\",\"s\",\"s\",\"v\",\"t\",\"u\",\"u\",\"v\",\"b\",\"t\",\"s\",\"t\"], \"changed\": [\"a\",\"b\",\"s\",\"t\",\"v\",\"a\",\"b\",\"v\",\"u\",\"t\",\"t\",\"s\",\"a\",\"s\",\"b\",\"a\",\"a\",\"v\",\"u\"], \"cost\": [848,908,555,510,759,404,799,963,855,901,609,854,878,915,879,594,748,937,942] }\nassert my_solution.minimumCost(**test_input) == 27052\n\ntest_input = { \"source\": \"sauaavvasvsatabbvuusvatsabssavvtsbvuusva\", \"target\": \"abtuuvutubsbbtuttbtubbasuaustsbssatubsvb\", \"original\": [\"s\",\"a\",\"a\",\"a\",\"v\",\"t\",\"b\",\"b\",\"v\",\"u\",\"u\",\"s\",\"t\",\"b\",\"v\",\"t\"], \"changed\": [\"a\",\"b\",\"u\",\"t\",\"b\",\"b\",\"u\",\"t\",\"t\",\"b\",\"t\",\"u\",\"a\",\"a\",\"s\",\"s\"], \"cost\": [689,325,535,931,528,722,965,786,645,499,791,717,557,988,229,834] }\nassert my_solution.minimumCost(**test_input) == 21007\n\ntest_input = { \"source\": \"ssautbbbuattvtutbavabtbvbusbsbaavutvbutu\", \"target\": \"svbvuttvtbtvuavbvtstutuvutvbasbauvabsvvv\", \"original\": [\"s\",\"a\",\"b\",\"u\",\"t\",\"v\",\"t\",\"u\",\"b\",\"a\",\"b\",\"v\",\"b\"], \"changed\": [\"v\",\"b\",\"t\",\"t\",\"v\",\"u\",\"a\",\"v\",\"v\",\"t\",\"u\",\"b\",\"s\"], \"cost\": [943,915,778,641,540,872,999,856,979,848,856,935,677] }\nassert my_solution.minimumCost(**test_input) == 33036\n\ntest_input = { \"source\": \"sstsvvvvvabubtvsvaatsavssbatstbbabbtbvvt\", \"target\": \"tattabsubsatbtbbbussususassautbabsbvabvu\", \"original\": [\"s\",\"s\",\"v\",\"v\",\"v\",\"v\",\"a\",\"b\",\"s\",\"a\",\"t\",\"s\",\"t\",\"a\",\"b\",\"t\",\"t\"], \"changed\": [\"t\",\"a\",\"a\",\"b\",\"s\",\"u\",\"s\",\"a\",\"b\",\"u\",\"s\",\"u\",\"a\",\"b\",\"s\",\"v\",\"u\"], \"cost\": [723,861,682,949,830,969,880,892,750,461,870,592,233,718,967,621,472] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"ssuuavtuuutubutvtssbasssvttuvuubbabubvsu\", \"target\": \"ustbvvsutaasabtasabuaasuatuaabatubsbtvbt\", \"original\": [\"s\",\"u\",\"u\",\"a\",\"t\",\"u\",\"b\",\"s\",\"b\",\"t\",\"u\",\"v\",\"b\",\"a\",\"b\",\"s\"], \"changed\": [\"u\",\"t\",\"b\",\"v\",\"a\",\"s\",\"a\",\"a\",\"u\",\"u\",\"a\",\"a\",\"t\",\"b\",\"s\",\"b\"], \"cost\": [709,599,774,993,858,730,987,700,596,200,984,567,656,971,777,790] }\nassert my_solution.minimumCost(**test_input) == 23824\n\ntest_input = { \"source\": \"suvsavbasssavasvvbttubvbvatbstbabsutvuua\", \"target\": \"aaavasusvsatsuvuatbsstbvstuatttuuvubavau\", \"original\": [\"s\",\"v\",\"b\",\"a\",\"s\",\"a\",\"t\",\"t\",\"u\",\"b\",\"v\",\"b\",\"b\",\"s\",\"a\",\"u\",\"u\"], \"changed\": [\"v\",\"s\",\"u\",\"s\",\"a\",\"t\",\"b\",\"s\",\"s\",\"t\",\"b\",\"v\",\"a\",\"t\",\"u\",\"v\",\"a\"], \"cost\": [944,923,845,911,686,687,403,705,378,929,315,296,484,666,354,375,649] }\nassert my_solution.minimumCost(**test_input) == 25662\n\ntest_input = { \"source\": \"tavauavbtsuuubtbuaatsbutvastasaavbtbsubs\", \"target\": \"stsautbvvtbuvvtstaaubavvuaabubavsvbasvvb\", \"original\": [\"t\",\"a\",\"v\",\"v\",\"s\",\"u\",\"b\",\"b\",\"u\",\"t\",\"s\",\"b\",\"u\",\"t\",\"v\",\"s\",\"t\",\"a\"], \"changed\": [\"s\",\"t\",\"s\",\"b\",\"t\",\"b\",\"v\",\"s\",\"t\",\"u\",\"b\",\"a\",\"v\",\"v\",\"u\",\"a\",\"b\",\"u\"], \"cost\": [936,867,711,886,565,650,500,694,394,662,948,878,864,993,925,508,714,815] }\nassert my_solution.minimumCost(**test_input) == 24476\n\ntest_input = { \"source\": \"tbsttbstvtvusvbaavuuuvvuavuuusbusabsubta\", \"target\": \"uvvbttvbvtbtausvtavsuavusvusuabuvtutttas\", \"original\": [\"t\",\"b\",\"s\",\"u\",\"v\",\"a\",\"a\",\"v\",\"u\",\"u\",\"a\",\"s\",\"b\",\"s\",\"b\",\"t\"], \"changed\": [\"u\",\"v\",\"v\",\"t\",\"u\",\"v\",\"t\",\"a\",\"v\",\"s\",\"s\",\"a\",\"u\",\"t\",\"t\",\"a\"], \"cost\": [409,241,815,861,536,968,983,726,882,674,981,516,918,653,368,845] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"tsauvattvvavaasbutvuavvvttuvasavbvavtsaa\", \"target\": \"vbtsubbbbbavvvbsvstavasaaaatsattvbtubsvs\", \"original\": [\"t\",\"s\",\"u\",\"a\",\"t\",\"v\",\"a\",\"b\",\"u\",\"v\",\"u\",\"v\",\"v\",\"t\",\"a\",\"a\",\"b\"], \"changed\": [\"v\",\"b\",\"s\",\"b\",\"b\",\"b\",\"v\",\"s\",\"v\",\"t\",\"a\",\"a\",\"s\",\"a\",\"s\",\"t\",\"v\"], \"cost\": [731,965,614,651,952,991,940,606,664,261,468,295,202,675,921,628,690] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"tsvsstututatsbvatauatsausaubsuuassssbuts\", \"target\": \"assutuavuvusbubbtavsavbvusvbvtbubvvuvtvb\", \"original\": [\"t\",\"v\",\"s\",\"s\",\"t\",\"u\",\"t\",\"a\",\"s\",\"b\",\"v\",\"a\",\"s\",\"u\",\"a\",\"u\",\"u\",\"b\"], \"changed\": [\"a\",\"s\",\"u\",\"t\",\"u\",\"a\",\"v\",\"u\",\"b\",\"u\",\"b\",\"b\",\"v\",\"v\",\"s\",\"t\",\"b\",\"v\"], \"cost\": [924,489,946,903,425,474,965,605,168,870,992,903,367,995,425,580,918,991] }\nassert my_solution.minimumCost(**test_input) == 23945\n\ntest_input = { \"source\": \"ttuvauavausttvusavuvsuababtubbbvvsttbasv\", \"target\": \"butttussvtvbbtbtasuusstattuvvvuavbtsbttu\", \"original\": [\"t\",\"t\",\"u\",\"a\",\"a\",\"u\",\"s\",\"v\",\"v\",\"u\",\"a\",\"b\",\"b\",\"u\",\"b\",\"b\",\"v\",\"s\",\"t\"], \"changed\": [\"b\",\"u\",\"t\",\"s\",\"v\",\"b\",\"t\",\"s\",\"u\",\"s\",\"t\",\"a\",\"t\",\"v\",\"v\",\"u\",\"a\",\"b\",\"s\"], \"cost\": [790,396,583,83,931,950,760,364,698,503,957,984,611,688,1000,986,679,913,906] }\nassert my_solution.minimumCost(**test_input) == 25663\n\ntest_input = { \"source\": \"tuasbutsuubbvauvautsbtabsaaauubbvaavtuua\", \"target\": \"tvauvutvbbavuatsbaatvtbavatavtsvttttuvta\", \"original\": [\"u\",\"s\",\"b\",\"u\",\"v\",\"u\",\"v\",\"a\",\"u\",\"t\",\"b\",\"s\",\"a\",\"b\",\"v\",\"t\"], \"changed\": [\"v\",\"u\",\"v\",\"b\",\"u\",\"t\",\"s\",\"b\",\"a\",\"a\",\"a\",\"v\",\"t\",\"s\",\"t\",\"u\"], \"cost\": [958,880,986,571,311,294,673,433,733,984,444,576,666,847,516,866] }\nassert my_solution.minimumCost(**test_input) == 21164\n\ntest_input = { \"source\": \"tvsbbttvsvubbtasvbusataaatautauavvstsbub\", \"target\": \"tbttvaavutvbstvutavavtbuvtuabsubsuvbtusa\", \"original\": [\"v\",\"b\",\"s\",\"u\",\"b\",\"v\",\"s\",\"a\",\"a\",\"a\",\"u\",\"t\",\"v\",\"v\",\"s\",\"s\",\"u\",\"b\"], \"changed\": [\"b\",\"v\",\"u\",\"v\",\"s\",\"t\",\"a\",\"v\",\"b\",\"u\",\"a\",\"b\",\"s\",\"u\",\"v\",\"t\",\"s\",\"a\"], \"cost\": [977,323,878,825,625,908,794,831,973,881,946,981,437,904,564,826,720,583] }\nassert my_solution.minimumCost(**test_input) == 29347\n\ntest_input = { \"source\": \"uatavuaavatstabvtvabbbuvatvabbauvsvtauuu\", \"target\": \"ustbbuvbtusutuutvsuttbuubuuubasvubuubusb\", \"original\": [\"a\",\"a\",\"v\",\"a\",\"v\",\"a\",\"t\",\"b\",\"t\",\"b\",\"v\",\"t\",\"s\",\"u\",\"u\"], \"changed\": [\"s\",\"b\",\"b\",\"v\",\"t\",\"u\",\"s\",\"u\",\"v\",\"t\",\"u\",\"u\",\"b\",\"s\",\"b\"], \"cost\": [681,801,894,221,732,732,984,989,750,705,181,993,888,957,912] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"ubvtusbavavtbssuutvsvasttbauvtvttsvtttss\", \"target\": \"usasbvasuttsbvvuuvvtubssuuuuvuvubtsbsstu\", \"original\": [\"b\",\"t\",\"a\",\"v\",\"a\",\"s\",\"s\",\"t\",\"b\",\"a\",\"t\",\"v\",\"s\"], \"changed\": [\"s\",\"s\",\"s\",\"u\",\"t\",\"v\",\"t\",\"u\",\"u\",\"u\",\"b\",\"s\",\"u\"], \"cost\": [933,864,772,686,918,885,923,892,538,120,913,892,441] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"ubvuasvuvuavasvvasausabbtausaaubbvbtuubv\", \"target\": \"sbbutubbvtvauatbavstvbttavbubvsvsutuavta\", \"original\": [\"u\",\"v\",\"a\",\"s\",\"u\",\"a\",\"v\",\"a\",\"s\",\"s\",\"a\",\"a\",\"b\",\"b\",\"u\",\"u\"], \"changed\": [\"s\",\"b\",\"t\",\"u\",\"b\",\"v\",\"a\",\"u\",\"a\",\"v\",\"s\",\"b\",\"t\",\"s\",\"a\",\"v\"], \"cost\": [951,655,564,597,402,910,850,664,352,937,698,281,997,798,368,963] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"utauutasstbuubsussstaauatvaavuuabvvbvaba\", \"target\": \"vttavbbbvbbbvuaavauubbsavaststtatsbssaab\", \"original\": [\"a\",\"u\",\"t\",\"a\",\"s\",\"s\",\"s\",\"t\",\"v\",\"a\",\"u\",\"b\",\"v\",\"b\",\"v\",\"b\"], \"changed\": [\"t\",\"a\",\"b\",\"b\",\"b\",\"a\",\"v\",\"v\",\"a\",\"s\",\"t\",\"t\",\"b\",\"s\",\"s\",\"a\"], \"cost\": [862,888,579,525,903,443,828,892,953,879,855,705,961,438,478,998] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"uttbbsvttssubvbbaabsavaabvsvbbbbbatvbtsu\", \"target\": \"tatsstaubbtbvsabvasbubvvbutasssvttuvvtvs\", \"original\": [\"u\",\"t\",\"b\",\"s\",\"v\",\"t\",\"t\",\"u\",\"b\",\"v\",\"b\",\"a\",\"s\",\"v\",\"v\",\"b\",\"a\",\"s\",\"u\"], \"changed\": [\"t\",\"a\",\"s\",\"t\",\"a\",\"u\",\"b\",\"b\",\"v\",\"s\",\"a\",\"v\",\"b\",\"b\",\"u\",\"t\",\"t\",\"v\",\"s\"], \"cost\": [880,822,798,549,420,189,730,621,865,189,950,921,887,816,772,69,907,868,715] }\nassert my_solution.minimumCost(**test_input) == 23971\n\ntest_input = { \"source\": \"utvsausubbtuasvtuttatbtasuvbtuuubsatabau\", \"target\": \"tstsatsbsttaatasbvvsabbabbtabtvbvuaavaau\", \"original\": [\"u\",\"b\",\"b\",\"u\",\"s\",\"v\",\"u\",\"t\",\"a\",\"t\",\"s\",\"b\",\"u\",\"b\",\"s\",\"a\"], \"changed\": [\"t\",\"s\",\"t\",\"a\",\"t\",\"a\",\"b\",\"v\",\"s\",\"a\",\"b\",\"a\",\"v\",\"v\",\"u\",\"v\"], \"cost\": [425,837,948,892,923,403,619,690,775,951,577,1000,816,999,602,800] }\nassert my_solution.minimumCost(**test_input) == 29865\n\ntest_input = { \"source\": \"uvtavsbvvvvavsstavustttuuvvavatattbavttv\", \"target\": \"vvbuuutbtvbtutatuttvsssvtvsbbvbbvuausavu\", \"original\": [\"t\",\"a\",\"v\",\"s\",\"b\",\"v\",\"v\",\"a\",\"s\",\"s\",\"u\",\"s\",\"t\",\"u\",\"v\",\"a\",\"t\",\"t\",\"b\"], \"changed\": [\"b\",\"u\",\"u\",\"u\",\"t\",\"b\",\"t\",\"t\",\"t\",\"a\",\"t\",\"v\",\"s\",\"v\",\"s\",\"b\",\"v\",\"u\",\"a\"], \"cost\": [984,969,379,449,842,818,399,954,718,823,932,935,405,591,643,965,1000,700,189] }\nassert my_solution.minimumCost(**test_input) == 27084\n\ntest_input = { \"source\": \"vabsuaavabatbastaauaaaututtutsvuusatavas\", \"target\": \"svubbsaavaubbbvasatssvvubtsssabsabsbstau\", \"original\": [\"a\",\"s\",\"u\",\"a\",\"v\",\"b\",\"a\",\"s\",\"t\",\"u\",\"u\",\"t\",\"u\",\"t\",\"s\",\"v\",\"u\",\"t\",\"v\",\"s\"], \"changed\": [\"v\",\"b\",\"b\",\"s\",\"a\",\"a\",\"u\",\"v\",\"a\",\"t\",\"v\",\"u\",\"s\",\"s\",\"a\",\"b\",\"a\",\"b\",\"t\",\"u\"], \"cost\": [948,531,696,662,908,460,829,859,857,374,1000,996,356,810,804,751,988,815,933,924] }\nassert my_solution.minimumCost(**test_input) == 27967\n\ntest_input = { \"source\": \"vsvstbbutastuuaubuausuuavvttvabvsaavbtvs\", \"target\": \"vbbtbuatasbauavbbabbbvbutaavsvtubvbuttst\", \"original\": [\"s\",\"v\",\"s\",\"t\",\"b\",\"b\",\"u\",\"a\",\"t\",\"u\",\"a\",\"u\",\"a\",\"u\",\"a\",\"v\",\"v\",\"b\",\"v\"], \"changed\": [\"b\",\"b\",\"t\",\"b\",\"u\",\"a\",\"t\",\"s\",\"a\",\"a\",\"v\",\"b\",\"b\",\"v\",\"u\",\"t\",\"s\",\"t\",\"u\"], \"cost\": [510,990,975,894,921,775,819,665,76,509,943,691,757,617,773,404,777,932,837] }\nassert my_solution.minimumCost(**test_input) == 25040\n\ntest_input = { \"source\": \"vusbbaubbusbbtusttbtavsavbbbausavbausbub\", \"target\": \"uvvbsututvavautuatuussbbttbaaaasbbuvavaa\", \"original\": [\"u\",\"b\",\"a\",\"u\",\"b\",\"b\",\"s\",\"b\",\"b\",\"t\",\"t\",\"s\",\"a\",\"v\",\"u\",\"a\",\"v\"], \"changed\": [\"v\",\"s\",\"u\",\"t\",\"u\",\"t\",\"a\",\"v\",\"a\",\"u\",\"a\",\"b\",\"b\",\"t\",\"a\",\"s\",\"b\"], \"cost\": [555,920,950,949,936,35,455,910,746,791,661,864,926,11,833,870,854] }\nassert my_solution.minimumCost(**test_input) == 26439\n\ntest_input = { \"source\": \"vvabsutautvsutvavtsvstabvbvtutbvuautaatb\", \"target\": \"taasvsstbstasbtuauvtbtusbssbbssbuusuvbbu\", \"original\": [\"v\",\"b\",\"s\",\"u\",\"t\",\"u\",\"v\",\"t\",\"a\",\"t\",\"s\",\"v\",\"v\",\"a\"], \"changed\": [\"a\",\"s\",\"v\",\"s\",\"s\",\"b\",\"t\",\"b\",\"u\",\"u\",\"b\",\"s\",\"b\",\"b\"], \"cost\": [813,860,971,768,419,950,866,741,989,756,325,806,507,571] }\nassert my_solution.minimumCost(**test_input) == 36258\n\ntest_input = { \"source\": \"vvvsaavtavaabtssasstbvuusbubbbsastvttbba\", \"target\": \"utssutvbabttvstsbbusttuuutvvbtasvuvbvvav\", \"original\": [\"v\",\"a\",\"a\",\"v\",\"b\",\"t\",\"s\",\"a\",\"s\",\"b\",\"s\",\"u\",\"s\",\"a\",\"s\",\"t\",\"t\",\"b\",\"a\"], \"changed\": [\"t\",\"u\",\"t\",\"b\",\"v\",\"s\",\"t\",\"b\",\"b\",\"t\",\"u\",\"v\",\"a\",\"s\",\"v\",\"b\",\"v\",\"a\",\"v\"], \"cost\": [722,823,981,465,482,999,572,191,410,968,377,549,658,692,898,263,928,197,831] }\nassert my_solution.minimumCost(**test_input) == 22953\n\ntest_input = { \"source\": \"asmlmoumomvummakmlbabvmvvavlavtsvbvssuumsllttsusts\", \"target\": \"asmlmoumomvummakmlbabvmvvaolklllvbsltuomkslvmmusts\", \"original\": [\"vlavtsvbvssuumslltts\",\"mtmubkasuvumkobbmsmo\",\"vsbbvauauvuvsauaastl\",\"uovumoluksslvkvlkmam\",\"smsvsuubusskmublvvst\",\"momuatbkubosmmavvssk\",\"mommltotttbtvlvalsbt\",\"vbbbuvslutblvvkvtmmo\",\"boaosasttvtvtabtubab\",\"mbtkumblvbasoobaauvm\",\"vbotklaoltambktlulot\",\"vluamsokkbaalsmmalav\",\"mttmbuosbmlttabmbabl\",\"sskvkbmlabaulluomovt\",\"lstbuomkaoatmavsmvml\"], \"changed\": [\"mtmubkasuvumkobbmsmo\",\"vsbbvauauvuvsauaastl\",\"uovumoluksslvkvlkmam\",\"smsvsuubusskmublvvst\",\"momuatbkubosmmavvssk\",\"mommltotttbtvlvalsbt\",\"vbbbuvslutblvvkvtmmo\",\"boaosasttvtvtabtubab\",\"mbtkumblvbasoobaauvm\",\"vbotklaoltambktlulot\",\"vluamsokkbaalsmmalav\",\"mttmbuosbmlttabmbabl\",\"sskvkbmlabaulluomovt\",\"lstbuomkaoatmavsmvml\",\"olklllvbsltuomkslvmm\"], \"cost\": [9758,7133,9355,8885,6055,7360,9168,9288,7422,6995,8167,6154,6939,6343,9733] }\nassert my_solution.minimumCost(**test_input) == 118755\n\ntest_input = { \"source\": \"bkmltoaakmatkvllubamuvbmkolamvolsaottsokbmutktsvlo\", \"target\": \"skmltoaakmatkvllubamuvbmkolamvolsosuataatovmktsvlo\", \"original\": [\"aottsokbmut\",\"ktuumtblakk\",\"mkumbambakt\",\"tubtvmuuoat\",\"kkkksosllks\",\"sastauoammb\",\"sbomolbklsk\",\"kaabakosmsb\",\"ltaltkmukoa\",\"lmlaovmluta\",\"kusalltssaa\",\"mattouslbou\",\"obaavmovsal\",\"bk\",\"ko\"], \"changed\": [\"ktuumtblakk\",\"mkumbambakt\",\"tubtvmuuoat\",\"kkkksosllks\",\"sastauoammb\",\"sbomolbklsk\",\"kaabakosmsb\",\"ltaltkmukoa\",\"lmlaovmluta\",\"kusalltssaa\",\"mattouslbou\",\"obaavmovsal\",\"osuataatovm\",\"ko\",\"sk\"], \"cost\": [5819,9018,7484,6655,5163,5728,3077,7032,4630,8093,6974,5623,9179,7307,9974] }\nassert my_solution.minimumCost(**test_input) == 101756\n\ntest_input = { \"source\": \"blvalvmkosattusaubkbuvusmoolmkloavaskmkbovkkbvtaas\", \"target\": \"blvalvmkosattlooutkvsmabuvaumkloavaskmkbovkkbvtaas\", \"original\": [\"usaubkbuvusmoolm\",\"stvkuuablkvlvbuv\",\"laosbokmbsusulta\",\"tosusvtstuousmtv\",\"tkbbalmtoubtmlvk\",\"vauvllvbootbvtsv\",\"malabvmoaavulomv\",\"ootsoksuosvlakov\",\"alaobmvbttmtobvl\",\"oauamtksvbuovmbt\",\"ubtlssmbbaloatsa\",\"sstskkmtkoobaavt\",\"avsskubbbtossbsu\",\"aumbsbautvkmsauu\",\"btsuvmosbtomvmma\"], \"changed\": [\"stvkuuablkvlvbuv\",\"laosbokmbsusulta\",\"tosusvtstuousmtv\",\"tkbbalmtoubtmlvk\",\"vauvllvbootbvtsv\",\"malabvmoaavulomv\",\"ootsoksuosvlakov\",\"alaobmvbttmtobvl\",\"oauamtksvbuovmbt\",\"ubtlssmbbaloatsa\",\"sstskkmtkoobaavt\",\"avsskubbbtossbsu\",\"aumbsbautvkmsauu\",\"btsuvmosbtomvmma\",\"looutkvsmabuvaum\"], \"cost\": [8903,5338,8835,8645,8789,7933,8044,3865,7564,5782,9245,9165,8886,7691,8039] }\nassert my_solution.minimumCost(**test_input) == 116724\n\ntest_input = { \"source\": \"mobbmmmsabbomsbukkotbttvsuoubtvuabaktsuoltvamlltbv\", \"target\": \"mobbmmmsauotksusvmvtbmaovtsvtaklabaktsuoltbamtumtl\", \"original\": [\"bbomsbukkotbttvsuoubtvua\",\"sbuastublskotvtotmokuota\",\"kssvtltakbtmlbmtoskaousb\",\"vuososkmtvsobkbvuvbklvbv\",\"vtsvllsklslkbulusbuastlm\",\"bttokabvovvktkavatskoamt\",\"lbmobulvomkovaalbtkoukso\",\"tmmlusaokamvstsmuksmbulu\",\"lkktooukbstvkumvbbsllaas\",\"mbvtkltbvuumuvobstooammv\",\"skovmvassobkbutolttvkokb\",\"olastbtotmlusbmlukmokubl\",\"kvbomsvuaskvkvvmssavubtt\",\"buusuklobuoukatusulotmks\",\"vamlltbv\"], \"changed\": [\"sbuastublskotvtotmokuota\",\"kssvtltakbtmlbmtoskaousb\",\"vuososkmtvsobkbvuvbklvbv\",\"vtsvllsklslkbulusbuastlm\",\"bttokabvovvktkavatskoamt\",\"lbmobulvomkovaalbtkoukso\",\"tmmlusaokamvstsmuksmbulu\",\"lkktooukbstvkumvbbsllaas\",\"mbvtkltbvuumuvobstooammv\",\"skovmvassobkbutolttvkokb\",\"olastbtotmlusbmlukmokubl\",\"kvbomsvuaskvkvvmssavubtt\",\"buusuklobuoukatusulotmks\",\"uotksusvmvtbmaovtsvtakla\",\"bamtumtl\"], \"cost\": [8432,9912,7958,9938,8402,7223,5772,9501,8749,8597,6195,7504,7103,9582,8898] }\nassert my_solution.minimumCost(**test_input) == 123766", "start_time": 1703385000} +{"task_id": "biweekly-contest-120-count-the-number-of-incremovable-subarrays-i", "url": "https://leetcode.com/problems/count-the-number-of-incremovable-subarrays-i", "title": "count-the-number-of-incremovable-subarrays-i", "meta": {"questionId": "3252", "questionFrontendId": "2970", "title": "Count the Number of Incremovable Subarrays I", "titleSlug": "count-the-number-of-incremovable-subarrays-i", "isPaidOnly": false, "difficulty": "Easy", "likes": 38, "dislikes": 49, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0开始的 正整数数组nums。\n如果 nums的一个子数组满足:移除这个子数组后剩余元素 严格递增,那么我们称这个子数组为 移除递增子数组。比方说,[5, 3, 4, 6, 7]中的 [3, 4]是一个移除递增子数组,因为移除该子数组后,[5, 3, 4, 6, 7]变为[5, 6, 7],是严格递增的。\n请你返回 nums中 移除递增子数组的总数目。\n注意,剩余元素为空的数组也视为是递增的。\n子数组 指的是一个数组中一段连续的元素序列。\n\n示例 1:\n\n输入:nums = [1,2,3,4]\n输出:10\n解释:10 个移除递增子数组分别为:[1], [2], [3], [4], [1,2], [2,3], [3,4], [1,2,3], [2,3,4] 和 [1,2,3,4]。移除任意一个子数组后,剩余元素都是递增的。注意,空数组不是移除递增子数组。\n\n示例 2:\n\n输入:nums = [6,5,7,8]\n输出:7\n解释:7个移除递增子数组分别为:[5], [6], [5,7], [6,5], [5,7,8], [6,5,7] 和 [6,5,7,8] 。\nnums 中只有这 7 个移除递增子数组。\n\n示例 3:\n\n输入:nums = [8,7,6,6]\n输出:3\n解释:3 个移除递增子数组分别为:[8,7,6], [7,6,6] 和 [8,7,6,6] 。注意 [8,7] 不是移除递增子数组因为移除 [8,7] 后 nums 变为 [6,6] ,它不是严格递增的。\n\n\n提示:\n\n1 <= nums.length <= 50\n1 <= nums[i] <= 50\n\"\"\"\nclass Solution:\n def incremovableSubarrayCount(self, nums: List[int]) -> int:\n ", "prompt_sft": "给你一个下标从 0开始的 正整数数组nums。\n如果 nums的一个子数组满足:移除这个子数组后剩余元素 严格递增,那么我们称这个子数组为 移除递增子数组。比方说,[5, 3, 4, 6, 7]中的 [3, 4]是一个移除递增子数组,因为移除该子数组后,[5, 3, 4, 6, 7]变为[5, 6, 7],是严格递增的。\n请你返回 nums中 移除递增子数组的总数目。\n注意,剩余元素为空的数组也视为是递增的。\n子数组 指的是一个数组中一段连续的元素序列。\n\n示例 1:\n\n输入:nums = [1,2,3,4]\n输出:10\n解释:10 个移除递增子数组分别为:[1], [2], [3], [4], [1,2], [2,3], [3,4], [1,2,3], [2,3,4] 和 [1,2,3,4]。移除任意一个子数组后,剩余元素都是递增的。注意,空数组不是移除递增子数组。\n\n示例 2:\n\n输入:nums = [6,5,7,8]\n输出:7\n解释:7个移除递增子数组分别为:[5], [6], [5,7], [6,5], [5,7,8], [6,5,7] 和 [6,5,7,8] 。\nnums 中只有这 7 个移除递增子数组。\n\n示例 3:\n\n输入:nums = [8,7,6,6]\n输出:3\n解释:3 个移除递增子数组分别为:[8,7,6], [7,6,6] 和 [8,7,6,6] 。注意 [8,7] 不是移除递增子数组因为移除 [8,7] 后 nums 变为 [6,6] ,它不是严格递增的。\n\n\n提示:\n\n1 <= nums.length <= 50\n1 <= nums[i] <= 50\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def incremovableSubarrayCount(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,2,3,4] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 10\n\ntest_input = { \"nums\": [6,5,7,8] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 7\n\ntest_input = { \"nums\": [8,7,6,6] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [1] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 1\n\ntest_input = { \"nums\": [2] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 1\n\ntest_input = { \"nums\": [3] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 1\n\ntest_input = { \"nums\": [4] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 1\n\ntest_input = { \"nums\": [5] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 1\n\ntest_input = { \"nums\": [6] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 1\n\ntest_input = { \"nums\": [7] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 1\n\ntest_input = { \"nums\": [8] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 1\n\ntest_input = { \"nums\": [9] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 1\n\ntest_input = { \"nums\": [10] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 1\n\ntest_input = { \"nums\": [1,2] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [1,4] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [1,8] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [2,10] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [3,4] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [3,8] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [3,10] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [4,2] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [4,3] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [4,5] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [5,1] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [5,4] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [5,6] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [5,7] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [5,9] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [6,4] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [6,5] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [6,9] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [9,3] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [9,4] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [9,7] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [9,8] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [10,5] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [10,10] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,3] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 6\n\ntest_input = { \"nums\": [1,2,6] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 6\n\ntest_input = { \"nums\": [2,1,6] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 5\n\ntest_input = { \"nums\": [2,4,5] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 6\n\ntest_input = { \"nums\": [2,6,8] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 6\n\ntest_input = { \"nums\": [2,6,9] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 6\n\ntest_input = { \"nums\": [2,10,9] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 5\n\ntest_input = { \"nums\": [3,1,9] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 5\n\ntest_input = { \"nums\": [3,5,9] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 6\n\ntest_input = { \"nums\": [3,7,2] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [3,8,8] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 5\n\ntest_input = { \"nums\": [3,10,10] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 5\n\ntest_input = { \"nums\": [4,5,2] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [5,8,4] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [5,9,3] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [5,9,7] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 5\n\ntest_input = { \"nums\": [6,7,4] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [8,7,4] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [8,7,5] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [8,9,5] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [9,2,5] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [9,5,2] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [9,6,9] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [9,9,4] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [10,7,4] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [10,10,6] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [2,1,1,4] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 5\n\ntest_input = { \"nums\": [2,5,7,9] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 10\n\ntest_input = { \"nums\": [3,5,3,5] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 6\n\ntest_input = { \"nums\": [3,7,10,6] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 6\n\ntest_input = { \"nums\": [3,8,3,8] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 6\n\ntest_input = { \"nums\": [4,1,3,7] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 6\n\ntest_input = { \"nums\": [4,3,5,1] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [4,3,7,5] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [4,8,7,6] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 5\n\ntest_input = { \"nums\": [4,9,10,6] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 6\n\ntest_input = { \"nums\": [5,4,3,8] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 5\n\ntest_input = { \"nums\": [5,5,9,5] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [5,10,10,9] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 5\n\ntest_input = { \"nums\": [6,4,4,9] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 5\n\ntest_input = { \"nums\": [6,5,2,10] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 5\n\ntest_input = { \"nums\": [7,3,2,3] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [7,5,1,10] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 5\n\ntest_input = { \"nums\": [7,9,7,2] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [7,9,8,8] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 5\n\ntest_input = { \"nums\": [7,10,4,3] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [8,8,1,7] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [9,2,8,7] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [10,5,9,5] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [10,7,2,8] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [10,9,1,3] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [1,1,4,4,7] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 6\n\ntest_input = { \"nums\": [1,2,3,4,5] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 15\n\ntest_input = { \"nums\": [1,2,8,9,2] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 7\n\ntest_input = { \"nums\": [1,7,4,9,2] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 5\n\ntest_input = { \"nums\": [2,2,4,6,3] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [2,7,1,3,9] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 9\n\ntest_input = { \"nums\": [3,1,9,6,5] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [3,3,3,6,1] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [3,7,1,8,1] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [4,1,6,10,2] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [5,4,8,4,2] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [6,1,1,8,10] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 7", "start_time": 1703341800} +{"task_id": "biweekly-contest-120-find-polygon-with-the-largest-perimeter", "url": "https://leetcode.com/problems/find-polygon-with-the-largest-perimeter", "title": "find-polygon-with-the-largest-perimeter", "meta": {"questionId": "3262", "questionFrontendId": "2971", "title": "Find Polygon With the Largest Perimeter", "titleSlug": "find-polygon-with-the-largest-perimeter", "isPaidOnly": false, "difficulty": "Medium", "likes": 53, "dislikes": 6, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个长度为n的正整数数组nums。\n多边形指的是一个至少有 3条边的封闭二维图形。多边形的 最长边一定 小于所有其他边长度之和。\n如果你有k(k >= 3)个正数a1,a2,a3, ...,ak 满足a1 <= a2 <= a3 <= ... <= ak 且 a1 + a2 + a3 + ... + ak-1 > ak,那么 一定存在一个k条边的多边形,每条边的长度分别为a1,a2,a3,...,ak。\n一个多边形的 周长指的是它所有边之和。\n请你返回从 nums中可以构造的 多边形的 最大周长。如果不能构造出任何多边形,请你返回 -1。\n\n示例 1:\n\n输入:nums = [5,5,5]\n输出:15\n解释:nums 中唯一可以构造的多边形为三角形,每条边的长度分别为 5 ,5 和 5 ,周长为 5 + 5 + 5 = 15 。\n\n示例 2:\n\n输入:nums = [1,12,1,2,5,50,3]\n输出:12\n解释:最大周长多边形为五边形,每条边的长度分别为 1 ,1 ,2 ,3 和 5 ,周长为 1 + 1 + 2 + 3 + 5 = 12 。\n我们无法构造一个包含变长为 12 或者 50 的多边形,因为其他边之和没法大于两者中的任何一个。\n所以最大周长为 12 。\n\n示例 3:\n\n输入:nums = [5,5,50]\n输出:-1\n解释:无法构造任何多边形,因为多边形至少要有 3 条边且 50 > 5 + 5 。\n\n\n提示:\n\n3 <= n <= 105\n1 <= nums[i] <= 109\n\"\"\"\nclass Solution:\n def largestPerimeter(self, nums: List[int]) -> int:\n ", "prompt_sft": "给你一个长度为n的正整数数组nums。\n多边形指的是一个至少有 3条边的封闭二维图形。多边形的 最长边一定 小于所有其他边长度之和。\n如果你有k(k >= 3)个正数a1,a2,a3, ...,ak 满足a1 <= a2 <= a3 <= ... <= ak 且 a1 + a2 + a3 + ... + ak-1 > ak,那么 一定存在一个k条边的多边形,每条边的长度分别为a1,a2,a3,...,ak。\n一个多边形的 周长指的是它所有边之和。\n请你返回从 nums中可以构造的 多边形的 最大周长。如果不能构造出任何多边形,请你返回 -1。\n\n示例 1:\n\n输入:nums = [5,5,5]\n输出:15\n解释:nums 中唯一可以构造的多边形为三角形,每条边的长度分别为 5 ,5 和 5 ,周长为 5 + 5 + 5 = 15 。\n\n示例 2:\n\n输入:nums = [1,12,1,2,5,50,3]\n输出:12\n解释:最大周长多边形为五边形,每条边的长度分别为 1 ,1 ,2 ,3 和 5 ,周长为 1 + 1 + 2 + 3 + 5 = 12 。\n我们无法构造一个包含变长为 12 或者 50 的多边形,因为其他边之和没法大于两者中的任何一个。\n所以最大周长为 12 。\n\n示例 3:\n\n输入:nums = [5,5,50]\n输出:-1\n解释:无法构造任何多边形,因为多边形至少要有 3 条边且 50 > 5 + 5 。\n\n\n提示:\n\n3 <= n <= 105\n1 <= nums[i] <= 109\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def largestPerimeter(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [5,5,5] }\nassert my_solution.largestPerimeter(**test_input) == 15\n\ntest_input = { \"nums\": [1,12,1,2,5,50,3] }\nassert my_solution.largestPerimeter(**test_input) == 12\n\ntest_input = { \"nums\": [5,5,50] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,1] }\nassert my_solution.largestPerimeter(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,2] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,3] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,4] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,5] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [1,2,1] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [1,2,2] }\nassert my_solution.largestPerimeter(**test_input) == 5\n\ntest_input = { \"nums\": [1,2,3] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [1,2,4] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [1,2,5] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [1,3,1] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [1,3,2] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [1,3,3] }\nassert my_solution.largestPerimeter(**test_input) == 7\n\ntest_input = { \"nums\": [1,3,4] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [1,3,5] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [1,4,1] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [1,4,2] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [1,4,3] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [1,4,4] }\nassert my_solution.largestPerimeter(**test_input) == 9\n\ntest_input = { \"nums\": [1,4,5] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [1,5,1] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [1,5,2] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [1,5,3] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [1,5,4] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [1,5,5] }\nassert my_solution.largestPerimeter(**test_input) == 11\n\ntest_input = { \"nums\": [2,1,1] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [2,1,2] }\nassert my_solution.largestPerimeter(**test_input) == 5\n\ntest_input = { \"nums\": [2,1,3] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [2,1,4] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [2,1,5] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [2,2,1] }\nassert my_solution.largestPerimeter(**test_input) == 5\n\ntest_input = { \"nums\": [2,2,2] }\nassert my_solution.largestPerimeter(**test_input) == 6\n\ntest_input = { \"nums\": [2,2,3] }\nassert my_solution.largestPerimeter(**test_input) == 7\n\ntest_input = { \"nums\": [2,2,4] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [2,2,5] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [2,3,1] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [2,3,2] }\nassert my_solution.largestPerimeter(**test_input) == 7\n\ntest_input = { \"nums\": [2,3,3] }\nassert my_solution.largestPerimeter(**test_input) == 8\n\ntest_input = { \"nums\": [2,3,4] }\nassert my_solution.largestPerimeter(**test_input) == 9\n\ntest_input = { \"nums\": [2,3,5] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [2,4,1] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [2,4,2] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [2,4,3] }\nassert my_solution.largestPerimeter(**test_input) == 9\n\ntest_input = { \"nums\": [2,4,4] }\nassert my_solution.largestPerimeter(**test_input) == 10\n\ntest_input = { \"nums\": [2,4,5] }\nassert my_solution.largestPerimeter(**test_input) == 11\n\ntest_input = { \"nums\": [2,5,1] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [2,5,2] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [2,5,3] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [2,5,4] }\nassert my_solution.largestPerimeter(**test_input) == 11\n\ntest_input = { \"nums\": [2,5,5] }\nassert my_solution.largestPerimeter(**test_input) == 12\n\ntest_input = { \"nums\": [3,1,1] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [3,1,2] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [3,1,3] }\nassert my_solution.largestPerimeter(**test_input) == 7\n\ntest_input = { \"nums\": [3,1,4] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [3,1,5] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [3,2,1] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [3,2,2] }\nassert my_solution.largestPerimeter(**test_input) == 7\n\ntest_input = { \"nums\": [3,2,3] }\nassert my_solution.largestPerimeter(**test_input) == 8\n\ntest_input = { \"nums\": [3,2,4] }\nassert my_solution.largestPerimeter(**test_input) == 9\n\ntest_input = { \"nums\": [3,2,5] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [3,3,1] }\nassert my_solution.largestPerimeter(**test_input) == 7\n\ntest_input = { \"nums\": [3,3,2] }\nassert my_solution.largestPerimeter(**test_input) == 8\n\ntest_input = { \"nums\": [3,3,3] }\nassert my_solution.largestPerimeter(**test_input) == 9\n\ntest_input = { \"nums\": [3,3,4] }\nassert my_solution.largestPerimeter(**test_input) == 10\n\ntest_input = { \"nums\": [3,3,5] }\nassert my_solution.largestPerimeter(**test_input) == 11\n\ntest_input = { \"nums\": [3,4,1] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [3,4,2] }\nassert my_solution.largestPerimeter(**test_input) == 9\n\ntest_input = { \"nums\": [3,4,3] }\nassert my_solution.largestPerimeter(**test_input) == 10\n\ntest_input = { \"nums\": [3,4,4] }\nassert my_solution.largestPerimeter(**test_input) == 11\n\ntest_input = { \"nums\": [3,4,5] }\nassert my_solution.largestPerimeter(**test_input) == 12\n\ntest_input = { \"nums\": [3,5,1] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [3,5,2] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [3,5,3] }\nassert my_solution.largestPerimeter(**test_input) == 11\n\ntest_input = { \"nums\": [3,5,4] }\nassert my_solution.largestPerimeter(**test_input) == 12\n\ntest_input = { \"nums\": [3,5,5] }\nassert my_solution.largestPerimeter(**test_input) == 13\n\ntest_input = { \"nums\": [4,1,1] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [4,1,2] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [4,1,3] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [4,1,4] }\nassert my_solution.largestPerimeter(**test_input) == 9\n\ntest_input = { \"nums\": [4,1,5] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [4,2,1] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [4,2,2] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [4,2,3] }\nassert my_solution.largestPerimeter(**test_input) == 9\n\ntest_input = { \"nums\": [4,2,4] }\nassert my_solution.largestPerimeter(**test_input) == 10\n\ntest_input = { \"nums\": [4,2,5] }\nassert my_solution.largestPerimeter(**test_input) == 11\n\ntest_input = { \"nums\": [4,3,1] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [4,3,2] }\nassert my_solution.largestPerimeter(**test_input) == 9\n\ntest_input = { \"nums\": [4,3,3] }\nassert my_solution.largestPerimeter(**test_input) == 10\n\ntest_input = { \"nums\": [4,3,4] }\nassert my_solution.largestPerimeter(**test_input) == 11\n\ntest_input = { \"nums\": [4,3,5] }\nassert my_solution.largestPerimeter(**test_input) == 12\n\ntest_input = { \"nums\": [4,4,1] }\nassert my_solution.largestPerimeter(**test_input) == 9\n\ntest_input = { \"nums\": [4,4,2] }\nassert my_solution.largestPerimeter(**test_input) == 10\n\ntest_input = { \"nums\": [4,4,3] }\nassert my_solution.largestPerimeter(**test_input) == 11\n\ntest_input = { \"nums\": [4,4,4] }\nassert my_solution.largestPerimeter(**test_input) == 12\n\ntest_input = { \"nums\": [4,4,5] }\nassert my_solution.largestPerimeter(**test_input) == 13\n\ntest_input = { \"nums\": [4,5,1] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [4,5,2] }\nassert my_solution.largestPerimeter(**test_input) == 11", "start_time": 1703341800} +{"task_id": "biweekly-contest-120-count-the-number-of-incremovable-subarrays-ii", "url": "https://leetcode.com/problems/count-the-number-of-incremovable-subarrays-ii", "title": "count-the-number-of-incremovable-subarrays-ii", "meta": {"questionId": "3248", "questionFrontendId": "2972", "title": "Count the Number of Incremovable Subarrays II", "titleSlug": "count-the-number-of-incremovable-subarrays-ii", "isPaidOnly": false, "difficulty": "Hard", "likes": 97, "dislikes": 15, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0开始的 正整数数组nums。\n如果 nums的一个子数组满足:移除这个子数组后剩余元素 严格递增,那么我们称这个子数组为 移除递增子数组。比方说,[5, 3, 4, 6, 7]中的 [3, 4]是一个移除递增子数组,因为移除该子数组后,[5, 3, 4, 6, 7]变为[5, 6, 7],是严格递增的。\n请你返回 nums中 移除递增子数组的总数目。\n注意,剩余元素为空的数组也视为是递增的。\n子数组 指的是一个数组中一段连续的元素序列。\n\n示例 1:\n\n输入:nums = [1,2,3,4]\n输出:10\n解释:10 个移除递增子数组分别为:[1], [2], [3], [4], [1,2], [2,3], [3,4], [1,2,3], [2,3,4] 和 [1,2,3,4]。移除任意一个子数组后,剩余元素都是递增的。注意,空数组不是移除递增子数组。\n\n示例 2:\n\n输入:nums = [6,5,7,8]\n输出:7\n解释:7个移除递增子数组分别为:[5], [6], [5,7], [6,5], [5,7,8], [6,5,7] 和 [6,5,7,8] 。\nnums 中只有这 7 个移除递增子数组。\n\n示例 3:\n\n输入:nums = [8,7,6,6]\n输出:3\n解释:3 个移除递增子数组分别为:[8,7,6], [7,6,6] 和 [8,7,6,6] 。注意 [8,7] 不是移除递增子数组因为移除 [8,7] 后 nums 变为 [6,6] ,它不是严格递增的。\n\n\n提示:\n\n1 <= nums.length <= 105\n1 <= nums[i] <= 109\n\"\"\"\nclass Solution:\n def incremovableSubarrayCount(self, nums: List[int]) -> int:\n ", "prompt_sft": "给你一个下标从 0开始的 正整数数组nums。\n如果 nums的一个子数组满足:移除这个子数组后剩余元素 严格递增,那么我们称这个子数组为 移除递增子数组。比方说,[5, 3, 4, 6, 7]中的 [3, 4]是一个移除递增子数组,因为移除该子数组后,[5, 3, 4, 6, 7]变为[5, 6, 7],是严格递增的。\n请你返回 nums中 移除递增子数组的总数目。\n注意,剩余元素为空的数组也视为是递增的。\n子数组 指的是一个数组中一段连续的元素序列。\n\n示例 1:\n\n输入:nums = [1,2,3,4]\n输出:10\n解释:10 个移除递增子数组分别为:[1], [2], [3], [4], [1,2], [2,3], [3,4], [1,2,3], [2,3,4] 和 [1,2,3,4]。移除任意一个子数组后,剩余元素都是递增的。注意,空数组不是移除递增子数组。\n\n示例 2:\n\n输入:nums = [6,5,7,8]\n输出:7\n解释:7个移除递增子数组分别为:[5], [6], [5,7], [6,5], [5,7,8], [6,5,7] 和 [6,5,7,8] 。\nnums 中只有这 7 个移除递增子数组。\n\n示例 3:\n\n输入:nums = [8,7,6,6]\n输出:3\n解释:3 个移除递增子数组分别为:[8,7,6], [7,6,6] 和 [8,7,6,6] 。注意 [8,7] 不是移除递增子数组因为移除 [8,7] 后 nums 变为 [6,6] ,它不是严格递增的。\n\n\n提示:\n\n1 <= nums.length <= 105\n1 <= nums[i] <= 109\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def incremovableSubarrayCount(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,2,3,4] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 10\n\ntest_input = { \"nums\": [6,5,7,8] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 7\n\ntest_input = { \"nums\": [8,7,6,6] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [1] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 1\n\ntest_input = { \"nums\": [2] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 1\n\ntest_input = { \"nums\": [3] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 1\n\ntest_input = { \"nums\": [4] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 1\n\ntest_input = { \"nums\": [5] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 1\n\ntest_input = { \"nums\": [6] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 1\n\ntest_input = { \"nums\": [7] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 1\n\ntest_input = { \"nums\": [8] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 1\n\ntest_input = { \"nums\": [9] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 1\n\ntest_input = { \"nums\": [10] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 1\n\ntest_input = { \"nums\": [4,10] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [7,3] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [8,5] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [8,10] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [9,9] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [5,5,6] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 5\n\ntest_input = { \"nums\": [6,7,5] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [8,1,2] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [9,2,8] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [9,3,8] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,10,6] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 7\n\ntest_input = { \"nums\": [1,9,6,9] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 7\n\ntest_input = { \"nums\": [4,8,5,9] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 8\n\ntest_input = { \"nums\": [6,2,6,4] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [10,2,5,7] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 5\n\ntest_input = { \"nums\": [1,2,4,7,10] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 15\n\ntest_input = { \"nums\": [1,5,9,5,7] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 9\n\ntest_input = { \"nums\": [6,6,5,3,5] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [8,5,5,3,10] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 5\n\ntest_input = { \"nums\": [9,10,1,8,2] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [11,50,14,33,45,38,33,19,28,34] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 9\n\ntest_input = { \"nums\": [25,9,28,31,38,15,31,44,46,49] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 11\n\ntest_input = { \"nums\": [25,26,49,31,40,47,30,29,32,34] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 13\n\ntest_input = { \"nums\": [25,39,29,30,40,28,30,39,30,42] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 8\n\ntest_input = { \"nums\": [25,41,31,38,30,38,37,41,36,32] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 5\n\ntest_input = { \"nums\": [25,45,49,28,47,44,42,34,28,25] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 5\n\ntest_input = { \"nums\": [25,46,48,41,29,47,32,34,41,34] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 6\n\ntest_input = { \"nums\": [25,47,25,35,48,49,27,37,36,43] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 7\n\ntest_input = { \"nums\": [26,26,50,38,30,38,31,26,39,45] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 7\n\ntest_input = { \"nums\": [26,32,41,38,45,32,31,27,48,41] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 7\n\ntest_input = { \"nums\": [26,45,44,26,33,35,34,36,44,38] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 5\n\ntest_input = { \"nums\": [26,49,42,26,37,41,31,36,45,41] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 5\n\ntest_input = { \"nums\": [27,39,32,30,38,41,28,26,49,49] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 6\n\ntest_input = { \"nums\": [27,43,36,37,33,46,48,35,49,49] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 6\n\ntest_input = { \"nums\": [28,17,12,21,21,49,31,30,40,13] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [28,30,39,31,33,41,47,36,43,46] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 15\n\ntest_input = { \"nums\": [29,27,32,38,26,38,39,30,41,45] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 8\n\ntest_input = { \"nums\": [29,31,48,28,27,38,32,28,30,44] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 10\n\ntest_input = { \"nums\": [29,34,44,27,45,31,37,32,50,26] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 5\n\ntest_input = { \"nums\": [29,38,36,42,31,38,27,48,42,28] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [29,46,34,47,46,41,29,29,38,39] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 8\n\ntest_input = { \"nums\": [29,49,32,35,38,37,27,25,50,46] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 5\n\ntest_input = { \"nums\": [30,27,38,33,28,48,41,30,25,50] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 5\n\ntest_input = { \"nums\": [30,29,31,44,31,25,50,35,35,47] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 6\n\ntest_input = { \"nums\": [30,30,46,35,31,41,30,37,37,33] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [30,41,28,45,35,41,47,32,29,33] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 6\n\ntest_input = { \"nums\": [30,45,44,27,43,40,28,34,39,40] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 10\n\ntest_input = { \"nums\": [30,49,34,26,50,50,48,49,39,26] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [31,34,25,43,38,34,29,50,27,34] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 6\n\ntest_input = { \"nums\": [31,35,39,38,41,47,26,43,47,46] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 8\n\ntest_input = { \"nums\": [31,37,29,41,32,46,25,28,30,29] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [31,38,31,47,25,25,36,29,43,28] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [31,41,25,37,43,29,30,26,30,46] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 8\n\ntest_input = { \"nums\": [31,42,40,36,39,28,43,29,35,50] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 9\n\ntest_input = { \"nums\": [32,29,13,39,34,47,38,15,10,5] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [32,35,32,50,32,26,29,49,40,41] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 9\n\ntest_input = { \"nums\": [32,37,35,26,45,44,47,29,31,28] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [32,43,44,44,36,41,31,33,41,43] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 11\n\ntest_input = { \"nums\": [32,50,50,46,32,30,32,32,31,39] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 6\n\ntest_input = { \"nums\": [33,27,34,46,42,35,36,49,25,40] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 5\n\ntest_input = { \"nums\": [33,28,35,32,36,38,33,47,36,35] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [33,31,36,38,39,46,42,41,27,33] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [33,45,25,48,45,42,35,38,47,43] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 5\n\ntest_input = { \"nums\": [33,46,38,37,42,48,31,43,38,29] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [33,48,50,48,46,33,34,26,32,33] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 7\n\ntest_input = { \"nums\": [34,25,38,41,31,46,40,46,39,30] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [34,38,35,28,30,37,35,25,48,28] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [34,47,26,48,30,25,26,43,44,41] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 5\n\ntest_input = { \"nums\": [35,22,35,6,20,47,3,29,45,30] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [35,25,29,40,32,29,35,39,39,32] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [35,26,39,41,26,44,36,26,46,50] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 7\n\ntest_input = { \"nums\": [35,27,29,45,29,30,48,42,37,50] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 6\n\ntest_input = { \"nums\": [35,31,27,45,39,46,47,49,26,27] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [35,39,36,30,32,48,34,25,37,45] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 9\n\ntest_input = { \"nums\": [36,26,44,32,36,29,44,28,48,30] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [36,28,28,45,40,40,32,48,34,48] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 5\n\ntest_input = { \"nums\": [36,28,34,49,48,36,50,25,43,40] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [36,30,47,32,32,35,41,49,41,45] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 6\n\ntest_input = { \"nums\": [36,31,45,34,47,48,49,31,34,34] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [37,33,50,48,25,37,29,49,46,45] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [37,35,29,27,39,38,49,48,27,37] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [37,40,42,41,30,40,46,44,47,27] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 5\n\ntest_input = { \"nums\": [37,43,49,40,30,46,31,44,47,25] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 5\n\ntest_input = { \"nums\": [37,45,49,26,32,45,33,40,35,43] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 7\n\ntest_input = { \"nums\": [37,50,42,50,40,26,34,25,28,44] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 7\n\ntest_input = { \"nums\": [38,28,25,31,28,44,35,26,33,41] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 6\n\ntest_input = { \"nums\": [38,30,36,50,36,40,41,25,43,43] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4", "start_time": 1703341800} +{"task_id": "biweekly-contest-120-find-number-of-coins-to-place-in-tree-nodes", "url": "https://leetcode.com/problems/find-number-of-coins-to-place-in-tree-nodes", "title": "find-number-of-coins-to-place-in-tree-nodes", "meta": {"questionId": "3218", "questionFrontendId": "2973", "title": "Find Number of Coins to Place in Tree Nodes", "titleSlug": "find-number-of-coins-to-place-in-tree-nodes", "isPaidOnly": false, "difficulty": "Hard", "likes": 67, "dislikes": 2, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一棵n个节点的无向树,节点编号为0到n - 1,树的根节点在节点0处。同时给你一个长度为 n - 1的二维整数数组edges,其中edges[i] = [ai, bi]表示树中节点ai 和bi之间有一条边。\n给你一个长度为 n下标从 0开始的整数数组cost,其中cost[i]是第 i个节点的 开销。\n你需要在树中每个节点都放置金币,在节点 i处的金币数目计算方法如下:\n\n如果节点 i对应的子树中的节点数目小于3,那么放1个金币。\n否则,计算节点 i 对应的子树内 3 个不同节点的开销乘积的 最大值 ,并在节点 i 处放置对应数目的金币。如果最大乘积是 负数,那么放置 0个金币。\n\n请你返回一个长度为 n的数组coin,coin[i]是节点i处的金币数目。\n\n示例 1:\n\n\n输入:edges = [[0,1],[0,2],[0,3],[0,4],[0,5]], cost = [1,2,3,4,5,6]\n输出:[120,1,1,1,1,1]\n解释:在节点 0 处放置 6 * 5 * 4 = 120 个金币。所有其他节点都是叶子节点,子树中只有 1 个节点,所以其他每个节点都放 1 个金币。\n\n示例 2:\n\n\n输入:edges = [[0,1],[0,2],[1,3],[1,4],[1,5],[2,6],[2,7],[2,8]], cost = [1,4,2,3,5,7,8,-4,2]\n输出:[280,140,32,1,1,1,1,1,1]\n解释:每个节点放置的金币数分别为:\n- 节点 0 处放置 8 * 7 * 5 = 280 个金币。\n- 节点 1 处放置 7 * 5 * 4 = 140 个金币。\n- 节点 2 处放置 8 * 2 * 2 = 32 个金币。\n- 其他节点都是叶子节点,子树内节点数目为 1 ,所以其他每个节点都放 1 个金币。\n\n示例 3:\n\n\n输入:edges = [[0,1],[0,2]], cost = [1,2,-2]\n输出:[0,1,1]\n解释:节点 1 和 2 都是叶子节点,子树内节点数目为 1 ,各放置 1 个金币。节点 0 处唯一的开销乘积是 2 * 1 * -2 = -4 。所以在节点 0 处放置 0 个金币。\n\n\n提示:\n\n2 <= n <= 2 * 104\nedges.length == n - 1\nedges[i].length == 2\n0 <= ai, bi < n\ncost.length == n\n1 <= |cost[i]| <= 104\nedges一定是一棵合法的树。\n\"\"\"\nclass Solution:\n def placedCoins(self, edges: List[List[int]], cost: List[int]) -> List[int]:\n ", "prompt_sft": "给你一棵n个节点的无向树,节点编号为0到n - 1,树的根节点在节点0处。同时给你一个长度为 n - 1的二维整数数组edges,其中edges[i] = [ai, bi]表示树中节点ai 和bi之间有一条边。\n给你一个长度为 n下标从 0开始的整数数组cost,其中cost[i]是第 i个节点的 开销。\n你需要在树中每个节点都放置金币,在节点 i处的金币数目计算方法如下:\n\n如果节点 i对应的子树中的节点数目小于3,那么放1个金币。\n否则,计算节点 i 对应的子树内 3 个不同节点的开销乘积的 最大值 ,并在节点 i 处放置对应数目的金币。如果最大乘积是 负数,那么放置 0个金币。\n\n请你返回一个长度为 n的数组coin,coin[i]是节点i处的金币数目。\n\n示例 1:\n\n\n输入:edges = [[0,1],[0,2],[0,3],[0,4],[0,5]], cost = [1,2,3,4,5,6]\n输出:[120,1,1,1,1,1]\n解释:在节点 0 处放置 6 * 5 * 4 = 120 个金币。所有其他节点都是叶子节点,子树中只有 1 个节点,所以其他每个节点都放 1 个金币。\n\n示例 2:\n\n\n输入:edges = [[0,1],[0,2],[1,3],[1,4],[1,5],[2,6],[2,7],[2,8]], cost = [1,4,2,3,5,7,8,-4,2]\n输出:[280,140,32,1,1,1,1,1,1]\n解释:每个节点放置的金币数分别为:\n- 节点 0 处放置 8 * 7 * 5 = 280 个金币。\n- 节点 1 处放置 7 * 5 * 4 = 140 个金币。\n- 节点 2 处放置 8 * 2 * 2 = 32 个金币。\n- 其他节点都是叶子节点,子树内节点数目为 1 ,所以其他每个节点都放 1 个金币。\n\n示例 3:\n\n\n输入:edges = [[0,1],[0,2]], cost = [1,2,-2]\n输出:[0,1,1]\n解释:节点 1 和 2 都是叶子节点,子树内节点数目为 1 ,各放置 1 个金币。节点 0 处唯一的开销乘积是 2 * 1 * -2 = -4 。所以在节点 0 处放置 0 个金币。\n\n\n提示:\n\n2 <= n <= 2 * 104\nedges.length == n - 1\nedges[i].length == 2\n0 <= ai, bi < n\ncost.length == n\n1 <= |cost[i]| <= 104\nedges一定是一棵合法的树。\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def placedCoins(self, edges: List[List[int]], cost: List[int]) -> List[int]:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"edges\": [[0,1],[0,2],[0,3],[0,4],[0,5]], \"cost\": [1,2,3,4,5,6] }\nassert my_solution.placedCoins(**test_input) == [120,1,1,1,1,1]\n\ntest_input = { \"edges\": [[0,1],[0,2],[1,3],[1,4],[1,5],[2,6],[2,7],[2,8]], \"cost\": [1,4,2,3,5,7,8,-4,2] }\nassert my_solution.placedCoins(**test_input) == [280,140,32,1,1,1,1,1,1]\n\ntest_input = { \"edges\": [[0,1],[0,2]], \"cost\": [1,2,-2] }\nassert my_solution.placedCoins(**test_input) == [0,1,1]\n\ntest_input = { \"edges\": [[0,1]], \"cost\": [1,2] }\nassert my_solution.placedCoins(**test_input) == [1,1]\n\ntest_input = { \"edges\": [[0,1]], \"cost\": [2,1] }\nassert my_solution.placedCoins(**test_input) == [1,1]\n\ntest_input = { \"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],[0,20],[0,21],[0,22],[0,23],[0,24],[0,25],[0,26],[0,27],[0,28],[0,29],[0,30],[0,31],[0,32],[0,33],[0,34],[0,35],[0,36],[0,37],[0,38],[0,39],[0,40],[0,41],[0,42],[0,43],[0,44],[0,45],[0,46],[0,47],[0,48],[0,49],[0,50],[0,51],[0,52],[0,53],[0,54],[0,55],[0,56],[0,57],[0,58],[0,59],[0,60],[0,61],[0,62],[0,63],[0,64],[0,65],[0,66],[0,67],[0,68],[0,69],[0,70],[0,71],[0,72],[0,73],[0,74],[0,75],[0,76],[0,77],[0,78],[0,79],[0,80],[0,81],[0,82],[0,83],[0,84],[0,85],[0,86],[0,87],[0,88],[0,89],[0,90],[0,91],[0,92],[0,93],[0,94],[0,95],[0,96],[0,97],[0,98],[0,99]], \"cost\": [-5959,602,-6457,7055,-1462,6347,7226,-8422,-6088,2997,-7909,6433,5217,3294,-3792,7463,8538,-3811,5009,151,5659,4458,-1702,-1877,2799,9861,-9668,-1765,2181,-8128,7046,9529,6202,-8026,6464,1345,121,1922,7274,-1227,-9914,3025,1046,-9368,-7368,6205,-6342,8091,-6732,-7620,3276,5136,6871,4823,-1885,-4005,-3974,-2725,-3845,-8508,7201,-9566,-7236,-3386,4021,6793,-8759,5066,5879,-5171,1011,1242,8536,-8405,-9646,-214,2251,-9934,-8820,6206,1006,1318,-9712,7230,5608,-4601,9185,346,3056,8913,-2454,-3445,-4295,4802,-8852,-6121,-4538,-5580,-9246,-6462] }\nassert my_solution.placedCoins(**test_input) == [971167251036,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]\n\ntest_input = { \"edges\": [[0,1],[0,2],[2,3]], \"cost\": [10000,-10000,10000,-10000] }\nassert my_solution.placedCoins(**test_input) == [1000000000000,1,1,1]\n\ntest_input = { \"edges\": [[0,2],[0,6],[1,4],[3,5],[7,6],[3,6],[1,8],[3,1],[9,3]], \"cost\": [63,13,-6,20,56,-14,61,25,-99,54] }\nassert my_solution.placedCoins(**test_input) == [215208,0,1,77616,1,1,184464,1,1,1]\n\ntest_input = { \"edges\": [[7,0],[4,3],[4,8],[1,5],[6,2],[2,7],[7,9],[1,8],[1,9]], \"cost\": [37,-48,30,-67,-84,36,-96,24,29,38] }\nassert my_solution.placedCoins(**test_input) == [306432,202608,1,1,1,1,1,306432,163212,213864]\n\ntest_input = { \"edges\": [[0,2],[2,7],[3,4],[5,4],[5,8],[7,6],[7,1],[8,1],[1,9]], \"cost\": [-18,15,-82,-85,63,-89,60,63,20,18] }\nassert my_solution.placedCoins(**test_input) == [476595,476595,476595,1,1,476595,1,476595,476595,1]\n\ntest_input = { \"edges\": [[2,0],[1,4],[3,8],[4,9],[6,8],[7,2],[2,8],[5,2],[5,9]], \"cost\": [-9,46,17,34,43,92,41,-50,4,76] }\nassert my_solution.placedCoins(**test_input) == [321632,1,321632,1,1,321632,1,1,5576,150328]\n\ntest_input = { \"edges\": [[0,6],[3,2],[3,1],[6,1],[8,7],[7,1],[5,1],[5,4],[9,4]], \"cost\": [86,50,10,-54,-85,-65,54,-19,39,37] }\nassert my_solution.placedCoins(**test_input) == [475150,276250,1,1,1,204425,298350,1,1,1]\n\ntest_input = { \"edges\": [[0,8],[8,1],[9,2],[4,6],[7,4],[3,7],[3,8],[5,8],[5,9]], \"cost\": [-4,83,-97,40,86,-85,-6,-84,-16,-53] }\nassert my_solution.placedCoins(**test_input) == [709070,1,1,43344,1,0,1,43344,709070,1]\n\ntest_input = { \"edges\": [[4,2],[1,3],[4,5],[7,5],[5,0],[8,1],[0,1],[0,6],[9,6]], \"cost\": [-72,-18,-27,38,13,-53,43,-95,-100,-77] }\nassert my_solution.placedCoins(**test_input) == [408500,68400,1,1,1,65455,1,1,1,1]\n\ntest_input = { \"edges\": [[0,2],[5,2],[1,5],[7,4],[4,8],[1,8],[1,6],[6,3],[9,3]], \"cost\": [6,93,59,-14,1,-71,-87,95,16,-12] }\nassert my_solution.placedCoins(**test_input) == [586815,141360,586815,1,1,586815,0,1,1520,1]\n\ntest_input = { \"edges\": [[0,1],[5,4],[4,2],[7,2],[7,3],[8,6],[3,6],[3,1],[9,1]], \"cost\": [66,-54,74,18,-77,-57,49,-82,-71,80] }\nassert my_solution.placedCoins(**test_input) == [505120,505120,324786,467236,1,1,1,467236,1,1]\n\ntest_input = { \"edges\": [[3,8],[2,4],[5,6],[6,7],[0,8],[2,0],[2,6],[1,6],[9,1]], \"cost\": [92,-71,-10,-70,-56,-47,69,51,100,65] }\nassert my_solution.placedCoins(**test_input) == [634800,1,274344,1,1,1,230253,1,1,1]\n\ntest_input = { \"edges\": [[0,3],[2,8],[5,6],[9,5],[7,9],[8,1],[1,4],[4,3],[9,3]], \"cost\": [-71,66,86,99,50,-29,-30,27,16,-65] }\nassert my_solution.placedCoins(**test_input) == [561924,90816,1,561924,283800,1,1,1,1,52650]\n\ntest_input = { \"edges\": [[1,0],[2,7],[6,3],[0,4],[6,5],[5,8],[0,7],[9,0],[9,8]], \"cost\": [40,8,43,31,-27,-21,-21,55,-36,75] }\nassert my_solution.placedCoins(**test_input) == [177375,1,1,1,1,13671,1,1,23436,56700]\n\ntest_input = { \"edges\": [[9,0],[9,3],[4,5],[1,6],[1,5],[8,5],[9,7],[8,2],[2,9]], \"cost\": [64,35,-1,-28,-50,38,-77,-13,-72,35] }\nassert my_solution.placedCoins(**test_input) == [354816,1,210672,1,1,146300,1,1,210672,210672]\n\ntest_input = { \"edges\": [[5,3],[4,2],[5,2],[6,5],[5,1],[0,1],[0,8],[9,7],[9,8]], \"cost\": [-100,44,-76,55,8,-8,38,26,-41,-83] }\nassert my_solution.placedCoins(**test_input) == [456500,91960,1,1,1,33440,1,1,88478,1]\n\ntest_input = { \"edges\": [[0,8],[9,3],[4,5],[8,5],[2,6],[7,8],[2,8],[1,2],[9,1]], \"cost\": [36,33,52,-24,7,-82,63,85,21,-64] }\nassert my_solution.placedCoins(**test_input) == [446080,50688,108108,1,1,1,1,1,446080,1]\n\ntest_input = { \"edges\": [[9,2],[1,3],[8,4],[1,5],[1,9],[8,6],[7,9],[8,0],[0,9]], \"cost\": [-67,-82,-2,32,-97,6,-85,14,8,1] }\nassert my_solution.placedCoins(**test_input) == [263840,0,1,1,1,1,1,1,65960,5248]\n\ntest_input = { \"edges\": [[7,0],[3,1],[7,3],[4,8],[8,5],[7,6],[2,6],[2,9],[8,9]], \"cost\": [-48,-69,-25,-65,65,51,85,34,17,-28] }\nassert my_solution.placedCoins(**test_input) == [381225,1,56355,1,1,1,281775,381225,56355,56355]\n\ntest_input = { \"edges\": [[4,2],[7,2],[3,5],[6,3],[3,0],[7,0],[1,8],[1,0],[9,0]], \"cost\": [-14,39,40,-76,-69,66,43,82,-66,-45] }\nassert my_solution.placedCoins(**test_input) == [430008,1,1,0,1,1,1,0,1,1]\n\ntest_input = { \"edges\": [[1,9],[3,7],[0,6],[7,0],[8,5],[2,5],[4,2],[4,0],[0,9]], \"cost\": [34,-87,-34,87,58,76,5,43,14,-45] }\nassert my_solution.placedCoins(**test_input) == [383496,1,0,1,61712,1,1,1,1,1]\n\ntest_input = { \"edges\": [[7,1],[2,7],[4,3],[9,5],[6,7],[3,6],[8,3],[0,3],[0,9]], \"cost\": [-9,67,10,-67,91,29,-4,-35,60,-84] }\nassert my_solution.placedCoins(**test_input) == [512148,1,1,365820,1,1,9380,0,1,1]\n\ntest_input = { \"edges\": [[2,3],[3,6],[3,7],[8,5],[1,5],[4,1],[4,0],[0,3],[9,3]], \"cost\": [88,-73,8,-82,64,-14,56,-82,-2,-89] }\nassert my_solution.placedCoins(**test_input) == [642224,0,1,408688,65408,1,1,1,1,1]\n\ntest_input = { \"edges\": [[8,4],[7,3],[3,0],[0,6],[6,8],[8,2],[5,2],[1,5],[1,9]], \"cost\": [-50,34,51,-69,-28,72,61,-76,-30,76] }\nassert my_solution.placedCoins(**test_input) == [398544,1,279072,1,1,186048,333792,1,279072,1]\n\ntest_input = { \"edges\": [[5,0],[1,6],[7,2],[4,9],[3,5],[3,7],[8,7],[6,7],[6,9]], \"cost\": [-75,-39,-30,-69,84,-7,98,92,-42,-51] }\nassert my_solution.placedCoins(**test_input) == [757344,1,1,757344,1,757344,194922,757344,1,1]\n\ntest_input = { \"edges\": [[0,8],[2,5],[3,5],[1,6],[4,1],[8,4],[7,8],[8,5],[9,5]], \"cost\": [81,-76,-61,1,39,-3,-21,-33,42,-78] }\nassert my_solution.placedCoins(**test_input) == [480168,1,1,1,62244,4758,1,1,248976,1]\n\ntest_input = { \"edges\": [[7,1],[0,2],[0,3],[6,5],[6,0],[0,7],[7,4],[9,4],[8,9]], \"cost\": [-37,-11,71,-57,-2,-78,87,55,-21,-66] }\nassert my_solution.placedCoins(**test_input) == [447876,1,1,1,0,1,1,76230,1,1]\n\ntest_input = { \"edges\": [[0,9],[8,2],[3,7],[6,4],[1,5],[8,1],[6,8],[6,7],[7,9]], \"cost\": [61,-53,-97,-86,-91,-32,-8,79,100,75] }\nassert my_solution.placedCoins(**test_input) == [882700,1,1,1,1,1,882700,882700,514100,882700]\n\ntest_input = { \"edges\": [[8,3],[4,6],[2,5],[2,1],[6,8],[8,0],[0,7],[1,7],[1,9]], \"cost\": [-40,-4,60,-47,35,39,-8,-12,-29,-43] }\nassert my_solution.placedCoins(**test_input) == [121260,10320,1,1,1,1,1,30960,47705,1]\n\ntest_input = { \"edges\": [[3,0],[1,7],[6,3],[7,5],[4,5],[4,6],[6,9],[2,8],[9,2]], \"cost\": [36,84,5,32,-36,86,-35,58,36,-100] }\nassert my_solution.placedCoins(**test_input) == [418992,1,1,418992,418992,418992,418992,1,1,0]\n\ntest_input = { \"edges\": [[1,0],[3,0],[2,5],[3,5],[6,4],[4,9],[7,3],[8,3],[3,9]], \"cost\": [39,22,-9,-65,9,-53,83,-94,-34,12] }\nassert my_solution.placedCoins(**test_input) == [507130,1,1,507130,1,1,1,1,1,8964]\n\ntest_input = { \"edges\": [[2,0],[7,0],[4,3],[5,8],[7,9],[8,1],[3,1],[3,6],[9,6]], \"cost\": [-68,1,-68,65,-45,-26,36,-3,-85,40] }\nassert my_solution.placedCoins(**test_input) == [375700,2210,1,248625,1,1,248625,248625,1,248625]\n\ntest_input = { \"edges\": [[4,0],[7,2],[2,6],[8,6],[5,6],[4,5],[4,3],[1,3],[1,9]], \"cost\": [-45,26,-26,-34,-33,81,-33,55,-87,52] }\nassert my_solution.placedCoins(**test_input) == [317115,1,1,0,239598,232551,157905,1,1,1]\n\ntest_input = { \"edges\": [[2,1],[0,1],[6,3],[5,4],[6,5],[0,6],[9,0],[8,7],[9,7]], \"cost\": [94,76,-92,61,27,78,-94,39,-12,77] }\nassert my_solution.placedCoins(**test_input) == [812912,1,1,1,1,1,128466,1,1,0]\n\ntest_input = { \"edges\": [[8,0],[3,2],[6,2],[1,2],[1,5],[4,7],[9,4],[8,5],[9,5]], \"cost\": [-6,-89,62,-82,-78,97,-71,58,-43,12] }\nassert my_solution.placedCoins(**test_input) == [707906,452476,360964,1,1,707906,1,1,707906,0]\n\ntest_input = { \"edges\": [[1,0],[2,0],[4,0],[4,3],[4,6],[6,5],[7,5],[7,8],[9,8]], \"cost\": [-35,4,-1,-44,-27,-93,10,55,-14,93] }\nassert my_solution.placedCoins(**test_input) == [380556,1,1,1,380556,121086,121086,0,1,1]\n\ntest_input = { \"edges\": [[0,6],[1,5],[8,2],[8,3],[9,6],[4,7],[5,8],[5,4],[4,9]], \"cost\": [26,22,32,-27,54,44,-58,-88,79,-77] }\nassert my_solution.placedCoins(**test_input) == [535304,1,1,1,187704,111232,535304,1,0,535304]\n\ntest_input = { \"edges\": [[7,2],[3,1],[5,1],[8,5],[6,9],[7,0],[0,4],[4,8],[9,4]], \"cost\": [-70,-80,17,23,19,-71,84,-52,-21,-44] }\nassert my_solution.placedCoins(**test_input) == [477120,1,1,1,477120,130640,1,1,130640,1]\n\ntest_input = { \"edges\": [[2,1],[3,6],[0,6],[7,2],[5,2],[5,4],[4,0],[0,8],[9,0]], \"cost\": [-27,11,-5,22,-81,48,-28,-85,85,-44] }\nassert my_solution.placedCoins(**test_input) == [585225,1,4675,1,330480,20400,1,1,1,1]\n\ntest_input = { \"edges\": [[8,1],[2,5],[4,3],[8,5],[5,6],[6,3],[0,3],[7,0],[9,7]], \"cost\": [79,-73,75,-96,61,87,-74,69,84,41] }\nassert my_solution.placedCoins(**test_input) == [618048,1,1,618048,1,548100,548100,1,1,1]\n\ntest_input = { \"edges\": [[1,0],[2,0],[3,0],[4,0],[0,7],[8,0],[8,6],[5,6],[5,9]], \"cost\": [-97,-61,-67,60,-75,-85,-21,75,-89,59] }\nassert my_solution.placedCoins(**test_input) == [647475,1,1,1,1,1,105315,1,446335,1]\n\ntest_input = { \"edges\": [[0,1],[0,4],[9,3],[9,4],[5,2],[2,7],[6,8],[8,7],[8,9]], \"cost\": [-88,-7,-16,-49,-53,46,-19,38,-2,-12] }\nassert my_solution.placedCoins(**test_input) == [214544,1,1,1,119462,1,1,0,13984,42826]\n\ntest_input = { \"edges\": [[2,0],[4,6],[4,5],[1,5],[3,1],[3,2],[2,7],[8,7],[7,9]], \"cost\": [-71,-13,56,3,95,74,79,81,-50,-24] }\nassert my_solution.placedCoins(**test_input) == [607905,555370,607905,555370,1,555370,1,97200,1,1]\n\ntest_input = { \"edges\": [[3,2],[7,3],[4,8],[1,5],[6,7],[0,7],[8,1],[0,1],[9,0]], \"cost\": [25,-2,22,-40,-53,-17,-97,-49,29,36] }\nassert my_solution.placedCoins(**test_input) == [185076,26129,1,1,1,1,1,104566,1,1]\n\ntest_input = { \"edges\": [[1,8],[2,6],[7,2],[7,3],[8,3],[8,4],[5,4],[5,0],[9,0]], \"cost\": [-54,-16,51,-79,73,-83,-54,5,45,14] }\nassert my_solution.placedCoins(**test_input) == [478661,1,1,217566,311418,478661,1,0,217566,1]\n\ntest_input = { \"edges\": [[3,1],[4,0],[1,5],[6,1],[6,0],[9,7],[0,8],[0,2],[2,9]], \"cost\": [23,-50,-5,-36,-49,49,39,-82,-8,81] }\nassert my_solution.placedCoins(**test_input) == [332100,88200,33210,1,1,1,88200,1,1,1]\n\ntest_input = { \"edges\": [[0,7],[8,1],[5,7],[8,2],[2,3],[3,7],[4,7],[4,6],[6,9]], \"cost\": [-12,-83,-3,-43,12,48,-46,19,-92,69] }\nassert my_solution.placedCoins(**test_input) == [526884,1,0,0,0,1,1,526884,1,1]\n\ntest_input = { \"edges\": [[0,1],[2,5],[7,2],[7,6],[1,8],[1,3],[3,7],[4,7],[9,4]], \"cost\": [56,61,-17,-3,-100,-28,81,42,1,-86] }\nassert my_solution.placedCoins(**test_input) == [696600,696600,1,696600,1,1,1,696600,1,1]\n\ntest_input = { \"edges\": [[0,3],[8,1],[3,6],[5,3],[2,8],[4,2],[4,7],[7,5],[5,9]], \"cost\": [-42,72,54,-46,57,95,94,21,-19,-92] }\nassert my_solution.placedCoins(**test_input) == [642960,1,0,642960,221616,389880,1,221616,1,1]\n\ntest_input = { \"edges\": [[2,0],[2,4],[6,5],[8,6],[3,7],[3,1],[1,8],[2,1],[2,9]], \"cost\": [-58,-82,-70,33,20,-40,21,-93,18,-6] }\nassert my_solution.placedCoins(**test_input) == [251658,251658,251658,1,1,1,1,1,0,1]\n\ntest_input = { \"edges\": [[1,5],[3,0],[0,2],[2,4],[5,2],[7,2],[6,7],[8,7],[7,9]], \"cost\": [-96,-98,41,59,-69,-51,-78,43,-40,-8] }\nassert my_solution.placedCoins(**test_input) == [555072,1,328692,1,1,1,1,134160,1,1]\n\ntest_input = { \"edges\": [[0,4],[1,4],[3,6],[5,7],[4,6],[7,2],[4,2],[4,9],[9,8]], \"cost\": [-98,-100,-37,62,38,-54,56,56,1,-72] }\nassert my_solution.placedCoins(**test_input) == [607600,1,111888,1,446400,1,1,1,1,1]\n\ntest_input = { \"edges\": [[8,0],[4,3],[6,3],[5,7],[6,8],[8,2],[1,2],[7,1],[9,7]], \"cost\": [-70,-59,-87,-64,56,-15,-62,-48,-58,-85] }\nassert my_solution.placedCoins(**test_input) == [414120,0,0,1,1,1,222208,0,414120,1]\n\ntest_input = { \"edges\": [[3,0],[1,8],[6,2],[5,3],[4,5],[8,4],[7,8],[8,6],[6,9]], \"cost\": [-56,-14,-44,-2,31,34,-61,53,-39,-21] }\nassert my_solution.placedCoins(**test_input) == [181048,1,1,142252,142252,142252,0,1,142252,1]\n\ntest_input = { \"edges\": [[2,1],[1,3],[5,8],[9,6],[8,1],[1,4],[4,0],[7,0],[7,9]], \"cost\": [-18,-10,25,-60,-48,4,14,38,26,16] }\nassert my_solution.placedCoins(**test_input) == [109440,15600,1,1,74880,1,1,8512,1,1]\n\ntest_input = { \"edges\": [[0,2],[2,5],[3,4],[5,3],[6,8],[7,1],[5,1],[5,9],[8,9]], \"cost\": [46,96,34,76,19,29,-36,48,-71,-45] }\nassert my_solution.placedCoins(**test_input) == [350208,1,350208,1,1,350208,1,1,1,0]\n\ntest_input = { \"edges\": [[0,2],[7,2],[3,4],[4,7],[5,1],[6,1],[7,6],[9,6],[8,9]], \"cost\": [4,70,65,-34,-59,-70,-83,-21,66,-10] }\nassert my_solution.placedCoins(**test_input) == [406700,1,406700,1,1,1,406700,406700,1,1]\n\ntest_input = { \"edges\": [[0,1],[2,3],[5,2],[9,2],[6,9],[9,7],[1,8],[4,1],[9,4]], \"cost\": [54,72,-52,45,-62,96,-54,28,-76,86] }\nassert my_solution.placedCoins(**test_input) == [594432,594432,0,1,371520,1,1,1,1,371520]\n\ntest_input = { \"edges\": [[1,0],[0,4],[3,5],[6,7],[6,3],[3,8],[8,0],[0,2],[9,2]], \"cost\": [-98,-85,82,-30,64,-76,36,-54,84,85] }\nassert my_solution.placedCoins(**test_input) == [708050,1,1,147744,1,1,1,1,344736,1]\n\ntest_input = { \"edges\": [[0,8],[2,6],[4,7],[5,1],[1,9],[3,7],[3,8],[6,8],[9,6]], \"cost\": [60,-76,-76,38,-5,-33,-80,-36,28,63] }\nassert my_solution.placedCoins(**test_input) == [383040,1,1,6840,1,1,383040,1,383040,158004]\n\ntest_input = { \"edges\": [[5,3],[6,5],[7,6],[6,2],[2,1],[0,1],[0,9],[4,8],[4,9]], \"cost\": [-56,-92,-10,-70,52,22,43,37,88,48] }\nassert my_solution.placedCoins(**test_input) == [566720,276920,35002,1,1,1,35002,1,1,219648]\n\ntest_input = { \"edges\": [[8,2],[9,4],[1,7],[3,1],[3,5],[5,8],[5,0],[0,6],[9,6]], \"cost\": [-70,17,-31,41,-93,17,-19,21,-66,-29] }\nassert my_solution.placedCoins(**test_input) == [266910,1,1,14637,1,83886,0,1,1,1]\n\ntest_input = { \"edges\": [[8,1],[2,4],[7,3],[2,3],[2,6],[6,5],[0,5],[0,8],[9,8]], \"cost\": [88,86,55,-61,3,-70,12,44,-92,-72] }\nassert my_solution.placedCoins(**test_input) == [582912,1,7260,1,1,234850,29040,1,569664,1]\n\ntest_input = { \"edges\": [[0,7],[1,3],[1,6],[4,2],[6,2],[5,6],[5,9],[7,8],[9,8]], \"cost\": [15,78,-48,58,-27,28,60,-9,-64,-71] }\nassert my_solution.placedCoins(**test_input) == [354432,1,1,1,1,271440,271440,354432,354432,271440]\n\ntest_input = { \"edges\": [[4,0],[8,0],[5,6],[8,6],[6,1],[7,1],[3,7],[2,3],[9,2]], \"cost\": [14,10,10,-73,-43,19,92,62,16,-27] }\nassert my_solution.placedCoins(**test_input) == [288788,122202,1,19710,1,1,181332,122202,181332,1]\n\ntest_input = { \"edges\": [[8,0],[3,1],[1,2],[8,5],[6,7],[4,7],[9,4],[2,8],[2,9]], \"cost\": [97,35,-74,5,65,5,86,61,-55,53] }\nassert my_solution.placedCoins(**test_input) == [542230,1,340990,1,340990,1,1,1,350020,340990]\n\ntest_input = { \"edges\": [[0,1],[7,0],[8,2],[3,4],[4,7],[4,8],[4,6],[5,6],[9,5]], \"cost\": [-74,40,73,-97,-62,9,-96,-98,-38,63] }\nassert my_solution.placedCoins(**test_input) == [693938,1,1,1,679776,1,0,693938,1,1]\n\ntest_input = { \"edges\": [[2,3],[0,3],[0,6],[6,5],[7,1],[1,5],[8,5],[4,5],[9,4]], \"cost\": [4,-30,59,61,78,-22,-24,85,-19,-89] }\nassert my_solution.placedCoins(**test_input) == [404430,1,1,1,1,226950,226950,1,1,1]\n\ntest_input = { \"edges\": [[1,2],[5,4],[5,6],[7,1],[3,1],[3,5],[5,8],[0,5],[0,9]], \"cost\": [11,-80,95,64,-76,56,61,22,13,-58] }\nassert my_solution.placedCoins(**test_input) == [577600,0,1,133760,1,577600,1,1,1,1]\n\ntest_input = { \"edges\": [[1,9],[2,7],[3,5],[4,3],[0,4],[0,6],[8,0],[7,0],[9,7]], \"cost\": [-69,18,-39,-59,-48,-65,97,1,74,-63] }\nassert my_solution.placedCoins(**test_input) == [435045,1,1,1,0,1,1,44226,1,1]\n\ntest_input = { \"edges\": [[0,6],[1,4],[5,4],[6,8],[3,8],[5,3],[5,2],[7,2],[9,7]], \"cost\": [-84,27,16,75,49,4,72,46,-17,48] }\nassert my_solution.placedCoins(**test_input) == [264600,1,35328,176400,1,108192,264600,1,176400,1]\n\ntest_input = { \"edges\": [[0,9],[1,7],[6,3],[8,7],[7,3],[5,3],[2,5],[2,4],[4,9]], \"cost\": [1,-53,88,-67,-55,-31,-89,-39,21,-96] }\nassert my_solution.placedCoins(**test_input) == [751872,1,524744,125223,524744,125223,1,43407,1,751872]\n\ntest_input = { \"edges\": [[3,6],[0,6],[8,0],[7,4],[4,1],[2,1],[2,9],[8,5],[9,5]], \"cost\": [78,-10,-51,-50,-55,-72,-7,31,-94,4] }\nassert my_solution.placedCoins(**test_input) == [527904,17050,86955,1,1,122760,1,1,209808,86955]\n\ntest_input = { \"edges\": [[2,5],[4,7],[4,5],[5,3],[3,6],[6,0],[1,0],[8,1],[9,8]], \"cost\": [-19,93,-23,-86,54,-70,-70,9,69,13] }\nassert my_solution.placedCoins(**test_input) == [559860,83421,1,325080,1,86940,325080,1,1,1]\n\ntest_input = { \"edges\": [[2,7],[3,9],[7,5],[4,5],[4,1],[6,1],[6,0],[8,0],[0,9]], \"cost\": [45,-53,-16,-26,99,50,33,-57,-97,74] }\nassert my_solution.placedCoins(**test_input) == [547371,299079,1,1,90288,45600,299079,1,1,1]\n\ntest_input = { \"edges\": [[5,0],[9,1],[3,6],[2,4],[2,6],[6,9],[8,7],[7,5],[5,9]], \"cost\": [-14,-4,-49,52,-45,77,-17,-79,21,-33] }\nassert my_solution.placedCoins(**test_input) == [298067,1,1,1,1,298067,114660,1,1,114660]\n\ntest_input = { \"edges\": [[6,3],[7,0],[2,0],[2,4],[9,4],[1,8],[1,6],[5,6],[9,5]], \"cost\": [-58,-55,17,68,37,-32,91,-63,79,69] }\nassert my_solution.placedCoins(**test_input) == [496041,1,496041,1,496041,488852,488852,1,1,496041]\n\ntest_input = { \"edges\": [[1,8],[0,3],[2,4],[0,2],[8,5],[0,5],[7,0],[7,6],[9,6]], \"cost\": [-8,-99,36,31,94,5,-35,54,33,19] }\nassert my_solution.placedCoins(**test_input) == [325710,1,1,1,1,0,1,0,1,1]\n\ntest_input = { \"edges\": [[1,0],[1,7],[3,4],[4,5],[5,6],[7,5],[5,2],[8,2],[2,9]], \"cost\": [70,-75,-13,30,-87,20,-67,76,20,-30] }\nassert my_solution.placedCoins(**test_input) == [495900,495900,7800,1,1,174870,1,443004,1,1]\n\ntest_input = { \"edges\": [[5,1],[2,1],[0,2],[6,0],[0,3],[3,7],[9,7],[4,8],[9,4]], \"cost\": [-10,-31,-7,-77,64,-80,-53,37,1,10] }\nassert my_solution.placedCoins(**test_input) == [394240,1,0,23680,1,1,1,23680,1,640]\n\ntest_input = { \"edges\": [[2,0],[1,2],[2,8],[4,3],[4,7],[5,9],[6,9],[8,7],[7,9]], \"cost\": [-80,77,-18,-72,11,66,82,80,32,61] }\nassert my_solution.placedCoins(**test_input) == [505120,1,505120,1,1,1,1,432960,432960,330132]\n\ntest_input = { \"edges\": [[0,3],[1,0],[1,8],[5,4],[9,6],[7,4],[9,4],[8,2],[9,2]], \"cost\": [70,-14,-91,98,-12,30,-24,79,-62,11] }\nassert my_solution.placedCoins(**test_input) == [552916,445718,172536,1,0,1,1,1,445718,26070]\n\ntest_input = { \"edges\": [[5,8],[2,6],[2,0],[0,3],[7,8],[8,4],[3,4],[1,3],[1,9]], \"cost\": [55,69,29,87,27,-35,-83,71,-82,-8] }\nassert my_solution.placedCoins(**test_input) == [592122,1,1,426213,203770,1,1,1,203770,1]\n\ntest_input = { \"edges\": [[1,9],[5,4],[5,3],[6,3],[6,2],[2,8],[0,7],[0,9],[8,9]], \"cost\": [-25,28,47,-75,-78,-39,23,93,-20,61] }\nassert my_solution.placedCoins(**test_input) == [544050,1,274950,0,1,1,134550,1,274950,356850]\n\ntest_input = { \"edges\": [[5,0],[1,8],[6,4],[4,9],[7,3],[8,5],[3,5],[3,2],[9,2]], \"cost\": [-11,-91,-54,53,58,16,-60,85,20,51] }\nassert my_solution.placedCoins(**test_input) == [464100,1,187920,275400,1,464100,1,1,1,0]\n\ntest_input = { \"edges\": [[1,3],[1,4],[2,4],[6,5],[7,5],[0,5],[9,0],[8,2],[9,2]], \"cost\": [-74,26,99,58,42,-55,-1,-56,29,-35] }\nassert my_solution.placedCoins(**test_input) == [410256,1,241164,1,63336,0,1,1,1,241164]\n\ntest_input = { \"edges\": [[2,5],[5,3],[0,4],[5,9],[6,1],[7,1],[7,0],[0,9],[8,9]], \"cost\": [72,68,-18,95,87,-58,-55,20,40,2] }\nassert my_solution.placedCoins(**test_input) == [595080,1,1,1,1,99180,1,0,1,99180]\n\ntest_input = { \"edges\": [[1,6],[3,2],[9,3],[6,5],[5,9],[7,0],[4,8],[0,4],[0,9]], \"cost\": [85,19,-56,-71,41,-72,59,30,55,67] }\nassert my_solution.placedCoins(**test_input) == [434520,1,1,1,1,0,1,1,1,342504]\n\ntest_input = { \"edges\": [[2,1],[7,1],[0,3],[8,4],[0,5],[7,6],[0,6],[8,0],[9,8]], \"cost\": [13,4,84,36,29,-97,-59,-40,77,41] }\nassert my_solution.placedCoins(**test_input) == [480732,1,1,1,1,1,198240,0,91553,1]\n\ntest_input = { \"edges\": [[2,1],[4,5],[6,3],[1,3],[1,0],[7,0],[8,7],[5,8],[9,5]], \"cost\": [85,64,-67,-60,5,-14,31,-84,47,-36] }\nassert my_solution.placedCoins(**test_input) == [478380,257280,1,1,1,2520,1,142128,23688,1]\n\ntest_input = { \"edges\": [[6,1],[4,2],[7,4],[5,7],[0,8],[6,0],[3,6],[7,3],[7,9]], \"cost\": [-51,-55,82,25,-53,13,-15,98,39,29] }\nassert my_solution.placedCoins(**test_input) == [313404,1,1,233044,1,1,285670,233044,1,1]\n\ntest_input = { \"edges\": [[0,2],[5,1],[6,2],[7,3],[5,4],[5,9],[6,9],[7,9],[8,9]], \"cost\": [-96,-75,-58,26,-73,-25,-9,87,57,3] }\nassert my_solution.placedCoins(**test_input) == [626400,1,476325,1,1,0,476325,1,1,476325]\n\ntest_input = { \"edges\": [[0,4],[0,9],[5,1],[2,6],[3,7],[3,8],[1,8],[1,2],[2,9]], \"cost\": [-58,20,21,77,-96,53,-77,-66,-32,42] }\nassert my_solution.placedCoins(**test_input) == [569184,162624,391314,1,1,1,1,1,162624,391314]\n\ntest_input = { \"edges\": [[2,4],[5,2],[6,3],[3,0],[7,5],[8,5],[1,8],[1,0],[0,9]], \"cost\": [-59,-25,-25,-78,22,29,9,-12,-11,-5] }\nassert my_solution.placedCoins(**test_input) == [133458,18125,1,1,1,8700,1,1,8700,1]\n\ntest_input = { \"edges\": [[8,1],[3,2],[5,4],[6,3],[0,3],[8,5],[5,7],[7,0],[9,0]], \"cost\": [86,-87,-96,-74,51,75,-76,74,-2,-60] }\nassert my_solution.placedCoins(**test_input) == [718272,1,1,0,1,13050,1,283050,1,1]", "start_time": 1703341800} +{"task_id": "weekly-contest-376-find-missing-and-repeated-values", "url": "https://leetcode.com/problems/find-missing-and-repeated-values", "title": "find-missing-and-repeated-values", "meta": {"questionId": "3227", "questionFrontendId": "2965", "title": "Find Missing and Repeated Values", "titleSlug": "find-missing-and-repeated-values", "isPaidOnly": false, "difficulty": "Easy", "likes": 90, "dislikes": 3, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0 开始的二维整数矩阵 grid,大小为 n * n ,其中的值在 [1, n2] 范围内。除了 a 出现 两次,b 缺失 之外,每个整数都 恰好出现一次 。\n任务是找出重复的数字a 和缺失的数字 b 。\n返回一个下标从 0 开始、长度为 2 的整数数组 ans ,其中 ans[0] 等于 a ,ans[1] 等于 b 。\n\n示例 1:\n\n输入:grid = [[1,3],[2,2]]\n输出:[2,4]\n解释:数字 2 重复,数字 4 缺失,所以答案是 [2,4] 。\n\n示例 2:\n\n输入:grid = [[9,1,7],[8,9,2],[3,4,6]]\n输出:[9,5]\n解释:数字 9 重复,数字 5 缺失,所以答案是 [9,5] 。\n\n\n提示:\n\n2 <= n == grid.length == grid[i].length <= 50\n1 <= grid[i][j] <= n * n\n对于所有满足1 <= x <= n * n 的 x ,恰好存在一个 x 与矩阵中的任何成员都不相等。\n对于所有满足1 <= x <= n * n 的 x ,恰好存在一个 x 与矩阵中的两个成员相等。\n除上述的两个之外,对于所有满足1 <= x <= n * n 的 x ,都恰好存在一对 i, j 满足 0 <= i, j <= n - 1 且 grid[i][j] == x 。\n\"\"\"\nclass Solution:\n def findMissingAndRepeatedValues(self, grid: List[List[int]]) -> List[int]:\n ", "prompt_sft": "给你一个下标从 0 开始的二维整数矩阵 grid,大小为 n * n ,其中的值在 [1, n2] 范围内。除了 a 出现 两次,b 缺失 之外,每个整数都 恰好出现一次 。\n任务是找出重复的数字a 和缺失的数字 b 。\n返回一个下标从 0 开始、长度为 2 的整数数组 ans ,其中 ans[0] 等于 a ,ans[1] 等于 b 。\n\n示例 1:\n\n输入:grid = [[1,3],[2,2]]\n输出:[2,4]\n解释:数字 2 重复,数字 4 缺失,所以答案是 [2,4] 。\n\n示例 2:\n\n输入:grid = [[9,1,7],[8,9,2],[3,4,6]]\n输出:[9,5]\n解释:数字 9 重复,数字 5 缺失,所以答案是 [9,5] 。\n\n\n提示:\n\n2 <= n == grid.length == grid[i].length <= 50\n1 <= grid[i][j] <= n * n\n对于所有满足1 <= x <= n * n 的 x ,恰好存在一个 x 与矩阵中的任何成员都不相等。\n对于所有满足1 <= x <= n * n 的 x ,恰好存在一个 x 与矩阵中的两个成员相等。\n除上述的两个之外,对于所有满足1 <= x <= n * n 的 x ,都恰好存在一对 i, j 满足 0 <= i, j <= n - 1 且 grid[i][j] == x 。\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def findMissingAndRepeatedValues(self, grid: List[List[int]]) -> List[int]:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"grid\": [[1,3],[2,2]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [2,4]\n\ntest_input = { \"grid\": [[9,1,7],[8,9,2],[3,4,6]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [9,5]\n\ntest_input = { \"grid\": [[1,1],[3,2]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [1,4]\n\ntest_input = { \"grid\": [[1,1],[3,4]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [1,2]\n\ntest_input = { \"grid\": [[1,2],[1,3]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [1,4]\n\ntest_input = { \"grid\": [[1,2],[1,4]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [1,3]\n\ntest_input = { \"grid\": [[1,2],[3,3]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [3,4]\n\ntest_input = { \"grid\": [[1,2],[4,1]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [1,3]\n\ntest_input = { \"grid\": [[1,2],[4,2]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [2,3]\n\ntest_input = { \"grid\": [[1,2],[4,4]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [4,3]\n\ntest_input = { \"grid\": [[1,4],[1,3]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [1,2]\n\ntest_input = { \"grid\": [[1,4],[2,1]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [1,3]\n\ntest_input = { \"grid\": [[1,4],[3,1]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [1,2]\n\ntest_input = { \"grid\": [[1,4],[3,4]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [4,2]\n\ntest_input = { \"grid\": [[1,4],[4,2]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [4,3]\n\ntest_input = { \"grid\": [[2,1],[4,2]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [2,3]\n\ntest_input = { \"grid\": [[2,1],[4,4]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [4,3]\n\ntest_input = { \"grid\": [[2,2],[3,4]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [2,1]\n\ntest_input = { \"grid\": [[2,2],[4,1]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [2,3]\n\ntest_input = { \"grid\": [[2,3],[2,1]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [2,4]\n\ntest_input = { \"grid\": [[2,3],[4,3]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [3,1]\n\ntest_input = { \"grid\": [[2,4],[3,2]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [2,1]\n\ntest_input = { \"grid\": [[2,4],[3,4]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [4,1]\n\ntest_input = { \"grid\": [[2,4],[4,1]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [4,3]\n\ntest_input = { \"grid\": [[3,1],[3,2]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [3,4]\n\ntest_input = { \"grid\": [[3,1],[3,4]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [3,2]\n\ntest_input = { \"grid\": [[3,1],[4,4]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [4,2]\n\ntest_input = { \"grid\": [[3,3],[1,4]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [3,2]\n\ntest_input = { \"grid\": [[3,4],[2,2]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [2,1]\n\ntest_input = { \"grid\": [[3,4],[2,4]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [4,1]\n\ntest_input = { \"grid\": [[3,4],[3,1]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [3,2]\n\ntest_input = { \"grid\": [[3,4],[4,1]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [4,2]\n\ntest_input = { \"grid\": [[4,1],[1,2]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [1,3]\n\ntest_input = { \"grid\": [[4,1],[2,2]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [2,3]\n\ntest_input = { \"grid\": [[4,1],[2,4]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [4,3]\n\ntest_input = { \"grid\": [[4,1],[3,1]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [1,2]\n\ntest_input = { \"grid\": [[4,1],[3,3]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [3,2]\n\ntest_input = { \"grid\": [[4,1],[4,2]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [4,3]\n\ntest_input = { \"grid\": [[4,2],[2,3]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [2,1]\n\ntest_input = { \"grid\": [[4,2],[4,1]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [4,3]\n\ntest_input = { \"grid\": [[4,3],[1,1]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [1,2]\n\ntest_input = { \"grid\": [[4,3],[2,2]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [2,1]\n\ntest_input = { \"grid\": [[4,3],[2,4]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [4,1]\n\ntest_input = { \"grid\": [[4,3],[3,1]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [3,2]\n\ntest_input = { \"grid\": [[4,4],[2,3]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [4,1]\n\ntest_input = { \"grid\": [[1,3,4],[9,7,5],[8,2,3]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [3,6]\n\ntest_input = { \"grid\": [[1,5,2],[8,4,3],[7,8,6]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [8,9]\n\ntest_input = { \"grid\": [[1,5,8],[2,7,3],[6,1,4]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [1,9]\n\ntest_input = { \"grid\": [[1,6,1],[4,3,7],[5,2,8]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [1,9]\n\ntest_input = { \"grid\": [[1,6,4],[9,7,5],[7,8,2]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [7,3]\n\ntest_input = { \"grid\": [[1,6,7],[3,6,8],[9,5,4]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [6,2]\n\ntest_input = { \"grid\": [[1,7,4],[8,6,2],[8,3,5]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [8,9]\n\ntest_input = { \"grid\": [[1,7,8],[4,5,6],[3,9,9]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [9,2]\n\ntest_input = { \"grid\": [[1,8,4],[9,2,7],[6,3,8]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [8,5]\n\ntest_input = { \"grid\": [[1,8,5],[4,3,2],[7,9,4]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [4,6]\n\ntest_input = { \"grid\": [[1,9,3],[2,7,8],[2,4,5]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [2,6]\n\ntest_input = { \"grid\": [[1,9,7],[8,4,2],[6,3,9]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [9,5]\n\ntest_input = { \"grid\": [[2,1,3],[2,9,4],[6,8,5]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [2,7]\n\ntest_input = { \"grid\": [[2,2,4],[7,5,3],[1,6,8]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [2,9]\n\ntest_input = { \"grid\": [[2,3,9],[5,6,4],[2,8,7]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [2,1]\n\ntest_input = { \"grid\": [[2,4,6],[4,8,9],[7,3,5]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [4,1]\n\ntest_input = { \"grid\": [[2,5,5],[4,8,7],[9,3,6]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [5,1]\n\ntest_input = { \"grid\": [[2,6,4],[6,9,5],[3,7,8]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [6,1]\n\ntest_input = { \"grid\": [[2,6,9],[1,7,9],[4,8,5]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [9,3]\n\ntest_input = { \"grid\": [[2,7,1],[8,6,2],[9,3,4]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [2,5]\n\ntest_input = { \"grid\": [[2,7,5],[7,6,4],[1,3,9]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [7,8]\n\ntest_input = { \"grid\": [[2,7,9],[6,8,1],[4,1,5]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [1,3]\n\ntest_input = { \"grid\": [[2,9,7],[8,5,1],[6,7,4]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [7,3]\n\ntest_input = { \"grid\": [[3,4,5],[8,2,4],[6,1,7]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [4,9]\n\ntest_input = { \"grid\": [[3,5,7],[8,6,9],[1,5,2]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [5,4]\n\ntest_input = { \"grid\": [[3,6,1],[5,9,2],[1,7,8]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [1,4]\n\ntest_input = { \"grid\": [[3,9,4],[3,6,1],[5,7,2]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [3,8]\n\ntest_input = { \"grid\": [[4,2,6],[3,5,8],[3,1,9]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [3,7]\n\ntest_input = { \"grid\": [[4,3,2],[6,9,9],[8,7,5]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [9,1]\n\ntest_input = { \"grid\": [[4,6,5],[3,5,7],[2,8,9]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [5,1]\n\ntest_input = { \"grid\": [[4,8,7],[4,6,9],[3,2,1]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [4,5]\n\ntest_input = { \"grid\": [[4,9,6],[2,5,8],[3,7,7]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [7,1]\n\ntest_input = { \"grid\": [[5,3,6],[1,4,2],[9,8,2]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [2,7]\n\ntest_input = { \"grid\": [[5,6,9],[3,7,8],[2,2,4]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [2,1]\n\ntest_input = { \"grid\": [[5,7,8],[1,3,2],[7,6,9]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [7,4]\n\ntest_input = { \"grid\": [[6,1,3],[2,4,2],[8,9,7]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [2,5]\n\ntest_input = { \"grid\": [[6,4,2],[3,7,8],[5,6,9]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [6,1]\n\ntest_input = { \"grid\": [[6,4,5],[7,9,3],[1,2,9]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [9,8]\n\ntest_input = { \"grid\": [[6,4,8],[8,1,2],[9,3,7]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [8,5]\n\ntest_input = { \"grid\": [[6,9,3],[8,9,7],[5,4,2]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [9,1]\n\ntest_input = { \"grid\": [[7,2,1],[6,5,3],[2,9,4]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [2,8]\n\ntest_input = { \"grid\": [[7,2,4],[5,8,7],[9,3,1]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [7,6]\n\ntest_input = { \"grid\": [[7,3,1],[8,9,2],[4,5,2]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [2,6]\n\ntest_input = { \"grid\": [[7,4,2],[9,1,9],[8,3,5]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [9,6]\n\ntest_input = { \"grid\": [[7,4,8],[1,1,3],[2,6,9]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [1,5]\n\ntest_input = { \"grid\": [[7,5,3],[4,6,3],[9,2,8]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [3,1]\n\ntest_input = { \"grid\": [[7,5,7],[3,1,6],[8,9,4]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [7,2]\n\ntest_input = { \"grid\": [[8,2,6],[1,8,9],[4,5,3]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [8,7]\n\ntest_input = { \"grid\": [[8,2,7],[3,5,1],[9,6,3]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [3,4]\n\ntest_input = { \"grid\": [[8,6,3],[1,9,5],[5,4,7]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [5,2]\n\ntest_input = { \"grid\": [[8,6,5],[3,9,1],[8,7,4]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [8,2]\n\ntest_input = { \"grid\": [[8,9,6],[6,1,3],[2,7,5]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [6,4]\n\ntest_input = { \"grid\": [[8,9,6],[7,4,2],[7,1,5]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [7,3]\n\ntest_input = { \"grid\": [[9,2,3],[7,6,4],[5,8,8]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [8,1]\n\ntest_input = { \"grid\": [[9,2,7],[3,8,7],[1,5,4]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [7,6]", "start_time": 1702780200} +{"task_id": "weekly-contest-376-divide-array-into-arrays-with-max-difference", "url": "https://leetcode.com/problems/divide-array-into-arrays-with-max-difference", "title": "divide-array-into-arrays-with-max-difference", "meta": {"questionId": "3241", "questionFrontendId": "2966", "title": "Divide Array Into Arrays With Max Difference", "titleSlug": "divide-array-into-arrays-with-max-difference", "isPaidOnly": false, "difficulty": "Medium", "likes": 95, "dislikes": 20, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个长度为 n 的整数数组 nums,以及一个正整数 k 。\n将这个数组划分为一个或多个长度为 3 的子数组,并满足以下条件:\n\nnums 中的 每个 元素都必须 恰好 存在于某个子数组中。\n子数组中 任意 两个元素的差必须小于或等于 k 。\n\n返回一个 二维数组 ,包含所有的子数组。如果不可能满足条件,就返回一个空数组。如果有多个答案,返回 任意一个 即可。\n\n示例 1:\n\n输入:nums = [1,3,4,8,7,9,3,5,1], k = 2\n输出:[[1,1,3],[3,4,5],[7,8,9]]\n解释:可以将数组划分为以下子数组:[1,1,3],[3,4,5] 和 [7,8,9] 。\n每个子数组中任意两个元素的差都小于或等于 2 。\n注意,元素的顺序并不重要。\n\n示例 2:\n\n输入:nums = [1,3,3,2,7,3], k = 3\n输出:[]\n解释:无法划分数组满足所有条件。\n\n\n提示:\n\nn == nums.length\n1 <= n <= 105\nn 是 3 的倍数\n1 <= nums[i] <= 105\n1 <= k <= 105\n\"\"\"\nclass Solution:\n def divideArray(self, nums: List[int], k: int) -> List[List[int]]:\n ", "prompt_sft": "给你一个长度为 n 的整数数组 nums,以及一个正整数 k 。\n将这个数组划分为一个或多个长度为 3 的子数组,并满足以下条件:\n\nnums 中的 每个 元素都必须 恰好 存在于某个子数组中。\n子数组中 任意 两个元素的差必须小于或等于 k 。\n\n返回一个 二维数组 ,包含所有的子数组。如果不可能满足条件,就返回一个空数组。如果有多个答案,返回 任意一个 即可。\n\n示例 1:\n\n输入:nums = [1,3,4,8,7,9,3,5,1], k = 2\n输出:[[1,1,3],[3,4,5],[7,8,9]]\n解释:可以将数组划分为以下子数组:[1,1,3],[3,4,5] 和 [7,8,9] 。\n每个子数组中任意两个元素的差都小于或等于 2 。\n注意,元素的顺序并不重要。\n\n示例 2:\n\n输入:nums = [1,3,3,2,7,3], k = 3\n输出:[]\n解释:无法划分数组满足所有条件。\n\n\n提示:\n\nn == nums.length\n1 <= n <= 105\nn 是 3 的倍数\n1 <= nums[i] <= 105\n1 <= k <= 105\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def divideArray(self, nums: List[int], k: int) -> List[List[int]]:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,3,4,8,7,9,3,5,1], \"k\": 2 }\nassert my_solution.divideArray(**test_input) == [[1,1,3],[3,4,5],[7,8,9]]\n\ntest_input = { \"nums\": [1,3,3,2,7,3], \"k\": 3 }\nassert my_solution.divideArray(**test_input) == []\n\ntest_input = { \"nums\": [4,2,9,8,2,12,7,12,10,5,8,5,5,7,9,2,5,11], \"k\": 14 }\nassert my_solution.divideArray(**test_input) == [[2,2,2],[4,5,5],[5,5,7],[7,8,8],[9,9,10],[11,12,12]]\n\ntest_input = { \"nums\": [33,26,4,18,16,24,24,15,8,18,34,20,24,16,3], \"k\": 16 }\nassert my_solution.divideArray(**test_input) == [[3,4,8],[15,16,16],[18,18,20],[24,24,24],[26,33,34]]\n\ntest_input = { \"nums\": [6,1,8,8,5,8,5,9,8,9,5,8,3,4,6], \"k\": 7 }\nassert my_solution.divideArray(**test_input) == [[1,3,4],[5,5,5],[6,6,8],[8,8,8],[8,9,9]]\n\ntest_input = { \"nums\": [20,21,34,3,19,2,23,32,20,17,14,13,19,20,6], \"k\": 15 }\nassert my_solution.divideArray(**test_input) == [[2,3,6],[13,14,17],[19,19,20],[20,20,21],[23,32,34]]\n\ntest_input = { \"nums\": [6,10,5,12,7,11,6,6,12,12,11,7], \"k\": 2 }\nassert my_solution.divideArray(**test_input) == [[5,6,6],[6,7,7],[10,11,11],[12,12,12]]\n\ntest_input = { \"nums\": [12,15,26,7,10,13,15,5,27,16,14,15], \"k\": 18 }\nassert my_solution.divideArray(**test_input) == [[5,7,10],[12,13,14],[15,15,15],[16,26,27]]\n\ntest_input = { \"nums\": [12,7,13,10,7,19,11,23,3,3,7,9], \"k\": 16 }\nassert my_solution.divideArray(**test_input) == [[3,3,7],[7,7,9],[10,11,12],[13,19,23]]\n\ntest_input = { \"nums\": [19,3,23,4,8,1,1,3,26], \"k\": 7 }\nassert my_solution.divideArray(**test_input) == [[1,1,3],[3,4,8],[19,23,26]]\n\ntest_input = { \"nums\": [11,13,24,11,9,23,16,19,13], \"k\": 8 }\nassert my_solution.divideArray(**test_input) == [[9,11,11],[13,13,16],[19,23,24]]\n\ntest_input = { \"nums\": [6,12,21,12,6,12,25,20,15,22,11,19,8,4,18,26,17,18,12,5,8], \"k\": 11 }\nassert my_solution.divideArray(**test_input) == [[4,5,6],[6,8,8],[11,12,12],[12,12,15],[17,18,18],[19,20,21],[22,25,26]]\n\ntest_input = { \"nums\": [15,17,14,3,25,15,11,25,15,16,12,18], \"k\": 10 }\nassert my_solution.divideArray(**test_input) == [[3,11,12],[14,15,15],[15,16,17],[18,25,25]]\n\ntest_input = { \"nums\": [16,20,16,19,20,13,14,20,14], \"k\": 10 }\nassert my_solution.divideArray(**test_input) == [[13,14,14],[16,16,19],[20,20,20]]\n\ntest_input = { \"nums\": [2,13,15,14,18,15,3,13,2], \"k\": 1 }\nassert my_solution.divideArray(**test_input) == []\n\ntest_input = { \"nums\": [1,14,20,7,17,2,14,1,8], \"k\": 11 }\nassert my_solution.divideArray(**test_input) == [[1,1,2],[7,8,14],[14,17,20]]\n\ntest_input = { \"nums\": [8,12,19,8,9,19,9,19,9,8,6,9,6,6,12], \"k\": 3 }\nassert my_solution.divideArray(**test_input) == [[6,6,6],[8,8,8],[9,9,9],[9,12,12],[19,19,19]]\n\ntest_input = { \"nums\": [18,16,17,19,12,25,11,27,11,32,32,17], \"k\": 20 }\nassert my_solution.divideArray(**test_input) == [[11,11,12],[16,17,17],[18,19,25],[27,32,32]]\n\ntest_input = { \"nums\": [21,11,24,20,17,13,7,20,20,16,24,20,12,17,16,15,7,7,18,15,20], \"k\": 6 }\nassert my_solution.divideArray(**test_input) == [[7,7,7],[11,12,13],[15,15,16],[16,17,17],[18,20,20],[20,20,20],[21,24,24]]\n\ntest_input = { \"nums\": [6,7,7,6,7,6], \"k\": 13 }\nassert my_solution.divideArray(**test_input) == [[6,6,6],[7,7,7]]\n\ntest_input = { \"nums\": [11,12,12,5,6,5], \"k\": 9 }\nassert my_solution.divideArray(**test_input) == [[5,5,6],[11,12,12]]\n\ntest_input = { \"nums\": [5,5,12,5,5,22,2,2,5,2,5,5,16,2,22,2,12,16,15,13,19], \"k\": 3 }\nassert my_solution.divideArray(**test_input) == [[2,2,2],[2,2,5],[5,5,5],[5,5,5],[12,12,13],[15,16,16],[19,22,22]]\n\ntest_input = { \"nums\": [11,28,12,5,19,15,16,9,21,13,12,9,19,19,18], \"k\": 9 }\nassert my_solution.divideArray(**test_input) == [[5,9,9],[11,12,12],[13,15,16],[18,19,19],[19,21,28]]\n\ntest_input = { \"nums\": [10,14,17], \"k\": 15 }\nassert my_solution.divideArray(**test_input) == [[10,14,17]]\n\ntest_input = { \"nums\": [16,15,9,20,17,19,11,18,16], \"k\": 9 }\nassert my_solution.divideArray(**test_input) == [[9,11,15],[16,16,17],[18,19,20]]\n\ntest_input = { \"nums\": [16,28,16,7,18,13,5,27,27,16,20,22,13,6,17], \"k\": 11 }\nassert my_solution.divideArray(**test_input) == [[5,6,7],[13,13,16],[16,16,17],[18,20,22],[27,27,28]]\n\ntest_input = { \"nums\": [14,7,13,2,3,7,17,13,13,2,14,7], \"k\": 3 }\nassert my_solution.divideArray(**test_input) == [[2,2,3],[7,7,7],[13,13,13],[14,14,17]]\n\ntest_input = { \"nums\": [20,8,6,5,10,5,10,2,20,6,12,13,13,20,4], \"k\": 6 }\nassert my_solution.divideArray(**test_input) == [[2,4,5],[5,6,6],[8,10,10],[12,13,13],[20,20,20]]\n\ntest_input = { \"nums\": [12,14,16,9,20,18,16,4,24,14,16,30,1,17,30,16,30,6], \"k\": 13 }\nassert my_solution.divideArray(**test_input) == [[1,4,6],[9,12,14],[14,16,16],[16,16,17],[18,20,24],[30,30,30]]\n\ntest_input = { \"nums\": [13,6,19,21,16,11,1,14,7], \"k\": 20 }\nassert my_solution.divideArray(**test_input) == [[1,6,7],[11,13,14],[16,19,21]]\n\ntest_input = { \"nums\": [13,2,12,22,18,15,3,20,2,18,3,14,2,10,14,9,14,3,14,17,5], \"k\": 9 }\nassert my_solution.divideArray(**test_input) == [[2,2,2],[3,3,3],[5,9,10],[12,13,14],[14,14,14],[15,17,18],[18,20,22]]\n\ntest_input = { \"nums\": [12,13,12,14,14,6,5,7,23,21,21,16,15,20,22,14,20,7], \"k\": 10 }\nassert my_solution.divideArray(**test_input) == [[5,6,7],[7,12,12],[13,14,14],[14,15,16],[20,20,21],[21,22,23]]\n\ntest_input = { \"nums\": [15,14,3,19,17,18,19,23,2,16,19,3], \"k\": 5 }\nassert my_solution.divideArray(**test_input) == [[2,3,3],[14,15,16],[17,18,19],[19,19,23]]\n\ntest_input = { \"nums\": [12,8,18,6,12,6,8,33,20,6,17,17,27,8,12], \"k\": 16 }\nassert my_solution.divideArray(**test_input) == [[6,6,6],[8,8,8],[12,12,12],[17,17,18],[20,27,33]]\n\ntest_input = { \"nums\": [1,1,23,17,18,1], \"k\": 12 }\nassert my_solution.divideArray(**test_input) == [[1,1,1],[17,18,23]]\n\ntest_input = { \"nums\": [13,13,3,7,6,13,6,4,3], \"k\": 1 }\nassert my_solution.divideArray(**test_input) == [[3,3,4],[6,6,7],[13,13,13]]\n\ntest_input = { \"nums\": [19,10,9,20,29,28,29,9,18,27,23,4,16,8,11,19,10,12,10,10,21], \"k\": 20 }\nassert my_solution.divideArray(**test_input) == [[4,8,9],[9,10,10],[10,10,11],[12,16,18],[19,19,20],[21,23,27],[28,29,29]]\n\ntest_input = { \"nums\": [13,12,12,11,22,10], \"k\": 15 }\nassert my_solution.divideArray(**test_input) == [[10,11,12],[12,13,22]]\n\ntest_input = { \"nums\": [15,16,12,34,16,16,24,21,3,24,29,10], \"k\": 20 }\nassert my_solution.divideArray(**test_input) == [[3,10,12],[15,16,16],[16,21,24],[24,29,34]]\n\ntest_input = { \"nums\": [17,16,17,11,13,6], \"k\": 19 }\nassert my_solution.divideArray(**test_input) == [[6,11,13],[16,17,17]]\n\ntest_input = { \"nums\": [11,16,16,6,8,20,21,3,20,11,16,6,6,11,6], \"k\": 3 }\nassert my_solution.divideArray(**test_input) == [[3,6,6],[6,6,8],[11,11,11],[16,16,16],[20,20,21]]\n\ntest_input = { \"nums\": [2,16,8,7,15,16], \"k\": 9 }\nassert my_solution.divideArray(**test_input) == [[2,7,8],[15,16,16]]\n\ntest_input = { \"nums\": [15,17,22], \"k\": 14 }\nassert my_solution.divideArray(**test_input) == [[15,17,22]]\n\ntest_input = { \"nums\": [8,4,9,18,18,5,10,11,19,18,19,23,4,15,25,20,20,6], \"k\": 7 }\nassert my_solution.divideArray(**test_input) == [[4,4,5],[6,8,9],[10,11,15],[18,18,18],[19,19,20],[20,23,25]]\n\ntest_input = { \"nums\": [12,20,16,12,15,16,15,20,14,16,19,13], \"k\": 1 }\nassert my_solution.divideArray(**test_input) == [[12,12,13],[14,15,15],[16,16,16],[19,20,20]]\n\ntest_input = { \"nums\": [20,19,8,21,13,18,21,12,12,18,9,9], \"k\": 1 }\nassert my_solution.divideArray(**test_input) == [[8,9,9],[12,12,13],[18,18,19],[20,21,21]]\n\ntest_input = { \"nums\": [6,14,19,17,13,4,17,10,17], \"k\": 19 }\nassert my_solution.divideArray(**test_input) == [[4,6,10],[13,14,17],[17,17,19]]\n\ntest_input = { \"nums\": [8,8,12], \"k\": 4 }\nassert my_solution.divideArray(**test_input) == [[8,8,12]]\n\ntest_input = { \"nums\": [3,16,17,18,10,8,20,16,20,10,10,21], \"k\": 16 }\nassert my_solution.divideArray(**test_input) == [[3,8,10],[10,10,16],[16,17,18],[20,20,21]]\n\ntest_input = { \"nums\": [19,14,17,20,16,16,7,10,18,8,16,15,15,13,12,14,17,11], \"k\": 8 }\nassert my_solution.divideArray(**test_input) == [[7,8,10],[11,12,13],[14,14,15],[15,16,16],[16,17,17],[18,19,20]]\n\ntest_input = { \"nums\": [18,7,11,13,13,9,22,20,21,13,7,18,8,8,16], \"k\": 4 }\nassert my_solution.divideArray(**test_input) == [[7,7,8],[8,9,11],[13,13,13],[16,18,18],[20,21,22]]\n\ntest_input = { \"nums\": [10,15,9,15,15,10], \"k\": 1 }\nassert my_solution.divideArray(**test_input) == [[9,10,10],[15,15,15]]\n\ntest_input = { \"nums\": [16,17,16], \"k\": 16 }\nassert my_solution.divideArray(**test_input) == [[16,16,17]]\n\ntest_input = { \"nums\": [15,1,15,14,18,17,1,18,12,16,6,6,7,1,12], \"k\": 4 }\nassert my_solution.divideArray(**test_input) == [[1,1,1],[6,6,7],[12,12,14],[15,15,16],[17,18,18]]\n\ntest_input = { \"nums\": [6,11,6,18,11,13,13,8,11,4,4,11,12,17,11], \"k\": 12 }\nassert my_solution.divideArray(**test_input) == [[4,4,6],[6,8,11],[11,11,11],[11,12,13],[13,17,18]]\n\ntest_input = { \"nums\": [5,13,4,14,11,18,9,10,20,5,17,11,5,8,20,5,14,4,18,17,17], \"k\": 8 }\nassert my_solution.divideArray(**test_input) == [[4,4,5],[5,5,5],[8,9,10],[11,11,13],[14,14,17],[17,17,18],[18,20,20]]\n\ntest_input = { \"nums\": [13,6,20,13,12,8,7,12,22,16,13,7,12,17,5], \"k\": 6 }\nassert my_solution.divideArray(**test_input) == [[5,6,7],[7,8,12],[12,12,13],[13,13,16],[17,20,22]]\n\ntest_input = { \"nums\": [23,2,15,20,18,14,20,7,2,22,4,14,7,9,15,14,2,7], \"k\": 8 }\nassert my_solution.divideArray(**test_input) == [[2,2,2],[4,7,7],[7,9,14],[14,14,15],[15,18,20],[20,22,23]]\n\ntest_input = { \"nums\": [19,9,2,4,17,2,27,18,17], \"k\": 18 }\nassert my_solution.divideArray(**test_input) == [[2,2,4],[9,17,17],[18,19,27]]\n\ntest_input = { \"nums\": [5,20,29,4,12,14,31,6,11,2,15,17,15,19,4], \"k\": 20 }\nassert my_solution.divideArray(**test_input) == [[2,4,4],[5,6,11],[12,14,15],[15,17,19],[20,29,31]]\n\ntest_input = { \"nums\": [15,20,5,24,18,16,25,21,28,12,19,28,25,20,14,18,24,28], \"k\": 17 }\nassert my_solution.divideArray(**test_input) == [[5,12,14],[15,16,18],[18,19,20],[20,21,24],[24,25,25],[28,28,28]]\n\ntest_input = { \"nums\": [9,6,23,17,7,17], \"k\": 20 }\nassert my_solution.divideArray(**test_input) == [[6,7,9],[17,17,23]]\n\ntest_input = { \"nums\": [24,23,19], \"k\": 6 }\nassert my_solution.divideArray(**test_input) == [[19,23,24]]\n\ntest_input = { \"nums\": [6,19,22,7,17,7,15,17,7,18,4,14,9,10,16], \"k\": 9 }\nassert my_solution.divideArray(**test_input) == [[4,6,7],[7,7,9],[10,14,15],[16,17,17],[18,19,22]]\n\ntest_input = { \"nums\": [4,3,15,1,15,15], \"k\": 4 }\nassert my_solution.divideArray(**test_input) == [[1,3,4],[15,15,15]]\n\ntest_input = { \"nums\": [10,22,18,15,7,21,6,7,11,9,7,6,7,10,18], \"k\": 8 }\nassert my_solution.divideArray(**test_input) == [[6,6,7],[7,7,7],[9,10,10],[11,15,18],[18,21,22]]\n\ntest_input = { \"nums\": [16,17,2,17,9,7,22,17,12,4,14,17,4,19,12,18,19,8,17,5,6], \"k\": 7 }\nassert my_solution.divideArray(**test_input) == [[2,4,4],[5,6,7],[8,9,12],[12,14,16],[17,17,17],[17,17,18],[19,19,22]]\n\ntest_input = { \"nums\": [20,18,18,22,7,9,9,10,16,4,18,18,11,9,18,11,11,21], \"k\": 7 }\nassert my_solution.divideArray(**test_input) == [[4,7,9],[9,9,10],[11,11,11],[16,18,18],[18,18,18],[20,21,22]]\n\ntest_input = { \"nums\": [5,11,15,9,17,6,16,14,4,9,5,13,10,12,13,15,13,12,16,12,13], \"k\": 5 }\nassert my_solution.divideArray(**test_input) == [[4,5,5],[6,9,9],[10,11,12],[12,12,13],[13,13,13],[14,15,15],[16,16,17]]\n\ntest_input = { \"nums\": [4,16,17], \"k\": 20 }\nassert my_solution.divideArray(**test_input) == [[4,16,17]]\n\ntest_input = { \"nums\": [10,9,22,13,17,11,6,9,11], \"k\": 10 }\nassert my_solution.divideArray(**test_input) == [[6,9,9],[10,11,11],[13,17,22]]\n\ntest_input = { \"nums\": [3,11,19,8,22,23,15,18,37,7,25,20,12,19,7], \"k\": 18 }\nassert my_solution.divideArray(**test_input) == [[3,7,7],[8,11,12],[15,18,19],[19,20,22],[23,25,37]]\n\ntest_input = { \"nums\": [4,6,6,3,11,11], \"k\": 16 }\nassert my_solution.divideArray(**test_input) == [[3,4,6],[6,11,11]]\n\ntest_input = { \"nums\": [10,17,10,15,16,8], \"k\": 7 }\nassert my_solution.divideArray(**test_input) == [[8,10,10],[15,16,17]]\n\ntest_input = { \"nums\": [4,20,4,19,8,7,4,20,7], \"k\": 3 }\nassert my_solution.divideArray(**test_input) == [[4,4,4],[7,7,8],[19,20,20]]\n\ntest_input = { \"nums\": [4,4,4], \"k\": 17 }\nassert my_solution.divideArray(**test_input) == [[4,4,4]]\n\ntest_input = { \"nums\": [18,6,15,20,5,27,23,15,26,11,11,4,17,23,11], \"k\": 15 }\nassert my_solution.divideArray(**test_input) == [[4,5,6],[11,11,11],[15,15,17],[18,20,23],[23,26,27]]\n\ntest_input = { \"nums\": [8,9,5], \"k\": 15 }\nassert my_solution.divideArray(**test_input) == [[5,8,9]]\n\ntest_input = { \"nums\": [20,15,8,11,11,10,19,7,20], \"k\": 7 }\nassert my_solution.divideArray(**test_input) == [[7,8,10],[11,11,15],[19,20,20]]\n\ntest_input = { \"nums\": [12,11,18,13,13,21], \"k\": 11 }\nassert my_solution.divideArray(**test_input) == [[11,12,13],[13,18,21]]\n\ntest_input = { \"nums\": [19,29,11,18,19,17,29,19,7], \"k\": 14 }\nassert my_solution.divideArray(**test_input) == [[7,11,17],[18,19,19],[19,29,29]]\n\ntest_input = { \"nums\": [14,1,25,1,14,19,2,2,4,16,17,11,26,29,12], \"k\": 17 }\nassert my_solution.divideArray(**test_input) == [[1,1,2],[2,4,11],[12,14,14],[16,17,19],[25,26,29]]\n\ntest_input = { \"nums\": [14,25,16,11,7,13,12,16,24,19,5,17], \"k\": 13 }\nassert my_solution.divideArray(**test_input) == [[5,7,11],[12,13,14],[16,16,17],[19,24,25]]\n\ntest_input = { \"nums\": [11,26,19,10,16,10,11,18,9], \"k\": 11 }\nassert my_solution.divideArray(**test_input) == [[9,10,10],[11,11,16],[18,19,26]]\n\ntest_input = { \"nums\": [16,8,15], \"k\": 16 }\nassert my_solution.divideArray(**test_input) == [[8,15,16]]\n\ntest_input = { \"nums\": [12,8,18,8,18,13,12,18,18,13,12,23,21,8,13], \"k\": 5 }\nassert my_solution.divideArray(**test_input) == [[8,8,8],[12,12,12],[13,13,13],[18,18,18],[18,21,23]]\n\ntest_input = { \"nums\": [12,16,9,8,22,16], \"k\": 16 }\nassert my_solution.divideArray(**test_input) == [[8,9,12],[16,16,22]]\n\ntest_input = { \"nums\": [15,16,18,8,12,7,5,17,23,17,18,13,5,4,13,18,7,20], \"k\": 6 }\nassert my_solution.divideArray(**test_input) == [[4,5,5],[7,7,8],[12,13,13],[15,16,17],[17,18,18],[18,20,23]]\n\ntest_input = { \"nums\": [12,11,14,13,9,16,31,19,21,22,7,1,22,23,9,2,21,21], \"k\": 15 }\nassert my_solution.divideArray(**test_input) == [[1,2,7],[9,9,11],[12,13,14],[16,19,21],[21,21,22],[22,23,31]]\n\ntest_input = { \"nums\": [7,15,18,20,6,21,18,17,11,1,14,15,18,8,17,13,11,8,5,12,11], \"k\": 10 }\nassert my_solution.divideArray(**test_input) == [[1,5,6],[7,8,8],[11,11,11],[12,13,14],[15,15,17],[17,18,18],[18,20,21]]\n\ntest_input = { \"nums\": [13,16,17,16,6,12], \"k\": 11 }\nassert my_solution.divideArray(**test_input) == [[6,12,13],[16,16,17]]\n\ntest_input = { \"nums\": [17,17,17,16,17,17], \"k\": 1 }\nassert my_solution.divideArray(**test_input) == [[16,17,17],[17,17,17]]\n\ntest_input = { \"nums\": [6,14,6,15,14,6], \"k\": 17 }\nassert my_solution.divideArray(**test_input) == [[6,6,6],[14,14,15]]\n\ntest_input = { \"nums\": [23,19,21,10,10,13,15,19,19,3,15,3], \"k\": 12 }\nassert my_solution.divideArray(**test_input) == [[3,3,10],[10,13,15],[15,19,19],[19,21,23]]\n\ntest_input = { \"nums\": [11,4,3,11,3,27,19,10,6,12,11,24,27,1,31], \"k\": 17 }\nassert my_solution.divideArray(**test_input) == [[1,3,3],[4,6,10],[11,11,11],[12,19,24],[27,27,31]]\n\ntest_input = { \"nums\": [8,18,18,20,20,19,20,31,7], \"k\": 17 }\nassert my_solution.divideArray(**test_input) == [[7,8,18],[18,19,20],[20,20,31]]\n\ntest_input = { \"nums\": [4,22,8,12,1,4,4,17,22,4,10,1], \"k\": 12 }\nassert my_solution.divideArray(**test_input) == [[1,1,4],[4,4,4],[8,10,12],[17,22,22]]\n\ntest_input = { \"nums\": [16,15,16,6,9,22,14,16,10,26,18,16,11,18,7], \"k\": 10 }\nassert my_solution.divideArray(**test_input) == [[6,7,9],[10,11,14],[15,16,16],[16,16,18],[18,22,26]]\n\ntest_input = { \"nums\": [5,16,12,26,16,18,1,6,23,2,1,21,8,11,9], \"k\": 14 }\nassert my_solution.divideArray(**test_input) == [[1,1,2],[5,6,8],[9,11,12],[16,16,18],[21,23,26]]\n\ntest_input = { \"nums\": [6,3,24,13,19,24,13,12,15,3,6,3], \"k\": 17 }\nassert my_solution.divideArray(**test_input) == [[3,3,3],[6,6,12],[13,13,15],[19,24,24]]", "start_time": 1702780200} +{"task_id": "weekly-contest-376-minimum-cost-to-make-array-equalindromic", "url": "https://leetcode.com/problems/minimum-cost-to-make-array-equalindromic", "title": "minimum-cost-to-make-array-equalindromic", "meta": {"questionId": "3229", "questionFrontendId": "2967", "title": "Minimum Cost to Make Array Equalindromic", "titleSlug": "minimum-cost-to-make-array-equalindromic", "isPaidOnly": false, "difficulty": "Medium", "likes": 164, "dislikes": 70, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个长度为 n下标从 0开始的整数数组nums。\n你可以对 nums执行特殊操作 任意次(也可以 0次)。每一次特殊操作中,你需要 按顺序执行以下步骤:\n\n从范围[0, n - 1]里选择一个下标 i和一个 正整数x。\n将|nums[i] - x|添加到总代价里。\n将 nums[i]变为x。\n\n如果一个正整数正着读和反着读都相同,那么我们称这个数是回文数。比方说,121,2552 和65756都是回文数,但是24,46,235都不是回文数。\n如果一个数组中的所有元素都等于一个整数y,且y是一个小于109的回文数,那么我们称这个数组是一个 等数数组。\n请你返回一个整数,表示执行任意次特殊操作后使 nums成为 等数数组的 最小总代价。\n\n示例 1:\n\n输入:nums = [1,2,3,4,5]\n输出:6\n解释:我们可以将数组中所有元素变为回文数 3 得到等数数组,数组变成 [3,3,3,3,3] 需要执行 4 次特殊操作,代价为 |1 - 3| + |2 - 3| + |4 - 3| + |5 - 3| = 6 。\n将所有元素变为其他回文数的总代价都大于 6 。\n\n示例 2:\n\n输入:nums = [10,12,13,14,15]\n输出:11\n解释:我们可以将数组中所有元素变为回文数 11 得到等数数组,数组变成 [11,11,11,11,11] 需要执行 5 次特殊操作,代价为 |10 - 11| + |12 - 11| + |13 - 11| + |14 - 11| + |15 - 11| = 11 。\n将所有元素变为其他回文数的总代价都大于 11 。\n\n示例 3 :\n\n输入:nums = [22,33,22,33,22]\n输出:22\n解释:我们可以将数组中所有元素变为回文数 22 得到等数数组,数组变为 [22,22,22,22,22] 需要执行 2 次特殊操作,代价为 |33 - 22| + |33 - 22| = 22 。\n将所有元素变为其他回文数的总代价都大于 22 。\n\n\n提示:\n\n1 <= n <= 105\n1 <= nums[i] <= 109\n\"\"\"\nclass Solution:\n def minimumCost(self, nums: List[int]) -> int:\n ", "prompt_sft": "给你一个长度为 n下标从 0开始的整数数组nums。\n你可以对 nums执行特殊操作 任意次(也可以 0次)。每一次特殊操作中,你需要 按顺序执行以下步骤:\n\n从范围[0, n - 1]里选择一个下标 i和一个 正整数x。\n将|nums[i] - x|添加到总代价里。\n将 nums[i]变为x。\n\n如果一个正整数正着读和反着读都相同,那么我们称这个数是回文数。比方说,121,2552 和65756都是回文数,但是24,46,235都不是回文数。\n如果一个数组中的所有元素都等于一个整数y,且y是一个小于109的回文数,那么我们称这个数组是一个 等数数组。\n请你返回一个整数,表示执行任意次特殊操作后使 nums成为 等数数组的 最小总代价。\n\n示例 1:\n\n输入:nums = [1,2,3,4,5]\n输出:6\n解释:我们可以将数组中所有元素变为回文数 3 得到等数数组,数组变成 [3,3,3,3,3] 需要执行 4 次特殊操作,代价为 |1 - 3| + |2 - 3| + |4 - 3| + |5 - 3| = 6 。\n将所有元素变为其他回文数的总代价都大于 6 。\n\n示例 2:\n\n输入:nums = [10,12,13,14,15]\n输出:11\n解释:我们可以将数组中所有元素变为回文数 11 得到等数数组,数组变成 [11,11,11,11,11] 需要执行 5 次特殊操作,代价为 |10 - 11| + |12 - 11| + |13 - 11| + |14 - 11| + |15 - 11| = 11 。\n将所有元素变为其他回文数的总代价都大于 11 。\n\n示例 3 :\n\n输入:nums = [22,33,22,33,22]\n输出:22\n解释:我们可以将数组中所有元素变为回文数 22 得到等数数组,数组变为 [22,22,22,22,22] 需要执行 2 次特殊操作,代价为 |33 - 22| + |33 - 22| = 22 。\n将所有元素变为其他回文数的总代价都大于 22 。\n\n\n提示:\n\n1 <= n <= 105\n1 <= nums[i] <= 109\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def minimumCost(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,2,3,4,5] }\nassert my_solution.minimumCost(**test_input) == 6\n\ntest_input = { \"nums\": [10,12,13,14,15] }\nassert my_solution.minimumCost(**test_input) == 11\n\ntest_input = { \"nums\": [22,33,22,33,22] }\nassert my_solution.minimumCost(**test_input) == 22\n\ntest_input = { \"nums\": [1] }\nassert my_solution.minimumCost(**test_input) == 0\n\ntest_input = { \"nums\": [2] }\nassert my_solution.minimumCost(**test_input) == 0\n\ntest_input = { \"nums\": [3] }\nassert my_solution.minimumCost(**test_input) == 0\n\ntest_input = { \"nums\": [4] }\nassert my_solution.minimumCost(**test_input) == 0\n\ntest_input = { \"nums\": [5] }\nassert my_solution.minimumCost(**test_input) == 0\n\ntest_input = { \"nums\": [2,1] }\nassert my_solution.minimumCost(**test_input) == 1\n\ntest_input = { \"nums\": [3,1] }\nassert my_solution.minimumCost(**test_input) == 2\n\ntest_input = { \"nums\": [3,2] }\nassert my_solution.minimumCost(**test_input) == 1\n\ntest_input = { \"nums\": [4,1] }\nassert my_solution.minimumCost(**test_input) == 3\n\ntest_input = { \"nums\": [4,2] }\nassert my_solution.minimumCost(**test_input) == 2\n\ntest_input = { \"nums\": [4,3] }\nassert my_solution.minimumCost(**test_input) == 1\n\ntest_input = { \"nums\": [5,1] }\nassert my_solution.minimumCost(**test_input) == 4\n\ntest_input = { \"nums\": [5,2] }\nassert my_solution.minimumCost(**test_input) == 3\n\ntest_input = { \"nums\": [5,3] }\nassert my_solution.minimumCost(**test_input) == 2\n\ntest_input = { \"nums\": [5,4] }\nassert my_solution.minimumCost(**test_input) == 1\n\ntest_input = { \"nums\": [3,2,1] }\nassert my_solution.minimumCost(**test_input) == 2\n\ntest_input = { \"nums\": [4,2,1] }\nassert my_solution.minimumCost(**test_input) == 3\n\ntest_input = { \"nums\": [4,3,1] }\nassert my_solution.minimumCost(**test_input) == 3\n\ntest_input = { \"nums\": [4,3,2] }\nassert my_solution.minimumCost(**test_input) == 2\n\ntest_input = { \"nums\": [5,2,1] }\nassert my_solution.minimumCost(**test_input) == 4\n\ntest_input = { \"nums\": [5,3,1] }\nassert my_solution.minimumCost(**test_input) == 4\n\ntest_input = { \"nums\": [5,3,2] }\nassert my_solution.minimumCost(**test_input) == 3\n\ntest_input = { \"nums\": [5,4,1] }\nassert my_solution.minimumCost(**test_input) == 4\n\ntest_input = { \"nums\": [5,4,2] }\nassert my_solution.minimumCost(**test_input) == 3\n\ntest_input = { \"nums\": [5,4,3] }\nassert my_solution.minimumCost(**test_input) == 2\n\ntest_input = { \"nums\": [4,3,2,1] }\nassert my_solution.minimumCost(**test_input) == 4\n\ntest_input = { \"nums\": [5,3,2,1] }\nassert my_solution.minimumCost(**test_input) == 5\n\ntest_input = { \"nums\": [5,4,2,1] }\nassert my_solution.minimumCost(**test_input) == 6\n\ntest_input = { \"nums\": [5,4,3,1] }\nassert my_solution.minimumCost(**test_input) == 5\n\ntest_input = { \"nums\": [5,4,3,2] }\nassert my_solution.minimumCost(**test_input) == 4\n\ntest_input = { \"nums\": [301,309,312,322] }\nassert my_solution.minimumCost(**test_input) == 26\n\ntest_input = { \"nums\": [302,306,316,329] }\nassert my_solution.minimumCost(**test_input) == 37\n\ntest_input = { \"nums\": [302,315,317,320] }\nassert my_solution.minimumCost(**test_input) == 24\n\ntest_input = { \"nums\": [304,310,324,328] }\nassert my_solution.minimumCost(**test_input) == 38\n\ntest_input = { \"nums\": [307,321,322,327] }\nassert my_solution.minimumCost(**test_input) == 23\n\ntest_input = { \"nums\": [307,323,325,330] }\nassert my_solution.minimumCost(**test_input) == 25\n\ntest_input = { \"nums\": [308,313,319,322] }\nassert my_solution.minimumCost(**test_input) == 20\n\ntest_input = { \"nums\": [311,313,320,324] }\nassert my_solution.minimumCost(**test_input) == 20\n\ntest_input = { \"nums\": [313,318,323,328] }\nassert my_solution.minimumCost(**test_input) == 20\n\ntest_input = { \"nums\": [101,102,105,108,124] }\nassert my_solution.minimumCost(**test_input) == 35\n\ntest_input = { \"nums\": [101,102,105,120,124] }\nassert my_solution.minimumCost(**test_input) == 47\n\ntest_input = { \"nums\": [101,102,111,125,126] }\nassert my_solution.minimumCost(**test_input) == 48\n\ntest_input = { \"nums\": [101,104,107,126,130] }\nassert my_solution.minimumCost(**test_input) == 55\n\ntest_input = { \"nums\": [101,106,113,120,124] }\nassert my_solution.minimumCost(**test_input) == 39\n\ntest_input = { \"nums\": [101,115,116,120,122] }\nassert my_solution.minimumCost(**test_input) == 33\n\ntest_input = { \"nums\": [102,103,105,106,109] }\nassert my_solution.minimumCost(**test_input) == 20\n\ntest_input = { \"nums\": [102,103,107,125,128] }\nassert my_solution.minimumCost(**test_input) == 52\n\ntest_input = { \"nums\": [102,103,111,119,125] }\nassert my_solution.minimumCost(**test_input) == 39\n\ntest_input = { \"nums\": [102,105,120,128,129] }\nassert my_solution.minimumCost(**test_input) == 51\n\ntest_input = { \"nums\": [103,104,113,116,119] }\nassert my_solution.minimumCost(**test_input) == 30\n\ntest_input = { \"nums\": [103,105,107,113,125] }\nassert my_solution.minimumCost(**test_input) == 34\n\ntest_input = { \"nums\": [103,106,113,120,130] }\nassert my_solution.minimumCost(**test_input) == 43\n\ntest_input = { \"nums\": [103,109,110,118,123] }\nassert my_solution.minimumCost(**test_input) == 30\n\ntest_input = { \"nums\": [103,110,121,127,129] }\nassert my_solution.minimumCost(**test_input) == 43\n\ntest_input = { \"nums\": [103,114,120,123,125] }\nassert my_solution.minimumCost(**test_input) == 32\n\ntest_input = { \"nums\": [103,115,120,122,128] }\nassert my_solution.minimumCost(**test_input) == 33\n\ntest_input = { \"nums\": [104,107,120,122,124] }\nassert my_solution.minimumCost(**test_input) == 36\n\ntest_input = { \"nums\": [104,111,121,128,129] }\nassert my_solution.minimumCost(**test_input) == 42\n\ntest_input = { \"nums\": [104,119,123,125,126] }\nassert my_solution.minimumCost(**test_input) == 30\n\ntest_input = { \"nums\": [105,108,112,119,130] }\nassert my_solution.minimumCost(**test_input) == 37\n\ntest_input = { \"nums\": [105,108,122,126,130] }\nassert my_solution.minimumCost(**test_input) == 44\n\ntest_input = { \"nums\": [105,110,118,123,125] }\nassert my_solution.minimumCost(**test_input) == 36\n\ntest_input = { \"nums\": [105,116,118,123,129] }\nassert my_solution.minimumCost(**test_input) == 34\n\ntest_input = { \"nums\": [106,107,114,117,127] }\nassert my_solution.minimumCost(**test_input) == 34\n\ntest_input = { \"nums\": [106,109,118,124,125] }\nassert my_solution.minimumCost(**test_input) == 37\n\ntest_input = { \"nums\": [106,111,113,123,129] }\nassert my_solution.minimumCost(**test_input) == 37\n\ntest_input = { \"nums\": [106,113,116,120,122] }\nassert my_solution.minimumCost(**test_input) == 30\n\ntest_input = { \"nums\": [107,108,113,114,122] }\nassert my_solution.minimumCost(**test_input) == 23\n\ntest_input = { \"nums\": [107,109,112,118,128] }\nassert my_solution.minimumCost(**test_input) == 31\n\ntest_input = { \"nums\": [107,109,115,116,129] }\nassert my_solution.minimumCost(**test_input) == 33\n\ntest_input = { \"nums\": [107,110,119,125,130] }\nassert my_solution.minimumCost(**test_input) == 40\n\ntest_input = { \"nums\": [107,112,116,121,124] }\nassert my_solution.minimumCost(**test_input) == 31\n\ntest_input = { \"nums\": [107,115,116,120,127] }\nassert my_solution.minimumCost(**test_input) == 32\n\ntest_input = { \"nums\": [107,116,123,125,128] }\nassert my_solution.minimumCost(**test_input) == 32\n\ntest_input = { \"nums\": [108,110,116,121,130] }\nassert my_solution.minimumCost(**test_input) == 38\n\ntest_input = { \"nums\": [108,113,114,115,119] }\nassert my_solution.minimumCost(**test_input) == 20\n\ntest_input = { \"nums\": [108,113,116,124,129] }\nassert my_solution.minimumCost(**test_input) == 37\n\ntest_input = { \"nums\": [108,115,124,127,129] }\nassert my_solution.minimumCost(**test_input) == 36\n\ntest_input = { \"nums\": [109,113,115,122,128] }\nassert my_solution.minimumCost(**test_input) == 34\n\ntest_input = { \"nums\": [110,111,112,126,129] }\nassert my_solution.minimumCost(**test_input) == 35\n\ntest_input = { \"nums\": [110,113,119,124,125] }\nassert my_solution.minimumCost(**test_input) == 28\n\ntest_input = { \"nums\": [111,114,117,118,125] }\nassert my_solution.minimumCost(**test_input) == 28\n\ntest_input = { \"nums\": [112,113,114,120,130] }\nassert my_solution.minimumCost(**test_input) == 34\n\ntest_input = { \"nums\": [112,115,120,123,129] }\nassert my_solution.minimumCost(**test_input) == 26\n\ntest_input = { \"nums\": [117,118,119,124,128] }\nassert my_solution.minimumCost(**test_input) == 19\n\ntest_input = { \"nums\": [201,202,203,205,215,228] }\nassert my_solution.minimumCost(**test_input) == 44\n\ntest_input = { \"nums\": [201,202,204,205,215,225] }\nassert my_solution.minimumCost(**test_input) == 42\n\ntest_input = { \"nums\": [201,202,204,207,220,224] }\nassert my_solution.minimumCost(**test_input) == 48\n\ntest_input = { \"nums\": [201,202,204,208,216,225] }\nassert my_solution.minimumCost(**test_input) == 46\n\ntest_input = { \"nums\": [201,202,204,218,223,224] }\nassert my_solution.minimumCost(**test_input) == 58\n\ntest_input = { \"nums\": [201,202,205,210,227,228] }\nassert my_solution.minimumCost(**test_input) == 61\n\ntest_input = { \"nums\": [201,202,205,211,214,225] }\nassert my_solution.minimumCost(**test_input) == 44\n\ntest_input = { \"nums\": [201,202,207,210,223,226] }\nassert my_solution.minimumCost(**test_input) == 53\n\ntest_input = { \"nums\": [201,202,207,212,215,222] }\nassert my_solution.minimumCost(**test_input) == 39\n\ntest_input = { \"nums\": [201,202,207,216,220,223] }\nassert my_solution.minimumCost(**test_input) == 49\n\ntest_input = { \"nums\": [201,202,211,213,221,223] }\nassert my_solution.minimumCost(**test_input) == 43\n\ntest_input = { \"nums\": [201,202,212,213,219,229] }\nassert my_solution.minimumCost(**test_input) == 46", "start_time": 1702780200} +{"task_id": "weekly-contest-376-apply-operations-to-maximize-frequency-score", "url": "https://leetcode.com/problems/apply-operations-to-maximize-frequency-score", "title": "apply-operations-to-maximize-frequency-score", "meta": {"questionId": "3196", "questionFrontendId": "2968", "title": "Apply Operations to Maximize Frequency Score", "titleSlug": "apply-operations-to-maximize-frequency-score", "isPaidOnly": false, "difficulty": "Hard", "likes": 175, "dislikes": 4, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0开始的整数数组nums和一个整数k。\n你可以对数组执行 至多k次操作:\n\n从数组中选择一个下标 i,将nums[i] 增加或者减少1。\n\n最终数组的频率分数定义为数组中众数的 频率。\n请你返回你可以得到的 最大频率分数。\n众数指的是数组中出现次数最多的数。一个元素的频率指的是数组中这个元素的出现次数。\n\n示例 1:\n\n输入:nums = [1,2,6,4], k = 3\n输出:3\n解释:我们可以对数组执行以下操作:\n- 选择 i = 0 ,将 nums[0] 增加 1 。得到数组 [2,2,6,4] 。\n- 选择 i = 3 ,将 nums[3] 减少 1 ,得到数组 [2,2,6,3] 。\n- 选择 i = 3 ,将 nums[3] 减少 1 ,得到数组 [2,2,6,2] 。\n元素 2 是最终数组中的众数,出现了 3 次,所以频率分数为 3 。\n3 是所有可行方案里的最大频率分数。\n\n示例 2:\n\n输入:nums = [1,4,4,2,4], k = 0\n输出:3\n解释:我们无法执行任何操作,所以得到的频率分数是原数组中众数的频率 3 。\n\n\n提示:\n\n1 <= nums.length <= 105\n1 <= nums[i] <= 109\n0 <= k <= 1014\n\"\"\"\nclass Solution:\n def maxFrequencyScore(self, nums: List[int], k: int) -> int:\n ", "prompt_sft": "给你一个下标从 0开始的整数数组nums和一个整数k。\n你可以对数组执行 至多k次操作:\n\n从数组中选择一个下标 i,将nums[i] 增加或者减少1。\n\n最终数组的频率分数定义为数组中众数的 频率。\n请你返回你可以得到的 最大频率分数。\n众数指的是数组中出现次数最多的数。一个元素的频率指的是数组中这个元素的出现次数。\n\n示例 1:\n\n输入:nums = [1,2,6,4], k = 3\n输出:3\n解释:我们可以对数组执行以下操作:\n- 选择 i = 0 ,将 nums[0] 增加 1 。得到数组 [2,2,6,4] 。\n- 选择 i = 3 ,将 nums[3] 减少 1 ,得到数组 [2,2,6,3] 。\n- 选择 i = 3 ,将 nums[3] 减少 1 ,得到数组 [2,2,6,2] 。\n元素 2 是最终数组中的众数,出现了 3 次,所以频率分数为 3 。\n3 是所有可行方案里的最大频率分数。\n\n示例 2:\n\n输入:nums = [1,4,4,2,4], k = 0\n输出:3\n解释:我们无法执行任何操作,所以得到的频率分数是原数组中众数的频率 3 。\n\n\n提示:\n\n1 <= nums.length <= 105\n1 <= nums[i] <= 109\n0 <= k <= 1014\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def maxFrequencyScore(self, nums: List[int], k: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,2,6,4], \"k\": 3 }\nassert my_solution.maxFrequencyScore(**test_input) == 3\n\ntest_input = { \"nums\": [1,4,4,2,4], \"k\": 0 }\nassert my_solution.maxFrequencyScore(**test_input) == 3\n\ntest_input = { \"nums\": [3,20,13,2,3,15,24,19,8,13,19,20,21], \"k\": 45 }\nassert my_solution.maxFrequencyScore(**test_input) == 10\n\ntest_input = { \"nums\": [13,22,29,21,13,17,5,2,27,6,10,4,23,29,27], \"k\": 117 }\nassert my_solution.maxFrequencyScore(**test_input) == 14\n\ntest_input = { \"nums\": [27,8,30,3,13,28,7,14,21,19,24,28,29,1,14,22,6], \"k\": 23 }\nassert my_solution.maxFrequencyScore(**test_input) == 8\n\ntest_input = { \"nums\": [10,11,3], \"k\": 1 }\nassert my_solution.maxFrequencyScore(**test_input) == 2\n\ntest_input = { \"nums\": [10,19,26,18,27,18], \"k\": 9 }\nassert my_solution.maxFrequencyScore(**test_input) == 4\n\ntest_input = { \"nums\": [17,24,10,23,22,15,25,2,13,24,22,25,25,21], \"k\": 52 }\nassert my_solution.maxFrequencyScore(**test_input) == 13\n\ntest_input = { \"nums\": [28,6,22,10], \"k\": 12 }\nassert my_solution.maxFrequencyScore(**test_input) == 2\n\ntest_input = { \"nums\": [17,17,25,14,29,28,20,14,16,22,4,28,2,5,3,11,6,20,17], \"k\": 76 }\nassert my_solution.maxFrequencyScore(**test_input) == 14\n\ntest_input = { \"nums\": [23,10,18,21,16,23,14], \"k\": 2 }\nassert my_solution.maxFrequencyScore(**test_input) == 3\n\ntest_input = { \"nums\": [5,13,7], \"k\": 8 }\nassert my_solution.maxFrequencyScore(**test_input) == 3\n\ntest_input = { \"nums\": [6,29,3,19,10,6,20,26,1,30,11,25,29,12,29,14,15,16,5], \"k\": 64 }\nassert my_solution.maxFrequencyScore(**test_input) == 12\n\ntest_input = { \"nums\": [10,26,21,18,30,25,1], \"k\": 8 }\nassert my_solution.maxFrequencyScore(**test_input) == 3\n\ntest_input = { \"nums\": [29,10,26,1,2,2,17,7,5,16,24,27,7,7,26,26,24], \"k\": 3 }\nassert my_solution.maxFrequencyScore(**test_input) == 5\n\ntest_input = { \"nums\": [11,16,6,12,3,8,5,29,9,15,7,9,14,6,11,14,12,23,22,14], \"k\": 79 }\nassert my_solution.maxFrequencyScore(**test_input) == 19\n\ntest_input = { \"nums\": [5,17,15,14,27,11,22,6,4], \"k\": 26 }\nassert my_solution.maxFrequencyScore(**test_input) == 6\n\ntest_input = { \"nums\": [13,22,17], \"k\": 4 }\nassert my_solution.maxFrequencyScore(**test_input) == 2\n\ntest_input = { \"nums\": [24,6,14,6,30,9,6,11,21,10,12,27,1], \"k\": 90 }\nassert my_solution.maxFrequencyScore(**test_input) == 13\n\ntest_input = { \"nums\": [19,5,2,23,16,22,3,2,5,20,17,3,22,1], \"k\": 15 }\nassert my_solution.maxFrequencyScore(**test_input) == 7\n\ntest_input = { \"nums\": [15,20], \"k\": 5 }\nassert my_solution.maxFrequencyScore(**test_input) == 2\n\ntest_input = { \"nums\": [9,2,5,14,19,5,10,10,2,25,1,1,1,14,9,13,5,6,10,1], \"k\": 80 }\nassert my_solution.maxFrequencyScore(**test_input) == 18\n\ntest_input = { \"nums\": [2,29,24,19,5], \"k\": 24 }\nassert my_solution.maxFrequencyScore(**test_input) == 3\n\ntest_input = { \"nums\": [4,10,5], \"k\": 6 }\nassert my_solution.maxFrequencyScore(**test_input) == 3\n\ntest_input = { \"nums\": [5,2,22,7,18,26,15,4,24,26,24], \"k\": 19 }\nassert my_solution.maxFrequencyScore(**test_input) == 6\n\ntest_input = { \"nums\": [23,21,10], \"k\": 13 }\nassert my_solution.maxFrequencyScore(**test_input) == 3\n\ntest_input = { \"nums\": [5,23,7,2,1,5,12,2,20,24,5,4], \"k\": 71 }\nassert my_solution.maxFrequencyScore(**test_input) == 11\n\ntest_input = { \"nums\": [22,13,30], \"k\": 17 }\nassert my_solution.maxFrequencyScore(**test_input) == 3\n\ntest_input = { \"nums\": [7,23,29,8,9,3,4,16,24,6,18,20,19,14,5], \"k\": 55 }\nassert my_solution.maxFrequencyScore(**test_input) == 11\n\ntest_input = { \"nums\": [3,11,24,27,10], \"k\": 24 }\nassert my_solution.maxFrequencyScore(**test_input) == 4\n\ntest_input = { \"nums\": [12,11,21,6,13,27,11,2,27,26,24,13], \"k\": 0 }\nassert my_solution.maxFrequencyScore(**test_input) == 2\n\ntest_input = { \"nums\": [4,10,26,16,21,26,11,26,30,24,18,30,23,26,24], \"k\": 50 }\nassert my_solution.maxFrequencyScore(**test_input) == 12\n\ntest_input = { \"nums\": [4,2,18,14,9,29], \"k\": 4 }\nassert my_solution.maxFrequencyScore(**test_input) == 2\n\ntest_input = { \"nums\": [9,27,19,18], \"k\": 9 }\nassert my_solution.maxFrequencyScore(**test_input) == 3\n\ntest_input = { \"nums\": [11,17,29,9,22,7,13,14,12,24,9], \"k\": 47 }\nassert my_solution.maxFrequencyScore(**test_input) == 10\n\ntest_input = { \"nums\": [20,10,15,16], \"k\": 10 }\nassert my_solution.maxFrequencyScore(**test_input) == 3\n\ntest_input = { \"nums\": [16,2,6,20,2,18,16,8,15,19,22,29,24,2,26,19], \"k\": 40 }\nassert my_solution.maxFrequencyScore(**test_input) == 11\n\ntest_input = { \"nums\": [17,13,19,28,6,8,5,25,2,3,9,4,21,6,13,10,5,3], \"k\": 113 }\nassert my_solution.maxFrequencyScore(**test_input) == 18\n\ntest_input = { \"nums\": [16,5,10,15], \"k\": 5 }\nassert my_solution.maxFrequencyScore(**test_input) == 2\n\ntest_input = { \"nums\": [23,2,23,27,21], \"k\": 2 }\nassert my_solution.maxFrequencyScore(**test_input) == 3\n\ntest_input = { \"nums\": [15,26,3,14,3,18,16,19,11,9,2,18,14,8,20,9], \"k\": 75 }\nassert my_solution.maxFrequencyScore(**test_input) == 15\n\ntest_input = { \"nums\": [13,23,4,5,2], \"k\": 3 }\nassert my_solution.maxFrequencyScore(**test_input) == 3\n\ntest_input = { \"nums\": [3,1,9,12], \"k\": 8 }\nassert my_solution.maxFrequencyScore(**test_input) == 3\n\ntest_input = { \"nums\": [4,27,21,16,11,5,5,1,5,10], \"k\": 18 }\nassert my_solution.maxFrequencyScore(**test_input) == 7\n\ntest_input = { \"nums\": [14,4,23,27,8,25,7,12,12,21,21,11,20,23,30,11,12,29,22], \"k\": 77 }\nassert my_solution.maxFrequencyScore(**test_input) == 15\n\ntest_input = { \"nums\": [10,30,25], \"k\": 20 }\nassert my_solution.maxFrequencyScore(**test_input) == 3\n\ntest_input = { \"nums\": [4,8,22,25,27,26,18,14,18], \"k\": 56 }\nassert my_solution.maxFrequencyScore(**test_input) == 9\n\ntest_input = { \"nums\": [2,19,27,25,23,17,8,16,28,10,6,24,6], \"k\": 28 }\nassert my_solution.maxFrequencyScore(**test_input) == 7\n\ntest_input = { \"nums\": [27,25,27,10,23,14,24,17,12,22,14,11,19,16,7,15], \"k\": 21 }\nassert my_solution.maxFrequencyScore(**test_input) == 9\n\ntest_input = { \"nums\": [23,11], \"k\": 12 }\nassert my_solution.maxFrequencyScore(**test_input) == 2\n\ntest_input = { \"nums\": [20,28,15,11,22,26,29,2,16,9], \"k\": 61 }\nassert my_solution.maxFrequencyScore(**test_input) == 9\n\ntest_input = { \"nums\": [21,11,1,17,20,19,24,10,1,4,10,30,11,29,20,12,18,5,4,27], \"k\": 110 }\nassert my_solution.maxFrequencyScore(**test_input) == 17\n\ntest_input = { \"nums\": [22,29,7,1,26,22,27,1,16,25,25], \"k\": 26 }\nassert my_solution.maxFrequencyScore(**test_input) == 8\n\ntest_input = { \"nums\": [26,6,24], \"k\": 20 }\nassert my_solution.maxFrequencyScore(**test_input) == 3\n\ntest_input = { \"nums\": [29,24,9,4,2,9,28,1,25,25,13,22,27,26,15,18], \"k\": 2 }\nassert my_solution.maxFrequencyScore(**test_input) == 4\n\ntest_input = { \"nums\": [9,19,1,24,15,19,22,13,10,8,4,10,26,23,11,8], \"k\": 89 }\nassert my_solution.maxFrequencyScore(**test_input) == 15\n\ntest_input = { \"nums\": [18,6,20,22,25,21,19,19,15,5,7,29,28,7,17,4], \"k\": 104 }\nassert my_solution.maxFrequencyScore(**test_input) == 16\n\ntest_input = { \"nums\": [9,11,28,24,30,6,1,30,22,16,20,19,21,17], \"k\": 62 }\nassert my_solution.maxFrequencyScore(**test_input) == 11\n\ntest_input = { \"nums\": [15,13,29,28], \"k\": 15 }\nassert my_solution.maxFrequencyScore(**test_input) == 3\n\ntest_input = { \"nums\": [28,26,8], \"k\": 18 }\nassert my_solution.maxFrequencyScore(**test_input) == 2\n\ntest_input = { \"nums\": [6,12,24,4,25,23,5,13,7,5], \"k\": 12 }\nassert my_solution.maxFrequencyScore(**test_input) == 6\n\ntest_input = { \"nums\": [8,23,15,15,3,19,6,20,12,18,7,8,18,19,11,20,4,18], \"k\": 54 }\nassert my_solution.maxFrequencyScore(**test_input) == 14\n\ntest_input = { \"nums\": [30,2,4,7,19,3,3,14,24,4,26,17,1,12,4,11], \"k\": 36 }\nassert my_solution.maxFrequencyScore(**test_input) == 11\n\ntest_input = { \"nums\": [12,15,21,17,7,20,16,30,8,6,28,28,23,6,12,14,19,26,27,5], \"k\": 87 }\nassert my_solution.maxFrequencyScore(**test_input) == 16\n\ntest_input = { \"nums\": [15,1,27,4,5,20,5,26,28], \"k\": 38 }\nassert my_solution.maxFrequencyScore(**test_input) == 6\n\ntest_input = { \"nums\": [27,14,30,6,14,29,5,8], \"k\": 51 }\nassert my_solution.maxFrequencyScore(**test_input) == 7\n\ntest_input = { \"nums\": [18,22], \"k\": 4 }\nassert my_solution.maxFrequencyScore(**test_input) == 2\n\ntest_input = { \"nums\": [17,28,16,24,29], \"k\": 5 }\nassert my_solution.maxFrequencyScore(**test_input) == 3\n\ntest_input = { \"nums\": [2,22,27,12,30,9,27,3,26,23,25,30,20,19,9,1,23,14,18,26], \"k\": 30 }\nassert my_solution.maxFrequencyScore(**test_input) == 11\n\ntest_input = { \"nums\": [26,16,9,7,10,16,26,22,24,1,30,8,15,5,28,16,13,12], \"k\": 84 }\nassert my_solution.maxFrequencyScore(**test_input) == 15\n\ntest_input = { \"nums\": [26,8,27,27,22,28,8,26,24,15,6,13,20,12], \"k\": 55 }\nassert my_solution.maxFrequencyScore(**test_input) == 11\n\ntest_input = { \"nums\": [19,19,20,14,19,20,5,4,14,26,12,17,14,29,3,9], \"k\": 94 }\nassert my_solution.maxFrequencyScore(**test_input) == 16\n\ntest_input = { \"nums\": [9,19,14,17,14,20,27,9,22,29,15,20,6,25,8,17,18,24,23], \"k\": 44 }\nassert my_solution.maxFrequencyScore(**test_input) == 13\n\ntest_input = { \"nums\": [2,10], \"k\": 8 }\nassert my_solution.maxFrequencyScore(**test_input) == 2\n\ntest_input = { \"nums\": [20,2,27,27,19,20,8,21,15,20,14,18,25], \"k\": 17 }\nassert my_solution.maxFrequencyScore(**test_input) == 8\n\ntest_input = { \"nums\": [6,27,6,30,2,1,7,24,18,4,2,18,17], \"k\": 56 }\nassert my_solution.maxFrequencyScore(**test_input) == 10\n\ntest_input = { \"nums\": [23,18,30,24,5,21], \"k\": 33 }\nassert my_solution.maxFrequencyScore(**test_input) == 6\n\ntest_input = { \"nums\": [12,16,24,18,12,20,26,15,11,23,4,25], \"k\": 35 }\nassert my_solution.maxFrequencyScore(**test_input) == 9\n\ntest_input = { \"nums\": [9,9,11,18], \"k\": 11 }\nassert my_solution.maxFrequencyScore(**test_input) == 4\n\ntest_input = { \"nums\": [19,21,7,15,21,10,5,27,2,27,14], \"k\": 63 }\nassert my_solution.maxFrequencyScore(**test_input) == 9\n\ntest_input = { \"nums\": [25,17,13,6,3,19,21,12,29,1,16,14,24,27,25,13,1,5,17], \"k\": 136 }\nassert my_solution.maxFrequencyScore(**test_input) == 19\n\ntest_input = { \"nums\": [4,4,8,9,14,7,27,8,2,29,1,28,23,13], \"k\": 109 }\nassert my_solution.maxFrequencyScore(**test_input) == 14\n\ntest_input = { \"nums\": [14,2,18,30,28,17,25,10,7,10,19,3,26,22,12,17,8,4], \"k\": 24 }\nassert my_solution.maxFrequencyScore(**test_input) == 8\n\ntest_input = { \"nums\": [27,17,12,19,25,1,9,4,9,20,2,5], \"k\": 70 }\nassert my_solution.maxFrequencyScore(**test_input) == 10\n\ntest_input = { \"nums\": [18,25,12,20,19,26,2,15,3,6,29,29,2,24,4,9], \"k\": 106 }\nassert my_solution.maxFrequencyScore(**test_input) == 14\n\ntest_input = { \"nums\": [17,18,14,1,28,15,14,13,9,16,28,9,21,23,2,11], \"k\": 65 }\nassert my_solution.maxFrequencyScore(**test_input) == 14\n\ntest_input = { \"nums\": [17,15,29,30,12,13,10], \"k\": 37 }\nassert my_solution.maxFrequencyScore(**test_input) == 6\n\ntest_input = { \"nums\": [15,4,11,1,18,29,9,23,14,25,15,12,15,6,30,28], \"k\": 60 }\nassert my_solution.maxFrequencyScore(**test_input) == 12\n\ntest_input = { \"nums\": [20,6,8,15,12,8,26,7,27,8,5,25,17,12,7,1,23,24,8], \"k\": 62 }\nassert my_solution.maxFrequencyScore(**test_input) == 14\n\ntest_input = { \"nums\": [22,21,30,16,23,24,2,2,24], \"k\": 39 }\nassert my_solution.maxFrequencyScore(**test_input) == 7\n\ntest_input = { \"nums\": [8,9,6,30,28,2,1,3,14,8,21,26,13,29,23,3,14,9,6,25], \"k\": 91 }\nassert my_solution.maxFrequencyScore(**test_input) == 16\n\ntest_input = { \"nums\": [7,10,16,23,17,22,28,7,4,21,25,21,19,30,13,19,15,21,23], \"k\": 53 }\nassert my_solution.maxFrequencyScore(**test_input) == 15\n\ntest_input = { \"nums\": [25,17,1,24,3,6,8,29,19,4,16,12,9,28,1,21,13,29], \"k\": 151 }\nassert my_solution.maxFrequencyScore(**test_input) == 18\n\ntest_input = { \"nums\": [1,6,14,9], \"k\": 8 }\nassert my_solution.maxFrequencyScore(**test_input) == 3\n\ntest_input = { \"nums\": [5,7,17,2,23,6,3,13,2,11,10,8,18,16,3,11,26], \"k\": 30 }\nassert my_solution.maxFrequencyScore(**test_input) == 10\n\ntest_input = { \"nums\": [27,27,16,18,24,7,26,30,21,25,28,28,29,27,28,6], \"k\": 0 }\nassert my_solution.maxFrequencyScore(**test_input) == 3\n\ntest_input = { \"nums\": [29,16,9,21,2,16,4,17,22,11,20,23,5,22,7,27,20], \"k\": 85 }\nassert my_solution.maxFrequencyScore(**test_input) == 15\n\ntest_input = { \"nums\": [25,5,24,2,30,15,17,27,15,15,27], \"k\": 69 }\nassert my_solution.maxFrequencyScore(**test_input) == 10\n\ntest_input = { \"nums\": [6,29,24,14,9,14,1,1,28,20,19,21,13,25,17,24,30,14], \"k\": 107 }\nassert my_solution.maxFrequencyScore(**test_input) == 16\n\ntest_input = { \"nums\": [17,20,2,11,5,7,28], \"k\": 36 }\nassert my_solution.maxFrequencyScore(**test_input) == 6", "start_time": 1702780200} +{"task_id": "weekly-contest-375-count-tested-devices-after-test-operations", "url": "https://leetcode.com/problems/count-tested-devices-after-test-operations", "title": "count-tested-devices-after-test-operations", "meta": {"questionId": "3220", "questionFrontendId": "2960", "title": "Count Tested Devices After Test Operations", "titleSlug": "count-tested-devices-after-test-operations", "isPaidOnly": false, "difficulty": "Easy", "likes": 90, "dislikes": 5, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个长度为 n 、下标从 0 开始的整数数组 batteryPercentages ,表示 n 个设备的电池百分比。\n你的任务是按照顺序测试每个设备 i,执行以下测试操作:\n\n如果 batteryPercentages[i] 大于 0:\n\n\t\n增加 已测试设备的计数。\n将下标在 [i + 1, n - 1] 的所有设备的电池百分比减少 1,确保它们的电池百分比 不会低于 0 ,即 batteryPercentages[j] = max(0, batteryPercentages[j] - 1)。\n移动到下一个设备。\n\n\n否则,移动到下一个设备而不执行任何测试。\n\n返回一个整数,表示按顺序执行测试操作后 已测试设备 的数量。\n\n示例 1:\n\n输入:batteryPercentages = [1,1,2,1,3]\n输出:3\n解释:按顺序从设备 0 开始执行测试操作:\n在设备 0 上,batteryPercentages[0] > 0 ,现在有 1 个已测试设备,batteryPercentages 变为 [1,0,1,0,2] 。\n在设备 1 上,batteryPercentages[1] == 0 ,移动到下一个设备而不进行测试。\n在设备 2 上,batteryPercentages[2] > 0 ,现在有 2 个已测试设备,batteryPercentages 变为 [1,0,1,0,1] 。\n在设备 3 上,batteryPercentages[3] == 0 ,移动到下一个设备而不进行测试。\n在设备 4 上,batteryPercentages[4] > 0 ,现在有 3 个已测试设备,batteryPercentages 保持不变。\n因此,答案是 3 。\n\n示例 2:\n\n输入:batteryPercentages = [0,1,2]\n输出:2\n解释:按顺序从设备 0 开始执行测试操作:\n在设备 0 上,batteryPercentages[0] == 0 ,移动到下一个设备而不进行测试。\n在设备 1 上,batteryPercentages[1] > 0 ,现在有 1 个已测试设备,batteryPercentages 变为 [0,1,1] 。\n在设备 2 上,batteryPercentages[2] > 0 ,现在有 2 个已测试设备,batteryPercentages 保持不变。\n因此,答案是 2 。\n\n\n提示:\n\n1 <= n == batteryPercentages.length <= 100 \n0 <= batteryPercentages[i] <= 100\n\"\"\"\nclass Solution:\n def countTestedDevices(self, batteryPercentages: List[int]) -> int:\n ", "prompt_sft": "给你一个长度为 n 、下标从 0 开始的整数数组 batteryPercentages ,表示 n 个设备的电池百分比。\n你的任务是按照顺序测试每个设备 i,执行以下测试操作:\n\n如果 batteryPercentages[i] 大于 0:\n\n\t\n增加 已测试设备的计数。\n将下标在 [i + 1, n - 1] 的所有设备的电池百分比减少 1,确保它们的电池百分比 不会低于 0 ,即 batteryPercentages[j] = max(0, batteryPercentages[j] - 1)。\n移动到下一个设备。\n\n\n否则,移动到下一个设备而不执行任何测试。\n\n返回一个整数,表示按顺序执行测试操作后 已测试设备 的数量。\n\n示例 1:\n\n输入:batteryPercentages = [1,1,2,1,3]\n输出:3\n解释:按顺序从设备 0 开始执行测试操作:\n在设备 0 上,batteryPercentages[0] > 0 ,现在有 1 个已测试设备,batteryPercentages 变为 [1,0,1,0,2] 。\n在设备 1 上,batteryPercentages[1] == 0 ,移动到下一个设备而不进行测试。\n在设备 2 上,batteryPercentages[2] > 0 ,现在有 2 个已测试设备,batteryPercentages 变为 [1,0,1,0,1] 。\n在设备 3 上,batteryPercentages[3] == 0 ,移动到下一个设备而不进行测试。\n在设备 4 上,batteryPercentages[4] > 0 ,现在有 3 个已测试设备,batteryPercentages 保持不变。\n因此,答案是 3 。\n\n示例 2:\n\n输入:batteryPercentages = [0,1,2]\n输出:2\n解释:按顺序从设备 0 开始执行测试操作:\n在设备 0 上,batteryPercentages[0] == 0 ,移动到下一个设备而不进行测试。\n在设备 1 上,batteryPercentages[1] > 0 ,现在有 1 个已测试设备,batteryPercentages 变为 [0,1,1] 。\n在设备 2 上,batteryPercentages[2] > 0 ,现在有 2 个已测试设备,batteryPercentages 保持不变。\n因此,答案是 2 。\n\n\n提示:\n\n1 <= n == batteryPercentages.length <= 100 \n0 <= batteryPercentages[i] <= 100\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def countTestedDevices(self, batteryPercentages: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"batteryPercentages\": [1,1,2,1,3] }\nassert my_solution.countTestedDevices(**test_input) == 3\n\ntest_input = { \"batteryPercentages\": [0,1,2] }\nassert my_solution.countTestedDevices(**test_input) == 2\n\ntest_input = { \"batteryPercentages\": [0] }\nassert my_solution.countTestedDevices(**test_input) == 0\n\ntest_input = { \"batteryPercentages\": [1] }\nassert my_solution.countTestedDevices(**test_input) == 1\n\ntest_input = { \"batteryPercentages\": [0,0] }\nassert my_solution.countTestedDevices(**test_input) == 0\n\ntest_input = { \"batteryPercentages\": [0,1] }\nassert my_solution.countTestedDevices(**test_input) == 1\n\ntest_input = { \"batteryPercentages\": [0,2] }\nassert my_solution.countTestedDevices(**test_input) == 1\n\ntest_input = { \"batteryPercentages\": [1,0] }\nassert my_solution.countTestedDevices(**test_input) == 1\n\ntest_input = { \"batteryPercentages\": [1,2] }\nassert my_solution.countTestedDevices(**test_input) == 2\n\ntest_input = { \"batteryPercentages\": [2,1] }\nassert my_solution.countTestedDevices(**test_input) == 1\n\ntest_input = { \"batteryPercentages\": [2,2] }\nassert my_solution.countTestedDevices(**test_input) == 2\n\ntest_input = { \"batteryPercentages\": [0,0,1] }\nassert my_solution.countTestedDevices(**test_input) == 1\n\ntest_input = { \"batteryPercentages\": [0,0,2] }\nassert my_solution.countTestedDevices(**test_input) == 1\n\ntest_input = { \"batteryPercentages\": [1,1,0] }\nassert my_solution.countTestedDevices(**test_input) == 1\n\ntest_input = { \"batteryPercentages\": [1,2,0] }\nassert my_solution.countTestedDevices(**test_input) == 2\n\ntest_input = { \"batteryPercentages\": [1,3,1] }\nassert my_solution.countTestedDevices(**test_input) == 2\n\ntest_input = { \"batteryPercentages\": [2,0,1] }\nassert my_solution.countTestedDevices(**test_input) == 1\n\ntest_input = { \"batteryPercentages\": [2,2,0] }\nassert my_solution.countTestedDevices(**test_input) == 2\n\ntest_input = { \"batteryPercentages\": [2,2,2] }\nassert my_solution.countTestedDevices(**test_input) == 2\n\ntest_input = { \"batteryPercentages\": [3,0,3] }\nassert my_solution.countTestedDevices(**test_input) == 2\n\ntest_input = { \"batteryPercentages\": [3,3,1] }\nassert my_solution.countTestedDevices(**test_input) == 2\n\ntest_input = { \"batteryPercentages\": [3,3,3] }\nassert my_solution.countTestedDevices(**test_input) == 3\n\ntest_input = { \"batteryPercentages\": [0,2,1,4] }\nassert my_solution.countTestedDevices(**test_input) == 2\n\ntest_input = { \"batteryPercentages\": [1,4,4,1] }\nassert my_solution.countTestedDevices(**test_input) == 3\n\ntest_input = { \"batteryPercentages\": [3,1,2,0] }\nassert my_solution.countTestedDevices(**test_input) == 2\n\ntest_input = { \"batteryPercentages\": [3,2,1,1] }\nassert my_solution.countTestedDevices(**test_input) == 2\n\ntest_input = { \"batteryPercentages\": [3,2,1,3] }\nassert my_solution.countTestedDevices(**test_input) == 3\n\ntest_input = { \"batteryPercentages\": [4,1,4,4] }\nassert my_solution.countTestedDevices(**test_input) == 3\n\ntest_input = { \"batteryPercentages\": [4,2,0,1] }\nassert my_solution.countTestedDevices(**test_input) == 2\n\ntest_input = { \"batteryPercentages\": [4,2,1,3] }\nassert my_solution.countTestedDevices(**test_input) == 3\n\ntest_input = { \"batteryPercentages\": [4,4,4,2] }\nassert my_solution.countTestedDevices(**test_input) == 3\n\ntest_input = { \"batteryPercentages\": [0,3,1,3,5] }\nassert my_solution.countTestedDevices(**test_input) == 3\n\ntest_input = { \"batteryPercentages\": [0,4,2,5,3] }\nassert my_solution.countTestedDevices(**test_input) == 3\n\ntest_input = { \"batteryPercentages\": [0,5,4,2,0] }\nassert my_solution.countTestedDevices(**test_input) == 2\n\ntest_input = { \"batteryPercentages\": [2,2,3,0,2] }\nassert my_solution.countTestedDevices(**test_input) == 3\n\ntest_input = { \"batteryPercentages\": [2,3,5,0,1] }\nassert my_solution.countTestedDevices(**test_input) == 3\n\ntest_input = { \"batteryPercentages\": [2,4,5,2,0] }\nassert my_solution.countTestedDevices(**test_input) == 3\n\ntest_input = { \"batteryPercentages\": [4,3,3,5,4] }\nassert my_solution.countTestedDevices(**test_input) == 4\n\ntest_input = { \"batteryPercentages\": [5,4,1,0,3] }\nassert my_solution.countTestedDevices(**test_input) == 3\n\ntest_input = { \"batteryPercentages\": [5,5,5,2,0] }\nassert my_solution.countTestedDevices(**test_input) == 3\n\ntest_input = { \"batteryPercentages\": [0,2,4,3,0,2] }\nassert my_solution.countTestedDevices(**test_input) == 3\n\ntest_input = { \"batteryPercentages\": [0,4,5,3,3,2] }\nassert my_solution.countTestedDevices(**test_input) == 3\n\ntest_input = { \"batteryPercentages\": [1,3,1,5,4,5] }\nassert my_solution.countTestedDevices(**test_input) == 5\n\ntest_input = { \"batteryPercentages\": [1,6,0,3,3,6] }\nassert my_solution.countTestedDevices(**test_input) == 4\n\ntest_input = { \"batteryPercentages\": [3,1,3,5,2,0] }\nassert my_solution.countTestedDevices(**test_input) == 3\n\ntest_input = { \"batteryPercentages\": [3,2,6,2,6,0] }\nassert my_solution.countTestedDevices(**test_input) == 4\n\ntest_input = { \"batteryPercentages\": [4,1,5,3,5,2] }\nassert my_solution.countTestedDevices(**test_input) == 4\n\ntest_input = { \"batteryPercentages\": [4,3,3,2,4,3] }\nassert my_solution.countTestedDevices(**test_input) == 4\n\ntest_input = { \"batteryPercentages\": [4,5,2,3,6,2] }\nassert my_solution.countTestedDevices(**test_input) == 4\n\ntest_input = { \"batteryPercentages\": [5,1,1,2,1,4] }\nassert my_solution.countTestedDevices(**test_input) == 3\n\ntest_input = { \"batteryPercentages\": [5,1,6,6,3,6] }\nassert my_solution.countTestedDevices(**test_input) == 4\n\ntest_input = { \"batteryPercentages\": [6,1,5,1,4,5] }\nassert my_solution.countTestedDevices(**test_input) == 4\n\ntest_input = { \"batteryPercentages\": [6,2,2,3,4,6] }\nassert my_solution.countTestedDevices(**test_input) == 5\n\ntest_input = { \"batteryPercentages\": [6,2,3,0,2,0] }\nassert my_solution.countTestedDevices(**test_input) == 3\n\ntest_input = { \"batteryPercentages\": [1,0,6,3,6,3,1] }\nassert my_solution.countTestedDevices(**test_input) == 4\n\ntest_input = { \"batteryPercentages\": [2,1,7,3,0,3,3] }\nassert my_solution.countTestedDevices(**test_input) == 3\n\ntest_input = { \"batteryPercentages\": [2,3,7,0,6,4,4] }\nassert my_solution.countTestedDevices(**test_input) == 4\n\ntest_input = { \"batteryPercentages\": [2,5,2,4,2,1,3] }\nassert my_solution.countTestedDevices(**test_input) == 3\n\ntest_input = { \"batteryPercentages\": [2,5,2,7,6,5,5] }\nassert my_solution.countTestedDevices(**test_input) == 5\n\ntest_input = { \"batteryPercentages\": [4,2,6,4,7,6,7] }\nassert my_solution.countTestedDevices(**test_input) == 7\n\ntest_input = { \"batteryPercentages\": [4,2,6,6,3,3,7] }\nassert my_solution.countTestedDevices(**test_input) == 5\n\ntest_input = { \"batteryPercentages\": [4,4,3,0,2,6,6] }\nassert my_solution.countTestedDevices(**test_input) == 5\n\ntest_input = { \"batteryPercentages\": [5,2,2,3,4,6,6] }\nassert my_solution.countTestedDevices(**test_input) == 6\n\ntest_input = { \"batteryPercentages\": [5,4,6,0,7,2,2] }\nassert my_solution.countTestedDevices(**test_input) == 4\n\ntest_input = { \"batteryPercentages\": [6,6,7,0,1,7,2] }\nassert my_solution.countTestedDevices(**test_input) == 4\n\ntest_input = { \"batteryPercentages\": [0,5,1,4,5,0,4,8] }\nassert my_solution.countTestedDevices(**test_input) == 5\n\ntest_input = { \"batteryPercentages\": [1,0,7,0,7,4,5,7] }\nassert my_solution.countTestedDevices(**test_input) == 6\n\ntest_input = { \"batteryPercentages\": [2,5,3,4,4,8,6,5] }\nassert my_solution.countTestedDevices(**test_input) == 6\n\ntest_input = { \"batteryPercentages\": [2,6,3,4,5,6,2,6] }\nassert my_solution.countTestedDevices(**test_input) == 6\n\ntest_input = { \"batteryPercentages\": [4,5,2,1,3,7,3,5] }\nassert my_solution.countTestedDevices(**test_input) == 5\n\ntest_input = { \"batteryPercentages\": [6,5,4,8,6,8,3,6] }\nassert my_solution.countTestedDevices(**test_input) == 6\n\ntest_input = { \"batteryPercentages\": [7,4,0,8,5,5,2,0] }\nassert my_solution.countTestedDevices(**test_input) == 5\n\ntest_input = { \"batteryPercentages\": [7,5,3,2,3,5,8,6] }\nassert my_solution.countTestedDevices(**test_input) == 6\n\ntest_input = { \"batteryPercentages\": [8,0,4,3,2,6,6,1] }\nassert my_solution.countTestedDevices(**test_input) == 5\n\ntest_input = { \"batteryPercentages\": [8,3,0,1,0,8,6,8] }\nassert my_solution.countTestedDevices(**test_input) == 5\n\ntest_input = { \"batteryPercentages\": [8,6,7,1,0,1,3,7] }\nassert my_solution.countTestedDevices(**test_input) == 4\n\ntest_input = { \"batteryPercentages\": [0,6,8,8,0,1,2,3,4] }\nassert my_solution.countTestedDevices(**test_input) == 4\n\ntest_input = { \"batteryPercentages\": [2,7,9,7,2,9,0,3,9] }\nassert my_solution.countTestedDevices(**test_input) == 6\n\ntest_input = { \"batteryPercentages\": [8,1,9,8,5,3,4,4,1] }\nassert my_solution.countTestedDevices(**test_input) == 4\n\ntest_input = { \"batteryPercentages\": [8,4,0,1,1,6,5,3,5] }\nassert my_solution.countTestedDevices(**test_input) == 5\n\ntest_input = { \"batteryPercentages\": [8,4,1,5,8,5,8,7,9] }\nassert my_solution.countTestedDevices(**test_input) == 8\n\ntest_input = { \"batteryPercentages\": [8,4,9,8,9,0,0,4,9] }\nassert my_solution.countTestedDevices(**test_input) == 6\n\ntest_input = { \"batteryPercentages\": [8,9,4,4,1,9,8,9,1] }\nassert my_solution.countTestedDevices(**test_input) == 7\n\ntest_input = { \"batteryPercentages\": [2,5,8,9,1,5,10,9,6,3] }\nassert my_solution.countTestedDevices(**test_input) == 7\n\ntest_input = { \"batteryPercentages\": [2,6,5,4,1,5,3,3,3,9] }\nassert my_solution.countTestedDevices(**test_input) == 6\n\ntest_input = { \"batteryPercentages\": [7,7,7,3,6,6,4,3,5,10] }\nassert my_solution.countTestedDevices(**test_input) == 6\n\ntest_input = { \"batteryPercentages\": [9,3,10,1,8,2,4,3,3,0] }\nassert my_solution.countTestedDevices(**test_input) == 4\n\ntest_input = { \"batteryPercentages\": [10,10,2,0,2,7,6,7,10,4] }\nassert my_solution.countTestedDevices(**test_input) == 6\n\ntest_input = { \"batteryPercentages\": [0,8,7,9,4,10,4,3,7,11,7] }\nassert my_solution.countTestedDevices(**test_input) == 7\n\ntest_input = { \"batteryPercentages\": [1,2,3,5,6,11,3,2,11,0,8] }\nassert my_solution.countTestedDevices(**test_input) == 8\n\ntest_input = { \"batteryPercentages\": [5,10,4,10,10,6,8,1,8,10,3] }\nassert my_solution.countTestedDevices(**test_input) == 9\n\ntest_input = { \"batteryPercentages\": [7,10,2,7,11,8,11,4,1,4,5] }\nassert my_solution.countTestedDevices(**test_input) == 6\n\ntest_input = { \"batteryPercentages\": [7,11,0,4,1,10,5,3,2,0,2] }\nassert my_solution.countTestedDevices(**test_input) == 5\n\ntest_input = { \"batteryPercentages\": [8,8,1,8,6,2,5,2,8,5,6] }\nassert my_solution.countTestedDevices(**test_input) == 6\n\ntest_input = { \"batteryPercentages\": [8,9,10,10,1,5,4,6,7,2,4] }\nassert my_solution.countTestedDevices(**test_input) == 7\n\ntest_input = { \"batteryPercentages\": [9,9,2,3,2,2,9,6,11,1,10] }\nassert my_solution.countTestedDevices(**test_input) == 7\n\ntest_input = { \"batteryPercentages\": [10,0,6,2,6,6,11,1,8,10,5] }\nassert my_solution.countTestedDevices(**test_input) == 7\n\ntest_input = { \"batteryPercentages\": [1,4,7,2,12,8,1,11,5,10,2,3] }\nassert my_solution.countTestedDevices(**test_input) == 7\n\ntest_input = { \"batteryPercentages\": [2,5,4,4,9,6,10,0,11,8,2,10] }\nassert my_solution.countTestedDevices(**test_input) == 9\n\ntest_input = { \"batteryPercentages\": [4,11,9,8,9,11,11,5,11,6,12,11] }\nassert my_solution.countTestedDevices(**test_input) == 10", "start_time": 1702175400} +{"task_id": "weekly-contest-375-double-modular-exponentiation", "url": "https://leetcode.com/problems/double-modular-exponentiation", "title": "double-modular-exponentiation", "meta": {"questionId": "3234", "questionFrontendId": "2961", "title": "Double Modular Exponentiation", "titleSlug": "double-modular-exponentiation", "isPaidOnly": false, "difficulty": "Medium", "likes": 87, "dislikes": 12, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0 开始的二维数组 variables ,其中 variables[i] = [ai, bi, ci, mi],以及一个整数 target 。\n如果满足以下公式,则下标 i 是 好下标:\n\n0 <= i < variables.length\n((aibi % 10)ci) % mi == target\n\n返回一个由 好下标 组成的数组,顺序不限 。\n\n示例 1:\n\n输入:variables = [[2,3,3,10],[3,3,3,1],[6,1,1,4]], target = 2\n输出:[0,2]\n解释:对于 variables 数组中的每个下标 i :\n1) 对于下标 0 ,variables[0] = [2,3,3,10] ,(23 % 10)3 % 10 = 2 。\n2) 对于下标 1 ,variables[1] = [3,3,3,1] ,(33 % 10)3 % 1 = 0 。\n3) 对于下标 2 ,variables[2] = [6,1,1,4] ,(61 % 10)1 % 4 = 2 。\n因此,返回 [0,2] 作为答案。\n\n示例 2:\n\n输入:variables = [[39,3,1000,1000]], target = 17\n输出:[]\n解释:对于 variables 数组中的每个下标 i :\n1) 对于下标 0 ,variables[0] = [39,3,1000,1000] ,(393 % 10)1000 % 1000 = 1 。\n因此,返回 [] 作为答案。\n\n\n提示:\n\n1 <= variables.length <= 100\nvariables[i] == [ai, bi, ci, mi]\n1 <= ai, bi, ci, mi <= 103\n0 <= target <= 103\n\"\"\"\nclass Solution:\n def getGoodIndices(self, variables: List[List[int]], target: int) -> List[int]:\n ", "prompt_sft": "给你一个下标从 0 开始的二维数组 variables ,其中 variables[i] = [ai, bi, ci, mi],以及一个整数 target 。\n如果满足以下公式,则下标 i 是 好下标:\n\n0 <= i < variables.length\n((aibi % 10)ci) % mi == target\n\n返回一个由 好下标 组成的数组,顺序不限 。\n\n示例 1:\n\n输入:variables = [[2,3,3,10],[3,3,3,1],[6,1,1,4]], target = 2\n输出:[0,2]\n解释:对于 variables 数组中的每个下标 i :\n1) 对于下标 0 ,variables[0] = [2,3,3,10] ,(23 % 10)3 % 10 = 2 。\n2) 对于下标 1 ,variables[1] = [3,3,3,1] ,(33 % 10)3 % 1 = 0 。\n3) 对于下标 2 ,variables[2] = [6,1,1,4] ,(61 % 10)1 % 4 = 2 。\n因此,返回 [0,2] 作为答案。\n\n示例 2:\n\n输入:variables = [[39,3,1000,1000]], target = 17\n输出:[]\n解释:对于 variables 数组中的每个下标 i :\n1) 对于下标 0 ,variables[0] = [39,3,1000,1000] ,(393 % 10)1000 % 1000 = 1 。\n因此,返回 [] 作为答案。\n\n\n提示:\n\n1 <= variables.length <= 100\nvariables[i] == [ai, bi, ci, mi]\n1 <= ai, bi, ci, mi <= 103\n0 <= target <= 103\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def getGoodIndices(self, variables: List[List[int]], target: int) -> List[int]:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"variables\": [[2,3,3,10],[3,3,3,1],[6,1,1,4]], \"target\": 2 }\nassert my_solution.getGoodIndices(**test_input) == [0,2]\n\ntest_input = { \"variables\": [[39,3,1000,1000]], \"target\": 17 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[3,2,4,2],[3,3,1,3],[2,2,2,4],[4,4,2,3],[2,4,1,3]], \"target\": 4 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[9,2,8,5],[7,8,8,8],[8,9,6,1],[8,6,2,2],[3,6,3,1]], \"target\": 9 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[2,2,3,2],[1,3,3,2],[3,2,2,3],[3,1,2,3],[1,2,3,1],[2,2,2,2],[2,1,3,1],[3,2,2,2],[2,1,3,1],[3,3,1,3]], \"target\": 0 }\nassert my_solution.getGoodIndices(**test_input) == [0,2,3,4,5,6,8]\n\ntest_input = { \"variables\": [[1,3,2,3],[4,2,3,3],[4,1,4,4],[4,2,3,1],[4,2,1,1],[1,2,4,1],[1,1,4,2],[1,4,4,3],[1,2,2,3]], \"target\": 2 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[5,4,1,3],[2,5,5,1],[5,3,4,1]], \"target\": 5 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[4,7,6,7],[7,6,6,4],[6,8,2,3],[8,3,5,8]], \"target\": 4 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[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]], \"target\": 0 }\nassert my_solution.getGoodIndices(**test_input) == [0,1,2,3,4,5,6]\n\ntest_input = { \"variables\": [[3,5,1,2],[3,2,5,2],[4,4,3,2],[3,2,5,3],[1,5,1,4]], \"target\": 1 }\nassert my_solution.getGoodIndices(**test_input) == [0,1,4]\n\ntest_input = { \"variables\": [[1,2,1,1],[2,2,2,2],[1,1,1,2],[1,2,2,2]], \"target\": 2 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[3,3,5,6],[8,2,9,2],[1,4,6,1],[6,4,7,7]], \"target\": 8 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[3,5,4,3],[1,3,3,1],[3,3,5,5],[4,5,5,5],[5,1,4,3],[2,5,3,4]], \"target\": 7 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[9,7,2,7],[9,1,8,1],[9,3,5,6],[6,1,8,4],[9,6,2,3]], \"target\": 8 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[10,6,8,7],[3,6,1,8]], \"target\": 5 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[4,6,5,2],[2,6,4,6],[4,6,3,6],[2,2,6,5],[6,5,5,2]], \"target\": 2 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[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]], \"target\": 1 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[5,6,5,1],[4,3,1,6],[5,4,4,2]], \"target\": 4 }\nassert my_solution.getGoodIndices(**test_input) == [1]\n\ntest_input = { \"variables\": [[5,1,2,4],[4,5,5,5],[5,9,7,4],[7,9,6,3],[1,8,6,1],[1,1,9,9],[3,7,6,5],[2,6,2,6]], \"target\": 1 }\nassert my_solution.getGoodIndices(**test_input) == [0,2,3,5]\n\ntest_input = { \"variables\": [[1,3,2,5],[5,4,1,2],[2,2,3,2],[4,2,5,4],[1,5,4,1],[2,2,5,2],[3,3,2,1],[2,5,4,3],[2,1,5,1]], \"target\": 4 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[3,2,1,3],[1,2,1,1],[2,1,3,2],[2,3,1,3],[3,3,1,1],[2,3,2,1],[2,1,3,3],[1,2,2,2],[3,2,1,3]], \"target\": 1 }\nassert my_solution.getGoodIndices(**test_input) == [7]\n\ntest_input = { \"variables\": [[3,3,2,2],[3,3,2,2]], \"target\": 0 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[1,6,7,5],[6,3,1,5],[7,5,5,4],[6,2,2,4],[6,1,1,2],[2,6,5,4]], \"target\": 8 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[7,8,9,3],[7,8,2,8],[2,4,4,8],[8,8,4,4]], \"target\": 6 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[6,7,6,6],[1,2,4,8],[6,4,2,4],[3,2,4,5]], \"target\": 2 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[2,3,1,1],[3,2,1,1],[2,1,2,3]], \"target\": 2 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[9,8,10,1],[7,1,3,9],[6,8,9,10],[4,8,8,9]], \"target\": 2 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[4,3,2,2],[3,6,4,6],[1,4,1,4],[5,2,5,1],[8,3,6,3],[8,4,8,3]], \"target\": 6 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[3,4,4,2],[4,4,1,2],[1,1,3,2],[3,1,4,3],[2,2,3,4],[2,3,2,4],[3,1,4,4],[1,4,1,4],[3,2,1,4]], \"target\": 0 }\nassert my_solution.getGoodIndices(**test_input) == [1,3,4,5]\n\ntest_input = { \"variables\": [[2,1,1,1],[2,2,2,2],[1,2,1,2],[1,1,1,1],[1,1,1,1],[2,1,2,2],[1,1,2,1],[2,2,2,2]], \"target\": 0 }\nassert my_solution.getGoodIndices(**test_input) == [0,1,3,4,5,6,7]\n\ntest_input = { \"variables\": [[3,1,2,4],[3,3,4,2],[3,4,3,4],[3,3,4,2]], \"target\": 1 }\nassert my_solution.getGoodIndices(**test_input) == [0,1,2,3]\n\ntest_input = { \"variables\": [[4,10,5,8],[7,7,5,8],[4,8,6,2],[6,3,3,2]], \"target\": 4 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[3,5,3,6],[3,1,6,3],[6,4,1,5],[3,2,3,5],[1,4,7,5],[6,6,6,2],[7,5,6,3],[1,2,7,1],[1,1,6,3]], \"target\": 4 }\nassert my_solution.getGoodIndices(**test_input) == [3]\n\ntest_input = { \"variables\": [[1,4,2,3],[4,3,1,4],[3,3,1,3],[1,4,1,3]], \"target\": 0 }\nassert my_solution.getGoodIndices(**test_input) == [1]\n\ntest_input = { \"variables\": [[1,4,2,2],[5,5,1,2],[3,4,2,3]], \"target\": 6 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[3,5,1,1],[4,8,6,8],[5,1,4,9],[4,3,1,2],[5,9,4,7],[8,7,7,1],[9,3,7,5]], \"target\": 0 }\nassert my_solution.getGoodIndices(**test_input) == [0,1,3,5]\n\ntest_input = { \"variables\": [[1,1,1,1],[2,2,2,1],[2,2,2,1],[2,2,2,2],[1,1,1,1],[1,1,1,1],[1,1,1,1]], \"target\": 1 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[5,5,6,5],[4,1,2,2],[6,2,5,3],[1,1,5,5],[3,5,6,5]], \"target\": 2 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[1,4,1,3],[2,4,4,1],[1,1,3,1],[2,3,3,1]], \"target\": 0 }\nassert my_solution.getGoodIndices(**test_input) == [1,2,3]\n\ntest_input = { \"variables\": [[1,1,1,1],[1,1,1,1]], \"target\": 1 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[4,2,1,7],[3,3,7,1],[5,5,8,2],[5,1,3,1]], \"target\": 4 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[1,5,7,2],[2,10,7,10],[6,8,2,2],[9,4,1,2],[1,7,4,1]], \"target\": 3 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[5,5,3,5],[4,2,5,9],[4,6,6,1],[4,5,3,6]], \"target\": 8 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[1,1,2,1],[1,1,3,2],[2,3,3,2],[1,2,3,2],[1,1,1,3],[2,2,1,2]], \"target\": 3 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[4,1,3,5],[4,7,1,6],[7,3,5,4],[2,4,2,7],[6,3,4,7]], \"target\": 7 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[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]], \"target\": 1 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[4,2,3,7],[2,9,6,2],[3,8,9,2],[1,7,7,3],[1,3,8,1],[2,4,5,1],[3,6,3,2],[4,4,6,8]], \"target\": 4 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[8,3,7,1],[7,8,3,2],[4,1,5,3],[6,6,6,3],[2,4,7,5]], \"target\": 2 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[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]], \"target\": 1 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[1,1,6,6],[1,1,1,2],[3,6,6,1],[4,5,5,6],[3,1,6,6],[3,2,2,1],[6,1,1,2]], \"target\": 6 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[4,2,2,1],[6,3,2,1],[2,4,3,2],[1,1,6,6],[4,6,2,1],[5,4,2,1],[1,2,6,1],[6,2,4,4]], \"target\": 6 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[2,2,2,2],[1,2,2,3]], \"target\": 3 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[1,1,1,1],[1,1,1,1]], \"target\": 0 }\nassert my_solution.getGoodIndices(**test_input) == [0,1]\n\ntest_input = { \"variables\": [[2,5,8,2],[2,6,1,2],[7,4,8,9],[6,3,1,4],[7,1,6,7],[4,6,2,7],[8,2,2,7],[4,5,3,8],[1,2,6,4]], \"target\": 2 }\nassert my_solution.getGoodIndices(**test_input) == [3,6]\n\ntest_input = { \"variables\": [[4,2,4,1],[6,1,2,6],[4,3,3,2]], \"target\": 8 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[1,1,1,1],[1,1,1,1],[1,1,1,1],[1,1,1,1]], \"target\": 1 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[6,4,3,5],[7,4,2,6],[1,4,2,1],[4,5,4,5],[7,2,2,7],[7,5,4,3],[2,7,1,3],[6,7,2,2],[4,7,4,1],[7,3,2,1]], \"target\": 1 }\nassert my_solution.getGoodIndices(**test_input) == [0,1,3,5]\n\ntest_input = { \"variables\": [[4,10,5,8],[8,8,9,8],[7,1,5,4],[8,9,2,2],[2,2,8,7],[6,8,10,3],[6,8,4,4],[5,4,10,5],[3,7,8,2]], \"target\": 1 }\nassert my_solution.getGoodIndices(**test_input) == [8]\n\ntest_input = { \"variables\": [[7,5,4,2],[2,1,3,6],[7,2,2,3],[1,4,7,3]], \"target\": 3 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[2,3,3,3],[3,2,1,3],[2,2,3,2],[3,1,2,2],[1,2,2,1],[2,3,3,3],[3,1,2,2]], \"target\": 1 }\nassert my_solution.getGoodIndices(**test_input) == [3,6]\n\ntest_input = { \"variables\": [[10,2,6,2],[8,10,5,7]], \"target\": 0 }\nassert my_solution.getGoodIndices(**test_input) == [0]\n\ntest_input = { \"variables\": [[6,8,3,6],[4,8,3,1],[6,8,6,5],[7,4,7,1],[5,2,1,5],[2,3,5,7],[3,2,6,3],[4,3,7,1]], \"target\": 6 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[5,5,5,1],[6,1,3,2],[3,1,2,6],[2,6,6,5],[6,1,3,6],[4,2,3,1],[2,5,3,5],[6,6,6,2]], \"target\": 4 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[1,1,1,2],[2,1,1,1],[2,1,1,1],[1,1,1,1],[2,1,2,2],[2,2,2,2],[1,1,1,1],[1,2,2,2],[1,2,1,1]], \"target\": 0 }\nassert my_solution.getGoodIndices(**test_input) == [1,2,3,4,5,6,8]\n\ntest_input = { \"variables\": [[9,4,4,9],[9,4,2,6],[7,5,1,4],[9,2,2,3],[6,5,1,2],[2,7,2,9],[1,8,1,6],[5,4,9,7],[8,1,7,4]], \"target\": 1 }\nassert my_solution.getGoodIndices(**test_input) == [0,1,3,5,6]\n\ntest_input = { \"variables\": [[1,3,1,3],[2,1,3,2],[2,2,1,1],[1,2,1,3]], \"target\": 2 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[3,5,5,1],[4,2,6,3],[3,5,6,6],[5,3,1,1],[5,1,3,4],[6,1,6,1]], \"target\": 1 }\nassert my_solution.getGoodIndices(**test_input) == [4]\n\ntest_input = { \"variables\": [[1,2,1,2],[1,2,1,2]], \"target\": 0 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[1,4,2,4],[5,5,3,5],[3,5,3,4],[2,4,5,5],[5,4,4,5],[2,2,2,3]], \"target\": 5 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[1,4,4,4],[5,2,4,4],[1,1,5,3],[3,4,1,2],[3,1,2,3],[4,3,3,3],[3,5,4,1],[2,1,4,5],[3,3,1,3]], \"target\": 1 }\nassert my_solution.getGoodIndices(**test_input) == [0,1,2,3,5,7,8]\n\ntest_input = { \"variables\": [[1,1,6,1],[3,8,4,7],[8,5,5,9],[4,9,1,3],[9,1,1,9]], \"target\": 0 }\nassert my_solution.getGoodIndices(**test_input) == [0,4]\n\ntest_input = { \"variables\": [[2,1,2,2],[2,2,2,1],[2,1,2,2],[1,2,1,1],[2,1,2,2],[2,2,2,2]], \"target\": 1 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[5,7,4,2],[2,8,10,10],[4,4,7,2],[7,4,4,6]], \"target\": 10 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[1,1,1,1],[1,1,1,1],[1,1,1,1],[1,1,1,1],[1,1,1,1],[1,1,1,1]], \"target\": 1 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[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]], \"target\": 0 }\nassert my_solution.getGoodIndices(**test_input) == [0,1,2,3,4,5,6,7,8,9]\n\ntest_input = { \"variables\": [[9,3,6,3],[9,7,2,5],[2,8,9,9],[4,7,7,4],[2,7,3,9],[8,5,5,3],[7,5,4,3],[9,9,2,9],[9,4,8,8]], \"target\": 4 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[7,5,2,3],[1,7,2,3],[9,1,7,1]], \"target\": 3 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[2,5,7,3],[2,6,5,1],[4,3,6,5]], \"target\": 3 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[7,8,1,1],[1,5,4,1],[4,7,8,9],[7,9,2,4],[5,1,4,3],[3,9,4,1],[6,6,1,8],[4,8,5,1],[1,4,5,9]], \"target\": 1 }\nassert my_solution.getGoodIndices(**test_input) == [3,4,8]\n\ntest_input = { \"variables\": [[5,1,6,1],[3,6,5,2],[4,2,5,4],[2,3,5,2],[2,4,3,1],[3,2,3,6],[6,2,4,6],[6,3,3,2]], \"target\": 0 }\nassert my_solution.getGoodIndices(**test_input) == [0,2,3,4,6,7]\n\ntest_input = { \"variables\": [[3,2,5,3],[9,4,2,4],[2,4,7,7],[1,4,9,2],[5,1,5,5],[9,5,6,7],[9,1,4,7]], \"target\": 5 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[3,2,2,2],[3,1,3,2],[2,1,2,2],[3,2,3,3],[1,1,2,3],[1,1,3,1]], \"target\": 0 }\nassert my_solution.getGoodIndices(**test_input) == [2,3,5]\n\ntest_input = { \"variables\": [[1,5,2,1],[3,5,3,2],[1,2,4,1],[1,4,1,4],[4,4,1,3],[4,2,4,5],[2,2,4,1],[2,1,3,3]], \"target\": 4 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[3,2,7,6],[10,6,5,10],[2,4,10,7],[9,5,8,6],[10,6,3,10],[9,6,5,2],[8,10,1,2],[7,1,8,8],[7,7,4,8],[8,3,8,1]], \"target\": 4 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[6,6,5,2],[3,5,4,3],[2,4,3,3],[6,3,4,4],[4,1,3,6],[1,6,3,5],[3,3,5,5]], \"target\": 0 }\nassert my_solution.getGoodIndices(**test_input) == [0,1,2,3]\n\ntest_input = { \"variables\": [[10,3,8,9],[9,1,5,5],[4,5,10,5],[9,8,3,5],[3,5,4,7],[1,10,2,3],[6,2,4,8],[6,4,3,2],[5,9,9,2]], \"target\": 8 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[7,7,4,3],[2,10,10,4],[8,1,9,1],[9,7,7,9],[8,9,8,5],[9,8,4,2],[1,9,3,8],[6,8,3,1]], \"target\": 8 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[9,8,1,4],[5,2,7,4],[5,6,3,4],[9,5,9,8],[2,1,10,10],[10,9,9,2],[8,5,2,3],[10,10,3,8],[1,7,8,1],[1,4,3,5]], \"target\": 2 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[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]], \"target\": 1 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[2,3,4,4],[2,3,7,2],[4,2,6,3],[2,3,3,6],[5,1,2,7],[7,6,7,1]], \"target\": 5 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[3,3,8,8],[2,5,6,5],[8,1,2,3],[1,4,8,7],[8,5,5,7],[6,6,3,9],[5,6,7,1],[4,7,5,1],[1,5,1,5],[5,3,2,1]], \"target\": 2 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[3,1,7,8],[4,3,7,8],[7,4,2,2]], \"target\": 1 }\nassert my_solution.getGoodIndices(**test_input) == [2]\n\ntest_input = { \"variables\": [[4,4,8,8],[4,7,8,7],[1,4,8,2],[5,5,6,4],[7,8,4,3],[8,6,2,1]], \"target\": 1 }\nassert my_solution.getGoodIndices(**test_input) == [2,3,4]\n\ntest_input = { \"variables\": [[2,5,2,5],[1,1,4,1],[3,2,4,3],[3,1,3,4]], \"target\": 1 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[2,2,1,2],[2,2,2,2],[2,2,1,2]], \"target\": 2 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[7,6,4,6],[3,7,2,3],[7,7,1,7],[7,7,6,5],[6,1,1,4],[1,4,2,3],[1,2,4,2],[3,2,2,1],[7,6,2,5],[2,4,5,7]], \"target\": 7 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[1,1,2,1],[1,1,1,2],[1,1,2,1],[2,1,1,2],[1,1,2,1],[2,1,1,1]], \"target\": 2 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[4,5,8,5],[4,2,9,9],[2,3,3,3],[8,6,3,1]], \"target\": 2 }\nassert my_solution.getGoodIndices(**test_input) == [2]\n\ntest_input = { \"variables\": [[4,1,4,2],[3,4,3,4],[5,5,1,5],[5,1,1,4],[4,2,1,5],[5,2,1,1],[1,4,1,4],[1,4,5,5],[5,1,4,5],[1,2,1,2]], \"target\": 2 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[3,1,3,3],[1,2,1,2],[3,1,1,3],[2,2,1,1],[3,3,2,2],[2,3,1,1]], \"target\": 0 }\nassert my_solution.getGoodIndices(**test_input) == [0,2,3,5]", "start_time": 1702175400} +{"task_id": "weekly-contest-375-count-subarrays-where-max-element-appears-at-least-k-times", "url": "https://leetcode.com/problems/count-subarrays-where-max-element-appears-at-least-k-times", "title": "count-subarrays-where-max-element-appears-at-least-k-times", "meta": {"questionId": "3213", "questionFrontendId": "2962", "title": "Count Subarrays Where Max Element Appears at Least K Times", "titleSlug": "count-subarrays-where-max-element-appears-at-least-k-times", "isPaidOnly": false, "difficulty": "Medium", "likes": 215, "dislikes": 10, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个整数数组 nums 和一个 正整数 k 。\n请你统计有多少满足 「nums 中的 最大 元素」至少出现 k 次的子数组,并返回满足这一条件的子数组的数目。\n子数组是数组中的一个连续元素序列。\n\n示例 1:\n\n输入:nums = [1,3,2,3,3], k = 2\n输出:6\n解释:包含元素 3 至少 2 次的子数组为:[1,3,2,3]、[1,3,2,3,3]、[3,2,3]、[3,2,3,3]、[2,3,3] 和 [3,3] 。\n\n示例 2:\n\n输入:nums = [1,4,2,1], k = 3\n输出:0\n解释:没有子数组包含元素 4 至少 3 次。\n\n\n提示:\n\n1 <= nums.length <= 105\n1 <= nums[i] <= 106\n1 <= k <= 105\n\"\"\"\nclass Solution:\n def countSubarrays(self, nums: List[int], k: int) -> int:\n ", "prompt_sft": "给你一个整数数组 nums 和一个 正整数 k 。\n请你统计有多少满足 「nums 中的 最大 元素」至少出现 k 次的子数组,并返回满足这一条件的子数组的数目。\n子数组是数组中的一个连续元素序列。\n\n示例 1:\n\n输入:nums = [1,3,2,3,3], k = 2\n输出:6\n解释:包含元素 3 至少 2 次的子数组为:[1,3,2,3]、[1,3,2,3,3]、[3,2,3]、[3,2,3,3]、[2,3,3] 和 [3,3] 。\n\n示例 2:\n\n输入:nums = [1,4,2,1], k = 3\n输出:0\n解释:没有子数组包含元素 4 至少 3 次。\n\n\n提示:\n\n1 <= nums.length <= 105\n1 <= nums[i] <= 106\n1 <= k <= 105\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def countSubarrays(self, nums: List[int], k: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,3,2,3,3], \"k\": 2 }\nassert my_solution.countSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [1,4,2,1], \"k\": 3 }\nassert my_solution.countSubarrays(**test_input) == 0\n\ntest_input = { \"nums\": [61,23,38,23,56,40,82,56,82,82,82,70,8,69,8,7,19,14,58,42,82,10,82,78,15,82], \"k\": 2 }\nassert my_solution.countSubarrays(**test_input) == 224\n\ntest_input = { \"nums\": [37,20,38,66,34,38,9,41,1,14,25,63,8,12,66,66,60,12,35,27,16,38,12,66,38,36,59,54,66,54,66,48,59,66,34,11,50,66,42,51,53,66,31,24,66,44,66,1,66,66,29,54], \"k\": 5 }\nassert my_solution.countSubarrays(**test_input) == 594\n\ntest_input = { \"nums\": [28,5,58,91,24,91,53,9,48,85,16,70,91,91,47,91,61,4,54,61,49], \"k\": 1 }\nassert my_solution.countSubarrays(**test_input) == 187\n\ntest_input = { \"nums\": [43,105,105,88,19,82,95,32,80,37,49,105,25,105,46,54,45,84,105,88,26,20,49,54,31,105,8,103,37,32,105,105,97,27,105,89,105,47,25,87,29,105,105,105,24,105,105,48,19,91,96,71], \"k\": 7 }\nassert my_solution.countSubarrays(**test_input) == 454\n\ntest_input = { \"nums\": [107,101,180,137,191,148,83,15,188,22,100,124,69,94,191,181,171,64,136,96,91,191,107,191,191,191,107,191,191,11,140,33,4,110,83,5,86,33,42,186,191,6,42,61,94,129,191,119,191,134,43,182,191,187,63,116,172,118,50,141,124,191,125,145,191,34,191,191], \"k\": 9 }\nassert my_solution.countSubarrays(**test_input) == 548\n\ntest_input = { \"nums\": [41,121,92,15,24,59,45,110,97,132,75,72,31,38,103,37,132,91,132,132,105,24], \"k\": 3 }\nassert my_solution.countSubarrays(**test_input) == 61\n\ntest_input = { \"nums\": [21,11,13,15,16,21,8,9,6,21], \"k\": 2 }\nassert my_solution.countSubarrays(**test_input) == 10\n\ntest_input = { \"nums\": [31,18,36,166,166,166,135,166,166,12,102], \"k\": 3 }\nassert my_solution.countSubarrays(**test_input) == 31\n\ntest_input = { \"nums\": [2,2,2,2,1,3,3,2,2,1,1,3,1,1,2,3,2,1,1,2,1,1,2,1,2,1,2,1,3,1,3,3], \"k\": 5 }\nassert my_solution.countSubarrays(**test_input) == 31\n\ntest_input = { \"nums\": [3,2,4,4,3,4,3,1,1,1,1,3,2,1,2,1,3,4,4,1,2,4,1,1,2,3,3,3,4,4,4,1,3,1,4,1,4,4,4,2,2,3,4,3,3,2,2,2,1,2,4,2,2,4,4,1,3,2,3,2,4,4,4,2,3,4,2,4,1,4,1,4,1,4,4,3,4,2,4,3,3,2,3,3,2,3,4,2,1,1,1,2,3], \"k\": 23 }\nassert my_solution.countSubarrays(**test_input) == 473\n\ntest_input = { \"nums\": [1,1,1,2,3,2,1,2,3,3,3,3,2,3,2,1,1,2,2,1,3,2,3,1,2,1,3,1,1,3,1,2,1,1,1,1,1,1,3], \"k\": 8 }\nassert my_solution.countSubarrays(**test_input) == 148\n\ntest_input = { \"nums\": [54,161,161,161,161,31,74,51,87,19,161,116,108,149,6,19,155,101,161,161,154,161,78,132,62,156,112,51,161,42,92,151,142,17,110,85], \"k\": 4 }\nassert my_solution.countSubarrays(**test_input) == 279\n\ntest_input = { \"nums\": [97,102,144,55,144,128,16,93,144,9,144,15,144,144,32,68,144,60,94,56,103,5,41,27,48,144,12,86,129,144,144,99,93,96,144,73,106,76,107,144,53,21,144,144,98,32,85,97,71,127,144,9,144,144,133,125,144,135,52,144,144,46,134,23,23,144,79], \"k\": 1 }\nassert my_solution.countSubarrays(**test_input) == 2163\n\ntest_input = { \"nums\": [17,17,15,9,14,11,15,1,6,2,1,17,3,17,11,12,9,11,2,4,15,17,3,17,8,6,7,12,3,16,2,9,14,17,17,17,3,7,8,9,8,17,17,17,4,2,12,17,7,17,17,16,17,17,8,12,11,3,10,4,10,17,14,7,5,17,12,10,17,13,5,17,8,14,9,17,17,17,7,16,10,13,17,15,1,14,6,8,11,3], \"k\": 15 }\nassert my_solution.countSubarrays(**test_input) == 1055\n\ntest_input = { \"nums\": [17,12,16,17,7,1,12,6,17,5,17,13,16,16,17,14,17,6,17,17,17,17,16,17,14,8,14,1,12,13,17,17,14,8,14,5,16,17,17], \"k\": 5 }\nassert my_solution.countSubarrays(**test_input) == 404\n\ntest_input = { \"nums\": [98,59,98,32,45,15,98,98,98,65,98,10,98,89,87,51,42,58,76,23,85,98,98,35,18,65,39,88,56,62,10,32,8,16,32,98,6,39,14,24,98,95,68,98,77,47,98,23,69,98,49,98,7,11,92,98,27,25,85,98,45,30,50,62,46,1,79,58,69,15,59,57,85,19,98,95,98,67,52,98,59,8,98,98,98,73,86,20,98,96,21,98,79,97,52,22,98,86], \"k\": 12 }\nassert my_solution.countSubarrays(**test_input) == 1168\n\ntest_input = { \"nums\": [6,50,118,27,133,133,3,121,133,72,117,133,91,57,107,93,66,122,133,6,133,122,81,20,133,133,121,133,46,25,133,133,133,17,8,49,133,116,40,133,67,9,133,133,133,133,109,41,127,13,39,133,133,133,122,58,8,125,33,62], \"k\": 12 }\nassert my_solution.countSubarrays(**test_input) == 538\n\ntest_input = { \"nums\": [94,34,112,106,112,13,12,112,112,21,48,71,112,104,112,29,99,58,23,11,49,112,20,86], \"k\": 4 }\nassert my_solution.countSubarrays(**test_input) == 105\n\ntest_input = { \"nums\": [21,27,9,85,1,7,28,11,44,39,85,52,51,30,67,83,75,10,57,59,53,85,75,33,35,85,76,85,65,85,85,85,35,4,60,85,85,72,57,42,34,85,53,85,85,36,85,56,13,16,69,55,81,24,85,27,54,66,10,85,30,58,71,43,85,66,42,27,85,70], \"k\": 13 }\nassert my_solution.countSubarrays(**test_input) == 508\n\ntest_input = { \"nums\": [8,14,7,1,11,10,1,13,7,14,14,6,13], \"k\": 2 }\nassert my_solution.countSubarrays(**test_input) == 32\n\ntest_input = { \"nums\": [165,135,165,46,126,165,73,165,165,155,150,165,40,38,165,145,137,106,10], \"k\": 7 }\nassert my_solution.countSubarrays(**test_input) == 5\n\ntest_input = { \"nums\": [9,3,12,6,24,23,24], \"k\": 2 }\nassert my_solution.countSubarrays(**test_input) == 5\n\ntest_input = { \"nums\": [42,85,78,92,46,63,21,14,22,37,96,50,74], \"k\": 1 }\nassert my_solution.countSubarrays(**test_input) == 33\n\ntest_input = { \"nums\": [73,54,15,4,23,70,53,65,73,73,2,72,36,71,73,69,35,18,62,73,62,73,73,50,30,73,20,71,60,9,12,57,48,73,40,20,8,73,73,73,34,59,31,49,73,5,51,36,47,38,36,58,34,42,23,28,52,73], \"k\": 1 }\nassert my_solution.countSubarrays(**test_input) == 1537\n\ntest_input = { \"nums\": [52,88,92,92,44,4,92,37,27,59,3,3,76,51,21,89,92,31,26,10,47,69,30,68,60,92,80,19,65,38,92,4,54,88,92,75,56,71,11,92,44,43,56,92,16,66,22,70], \"k\": 2 }\nassert my_solution.countSubarrays(**test_input) == 796\n\ntest_input = { \"nums\": [29,9,43,5,8,52,24,52,52,41,33,52,27,52,8,6,35,52,27,52,7,2,9,52,52,42,52,52], \"k\": 7 }\nassert my_solution.countSubarrays(**test_input) == 76\n\ntest_input = { \"nums\": [165,165,58,153,45,124,165,143,38,165,165,165,165,73,8,138,165,139,165,165,59,40,120,165,123,92,98,136,161], \"k\": 1 }\nassert my_solution.countSubarrays(**test_input) == 394\n\ntest_input = { \"nums\": [28,64,64,63,21,64,55,64,10,30,12,5,64,56,63,64,64,31,31,64,19,54,53,64,58,44,64,28,64,64,63,10,64,64,57,29,44,32,50,55,49,21,64,64,34,26,28,64,15,31,28,64,45,64,19,54,9,41,25,33,7,60,1,7,34,14,4,64,64,64,55,49,3,41,28,42,40,52,25,46,25,15], \"k\": 18 }\nassert my_solution.countSubarrays(**test_input) == 229\n\ntest_input = { \"nums\": [97,23,53,33,141,150,128,153,71,39,153,35,125,143], \"k\": 2 }\nassert my_solution.countSubarrays(**test_input) == 32\n\ntest_input = { \"nums\": [144,144,87,144,18,53,129,61,34,123,141,68,37,23,94,28,64,58,16,36,27,112,144,80,77,144,97,142,8,101,14,74,37,115,115,144,99,37,144,48,28,110,13,78,144,144,83,7,112,144,144,144,78,61,87,144,144,61,144,44,123,74,144,142], \"k\": 4 }\nassert my_solution.countSubarrays(**test_input) == 1083\n\ntest_input = { \"nums\": [63,129,134,61,134,134,134,43,74,4,111], \"k\": 2 }\nassert my_solution.countSubarrays(**test_input) == 38\n\ntest_input = { \"nums\": [46,105,44,36,106,35,91,8,52,106,95,86,75,7,19,30,25,27,18,72,106,106,33,106,6,63,67,45,15,106,106,6,42,106,27,14,18,106,4,106,95,64,23,93,106,37,106,106,16,81,91,79,106,97,106,66,31,59,58], \"k\": 1 }\nassert my_solution.countSubarrays(**test_input) == 1637\n\ntest_input = { \"nums\": [78,120,110,53,53,120,116,39,64,120,120,120,120,120,97,28,92,120,101,5,46,92], \"k\": 1 }\nassert my_solution.countSubarrays(**test_input) == 224\n\ntest_input = { \"nums\": [111,111,72,111,111,56,21,95,111,101,38,77,111,111,76,58,70,72,32,72,19,111,111,63,39,111], \"k\": 9 }\nassert my_solution.countSubarrays(**test_input) == 5\n\ntest_input = { \"nums\": [33,82,82,82,71,39,17,82,38,75,82,2,82,82,9,82,57,12,78,65,29,20,82,82,50,11,39,74,65,69,81,71,25,82,46,43,49,80], \"k\": 6 }\nassert my_solution.countSubarrays(**test_input) == 219\n\ntest_input = { \"nums\": [83,72,17,147,147,57,147,22,120,107,59,133,123,91,147,147,72,147,31,147,147,147,96,147,18,25,13,8,18,59,46,91,15,147,25,30,6,147,113,27,84,95,38,147,147,147,106,53,127,132,55,147,22,147,124,102,17,69,131,147,4,95,59,38,147,147,41,99,142,147,136,142,57,26,16,3,142], \"k\": 8 }\nassert my_solution.countSubarrays(**test_input) == 1336\n\ntest_input = { \"nums\": [52,95,173,26,173,16,4,144,173,77,22,103,162,120,77,173,173,89,173,104,62,151,173,124,173,117,113,164,3,70,15,144,161,118,139,16,157,173,154,151,37,69,60,173,173,168,148,97,173,125,161,128,85,64,70,102,100,168,56,57,157,112,119,135,42,72,135,173,173,124,143,121,75,37,162,161,102,50,173,173,107], \"k\": 4 }\nassert my_solution.countSubarrays(**test_input) == 1940\n\ntest_input = { \"nums\": [4,18,6,22,19,15,20,12,22,22,19,6,10,7,20,4,22,21,7,17,3,16,13,17,22,14,8,2,3,22,18,18,22,22,7,22,13,10,20,4,14,17,9,19,1,12,3,11,19,15,6,4,10], \"k\": 6 }\nassert my_solution.countSubarrays(**test_input) == 347\n\ntest_input = { \"nums\": [55,103,123,68,16,72,104,63,40,15,180,162,82,180,131,46,180,2,120,107,100,97,180,180,17,134,180,124,40,125,15,132,4,112,180,180,28,66,180,122,99,46,15,180,180,111,30,169,132,180,10,180,180,180,107,74,95,28,180,66,180,128,61,180,118,180,28,103,37,180,88,152], \"k\": 8 }\nassert my_solution.countSubarrays(**test_input) == 1181\n\ntest_input = { \"nums\": [20,6,49,60,16,54,13,2,35,6,27,62,67,56,27,6,33,51,67,42,9,59,67,14,59,7,67,34,51,5,67,48,53,20,35,67,65,34,67,67,62,7,27,18,40,10,67,67,9,8,60,12,2,67,64,67,60,28,60,26,37,2,67,33,49,23,2,36,67,6,67,7,67,44,18], \"k\": 8 }\nassert my_solution.countSubarrays(**test_input) == 1034\n\ntest_input = { \"nums\": [191,2,46,65,191,166,191,156,157,181,167,123,26,191,191,104,33,126,51,191,191,191,6,152,74,84,126,191,191,162,188,38,30,191,191,125,30,56,12,151,45,163,91,168,15,125,60,4,108,27,67,97,125,147,167,152,191,159,142,105], \"k\": 7 }\nassert my_solution.countSubarrays(**test_input) == 647\n\ntest_input = { \"nums\": [2,4,11,30,23,1,8,18,4,6,30,30,30,10,30,17,24,13,17,30,25,30,30,12,15,29,24,28,21,30,25,11,1,30,9,30,21,3,10,6,30,5,5,24,21,30,17,29,21,30,3,30,8,18,17], \"k\": 7 }\nassert my_solution.countSubarrays(**test_input) == 584\n\ntest_input = { \"nums\": [141,106,141,141,94,98,33,141,2,115,11,141,9,131,104,2,141,75,141,141,24,141,28,68,141,134,141,110,15,21,141,65,108,141,35,95,94,141,117,25], \"k\": 10 }\nassert my_solution.countSubarrays(**test_input) == 94\n\ntest_input = { \"nums\": [139,94,77,139,139,139,139,92,61,105,25,139,93,139,113,128,139,81,70,139,25,139,37,118,15,5,139,115,133,1], \"k\": 3 }\nassert my_solution.countSubarrays(**test_input) == 292\n\ntest_input = { \"nums\": [107,160,86,160,69,160,160,73,120,129,130,104,112,136,7,100,21,160,160,94,3,96,160,65,74,87,110,160,145,116,38,72,127,152,71,24,35,79,160,120,160,80,50,160,129,50,82,160,140,160,3,17,129,18,108,34,132,69,4,160,124,108,30,125,160,102,51,138,160,120,159,160,49,68,160,19,87,160,6,160,76,160,110], \"k\": 16 }\nassert my_solution.countSubarrays(**test_input) == 124\n\ntest_input = { \"nums\": [89,9,89,82,89,11,31,45,61,56,27,15,33,6,5,89,28,73,8,48,11,89,5,89,4,65,18,20,17,38,4,36,59,34,5,81,10,6,44,19,20,86,58,60,27,89,34,29,36,88,89,10,73], \"k\": 7 }\nassert my_solution.countSubarrays(**test_input) == 14\n\ntest_input = { \"nums\": [45,40,44,51,51,33,33,38,46,38,51,40,9,29,51,40,51,36,39,36,51,24,39,51,31,50,12,50,1,51,32,51,49,12,44,19,4,26,7,51,14,4,33,36,19,18,14,20,16,11,51,51,7,18,7,10,8,8,48,51,43,41,51], \"k\": 10 }\nassert my_solution.countSubarrays(**test_input) == 199\n\ntest_input = { \"nums\": [102,4,3,22,78,96,21,126,103,52,99,94,57,126,49,20,75,126,93,1,4,126,122,123,21,111,23,110,126,81,112,92,121,30,41,126,20,10,126,54,15,27,126,126,9,126,126,1,106,34,119,108,126,126,34,57,27,126,110,126,65,125,126,59,117,126,67,114,115,38,79,123,118,126,33,52,1,119,11,105,21,51,75,126,84], \"k\": 9 }\nassert my_solution.countSubarrays(**test_input) == 1500\n\ntest_input = { \"nums\": [71,122,36,39,48,158,83,20,131,41,126,1,33,19,138,133,80,106,92,2,68,158,158,111,158,50,158,81,158,138,108,36,149], \"k\": 4 }\nassert my_solution.countSubarrays(**test_input) == 171\n\ntest_input = { \"nums\": [39,136,153,85,134,19,34,22,5,124,116,91,122,160,112,160,22,111,160,160,113,34,40,16,160,117,61,160,31,34,145,160], \"k\": 6 }\nassert my_solution.countSubarrays(**test_input) == 72\n\ntest_input = { \"nums\": [14,14,1,8,2,11,14,14,5,1,8,1,6,3,14,14,14,2,9,10,14,2,3,14,2,5,5,11,10,11,14,5,3,10,5,3,1,3,14,5,13,9,2,9,3,5,14,14,2,3,10,4,14,14,10,14,2,10,9,2,7,9,11,14,9,5,1,5,13,6,10,1,7,4,13,13,9,10,2,10,3,8,14,3,14,13,1,14,8,12,1,6,12,14,14], \"k\": 14 }\nassert my_solution.countSubarrays(**test_input) == 438\n\ntest_input = { \"nums\": [1,7,4,10,12,10,10,1,12,1,6,6,9,7,10,6,12,10,7,9,6,10,12,8,11,9,8,3,8,3,12,12,12,3,2,2,3,1,10,2,12,12,12,9,10,1,8,10,12,4,8,8,6,2,11,7,3,3,12,12,2,7,8,11,4,3,12,5,8,12,10,2,9,6,5,10,8], \"k\": 7 }\nassert my_solution.countSubarrays(**test_input) == 1236\n\ntest_input = { \"nums\": [1,7,11,13,10,13,8,6,4,11,13,6,1,6,8,10,5,13,4,2,3,7,12,5,1,1,11,13,8,9,1,8], \"k\": 2 }\nassert my_solution.countSubarrays(**test_input) == 262\n\ntest_input = { \"nums\": [73,24,67,11,66,73,73,40,4,47,25,26,48,40,27,69,73,28,23,9,16,8,63,65,73,57,73,21,43,73,19], \"k\": 1 }\nassert my_solution.countSubarrays(**test_input) == 408\n\ntest_input = { \"nums\": [7,47,50,16,35,24,61,44,53,49], \"k\": 1 }\nassert my_solution.countSubarrays(**test_input) == 28\n\ntest_input = { \"nums\": [14,89,43,1,12,64,23,89,55,23,56,69,62,89,89,86,89,89,89,76,84,57,18,54,29,50,67,69,65,3,22,26,8,77,51,74,74,40,89,89,18,74,89,26,16,27,1,66,72,22,78,20,15,14,63,77,73,23,65,89,79,32,18,89,59,16,24,39,87,78,29,84,89,49,80,69,89,44,89,89,58,6,55,38,89,53,89,3,81,28,65,39,30,14,16,89,22,4,23,84], \"k\": 7 }\nassert my_solution.countSubarrays(**test_input) == 2045\n\ntest_input = { \"nums\": [16,11,12,16,5,17,11,13,12,17,16,2,3,13,1,4,10,2,17,17,8,7,4,17,11,17,8,2,15,17,4,16,9,8,17,2,17,16,17,4,6,8,12,17,16,13,4,11,9,11,16,10,17,17,10,13,17,13,1,13,3,7,4,2,15,6,11,12,17,17,7,15,9,16,7,2,17,7,17,16,5,8], \"k\": 8 }\nassert my_solution.countSubarrays(**test_input) == 1317\n\ntest_input = { \"nums\": [52,46,47,52,52,4,2,21,2,26,47,26,52,7,12,35,52,33,47,3,31,37,36,52,38,19,12,40,52,7,40,16,51,41,52,23,20,52,18,52,21,2,52,49,5,48,23,52,52], \"k\": 8 }\nassert my_solution.countSubarrays(**test_input) == 132\n\ntest_input = { \"nums\": [99,155,73,80,32,69,113,37,126,155,95,155,155,48,155,43,37,68,131,68,150,155,153,155,45,59,155,155,155,77,155,155,100,4,127,155,107,151,101,104,155,155,71,147,153,37,155,18,155,100,155,153,155,155,138,4,114,153,111,83,74,144,18,64,94,155,50,45,51,122,146,50,43], \"k\": 8 }\nassert my_solution.countSubarrays(**test_input) == 1346\n\ntest_input = { \"nums\": [64,156,156,119,156,35,108,82,86,18,107,156,68,83,130,86,80,8,129,95,23,7,71,131,19,156,17,21,43,156,25,156,124,51,91,156,77,88,156,156,62,105,135,142,156,156,78,156,113,156,47,156,156,22,71,49,156,57,71,156,36,84,139,156,17,49,156,121,46,7,155,156,156,156,93,150,102,81,90,52,52,91,2,63,156,49,118,77,156,156,156,79], \"k\": 19 }\nassert my_solution.countSubarrays(**test_input) == 590\n\ntest_input = { \"nums\": [24,9,28,46,14,41], \"k\": 1 }\nassert my_solution.countSubarrays(**test_input) == 12\n\ntest_input = { \"nums\": [169,19], \"k\": 1 }\nassert my_solution.countSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [95,109,79,198,195,198,198,97,34,43,165,198,198,195,98,198,198,170,39,78,21,198,140,187,29,107,198,132,198,174,109,187,173,198,58,38,62,179,198,68,114,198,10,198,81,198,40,10,71,82,196,128,50,153,146,101,195], \"k\": 12 }\nassert my_solution.countSubarrays(**test_input) == 182\n\ntest_input = { \"nums\": [9,15,39,33,43,47,15,29,14,12,48,37,9,37,15,48,48,3,1,48,37,39,43,29,43,15,35,2,33,48,28,37,48,45,9,36,3,48,29,14,48,11,24,30,38,18,24,12,47,31,22,10,29,46,14,48,15,29,43,48,37,48,46,14,32,33,15,42,9,12,48,20,35,44,48,4], \"k\": 10 }\nassert my_solution.countSubarrays(**test_input) == 274\n\ntest_input = { \"nums\": [37,12,14,46,29,98,149,149,149,67,97,56,81,71,11,149,32,149,119,149,44,149,43,149,149,32,75,54,24,148,41], \"k\": 2 }\nassert my_solution.countSubarrays(**test_input) == 379\n\ntest_input = { \"nums\": [59,101,127,118,19,55,18,127,127,26,127,103,4,127,26,43,26,125,80,127,127,112,2,107,127,127,110,122,77,127,11,86,127,127,91,27,85,86,71,36,41,127,86,37,11], \"k\": 6 }\nassert my_solution.countSubarrays(**test_input) == 418\n\ntest_input = { \"nums\": [82,82,42,51,82,64,13,16,36,49,22,52,82,10,72,9,6,42,80,74,37,80,73,10,82,31,78,22,14,11,82,60,76,67,82,2,61,52,79,72,77,12,23,33,44,11,82,4,14,65,19,66,56,11,75,82,42,82,56,77,82,81,51,48,19,70,33,51,9,78,62,31,41,46,13,82,82,77,55,24,49,82,82,8,3,44,34], \"k\": 9 }\nassert my_solution.countSubarrays(**test_input) == 427\n\ntest_input = { \"nums\": [30,83,42,83,83,60,61,60,62,83,74,32,83,83,46,82,25,81,31,83,48,15,49,43,41,83,29,36,45,53,83,74,55,63,1,19,74,2,15,83,61,82,46,48,83,83,8,45,83,80,30,33,83,83,83,22,65,79,57,15,24,25,83,83,60,60,83,44,9,29,60,69,2,83,35,7,40,74,55,83,7,21,11,59,5,80], \"k\": 17 }\nassert my_solution.countSubarrays(**test_input) == 200\n\ntest_input = { \"nums\": [11,25,22,14,14,29,6,28,12,14,2,15,29,2,6,27,22,29,26,29,11,1,7,27,24,29,7,29,6], \"k\": 1 }\nassert my_solution.countSubarrays(**test_input) == 371\n\ntest_input = { \"nums\": [173,97,53,181,161,119,152,97,69,181,123,84,83,9,169,135,86,27,119,181,64,147,7,181,154,43,83,181,14,181,45,77,181,83,181,53,181,117,181,27,181,174,181,47], \"k\": 6 }\nassert my_solution.countSubarrays(**test_input) == 302\n\ntest_input = { \"nums\": [124,52,111,24,191,117,128,153,69,190,51,1,112,52,28,191,188,191,1,124,128,111,191,94,34,167,191,191,9,191,164,60,113,69,151,130,15,86,150,191,175,36,113,23,119,68,191,87,90,159,178,50,104,191,187,48,97,100,136,155,140,132,1,180,182,191,130,110,191,191,191,191,191,177,73,118,191,27,129,124,43,140,191,132,191,41,44,191,169,49,191,191,191,191,113,4], \"k\": 7 }\nassert my_solution.countSubarrays(**test_input) == 2434\n\ntest_input = { \"nums\": [86,89,92,23,92,72,41,92,92,92,47,30,46,76,20,80,92,60,20,9,92,92,92,36,4,38,92,74,15,20,92,2,73,58,68,2,29,13,92,91,92,44,46,8,57,10,47,92,6,90,92,92,76,92,86,26,22,67,92,92,17,92,18,23,22,40,7], \"k\": 9 }\nassert my_solution.countSubarrays(**test_input) == 738\n\ntest_input = { \"nums\": [75,65,37,83,80,17,69,83,83,76,64,58,13,83,18,66,25,55,25,60,83,83,83,50,70,39,82,83,47,39,74,83,75,83,34,8,81,46,52,72,45,65,46,2,9,4,23,47,83,83,59,32,54,43,53,56,83], \"k\": 9 }\nassert my_solution.countSubarrays(**test_input) == 256\n\ntest_input = { \"nums\": [23,70,2,70,49,65,6,69,5,26,29,70,70,15,17,22,70,63,51,25,18,68,31,3,43,60,70,6,61,23,46,21,66,67,63,3,7,70,66,47,15,65,52,70,70,38,8,18,29,33,50,9,70,9], \"k\": 1 }\nassert my_solution.countSubarrays(**test_input) == 1305\n\ntest_input = { \"nums\": [23,12,6,3,4,7,23,23,6,23,23,9,23,2,14,11,21,23,8,9,19,10,17,23,11,3,13,23,18,3,6,7,6,19,17,14,17,7,23,21,10,22,6,23,23,3,1,20,14,7,19,20,23,19,23,15,4,23,2,6,20,23,8,6,17,14,23,6,10,23,17,6,11,8,3,6,23,16,19,16,2,19,2,23,1,16,20,4,20,12,1], \"k\": 11 }\nassert my_solution.countSubarrays(**test_input) == 942\n\ntest_input = { \"nums\": [199,146,138,199,97,169,199,198,199,199,11,62,68,122,193,199,22,41,199,181,199,157,199,44,199,199,199,142,132,112,199,199,155,199,97,101,26,52,199,45,164,112,188,97,180,103,199,3,130,64,131,199,194,135,36,199,80,67,41,67,158,183,188,12,126], \"k\": 13 }\nassert my_solution.countSubarrays(**test_input) == 420\n\ntest_input = { \"nums\": [25,32,40,47,35,9,39,58,67,42,77,57,77,77,34,28,13,77,15,33,77,10,64,67,35,21,61,60,74,57,77,71,28,77,48,67,17,48,77,77,77,60,26,30,77,49,77,3,77,33,75,77,20,77,77], \"k\": 9 }\nassert my_solution.countSubarrays(**test_input) == 325\n\ntest_input = { \"nums\": [50,108,19,118,46,45,126,118,89,126,46,63,30,126,120,10,126,126,108,95,126,94], \"k\": 3 }\nassert my_solution.countSubarrays(**test_input) == 107\n\ntest_input = { \"nums\": [28,94,94,5,1,74,33,3,88,76,78,30], \"k\": 1 }\nassert my_solution.countSubarrays(**test_input) == 32\n\ntest_input = { \"nums\": [44,4,4,31,33,51,51,40,51,2,27,48,51,6,51,27,45,1,25,2,20,43,51,12,11,44,40,28,29,51,51,45,30,24,51,51,30,51,13,18,29,51,15,11,39], \"k\": 11 }\nassert my_solution.countSubarrays(**test_input) == 52\n\ntest_input = { \"nums\": [6,30,19,32,24,8,28,2,18,32,5,31,3,31,28,30,30,22,32,22,31,1,9,2,7,32,14,24,24,6,23,6,25,32,32,22,10,11,4,2,32,18,15,1,22,20,6,26,11,13,26,22,32,30,18], \"k\": 4 }\nassert my_solution.countSubarrays(**test_input) == 570\n\ntest_input = { \"nums\": [17,41,71,95,56,88,25,95,73,95,91,95,8,43,2,52,95,88,5,49,20,48,95,84,95,44,27,95,87,32,45,95,95,95,51,56,6,5,65,21,52,56,84,95,75,33,95,62,47,95], \"k\": 13 }\nassert my_solution.countSubarrays(**test_input) == 20\n\ntest_input = { \"nums\": [5,12,6,13,11,13,9,13,10,13,13,12,7,11,2,11,4,7,6,6,13,9,1,12,13,11,7,11,11,13,2,13,7,4,9,5,13,8,4,1,2,5,13,7,7,12,2,2,8,11,12,1,8,5,3,6,4,2,9,10,6,6,13,12,13,6,13,13,13,13,13,3,4,4,10,1,2,12,12,13,13,6,13,4,13,1,12,11,9,12,2,5], \"k\": 3 }\nassert my_solution.countSubarrays(**test_input) == 3240\n\ntest_input = { \"nums\": [13,16,2,27,10,2,44,44,44,28,44,44,23], \"k\": 4 }\nassert my_solution.countSubarrays(**test_input) == 23\n\ntest_input = { \"nums\": [69,46,80,10,80,48,76,15,67,1,80,80,34,4,14,15,2,38,62,31,17,56,58,17,38,29,67], \"k\": 4 }\nassert my_solution.countSubarrays(**test_input) == 48\n\ntest_input = { \"nums\": [39,38,136,136,97,122,54,102,112,125,135,57,136], \"k\": 1 }\nassert my_solution.countSubarrays(**test_input) == 52\n\ntest_input = { \"nums\": [39,67,17,52,89,63,52,8,14,90,76,2,90,65,90,80,90,33,61,76,90,32,43,55,62,24,29,90,35,36,90,8,40,1,72,54,64,90,58,88,77,89,35,79,90,81,90], \"k\": 2 }\nassert my_solution.countSubarrays(**test_input) == 822\n\ntest_input = { \"nums\": [16,22,10,22,4,16,16,15,3,22,22,15,7,7,21,17,16,1,10,13,16,17,2,18,2,5,11], \"k\": 3 }\nassert my_solution.countSubarrays(**test_input) == 70\n\ntest_input = { \"nums\": [120,58,118,34,32,110,94,10,119,133,70,154,151,107,124,148,154,154,24,154,6,83,20,6,3,72,154,28,148,107,154,73,126,154,41], \"k\": 5 }\nassert my_solution.countSubarrays(**test_input) == 135\n\ntest_input = { \"nums\": [15,2,1,21,20,33,16,19], \"k\": 1 }\nassert my_solution.countSubarrays(**test_input) == 18\n\ntest_input = { \"nums\": [45,25], \"k\": 1 }\nassert my_solution.countSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [179,127,54,149,90,119,179,127,115,82,159,128,6,55,33,43,2,172,105,159,83,179,30,179,175,125,179,179,105,179,74,77,179,153,145,124,70,179,129,31,62,172,179,29,130,179,82,64,98,179,91,179,89,166,60,159,54,179,179,137,54,158,64,177,56,165,97,142,90,170,179,127,111,179,145,179,8], \"k\": 16 }\nassert my_solution.countSubarrays(**test_input) == 61\n\ntest_input = { \"nums\": [25,41,11,41,26,30,41,34,31,41,40,23,14,41,10,34,8,15,41,10,14,41,37,20,37,35,37,8,21,30,11,7,33,3,25,1,3,38,27,26,27,20,29,41,30,7,23,15,41,41,41,25,18,41,19,41,34,35,33,41,4,41,15], \"k\": 3 }\nassert my_solution.countSubarrays(**test_input) == 1227\n\ntest_input = { \"nums\": [7,6,3,9,6,3,4,4,9,7,3,3,8,9,2,4,8,8,8,6,3,2,9,9,9,4,2,6,9,3], \"k\": 1 }\nassert my_solution.countSubarrays(**test_input) == 396\n\ntest_input = { \"nums\": [158,2,138,177,96,104,175,81,46,19,85,1,174,177,115,145,32,177,174,95,96,101,177,114,115,137,77,98,15,177,125,162,177,177,111,106,112,177,174,40,177,177,176,40,177,145,177,99,177,177,163,177,143,147,177,11,142,177,44,171,52,98,177,163,140,139,61,147,71,20,177,45,172], \"k\": 5 }\nassert my_solution.countSubarrays(**test_input) == 1642\n\ntest_input = { \"nums\": [3,1], \"k\": 1 }\nassert my_solution.countSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [99,166,166,5,166,44,83,73,40,64,166,135,166,24,166,41,70,93,166,166,166,49,157,3,135,137,1,133,18,166,15,82,4,166,13,55,95,166,166,151,102,166,166,34,32,31,48,166,166,13,166,166,94,28,166,166,119,103,157,12,103,19,126,13,117,71,85,166,166,81,132,105,128,166,166,125,73,161,166,139,6,32,5,31,137], \"k\": 24 }\nassert my_solution.countSubarrays(**test_input) == 49\n\ntest_input = { \"nums\": [121,135,135,135,57,18,7,22,135,57,96,72,23,68,32,39,135,135,135,135,51,25,100,49,72,135,99,38,126,110,52,63,48,135,135,132,111,114,135,135,24,125,135,135,120,93,55,40,135,44,135,22,135,48,35,12,116,79,80,22,135,135,111,135], \"k\": 20 }\nassert my_solution.countSubarrays(**test_input) == 7", "start_time": 1702175400} +{"task_id": "weekly-contest-375-count-the-number-of-good-partitions", "url": "https://leetcode.com/problems/count-the-number-of-good-partitions", "title": "count-the-number-of-good-partitions", "meta": {"questionId": "3212", "questionFrontendId": "2963", "title": "Count the Number of Good Partitions", "titleSlug": "count-the-number-of-good-partitions", "isPaidOnly": false, "difficulty": "Hard", "likes": 163, "dislikes": 1, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0 开始、由 正整数 组成的数组 nums。\n将数组分割成一个或多个 连续 子数组,如果不存在包含了相同数字的两个子数组,则认为是一种 好分割方案 。\n返回 nums 的 好分割方案 的 数目。\n由于答案可能很大,请返回答案对 109 + 7 取余 的结果。\n\n示例 1:\n\n输入:nums = [1,2,3,4]\n输出:8\n解释:有 8 种 好分割方案 :([1], [2], [3], [4]), ([1], [2], [3,4]), ([1], [2,3], [4]), ([1], [2,3,4]), ([1,2], [3], [4]), ([1,2], [3,4]), ([1,2,3], [4]) 和 ([1,2,3,4]) 。\n\n示例 2:\n\n输入:nums = [1,1,1,1]\n输出:1\n解释:唯一的 好分割方案 是:([1,1,1,1]) 。\n\n示例 3:\n\n输入:nums = [1,2,1,3]\n输出:2\n解释:有 2 种 好分割方案 :([1,2,1], [3]) 和 ([1,2,1,3]) 。\n\n\n提示:\n\n1 <= nums.length <= 105\n1 <= nums[i] <= 109\n\"\"\"\nclass Solution:\n def numberOfGoodPartitions(self, nums: List[int]) -> int:\n ", "prompt_sft": "给你一个下标从 0 开始、由 正整数 组成的数组 nums。\n将数组分割成一个或多个 连续 子数组,如果不存在包含了相同数字的两个子数组,则认为是一种 好分割方案 。\n返回 nums 的 好分割方案 的 数目。\n由于答案可能很大,请返回答案对 109 + 7 取余 的结果。\n\n示例 1:\n\n输入:nums = [1,2,3,4]\n输出:8\n解释:有 8 种 好分割方案 :([1], [2], [3], [4]), ([1], [2], [3,4]), ([1], [2,3], [4]), ([1], [2,3,4]), ([1,2], [3], [4]), ([1,2], [3,4]), ([1,2,3], [4]) 和 ([1,2,3,4]) 。\n\n示例 2:\n\n输入:nums = [1,1,1,1]\n输出:1\n解释:唯一的 好分割方案 是:([1,1,1,1]) 。\n\n示例 3:\n\n输入:nums = [1,2,1,3]\n输出:2\n解释:有 2 种 好分割方案 :([1,2,1], [3]) 和 ([1,2,1,3]) 。\n\n\n提示:\n\n1 <= nums.length <= 105\n1 <= nums[i] <= 109\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def numberOfGoodPartitions(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,2,3,4] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 8\n\ntest_input = { \"nums\": [1,1,1,1] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,1,3] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 2\n\ntest_input = { \"nums\": [1] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 1\n\ntest_input = { \"nums\": [100000] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 1\n\ntest_input = { \"nums\": [1000000000] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,1,3,2] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 4\n\ntest_input = { \"nums\": [1,1,1,9,7] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 4\n\ntest_input = { \"nums\": [1,1,5,9,2] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 8\n\ntest_input = { \"nums\": [1,4,1,7,5] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 4\n\ntest_input = { \"nums\": [1,5,1,5,6] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 2\n\ntest_input = { \"nums\": [1,5,1,10,8] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 4\n\ntest_input = { \"nums\": [1,6,8,1,5] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 2\n\ntest_input = { \"nums\": [1,6,9,4,10] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 16\n\ntest_input = { \"nums\": [1,7,1,6,8] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 4\n\ntest_input = { \"nums\": [1,9,1,1,7] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 2\n\ntest_input = { \"nums\": [2,1,6,7,5] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 16\n\ntest_input = { \"nums\": [2,3,2,6,9] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 4\n\ntest_input = { \"nums\": [2,3,2,8,8] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 2\n\ntest_input = { \"nums\": [2,3,9,2,6] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 2\n\ntest_input = { \"nums\": [2,4,2,7,4] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 1\n\ntest_input = { \"nums\": [2,4,7,1,2] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 1\n\ntest_input = { \"nums\": [2,5,1,2,2] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 1\n\ntest_input = { \"nums\": [2,5,1,4,9] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 16\n\ntest_input = { \"nums\": [2,5,6,4,2] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 1\n\ntest_input = { \"nums\": [2,6,1,9,5] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 16\n\ntest_input = { \"nums\": [2,7,8,9,3] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 16\n\ntest_input = { \"nums\": [2,9,1,2,4] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 2\n\ntest_input = { \"nums\": [2,10,4,2,3] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 2\n\ntest_input = { \"nums\": [3,3,3,9,9] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 2\n\ntest_input = { \"nums\": [3,3,8,1,6] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 8\n\ntest_input = { \"nums\": [3,3,10,4,2] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 8\n\ntest_input = { \"nums\": [3,4,5,1,7] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 16\n\ntest_input = { \"nums\": [3,7,6,4,9] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 16\n\ntest_input = { \"nums\": [3,8,10,7,6] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 16\n\ntest_input = { \"nums\": [3,10,10,10,4] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 4\n\ntest_input = { \"nums\": [4,1,2,3,10] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 16\n\ntest_input = { \"nums\": [4,1,7,9,4] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 1\n\ntest_input = { \"nums\": [4,8,4,8,6] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 2\n\ntest_input = { \"nums\": [5,1,1,9,3] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 8\n\ntest_input = { \"nums\": [5,2,8,10,4] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 16\n\ntest_input = { \"nums\": [5,3,6,6,6] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 4\n\ntest_input = { \"nums\": [5,3,8,8,2] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 8\n\ntest_input = { \"nums\": [5,4,5,9,9] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 2\n\ntest_input = { \"nums\": [5,4,10,2,4] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 2\n\ntest_input = { \"nums\": [5,5,7,3,1] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 8\n\ntest_input = { \"nums\": [5,5,8,4,1] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 8\n\ntest_input = { \"nums\": [5,9,1,9,2] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 4\n\ntest_input = { \"nums\": [5,10,1,1,6] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 8\n\ntest_input = { \"nums\": [6,1,7,9,10] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 16\n\ntest_input = { \"nums\": [6,3,5,1,10] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 16\n\ntest_input = { \"nums\": [6,3,9,9,3] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 2\n\ntest_input = { \"nums\": [6,6,5,5,8] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 4\n\ntest_input = { \"nums\": [6,7,3,3,8] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 8\n\ntest_input = { \"nums\": [6,8,6,5,7] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 4\n\ntest_input = { \"nums\": [6,9,10,5,8] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 16\n\ntest_input = { \"nums\": [6,10,2,6,10] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 1\n\ntest_input = { \"nums\": [6,10,5,4,3] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 16\n\ntest_input = { \"nums\": [7,1,2,3,5] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 16\n\ntest_input = { \"nums\": [7,1,9,2,1] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 2\n\ntest_input = { \"nums\": [7,2,1,2,6] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 4\n\ntest_input = { \"nums\": [7,5,1,10,10] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 8\n\ntest_input = { \"nums\": [7,5,7,4,6] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 4\n\ntest_input = { \"nums\": [7,5,8,4,6] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 16\n\ntest_input = { \"nums\": [7,9,4,8,7] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 1\n\ntest_input = { \"nums\": [7,9,8,8,4] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 8\n\ntest_input = { \"nums\": [8,2,2,5,6] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 8\n\ntest_input = { \"nums\": [8,3,2,1,9] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 16\n\ntest_input = { \"nums\": [8,3,4,9,7] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 16\n\ntest_input = { \"nums\": [8,3,6,5,1] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 16\n\ntest_input = { \"nums\": [8,3,8,3,4] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 2\n\ntest_input = { \"nums\": [8,3,8,3,10] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 2\n\ntest_input = { \"nums\": [8,4,4,5,8] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 1\n\ntest_input = { \"nums\": [8,4,8,10,9] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 4\n\ntest_input = { \"nums\": [8,5,5,3,9] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 8\n\ntest_input = { \"nums\": [8,7,4,2,1] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 16\n\ntest_input = { \"nums\": [8,7,6,10,1] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 16\n\ntest_input = { \"nums\": [8,9,7,3,6] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 16\n\ntest_input = { \"nums\": [8,10,5,9,9] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 8\n\ntest_input = { \"nums\": [9,1,2,2,3] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 8\n\ntest_input = { \"nums\": [9,1,4,3,7] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 16\n\ntest_input = { \"nums\": [9,1,7,8,9] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 1\n\ntest_input = { \"nums\": [9,2,7,5,10] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 16\n\ntest_input = { \"nums\": [9,3,6,5,5] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 8\n\ntest_input = { \"nums\": [9,4,7,1,1] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 8\n\ntest_input = { \"nums\": [9,5,5,8,3] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 8\n\ntest_input = { \"nums\": [9,7,2,7,10] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 4\n\ntest_input = { \"nums\": [9,7,8,3,2] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 16\n\ntest_input = { \"nums\": [9,8,2,5,5] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 8\n\ntest_input = { \"nums\": [9,8,2,10,7] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 16\n\ntest_input = { \"nums\": [9,8,3,7,6] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 16\n\ntest_input = { \"nums\": [9,8,6,6,8] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 2\n\ntest_input = { \"nums\": [9,8,8,2,1] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 8\n\ntest_input = { \"nums\": [9,8,9,5,7] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 4\n\ntest_input = { \"nums\": [10,1,3,2,3] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 4\n\ntest_input = { \"nums\": [10,1,10,3,5] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 4\n\ntest_input = { \"nums\": [10,2,1,4,1] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 4\n\ntest_input = { \"nums\": [10,3,1,3,4] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 4\n\ntest_input = { \"nums\": [10,5,6,2,8] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 16\n\ntest_input = { \"nums\": [10,6,5,10,2] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 2", "start_time": 1702175400} +{"task_id": "biweekly-contest-119-find-common-elements-between-two-arrays", "url": "https://leetcode.com/problems/find-common-elements-between-two-arrays", "title": "find-common-elements-between-two-arrays", "meta": {"questionId": "3206", "questionFrontendId": "2956", "title": "Find Common Elements Between Two Arrays", "titleSlug": "find-common-elements-between-two-arrays", "isPaidOnly": false, "difficulty": "Easy", "likes": 66, "dislikes": 25, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你两个下标从 0开始的整数数组nums1和nums2,它们分别含有 n和 m个元素。\n请你计算以下两个数值:\n\n统计0 <= i < n中的下标i,满足nums1[i]在 nums2中 至少出现了一次。\n统计0 <= i < m中的下标i,满足nums2[i]在 nums1中 至少出现了一次。\n\n请你返回一个长度为 2的整数数组answer,按顺序分别为以上两个数值。\n\n示例 1:\n\n输入:nums1 = [4,3,2,3,1], nums2 = [2,2,5,2,3,6]\n输出:[3,4]\n解释:分别计算两个数值:\n- nums1 中下标为 1 ,2 和 3 的元素在 nums2 中至少出现了一次,所以第一个值为 3 。\n- nums2 中下标为 0 ,1 ,3 和 4 的元素在 nums1 中至少出现了一次,所以第二个值为 4 。\n\n示例 2:\n\n输入:nums1 = [3,4,2,3], nums2 = [1,5]\n输出:[0,0]\n解释:两个数组中没有公共元素,所以两个值都为 0 。\n\n\n提示:\n\nn == nums1.length\nm == nums2.length\n1 <= n, m <= 100\n1 <= nums1[i], nums2[i] <= 100\n\"\"\"\nclass Solution:\n def findIntersectionValues(self, nums1: List[int], nums2: List[int]) -> List[int]:\n ", "prompt_sft": "给你两个下标从 0开始的整数数组nums1和nums2,它们分别含有 n和 m个元素。\n请你计算以下两个数值:\n\n统计0 <= i < n中的下标i,满足nums1[i]在 nums2中 至少出现了一次。\n统计0 <= i < m中的下标i,满足nums2[i]在 nums1中 至少出现了一次。\n\n请你返回一个长度为 2的整数数组answer,按顺序分别为以上两个数值。\n\n示例 1:\n\n输入:nums1 = [4,3,2,3,1], nums2 = [2,2,5,2,3,6]\n输出:[3,4]\n解释:分别计算两个数值:\n- nums1 中下标为 1 ,2 和 3 的元素在 nums2 中至少出现了一次,所以第一个值为 3 。\n- nums2 中下标为 0 ,1 ,3 和 4 的元素在 nums1 中至少出现了一次,所以第二个值为 4 。\n\n示例 2:\n\n输入:nums1 = [3,4,2,3], nums2 = [1,5]\n输出:[0,0]\n解释:两个数组中没有公共元素,所以两个值都为 0 。\n\n\n提示:\n\nn == nums1.length\nm == nums2.length\n1 <= n, m <= 100\n1 <= nums1[i], nums2[i] <= 100\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def findIntersectionValues(self, nums1: List[int], nums2: List[int]) -> List[int]:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums1\": [4,3,2,3,1], \"nums2\": [2,2,5,2,3,6] }\nassert my_solution.findIntersectionValues(**test_input) == [3,4]\n\ntest_input = { \"nums1\": [3,4,2,3], \"nums2\": [1,5] }\nassert my_solution.findIntersectionValues(**test_input) == [0,0]\n\ntest_input = { \"nums1\": [24,28,7,27,7,27,9,24,9,10], \"nums2\": [12,29,9,7,5] }\nassert my_solution.findIntersectionValues(**test_input) == [4,2]\n\ntest_input = { \"nums1\": [10,30,16,18], \"nums2\": [23,30,30,6,10,26,9,27,6,16,18,10,27,2,20,7,16] }\nassert my_solution.findIntersectionValues(**test_input) == [4,7]\n\ntest_input = { \"nums1\": [7,23,27,20,21,29,7,27,27,18,7,6,20,10], \"nums2\": [27,27,28,24,20,4,6,17,9,29,20,14,20] }\nassert my_solution.findIntersectionValues(**test_input) == [7,7]\n\ntest_input = { \"nums1\": [15,30,6,6], \"nums2\": [15,4,16,10,7,23,24,3,4,6,14,8,18,1,29,27,2,17] }\nassert my_solution.findIntersectionValues(**test_input) == [3,2]\n\ntest_input = { \"nums1\": [24,7,8,6,22,28,22,28,7,19], \"nums2\": [3,7,28,7,3,3] }\nassert my_solution.findIntersectionValues(**test_input) == [4,3]\n\ntest_input = { \"nums1\": [23,4,26,17,23,13], \"nums2\": [24,17,20,16,1,13,17,28,17] }\nassert my_solution.findIntersectionValues(**test_input) == [2,4]\n\ntest_input = { \"nums1\": [5,8,18,27,16,29,27,12,1,29,16,27,22,19,14,12,11,25], \"nums2\": [24,8,16] }\nassert my_solution.findIntersectionValues(**test_input) == [3,2]\n\ntest_input = { \"nums1\": [29,17,30,17,15,30,11,2,24,28,28,30,30,27,30,2,30,9,1,7], \"nums2\": [12,12,11,21,2,28,5,24,12,17,24,29,22,19,11,17,1,23] }\nassert my_solution.findIntersectionValues(**test_input) == [10,10]\n\ntest_input = { \"nums1\": [4,27,12,16,16,21,26,7,19,21,24,26,12,24,22,12,16], \"nums2\": [1,25,8,27,23,27,27,24] }\nassert my_solution.findIntersectionValues(**test_input) == [3,4]\n\ntest_input = { \"nums1\": [27,19,20,16,24,27,27,24], \"nums2\": [30,21,21,6,17,16] }\nassert my_solution.findIntersectionValues(**test_input) == [1,1]\n\ntest_input = { \"nums1\": [3,19,21,5,24,26,22,22,5], \"nums2\": [23,26,20,14,30,9,10,24,19,22,19,6,3,20,22,22,5,24,24] }\nassert my_solution.findIntersectionValues(**test_input) == [8,11]\n\ntest_input = { \"nums1\": [13,13,29,12], \"nums2\": [29,29,13,7,30,22] }\nassert my_solution.findIntersectionValues(**test_input) == [3,3]\n\ntest_input = { \"nums1\": [30,4,16,14,14,14,20,15,20,30,6,10,14], \"nums2\": [30,16,20,2,18,10,5,6,30,20,22,18,14,23,15] }\nassert my_solution.findIntersectionValues(**test_input) == [12,9]\n\ntest_input = { \"nums1\": [22,1,22,4,11,22,4,20,11,29,11,11,4,26,20,12,20,8,26,17], \"nums2\": [4,17,7,15] }\nassert my_solution.findIntersectionValues(**test_input) == [4,2]\n\ntest_input = { \"nums1\": [30,15,16,15,11,16,26,15,21], \"nums2\": [22,25,27,2,26,20,18,15,26,20,16] }\nassert my_solution.findIntersectionValues(**test_input) == [6,4]\n\ntest_input = { \"nums1\": [5,6], \"nums2\": [13,12,8,5,19,13,27] }\nassert my_solution.findIntersectionValues(**test_input) == [1,1]\n\ntest_input = { \"nums1\": [27,28,15,20,5,13,28,29,24,29,20,15,5,20,20,25,9,20,24,20], \"nums2\": [16,20,13,24,11] }\nassert my_solution.findIntersectionValues(**test_input) == [9,3]\n\ntest_input = { \"nums1\": [25,7,18], \"nums2\": [28,1,14,22,24,8,25,17] }\nassert my_solution.findIntersectionValues(**test_input) == [1,1]\n\ntest_input = { \"nums1\": [10,15], \"nums2\": [4,10,15,28] }\nassert my_solution.findIntersectionValues(**test_input) == [2,2]\n\ntest_input = { \"nums1\": [11,11,25], \"nums2\": [11,28,25,13,23,11] }\nassert my_solution.findIntersectionValues(**test_input) == [3,3]\n\ntest_input = { \"nums1\": [10,30,27,8,8,5,11,12,17,13,14,27,17,19,13,20,27], \"nums2\": [10,14,25,2,17,29,10,9,5,30,15,27] }\nassert my_solution.findIntersectionValues(**test_input) == [9,7]\n\ntest_input = { \"nums1\": [19,22,22,22,22,29,22,28,29], \"nums2\": [7,28,29,22,16,22,22,4,17,11,22,22,22,25,25] }\nassert my_solution.findIntersectionValues(**test_input) == [8,8]\n\ntest_input = { \"nums1\": [18,1,23,1,1], \"nums2\": [16,9,1,4,15,11] }\nassert my_solution.findIntersectionValues(**test_input) == [3,1]\n\ntest_input = { \"nums1\": [30,11,15,1,15,6,5,26,15,15], \"nums2\": [1,20,19,30,17,10,6,15] }\nassert my_solution.findIntersectionValues(**test_input) == [7,4]\n\ntest_input = { \"nums1\": [17,6,30,30,15,30,22,2,18,22,21,21,17,19,25,30,18,30,1], \"nums2\": [2,16,25,5,25,1,14,11] }\nassert my_solution.findIntersectionValues(**test_input) == [3,4]\n\ntest_input = { \"nums1\": [3,21,21,23,14], \"nums2\": [1,28,1,3,27,15,28,29,22,14,8,24] }\nassert my_solution.findIntersectionValues(**test_input) == [2,2]\n\ntest_input = { \"nums1\": [8,20,29,23,29,2,2,2,20], \"nums2\": [2,24,20,28,11,8,6,25] }\nassert my_solution.findIntersectionValues(**test_input) == [6,3]\n\ntest_input = { \"nums1\": [22,27,4,27,30,22,25,8,8,30,1,16,1], \"nums2\": [9,21,8,12] }\nassert my_solution.findIntersectionValues(**test_input) == [2,1]\n\ntest_input = { \"nums1\": [19,11,13,1,26,25,19,24,3,10,1,11,1,15,20,20,26,13,13], \"nums2\": [13,23] }\nassert my_solution.findIntersectionValues(**test_input) == [3,1]\n\ntest_input = { \"nums1\": [21,16,11,21], \"nums2\": [21,11,21,2,2,8,16,29,16,16,18,14,18,16,29,10,2] }\nassert my_solution.findIntersectionValues(**test_input) == [4,7]\n\ntest_input = { \"nums1\": [15,7,23,12,23,16,18,1,16,28,28,19,7,30,19], \"nums2\": [9,1,10,15,23,8,8,24,30] }\nassert my_solution.findIntersectionValues(**test_input) == [5,4]\n\ntest_input = { \"nums1\": [2,2,22,24,20,22,1,27,27,10,8,26,22,22,22,10,13,29], \"nums2\": [8,11,1,11] }\nassert my_solution.findIntersectionValues(**test_input) == [2,2]\n\ntest_input = { \"nums1\": [25,29,15,15,21,14,10,23,10,18,11,30,28,16,29], \"nums2\": [1,16,10,2,25,1,15] }\nassert my_solution.findIntersectionValues(**test_input) == [6,4]\n\ntest_input = { \"nums1\": [18,18,11,27,18,20,20], \"nums2\": [16,28,25,28,20,15,8,21,4,6,19,20,20,20,29] }\nassert my_solution.findIntersectionValues(**test_input) == [2,4]\n\ntest_input = { \"nums1\": [1,25,15,20,25,11,4,1,1,21,17,1,19], \"nums2\": [19,19,9,23,1,5,28,28,17,28,3,9,8] }\nassert my_solution.findIntersectionValues(**test_input) == [6,4]\n\ntest_input = { \"nums1\": [7,30,7,7,30,2,7,7], \"nums2\": [19,7,1,7,17,17,20,7,21,30,8,21,10,30,14] }\nassert my_solution.findIntersectionValues(**test_input) == [7,5]\n\ntest_input = { \"nums1\": [7,18,13,27,13,9,22,30], \"nums2\": [27,29,21,30,16,13,29,5,9,16,29,27] }\nassert my_solution.findIntersectionValues(**test_input) == [5,5]\n\ntest_input = { \"nums1\": [19,19,25,24,24,3,19,24,3], \"nums2\": [16,19,19,17,19,24,5,19] }\nassert my_solution.findIntersectionValues(**test_input) == [6,5]\n\ntest_input = { \"nums1\": [19,11,3,11,22,12,23,12,29,19,25,15,23,23], \"nums2\": [4,29,19,23,23,10,2,10,10,15,19,20,19,12,2,19,15,29] }\nassert my_solution.findIntersectionValues(**test_input) == [9,11]\n\ntest_input = { \"nums1\": [25,21], \"nums2\": [20,12,5,13,21,25,9,30,21,7,21,12,20,7] }\nassert my_solution.findIntersectionValues(**test_input) == [2,4]\n\ntest_input = { \"nums1\": [16,17,16,20,29,16,30,24], \"nums2\": [1,30,24] }\nassert my_solution.findIntersectionValues(**test_input) == [2,2]\n\ntest_input = { \"nums1\": [10,6,7,24,17,24,3,24], \"nums2\": [24,27,26,8,7,3,19,24,6,7,30,6] }\nassert my_solution.findIntersectionValues(**test_input) == [6,7]\n\ntest_input = { \"nums1\": [3,26,7,6,23,22,26,8,11,23,17,26,7,2], \"nums2\": [13,11,10,8,4,23] }\nassert my_solution.findIntersectionValues(**test_input) == [4,3]\n\ntest_input = { \"nums1\": [29,10,9,26,30,21,11,26,30], \"nums2\": [2,9,12,9,30,9,30,21,8,3,17,15,25,26,9,15] }\nassert my_solution.findIntersectionValues(**test_input) == [6,8]\n\ntest_input = { \"nums1\": [14,29,15,12,20,27,24,29,4,29,12,6,12,4,7], \"nums2\": [2,19,6,29,10,20,26,11,11,19,4,12,30,22,13,4,24] }\nassert my_solution.findIntersectionValues(**test_input) == [11,7]\n\ntest_input = { \"nums1\": [11,5,3,4,15,30,25,25,30,6,3,28,25,6,30,17,15], \"nums2\": [4,25,17,2,24,28,25,15,4,25,8,6,15] }\nassert my_solution.findIntersectionValues(**test_input) == [10,10]\n\ntest_input = { \"nums1\": [5,23,17,6,5,15,29,2,7,27,5], \"nums2\": [28,14,1,1,27,26,23,20,6,17,11] }\nassert my_solution.findIntersectionValues(**test_input) == [4,4]\n\ntest_input = { \"nums1\": [26,20,12,2,11,23,8,28,28,2,28,20,2,13,13,28,22], \"nums2\": [8,7,12,15,20] }\nassert my_solution.findIntersectionValues(**test_input) == [4,3]\n\ntest_input = { \"nums1\": [15,6,14,24,6,22,6,24,6,6,6,16,24,3,7,6], \"nums2\": [11,6,18,20,12,14,17,3,11,6,2,3,17,19,3] }\nassert my_solution.findIntersectionValues(**test_input) == [9,6]\n\ntest_input = { \"nums1\": [21,10,13,2,3,29,2,29,12,21,16,7,21,26], \"nums2\": [26,16,18,29,16,15,2,16,23,24,26,21,26,13,4,29,13,17,10] }\nassert my_solution.findIntersectionValues(**test_input) == [11,13]\n\ntest_input = { \"nums1\": [5,18,7,30,16,1,24,5,1,15,28,24,25], \"nums2\": [20,29,16,14] }\nassert my_solution.findIntersectionValues(**test_input) == [1,1]\n\ntest_input = { \"nums1\": [1,11,11,28,28,10,15,28,6], \"nums2\": [27,21,28,18,7,7,20,26,4,28,11,22,16,30,11,9,9] }\nassert my_solution.findIntersectionValues(**test_input) == [5,4]\n\ntest_input = { \"nums1\": [27,3], \"nums2\": [29,29,27,1,26,21,27,1,8,3,7,24,19] }\nassert my_solution.findIntersectionValues(**test_input) == [2,3]\n\ntest_input = { \"nums1\": [19,20,25,16,22,23,25,16,23,16,23,14], \"nums2\": [16,5] }\nassert my_solution.findIntersectionValues(**test_input) == [3,1]\n\ntest_input = { \"nums1\": [9,9,5,28,22,15,11,28,5,3,15,6,16,13,29,30], \"nums2\": [18,12,3,5,24,15] }\nassert my_solution.findIntersectionValues(**test_input) == [5,3]\n\ntest_input = { \"nums1\": [21,19,11,24,7,5,10], \"nums2\": [19,19,14,3,4,14,27,18,14,10] }\nassert my_solution.findIntersectionValues(**test_input) == [2,3]\n\ntest_input = { \"nums1\": [6,18,18,20,5,18,1,15,18,26,28,26], \"nums2\": [13,12,2,24,20,28,27,20,11] }\nassert my_solution.findIntersectionValues(**test_input) == [2,3]\n\ntest_input = { \"nums1\": [18,14,14,15,10,14,7,1,28,15], \"nums2\": [11,18,15,18,27,12] }\nassert my_solution.findIntersectionValues(**test_input) == [3,3]\n\ntest_input = { \"nums1\": [29,18,29,18,27,11,11,8,4,18,11,14,5,21,21,29,11], \"nums2\": [25,29,15,17,27,20,9,23,11,13,26,8,11,6] }\nassert my_solution.findIntersectionValues(**test_input) == [9,5]\n\ntest_input = { \"nums1\": [14,5,8,21,24,5,21,19,29], \"nums2\": [15,10,9,13,24,4,9,10,3,6,5,20,24,26,14,27,14,10,22] }\nassert my_solution.findIntersectionValues(**test_input) == [4,5]\n\ntest_input = { \"nums1\": [2,11,11,9,25,11,27,16,28,10,18,3,22,15,16,11], \"nums2\": [11,3,21,9,3,13,23,9,28,25,8,28,29,2,23,12,13,14,14] }\nassert my_solution.findIntersectionValues(**test_input) == [9,9]\n\ntest_input = { \"nums1\": [12,11,23,17,23,3,17], \"nums2\": [18,20,8,29,28,27,14,28,13,25,24,2,11,23] }\nassert my_solution.findIntersectionValues(**test_input) == [3,2]\n\ntest_input = { \"nums1\": [8,18,7,7,7,24,16,8,23,23,16,16,3,16,22,18,8], \"nums2\": [29,3,14,22,17,22,25,25,1,23,6,23,7,12,16] }\nassert my_solution.findIntersectionValues(**test_input) == [11,7]\n\ntest_input = { \"nums1\": [25,9,11,13,21,3,7,24,29,14,2,7,18,30,18], \"nums2\": [2,3,28,3,25,25,21,10,4,19,23,11,27] }\nassert my_solution.findIntersectionValues(**test_input) == [5,7]\n\ntest_input = { \"nums1\": [5,8,12,18,5,8], \"nums2\": [12,19,30,16,13] }\nassert my_solution.findIntersectionValues(**test_input) == [1,1]\n\ntest_input = { \"nums1\": [14,22,29,29,3,22,4,29,28,27], \"nums2\": [14,29] }\nassert my_solution.findIntersectionValues(**test_input) == [4,2]\n\ntest_input = { \"nums1\": [28,28,11,5,18,5,18,17,21,4,9,4], \"nums2\": [19,6,12,17,13] }\nassert my_solution.findIntersectionValues(**test_input) == [1,1]\n\ntest_input = { \"nums1\": [24,29,19,25,7,26,7,25,7,25,2], \"nums2\": [9,4,2,20,29,1,27] }\nassert my_solution.findIntersectionValues(**test_input) == [2,2]\n\ntest_input = { \"nums1\": [19,14,14,21,14,11,21,18,11,14,18,28,4], \"nums2\": [25,30,1] }\nassert my_solution.findIntersectionValues(**test_input) == [0,0]\n\ntest_input = { \"nums1\": [9,17,21,21,18,9,9,16,9,3,17,9,3], \"nums2\": [9,10,20,7,3,13,13,22,15] }\nassert my_solution.findIntersectionValues(**test_input) == [7,2]\n\ntest_input = { \"nums1\": [21,14,14,14,5,11,8,7,9,3,7,3], \"nums2\": [2,24,28,8,15,5,3,6,14,3,19,25,5] }\nassert my_solution.findIntersectionValues(**test_input) == [7,6]\n\ntest_input = { \"nums1\": [3,17,13,18,18,12,5,12,27,6,3,13,7,3,12,27,6], \"nums2\": [17,28,13,26,12,27,20,12,27,7,10,24] }\nassert my_solution.findIntersectionValues(**test_input) == [9,7]\n\ntest_input = { \"nums1\": [18,9,30,9,3,13,25,5,30,25,13,19,25,3,28,29,9,9,9,12], \"nums2\": [17,20,28,30,27,1,22] }\nassert my_solution.findIntersectionValues(**test_input) == [3,2]\n\ntest_input = { \"nums1\": [18,19,13,20,26,26,13,13,26,25,22,20,17], \"nums2\": [3,21,12,12,18,20,26,17,30,6,22,13] }\nassert my_solution.findIntersectionValues(**test_input) == [11,6]\n\ntest_input = { \"nums1\": [19,10,2,18,15,24,4,11,12,24,10,10,9,12,6,10,17,22,11,12], \"nums2\": [10,16,7,2,27,22,19,17,11,15,27,24] }\nassert my_solution.findIntersectionValues(**test_input) == [13,8]\n\ntest_input = { \"nums1\": [8,8], \"nums2\": [8,24,8,8,19,27,7,21,8,8] }\nassert my_solution.findIntersectionValues(**test_input) == [2,5]\n\ntest_input = { \"nums1\": [22,23,22], \"nums2\": [22,21,3,22,17,27] }\nassert my_solution.findIntersectionValues(**test_input) == [2,2]\n\ntest_input = { \"nums1\": [20,10], \"nums2\": [10,20,12] }\nassert my_solution.findIntersectionValues(**test_input) == [2,2]\n\ntest_input = { \"nums1\": [15,28,15,17,3,6], \"nums2\": [3,15,17,30,18,22,4] }\nassert my_solution.findIntersectionValues(**test_input) == [4,3]\n\ntest_input = { \"nums1\": [30,15], \"nums2\": [15,25,23,26,14,30,8,19,15,8,10,14,26,15,28,30] }\nassert my_solution.findIntersectionValues(**test_input) == [2,5]\n\ntest_input = { \"nums1\": [16,11,16,24,7,9,9,24], \"nums2\": [19,2,9,18,25,11,1,16,24,18,20,9,24,7,9,29,16,22,15] }\nassert my_solution.findIntersectionValues(**test_input) == [8,9]\n\ntest_input = { \"nums1\": [13,25,8,8,1,14,8,4,8,8,25,8,22], \"nums2\": [17,8,13,8,8,20,26,20,8,22,17,14,8,16,26,2,23,18,18,4] }\nassert my_solution.findIntersectionValues(**test_input) == [10,9]\n\ntest_input = { \"nums1\": [9,9,9,29,11,9,18,23,9,9,26,9,23,9,9,2,28,7], \"nums2\": [17,6,2,11,10,23,11,30,11,24,1,11,13,9,23,25] }\nassert my_solution.findIntersectionValues(**test_input) == [13,8]\n\ntest_input = { \"nums1\": [27,16,16,15], \"nums2\": [3,16,7,16,23,16,3,26,27,30,4,28,26,24,7] }\nassert my_solution.findIntersectionValues(**test_input) == [3,4]\n\ntest_input = { \"nums1\": [19,1,26,15,15], \"nums2\": [6,25] }\nassert my_solution.findIntersectionValues(**test_input) == [0,0]\n\ntest_input = { \"nums1\": [13,29,29,12,25,22,2,25,11,3,22,13,23,19,24,24,8,30], \"nums2\": [20,25,12,5,2,28,14,27,24,3,21,15,25,2,12,28,19,7,5] }\nassert my_solution.findIntersectionValues(**test_input) == [8,9]\n\ntest_input = { \"nums1\": [14,14,26,25,28,26], \"nums2\": [4,23,9,3,1,2,27,8,22,6,24] }\nassert my_solution.findIntersectionValues(**test_input) == [0,0]\n\ntest_input = { \"nums1\": [14,29,2,26,14,10,1,23,28,5,17,1,21,5,28,14,6,4,18], \"nums2\": [1,20,7,15,18,26,5,10,8,6,27] }\nassert my_solution.findIntersectionValues(**test_input) == [8,6]\n\ntest_input = { \"nums1\": [29,3,15,7,2,20,30,15,7,29,2,21], \"nums2\": [15,23,22,19,21,5,7,29,23,2,17,27,21,15,6,7] }\nassert my_solution.findIntersectionValues(**test_input) == [9,8]\n\ntest_input = { \"nums1\": [7,23,23,15,23,10,30,23,30,10,30,17,30,10,3,7,10], \"nums2\": [21,21] }\nassert my_solution.findIntersectionValues(**test_input) == [0,0]\n\ntest_input = { \"nums1\": [8,13,1,13,13,12,27,21,4,4,17], \"nums2\": [12,13,1,27,4,9,12,8,25,29,4,8,4,29,21,28,1,8,6,6] }\nassert my_solution.findIntersectionValues(**test_input) == [10,13]\n\ntest_input = { \"nums1\": [6,15,7,1,7,14,21,3,30,23,22,29], \"nums2\": [30,1,7,29,3,4] }\nassert my_solution.findIntersectionValues(**test_input) == [6,5]\n\ntest_input = { \"nums1\": [15,10,22,22,6,8,15,8,10], \"nums2\": [10,4,8,15,29,6,9,22,3,3,23,3,13,8,5,8,3] }\nassert my_solution.findIntersectionValues(**test_input) == [9,7]\n\ntest_input = { \"nums1\": [14,4,1,27,22,14,7,22,15,3,22,8], \"nums2\": [30,4,4,27,6,4,16,11,23,14,4,7,21,22,9,14,4,27,17,27] }\nassert my_solution.findIntersectionValues(**test_input) == [8,12]\n\ntest_input = { \"nums1\": [23,15,15,15], \"nums2\": [23,17,12,15,21] }\nassert my_solution.findIntersectionValues(**test_input) == [4,2]\n\ntest_input = { \"nums1\": [28,29,15,19,1,23,25,9,29,25,19,11,9,19], \"nums2\": [9,4,11,23,13,8,24,9,23] }\nassert my_solution.findIntersectionValues(**test_input) == [4,5]\n\ntest_input = { \"nums1\": [19,24,7,2,3,10,27,10,4,4,9,29,10,7], \"nums2\": [23,4,7,4,27,13,2,9,23] }\nassert my_solution.findIntersectionValues(**test_input) == [7,6]\n\ntest_input = { \"nums1\": [24,22,17,24,22,16,1,5], \"nums2\": [1,27,7,22,27,13,4,5,12,8,22,18,5] }\nassert my_solution.findIntersectionValues(**test_input) == [4,5]", "start_time": 1702132200} +{"task_id": "biweekly-contest-119-remove-adjacent-almost-equal-characters", "url": "https://leetcode.com/problems/remove-adjacent-almost-equal-characters", "title": "remove-adjacent-almost-equal-characters", "meta": {"questionId": "3230", "questionFrontendId": "2957", "title": "Remove Adjacent Almost-Equal Characters", "titleSlug": "remove-adjacent-almost-equal-characters", "isPaidOnly": false, "difficulty": "Medium", "likes": 115, "dislikes": 16, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0开始的字符串word。\n一次操作中,你可以选择word中任意一个下标 i,将word[i] 修改成任意一个小写英文字母。\n请你返回消除 word中所有相邻 近似相等字符的 最少操作次数。\n两个字符a 和b如果满足a == b或者a 和b在字母表中是相邻的,那么我们称它们是 近似相等字符。\n\n示例 1:\n\n输入:word = \"aaaaa\"\n输出:2\n解释:我们将 word 变为 \"acaca\" ,该字符串没有相邻近似相等字符。\n消除 word 中所有相邻近似相等字符最少需要 2 次操作。\n\n示例 2:\n\n输入:word = \"abddez\"\n输出:2\n解释:我们将 word 变为 \"ybdoez\" ,该字符串没有相邻近似相等字符。\n消除 word 中所有相邻近似相等字符最少需要 2 次操作。\n示例 3:\n\n输入:word = \"zyxyxyz\"\n输出:3\n解释:我们将 word 变为 \"zaxaxaz\" ,该字符串没有相邻近似相等字符。\n消除 word 中所有相邻近似相等字符最少需要 3 次操作\n\n\n提示:\n\n1 <= word.length <= 100\nword只包含小写英文字母。\n\"\"\"\nclass Solution:\n def removeAlmostEqualCharacters(self, word: str) -> int:\n ", "prompt_sft": "给你一个下标从 0开始的字符串word。\n一次操作中,你可以选择word中任意一个下标 i,将word[i] 修改成任意一个小写英文字母。\n请你返回消除 word中所有相邻 近似相等字符的 最少操作次数。\n两个字符a 和b如果满足a == b或者a 和b在字母表中是相邻的,那么我们称它们是 近似相等字符。\n\n示例 1:\n\n输入:word = \"aaaaa\"\n输出:2\n解释:我们将 word 变为 \"acaca\" ,该字符串没有相邻近似相等字符。\n消除 word 中所有相邻近似相等字符最少需要 2 次操作。\n\n示例 2:\n\n输入:word = \"abddez\"\n输出:2\n解释:我们将 word 变为 \"ybdoez\" ,该字符串没有相邻近似相等字符。\n消除 word 中所有相邻近似相等字符最少需要 2 次操作。\n示例 3:\n\n输入:word = \"zyxyxyz\"\n输出:3\n解释:我们将 word 变为 \"zaxaxaz\" ,该字符串没有相邻近似相等字符。\n消除 word 中所有相邻近似相等字符最少需要 3 次操作\n\n\n提示:\n\n1 <= word.length <= 100\nword只包含小写英文字母。\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def removeAlmostEqualCharacters(self, word: str) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"word\": \"aaaaa\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"abddez\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"zyxyxyz\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 3\n\ntest_input = { \"word\": \"a\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 0\n\ntest_input = { \"word\": \"b\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 0\n\ntest_input = { \"word\": \"c\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 0\n\ntest_input = { \"word\": \"aa\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"ab\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"ac\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 0\n\ntest_input = { \"word\": \"ba\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"bb\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"bc\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"ca\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 0\n\ntest_input = { \"word\": \"cb\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"cc\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"aaa\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"aab\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"aac\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"aba\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"abb\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"abc\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"aca\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 0\n\ntest_input = { \"word\": \"acb\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"acc\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"baa\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"bab\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"bac\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"bba\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"bbb\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"bbc\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"bca\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"bcb\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"bcc\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"caa\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"cab\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"cac\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 0\n\ntest_input = { \"word\": \"cba\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"cbb\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"cbc\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"cca\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"ccb\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"ccc\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"aaaa\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"aaab\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"aaac\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"aaba\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"aabb\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"aabc\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"aaca\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"aacb\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"aacc\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"abaa\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"abab\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"abac\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"abba\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"abbb\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"abbc\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"abca\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"abcb\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"abcc\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"acaa\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"acab\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"acac\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 0\n\ntest_input = { \"word\": \"acba\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"acbb\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"acbc\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"acca\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"accb\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"accc\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"baaa\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"baab\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"baac\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"baba\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"babb\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"babc\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"baca\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"bacb\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"bacc\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"bbaa\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"bbab\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"bbac\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"bbba\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"bbbb\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"bbbc\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"bbca\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"bbcb\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"bbcc\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"bcaa\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"bcab\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"bcac\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"bcba\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"bcbb\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"bcbc\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"bcca\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"bccb\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"bccc\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"caaa\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"caab\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"caac\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"caba\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1", "start_time": 1702132200} +{"task_id": "biweekly-contest-119-length-of-longest-subarray-with-at-most-k-frequency", "url": "https://leetcode.com/problems/length-of-longest-subarray-with-at-most-k-frequency", "title": "length-of-longest-subarray-with-at-most-k-frequency", "meta": {"questionId": "3225", "questionFrontendId": "2958", "title": "Length of Longest Subarray With at Most K Frequency", "titleSlug": "length-of-longest-subarray-with-at-most-k-frequency", "isPaidOnly": false, "difficulty": "Medium", "likes": 139, "dislikes": 5, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个整数数组nums和一个整数k。\n一个元素 x在数组中的 频率指的是它在数组中的出现次数。\n如果一个数组中所有元素的频率都 小于等于k,那么我们称这个数组是 好数组。\n请你返回 nums中 最长好子数组的长度。\n子数组 指的是一个数组中一段连续非空的元素序列。\n\n示例 1:\n\n输入:nums = [1,2,3,1,2,3,1,2], k = 2\n输出:6\n解释:最长好子数组是 [1,2,3,1,2,3] ,值 1 ,2 和 3 在子数组中的频率都没有超过 k = 2 。[2,3,1,2,3,1] 和 [3,1,2,3,1,2] 也是好子数组。\n最长好子数组的长度为 6 。\n\n示例 2:\n\n输入:nums = [1,2,1,2,1,2,1,2], k = 1\n输出:2\n解释:最长好子数组是 [1,2] ,值 1 和 2 在子数组中的频率都没有超过 k = 1 。[2,1] 也是好子数组。\n最长好子数组的长度为 2 。\n\n示例 3:\n\n输入:nums = [5,5,5,5,5,5,5], k = 4\n输出:4\n解释:最长好子数组是 [5,5,5,5] ,值 5 在子数组中的频率没有超过 k = 4 。\n最长好子数组的长度为 4 。\n\n\n提示:\n\n1 <= nums.length <= 105\n1 <= nums[i] <= 109\n1 <= k <= nums.length\n\"\"\"\nclass Solution:\n def maxSubarrayLength(self, nums: List[int], k: int) -> int:\n ", "prompt_sft": "给你一个整数数组nums和一个整数k。\n一个元素 x在数组中的 频率指的是它在数组中的出现次数。\n如果一个数组中所有元素的频率都 小于等于k,那么我们称这个数组是 好数组。\n请你返回 nums中 最长好子数组的长度。\n子数组 指的是一个数组中一段连续非空的元素序列。\n\n示例 1:\n\n输入:nums = [1,2,3,1,2,3,1,2], k = 2\n输出:6\n解释:最长好子数组是 [1,2,3,1,2,3] ,值 1 ,2 和 3 在子数组中的频率都没有超过 k = 2 。[2,3,1,2,3,1] 和 [3,1,2,3,1,2] 也是好子数组。\n最长好子数组的长度为 6 。\n\n示例 2:\n\n输入:nums = [1,2,1,2,1,2,1,2], k = 1\n输出:2\n解释:最长好子数组是 [1,2] ,值 1 和 2 在子数组中的频率都没有超过 k = 1 。[2,1] 也是好子数组。\n最长好子数组的长度为 2 。\n\n示例 3:\n\n输入:nums = [5,5,5,5,5,5,5], k = 4\n输出:4\n解释:最长好子数组是 [5,5,5,5] ,值 5 在子数组中的频率没有超过 k = 4 。\n最长好子数组的长度为 4 。\n\n\n提示:\n\n1 <= nums.length <= 105\n1 <= nums[i] <= 109\n1 <= k <= nums.length\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def maxSubarrayLength(self, nums: List[int], k: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,2,3,1,2,3,1,2], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 6\n\ntest_input = { \"nums\": [1,2,1,2,1,2,1,2], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 2\n\ntest_input = { \"nums\": [5,5,5,5,5,5,5], \"k\": 4 }\nassert my_solution.maxSubarrayLength(**test_input) == 4\n\ntest_input = { \"nums\": [1], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [2], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [3], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [4], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [5], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [6], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [7], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [8], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [9], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [10], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [1,11], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 2\n\ntest_input = { \"nums\": [2,11], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 2\n\ntest_input = { \"nums\": [3,5], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 2\n\ntest_input = { \"nums\": [4,6], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 2\n\ntest_input = { \"nums\": [5,8], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 2\n\ntest_input = { \"nums\": [6,7], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 2\n\ntest_input = { \"nums\": [7,9], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 2\n\ntest_input = { \"nums\": [8,8], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [9,8], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 2\n\ntest_input = { \"nums\": [10,5], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,2], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,5], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,3], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,4], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [1,3,3], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [1,3,5], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [1,4,1], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 2\n\ntest_input = { \"nums\": [1,4,1], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [1,5,1], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [1,5,5], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [1,6,4], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [1,6,4], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [1,7,1], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 2\n\ntest_input = { \"nums\": [1,7,5], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [1,8,2], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [1,8,4], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [1,9,2], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [1,9,2], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [1,10,2], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [2,1,2], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [2,2,3], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 2\n\ntest_input = { \"nums\": [2,2,4], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [2,3,3], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [2,3,4], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [2,4,1], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [2,4,2], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [2,5,2], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 2\n\ntest_input = { \"nums\": [2,5,4], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [2,6,2], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 2\n\ntest_input = { \"nums\": [2,6,3], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [2,7,1], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [2,7,2], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [2,8,2], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [2,8,5], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [2,9,2], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 2\n\ntest_input = { \"nums\": [2,9,5], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [2,10,1], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [2,10,3], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [3,1,1], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 2\n\ntest_input = { \"nums\": [3,1,4], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [3,2,3], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 2\n\ntest_input = { \"nums\": [3,2,4], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [3,3,1], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [3,3,3], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 2\n\ntest_input = { \"nums\": [3,4,1], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [3,4,2], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [3,5,4], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [3,5,5], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 2\n\ntest_input = { \"nums\": [3,6,2], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [3,6,4], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [3,7,5], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [3,7,5], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [3,8,1], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [3,8,2], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [3,9,1], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [3,9,4], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [3,10,1], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [3,10,3], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [4,1,2], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [4,1,5], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [4,2,4], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [4,2,5], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [4,3,1], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [4,3,3], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 2\n\ntest_input = { \"nums\": [4,4,3], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [4,4,5], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [4,5,2], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [4,5,4], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [4,6,1], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [4,6,2], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [4,7,1], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [4,7,4], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [4,8,2], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [4,8,4], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [4,9,2], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [4,9,3], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [4,10,2], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 3", "start_time": 1702132200} +{"task_id": "biweekly-contest-119-number-of-possible-sets-of-closing-branches", "url": "https://leetcode.com/problems/number-of-possible-sets-of-closing-branches", "title": "number-of-possible-sets-of-closing-branches", "meta": {"questionId": "3217", "questionFrontendId": "2959", "title": "Number of Possible Sets of Closing Branches", "titleSlug": "number-of-possible-sets-of-closing-branches", "isPaidOnly": false, "difficulty": "Hard", "likes": 110, "dislikes": 9, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n一个公司在全国有 n个分部,它们之间有的有道路连接。一开始,所有分部通过这些道路两两之间互相可以到达。\n公司意识到在分部之间旅行花费了太多时间,所以它们决定关闭一些分部(也可能不关闭任何分部),同时保证剩下的分部之间两两互相可以到达且最远距离不超过maxDistance。\n两个分部之间的 距离 是通过道路长度之和的 最小值。\n给你整数n,maxDistance和下标从 0开始的二维整数数组roads,其中roads[i] = [ui, vi, wi]表示一条从ui到vi长度为wi的无向道路。\n请你返回关闭分部的可行方案数目,满足每个方案里剩余分部之间的最远距离不超过maxDistance。\n注意,关闭一个分部后,与之相连的所有道路不可通行。\n注意,两个分部之间可能会有多条道路。\n\n示例 1:\n\n\n输入:n = 3, maxDistance = 5, roads = [[0,1,2],[1,2,10],[0,2,10]]\n输出:5\n解释:可行的关闭分部方案有:\n- 关闭分部集合 [2] ,剩余分部为 [0,1] ,它们之间的距离为 2 。\n- 关闭分部集合 [0,1] ,剩余分部为 [2] 。\n- 关闭分部集合 [1,2] ,剩余分部为 [0] 。\n- 关闭分部集合 [0,2] ,剩余分部为 [1] 。\n- 关闭分部集合 [0,1,2] ,关闭后没有剩余分部。\n总共有 5 种可行的关闭方案。\n\n示例 2:\n\n\n输入:n = 3, maxDistance = 5, roads = [[0,1,20],[0,1,10],[1,2,2],[0,2,2]]\n输出:7\n解释:可行的关闭分部方案有:\n- 关闭分部集合 [] ,剩余分部为 [0,1,2] ,它们之间的最远距离为 4 。\n- 关闭分部集合 [0] ,剩余分部为 [1,2] ,它们之间的距离为 2 。\n- 关闭分部集合 [1] ,剩余分部为 [0,2] ,它们之间的距离为 2 。\n- 关闭分部集合 [0,1] ,剩余分部为 [2] 。\n- 关闭分部集合 [1,2] ,剩余分部为 [0] 。\n- 关闭分部集合 [0,2] ,剩余分部为 [1] 。\n- 关闭分部集合 [0,1,2] ,关闭后没有剩余分部。\n总共有 7 种可行的关闭方案。\n\n示例 3:\n\n输入:n = 1, maxDistance = 10, roads = []\n输出:2\n解释:可行的关闭分部方案有:\n- 关闭分部集合 [] ,剩余分部为 [0] 。\n- 关闭分部集合 [0] ,关闭后没有剩余分部。\n总共有 2 种可行的关闭方案。\n\n\n提示:\n\n1 <= n <= 10\n1 <= maxDistance <= 105\n0 <= roads.length <= 1000\nroads[i].length == 3\n0 <= ui, vi <= n - 1\nui != vi\n1 <= wi <= 1000\n一开始所有分部之间通过道路互相可以到达。\n\"\"\"\nclass Solution:\n def numberOfSets(self, n: int, maxDistance: int, roads: List[List[int]]) -> int:\n ", "prompt_sft": "一个公司在全国有 n个分部,它们之间有的有道路连接。一开始,所有分部通过这些道路两两之间互相可以到达。\n公司意识到在分部之间旅行花费了太多时间,所以它们决定关闭一些分部(也可能不关闭任何分部),同时保证剩下的分部之间两两互相可以到达且最远距离不超过maxDistance。\n两个分部之间的 距离 是通过道路长度之和的 最小值。\n给你整数n,maxDistance和下标从 0开始的二维整数数组roads,其中roads[i] = [ui, vi, wi]表示一条从ui到vi长度为wi的无向道路。\n请你返回关闭分部的可行方案数目,满足每个方案里剩余分部之间的最远距离不超过maxDistance。\n注意,关闭一个分部后,与之相连的所有道路不可通行。\n注意,两个分部之间可能会有多条道路。\n\n示例 1:\n\n\n输入:n = 3, maxDistance = 5, roads = [[0,1,2],[1,2,10],[0,2,10]]\n输出:5\n解释:可行的关闭分部方案有:\n- 关闭分部集合 [2] ,剩余分部为 [0,1] ,它们之间的距离为 2 。\n- 关闭分部集合 [0,1] ,剩余分部为 [2] 。\n- 关闭分部集合 [1,2] ,剩余分部为 [0] 。\n- 关闭分部集合 [0,2] ,剩余分部为 [1] 。\n- 关闭分部集合 [0,1,2] ,关闭后没有剩余分部。\n总共有 5 种可行的关闭方案。\n\n示例 2:\n\n\n输入:n = 3, maxDistance = 5, roads = [[0,1,20],[0,1,10],[1,2,2],[0,2,2]]\n输出:7\n解释:可行的关闭分部方案有:\n- 关闭分部集合 [] ,剩余分部为 [0,1,2] ,它们之间的最远距离为 4 。\n- 关闭分部集合 [0] ,剩余分部为 [1,2] ,它们之间的距离为 2 。\n- 关闭分部集合 [1] ,剩余分部为 [0,2] ,它们之间的距离为 2 。\n- 关闭分部集合 [0,1] ,剩余分部为 [2] 。\n- 关闭分部集合 [1,2] ,剩余分部为 [0] 。\n- 关闭分部集合 [0,2] ,剩余分部为 [1] 。\n- 关闭分部集合 [0,1,2] ,关闭后没有剩余分部。\n总共有 7 种可行的关闭方案。\n\n示例 3:\n\n输入:n = 1, maxDistance = 10, roads = []\n输出:2\n解释:可行的关闭分部方案有:\n- 关闭分部集合 [] ,剩余分部为 [0] 。\n- 关闭分部集合 [0] ,关闭后没有剩余分部。\n总共有 2 种可行的关闭方案。\n\n\n提示:\n\n1 <= n <= 10\n1 <= maxDistance <= 105\n0 <= roads.length <= 1000\nroads[i].length == 3\n0 <= ui, vi <= n - 1\nui != vi\n1 <= wi <= 1000\n一开始所有分部之间通过道路互相可以到达。\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def numberOfSets(self, n: int, maxDistance: int, roads: List[List[int]]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"n\": 3, \"maxDistance\": 5, \"roads\": [[0,1,2],[1,2,10],[0,2,10]] }\nassert my_solution.numberOfSets(**test_input) == 5\n\ntest_input = { \"n\": 3, \"maxDistance\": 5, \"roads\": [[0,1,20],[0,1,10],[1,2,2],[0,2,2]] }\nassert my_solution.numberOfSets(**test_input) == 7\n\ntest_input = { \"n\": 1, \"maxDistance\": 10, \"roads\": [] }\nassert my_solution.numberOfSets(**test_input) == 2\n\ntest_input = { \"n\": 3, \"maxDistance\": 12, \"roads\": [[1,0,11],[1,0,16],[0,2,13]] }\nassert my_solution.numberOfSets(**test_input) == 5\n\ntest_input = { \"n\": 3, \"maxDistance\": 3, \"roads\": [[2,0,14],[1,0,15],[1,0,7]] }\nassert my_solution.numberOfSets(**test_input) == 4\n\ntest_input = { \"n\": 3, \"maxDistance\": 19, \"roads\": [[1,0,7],[0,2,18]] }\nassert my_solution.numberOfSets(**test_input) == 6\n\ntest_input = { \"n\": 3, \"maxDistance\": 5, \"roads\": [[2,0,4],[1,0,3],[1,0,2]] }\nassert my_solution.numberOfSets(**test_input) == 6\n\ntest_input = { \"n\": 4, \"maxDistance\": 3, \"roads\": [[2,1,8],[1,0,3],[0,3,8]] }\nassert my_solution.numberOfSets(**test_input) == 6\n\ntest_input = { \"n\": 5, \"maxDistance\": 20, \"roads\": [[3,2,20],[1,0,10],[0,2,19],[0,3,13],[0,4,19]] }\nassert my_solution.numberOfSets(**test_input) == 12\n\ntest_input = { \"n\": 2, \"maxDistance\": 30, \"roads\": [[1,0,33]] }\nassert my_solution.numberOfSets(**test_input) == 3\n\ntest_input = { \"n\": 3, \"maxDistance\": 12, \"roads\": [[2,1,4],[0,1,4],[0,2,6]] }\nassert my_solution.numberOfSets(**test_input) == 8\n\ntest_input = { \"n\": 3, \"maxDistance\": 3, \"roads\": [[1,0,4],[0,2,5]] }\nassert my_solution.numberOfSets(**test_input) == 4\n\ntest_input = { \"n\": 3, \"maxDistance\": 27, \"roads\": [[2,1,23],[0,1,14],[0,2,18]] }\nassert my_solution.numberOfSets(**test_input) == 8\n\ntest_input = { \"n\": 4, \"maxDistance\": 20, \"roads\": [[2,0,16],[0,1,13],[0,3,11]] }\nassert my_solution.numberOfSets(**test_input) == 8\n\ntest_input = { \"n\": 3, \"maxDistance\": 22, \"roads\": [[1,0,21],[2,1,28]] }\nassert my_solution.numberOfSets(**test_input) == 5\n\ntest_input = { \"n\": 2, \"maxDistance\": 2, \"roads\": [[1,0,6]] }\nassert my_solution.numberOfSets(**test_input) == 3\n\ntest_input = { \"n\": 3, \"maxDistance\": 22, \"roads\": [[1,0,16],[1,0,12],[0,2,14]] }\nassert my_solution.numberOfSets(**test_input) == 6\n\ntest_input = { \"n\": 2, \"maxDistance\": 8, \"roads\": [[1,0,9]] }\nassert my_solution.numberOfSets(**test_input) == 3\n\ntest_input = { \"n\": 2, \"maxDistance\": 18, \"roads\": [[1,0,3]] }\nassert my_solution.numberOfSets(**test_input) == 4\n\ntest_input = { \"n\": 4, \"maxDistance\": 27, \"roads\": [[3,2,3],[0,1,27],[0,2,6],[0,3,17]] }\nassert my_solution.numberOfSets(**test_input) == 10\n\ntest_input = { \"n\": 5, \"maxDistance\": 14, \"roads\": [[1,0,13],[2,0,19],[0,3,16],[0,4,18]] }\nassert my_solution.numberOfSets(**test_input) == 7\n\ntest_input = { \"n\": 5, \"maxDistance\": 8, \"roads\": [[1,0,3],[3,1,10],[4,0,6],[2,0,9],[3,2,11],[4,0,12]] }\nassert my_solution.numberOfSets(**test_input) == 8\n\ntest_input = { \"n\": 2, \"maxDistance\": 4, \"roads\": [[1,0,7]] }\nassert my_solution.numberOfSets(**test_input) == 3\n\ntest_input = { \"n\": 4, \"maxDistance\": 39, \"roads\": [[2,0,44],[3,2,42],[2,1,45]] }\nassert my_solution.numberOfSets(**test_input) == 5\n\ntest_input = { \"n\": 5, \"maxDistance\": 2, \"roads\": [[4,1,11],[3,1,5],[1,0,4],[0,2,7]] }\nassert my_solution.numberOfSets(**test_input) == 6\n\ntest_input = { \"n\": 3, \"maxDistance\": 9, \"roads\": [[1,0,17],[0,2,22]] }\nassert my_solution.numberOfSets(**test_input) == 4\n\ntest_input = { \"n\": 2, \"maxDistance\": 1, \"roads\": [[1,0,3]] }\nassert my_solution.numberOfSets(**test_input) == 3\n\ntest_input = { \"n\": 3, \"maxDistance\": 39, \"roads\": [[1,0,28],[0,2,35]] }\nassert my_solution.numberOfSets(**test_input) == 6\n\ntest_input = { \"n\": 4, \"maxDistance\": 17, \"roads\": [[2,1,28],[2,0,6],[1,0,28],[1,0,24],[1,0,18],[1,0,25],[0,3,10]] }\nassert my_solution.numberOfSets(**test_input) == 8\n\ntest_input = { \"n\": 5, \"maxDistance\": 16, \"roads\": [[2,1,27],[3,0,22],[2,1,4],[1,0,11],[2,1,48],[1,0,40],[4,2,33],[4,3,44],[1,0,1]] }\nassert my_solution.numberOfSets(**test_input) == 9\n\ntest_input = { \"n\": 3, \"maxDistance\": 23, \"roads\": [[2,1,20],[0,1,12],[0,2,10]] }\nassert my_solution.numberOfSets(**test_input) == 8\n\ntest_input = { \"n\": 5, \"maxDistance\": 3, \"roads\": [[4,0,5],[1,0,2],[3,0,5],[3,0,4],[4,2,5],[4,2,1]] }\nassert my_solution.numberOfSets(**test_input) == 8\n\ntest_input = { \"n\": 3, \"maxDistance\": 5, \"roads\": [[1,0,6],[2,0,7]] }\nassert my_solution.numberOfSets(**test_input) == 4\n\ntest_input = { \"n\": 3, \"maxDistance\": 21, \"roads\": [[2,1,30],[0,1,36],[0,2,44]] }\nassert my_solution.numberOfSets(**test_input) == 4\n\ntest_input = { \"n\": 5, \"maxDistance\": 25, \"roads\": [[1,0,17],[1,0,1],[2,1,24],[3,2,12],[1,0,7],[3,2,4],[2,1,15],[0,4,14]] }\nassert my_solution.numberOfSets(**test_input) == 14\n\ntest_input = { \"n\": 2, \"maxDistance\": 3, \"roads\": [[1,0,6]] }\nassert my_solution.numberOfSets(**test_input) == 3\n\ntest_input = { \"n\": 3, \"maxDistance\": 4, \"roads\": [[1,0,6],[2,1,6],[2,0,2]] }\nassert my_solution.numberOfSets(**test_input) == 5\n\ntest_input = { \"n\": 4, \"maxDistance\": 21, \"roads\": [[3,2,18],[1,0,15],[2,1,15],[3,0,19],[3,2,19]] }\nassert my_solution.numberOfSets(**test_input) == 9\n\ntest_input = { \"n\": 4, \"maxDistance\": 1, \"roads\": [[1,0,4],[1,0,2],[3,1,2],[2,1,1],[1,0,3],[2,0,3]] }\nassert my_solution.numberOfSets(**test_input) == 6\n\ntest_input = { \"n\": 3, \"maxDistance\": 33, \"roads\": [[2,1,2],[1,0,40],[2,1,43]] }\nassert my_solution.numberOfSets(**test_input) == 5\n\ntest_input = { \"n\": 4, \"maxDistance\": 29, \"roads\": [[2,1,20],[1,0,38],[2,1,15],[2,0,32],[0,3,18]] }\nassert my_solution.numberOfSets(**test_input) == 7\n\ntest_input = { \"n\": 3, \"maxDistance\": 1, \"roads\": [[2,1,4],[2,0,2],[1,0,12]] }\nassert my_solution.numberOfSets(**test_input) == 4\n\ntest_input = { \"n\": 2, \"maxDistance\": 2, \"roads\": [[1,0,3]] }\nassert my_solution.numberOfSets(**test_input) == 3\n\ntest_input = { \"n\": 3, \"maxDistance\": 13, \"roads\": [[1,0,18],[2,0,1],[2,1,2]] }\nassert my_solution.numberOfSets(**test_input) == 7\n\ntest_input = { \"n\": 3, \"maxDistance\": 1, \"roads\": [[1,0,23],[0,2,37]] }\nassert my_solution.numberOfSets(**test_input) == 4\n\ntest_input = { \"n\": 3, \"maxDistance\": 18, \"roads\": [[2,0,39],[0,1,47]] }\nassert my_solution.numberOfSets(**test_input) == 4\n\ntest_input = { \"n\": 4, \"maxDistance\": 6, \"roads\": [[3,0,6],[0,1,3],[0,2,9]] }\nassert my_solution.numberOfSets(**test_input) == 7\n\ntest_input = { \"n\": 3, \"maxDistance\": 35, \"roads\": [[1,0,10],[1,0,15],[0,2,32]] }\nassert my_solution.numberOfSets(**test_input) == 6\n\ntest_input = { \"n\": 5, \"maxDistance\": 10, \"roads\": [[4,0,38],[4,0,11],[2,0,24],[3,0,5],[2,1,18],[2,0,38],[1,0,7],[2,1,3],[2,1,2],[3,1,36]] }\nassert my_solution.numberOfSets(**test_input) == 10\n\ntest_input = { \"n\": 5, \"maxDistance\": 16, \"roads\": [[2,0,32],[4,0,17],[2,0,22],[3,1,38],[3,0,13],[3,1,34],[3,1,36],[1,0,36],[3,1,18],[3,2,10]] }\nassert my_solution.numberOfSets(**test_input) == 8\n\ntest_input = { \"n\": 2, \"maxDistance\": 4, \"roads\": [[1,0,18]] }\nassert my_solution.numberOfSets(**test_input) == 3\n\ntest_input = { \"n\": 5, \"maxDistance\": 13, \"roads\": [[3,0,5],[2,1,3],[1,0,6],[3,2,19],[2,1,29],[2,1,30],[1,0,5],[2,0,29],[4,3,15],[2,1,23]] }\nassert my_solution.numberOfSets(**test_input) == 12\n\ntest_input = { \"n\": 3, \"maxDistance\": 23, \"roads\": [[2,1,12],[1,0,8],[2,1,7]] }\nassert my_solution.numberOfSets(**test_input) == 7\n\ntest_input = { \"n\": 5, \"maxDistance\": 38, \"roads\": [[2,0,8],[2,1,10],[0,3,25],[0,4,48]] }\nassert my_solution.numberOfSets(**test_input) == 11\n\ntest_input = { \"n\": 2, \"maxDistance\": 4, \"roads\": [[1,0,2]] }\nassert my_solution.numberOfSets(**test_input) == 4\n\ntest_input = { \"n\": 4, \"maxDistance\": 12, \"roads\": [[2,1,18],[0,1,25],[0,2,24],[0,3,16]] }\nassert my_solution.numberOfSets(**test_input) == 5\n\ntest_input = { \"n\": 4, \"maxDistance\": 1, \"roads\": [[2,0,1],[3,2,2],[2,0,2],[2,0,1],[1,0,1],[1,0,1]] }\nassert my_solution.numberOfSets(**test_input) == 7\n\ntest_input = { \"n\": 3, \"maxDistance\": 1, \"roads\": [[1,0,1],[0,2,1]] }\nassert my_solution.numberOfSets(**test_input) == 6\n\ntest_input = { \"n\": 2, \"maxDistance\": 3, \"roads\": [[1,0,24]] }\nassert my_solution.numberOfSets(**test_input) == 3\n\ntest_input = { \"n\": 2, \"maxDistance\": 10, \"roads\": [[1,0,13]] }\nassert my_solution.numberOfSets(**test_input) == 3\n\ntest_input = { \"n\": 3, \"maxDistance\": 1, \"roads\": [[2,1,1],[0,1,1],[0,2,1]] }\nassert my_solution.numberOfSets(**test_input) == 8\n\ntest_input = { \"n\": 5, \"maxDistance\": 13, \"roads\": [[1,0,17],[1,0,21],[3,0,9],[1,0,10],[2,0,11],[4,1,12],[2,1,11],[1,0,18]] }\nassert my_solution.numberOfSets(**test_input) == 12\n\ntest_input = { \"n\": 2, \"maxDistance\": 19, \"roads\": [[1,0,28]] }\nassert my_solution.numberOfSets(**test_input) == 3\n\ntest_input = { \"n\": 3, \"maxDistance\": 8, \"roads\": [[2,0,7],[2,0,28],[0,1,34]] }\nassert my_solution.numberOfSets(**test_input) == 5\n\ntest_input = { \"n\": 5, \"maxDistance\": 7, \"roads\": [[1,0,32],[0,2,35],[0,3,20],[0,4,27]] }\nassert my_solution.numberOfSets(**test_input) == 6\n\ntest_input = { \"n\": 4, \"maxDistance\": 1, \"roads\": [[1,0,4],[1,0,3],[3,0,4],[1,0,7],[0,2,11]] }\nassert my_solution.numberOfSets(**test_input) == 5\n\ntest_input = { \"n\": 2, \"maxDistance\": 34, \"roads\": [[1,0,11]] }\nassert my_solution.numberOfSets(**test_input) == 4\n\ntest_input = { \"n\": 5, \"maxDistance\": 10, \"roads\": [[2,1,32],[4,3,14],[3,2,3],[2,1,21],[3,1,37],[2,1,30],[0,1,18],[0,2,26],[0,3,19],[0,4,23]] }\nassert my_solution.numberOfSets(**test_input) == 7\n\ntest_input = { \"n\": 5, \"maxDistance\": 14, \"roads\": [[2,0,19],[3,1,24],[4,3,10],[4,1,15],[0,1,21],[0,3,21],[0,4,12]] }\nassert my_solution.numberOfSets(**test_input) == 8\n\ntest_input = { \"n\": 4, \"maxDistance\": 30, \"roads\": [[2,0,5],[0,1,27],[0,3,24]] }\nassert my_solution.numberOfSets(**test_input) == 9\n\ntest_input = { \"n\": 2, \"maxDistance\": 6, \"roads\": [[1,0,23]] }\nassert my_solution.numberOfSets(**test_input) == 3\n\ntest_input = { \"n\": 5, \"maxDistance\": 6, \"roads\": [[4,0,17],[2,1,7],[4,1,23],[1,0,1],[1,0,19],[0,3,20]] }\nassert my_solution.numberOfSets(**test_input) == 7\n\ntest_input = { \"n\": 3, \"maxDistance\": 5, \"roads\": [[1,0,1],[1,0,3],[2,0,4]] }\nassert my_solution.numberOfSets(**test_input) == 7\n\ntest_input = { \"n\": 4, \"maxDistance\": 19, \"roads\": [[3,2,21],[2,1,3],[0,1,15],[0,2,22],[0,3,8]] }\nassert my_solution.numberOfSets(**test_input) == 9\n\ntest_input = { \"n\": 2, \"maxDistance\": 5, \"roads\": [[1,0,4]] }\nassert my_solution.numberOfSets(**test_input) == 4\n\ntest_input = { \"n\": 4, \"maxDistance\": 18, \"roads\": [[2,1,7],[2,0,5],[0,3,10]] }\nassert my_solution.numberOfSets(**test_input) == 10\n\ntest_input = { \"n\": 5, \"maxDistance\": 35, \"roads\": [[1,0,39],[1,0,3],[3,1,45],[2,0,21],[3,2,40],[3,0,27],[2,1,44],[4,2,6],[4,2,45],[3,0,22]] }\nassert my_solution.numberOfSets(**test_input) == 14\n\ntest_input = { \"n\": 4, \"maxDistance\": 2, \"roads\": [[1,0,2],[1,0,3],[1,0,15],[1,0,7],[0,2,4],[0,3,6]] }\nassert my_solution.numberOfSets(**test_input) == 6\n\ntest_input = { \"n\": 4, \"maxDistance\": 5, \"roads\": [[2,0,1],[1,0,3],[0,3,4]] }\nassert my_solution.numberOfSets(**test_input) == 10\n\ntest_input = { \"n\": 3, \"maxDistance\": 19, \"roads\": [[1,0,9],[0,2,4]] }\nassert my_solution.numberOfSets(**test_input) == 7\n\ntest_input = { \"n\": 4, \"maxDistance\": 1, \"roads\": [[3,0,4],[2,1,4],[1,0,4]] }\nassert my_solution.numberOfSets(**test_input) == 5\n\ntest_input = { \"n\": 2, \"maxDistance\": 29, \"roads\": [[1,0,18]] }\nassert my_solution.numberOfSets(**test_input) == 4\n\ntest_input = { \"n\": 2, \"maxDistance\": 11, \"roads\": [[1,0,28]] }\nassert my_solution.numberOfSets(**test_input) == 3\n\ntest_input = { \"n\": 2, \"maxDistance\": 12, \"roads\": [[1,0,10]] }\nassert my_solution.numberOfSets(**test_input) == 4\n\ntest_input = { \"n\": 5, \"maxDistance\": 9, \"roads\": [[3,2,23],[4,3,11],[1,0,16],[2,0,11],[2,0,16],[1,0,20],[4,0,16],[2,0,36],[3,0,7]] }\nassert my_solution.numberOfSets(**test_input) == 7\n\ntest_input = { \"n\": 5, \"maxDistance\": 17, \"roads\": [[3,2,22],[3,2,3],[4,0,19],[3,0,21],[4,3,4],[1,0,24],[3,0,7],[3,2,12],[1,0,17]] }\nassert my_solution.numberOfSets(**test_input) == 14\n\ntest_input = { \"n\": 4, \"maxDistance\": 5, \"roads\": [[2,0,26],[1,0,15],[3,2,17]] }\nassert my_solution.numberOfSets(**test_input) == 5\n\ntest_input = { \"n\": 4, \"maxDistance\": 4, \"roads\": [[1,0,11],[0,2,3],[0,3,3]] }\nassert my_solution.numberOfSets(**test_input) == 7\n\ntest_input = { \"n\": 5, \"maxDistance\": 13, \"roads\": [[3,1,16],[0,1,3],[0,2,19],[0,3,10],[0,4,2]] }\nassert my_solution.numberOfSets(**test_input) == 13\n\ntest_input = { \"n\": 4, \"maxDistance\": 5, \"roads\": [[1,0,21],[1,0,13],[1,0,19],[2,1,15],[1,0,17],[1,0,3],[0,3,1]] }\nassert my_solution.numberOfSets(**test_input) == 8\n\ntest_input = { \"n\": 5, \"maxDistance\": 25, \"roads\": [[1,0,18],[3,0,20],[2,0,17],[2,1,21],[0,4,3]] }\nassert my_solution.numberOfSets(**test_input) == 16\n\ntest_input = { \"n\": 5, \"maxDistance\": 15, \"roads\": [[2,1,33],[1,0,18],[2,0,16],[3,1,37],[3,0,26],[0,4,18]] }\nassert my_solution.numberOfSets(**test_input) == 6\n\ntest_input = { \"n\": 4, \"maxDistance\": 1, \"roads\": [[1,0,1],[1,0,1],[0,2,1],[0,3,1]] }\nassert my_solution.numberOfSets(**test_input) == 8\n\ntest_input = { \"n\": 4, \"maxDistance\": 10, \"roads\": [[2,0,22],[2,1,6],[2,0,21],[2,1,27],[3,1,12]] }\nassert my_solution.numberOfSets(**test_input) == 6\n\ntest_input = { \"n\": 2, \"maxDistance\": 13, \"roads\": [[1,0,21]] }\nassert my_solution.numberOfSets(**test_input) == 3\n\ntest_input = { \"n\": 4, \"maxDistance\": 31, \"roads\": [[3,1,7],[2,1,10],[2,0,25],[2,0,27]] }\nassert my_solution.numberOfSets(**test_input) == 9\n\ntest_input = { \"n\": 3, \"maxDistance\": 17, \"roads\": [[1,0,8],[1,0,8],[0,2,14]] }\nassert my_solution.numberOfSets(**test_input) == 6\n\ntest_input = { \"n\": 2, \"maxDistance\": 3, \"roads\": [[1,0,3]] }\nassert my_solution.numberOfSets(**test_input) == 4\n\ntest_input = { \"n\": 5, \"maxDistance\": 5, \"roads\": [[4,1,37],[4,1,7],[2,1,6],[3,2,8],[2,1,35],[1,0,28],[4,1,3],[2,1,2]] }\nassert my_solution.numberOfSets(**test_input) == 9\n\ntest_input = { \"n\": 4, \"maxDistance\": 1, \"roads\": [[2,0,2],[2,0,1],[0,1,2],[0,3,2]] }\nassert my_solution.numberOfSets(**test_input) == 6", "start_time": 1702132200} +{"task_id": "weekly-contest-374-find-the-peaks", "url": "https://leetcode.com/problems/find-the-peaks", "title": "find-the-peaks", "meta": {"questionId": "3221", "questionFrontendId": "2951", "title": "Find the Peaks", "titleSlug": "find-the-peaks", "isPaidOnly": false, "difficulty": "Easy", "likes": 91, "dislikes": 9, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0 开始的数组 mountain 。你的任务是找出数组mountain 中的所有 峰值。\n以数组形式返回给定数组中 峰值 的下标,顺序不限 。\n注意:\n\n峰值 是指一个严格大于其相邻元素的元素。\n数组的第一个和最后一个元素 不 是峰值。\n\n\n示例 1:\n\n输入:mountain = [2,4,4]\n输出:[]\n解释:mountain[0] 和 mountain[2] 不可能是峰值,因为它们是数组的第一个和最后一个元素。\nmountain[1] 也不可能是峰值,因为它不严格大于 mountain[2] 。\n因此,答案为 [] 。\n\n示例 2:\n\n输入:mountain = [1,4,3,8,5]\n输出:[1,3]\n解释:mountain[0] 和 mountain[4] 不可能是峰值,因为它们是数组的第一个和最后一个元素。\nmountain[2] 也不可能是峰值,因为它不严格大于 mountain[3] 和 mountain[1] 。\n但是 mountain[1] 和 mountain[3] 严格大于它们的相邻元素。\n因此,答案是 [1,3] 。\n\n\n提示:\n\n3 <= mountain.length <= 100\n1 <= mountain[i] <= 100\n\"\"\"\nclass Solution:\n def findPeaks(self, mountain: List[int]) -> List[int]:\n ", "prompt_sft": "给你一个下标从 0 开始的数组 mountain 。你的任务是找出数组mountain 中的所有 峰值。\n以数组形式返回给定数组中 峰值 的下标,顺序不限 。\n注意:\n\n峰值 是指一个严格大于其相邻元素的元素。\n数组的第一个和最后一个元素 不 是峰值。\n\n\n示例 1:\n\n输入:mountain = [2,4,4]\n输出:[]\n解释:mountain[0] 和 mountain[2] 不可能是峰值,因为它们是数组的第一个和最后一个元素。\nmountain[1] 也不可能是峰值,因为它不严格大于 mountain[2] 。\n因此,答案为 [] 。\n\n示例 2:\n\n输入:mountain = [1,4,3,8,5]\n输出:[1,3]\n解释:mountain[0] 和 mountain[4] 不可能是峰值,因为它们是数组的第一个和最后一个元素。\nmountain[2] 也不可能是峰值,因为它不严格大于 mountain[3] 和 mountain[1] 。\n但是 mountain[1] 和 mountain[3] 严格大于它们的相邻元素。\n因此,答案是 [1,3] 。\n\n\n提示:\n\n3 <= mountain.length <= 100\n1 <= mountain[i] <= 100\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def findPeaks(self, mountain: List[int]) -> List[int]:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"mountain\": [2,4,4] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [1,4,3,8,5] }\nassert my_solution.findPeaks(**test_input) == [1,3]\n\ntest_input = { \"mountain\": [1,1,1] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [1,1,3] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [1,1,5] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [1,2,5] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [1,4,1] }\nassert my_solution.findPeaks(**test_input) == [1]\n\ntest_input = { \"mountain\": [1,4,3] }\nassert my_solution.findPeaks(**test_input) == [1]\n\ntest_input = { \"mountain\": [1,5,5] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [1,6,4] }\nassert my_solution.findPeaks(**test_input) == [1]\n\ntest_input = { \"mountain\": [2,1,1] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [2,1,2] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [2,2,3] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [2,2,5] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [2,3,2] }\nassert my_solution.findPeaks(**test_input) == [1]\n\ntest_input = { \"mountain\": [2,3,6] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [2,4,3] }\nassert my_solution.findPeaks(**test_input) == [1]\n\ntest_input = { \"mountain\": [2,4,5] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [2,6,4] }\nassert my_solution.findPeaks(**test_input) == [1]\n\ntest_input = { \"mountain\": [3,3,3] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [3,3,5] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [3,4,6] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [3,5,1] }\nassert my_solution.findPeaks(**test_input) == [1]\n\ntest_input = { \"mountain\": [3,5,3] }\nassert my_solution.findPeaks(**test_input) == [1]\n\ntest_input = { \"mountain\": [3,5,4] }\nassert my_solution.findPeaks(**test_input) == [1]\n\ntest_input = { \"mountain\": [3,5,6] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [4,2,1] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [4,2,2] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [4,2,4] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [4,2,6] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [4,4,1] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [4,4,2] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [4,4,5] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [4,5,4] }\nassert my_solution.findPeaks(**test_input) == [1]\n\ntest_input = { \"mountain\": [4,6,1] }\nassert my_solution.findPeaks(**test_input) == [1]\n\ntest_input = { \"mountain\": [4,6,6] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [5,1,2] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [5,2,1] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [5,2,2] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [5,2,4] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [5,3,1] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [5,5,1] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [5,5,2] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [5,5,6] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [5,6,1] }\nassert my_solution.findPeaks(**test_input) == [1]\n\ntest_input = { \"mountain\": [5,6,4] }\nassert my_solution.findPeaks(**test_input) == [1]\n\ntest_input = { \"mountain\": [6,1,1] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [6,1,2] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [6,1,5] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [6,2,2] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [6,2,5] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [6,3,2] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [6,3,3] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [6,3,6] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [6,4,3] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [6,5,2] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [6,5,4] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [6,6,4] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [1,1,1,4] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [1,1,7,7] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [1,3,6,5] }\nassert my_solution.findPeaks(**test_input) == [2]\n\ntest_input = { \"mountain\": [1,4,7,8] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [1,6,6,6] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [1,8,1,8] }\nassert my_solution.findPeaks(**test_input) == [1]\n\ntest_input = { \"mountain\": [2,2,1,2] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [2,3,7,6] }\nassert my_solution.findPeaks(**test_input) == [2]\n\ntest_input = { \"mountain\": [2,5,4,5] }\nassert my_solution.findPeaks(**test_input) == [1]\n\ntest_input = { \"mountain\": [2,7,1,2] }\nassert my_solution.findPeaks(**test_input) == [1]\n\ntest_input = { \"mountain\": [2,7,2,6] }\nassert my_solution.findPeaks(**test_input) == [1]\n\ntest_input = { \"mountain\": [2,7,5,3] }\nassert my_solution.findPeaks(**test_input) == [1]\n\ntest_input = { \"mountain\": [2,7,7,6] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [3,1,2,5] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [3,3,4,2] }\nassert my_solution.findPeaks(**test_input) == [2]\n\ntest_input = { \"mountain\": [3,3,7,8] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [3,4,2,4] }\nassert my_solution.findPeaks(**test_input) == [1]\n\ntest_input = { \"mountain\": [3,4,5,4] }\nassert my_solution.findPeaks(**test_input) == [2]\n\ntest_input = { \"mountain\": [3,4,7,6] }\nassert my_solution.findPeaks(**test_input) == [2]\n\ntest_input = { \"mountain\": [3,5,5,3] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [3,6,4,7] }\nassert my_solution.findPeaks(**test_input) == [1]\n\ntest_input = { \"mountain\": [3,8,5,5] }\nassert my_solution.findPeaks(**test_input) == [1]\n\ntest_input = { \"mountain\": [4,2,4,3] }\nassert my_solution.findPeaks(**test_input) == [2]\n\ntest_input = { \"mountain\": [4,2,6,8] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [4,3,3,8] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [4,4,8,7] }\nassert my_solution.findPeaks(**test_input) == [2]\n\ntest_input = { \"mountain\": [4,5,1,1] }\nassert my_solution.findPeaks(**test_input) == [1]\n\ntest_input = { \"mountain\": [4,6,1,7] }\nassert my_solution.findPeaks(**test_input) == [1]\n\ntest_input = { \"mountain\": [4,6,2,1] }\nassert my_solution.findPeaks(**test_input) == [1]\n\ntest_input = { \"mountain\": [4,6,2,2] }\nassert my_solution.findPeaks(**test_input) == [1]\n\ntest_input = { \"mountain\": [5,1,7,6] }\nassert my_solution.findPeaks(**test_input) == [2]\n\ntest_input = { \"mountain\": [5,3,2,2] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [5,3,6,3] }\nassert my_solution.findPeaks(**test_input) == [2]\n\ntest_input = { \"mountain\": [5,3,8,3] }\nassert my_solution.findPeaks(**test_input) == [2]\n\ntest_input = { \"mountain\": [5,4,4,6] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [5,4,4,8] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [5,5,1,7] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [5,5,8,2] }\nassert my_solution.findPeaks(**test_input) == [2]\n\ntest_input = { \"mountain\": [5,6,7,4] }\nassert my_solution.findPeaks(**test_input) == [2]\n\ntest_input = { \"mountain\": [5,7,4,3] }\nassert my_solution.findPeaks(**test_input) == [1]\n\ntest_input = { \"mountain\": [5,8,7,8] }\nassert my_solution.findPeaks(**test_input) == [1]\n\ntest_input = { \"mountain\": [6,2,8,6] }\nassert my_solution.findPeaks(**test_input) == [2]", "start_time": 1701570600} +{"task_id": "weekly-contest-374-minimum-number-of-coins-to-be-added", "url": "https://leetcode.com/problems/minimum-number-of-coins-to-be-added", "title": "minimum-number-of-coins-to-be-added", "meta": {"questionId": "3231", "questionFrontendId": "2952", "title": "Minimum Number of Coins to be Added", "titleSlug": "minimum-number-of-coins-to-be-added", "isPaidOnly": false, "difficulty": "Medium", "likes": 227, "dislikes": 40, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0 开始的整数数组 coins,表示可用的硬币的面值,以及一个整数 target 。\n如果存在某个 coins 的子序列总和为 x,那么整数 x 就是一个 可取得的金额 。\n返回需要添加到数组中的 任意面值 硬币的 最小数量 ,使范围 [1, target] 内的每个整数都属于 可取得的金额 。\n数组的 子序列 是通过删除原始数组的一些(可能不删除)元素而形成的新的 非空 数组,删除过程不会改变剩余元素的相对位置。\n\n示例 1:\n\n输入:coins = [1,4,10], target = 19\n输出:2\n解释:需要添加面值为 2 和 8 的硬币各一枚,得到硬币数组 [1,2,4,8,10] 。\n可以证明从 1 到 19 的所有整数都可由数组中的硬币组合得到,且需要添加到数组中的硬币数目最小为 2 。\n\n示例 2:\n\n输入:coins = [1,4,10,5,7,19], target = 19\n输出:1\n解释:只需要添加一枚面值为 2 的硬币,得到硬币数组 [1,2,4,5,7,10,19] 。\n可以证明从 1 到 19 的所有整数都可由数组中的硬币组合得到,且需要添加到数组中的硬币数目最小为 1 。\n示例 3:\n\n输入:coins = [1,1,1], target = 20\n输出:3\n解释:\n需要添加面值为 4 、8 和 16 的硬币各一枚,得到硬币数组 [1,1,1,4,8,16] 。 \n可以证明从 1 到 20 的所有整数都可由数组中的硬币组合得到,且需要添加到数组中的硬币数目最小为 3 。\n\n提示:\n\n1 <= target <= 105\n1 <= coins.length <= 105\n1 <= coins[i] <= target\n\"\"\"\nclass Solution:\n def minimumAddedCoins(self, coins: List[int], target: int) -> int:\n ", "prompt_sft": "给你一个下标从 0 开始的整数数组 coins,表示可用的硬币的面值,以及一个整数 target 。\n如果存在某个 coins 的子序列总和为 x,那么整数 x 就是一个 可取得的金额 。\n返回需要添加到数组中的 任意面值 硬币的 最小数量 ,使范围 [1, target] 内的每个整数都属于 可取得的金额 。\n数组的 子序列 是通过删除原始数组的一些(可能不删除)元素而形成的新的 非空 数组,删除过程不会改变剩余元素的相对位置。\n\n示例 1:\n\n输入:coins = [1,4,10], target = 19\n输出:2\n解释:需要添加面值为 2 和 8 的硬币各一枚,得到硬币数组 [1,2,4,8,10] 。\n可以证明从 1 到 19 的所有整数都可由数组中的硬币组合得到,且需要添加到数组中的硬币数目最小为 2 。\n\n示例 2:\n\n输入:coins = [1,4,10,5,7,19], target = 19\n输出:1\n解释:只需要添加一枚面值为 2 的硬币,得到硬币数组 [1,2,4,5,7,10,19] 。\n可以证明从 1 到 19 的所有整数都可由数组中的硬币组合得到,且需要添加到数组中的硬币数目最小为 1 。\n示例 3:\n\n输入:coins = [1,1,1], target = 20\n输出:3\n解释:\n需要添加面值为 4 、8 和 16 的硬币各一枚,得到硬币数组 [1,1,1,4,8,16] 。 \n可以证明从 1 到 20 的所有整数都可由数组中的硬币组合得到,且需要添加到数组中的硬币数目最小为 3 。\n\n提示:\n\n1 <= target <= 105\n1 <= coins.length <= 105\n1 <= coins[i] <= target\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def minimumAddedCoins(self, coins: List[int], target: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"coins\": [1,4,10], \"target\": 19 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [1,4,10,5,7,19], \"target\": 19 }\nassert my_solution.minimumAddedCoins(**test_input) == 1\n\ntest_input = { \"coins\": [1,1,1], \"target\": 20 }\nassert my_solution.minimumAddedCoins(**test_input) == 3\n\ntest_input = { \"coins\": [1], \"target\": 100000 }\nassert my_solution.minimumAddedCoins(**test_input) == 16\n\ntest_input = { \"coins\": [100000], \"target\": 100000 }\nassert my_solution.minimumAddedCoins(**test_input) == 17\n\ntest_input = { \"coins\": [2], \"target\": 5 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [5,6,7], \"target\": 10 }\nassert my_solution.minimumAddedCoins(**test_input) == 3\n\ntest_input = { \"coins\": [5,6,7], \"target\": 15 }\nassert my_solution.minimumAddedCoins(**test_input) == 3\n\ntest_input = { \"coins\": [4,11,13,15,7,5,12,11,5,9], \"target\": 34 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [8,12,9], \"target\": 27 }\nassert my_solution.minimumAddedCoins(**test_input) == 3\n\ntest_input = { \"coins\": [2,13,7,1,11], \"target\": 35 }\nassert my_solution.minimumAddedCoins(**test_input) == 1\n\ntest_input = { \"coins\": [10,3,5,11,6], \"target\": 27 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [6,6,6,15,4], \"target\": 31 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [6,15,6], \"target\": 22 }\nassert my_solution.minimumAddedCoins(**test_input) == 3\n\ntest_input = { \"coins\": [8,14,15,4,14,15,8,10,8], \"target\": 42 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [9,14,14,9,14,5,12,10,11], \"target\": 17 }\nassert my_solution.minimumAddedCoins(**test_input) == 3\n\ntest_input = { \"coins\": [14,5,13,3,7,10,10,10], \"target\": 32 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [8,6,7,12], \"target\": 26 }\nassert my_solution.minimumAddedCoins(**test_input) == 3\n\ntest_input = { \"coins\": [15,1,12], \"target\": 43 }\nassert my_solution.minimumAddedCoins(**test_input) == 4\n\ntest_input = { \"coins\": [4,1,4,10], \"target\": 16 }\nassert my_solution.minimumAddedCoins(**test_input) == 1\n\ntest_input = { \"coins\": [10,2,13,5,7,15], \"target\": 26 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [10,1,10], \"target\": 10 }\nassert my_solution.minimumAddedCoins(**test_input) == 3\n\ntest_input = { \"coins\": [9,5,13,8], \"target\": 30 }\nassert my_solution.minimumAddedCoins(**test_input) == 3\n\ntest_input = { \"coins\": [13,9,4,5], \"target\": 37 }\nassert my_solution.minimumAddedCoins(**test_input) == 3\n\ntest_input = { \"coins\": [1,15,5,12,13,10,14,8,1,7], \"target\": 29 }\nassert my_solution.minimumAddedCoins(**test_input) == 1\n\ntest_input = { \"coins\": [14,14,6,2,9,1,4,10], \"target\": 38 }\nassert my_solution.minimumAddedCoins(**test_input) == 0\n\ntest_input = { \"coins\": [7,10,6,14,10,11,2], \"target\": 45 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [6,3,2,6,8,9,13,3,12,13], \"target\": 47 }\nassert my_solution.minimumAddedCoins(**test_input) == 1\n\ntest_input = { \"coins\": [8,1,9,2,15], \"target\": 34 }\nassert my_solution.minimumAddedCoins(**test_input) == 1\n\ntest_input = { \"coins\": [5,13,9,11,6,1], \"target\": 27 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [10,15,7,14,2,2,12,14,13], \"target\": 45 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [9,3,10,3,8,2,7,11,1], \"target\": 26 }\nassert my_solution.minimumAddedCoins(**test_input) == 0\n\ntest_input = { \"coins\": [9,11,2,5,2,7,11], \"target\": 28 }\nassert my_solution.minimumAddedCoins(**test_input) == 1\n\ntest_input = { \"coins\": [5,5,15,3,13], \"target\": 17 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [2,2,9,10,7,15,4,3,9,15], \"target\": 16 }\nassert my_solution.minimumAddedCoins(**test_input) == 1\n\ntest_input = { \"coins\": [3,1,12,15,5,10], \"target\": 34 }\nassert my_solution.minimumAddedCoins(**test_input) == 1\n\ntest_input = { \"coins\": [12,7,5,2,12], \"target\": 50 }\nassert my_solution.minimumAddedCoins(**test_input) == 3\n\ntest_input = { \"coins\": [11,6,10,3,1,7,11], \"target\": 44 }\nassert my_solution.minimumAddedCoins(**test_input) == 1\n\ntest_input = { \"coins\": [13,12,1,11,3,4,11,9,13,13], \"target\": 41 }\nassert my_solution.minimumAddedCoins(**test_input) == 1\n\ntest_input = { \"coins\": [6,4,1,9,9,2,10,7], \"target\": 48 }\nassert my_solution.minimumAddedCoins(**test_input) == 0\n\ntest_input = { \"coins\": [10,4,4,3,9,6,8,4,7,7], \"target\": 22 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [15,9,5,7,4,13], \"target\": 19 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [13,11,8,6,11], \"target\": 16 }\nassert my_solution.minimumAddedCoins(**test_input) == 3\n\ntest_input = { \"coins\": [8,14,15,9,8,10,13,7,3], \"target\": 42 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [6,14,7,4,10,9,10,9,7], \"target\": 22 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [4,6,7,15,13,14,5,7], \"target\": 16 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [10,12,5], \"target\": 32 }\nassert my_solution.minimumAddedCoins(**test_input) == 3\n\ntest_input = { \"coins\": [8,5,14,13,13,11,14,13], \"target\": 43 }\nassert my_solution.minimumAddedCoins(**test_input) == 3\n\ntest_input = { \"coins\": [3,14,4,2,10,3,7], \"target\": 50 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [1,3,11,9,2,10,6,12], \"target\": 12 }\nassert my_solution.minimumAddedCoins(**test_input) == 0\n\ntest_input = { \"coins\": [2,5,4,12,6,7,11,15], \"target\": 17 }\nassert my_solution.minimumAddedCoins(**test_input) == 1\n\ntest_input = { \"coins\": [7,12,10,15,6,15,14,2,9,12], \"target\": 24 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [4,7,15,10,14], \"target\": 38 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [10,1,12,9], \"target\": 16 }\nassert my_solution.minimumAddedCoins(**test_input) == 3\n\ntest_input = { \"coins\": [5,8,12,6,15,13,11,5], \"target\": 35 }\nassert my_solution.minimumAddedCoins(**test_input) == 3\n\ntest_input = { \"coins\": [6,2,6], \"target\": 39 }\nassert my_solution.minimumAddedCoins(**test_input) == 3\n\ntest_input = { \"coins\": [15,10,5,4,7,12,12,5,11], \"target\": 30 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [9,10,7,12,10,4], \"target\": 35 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [4,4,2], \"target\": 8 }\nassert my_solution.minimumAddedCoins(**test_input) == 1\n\ntest_input = { \"coins\": [13,4,15,1,8], \"target\": 25 }\nassert my_solution.minimumAddedCoins(**test_input) == 1\n\ntest_input = { \"coins\": [14,7,7,1,6,14,3,15,13], \"target\": 18 }\nassert my_solution.minimumAddedCoins(**test_input) == 1\n\ntest_input = { \"coins\": [8,2,14,2,3,10,15,5], \"target\": 31 }\nassert my_solution.minimumAddedCoins(**test_input) == 1\n\ntest_input = { \"coins\": [3,7,12,10,11,5,3], \"target\": 36 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [5,3,14,8,10], \"target\": 33 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [9,14,9,14,4,1,4,12,12], \"target\": 41 }\nassert my_solution.minimumAddedCoins(**test_input) == 1\n\ntest_input = { \"coins\": [6,3,9,7,3,4,4,15,15,10], \"target\": 47 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [4,9,6], \"target\": 43 }\nassert my_solution.minimumAddedCoins(**test_input) == 3\n\ntest_input = { \"coins\": [12,9,13,12,10,4,9,9,4], \"target\": 28 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [6,8,2,13,1,5,6], \"target\": 31 }\nassert my_solution.minimumAddedCoins(**test_input) == 1\n\ntest_input = { \"coins\": [9,8,9,9,3,5,10,15,1], \"target\": 45 }\nassert my_solution.minimumAddedCoins(**test_input) == 1\n\ntest_input = { \"coins\": [1,10,15,15], \"target\": 24 }\nassert my_solution.minimumAddedCoins(**test_input) == 3\n\ntest_input = { \"coins\": [9,12,2], \"target\": 43 }\nassert my_solution.minimumAddedCoins(**test_input) == 4\n\ntest_input = { \"coins\": [14,13,10,2,2], \"target\": 16 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [11,5,5,13,4,13,10,3,4], \"target\": 21 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [8,9,1,5,8,7,6,8,6], \"target\": 47 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [4,10,9], \"target\": 18 }\nassert my_solution.minimumAddedCoins(**test_input) == 3\n\ntest_input = { \"coins\": [7,9,7,6,8,11], \"target\": 50 }\nassert my_solution.minimumAddedCoins(**test_input) == 3\n\ntest_input = { \"coins\": [11,6,6,14,12,2], \"target\": 46 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [8,9,2], \"target\": 31 }\nassert my_solution.minimumAddedCoins(**test_input) == 3\n\ntest_input = { \"coins\": [12,1,4,3,5,3], \"target\": 18 }\nassert my_solution.minimumAddedCoins(**test_input) == 1\n\ntest_input = { \"coins\": [4,3,13], \"target\": 34 }\nassert my_solution.minimumAddedCoins(**test_input) == 3\n\ntest_input = { \"coins\": [9,11,3], \"target\": 22 }\nassert my_solution.minimumAddedCoins(**test_input) == 3\n\ntest_input = { \"coins\": [1,11,15,1,10,13,7,6,12], \"target\": 28 }\nassert my_solution.minimumAddedCoins(**test_input) == 1\n\ntest_input = { \"coins\": [1,10,8,7,12], \"target\": 19 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [1,5,15,13,8,4,5,7], \"target\": 29 }\nassert my_solution.minimumAddedCoins(**test_input) == 1\n\ntest_input = { \"coins\": [3,8,13,8,5,3,7,2,9,8], \"target\": 50 }\nassert my_solution.minimumAddedCoins(**test_input) == 1\n\ntest_input = { \"coins\": [4,13,12], \"target\": 47 }\nassert my_solution.minimumAddedCoins(**test_input) == 4\n\ntest_input = { \"coins\": [9,3,10,9,11], \"target\": 48 }\nassert my_solution.minimumAddedCoins(**test_input) == 3\n\ntest_input = { \"coins\": [8,7,6,1,9,5,5], \"target\": 13 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [11,9,1,15], \"target\": 16 }\nassert my_solution.minimumAddedCoins(**test_input) == 3\n\ntest_input = { \"coins\": [8,13,8], \"target\": 27 }\nassert my_solution.minimumAddedCoins(**test_input) == 3\n\ntest_input = { \"coins\": [7,10,11,3,10,14], \"target\": 36 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [14,9,6,11,13,8,8,5,6], \"target\": 22 }\nassert my_solution.minimumAddedCoins(**test_input) == 3\n\ntest_input = { \"coins\": [9,3,6,10,11,1,5,14,3], \"target\": 27 }\nassert my_solution.minimumAddedCoins(**test_input) == 1\n\ntest_input = { \"coins\": [4,5,9,6,2,2,10,5,13], \"target\": 43 }\nassert my_solution.minimumAddedCoins(**test_input) == 1\n\ntest_input = { \"coins\": [3,10,2,13,6,13,14,14,3], \"target\": 28 }\nassert my_solution.minimumAddedCoins(**test_input) == 1\n\ntest_input = { \"coins\": [14,15,15,12,13,4,15], \"target\": 38 }\nassert my_solution.minimumAddedCoins(**test_input) == 3\n\ntest_input = { \"coins\": [10,5,12,11,9,8,1], \"target\": 12 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [15,13,12,4], \"target\": 31 }\nassert my_solution.minimumAddedCoins(**test_input) == 3\n\ntest_input = { \"coins\": [4,5,14,13,10,12], \"target\": 31 }\nassert my_solution.minimumAddedCoins(**test_input) == 2", "start_time": 1701570600} +{"task_id": "weekly-contest-374-count-complete-substrings", "url": "https://leetcode.com/problems/count-complete-substrings", "title": "count-complete-substrings", "meta": {"questionId": "3223", "questionFrontendId": "2953", "title": "Count Complete Substrings", "titleSlug": "count-complete-substrings", "isPaidOnly": false, "difficulty": "Hard", "likes": 154, "dislikes": 30, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个字符串word和一个整数 k。\n如果word的一个子字符串 s满足以下条件,我们称它是 完全字符串:\n\ns中每个字符 恰好出现 k次。\n相邻字符在字母表中的顺序 至多相差2。也就是说,s中两个相邻字符c1 和c2,它们在字母表中的位置相差至多为 2 。\n\n请你返回 word中 完全子字符串的数目。\n子字符串指的是一个字符串中一段连续 非空的字符序列。\n\n示例 1:\n\n输入:word = \"igigee\", k = 2\n输出:3\n解释:完全子字符串需要满足每个字符恰好出现 2 次,且相邻字符相差至多为 2 :igigee, igigee, igigee。\n\n示例 2:\n\n输入:word = \"aaabbbccc\", k = 3\n输出:6\n解释:完全子字符串需要满足每个字符恰好出现 3 次,且相邻字符相差至多为 2 :aaabbbccc, aaabbbccc, aaabbbccc, aaabbbccc, aaabbbccc, aaabbbccc 。\n\n\n提示:\n\n1 <= word.length <= 105\nword只包含小写英文字母。\n1 <= k <= word.length\n\"\"\"\nclass Solution:\n def countCompleteSubstrings(self, word: str, k: int) -> int:\n ", "prompt_sft": "给你一个字符串word和一个整数 k。\n如果word的一个子字符串 s满足以下条件,我们称它是 完全字符串:\n\ns中每个字符 恰好出现 k次。\n相邻字符在字母表中的顺序 至多相差2。也就是说,s中两个相邻字符c1 和c2,它们在字母表中的位置相差至多为 2 。\n\n请你返回 word中 完全子字符串的数目。\n子字符串指的是一个字符串中一段连续 非空的字符序列。\n\n示例 1:\n\n输入:word = \"igigee\", k = 2\n输出:3\n解释:完全子字符串需要满足每个字符恰好出现 2 次,且相邻字符相差至多为 2 :igigee, igigee, igigee。\n\n示例 2:\n\n输入:word = \"aaabbbccc\", k = 3\n输出:6\n解释:完全子字符串需要满足每个字符恰好出现 3 次,且相邻字符相差至多为 2 :aaabbbccc, aaabbbccc, aaabbbccc, aaabbbccc, aaabbbccc, aaabbbccc 。\n\n\n提示:\n\n1 <= word.length <= 105\nword只包含小写英文字母。\n1 <= k <= word.length\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def countCompleteSubstrings(self, word: str, k: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"word\": \"igigee\", \"k\": 2 }\nassert my_solution.countCompleteSubstrings(**test_input) == 3\n\ntest_input = { \"word\": \"aaabbbccc\", \"k\": 3 }\nassert my_solution.countCompleteSubstrings(**test_input) == 6\n\ntest_input = { \"word\": \"a\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 1\n\ntest_input = { \"word\": \"b\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 1\n\ntest_input = { \"word\": \"c\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 1\n\ntest_input = { \"word\": \"aa\", \"k\": 2 }\nassert my_solution.countCompleteSubstrings(**test_input) == 1\n\ntest_input = { \"word\": \"ab\", \"k\": 2 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"ac\", \"k\": 2 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"ba\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 3\n\ntest_input = { \"word\": \"bb\", \"k\": 2 }\nassert my_solution.countCompleteSubstrings(**test_input) == 1\n\ntest_input = { \"word\": \"bc\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 3\n\ntest_input = { \"word\": \"ca\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 3\n\ntest_input = { \"word\": \"cb\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 3\n\ntest_input = { \"word\": \"cc\", \"k\": 2 }\nassert my_solution.countCompleteSubstrings(**test_input) == 1\n\ntest_input = { \"word\": \"aaa\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 3\n\ntest_input = { \"word\": \"aab\", \"k\": 3 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"aac\", \"k\": 2 }\nassert my_solution.countCompleteSubstrings(**test_input) == 1\n\ntest_input = { \"word\": \"aba\", \"k\": 3 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"abb\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 4\n\ntest_input = { \"word\": \"abc\", \"k\": 3 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"aca\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 5\n\ntest_input = { \"word\": \"acb\", \"k\": 2 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"acc\", \"k\": 3 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"baa\", \"k\": 2 }\nassert my_solution.countCompleteSubstrings(**test_input) == 1\n\ntest_input = { \"word\": \"bab\", \"k\": 3 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"bac\", \"k\": 2 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"bba\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 4\n\ntest_input = { \"word\": \"bbb\", \"k\": 2 }\nassert my_solution.countCompleteSubstrings(**test_input) == 2\n\ntest_input = { \"word\": \"bbc\", \"k\": 2 }\nassert my_solution.countCompleteSubstrings(**test_input) == 1\n\ntest_input = { \"word\": \"bca\", \"k\": 2 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"bcb\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 5\n\ntest_input = { \"word\": \"bcc\", \"k\": 2 }\nassert my_solution.countCompleteSubstrings(**test_input) == 1\n\ntest_input = { \"word\": \"caa\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 4\n\ntest_input = { \"word\": \"cab\", \"k\": 2 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"cac\", \"k\": 2 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"cba\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 6\n\ntest_input = { \"word\": \"cbb\", \"k\": 3 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"cbc\", \"k\": 2 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"cca\", \"k\": 2 }\nassert my_solution.countCompleteSubstrings(**test_input) == 1\n\ntest_input = { \"word\": \"ccb\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 4\n\ntest_input = { \"word\": \"ccc\", \"k\": 2 }\nassert my_solution.countCompleteSubstrings(**test_input) == 2\n\ntest_input = { \"word\": \"aaaa\", \"k\": 4 }\nassert my_solution.countCompleteSubstrings(**test_input) == 1\n\ntest_input = { \"word\": \"aaab\", \"k\": 4 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"aaac\", \"k\": 4 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"aaba\", \"k\": 3 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"aabb\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 5\n\ntest_input = { \"word\": \"aabc\", \"k\": 3 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"aaca\", \"k\": 3 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"aacb\", \"k\": 2 }\nassert my_solution.countCompleteSubstrings(**test_input) == 1\n\ntest_input = { \"word\": \"aacc\", \"k\": 4 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"abaa\", \"k\": 3 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"abab\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 7\n\ntest_input = { \"word\": \"abac\", \"k\": 4 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"abba\", \"k\": 3 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"abbb\", \"k\": 4 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"abbc\", \"k\": 2 }\nassert my_solution.countCompleteSubstrings(**test_input) == 1\n\ntest_input = { \"word\": \"abca\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 9\n\ntest_input = { \"word\": \"abcb\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 8\n\ntest_input = { \"word\": \"abcc\", \"k\": 4 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"acaa\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 6\n\ntest_input = { \"word\": \"acab\", \"k\": 2 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"acac\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 7\n\ntest_input = { \"word\": \"acba\", \"k\": 2 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"acbb\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 7\n\ntest_input = { \"word\": \"acbc\", \"k\": 2 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"acca\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 6\n\ntest_input = { \"word\": \"accb\", \"k\": 3 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"accc\", \"k\": 4 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"baaa\", \"k\": 2 }\nassert my_solution.countCompleteSubstrings(**test_input) == 2\n\ntest_input = { \"word\": \"baab\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 6\n\ntest_input = { \"word\": \"baac\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 6\n\ntest_input = { \"word\": \"baba\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 7\n\ntest_input = { \"word\": \"babb\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 6\n\ntest_input = { \"word\": \"babc\", \"k\": 3 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"baca\", \"k\": 4 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"bacb\", \"k\": 3 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"bacc\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 7\n\ntest_input = { \"word\": \"bbaa\", \"k\": 2 }\nassert my_solution.countCompleteSubstrings(**test_input) == 3\n\ntest_input = { \"word\": \"bbab\", \"k\": 3 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"bbac\", \"k\": 4 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"bbba\", \"k\": 4 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"bbbb\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 4\n\ntest_input = { \"word\": \"bbbc\", \"k\": 3 }\nassert my_solution.countCompleteSubstrings(**test_input) == 1\n\ntest_input = { \"word\": \"bbca\", \"k\": 4 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"bbcb\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 6\n\ntest_input = { \"word\": \"bbcc\", \"k\": 4 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"bcaa\", \"k\": 2 }\nassert my_solution.countCompleteSubstrings(**test_input) == 1\n\ntest_input = { \"word\": \"bcab\", \"k\": 3 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"bcac\", \"k\": 3 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"bcba\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 8\n\ntest_input = { \"word\": \"bcbb\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 6\n\ntest_input = { \"word\": \"bcbc\", \"k\": 2 }\nassert my_solution.countCompleteSubstrings(**test_input) == 1\n\ntest_input = { \"word\": \"bcca\", \"k\": 4 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"bccb\", \"k\": 3 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"bccc\", \"k\": 4 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"caaa\", \"k\": 3 }\nassert my_solution.countCompleteSubstrings(**test_input) == 1\n\ntest_input = { \"word\": \"caab\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 6\n\ntest_input = { \"word\": \"caac\", \"k\": 4 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"caba\", \"k\": 4 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"cabb\", \"k\": 3 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0", "start_time": 1701570600} +{"task_id": "weekly-contest-374-count-the-number-of-infection-sequences", "url": "https://leetcode.com/problems/count-the-number-of-infection-sequences", "title": "count-the-number-of-infection-sequences", "meta": {"questionId": "3224", "questionFrontendId": "2954", "title": "Count the Number of Infection Sequences", "titleSlug": "count-the-number-of-infection-sequences", "isPaidOnly": false, "difficulty": "Hard", "likes": 50, "dislikes": 12, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个整数n和一个下标从 0开始的整数数组sick,数组按 升序排序。\n有n位小朋友站成一排,按顺序编号为 0到 n - 1。数组sick包含一开始得了感冒的小朋友的位置。如果位置为i的小朋友得了感冒,他会传染给下标为 i - 1或者 i + 1的小朋友,前提 是被传染的小朋友存在且还没有得感冒。每一秒中, 至多一位还没感冒的小朋友会被传染。\n经过有限的秒数后,队列中所有小朋友都会感冒。感冒序列指的是 所有一开始没有感冒的小朋友最后得感冒的顺序序列。请你返回所有感冒序列的数目。\n由于答案可能很大,请你将答案对109 + 7取余后返回。\n注意,感冒序列 不 包含一开始就得了感冒的小朋友的下标。\n\n示例 1:\n\n输入:n = 5, sick = [0,4]\n输出:4\n解释:一开始,下标为 1 ,2 和 3 的小朋友没有感冒。总共有 4 个可能的感冒序列:\n- 一开始,下标为 1 和 3 的小朋友可以被传染,因为他们分别挨着有感冒的小朋友 0 和 4 ,令下标为 1 的小朋友先被传染。\n然后,下标为 2 的小朋友挨着感冒的小朋友 1 ,下标为 3 的小朋友挨着感冒的小朋友 4 ,两位小朋友都可以被传染,令下标为 2 的小朋友被传染。\n最后,下标为 3 的小朋友被传染,因为他挨着感冒的小朋友 2 和 4 ,感冒序列为 [1,2,3] 。\n- 一开始,下标为 1 和 3 的小朋友可以被传染,因为他们分别挨着感冒的小朋友 0 和 4 ,令下标为 1 的小朋友先被传染。\n然后,下标为 2 的小朋友挨着感冒的小朋友 1 ,下标为 3 的小朋友挨着感冒的小朋友 4 ,两位小朋友都可以被传染,令下标为 3 的小朋友被传染。\n最后,下标为 2 的小朋友被传染,因为他挨着感冒的小朋友 1 和 3 ,感冒序列为 [1,3,2] 。\n- 感冒序列 [3,1,2] ,被传染的顺序:[0,1,2,3,4] => [0,1,2,3,4] => [0,1,2,3,4] => [0,1,2,3,4] 。\n- 感冒序列 [3,2,1] ,被传染的顺序:[0,1,2,3,4] => [0,1,2,3,4] => [0,1,2,3,4] => [0,1,2,3,4] 。\n\n示例 2:\n\n输入:n = 4, sick = [1]\n输出:3\n解释:一开始,下标为 0 ,2 和 3 的小朋友没有感冒。总共有 3 个可能的感冒序列:\n- 感冒序列 [0,2,3] ,被传染的顺序:[0,1,2,3] => [0,1,2,3] => [0,1,2,3] => [0,1,2,3] 。\n- 感冒序列 [2,0,3] ,被传染的顺序:[0,1,2,3] => [0,1,2,3] => [0,1,2,3] => [0,1,2,3] 。\n- 感冒序列 [2,3,0] ,被传染的顺序:[0,1,2,3] => [0,1,2,3] => [0,1,2,3] => [0,1,2,3] 。\n\n\n提示:\n\n2 <= n <= 105\n1 <= sick.length <= n - 1\n0 <= sick[i] <= n - 1\nsick按升序排列。\n\"\"\"\nclass Solution:\n def numberOfSequence(self, n: int, sick: List[int]) -> int:\n ", "prompt_sft": "给你一个整数n和一个下标从 0开始的整数数组sick,数组按 升序排序。\n有n位小朋友站成一排,按顺序编号为 0到 n - 1。数组sick包含一开始得了感冒的小朋友的位置。如果位置为i的小朋友得了感冒,他会传染给下标为 i - 1或者 i + 1的小朋友,前提 是被传染的小朋友存在且还没有得感冒。每一秒中, 至多一位还没感冒的小朋友会被传染。\n经过有限的秒数后,队列中所有小朋友都会感冒。感冒序列指的是 所有一开始没有感冒的小朋友最后得感冒的顺序序列。请你返回所有感冒序列的数目。\n由于答案可能很大,请你将答案对109 + 7取余后返回。\n注意,感冒序列 不 包含一开始就得了感冒的小朋友的下标。\n\n示例 1:\n\n输入:n = 5, sick = [0,4]\n输出:4\n解释:一开始,下标为 1 ,2 和 3 的小朋友没有感冒。总共有 4 个可能的感冒序列:\n- 一开始,下标为 1 和 3 的小朋友可以被传染,因为他们分别挨着有感冒的小朋友 0 和 4 ,令下标为 1 的小朋友先被传染。\n然后,下标为 2 的小朋友挨着感冒的小朋友 1 ,下标为 3 的小朋友挨着感冒的小朋友 4 ,两位小朋友都可以被传染,令下标为 2 的小朋友被传染。\n最后,下标为 3 的小朋友被传染,因为他挨着感冒的小朋友 2 和 4 ,感冒序列为 [1,2,3] 。\n- 一开始,下标为 1 和 3 的小朋友可以被传染,因为他们分别挨着感冒的小朋友 0 和 4 ,令下标为 1 的小朋友先被传染。\n然后,下标为 2 的小朋友挨着感冒的小朋友 1 ,下标为 3 的小朋友挨着感冒的小朋友 4 ,两位小朋友都可以被传染,令下标为 3 的小朋友被传染。\n最后,下标为 2 的小朋友被传染,因为他挨着感冒的小朋友 1 和 3 ,感冒序列为 [1,3,2] 。\n- 感冒序列 [3,1,2] ,被传染的顺序:[0,1,2,3,4] => [0,1,2,3,4] => [0,1,2,3,4] => [0,1,2,3,4] 。\n- 感冒序列 [3,2,1] ,被传染的顺序:[0,1,2,3,4] => [0,1,2,3,4] => [0,1,2,3,4] => [0,1,2,3,4] 。\n\n示例 2:\n\n输入:n = 4, sick = [1]\n输出:3\n解释:一开始,下标为 0 ,2 和 3 的小朋友没有感冒。总共有 3 个可能的感冒序列:\n- 感冒序列 [0,2,3] ,被传染的顺序:[0,1,2,3] => [0,1,2,3] => [0,1,2,3] => [0,1,2,3] 。\n- 感冒序列 [2,0,3] ,被传染的顺序:[0,1,2,3] => [0,1,2,3] => [0,1,2,3] => [0,1,2,3] 。\n- 感冒序列 [2,3,0] ,被传染的顺序:[0,1,2,3] => [0,1,2,3] => [0,1,2,3] => [0,1,2,3] 。\n\n\n提示:\n\n2 <= n <= 105\n1 <= sick.length <= n - 1\n0 <= sick[i] <= n - 1\nsick按升序排列。\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def numberOfSequence(self, n: int, sick: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"n\": 5, \"sick\": [0,4] }\nassert my_solution.numberOfSequence(**test_input) == 4\n\ntest_input = { \"n\": 4, \"sick\": [1] }\nassert my_solution.numberOfSequence(**test_input) == 3\n\ntest_input = { \"n\": 2, \"sick\": [0] }\nassert my_solution.numberOfSequence(**test_input) == 1\n\ntest_input = { \"n\": 5, \"sick\": [0] }\nassert my_solution.numberOfSequence(**test_input) == 1\n\ntest_input = { \"n\": 100, \"sick\": [0] }\nassert my_solution.numberOfSequence(**test_input) == 1\n\ntest_input = { \"n\": 2, \"sick\": [1] }\nassert my_solution.numberOfSequence(**test_input) == 1\n\ntest_input = { \"n\": 5, \"sick\": [1] }\nassert my_solution.numberOfSequence(**test_input) == 4\n\ntest_input = { \"n\": 5, \"sick\": [2] }\nassert my_solution.numberOfSequence(**test_input) == 6\n\ntest_input = { \"n\": 5, \"sick\": [3] }\nassert my_solution.numberOfSequence(**test_input) == 4\n\ntest_input = { \"n\": 5, \"sick\": [4] }\nassert my_solution.numberOfSequence(**test_input) == 1\n\ntest_input = { \"n\": 5, \"sick\": [0,1] }\nassert my_solution.numberOfSequence(**test_input) == 1\n\ntest_input = { \"n\": 3, \"sick\": [0,2] }\nassert my_solution.numberOfSequence(**test_input) == 1\n\ntest_input = { \"n\": 5, \"sick\": [0,2] }\nassert my_solution.numberOfSequence(**test_input) == 3\n\ntest_input = { \"n\": 5, \"sick\": [0,3] }\nassert my_solution.numberOfSequence(**test_input) == 6\n\ntest_input = { \"n\": 5, \"sick\": [1,2] }\nassert my_solution.numberOfSequence(**test_input) == 3\n\ntest_input = { \"n\": 5, \"sick\": [1,3] }\nassert my_solution.numberOfSequence(**test_input) == 6\n\ntest_input = { \"n\": 5, \"sick\": [1,4] }\nassert my_solution.numberOfSequence(**test_input) == 6\n\ntest_input = { \"n\": 5, \"sick\": [2,3] }\nassert my_solution.numberOfSequence(**test_input) == 3\n\ntest_input = { \"n\": 5, \"sick\": [2,4] }\nassert my_solution.numberOfSequence(**test_input) == 3\n\ntest_input = { \"n\": 5, \"sick\": [3,4] }\nassert my_solution.numberOfSequence(**test_input) == 1\n\ntest_input = { \"n\": 5, \"sick\": [0,1,2] }\nassert my_solution.numberOfSequence(**test_input) == 1\n\ntest_input = { \"n\": 5, \"sick\": [0,1,3] }\nassert my_solution.numberOfSequence(**test_input) == 2\n\ntest_input = { \"n\": 5, \"sick\": [0,1,4] }\nassert my_solution.numberOfSequence(**test_input) == 2\n\ntest_input = { \"n\": 5, \"sick\": [0,2,3] }\nassert my_solution.numberOfSequence(**test_input) == 2\n\ntest_input = { \"n\": 5, \"sick\": [0,2,4] }\nassert my_solution.numberOfSequence(**test_input) == 2\n\ntest_input = { \"n\": 5, \"sick\": [0,3,4] }\nassert my_solution.numberOfSequence(**test_input) == 2\n\ntest_input = { \"n\": 5, \"sick\": [1,2,3] }\nassert my_solution.numberOfSequence(**test_input) == 2\n\ntest_input = { \"n\": 5, \"sick\": [1,2,4] }\nassert my_solution.numberOfSequence(**test_input) == 2\n\ntest_input = { \"n\": 5, \"sick\": [1,3,4] }\nassert my_solution.numberOfSequence(**test_input) == 2\n\ntest_input = { \"n\": 5, \"sick\": [2,3,4] }\nassert my_solution.numberOfSequence(**test_input) == 1\n\ntest_input = { \"n\": 5, \"sick\": [0,1,2,3] }\nassert my_solution.numberOfSequence(**test_input) == 1\n\ntest_input = { \"n\": 10, \"sick\": [0,1,2,3] }\nassert my_solution.numberOfSequence(**test_input) == 1\n\ntest_input = { \"n\": 5, \"sick\": [0,1,2,4] }\nassert my_solution.numberOfSequence(**test_input) == 1\n\ntest_input = { \"n\": 10, \"sick\": [0,1,2,4] }\nassert my_solution.numberOfSequence(**test_input) == 6\n\ntest_input = { \"n\": 10, \"sick\": [0,1,2,5] }\nassert my_solution.numberOfSequence(**test_input) == 30\n\ntest_input = { \"n\": 10, \"sick\": [0,1,2,8] }\nassert my_solution.numberOfSequence(**test_input) == 96\n\ntest_input = { \"n\": 10, \"sick\": [0,1,2,9] }\nassert my_solution.numberOfSequence(**test_input) == 32\n\ntest_input = { \"n\": 5, \"sick\": [0,1,3,4] }\nassert my_solution.numberOfSequence(**test_input) == 1\n\ntest_input = { \"n\": 10, \"sick\": [0,1,3,5] }\nassert my_solution.numberOfSequence(**test_input) == 30\n\ntest_input = { \"n\": 10, \"sick\": [0,1,3,6] }\nassert my_solution.numberOfSequence(**test_input) == 120\n\ntest_input = { \"n\": 10, \"sick\": [0,1,3,7] }\nassert my_solution.numberOfSequence(**test_input) == 240\n\ntest_input = { \"n\": 10, \"sick\": [0,1,3,8] }\nassert my_solution.numberOfSequence(**test_input) == 240\n\ntest_input = { \"n\": 10, \"sick\": [0,1,4,5] }\nassert my_solution.numberOfSequence(**test_input) == 30\n\ntest_input = { \"n\": 10, \"sick\": [0,1,4,6] }\nassert my_solution.numberOfSequence(**test_input) == 120\n\ntest_input = { \"n\": 10, \"sick\": [0,1,4,7] }\nassert my_solution.numberOfSequence(**test_input) == 360\n\ntest_input = { \"n\": 10, \"sick\": [0,1,4,8] }\nassert my_solution.numberOfSequence(**test_input) == 480\n\ntest_input = { \"n\": 10, \"sick\": [0,1,4,9] }\nassert my_solution.numberOfSequence(**test_input) == 240\n\ntest_input = { \"n\": 10, \"sick\": [0,1,5,6] }\nassert my_solution.numberOfSequence(**test_input) == 80\n\ntest_input = { \"n\": 10, \"sick\": [0,1,5,7] }\nassert my_solution.numberOfSequence(**test_input) == 240\n\ntest_input = { \"n\": 10, \"sick\": [0,1,5,8] }\nassert my_solution.numberOfSequence(**test_input) == 480\n\ntest_input = { \"n\": 10, \"sick\": [0,1,5,9] }\nassert my_solution.numberOfSequence(**test_input) == 320\n\ntest_input = { \"n\": 10, \"sick\": [0,1,6,7] }\nassert my_solution.numberOfSequence(**test_input) == 120\n\ntest_input = { \"n\": 10, \"sick\": [0,1,6,8] }\nassert my_solution.numberOfSequence(**test_input) == 240\n\ntest_input = { \"n\": 10, \"sick\": [0,1,6,9] }\nassert my_solution.numberOfSequence(**test_input) == 240\n\ntest_input = { \"n\": 10, \"sick\": [0,1,7,8] }\nassert my_solution.numberOfSequence(**test_input) == 96\n\ntest_input = { \"n\": 10, \"sick\": [0,1,7,9] }\nassert my_solution.numberOfSequence(**test_input) == 96\n\ntest_input = { \"n\": 10, \"sick\": [0,1,8,9] }\nassert my_solution.numberOfSequence(**test_input) == 32\n\ntest_input = { \"n\": 5, \"sick\": [0,2,3,4] }\nassert my_solution.numberOfSequence(**test_input) == 1\n\ntest_input = { \"n\": 10, \"sick\": [0,2,3,4] }\nassert my_solution.numberOfSequence(**test_input) == 6\n\ntest_input = { \"n\": 10, \"sick\": [0,2,3,5] }\nassert my_solution.numberOfSequence(**test_input) == 30\n\ntest_input = { \"n\": 10, \"sick\": [0,2,3,6] }\nassert my_solution.numberOfSequence(**test_input) == 120\n\ntest_input = { \"n\": 10, \"sick\": [0,2,3,7] }\nassert my_solution.numberOfSequence(**test_input) == 240\n\ntest_input = { \"n\": 10, \"sick\": [0,2,3,8] }\nassert my_solution.numberOfSequence(**test_input) == 240\n\ntest_input = { \"n\": 10, \"sick\": [0,2,3,9] }\nassert my_solution.numberOfSequence(**test_input) == 96\n\ntest_input = { \"n\": 10, \"sick\": [0,2,4,5] }\nassert my_solution.numberOfSequence(**test_input) == 30\n\ntest_input = { \"n\": 10, \"sick\": [0,2,4,6] }\nassert my_solution.numberOfSequence(**test_input) == 120\n\ntest_input = { \"n\": 10, \"sick\": [0,2,4,7] }\nassert my_solution.numberOfSequence(**test_input) == 360\n\ntest_input = { \"n\": 10, \"sick\": [0,2,4,8] }\nassert my_solution.numberOfSequence(**test_input) == 480\n\ntest_input = { \"n\": 10, \"sick\": [0,2,4,9] }\nassert my_solution.numberOfSequence(**test_input) == 240\n\ntest_input = { \"n\": 10, \"sick\": [0,2,5,6] }\nassert my_solution.numberOfSequence(**test_input) == 120\n\ntest_input = { \"n\": 10, \"sick\": [0,2,5,7] }\nassert my_solution.numberOfSequence(**test_input) == 360\n\ntest_input = { \"n\": 10, \"sick\": [0,2,5,8] }\nassert my_solution.numberOfSequence(**test_input) == 720\n\ntest_input = { \"n\": 10, \"sick\": [0,2,5,9] }\nassert my_solution.numberOfSequence(**test_input) == 480\n\ntest_input = { \"n\": 10, \"sick\": [0,2,6,7] }\nassert my_solution.numberOfSequence(**test_input) == 240\n\ntest_input = { \"n\": 10, \"sick\": [0,2,6,8] }\nassert my_solution.numberOfSequence(**test_input) == 480\n\ntest_input = { \"n\": 10, \"sick\": [0,2,7,8] }\nassert my_solution.numberOfSequence(**test_input) == 240\n\ntest_input = { \"n\": 10, \"sick\": [0,2,7,9] }\nassert my_solution.numberOfSequence(**test_input) == 240\n\ntest_input = { \"n\": 10, \"sick\": [0,2,8,9] }\nassert my_solution.numberOfSequence(**test_input) == 96\n\ntest_input = { \"n\": 10, \"sick\": [0,3,4,5] }\nassert my_solution.numberOfSequence(**test_input) == 30\n\ntest_input = { \"n\": 10, \"sick\": [0,3,4,7] }\nassert my_solution.numberOfSequence(**test_input) == 360\n\ntest_input = { \"n\": 10, \"sick\": [0,3,4,8] }\nassert my_solution.numberOfSequence(**test_input) == 480\n\ntest_input = { \"n\": 10, \"sick\": [0,3,4,9] }\nassert my_solution.numberOfSequence(**test_input) == 240\n\ntest_input = { \"n\": 10, \"sick\": [0,3,5,6] }\nassert my_solution.numberOfSequence(**test_input) == 120\n\ntest_input = { \"n\": 10, \"sick\": [0,3,5,7] }\nassert my_solution.numberOfSequence(**test_input) == 360\n\ntest_input = { \"n\": 10, \"sick\": [0,3,6,7] }\nassert my_solution.numberOfSequence(**test_input) == 360\n\ntest_input = { \"n\": 10, \"sick\": [0,3,6,8] }\nassert my_solution.numberOfSequence(**test_input) == 720\n\ntest_input = { \"n\": 10, \"sick\": [0,3,6,9] }\nassert my_solution.numberOfSequence(**test_input) == 720\n\ntest_input = { \"n\": 10, \"sick\": [0,3,7,8] }\nassert my_solution.numberOfSequence(**test_input) == 480\n\ntest_input = { \"n\": 10, \"sick\": [0,3,7,9] }\nassert my_solution.numberOfSequence(**test_input) == 480\n\ntest_input = { \"n\": 10, \"sick\": [0,3,8,9] }\nassert my_solution.numberOfSequence(**test_input) == 240\n\ntest_input = { \"n\": 10, \"sick\": [0,4,5,6] }\nassert my_solution.numberOfSequence(**test_input) == 80\n\ntest_input = { \"n\": 10, \"sick\": [0,4,5,7] }\nassert my_solution.numberOfSequence(**test_input) == 240\n\ntest_input = { \"n\": 10, \"sick\": [0,4,5,9] }\nassert my_solution.numberOfSequence(**test_input) == 320\n\ntest_input = { \"n\": 10, \"sick\": [0,4,6,7] }\nassert my_solution.numberOfSequence(**test_input) == 240\n\ntest_input = { \"n\": 10, \"sick\": [0,4,6,8] }\nassert my_solution.numberOfSequence(**test_input) == 480\n\ntest_input = { \"n\": 10, \"sick\": [0,4,8,9] }\nassert my_solution.numberOfSequence(**test_input) == 320\n\ntest_input = { \"n\": 10, \"sick\": [0,5,6,7] }\nassert my_solution.numberOfSequence(**test_input) == 120\n\ntest_input = { \"n\": 10, \"sick\": [0,5,6,9] }\nassert my_solution.numberOfSequence(**test_input) == 240\n\ntest_input = { \"n\": 10, \"sick\": [0,5,7,8] }\nassert my_solution.numberOfSequence(**test_input) == 240\n\ntest_input = { \"n\": 10, \"sick\": [0,5,7,9] }\nassert my_solution.numberOfSequence(**test_input) == 240", "start_time": 1701570600} +{"task_id": "weekly-contest-373-matrix-similarity-after-cyclic-shifts", "url": "https://leetcode.com/problems/matrix-similarity-after-cyclic-shifts", "title": "matrix-similarity-after-cyclic-shifts", "meta": {"questionId": "3215", "questionFrontendId": "2946", "title": "Matrix Similarity After Cyclic Shifts", "titleSlug": "matrix-similarity-after-cyclic-shifts", "isPaidOnly": false, "difficulty": "Easy", "likes": 72, "dislikes": 48, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0 开始且大小为 m x n 的整数矩阵 mat 和一个整数 k 。请你将矩阵中的 奇数 行循环 右 移 k 次,偶数 行循环 左 移 k 次。\n如果初始矩阵和最终矩阵完全相同,则返回 true ,否则返回 false 。\n\n示例 1:\n\n输入:mat = [[1,2,1,2],[5,5,5,5],[6,3,6,3]], k = 2\n输出:true\n解释:\n\n\n初始矩阵如图一所示。\n图二表示对奇数行右移一次且对偶数行左移一次后的矩阵状态。\n图三是经过两次循环移位后的最终矩阵状态,与初始矩阵相同。\n因此,返回 true 。\n\n示例 2:\n\n输入:mat = [[2,2],[2,2]], k = 3\n输出:true\n解释:由于矩阵中的所有值都相等,即使进行循环移位,矩阵仍然保持不变。因此,返回 true 。\n\n示例 3:\n\n输入:mat = [[1,2]], k = 1\n输出:false\n解释:循环移位一次后,mat = [[2,1]],与初始矩阵不相等。因此,返回 false 。\n\n\n提示:\n\n1 <= mat.length <= 25\n1 <= mat[i].length <= 25\n1 <= mat[i][j] <= 25\n1 <= k <= 50\n\"\"\"\nclass Solution:\n def areSimilar(self, mat: List[List[int]], k: int) -> bool:\n ", "prompt_sft": "给你一个下标从 0 开始且大小为 m x n 的整数矩阵 mat 和一个整数 k 。请你将矩阵中的 奇数 行循环 右 移 k 次,偶数 行循环 左 移 k 次。\n如果初始矩阵和最终矩阵完全相同,则返回 true ,否则返回 false 。\n\n示例 1:\n\n输入:mat = [[1,2,1,2],[5,5,5,5],[6,3,6,3]], k = 2\n输出:true\n解释:\n\n\n初始矩阵如图一所示。\n图二表示对奇数行右移一次且对偶数行左移一次后的矩阵状态。\n图三是经过两次循环移位后的最终矩阵状态,与初始矩阵相同。\n因此,返回 true 。\n\n示例 2:\n\n输入:mat = [[2,2],[2,2]], k = 3\n输出:true\n解释:由于矩阵中的所有值都相等,即使进行循环移位,矩阵仍然保持不变。因此,返回 true 。\n\n示例 3:\n\n输入:mat = [[1,2]], k = 1\n输出:false\n解释:循环移位一次后,mat = [[2,1]],与初始矩阵不相等。因此,返回 false 。\n\n\n提示:\n\n1 <= mat.length <= 25\n1 <= mat[i].length <= 25\n1 <= mat[i][j] <= 25\n1 <= k <= 50\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def areSimilar(self, mat: List[List[int]], k: int) -> bool:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"mat\": [[1,2]], \"k\": 1 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[1,2,1,2],[5,5,5,5],[6,3,6,3]], \"k\": 2 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[4,9,10,10],[9,3,8,4],[2,5,3,8],[6,1,10,4]], \"k\": 5 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[5,8,8,4,7,2,3,4,3,10],[8,7,9,1,3,4,2,6,6,9],[6,2,10,10,4,6,3,4,1,1]], \"k\": 3 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[4,7,9,1,10,5,2,6,1,7],[8,9,9,2,3,2,3,2,3,5],[1,2,4,7,4,7,9,7,9,9]], \"k\": 5 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[10,6,3,6],[4,8,1,2]], \"k\": 6 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[7,10,6,7,7,4,4,7,2,2],[3,6,4,8,4,6,4,3,1,4],[4,8,7,1,10,2,10,8,10,1],[4,7,10,5,1,9,8,3,5,8],[3,7,6,5,3,1,3,2,8,5],[6,1,5,10,8,7,7,10,1,3]], \"k\": 7 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[6,5,3],[4,6,2],[4,1,8],[3,9,1],[6,1,2],[1,9,9],[2,6,10]], \"k\": 5 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[2,4],[9,8]], \"k\": 9 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[2,2],[2,2]], \"k\": 3 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[9,1,10,6,10,7,3],[9,2,9,10,7,10,10]], \"k\": 4 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[7,7],[10,10],[4,4]], \"k\": 2 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[6,6,6,6,6,6,6,6,6,6],[9,9,9,9,9,9,9,9,9,9],[1,1,1,1,1,1,1,1,1,1],[10,10,10,10,10,10,10,10,10,10],[2,2,2,2,2,2,2,2,2,2],[6,6,6,6,6,6,6,6,6,6],[7,7,7,7,7,7,7,7,7,7],[9,9,9,9,9,9,9,9,9,9],[8,8,8,8,8,8,8,8,8,8]], \"k\": 1 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[6,9,1],[8,9,7],[2,8,7],[1,5,7],[10,5,9],[5,5,6],[8,6,1],[5,7,8]], \"k\": 5 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[3,10,3,10,3,10,3,10],[5,8,5,8,5,8,5,8],[3,9,3,9,3,9,3,9],[3,8,3,8,3,8,3,8],[2,3,2,3,2,3,2,3]], \"k\": 2 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[9,5,3,10],[4,7,10,7],[1,7,9,4],[8,8,1,6],[6,7,6,1],[3,1,1,8],[9,2,8,3],[1,9,7,6]], \"k\": 4 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[4,6],[10,1],[8,8],[10,9],[9,10]], \"k\": 9 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[1,9,6,7,1,4,7,6,7],[7,10,6,6,4,9,6,8,2],[3,9,8,10,9,9,3,9,5],[8,5,2,3,4,7,3,3,1],[1,5,9,9,6,1,9,7,5],[8,3,10,2,4,8,7,9,9],[5,9,6,8,4,3,4,6,4],[7,2,6,9,2,4,5,4,9],[4,8,7,5,3,6,3,9,5]], \"k\": 1 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[9,3,3,7,7,5,3,3],[10,9,9,3,6,8,7,5],[8,9,3,10,10,10,2,1],[9,7,8,2,3,4,8,4],[5,9,5,2,2,6,5,7],[1,5,9,7,8,1,1,1]], \"k\": 10 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[10,6,10,6,10,6,10,6]], \"k\": 4 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[2,4],[6,1],[1,2],[2,10],[6,5],[4,9]], \"k\": 7 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[8,8,8,8,8,8,8,8,8,8],[7,7,7,7,7,7,7,7,7,7],[6,6,6,6,6,6,6,6,6,6]], \"k\": 2 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[8,10,1,7,1,3,9,6,8],[9,10,4,8,8,9,3,10,10],[4,3,2,2,3,6,4,6,1],[9,4,1,4,5,2,5,1,8],[3,10,6,3,8,4,8,3,10]], \"k\": 7 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[8,9],[3,3],[5,6],[10,1],[2,5],[5,8],[5,4],[9,5]], \"k\": 2 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[9,1,8,9,2,9,1,8,9,2],[10,2,7,8,9,10,2,7,8,9],[7,6,6,9,5,7,6,6,9,5]], \"k\": 5 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[4,4,4,2,7,9,1,8,9,8],[3,3,6,3,8,8,7,7,4,5],[10,1,3,7,6,5,7,10,3,10]], \"k\": 5 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[9,10,10,6,6,8,10,7,10,9],[10,6,1,10,10,5,7,9,9,2],[8,5,8,3,5,2,2,9,7,10]], \"k\": 20 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[4,5,1,3,10],[10,5,9,10,2],[8,10,2,8,1],[5,8,9,3,4],[6,6,10,10,10],[6,1,7,9,4],[6,7,6,2,10]], \"k\": 8 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[2,7,1,10,5,3],[10,7,8,2,2,2],[9,6,1,4,10,6],[6,1,1,9,2,5],[6,4,7,3,6,4],[10,10,5,4,2,1],[7,3,3,7,1,5],[5,8,2,10,5,1],[3,1,5,1,5,7]], \"k\": 2 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[7,7,4],[8,9,9],[9,7,5],[6,3,6],[4,9,5],[1,10,3],[4,4,7],[4,7,6]], \"k\": 1 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[10,10],[10,10],[5,5],[3,3],[2,2]], \"k\": 2 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[6,4,7,6,3,9,4,2,10,5],[9,7,7,3,10,9,7,4,3,1]], \"k\": 20 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[7]], \"k\": 1 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[6,3,2]], \"k\": 4 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[6,8]], \"k\": 4 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[6,6,7,7,1],[10,3,3,2,2],[7,9,8,10,7],[10,8,2,7,1],[2,2,1,2,3],[6,2,8,10,10],[6,2,6,3,3],[2,2,2,4,7]], \"k\": 4 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[8,8,5,3,7,8],[8,9,1,7,3,10],[4,3,9,8,4,7],[2,2,5,8,2,2],[6,1,2,7,4,8],[10,9,6,3,1,4],[7,1,6,7,4,6]], \"k\": 2 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[7],[5],[5],[4],[4],[5],[8]], \"k\": 6 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[8,8,5,10,7,8,8,5,10,7],[1,2,6,10,7,1,2,6,10,7]], \"k\": 5 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[10,2,6,7,6,6,5],[6,3,3,4,6,5,7],[6,8,5,10,8,4,1]], \"k\": 8 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[4,10,9,7,9,9,2],[3,9,2,1,8,9,10],[7,10,9,7,2,3,8]], \"k\": 1 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[1,7,10,10,9,2,1],[6,4,5,2,3,3,10],[2,6,8,3,6,1,4]], \"k\": 9 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[2,9,2,2,6,10,4,8,3],[10,8,4,5,10,3,3,8,5],[2,6,4,5,4,8,5,5,4],[1,3,2,10,5,3,10,9,4],[2,4,2,4,7,7,1,4,9]], \"k\": 2 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[9,5,6,9,5,6],[1,9,4,1,9,4],[5,7,2,5,7,2],[9,1,5,9,1,5],[6,8,6,6,8,6],[10,1,7,10,1,7]], \"k\": 6 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[2,7,6],[10,6,5],[10,2,4],[10,7,9],[5,8,6],[10,6,3],[10,9,6],[5,2,8],[10,1,2]], \"k\": 7 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[5,4,5,10,5]], \"k\": 9 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[10,10,9],[5,6,7],[1,4,7],[5,1,1],[5,1,5],[5,10,3]], \"k\": 2 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[9,4,5],[8,5,4],[2,9,9]], \"k\": 10 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[4,2,2,7,9,1,1,2],[1,8,7,5,7,5,9,6],[2,9,4,10,1,8,5,4]], \"k\": 3 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[10],[7],[8],[2]], \"k\": 1 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[10],[1],[5],[3],[1],[1]], \"k\": 4 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[7,1,7,7,1,7,7,1,7],[5,10,1,5,10,1,5,10,1]], \"k\": 3 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[4,7,9,9,4,7,9,9],[8,9,7,4,8,9,7,4],[6,8,6,4,6,8,6,4],[9,8,8,8,9,8,8,8],[3,6,5,3,3,6,5,3],[1,9,4,3,1,9,4,3],[8,3,2,7,8,3,2,7],[3,8,2,8,3,8,2,8],[6,5,2,8,6,5,2,8]], \"k\": 8 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[4],[5],[4],[2],[4],[2],[7],[4]], \"k\": 1 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[3,8,5,4,10,2],[9,3,9,5,4,2]], \"k\": 6 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[8,9,10,6,5,7],[8,9,9,3,3,9],[4,5,4,4,4,10],[2,6,3,9,7,1],[10,10,4,4,6,10]], \"k\": 9 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[7,7,7,7,7],[1,1,1,1,1]], \"k\": 1 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[5,7,5,5,1,9,1,8,6,7],[8,1,9,10,10,5,4,9,1,8],[10,6,8,10,2,10,9,4,9,6],[4,7,10,2,7,4,2,10,3,5],[2,2,4,9,10,1,6,2,8,3],[1,3,5,9,9,8,10,8,9,10],[7,8,7,7,6,9,2,5,8,4],[6,9,4,2,4,10,10,8,10,7]], \"k\": 8 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[2,9,10],[7,3,3],[7,6,2]], \"k\": 1 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[2,5,8,9,6,8],[3,6,4,10,10,6],[9,6,10,9,6,5]], \"k\": 1 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[2,2],[4,5],[3,2],[4,6],[1,9],[5,3],[3,5],[2,4],[3,9]], \"k\": 7 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[1,8,6,8,6,7,1,6]], \"k\": 16 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[7,9,9,2,7],[8,5,8,6,7],[2,9,8,5,2],[9,9,2,6,8],[7,4,10,10,8]], \"k\": 6 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[8,8],[6,6],[2,2],[8,8],[9,9],[8,8],[10,10],[3,3],[4,4],[5,5]], \"k\": 1 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[3,3,3,3,3,3],[5,3,5,3,5,3],[2,5,2,5,2,5],[8,8,8,8,8,8],[3,8,3,8,3,8],[5,3,5,3,5,3],[1,8,1,8,1,8],[8,9,8,9,8,9],[2,8,2,8,2,8]], \"k\": 4 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[2,2,2,2,2],[7,7,7,7,7],[5,5,5,5,5],[8,8,8,8,8],[1,1,1,1,1],[10,10,10,10,10],[7,7,7,7,7]], \"k\": 1 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[3,1,10,5,10,3,1,10,5,10],[3,5,9,2,10,3,5,9,2,10],[4,6,3,5,7,4,6,3,5,7],[8,10,6,7,8,8,10,6,7,8]], \"k\": 5 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[10,7,1,7],[3,5,9,5],[2,8,3,10],[8,7,1,9],[3,8,6,3],[6,5,8,9],[8,7,5,1],[10,4,9,9],[4,6,1,9],[6,10,1,7]], \"k\": 3 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[1,10,3,9,6],[7,1,3,4,10]], \"k\": 3 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[7,7],[2,2],[5,5]], \"k\": 1 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[4,4,4,4,4,4,4],[2,2,2,2,2,2,2],[3,3,3,3,3,3,3],[8,8,8,8,8,8,8],[6,6,6,6,6,6,6]], \"k\": 2 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[10,3,5,3,10,3,5,3],[2,3,9,7,2,3,9,7],[10,4,4,8,10,4,4,8],[10,2,7,9,10,2,7,9],[8,1,8,3,8,1,8,3],[1,9,1,7,1,9,1,7]], \"k\": 4 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[6],[7],[1]], \"k\": 2 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[7,6,4,5]], \"k\": 5 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[5,5,5,5],[5,5,5,5],[10,10,10,10],[2,2,2,2],[3,3,3,3],[2,2,2,2],[8,8,8,8],[10,10,10,10],[9,9,9,9],[7,7,7,7]], \"k\": 2 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[5,1,1,9,4,1,7,6],[8,7,7,6,2,2,1,5],[10,2,5,3,10,7,7,5],[10,6,1,6,8,4,6,3],[10,10,9,8,2,10,8,7],[7,4,2,10,2,3,8,7],[4,7,5,9,10,4,3,2],[10,9,7,7,6,3,9,7],[1,4,8,4,6,5,5,1]], \"k\": 1 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[3]], \"k\": 1 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[1,1,1,1,1],[10,10,10,10,10],[10,10,10,10,10]], \"k\": 2 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[6],[3],[2],[10]], \"k\": 2 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[9,7,5,6],[5,2,1,8],[9,4,3,6],[5,7,4,1],[8,1,8,9],[4,3,6,5],[6,2,7,3],[1,3,6,4],[4,9,5,5]], \"k\": 7 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[10,7,2,10,5,2,7],[10,10,3,8,3,3,8],[4,3,10,10,10,4,10]], \"k\": 4 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[8,5],[8,10],[8,10],[1,1],[2,1]], \"k\": 7 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[9,9],[8,8],[2,2],[1,1],[8,8],[4,4],[9,9],[4,4],[6,6]], \"k\": 2 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[10,1,1],[7,10,6],[9,6,6],[9,8,10],[8,2,1],[6,8,3],[8,6,6]], \"k\": 5 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[2,10,5,6,5,5],[6,3,1,5,4,7],[5,6,3,2,4,10],[9,2,6,8,6,2],[3,6,8,4,9,1]], \"k\": 8 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[10,3,4,2,8,10,3,4,2,8],[9,9,3,4,5,9,9,3,4,5],[6,9,9,2,7,6,9,9,2,7],[5,2,3,3,4,5,2,3,3,4]], \"k\": 5 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[3,4,10,3,4,10],[5,5,4,5,5,4],[5,5,3,5,5,3],[7,8,7,7,8,7]], \"k\": 3 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[7,1,9,3,6],[5,6,5,5,6],[2,3,5,10,8],[5,10,2,5,4],[7,9,1,7,10],[8,2,3,4,2],[1,6,9,2,1]], \"k\": 7 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[3,3],[3,3],[4,4],[3,3],[8,8],[5,5]], \"k\": 1 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[2,10,2,6,3,6],[4,5,10,7,7,9],[1,7,4,1,9,4],[3,7,6,3,1,4],[4,10,4,6,3,5],[1,5,5,9,5,1],[10,2,5,4,7,10],[2,9,7,4,5,3],[5,5,1,2,8,3]], \"k\": 2 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[5],[5],[5]], \"k\": 2 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[9,5,5,6,7],[7,9,3,8,1],[8,8,8,9,5],[1,3,2,6,9],[3,6,4,8,7],[9,3,3,9,10],[8,5,1,2,8],[7,3,10,5,1],[8,4,5,5,1]], \"k\": 5 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[5,8,5,2,8,5,9],[7,8,2,2,8,2,2],[4,5,6,7,3,9,9],[5,7,4,8,2,9,2],[9,5,3,3,5,7,3],[3,8,9,6,3,10,7],[6,7,3,7,3,6,6]], \"k\": 8 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[8,8,8,8,8,8],[8,8,8,8,8,8],[2,2,2,2,2,2],[6,6,6,6,6,6],[9,9,9,9,9,9],[10,10,10,10,10,10],[10,10,10,10,10,10]], \"k\": 2 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[7,7,10,2],[3,5,7,6],[2,10,1,8],[8,3,1,10],[5,1,3,3],[6,3,4,9],[8,9,1,1]], \"k\": 7 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[5,2,7,2,6,10,7,5],[10,9,4,1,7,2,7,4],[2,6,7,3,2,10,4,5],[10,4,7,2,10,3,6,2]], \"k\": 16 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[9,10,10,1],[1,7,3,5],[9,6,4,7],[6,6,4,5],[2,4,2,7],[2,1,1,1],[7,2,1,8],[2,8,1,3],[7,4,6,1],[10,10,7,5]], \"k\": 4 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[7,3,10,2,3,1,10],[7,6,10,1,3,2,1],[9,1,5,7,1,8,3],[4,10,10,7,7,9,7],[7,9,1,5,3,8,4],[4,9,5,10,2,8,10],[2,5,10,3,6,2,9],[6,7,2,3,4,2,2]], \"k\": 1 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[8,8],[9,9],[2,2],[10,10],[10,10],[1,1],[5,5],[9,9],[7,7]], \"k\": 2 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[2,1,7,3,7,6,7,9,9,3],[3,9,10,4,4,6,8,10,5,6],[9,8,6,2,3,4,9,1,9,10],[7,10,8,8,3,9,9,5,8,9],[9,5,6,9,9,6,4,3,2,3],[3,10,6,2,7,6,10,6,2,6],[7,9,7,4,5,7,2,4,9,5],[4,7,9,6,7,4,6,4,10,4]], \"k\": 6 }\nassert my_solution.areSimilar(**test_input) == False", "start_time": 1700965800} +{"task_id": "weekly-contest-373-count-beautiful-substrings-i", "url": "https://leetcode.com/problems/count-beautiful-substrings-i", "title": "count-beautiful-substrings-i", "meta": {"questionId": "3210", "questionFrontendId": "2947", "title": "Count Beautiful Substrings I", "titleSlug": "count-beautiful-substrings-i", "isPaidOnly": false, "difficulty": "Medium", "likes": 102, "dislikes": 8, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个字符串 s 和一个正整数 k 。\n用 vowels 和 consonants 分别表示字符串中元音字母和辅音字母的数量。\n如果某个字符串满足以下条件,则称其为 美丽字符串 :\n\nvowels == consonants,即元音字母和辅音字母的数量相等。\n(vowels * consonants) % k == 0,即元音字母和辅音字母的数量的乘积能被 k 整除。\n\n返回字符串 s 中 非空美丽子字符串 的数量。\n子字符串是字符串中的一个连续字符序列。\n英语中的 元音字母 为 'a'、'e'、'i'、'o' 和 'u' 。\n英语中的 辅音字母 为除了元音字母之外的所有字母。\n\n示例 1:\n\n输入:s = \"baeyh\", k = 2\n输出:2\n解释:字符串 s 中有 2 个美丽子字符串。\n- 子字符串 \"baeyh\",vowels = 2([\"a\",\"e\"]),consonants = 2([\"y\",\"h\"])。\n可以看出字符串 \"aeyh\" 是美丽字符串,因为 vowels == consonants 且 vowels * consonants % k == 0 。\n- 子字符串 \"baeyh\",vowels = 2([\"a\",\"e\"]),consonants = 2([\"b\",\"y\"])。\n可以看出字符串 \"baey\" 是美丽字符串,因为 vowels == consonants 且 vowels * consonants % k == 0 。\n可以证明字符串 s 中只有 2 个美丽子字符串。\n\n示例 2:\n\n输入:s = \"abba\", k = 1\n输出:3\n解释:字符串 s 中有 3 个美丽子字符串。\n- 子字符串 \"abba\",vowels = 1([\"a\"]),consonants = 1([\"b\"])。\n- 子字符串 \"abba\",vowels = 1([\"a\"]),consonants = 1([\"b\"])。\n- 子字符串 \"abba\",vowels = 2([\"a\",\"a\"]),consonants = 2([\"b\",\"b\"])。\n可以证明字符串 s 中只有 3 个美丽子字符串。\n\n示例 3:\n\n输入:s = \"bcdf\", k = 1\n输出:0\n解释:字符串 s 中没有美丽子字符串。\n\n\n提示:\n\n1 <= s.length <= 1000\n1 <= k <= 1000\ns 仅由小写英文字母组成。\n\"\"\"\nclass Solution:\n def beautifulSubstrings(self, s: str, k: int) -> int:\n ", "prompt_sft": "给你一个字符串 s 和一个正整数 k 。\n用 vowels 和 consonants 分别表示字符串中元音字母和辅音字母的数量。\n如果某个字符串满足以下条件,则称其为 美丽字符串 :\n\nvowels == consonants,即元音字母和辅音字母的数量相等。\n(vowels * consonants) % k == 0,即元音字母和辅音字母的数量的乘积能被 k 整除。\n\n返回字符串 s 中 非空美丽子字符串 的数量。\n子字符串是字符串中的一个连续字符序列。\n英语中的 元音字母 为 'a'、'e'、'i'、'o' 和 'u' 。\n英语中的 辅音字母 为除了元音字母之外的所有字母。\n\n示例 1:\n\n输入:s = \"baeyh\", k = 2\n输出:2\n解释:字符串 s 中有 2 个美丽子字符串。\n- 子字符串 \"baeyh\",vowels = 2([\"a\",\"e\"]),consonants = 2([\"y\",\"h\"])。\n可以看出字符串 \"aeyh\" 是美丽字符串,因为 vowels == consonants 且 vowels * consonants % k == 0 。\n- 子字符串 \"baeyh\",vowels = 2([\"a\",\"e\"]),consonants = 2([\"b\",\"y\"])。\n可以看出字符串 \"baey\" 是美丽字符串,因为 vowels == consonants 且 vowels * consonants % k == 0 。\n可以证明字符串 s 中只有 2 个美丽子字符串。\n\n示例 2:\n\n输入:s = \"abba\", k = 1\n输出:3\n解释:字符串 s 中有 3 个美丽子字符串。\n- 子字符串 \"abba\",vowels = 1([\"a\"]),consonants = 1([\"b\"])。\n- 子字符串 \"abba\",vowels = 1([\"a\"]),consonants = 1([\"b\"])。\n- 子字符串 \"abba\",vowels = 2([\"a\",\"a\"]),consonants = 2([\"b\",\"b\"])。\n可以证明字符串 s 中只有 3 个美丽子字符串。\n\n示例 3:\n\n输入:s = \"bcdf\", k = 1\n输出:0\n解释:字符串 s 中没有美丽子字符串。\n\n\n提示:\n\n1 <= s.length <= 1000\n1 <= k <= 1000\ns 仅由小写英文字母组成。\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def beautifulSubstrings(self, s: str, k: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"s\": \"baeyh\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 2\n\ntest_input = { \"s\": \"abba\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 3\n\ntest_input = { \"s\": \"bcdf\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"ihroyeeb\", \"k\": 5 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"uzuxpzou\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 1\n\ntest_input = { \"s\": \"ouuoeqd\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 1\n\ntest_input = { \"s\": \"eeebjoxxujuaeoqibd\", \"k\": 8 }\nassert my_solution.beautifulSubstrings(**test_input) == 4\n\ntest_input = { \"s\": \"ilougekqlovegioemdvu\", \"k\": 4 }\nassert my_solution.beautifulSubstrings(**test_input) == 21\n\ntest_input = { \"s\": \"tqaewreikaztwpfwnef\", \"k\": 8 }\nassert my_solution.beautifulSubstrings(**test_input) == 3\n\ntest_input = { \"s\": \"oykiuhsafgfjumnzb\", \"k\": 7 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"ifvsa\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"svzauyuevujektj\", \"k\": 5 }\nassert my_solution.beautifulSubstrings(**test_input) == 3\n\ntest_input = { \"s\": \"urahjig\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 2\n\ntest_input = { \"s\": \"ime\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"oacghieut\", \"k\": 5 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"aoluu\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"ioaoiciiuoziout\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 5\n\ntest_input = { \"s\": \"ouafupsuhid\", \"k\": 6 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"ox\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"tlaiwoauazutusiaaui\", \"k\": 10 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"caepeym\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 2\n\ntest_input = { \"s\": \"apyxvceue\", \"k\": 4 }\nassert my_solution.beautifulSubstrings(**test_input) == 1\n\ntest_input = { \"s\": \"imkqbb\", \"k\": 4 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"caaz\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 1\n\ntest_input = { \"s\": \"pyicoy\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 6\n\ntest_input = { \"s\": \"uopmyrsntjhiroikup\", \"k\": 8 }\nassert my_solution.beautifulSubstrings(**test_input) == 2\n\ntest_input = { \"s\": \"aujfxqxcj\", \"k\": 5 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"eeizejuoxeumz\", \"k\": 4 }\nassert my_solution.beautifulSubstrings(**test_input) == 6\n\ntest_input = { \"s\": \"uuouuaifnboeiulttio\", \"k\": 4 }\nassert my_solution.beautifulSubstrings(**test_input) == 10\n\ntest_input = { \"s\": \"woozzxd\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"pulorolqcvhafexui\", \"k\": 9 }\nassert my_solution.beautifulSubstrings(**test_input) == 3\n\ntest_input = { \"s\": \"hmuaewojioizoguvoaje\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 4\n\ntest_input = { \"s\": \"b\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"aiejouohnqnketinvat\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 6\n\ntest_input = { \"s\": \"mjiogpri\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 3\n\ntest_input = { \"s\": \"movbyaeouil\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 2\n\ntest_input = { \"s\": \"puureouausxmitvav\", \"k\": 6 }\nassert my_solution.beautifulSubstrings(**test_input) == 2\n\ntest_input = { \"s\": \"op\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 1\n\ntest_input = { \"s\": \"iuhoezpooxcohtlapolo\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 39\n\ntest_input = { \"s\": \"cioi\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"pueutaoyaxk\", \"k\": 6 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"iiuresacruaaan\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 3\n\ntest_input = { \"s\": \"agntyaazvpejidwaph\", \"k\": 8 }\nassert my_solution.beautifulSubstrings(**test_input) == 1\n\ntest_input = { \"s\": \"wiybolyniexiibou\", \"k\": 6 }\nassert my_solution.beautifulSubstrings(**test_input) == 2\n\ntest_input = { \"s\": \"coiyakadxi\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 8\n\ntest_input = { \"s\": \"oraajoeruiakixj\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 1\n\ntest_input = { \"s\": \"jeayap\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 7\n\ntest_input = { \"s\": \"iu\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"awozoy\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 3\n\ntest_input = { \"s\": \"fheabmlsyeeeuoeogyz\", \"k\": 9 }\nassert my_solution.beautifulSubstrings(**test_input) == 5\n\ntest_input = { \"s\": \"eaizneuxi\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 10\n\ntest_input = { \"s\": \"uurqufaucsuoqljh\", \"k\": 4 }\nassert my_solution.beautifulSubstrings(**test_input) == 14\n\ntest_input = { \"s\": \"jrtept\", \"k\": 4 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"olgioxooiejooosaed\", \"k\": 5 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"uizoy\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 1\n\ntest_input = { \"s\": \"lswabfiujjhexzos\", \"k\": 4 }\nassert my_solution.beautifulSubstrings(**test_input) == 5\n\ntest_input = { \"s\": \"iuu\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"qeaxut\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 7\n\ntest_input = { \"s\": \"aojiau\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"oaiaaaargkonlcsoaygf\", \"k\": 5 }\nassert my_solution.beautifulSubstrings(**test_input) == 2\n\ntest_input = { \"s\": \"zoowrawkm\", \"k\": 4 }\nassert my_solution.beautifulSubstrings(**test_input) == 3\n\ntest_input = { \"s\": \"uqiwuoevkfhkkua\", \"k\": 4 }\nassert my_solution.beautifulSubstrings(**test_input) == 6\n\ntest_input = { \"s\": \"kavuaaeodvaxicm\", \"k\": 6 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"qpxeceq\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 6\n\ntest_input = { \"s\": \"iaabaofuodcbek\", \"k\": 5 }\nassert my_solution.beautifulSubstrings(**test_input) == 3\n\ntest_input = { \"s\": \"eel\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 1\n\ntest_input = { \"s\": \"ikeuhe\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 5\n\ntest_input = { \"s\": \"lueikvo\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 2\n\ntest_input = { \"s\": \"oauau\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"qzoieeotieeakqraeao\", \"k\": 4 }\nassert my_solution.beautifulSubstrings(**test_input) == 4\n\ntest_input = { \"s\": \"ehaascocsdmgekni\", \"k\": 9 }\nassert my_solution.beautifulSubstrings(**test_input) == 3\n\ntest_input = { \"s\": \"euqeklniykiji\", \"k\": 5 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"vaeiiioidiioxhduu\", \"k\": 7 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"aa\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"chaua\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"edfrglfr\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"dqbe\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 1\n\ntest_input = { \"s\": \"ghooirorxge\", \"k\": 4 }\nassert my_solution.beautifulSubstrings(**test_input) == 6\n\ntest_input = { \"s\": \"fodartekaonq\", \"k\": 4 }\nassert my_solution.beautifulSubstrings(**test_input) == 9\n\ntest_input = { \"s\": \"feeanzkjpfehzeuni\", \"k\": 6 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"ignoouesduu\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 6\n\ntest_input = { \"s\": \"yif\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"gondfjaeeuhbuuasgip\", \"k\": 10 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"djooomsffoonelyeode\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 14\n\ntest_input = { \"s\": \"pgaimei\", \"k\": 4 }\nassert my_solution.beautifulSubstrings(**test_input) == 2\n\ntest_input = { \"s\": \"naipqentonee\", \"k\": 4 }\nassert my_solution.beautifulSubstrings(**test_input) == 8\n\ntest_input = { \"s\": \"bouov\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"lcuhoypz\", \"k\": 5 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"g\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"qc\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"mhznea\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 1\n\ntest_input = { \"s\": \"uxvjixdujgyfauo\", \"k\": 8 }\nassert my_solution.beautifulSubstrings(**test_input) == 1\n\ntest_input = { \"s\": \"iyjkuox\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 1\n\ntest_input = { \"s\": \"xbjfoayfpafatnuyord\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 3\n\ntest_input = { \"s\": \"nvoede\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 1\n\ntest_input = { \"s\": \"usnuaxpaktrweatruu\", \"k\": 5 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"euojmsora\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 10\n\ntest_input = { \"s\": \"iapgoi\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"uafuimcpxyeoixgbyeio\", \"k\": 5 }\nassert my_solution.beautifulSubstrings(**test_input) == 3\n\ntest_input = { \"s\": \"weuaatpu\", \"k\": 5 }\nassert my_solution.beautifulSubstrings(**test_input) == 0", "start_time": 1700965800} +{"task_id": "weekly-contest-373-make-lexicographically-smallest-array-by-swapping-elements", "url": "https://leetcode.com/problems/make-lexicographically-smallest-array-by-swapping-elements", "title": "make-lexicographically-smallest-array-by-swapping-elements", "meta": {"questionId": "3219", "questionFrontendId": "2948", "title": "Make Lexicographically Smallest Array by Swapping Elements", "titleSlug": "make-lexicographically-smallest-array-by-swapping-elements", "isPaidOnly": false, "difficulty": "Medium", "likes": 197, "dislikes": 10, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0 开始的 正整数 数组 nums 和一个 正整数 limit 。\n在一次操作中,你可以选择任意两个下标 i 和 j,如果 满足 |nums[i] - nums[j]| <= limit ,则交换 nums[i] 和 nums[j] 。\n返回执行任意次操作后能得到的 字典序最小的数组 。\n如果在数组 a 和数组 b 第一个不同的位置上,数组 a 中的对应元素比数组 b 中的对应元素的字典序更小,则认为数组 a 就比数组 b 字典序更小。例如,数组 [2,10,3] 比数组 [10,2,3] 字典序更小,下标 0 处是两个数组第一个不同的位置,且 2 < 10 。\n\n示例 1:\n\n输入:nums = [1,5,3,9,8], limit = 2\n输出:[1,3,5,8,9]\n解释:执行 2 次操作:\n- 交换 nums[1] 和 nums[2] 。数组变为 [1,3,5,9,8] 。\n- 交换 nums[3] 和 nums[4] 。数组变为 [1,3,5,8,9] 。\n即便执行更多次操作,也无法得到字典序更小的数组。\n注意,执行不同的操作也可能会得到相同的结果。\n\n示例 2:\n\n输入:nums = [1,7,6,18,2,1], limit = 3\n输出:[1,6,7,18,1,2]\n解释:执行 3 次操作:\n- 交换 nums[1] 和 nums[2] 。数组变为 [1,6,7,18,2,1] 。\n- 交换 nums[0] 和 nums[4] 。数组变为 [2,6,7,18,1,1] 。\n- 交换 nums[0] 和 nums[5] 。数组变为 [1,6,7,18,1,2] 。\n即便执行更多次操作,也无法得到字典序更小的数组。\n\n示例 3:\n\n输入:nums = [1,7,28,19,10], limit = 3\n输出:[1,7,28,19,10]\n解释:[1,7,28,19,10] 是字典序最小的数组,因为不管怎么选择下标都无法执行操作。\n\n\n提示:\n\n1 <= nums.length <= 105\n1 <= nums[i] <= 109\n1 <= limit <= 109\n\"\"\"\nclass Solution:\n def lexicographicallySmallestArray(self, nums: List[int], limit: int) -> List[int]:\n ", "prompt_sft": "给你一个下标从 0 开始的 正整数 数组 nums 和一个 正整数 limit 。\n在一次操作中,你可以选择任意两个下标 i 和 j,如果 满足 |nums[i] - nums[j]| <= limit ,则交换 nums[i] 和 nums[j] 。\n返回执行任意次操作后能得到的 字典序最小的数组 。\n如果在数组 a 和数组 b 第一个不同的位置上,数组 a 中的对应元素比数组 b 中的对应元素的字典序更小,则认为数组 a 就比数组 b 字典序更小。例如,数组 [2,10,3] 比数组 [10,2,3] 字典序更小,下标 0 处是两个数组第一个不同的位置,且 2 < 10 。\n\n示例 1:\n\n输入:nums = [1,5,3,9,8], limit = 2\n输出:[1,3,5,8,9]\n解释:执行 2 次操作:\n- 交换 nums[1] 和 nums[2] 。数组变为 [1,3,5,9,8] 。\n- 交换 nums[3] 和 nums[4] 。数组变为 [1,3,5,8,9] 。\n即便执行更多次操作,也无法得到字典序更小的数组。\n注意,执行不同的操作也可能会得到相同的结果。\n\n示例 2:\n\n输入:nums = [1,7,6,18,2,1], limit = 3\n输出:[1,6,7,18,1,2]\n解释:执行 3 次操作:\n- 交换 nums[1] 和 nums[2] 。数组变为 [1,6,7,18,2,1] 。\n- 交换 nums[0] 和 nums[4] 。数组变为 [2,6,7,18,1,1] 。\n- 交换 nums[0] 和 nums[5] 。数组变为 [1,6,7,18,1,2] 。\n即便执行更多次操作,也无法得到字典序更小的数组。\n\n示例 3:\n\n输入:nums = [1,7,28,19,10], limit = 3\n输出:[1,7,28,19,10]\n解释:[1,7,28,19,10] 是字典序最小的数组,因为不管怎么选择下标都无法执行操作。\n\n\n提示:\n\n1 <= nums.length <= 105\n1 <= nums[i] <= 109\n1 <= limit <= 109\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def lexicographicallySmallestArray(self, nums: List[int], limit: int) -> List[int]:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,5,3,9,8], \"limit\": 2 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [1,3,5,8,9]\n\ntest_input = { \"nums\": [1,7,6,18,2,1], \"limit\": 3 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [1,6,7,18,1,2]\n\ntest_input = { \"nums\": [1,7,28,19,10], \"limit\": 3 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [1,7,28,19,10]\n\ntest_input = { \"nums\": [1000000000], \"limit\": 1 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [1000000000]\n\ntest_input = { \"nums\": [1,60,34,84,62,56,39,76,49,38], \"limit\": 4 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [1,56,34,84,60,62,38,76,49,39]\n\ntest_input = { \"nums\": [1,81,10,79,36,2,87,12,20,77], \"limit\": 7 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [1,77,10,79,36,2,81,12,20,87]\n\ntest_input = { \"nums\": [2,71,5,87,11,15,70,70,14,38], \"limit\": 14 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [2,70,5,87,11,14,70,71,15,38]\n\ntest_input = { \"nums\": [4,3,23,84,34,88,44,44,18,15], \"limit\": 3 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [3,4,23,84,34,88,44,44,15,18]\n\ntest_input = { \"nums\": [4,34,29,73,51,11,8,53,98,47], \"limit\": 10 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [4,29,34,73,47,8,11,51,98,53]\n\ntest_input = { \"nums\": [4,52,38,59,71,27,31,83,88,10], \"limit\": 14 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [4,27,31,38,52,59,71,83,88,10]\n\ntest_input = { \"nums\": [4,68,8,10,70,62,27,5,42,61], \"limit\": 11 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [4,61,5,8,62,68,27,10,42,70]\n\ntest_input = { \"nums\": [5,9,35,60,73,91,61,57,87,76], \"limit\": 11 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [5,9,35,57,73,76,60,61,87,91]\n\ntest_input = { \"nums\": [5,15,68,47,49,67,9,6,35,14], \"limit\": 4 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [5,14,67,47,49,68,6,9,35,15]\n\ntest_input = { \"nums\": [5,16,43,15,66,21,58,74,55,66], \"limit\": 9 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [5,15,43,16,55,21,58,66,66,74]\n\ntest_input = { \"nums\": [5,30,92,4,31,2,17,39,15,7], \"limit\": 3 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [2,30,92,4,31,5,15,39,17,7]\n\ntest_input = { \"nums\": [5,38,68,80,64,79,50,5,8,95], \"limit\": 7 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [5,38,64,79,68,80,50,5,8,95]\n\ntest_input = { \"nums\": [5,100,44,45,16,30,14,65,83,64], \"limit\": 15 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [5,100,14,16,30,44,45,64,83,65]\n\ntest_input = { \"nums\": [6,57,100,67,4,63,47,59,21,66], \"limit\": 8 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [4,57,100,59,6,63,47,66,21,67]\n\ntest_input = { \"nums\": [6,70,90,1,33,81,60,80,68,44], \"limit\": 7 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [1,68,90,6,33,80,60,81,70,44]\n\ntest_input = { \"nums\": [6,74,74,74,30,70,91,74,76,41], \"limit\": 1 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [6,74,74,74,30,70,91,74,76,41]\n\ntest_input = { \"nums\": [6,77,68,15,3,98,56,22,81,72], \"limit\": 2 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [6,77,68,15,3,98,56,22,81,72]\n\ntest_input = { \"nums\": [7,17,79,29,29,83,21,12,5,1], \"limit\": 10 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [1,5,79,7,12,83,17,21,29,29]\n\ntest_input = { \"nums\": [7,66,85,9,29,1,25,69,57,95], \"limit\": 13 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [1,57,85,7,25,9,29,66,69,95]\n\ntest_input = { \"nums\": [7,73,1,97,13,55,74,29,76,19], \"limit\": 14 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [1,73,7,97,13,55,74,19,76,29]\n\ntest_input = { \"nums\": [8,4,47,23,73,79,63,62,35,51], \"limit\": 11 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [4,8,47,23,51,62,63,73,35,79]\n\ntest_input = { \"nums\": [8,17,20,100,59,98,64,78,64,53], \"limit\": 1 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [8,17,20,100,59,98,64,78,64,53]\n\ntest_input = { \"nums\": [8,70,99,5,49,27,79,2,57,49], \"limit\": 14 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [2,49,99,5,49,27,57,8,70,79]\n\ntest_input = { \"nums\": [9,67,94,37,5,90,43,13,27,21], \"limit\": 11 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [5,67,90,9,13,94,21,27,37,43]\n\ntest_input = { \"nums\": [10,22,17,76,6,64,51,60,65,37], \"limit\": 9 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [6,10,17,76,22,51,60,64,65,37]\n\ntest_input = { \"nums\": [10,34,63,88,76,30,70,80,52,13], \"limit\": 7 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [10,30,63,88,70,34,76,80,52,13]\n\ntest_input = { \"nums\": [10,69,4,28,15,30,23,53,41,93], \"limit\": 9 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [4,69,10,15,23,28,30,53,41,93]\n\ntest_input = { \"nums\": [12,86,98,73,64,77,30,76,46,69], \"limit\": 4 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [12,86,98,69,64,73,30,76,46,77]\n\ntest_input = { \"nums\": [13,43,32,15,45,69,58,89,64,76], \"limit\": 12 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [13,32,43,15,45,58,64,89,69,76]\n\ntest_input = { \"nums\": [13,70,11,74,73,21,4,45,95,38], \"limit\": 9 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [4,70,11,73,74,13,21,38,95,45]\n\ntest_input = { \"nums\": [14,15,53,11,38,18,27,69,55,2], \"limit\": 13 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [2,11,53,14,15,18,27,69,55,38]\n\ntest_input = { \"nums\": [14,28,61,49,10,25,80,83,42,100], \"limit\": 3 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [14,25,61,49,10,28,80,83,42,100]\n\ntest_input = { \"nums\": [14,71,7,77,99,90,20,81,100,65], \"limit\": 7 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [7,65,14,71,99,90,20,77,100,81]\n\ntest_input = { \"nums\": [14,95,75,100,33,98,88,2,74,26], \"limit\": 1 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [14,95,74,100,33,98,88,2,75,26]\n\ntest_input = { \"nums\": [15,29,16,37,10,70,58,5,33,76], \"limit\": 8 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [5,29,10,33,15,70,58,16,37,76]\n\ntest_input = { \"nums\": [15,33,1,74,47,6,60,95,78,72], \"limit\": 7 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [15,33,1,72,47,6,60,95,74,78]\n\ntest_input = { \"nums\": [16,20,79,92,17,7,70,41,54,18], \"limit\": 6 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [16,17,79,92,18,7,70,41,54,20]\n\ntest_input = { \"nums\": [16,43,19,36,99,15,70,89,45,71], \"limit\": 4 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [15,43,16,36,99,19,70,89,45,71]\n\ntest_input = { \"nums\": [17,99,88,73,13,1,3,5,55,4], \"limit\": 15 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [1,73,88,99,3,4,5,13,55,17]\n\ntest_input = { \"nums\": [18,97,57,1,23,36,77,80,47,91], \"limit\": 10 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [18,91,47,1,23,36,77,80,57,97]\n\ntest_input = { \"nums\": [19,25,49,96,35,69,81,81,51,50], \"limit\": 12 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [19,25,49,96,35,69,81,81,50,51]\n\ntest_input = { \"nums\": [19,37,12,11,70,99,88,36,64,9], \"limit\": 3 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [19,36,9,11,70,99,88,37,64,12]\n\ntest_input = { \"nums\": [19,64,26,5,70,10,17,66,51,36], \"limit\": 13 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [5,51,10,17,64,19,26,66,70,36]\n\ntest_input = { \"nums\": [21,14,21,34,4,88,39,62,30,20], \"limit\": 12 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [4,14,20,21,21,88,30,62,34,39]\n\ntest_input = { \"nums\": [22,94,100,54,97,14,100,48,41,35], \"limit\": 6 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [22,94,97,48,100,14,100,54,35,41]\n\ntest_input = { \"nums\": [23,50,8,48,62,26,92,5,96,9], \"limit\": 13 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [23,48,5,50,62,26,92,8,96,9]\n\ntest_input = { \"nums\": [25,47,34,69,36,91,14,44,37,2], \"limit\": 1 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [25,47,34,69,36,91,14,44,37,2]\n\ntest_input = { \"nums\": [25,58,36,16,42,57,17,96,10,2], \"limit\": 13 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [2,57,10,16,17,58,25,96,36,42]\n\ntest_input = { \"nums\": [26,21,9,15,94,47,52,86,89,7], \"limit\": 9 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [7,9,15,21,86,47,52,89,94,26]\n\ntest_input = { \"nums\": [27,26,24,2,95,90,41,14,20,35], \"limit\": 2 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [24,26,27,2,95,90,41,14,20,35]\n\ntest_input = { \"nums\": [27,56,68,41,39,80,60,36,24,5], \"limit\": 13 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [24,56,60,27,36,68,80,39,41,5]\n\ntest_input = { \"nums\": [27,71,52,71,68,2,49,37,34,97], \"limit\": 8 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [27,68,49,71,71,2,52,34,37,97]\n\ntest_input = { \"nums\": [29,82,25,91,17,9,38,25,29,68], \"limit\": 7 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [25,82,25,91,17,9,38,29,29,68]\n\ntest_input = { \"nums\": [30,48,76,86,21,1,55,49,90,9], \"limit\": 2 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [30,48,76,86,21,1,55,49,90,9]\n\ntest_input = { \"nums\": [31,10,64,15,60,32,88,79,79,33], \"limit\": 2 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [31,10,64,15,60,32,88,79,79,33]\n\ntest_input = { \"nums\": [32,70,43,51,40,73,56,39,75,45], \"limit\": 8 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [32,70,39,40,43,73,45,51,75,56]\n\ntest_input = { \"nums\": [32,95,51,87,29,43,21,55,45,84], \"limit\": 2 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [32,95,51,87,29,43,21,55,45,84]\n\ntest_input = { \"nums\": [33,25,25,65,82,71,56,82,13,46], \"limit\": 14 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [13,25,25,33,46,56,65,71,82,82]\n\ntest_input = { \"nums\": [33,37,77,41,83,75,96,97,4,60], \"limit\": 15 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [33,37,60,41,75,77,83,96,4,97]\n\ntest_input = { \"nums\": [35,81,18,79,47,53,20,2,98,22], \"limit\": 2 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [35,79,18,81,47,53,20,2,98,22]\n\ntest_input = { \"nums\": [36,39,100,4,44,33,65,11,15,35], \"limit\": 10 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [33,35,100,4,36,39,65,11,15,44]\n\ntest_input = { \"nums\": [38,56,60,98,21,15,70,37,24,61], \"limit\": 15 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [15,56,60,98,21,24,61,37,38,70]\n\ntest_input = { \"nums\": [39,36,18,39,99,51,68,92,5,38], \"limit\": 4 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [36,38,18,39,99,51,68,92,5,39]\n\ntest_input = { \"nums\": [39,89,81,37,67,37,98,89,49,47], \"limit\": 12 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [37,81,89,37,67,39,89,98,47,49]\n\ntest_input = { \"nums\": [40,67,99,53,95,47,59,99,64,44], \"limit\": 7 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [40,44,95,47,99,53,59,99,64,67]\n\ntest_input = { \"nums\": [40,97,72,48,55,91,83,82,91,63], \"limit\": 11 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [40,48,55,63,72,82,83,91,91,97]\n\ntest_input = { \"nums\": [41,10,22,43,17,38,67,7,68,70], \"limit\": 7 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [38,7,10,41,17,43,67,22,68,70]\n\ntest_input = { \"nums\": [41,25,83,44,39,37,67,33,58,5], \"limit\": 1 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [41,25,83,44,39,37,67,33,58,5]\n\ntest_input = { \"nums\": [41,87,34,74,77,62,18,28,5,8], \"limit\": 1 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [41,87,34,74,77,62,18,28,5,8]\n\ntest_input = { \"nums\": [45,1,66,44,45,74,75,96,31,47], \"limit\": 2 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [44,1,66,45,45,74,75,96,31,47]\n\ntest_input = { \"nums\": [45,64,77,71,73,6,24,55,82,25], \"limit\": 3 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [45,64,77,71,73,6,24,55,82,25]\n\ntest_input = { \"nums\": [46,72,1,33,1,51,78,96,44,20], \"limit\": 1 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [46,72,1,33,1,51,78,96,44,20]\n\ntest_input = { \"nums\": [47,32,72,79,16,69,85,70,87,73], \"limit\": 2 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [47,32,69,79,16,70,85,72,87,73]\n\ntest_input = { \"nums\": [47,94,72,49,50,62,17,22,85,86], \"limit\": 7 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [47,94,72,49,50,62,17,22,85,86]\n\ntest_input = { \"nums\": [48,39,45,58,26,57,38,63,82,80], \"limit\": 2 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [48,38,45,57,26,58,39,63,80,82]\n\ntest_input = { \"nums\": [48,51,51,39,54,56,57,6,1,40], \"limit\": 2 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [48,51,51,39,54,56,57,6,1,40]\n\ntest_input = { \"nums\": [49,4,95,24,20,12,70,60,82,62], \"limit\": 11 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [49,4,95,12,20,24,60,62,82,70]\n\ntest_input = { \"nums\": [49,7,92,79,43,88,31,89,36,97], \"limit\": 8 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [31,7,88,79,36,89,43,92,49,97]\n\ntest_input = { \"nums\": [49,16,32,11,7,57,69,41,52,23], \"limit\": 15 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [7,11,16,23,32,41,49,52,57,69]\n\ntest_input = { \"nums\": [49,26,82,77,52,76,90,23,64,42], \"limit\": 12 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [42,23,49,52,64,76,77,26,82,90]\n\ntest_input = { \"nums\": [49,62,63,32,57,22,74,87,42,19], \"limit\": 13 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [19,22,32,42,49,57,62,63,74,87]\n\ntest_input = { \"nums\": [49,93,5,15,56,2,65,74,82,42], \"limit\": 13 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [42,49,2,5,56,15,65,74,82,93]\n\ntest_input = { \"nums\": [49,93,100,79,76,14,90,32,4,5], \"limit\": 10 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [49,90,93,76,79,4,100,32,5,14]\n\ntest_input = { \"nums\": [49,96,75,44,74,78,82,40,43,68], \"limit\": 4 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [49,96,74,40,75,78,82,43,44,68]\n\ntest_input = { \"nums\": [51,61,49,11,69,78,40,98,68,36], \"limit\": 10 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [36,40,49,11,51,61,68,98,69,78]\n\ntest_input = { \"nums\": [51,99,52,80,83,69,18,49,71,13], \"limit\": 14 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [49,99,51,69,71,80,13,52,83,18]\n\ntest_input = { \"nums\": [52,28,93,16,33,37,37,21,47,64], \"limit\": 12 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [16,21,93,28,33,37,37,47,52,64]\n\ntest_input = { \"nums\": [53,7,99,22,3,50,62,70,56,40], \"limit\": 2 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [53,7,99,22,3,50,62,70,56,40]\n\ntest_input = { \"nums\": [53,17,39,72,5,78,40,3,84,20], \"limit\": 5 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [53,17,39,72,3,78,40,5,84,20]\n\ntest_input = { \"nums\": [53,71,55,38,26,89,20,98,55,21], \"limit\": 4 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [53,71,55,38,26,89,20,98,55,21]\n\ntest_input = { \"nums\": [53,71,74,7,99,64,95,99,90,22], \"limit\": 9 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [53,64,71,7,90,74,95,99,99,22]\n\ntest_input = { \"nums\": [55,19,82,86,12,64,44,76,88,31], \"limit\": 4 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [55,19,82,86,12,64,44,76,88,31]\n\ntest_input = { \"nums\": [56,13,55,1,18,36,45,25,20,52], \"limit\": 14 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [1,13,18,20,25,36,45,52,55,56]\n\ntest_input = { \"nums\": [56,28,50,100,56,99,80,71,6,5], \"limit\": 7 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [50,28,56,99,56,100,80,71,5,6]\n\ntest_input = { \"nums\": [56,35,19,2,83,20,96,42,33,68], \"limit\": 3 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [56,33,19,2,83,20,96,42,35,68]\n\ntest_input = { \"nums\": [56,69,94,21,65,46,64,91,75,25], \"limit\": 5 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [56,64,91,21,65,46,69,94,75,25]", "start_time": 1700965800} +{"task_id": "weekly-contest-373-count-beautiful-substrings-ii", "url": "https://leetcode.com/problems/count-beautiful-substrings-ii", "title": "count-beautiful-substrings-ii", "meta": {"questionId": "3208", "questionFrontendId": "2949", "title": "Count Beautiful Substrings II", "titleSlug": "count-beautiful-substrings-ii", "isPaidOnly": false, "difficulty": "Hard", "likes": 137, "dislikes": 3, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个字符串 s 和一个正整数 k 。\n用 vowels 和 consonants 分别表示字符串中元音字母和辅音字母的数量。\n如果某个字符串满足以下条件,则称其为 美丽字符串 :\n\nvowels == consonants,即元音字母和辅音字母的数量相等。\n(vowels * consonants) % k == 0,即元音字母和辅音字母的数量的乘积能被 k 整除。\n\n返回字符串 s 中 非空美丽子字符串 的数量。\n子字符串是字符串中的一个连续字符序列。\n英语中的 元音字母 为 'a'、'e'、'i'、'o' 和 'u' 。\n英语中的 辅音字母 为除了元音字母之外的所有字母。\n\n示例 1:\n\n输入:s = \"baeyh\", k = 2\n输出:2\n解释:字符串 s 中有 2 个美丽子字符串。\n- 子字符串 \"baeyh\",vowels = 2([\"a\",\"e\"]),consonants = 2([\"y\",\"h\"])。\n可以看出字符串 \"aeyh\" 是美丽字符串,因为 vowels == consonants 且 vowels * consonants % k == 0 。\n- 子字符串 \"baeyh\",vowels = 2([\"a\",\"e\"]),consonants = 2([\"b\",\"y\"])。\n可以看出字符串 \"baey\" 是美丽字符串,因为 vowels == consonants 且 vowels * consonants % k == 0 。\n可以证明字符串 s 中只有 2 个美丽子字符串。\n\n示例 2:\n\n输入:s = \"abba\", k = 1\n输出:3\n解释:字符串 s 中有 3 个美丽子字符串。\n- 子字符串 \"abba\",vowels = 1([\"a\"]),consonants = 1([\"b\"])。\n- 子字符串 \"abba\",vowels = 1([\"a\"]),consonants = 1([\"b\"])。\n- 子字符串 \"abba\",vowels = 2([\"a\",\"a\"]),consonants = 2([\"b\",\"b\"])。\n可以证明字符串 s 中只有 3 个美丽子字符串。\n\n示例 3:\n\n输入:s = \"bcdf\", k = 1\n输出:0\n解释:字符串 s 中没有美丽子字符串。\n\n\n提示:\n\n1 <= s.length <= 5 * 104\n1 <= k <= 1000\ns 仅由小写英文字母组成。\n\"\"\"\nclass Solution:\n def beautifulSubstrings(self, s: str, k: int) -> int:\n ", "prompt_sft": "给你一个字符串 s 和一个正整数 k 。\n用 vowels 和 consonants 分别表示字符串中元音字母和辅音字母的数量。\n如果某个字符串满足以下条件,则称其为 美丽字符串 :\n\nvowels == consonants,即元音字母和辅音字母的数量相等。\n(vowels * consonants) % k == 0,即元音字母和辅音字母的数量的乘积能被 k 整除。\n\n返回字符串 s 中 非空美丽子字符串 的数量。\n子字符串是字符串中的一个连续字符序列。\n英语中的 元音字母 为 'a'、'e'、'i'、'o' 和 'u' 。\n英语中的 辅音字母 为除了元音字母之外的所有字母。\n\n示例 1:\n\n输入:s = \"baeyh\", k = 2\n输出:2\n解释:字符串 s 中有 2 个美丽子字符串。\n- 子字符串 \"baeyh\",vowels = 2([\"a\",\"e\"]),consonants = 2([\"y\",\"h\"])。\n可以看出字符串 \"aeyh\" 是美丽字符串,因为 vowels == consonants 且 vowels * consonants % k == 0 。\n- 子字符串 \"baeyh\",vowels = 2([\"a\",\"e\"]),consonants = 2([\"b\",\"y\"])。\n可以看出字符串 \"baey\" 是美丽字符串,因为 vowels == consonants 且 vowels * consonants % k == 0 。\n可以证明字符串 s 中只有 2 个美丽子字符串。\n\n示例 2:\n\n输入:s = \"abba\", k = 1\n输出:3\n解释:字符串 s 中有 3 个美丽子字符串。\n- 子字符串 \"abba\",vowels = 1([\"a\"]),consonants = 1([\"b\"])。\n- 子字符串 \"abba\",vowels = 1([\"a\"]),consonants = 1([\"b\"])。\n- 子字符串 \"abba\",vowels = 2([\"a\",\"a\"]),consonants = 2([\"b\",\"b\"])。\n可以证明字符串 s 中只有 3 个美丽子字符串。\n\n示例 3:\n\n输入:s = \"bcdf\", k = 1\n输出:0\n解释:字符串 s 中没有美丽子字符串。\n\n\n提示:\n\n1 <= s.length <= 5 * 104\n1 <= k <= 1000\ns 仅由小写英文字母组成。\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def beautifulSubstrings(self, s: str, k: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"s\": \"baeyh\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 2\n\ntest_input = { \"s\": \"abba\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 3\n\ntest_input = { \"s\": \"bcdf\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"ihroyeeb\", \"k\": 5 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"uzuxpzou\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 1\n\ntest_input = { \"s\": \"ouuoeqd\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 1\n\ntest_input = { \"s\": \"eeebjoxxujuaeoqibd\", \"k\": 8 }\nassert my_solution.beautifulSubstrings(**test_input) == 4\n\ntest_input = { \"s\": \"ilougekqlovegioemdvu\", \"k\": 4 }\nassert my_solution.beautifulSubstrings(**test_input) == 21\n\ntest_input = { \"s\": \"tqaewreikaztwpfwnef\", \"k\": 8 }\nassert my_solution.beautifulSubstrings(**test_input) == 3\n\ntest_input = { \"s\": \"oykiuhsafgfjumnzb\", \"k\": 7 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"ifvsa\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"svzauyuevujektj\", \"k\": 5 }\nassert my_solution.beautifulSubstrings(**test_input) == 3\n\ntest_input = { \"s\": \"urahjig\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 2\n\ntest_input = { \"s\": \"ime\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"oacghieut\", \"k\": 5 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"aoluu\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"ioaoiciiuoziout\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 5\n\ntest_input = { \"s\": \"ouafupsuhid\", \"k\": 6 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"ox\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"tlaiwoauazutusiaaui\", \"k\": 10 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"caepeym\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 2\n\ntest_input = { \"s\": \"apyxvceue\", \"k\": 4 }\nassert my_solution.beautifulSubstrings(**test_input) == 1\n\ntest_input = { \"s\": \"imkqbb\", \"k\": 4 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"caaz\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 1\n\ntest_input = { \"s\": \"pyicoy\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 6\n\ntest_input = { \"s\": \"uopmyrsntjhiroikup\", \"k\": 8 }\nassert my_solution.beautifulSubstrings(**test_input) == 2\n\ntest_input = { \"s\": \"aujfxqxcj\", \"k\": 5 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"eeizejuoxeumz\", \"k\": 4 }\nassert my_solution.beautifulSubstrings(**test_input) == 6\n\ntest_input = { \"s\": \"uuouuaifnboeiulttio\", \"k\": 4 }\nassert my_solution.beautifulSubstrings(**test_input) == 10\n\ntest_input = { \"s\": \"woozzxd\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"pulorolqcvhafexui\", \"k\": 9 }\nassert my_solution.beautifulSubstrings(**test_input) == 3\n\ntest_input = { \"s\": \"hmuaewojioizoguvoaje\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 4\n\ntest_input = { \"s\": \"b\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"aiejouohnqnketinvat\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 6\n\ntest_input = { \"s\": \"mjiogpri\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 3\n\ntest_input = { \"s\": \"movbyaeouil\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 2\n\ntest_input = { \"s\": \"puureouausxmitvav\", \"k\": 6 }\nassert my_solution.beautifulSubstrings(**test_input) == 2\n\ntest_input = { \"s\": \"op\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 1\n\ntest_input = { \"s\": \"iuhoezpooxcohtlapolo\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 39\n\ntest_input = { \"s\": \"cioi\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"pueutaoyaxk\", \"k\": 6 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"iiuresacruaaan\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 3\n\ntest_input = { \"s\": \"agntyaazvpejidwaph\", \"k\": 8 }\nassert my_solution.beautifulSubstrings(**test_input) == 1\n\ntest_input = { \"s\": \"wiybolyniexiibou\", \"k\": 6 }\nassert my_solution.beautifulSubstrings(**test_input) == 2\n\ntest_input = { \"s\": \"coiyakadxi\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 8\n\ntest_input = { \"s\": \"oraajoeruiakixj\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 1\n\ntest_input = { \"s\": \"jeayap\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 7\n\ntest_input = { \"s\": \"iu\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"awozoy\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 3\n\ntest_input = { \"s\": \"fheabmlsyeeeuoeogyz\", \"k\": 9 }\nassert my_solution.beautifulSubstrings(**test_input) == 5\n\ntest_input = { \"s\": \"eaizneuxi\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 10\n\ntest_input = { \"s\": \"uurqufaucsuoqljh\", \"k\": 4 }\nassert my_solution.beautifulSubstrings(**test_input) == 14\n\ntest_input = { \"s\": \"jrtept\", \"k\": 4 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"olgioxooiejooosaed\", \"k\": 5 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"uizoy\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 1\n\ntest_input = { \"s\": \"lswabfiujjhexzos\", \"k\": 4 }\nassert my_solution.beautifulSubstrings(**test_input) == 5\n\ntest_input = { \"s\": \"iuu\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"qeaxut\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 7\n\ntest_input = { \"s\": \"aojiau\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"oaiaaaargkonlcsoaygf\", \"k\": 5 }\nassert my_solution.beautifulSubstrings(**test_input) == 2\n\ntest_input = { \"s\": \"zoowrawkm\", \"k\": 4 }\nassert my_solution.beautifulSubstrings(**test_input) == 3\n\ntest_input = { \"s\": \"uqiwuoevkfhkkua\", \"k\": 4 }\nassert my_solution.beautifulSubstrings(**test_input) == 6\n\ntest_input = { \"s\": \"kavuaaeodvaxicm\", \"k\": 6 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"qpxeceq\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 6\n\ntest_input = { \"s\": \"iaabaofuodcbek\", \"k\": 5 }\nassert my_solution.beautifulSubstrings(**test_input) == 3\n\ntest_input = { \"s\": \"eel\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 1\n\ntest_input = { \"s\": \"ikeuhe\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 5\n\ntest_input = { \"s\": \"lueikvo\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 2\n\ntest_input = { \"s\": \"oauau\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"qzoieeotieeakqraeao\", \"k\": 4 }\nassert my_solution.beautifulSubstrings(**test_input) == 4\n\ntest_input = { \"s\": \"ehaascocsdmgekni\", \"k\": 9 }\nassert my_solution.beautifulSubstrings(**test_input) == 3\n\ntest_input = { \"s\": \"euqeklniykiji\", \"k\": 5 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"vaeiiioidiioxhduu\", \"k\": 7 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"aa\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"chaua\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"edfrglfr\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"dqbe\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 1\n\ntest_input = { \"s\": \"ghooirorxge\", \"k\": 4 }\nassert my_solution.beautifulSubstrings(**test_input) == 6\n\ntest_input = { \"s\": \"fodartekaonq\", \"k\": 4 }\nassert my_solution.beautifulSubstrings(**test_input) == 9\n\ntest_input = { \"s\": \"feeanzkjpfehzeuni\", \"k\": 6 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"ignoouesduu\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 6\n\ntest_input = { \"s\": \"yif\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"gondfjaeeuhbuuasgip\", \"k\": 10 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"djooomsffoonelyeode\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 14\n\ntest_input = { \"s\": \"pgaimei\", \"k\": 4 }\nassert my_solution.beautifulSubstrings(**test_input) == 2\n\ntest_input = { \"s\": \"naipqentonee\", \"k\": 4 }\nassert my_solution.beautifulSubstrings(**test_input) == 8\n\ntest_input = { \"s\": \"bouov\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"lcuhoypz\", \"k\": 5 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"g\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"qc\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"mhznea\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 1\n\ntest_input = { \"s\": \"uxvjixdujgyfauo\", \"k\": 8 }\nassert my_solution.beautifulSubstrings(**test_input) == 1\n\ntest_input = { \"s\": \"iyjkuox\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 1\n\ntest_input = { \"s\": \"xbjfoayfpafatnuyord\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 3\n\ntest_input = { \"s\": \"nvoede\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 1\n\ntest_input = { \"s\": \"usnuaxpaktrweatruu\", \"k\": 5 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"euojmsora\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 10\n\ntest_input = { \"s\": \"iapgoi\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"uafuimcpxyeoixgbyeio\", \"k\": 5 }\nassert my_solution.beautifulSubstrings(**test_input) == 3\n\ntest_input = { \"s\": \"weuaatpu\", \"k\": 5 }\nassert my_solution.beautifulSubstrings(**test_input) == 0", "start_time": 1700965800} +{"task_id": "biweekly-contest-118-find-words-containing-character", "url": "https://leetcode.com/problems/find-words-containing-character", "title": "find-words-containing-character", "meta": {"questionId": "3194", "questionFrontendId": "2942", "title": "Find Words Containing Character", "titleSlug": "find-words-containing-character", "isPaidOnly": false, "difficulty": "Easy", "likes": 134, "dislikes": 4, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0开始的字符串数组words和一个字符x。\n请你返回一个 下标数组,表示下标在数组中对应的单词包含字符 x。\n注意,返回的数组可以是任意顺序。\n\n示例 1:\n\n输入:words = [\"leet\",\"code\"], x = \"e\"\n输出:[0,1]\n解释:\"e\" 在两个单词中都出现了:\"leet\" 和 \"code\" 。所以我们返回下标 0 和 1 。\n\n示例 2:\n\n输入:words = [\"abc\",\"bcd\",\"aaaa\",\"cbc\"], x = \"a\"\n输出:[0,2]\n解释:\"a\" 在 \"abc\" 和 \"aaaa\" 中出现了,所以我们返回下标 0 和 2 。\n\n示例 3:\n\n输入:words = [\"abc\",\"bcd\",\"aaaa\",\"cbc\"], x = \"z\"\n输出:[]\n解释:\"z\" 没有在任何单词中出现。所以我们返回空数组。\n\n\n提示:\n\n1 <= words.length <= 50\n1 <= words[i].length <= 50\nx是一个小写英文字母。\nwords[i]只包含小写英文字母。\n\"\"\"\nclass Solution:\n def findWordsContaining(self, words: List[str], x: str) -> List[int]:\n ", "prompt_sft": "给你一个下标从 0开始的字符串数组words和一个字符x。\n请你返回一个 下标数组,表示下标在数组中对应的单词包含字符 x。\n注意,返回的数组可以是任意顺序。\n\n示例 1:\n\n输入:words = [\"leet\",\"code\"], x = \"e\"\n输出:[0,1]\n解释:\"e\" 在两个单词中都出现了:\"leet\" 和 \"code\" 。所以我们返回下标 0 和 1 。\n\n示例 2:\n\n输入:words = [\"abc\",\"bcd\",\"aaaa\",\"cbc\"], x = \"a\"\n输出:[0,2]\n解释:\"a\" 在 \"abc\" 和 \"aaaa\" 中出现了,所以我们返回下标 0 和 2 。\n\n示例 3:\n\n输入:words = [\"abc\",\"bcd\",\"aaaa\",\"cbc\"], x = \"z\"\n输出:[]\n解释:\"z\" 没有在任何单词中出现。所以我们返回空数组。\n\n\n提示:\n\n1 <= words.length <= 50\n1 <= words[i].length <= 50\nx是一个小写英文字母。\nwords[i]只包含小写英文字母。\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def findWordsContaining(self, words: List[str], x: str) -> List[int]:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"words\": [\"leet\",\"code\"], \"x\": \"e\" }\nassert my_solution.findWordsContaining(**test_input) == [0,1]\n\ntest_input = { \"words\": [\"abc\",\"bcd\",\"aaaa\",\"cbc\"], \"x\": \"a\" }\nassert my_solution.findWordsContaining(**test_input) == [0,2]\n\ntest_input = { \"words\": [\"abc\",\"bcd\",\"aaaa\",\"cbc\"], \"x\": \"z\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"sgtkshnss\",\"m\",\"ryvbkyvuz\",\"ezittyjwgb\",\"wudlwg\"], \"x\": \"x\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"lkwnhpbj\",\"tlohm\",\"juazsb\",\"f\",\"rq\"], \"x\": \"v\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"aaa\",\"imvtfjmxr\",\"wbzfoovjnf\",\"hqwrwmi\"], \"x\": \"c\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"utyeachht\",\"bgpkcs\",\"skeecqvvvw\",\"nccrd\"], \"x\": \"i\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"alcpxexztg\",\"r\"], \"x\": \"h\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"ekcpg\",\"pdknua\",\"fot\",\"janppw\",\"ofomkfvx\"], \"x\": \"g\" }\nassert my_solution.findWordsContaining(**test_input) == [0]\n\ntest_input = { \"words\": [\"dq\",\"rlvopu\"], \"x\": \"d\" }\nassert my_solution.findWordsContaining(**test_input) == [0]\n\ntest_input = { \"words\": [\"wzppkd\",\"jxvk\",\"zaztizmwuv\",\"hvcdtobr\"], \"x\": \"b\" }\nassert my_solution.findWordsContaining(**test_input) == [3]\n\ntest_input = { \"words\": [\"y\",\"hs\",\"qznrkpi\"], \"x\": \"v\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"pze\",\"yojczsb\",\"mjvyr\",\"i\",\"xsygks\"], \"x\": \"q\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"qsgtjagcu\",\"m\"], \"x\": \"e\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"kidtwmw\",\"ogh\",\"trdedlh\",\"wwbtlindg\",\"naoylytpof\",\"ujcbzwzkm\",\"doamcoxdv\"], \"x\": \"o\" }\nassert my_solution.findWordsContaining(**test_input) == [1,4,6]\n\ntest_input = { \"words\": [\"tsmeupctki\"], \"x\": \"t\" }\nassert my_solution.findWordsContaining(**test_input) == [0]\n\ntest_input = { \"words\": [\"dqxlbljmpf\",\"uvdzfoiqg\",\"jsnbnx\",\"fbedae\",\"nodewb\",\"o\",\"ivepktj\"], \"x\": \"g\" }\nassert my_solution.findWordsContaining(**test_input) == [1]\n\ntest_input = { \"words\": [\"fjlmmecm\",\"sautsoorhl\",\"n\",\"hsyco\",\"amlukrpjpv\",\"rmhdnj\",\"g\"], \"x\": \"e\" }\nassert my_solution.findWordsContaining(**test_input) == [0]\n\ntest_input = { \"words\": [\"khjchmeciv\",\"vgx\",\"xghr\",\"bbufgegu\",\"qyfxu\"], \"x\": \"r\" }\nassert my_solution.findWordsContaining(**test_input) == [2]\n\ntest_input = { \"words\": [\"jhtcugtcpl\",\"bvhlgmmla\",\"ntfkwzite\",\"imbtzafaj\",\"sdl\",\"t\"], \"x\": \"m\" }\nassert my_solution.findWordsContaining(**test_input) == [1,3]\n\ntest_input = { \"words\": [\"kxoziqoafc\",\"vifcxifq\"], \"x\": \"q\" }\nassert my_solution.findWordsContaining(**test_input) == [0,1]\n\ntest_input = { \"words\": [\"ckfkjjsonl\",\"scaaug\",\"rmvqzyiwc\",\"a\",\"smymw\"], \"x\": \"p\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"t\",\"exo\",\"npr\",\"skd\",\"bxpmbu\"], \"x\": \"e\" }\nassert my_solution.findWordsContaining(**test_input) == [1]\n\ntest_input = { \"words\": [\"eulsl\",\"fwooyct\",\"ypytexil\"], \"x\": \"c\" }\nassert my_solution.findWordsContaining(**test_input) == [1]\n\ntest_input = { \"words\": [\"nhd\",\"zheyegi\",\"ogz\",\"fpybmcc\",\"ntbbwtde\"], \"x\": \"g\" }\nassert my_solution.findWordsContaining(**test_input) == [1,2]\n\ntest_input = { \"words\": [\"gwzvusl\",\"upcpvbfyxy\",\"hg\",\"yu\",\"wsfqgzhh\",\"zgphqacsyo\"], \"x\": \"o\" }\nassert my_solution.findWordsContaining(**test_input) == [5]\n\ntest_input = { \"words\": [\"uiovpph\",\"xxj\",\"uwzxzvkobk\"], \"x\": \"r\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"abtrpwo\",\"sgaegnavk\",\"pfmv\"], \"x\": \"z\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"m\",\"fxtphsdmgy\",\"otq\",\"vwuhhnebr\",\"yen\"], \"x\": \"y\" }\nassert my_solution.findWordsContaining(**test_input) == [1,4]\n\ntest_input = { \"words\": [\"irlzx\",\"lbrknhl\",\"roupfj\",\"fskaieszo\",\"nz\",\"ijfyejq\"], \"x\": \"e\" }\nassert my_solution.findWordsContaining(**test_input) == [3,5]\n\ntest_input = { \"words\": [\"raavc\",\"tx\"], \"x\": \"l\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"bkpuvcrexw\",\"hxtbcdprhr\",\"ovt\",\"xgurm\",\"pjcz\",\"sbhwpjmyz\"], \"x\": \"g\" }\nassert my_solution.findWordsContaining(**test_input) == [3]\n\ntest_input = { \"words\": [\"f\",\"xlmy\",\"akbiqa\",\"fobo\"], \"x\": \"s\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"mhan\"], \"x\": \"a\" }\nassert my_solution.findWordsContaining(**test_input) == [0]\n\ntest_input = { \"words\": [\"uisx\"], \"x\": \"o\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"znqdolksyn\",\"keewspe\",\"ffod\",\"lah\",\"gadhym\",\"awnyymd\",\"fvkl\"], \"x\": \"v\" }\nassert my_solution.findWordsContaining(**test_input) == [6]\n\ntest_input = { \"words\": [\"ftujx\",\"dnbwrurk\",\"t\",\"x\",\"zjzhdl\",\"jc\"], \"x\": \"t\" }\nassert my_solution.findWordsContaining(**test_input) == [0,2]\n\ntest_input = { \"words\": [\"zrwf\",\"thp\",\"qecwlnq\",\"w\",\"teetdaxx\"], \"x\": \"t\" }\nassert my_solution.findWordsContaining(**test_input) == [1,4]\n\ntest_input = { \"words\": [\"xyzgb\",\"qflfrfqgaf\"], \"x\": \"l\" }\nassert my_solution.findWordsContaining(**test_input) == [1]\n\ntest_input = { \"words\": [\"shnjr\",\"qfvop\"], \"x\": \"y\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"fmwclqh\",\"xbphhgreze\",\"yi\",\"gmtzrfdab\",\"uicqa\",\"n\"], \"x\": \"i\" }\nassert my_solution.findWordsContaining(**test_input) == [2,4]\n\ntest_input = { \"words\": [\"jgkv\",\"njhwihtv\",\"v\"], \"x\": \"z\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"tqkwoofh\",\"bcgngl\",\"frjpqgrr\",\"drvb\"], \"x\": \"x\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"npkvocbw\",\"tn\",\"dp\",\"c\",\"g\",\"fsxvzcnty\",\"ywnf\"], \"x\": \"k\" }\nassert my_solution.findWordsContaining(**test_input) == [0]\n\ntest_input = { \"words\": [\"leompil\",\"vta\",\"fzrsps\",\"yp\",\"bykmgwgk\"], \"x\": \"o\" }\nassert my_solution.findWordsContaining(**test_input) == [0]\n\ntest_input = { \"words\": [\"umq\",\"c\",\"ctuh\",\"eadzeuui\",\"tabum\",\"isuct\"], \"x\": \"p\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"rnmpdkmrnb\",\"icxxsvss\",\"h\",\"gd\"], \"x\": \"s\" }\nassert my_solution.findWordsContaining(**test_input) == [1]\n\ntest_input = { \"words\": [\"ft\",\"hsjf\",\"e\",\"xi\"], \"x\": \"w\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"ozf\",\"xkehlkgp\",\"vliewlbv\",\"okgaahah\"], \"x\": \"b\" }\nassert my_solution.findWordsContaining(**test_input) == [2]\n\ntest_input = { \"words\": [\"gbktzr\",\"kbamubluz\",\"dwoi\",\"crhldx\",\"idjronpded\",\"rqaz\"], \"x\": \"c\" }\nassert my_solution.findWordsContaining(**test_input) == [3]\n\ntest_input = { \"words\": [\"gvbzqcb\",\"rwtbra\",\"iuijl\",\"qbmpbi\"], \"x\": \"c\" }\nassert my_solution.findWordsContaining(**test_input) == [0]\n\ntest_input = { \"words\": [\"lsh\",\"szhxhcdc\",\"quem\",\"zupiydjeqp\",\"czxyvysrrb\",\"aqnlqtnfiv\"], \"x\": \"p\" }\nassert my_solution.findWordsContaining(**test_input) == [3]\n\ntest_input = { \"words\": [\"leuah\",\"liaoczeuch\",\"ol\",\"ify\",\"layh\",\"ifzudwuybw\",\"x\"], \"x\": \"p\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"ksdpwwho\",\"ktunsikyu\"], \"x\": \"a\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"vpypaumzlp\",\"kqrb\",\"pgw\"], \"x\": \"l\" }\nassert my_solution.findWordsContaining(**test_input) == [0]\n\ntest_input = { \"words\": [\"jkrpnx\",\"c\",\"kqi\",\"xrsaviyusg\",\"waoxq\",\"fld\",\"otxfgcp\"], \"x\": \"l\" }\nassert my_solution.findWordsContaining(**test_input) == [5]\n\ntest_input = { \"words\": [\"tetw\",\"zl\",\"wd\",\"hnkxoxlnz\",\"dexgufawjd\",\"oolpr\",\"yyfwizbsl\"], \"x\": \"p\" }\nassert my_solution.findWordsContaining(**test_input) == [5]\n\ntest_input = { \"words\": [\"hihprd\",\"kitgiflc\",\"nr\",\"idduuahfkm\"], \"x\": \"x\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"flfxeca\",\"g\"], \"x\": \"e\" }\nassert my_solution.findWordsContaining(**test_input) == [0]\n\ntest_input = { \"words\": [\"st\",\"betf\",\"ipacxza\",\"jpnw\"], \"x\": \"r\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"cvuxnzaib\",\"c\",\"tiytr\",\"yiav\",\"hp\",\"yg\"], \"x\": \"d\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"yz\",\"k\",\"midujexvn\",\"kwcgbht\"], \"x\": \"y\" }\nassert my_solution.findWordsContaining(**test_input) == [0]\n\ntest_input = { \"words\": [\"qcxobdaxv\"], \"x\": \"q\" }\nassert my_solution.findWordsContaining(**test_input) == [0]\n\ntest_input = { \"words\": [\"b\",\"shrexcf\",\"ve\",\"eqpbnuy\",\"qdhahodo\",\"aerdf\",\"bdjlaakagk\"], \"x\": \"p\" }\nassert my_solution.findWordsContaining(**test_input) == [3]\n\ntest_input = { \"words\": [\"ympv\"], \"x\": \"q\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"thfy\",\"lnfzoyafiy\",\"qmc\",\"boijcl\",\"pvbzmsa\",\"yjarwylcyc\"], \"x\": \"e\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"hqptwi\"], \"x\": \"o\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"bv\",\"xgrhtjnxh\",\"fdtljkxa\",\"po\",\"hejof\"], \"x\": \"k\" }\nassert my_solution.findWordsContaining(**test_input) == [2]\n\ntest_input = { \"words\": [\"mfdrclyx\",\"pith\"], \"x\": \"e\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"bxeblhrl\",\"o\",\"uvv\"], \"x\": \"b\" }\nassert my_solution.findWordsContaining(**test_input) == [0]\n\ntest_input = { \"words\": [\"giygz\"], \"x\": \"u\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"ffqw\",\"nykncbxrqi\",\"pgzy\",\"of\",\"oye\",\"f\"], \"x\": \"g\" }\nassert my_solution.findWordsContaining(**test_input) == [2]\n\ntest_input = { \"words\": [\"jjnh\",\"nrbh\",\"z\"], \"x\": \"l\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"gdzkdtvrm\",\"ps\",\"kp\",\"sbdlkac\",\"s\",\"bt\"], \"x\": \"n\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"hpsk\",\"stjltzz\",\"gvbjwzktgg\",\"hmeovbxvv\",\"gqaxqoshbh\",\"mqnwyabqq\",\"sq\"], \"x\": \"f\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"gwmg\",\"qdjeaxgc\",\"rlajltxpd\",\"d\"], \"x\": \"g\" }\nassert my_solution.findWordsContaining(**test_input) == [0,1]\n\ntest_input = { \"words\": [\"dupx\",\"r\",\"j\",\"wq\",\"macfcfoz\"], \"x\": \"r\" }\nassert my_solution.findWordsContaining(**test_input) == [1]\n\ntest_input = { \"words\": [\"rmypzoyto\",\"wvhtrbuz\",\"dgt\",\"tmhqswmkx\",\"trpjwzitp\",\"tbetdxic\"], \"x\": \"t\" }\nassert my_solution.findWordsContaining(**test_input) == [0,1,2,3,4,5]\n\ntest_input = { \"words\": [\"vpkjymgdb\",\"s\",\"gv\",\"geie\"], \"x\": \"g\" }\nassert my_solution.findWordsContaining(**test_input) == [0,2,3]\n\ntest_input = { \"words\": [\"epnmbry\",\"hhfhprvqba\"], \"x\": \"l\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"zst\",\"mjzbdxsks\",\"dza\",\"neqj\",\"oqeilr\"], \"x\": \"d\" }\nassert my_solution.findWordsContaining(**test_input) == [1,2]\n\ntest_input = { \"words\": [\"ffruqk\",\"sse\",\"cyj\",\"tntq\",\"mibbhhpce\"], \"x\": \"c\" }\nassert my_solution.findWordsContaining(**test_input) == [2,4]\n\ntest_input = { \"words\": [\"vumzrbe\",\"qudq\",\"qfrt\"], \"x\": \"u\" }\nassert my_solution.findWordsContaining(**test_input) == [0,1]\n\ntest_input = { \"words\": [\"wcrrprvu\",\"fizkw\",\"vzcjxhjy\",\"e\"], \"x\": \"r\" }\nassert my_solution.findWordsContaining(**test_input) == [0]\n\ntest_input = { \"words\": [\"gjk\",\"vri\"], \"x\": \"n\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"fds\",\"vbmg\",\"p\",\"iesyvc\",\"wgmyxhoo\",\"yfllvzr\"], \"x\": \"f\" }\nassert my_solution.findWordsContaining(**test_input) == [0,5]\n\ntest_input = { \"words\": [\"mifbjo\",\"kpjlwfbas\",\"skhueysodn\",\"zeewicisy\"], \"x\": \"g\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"pvkmoccv\",\"j\"], \"x\": \"y\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"s\",\"uhcfwsssbe\",\"iwofeukmx\",\"yfta\",\"ovrdcb\",\"psnje\"], \"x\": \"s\" }\nassert my_solution.findWordsContaining(**test_input) == [0,1,5]\n\ntest_input = { \"words\": [\"klpzrjw\",\"qmrhbpa\"], \"x\": \"v\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"fzegksjmw\",\"masiwhjue\",\"gngsht\",\"xwvmp\",\"aahn\",\"dwxr\"], \"x\": \"c\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"mveahpesx\",\"tsqds\",\"g\",\"mux\",\"bivffitjx\",\"zfsqdje\"], \"x\": \"f\" }\nassert my_solution.findWordsContaining(**test_input) == [4,5]\n\ntest_input = { \"words\": [\"c\"], \"x\": \"a\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"jzmhnhqkq\"], \"x\": \"a\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"cfdgbc\",\"ltpvko\",\"batjenrlq\",\"edwefhw\"], \"x\": \"t\" }\nassert my_solution.findWordsContaining(**test_input) == [1,2]\n\ntest_input = { \"words\": [\"smlcojfydr\",\"slb\"], \"x\": \"r\" }\nassert my_solution.findWordsContaining(**test_input) == [0]\n\ntest_input = { \"words\": [\"lnjimir\"], \"x\": \"x\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"do\"], \"x\": \"e\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"xyyvbxsb\",\"dc\",\"mmqpb\",\"mmbwv\",\"wdreyof\",\"kpk\",\"reeb\"], \"x\": \"l\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"ytvyknnmzv\",\"jsoe\",\"wctzk\"], \"x\": \"i\" }\nassert my_solution.findWordsContaining(**test_input) == []", "start_time": 1700922600} +{"task_id": "biweekly-contest-118-maximize-area-of-square-hole-in-grid", "url": "https://leetcode.com/problems/maximize-area-of-square-hole-in-grid", "title": "maximize-area-of-square-hole-in-grid", "meta": {"questionId": "3214", "questionFrontendId": "2943", "title": "Maximize Area of Square Hole in Grid", "titleSlug": "maximize-area-of-square-hole-in-grid", "isPaidOnly": false, "difficulty": "Medium", "likes": 73, "dislikes": 110, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个网格图,由n + 2条 横线段和m + 2条竖线段组成,一开始所有区域均为1 x 1的单元格。\n所有线段的编号从 1开始。\n给你两个整数n 和m。\n同时给你两个整数数组hBars 和vBars。\n\nhBars 包含区间[2, n + 1]内互不相同的横线段编号。\nvBars包含[2, m + 1]内互不相同的竖线段编号。\n\n如果满足以下条件之一,你可以 移除两个数组中的部分线段:\n\n如果移除的是横线段,它必须是hBars中的值。\n如果移除的是竖线段,它必须是vBars中的值。\n\n请你返回移除一些线段后(可能不移除任何线段),剩余网格图中 最大正方形空洞的面积,正方形空洞的意思是正方形 内部 不含有任何线段。\n\n示例 1:\n\n\n输入:n = 2, m = 1, hBars = [2,3], vBars = [2]\n输出:4\n解释:左边的图是一开始的网格图。\n横线编号的范围是区间 [1,4] ,竖线编号的范围是区间 [1,3] 。\n可以移除的横线段为 [2,3] ,竖线段为 [2] 。\n一种得到最大正方形面积的方法是移除横线段 2 和竖线段 2 。\n操作后得到的网格图如右图所示。\n正方形空洞面积为 4。\n无法得到面积大于 4 的正方形空洞。\n所以答案为 4 。\n\n示例 2:\n\n\n输入:n = 1, m = 1, hBars = [2], vBars = [2]\n输出:4\n解释:左边的图是一开始的网格图。\n横线编号的范围是区间 [1,3] ,竖线编号的范围是区间 [1,3] 。\n可以移除的横线段为 [2] ,竖线段为 [2] 。\n一种得到最大正方形面积的方法是移除横线段 2 和竖线段 2 。\n操作后得到的网格图如右图所示。\n正方形空洞面积为 4。\n无法得到面积大于 4 的正方形空洞。\n所以答案为 4 。\n\n示例 3:\n\n\n输入:n = 2, m = 3, hBars = [2,3], vBars = [2,3,4]\n输出:9\n解释:左边的图是一开始的网格图。\n横线编号的范围是区间 [1,4] ,竖线编号的范围是区间 [1,5] 。\n可以移除的横线段为 [2,3] ,竖线段为 [2,3,4] 。\n一种得到最大正方形面积的方法是移除横线段 2、3 和竖线段 3、4 。\n操作后得到的网格图如右图所示。\n正方形空洞面积为 9。\n无法得到面积大于 9 的正方形空洞。\n所以答案为 9 。\n\n\n提示:\n\n1 <= n <= 109\n1 <= m <= 109\n1 <= hBars.length <= 100\n2 <= hBars[i] <= n + 1\n1 <= vBars.length <= 100\n2 <= vBars[i] <= m + 1\nhBars中的值互不相同。\nvBars 中的值互不相同。\n\"\"\"\nclass Solution:\n def maximizeSquareHoleArea(self, n: int, m: int, hBars: List[int], vBars: List[int]) -> int:\n ", "prompt_sft": "给你一个网格图,由n + 2条 横线段和m + 2条竖线段组成,一开始所有区域均为1 x 1的单元格。\n所有线段的编号从 1开始。\n给你两个整数n 和m。\n同时给你两个整数数组hBars 和vBars。\n\nhBars 包含区间[2, n + 1]内互不相同的横线段编号。\nvBars包含[2, m + 1]内互不相同的竖线段编号。\n\n如果满足以下条件之一,你可以 移除两个数组中的部分线段:\n\n如果移除的是横线段,它必须是hBars中的值。\n如果移除的是竖线段,它必须是vBars中的值。\n\n请你返回移除一些线段后(可能不移除任何线段),剩余网格图中 最大正方形空洞的面积,正方形空洞的意思是正方形 内部 不含有任何线段。\n\n示例 1:\n\n\n输入:n = 2, m = 1, hBars = [2,3], vBars = [2]\n输出:4\n解释:左边的图是一开始的网格图。\n横线编号的范围是区间 [1,4] ,竖线编号的范围是区间 [1,3] 。\n可以移除的横线段为 [2,3] ,竖线段为 [2] 。\n一种得到最大正方形面积的方法是移除横线段 2 和竖线段 2 。\n操作后得到的网格图如右图所示。\n正方形空洞面积为 4。\n无法得到面积大于 4 的正方形空洞。\n所以答案为 4 。\n\n示例 2:\n\n\n输入:n = 1, m = 1, hBars = [2], vBars = [2]\n输出:4\n解释:左边的图是一开始的网格图。\n横线编号的范围是区间 [1,3] ,竖线编号的范围是区间 [1,3] 。\n可以移除的横线段为 [2] ,竖线段为 [2] 。\n一种得到最大正方形面积的方法是移除横线段 2 和竖线段 2 。\n操作后得到的网格图如右图所示。\n正方形空洞面积为 4。\n无法得到面积大于 4 的正方形空洞。\n所以答案为 4 。\n\n示例 3:\n\n\n输入:n = 2, m = 3, hBars = [2,3], vBars = [2,3,4]\n输出:9\n解释:左边的图是一开始的网格图。\n横线编号的范围是区间 [1,4] ,竖线编号的范围是区间 [1,5] 。\n可以移除的横线段为 [2,3] ,竖线段为 [2,3,4] 。\n一种得到最大正方形面积的方法是移除横线段 2、3 和竖线段 3、4 。\n操作后得到的网格图如右图所示。\n正方形空洞面积为 9。\n无法得到面积大于 9 的正方形空洞。\n所以答案为 9 。\n\n\n提示:\n\n1 <= n <= 109\n1 <= m <= 109\n1 <= hBars.length <= 100\n2 <= hBars[i] <= n + 1\n1 <= vBars.length <= 100\n2 <= vBars[i] <= m + 1\nhBars中的值互不相同。\nvBars 中的值互不相同。\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def maximizeSquareHoleArea(self, n: int, m: int, hBars: List[int], vBars: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"n\": 2, \"m\": 1, \"hBars\": [2,3], \"vBars\": [2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 4\n\ntest_input = { \"n\": 1, \"m\": 1, \"hBars\": [2], \"vBars\": [2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 4\n\ntest_input = { \"n\": 2, \"m\": 3, \"hBars\": [2,3], \"vBars\": [2,3,4] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 9\n\ntest_input = { \"n\": 1, \"m\": 5, \"hBars\": [2], \"vBars\": [2,3] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 4\n\ntest_input = { \"n\": 2, \"m\": 4, \"hBars\": [3,2], \"vBars\": [4,2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 4\n\ntest_input = { \"n\": 1, \"m\": 4, \"hBars\": [2], \"vBars\": [2,3,5,4] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 4\n\ntest_input = { \"n\": 1, \"m\": 4, \"hBars\": [2], \"vBars\": [4,3,2,5] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 4\n\ntest_input = { \"n\": 3, \"m\": 2, \"hBars\": [3,2,4], \"vBars\": [3,2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 9\n\ntest_input = { \"n\": 3, \"m\": 2, \"hBars\": [4,2,3], \"vBars\": [3,2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 9\n\ntest_input = { \"n\": 14, \"m\": 4, \"hBars\": [13], \"vBars\": [3,4,5,2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 4\n\ntest_input = { \"n\": 19, \"m\": 7, \"hBars\": [6,12,4], \"vBars\": [6,3] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 4\n\ntest_input = { \"n\": 2, \"m\": 4, \"hBars\": [2,3], \"vBars\": [4,2,3,5] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 9\n\ntest_input = { \"n\": 4, \"m\": 2, \"hBars\": [2,5,4,3], \"vBars\": [3,2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 9\n\ntest_input = { \"n\": 5, \"m\": 1, \"hBars\": [2,4,3,6,5], \"vBars\": [2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 4\n\ntest_input = { \"n\": 1, \"m\": 6, \"hBars\": [2], \"vBars\": [3,2,7,4,6,5] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 4\n\ntest_input = { \"n\": 1, \"m\": 13, \"hBars\": [2], \"vBars\": [4,14,2,12,11,3] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 4\n\ntest_input = { \"n\": 2, \"m\": 5, \"hBars\": [2,3], \"vBars\": [6,2,5,4,3] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 9\n\ntest_input = { \"n\": 5, \"m\": 2, \"hBars\": [2,3,6,4,5], \"vBars\": [2,3] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 9\n\ntest_input = { \"n\": 6, \"m\": 1, \"hBars\": [7,4,3,2,5,6], \"vBars\": [2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 4\n\ntest_input = { \"n\": 4, \"m\": 4, \"hBars\": [2,3,4,5], \"vBars\": [5,4,3,2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 25\n\ntest_input = { \"n\": 4, \"m\": 4, \"hBars\": [3,4,2,5], \"vBars\": [2,5,3,4] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 25\n\ntest_input = { \"n\": 6, \"m\": 2, \"hBars\": [7,3,5,4,6,2], \"vBars\": [3,2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 9\n\ntest_input = { \"n\": 7, \"m\": 11, \"hBars\": [7,4,5,2,8,6,3], \"vBars\": [4] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 4\n\ntest_input = { \"n\": 1, \"m\": 8, \"hBars\": [2], \"vBars\": [9,7,8,2,5,6,4,3] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 4\n\ntest_input = { \"n\": 1, \"m\": 9, \"hBars\": [2], \"vBars\": [5,2,10,4,3,6,8,7] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 4\n\ntest_input = { \"n\": 2, \"m\": 7, \"hBars\": [2,3], \"vBars\": [2,5,6,8,7,3,4] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 9\n\ntest_input = { \"n\": 2, \"m\": 7, \"hBars\": [2,3], \"vBars\": [2,8,6,7,5,3,4] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 9\n\ntest_input = { \"n\": 4, \"m\": 5, \"hBars\": [3,2,4,5], \"vBars\": [4,3,6,5,2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 25\n\ntest_input = { \"n\": 4, \"m\": 5, \"hBars\": [5,3,4,2], \"vBars\": [5,3,6,4,2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 25\n\ntest_input = { \"n\": 4, \"m\": 40, \"hBars\": [5,3,2,4], \"vBars\": [36,41,6,34,33] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 9\n\ntest_input = { \"n\": 8, \"m\": 1, \"hBars\": [4,7,9,8,6,2,3,5], \"vBars\": [2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 4\n\ntest_input = { \"n\": 11, \"m\": 6, \"hBars\": [8,9,6], \"vBars\": [5,3,6,4,2,7] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 9\n\ntest_input = { \"n\": 22, \"m\": 50, \"hBars\": [6,19,8,17,23], \"vBars\": [51,3,32,44] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 4\n\ntest_input = { \"n\": 27, \"m\": 2, \"hBars\": [2,26,28,22,4,8,23], \"vBars\": [3,2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 9\n\ntest_input = { \"n\": 1, \"m\": 9, \"hBars\": [2], \"vBars\": [3,6,10,4,8,5,9,7,2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 4\n\ntest_input = { \"n\": 1, \"m\": 9, \"hBars\": [2], \"vBars\": [3,7,5,9,10,2,4,8,6] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 4\n\ntest_input = { \"n\": 3, \"m\": 7, \"hBars\": [2,4,3], \"vBars\": [5,4,2,3,7,6,8] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 16\n\ntest_input = { \"n\": 3, \"m\": 7, \"hBars\": [4,3,2], \"vBars\": [2,7,3,6,5,4,8] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 16\n\ntest_input = { \"n\": 3, \"m\": 7, \"hBars\": [4,3,2], \"vBars\": [3,7,5,2,6,4,8] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 16\n\ntest_input = { \"n\": 3, \"m\": 7, \"hBars\": [4,3,2], \"vBars\": [8,2,5,3,6,4,7] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 16\n\ntest_input = { \"n\": 3, \"m\": 13, \"hBars\": [2,4,3], \"vBars\": [4,6,7,12,10,13,2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 9\n\ntest_input = { \"n\": 4, \"m\": 6, \"hBars\": [2,3,4,5], \"vBars\": [7,2,4,6,3,5] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 25\n\ntest_input = { \"n\": 5, \"m\": 5, \"hBars\": [4,6,5,2,3], \"vBars\": [2,4,5,6,3] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 36\n\ntest_input = { \"n\": 7, \"m\": 3, \"hBars\": [8,6,4,5,7,2,3], \"vBars\": [4,3,2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 16\n\ntest_input = { \"n\": 8, \"m\": 2, \"hBars\": [4,2,6,8,7,5,3,9], \"vBars\": [3,2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 9\n\ntest_input = { \"n\": 9, \"m\": 1, \"hBars\": [2,9,3,10,4,6,7,8,5], \"vBars\": [2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 4\n\ntest_input = { \"n\": 9, \"m\": 1, \"hBars\": [9,5,4,8,7,10,3,2,6], \"vBars\": [2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 4\n\ntest_input = { \"n\": 12, \"m\": 5, \"hBars\": [10,9,13,6,3], \"vBars\": [3,4,2,5,6] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 9\n\ntest_input = { \"n\": 29, \"m\": 2, \"hBars\": [25,14,11,29,7,10,16,8], \"vBars\": [2,3] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 9\n\ntest_input = { \"n\": 1, \"m\": 10, \"hBars\": [2], \"vBars\": [3,4,6,8,5,7,9,10,11,2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 4\n\ntest_input = { \"n\": 1, \"m\": 10, \"hBars\": [2], \"vBars\": [10,6,5,7,4,3,11,8,9,2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 4\n\ntest_input = { \"n\": 2, \"m\": 9, \"hBars\": [2,3], \"vBars\": [6,7,9,3,10,2,5,4,8] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 9\n\ntest_input = { \"n\": 2, \"m\": 9, \"hBars\": [3,2], \"vBars\": [4,8,2,6,7,3,5,9,10] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 9\n\ntest_input = { \"n\": 4, \"m\": 7, \"hBars\": [5,4,3,2], \"vBars\": [8,7,5,2,4,3,6] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 25\n\ntest_input = { \"n\": 5, \"m\": 6, \"hBars\": [2,6,5,3,4], \"vBars\": [4,2,5,3,7,6] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 36\n\ntest_input = { \"n\": 5, \"m\": 6, \"hBars\": [5,3,6,2,4], \"vBars\": [5,7,2,4,3,6] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 36\n\ntest_input = { \"n\": 5, \"m\": 6, \"hBars\": [6,4,3,5,2], \"vBars\": [2,4,5,7,6,3] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 36\n\ntest_input = { \"n\": 5, \"m\": 11, \"hBars\": [4,2,6,3,5], \"vBars\": [8,11,10,12,6,2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 16\n\ntest_input = { \"n\": 6, \"m\": 5, \"hBars\": [4,5,3,2,7,6], \"vBars\": [6,3,5,4,2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 36\n\ntest_input = { \"n\": 6, \"m\": 5, \"hBars\": [5,2,3,7,4,6], \"vBars\": [6,2,4,3,5] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 36\n\ntest_input = { \"n\": 6, \"m\": 5, \"hBars\": [6,3,4,2,7,5], \"vBars\": [2,5,4,3,6] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 36\n\ntest_input = { \"n\": 6, \"m\": 5, \"hBars\": [7,2,3,4,5,6], \"vBars\": [6,5,4,2,3] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 36\n\ntest_input = { \"n\": 8, \"m\": 3, \"hBars\": [4,6,9,3,8,2,7,5], \"vBars\": [2,4,3] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 16\n\ntest_input = { \"n\": 8, \"m\": 3, \"hBars\": [5,6,9,3,2,4,8,7], \"vBars\": [2,4,3] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 16\n\ntest_input = { \"n\": 8, \"m\": 3, \"hBars\": [8,6,4,3,7,2,9,5], \"vBars\": [4,2,3] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 16\n\ntest_input = { \"n\": 8, \"m\": 3, \"hBars\": [9,2,7,6,8,3,4,5], \"vBars\": [4,2,3] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 16\n\ntest_input = { \"n\": 9, \"m\": 2, \"hBars\": [5,4,6,8,9,10,2,3,7], \"vBars\": [3,2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 9\n\ntest_input = { \"n\": 9, \"m\": 2, \"hBars\": [6,3,5,4,8,9,2,10,7], \"vBars\": [3,2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 9\n\ntest_input = { \"n\": 10, \"m\": 1, \"hBars\": [4,3,10,2,11,5,6,9,8,7], \"vBars\": [2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 4\n\ntest_input = { \"n\": 1, \"m\": 11, \"hBars\": [2], \"vBars\": [7,12,6,3,4,9,5,10,11,2,8] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 4\n\ntest_input = { \"n\": 2, \"m\": 10, \"hBars\": [2,3], \"vBars\": [11,10,2,8,7,5,6,9,3,4] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 9\n\ntest_input = { \"n\": 4, \"m\": 8, \"hBars\": [5,2,3,4], \"vBars\": [8,7,5,9,4,2,3,6] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 25\n\ntest_input = { \"n\": 5, \"m\": 7, \"hBars\": [2,3,6,4,5], \"vBars\": [6,8,4,5,3,7,2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 36\n\ntest_input = { \"n\": 6, \"m\": 10, \"hBars\": [2,4,3,6,5,7], \"vBars\": [11,3,9,6,10,4] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 16\n\ntest_input = { \"n\": 10, \"m\": 2, \"hBars\": [8,5,4,3,10,2,11,9,6,7], \"vBars\": [3,2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 9\n\ntest_input = { \"n\": 11, \"m\": 1, \"hBars\": [2,6,9,7,5,11,3,10,4,12,8], \"vBars\": [2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 4\n\ntest_input = { \"n\": 44, \"m\": 2, \"hBars\": [5,16,18,28,3,9,6,35,14,10], \"vBars\": [3,2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 9\n\ntest_input = { \"n\": 1, \"m\": 12, \"hBars\": [2], \"vBars\": [12,9,3,13,7,2,6,11,10,8,4,5] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 4\n\ntest_input = { \"n\": 2, \"m\": 11, \"hBars\": [2,3], \"vBars\": [3,7,2,5,12,9,10,4,8,11,6] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 9\n\ntest_input = { \"n\": 2, \"m\": 11, \"hBars\": [2,3], \"vBars\": [12,10,6,7,2,3,5,11,4,8,9] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 9\n\ntest_input = { \"n\": 5, \"m\": 8, \"hBars\": [2,4,6,3,5], \"vBars\": [8,7,9,4,2,5,6,3] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 36\n\ntest_input = { \"n\": 6, \"m\": 7, \"hBars\": [5,4,6,3,2,7], \"vBars\": [4,7,6,5,2,8,3] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 49\n\ntest_input = { \"n\": 6, \"m\": 7, \"hBars\": [6,3,2,7,4,5], \"vBars\": [6,7,5,2,3,4,8] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 49\n\ntest_input = { \"n\": 8, \"m\": 5, \"hBars\": [7,4,3,9,2,8,6,5], \"vBars\": [5,2,6,3,4] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 36\n\ntest_input = { \"n\": 9, \"m\": 4, \"hBars\": [4,5,6,10,7,2,3,9,8], \"vBars\": [5,3,2,4] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 25\n\ntest_input = { \"n\": 9, \"m\": 4, \"hBars\": [9,6,3,10,2,8,4,5,7], \"vBars\": [4,3,2,5] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 25\n\ntest_input = { \"n\": 10, \"m\": 3, \"hBars\": [5,4,9,8,3,6,11,2,10,7], \"vBars\": [4,3,2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 16\n\ntest_input = { \"n\": 10, \"m\": 6, \"hBars\": [6,2,8,3,11,9,10,7,4,5], \"vBars\": [6,2,5] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 9\n\ntest_input = { \"n\": 11, \"m\": 2, \"hBars\": [8,12,9,3,5,2,10,6,7,4,11], \"vBars\": [3,2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 9\n\ntest_input = { \"n\": 28, \"m\": 31, \"hBars\": [29,24,4], \"vBars\": [22,24,2,14,26,4,29,13,15,25] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 4\n\ntest_input = { \"n\": 1, \"m\": 13, \"hBars\": [2], \"vBars\": [9,5,2,6,8,11,7,10,3,13,14,4,12] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 4\n\ntest_input = { \"n\": 2, \"m\": 12, \"hBars\": [3,2], \"vBars\": [13,2,7,4,12,9,10,3,6,5,8,11] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 9\n\ntest_input = { \"n\": 2, \"m\": 12, \"hBars\": [3,2], \"vBars\": [13,4,7,8,3,2,11,12,5,9,6,10] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 9\n\ntest_input = { \"n\": 5, \"m\": 9, \"hBars\": [2,5,6,3,4], \"vBars\": [2,7,3,9,4,10,8,6,5] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 36\n\ntest_input = { \"n\": 6, \"m\": 9, \"hBars\": [4,2,5,7,6,3], \"vBars\": [4,2,6,8,10,3,7,5] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 49\n\ntest_input = { \"n\": 8, \"m\": 6, \"hBars\": [4,8,6,7,2,9,3,5], \"vBars\": [4,7,6,3,2,5] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 49\n\ntest_input = { \"n\": 9, \"m\": 5, \"hBars\": [2,5,4,8,3,7,6,10,9], \"vBars\": [6,3,5,2,4] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 36\n\ntest_input = { \"n\": 9, \"m\": 5, \"hBars\": [8,9,5,2,6,7,4,10,3], \"vBars\": [6,2,3,4,5] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 36\n\ntest_input = { \"n\": 10, \"m\": 4, \"hBars\": [4,8,6,3,10,2,7,9,5,11], \"vBars\": [5,4,3,2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 25\n\ntest_input = { \"n\": 11, \"m\": 3, \"hBars\": [2,8,5,3,12,10,4,11,6,7,9], \"vBars\": [3,4,2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 16", "start_time": 1700922600} +{"task_id": "biweekly-contest-118-minimum-number-of-coins-for-fruits", "url": "https://leetcode.com/problems/minimum-number-of-coins-for-fruits", "title": "minimum-number-of-coins-for-fruits", "meta": {"questionId": "3209", "questionFrontendId": "2944", "title": "Minimum Number of Coins for Fruits", "titleSlug": "minimum-number-of-coins-for-fruits", "isPaidOnly": false, "difficulty": "Medium", "likes": 141, "dislikes": 27, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n你在一个水果超市里,货架上摆满了玲琅满目的奇珍异果。\n给你一个下标从 1开始的数组prices,其中prices[i]表示你购买第 i个水果需要花费的金币数目。\n水果超市有如下促销活动:\n\n如果你花费 price[i]购买了水果i,那么接下来的 i个水果你都可以免费获得。\n\n注意,即使你可以免费获得水果j,你仍然可以花费prices[j]个金币去购买它以便能免费获得接下来的 j个水果。\n请你返回获得所有水果所需要的 最少金币数。\n\n示例 1:\n\n输入:prices = [3,1,2]\n输出:4\n解释:你可以按如下方法获得所有水果:\n- 花 3 个金币购买水果 1 ,然后免费获得水果 2 。\n- 花 1 个金币购买水果 2 ,然后免费获得水果 3 。\n- 免费获得水果 3 。\n注意,虽然你可以免费获得水果 2 ,但你还是花 1 个金币去购买它,因为这样的总花费最少。\n购买所有水果需要最少花费 4 个金币。\n\n示例 2:\n\n输入:prices = [1,10,1,1]\n输出:2\n解释:你可以按如下方法获得所有水果:\n- 花 1 个金币购买水果 1 ,然后免费获得水果 2 。\n- 免费获得水果 2 。\n- 花 1 个金币购买水果 3 ,然后免费获得水果 4 。\n- 免费获得水果 4 。\n购买所有水果需要最少花费 2 个金币。\n\n\n提示:\n\n1 <= prices.length <= 1000\n1 <= prices[i] <= 105\n\"\"\"\nclass Solution:\n def minimumCoins(self, prices: List[int]) -> int:\n ", "prompt_sft": "你在一个水果超市里,货架上摆满了玲琅满目的奇珍异果。\n给你一个下标从 1开始的数组prices,其中prices[i]表示你购买第 i个水果需要花费的金币数目。\n水果超市有如下促销活动:\n\n如果你花费 price[i]购买了水果i,那么接下来的 i个水果你都可以免费获得。\n\n注意,即使你可以免费获得水果j,你仍然可以花费prices[j]个金币去购买它以便能免费获得接下来的 j个水果。\n请你返回获得所有水果所需要的 最少金币数。\n\n示例 1:\n\n输入:prices = [3,1,2]\n输出:4\n解释:你可以按如下方法获得所有水果:\n- 花 3 个金币购买水果 1 ,然后免费获得水果 2 。\n- 花 1 个金币购买水果 2 ,然后免费获得水果 3 。\n- 免费获得水果 3 。\n注意,虽然你可以免费获得水果 2 ,但你还是花 1 个金币去购买它,因为这样的总花费最少。\n购买所有水果需要最少花费 4 个金币。\n\n示例 2:\n\n输入:prices = [1,10,1,1]\n输出:2\n解释:你可以按如下方法获得所有水果:\n- 花 1 个金币购买水果 1 ,然后免费获得水果 2 。\n- 免费获得水果 2 。\n- 花 1 个金币购买水果 3 ,然后免费获得水果 4 。\n- 免费获得水果 4 。\n购买所有水果需要最少花费 2 个金币。\n\n\n提示:\n\n1 <= prices.length <= 1000\n1 <= prices[i] <= 105\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def minimumCoins(self, prices: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"prices\": [3,1,2] }\nassert my_solution.minimumCoins(**test_input) == 4\n\ntest_input = { \"prices\": [1,10,1,1] }\nassert my_solution.minimumCoins(**test_input) == 2\n\ntest_input = { \"prices\": [26,18,6,12,49,7,45,45] }\nassert my_solution.minimumCoins(**test_input) == 39\n\ntest_input = { \"prices\": [27,17,29,45,3,39,42,26] }\nassert my_solution.minimumCoins(**test_input) == 47\n\ntest_input = { \"prices\": [14,37,37,38,24,15,12] }\nassert my_solution.minimumCoins(**test_input) == 63\n\ntest_input = { \"prices\": [1,37,19,38,11,42,18,33,6,37,15,48,23,12,41,18,27,32] }\nassert my_solution.minimumCoins(**test_input) == 37\n\ntest_input = { \"prices\": [38,23,27,32,47,45,48,24,39,26,37,42,24,45,27,26,15,16,26,6] }\nassert my_solution.minimumCoins(**test_input) == 132\n\ntest_input = { \"prices\": [45,44,5,9,22,14,29,14,21,13,45,10,2,16,14,30,26,1,49] }\nassert my_solution.minimumCoins(**test_input) == 66\n\ntest_input = { \"prices\": [37,42,6,50,50,38,30,38,1,13,25,39,18,1,35,32,12] }\nassert my_solution.minimumCoins(**test_input) == 74\n\ntest_input = { \"prices\": [17,32,11,25,22] }\nassert my_solution.minimumCoins(**test_input) == 28\n\ntest_input = { \"prices\": [18,10,1,11,6,30,19,24,1,18,37,29,28,27,38] }\nassert my_solution.minimumCoins(**test_input) == 26\n\ntest_input = { \"prices\": [3,10,25,47,49,10,49] }\nassert my_solution.minimumCoins(**test_input) == 38\n\ntest_input = { \"prices\": [46,7,15] }\nassert my_solution.minimumCoins(**test_input) == 53\n\ntest_input = { \"prices\": [16,45,25,5,18,19,25,13,33] }\nassert my_solution.minimumCoins(**test_input) == 59\n\ntest_input = { \"prices\": [21,16,7,10,30] }\nassert my_solution.minimumCoins(**test_input) == 28\n\ntest_input = { \"prices\": [21,22,29,37,23,15,39,9,19,10,6,9,33,28,43] }\nassert my_solution.minimumCoins(**test_input) == 71\n\ntest_input = { \"prices\": [37,16,42,47,16,31,39,8,26,50,33] }\nassert my_solution.minimumCoins(**test_input) == 77\n\ntest_input = { \"prices\": [32,4] }\nassert my_solution.minimumCoins(**test_input) == 32\n\ntest_input = { \"prices\": [31,9,2,36,4,45,28,28,12,22,44,17,10,48,15,22,7,14,41] }\nassert my_solution.minimumCoins(**test_input) == 56\n\ntest_input = { \"prices\": [1,31,9,36,44,2,23] }\nassert my_solution.minimumCoins(**test_input) == 12\n\ntest_input = { \"prices\": [3,7,2,36,33,7,21,40,19] }\nassert my_solution.minimumCoins(**test_input) == 12\n\ntest_input = { \"prices\": [9,4,7,29,22,50] }\nassert my_solution.minimumCoins(**test_input) == 16\n\ntest_input = { \"prices\": [28,2,40,15] }\nassert my_solution.minimumCoins(**test_input) == 30\n\ntest_input = { \"prices\": [16,17,47,20,18,37] }\nassert my_solution.minimumCoins(**test_input) == 51\n\ntest_input = { \"prices\": [42,6,44,47,11,6,30,38,41,43,46,35,28,4,47,1,7,35] }\nassert my_solution.minimumCoins(**test_input) == 93\n\ntest_input = { \"prices\": [10,10,5,8,5,13,34,31,36] }\nassert my_solution.minimumCoins(**test_input) == 20\n\ntest_input = { \"prices\": [12,20,14,46,22,1,42,50,47,47,38,37,13] }\nassert my_solution.minimumCoins(**test_input) == 40\n\ntest_input = { \"prices\": [1,38,28,46,18,22,12,7,44,44,40,36,41,5,33,5,30,33,31] }\nassert my_solution.minimumCoins(**test_input) == 46\n\ntest_input = { \"prices\": [6,45,2,29,44,14,44] }\nassert my_solution.minimumCoins(**test_input) == 22\n\ntest_input = { \"prices\": [34,13,50,42,24,47,41,8,26,34,3,48,39,24,39,26,46] }\nassert my_solution.minimumCoins(**test_input) == 74\n\ntest_input = { \"prices\": [47,9,33,6,33,40,28,37,49,39,45,14,13,40,17,14,39,12,15,6] }\nassert my_solution.minimumCoins(**test_input) == 103\n\ntest_input = { \"prices\": [32] }\nassert my_solution.minimumCoins(**test_input) == 32\n\ntest_input = { \"prices\": [35,46,50,35,11,14,44,17,45,23,34,33,8,27,19,7,10,12,14] }\nassert my_solution.minimumCoins(**test_input) == 107\n\ntest_input = { \"prices\": [50,45,14,24,18,15,9,14] }\nassert my_solution.minimumCoins(**test_input) == 73\n\ntest_input = { \"prices\": [38,19,18,15,20,43,18,9,44,26,29] }\nassert my_solution.minimumCoins(**test_input) == 74\n\ntest_input = { \"prices\": [26,21,7,40,37,44,13,3,10,9,15,12,30,18,31,10,23] }\nassert my_solution.minimumCoins(**test_input) == 55\n\ntest_input = { \"prices\": [36,50] }\nassert my_solution.minimumCoins(**test_input) == 36\n\ntest_input = { \"prices\": [1,32,48,36,26,5,30,25,2,17,26,39,17,46,34,47,43,45,20,48] }\nassert my_solution.minimumCoins(**test_input) == 71\n\ntest_input = { \"prices\": [19,24,31,24] }\nassert my_solution.minimumCoins(**test_input) == 43\n\ntest_input = { \"prices\": [1,18,25,29,17,9,3,29,23,17,18] }\nassert my_solution.minimumCoins(**test_input) == 29\n\ntest_input = { \"prices\": [18,36,18,44,30,8,42,33,45,19,50,19,24,48] }\nassert my_solution.minimumCoins(**test_input) == 63\n\ntest_input = { \"prices\": [26,25,47,36,9,31,1,29,29,42,29,42,36,19,45,4,11,7] }\nassert my_solution.minimumCoins(**test_input) == 80\n\ntest_input = { \"prices\": [24,34,47,12,24,48,14,30,28,43,35,45,11,11,35,38] }\nassert my_solution.minimumCoins(**test_input) == 95\n\ntest_input = { \"prices\": [29,18,2,6,47,32,27,12,38,17] }\nassert my_solution.minimumCoins(**test_input) == 49\n\ntest_input = { \"prices\": [3,31,15,18,47,18,2,27,24,6,36,35,41,21,30] }\nassert my_solution.minimumCoins(**test_input) == 26\n\ntest_input = { \"prices\": [29,45,8,45,23,35] }\nassert my_solution.minimumCoins(**test_input) == 37\n\ntest_input = { \"prices\": [39,37] }\nassert my_solution.minimumCoins(**test_input) == 39\n\ntest_input = { \"prices\": [18,45,6,14,41,41] }\nassert my_solution.minimumCoins(**test_input) == 24\n\ntest_input = { \"prices\": [50,21,38,2,32,49,32,40,41,34,33,40,36,16,29,34,42,40,46] }\nassert my_solution.minimumCoins(**test_input) == 121\n\ntest_input = { \"prices\": [28,17,42,20,6,26,47,6,23] }\nassert my_solution.minimumCoins(**test_input) == 51\n\ntest_input = { \"prices\": [37,27,17,40,50,35,16,4,28,5,27,13,46,7,23,27] }\nassert my_solution.minimumCoins(**test_input) == 74\n\ntest_input = { \"prices\": [11,5,40,16,20,38] }\nassert my_solution.minimumCoins(**test_input) == 32\n\ntest_input = { \"prices\": [16,27,5,38,12,24,7,49,40,13,38,13,34,38,37,2,4,44] }\nassert my_solution.minimumCoins(**test_input) == 41\n\ntest_input = { \"prices\": [25,9,49,19,33] }\nassert my_solution.minimumCoins(**test_input) == 53\n\ntest_input = { \"prices\": [47,23,46,13,26,44,43,22,43,24,13,20,6,16,8,26] }\nassert my_solution.minimumCoins(**test_input) == 105\n\ntest_input = { \"prices\": [8,1,1] }\nassert my_solution.minimumCoins(**test_input) == 9\n\ntest_input = { \"prices\": [47,45,2,25,7,46] }\nassert my_solution.minimumCoins(**test_input) == 49\n\ntest_input = { \"prices\": [4,31,50,45,5,50] }\nassert my_solution.minimumCoins(**test_input) == 40\n\ntest_input = { \"prices\": [30,41,1,49,9,49,41,27,41,14,23,3,46,40,37,28,45,19,36,49] }\nassert my_solution.minimumCoins(**test_input) == 54\n\ntest_input = { \"prices\": [6,3,49,28,31,36,5,50,39] }\nassert my_solution.minimumCoins(**test_input) == 40\n\ntest_input = { \"prices\": [37,2,19,36,26,27,3,23,10,20,33,8,39,6,28] }\nassert my_solution.minimumCoins(**test_input) == 65\n\ntest_input = { \"prices\": [37,34,12,30,43,35,6,21,47,38,14,31,49,11,14] }\nassert my_solution.minimumCoins(**test_input) == 66\n\ntest_input = { \"prices\": [49,6,12,35,17,17,2] }\nassert my_solution.minimumCoins(**test_input) == 63\n\ntest_input = { \"prices\": [45,27,43,34,41,30,28,45,24,50,20,4,15,42] }\nassert my_solution.minimumCoins(**test_input) == 116\n\ntest_input = { \"prices\": [48,22,36] }\nassert my_solution.minimumCoins(**test_input) == 70\n\ntest_input = { \"prices\": [47,13,23,31,41,25] }\nassert my_solution.minimumCoins(**test_input) == 70\n\ntest_input = { \"prices\": [3,44,17,37,9,14,37] }\nassert my_solution.minimumCoins(**test_input) == 29\n\ntest_input = { \"prices\": [4,43,7,15,38] }\nassert my_solution.minimumCoins(**test_input) == 11\n\ntest_input = { \"prices\": [10,25,7,37,6,43,4,50,9,14,36,35,36,44,17,10,44,46,50] }\nassert my_solution.minimumCoins(**test_input) == 35\n\ntest_input = { \"prices\": [45,28,10,18,18,3,42,24,14,11,13,32,37,31,50,32] }\nassert my_solution.minimumCoins(**test_input) == 69\n\ntest_input = { \"prices\": [12,38,44,24,42,9,32,40,8,20,46,39,33] }\nassert my_solution.minimumCoins(**test_input) == 73\n\ntest_input = { \"prices\": [5,42,30,20,37,26,38,30,30,32,39,31,33,41,23,4,29] }\nassert my_solution.minimumCoins(**test_input) == 85\n\ntest_input = { \"prices\": [44,22] }\nassert my_solution.minimumCoins(**test_input) == 44\n\ntest_input = { \"prices\": [8,8,11,21,9] }\nassert my_solution.minimumCoins(**test_input) == 19\n\ntest_input = { \"prices\": [2,37,19,30,37,27,10,37] }\nassert my_solution.minimumCoins(**test_input) == 31\n\ntest_input = { \"prices\": [43,27,48,22] }\nassert my_solution.minimumCoins(**test_input) == 70\n\ntest_input = { \"prices\": [50,23,37,49,45,14,18,39,50,7,31] }\nassert my_solution.minimumCoins(**test_input) == 101\n\ntest_input = { \"prices\": [37,3,32,25,21,22,26,49,14,45,1,36] }\nassert my_solution.minimumCoins(**test_input) == 62\n\ntest_input = { \"prices\": [21,29,31,28,2,41,4,43,41,16,38,33,3,6,43,22,15] }\nassert my_solution.minimumCoins(**test_input) == 59\n\ntest_input = { \"prices\": [24,47,32,41,35,14,18,23,27,8,27] }\nassert my_solution.minimumCoins(**test_input) == 70\n\ntest_input = { \"prices\": [40,25,32] }\nassert my_solution.minimumCoins(**test_input) == 65\n\ntest_input = { \"prices\": [9,18,2,26,15,3,2,33,46,6,11,34,27,7,5,7,26,13,48] }\nassert my_solution.minimumCoins(**test_input) == 18\n\ntest_input = { \"prices\": [41,8,38,32,36,30,23,49,40,46,42,34,2,12,12,19,20,50,40] }\nassert my_solution.minimumCoins(**test_input) == 104\n\ntest_input = { \"prices\": [28,8,24,14,34,36,48] }\nassert my_solution.minimumCoins(**test_input) == 50\n\ntest_input = { \"prices\": [2,36,22,41,42,26,1,48,14,27,22,26] }\nassert my_solution.minimumCoins(**test_input) == 25\n\ntest_input = { \"prices\": [25,39,21,21,16] }\nassert my_solution.minimumCoins(**test_input) == 46\n\ntest_input = { \"prices\": [44,41,36,42,21,32,45,5] }\nassert my_solution.minimumCoins(**test_input) == 101\n\ntest_input = { \"prices\": [10] }\nassert my_solution.minimumCoins(**test_input) == 10\n\ntest_input = { \"prices\": [35,29] }\nassert my_solution.minimumCoins(**test_input) == 35\n\ntest_input = { \"prices\": [38,35,33,11,43,33] }\nassert my_solution.minimumCoins(**test_input) == 71\n\ntest_input = { \"prices\": [19,29,49,20,8,12,13,28,45,9,12,3,1,17,35] }\nassert my_solution.minimumCoins(**test_input) == 65\n\ntest_input = { \"prices\": [34,22,1,41,34,27,18] }\nassert my_solution.minimumCoins(**test_input) == 53\n\ntest_input = { \"prices\": [31,9,39,6,14,32,28,35,34,42,19,41,35,24,32,16,12,49,16] }\nassert my_solution.minimumCoins(**test_input) == 73\n\ntest_input = { \"prices\": [46,50,21,14,26,47] }\nassert my_solution.minimumCoins(**test_input) == 67\n\ntest_input = { \"prices\": [5,22,36,6,15,49,20,16,36,15,32,27,50,19,12,22,9,33] }\nassert my_solution.minimumCoins(**test_input) == 57\n\ntest_input = { \"prices\": [17,4,36,4,32,11,42,12,20] }\nassert my_solution.minimumCoins(**test_input) == 36\n\ntest_input = { \"prices\": [48,33,39,1,13,40] }\nassert my_solution.minimumCoins(**test_input) == 82\n\ntest_input = { \"prices\": [32,19,33,30,32,44,47,8,10,1,23,6,28,19,20,48,12,10,20,22] }\nassert my_solution.minimumCoins(**test_input) == 84\n\ntest_input = { \"prices\": [29,5,46,34,38,7,1,15] }\nassert my_solution.minimumCoins(**test_input) == 68\n\ntest_input = { \"prices\": [39,50,22,1,38,22,49,16,27,48,45,28,43,34] }\nassert my_solution.minimumCoins(**test_input) == 78", "start_time": 1700922600} +{"task_id": "biweekly-contest-118-find-maximum-non-decreasing-array-length", "url": "https://leetcode.com/problems/find-maximum-non-decreasing-array-length", "title": "find-maximum-non-decreasing-array-length", "meta": {"questionId": "3211", "questionFrontendId": "2945", "title": "Find Maximum Non-decreasing Array Length", "titleSlug": "find-maximum-non-decreasing-array-length", "isPaidOnly": false, "difficulty": "Hard", "likes": 90, "dislikes": 9, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0开始的整数数组nums。\n你可以执行任意次操作。每次操作中,你需要选择一个 子数组,并将这个子数组用它所包含元素的 和替换。比方说,给定数组是[1,3,5,6],你可以选择子数组[3,5],用子数组的和 8替换掉子数组,然后数组会变为[1,8,6]。\n请你返回执行任意次操作以后,可以得到的 最长非递减数组的长度。\n子数组指的是一个数组中一段连续 非空的元素序列。\n\n示例 1:\n\n输入:nums = [5,2,2]\n输出:1\n解释:这个长度为 3 的数组不是非递减的。\n我们有 2 种方案使数组长度为 2 。\n第一种,选择子数组 [2,2] ,对数组执行操作后得到 [5,4] 。\n第二种,选择子数组 [5,2] ,对数组执行操作后得到 [7,2] 。\n这两种方案中,数组最后都不是 非递减的,所以不是可行的答案。\n如果我们选择子数组 [5,2,2] ,并将它替换为 [9] ,数组变成非递减的。\n所以答案为 1 。\n\n示例 2:\n\n输入:nums = [1,2,3,4]\n输出:4\n解释:数组已经是非递减的。所以答案为 4 。\n\n示例 3:\n\n输入:nums = [4,3,2,6]\n输出:3\n解释:将 [3,2] 替换为 [5] ,得到数组 [4,5,6] ,它是非递减的。\n最大可能的答案为 3 。\n\n提示:\n\n1 <= nums.length <= 105\n1 <= nums[i] <= 105\n\"\"\"\nclass Solution:\n def findMaximumLength(self, nums: List[int]) -> int:\n ", "prompt_sft": "给你一个下标从 0开始的整数数组nums。\n你可以执行任意次操作。每次操作中,你需要选择一个 子数组,并将这个子数组用它所包含元素的 和替换。比方说,给定数组是[1,3,5,6],你可以选择子数组[3,5],用子数组的和 8替换掉子数组,然后数组会变为[1,8,6]。\n请你返回执行任意次操作以后,可以得到的 最长非递减数组的长度。\n子数组指的是一个数组中一段连续 非空的元素序列。\n\n示例 1:\n\n输入:nums = [5,2,2]\n输出:1\n解释:这个长度为 3 的数组不是非递减的。\n我们有 2 种方案使数组长度为 2 。\n第一种,选择子数组 [2,2] ,对数组执行操作后得到 [5,4] 。\n第二种,选择子数组 [5,2] ,对数组执行操作后得到 [7,2] 。\n这两种方案中,数组最后都不是 非递减的,所以不是可行的答案。\n如果我们选择子数组 [5,2,2] ,并将它替换为 [9] ,数组变成非递减的。\n所以答案为 1 。\n\n示例 2:\n\n输入:nums = [1,2,3,4]\n输出:4\n解释:数组已经是非递减的。所以答案为 4 。\n\n示例 3:\n\n输入:nums = [4,3,2,6]\n输出:3\n解释:将 [3,2] 替换为 [5] ,得到数组 [4,5,6] ,它是非递减的。\n最大可能的答案为 3 。\n\n提示:\n\n1 <= nums.length <= 105\n1 <= nums[i] <= 105\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def findMaximumLength(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [5,2,2] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,3,4] }\nassert my_solution.findMaximumLength(**test_input) == 4\n\ntest_input = { \"nums\": [4,3,2,6] }\nassert my_solution.findMaximumLength(**test_input) == 3\n\ntest_input = { \"nums\": [32] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [38] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [60] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [79] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [85] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [170] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [198] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [220] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [318] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [350] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [381] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [413] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [426] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [429] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [431] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [445] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [488] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [492] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [497] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [515] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [582] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [589] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [620] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [632] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [703] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [748] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [776] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [977] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [986] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [990] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [29,859] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [48,612] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [76,837] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [103,341] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [171,323] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [248,719] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [253,61] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [274,467] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [351,665] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [372,382] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [404,409] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [455,40] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [472,843] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [504,838] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [549,747] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [570,810] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [621,809] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [643,802] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [689,192] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [709,481] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [742,67] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [745,725] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [773,877] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [776,962] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [791,434] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [824,783] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [840,388] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [876,264] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [940,694] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [959,372] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [981,998] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [41,340,784] }\nassert my_solution.findMaximumLength(**test_input) == 3\n\ntest_input = { \"nums\": [103,652,579] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [116,635,966] }\nassert my_solution.findMaximumLength(**test_input) == 3\n\ntest_input = { \"nums\": [137,32,745] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [247,173,316] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [276,315,947] }\nassert my_solution.findMaximumLength(**test_input) == 3\n\ntest_input = { \"nums\": [278,754,912] }\nassert my_solution.findMaximumLength(**test_input) == 3\n\ntest_input = { \"nums\": [314,882,708] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [371,101,367] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [402,305,990] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [403,553,697] }\nassert my_solution.findMaximumLength(**test_input) == 3\n\ntest_input = { \"nums\": [431,780,315] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [479,322,44] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [512,234,679] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [513,847,778] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [525,177,936] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [588,42,18] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [646,174,827] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [680,242,726] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [769,131,241] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [780,591,213] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [783,23,848] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [787,201,30] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [791,470,87] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [797,181,492] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [868,4,455] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [881,306,316] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [886,116,68] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [893,531,805] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [926,641,145] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [964,624,279] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [987,694,396] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [38,986,134,156] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [43,236,417,521] }\nassert my_solution.findMaximumLength(**test_input) == 4\n\ntest_input = { \"nums\": [58,890,892,52] }\nassert my_solution.findMaximumLength(**test_input) == 3\n\ntest_input = { \"nums\": [81,738,403,654] }\nassert my_solution.findMaximumLength(**test_input) == 3", "start_time": 1700922600} +{"task_id": "weekly-contest-372-make-three-strings-equal", "url": "https://leetcode.com/problems/make-three-strings-equal/", "title": "make-three-strings-equal", "meta": {"questionId": "3207", "questionFrontendId": "2937", "title": "Make Three Strings Equal", "titleSlug": "make-three-strings-equal", "isPaidOnly": false, "difficulty": "Easy", "likes": 114, "dislikes": 30, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你三个字符串 s1、s2 和 s3。 你可以根据需要对这三个字符串执行以下操作 任意次数 。\n在每次操作中,你可以选择其中一个长度至少为 2 的字符串 并删除其 最右位置上 的字符。\n如果存在某种方法能够使这三个字符串相等,请返回使它们相等所需的 最小 操作次数;否则,返回 -1。\n\n示例 1:\n\n输入:s1 = \"abc\",s2 = \"abb\",s3 = \"ab\"\n输出:2\n解释:对 s1 和 s2 进行一次操作后,可以得到三个相等的字符串。\n可以证明,不可能用少于两次操作使它们相等。\n示例 2:\n\n输入:s1 = \"dac\",s2 = \"bac\",s3 = \"cac\"\n输出:-1\n解释:因为 s1 和 s2 的最左位置上的字母不相等,所以无论进行多少次操作,它们都不可能相等。因此答案是 -1 。\n\n提示:\n\n1 <= s1.length, s2.length, s3.length <= 100\ns1、s2 和 s3 仅由小写英文字母组成。\n\"\"\"\nclass Solution:\n def findMinimumOperations(self, s1: str, s2: str, s3: str) -> int:\n ", "prompt_sft": "给你三个字符串 s1、s2 和 s3。 你可以根据需要对这三个字符串执行以下操作 任意次数 。\n在每次操作中,你可以选择其中一个长度至少为 2 的字符串 并删除其 最右位置上 的字符。\n如果存在某种方法能够使这三个字符串相等,请返回使它们相等所需的 最小 操作次数;否则,返回 -1。\n\n示例 1:\n\n输入:s1 = \"abc\",s2 = \"abb\",s3 = \"ab\"\n输出:2\n解释:对 s1 和 s2 进行一次操作后,可以得到三个相等的字符串。\n可以证明,不可能用少于两次操作使它们相等。\n示例 2:\n\n输入:s1 = \"dac\",s2 = \"bac\",s3 = \"cac\"\n输出:-1\n解释:因为 s1 和 s2 的最左位置上的字母不相等,所以无论进行多少次操作,它们都不可能相等。因此答案是 -1 。\n\n提示:\n\n1 <= s1.length, s2.length, s3.length <= 100\ns1、s2 和 s3 仅由小写英文字母组成。\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def findMinimumOperations(self, s1: str, s2: str, s3: str) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"s1\": \"abc\", \"s2\": \"abb\", \"s3\": \"ab\" }\nassert my_solution.findMinimumOperations(**test_input) == 2\n\ntest_input = { \"s1\": \"dac\", \"s2\": \"bac\", \"s3\": \"cac\" }\nassert my_solution.findMinimumOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"a\", \"s2\": \"a\", \"s3\": \"a\" }\nassert my_solution.findMinimumOperations(**test_input) == 0\n\ntest_input = { \"s1\": \"kui\", \"s2\": \"m\", \"s3\": \"v\" }\nassert my_solution.findMinimumOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"a\", \"s2\": \"aabc\", \"s3\": \"a\" }\nassert my_solution.findMinimumOperations(**test_input) == 3\n\ntest_input = { \"s1\": \"cc\", \"s2\": \"cccb\", \"s3\": \"c\" }\nassert my_solution.findMinimumOperations(**test_input) == 4\n\ntest_input = { \"s1\": \"luso\", \"s2\": \"lu\", \"s3\": \"lu\" }\nassert my_solution.findMinimumOperations(**test_input) == 2\n\ntest_input = { \"s1\": \"xx\", \"s2\": \"phe\", \"s3\": \"xie\" }\nassert my_solution.findMinimumOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"gzd\", \"s2\": \"bcju\", \"s3\": \"db\" }\nassert my_solution.findMinimumOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"cbba\", \"s2\": \"cbaa\", \"s3\": \"c\" }\nassert my_solution.findMinimumOperations(**test_input) == 6\n\ntest_input = { \"s1\": \"k\", \"s2\": \"kfb\", \"s3\": \"krcnf\" }\nassert my_solution.findMinimumOperations(**test_input) == 6\n\ntest_input = { \"s1\": \"oby\", \"s2\": \"obz\", \"s3\": \"obf\" }\nassert my_solution.findMinimumOperations(**test_input) == 3\n\ntest_input = { \"s1\": \"b\", \"s2\": \"aba\", \"s3\": \"aaccaa\" }\nassert my_solution.findMinimumOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"a\", \"s2\": \"accabb\", \"s3\": \"aaa\" }\nassert my_solution.findMinimumOperations(**test_input) == 7\n\ntest_input = { \"s1\": \"b\", \"s2\": \"bccaaba\", \"s3\": \"ba\" }\nassert my_solution.findMinimumOperations(**test_input) == 7\n\ntest_input = { \"s1\": \"b\", \"s2\": \"bacccab\", \"s3\": \"cc\" }\nassert my_solution.findMinimumOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"ca\", \"s2\": \"cccabb\", \"s3\": \"cb\" }\nassert my_solution.findMinimumOperations(**test_input) == 7\n\ntest_input = { \"s1\": \"ccb\", \"s2\": \"ccba\", \"s3\": \"ccb\" }\nassert my_solution.findMinimumOperations(**test_input) == 1\n\ntest_input = { \"s1\": \"mbooi\", \"s2\": \"pdq\", \"s3\": \"br\" }\nassert my_solution.findMinimumOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"xxfzj\", \"s2\": \"faho\", \"s3\": \"c\" }\nassert my_solution.findMinimumOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"acbc\", \"s2\": \"acba\", \"s3\": \"acb\" }\nassert my_solution.findMinimumOperations(**test_input) == 2\n\ntest_input = { \"s1\": \"aduyyk\", \"s2\": \"v\", \"s3\": \"lpyt\" }\nassert my_solution.findMinimumOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"xd\", \"s2\": \"sl\", \"s3\": \"azoeaje\" }\nassert my_solution.findMinimumOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"bbbaa\", \"s2\": \"bacab\", \"s3\": \"b\" }\nassert my_solution.findMinimumOperations(**test_input) == 8\n\ntest_input = { \"s1\": \"cibn\", \"s2\": \"ioom\", \"s3\": \"bxa\" }\nassert my_solution.findMinimumOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"bcb\", \"s2\": \"bbac\", \"s3\": \"cbbc\" }\nassert my_solution.findMinimumOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"aabbb\", \"s2\": \"cc\", \"s3\": \"cccb\" }\nassert my_solution.findMinimumOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"i\", \"s2\": \"xqsfy\", \"s3\": \"diqae\" }\nassert my_solution.findMinimumOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"iq\", \"s2\": \"iimanmy\", \"s3\": \"id\" }\nassert my_solution.findMinimumOperations(**test_input) == 8\n\ntest_input = { \"s1\": \"pitggt\", \"s2\": \"pi\", \"s3\": \"pih\" }\nassert my_solution.findMinimumOperations(**test_input) == 5\n\ntest_input = { \"s1\": \"ten\", \"s2\": \"ten\", \"s3\": \"tenob\" }\nassert my_solution.findMinimumOperations(**test_input) == 2\n\ntest_input = { \"s1\": \"vejy\", \"s2\": \"fbqfo\", \"s3\": \"gl\" }\nassert my_solution.findMinimumOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"aca\", \"s2\": \"abcc\", \"s3\": \"accba\" }\nassert my_solution.findMinimumOperations(**test_input) == 9\n\ntest_input = { \"s1\": \"br\", \"s2\": \"br\", \"s3\": \"brvhgtou\" }\nassert my_solution.findMinimumOperations(**test_input) == 6\n\ntest_input = { \"s1\": \"c\", \"s2\": \"bcc\", \"s3\": \"aacbcaca\" }\nassert my_solution.findMinimumOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"cab\", \"s2\": \"caac\", \"s3\": \"cacbb\" }\nassert my_solution.findMinimumOperations(**test_input) == 6\n\ntest_input = { \"s1\": \"ccab\", \"s2\": \"cbbcbb\", \"s3\": \"ca\" }\nassert my_solution.findMinimumOperations(**test_input) == 9\n\ntest_input = { \"s1\": \"inuc\", \"s2\": \"iwpdfj\", \"s3\": \"ib\" }\nassert my_solution.findMinimumOperations(**test_input) == 9\n\ntest_input = { \"s1\": \"jrrpyyc\", \"s2\": \"jr\", \"s3\": \"jrt\" }\nassert my_solution.findMinimumOperations(**test_input) == 6\n\ntest_input = { \"s1\": \"l\", \"s2\": \"gebqrgnz\", \"s3\": \"jkr\" }\nassert my_solution.findMinimumOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"naynn\", \"s2\": \"ax\", \"s3\": \"bhdcz\" }\nassert my_solution.findMinimumOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"rexmx\", \"s2\": \"ujmbg\", \"s3\": \"gg\" }\nassert my_solution.findMinimumOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"aacbcb\", \"s2\": \"a\", \"s3\": \"acaaac\" }\nassert my_solution.findMinimumOperations(**test_input) == 10\n\ntest_input = { \"s1\": \"acbb\", \"s2\": \"acbacc\", \"s3\": \"acb\" }\nassert my_solution.findMinimumOperations(**test_input) == 4\n\ntest_input = { \"s1\": \"baacbab\", \"s2\": \"bcc\", \"s3\": \"bca\" }\nassert my_solution.findMinimumOperations(**test_input) == 10\n\ntest_input = { \"s1\": \"bcacbba\", \"s2\": \"bca\", \"s3\": \"bca\" }\nassert my_solution.findMinimumOperations(**test_input) == 4\n\ntest_input = { \"s1\": \"bcaca\", \"s2\": \"bcaba\", \"s3\": \"bca\" }\nassert my_solution.findMinimumOperations(**test_input) == 4\n\ntest_input = { \"s1\": \"ba\", \"s2\": \"bcbcab\", \"s3\": \"bbcbb\" }\nassert my_solution.findMinimumOperations(**test_input) == 10\n\ntest_input = { \"s1\": \"cabc\", \"s2\": \"cab\", \"s3\": \"cabbac\" }\nassert my_solution.findMinimumOperations(**test_input) == 4\n\ntest_input = { \"s1\": \"bbbbcaac\", \"s2\": \"a\", \"s3\": \"cbcc\" }\nassert my_solution.findMinimumOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"gjbtodtym\", \"s2\": \"gxp\", \"s3\": \"g\" }\nassert my_solution.findMinimumOperations(**test_input) == 10\n\ntest_input = { \"s1\": \"hfkq\", \"s2\": \"hfrbvno\", \"s3\": \"hf\" }\nassert my_solution.findMinimumOperations(**test_input) == 7\n\ntest_input = { \"s1\": \"hym\", \"s2\": \"hl\", \"s3\": \"hshxmbbj\" }\nassert my_solution.findMinimumOperations(**test_input) == 10\n\ntest_input = { \"s1\": \"mkdflu\", \"s2\": \"mmbn\", \"s3\": \"mge\" }\nassert my_solution.findMinimumOperations(**test_input) == 10\n\ntest_input = { \"s1\": \"nvlobl\", \"s2\": \"mekbzd\", \"s3\": \"s\" }\nassert my_solution.findMinimumOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"rpa\", \"s2\": \"rpaxpoh\", \"s3\": \"rpa\" }\nassert my_solution.findMinimumOperations(**test_input) == 4\n\ntest_input = { \"s1\": \"ac\", \"s2\": \"aacccccbc\", \"s3\": \"acc\" }\nassert my_solution.findMinimumOperations(**test_input) == 11\n\ntest_input = { \"s1\": \"abb\", \"s2\": \"abaac\", \"s3\": \"abcaca\" }\nassert my_solution.findMinimumOperations(**test_input) == 8\n\ntest_input = { \"s1\": \"caa\", \"s2\": \"caccaccacb\", \"s3\": \"c\" }\nassert my_solution.findMinimumOperations(**test_input) == 11\n\ntest_input = { \"s1\": \"baccaab\", \"s2\": \"cababc\", \"s3\": \"a\" }\nassert my_solution.findMinimumOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"cacbb\", \"s2\": \"ca\", \"s3\": \"cacbcac\" }\nassert my_solution.findMinimumOperations(**test_input) == 8\n\ntest_input = { \"s1\": \"cbba\", \"s2\": \"cabcabab\", \"s3\": \"ca\" }\nassert my_solution.findMinimumOperations(**test_input) == 11\n\ntest_input = { \"s1\": \"cb\", \"s2\": \"cbcbb\", \"s3\": \"cbaaabb\" }\nassert my_solution.findMinimumOperations(**test_input) == 8\n\ntest_input = { \"s1\": \"ccabaa\", \"s2\": \"ccabc\", \"s3\": \"cca\" }\nassert my_solution.findMinimumOperations(**test_input) == 5\n\ntest_input = { \"s1\": \"ccb\", \"s2\": \"ccac\", \"s3\": \"cccaaca\" }\nassert my_solution.findMinimumOperations(**test_input) == 8\n\ntest_input = { \"s1\": \"ccccbb\", \"s2\": \"cccc\", \"s3\": \"cccc\" }\nassert my_solution.findMinimumOperations(**test_input) == 2\n\ntest_input = { \"s1\": \"cxxq\", \"s2\": \"cxx\", \"s3\": \"cxxdeqh\" }\nassert my_solution.findMinimumOperations(**test_input) == 5\n\ntest_input = { \"s1\": \"d\", \"s2\": \"dffjiulzya\", \"s3\": \"dke\" }\nassert my_solution.findMinimumOperations(**test_input) == 11\n\ntest_input = { \"s1\": \"dogv\", \"s2\": \"dofjkhx\", \"s3\": \"dog\" }\nassert my_solution.findMinimumOperations(**test_input) == 8\n\ntest_input = { \"s1\": \"dwefrocz\", \"s2\": \"dzz\", \"s3\": \"dwn\" }\nassert my_solution.findMinimumOperations(**test_input) == 11\n\ntest_input = { \"s1\": \"etr\", \"s2\": \"ejb\", \"s3\": \"etpubpvr\" }\nassert my_solution.findMinimumOperations(**test_input) == 11\n\ntest_input = { \"s1\": \"f\", \"s2\": \"morycy\", \"s3\": \"vledqoo\" }\nassert my_solution.findMinimumOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"ful\", \"s2\": \"fular\", \"s3\": \"fulvkv\" }\nassert my_solution.findMinimumOperations(**test_input) == 5\n\ntest_input = { \"s1\": \"kzwat\", \"s2\": \"ku\", \"s3\": \"koftvbd\" }\nassert my_solution.findMinimumOperations(**test_input) == 11\n\ntest_input = { \"s1\": \"qey\", \"s2\": \"qevtkbss\", \"s3\": \"qeb\" }\nassert my_solution.findMinimumOperations(**test_input) == 8\n\ntest_input = { \"s1\": \"saqy\", \"s2\": \"hvufcpko\", \"s3\": \"xm\" }\nassert my_solution.findMinimumOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"tllwgcdi\", \"s2\": \"t\", \"s3\": \"tvham\" }\nassert my_solution.findMinimumOperations(**test_input) == 11\n\ntest_input = { \"s1\": \"vmwdmadn\", \"s2\": \"vmw\", \"s3\": \"vmw\" }\nassert my_solution.findMinimumOperations(**test_input) == 5\n\ntest_input = { \"s1\": \"xobwwhu\", \"s2\": \"xobb\", \"s3\": \"xob\" }\nassert my_solution.findMinimumOperations(**test_input) == 5\n\ntest_input = { \"s1\": \"yptajimiz\", \"s2\": \"yp\", \"s3\": \"ypr\" }\nassert my_solution.findMinimumOperations(**test_input) == 8\n\ntest_input = { \"s1\": \"z\", \"s2\": \"zcrouxlukb\", \"s3\": \"zbb\" }\nassert my_solution.findMinimumOperations(**test_input) == 11\n\ntest_input = { \"s1\": \"aaabc\", \"s2\": \"aaaa\", \"s3\": \"aaaabc\" }\nassert my_solution.findMinimumOperations(**test_input) == 6\n\ntest_input = { \"s1\": \"aaa\", \"s2\": \"aab\", \"s3\": \"aabaacaab\" }\nassert my_solution.findMinimumOperations(**test_input) == 9\n\ntest_input = { \"s1\": \"aac\", \"s2\": \"aac\", \"s3\": \"aacabbbca\" }\nassert my_solution.findMinimumOperations(**test_input) == 6\n\ntest_input = { \"s1\": \"abaab\", \"s2\": \"abaabb\", \"s3\": \"abaa\" }\nassert my_solution.findMinimumOperations(**test_input) == 3\n\ntest_input = { \"s1\": \"abcomon\", \"s2\": \"gkuneup\", \"s3\": \"q\" }\nassert my_solution.findMinimumOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"acc\", \"s2\": \"accacb\", \"s3\": \"acbabc\" }\nassert my_solution.findMinimumOperations(**test_input) == 9\n\ntest_input = { \"s1\": \"cca\", \"s2\": \"caaab\", \"s3\": \"babbacc\" }\nassert my_solution.findMinimumOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"bccbc\", \"s2\": \"bc\", \"s3\": \"bcccbcac\" }\nassert my_solution.findMinimumOperations(**test_input) == 9\n\ntest_input = { \"s1\": \"bpp\", \"s2\": \"bin\", \"s3\": \"bfkbyhubw\" }\nassert my_solution.findMinimumOperations(**test_input) == 12\n\ntest_input = { \"s1\": \"bbsyg\", \"s2\": \"blbp\", \"s3\": \"brghkr\" }\nassert my_solution.findMinimumOperations(**test_input) == 12\n\ntest_input = { \"s1\": \"bxpvamp\", \"s2\": \"bxpv\", \"s3\": \"bxpv\" }\nassert my_solution.findMinimumOperations(**test_input) == 3\n\ntest_input = { \"s1\": \"ccbabca\", \"s2\": \"cbcbaca\", \"s3\": \"c\" }\nassert my_solution.findMinimumOperations(**test_input) == 12\n\ntest_input = { \"s1\": \"accb\", \"s2\": \"bbc\", \"s3\": \"cbbaccba\" }\nassert my_solution.findMinimumOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"cbccc\", \"s2\": \"cbc\", \"s3\": \"cbcccba\" }\nassert my_solution.findMinimumOperations(**test_input) == 6\n\ntest_input = { \"s1\": \"cac\", \"s2\": \"ccacc\", \"s3\": \"cabacba\" }\nassert my_solution.findMinimumOperations(**test_input) == 12\n\ntest_input = { \"s1\": \"ccb\", \"s2\": \"ccbcb\", \"s3\": \"ccbccab\" }\nassert my_solution.findMinimumOperations(**test_input) == 6\n\ntest_input = { \"s1\": \"caacabcbc\", \"s2\": \"ccb\", \"s3\": \"ccc\" }\nassert my_solution.findMinimumOperations(**test_input) == 12\n\ntest_input = { \"s1\": \"cccabaacc\", \"s2\": \"ccc\", \"s3\": \"ccc\" }\nassert my_solution.findMinimumOperations(**test_input) == 6\n\ntest_input = { \"s1\": \"ajjdre\", \"s2\": \"gsrq\", \"s3\": \"eurcj\" }\nassert my_solution.findMinimumOperations(**test_input) == -1", "start_time": 1700361000} +{"task_id": "weekly-contest-372-separate-black-and-white-balls", "url": "https://leetcode.com/problems/separate-black-and-white-balls", "title": "separate-black-and-white-balls", "meta": {"questionId": "3195", "questionFrontendId": "2938", "title": "Separate Black and White Balls", "titleSlug": "separate-black-and-white-balls", "isPaidOnly": false, "difficulty": "Medium", "likes": 133, "dislikes": 3, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n桌子上有 n 个球,每个球的颜色不是黑色,就是白色。\n给你一个长度为 n 、下标从 0 开始的二进制字符串 s,其中 1 和 0 分别代表黑色和白色的球。\n在每一步中,你可以选择两个相邻的球并交换它们。\n返回「将所有黑色球都移到右侧,所有白色球都移到左侧所需的 最小步数」。\n\n示例 1:\n\n输入:s = \"101\"\n输出:1\n解释:我们可以按以下方式将所有黑色球移到右侧:\n- 交换 s[0] 和 s[1],s = \"011\"。\n最开始,1 没有都在右侧,需要至少 1 步将其移到右侧。\n示例 2:\n\n输入:s = \"100\"\n输出:2\n解释:我们可以按以下方式将所有黑色球移到右侧:\n- 交换 s[0] 和 s[1],s = \"010\"。\n- 交换 s[1] 和 s[2],s = \"001\"。\n可以证明所需的最小步数为 2 。\n\n示例 3:\n\n输入:s = \"0111\"\n输出:0\n解释:所有黑色球都已经在右侧。\n\n\n提示:\n\n1 <= n == s.length <= 105\ns[i] 不是 '0',就是 '1'。\n\"\"\"\nclass Solution:\n def minimumSteps(self, s: str) -> int:\n ", "prompt_sft": "桌子上有 n 个球,每个球的颜色不是黑色,就是白色。\n给你一个长度为 n 、下标从 0 开始的二进制字符串 s,其中 1 和 0 分别代表黑色和白色的球。\n在每一步中,你可以选择两个相邻的球并交换它们。\n返回「将所有黑色球都移到右侧,所有白色球都移到左侧所需的 最小步数」。\n\n示例 1:\n\n输入:s = \"101\"\n输出:1\n解释:我们可以按以下方式将所有黑色球移到右侧:\n- 交换 s[0] 和 s[1],s = \"011\"。\n最开始,1 没有都在右侧,需要至少 1 步将其移到右侧。\n示例 2:\n\n输入:s = \"100\"\n输出:2\n解释:我们可以按以下方式将所有黑色球移到右侧:\n- 交换 s[0] 和 s[1],s = \"010\"。\n- 交换 s[1] 和 s[2],s = \"001\"。\n可以证明所需的最小步数为 2 。\n\n示例 3:\n\n输入:s = \"0111\"\n输出:0\n解释:所有黑色球都已经在右侧。\n\n\n提示:\n\n1 <= n == s.length <= 105\ns[i] 不是 '0',就是 '1'。\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def minimumSteps(self, s: str) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"s\": \"101\" }\nassert my_solution.minimumSteps(**test_input) == 1\n\ntest_input = { \"s\": \"100\" }\nassert my_solution.minimumSteps(**test_input) == 2\n\ntest_input = { \"s\": \"0111\" }\nassert my_solution.minimumSteps(**test_input) == 0\n\ntest_input = { \"s\": \"11000111\" }\nassert my_solution.minimumSteps(**test_input) == 6\n\ntest_input = { \"s\": \"01010001\" }\nassert my_solution.minimumSteps(**test_input) == 7\n\ntest_input = { \"s\": \"0100101\" }\nassert my_solution.minimumSteps(**test_input) == 4\n\ntest_input = { \"s\": \"111111111100100010\" }\nassert my_solution.minimumSteps(**test_input) == 65\n\ntest_input = { \"s\": \"10100000110010011010\" }\nassert my_solution.minimumSteps(**test_input) == 44\n\ntest_input = { \"s\": \"1101110000111011110\" }\nassert my_solution.minimumSteps(**test_input) == 42\n\ntest_input = { \"s\": \"01000010111010001\" }\nassert my_solution.minimumSteps(**test_input) == 29\n\ntest_input = { \"s\": \"11110\" }\nassert my_solution.minimumSteps(**test_input) == 4\n\ntest_input = { \"s\": \"010001001011010\" }\nassert my_solution.minimumSteps(**test_input) == 21\n\ntest_input = { \"s\": \"0011011\" }\nassert my_solution.minimumSteps(**test_input) == 2\n\ntest_input = { \"s\": \"001\" }\nassert my_solution.minimumSteps(**test_input) == 0\n\ntest_input = { \"s\": \"000100100\" }\nassert my_solution.minimumSteps(**test_input) == 6\n\ntest_input = { \"s\": \"00110\" }\nassert my_solution.minimumSteps(**test_input) == 2\n\ntest_input = { \"s\": \"001110001110001\" }\nassert my_solution.minimumSteps(**test_input) == 27\n\ntest_input = { \"s\": \"10000000001\" }\nassert my_solution.minimumSteps(**test_input) == 9\n\ntest_input = { \"s\": \"01\" }\nassert my_solution.minimumSteps(**test_input) == 0\n\ntest_input = { \"s\": \"0100011100001100100\" }\nassert my_solution.minimumSteps(**test_input) == 45\n\ntest_input = { \"s\": \"1010110\" }\nassert my_solution.minimumSteps(**test_input) == 7\n\ntest_input = { \"s\": \"010010000\" }\nassert my_solution.minimumSteps(**test_input) == 10\n\ntest_input = { \"s\": \"100110\" }\nassert my_solution.minimumSteps(**test_input) == 5\n\ntest_input = { \"s\": \"1100\" }\nassert my_solution.minimumSteps(**test_input) == 4\n\ntest_input = { \"s\": \"000110\" }\nassert my_solution.minimumSteps(**test_input) == 2\n\ntest_input = { \"s\": \"001101101111000000\" }\nassert my_solution.minimumSteps(**test_input) == 54\n\ntest_input = { \"s\": \"011101011\" }\nassert my_solution.minimumSteps(**test_input) == 7\n\ntest_input = { \"s\": \"0110111111110\" }\nassert my_solution.minimumSteps(**test_input) == 12\n\ntest_input = { \"s\": \"1111001111111011111\" }\nassert my_solution.minimumSteps(**test_input) == 19\n\ntest_input = { \"s\": \"0101111\" }\nassert my_solution.minimumSteps(**test_input) == 1\n\ntest_input = { \"s\": \"00010101100110011\" }\nassert my_solution.minimumSteps(**test_input) == 23\n\ntest_input = { \"s\": \"01010110110111011001\" }\nassert my_solution.minimumSteps(**test_input) == 44\n\ntest_input = { \"s\": \"0\" }\nassert my_solution.minimumSteps(**test_input) == 0\n\ntest_input = { \"s\": \"1101111010111001010\" }\nassert my_solution.minimumSteps(**test_input) == 58\n\ntest_input = { \"s\": \"01100010\" }\nassert my_solution.minimumSteps(**test_input) == 9\n\ntest_input = { \"s\": \"10010000010\" }\nassert my_solution.minimumSteps(**test_input) == 15\n\ntest_input = { \"s\": \"11011101000100001\" }\nassert my_solution.minimumSteps(**test_input) == 53\n\ntest_input = { \"s\": \"00\" }\nassert my_solution.minimumSteps(**test_input) == 0\n\ntest_input = { \"s\": \"10100101011001100111\" }\nassert my_solution.minimumSteps(**test_input) == 40\n\ntest_input = { \"s\": \"0101\" }\nassert my_solution.minimumSteps(**test_input) == 1\n\ntest_input = { \"s\": \"00101010100\" }\nassert my_solution.minimumSteps(**test_input) == 14\n\ntest_input = { \"s\": \"00110111110010\" }\nassert my_solution.minimumSteps(**test_input) == 24\n\ntest_input = { \"s\": \"111010000001000001\" }\nassert my_solution.minimumSteps(**test_input) == 52\n\ntest_input = { \"s\": \"0101101000111010\" }\nassert my_solution.minimumSteps(**test_input) == 31\n\ntest_input = { \"s\": \"1010111111\" }\nassert my_solution.minimumSteps(**test_input) == 3\n\ntest_input = { \"s\": \"110110001001110\" }\nassert my_solution.minimumSteps(**test_input) == 32\n\ntest_input = { \"s\": \"111010\" }\nassert my_solution.minimumSteps(**test_input) == 7\n\ntest_input = { \"s\": \"10\" }\nassert my_solution.minimumSteps(**test_input) == 1\n\ntest_input = { \"s\": \"111110\" }\nassert my_solution.minimumSteps(**test_input) == 5\n\ntest_input = { \"s\": \"0111100000101101110\" }\nassert my_solution.minimumSteps(**test_input) == 42\n\ntest_input = { \"s\": \"111010100\" }\nassert my_solution.minimumSteps(**test_input) == 17\n\ntest_input = { \"s\": \"0001000100111000\" }\nassert my_solution.minimumSteps(**test_input) == 22\n\ntest_input = { \"s\": \"011001111110110010\" }\nassert my_solution.minimumSteps(**test_input) == 43\n\ntest_input = { \"s\": \"11100\" }\nassert my_solution.minimumSteps(**test_input) == 6\n\ntest_input = { \"s\": \"0100001101110001\" }\nassert my_solution.minimumSteps(**test_input) == 25\n\ntest_input = { \"s\": \"111\" }\nassert my_solution.minimumSteps(**test_input) == 0\n\ntest_input = { \"s\": \"100010\" }\nassert my_solution.minimumSteps(**test_input) == 5\n\ntest_input = { \"s\": \"101001\" }\nassert my_solution.minimumSteps(**test_input) == 5\n\ntest_input = { \"s\": \"00111010100100100111\" }\nassert my_solution.minimumSteps(**test_input) == 43\n\ntest_input = { \"s\": \"100010111\" }\nassert my_solution.minimumSteps(**test_input) == 5\n\ntest_input = { \"s\": \"001110000101011\" }\nassert my_solution.minimumSteps(**test_input) == 21\n\ntest_input = { \"s\": \"111011011101101\" }\nassert my_solution.minimumSteps(**test_input) == 26\n\ntest_input = { \"s\": \"1110101\" }\nassert my_solution.minimumSteps(**test_input) == 7\n\ntest_input = { \"s\": \"00111010100111\" }\nassert my_solution.minimumSteps(**test_input) == 17\n\ntest_input = { \"s\": \"010\" }\nassert my_solution.minimumSteps(**test_input) == 1\n\ntest_input = { \"s\": \"111001\" }\nassert my_solution.minimumSteps(**test_input) == 6\n\ntest_input = { \"s\": \"1100011\" }\nassert my_solution.minimumSteps(**test_input) == 6\n\ntest_input = { \"s\": \"0110001011001110111\" }\nassert my_solution.minimumSteps(**test_input) == 27\n\ntest_input = { \"s\": \"0001111111011101\" }\nassert my_solution.minimumSteps(**test_input) == 17\n\ntest_input = { \"s\": \"0110110100001\" }\nassert my_solution.minimumSteps(**test_input) == 26\n\ntest_input = { \"s\": \"11110110011000011\" }\nassert my_solution.minimumSteps(**test_input) == 48\n\ntest_input = { \"s\": \"10100\" }\nassert my_solution.minimumSteps(**test_input) == 5\n\ntest_input = { \"s\": \"10100001\" }\nassert my_solution.minimumSteps(**test_input) == 9\n\ntest_input = { \"s\": \"01000011000\" }\nassert my_solution.minimumSteps(**test_input) == 13\n\ntest_input = { \"s\": \"110001001001\" }\nassert my_solution.minimumSteps(**test_input) == 20\n\ntest_input = { \"s\": \"01100011010011110\" }\nassert my_solution.minimumSteps(**test_input) == 29\n\ntest_input = { \"s\": \"01111001111\" }\nassert my_solution.minimumSteps(**test_input) == 8\n\ntest_input = { \"s\": \"1110100010000110110\" }\nassert my_solution.minimumSteps(**test_input) == 51\n\ntest_input = { \"s\": \"1101000111001111100\" }\nassert my_solution.minimumSteps(**test_input) == 45\n\ntest_input = { \"s\": \"0110000\" }\nassert my_solution.minimumSteps(**test_input) == 8\n\ntest_input = { \"s\": \"001010010010\" }\nassert my_solution.minimumSteps(**test_input) == 15\n\ntest_input = { \"s\": \"11101\" }\nassert my_solution.minimumSteps(**test_input) == 3\n\ntest_input = { \"s\": \"00110110\" }\nassert my_solution.minimumSteps(**test_input) == 6\n\ntest_input = { \"s\": \"001010\" }\nassert my_solution.minimumSteps(**test_input) == 3\n\ntest_input = { \"s\": \"000101010101010\" }\nassert my_solution.minimumSteps(**test_input) == 21\n\ntest_input = { \"s\": \"1111011\" }\nassert my_solution.minimumSteps(**test_input) == 4\n\ntest_input = { \"s\": \"0000101011001101011\" }\nassert my_solution.minimumSteps(**test_input) == 24\n\ntest_input = { \"s\": \"011010\" }\nassert my_solution.minimumSteps(**test_input) == 5\n\ntest_input = { \"s\": \"110010100011110101\" }\nassert my_solution.minimumSteps(**test_input) == 36\n\ntest_input = { \"s\": \"000000001\" }\nassert my_solution.minimumSteps(**test_input) == 0\n\ntest_input = { \"s\": \"011001\" }\nassert my_solution.minimumSteps(**test_input) == 4\n\ntest_input = { \"s\": \"01111010011110111111\" }\nassert my_solution.minimumSteps(**test_input) == 23\n\ntest_input = { \"s\": \"10001111\" }\nassert my_solution.minimumSteps(**test_input) == 3\n\ntest_input = { \"s\": \"11011010001111\" }\nassert my_solution.minimumSteps(**test_input) == 21\n\ntest_input = { \"s\": \"0110101010100000111\" }\nassert my_solution.minimumSteps(**test_input) == 44\n\ntest_input = { \"s\": \"0000001000110\" }\nassert my_solution.minimumSteps(**test_input) == 6\n\ntest_input = { \"s\": \"1\" }\nassert my_solution.minimumSteps(**test_input) == 0\n\ntest_input = { \"s\": \"0111100110100\" }\nassert my_solution.minimumSteps(**test_input) == 28\n\ntest_input = { \"s\": \"101010110011101011\" }\nassert my_solution.minimumSteps(**test_input) == 33\n\ntest_input = { \"s\": \"1011101\" }\nassert my_solution.minimumSteps(**test_input) == 5", "start_time": 1700361000} +{"task_id": "weekly-contest-372-maximum-xor-product", "url": "https://leetcode.com/problems/maximum-xor-product", "title": "maximum-xor-product", "meta": {"questionId": "3192", "questionFrontendId": "2939", "title": "Maximum Xor Product", "titleSlug": "maximum-xor-product", "isPaidOnly": false, "difficulty": "Medium", "likes": 140, "dislikes": 63, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你三个整数a,b和n,请你返回(a XOR x) * (b XOR x)的最大值且 x需要满足 0 <= x < 2n。\n由于答案可能会很大,返回它对109 + 7取余后的结果。\n注意,XOR是按位异或操作。\n\n示例 1:\n\n输入:a = 12, b = 5, n = 4\n输出:98\n解释:当 x = 2 时,(a XOR x) = 14 且 (b XOR x) = 7 。所以,(a XOR x) * (b XOR x) = 98 。\n98 是所有满足 0 <= x < 2n 中 (a XOR x) * (b XOR x) 的最大值。\n\n示例 2:\n\n输入:a = 6, b = 7 , n = 5\n输出:930\n解释:当 x = 25 时,(a XOR x) = 31 且 (b XOR x) = 30 。所以,(a XOR x) * (b XOR x) = 930 。\n930 是所有满足 0 <= x < 2n 中 (a XOR x) * (b XOR x) 的最大值。\n示例 3:\n\n输入:a = 1, b = 6, n = 3\n输出:12\n解释: 当 x = 5 时,(a XOR x) = 4 且 (b XOR x) = 3 。所以,(a XOR x) * (b XOR x) = 12 。\n12 是所有满足 0 <= x < 2n 中 (a XOR x) * (b XOR x) 的最大值。\n\n\n提示:\n\n0 <= a, b < 250\n0 <= n <= 50\n\"\"\"\nclass Solution:\n def maximumXorProduct(self, a: int, b: int, n: int) -> int:\n ", "prompt_sft": "给你三个整数a,b和n,请你返回(a XOR x) * (b XOR x)的最大值且 x需要满足 0 <= x < 2n。\n由于答案可能会很大,返回它对109 + 7取余后的结果。\n注意,XOR是按位异或操作。\n\n示例 1:\n\n输入:a = 12, b = 5, n = 4\n输出:98\n解释:当 x = 2 时,(a XOR x) = 14 且 (b XOR x) = 7 。所以,(a XOR x) * (b XOR x) = 98 。\n98 是所有满足 0 <= x < 2n 中 (a XOR x) * (b XOR x) 的最大值。\n\n示例 2:\n\n输入:a = 6, b = 7 , n = 5\n输出:930\n解释:当 x = 25 时,(a XOR x) = 31 且 (b XOR x) = 30 。所以,(a XOR x) * (b XOR x) = 930 。\n930 是所有满足 0 <= x < 2n 中 (a XOR x) * (b XOR x) 的最大值。\n示例 3:\n\n输入:a = 1, b = 6, n = 3\n输出:12\n解释: 当 x = 5 时,(a XOR x) = 4 且 (b XOR x) = 3 。所以,(a XOR x) * (b XOR x) = 12 。\n12 是所有满足 0 <= x < 2n 中 (a XOR x) * (b XOR x) 的最大值。\n\n\n提示:\n\n0 <= a, b < 250\n0 <= n <= 50\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def maximumXorProduct(self, a: int, b: int, n: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"a\": 12, \"b\": 5, \"n\": 4 }\nassert my_solution.maximumXorProduct(**test_input) == 98\n\ntest_input = { \"a\": 6, \"b\": 7, \"n\": 5 }\nassert my_solution.maximumXorProduct(**test_input) == 930\n\ntest_input = { \"a\": 1, \"b\": 6, \"n\": 3 }\nassert my_solution.maximumXorProduct(**test_input) == 12\n\ntest_input = { \"a\": 0, \"b\": 0, \"n\": 1 }\nassert my_solution.maximumXorProduct(**test_input) == 1\n\ntest_input = { \"a\": 0, \"b\": 1, \"n\": 6 }\nassert my_solution.maximumXorProduct(**test_input) == 3906\n\ntest_input = { \"a\": 0, \"b\": 2, \"n\": 7 }\nassert my_solution.maximumXorProduct(**test_input) == 15875\n\ntest_input = { \"a\": 0, \"b\": 3, \"n\": 1 }\nassert my_solution.maximumXorProduct(**test_input) == 2\n\ntest_input = { \"a\": 0, \"b\": 4, \"n\": 0 }\nassert my_solution.maximumXorProduct(**test_input) == 0\n\ntest_input = { \"a\": 0, \"b\": 5, \"n\": 6 }\nassert my_solution.maximumXorProduct(**test_input) == 3658\n\ntest_input = { \"a\": 0, \"b\": 6, \"n\": 1 }\nassert my_solution.maximumXorProduct(**test_input) == 7\n\ntest_input = { \"a\": 0, \"b\": 7, \"n\": 2 }\nassert my_solution.maximumXorProduct(**test_input) == 12\n\ntest_input = { \"a\": 0, \"b\": 8, \"n\": 5 }\nassert my_solution.maximumXorProduct(**test_input) == 713\n\ntest_input = { \"a\": 0, \"b\": 9, \"n\": 2 }\nassert my_solution.maximumXorProduct(**test_input) == 30\n\ntest_input = { \"a\": 0, \"b\": 10, \"n\": 7 }\nassert my_solution.maximumXorProduct(**test_input) == 14875\n\ntest_input = { \"a\": 0, \"b\": 11, \"n\": 4 }\nassert my_solution.maximumXorProduct(**test_input) == 84\n\ntest_input = { \"a\": 0, \"b\": 12, \"n\": 2 }\nassert my_solution.maximumXorProduct(**test_input) == 45\n\ntest_input = { \"a\": 0, \"b\": 13, \"n\": 2 }\nassert my_solution.maximumXorProduct(**test_input) == 42\n\ntest_input = { \"a\": 0, \"b\": 14, \"n\": 0 }\nassert my_solution.maximumXorProduct(**test_input) == 0\n\ntest_input = { \"a\": 0, \"b\": 15, \"n\": 6 }\nassert my_solution.maximumXorProduct(**test_input) == 3080\n\ntest_input = { \"a\": 1, \"b\": 0, \"n\": 3 }\nassert my_solution.maximumXorProduct(**test_input) == 42\n\ntest_input = { \"a\": 1, \"b\": 1, \"n\": 4 }\nassert my_solution.maximumXorProduct(**test_input) == 225\n\ntest_input = { \"a\": 1, \"b\": 2, \"n\": 6 }\nassert my_solution.maximumXorProduct(**test_input) == 3782\n\ntest_input = { \"a\": 1, \"b\": 3, \"n\": 2 }\nassert my_solution.maximumXorProduct(**test_input) == 3\n\ntest_input = { \"a\": 1, \"b\": 4, \"n\": 5 }\nassert my_solution.maximumXorProduct(**test_input) == 810\n\ntest_input = { \"a\": 1, \"b\": 5, \"n\": 4 }\nassert my_solution.maximumXorProduct(**test_input) == 165\n\ntest_input = { \"a\": 1, \"b\": 6, \"n\": 4 }\nassert my_solution.maximumXorProduct(**test_input) == 132\n\ntest_input = { \"a\": 1, \"b\": 7, \"n\": 2 }\nassert my_solution.maximumXorProduct(**test_input) == 15\n\ntest_input = { \"a\": 1, \"b\": 8, \"n\": 0 }\nassert my_solution.maximumXorProduct(**test_input) == 8\n\ntest_input = { \"a\": 1, \"b\": 9, \"n\": 2 }\nassert my_solution.maximumXorProduct(**test_input) == 33\n\ntest_input = { \"a\": 1, \"b\": 10, \"n\": 7 }\nassert my_solution.maximumXorProduct(**test_input) == 14756\n\ntest_input = { \"a\": 1, \"b\": 11, \"n\": 7 }\nassert my_solution.maximumXorProduct(**test_input) == 14875\n\ntest_input = { \"a\": 1, \"b\": 12, \"n\": 7 }\nassert my_solution.maximumXorProduct(**test_input) == 14518\n\ntest_input = { \"a\": 1, \"b\": 13, \"n\": 0 }\nassert my_solution.maximumXorProduct(**test_input) == 13\n\ntest_input = { \"a\": 1, \"b\": 14, \"n\": 5 }\nassert my_solution.maximumXorProduct(**test_input) == 552\n\ntest_input = { \"a\": 1, \"b\": 15, \"n\": 4 }\nassert my_solution.maximumXorProduct(**test_input) == 63\n\ntest_input = { \"a\": 2, \"b\": 0, \"n\": 0 }\nassert my_solution.maximumXorProduct(**test_input) == 0\n\ntest_input = { \"a\": 2, \"b\": 1, \"n\": 0 }\nassert my_solution.maximumXorProduct(**test_input) == 2\n\ntest_input = { \"a\": 2, \"b\": 2, \"n\": 0 }\nassert my_solution.maximumXorProduct(**test_input) == 4\n\ntest_input = { \"a\": 2, \"b\": 3, \"n\": 5 }\nassert my_solution.maximumXorProduct(**test_input) == 930\n\ntest_input = { \"a\": 2, \"b\": 4, \"n\": 4 }\nassert my_solution.maximumXorProduct(**test_input) == 143\n\ntest_input = { \"a\": 2, \"b\": 5, \"n\": 5 }\nassert my_solution.maximumXorProduct(**test_input) == 756\n\ntest_input = { \"a\": 2, \"b\": 6, \"n\": 4 }\nassert my_solution.maximumXorProduct(**test_input) == 165\n\ntest_input = { \"a\": 2, \"b\": 7, \"n\": 3 }\nassert my_solution.maximumXorProduct(**test_input) == 18\n\ntest_input = { \"a\": 2, \"b\": 8, \"n\": 1 }\nassert my_solution.maximumXorProduct(**test_input) == 27\n\ntest_input = { \"a\": 2, \"b\": 9, \"n\": 2 }\nassert my_solution.maximumXorProduct(**test_input) == 24\n\ntest_input = { \"a\": 2, \"b\": 10, \"n\": 5 }\nassert my_solution.maximumXorProduct(**test_input) == 713\n\ntest_input = { \"a\": 2, \"b\": 11, \"n\": 0 }\nassert my_solution.maximumXorProduct(**test_input) == 22\n\ntest_input = { \"a\": 2, \"b\": 12, \"n\": 2 }\nassert my_solution.maximumXorProduct(**test_input) == 39\n\ntest_input = { \"a\": 2, \"b\": 13, \"n\": 1 }\nassert my_solution.maximumXorProduct(**test_input) == 36\n\ntest_input = { \"a\": 2, \"b\": 14, \"n\": 0 }\nassert my_solution.maximumXorProduct(**test_input) == 28\n\ntest_input = { \"a\": 2, \"b\": 15, \"n\": 2 }\nassert my_solution.maximumXorProduct(**test_input) == 42\n\ntest_input = { \"a\": 3, \"b\": 0, \"n\": 6 }\nassert my_solution.maximumXorProduct(**test_input) == 3782\n\ntest_input = { \"a\": 3, \"b\": 1, \"n\": 6 }\nassert my_solution.maximumXorProduct(**test_input) == 3843\n\ntest_input = { \"a\": 3, \"b\": 2, \"n\": 2 }\nassert my_solution.maximumXorProduct(**test_input) == 6\n\ntest_input = { \"a\": 3, \"b\": 3, \"n\": 7 }\nassert my_solution.maximumXorProduct(**test_input) == 16129\n\ntest_input = { \"a\": 3, \"b\": 4, \"n\": 5 }\nassert my_solution.maximumXorProduct(**test_input) == 756\n\ntest_input = { \"a\": 3, \"b\": 5, \"n\": 4 }\nassert my_solution.maximumXorProduct(**test_input) == 143\n\ntest_input = { \"a\": 3, \"b\": 6, \"n\": 2 }\nassert my_solution.maximumXorProduct(**test_input) == 18\n\ntest_input = { \"a\": 3, \"b\": 7, \"n\": 2 }\nassert my_solution.maximumXorProduct(**test_input) == 21\n\ntest_input = { \"a\": 3, \"b\": 8, \"n\": 6 }\nassert my_solution.maximumXorProduct(**test_input) == 3300\n\ntest_input = { \"a\": 3, \"b\": 9, \"n\": 1 }\nassert my_solution.maximumXorProduct(**test_input) == 27\n\ntest_input = { \"a\": 3, \"b\": 10, \"n\": 5 }\nassert my_solution.maximumXorProduct(**test_input) == 690\n\ntest_input = { \"a\": 3, \"b\": 11, \"n\": 1 }\nassert my_solution.maximumXorProduct(**test_input) == 33\n\ntest_input = { \"a\": 3, \"b\": 12, \"n\": 1 }\nassert my_solution.maximumXorProduct(**test_input) == 36\n\ntest_input = { \"a\": 3, \"b\": 13, \"n\": 2 }\nassert my_solution.maximumXorProduct(**test_input) == 39\n\ntest_input = { \"a\": 3, \"b\": 14, \"n\": 0 }\nassert my_solution.maximumXorProduct(**test_input) == 42\n\ntest_input = { \"a\": 3, \"b\": 15, \"n\": 6 }\nassert my_solution.maximumXorProduct(**test_input) == 3245\n\ntest_input = { \"a\": 4, \"b\": 0, \"n\": 4 }\nassert my_solution.maximumXorProduct(**test_input) == 165\n\ntest_input = { \"a\": 4, \"b\": 1, \"n\": 2 }\nassert my_solution.maximumXorProduct(**test_input) == 18\n\ntest_input = { \"a\": 4, \"b\": 2, \"n\": 2 }\nassert my_solution.maximumXorProduct(**test_input) == 15\n\ntest_input = { \"a\": 4, \"b\": 3, \"n\": 0 }\nassert my_solution.maximumXorProduct(**test_input) == 12\n\ntest_input = { \"a\": 4, \"b\": 4, \"n\": 3 }\nassert my_solution.maximumXorProduct(**test_input) == 49\n\ntest_input = { \"a\": 4, \"b\": 5, \"n\": 3 }\nassert my_solution.maximumXorProduct(**test_input) == 42\n\ntest_input = { \"a\": 4, \"b\": 6, \"n\": 2 }\nassert my_solution.maximumXorProduct(**test_input) == 35\n\ntest_input = { \"a\": 4, \"b\": 7, \"n\": 3 }\nassert my_solution.maximumXorProduct(**test_input) == 30\n\ntest_input = { \"a\": 4, \"b\": 8, \"n\": 4 }\nassert my_solution.maximumXorProduct(**test_input) == 77\n\ntest_input = { \"a\": 4, \"b\": 9, \"n\": 7 }\nassert my_solution.maximumXorProduct(**test_input) == 14518\n\ntest_input = { \"a\": 4, \"b\": 10, \"n\": 0 }\nassert my_solution.maximumXorProduct(**test_input) == 40\n\ntest_input = { \"a\": 4, \"b\": 11, \"n\": 5 }\nassert my_solution.maximumXorProduct(**test_input) == 552\n\ntest_input = { \"a\": 4, \"b\": 12, \"n\": 6 }\nassert my_solution.maximumXorProduct(**test_input) == 3465\n\ntest_input = { \"a\": 4, \"b\": 13, \"n\": 7 }\nassert my_solution.maximumXorProduct(**test_input) == 14994\n\ntest_input = { \"a\": 4, \"b\": 14, \"n\": 5 }\nassert my_solution.maximumXorProduct(**test_input) == 667\n\ntest_input = { \"a\": 4, \"b\": 15, \"n\": 6 }\nassert my_solution.maximumXorProduct(**test_input) == 3300\n\ntest_input = { \"a\": 5, \"b\": 0, \"n\": 1 }\nassert my_solution.maximumXorProduct(**test_input) == 4\n\ntest_input = { \"a\": 5, \"b\": 1, \"n\": 3 }\nassert my_solution.maximumXorProduct(**test_input) == 21\n\ntest_input = { \"a\": 5, \"b\": 2, \"n\": 2 }\nassert my_solution.maximumXorProduct(**test_input) == 12\n\ntest_input = { \"a\": 5, \"b\": 3, \"n\": 7 }\nassert my_solution.maximumXorProduct(**test_input) == 15375\n\ntest_input = { \"a\": 5, \"b\": 4, \"n\": 7 }\nassert my_solution.maximumXorProduct(**test_input) == 16002\n\ntest_input = { \"a\": 5, \"b\": 5, \"n\": 0 }\nassert my_solution.maximumXorProduct(**test_input) == 25\n\ntest_input = { \"a\": 5, \"b\": 6, \"n\": 1 }\nassert my_solution.maximumXorProduct(**test_input) == 30\n\ntest_input = { \"a\": 5, \"b\": 7, \"n\": 0 }\nassert my_solution.maximumXorProduct(**test_input) == 35\n\ntest_input = { \"a\": 5, \"b\": 8, \"n\": 2 }\nassert my_solution.maximumXorProduct(**test_input) == 70\n\ntest_input = { \"a\": 5, \"b\": 9, \"n\": 4 }\nassert my_solution.maximumXorProduct(**test_input) == 77\n\ntest_input = { \"a\": 5, \"b\": 10, \"n\": 5 }\nassert my_solution.maximumXorProduct(**test_input) == 552\n\ntest_input = { \"a\": 5, \"b\": 11, \"n\": 7 }\nassert my_solution.maximumXorProduct(**test_input) == 14399\n\ntest_input = { \"a\": 5, \"b\": 12, \"n\": 1 }\nassert my_solution.maximumXorProduct(**test_input) == 60\n\ntest_input = { \"a\": 5, \"b\": 13, \"n\": 5 }\nassert my_solution.maximumXorProduct(**test_input) == 713\n\ntest_input = { \"a\": 5, \"b\": 14, \"n\": 4 }\nassert my_solution.maximumXorProduct(**test_input) == 84\n\ntest_input = { \"a\": 5, \"b\": 15, \"n\": 0 }\nassert my_solution.maximumXorProduct(**test_input) == 75\n\ntest_input = { \"a\": 6, \"b\": 0, \"n\": 4 }\nassert my_solution.maximumXorProduct(**test_input) == 143", "start_time": 1700361000} +{"task_id": "weekly-contest-372-find-building-where-alice-and-bob-can-meet", "url": "https://leetcode.com/problems/find-building-where-alice-and-bob-can-meet", "title": "find-building-where-alice-and-bob-can-meet", "meta": {"questionId": "3181", "questionFrontendId": "2940", "title": "Find Building Where Alice and Bob Can Meet", "titleSlug": "find-building-where-alice-and-bob-can-meet", "isPaidOnly": false, "difficulty": "Hard", "likes": 171, "dislikes": 3, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0开始的正整数数组heights,其中heights[i]表示第 i栋建筑的高度。\n如果一个人在建筑i,且存在i < j的建筑j满足heights[i] < heights[j],那么这个人可以移动到建筑j。\n给你另外一个数组queries,其中queries[i] = [ai, bi]。第i个查询中,Alice 在建筑ai ,Bob 在建筑bi。\n请你能返回一个数组ans,其中ans[i]是第i个查询中,Alice 和 Bob 可以相遇的最左边的建筑。如果对于查询i,Alice 和 Bob 不能相遇,令ans[i] 为-1。\n\n示例 1:\n\n输入:heights = [6,4,8,5,2,7], queries = [[0,1],[0,3],[2,4],[3,4],[2,2]]\n输出:[2,5,-1,5,2]\n解释:第一个查询中,Alice 和 Bob 可以移动到建筑 2 ,因为 heights[0] < heights[2] 且 heights[1] < heights[2] 。\n第二个查询中,Alice 和 Bob 可以移动到建筑 5 ,因为 heights[0] < heights[5] 且 heights[3] < heights[5] 。\n第三个查询中,Alice 无法与 Bob 相遇,因为 Alice 不能移动到任何其他建筑。\n第四个查询中,Alice 和 Bob 可以移动到建筑 5 ,因为 heights[3] < heights[5] 且 heights[4] < heights[5] 。\n第五个查询中,Alice 和 Bob 已经在同一栋建筑中。\n对于 ans[i] != -1 ,ans[i] 是 Alice 和 Bob 可以相遇的建筑中最左边建筑的下标。\n对于 ans[i] == -1 ,不存在 Alice 和 Bob 可以相遇的建筑。\n\n示例 2:\n\n输入:heights = [5,3,8,2,6,1,4,6], queries = [[0,7],[3,5],[5,2],[3,0],[1,6]]\n输出:[7,6,-1,4,6]\n解释:第一个查询中,Alice 可以直接移动到 Bob 的建筑,因为 heights[0] < heights[7] 。\n第二个查询中,Alice 和 Bob 可以移动到建筑 6 ,因为 heights[3] < heights[6] 且 heights[5] < heights[6] 。\n第三个查询中,Alice 无法与 Bob 相遇,因为 Bob 不能移动到任何其他建筑。\n第四个查询中,Alice 和 Bob 可以移动到建筑 4 ,因为 heights[3] < heights[4] 且 heights[0] < heights[4] 。\n第五个查询中,Alice 可以直接移动到 Bob 的建筑,因为 heights[1] < heights[6] 。\n对于 ans[i] != -1 ,ans[i] 是 Alice 和 Bob 可以相遇的建筑中最左边建筑的下标。\n对于 ans[i] == -1 ,不存在 Alice 和 Bob 可以相遇的建筑。\n\n\n提示:\n\n1 <= heights.length <= 5 * 104\n1 <= heights[i] <= 109\n1 <= queries.length <= 5 * 104\nqueries[i] = [ai, bi]\n0 <= ai, bi <= heights.length - 1\n\"\"\"\nclass Solution:\n def leftmostBuildingQueries(self, heights: List[int], queries: List[List[int]]) -> List[int]:\n ", "prompt_sft": "给你一个下标从 0开始的正整数数组heights,其中heights[i]表示第 i栋建筑的高度。\n如果一个人在建筑i,且存在i < j的建筑j满足heights[i] < heights[j],那么这个人可以移动到建筑j。\n给你另外一个数组queries,其中queries[i] = [ai, bi]。第i个查询中,Alice 在建筑ai ,Bob 在建筑bi。\n请你能返回一个数组ans,其中ans[i]是第i个查询中,Alice 和 Bob 可以相遇的最左边的建筑。如果对于查询i,Alice 和 Bob 不能相遇,令ans[i] 为-1。\n\n示例 1:\n\n输入:heights = [6,4,8,5,2,7], queries = [[0,1],[0,3],[2,4],[3,4],[2,2]]\n输出:[2,5,-1,5,2]\n解释:第一个查询中,Alice 和 Bob 可以移动到建筑 2 ,因为 heights[0] < heights[2] 且 heights[1] < heights[2] 。\n第二个查询中,Alice 和 Bob 可以移动到建筑 5 ,因为 heights[0] < heights[5] 且 heights[3] < heights[5] 。\n第三个查询中,Alice 无法与 Bob 相遇,因为 Alice 不能移动到任何其他建筑。\n第四个查询中,Alice 和 Bob 可以移动到建筑 5 ,因为 heights[3] < heights[5] 且 heights[4] < heights[5] 。\n第五个查询中,Alice 和 Bob 已经在同一栋建筑中。\n对于 ans[i] != -1 ,ans[i] 是 Alice 和 Bob 可以相遇的建筑中最左边建筑的下标。\n对于 ans[i] == -1 ,不存在 Alice 和 Bob 可以相遇的建筑。\n\n示例 2:\n\n输入:heights = [5,3,8,2,6,1,4,6], queries = [[0,7],[3,5],[5,2],[3,0],[1,6]]\n输出:[7,6,-1,4,6]\n解释:第一个查询中,Alice 可以直接移动到 Bob 的建筑,因为 heights[0] < heights[7] 。\n第二个查询中,Alice 和 Bob 可以移动到建筑 6 ,因为 heights[3] < heights[6] 且 heights[5] < heights[6] 。\n第三个查询中,Alice 无法与 Bob 相遇,因为 Bob 不能移动到任何其他建筑。\n第四个查询中,Alice 和 Bob 可以移动到建筑 4 ,因为 heights[3] < heights[4] 且 heights[0] < heights[4] 。\n第五个查询中,Alice 可以直接移动到 Bob 的建筑,因为 heights[1] < heights[6] 。\n对于 ans[i] != -1 ,ans[i] 是 Alice 和 Bob 可以相遇的建筑中最左边建筑的下标。\n对于 ans[i] == -1 ,不存在 Alice 和 Bob 可以相遇的建筑。\n\n\n提示:\n\n1 <= heights.length <= 5 * 104\n1 <= heights[i] <= 109\n1 <= queries.length <= 5 * 104\nqueries[i] = [ai, bi]\n0 <= ai, bi <= heights.length - 1\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def leftmostBuildingQueries(self, heights: List[int], queries: List[List[int]]) -> List[int]:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"heights\": [6,4,8,5,2,7], \"queries\": [[0,1],[0,3],[2,4],[3,4],[2,2]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [2,5,-1,5,2]\n\ntest_input = { \"heights\": [5,3,8,2,6,1,4,6], \"queries\": [[0,7],[3,5],[5,2],[3,0],[1,6]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [7,6,-1,4,6]\n\ntest_input = { \"heights\": [1], \"queries\": [[0,0]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0]\n\ntest_input = { \"heights\": [1000000000], \"queries\": [[0,0]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0]\n\ntest_input = { \"heights\": [1,2], \"queries\": [[0,0],[0,1],[1,0],[1,1]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,1,1]\n\ntest_input = { \"heights\": [2,1], \"queries\": [[0,0],[0,1],[1,0],[1,1]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,-1,-1,1]\n\ntest_input = { \"heights\": [1,2,3], \"queries\": [[0,0],[0,1],[0,2],[1,0],[1,1],[1,2],[2,0],[2,1],[2,2]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,1,1,2,2,2,2]\n\ntest_input = { \"heights\": [1,3,2], \"queries\": [[0,0],[0,1],[0,2],[1,0],[1,1],[1,2],[2,0],[2,1],[2,2]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,1,1,-1,2,-1,2]\n\ntest_input = { \"heights\": [2,1,3], \"queries\": [[0,0],[0,1],[0,2],[1,0],[1,1],[1,2],[2,0],[2,1],[2,2]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,2,2,2,1,2,2,2,2]\n\ntest_input = { \"heights\": [2,3,1], \"queries\": [[0,0],[0,1],[0,2],[1,0],[1,1],[1,2],[2,0],[2,1],[2,2]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,-1,1,1,-1,-1,-1,2]\n\ntest_input = { \"heights\": [3,1,2], \"queries\": [[0,0],[0,1],[0,2],[1,0],[1,1],[1,2],[2,0],[2,1],[2,2]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,-1,-1,-1,1,2,-1,2,2]\n\ntest_input = { \"heights\": [3,2,1], \"queries\": [[0,0],[0,1],[0,2],[1,0],[1,1],[1,2],[2,0],[2,1],[2,2]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,-1,-1,-1,1,-1,-1,-1,2]\n\ntest_input = { \"heights\": [1,2,3,4], \"queries\": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,1,1,2,3,2,2,2,3,3,3,3,3]\n\ntest_input = { \"heights\": [1,2,4,3], \"queries\": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,1,1,2,3,2,2,2,-1,3,3,-1,3]\n\ntest_input = { \"heights\": [1,3,2,4], \"queries\": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,1,1,3,3,2,3,2,3,3,3,3,3]\n\ntest_input = { \"heights\": [1,3,4,2], \"queries\": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,1,1,2,-1,2,2,2,-1,3,-1,-1,3]\n\ntest_input = { \"heights\": [1,4,2,3], \"queries\": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,1,1,-1,-1,2,-1,2,3,3,-1,3,3]\n\ntest_input = { \"heights\": [1,4,3,2], \"queries\": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,1,1,-1,-1,2,-1,2,-1,3,-1,-1,3]\n\ntest_input = { \"heights\": [2,1,3,4], \"queries\": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,2,2,3,2,1,2,3,2,2,2,3,3,3,3,3]\n\ntest_input = { \"heights\": [2,1,4,3], \"queries\": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,2,2,3,2,1,2,3,2,2,2,-1,3,3,-1,3]\n\ntest_input = { \"heights\": [2,3,1,4], \"queries\": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,3,3,1,1,3,3,3,3,2,3,3,3,3,3]\n\ntest_input = { \"heights\": [2,3,4,1], \"queries\": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,-1,1,1,2,-1,2,2,2,-1,-1,-1,-1,3]\n\ntest_input = { \"heights\": [2,4,1,3], \"queries\": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,3,3,1,1,-1,-1,3,-1,2,3,3,-1,3,3]\n\ntest_input = { \"heights\": [2,4,3,1], \"queries\": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,-1,1,1,-1,-1,2,-1,2,-1,-1,-1,-1,3]\n\ntest_input = { \"heights\": [3,1,2,4], \"queries\": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,3,3,3,3,1,2,3,3,2,2,3,3,3,3,3]\n\ntest_input = { \"heights\": [3,1,4,2], \"queries\": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,2,2,-1,2,1,2,3,2,2,2,-1,-1,3,-1,3]\n\ntest_input = { \"heights\": [3,2,1,4], \"queries\": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,3,3,3,3,1,3,3,3,3,2,3,3,3,3,3]\n\ntest_input = { \"heights\": [3,2,4,1], \"queries\": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,2,2,-1,2,1,2,-1,2,2,2,-1,-1,-1,-1,3]\n\ntest_input = { \"heights\": [3,4,1,2], \"queries\": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,-1,-1,1,1,-1,-1,-1,-1,2,3,-1,-1,3,3]\n\ntest_input = { \"heights\": [3,4,2,1], \"queries\": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,-1,-1,1,1,-1,-1,-1,-1,2,-1,-1,-1,-1,3]\n\ntest_input = { \"heights\": [4,1,2,3], \"queries\": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,-1,-1,-1,-1,1,2,3,-1,2,2,3,-1,3,3,3]\n\ntest_input = { \"heights\": [4,1,3,2], \"queries\": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,-1,-1,-1,-1,1,2,3,-1,2,2,-1,-1,3,-1,3]\n\ntest_input = { \"heights\": [4,2,1,3], \"queries\": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,-1,-1,-1,-1,1,3,3,-1,3,2,3,-1,3,3,3]\n\ntest_input = { \"heights\": [4,2,3,1], \"queries\": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,-1,-1,-1,-1,1,2,-1,-1,2,2,-1,-1,-1,-1,3]\n\ntest_input = { \"heights\": [4,3,1,2], \"queries\": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,-1,-1,-1,-1,1,-1,-1,-1,-1,2,3,-1,-1,3,3]\n\ntest_input = { \"heights\": [4,3,2,1], \"queries\": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,-1,-1,-1,-1,1,-1,-1,-1,-1,2,-1,-1,-1,-1,3]\n\ntest_input = { \"heights\": [1,2,3,4,5], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,2,3,4,2,2,2,3,4,3,3,3,3,4,4,4,4,4,4]\n\ntest_input = { \"heights\": [1,2,3,5,4], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,2,3,4,2,2,2,3,4,3,3,3,3,-1,4,4,4,-1,4]\n\ntest_input = { \"heights\": [1,2,4,3,5], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,2,3,4,2,2,2,4,4,3,3,4,3,4,4,4,4,4,4]\n\ntest_input = { \"heights\": [1,2,4,5,3], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,2,3,4,2,2,2,3,-1,3,3,3,3,-1,4,4,-1,-1,4]\n\ntest_input = { \"heights\": [1,2,5,3,4], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,2,3,4,2,2,2,-1,-1,3,3,-1,3,4,4,4,-1,4,4]\n\ntest_input = { \"heights\": [1,2,5,4,3], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,2,3,4,2,2,2,-1,-1,3,3,-1,3,-1,4,4,-1,-1,4]\n\ntest_input = { \"heights\": [1,3,2,4,5], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,3,3,4,2,3,2,3,4,3,3,3,3,4,4,4,4,4,4]\n\ntest_input = { \"heights\": [1,3,2,5,4], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,3,3,4,2,3,2,3,4,3,3,3,3,-1,4,4,4,-1,4]\n\ntest_input = { \"heights\": [1,3,4,2,5], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,2,4,4,2,2,2,4,4,3,4,4,3,4,4,4,4,4,4]\n\ntest_input = { \"heights\": [1,3,4,5,2], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,2,3,-1,2,2,2,3,-1,3,3,3,3,-1,4,-1,-1,-1,4]\n\ntest_input = { \"heights\": [1,3,5,2,4], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,2,4,4,2,2,2,-1,-1,3,4,-1,3,4,4,4,-1,4,4]\n\ntest_input = { \"heights\": [1,3,5,4,2], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,2,3,-1,2,2,2,-1,-1,3,3,-1,3,-1,4,-1,-1,-1,4]\n\ntest_input = { \"heights\": [1,4,2,3,5], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,4,4,4,2,4,2,3,4,3,4,3,3,4,4,4,4,4,4]\n\ntest_input = { \"heights\": [1,4,2,5,3], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,3,3,-1,2,3,2,3,4,3,3,3,3,-1,4,-1,4,-1,4]\n\ntest_input = { \"heights\": [1,4,3,2,5], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,4,4,4,2,4,2,4,4,3,4,4,3,4,4,4,4,4,4]\n\ntest_input = { \"heights\": [1,4,3,5,2], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,3,3,-1,2,3,2,3,-1,3,3,3,3,-1,4,-1,-1,-1,4]\n\ntest_input = { \"heights\": [1,4,5,2,3], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,2,-1,-1,2,2,2,-1,-1,3,-1,-1,3,4,4,-1,-1,4,4]\n\ntest_input = { \"heights\": [1,4,5,3,2], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,2,-1,-1,2,2,2,-1,-1,3,-1,-1,3,-1,4,-1,-1,-1,4]\n\ntest_input = { \"heights\": [1,5,2,3,4], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,-1,-1,-1,2,-1,2,3,4,3,-1,3,3,4,4,-1,4,4,4]\n\ntest_input = { \"heights\": [1,5,2,4,3], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,-1,-1,-1,2,-1,2,3,4,3,-1,3,3,-1,4,-1,4,-1,4]\n\ntest_input = { \"heights\": [1,5,3,2,4], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,-1,-1,-1,2,-1,2,4,4,3,-1,4,3,4,4,-1,4,4,4]\n\ntest_input = { \"heights\": [1,5,3,4,2], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,-1,-1,-1,2,-1,2,3,-1,3,-1,3,3,-1,4,-1,-1,-1,4]\n\ntest_input = { \"heights\": [1,5,4,2,3], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,-1,-1,-1,2,-1,2,-1,-1,3,-1,-1,3,4,4,-1,-1,4,4]\n\ntest_input = { \"heights\": [1,5,4,3,2], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,-1,-1,-1,2,-1,2,-1,-1,3,-1,-1,3,-1,4,-1,-1,-1,4]\n\ntest_input = { \"heights\": [2,1,3,4,5], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,2,2,3,4,2,1,2,3,4,2,2,2,3,4,3,3,3,3,4,4,4,4,4,4]\n\ntest_input = { \"heights\": [2,1,3,5,4], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,2,2,3,4,2,1,2,3,4,2,2,2,3,4,3,3,3,3,-1,4,4,4,-1,4]\n\ntest_input = { \"heights\": [2,1,4,3,5], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,2,2,3,4,2,1,2,3,4,2,2,2,4,4,3,3,4,3,4,4,4,4,4,4]\n\ntest_input = { \"heights\": [2,1,4,5,3], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,2,2,3,4,2,1,2,3,4,2,2,2,3,-1,3,3,3,3,-1,4,4,-1,-1,4]\n\ntest_input = { \"heights\": [2,1,5,3,4], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,2,2,3,4,2,1,2,3,4,2,2,2,-1,-1,3,3,-1,3,4,4,4,-1,4,4]\n\ntest_input = { \"heights\": [2,1,5,4,3], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,2,2,3,4,2,1,2,3,4,2,2,2,-1,-1,3,3,-1,3,-1,4,4,-1,-1,4]\n\ntest_input = { \"heights\": [2,3,1,4,5], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,3,3,4,1,1,3,3,4,3,3,2,3,4,3,3,3,3,4,4,4,4,4,4]\n\ntest_input = { \"heights\": [2,3,1,5,4], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,3,3,4,1,1,3,3,4,3,3,2,3,4,3,3,3,3,-1,4,4,4,-1,4]\n\ntest_input = { \"heights\": [2,3,4,1,5], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,4,4,1,1,2,4,4,2,2,2,4,4,4,4,4,3,4,4,4,4,4,4]\n\ntest_input = { \"heights\": [2,3,4,5,1], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,-1,1,1,2,3,-1,2,2,2,3,-1,3,3,3,3,-1,-1,-1,-1,-1,4]\n\ntest_input = { \"heights\": [2,3,5,1,4], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,4,4,1,1,2,4,4,2,2,2,-1,-1,4,4,-1,3,4,4,4,-1,4,4]\n\ntest_input = { \"heights\": [2,3,5,4,1], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,-1,1,1,2,3,-1,2,2,2,-1,-1,3,3,-1,3,-1,-1,-1,-1,-1,4]\n\ntest_input = { \"heights\": [2,4,1,3,5], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,3,3,4,1,1,4,4,4,3,4,2,3,4,3,4,3,3,4,4,4,4,4,4]\n\ntest_input = { \"heights\": [2,4,1,5,3], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,3,3,4,1,1,3,3,-1,3,3,2,3,4,3,3,3,3,-1,4,-1,4,-1,4]\n\ntest_input = { \"heights\": [2,4,3,1,5], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,4,4,1,1,4,4,4,2,4,2,4,4,4,4,4,3,4,4,4,4,4,4]\n\ntest_input = { \"heights\": [2,4,3,5,1], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,-1,1,1,3,3,-1,2,3,2,3,-1,3,3,3,3,-1,-1,-1,-1,-1,4]\n\ntest_input = { \"heights\": [2,4,5,1,3], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,4,4,1,1,2,-1,-1,2,2,2,-1,-1,4,-1,-1,3,4,4,-1,-1,4,4]\n\ntest_input = { \"heights\": [2,4,5,3,1], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,-1,1,1,2,-1,-1,2,2,2,-1,-1,3,-1,-1,3,-1,-1,-1,-1,-1,4]\n\ntest_input = { \"heights\": [2,5,1,3,4], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,3,3,4,1,1,-1,-1,-1,3,-1,2,3,4,3,-1,3,3,4,4,-1,4,4,4]\n\ntest_input = { \"heights\": [2,5,1,4,3], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,3,3,4,1,1,-1,-1,-1,3,-1,2,3,4,3,-1,3,3,-1,4,-1,4,-1,4]\n\ntest_input = { \"heights\": [2,5,3,1,4], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,4,4,1,1,-1,-1,-1,2,-1,2,4,4,4,-1,4,3,4,4,-1,4,4,4]\n\ntest_input = { \"heights\": [2,5,3,4,1], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,-1,1,1,-1,-1,-1,2,-1,2,3,-1,3,-1,3,3,-1,-1,-1,-1,-1,4]\n\ntest_input = { \"heights\": [2,5,4,1,3], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,4,4,1,1,-1,-1,-1,2,-1,2,-1,-1,4,-1,-1,3,4,4,-1,-1,4,4]\n\ntest_input = { \"heights\": [2,5,4,3,1], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,-1,1,1,-1,-1,-1,2,-1,2,-1,-1,3,-1,-1,3,-1,-1,-1,-1,-1,4]\n\ntest_input = { \"heights\": [3,1,2,4,5], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,3,3,3,4,3,1,2,3,4,3,2,2,3,4,3,3,3,3,4,4,4,4,4,4]\n\ntest_input = { \"heights\": [3,1,2,5,4], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,3,3,3,4,3,1,2,3,4,3,2,2,3,4,3,3,3,3,-1,4,4,4,-1,4]\n\ntest_input = { \"heights\": [3,1,4,2,5], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,2,2,4,4,2,1,2,3,4,2,2,2,4,4,4,3,4,3,4,4,4,4,4,4]\n\ntest_input = { \"heights\": [3,1,4,5,2], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,2,2,3,-1,2,1,2,3,4,2,2,2,3,-1,3,3,3,3,-1,-1,4,-1,-1,4]\n\ntest_input = { \"heights\": [3,1,5,2,4], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,2,2,4,4,2,1,2,3,4,2,2,2,-1,-1,4,3,-1,3,4,4,4,-1,4,4]\n\ntest_input = { \"heights\": [3,1,5,4,2], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,2,2,3,-1,2,1,2,3,4,2,2,2,-1,-1,3,3,-1,3,-1,-1,4,-1,-1,4]\n\ntest_input = { \"heights\": [3,2,1,4,5], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,3,3,3,4,3,1,3,3,4,3,3,2,3,4,3,3,3,3,4,4,4,4,4,4]\n\ntest_input = { \"heights\": [3,2,1,5,4], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,3,3,3,4,3,1,3,3,4,3,3,2,3,4,3,3,3,3,-1,4,4,4,-1,4]\n\ntest_input = { \"heights\": [3,2,4,1,5], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,2,2,4,4,2,1,2,4,4,2,2,2,4,4,4,4,4,3,4,4,4,4,4,4]\n\ntest_input = { \"heights\": [3,2,4,5,1], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,2,2,3,-1,2,1,2,3,-1,2,2,2,3,-1,3,3,3,3,-1,-1,-1,-1,-1,4]\n\ntest_input = { \"heights\": [3,2,5,1,4], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,2,2,4,4,2,1,2,4,4,2,2,2,-1,-1,4,4,-1,3,4,4,4,-1,4,4]\n\ntest_input = { \"heights\": [3,2,5,4,1], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,2,2,3,-1,2,1,2,3,-1,2,2,2,-1,-1,3,3,-1,3,-1,-1,-1,-1,-1,4]\n\ntest_input = { \"heights\": [3,4,1,2,5], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,4,4,4,1,1,4,4,4,4,4,2,3,4,4,4,3,3,4,4,4,4,4,4]\n\ntest_input = { \"heights\": [3,4,1,5,2], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,3,3,-1,1,1,3,3,-1,3,3,2,3,4,3,3,3,3,-1,-1,-1,4,-1,4]\n\ntest_input = { \"heights\": [3,4,2,1,5], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,4,4,4,1,1,4,4,4,4,4,2,4,4,4,4,4,3,4,4,4,4,4,4]\n\ntest_input = { \"heights\": [3,4,2,5,1], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,3,3,-1,1,1,3,3,-1,3,3,2,3,-1,3,3,3,3,-1,-1,-1,-1,-1,4]", "start_time": 1700361000} +{"task_id": "weekly-contest-371-maximum-strong-pair-xor-i", "url": "https://leetcode.com/problems/maximum-strong-pair-xor-i", "title": "maximum-strong-pair-xor-i", "meta": {"questionId": "3193", "questionFrontendId": "2932", "title": "Maximum Strong Pair XOR I", "titleSlug": "maximum-strong-pair-xor-i", "isPaidOnly": false, "difficulty": "Easy", "likes": 77, "dislikes": 4, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0 开始的整数数组 nums 。如果一对整数 x 和 y 满足以下条件,则称其为 强数对 :\n\n|x - y| <= min(x, y)\n\n你需要从 nums 中选出两个整数,且满足:这两个整数可以形成一个强数对,并且它们的按位异或(XOR)值是在该数组所有强数对中的 最大值 。\n返回数组 nums 所有可能的强数对中的 最大 异或值。\n注意,你可以选择同一个整数两次来形成一个强数对。\n\n示例 1:\n\n输入:nums = [1,2,3,4,5]\n输出:7\n解释:数组 nums 中有 11 个强数对:(1, 1), (1, 2), (2, 2), (2, 3), (2, 4), (3, 3), (3, 4), (3, 5), (4, 4), (4, 5) 和 (5, 5) 。\n这些强数对中的最大异或值是 3 XOR 4 = 7 。\n\n示例 2:\n\n输入:nums = [10,100]\n输出:0\n解释:数组 nums 中有 2 个强数对:(10, 10) 和 (100, 100) 。\n这些强数对中的最大异或值是 10 XOR 10 = 0 ,数对 (100, 100) 的异或值也是 100 XOR 100 = 0 。\n\n示例 3:\n\n输入:nums = [5,6,25,30]\n输出:7\n解释:数组 nums 中有 6 个强数对:(5, 5), (5, 6), (6, 6), (25, 25), (25, 30) 和 (30, 30) 。\n这些强数对中的最大异或值是 25 XOR 30 = 7 ;另一个异或值非零的数对是 (5, 6) ,其异或值是 5 XOR 6 = 3 。\n\n\n提示:\n\n1 <= nums.length <= 50\n1 <= nums[i] <= 100\n\"\"\"\nclass Solution:\n def maximumStrongPairXor(self, nums: List[int]) -> int:\n ", "prompt_sft": "给你一个下标从 0 开始的整数数组 nums 。如果一对整数 x 和 y 满足以下条件,则称其为 强数对 :\n\n|x - y| <= min(x, y)\n\n你需要从 nums 中选出两个整数,且满足:这两个整数可以形成一个强数对,并且它们的按位异或(XOR)值是在该数组所有强数对中的 最大值 。\n返回数组 nums 所有可能的强数对中的 最大 异或值。\n注意,你可以选择同一个整数两次来形成一个强数对。\n\n示例 1:\n\n输入:nums = [1,2,3,4,5]\n输出:7\n解释:数组 nums 中有 11 个强数对:(1, 1), (1, 2), (2, 2), (2, 3), (2, 4), (3, 3), (3, 4), (3, 5), (4, 4), (4, 5) 和 (5, 5) 。\n这些强数对中的最大异或值是 3 XOR 4 = 7 。\n\n示例 2:\n\n输入:nums = [10,100]\n输出:0\n解释:数组 nums 中有 2 个强数对:(10, 10) 和 (100, 100) 。\n这些强数对中的最大异或值是 10 XOR 10 = 0 ,数对 (100, 100) 的异或值也是 100 XOR 100 = 0 。\n\n示例 3:\n\n输入:nums = [5,6,25,30]\n输出:7\n解释:数组 nums 中有 6 个强数对:(5, 5), (5, 6), (6, 6), (25, 25), (25, 30) 和 (30, 30) 。\n这些强数对中的最大异或值是 25 XOR 30 = 7 ;另一个异或值非零的数对是 (5, 6) ,其异或值是 5 XOR 6 = 3 。\n\n\n提示:\n\n1 <= nums.length <= 50\n1 <= nums[i] <= 100\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def maximumStrongPairXor(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,2,3,4,5] }\nassert my_solution.maximumStrongPairXor(**test_input) == 7\n\ntest_input = { \"nums\": [10,100] }\nassert my_solution.maximumStrongPairXor(**test_input) == 0\n\ntest_input = { \"nums\": [5,6,25,30] }\nassert my_solution.maximumStrongPairXor(**test_input) == 7\n\ntest_input = { \"nums\": [1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 0\n\ntest_input = { \"nums\": [100] }\nassert my_solution.maximumStrongPairXor(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,2,3,5] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [1,1,3,8,7] }\nassert my_solution.maximumStrongPairXor(**test_input) == 15\n\ntest_input = { \"nums\": [1,1,4,4,3] }\nassert my_solution.maximumStrongPairXor(**test_input) == 7\n\ntest_input = { \"nums\": [1,1,6,6,9] }\nassert my_solution.maximumStrongPairXor(**test_input) == 15\n\ntest_input = { \"nums\": [1,1,10,3,9] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,1,5,3] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [1,2,2,1,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,3,8,1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,5,5,10] }\nassert my_solution.maximumStrongPairXor(**test_input) == 15\n\ntest_input = { \"nums\": [1,2,8,3,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,9,2,8] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [1,3,3,2,1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [1,3,8,5,3] }\nassert my_solution.maximumStrongPairXor(**test_input) == 13\n\ntest_input = { \"nums\": [1,3,9,6,5] }\nassert my_solution.maximumStrongPairXor(**test_input) == 15\n\ntest_input = { \"nums\": [1,4,1,2,5] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [1,4,3,9,7] }\nassert my_solution.maximumStrongPairXor(**test_input) == 14\n\ntest_input = { \"nums\": [1,4,4,3,4] }\nassert my_solution.maximumStrongPairXor(**test_input) == 7\n\ntest_input = { \"nums\": [1,4,5,2,1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [1,4,8,6,6] }\nassert my_solution.maximumStrongPairXor(**test_input) == 14\n\ntest_input = { \"nums\": [1,5,1,9,1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 12\n\ntest_input = { \"nums\": [1,5,4,1,7] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [1,5,5,2,7] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [1,5,9,1,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 12\n\ntest_input = { \"nums\": [1,5,9,10,4] }\nassert my_solution.maximumStrongPairXor(**test_input) == 15\n\ntest_input = { \"nums\": [1,6,2,7,9] }\nassert my_solution.maximumStrongPairXor(**test_input) == 15\n\ntest_input = { \"nums\": [1,6,3,3,10] }\nassert my_solution.maximumStrongPairXor(**test_input) == 12\n\ntest_input = { \"nums\": [1,6,4,5,3] }\nassert my_solution.maximumStrongPairXor(**test_input) == 7\n\ntest_input = { \"nums\": [1,6,4,6,1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 2\n\ntest_input = { \"nums\": [1,6,5,5,8] }\nassert my_solution.maximumStrongPairXor(**test_input) == 14\n\ntest_input = { \"nums\": [1,6,6,1,9] }\nassert my_solution.maximumStrongPairXor(**test_input) == 15\n\ntest_input = { \"nums\": [1,6,8,5,3] }\nassert my_solution.maximumStrongPairXor(**test_input) == 14\n\ntest_input = { \"nums\": [1,6,8,10,3] }\nassert my_solution.maximumStrongPairXor(**test_input) == 14\n\ntest_input = { \"nums\": [1,6,9,8,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 15\n\ntest_input = { \"nums\": [1,6,10,1,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 12\n\ntest_input = { \"nums\": [1,7,1,4,3] }\nassert my_solution.maximumStrongPairXor(**test_input) == 7\n\ntest_input = { \"nums\": [1,7,2,1,10] }\nassert my_solution.maximumStrongPairXor(**test_input) == 13\n\ntest_input = { \"nums\": [1,7,2,10,10] }\nassert my_solution.maximumStrongPairXor(**test_input) == 13\n\ntest_input = { \"nums\": [1,7,6,1,4] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [1,7,8,6,8] }\nassert my_solution.maximumStrongPairXor(**test_input) == 15\n\ntest_input = { \"nums\": [1,8,1,1,8] }\nassert my_solution.maximumStrongPairXor(**test_input) == 0\n\ntest_input = { \"nums\": [1,8,4,2,1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 12\n\ntest_input = { \"nums\": [1,8,4,5,6] }\nassert my_solution.maximumStrongPairXor(**test_input) == 14\n\ntest_input = { \"nums\": [1,8,5,10,4] }\nassert my_solution.maximumStrongPairXor(**test_input) == 15\n\ntest_input = { \"nums\": [1,8,8,8,3] }\nassert my_solution.maximumStrongPairXor(**test_input) == 0\n\ntest_input = { \"nums\": [1,8,10,2,6] }\nassert my_solution.maximumStrongPairXor(**test_input) == 14\n\ntest_input = { \"nums\": [1,9,4,4,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [1,9,6,5,7] }\nassert my_solution.maximumStrongPairXor(**test_input) == 15\n\ntest_input = { \"nums\": [1,9,6,8,1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 15\n\ntest_input = { \"nums\": [1,9,8,2,8] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [1,9,8,9,6] }\nassert my_solution.maximumStrongPairXor(**test_input) == 15\n\ntest_input = { \"nums\": [1,9,9,7,6] }\nassert my_solution.maximumStrongPairXor(**test_input) == 15\n\ntest_input = { \"nums\": [1,10,1,1,1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 0\n\ntest_input = { \"nums\": [1,10,5,10,6] }\nassert my_solution.maximumStrongPairXor(**test_input) == 15\n\ntest_input = { \"nums\": [1,10,8,7,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 15\n\ntest_input = { \"nums\": [1,10,9,9,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [2,1,1,5,5] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [2,1,1,7,4] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [2,1,8,3,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [2,1,9,2,1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [2,2,4,1,4] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [2,2,5,5,1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [2,2,5,10,6] }\nassert my_solution.maximumStrongPairXor(**test_input) == 15\n\ntest_input = { \"nums\": [2,2,8,2,10] }\nassert my_solution.maximumStrongPairXor(**test_input) == 2\n\ntest_input = { \"nums\": [2,2,10,5,9] }\nassert my_solution.maximumStrongPairXor(**test_input) == 15\n\ntest_input = { \"nums\": [2,3,3,5,3] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [2,3,8,8,10] }\nassert my_solution.maximumStrongPairXor(**test_input) == 2\n\ntest_input = { \"nums\": [2,4,5,3,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 7\n\ntest_input = { \"nums\": [2,4,6,8,8] }\nassert my_solution.maximumStrongPairXor(**test_input) == 14\n\ntest_input = { \"nums\": [2,4,6,9,8] }\nassert my_solution.maximumStrongPairXor(**test_input) == 15\n\ntest_input = { \"nums\": [2,4,8,7,5] }\nassert my_solution.maximumStrongPairXor(**test_input) == 15\n\ntest_input = { \"nums\": [2,4,10,4,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [2,4,10,6,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 12\n\ntest_input = { \"nums\": [2,4,10,7,8] }\nassert my_solution.maximumStrongPairXor(**test_input) == 15\n\ntest_input = { \"nums\": [2,4,10,9,3] }\nassert my_solution.maximumStrongPairXor(**test_input) == 7\n\ntest_input = { \"nums\": [2,5,2,5,5] }\nassert my_solution.maximumStrongPairXor(**test_input) == 0\n\ntest_input = { \"nums\": [2,5,3,10,10] }\nassert my_solution.maximumStrongPairXor(**test_input) == 15\n\ntest_input = { \"nums\": [2,5,7,2,7] }\nassert my_solution.maximumStrongPairXor(**test_input) == 2\n\ntest_input = { \"nums\": [2,5,9,8,9] }\nassert my_solution.maximumStrongPairXor(**test_input) == 13\n\ntest_input = { \"nums\": [2,5,10,8,4] }\nassert my_solution.maximumStrongPairXor(**test_input) == 15\n\ntest_input = { \"nums\": [2,6,1,6,4] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [2,6,1,8,7] }\nassert my_solution.maximumStrongPairXor(**test_input) == 15\n\ntest_input = { \"nums\": [2,6,7,4,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [2,6,8,6,10] }\nassert my_solution.maximumStrongPairXor(**test_input) == 14\n\ntest_input = { \"nums\": [2,6,10,5,4] }\nassert my_solution.maximumStrongPairXor(**test_input) == 15\n\ntest_input = { \"nums\": [2,7,1,8,9] }\nassert my_solution.maximumStrongPairXor(**test_input) == 15\n\ntest_input = { \"nums\": [2,7,2,8,10] }\nassert my_solution.maximumStrongPairXor(**test_input) == 15\n\ntest_input = { \"nums\": [2,7,3,3,7] }\nassert my_solution.maximumStrongPairXor(**test_input) == 1\n\ntest_input = { \"nums\": [2,7,4,8,1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 15\n\ntest_input = { \"nums\": [2,7,9,2,6] }\nassert my_solution.maximumStrongPairXor(**test_input) == 15\n\ntest_input = { \"nums\": [2,7,10,7,1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 13\n\ntest_input = { \"nums\": [2,8,1,9,5] }\nassert my_solution.maximumStrongPairXor(**test_input) == 13\n\ntest_input = { \"nums\": [2,8,7,10,3] }\nassert my_solution.maximumStrongPairXor(**test_input) == 15\n\ntest_input = { \"nums\": [2,9,1,7,7] }\nassert my_solution.maximumStrongPairXor(**test_input) == 14\n\ntest_input = { \"nums\": [2,9,2,8,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 1\n\ntest_input = { \"nums\": [2,9,5,10,10] }\nassert my_solution.maximumStrongPairXor(**test_input) == 15", "start_time": 1699756200} +{"task_id": "weekly-contest-371-high-access-employees", "url": "https://leetcode.com/problems/high-access-employees", "title": "high-access-employees", "meta": {"questionId": "3202", "questionFrontendId": "2933", "title": "High-Access Employees", "titleSlug": "high-access-employees", "isPaidOnly": false, "difficulty": "Medium", "likes": 110, "dislikes": 14, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个长度为 n 、下标从 0 开始的二维字符串数组 access_times 。对于每个 i(0 <= i <= n - 1 ),access_times[i][0] 表示某位员工的姓名,access_times[i][1] 表示该员工的访问时间。access_times 中的所有条目都发生在同一天内。\n访问时间用 四位 数字表示, 符合 24 小时制 ,例如 \"0800\" 或 \"2250\" 。\n如果员工在 同一小时内 访问系统 三次或更多 ,则称其为 高访问 员工。\n时间间隔正好相差一小时的时间 不 被视为同一小时内。例如,\"0815\" 和 \"0915\" 不属于同一小时内。\n一天开始和结束时的访问时间不被计算为同一小时内。例如,\"0005\" 和 \"2350\" 不属于同一小时内。\n以列表形式,按任意顺序,返回所有 高访问 员工的姓名。\n\n示例 1:\n\n输入:access_times = [[\"a\",\"0549\"],[\"b\",\"0457\"],[\"a\",\"0532\"],[\"a\",\"0621\"],[\"b\",\"0540\"]]\n输出:[\"a\"]\n解释:\"a\" 在时间段 [05:32, 06:31] 内有三条访问记录,时间分别为 05:32 、05:49 和 06:21 。\n但是 \"b\" 的访问记录只有两条。\n因此,答案是 [\"a\"] 。\n示例 2:\n\n输入:access_times = [[\"d\",\"0002\"],[\"c\",\"0808\"],[\"c\",\"0829\"],[\"e\",\"0215\"],[\"d\",\"1508\"],[\"d\",\"1444\"],[\"d\",\"1410\"],[\"c\",\"0809\"]]\n输出:[\"c\",\"d\"]\n解释:\"c\" 在时间段 [08:08, 09:07] 内有三条访问记录,时间分别为 08:08 、08:09 和 08:29 。\n\"d\" 在时间段 [14:10, 15:09] 内有三条访问记录,时间分别为 14:10 、14:44 和 15:08 。\n然而,\"e\" 只有一条访问记录,因此不能包含在答案中,最终答案是 [\"c\",\"d\"] 。\n示例 3:\n\n输入:access_times = [[\"cd\",\"1025\"],[\"ab\",\"1025\"],[\"cd\",\"1046\"],[\"cd\",\"1055\"],[\"ab\",\"1124\"],[\"ab\",\"1120\"]]\n输出:[\"ab\",\"cd\"]\n解释:\"ab\"在时间段 [10:25, 11:24] 内有三条访问记录,时间分别为 10:25 、11:20 和 11:24 。\n\"cd\" 在时间段 [10:25, 11:24] 内有三条访问记录,时间分别为 10:25 、10:46 和 10:55 。\n因此,答案是 [\"ab\",\"cd\"] 。\n\n提示:\n\n1 <= access_times.length <= 100\naccess_times[i].length == 2\n1 <= access_times[i][0].length <= 10\naccess_times[i][0] 仅由小写英文字母组成。\naccess_times[i][1].length == 4\naccess_times[i][1] 采用24小时制表示时间。\naccess_times[i][1] 仅由数字 '0' 到 '9' 组成。\n\"\"\"\nclass Solution:\n def findHighAccessEmployees(self, access_times: List[List[str]]) -> List[str]:\n ", "prompt_sft": "给你一个长度为 n 、下标从 0 开始的二维字符串数组 access_times 。对于每个 i(0 <= i <= n - 1 ),access_times[i][0] 表示某位员工的姓名,access_times[i][1] 表示该员工的访问时间。access_times 中的所有条目都发生在同一天内。\n访问时间用 四位 数字表示, 符合 24 小时制 ,例如 \"0800\" 或 \"2250\" 。\n如果员工在 同一小时内 访问系统 三次或更多 ,则称其为 高访问 员工。\n时间间隔正好相差一小时的时间 不 被视为同一小时内。例如,\"0815\" 和 \"0915\" 不属于同一小时内。\n一天开始和结束时的访问时间不被计算为同一小时内。例如,\"0005\" 和 \"2350\" 不属于同一小时内。\n以列表形式,按任意顺序,返回所有 高访问 员工的姓名。\n\n示例 1:\n\n输入:access_times = [[\"a\",\"0549\"],[\"b\",\"0457\"],[\"a\",\"0532\"],[\"a\",\"0621\"],[\"b\",\"0540\"]]\n输出:[\"a\"]\n解释:\"a\" 在时间段 [05:32, 06:31] 内有三条访问记录,时间分别为 05:32 、05:49 和 06:21 。\n但是 \"b\" 的访问记录只有两条。\n因此,答案是 [\"a\"] 。\n示例 2:\n\n输入:access_times = [[\"d\",\"0002\"],[\"c\",\"0808\"],[\"c\",\"0829\"],[\"e\",\"0215\"],[\"d\",\"1508\"],[\"d\",\"1444\"],[\"d\",\"1410\"],[\"c\",\"0809\"]]\n输出:[\"c\",\"d\"]\n解释:\"c\" 在时间段 [08:08, 09:07] 内有三条访问记录,时间分别为 08:08 、08:09 和 08:29 。\n\"d\" 在时间段 [14:10, 15:09] 内有三条访问记录,时间分别为 14:10 、14:44 和 15:08 。\n然而,\"e\" 只有一条访问记录,因此不能包含在答案中,最终答案是 [\"c\",\"d\"] 。\n示例 3:\n\n输入:access_times = [[\"cd\",\"1025\"],[\"ab\",\"1025\"],[\"cd\",\"1046\"],[\"cd\",\"1055\"],[\"ab\",\"1124\"],[\"ab\",\"1120\"]]\n输出:[\"ab\",\"cd\"]\n解释:\"ab\"在时间段 [10:25, 11:24] 内有三条访问记录,时间分别为 10:25 、11:20 和 11:24 。\n\"cd\" 在时间段 [10:25, 11:24] 内有三条访问记录,时间分别为 10:25 、10:46 和 10:55 。\n因此,答案是 [\"ab\",\"cd\"] 。\n\n提示:\n\n1 <= access_times.length <= 100\naccess_times[i].length == 2\n1 <= access_times[i][0].length <= 10\naccess_times[i][0] 仅由小写英文字母组成。\naccess_times[i][1].length == 4\naccess_times[i][1] 采用24小时制表示时间。\naccess_times[i][1] 仅由数字 '0' 到 '9' 组成。\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def findHighAccessEmployees(self, access_times: List[List[str]]) -> List[str]:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"access_times\": [[\"a\",\"0549\"],[\"b\",\"0457\"],[\"a\",\"0532\"],[\"a\",\"0621\"],[\"b\",\"0540\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == [\"a\"]\n\ntest_input = { \"access_times\": [[\"d\",\"0002\"],[\"c\",\"0808\"],[\"c\",\"0829\"],[\"e\",\"0215\"],[\"d\",\"1508\"],[\"d\",\"1444\"],[\"d\",\"1410\"],[\"c\",\"0809\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == [\"c\",\"d\"]\n\ntest_input = { \"access_times\": [[\"cd\",\"1025\"],[\"ab\",\"1025\"],[\"cd\",\"1046\"],[\"cd\",\"1055\"],[\"ab\",\"1124\"],[\"ab\",\"1120\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == [\"ab\",\"cd\"]\n\ntest_input = { \"access_times\": [[\"baipstt\",\"1456\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"bouo\",\"1126\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"cavfbqg\",\"2304\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"cenjcq\",\"1007\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"cqotrwqcaq\",\"0131\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"downbuk\",\"1951\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"dqsoiyz\",\"2204\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"duzeyrov\",\"0243\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"erfg\",\"1223\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"fwhefd\",\"2026\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"gbefbne\",\"0911\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"gp\",\"1540\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"ht\",\"1319\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"inahnsjdqz\",\"1750\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"jwxvijxo\",\"0851\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"kibwwvjuez\",\"0716\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"lvry\",\"0706\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"mbsyxxfzjf\",\"0114\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"mlehvzqb\",\"1620\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"mmgat\",\"0516\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"mxatapbs\",\"2240\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"mzxbgtfc\",\"1531\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"nnhh\",\"1445\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"o\",\"1414\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"qaxqifxxww\",\"1557\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"rjy\",\"0200\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"sgpgh\",\"0539\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"sxx\",\"0325\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"tkvgcf\",\"1645\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"ttk\",\"0304\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"un\",\"0833\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"vlifcdn\",\"0731\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"w\",\"2224\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"wkmehwsg\",\"2023\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"y\",\"1005\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"ynnale\",\"1331\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"yt\",\"0900\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"zbgzk\",\"0527\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"a\",\"0039\"],[\"a\",\"0042\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"ajhzcltqse\",\"0605\"],[\"ajhzcltqse\",\"0558\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"cbaqsymoi\",\"0001\"],[\"cbaqsymoi\",\"0004\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"df\",\"1958\"],[\"df\",\"2002\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"dhmnhvou\",\"0529\"],[\"dhmnhvou\",\"0531\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"epghzrog\",\"0333\"],[\"epghzrog\",\"0333\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"gda\",\"1529\"],[\"gda\",\"1534\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"gjhtgm\",\"2207\"],[\"gjhtgm\",\"2156\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"gsd\",\"2030\"],[\"gsd\",\"2046\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"gsstuktwm\",\"1403\"],[\"gsstuktwm\",\"1357\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"h\",\"2159\"],[\"h\",\"2203\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"hxrdffk\",\"1736\"],[\"hxrdffk\",\"1724\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"iaxsnenx\",\"2037\"],[\"iaxsnenx\",\"2050\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"ikwjvflxq\",\"0055\"],[\"ikwjvflxq\",\"0056\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"jkgjmku\",\"0743\"],[\"jkgjmku\",\"0754\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"jkw\",\"0241\"],[\"jkw\",\"0235\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"jykugiprxf\",\"1633\"],[\"jykugiprxf\",\"1641\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"kdxw\",\"1338\"],[\"kdxw\",\"1336\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"kenltmrg\",\"0932\"],[\"kenltmrg\",\"0941\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"kptjrr\",\"1356\"],[\"kptjrr\",\"1349\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"mcd\",\"1333\"],[\"mcd\",\"1325\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"mhkizga\",\"1552\"],[\"mhkizga\",\"1551\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"monxm\",\"1748\"],[\"monxm\",\"1742\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"msjydtinfy\",\"1301\"],[\"msjydtinfy\",\"1245\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"myhdmu\",\"1407\"],[\"myhdmu\",\"1419\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"nyoezc\",\"1050\"],[\"nyoezc\",\"1041\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"oksvrskxch\",\"0053\"],[\"oksvrskxch\",\"0111\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"pxc\",\"1915\"],[\"pxc\",\"1910\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"qedxyj\",\"0609\"],[\"qedxyj\",\"0614\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"qmslkyxnph\",\"0946\"],[\"qmslkyxnph\",\"0958\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"r\",\"0206\"],[\"r\",\"0202\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"r\",\"2041\"],[\"r\",\"2052\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"rf\",\"2205\"],[\"rf\",\"2203\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"rswegeuhqd\",\"0235\"],[\"rswegeuhqd\",\"0238\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"skfgl\",\"0718\"],[\"skfgl\",\"0712\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"smnnl\",\"2329\"],[\"smnnl\",\"2340\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"tpbbxpx\",\"0409\"],[\"tpbbxpx\",\"0408\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"uiqxqp\",\"0515\"],[\"uiqxqp\",\"0516\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"uyuz\",\"1530\"],[\"uyuz\",\"1543\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"vfeunkee\",\"1500\"],[\"vfeunkee\",\"1508\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"wbyd\",\"1848\"],[\"wbyd\",\"1839\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"x\",\"0522\"],[\"x\",\"0506\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"xhrhdy\",\"1455\"],[\"xhrhdy\",\"1454\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"xmsypay\",\"1605\"],[\"xmsypay\",\"1612\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"xy\",\"0015\"],[\"xy\",\"0021\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"ydtnnpzw\",\"0516\"],[\"ydtnnpzw\",\"0520\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"zh\",\"2348\"],[\"zh\",\"2334\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"zinywjn\",\"0017\"],[\"zinywjn\",\"0019\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"aczdfmsd\",\"0317\"],[\"aczdfmsd\",\"0314\"],[\"aczdfmsd\",\"0320\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == [\"aczdfmsd\"]\n\ntest_input = { \"access_times\": [[\"bsluadumi\",\"1518\"],[\"bsluadumi\",\"1516\"],[\"bsluadumi\",\"1510\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == [\"bsluadumi\"]\n\ntest_input = { \"access_times\": [[\"ckrdpxq\",\"1122\"],[\"ckrdpxq\",\"1125\"],[\"ckrdpxq\",\"1121\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == [\"ckrdpxq\"]\n\ntest_input = { \"access_times\": [[\"fe\",\"1320\"],[\"fe\",\"1326\"],[\"fe\",\"1331\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == [\"fe\"]\n\ntest_input = { \"access_times\": [[\"ff\",\"1508\"],[\"ff\",\"1508\"],[\"ff\",\"1516\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == [\"ff\"]\n\ntest_input = { \"access_times\": [[\"fnlmbcedu\",\"0052\"],[\"fnlmbcedu\",\"0103\"],[\"fnlmbcedu\",\"0055\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == [\"fnlmbcedu\"]\n\ntest_input = { \"access_times\": [[\"hffgwjjve\",\"0159\"],[\"hffgwjjve\",\"0152\"],[\"hffgwjjve\",\"0159\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == [\"hffgwjjve\"]\n\ntest_input = { \"access_times\": [[\"ivlvfgwsx\",\"0122\"],[\"ivlvfgwsx\",\"0135\"],[\"ivlvfgwsx\",\"0139\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == [\"ivlvfgwsx\"]\n\ntest_input = { \"access_times\": [[\"jlfnksqlt\",\"0304\"],[\"jlfnksqlt\",\"0252\"],[\"jlfnksqlt\",\"0304\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == [\"jlfnksqlt\"]\n\ntest_input = { \"access_times\": [[\"jy\",\"0647\"],[\"jy\",\"0652\"],[\"jy\",\"0704\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == [\"jy\"]\n\ntest_input = { \"access_times\": [[\"kchzzdso\",\"2329\"],[\"kchzzdso\",\"2326\"],[\"kchzzdso\",\"2329\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == [\"kchzzdso\"]", "start_time": 1699756200} +{"task_id": "weekly-contest-371-minimum-operations-to-maximize-last-elements-in-arrays", "url": "https://leetcode.com/problems/minimum-operations-to-maximize-last-elements-in-arrays", "title": "minimum-operations-to-maximize-last-elements-in-arrays", "meta": {"questionId": "3190", "questionFrontendId": "2934", "title": "Minimum Operations to Maximize Last Elements in Arrays", "titleSlug": "minimum-operations-to-maximize-last-elements-in-arrays", "isPaidOnly": false, "difficulty": "Medium", "likes": 152, "dislikes": 12, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你两个下标从 0 开始的整数数组 nums1 和 nums2 ,这两个数组的长度都是 n 。\n你可以执行一系列 操作(可能不执行)。\n在每次操作中,你可以选择一个在范围 [0, n - 1] 内的下标 i ,并交换 nums1[i] 和 nums2[i] 的值。\n你的任务是找到满足以下条件所需的 最小 操作次数:\n\nnums1[n - 1] 等于 nums1 中所有元素的 最大值 ,即 nums1[n - 1] = max(nums1[0], nums1[1], ..., nums1[n - 1]) 。\nnums2[n - 1] 等于 nums2 中所有元素的 最大值 ,即 nums2[n - 1] = max(nums2[0], nums2[1], ..., nums2[n - 1]) 。\n\n以整数形式,表示并返回满足上述 全部 条件所需的 最小 操作次数,如果无法同时满足两个条件,则返回 -1 。\n\n示例 1:\n\n输入:nums1 = [1,2,7],nums2 = [4,5,3]\n输出:1\n解释:在这个示例中,可以选择下标 i = 2 执行一次操作。\n交换 nums1[2] 和 nums2[2] 的值,nums1 变为 [1,2,3] ,nums2 变为 [4,5,7] 。\n同时满足两个条件。\n可以证明,需要执行的最小操作次数为 1 。\n因此,答案是 1 。\n\n示例 2:\n\n输入:nums1 = [2,3,4,5,9],nums2 = [8,8,4,4,4]\n输出:2\n解释:在这个示例中,可以执行以下操作:\n首先,选择下标 i = 4 执行操作。\n交换 nums1[4] 和 nums2[4] 的值,nums1 变为 [2,3,4,5,4] ,nums2 变为 [8,8,4,4,9] 。\n然后,选择下标 i = 3 执行操作。\n交换 nums1[3] 和 nums2[3] 的值,nums1 变为 [2,3,4,4,4] ,nums2 变为 [8,8,4,5,9] 。\n同时满足两个条件。 \n可以证明,需要执行的最小操作次数为 2 。 \n因此,答案是 2 。\n\n示例 3:\n\n输入:nums1 = [1,5,4],nums2 = [2,5,3]\n输出:-1\n解释:在这个示例中,无法同时满足两个条件。\n因此,答案是 -1 。\n\n\n提示:\n\n1 <= n == nums1.length == nums2.length <= 1000\n1 <= nums1[i] <= 109\n1 <= nums2[i] <= 109\n\"\"\"\nclass Solution:\n def minOperations(self, nums1: List[int], nums2: List[int]) -> int:\n ", "prompt_sft": "给你两个下标从 0 开始的整数数组 nums1 和 nums2 ,这两个数组的长度都是 n 。\n你可以执行一系列 操作(可能不执行)。\n在每次操作中,你可以选择一个在范围 [0, n - 1] 内的下标 i ,并交换 nums1[i] 和 nums2[i] 的值。\n你的任务是找到满足以下条件所需的 最小 操作次数:\n\nnums1[n - 1] 等于 nums1 中所有元素的 最大值 ,即 nums1[n - 1] = max(nums1[0], nums1[1], ..., nums1[n - 1]) 。\nnums2[n - 1] 等于 nums2 中所有元素的 最大值 ,即 nums2[n - 1] = max(nums2[0], nums2[1], ..., nums2[n - 1]) 。\n\n以整数形式,表示并返回满足上述 全部 条件所需的 最小 操作次数,如果无法同时满足两个条件,则返回 -1 。\n\n示例 1:\n\n输入:nums1 = [1,2,7],nums2 = [4,5,3]\n输出:1\n解释:在这个示例中,可以选择下标 i = 2 执行一次操作。\n交换 nums1[2] 和 nums2[2] 的值,nums1 变为 [1,2,3] ,nums2 变为 [4,5,7] 。\n同时满足两个条件。\n可以证明,需要执行的最小操作次数为 1 。\n因此,答案是 1 。\n\n示例 2:\n\n输入:nums1 = [2,3,4,5,9],nums2 = [8,8,4,4,4]\n输出:2\n解释:在这个示例中,可以执行以下操作:\n首先,选择下标 i = 4 执行操作。\n交换 nums1[4] 和 nums2[4] 的值,nums1 变为 [2,3,4,5,4] ,nums2 变为 [8,8,4,4,9] 。\n然后,选择下标 i = 3 执行操作。\n交换 nums1[3] 和 nums2[3] 的值,nums1 变为 [2,3,4,4,4] ,nums2 变为 [8,8,4,5,9] 。\n同时满足两个条件。 \n可以证明,需要执行的最小操作次数为 2 。 \n因此,答案是 2 。\n\n示例 3:\n\n输入:nums1 = [1,5,4],nums2 = [2,5,3]\n输出:-1\n解释:在这个示例中,无法同时满足两个条件。\n因此,答案是 -1 。\n\n\n提示:\n\n1 <= n == nums1.length == nums2.length <= 1000\n1 <= nums1[i] <= 109\n1 <= nums2[i] <= 109\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def minOperations(self, nums1: List[int], nums2: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums1\": [1,2,7], \"nums2\": [4,5,3] }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums1\": [2,3,4,5,9], \"nums2\": [8,8,4,4,4] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums1\": [1,5,4], \"nums2\": [2,5,3] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums1\": [1], \"nums2\": [1] }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums1\": [1,2], \"nums2\": [2,1] }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums1\": [1,1,10], \"nums2\": [1,5,1] }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums1\": [1,4,16], \"nums2\": [16,16,16] }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums1\": [1,5,15], \"nums2\": [1,1,1] }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums1\": [2,5,7], \"nums2\": [2,2,2] }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums1\": [8,9,10], \"nums2\": [10,9,9] }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums1\": [9,14,14], \"nums2\": [14,11,14] }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums1\": [16,16,16], \"nums2\": [6,7,16] }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums1\": [19,7,19], \"nums2\": [5,19,19] }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums1\": [1,1,8,9], \"nums2\": [1,7,1,1] }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums1\": [1,5,9,9], \"nums2\": [9,9,8,9] }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums1\": [1,7,7,7], \"nums2\": [7,3,3,7] }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums1\": [10,18,12,12], \"nums2\": [19,6,5,12] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums1\": [12,9,11,12], \"nums2\": [3,9,9,9] }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums1\": [15,54,22,54], \"nums2\": [54,19,54,54] }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums1\": [20,20,20,20], \"nums2\": [5,8,19,20] }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums1\": [1,3,4,6,7], \"nums2\": [1,1,1,1,1] }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums1\": [1,11,17,1,18], \"nums2\": [1,1,1,18,1] }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums1\": [3,3,3,14,14], \"nums2\": [3,3,4,3,3] }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums1\": [4,4,8,4,17], \"nums2\": [4,8,4,14,4] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums1\": [4,12,11,11,12], \"nums2\": [12,6,12,12,12] }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums1\": [6,21,87,63,87], \"nums2\": [87,87,23,63,63] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums1\": [10,6,6,6,10], \"nums2\": [6,6,10,10,6] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums1\": [16,12,15,15,16], \"nums2\": [8,16,16,15,15] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums1\": [17,3,6,6,17], \"nums2\": [3,17,6,14,6] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums1\": [19,13,18,18,19], \"nums2\": [5,13,13,13,13] }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums1\": [20,20,53,20,68], \"nums2\": [20,28,20,61,20] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums1\": [6,6,2,4,4,6], \"nums2\": [1,1,6,4,4,4] }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums1\": [8,6,6,6,7,8], \"nums2\": [5,8,8,8,7,7] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums1\": [15,1,15,6,12,15], \"nums2\": [1,15,2,15,15,15] }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums1\": [17,13,19,9,6,14], \"nums2\": [17,14,15,1,19,19] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums1\": [20,8,10,12,17,20], \"nums2\": [7,20,20,20,20,20] }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums1\": [20,18,15,11,17,20], \"nums2\": [7,15,13,7,20,12] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums1\": [20,20,20,20,19,20], \"nums2\": [3,6,7,15,20,20] }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums1\": [28,43,79,32,40,3], \"nums2\": [95,25,74,16,82,56] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums1\": [29,81,58,99,41,36], \"nums2\": [15,34,47,57,31,95] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums1\": [1,1,4,1,7,1,15], \"nums2\": [1,1,1,4,1,9,1] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums1\": [1,4,4,4,7,4,9], \"nums2\": [9,9,4,6,4,9,4] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums1\": [2,88,17,88,68,68,88], \"nums2\": [88,16,88,68,68,68,68] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums1\": [3,3,5,3,3,3,18], \"nums2\": [3,4,3,11,13,14,3] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums1\": [3,41,98,71,71,71,98], \"nums2\": [98,98,49,71,85,94,71] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums1\": [5,5,27,53,5,59,65], \"nums2\": [5,16,5,5,58,5,5] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums1\": [5,6,11,11,13,11,14], \"nums2\": [14,14,11,11,11,14,11] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums1\": [6,5,1,10,8,4,5], \"nums2\": [3,8,8,3,6,1,4] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums1\": [14,3,4,4,4,4,14], \"nums2\": [2,14,4,4,5,12,4] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums1\": [14,28,68,68,65,67,68], \"nums2\": [68,68,49,64,68,67,67] }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums1\": [19,19,8,9,10,13,19], \"nums2\": [1,5,19,19,19,13,13] }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums1\": [20,6,20,20,20,20,20], \"nums2\": [3,20,7,9,13,14,20] }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums1\": [85,85,62,85,78,84,85], \"nums2\": [5,37,85,76,85,85,85] }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums1\": [1,2,2,2,2,2,2,10], \"nums2\": [10,2,2,2,7,8,9,2] }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums1\": [1,9,3,3,4,9,9,9], \"nums2\": [9,2,9,9,9,6,8,9] }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums1\": [3,3,4,3,3,3,3,8], \"nums2\": [3,3,3,5,7,7,8,3] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums1\": [4,8,11,19,16,16,19,19], \"nums2\": [19,19,19,13,16,16,16,16] }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums1\": [8,20,4,9,9,4,4,20], \"nums2\": [9,14,10,1,1,20,16,15] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums1\": [9,9,1,2,2,6,8,9], \"nums2\": [1,1,9,2,2,2,2,2] }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums1\": [10,4,10,9,10,10,10,10], \"nums2\": [4,10,9,9,9,9,9,9] }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums1\": [13,95,19,56,59,95,95,95], \"nums2\": [95,14,95,95,95,83,88,95] }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums1\": [19,7,19,8,9,15,9,19], \"nums2\": [7,19,7,19,9,9,18,9] }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums1\": [19,19,3,3,15,16,3,19], \"nums2\": [2,2,3,7,3,3,17,3] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums1\": [1,8,8,5,8,8,8,7,8], \"nums2\": [8,2,4,8,5,6,6,8,8] }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums1\": [1,10,10,5,10,8,10,10,10], \"nums2\": [10,2,4,10,7,8,8,8,8] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums1\": [2,7,7,7,7,7,7,17,18], \"nums2\": [18,7,10,11,13,15,17,7,7] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums1\": [3,13,22,24,13,13,13,81,91], \"nums2\": [91,13,13,13,45,59,71,13,13] }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums1\": [4,4,9,4,16,4,17,4,18], \"nums2\": [4,8,4,14,4,16,4,18,4] }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums1\": [6,9,65,13,65,65,28,28,65], \"nums2\": [65,65,13,65,24,27,28,34,28] }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums1\": [8,3,5,6,6,3,3,3,8], \"nums2\": [1,3,3,3,3,7,7,8,3] }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums1\": [10,1,10,10,10,9,9,9,10], \"nums2\": [1,10,5,6,8,9,9,10,9] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums1\": [15,15,3,5,15,15,9,13,15], \"nums2\": [1,2,15,15,6,8,9,9,9] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums1\": [16,3,3,7,3,11,3,3,16], \"nums2\": [2,3,6,3,10,3,15,16,3] }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums1\": [16,3,16,7,16,16,10,10,16], \"nums2\": [2,16,4,16,9,10,10,13,10] }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums1\": [80,80,18,39,39,62,39,39,80], \"nums2\": [2,10,80,39,42,39,66,66,39] }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums1\": [1,1,1,1,1,1,1,7,1,9], \"nums2\": [9,1,3,3,3,5,5,1,9,1] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums1\": [1,2,2,2,2,5,8,2,2,9], \"nums2\": [9,2,2,2,4,2,2,9,9,2] }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums1\": [1,2,18,18,10,18,18,17,18,18], \"nums2\": [18,18,5,5,18,13,14,18,18,18] }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums1\": [1,3,1,1,1,1,16,16,1,19], \"nums2\": [1,1,7,7,9,12,1,1,18,1] }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums1\": [1,9,3,9,4,5,7,8,8,9], \"nums2\": [9,1,9,3,9,9,7,7,7,7] }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums1\": [2,2,2,2,10,11,2,2,2,20], \"nums2\": [2,3,9,9,2,2,12,14,19,2] }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums1\": [3,15,6,7,7,10,7,7,15,15], \"nums2\": [15,6,15,7,9,7,12,13,7,7] }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums1\": [5,20,20,8,8,12,20,19,20,20], \"nums2\": [20,6,7,20,20,20,15,20,20,20] }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums1\": [8,8,8,8,8,8,8,8,6,8], \"nums2\": [1,2,3,4,4,5,5,5,8,8] }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums1\": [9,3,3,3,3,6,7,7,3,9], \"nums2\": [3,3,4,5,5,3,3,3,7,3] }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums1\": [9,8,6,2,1,10,9,7,9,4], \"nums2\": [6,2,8,2,5,3,6,5,6,10] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums1\": [10,2,2,2,3,2,2,2,2,10], \"nums2\": [1,10,2,2,2,6,6,8,10,2] }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums1\": [12,19,10,4,17,12,18,6,7,7], \"nums2\": [20,5,15,7,10,8,2,16,14,1] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums1\": [17,31,31,34,31,42,31,65,31,89], \"nums2\": [89,31,32,31,37,31,45,31,84,31] }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums1\": [19,7,7,19,9,19,19,19,17,19], \"nums2\": [6,19,19,8,19,10,10,16,19,19] }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums1\": [20,20,7,20,8,11,11,11,11,20], \"nums2\": [5,6,20,7,20,11,15,18,20,11] }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums1\": [90,7,90,13,90,33,33,83,33,90], \"nums2\": [6,90,13,90,22,33,62,33,86,33] }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums1\": [1,1,1,1,1,10,1,15,16,17,20], \"nums2\": [1,2,2,9,10,1,14,1,1,1,1] }\nassert my_solution.minOperations(**test_input) == 5\n\ntest_input = { \"nums1\": [1,1,1,1,3,1,1,6,1,1,8], \"nums2\": [1,1,1,3,1,3,5,1,6,7,1] }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums1\": [1,2,2,6,2,2,2,2,2,2,10], \"nums2\": [10,2,4,2,6,6,7,8,9,9,2] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums1\": [1,2,3,20,8,8,19,19,19,20,20], \"nums2\": [20,20,20,5,20,20,20,19,19,19,19] }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums1\": [1,2,4,9,5,9,9,6,7,6,9], \"nums2\": [9,9,9,4,9,5,5,6,6,7,6] }\nassert my_solution.minOperations(**test_input) == 5\n\ntest_input = { \"nums1\": [1,7,7,7,7,7,13,16,7,19,19], \"nums2\": [19,7,10,11,11,12,7,7,16,7,7] }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums1\": [1,10,4,10,10,10,6,10,7,9,10], \"nums2\": [10,3,10,5,5,6,10,7,10,9,9] }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums1\": [1,20,20,7,20,20,13,17,17,19,20], \"nums2\": [20,2,4,20,7,7,20,20,17,17,17] }\nassert my_solution.minOperations(**test_input) == 4", "start_time": 1699756200} +{"task_id": "weekly-contest-371-maximum-strong-pair-xor-ii", "url": "https://leetcode.com/problems/maximum-strong-pair-xor-ii", "title": "maximum-strong-pair-xor-ii", "meta": {"questionId": "3197", "questionFrontendId": "2935", "title": "Maximum Strong Pair XOR II", "titleSlug": "maximum-strong-pair-xor-ii", "isPaidOnly": false, "difficulty": "Hard", "likes": 140, "dislikes": 1, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0 开始的整数数组 nums 。如果一对整数 x 和 y 满足以下条件,则称其为 强数对 :\n\n|x - y| <= min(x, y)\n\n你需要从 nums 中选出两个整数,且满足:这两个整数可以形成一个强数对,并且它们的按位异或(XOR)值是在该数组所有强数对中的 最大值 。\n返回数组 nums 所有可能的强数对中的 最大 异或值。\n注意,你可以选择同一个整数两次来形成一个强数对。\n\n示例 1:\n\n输入:nums = [1,2,3,4,5]\n输出:7\n解释:数组 nums 中有 11 个强数对:(1, 1), (1, 2), (2, 2), (2, 3), (2, 4), (3, 3), (3, 4), (3, 5), (4, 4), (4, 5) 和 (5, 5) 。\n这些强数对中的最大异或值是 3 XOR 4 = 7 。\n\n示例 2:\n\n输入:nums = [10,100]\n输出:0\n解释:数组 nums 中有 2 个强数对:(10, 10) 和 (100, 100) 。\n这些强数对中的最大异或值是 10 XOR 10 = 0 ,数对 (100, 100) 的异或值也是 100 XOR 100 = 0 。\n\n示例 3:\n\n输入:nums = [500,520,2500,3000]\n输出:1020\n解释:数组 nums 中有 6 个强数对:(500, 500), (500, 520), (520, 520), (2500, 2500), (2500, 3000) 和 (3000, 3000) 。\n这些强数对中的最大异或值是 500 XOR 520 = 1020 ;另一个异或值非零的数对是 (5, 6) ,其异或值是 2500 XOR 3000 = 636 。\n\n\n提示:\n\n1 <= nums.length <= 5 * 104\n1 <= nums[i] <= 220 - 1\n\"\"\"\nclass Solution:\n def maximumStrongPairXor(self, nums: List[int]) -> int:\n ", "prompt_sft": "给你一个下标从 0 开始的整数数组 nums 。如果一对整数 x 和 y 满足以下条件,则称其为 强数对 :\n\n|x - y| <= min(x, y)\n\n你需要从 nums 中选出两个整数,且满足:这两个整数可以形成一个强数对,并且它们的按位异或(XOR)值是在该数组所有强数对中的 最大值 。\n返回数组 nums 所有可能的强数对中的 最大 异或值。\n注意,你可以选择同一个整数两次来形成一个强数对。\n\n示例 1:\n\n输入:nums = [1,2,3,4,5]\n输出:7\n解释:数组 nums 中有 11 个强数对:(1, 1), (1, 2), (2, 2), (2, 3), (2, 4), (3, 3), (3, 4), (3, 5), (4, 4), (4, 5) 和 (5, 5) 。\n这些强数对中的最大异或值是 3 XOR 4 = 7 。\n\n示例 2:\n\n输入:nums = [10,100]\n输出:0\n解释:数组 nums 中有 2 个强数对:(10, 10) 和 (100, 100) 。\n这些强数对中的最大异或值是 10 XOR 10 = 0 ,数对 (100, 100) 的异或值也是 100 XOR 100 = 0 。\n\n示例 3:\n\n输入:nums = [500,520,2500,3000]\n输出:1020\n解释:数组 nums 中有 6 个强数对:(500, 500), (500, 520), (520, 520), (2500, 2500), (2500, 3000) 和 (3000, 3000) 。\n这些强数对中的最大异或值是 500 XOR 520 = 1020 ;另一个异或值非零的数对是 (5, 6) ,其异或值是 2500 XOR 3000 = 636 。\n\n\n提示:\n\n1 <= nums.length <= 5 * 104\n1 <= nums[i] <= 220 - 1\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def maximumStrongPairXor(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,2,3,4,5] }\nassert my_solution.maximumStrongPairXor(**test_input) == 7\n\ntest_input = { \"nums\": [10,100] }\nassert my_solution.maximumStrongPairXor(**test_input) == 0\n\ntest_input = { \"nums\": [500,520,2500,3000] }\nassert my_solution.maximumStrongPairXor(**test_input) == 1020\n\ntest_input = { \"nums\": [1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 0\n\ntest_input = { \"nums\": [2,3] }\nassert my_solution.maximumStrongPairXor(**test_input) == 1\n\ntest_input = { \"nums\": [3,4] }\nassert my_solution.maximumStrongPairXor(**test_input) == 7\n\ntest_input = { \"nums\": [4,5] }\nassert my_solution.maximumStrongPairXor(**test_input) == 1\n\ntest_input = { \"nums\": [5,6] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,3] }\nassert my_solution.maximumStrongPairXor(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,4] }\nassert my_solution.maximumStrongPairXor(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,5] }\nassert my_solution.maximumStrongPairXor(**test_input) == 0\n\ntest_input = { \"nums\": [1,2,1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,3] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,4] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [1,2,5] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [1,3,1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 0\n\ntest_input = { \"nums\": [1,3,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [1,3,3] }\nassert my_solution.maximumStrongPairXor(**test_input) == 0\n\ntest_input = { \"nums\": [1,3,4] }\nassert my_solution.maximumStrongPairXor(**test_input) == 7\n\ntest_input = { \"nums\": [1,3,5] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [1,4,1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 0\n\ntest_input = { \"nums\": [1,4,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [1,4,3] }\nassert my_solution.maximumStrongPairXor(**test_input) == 7\n\ntest_input = { \"nums\": [1,4,4] }\nassert my_solution.maximumStrongPairXor(**test_input) == 0\n\ntest_input = { \"nums\": [1,4,5] }\nassert my_solution.maximumStrongPairXor(**test_input) == 1\n\ntest_input = { \"nums\": [1,5,1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 0\n\ntest_input = { \"nums\": [1,5,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [1,5,3] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [1,5,4] }\nassert my_solution.maximumStrongPairXor(**test_input) == 1\n\ntest_input = { \"nums\": [1,5,5] }\nassert my_solution.maximumStrongPairXor(**test_input) == 0\n\ntest_input = { \"nums\": [2,1,1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [2,1,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [2,1,3] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [2,1,4] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [2,1,5] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [2,2,1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [2,2,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 0\n\ntest_input = { \"nums\": [2,2,3] }\nassert my_solution.maximumStrongPairXor(**test_input) == 1\n\ntest_input = { \"nums\": [2,2,4] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [2,2,5] }\nassert my_solution.maximumStrongPairXor(**test_input) == 0\n\ntest_input = { \"nums\": [2,3,1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [2,3,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 1\n\ntest_input = { \"nums\": [2,3,3] }\nassert my_solution.maximumStrongPairXor(**test_input) == 1\n\ntest_input = { \"nums\": [2,3,4] }\nassert my_solution.maximumStrongPairXor(**test_input) == 7\n\ntest_input = { \"nums\": [2,3,5] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [2,4,1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [2,4,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [2,4,3] }\nassert my_solution.maximumStrongPairXor(**test_input) == 7\n\ntest_input = { \"nums\": [2,4,4] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [2,4,5] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [2,5,1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [2,5,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 0\n\ntest_input = { \"nums\": [2,5,3] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [2,5,4] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [2,5,5] }\nassert my_solution.maximumStrongPairXor(**test_input) == 0\n\ntest_input = { \"nums\": [3,1,1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 0\n\ntest_input = { \"nums\": [3,1,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [3,1,3] }\nassert my_solution.maximumStrongPairXor(**test_input) == 0\n\ntest_input = { \"nums\": [3,1,4] }\nassert my_solution.maximumStrongPairXor(**test_input) == 7\n\ntest_input = { \"nums\": [3,1,5] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [3,2,1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [3,2,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 1\n\ntest_input = { \"nums\": [3,2,3] }\nassert my_solution.maximumStrongPairXor(**test_input) == 1\n\ntest_input = { \"nums\": [3,2,4] }\nassert my_solution.maximumStrongPairXor(**test_input) == 7\n\ntest_input = { \"nums\": [3,2,5] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [3,3,1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 0\n\ntest_input = { \"nums\": [3,3,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 1\n\ntest_input = { \"nums\": [3,3,3] }\nassert my_solution.maximumStrongPairXor(**test_input) == 0\n\ntest_input = { \"nums\": [3,3,4] }\nassert my_solution.maximumStrongPairXor(**test_input) == 7\n\ntest_input = { \"nums\": [3,3,5] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [3,4,1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 7\n\ntest_input = { \"nums\": [3,4,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 7\n\ntest_input = { \"nums\": [3,4,3] }\nassert my_solution.maximumStrongPairXor(**test_input) == 7\n\ntest_input = { \"nums\": [3,4,4] }\nassert my_solution.maximumStrongPairXor(**test_input) == 7\n\ntest_input = { \"nums\": [3,4,5] }\nassert my_solution.maximumStrongPairXor(**test_input) == 7\n\ntest_input = { \"nums\": [3,5,1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [3,5,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [3,5,3] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [3,5,4] }\nassert my_solution.maximumStrongPairXor(**test_input) == 7\n\ntest_input = { \"nums\": [3,5,5] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [4,1,1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 0\n\ntest_input = { \"nums\": [4,1,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [4,1,3] }\nassert my_solution.maximumStrongPairXor(**test_input) == 7\n\ntest_input = { \"nums\": [4,1,4] }\nassert my_solution.maximumStrongPairXor(**test_input) == 0\n\ntest_input = { \"nums\": [4,1,5] }\nassert my_solution.maximumStrongPairXor(**test_input) == 1\n\ntest_input = { \"nums\": [4,2,1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [4,2,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [4,2,3] }\nassert my_solution.maximumStrongPairXor(**test_input) == 7\n\ntest_input = { \"nums\": [4,2,4] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [4,2,5] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [4,3,1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 7\n\ntest_input = { \"nums\": [4,3,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 7\n\ntest_input = { \"nums\": [4,3,3] }\nassert my_solution.maximumStrongPairXor(**test_input) == 7\n\ntest_input = { \"nums\": [4,3,4] }\nassert my_solution.maximumStrongPairXor(**test_input) == 7\n\ntest_input = { \"nums\": [4,3,5] }\nassert my_solution.maximumStrongPairXor(**test_input) == 7\n\ntest_input = { \"nums\": [4,4,1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 0\n\ntest_input = { \"nums\": [4,4,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6", "start_time": 1699756200} +{"task_id": "biweekly-contest-117-distribute-candies-among-children-i", "url": "https://leetcode.com/problems/distribute-candies-among-children-i", "title": "distribute-candies-among-children-i", "meta": {"questionId": "3199", "questionFrontendId": "2928", "title": "Distribute Candies Among Children I", "titleSlug": "distribute-candies-among-children-i", "isPaidOnly": false, "difficulty": "Easy", "likes": 50, "dislikes": 25, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你两个正整数 n 和 limit 。\n\n请你将 n 颗糖果分给 3 位小朋友,确保没有任何小朋友得到超过 limit 颗糖果,请你返回满足此条件下的 总方案数 。\n\n示例 1:\n\n输入:n = 5, limit = 2\n输出:3\n解释:总共有 3 种方法分配 5 颗糖果,且每位小朋友的糖果数不超过 2 :(1, 2, 2) ,(2, 1, 2) 和 (2, 2, 1) 。\n\n示例 2:\n\n输入:n = 3, limit = 3\n输出:10\n解释:总共有 10 种方法分配 3 颗糖果,且每位小朋友的糖果数不超过 3 :(0, 0, 3) ,(0, 1, 2) ,(0, 2, 1) ,(0, 3, 0) ,(1, 0, 2) ,(1, 1, 1) ,(1, 2, 0) ,(2, 0, 1) ,(2, 1, 0) 和 (3, 0, 0) 。\n\n\n提示:\n\n * 1 <= n <= 50\n * 1 <= limit <= 50\n\"\"\"\nclass Solution:\n def distributeCandies(self, n: int, limit: int) -> int:\n ", "prompt_sft": "给你两个正整数 n 和 limit 。\n\n请你将 n 颗糖果分给 3 位小朋友,确保没有任何小朋友得到超过 limit 颗糖果,请你返回满足此条件下的 总方案数 。\n\n示例 1:\n\n输入:n = 5, limit = 2\n输出:3\n解释:总共有 3 种方法分配 5 颗糖果,且每位小朋友的糖果数不超过 2 :(1, 2, 2) ,(2, 1, 2) 和 (2, 2, 1) 。\n\n示例 2:\n\n输入:n = 3, limit = 3\n输出:10\n解释:总共有 10 种方法分配 3 颗糖果,且每位小朋友的糖果数不超过 3 :(0, 0, 3) ,(0, 1, 2) ,(0, 2, 1) ,(0, 3, 0) ,(1, 0, 2) ,(1, 1, 1) ,(1, 2, 0) ,(2, 0, 1) ,(2, 1, 0) 和 (3, 0, 0) 。\n\n\n提示:\n\n * 1 <= n <= 50\n * 1 <= limit <= 50\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def distributeCandies(self, n: int, limit: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"n\": 5, \"limit\": 2 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 3, \"limit\": 3 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 1, \"limit\": 1 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 2 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 3 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 4 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 5 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 6 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 7 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 8 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 9 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 10 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 11 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 12 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 13 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 14 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 15 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 16 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 17 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 18 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 19 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 20 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 21 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 22 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 23 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 24 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 25 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 2, \"limit\": 1 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 2, \"limit\": 2 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 3 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 4 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 5 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 6 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 7 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 8 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 9 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 10 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 11 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 12 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 13 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 14 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 15 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 16 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 17 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 18 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 19 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 20 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 21 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 22 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 23 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 24 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 25 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 3, \"limit\": 1 }\nassert my_solution.distributeCandies(**test_input) == 1\n\ntest_input = { \"n\": 3, \"limit\": 2 }\nassert my_solution.distributeCandies(**test_input) == 7\n\ntest_input = { \"n\": 3, \"limit\": 4 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 5 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 6 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 7 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 8 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 9 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 10 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 11 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 12 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 13 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 14 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 15 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 16 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 17 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 18 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 19 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 20 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 21 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 22 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 23 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 24 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 25 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 4, \"limit\": 1 }\nassert my_solution.distributeCandies(**test_input) == 0\n\ntest_input = { \"n\": 4, \"limit\": 2 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 4, \"limit\": 3 }\nassert my_solution.distributeCandies(**test_input) == 12\n\ntest_input = { \"n\": 4, \"limit\": 4 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 5 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 6 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 7 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 8 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 9 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 10 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 11 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 12 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 13 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 14 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 15 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 16 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 17 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 18 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 19 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 20 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 21 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 22 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 23 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 24 }\nassert my_solution.distributeCandies(**test_input) == 15", "start_time": 1699713000} +{"task_id": "biweekly-contest-117-distribute-candies-among-children-ii", "url": "https://leetcode.com/problems/distribute-candies-among-children-ii", "title": "distribute-candies-among-children-ii", "meta": {"questionId": "3201", "questionFrontendId": "2929", "title": "Distribute Candies Among Children II", "titleSlug": "distribute-candies-among-children-ii", "isPaidOnly": false, "difficulty": "Medium", "likes": 62, "dislikes": 95, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你两个正整数 n 和 limit 。\n\n请你将 n 颗糖果分给 3 位小朋友,确保没有任何小朋友得到超过 limit 颗糖果,请你返回满足此条件下的 总方案数 。\n\n示例 1:\n\n输入:n = 5, limit = 2\n输出:3\n解释:总共有 3 种方法分配 5 颗糖果,且每位小朋友的糖果数不超过 2 :(1, 2, 2) ,(2, 1, 2) 和 (2, 2, 1) 。\n\n示例 2:\n\n输入:n = 3, limit = 3\n输出:10\n解释:总共有 10 种方法分配 3 颗糖果,且每位小朋友的糖果数不超过 3 :(0, 0, 3) ,(0, 1, 2) ,(0, 2, 1) ,(0, 3, 0) ,(1, 0, 2) ,(1, 1, 1) ,(1, 2, 0) ,(2, 0, 1) ,(2, 1, 0) 和 (3, 0, 0) 。\n\n\n提示:\n\n * 1 <= n <= 106\n * 1 <= limit <= 106\n\"\"\"\nclass Solution:\n def distributeCandies(self, n: int, limit: int) -> int:\n ", "prompt_sft": "给你两个正整数 n 和 limit 。\n\n请你将 n 颗糖果分给 3 位小朋友,确保没有任何小朋友得到超过 limit 颗糖果,请你返回满足此条件下的 总方案数 。\n\n示例 1:\n\n输入:n = 5, limit = 2\n输出:3\n解释:总共有 3 种方法分配 5 颗糖果,且每位小朋友的糖果数不超过 2 :(1, 2, 2) ,(2, 1, 2) 和 (2, 2, 1) 。\n\n示例 2:\n\n输入:n = 3, limit = 3\n输出:10\n解释:总共有 10 种方法分配 3 颗糖果,且每位小朋友的糖果数不超过 3 :(0, 0, 3) ,(0, 1, 2) ,(0, 2, 1) ,(0, 3, 0) ,(1, 0, 2) ,(1, 1, 1) ,(1, 2, 0) ,(2, 0, 1) ,(2, 1, 0) 和 (3, 0, 0) 。\n\n\n提示:\n\n * 1 <= n <= 106\n * 1 <= limit <= 106\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def distributeCandies(self, n: int, limit: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"n\": 5, \"limit\": 2 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 3, \"limit\": 3 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 1, \"limit\": 1 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 2 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 3 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 4 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 5 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 6 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 7 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 8 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 9 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 10 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 11 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 12 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 13 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 14 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 15 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 16 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 17 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 18 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 19 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 20 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 2, \"limit\": 1 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 2, \"limit\": 2 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 3 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 4 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 5 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 6 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 7 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 8 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 9 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 10 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 11 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 12 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 13 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 14 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 15 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 16 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 17 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 18 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 19 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 20 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 3, \"limit\": 1 }\nassert my_solution.distributeCandies(**test_input) == 1\n\ntest_input = { \"n\": 3, \"limit\": 2 }\nassert my_solution.distributeCandies(**test_input) == 7\n\ntest_input = { \"n\": 3, \"limit\": 4 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 5 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 6 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 7 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 8 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 9 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 10 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 11 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 12 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 13 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 14 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 15 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 16 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 17 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 18 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 19 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 20 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 4, \"limit\": 1 }\nassert my_solution.distributeCandies(**test_input) == 0\n\ntest_input = { \"n\": 4, \"limit\": 2 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 4, \"limit\": 3 }\nassert my_solution.distributeCandies(**test_input) == 12\n\ntest_input = { \"n\": 4, \"limit\": 4 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 5 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 6 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 7 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 8 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 9 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 10 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 11 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 12 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 13 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 14 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 15 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 16 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 17 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 18 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 19 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 20 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 5, \"limit\": 1 }\nassert my_solution.distributeCandies(**test_input) == 0\n\ntest_input = { \"n\": 5, \"limit\": 3 }\nassert my_solution.distributeCandies(**test_input) == 12\n\ntest_input = { \"n\": 5, \"limit\": 4 }\nassert my_solution.distributeCandies(**test_input) == 18\n\ntest_input = { \"n\": 5, \"limit\": 5 }\nassert my_solution.distributeCandies(**test_input) == 21\n\ntest_input = { \"n\": 5, \"limit\": 6 }\nassert my_solution.distributeCandies(**test_input) == 21\n\ntest_input = { \"n\": 5, \"limit\": 7 }\nassert my_solution.distributeCandies(**test_input) == 21\n\ntest_input = { \"n\": 5, \"limit\": 8 }\nassert my_solution.distributeCandies(**test_input) == 21\n\ntest_input = { \"n\": 5, \"limit\": 9 }\nassert my_solution.distributeCandies(**test_input) == 21\n\ntest_input = { \"n\": 5, \"limit\": 10 }\nassert my_solution.distributeCandies(**test_input) == 21\n\ntest_input = { \"n\": 5, \"limit\": 11 }\nassert my_solution.distributeCandies(**test_input) == 21\n\ntest_input = { \"n\": 5, \"limit\": 12 }\nassert my_solution.distributeCandies(**test_input) == 21\n\ntest_input = { \"n\": 5, \"limit\": 13 }\nassert my_solution.distributeCandies(**test_input) == 21\n\ntest_input = { \"n\": 5, \"limit\": 14 }\nassert my_solution.distributeCandies(**test_input) == 21\n\ntest_input = { \"n\": 5, \"limit\": 15 }\nassert my_solution.distributeCandies(**test_input) == 21\n\ntest_input = { \"n\": 5, \"limit\": 16 }\nassert my_solution.distributeCandies(**test_input) == 21\n\ntest_input = { \"n\": 5, \"limit\": 17 }\nassert my_solution.distributeCandies(**test_input) == 21\n\ntest_input = { \"n\": 5, \"limit\": 18 }\nassert my_solution.distributeCandies(**test_input) == 21\n\ntest_input = { \"n\": 5, \"limit\": 19 }\nassert my_solution.distributeCandies(**test_input) == 21\n\ntest_input = { \"n\": 5, \"limit\": 20 }\nassert my_solution.distributeCandies(**test_input) == 21", "start_time": 1699713000} +{"task_id": "biweekly-contest-117-number-of-strings-which-can-be-rearranged-to-contain-substring", "url": "https://leetcode.com/problems/number-of-strings-which-can-be-rearranged-to-contain-substring", "title": "number-of-strings-which-can-be-rearranged-to-contain-substring", "meta": {"questionId": "3200", "questionFrontendId": "2930", "title": "Number of Strings Which Can Be Rearranged to Contain Substring", "titleSlug": "number-of-strings-which-can-be-rearranged-to-contain-substring", "isPaidOnly": false, "difficulty": "Medium", "likes": 119, "dislikes": 54, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个整数 n 。\n\n如果一个字符串 s 只包含小写英文字母,且 将 s 的字符重新排列后,新字符串包含 子字符串 \"leet\" ,那么我们称字符串 s 是一个 好 字符串。\n\n比方说:\n\n * 字符串 \"lteer\" 是好字符串,因为重新排列后可以得到 \"leetr\" 。\n * \"letl\" 不是好字符串,因为无法重新排列并得到子字符串 \"leet\" 。\n\n请你返回长度为 n 的好字符串 总 数目。\n\n由于答案可能很大,将答案对 109 + 7 取余 后返回。\n\n子字符串 是一个字符串中一段连续的字符序列。\n\n示例 1:\n\n输入:n = 4\n输出:12\n解释:总共有 12 个字符串重新排列后包含子字符串 \"leet\" :\"eelt\" ,\"eetl\" ,\"elet\" ,\"elte\" ,\"etel\" ,\"etle\" ,\"leet\" ,\"lete\" ,\"ltee\" ,\"teel\" ,\"tele\" 和 \"tlee\" 。\n\n示例 2:\n\n输入:n = 10\n输出:83943898\n解释:长度为 10 的字符串重新排列后包含子字符串 \"leet\" 的方案数为 526083947580 。所以答案为 526083947580 % (109 + 7) = 83943898 。\n\n\n提示:\n\n * 1 <= n <= 105\n\"\"\"\nclass Solution:\n def stringCount(self, n: int) -> int:\n ", "prompt_sft": "给你一个整数 n 。\n\n如果一个字符串 s 只包含小写英文字母,且 将 s 的字符重新排列后,新字符串包含 子字符串 \"leet\" ,那么我们称字符串 s 是一个 好 字符串。\n\n比方说:\n\n * 字符串 \"lteer\" 是好字符串,因为重新排列后可以得到 \"leetr\" 。\n * \"letl\" 不是好字符串,因为无法重新排列并得到子字符串 \"leet\" 。\n\n请你返回长度为 n 的好字符串 总 数目。\n\n由于答案可能很大,将答案对 109 + 7 取余 后返回。\n\n子字符串 是一个字符串中一段连续的字符序列。\n\n示例 1:\n\n输入:n = 4\n输出:12\n解释:总共有 12 个字符串重新排列后包含子字符串 \"leet\" :\"eelt\" ,\"eetl\" ,\"elet\" ,\"elte\" ,\"etel\" ,\"etle\" ,\"leet\" ,\"lete\" ,\"ltee\" ,\"teel\" ,\"tele\" 和 \"tlee\" 。\n\n示例 2:\n\n输入:n = 10\n输出:83943898\n解释:长度为 10 的字符串重新排列后包含子字符串 \"leet\" 的方案数为 526083947580 。所以答案为 526083947580 % (109 + 7) = 83943898 。\n\n\n提示:\n\n * 1 <= n <= 105\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def stringCount(self, n: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"n\": 4 }\nassert my_solution.stringCount(**test_input) == 12\n\ntest_input = { \"n\": 10 }\nassert my_solution.stringCount(**test_input) == 83943898\n\ntest_input = { \"n\": 1 }\nassert my_solution.stringCount(**test_input) == 0\n\ntest_input = { \"n\": 2 }\nassert my_solution.stringCount(**test_input) == 0\n\ntest_input = { \"n\": 3 }\nassert my_solution.stringCount(**test_input) == 0\n\ntest_input = { \"n\": 5 }\nassert my_solution.stringCount(**test_input) == 1460\n\ntest_input = { \"n\": 6 }\nassert my_solution.stringCount(**test_input) == 106620\n\ntest_input = { \"n\": 7 }\nassert my_solution.stringCount(**test_input) == 6058192\n\ntest_input = { \"n\": 8 }\nassert my_solution.stringCount(**test_input) == 295164156\n\ntest_input = { \"n\": 9 }\nassert my_solution.stringCount(**test_input) == 947613240\n\ntest_input = { \"n\": 11 }\nassert my_solution.stringCount(**test_input) == 795234177\n\ntest_input = { \"n\": 12 }\nassert my_solution.stringCount(**test_input) == 55396773\n\ntest_input = { \"n\": 13 }\nassert my_solution.stringCount(**test_input) == 968092561\n\ntest_input = { \"n\": 14 }\nassert my_solution.stringCount(**test_input) == 715599898\n\ntest_input = { \"n\": 15 }\nassert my_solution.stringCount(**test_input) == 430509685\n\ntest_input = { \"n\": 16 }\nassert my_solution.stringCount(**test_input) == 462719236\n\ntest_input = { \"n\": 17 }\nassert my_solution.stringCount(**test_input) == 155543310\n\ntest_input = { \"n\": 18 }\nassert my_solution.stringCount(**test_input) == 159683962\n\ntest_input = { \"n\": 19 }\nassert my_solution.stringCount(**test_input) == 808507313\n\ntest_input = { \"n\": 20 }\nassert my_solution.stringCount(**test_input) == 291395991\n\ntest_input = { \"n\": 21 }\nassert my_solution.stringCount(**test_input) == 461951930\n\ntest_input = { \"n\": 22 }\nassert my_solution.stringCount(**test_input) == 871561520\n\ntest_input = { \"n\": 23 }\nassert my_solution.stringCount(**test_input) == 993268925\n\ntest_input = { \"n\": 24 }\nassert my_solution.stringCount(**test_input) == 871982505\n\ntest_input = { \"n\": 25 }\nassert my_solution.stringCount(**test_input) == 935610434\n\ntest_input = { \"n\": 26 }\nassert my_solution.stringCount(**test_input) == 867518559\n\ntest_input = { \"n\": 27 }\nassert my_solution.stringCount(**test_input) == 3067523\n\ntest_input = { \"n\": 28 }\nassert my_solution.stringCount(**test_input) == 716801469\n\ntest_input = { \"n\": 29 }\nassert my_solution.stringCount(**test_input) == 452206104\n\ntest_input = { \"n\": 30 }\nassert my_solution.stringCount(**test_input) == 52805056\n\ntest_input = { \"n\": 31 }\nassert my_solution.stringCount(**test_input) == 61992724\n\ntest_input = { \"n\": 32 }\nassert my_solution.stringCount(**test_input) == 76928250\n\ntest_input = { \"n\": 33 }\nassert my_solution.stringCount(**test_input) == 257967635\n\ntest_input = { \"n\": 34 }\nassert my_solution.stringCount(**test_input) == 549347744\n\ntest_input = { \"n\": 35 }\nassert my_solution.stringCount(**test_input) == 290653839\n\ntest_input = { \"n\": 36 }\nassert my_solution.stringCount(**test_input) == 123906995\n\ntest_input = { \"n\": 37 }\nassert my_solution.stringCount(**test_input) == 41253530\n\ntest_input = { \"n\": 38 }\nassert my_solution.stringCount(**test_input) == 828924891\n\ntest_input = { \"n\": 39 }\nassert my_solution.stringCount(**test_input) == 60893212\n\ntest_input = { \"n\": 40 }\nassert my_solution.stringCount(**test_input) == 618599272\n\ntest_input = { \"n\": 41 }\nassert my_solution.stringCount(**test_input) == 840600409\n\ntest_input = { \"n\": 42 }\nassert my_solution.stringCount(**test_input) == 995406621\n\ntest_input = { \"n\": 43 }\nassert my_solution.stringCount(**test_input) == 991833054\n\ntest_input = { \"n\": 44 }\nassert my_solution.stringCount(**test_input) == 403185520\n\ntest_input = { \"n\": 45 }\nassert my_solution.stringCount(**test_input) == 904195428\n\ntest_input = { \"n\": 46 }\nassert my_solution.stringCount(**test_input) == 643609894\n\ntest_input = { \"n\": 47 }\nassert my_solution.stringCount(**test_input) == 177947842\n\ntest_input = { \"n\": 48 }\nassert my_solution.stringCount(**test_input) == 826753905\n\ntest_input = { \"n\": 49 }\nassert my_solution.stringCount(**test_input) == 855443295\n\ntest_input = { \"n\": 50 }\nassert my_solution.stringCount(**test_input) == 232825199\n\ntest_input = { \"n\": 51 }\nassert my_solution.stringCount(**test_input) == 227116084\n\ntest_input = { \"n\": 52 }\nassert my_solution.stringCount(**test_input) == 417264566\n\ntest_input = { \"n\": 53 }\nassert my_solution.stringCount(**test_input) == 468973861\n\ntest_input = { \"n\": 54 }\nassert my_solution.stringCount(**test_input) == 999145386\n\ntest_input = { \"n\": 55 }\nassert my_solution.stringCount(**test_input) == 721276317\n\ntest_input = { \"n\": 56 }\nassert my_solution.stringCount(**test_input) == 385673910\n\ntest_input = { \"n\": 57 }\nassert my_solution.stringCount(**test_input) == 7891114\n\ntest_input = { \"n\": 58 }\nassert my_solution.stringCount(**test_input) == 85081065\n\ntest_input = { \"n\": 59 }\nassert my_solution.stringCount(**test_input) == 194677227\n\ntest_input = { \"n\": 60 }\nassert my_solution.stringCount(**test_input) == 759126147\n\ntest_input = { \"n\": 61 }\nassert my_solution.stringCount(**test_input) == 273111337\n\ntest_input = { \"n\": 62 }\nassert my_solution.stringCount(**test_input) == 166598301\n\ntest_input = { \"n\": 63 }\nassert my_solution.stringCount(**test_input) == 955460796\n\ntest_input = { \"n\": 64 }\nassert my_solution.stringCount(**test_input) == 685704195\n\ntest_input = { \"n\": 65 }\nassert my_solution.stringCount(**test_input) == 821093882\n\ntest_input = { \"n\": 66 }\nassert my_solution.stringCount(**test_input) == 172674695\n\ntest_input = { \"n\": 67 }\nassert my_solution.stringCount(**test_input) == 464621746\n\ntest_input = { \"n\": 68 }\nassert my_solution.stringCount(**test_input) == 432202634\n\ntest_input = { \"n\": 69 }\nassert my_solution.stringCount(**test_input) == 465445347\n\ntest_input = { \"n\": 70 }\nassert my_solution.stringCount(**test_input) == 654273613\n\ntest_input = { \"n\": 71 }\nassert my_solution.stringCount(**test_input) == 366864502\n\ntest_input = { \"n\": 72 }\nassert my_solution.stringCount(**test_input) == 124689502\n\ntest_input = { \"n\": 73 }\nassert my_solution.stringCount(**test_input) == 419691288\n\ntest_input = { \"n\": 74 }\nassert my_solution.stringCount(**test_input) == 987033948\n\ntest_input = { \"n\": 75 }\nassert my_solution.stringCount(**test_input) == 842828500\n\ntest_input = { \"n\": 76 }\nassert my_solution.stringCount(**test_input) == 409614634\n\ntest_input = { \"n\": 77 }\nassert my_solution.stringCount(**test_input) == 73844796\n\ntest_input = { \"n\": 78 }\nassert my_solution.stringCount(**test_input) == 584672527\n\ntest_input = { \"n\": 79 }\nassert my_solution.stringCount(**test_input) == 113476429\n\ntest_input = { \"n\": 80 }\nassert my_solution.stringCount(**test_input) == 974106352\n\ntest_input = { \"n\": 81 }\nassert my_solution.stringCount(**test_input) == 646239862\n\ntest_input = { \"n\": 82 }\nassert my_solution.stringCount(**test_input) == 420253116\n\ntest_input = { \"n\": 83 }\nassert my_solution.stringCount(**test_input) == 817573615\n\ntest_input = { \"n\": 84 }\nassert my_solution.stringCount(**test_input) == 471199144\n\ntest_input = { \"n\": 85 }\nassert my_solution.stringCount(**test_input) == 567239979\n\ntest_input = { \"n\": 86 }\nassert my_solution.stringCount(**test_input) == 221534816\n\ntest_input = { \"n\": 87 }\nassert my_solution.stringCount(**test_input) == 707218848\n\ntest_input = { \"n\": 88 }\nassert my_solution.stringCount(**test_input) == 687360104\n\ntest_input = { \"n\": 89 }\nassert my_solution.stringCount(**test_input) == 551986596\n\ntest_input = { \"n\": 90 }\nassert my_solution.stringCount(**test_input) == 122933939\n\ntest_input = { \"n\": 91 }\nassert my_solution.stringCount(**test_input) == 427294641\n\ntest_input = { \"n\": 92 }\nassert my_solution.stringCount(**test_input) == 14022454\n\ntest_input = { \"n\": 93 }\nassert my_solution.stringCount(**test_input) == 568729284\n\ntest_input = { \"n\": 94 }\nassert my_solution.stringCount(**test_input) == 653568519\n\ntest_input = { \"n\": 95 }\nassert my_solution.stringCount(**test_input) == 15509440\n\ntest_input = { \"n\": 96 }\nassert my_solution.stringCount(**test_input) == 991824044\n\ntest_input = { \"n\": 97 }\nassert my_solution.stringCount(**test_input) == 690441338\n\ntest_input = { \"n\": 98 }\nassert my_solution.stringCount(**test_input) == 600462833\n\ntest_input = { \"n\": 99 }\nassert my_solution.stringCount(**test_input) == 880019356\n\ntest_input = { \"n\": 100 }\nassert my_solution.stringCount(**test_input) == 86731066", "start_time": 1699713000} +{"task_id": "biweekly-contest-117-maximum-spending-after-buying-items", "url": "https://leetcode.com/problems/maximum-spending-after-buying-items", "title": "maximum-spending-after-buying-items", "meta": {"questionId": "3107", "questionFrontendId": "2931", "title": "Maximum Spending After Buying Items", "titleSlug": "maximum-spending-after-buying-items", "isPaidOnly": false, "difficulty": "Hard", "likes": 66, "dislikes": 20, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0 开始大小为 m * n 的整数矩阵 values ,表示 m 个不同商店里 m * n 件不同的物品。每个商店有 n 件物品,第 i 个商店的第 j 件物品的价值为 values[i][j] 。除此以外,第 i 个商店的物品已经按照价值非递增排好序了,也就是说对于所有 0 <= j < n - 1 都有 values[i][j] >= values[i][j + 1] 。\n\n每一天,你可以在一个商店里购买一件物品。具体来说,在第 d 天,你可以:\n\n * 选择商店 i 。\n * 购买数组中最右边的物品 j ,开销为 values[i][j] * d 。换句话说,选择该商店中还没购买过的物品中最大的下标 j ,并且花费 values[i][j] * d 去购买。\n\n注意,所有物品都视为不同的物品。比方说如果你已经从商店 1 购买了物品 0 ,你还可以在别的商店里购买其他商店的物品 0 。\n\n请你返回购买所有 m * n 件物品需要的 最大开销 。\n\n示例 1:\n\n输入:values = [[8,5,2],[6,4,1],[9,7,3]]\n输出:285\n解释:第一天,从商店 1 购买物品 2 ,开销为 values[1][2] * 1 = 1 。\n第二天,从商店 0 购买物品 2 ,开销为 values[0][2] * 2 = 4 。\n第三天,从商店 2 购买物品 2 ,开销为 values[2][2] * 3 = 9 。\n第四天,从商店 1 购买物品 1 ,开销为 values[1][1] * 4 = 16 。\n第五天,从商店 0 购买物品 1 ,开销为 values[0][1] * 5 = 25 。\n第六天,从商店 1 购买物品 0 ,开销为 values[1][0] * 6 = 36 。\n第七天,从商店 2 购买物品 1 ,开销为 values[2][1] * 7 = 49 。\n第八天,从商店 0 购买物品 0 ,开销为 values[0][0] * 8 = 64 。\n第九天,从商店 2 购买物品 0 ,开销为 values[2][0] * 9 = 81 。\n所以总开销为 285 。\n285 是购买所有 m * n 件物品的最大总开销。\n\n示例 2:\n\n输入:values = [[10,8,6,4,2],[9,7,5,3,2]]\n输出:386\n解释:第一天,从商店 0 购买物品 4 ,开销为 values[0][4] * 1 = 2 。\n第二天,从商店 1 购买物品 4 ,开销为 values[1][4] * 2 = 4 。\n第三天,从商店 1 购买物品 3 ,开销为 values[1][3] * 3 = 9 。\n第四天,从商店 0 购买物品 3 ,开销为 values[0][3] * 4 = 16 。\n第五天,从商店 1 购买物品 2 ,开销为 values[1][2] * 5 = 25 。\n第六天,从商店 0 购买物品 2 ,开销为 values[0][2] * 6 = 36 。\n第七天,从商店 1 购买物品 1 ,开销为 values[1][1] * 7 = 49 。\n第八天,从商店 0 购买物品 1 ,开销为 values[0][1] * 8 = 64 。\n第九天,从商店 1 购买物品 0 ,开销为 values[1][0] * 9 = 81 。\n第十天,从商店 0 购买物品 0 ,开销为 values[0][0] * 10 = 100 。\n所以总开销为 386 。\n386 是购买所有 m * n 件物品的最大总开销。\n\n\n提示:\n\n * 1 <= m == values.length <= 10\n * 1 <= n == values[i].length <= 104\n * 1 <= values[i][j] <= 106\n * values[i] 按照非递增顺序排序。\n\"\"\"\nclass Solution:\n def maxSpending(self, values: List[List[int]]) -> int:\n ", "prompt_sft": "给你一个下标从 0 开始大小为 m * n 的整数矩阵 values ,表示 m 个不同商店里 m * n 件不同的物品。每个商店有 n 件物品,第 i 个商店的第 j 件物品的价值为 values[i][j] 。除此以外,第 i 个商店的物品已经按照价值非递增排好序了,也就是说对于所有 0 <= j < n - 1 都有 values[i][j] >= values[i][j + 1] 。\n\n每一天,你可以在一个商店里购买一件物品。具体来说,在第 d 天,你可以:\n\n * 选择商店 i 。\n * 购买数组中最右边的物品 j ,开销为 values[i][j] * d 。换句话说,选择该商店中还没购买过的物品中最大的下标 j ,并且花费 values[i][j] * d 去购买。\n\n注意,所有物品都视为不同的物品。比方说如果你已经从商店 1 购买了物品 0 ,你还可以在别的商店里购买其他商店的物品 0 。\n\n请你返回购买所有 m * n 件物品需要的 最大开销 。\n\n示例 1:\n\n输入:values = [[8,5,2],[6,4,1],[9,7,3]]\n输出:285\n解释:第一天,从商店 1 购买物品 2 ,开销为 values[1][2] * 1 = 1 。\n第二天,从商店 0 购买物品 2 ,开销为 values[0][2] * 2 = 4 。\n第三天,从商店 2 购买物品 2 ,开销为 values[2][2] * 3 = 9 。\n第四天,从商店 1 购买物品 1 ,开销为 values[1][1] * 4 = 16 。\n第五天,从商店 0 购买物品 1 ,开销为 values[0][1] * 5 = 25 。\n第六天,从商店 1 购买物品 0 ,开销为 values[1][0] * 6 = 36 。\n第七天,从商店 2 购买物品 1 ,开销为 values[2][1] * 7 = 49 。\n第八天,从商店 0 购买物品 0 ,开销为 values[0][0] * 8 = 64 。\n第九天,从商店 2 购买物品 0 ,开销为 values[2][0] * 9 = 81 。\n所以总开销为 285 。\n285 是购买所有 m * n 件物品的最大总开销。\n\n示例 2:\n\n输入:values = [[10,8,6,4,2],[9,7,5,3,2]]\n输出:386\n解释:第一天,从商店 0 购买物品 4 ,开销为 values[0][4] * 1 = 2 。\n第二天,从商店 1 购买物品 4 ,开销为 values[1][4] * 2 = 4 。\n第三天,从商店 1 购买物品 3 ,开销为 values[1][3] * 3 = 9 。\n第四天,从商店 0 购买物品 3 ,开销为 values[0][3] * 4 = 16 。\n第五天,从商店 1 购买物品 2 ,开销为 values[1][2] * 5 = 25 。\n第六天,从商店 0 购买物品 2 ,开销为 values[0][2] * 6 = 36 。\n第七天,从商店 1 购买物品 1 ,开销为 values[1][1] * 7 = 49 。\n第八天,从商店 0 购买物品 1 ,开销为 values[0][1] * 8 = 64 。\n第九天,从商店 1 购买物品 0 ,开销为 values[1][0] * 9 = 81 。\n第十天,从商店 0 购买物品 0 ,开销为 values[0][0] * 10 = 100 。\n所以总开销为 386 。\n386 是购买所有 m * n 件物品的最大总开销。\n\n\n提示:\n\n * 1 <= m == values.length <= 10\n * 1 <= n == values[i].length <= 104\n * 1 <= values[i][j] <= 106\n * values[i] 按照非递增顺序排序。\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def maxSpending(self, values: List[List[int]]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"values\": [[8,5,2],[6,4,1],[9,7,3]] }\nassert my_solution.maxSpending(**test_input) == 285\n\ntest_input = { \"values\": [[10,8,6,4,2],[9,7,5,3,2]] }\nassert my_solution.maxSpending(**test_input) == 386\n\ntest_input = { \"values\": [[1000000]] }\nassert my_solution.maxSpending(**test_input) == 1000000\n\ntest_input = { \"values\": [[1]] }\nassert my_solution.maxSpending(**test_input) == 1\n\ntest_input = { \"values\": [[1],[2]] }\nassert my_solution.maxSpending(**test_input) == 5\n\ntest_input = { \"values\": [[2],[1]] }\nassert my_solution.maxSpending(**test_input) == 5\n\ntest_input = { \"values\": [[1],[1]] }\nassert my_solution.maxSpending(**test_input) == 3\n\ntest_input = { \"values\": [[5,2]] }\nassert my_solution.maxSpending(**test_input) == 12\n\ntest_input = { \"values\": [[5,5]] }\nassert my_solution.maxSpending(**test_input) == 15\n\ntest_input = { \"values\": [[7,5]] }\nassert my_solution.maxSpending(**test_input) == 19\n\ntest_input = { \"values\": [[3,2,1]] }\nassert my_solution.maxSpending(**test_input) == 14\n\ntest_input = { \"values\": [[2,2,1]] }\nassert my_solution.maxSpending(**test_input) == 11\n\ntest_input = { \"values\": [[3,3,2]] }\nassert my_solution.maxSpending(**test_input) == 17\n\ntest_input = { \"values\": [[3],[2],[1]] }\nassert my_solution.maxSpending(**test_input) == 14\n\ntest_input = { \"values\": [[2],[10],[1]] }\nassert my_solution.maxSpending(**test_input) == 35\n\ntest_input = { \"values\": [[1000000,1000000,1000000]] }\nassert my_solution.maxSpending(**test_input) == 6000000\n\ntest_input = { \"values\": [[1000000,1000000,1000000,1000000]] }\nassert my_solution.maxSpending(**test_input) == 10000000\n\ntest_input = { \"values\": [[1000000],[1000000],[1000000],[1000000]] }\nassert my_solution.maxSpending(**test_input) == 10000000\n\ntest_input = { \"values\": [[1000000,1000000],[1000000,1000000]] }\nassert my_solution.maxSpending(**test_input) == 10000000\n\ntest_input = { \"values\": [[2,1],[4,3]] }\nassert my_solution.maxSpending(**test_input) == 30\n\ntest_input = { \"values\": [[3,1],[4,2]] }\nassert my_solution.maxSpending(**test_input) == 30\n\ntest_input = { \"values\": [[4,1],[3,2]] }\nassert my_solution.maxSpending(**test_input) == 30\n\ntest_input = { \"values\": [[15,13,13,12,12,12,12,11,11,11,11,9,9,8,7,5,5,5,1]] }\nassert my_solution.maxSpending(**test_input) == 2162\n\ntest_input = { \"values\": [[13,13,11,7,2,1],[13,10,10,6,3,3]] }\nassert my_solution.maxSpending(**test_input) == 776\n\ntest_input = { \"values\": [[12,6],[13,5],[13,3],[6,6],[15,6],[5,4],[6,1]] }\nassert my_solution.maxSpending(**test_input) == 971\n\ntest_input = { \"values\": [[15,15,14,14,14,10,10,9,9,8,8,8,7,7,7,4]] }\nassert my_solution.maxSpending(**test_input) == 1585\n\ntest_input = { \"values\": [[11,10],[10,1],[14,6],[13,5],[7,3],[10,10],[10,5]] }\nassert my_solution.maxSpending(**test_input) == 1061\n\ntest_input = { \"values\": [[15,13,12,7,6,4,1]] }\nassert my_solution.maxSpending(**test_input) == 298\n\ntest_input = { \"values\": [[8,2],[4,1],[10,4]] }\nassert my_solution.maxSpending(**test_input) == 133\n\ntest_input = { \"values\": [[10,4],[13,2],[7,5],[15,11]] }\nassert my_solution.maxSpending(**test_input) == 380\n\ntest_input = { \"values\": [[13,10,10,9,8,5,5,2,1,1]] }\nassert my_solution.maxSpending(**test_input) == 465\n\ntest_input = { \"values\": [[15,14,8,7,5,5,1]] }\nassert my_solution.maxSpending(**test_input) == 283\n\ntest_input = { \"values\": [[15,15,14,14,14,14,13,11,10,10,10,9,7,7,6,6,4,4,2,1]] }\nassert my_solution.maxSpending(**test_input) == 2449\n\ntest_input = { \"values\": [[15,14,11,10,10,6,2],[13,8,8,6,6,3,2]] }\nassert my_solution.maxSpending(**test_input) == 1084\n\ntest_input = { \"values\": [[15,15,14,13,13,12,11,9,9,9,8,6,5,5,4,3,2,1,1]] }\nassert my_solution.maxSpending(**test_input) == 2030\n\ntest_input = { \"values\": [[15,10,7],[14,2,2],[14,13,12],[13,13,10]] }\nassert my_solution.maxSpending(**test_input) == 975\n\ntest_input = { \"values\": [[10,9,3,3],[11,8,7,2],[14,14,13,1],[14,14,11,4],[13,11,9,5]] }\nassert my_solution.maxSpending(**test_input) == 2338\n\ntest_input = { \"values\": [[11,7,5,2],[15,5,5,3]] }\nassert my_solution.maxSpending(**test_input) == 307\n\ntest_input = { \"values\": [[15,10,10,9,8,7,4,2,2]] }\nassert my_solution.maxSpending(**test_input) == 425\n\ntest_input = { \"values\": [[15,13,12,12,10,5,4,3,1]] }\nassert my_solution.maxSpending(**test_input) == 484\n\ntest_input = { \"values\": [[12,12,12,11,10,10,7,7,6,5,5,3,2,1]] }\nassert my_solution.maxSpending(**test_input) == 979\n\ntest_input = { \"values\": [[15,13,13,13,12,12,11,11,10,9,9,9,8,6,6,4,4,3,2,1]] }\nassert my_solution.maxSpending(**test_input) == 2253\n\ntest_input = { \"values\": [[14,11],[11,8],[10,4],[4,3],[9,6],[8,4],[7,7],[10,4],[14,4]] }\nassert my_solution.maxSpending(**test_input) == 1621\n\ntest_input = { \"values\": [[14,13,13,11,11,8,8,7,6,4,3,2,1]] }\nassert my_solution.maxSpending(**test_input) == 912\n\ntest_input = { \"values\": [[15,14,14,10,10,9,9,7,7,7,7,7,6,6,6,4,4,3,3]] }\nassert my_solution.maxSpending(**test_input) == 1823\n\ntest_input = { \"values\": [[14,13,11,10,10,1,1],[15,12,8,6,6,5,5]] }\nassert my_solution.maxSpending(**test_input) == 1120\n\ntest_input = { \"values\": [[15,14,13,12,11,10,10,10,9,7,6,6,4,3,3,3,2,2,1]] }\nassert my_solution.maxSpending(**test_input) == 1860\n\ntest_input = { \"values\": [[12,6,5,4,2]] }\nassert my_solution.maxSpending(**test_input) == 109\n\ntest_input = { \"values\": [[15,15,14,13,12,12,12,11,10,10,9,9,9,8,7,6,3,2]] }\nassert my_solution.maxSpending(**test_input) == 2006\n\ntest_input = { \"values\": [[15,14,12,11,10,10,7,6,2,1]] }\nassert my_solution.maxSpending(**test_input) == 610\n\ntest_input = { \"values\": [[15,13,12,11,8,6,5]] }\nassert my_solution.maxSpending(**test_input) == 328\n\ntest_input = { \"values\": [[15,15,12,10,9,7,7,6,6,5,4,2,1]] }\nassert my_solution.maxSpending(**test_input) == 896\n\ntest_input = { \"values\": [[15,15,12,12,10,10,9,7,6,4,4,4,1]] }\nassert my_solution.maxSpending(**test_input) == 969\n\ntest_input = { \"values\": [[15,14,14,13,8,7,7,4,3,3,2,1]] }\nassert my_solution.maxSpending(**test_input) == 792\n\ntest_input = { \"values\": [[15,15,14,14,14,13,10,8,6,6,5,5,3,3,2,2,1]] }\nassert my_solution.maxSpending(**test_input) == 1634\n\ntest_input = { \"values\": [[14,12,11,10,10,8,7,7,5,5,3,3,3]] }\nassert my_solution.maxSpending(**test_input) == 855\n\ntest_input = { \"values\": [[14,14,9,9,4,4,1],[12,12,9,8,7,6,3]] }\nassert my_solution.maxSpending(**test_input) == 1060\n\ntest_input = { \"values\": [[15,15,15,13,12,12,10,9,9,9,9,7,6,4,4,4,1]] }\nassert my_solution.maxSpending(**test_input) == 1727\n\ntest_input = { \"values\": [[9,4],[13,4],[13,9],[6,5],[8,2],[13,1]] }\nassert my_solution.maxSpending(**test_input) == 732\n\ntest_input = { \"values\": [[14,9,9,9,8,7,5],[15,14,10,8,5,3,1]] }\nassert my_solution.maxSpending(**test_input) == 1094\n\ntest_input = { \"values\": [[15,15,14,13,10,3,1]] }\nassert my_solution.maxSpending(**test_input) == 354\n\ntest_input = { \"values\": [[13,12],[13,12],[11,8],[14,3]] }\nassert my_solution.maxSpending(**test_input) == 441\n\ntest_input = { \"values\": [[13,12,11,10,7,5,5,1]] }\nassert my_solution.maxSpending(**test_input) == 358\n\ntest_input = { \"values\": [[15,10,9,8,8,7,7,5,4,3,1]] }\nassert my_solution.maxSpending(**test_input) == 582\n\ntest_input = { \"values\": [[10,10,6,4,1],[14,13,13,11,9],[14,11,7,4,3]] }\nassert my_solution.maxSpending(**test_input) == 1302\n\ntest_input = { \"values\": [[15,14,12,12,11,11,10,9,9,8,8,6,6,4,2,2,1]] }\nassert my_solution.maxSpending(**test_input) == 1596\n\ntest_input = { \"values\": [[12,5,4,3,3,2,1,1],[13,11,9,9,6,4,3,1]] }\nassert my_solution.maxSpending(**test_input) == 1019\n\ntest_input = { \"values\": [[15,15,13,11,10,10,7,1,1]] }\nassert my_solution.maxSpending(**test_input) == 526\n\ntest_input = { \"values\": [[14,12,10,4,3,1],[12,12,8,7,6,2],[15,13,8,5,4,1]] }\nassert my_solution.maxSpending(**test_input) == 1719\n\ntest_input = { \"values\": [[13,8,8,8,5,4,3],[15,13,9,8,7,3,2]] }\nassert my_solution.maxSpending(**test_input) == 1006\n\ntest_input = { \"values\": [[13,13,12,12,9]] }\nassert my_solution.maxSpending(**test_input) == 186\n\ntest_input = { \"values\": [[10,3],[11,9],[10,5],[8,7],[6,1]] }\nassert my_solution.maxSpending(**test_input) == 472\n\ntest_input = { \"values\": [[15,15,12,12,11,10,9,8,2,2,1,1,1]] }\nassert my_solution.maxSpending(**test_input) == 941\n\ntest_input = { \"values\": [[14,14,13,13,11,11,10,10,10,9,8,8,7,7,6,6,5,4,3]] }\nassert my_solution.maxSpending(**test_input) == 2023\n\ntest_input = { \"values\": [[11,10,9,7,6,5,3,1],[14,14,10,9,7,4,4,3]] }\nassert my_solution.maxSpending(**test_input) == 1270\n\ntest_input = { \"values\": [[6,2],[10,2],[13,5],[8,7],[10,3],[13,2],[13,6]] }\nassert my_solution.maxSpending(**test_input) == 972\n\ntest_input = { \"values\": [[15,15,15,14,13,12,6,5,5,4]] }\nassert my_solution.maxSpending(**test_input) == 694\n\ntest_input = { \"values\": [[11,9],[8,1],[2,1],[15,13],[12,4],[14,5],[13,4]] }\nassert my_solution.maxSpending(**test_input) == 1113\n\ntest_input = { \"values\": [[15,14,14,13,12,11,10,10,5,4,2]] }\nassert my_solution.maxSpending(**test_input) == 800\n\ntest_input = { \"values\": [[13,12,12,6,5,5,4,2,2,2,1]] }\nassert my_solution.maxSpending(**test_input) == 523\n\ntest_input = { \"values\": [[13,8],[15,1],[9,1],[13,1]] }\nassert my_solution.maxSpending(**test_input) == 372\n\ntest_input = { \"values\": [[12,8,4,1],[14,8,8,3]] }\nassert my_solution.maxSpending(**test_input) == 335\n\ntest_input = { \"values\": [[15,14,14,13,13,13,12,12,9,9,8,7,6,5,5,5,4,3,1]] }\nassert my_solution.maxSpending(**test_input) == 2113\n\ntest_input = { \"values\": [[13,9,8,2,1],[9,4,3,2,1],[10,8,6,3,1]] }\nassert my_solution.maxSpending(**test_input) == 877\n\ntest_input = { \"values\": [[8,6],[13,1],[12,8],[8,7]] }\nassert my_solution.maxSpending(**test_input) == 342\n\ntest_input = { \"values\": [[9,7],[15,15],[9,8],[6,1],[11,4]] }\nassert my_solution.maxSpending(**test_input) == 585\n\ntest_input = { \"values\": [[14,9,9,8,6,4,2]] }\nassert my_solution.maxSpending(**test_input) == 257\n\ntest_input = { \"values\": [[15,13,11,11,10,9,5,5,4,4,4,4,3,2]] }\nassert my_solution.maxSpending(**test_input) == 968\n\ntest_input = { \"values\": [[13,7,7,4],[8,8,6,6]] }\nassert my_solution.maxSpending(**test_input) == 305\n\ntest_input = { \"values\": [[15,13,12,10,10,10,9,9,9,8,7,6,6,5,4,4,2,1,1]] }\nassert my_solution.maxSpending(**test_input) == 1805\n\ntest_input = { \"values\": [[13,13,1],[11,5,4],[14,5,1],[15,5,2],[10,1,1],[15,12,1]] }\nassert my_solution.maxSpending(**test_input) == 1714\n\ntest_input = { \"values\": [[15,15,14,14,11,10,10,8,8,8,3,1,1]] }\nassert my_solution.maxSpending(**test_input) == 1050\n\ntest_input = { \"values\": [[3,3],[15,10],[14,9]] }\nassert my_solution.maxSpending(**test_input) == 236\n\ntest_input = { \"values\": [[14,13,11,10,9,7,2]] }\nassert my_solution.maxSpending(**test_input) == 314\n\ntest_input = { \"values\": [[11,7],[5,3],[11,6],[6,1],[15,13]] }\nassert my_solution.maxSpending(**test_input) == 550\n\ntest_input = { \"values\": [[14,13,13,12,12,12,11,11,9,8,8,6,5,5,5,5,3,3,2]] }\nassert my_solution.maxSpending(**test_input) == 1962\n\ntest_input = { \"values\": [[14,14,13,13,13,12,12,11,10,9,9,8,8,7,3,2,2]] }\nassert my_solution.maxSpending(**test_input) == 1750\n\ntest_input = { \"values\": [[15,8],[12,2],[15,10],[9,3],[5,4],[14,2],[7,6]] }\nassert my_solution.maxSpending(**test_input) == 1091\n\ntest_input = { \"values\": [[15,9,7,3,3],[7,6,4,3,2],[15,9,8,4,4],[15,10,9,7,4]] }\nassert my_solution.maxSpending(**test_input) == 1952\n\ntest_input = { \"values\": [[12,12,10,8,8,8,8,6,2,2,1]] }\nassert my_solution.maxSpending(**test_input) == 585", "start_time": 1699713000} +{"task_id": "weekly-contest-370-find-champion-i", "url": "https://leetcode.com/problems/find-champion-i", "title": "find-champion-i", "meta": {"questionId": "3188", "questionFrontendId": "2923", "title": "Find Champion I", "titleSlug": "find-champion-i", "isPaidOnly": false, "difficulty": "Easy", "likes": 84, "dislikes": 20, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n一场比赛中共有 n 支队伍,按从 0 到  n - 1 编号。\n\n给你一个下标从 0 开始、大小为 n * n 的二维布尔矩阵 grid 。对于满足 0 <= i, j <= n - 1 且 i != j 的所有 i, j :如果 grid[i][j] == 1,那么 i 队比 j 队 强 ;否则,j 队比 i 队 强 。\n\n在这场比赛中,如果不存在某支强于 a 队的队伍,则认为 a 队将会是 冠军 。\n\n返回这场比赛中将会成为冠军的队伍。\n\n示例 1:\n\n输入:grid = [[0,1],[0,0]]\n输出:0\n解释:比赛中有两支队伍。\ngrid[0][1] == 1 表示 0 队比 1 队强。所以 0 队是冠军。\n\n示例 2:\n\n输入:grid = [[0,0,1],[1,0,1],[0,0,0]]\n输出:1\n解释:比赛中有三支队伍。\ngrid[1][0] == 1 表示 1 队比 0 队强。\ngrid[1][2] == 1 表示 1 队比 2 队强。\n所以 1 队是冠军。\n\n\n提示:\n\n * n == grid.length\n * n == grid[i].length\n * 2 <= n <= 100\n * grid[i][j] 的值为 0 或 1\n * 对于所有 i, grid[i][i] 等于 0.\n * 对于满足 i != j 的所有 i, j ,grid[i][j] != grid[j][i] 均成立\n * 生成的输入满足:如果 a 队比 b 队强,b 队比 c 队强,那么 a 队比 c 队强\n\"\"\"\nclass Solution:\n def findChampion(self, grid: List[List[int]]) -> int:\n ", "prompt_sft": "一场比赛中共有 n 支队伍,按从 0 到  n - 1 编号。\n\n给你一个下标从 0 开始、大小为 n * n 的二维布尔矩阵 grid 。对于满足 0 <= i, j <= n - 1 且 i != j 的所有 i, j :如果 grid[i][j] == 1,那么 i 队比 j 队 强 ;否则,j 队比 i 队 强 。\n\n在这场比赛中,如果不存在某支强于 a 队的队伍,则认为 a 队将会是 冠军 。\n\n返回这场比赛中将会成为冠军的队伍。\n\n示例 1:\n\n输入:grid = [[0,1],[0,0]]\n输出:0\n解释:比赛中有两支队伍。\ngrid[0][1] == 1 表示 0 队比 1 队强。所以 0 队是冠军。\n\n示例 2:\n\n输入:grid = [[0,0,1],[1,0,1],[0,0,0]]\n输出:1\n解释:比赛中有三支队伍。\ngrid[1][0] == 1 表示 1 队比 0 队强。\ngrid[1][2] == 1 表示 1 队比 2 队强。\n所以 1 队是冠军。\n\n\n提示:\n\n * n == grid.length\n * n == grid[i].length\n * 2 <= n <= 100\n * grid[i][j] 的值为 0 或 1\n * 对于所有 i, grid[i][i] 等于 0.\n * 对于满足 i != j 的所有 i, j ,grid[i][j] != grid[j][i] 均成立\n * 生成的输入满足:如果 a 队比 b 队强,b 队比 c 队强,那么 a 队比 c 队强\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def findChampion(self, grid: List[List[int]]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"grid\": [[0,1],[0,0]] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"grid\": [[0,0,1],[1,0,1],[0,0,0]] }\nassert my_solution.findChampion(**test_input) == 1\n\ntest_input = { \"grid\": [[0,0],[1,0]] }\nassert my_solution.findChampion(**test_input) == 1\n\ntest_input = { \"grid\": [[0,0,0],[1,0,0],[1,1,0]] }\nassert my_solution.findChampion(**test_input) == 2\n\ntest_input = { \"grid\": [[0,0,0],[1,0,1],[1,0,0]] }\nassert my_solution.findChampion(**test_input) == 1\n\ntest_input = { \"grid\": [[0,1,0],[0,0,0],[1,1,0]] }\nassert my_solution.findChampion(**test_input) == 2\n\ntest_input = { \"grid\": [[0,1,1],[0,0,0],[0,1,0]] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"grid\": [[0,1,1],[0,0,1],[0,0,0]] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"grid\": [[0,0,0,0],[1,0,0,0],[1,1,0,0],[1,1,1,0]] }\nassert my_solution.findChampion(**test_input) == 3\n\ntest_input = { \"grid\": [[0,0,0,0],[1,0,0,0],[1,1,0,1],[1,1,0,0]] }\nassert my_solution.findChampion(**test_input) == 2\n\ntest_input = { \"grid\": [[0,0,0,0],[1,0,0,1],[1,1,0,1],[1,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 2\n\ntest_input = { \"grid\": [[0,0,0,0],[1,0,1,0],[1,0,0,0],[1,1,1,0]] }\nassert my_solution.findChampion(**test_input) == 3\n\ntest_input = { \"grid\": [[0,0,0,0],[1,0,1,1],[1,0,0,0],[1,0,1,0]] }\nassert my_solution.findChampion(**test_input) == 1\n\ntest_input = { \"grid\": [[0,0,0,0],[1,0,1,1],[1,0,0,1],[1,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 1\n\ntest_input = { \"grid\": [[0,0,0,1],[1,0,0,1],[1,1,0,1],[0,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 2\n\ntest_input = { \"grid\": [[0,0,0,1],[1,0,1,1],[1,0,0,1],[0,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 1\n\ntest_input = { \"grid\": [[0,0,1,0],[1,0,1,0],[0,0,0,0],[1,1,1,0]] }\nassert my_solution.findChampion(**test_input) == 3\n\ntest_input = { \"grid\": [[0,0,1,0],[1,0,1,1],[0,0,0,0],[1,0,1,0]] }\nassert my_solution.findChampion(**test_input) == 1\n\ntest_input = { \"grid\": [[0,0,1,1],[1,0,1,1],[0,0,0,0],[0,0,1,0]] }\nassert my_solution.findChampion(**test_input) == 1\n\ntest_input = { \"grid\": [[0,0,1,1],[1,0,1,1],[0,0,0,1],[0,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 1\n\ntest_input = { \"grid\": [[0,1,0,0],[0,0,0,0],[1,1,0,0],[1,1,1,0]] }\nassert my_solution.findChampion(**test_input) == 3\n\ntest_input = { \"grid\": [[0,1,0,0],[0,0,0,0],[1,1,0,1],[1,1,0,0]] }\nassert my_solution.findChampion(**test_input) == 2\n\ntest_input = { \"grid\": [[0,1,0,1],[0,0,0,0],[1,1,0,1],[0,1,0,0]] }\nassert my_solution.findChampion(**test_input) == 2\n\ntest_input = { \"grid\": [[0,1,0,1],[0,0,0,1],[1,1,0,1],[0,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 2\n\ntest_input = { \"grid\": [[0,1,1,0],[0,0,0,0],[0,1,0,0],[1,1,1,0]] }\nassert my_solution.findChampion(**test_input) == 3\n\ntest_input = { \"grid\": [[0,1,1,0],[0,0,1,0],[0,0,0,0],[1,1,1,0]] }\nassert my_solution.findChampion(**test_input) == 3\n\ntest_input = { \"grid\": [[0,1,1,1],[0,0,0,0],[0,1,0,0],[0,1,1,0]] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"grid\": [[0,1,1,1],[0,0,0,0],[0,1,0,1],[0,1,0,0]] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"grid\": [[0,1,1,1],[0,0,0,1],[0,1,0,1],[0,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"grid\": [[0,1,1,1],[0,0,1,0],[0,0,0,0],[0,1,1,0]] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"grid\": [[0,1,1,1],[0,0,1,1],[0,0,0,0],[0,0,1,0]] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"grid\": [[0,1,1,1],[0,0,1,1],[0,0,0,1],[0,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"grid\": [[0,0,0,0,0],[1,0,0,0,0],[1,1,0,0,0],[1,1,1,0,1],[1,1,1,0,0]] }\nassert my_solution.findChampion(**test_input) == 3\n\ntest_input = { \"grid\": [[0,0,0,0,0],[1,0,0,0,0],[1,1,0,1,0],[1,1,0,0,0],[1,1,1,1,0]] }\nassert my_solution.findChampion(**test_input) == 4\n\ntest_input = { \"grid\": [[0,0,0,0,0],[1,0,0,0,0],[1,1,0,1,1],[1,1,0,0,0],[1,1,0,1,0]] }\nassert my_solution.findChampion(**test_input) == 2\n\ntest_input = { \"grid\": [[0,0,0,0,0],[1,0,0,0,0],[1,1,0,1,1],[1,1,0,0,1],[1,1,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 2\n\ntest_input = { \"grid\": [[0,0,0,0,0],[1,0,0,0,1],[1,1,0,0,1],[1,1,1,0,1],[1,0,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 3\n\ntest_input = { \"grid\": [[0,0,0,0,0],[1,0,0,0,1],[1,1,0,1,1],[1,1,0,0,1],[1,0,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 2\n\ntest_input = { \"grid\": [[0,0,0,0,0],[1,0,0,1,0],[1,1,0,1,0],[1,0,0,0,0],[1,1,1,1,0]] }\nassert my_solution.findChampion(**test_input) == 4\n\ntest_input = { \"grid\": [[0,0,0,0,0],[1,0,0,1,0],[1,1,0,1,1],[1,0,0,0,0],[1,1,0,1,0]] }\nassert my_solution.findChampion(**test_input) == 2\n\ntest_input = { \"grid\": [[0,0,0,0,0],[1,0,0,1,1],[1,1,0,1,1],[1,0,0,0,1],[1,0,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 2\n\ntest_input = { \"grid\": [[0,0,0,0,0],[1,0,1,0,1],[1,0,0,0,0],[1,1,1,0,1],[1,0,1,0,0]] }\nassert my_solution.findChampion(**test_input) == 3\n\ntest_input = { \"grid\": [[0,0,0,0,0],[1,0,1,1,0],[1,0,0,0,0],[1,0,1,0,0],[1,1,1,1,0]] }\nassert my_solution.findChampion(**test_input) == 4\n\ntest_input = { \"grid\": [[0,0,0,0,0],[1,0,1,1,0],[1,0,0,1,0],[1,0,0,0,0],[1,1,1,1,0]] }\nassert my_solution.findChampion(**test_input) == 4\n\ntest_input = { \"grid\": [[0,0,0,0,0],[1,0,1,1,1],[1,0,0,0,0],[1,0,1,0,1],[1,0,1,0,0]] }\nassert my_solution.findChampion(**test_input) == 1\n\ntest_input = { \"grid\": [[0,0,0,0,0],[1,0,1,1,1],[1,0,0,0,1],[1,0,1,0,1],[1,0,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 1\n\ntest_input = { \"grid\": [[0,0,0,0,0],[1,0,1,1,1],[1,0,0,1,1],[1,0,0,0,1],[1,0,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 1\n\ntest_input = { \"grid\": [[0,0,0,0,1],[1,0,0,0,1],[1,1,0,0,1],[1,1,1,0,1],[0,0,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 3\n\ntest_input = { \"grid\": [[0,0,0,0,1],[1,0,0,0,1],[1,1,0,1,1],[1,1,0,0,1],[0,0,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 2\n\ntest_input = { \"grid\": [[0,0,0,0,1],[1,0,0,1,1],[1,1,0,1,1],[1,0,0,0,1],[0,0,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 2\n\ntest_input = { \"grid\": [[0,0,0,0,1],[1,0,1,1,1],[1,0,0,0,1],[1,0,1,0,1],[0,0,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 1\n\ntest_input = { \"grid\": [[0,0,0,1,0],[1,0,0,1,0],[1,1,0,1,0],[0,0,0,0,0],[1,1,1,1,0]] }\nassert my_solution.findChampion(**test_input) == 4\n\ntest_input = { \"grid\": [[0,0,0,1,0],[1,0,0,1,0],[1,1,0,1,1],[0,0,0,0,0],[1,1,0,1,0]] }\nassert my_solution.findChampion(**test_input) == 2\n\ntest_input = { \"grid\": [[0,0,0,1,0],[1,0,0,1,1],[1,1,0,1,1],[0,0,0,0,0],[1,0,0,1,0]] }\nassert my_solution.findChampion(**test_input) == 2\n\ntest_input = { \"grid\": [[0,0,0,1,0],[1,0,1,1,0],[1,0,0,1,0],[0,0,0,0,0],[1,1,1,1,0]] }\nassert my_solution.findChampion(**test_input) == 4\n\ntest_input = { \"grid\": [[0,0,0,1,0],[1,0,1,1,1],[1,0,0,1,0],[0,0,0,0,0],[1,0,1,1,0]] }\nassert my_solution.findChampion(**test_input) == 1\n\ntest_input = { \"grid\": [[0,0,0,1,0],[1,0,1,1,1],[1,0,0,1,1],[0,0,0,0,0],[1,0,0,1,0]] }\nassert my_solution.findChampion(**test_input) == 1\n\ntest_input = { \"grid\": [[0,0,0,1,1],[1,0,0,1,1],[1,1,0,1,1],[0,0,0,0,0],[0,0,0,1,0]] }\nassert my_solution.findChampion(**test_input) == 2\n\ntest_input = { \"grid\": [[0,0,0,1,1],[1,0,0,1,1],[1,1,0,1,1],[0,0,0,0,1],[0,0,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 2\n\ntest_input = { \"grid\": [[0,0,0,1,1],[1,0,1,1,1],[1,0,0,1,1],[0,0,0,0,0],[0,0,0,1,0]] }\nassert my_solution.findChampion(**test_input) == 1\n\ntest_input = { \"grid\": [[0,0,0,1,1],[1,0,1,1,1],[1,0,0,1,1],[0,0,0,0,1],[0,0,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 1\n\ntest_input = { \"grid\": [[0,0,1,0,0],[1,0,1,0,0],[0,0,0,0,0],[1,1,1,0,0],[1,1,1,1,0]] }\nassert my_solution.findChampion(**test_input) == 4\n\ntest_input = { \"grid\": [[0,0,1,0,0],[1,0,1,1,0],[0,0,0,0,0],[1,0,1,0,0],[1,1,1,1,0]] }\nassert my_solution.findChampion(**test_input) == 4\n\ntest_input = { \"grid\": [[0,0,1,0,0],[1,0,1,1,1],[0,0,0,0,0],[1,0,1,0,1],[1,0,1,0,0]] }\nassert my_solution.findChampion(**test_input) == 1\n\ntest_input = { \"grid\": [[0,0,1,0,1],[1,0,1,0,1],[0,0,0,0,1],[1,1,1,0,1],[0,0,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 3\n\ntest_input = { \"grid\": [[0,0,1,1,0],[1,0,1,1,0],[0,0,0,1,0],[0,0,0,0,0],[1,1,1,1,0]] }\nassert my_solution.findChampion(**test_input) == 4\n\ntest_input = { \"grid\": [[0,0,1,1,0],[1,0,1,1,1],[0,0,0,0,0],[0,0,1,0,0],[1,0,1,1,0]] }\nassert my_solution.findChampion(**test_input) == 1\n\ntest_input = { \"grid\": [[0,0,1,1,1],[1,0,1,1,1],[0,0,0,1,0],[0,0,0,0,0],[0,0,1,1,0]] }\nassert my_solution.findChampion(**test_input) == 1\n\ntest_input = { \"grid\": [[0,0,1,1,1],[1,0,1,1,1],[0,0,0,1,1],[0,0,0,0,1],[0,0,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 1\n\ntest_input = { \"grid\": [[0,1,0,0,0],[0,0,0,0,0],[1,1,0,0,0],[1,1,1,0,1],[1,1,1,0,0]] }\nassert my_solution.findChampion(**test_input) == 3\n\ntest_input = { \"grid\": [[0,1,0,0,0],[0,0,0,0,0],[1,1,0,1,1],[1,1,0,0,0],[1,1,0,1,0]] }\nassert my_solution.findChampion(**test_input) == 2\n\ntest_input = { \"grid\": [[0,1,0,0,1],[0,0,0,0,0],[1,1,0,0,1],[1,1,1,0,1],[0,1,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 3\n\ntest_input = { \"grid\": [[0,1,0,0,1],[0,0,0,0,0],[1,1,0,1,1],[1,1,0,0,1],[0,1,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 2\n\ntest_input = { \"grid\": [[0,1,0,1,0],[0,0,0,0,0],[1,1,0,1,0],[0,1,0,0,0],[1,1,1,1,0]] }\nassert my_solution.findChampion(**test_input) == 4\n\ntest_input = { \"grid\": [[0,1,0,1,0],[0,0,0,0,0],[1,1,0,1,1],[0,1,0,0,0],[1,1,0,1,0]] }\nassert my_solution.findChampion(**test_input) == 2\n\ntest_input = { \"grid\": [[0,1,0,1,0],[0,0,0,1,0],[1,1,0,1,0],[0,0,0,0,0],[1,1,1,1,0]] }\nassert my_solution.findChampion(**test_input) == 4\n\ntest_input = { \"grid\": [[0,1,0,1,0],[0,0,0,1,0],[1,1,0,1,1],[0,0,0,0,0],[1,1,0,1,0]] }\nassert my_solution.findChampion(**test_input) == 2\n\ntest_input = { \"grid\": [[0,1,0,1,1],[0,0,0,0,0],[1,1,0,1,1],[0,1,0,0,1],[0,1,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 2\n\ntest_input = { \"grid\": [[0,1,0,1,1],[0,0,0,1,1],[1,1,0,1,1],[0,0,0,0,0],[0,0,0,1,0]] }\nassert my_solution.findChampion(**test_input) == 2\n\ntest_input = { \"grid\": [[0,1,1,0,0],[0,0,0,0,0],[0,1,0,0,0],[1,1,1,0,0],[1,1,1,1,0]] }\nassert my_solution.findChampion(**test_input) == 4\n\ntest_input = { \"grid\": [[0,1,1,0,0],[0,0,1,0,0],[0,0,0,0,0],[1,1,1,0,1],[1,1,1,0,0]] }\nassert my_solution.findChampion(**test_input) == 3\n\ntest_input = { \"grid\": [[0,1,1,0,1],[0,0,0,0,0],[0,1,0,0,1],[1,1,1,0,1],[0,1,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 3\n\ntest_input = { \"grid\": [[0,1,1,0,1],[0,0,0,0,1],[0,1,0,0,1],[1,1,1,0,1],[0,0,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 3\n\ntest_input = { \"grid\": [[0,1,1,0,1],[0,0,1,0,0],[0,0,0,0,0],[1,1,1,0,1],[0,1,1,0,0]] }\nassert my_solution.findChampion(**test_input) == 3\n\ntest_input = { \"grid\": [[0,1,1,0,1],[0,0,1,0,1],[0,0,0,0,0],[1,1,1,0,1],[0,0,1,0,0]] }\nassert my_solution.findChampion(**test_input) == 3\n\ntest_input = { \"grid\": [[0,1,1,0,1],[0,0,1,0,1],[0,0,0,0,1],[1,1,1,0,1],[0,0,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 3\n\ntest_input = { \"grid\": [[0,1,1,1,0],[0,0,0,1,0],[0,1,0,1,0],[0,0,0,0,0],[1,1,1,1,0]] }\nassert my_solution.findChampion(**test_input) == 4\n\ntest_input = { \"grid\": [[0,1,1,1,0],[0,0,1,0,0],[0,0,0,0,0],[0,1,1,0,0],[1,1,1,1,0]] }\nassert my_solution.findChampion(**test_input) == 4\n\ntest_input = { \"grid\": [[0,1,1,1,0],[0,0,1,1,0],[0,0,0,0,0],[0,0,1,0,0],[1,1,1,1,0]] }\nassert my_solution.findChampion(**test_input) == 4\n\ntest_input = { \"grid\": [[0,1,1,1,1],[0,0,0,0,0],[0,1,0,0,0],[0,1,1,0,0],[0,1,1,1,0]] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"grid\": [[0,1,1,1,1],[0,0,0,0,0],[0,1,0,0,0],[0,1,1,0,1],[0,1,1,0,0]] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"grid\": [[0,1,1,1,1],[0,0,0,0,0],[0,1,0,0,1],[0,1,1,0,1],[0,1,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"grid\": [[0,1,1,1,1],[0,0,0,0,0],[0,1,0,1,0],[0,1,0,0,0],[0,1,1,1,0]] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"grid\": [[0,1,1,1,1],[0,0,0,0,0],[0,1,0,1,1],[0,1,0,0,0],[0,1,0,1,0]] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"grid\": [[0,1,1,1,1],[0,0,0,0,0],[0,1,0,1,1],[0,1,0,0,1],[0,1,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"grid\": [[0,1,1,1,1],[0,0,0,0,1],[0,1,0,0,1],[0,1,1,0,1],[0,0,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"grid\": [[0,1,1,1,1],[0,0,1,0,0],[0,0,0,0,0],[0,1,1,0,0],[0,1,1,1,0]] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"grid\": [[0,1,1,1,1],[0,0,1,0,0],[0,0,0,0,0],[0,1,1,0,1],[0,1,1,0,0]] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"grid\": [[0,1,1,1,1],[0,0,1,0,1],[0,0,0,0,1],[0,1,1,0,1],[0,0,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"grid\": [[0,1,1,1,1],[0,0,1,1,0],[0,0,0,0,0],[0,0,1,0,0],[0,1,1,1,0]] }\nassert my_solution.findChampion(**test_input) == 0", "start_time": 1699151400} +{"task_id": "weekly-contest-370-find-champion-ii", "url": "https://leetcode.com/problems/find-champion-ii", "title": "find-champion-ii", "meta": {"questionId": "3189", "questionFrontendId": "2924", "title": "Find Champion II", "titleSlug": "find-champion-ii", "isPaidOnly": false, "difficulty": "Medium", "likes": 92, "dislikes": 7, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n一场比赛中共有 n 支队伍,按从 0 到  n - 1 编号。每支队伍也是 有向无环图(DAG) 上的一个节点。\n\n给你一个整数 n 和一个下标从 0 开始、长度为 m 的二维整数数组 edges 表示这个有向无环图,其中 edges[i] = [ui, vi] 表示图中存在一条从 ui 队到 vi 队的有向边。\n\n从 a 队到 b 队的有向边意味着 a 队比 b 队 强 ,也就是 b 队比 a 队 弱 。\n\n在这场比赛中,如果不存在某支强于 a 队的队伍,则认为 a 队将会是 冠军 。\n\n如果这场比赛存在 唯一 一个冠军,则返回将会成为冠军的队伍。否则,返回 -1 。\n\n注意\n\n * 环 是形如 a1, a2, ..., an, an+1 的一个序列,且满足:节点 a1 与节点 an+1 是同一个节点;节点 a1, a2, ..., an 互不相同;对于范围 [1, n] 中的每个 i ,均存在一条从节点 ai 到节点 ai+1 的有向边。\n * 有向无环图 是不存在任何环的有向图。\n\n示例 1:\n\n[https://assets.leetcode.com/uploads/2023/10/19/graph-3.png]\n\n输入:n = 3, edges = [[0,1],[1,2]]\n输出:0\n解释:1 队比 0 队弱。2 队比 1 队弱。所以冠军是 0 队。\n\n示例 2:\n\n[https://assets.leetcode.com/uploads/2023/10/19/graph-4.png]\n\n输入:n = 4, edges = [[0,2],[1,3],[1,2]]\n输出:-1\n解释:2 队比 0 队和 1 队弱。3 队比 1 队弱。但是 1 队和 0 队之间不存在强弱对比。所以答案是 -1 。\n\n\n提示:\n\n * 1 <= n <= 100\n * m == edges.length\n * 0 <= m <= n * (n - 1) / 2\n * edges[i].length == 2\n * 0 <= edge[i][j] <= n - 1\n * edges[i][0] != edges[i][1]\n * 生成的输入满足:如果 a 队比 b 队强,就不存在 b 队比 a 队强\n * 生成的输入满足:如果 a 队比 b 队强,b 队比 c 队强,那么 a 队比 c 队强\n\"\"\"\nclass Solution:\n def findChampion(self, n: int, edges: List[List[int]]) -> int:\n ", "prompt_sft": "一场比赛中共有 n 支队伍,按从 0 到  n - 1 编号。每支队伍也是 有向无环图(DAG) 上的一个节点。\n\n给你一个整数 n 和一个下标从 0 开始、长度为 m 的二维整数数组 edges 表示这个有向无环图,其中 edges[i] = [ui, vi] 表示图中存在一条从 ui 队到 vi 队的有向边。\n\n从 a 队到 b 队的有向边意味着 a 队比 b 队 强 ,也就是 b 队比 a 队 弱 。\n\n在这场比赛中,如果不存在某支强于 a 队的队伍,则认为 a 队将会是 冠军 。\n\n如果这场比赛存在 唯一 一个冠军,则返回将会成为冠军的队伍。否则,返回 -1 。\n\n注意\n\n * 环 是形如 a1, a2, ..., an, an+1 的一个序列,且满足:节点 a1 与节点 an+1 是同一个节点;节点 a1, a2, ..., an 互不相同;对于范围 [1, n] 中的每个 i ,均存在一条从节点 ai 到节点 ai+1 的有向边。\n * 有向无环图 是不存在任何环的有向图。\n\n示例 1:\n\n[https://assets.leetcode.com/uploads/2023/10/19/graph-3.png]\n\n输入:n = 3, edges = [[0,1],[1,2]]\n输出:0\n解释:1 队比 0 队弱。2 队比 1 队弱。所以冠军是 0 队。\n\n示例 2:\n\n[https://assets.leetcode.com/uploads/2023/10/19/graph-4.png]\n\n输入:n = 4, edges = [[0,2],[1,3],[1,2]]\n输出:-1\n解释:2 队比 0 队和 1 队弱。3 队比 1 队弱。但是 1 队和 0 队之间不存在强弱对比。所以答案是 -1 。\n\n\n提示:\n\n * 1 <= n <= 100\n * m == edges.length\n * 0 <= m <= n * (n - 1) / 2\n * edges[i].length == 2\n * 0 <= edge[i][j] <= n - 1\n * edges[i][0] != edges[i][1]\n * 生成的输入满足:如果 a 队比 b 队强,就不存在 b 队比 a 队强\n * 生成的输入满足:如果 a 队比 b 队强,b 队比 c 队强,那么 a 队比 c 队强\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def findChampion(self, n: int, edges: List[List[int]]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"n\": 3, \"edges\": [[0,1],[1,2]] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"n\": 4, \"edges\": [[0,2],[1,3],[1,2]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 1, \"edges\": [] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"n\": 2, \"edges\": [] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 2, \"edges\": [[0,1]] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"n\": 2, \"edges\": [[1,0]] }\nassert my_solution.findChampion(**test_input) == 1\n\ntest_input = { \"n\": 3, \"edges\": [] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 3, \"edges\": [[0,1]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 3, \"edges\": [[0,2]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 3, \"edges\": [[1,2]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 3, \"edges\": [[2,0]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 3, \"edges\": [[0,1],[2,1]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 3, \"edges\": [[0,2],[0,1]] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"n\": 3, \"edges\": [[0,2],[1,0]] }\nassert my_solution.findChampion(**test_input) == 1\n\ntest_input = { \"n\": 3, \"edges\": [[2,0],[1,0]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 3, \"edges\": [[2,0],[2,1]] }\nassert my_solution.findChampion(**test_input) == 2\n\ntest_input = { \"n\": 3, \"edges\": [[2,1],[2,0]] }\nassert my_solution.findChampion(**test_input) == 2\n\ntest_input = { \"n\": 3, \"edges\": [[0,1],[1,2],[0,2]] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"n\": 3, \"edges\": [[0,1],[2,1],[0,2]] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"n\": 3, \"edges\": [[0,2],[0,1],[1,2]] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"n\": 3, \"edges\": [[0,2],[0,1],[2,1]] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"n\": 3, \"edges\": [[0,2],[1,2],[1,0]] }\nassert my_solution.findChampion(**test_input) == 1\n\ntest_input = { \"n\": 3, \"edges\": [[1,0],[0,2],[1,2]] }\nassert my_solution.findChampion(**test_input) == 1\n\ntest_input = { \"n\": 3, \"edges\": [[2,1],[1,0],[2,0]] }\nassert my_solution.findChampion(**test_input) == 2\n\ntest_input = { \"n\": 4, \"edges\": [] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 4, \"edges\": [[0,2]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 4, \"edges\": [[1,0]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 4, \"edges\": [[1,3]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 4, \"edges\": [[3,2]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 4, \"edges\": [[0,1],[2,3]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 4, \"edges\": [[0,3],[2,3]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 4, \"edges\": [[1,3],[2,1]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 4, \"edges\": [[2,1],[1,3]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 4, \"edges\": [[3,0],[3,1]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 4, \"edges\": [[0,1],[2,0],[2,1]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 4, \"edges\": [[0,2],[3,2],[1,2]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 4, \"edges\": [[1,0],[2,3],[1,2]] }\nassert my_solution.findChampion(**test_input) == 1\n\ntest_input = { \"n\": 4, \"edges\": [[1,2],[0,3],[1,3]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 4, \"edges\": [[1,2],[1,0],[1,3]] }\nassert my_solution.findChampion(**test_input) == 1\n\ntest_input = { \"n\": 4, \"edges\": [[1,3],[1,2],[0,3]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 4, \"edges\": [[1,3],[3,0],[2,0]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 4, \"edges\": [[3,1],[2,0],[1,2]] }\nassert my_solution.findChampion(**test_input) == 3\n\ntest_input = { \"n\": 4, \"edges\": [[3,1],[2,1],[0,2]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 4, \"edges\": [[0,2],[0,3],[1,2],[1,0]] }\nassert my_solution.findChampion(**test_input) == 1\n\ntest_input = { \"n\": 4, \"edges\": [[2,0],[2,3],[3,1],[2,1]] }\nassert my_solution.findChampion(**test_input) == 2\n\ntest_input = { \"n\": 4, \"edges\": [[2,1],[1,0],[3,0],[2,0]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 4, \"edges\": [[3,0],[3,1],[2,1],[0,1]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 4, \"edges\": [[3,0],[1,0],[1,2],[3,2],[2,0]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 4, \"edges\": [[3,0],[2,0],[1,0],[2,3],[1,2]] }\nassert my_solution.findChampion(**test_input) == 1\n\ntest_input = { \"n\": 4, \"edges\": [[3,2],[0,1],[3,0],[3,1],[2,0]] }\nassert my_solution.findChampion(**test_input) == 3\n\ntest_input = { \"n\": 4, \"edges\": [[0,3],[2,3],[2,1],[1,0],[2,0],[1,3]] }\nassert my_solution.findChampion(**test_input) == 2\n\ntest_input = { \"n\": 4, \"edges\": [[1,2],[2,3],[0,2],[0,1],[0,3],[1,3]] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"n\": 4, \"edges\": [[2,1],[3,1],[3,0],[3,2],[2,0],[0,1]] }\nassert my_solution.findChampion(**test_input) == 3\n\ntest_input = { \"n\": 4, \"edges\": [[2,3],[2,1],[0,1],[0,3],[3,1],[0,2]] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"n\": 5, \"edges\": [] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 5, \"edges\": [[0,2]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 5, \"edges\": [[2,0]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 5, \"edges\": [[4,0]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 5, \"edges\": [[1,4],[2,0]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 5, \"edges\": [[2,0],[4,3]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 5, \"edges\": [[3,2],[0,2]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 5, \"edges\": [[3,4],[2,1]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 5, \"edges\": [[0,4],[1,4],[0,1]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 5, \"edges\": [[1,3],[4,2],[1,0]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 5, \"edges\": [[2,3],[4,1],[3,0]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 5, \"edges\": [[0,4],[2,0],[1,3],[2,4]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 5, \"edges\": [[0,1],[2,1],[4,1],[4,2],[4,0]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 5, \"edges\": [[0,2],[2,1],[3,2],[4,1],[0,4]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 5, \"edges\": [[2,3],[0,4],[1,4],[1,0],[4,3]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 5, \"edges\": [[3,1],[0,2],[4,2],[0,1],[1,2]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 5, \"edges\": [[3,2],[3,4],[3,0],[3,1],[0,2]] }\nassert my_solution.findChampion(**test_input) == 3\n\ntest_input = { \"n\": 5, \"edges\": [[4,0],[3,0],[2,4],[3,4],[4,1]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 5, \"edges\": [[4,3],[1,0],[1,2],[3,2],[4,1]] }\nassert my_solution.findChampion(**test_input) == 4\n\ntest_input = { \"n\": 5, \"edges\": [[2,1],[0,3],[0,1],[0,4],[0,2],[4,1]] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"n\": 5, \"edges\": [[2,1],[4,1],[3,0],[2,0],[3,4],[3,2]] }\nassert my_solution.findChampion(**test_input) == 3\n\ntest_input = { \"n\": 5, \"edges\": [[0,1],[0,4],[2,0],[3,4],[3,1],[2,1],[3,0]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 5, \"edges\": [[1,4],[3,1],[0,1],[3,0],[0,2],[2,4],[3,4]] }\nassert my_solution.findChampion(**test_input) == 3\n\ntest_input = { \"n\": 5, \"edges\": [[3,2],[1,2],[2,0],[2,4],[1,4],[3,1],[3,4]] }\nassert my_solution.findChampion(**test_input) == 3\n\ntest_input = { \"n\": 5, \"edges\": [[0,4],[0,3],[4,3],[4,2],[1,2],[4,1],[0,1],[3,2]] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"n\": 5, \"edges\": [[4,3],[4,2],[4,1],[2,3],[4,0],[3,1],[2,0],[0,3]] }\nassert my_solution.findChampion(**test_input) == 4\n\ntest_input = { \"n\": 5, \"edges\": [[1,2],[1,4],[2,3],[0,2],[1,0],[1,3],[0,3],[4,3],[0,4]] }\nassert my_solution.findChampion(**test_input) == 1\n\ntest_input = { \"n\": 5, \"edges\": [[1,3],[3,0],[3,4],[2,0],[3,2],[0,4],[2,4],[1,0],[1,2]] }\nassert my_solution.findChampion(**test_input) == 1\n\ntest_input = { \"n\": 5, \"edges\": [[3,0],[4,0],[3,2],[0,1],[0,2],[4,3],[1,2],[4,2],[3,1]] }\nassert my_solution.findChampion(**test_input) == 4\n\ntest_input = { \"n\": 5, \"edges\": [[4,0],[2,3],[4,3],[4,2],[2,0],[4,1],[1,3],[1,0],[3,0]] }\nassert my_solution.findChampion(**test_input) == 4\n\ntest_input = { \"n\": 5, \"edges\": [[0,2],[1,3],[4,1],[4,2],[2,1],[0,3],[0,1],[2,3],[0,4],[4,3]] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"n\": 5, \"edges\": [[2,0],[4,0],[3,4],[4,2],[1,2],[1,0],[3,1],[3,0],[1,4],[3,2]] }\nassert my_solution.findChampion(**test_input) == 3\n\ntest_input = { \"n\": 6, \"edges\": [] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 6, \"edges\": [[2,1]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 6, \"edges\": [[2,3]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 6, \"edges\": [[3,5]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 6, \"edges\": [[5,4]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 6, \"edges\": [[1,2],[4,3]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 6, \"edges\": [[0,4],[4,5],[3,1]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 6, \"edges\": [[0,4],[5,2],[5,4],[3,0],[1,0]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 6, \"edges\": [[1,0],[1,4],[0,2],[3,5],[3,4]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 6, \"edges\": [[5,0],[2,4],[0,4],[3,2],[2,0]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 6, \"edges\": [[1,2],[3,2],[3,5],[4,0],[1,5],[0,5]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 6, \"edges\": [[3,2],[1,2],[3,0],[5,0],[5,1],[5,3]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 6, \"edges\": [[4,2],[0,4],[1,3],[3,4],[1,2],[1,0]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 6, \"edges\": [[0,5],[2,0],[1,5],[3,2],[2,1],[2,4],[4,5]] }\nassert my_solution.findChampion(**test_input) == 3", "start_time": 1699151400} +{"task_id": "weekly-contest-370-maximum-score-after-applying-operations-on-a-tree", "url": "https://leetcode.com/problems/maximum-score-after-applying-operations-on-a-tree", "title": "maximum-score-after-applying-operations-on-a-tree", "meta": {"questionId": "3191", "questionFrontendId": "2925", "title": "Maximum Score After Applying Operations on a Tree", "titleSlug": "maximum-score-after-applying-operations-on-a-tree", "isPaidOnly": false, "difficulty": "Medium", "likes": 243, "dislikes": 45, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n有一棵 n 个节点的无向树,节点编号为 0 到 n - 1 ,根节点编号为 0 。给你一个长度为 n - 1 的二维整数数组 edges 表示这棵树,其中 edges[i] = [ai, bi] 表示树中节点 ai 和 bi 有一条边。\n\n同时给你一个长度为 n 下标从 0 开始的整数数组 values ,其中 values[i] 表示第 i 个节点的值。\n\n一开始你的分数为 0 ,每次操作中,你将执行:\n\n * 选择节点 i 。\n * 将 values[i] 加入你的分数。\n * 将 values[i] 变为 0 。\n\n如果从根节点出发,到任意叶子节点经过的路径上的节点值之和都不等于 0 ,那么我们称这棵树是 健康的 。\n\n你可以对这棵树执行任意次操作,但要求执行完所有操作以后树是 健康的 ,请你返回你可以获得的 最大分数 。\n\n示例 1:\n\n[https://assets.leetcode.com/uploads/2023/10/11/graph-13-1.png]\n\n输入:edges = [[0,1],[0,2],[0,3],[2,4],[4,5]], values = [5,2,5,2,1,1]\n输出:11\n解释:我们可以选择节点 1 ,2 ,3 ,4 和 5 。根节点的值是非 0 的。所以从根出发到任意叶子节点路径上节点值之和都不为 0 。所以树是健康的。你的得分之和为 values[1] + values[2] + values[3] + values[4] + values[5] = 11 。\n11 是你对树执行任意次操作以后可以获得的最大得分之和。\n\n示例 2:\n\n[https://assets.leetcode.com/uploads/2023/10/11/graph-14-2.png]\n\n输入:edges = [[0,1],[0,2],[1,3],[1,4],[2,5],[2,6]], values = [20,10,9,7,4,3,5]\n输出:40\n解释:我们选择节点 0 ,2 ,3 和 4 。\n- 从 0 到 4 的节点值之和为 10 。\n- 从 0 到 3 的节点值之和为 10 。\n- 从 0 到 5 的节点值之和为 3 。\n- 从 0 到 6 的节点值之和为 5 。\n所以树是健康的。你的得分之和为 values[0] + values[2] + values[3] + values[4] = 40 。\n40 是你对树执行任意次操作以后可以获得的最大得分之和。\n\n\n提示:\n\n * 2 <= n <= 2 * 104\n * edges.length == n - 1\n * edges[i].length == 2\n * 0 <= ai, bi < n\n * values.length == n\n * 1 <= values[i] <= 109\n * 输入保证 edges 构成一棵合法的树。\n\"\"\"\nclass Solution:\n def maximumScoreAfterOperations(self, edges: List[List[int]], values: List[int]) -> int:\n ", "prompt_sft": "有一棵 n 个节点的无向树,节点编号为 0 到 n - 1 ,根节点编号为 0 。给你一个长度为 n - 1 的二维整数数组 edges 表示这棵树,其中 edges[i] = [ai, bi] 表示树中节点 ai 和 bi 有一条边。\n\n同时给你一个长度为 n 下标从 0 开始的整数数组 values ,其中 values[i] 表示第 i 个节点的值。\n\n一开始你的分数为 0 ,每次操作中,你将执行:\n\n * 选择节点 i 。\n * 将 values[i] 加入你的分数。\n * 将 values[i] 变为 0 。\n\n如果从根节点出发,到任意叶子节点经过的路径上的节点值之和都不等于 0 ,那么我们称这棵树是 健康的 。\n\n你可以对这棵树执行任意次操作,但要求执行完所有操作以后树是 健康的 ,请你返回你可以获得的 最大分数 。\n\n示例 1:\n\n[https://assets.leetcode.com/uploads/2023/10/11/graph-13-1.png]\n\n输入:edges = [[0,1],[0,2],[0,3],[2,4],[4,5]], values = [5,2,5,2,1,1]\n输出:11\n解释:我们可以选择节点 1 ,2 ,3 ,4 和 5 。根节点的值是非 0 的。所以从根出发到任意叶子节点路径上节点值之和都不为 0 。所以树是健康的。你的得分之和为 values[1] + values[2] + values[3] + values[4] + values[5] = 11 。\n11 是你对树执行任意次操作以后可以获得的最大得分之和。\n\n示例 2:\n\n[https://assets.leetcode.com/uploads/2023/10/11/graph-14-2.png]\n\n输入:edges = [[0,1],[0,2],[1,3],[1,4],[2,5],[2,6]], values = [20,10,9,7,4,3,5]\n输出:40\n解释:我们选择节点 0 ,2 ,3 和 4 。\n- 从 0 到 4 的节点值之和为 10 。\n- 从 0 到 3 的节点值之和为 10 。\n- 从 0 到 5 的节点值之和为 3 。\n- 从 0 到 6 的节点值之和为 5 。\n所以树是健康的。你的得分之和为 values[0] + values[2] + values[3] + values[4] = 40 。\n40 是你对树执行任意次操作以后可以获得的最大得分之和。\n\n\n提示:\n\n * 2 <= n <= 2 * 104\n * edges.length == n - 1\n * edges[i].length == 2\n * 0 <= ai, bi < n\n * values.length == n\n * 1 <= values[i] <= 109\n * 输入保证 edges 构成一棵合法的树。\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def maximumScoreAfterOperations(self, edges: List[List[int]], values: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"edges\": [[0,1],[0,2],[0,3],[2,4],[4,5]], \"values\": [5,2,5,2,1,1] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 11\n\ntest_input = { \"edges\": [[0,1],[0,2],[1,3],[1,4],[2,5],[2,6]], \"values\": [20,10,9,7,4,3,5] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 40\n\ntest_input = { \"edges\": [[0,1]], \"values\": [1,2] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 2\n\ntest_input = { \"edges\": [[0,1]], \"values\": [2,1] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 2\n\ntest_input = { \"edges\": [[0,1],[0,2]], \"values\": [1000000000,1000000000,1000000000] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 2000000000\n\ntest_input = { \"edges\": [[0,1],[0,2],[0,3]], \"values\": [1000000000,1000000000,1000000000,1000000000] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 3000000000\n\ntest_input = { \"edges\": [[7,0],[3,1],[6,2],[4,3],[4,5],[4,6],[4,7]], \"values\": [2,16,23,17,22,21,8,6] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 113\n\ntest_input = { \"edges\": [[3,1],[0,2],[0,3]], \"values\": [21,12,19,5] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 36\n\ntest_input = { \"edges\": [[2,0],[4,1],[5,3],[4,6],[2,4],[5,2],[5,7]], \"values\": [12,12,7,9,2,11,12,25] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 83\n\ntest_input = { \"edges\": [[1,0],[9,1],[6,2],[7,4],[3,5],[7,3],[9,6],[7,8],[7,9]], \"values\": [14,17,13,18,17,10,23,19,22,2] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 153\n\ntest_input = { \"edges\": [[5,0],[4,3],[2,5],[6,2],[4,6],[1,4],[1,7]], \"values\": [15,12,13,23,8,1,2,23] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 96\n\ntest_input = { \"edges\": [[0,2],[1,3],[0,5],[1,0],[4,1],[4,6]], \"values\": [22,25,4,21,8,20,4] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 82\n\ntest_input = { \"edges\": [[4,1],[6,3],[2,4],[0,2],[9,5],[0,6],[9,7],[0,8],[0,9]], \"values\": [3,18,10,16,9,3,25,17,8,9] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 115\n\ntest_input = { \"edges\": [[6,1],[3,4],[0,3],[2,0],[5,2],[5,6]], \"values\": [25,20,16,2,13,8,19] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 93\n\ntest_input = { \"edges\": [[9,2],[5,4],[5,6],[1,5],[8,1],[0,7],[3,0],[9,3],[8,9]], \"values\": [21,13,10,14,20,11,19,22,3,16] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 128\n\ntest_input = { \"edges\": [[2,4],[1,5],[0,1],[2,0],[3,2],[3,6]], \"values\": [17,5,24,18,6,16,1] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 75\n\ntest_input = { \"edges\": [[1,2],[4,1],[3,6],[4,3],[5,4],[0,5],[0,7]], \"values\": [8,13,19,13,4,3,24,25] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 101\n\ntest_input = { \"edges\": [[9,0],[7,1],[6,3],[8,4],[2,5],[9,6],[2,8],[7,2],[7,9]], \"values\": [4,13,21,1,25,8,21,22,9,18] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 138\n\ntest_input = { \"edges\": [[1,0],[4,3],[1,5],[6,1],[4,6],[2,7],[4,2],[4,8]], \"values\": [10,5,25,19,2,20,15,3,3] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 97\n\ntest_input = { \"edges\": [[6,1],[3,4],[2,5],[0,6],[3,0],[2,3],[2,7]], \"values\": [2,23,10,20,22,10,6,24] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 115\n\ntest_input = { \"edges\": [[2,1],[0,2],[5,0],[4,3],[5,4],[5,6]], \"values\": [9,21,12,20,5,2,13] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 73\n\ntest_input = { \"edges\": [[8,1],[7,4],[0,5],[2,0],[3,2],[8,3],[7,6],[7,8]], \"values\": [23,24,25,12,12,7,1,17,17] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 119\n\ntest_input = { \"edges\": [[3,0],[3,1],[2,3]], \"values\": [19,8,8,5] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 35\n\ntest_input = { \"edges\": [[5,0],[7,1],[3,2],[6,4],[6,5],[3,6],[3,7]], \"values\": [19,7,17,9,13,7,25,3] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 93\n\ntest_input = { \"edges\": [[3,1],[2,3],[0,2],[0,4]], \"values\": [14,15,18,15,20] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 68\n\ntest_input = { \"edges\": [[6,0],[2,1],[6,2],[6,4],[5,7],[6,5],[3,6],[9,3],[8,9]], \"values\": [17,20,17,13,5,12,8,12,14,25] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 135\n\ntest_input = { \"edges\": [[4,1],[6,2],[9,3],[0,6],[0,7],[9,0],[4,8],[5,4],[5,9]], \"values\": [11,16,10,25,21,25,15,10,5,7] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 134\n\ntest_input = { \"edges\": [[1,0],[3,1],[2,3]], \"values\": [25,19,12,2] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 56\n\ntest_input = { \"edges\": [[4,1],[0,2],[4,0],[3,4]], \"values\": [12,24,1,11,3] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 47\n\ntest_input = { \"edges\": [[1,0],[5,1],[2,4],[3,2],[3,5]], \"values\": [21,2,17,18,22,16] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 94\n\ntest_input = { \"edges\": [[5,1],[4,3],[2,4],[6,2],[0,5],[0,6]], \"values\": [18,24,5,20,23,6,7] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 92\n\ntest_input = { \"edges\": [[4,1],[6,3],[2,4],[5,2],[0,5],[0,6]], \"values\": [19,2,23,18,3,12,9] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 75\n\ntest_input = { \"edges\": [[5,0],[2,1],[6,3],[5,4],[2,5],[2,6]], \"values\": [22,11,2,11,3,11,17] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 72\n\ntest_input = { \"edges\": [[6,0],[4,1],[3,2],[6,5],[4,6],[3,4],[3,7],[3,8]], \"values\": [18,20,14,23,20,8,24,12,1] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 122\n\ntest_input = { \"edges\": [[1,2],[0,1],[0,3],[0,4]], \"values\": [6,8,2,16,6] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 32\n\ntest_input = { \"edges\": [[6,1],[3,4],[3,5],[0,3],[2,0],[2,6]], \"values\": [5,25,2,12,15,3,3] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 60\n\ntest_input = { \"edges\": [[4,0],[2,1],[2,3],[2,4]], \"values\": [9,5,14,24,19] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 62\n\ntest_input = { \"edges\": [[4,0],[2,1],[6,3],[2,5],[4,6],[2,4],[7,2],[7,8]], \"values\": [19,10,14,18,17,8,2,8,24] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 104\n\ntest_input = { \"edges\": [[6,0],[7,1],[5,3],[2,4],[8,5],[6,7],[2,6],[2,8]], \"values\": [8,8,19,17,24,1,7,18,12] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 107\n\ntest_input = { \"edges\": [[6,0],[3,1],[3,2],[3,6],[4,3],[5,4],[5,7]], \"values\": [15,3,25,2,10,11,10,13] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 87\n\ntest_input = { \"edges\": [[7,3],[2,5],[4,2],[0,4],[7,0],[1,6],[1,7]], \"values\": [1,19,5,1,18,24,4,20] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 91\n\ntest_input = { \"edges\": [[7,3],[2,4],[9,2],[1,5],[1,7],[0,1],[9,0],[6,8],[6,9]], \"values\": [21,10,9,25,7,20,5,8,20,5] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 115\n\ntest_input = { \"edges\": [[3,1],[4,5],[0,4],[2,0],[3,2],[3,6]], \"values\": [13,11,16,12,20,1,7] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 67\n\ntest_input = { \"edges\": [[2,0],[3,1],[6,2],[6,3],[5,4],[7,5],[6,7]], \"values\": [21,20,8,21,11,12,23,4] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 112\n\ntest_input = { \"edges\": [[0,2],[7,4],[1,6],[5,1],[3,5],[0,3],[0,7]], \"values\": [8,6,9,5,4,1,8,6] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 39\n\ntest_input = { \"edges\": [[5,1],[8,3],[0,4],[8,0],[2,5],[2,7],[9,2],[6,8],[6,9]], \"values\": [2,22,2,19,25,14,11,24,7,6] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 130\n\ntest_input = { \"edges\": [[3,0],[3,1],[2,3]], \"values\": [24,24,4,12] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 52\n\ntest_input = { \"edges\": [[2,0],[3,1],[2,3]], \"values\": [7,10,13,8] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 31\n\ntest_input = { \"edges\": [[1,0],[3,1],[6,4],[3,5],[2,3],[2,6]], \"values\": [6,14,4,17,16,19,24] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 94\n\ntest_input = { \"edges\": [[0,1],[3,0],[8,3],[2,4],[8,5],[2,6],[8,2],[7,8]], \"values\": [22,19,10,16,14,11,2,17,9] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 98\n\ntest_input = { \"edges\": [[5,1],[5,2],[0,3],[0,4],[0,5]], \"values\": [21,18,2,20,1,1] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 42\n\ntest_input = { \"edges\": [[6,0],[3,2],[1,3],[6,4],[1,5],[1,6]], \"values\": [14,19,22,6,19,12,20] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 98\n\ntest_input = { \"edges\": [[6,0],[4,1],[2,3],[5,2],[6,4],[5,6]], \"values\": [16,16,9,12,5,14,17] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 75\n\ntest_input = { \"edges\": [[2,1],[4,2],[0,3],[0,4]], \"values\": [9,6,7,17,19] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 49\n\ntest_input = { \"edges\": [[1,3],[2,1],[4,5],[2,4],[0,2],[0,6]], \"values\": [4,19,10,25,16,13,6] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 89\n\ntest_input = { \"edges\": [[1,0],[5,1],[2,5],[3,2],[4,6],[3,4],[3,7]], \"values\": [12,9,19,10,24,22,18,16] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 121\n\ntest_input = { \"edges\": [[0,1],[0,2],[0,3]], \"values\": [25,23,7,9] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 39\n\ntest_input = { \"edges\": [[3,0],[3,2],[4,5],[9,6],[4,7],[9,4],[3,8],[1,3],[1,9]], \"values\": [23,22,7,22,19,12,10,11,24,3] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 131\n\ntest_input = { \"edges\": [[0,1],[0,2],[0,3]], \"values\": [9,8,24,21] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 53\n\ntest_input = { \"edges\": [[3,1],[0,2],[0,3]], \"values\": [17,2,2,4] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 21\n\ntest_input = { \"edges\": [[5,2],[3,4],[0,3],[1,0],[1,5]], \"values\": [16,6,15,15,10,1] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 52\n\ntest_input = { \"edges\": [[8,0],[8,1],[7,2],[3,7],[6,3],[4,6],[5,4],[5,8]], \"values\": [10,25,10,6,21,17,11,15,15] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 120\n\ntest_input = { \"edges\": [[0,4],[1,5],[2,6],[0,2],[1,0],[3,1],[3,7]], \"values\": [20,1,16,12,5,23,21,4] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 82\n\ntest_input = { \"edges\": [[7,1],[5,2],[0,3],[7,0],[7,4],[6,5],[6,7]], \"values\": [6,20,14,17,18,16,11,1] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 97\n\ntest_input = { \"edges\": [[3,2],[8,4],[1,6],[0,1],[5,0],[3,5],[8,3],[7,8]], \"values\": [3,18,16,22,10,2,7,3,10] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 88\n\ntest_input = { \"edges\": [[4,0],[3,4],[3,5],[3,6],[2,3],[1,2],[1,7]], \"values\": [12,14,7,25,13,16,12,15] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 102\n\ntest_input = { \"edges\": [[3,0],[5,2],[1,3],[4,1],[4,5]], \"values\": [11,18,19,14,8,11] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 73\n\ntest_input = { \"edges\": [[1,2],[4,1],[0,4],[8,5],[0,6],[7,0],[3,7],[3,8]], \"values\": [17,22,14,15,2,21,7,9,1] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 98\n\ntest_input = { \"edges\": [[2,1],[0,2],[4,3],[0,4],[0,5]], \"values\": [1,2,24,25,9,24] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 84\n\ntest_input = { \"edges\": [[3,1],[3,2],[0,4],[3,5],[0,3],[0,6]], \"values\": [21,19,5,20,2,25,20] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 91\n\ntest_input = { \"edges\": [[1,0],[4,1],[4,2],[3,4]], \"values\": [3,6,17,4,20] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 47\n\ntest_input = { \"edges\": [[6,1],[2,3],[6,7],[4,6],[2,4],[5,2],[5,8],[0,5],[0,9]], \"values\": [23,19,15,4,3,18,25,22,6,11] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 123\n\ntest_input = { \"edges\": [[2,0],[1,2],[5,1],[3,4],[3,5]], \"values\": [23,24,10,15,10,22] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 94\n\ntest_input = { \"edges\": [[1,0],[6,1],[6,2],[4,3],[5,4],[5,6]], \"values\": [18,21,3,13,25,15,20] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 99\n\ntest_input = { \"edges\": [[1,0],[3,1],[2,3]], \"values\": [23,10,24,15] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 62\n\ntest_input = { \"edges\": [[1,0],[1,2],[1,3]], \"values\": [10,4,12,14] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 36\n\ntest_input = { \"edges\": [[2,0],[3,2],[1,3],[4,5],[1,4],[1,6]], \"values\": [3,8,13,11,6,18,8] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 64\n\ntest_input = { \"edges\": [[3,0],[3,2],[1,3],[1,4]], \"values\": [18,19,7,7,2] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 46\n\ntest_input = { \"edges\": [[7,0],[5,2],[1,3],[7,4],[1,5],[7,1],[6,7]], \"values\": [24,24,16,17,25,9,3,23] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 118\n\ntest_input = { \"edges\": [[2,0],[2,1],[2,3]], \"values\": [25,12,5,7] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 44\n\ntest_input = { \"edges\": [[0,1],[2,0],[2,3],[2,4]], \"values\": [24,14,9,5,24] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 53\n\ntest_input = { \"edges\": [[6,2],[7,3],[0,5],[4,0],[1,6],[4,1],[4,7]], \"values\": [20,15,15,2,22,7,19,24] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 104\n\ntest_input = { \"edges\": [[1,0],[4,2],[7,5],[3,6],[1,3],[4,1],[4,7]], \"values\": [11,21,15,23,2,7,21,3] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 92\n\ntest_input = { \"edges\": [[4,0],[2,1],[2,3],[2,4]], \"values\": [22,20,20,8,14] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 70\n\ntest_input = { \"edges\": [[0,2],[4,3],[0,4],[1,0],[1,6],[5,1],[5,7]], \"values\": [18,10,19,9,11,14,11,18] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 92\n\ntest_input = { \"edges\": [[6,1],[4,2],[4,3],[0,5],[4,0],[4,6]], \"values\": [18,10,5,23,16,13,1] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 68\n\ntest_input = { \"edges\": [[4,0],[6,2],[6,3],[6,4],[1,5],[7,1],[6,7]], \"values\": [14,15,22,9,13,2,25,3] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 90\n\ntest_input = { \"edges\": [[6,2],[0,3],[5,0],[1,5],[4,1],[4,6]], \"values\": [22,10,19,14,18,24,8] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 93\n\ntest_input = { \"edges\": [[0,1],[0,2],[0,3]], \"values\": [6,22,9,5] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 36\n\ntest_input = { \"edges\": [[2,1],[0,2],[6,0],[6,4],[3,5],[3,6],[3,7]], \"values\": [9,16,13,9,19,1,16,19] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 93\n\ntest_input = { \"edges\": [[3,5],[7,3],[0,6],[4,0],[1,4],[2,1],[2,7]], \"values\": [16,9,8,14,6,18,23,25] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 103\n\ntest_input = { \"edges\": [[7,1],[4,5],[3,6],[4,3],[2,4],[0,2],[0,7]], \"values\": [7,22,12,22,5,3,6,7] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 77\n\ntest_input = { \"edges\": [[5,0],[4,1],[5,2],[3,5],[4,3],[7,4],[6,7]], \"values\": [19,16,8,13,15,13,3,5] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 79\n\ntest_input = { \"edges\": [[7,1],[6,2],[3,5],[8,3],[0,6],[4,0],[7,4],[7,8]], \"values\": [23,11,22,6,19,6,19,8,25] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 116\n\ntest_input = { \"edges\": [[4,0],[4,2],[1,3],[4,1],[4,5]], \"values\": [23,22,13,1,11,25] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 84\n\ntest_input = { \"edges\": [[4,0],[4,1],[2,3],[2,4]], \"values\": [3,17,5,24,14] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 60\n\ntest_input = { \"edges\": [[4,0],[2,4],[1,2],[3,1],[3,5]], \"values\": [6,12,21,6,8,8] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 55\n\ntest_input = { \"edges\": [[4,2],[5,4],[0,5],[0,6],[3,0],[1,3],[7,8],[1,7],[1,9]], \"values\": [25,16,16,14,22,19,2,22,13,11] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 135\n\ntest_input = { \"edges\": [[4,0],[1,3],[4,1],[7,5],[2,6],[4,2],[4,7]], \"values\": [23,16,24,25,3,21,3,25] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 137\n\ntest_input = { \"edges\": [[0,1],[2,0],[2,3]], \"values\": [22,17,9,9] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 35", "start_time": 1699151400} +{"task_id": "weekly-contest-370-maximum-balanced-subsequence-sum", "url": "https://leetcode.com/problems/maximum-balanced-subsequence-sum", "title": "maximum-balanced-subsequence-sum", "meta": {"questionId": "3184", "questionFrontendId": "2926", "title": "Maximum Balanced Subsequence Sum", "titleSlug": "maximum-balanced-subsequence-sum", "isPaidOnly": false, "difficulty": "Hard", "likes": 133, "dislikes": 6, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0 开始的整数数组 nums 。\n\nnums 一个长度为 k 的 子序列 指的是选出 k 个 下标 i0 < i1 < ... < ik-1 ,如果这个子序列满足以下条件,我们说它是 平衡的 :\n\n * 对于范围 [1, k - 1] 内的所有 j ,nums[ij] - nums[ij-1] >= ij - ij-1 都成立。\n\nnums 长度为 1 的 子序列 是平衡的。\n\n请你返回一个整数,表示 nums 平衡 子序列里面的 最大元素和 。\n\n一个数组的 子序列 指的是从原数组中删除一些元素(也可能一个元素也不删除)后,剩余元素保持相对顺序得到的 非空 新数组。\n\n示例 1:\n\n输入:nums = [3,3,5,6]\n输出:14\n解释:这个例子中,选择子序列 [3,5,6] ,下标为 0 ,2 和 3 的元素被选中。\nnums[2] - nums[0] >= 2 - 0 。\nnums[3] - nums[2] >= 3 - 2 。\n所以,这是一个平衡子序列,且它的和是所有平衡子序列里最大的。\n包含下标 1 ,2 和 3 的子序列也是一个平衡的子序列。\n最大平衡子序列和为 14 。\n\n示例 2:\n\n输入:nums = [5,-1,-3,8]\n输出:13\n解释:这个例子中,选择子序列 [5,8] ,下标为 0 和 3 的元素被选中。\nnums[3] - nums[0] >= 3 - 0 。\n所以,这是一个平衡子序列,且它的和是所有平衡子序列里最大的。\n最大平衡子序列和为 13 。\n\n示例 3:\n\n输入:nums = [-2,-1]\n输出:-1\n解释:这个例子中,选择子序列 [-1] 。\n这是一个平衡子序列,而且它的和是 nums 所有平衡子序列里最大的。\n\n\n提示:\n\n * 1 <= nums.length <= 105\n * -109 <= nums[i] <= 109\n\"\"\"\nclass Solution:\n def maxBalancedSubsequenceSum(self, nums: List[int]) -> int:\n ", "prompt_sft": "给你一个下标从 0 开始的整数数组 nums 。\n\nnums 一个长度为 k 的 子序列 指的是选出 k 个 下标 i0 < i1 < ... < ik-1 ,如果这个子序列满足以下条件,我们说它是 平衡的 :\n\n * 对于范围 [1, k - 1] 内的所有 j ,nums[ij] - nums[ij-1] >= ij - ij-1 都成立。\n\nnums 长度为 1 的 子序列 是平衡的。\n\n请你返回一个整数,表示 nums 平衡 子序列里面的 最大元素和 。\n\n一个数组的 子序列 指的是从原数组中删除一些元素(也可能一个元素也不删除)后,剩余元素保持相对顺序得到的 非空 新数组。\n\n示例 1:\n\n输入:nums = [3,3,5,6]\n输出:14\n解释:这个例子中,选择子序列 [3,5,6] ,下标为 0 ,2 和 3 的元素被选中。\nnums[2] - nums[0] >= 2 - 0 。\nnums[3] - nums[2] >= 3 - 2 。\n所以,这是一个平衡子序列,且它的和是所有平衡子序列里最大的。\n包含下标 1 ,2 和 3 的子序列也是一个平衡的子序列。\n最大平衡子序列和为 14 。\n\n示例 2:\n\n输入:nums = [5,-1,-3,8]\n输出:13\n解释:这个例子中,选择子序列 [5,8] ,下标为 0 和 3 的元素被选中。\nnums[3] - nums[0] >= 3 - 0 。\n所以,这是一个平衡子序列,且它的和是所有平衡子序列里最大的。\n最大平衡子序列和为 13 。\n\n示例 3:\n\n输入:nums = [-2,-1]\n输出:-1\n解释:这个例子中,选择子序列 [-1] 。\n这是一个平衡子序列,而且它的和是 nums 所有平衡子序列里最大的。\n\n\n提示:\n\n * 1 <= nums.length <= 105\n * -109 <= nums[i] <= 109\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def maxBalancedSubsequenceSum(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [3,3,5,6] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 14\n\ntest_input = { \"nums\": [5,-1,-3,8] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 13\n\ntest_input = { \"nums\": [-2,-1] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == -1\n\ntest_input = { \"nums\": [0] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 0\n\ntest_input = { \"nums\": [-47] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == -47\n\ntest_input = { \"nums\": [-8] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == -8\n\ntest_input = { \"nums\": [-7] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == -7\n\ntest_input = { \"nums\": [-6] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == -6\n\ntest_input = { \"nums\": [-5] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == -5\n\ntest_input = { \"nums\": [-3] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == -3\n\ntest_input = { \"nums\": [-2] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == -2\n\ntest_input = { \"nums\": [-1] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == -1\n\ntest_input = { \"nums\": [1] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 1\n\ntest_input = { \"nums\": [3] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 3\n\ntest_input = { \"nums\": [4] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 4\n\ntest_input = { \"nums\": [5] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 5\n\ntest_input = { \"nums\": [7] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 7\n\ntest_input = { \"nums\": [8] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 8\n\ntest_input = { \"nums\": [9] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 9\n\ntest_input = { \"nums\": [45] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 45\n\ntest_input = { \"nums\": [-9,-5] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == -5\n\ntest_input = { \"nums\": [-6,8] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 8\n\ntest_input = { \"nums\": [-5,-1] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == -1\n\ntest_input = { \"nums\": [-5,0] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 0\n\ntest_input = { \"nums\": [-3,-1] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == -1\n\ntest_input = { \"nums\": [-2,3] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 3\n\ntest_input = { \"nums\": [-1,-5] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == -1\n\ntest_input = { \"nums\": [-1,0] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 0\n\ntest_input = { \"nums\": [-1,3] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 3\n\ntest_input = { \"nums\": [0,-3] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 0\n\ntest_input = { \"nums\": [0,5] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 5\n\ntest_input = { \"nums\": [2,7] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 9\n\ntest_input = { \"nums\": [5,-1] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 5\n\ntest_input = { \"nums\": [6,-8] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 6\n\ntest_input = { \"nums\": [7,-2] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 7\n\ntest_input = { \"nums\": [7,2] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 7\n\ntest_input = { \"nums\": [8,-9] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 8\n\ntest_input = { \"nums\": [9,-9] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 9\n\ntest_input = { \"nums\": [-43,23,-49] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 23\n\ntest_input = { \"nums\": [-9,-6,-5] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == -5\n\ntest_input = { \"nums\": [-9,-2,4] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 4\n\ntest_input = { \"nums\": [-9,5,-6] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 5\n\ntest_input = { \"nums\": [-8,9,-9] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 9\n\ntest_input = { \"nums\": [-5,-1,-9] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == -1\n\ntest_input = { \"nums\": [-4,-9,3] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 3\n\ntest_input = { \"nums\": [-4,-2,-7] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == -2\n\ntest_input = { \"nums\": [-3,-4,-2] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == -2\n\ntest_input = { \"nums\": [-2,-1,-2] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == -1\n\ntest_input = { \"nums\": [-1,-6,1] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 1\n\ntest_input = { \"nums\": [0,-6,-4] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 0\n\ntest_input = { \"nums\": [0,-5,4] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,-4,4] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 5\n\ntest_input = { \"nums\": [4,1,-8] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 4\n\ntest_input = { \"nums\": [5,-6,-8] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 5\n\ntest_input = { \"nums\": [5,-4,-5] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 5\n\ntest_input = { \"nums\": [6,-3,9] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 15\n\ntest_input = { \"nums\": [6,0,2] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 6\n\ntest_input = { \"nums\": [7,-6,0] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 7\n\ntest_input = { \"nums\": [8,-7,2] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 8\n\ntest_input = { \"nums\": [14,-21,-18] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 14\n\ntest_input = { \"nums\": [-9,7,-8,1] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 7\n\ntest_input = { \"nums\": [-8,2,-5,-7] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 2\n\ntest_input = { \"nums\": [-7,1,-2,-8] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 1\n\ntest_input = { \"nums\": [-6,-8,7,-3] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 7\n\ntest_input = { \"nums\": [-5,-1,0,6] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 6\n\ntest_input = { \"nums\": [-4,8,9,2] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 17\n\ntest_input = { \"nums\": [-4,9,7,-4] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 9\n\ntest_input = { \"nums\": [-2,-6,0,-5] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 0\n\ntest_input = { \"nums\": [-2,-3,9,3] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 9\n\ntest_input = { \"nums\": [0,-6,-3,5] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 5\n\ntest_input = { \"nums\": [0,1,0,-2] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 1\n\ntest_input = { \"nums\": [1,-7,-8,6] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 7\n\ntest_input = { \"nums\": [3,-7,9,-3] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 12\n\ntest_input = { \"nums\": [3,-7,9,2] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 12\n\ntest_input = { \"nums\": [4,-8,-1,8] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 12\n\ntest_input = { \"nums\": [5,4,1,0] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 5\n\ntest_input = { \"nums\": [7,7,-9,-4] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 7\n\ntest_input = { \"nums\": [8,0,4,-2] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 8\n\ntest_input = { \"nums\": [9,7,-2,1] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 9\n\ntest_input = { \"nums\": [34,34,32,33] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 65\n\ntest_input = { \"nums\": [-9,-6,-8,-2,4] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 4\n\ntest_input = { \"nums\": [-9,-5,2,2,7] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 9\n\ntest_input = { \"nums\": [-9,-2,-6,0,6] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 6\n\ntest_input = { \"nums\": [-7,0,-8,-9,-3] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 0\n\ntest_input = { \"nums\": [-7,0,9,-4,9] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 9\n\ntest_input = { \"nums\": [-6,-2,-8,-4,-8] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == -2\n\ntest_input = { \"nums\": [-6,2,-3,0,-5] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 2\n\ntest_input = { \"nums\": [-6,3,-6,-3,-2] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 3\n\ntest_input = { \"nums\": [-5,-9,1,3,-5] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 4\n\ntest_input = { \"nums\": [-5,1,5,-5,-1] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 6\n\ntest_input = { \"nums\": [-3,7,0,4,6] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 10\n\ntest_input = { \"nums\": [-2,-2,9,-2,-8] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 9\n\ntest_input = { \"nums\": [0,-6,-9,-8,-3] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 0\n\ntest_input = { \"nums\": [0,-2,-7,-1,-8] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 0\n\ntest_input = { \"nums\": [0,-1,-4,-6,-9] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 0\n\ntest_input = { \"nums\": [1,-3,-8,9,-9] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 10\n\ntest_input = { \"nums\": [2,-6,-2,0,-3] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 2\n\ntest_input = { \"nums\": [2,9,-4,4,2] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 11\n\ntest_input = { \"nums\": [4,-1,5,-1,-7] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 5\n\ntest_input = { \"nums\": [4,6,-8,-8,-5] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 10", "start_time": 1699151400} +{"task_id": "weekly-contest-369-find-the-k-or-of-an-array", "url": "https://leetcode.com/problems/find-the-k-or-of-an-array", "title": "find-the-k-or-of-an-array", "meta": {"questionId": "3183", "questionFrontendId": "2917", "title": "Find the K-or of an Array", "titleSlug": "find-the-k-or-of-an-array", "isPaidOnly": false, "difficulty": "Easy", "likes": 55, "dislikes": 201, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0 开始的整数数组 nums 和一个整数 k 。\n\nnums 中的 K-or 是一个满足以下条件的非负整数:\n\n * 只有在 nums 中,至少存在 k 个元素的第 i 位值为 1 ,那么 K-or 中的第 i 位的值才是 1 。\n\n返回 nums 的 K-or 值。\n\n注意 :对于整数 x ,如果 (2i AND x) == 2i ,则 x 中的第 i 位值为 1 ,其中 AND 为按位与运算符。\n\n示例 1:\n\n输入:nums = [7,12,9,8,9,15], k = 4\n输出:9\n解释:nums[0]、nums[2]、nums[4] 和 nums[5] 的第 0 位的值为 1 。\nnums[0] 和 nums[5] 的第 1 位的值为 1 。\nnums[0]、nums[1] 和 nums[5] 的第 2 位的值为 1 。\nnums[1]、nums[2]、nums[3]、nums[4] 和 nums[5] 的第 3 位的值为 1 。\n只有第 0 位和第 3 位满足数组中至少存在 k 个元素在对应位上的值为 1 。因此,答案为 2^0 + 2^3 = 9 。\n\n示例 2:\n\n输入:nums = [2,12,1,11,4,5], k = 6\n输出:0\n解释:因为 k == 6 == nums.length ,所以数组的 6-or 等于其中所有元素按位与运算的结果。因此,答案为 2 AND 12 AND 1 AND 11 AND 4 AND 5 = 0 。\n\n示例 3:\n\n输入:nums = [10,8,5,9,11,6,8], k = 1\n输出:15\n解释:因为 k == 1 ,数组的 1-or 等于其中所有元素按位或运算的结果。因此,答案为 10 OR 8 OR 5 OR 9 OR 11 OR 6 OR 8 = 15 。\n\n提示:\n\n * 1 <= nums.length <= 50\n * 0 <= nums[i] < 231\n * 1 <= k <= nums.length\n\"\"\"\nclass Solution:\n def findKOr(self, nums: List[int], k: int) -> int:\n ", "prompt_sft": "给你一个下标从 0 开始的整数数组 nums 和一个整数 k 。\n\nnums 中的 K-or 是一个满足以下条件的非负整数:\n\n * 只有在 nums 中,至少存在 k 个元素的第 i 位值为 1 ,那么 K-or 中的第 i 位的值才是 1 。\n\n返回 nums 的 K-or 值。\n\n注意 :对于整数 x ,如果 (2i AND x) == 2i ,则 x 中的第 i 位值为 1 ,其中 AND 为按位与运算符。\n\n示例 1:\n\n输入:nums = [7,12,9,8,9,15], k = 4\n输出:9\n解释:nums[0]、nums[2]、nums[4] 和 nums[5] 的第 0 位的值为 1 。\nnums[0] 和 nums[5] 的第 1 位的值为 1 。\nnums[0]、nums[1] 和 nums[5] 的第 2 位的值为 1 。\nnums[1]、nums[2]、nums[3]、nums[4] 和 nums[5] 的第 3 位的值为 1 。\n只有第 0 位和第 3 位满足数组中至少存在 k 个元素在对应位上的值为 1 。因此,答案为 2^0 + 2^3 = 9 。\n\n示例 2:\n\n输入:nums = [2,12,1,11,4,5], k = 6\n输出:0\n解释:因为 k == 6 == nums.length ,所以数组的 6-or 等于其中所有元素按位与运算的结果。因此,答案为 2 AND 12 AND 1 AND 11 AND 4 AND 5 = 0 。\n\n示例 3:\n\n输入:nums = [10,8,5,9,11,6,8], k = 1\n输出:15\n解释:因为 k == 1 ,数组的 1-or 等于其中所有元素按位或运算的结果。因此,答案为 10 OR 8 OR 5 OR 9 OR 11 OR 6 OR 8 = 15 。\n\n提示:\n\n * 1 <= nums.length <= 50\n * 0 <= nums[i] < 231\n * 1 <= k <= nums.length\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def findKOr(self, nums: List[int], k: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [7,12,9,8,9,15], \"k\": 4 }\nassert my_solution.findKOr(**test_input) == 9\n\ntest_input = { \"nums\": [2,12,1,11,4,5], \"k\": 6 }\nassert my_solution.findKOr(**test_input) == 0\n\ntest_input = { \"nums\": [10,8,5,9,11,6,8], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 15\n\ntest_input = { \"nums\": [14,7,12,9,8,9,1,15], \"k\": 4 }\nassert my_solution.findKOr(**test_input) == 13\n\ntest_input = { \"nums\": [2,12,1,11,4,5], \"k\": 3 }\nassert my_solution.findKOr(**test_input) == 5\n\ntest_input = { \"nums\": [10,8,5,10,11,11,6,8], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 15\n\ntest_input = { \"nums\": [0], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 0\n\ntest_input = { \"nums\": [1], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 1\n\ntest_input = { \"nums\": [2], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 2\n\ntest_input = { \"nums\": [3], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 3\n\ntest_input = { \"nums\": [4], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 4\n\ntest_input = { \"nums\": [5], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 5\n\ntest_input = { \"nums\": [6], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 6\n\ntest_input = { \"nums\": [7], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 7\n\ntest_input = { \"nums\": [8], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 8\n\ntest_input = { \"nums\": [9], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 9\n\ntest_input = { \"nums\": [10], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 10\n\ntest_input = { \"nums\": [11], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 11\n\ntest_input = { \"nums\": [12], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 12\n\ntest_input = { \"nums\": [13], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 13\n\ntest_input = { \"nums\": [14], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 14\n\ntest_input = { \"nums\": [15], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 15\n\ntest_input = { \"nums\": [16], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 16\n\ntest_input = { \"nums\": [17], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 17\n\ntest_input = { \"nums\": [18], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 18\n\ntest_input = { \"nums\": [19], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 19\n\ntest_input = { \"nums\": [20], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 20\n\ntest_input = { \"nums\": [21], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 21\n\ntest_input = { \"nums\": [22], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 22\n\ntest_input = { \"nums\": [23], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 23\n\ntest_input = { \"nums\": [24], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 24\n\ntest_input = { \"nums\": [25], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 25\n\ntest_input = { \"nums\": [26], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 26\n\ntest_input = { \"nums\": [27], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 27\n\ntest_input = { \"nums\": [28], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 28\n\ntest_input = { \"nums\": [29], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 29\n\ntest_input = { \"nums\": [30], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 30\n\ntest_input = { \"nums\": [31], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 31\n\ntest_input = { \"nums\": [22,7,27,30,15,30,28], \"k\": 4 }\nassert my_solution.findKOr(**test_input) == 30\n\ntest_input = { \"nums\": [24,18,3,23,16,11,27,18,5,29], \"k\": 6 }\nassert my_solution.findKOr(**test_input) == 19\n\ntest_input = { \"nums\": [14,1,2,28,4,15,3,12], \"k\": 2 }\nassert my_solution.findKOr(**test_input) == 15\n\ntest_input = { \"nums\": [7,18,25,11,2], \"k\": 5 }\nassert my_solution.findKOr(**test_input) == 0\n\ntest_input = { \"nums\": [0,4], \"k\": 2 }\nassert my_solution.findKOr(**test_input) == 0\n\ntest_input = { \"nums\": [17,5,14,16,24,30,3,19,31], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 31\n\ntest_input = { \"nums\": [14,20,23,7,1,12,24,19], \"k\": 7 }\nassert my_solution.findKOr(**test_input) == 0\n\ntest_input = { \"nums\": [5,31,29,22,8,6,23], \"k\": 4 }\nassert my_solution.findKOr(**test_input) == 23\n\ntest_input = { \"nums\": [9,10,30,0,7,19,14,19,20,3], \"k\": 4 }\nassert my_solution.findKOr(**test_input) == 31\n\ntest_input = { \"nums\": [25,6,5,30,27,11,10,30], \"k\": 2 }\nassert my_solution.findKOr(**test_input) == 31\n\ntest_input = { \"nums\": [0,15,16,6,19,5,24,17], \"k\": 3 }\nassert my_solution.findKOr(**test_input) == 23\n\ntest_input = { \"nums\": [19,8,2,28,4,5], \"k\": 5 }\nassert my_solution.findKOr(**test_input) == 0\n\ntest_input = { \"nums\": [13,9,1,15,9,2,19,19], \"k\": 3 }\nassert my_solution.findKOr(**test_input) == 11\n\ntest_input = { \"nums\": [16,6,16,22,8,2,25,30], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 31\n\ntest_input = { \"nums\": [14,28,23,22], \"k\": 2 }\nassert my_solution.findKOr(**test_input) == 30\n\ntest_input = { \"nums\": [6,26], \"k\": 2 }\nassert my_solution.findKOr(**test_input) == 2\n\ntest_input = { \"nums\": [14,9,22,30,15], \"k\": 4 }\nassert my_solution.findKOr(**test_input) == 14\n\ntest_input = { \"nums\": [12,13,16,25,12,4,8,29], \"k\": 6 }\nassert my_solution.findKOr(**test_input) == 8\n\ntest_input = { \"nums\": [27,29], \"k\": 2 }\nassert my_solution.findKOr(**test_input) == 25\n\ntest_input = { \"nums\": [9,27,27,20,24,13,25,8], \"k\": 6 }\nassert my_solution.findKOr(**test_input) == 8\n\ntest_input = { \"nums\": [22,26,18,26,1], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 31\n\ntest_input = { \"nums\": [20,20,31,19,29,19], \"k\": 2 }\nassert my_solution.findKOr(**test_input) == 31\n\ntest_input = { \"nums\": [5,8,27,23,3], \"k\": 2 }\nassert my_solution.findKOr(**test_input) == 31\n\ntest_input = { \"nums\": [4,23,0,20,4,19,14,22,26,2], \"k\": 9 }\nassert my_solution.findKOr(**test_input) == 0\n\ntest_input = { \"nums\": [31,26,21,4,9,11,13,24,23,5], \"k\": 10 }\nassert my_solution.findKOr(**test_input) == 0\n\ntest_input = { \"nums\": [4,22], \"k\": 2 }\nassert my_solution.findKOr(**test_input) == 4\n\ntest_input = { \"nums\": [22,17,20,3,21,5,20,25,16], \"k\": 4 }\nassert my_solution.findKOr(**test_input) == 21\n\ntest_input = { \"nums\": [16,15,13,26,15,23,0,12], \"k\": 4 }\nassert my_solution.findKOr(**test_input) == 15\n\ntest_input = { \"nums\": [4,11,14], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 15\n\ntest_input = { \"nums\": [10,26,27,25,3,21,9,3,22], \"k\": 8 }\nassert my_solution.findKOr(**test_input) == 0\n\ntest_input = { \"nums\": [4,11,16], \"k\": 2 }\nassert my_solution.findKOr(**test_input) == 0\n\ntest_input = { \"nums\": [9,27,19,9,24,11], \"k\": 3 }\nassert my_solution.findKOr(**test_input) == 27\n\ntest_input = { \"nums\": [29,19,27,14], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 31\n\ntest_input = { \"nums\": [27,31,21,8,25], \"k\": 2 }\nassert my_solution.findKOr(**test_input) == 31\n\ntest_input = { \"nums\": [14,1,13,22,27], \"k\": 5 }\nassert my_solution.findKOr(**test_input) == 0\n\ntest_input = { \"nums\": [14,15,17,23,29], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 31\n\ntest_input = { \"nums\": [19,21], \"k\": 2 }\nassert my_solution.findKOr(**test_input) == 17\n\ntest_input = { \"nums\": [29,9,18,0,30,5,1,9], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 31\n\ntest_input = { \"nums\": [6,31,11,7,6,2,26,19,17,13], \"k\": 10 }\nassert my_solution.findKOr(**test_input) == 0\n\ntest_input = { \"nums\": [15,8,27,28], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 31\n\ntest_input = { \"nums\": [28,24,20,31,23,1], \"k\": 2 }\nassert my_solution.findKOr(**test_input) == 31\n\ntest_input = { \"nums\": [8,13,27,24,20,28,15,21,23,6], \"k\": 9 }\nassert my_solution.findKOr(**test_input) == 0\n\ntest_input = { \"nums\": [31,6], \"k\": 2 }\nassert my_solution.findKOr(**test_input) == 6\n\ntest_input = { \"nums\": [3,14,11,17,9], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 31\n\ntest_input = { \"nums\": [14,11], \"k\": 2 }\nassert my_solution.findKOr(**test_input) == 10\n\ntest_input = { \"nums\": [2,9,11,25,3,2,26,21,13,11], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 31\n\ntest_input = { \"nums\": [26,7,23,0,16,31,12,18,24], \"k\": 4 }\nassert my_solution.findKOr(**test_input) == 30\n\ntest_input = { \"nums\": [11,30,30,17,10,27,6,31,0], \"k\": 4 }\nassert my_solution.findKOr(**test_input) == 31\n\ntest_input = { \"nums\": [11,9,18,30,27,20,2,17,18,4], \"k\": 2 }\nassert my_solution.findKOr(**test_input) == 31\n\ntest_input = { \"nums\": [2,1,0,30,29,14,13,26,10,22], \"k\": 10 }\nassert my_solution.findKOr(**test_input) == 0\n\ntest_input = { \"nums\": [21,30,30,17,23,8,26,9], \"k\": 6 }\nassert my_solution.findKOr(**test_input) == 16\n\ntest_input = { \"nums\": [16,10], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 26\n\ntest_input = { \"nums\": [26,12,19,22,5,6,19,30,24,11], \"k\": 10 }\nassert my_solution.findKOr(**test_input) == 0\n\ntest_input = { \"nums\": [20,10,14], \"k\": 2 }\nassert my_solution.findKOr(**test_input) == 14\n\ntest_input = { \"nums\": [23,17,18,30,3], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 31\n\ntest_input = { \"nums\": [13,16,12], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 29\n\ntest_input = { \"nums\": [17,12,5,13,23,19], \"k\": 3 }\nassert my_solution.findKOr(**test_input) == 21\n\ntest_input = { \"nums\": [5,4,3], \"k\": 2 }\nassert my_solution.findKOr(**test_input) == 5\n\ntest_input = { \"nums\": [6,28,1,3,2], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 31\n\ntest_input = { \"nums\": [28,3,15,30,10,29], \"k\": 4 }\nassert my_solution.findKOr(**test_input) == 14\n\ntest_input = { \"nums\": [0,31,13,24,16,21], \"k\": 3 }\nassert my_solution.findKOr(**test_input) == 29\n\ntest_input = { \"nums\": [11,20,28,29,3,4], \"k\": 2 }\nassert my_solution.findKOr(**test_input) == 31", "start_time": 1698546600} +{"task_id": "weekly-contest-369-minimum-equal-sum-of-two-arrays-after-replacing-zeros", "url": "https://leetcode.com/problems/minimum-equal-sum-of-two-arrays-after-replacing-zeros", "title": "minimum-equal-sum-of-two-arrays-after-replacing-zeros", "meta": {"questionId": "3171", "questionFrontendId": "2918", "title": "Minimum Equal Sum of Two Arrays After Replacing Zeros", "titleSlug": "minimum-equal-sum-of-two-arrays-after-replacing-zeros", "isPaidOnly": false, "difficulty": "Medium", "likes": 131, "dislikes": 15, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你两个由正整数和 0 组成的数组 nums1 和 nums2 。\n\n你必须将两个数组中的 所有 0 替换为 严格 正整数,并且满足两个数组中所有元素的和 相等 。\n\n返回 最小 相等和 ,如果无法使两数组相等,则返回 -1 。\n\n示例 1:\n\n输入:nums1 = [3,2,0,1,0], nums2 = [6,5,0]\n输出:12\n解释:可以按下述方式替换数组中的 0 :\n- 用 2 和 4 替换 nums1 中的两个 0 。得到 nums1 = [3,2,2,1,4] 。\n- 用 1 替换 nums2 中的一个 0 。得到 nums2 = [6,5,1] 。\n两个数组的元素和相等,都等于 12 。可以证明这是可以获得的最小相等和。\n\n示例 2:\n\n输入:nums1 = [2,0,2,0], nums2 = [1,4]\n输出:-1\n解释:无法使两个数组的和相等。\n\n\n提示:\n\n * 1 <= nums1.length, nums2.length <= 105\n * 0 <= nums1[i], nums2[i] <= 106\n\"\"\"\nclass Solution:\n def minSum(self, nums1: List[int], nums2: List[int]) -> int:\n ", "prompt_sft": "给你两个由正整数和 0 组成的数组 nums1 和 nums2 。\n\n你必须将两个数组中的 所有 0 替换为 严格 正整数,并且满足两个数组中所有元素的和 相等 。\n\n返回 最小 相等和 ,如果无法使两数组相等,则返回 -1 。\n\n示例 1:\n\n输入:nums1 = [3,2,0,1,0], nums2 = [6,5,0]\n输出:12\n解释:可以按下述方式替换数组中的 0 :\n- 用 2 和 4 替换 nums1 中的两个 0 。得到 nums1 = [3,2,2,1,4] 。\n- 用 1 替换 nums2 中的一个 0 。得到 nums2 = [6,5,1] 。\n两个数组的元素和相等,都等于 12 。可以证明这是可以获得的最小相等和。\n\n示例 2:\n\n输入:nums1 = [2,0,2,0], nums2 = [1,4]\n输出:-1\n解释:无法使两个数组的和相等。\n\n\n提示:\n\n * 1 <= nums1.length, nums2.length <= 105\n * 0 <= nums1[i], nums2[i] <= 106\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def minSum(self, nums1: List[int], nums2: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums1\": [3,2,0,1,0], \"nums2\": [6,5,0] }\nassert my_solution.minSum(**test_input) == 12\n\ntest_input = { \"nums1\": [2,0,2,0], \"nums2\": [1,4] }\nassert my_solution.minSum(**test_input) == -1\n\ntest_input = { \"nums1\": [0,7,28,17,18], \"nums2\": [1,2,6,26,1,0,27,3,0,30] }\nassert my_solution.minSum(**test_input) == 98\n\ntest_input = { \"nums1\": [8,13,15,18,0,18,0,0,5,20,12,27,3,14,22,0], \"nums2\": [29,1,6,0,10,24,27,17,14,13,2,19,2,11] }\nassert my_solution.minSum(**test_input) == 179\n\ntest_input = { \"nums1\": [9,5], \"nums2\": [15,12,5,21,4,26,27,9,6,29,0,18,16,0,0,0,20] }\nassert my_solution.minSum(**test_input) == -1\n\ntest_input = { \"nums1\": [0,29,5,22,5,9,30,11,20,0,18,16,26,11,3,0,24,24,14,24], \"nums2\": [30,12,16,3,24,6,13,0,16] }\nassert my_solution.minSum(**test_input) == 294\n\ntest_input = { \"nums1\": [9,13,0,0,12,10,0,8,0,0,5,13,0], \"nums2\": [8,14,11,2,27,0,0] }\nassert my_solution.minSum(**test_input) == 76\n\ntest_input = { \"nums1\": [3,0,20,9,20,0,20,25,26,9,0,12,6,11,0,6], \"nums2\": [0,3,8,13,27,0,0,0,29,27,0,11,23,0,19,19,0] }\nassert my_solution.minSum(**test_input) == 186\n\ntest_input = { \"nums1\": [25,28,13,0,14,23,14,0,3,3,12], \"nums2\": [24,30,0,15,20,19,18,0,23,23,0,16,26,0,29,19,16,25] }\nassert my_solution.minSum(**test_input) == 307\n\ntest_input = { \"nums1\": [0,29,30,18,5,24,16,5,17,0,18,16,26,0,15,19,14,20,3,26], \"nums2\": [0,8,14,11,13,6,8,0,13] }\nassert my_solution.minSum(**test_input) == 304\n\ntest_input = { \"nums1\": [0,17,20,17,5,0,14,19,7,8,16,18,6], \"nums2\": [21,1,27,19,2,2,24,21,16,1,13,27,8,5,3,11,13,7,29,7] }\nassert my_solution.minSum(**test_input) == 257\n\ntest_input = { \"nums1\": [26,1,25,10,14,14,4,0,10,0,23], \"nums2\": [23,8,30,18,8,15,6,9,0,2,0,0,19,8,19,4,10] }\nassert my_solution.minSum(**test_input) == 182\n\ntest_input = { \"nums1\": [15,10,7,16], \"nums2\": [8,16,2,6,4,12,6,16,24,0] }\nassert my_solution.minSum(**test_input) == -1\n\ntest_input = { \"nums1\": [0,0,0,17,0,6,2,22,12,0,25,18,1,12,19,0,0], \"nums2\": [0,0,0,30,4,3,13,25,9,25,3,0,1,12,2,10,4,7,30,16] }\nassert my_solution.minSum(**test_input) == 198\n\ntest_input = { \"nums1\": [23,17], \"nums2\": [7,3,22,0,12] }\nassert my_solution.minSum(**test_input) == -1\n\ntest_input = { \"nums1\": [15,0,8,30,6,3,24,6,0,11,13,30,6,25,23,3], \"nums2\": [12,20,0,6,0,0,14,0,0,8,5,19,16,0,0,15] }\nassert my_solution.minSum(**test_input) == 205\n\ntest_input = { \"nums1\": [3,25,1,13], \"nums2\": [19,13,10,27,10,20,27,0,3,12,16,26,0,27] }\nassert my_solution.minSum(**test_input) == -1\n\ntest_input = { \"nums1\": [0,0], \"nums2\": [29,28] }\nassert my_solution.minSum(**test_input) == 57\n\ntest_input = { \"nums1\": [17,4,11,8,0,17,0,0,12,27,20,28,0,30,21,18,12], \"nums2\": [0,2,30,0,5,17,0,0,0,15,11,2,25,18,18] }\nassert my_solution.minSum(**test_input) == 229\n\ntest_input = { \"nums1\": [0,17,0,7,29,10,22,27,13,8,19], \"nums2\": [26,23,8,14,0,17,20,4,26,15,0,9,14,0,12,10,23,16] }\nassert my_solution.minSum(**test_input) == 240\n\ntest_input = { \"nums1\": [0,25,8,0,22,0], \"nums2\": [6,12,22,3,0,28,19,0,20,21,2,3] }\nassert my_solution.minSum(**test_input) == 138\n\ntest_input = { \"nums1\": [2,17,23,16,2,0,6,12,10], \"nums2\": [19,11,7,16,0] }\nassert my_solution.minSum(**test_input) == 89\n\ntest_input = { \"nums1\": [4,7,14,15,18,7,0,6,8], \"nums2\": [27,2,13,18,20,23,9,0,0,25,5,0,17,0,0,14] }\nassert my_solution.minSum(**test_input) == 178\n\ntest_input = { \"nums1\": [16,0,7,19,0,0,7,26,12,0,4,0,7,0,22,12,0,26], \"nums2\": [7,25,0,25,18,0,6,14,0] }\nassert my_solution.minSum(**test_input) == 165\n\ntest_input = { \"nums1\": [7,0,3,6,5,24,0,0,0,30,20,13,0,5,19,4,25,17], \"nums2\": [11,19,28,25,27,6,0,18,0,19,18,16,0,16,9,0,2,23,23,10] }\nassert my_solution.minSum(**test_input) == 274\n\ntest_input = { \"nums1\": [23,19,24,0,8,19,30,0,14], \"nums2\": [25,17,18,6,30] }\nassert my_solution.minSum(**test_input) == -1\n\ntest_input = { \"nums1\": [0,15,8,0,4,0,21,20,0,0,18], \"nums2\": [16,0] }\nassert my_solution.minSum(**test_input) == 91\n\ntest_input = { \"nums1\": [0,0,24,21,16,4,22,21], \"nums2\": [18,7,28,0,0,11,2,0] }\nassert my_solution.minSum(**test_input) == 110\n\ntest_input = { \"nums1\": [4,11,17,30,11,21,21,10,2,10,7,29,21,1,0,9,15,5], \"nums2\": [0,0,1,7,8,0,27,20] }\nassert my_solution.minSum(**test_input) == 225\n\ntest_input = { \"nums1\": [12,16,1], \"nums2\": [1,0,19,24,21,0,0,24,24,18,26,19,13,14,30,9,0,4,20] }\nassert my_solution.minSum(**test_input) == -1\n\ntest_input = { \"nums1\": [0,0,8,0], \"nums2\": [23,0,15,29,25] }\nassert my_solution.minSum(**test_input) == 93\n\ntest_input = { \"nums1\": [28,25,14,10], \"nums2\": [0,6,16,2,0,13,0,0,4,2,16,6,18,0,8,14,10] }\nassert my_solution.minSum(**test_input) == -1\n\ntest_input = { \"nums1\": [0,0,8,30,1,0,22,0,0,1,0], \"nums2\": [22,6,0,13,0,23,14,27,20,4,0,11,11,25,9,22,11,17,17] }\nassert my_solution.minSum(**test_input) == 255\n\ntest_input = { \"nums1\": [0,0,27], \"nums2\": [18,0,0,7,26,11,28,20,1,19] }\nassert my_solution.minSum(**test_input) == 132\n\ntest_input = { \"nums1\": [30,6,0,8,14,0,15,0,11,13,0,8,28,8,8,0,28,0,25], \"nums2\": [21,8,0,10,28,2,6,3,0,20,1,2,24,12,29] }\nassert my_solution.minSum(**test_input) == 208\n\ntest_input = { \"nums1\": [18,27,20,10,28,12,29,5,24,0,27,9,22,0,14,0,5,11], \"nums2\": [24,0,14,26,1,9,24,0,12,30,13,21] }\nassert my_solution.minSum(**test_input) == 264\n\ntest_input = { \"nums1\": [0,5], \"nums2\": [17,12,5,6,0,13,19,7] }\nassert my_solution.minSum(**test_input) == 80\n\ntest_input = { \"nums1\": [30,2,20,30], \"nums2\": [8,14,0,2,0,18,9,24,0,0,28,0,1,14,27] }\nassert my_solution.minSum(**test_input) == -1\n\ntest_input = { \"nums1\": [0,17,0,1,19,0,0,7,23,0,0,0,5,0], \"nums2\": [7,1,28,8,1,0,0,5,5,18,17,23] }\nassert my_solution.minSum(**test_input) == 115\n\ntest_input = { \"nums1\": [17,4,26,28,0,0,1,0,24,5,4,6,10,8,8,16,27], \"nums2\": [0,18,12,0,0,22,15] }\nassert my_solution.minSum(**test_input) == 187\n\ntest_input = { \"nums1\": [17,1,13,12,3,13], \"nums2\": [2,25] }\nassert my_solution.minSum(**test_input) == -1\n\ntest_input = { \"nums1\": [19,19,21,6,0,0,28,3], \"nums2\": [5,0,16] }\nassert my_solution.minSum(**test_input) == 98\n\ntest_input = { \"nums1\": [27,17,9,23,21,18,8,27,19,3,0,0,0,0,19], \"nums2\": [4,7,27,21,27,0,28,0,28,19,20,14,0,12,24,3] }\nassert my_solution.minSum(**test_input) == 237\n\ntest_input = { \"nums1\": [25,25,0,5,15,13,26,5,25,23,19,20,1,15], \"nums2\": [23,6] }\nassert my_solution.minSum(**test_input) == -1\n\ntest_input = { \"nums1\": [9,0,15,10,18,30,7,0,1,27,24,2,8,0], \"nums2\": [0,0,1,13,0,9,21,3,0,20] }\nassert my_solution.minSum(**test_input) == 154\n\ntest_input = { \"nums1\": [23,7,0,4,21,20,18,3,17,18,4,0,0,13,29,17], \"nums2\": [0,0,18,9,0,11,21,0] }\nassert my_solution.minSum(**test_input) == 197\n\ntest_input = { \"nums1\": [7,0,5,7,19,12,0,11,7,24,22], \"nums2\": [8,3,0,23,19,24,2,10,4,20,0,14] }\nassert my_solution.minSum(**test_input) == 129\n\ntest_input = { \"nums1\": [15,23,12,0,0,1,29,24,0,5,21,9,7,6,27,11,0,19,20], \"nums2\": [14,25,7,18] }\nassert my_solution.minSum(**test_input) == -1\n\ntest_input = { \"nums1\": [26,14,0], \"nums2\": [0,16,0,8,14,7,0,2,0,0,10,10,7,14,0,18,11] }\nassert my_solution.minSum(**test_input) == 123\n\ntest_input = { \"nums1\": [16,15,27,20,29], \"nums2\": [27,19,0,11,2,19,28,16,0,16,24,11,0,4,2,24,8] }\nassert my_solution.minSum(**test_input) == -1\n\ntest_input = { \"nums1\": [26,0,28,0,28,24,15,30,9,17,0,1,21,26,21,8,0,28,0,11], \"nums2\": [0,20,9,12,10,16,2,21,12,0,26,11,0,21,0,0,0,29,23,22] }\nassert my_solution.minSum(**test_input) == 298\n\ntest_input = { \"nums1\": [0,0,9,22,3,14,13,26,21], \"nums2\": [21,9,21,28,17,6,15,11,5,14,17,22,0,24] }\nassert my_solution.minSum(**test_input) == 211\n\ntest_input = { \"nums1\": [0,0,18,27,7,20,9,10,29], \"nums2\": [29,26,19,0,0,0,0,8,24] }\nassert my_solution.minSum(**test_input) == 122\n\ntest_input = { \"nums1\": [5,0,0,0,27,22,0,0,1,9], \"nums2\": [20,22,5,0,0,24,22,27,15] }\nassert my_solution.minSum(**test_input) == 137\n\ntest_input = { \"nums1\": [2,3,0,0,0,1,18,14,25,1,0,0,3,1,13,29,0,11,0,0], \"nums2\": [0,12,5,14,2,0,0,14,1,10,5,17,17,8,0,0,9] }\nassert my_solution.minSum(**test_input) == 129\n\ntest_input = { \"nums1\": [22,0,16,16,27,21,13,9,15,28,0,7,21,8,28,27,26,4], \"nums2\": [0,16,23,0,26,4,0,13,19,0,0,0,14,18,5,14,20,0,27] }\nassert my_solution.minSum(**test_input) == 290\n\ntest_input = { \"nums1\": [26,0,26,18,25,20,20,3,0,14,13,5,13,0,20], \"nums2\": [16,17,0,12,2,26,14,0,27,17,14,10,0,0,28,29,8,25,3,7] }\nassert my_solution.minSum(**test_input) == 259\n\ntest_input = { \"nums1\": [0,25,27,23], \"nums2\": [28,0,12,0,24,4,14,5,16,30,26,15,6,9,28,0] }\nassert my_solution.minSum(**test_input) == 220\n\ntest_input = { \"nums1\": [3,23,15,19,0,7,24,27,25,0,0,16,28,15], \"nums2\": [26,3,21,0,26,0,9,12,0,0,21,28,23,0,0,4,16,9,7] }\nassert my_solution.minSum(**test_input) == 211\n\ntest_input = { \"nums1\": [0,2,0,11,22,0,26,0,1,0,6,0,24,2,24,19,15,12], \"nums2\": [9,14,0,25,24,29,17,16,24,26,1,28,27,4,11,5,14] }\nassert my_solution.minSum(**test_input) == 275\n\ntest_input = { \"nums1\": [1,1,1], \"nums2\": [18] }\nassert my_solution.minSum(**test_input) == -1\n\ntest_input = { \"nums1\": [29,15,0,0,0,0,1,0,9,0,0], \"nums2\": [16,0,30,28,23,0,0,0,0,24,14,27,0,0] }\nassert my_solution.minSum(**test_input) == 169\n\ntest_input = { \"nums1\": [27,10,0,13,25], \"nums2\": [24,10,18,27,3,0,23,6,6] }\nassert my_solution.minSum(**test_input) == 118\n\ntest_input = { \"nums1\": [5,0,10,0,4,0,13,0,27,20,12,10,15,29], \"nums2\": [13,25,4,0,11,0,30,0,29,17,7,28,23] }\nassert my_solution.minSum(**test_input) == 190\n\ntest_input = { \"nums1\": [29,6,30,0,25,8,12,0,25,7,2,15,12,1,5,0,0,12], \"nums2\": [12,14,13,0,0,24,25,22,0,5,8,28,23,6,20,3] }\nassert my_solution.minSum(**test_input) == 206\n\ntest_input = { \"nums1\": [9,11,20,0,0,0,21,25,0,0,0,3,11,5,18], \"nums2\": [0,27,27,21,28,25,3,0,25,0,21,0,3,0,30,20,17] }\nassert my_solution.minSum(**test_input) == 252\n\ntest_input = { \"nums1\": [0,0,10,4], \"nums2\": [9,0,22,9,22,3,16,3,9,19,0,29,3,1,0,1,8,12] }\nassert my_solution.minSum(**test_input) == 169\n\ntest_input = { \"nums1\": [20,10,0,16,18,0,16,21,22,4,0,15,0,8], \"nums2\": [0,1,2,0,20] }\nassert my_solution.minSum(**test_input) == 154\n\ntest_input = { \"nums1\": [23,24,0], \"nums2\": [0,0,26,27,12,18,0] }\nassert my_solution.minSum(**test_input) == 86\n\ntest_input = { \"nums1\": [0,17,27,12,0,22], \"nums2\": [20,0] }\nassert my_solution.minSum(**test_input) == 80\n\ntest_input = { \"nums1\": [1,29], \"nums2\": [20,0,8,11,13,17,0,18,0,2,5,3,27,11,7,17] }\nassert my_solution.minSum(**test_input) == -1\n\ntest_input = { \"nums1\": [19,29,0,0,1,0,0,0,0,24,18,0,24,0,11,14,16,18], \"nums2\": [2,0,26,8,17] }\nassert my_solution.minSum(**test_input) == 182\n\ntest_input = { \"nums1\": [2,0,0,19,6,29], \"nums2\": [25,4,0,11,0,13,28,0,28,7,4,2,16,0,22] }\nassert my_solution.minSum(**test_input) == 164\n\ntest_input = { \"nums1\": [0,0], \"nums2\": [26,5,7,0,1,3,0,7,0,0,5,25,26,20,0,3,20,23,18] }\nassert my_solution.minSum(**test_input) == 194\n\ntest_input = { \"nums1\": [21,2,0,0,12,2,0,4,6,29,15,0], \"nums2\": [12,20,3,10,16,25,17,8,27,0,0,23,2,0,2,4,10,27] }\nassert my_solution.minSum(**test_input) == 209\n\ntest_input = { \"nums1\": [25,29,10,12,25,26,19,6,19,10,18], \"nums2\": [0,0,22,2,17,0,7,23,22,18,20,0,13,22,0,0,0,13,6,8] }\nassert my_solution.minSum(**test_input) == -1\n\ntest_input = { \"nums1\": [0,0,16,23,28,20,0,22,4,1,0,0,19,0,0,3,2,28], \"nums2\": [20,28] }\nassert my_solution.minSum(**test_input) == -1\n\ntest_input = { \"nums1\": [16,14,0,11,9,7,18,2,24,0,0,11,0,0,23], \"nums2\": [0,0,0,7,0,24,24,6,0,0,12,18,1,0,0] }\nassert my_solution.minSum(**test_input) == 140\n\ntest_input = { \"nums1\": [4,15,7,10,8,11,2,0,0,22,11,0,4,14,0,16,29,0,0,27], \"nums2\": [13,23,8,16] }\nassert my_solution.minSum(**test_input) == -1\n\ntest_input = { \"nums1\": [7], \"nums2\": [6,26,25,0,14,19,0,29,16,29,5,26,29,6,0,25,12,0,19,19] }\nassert my_solution.minSum(**test_input) == -1\n\ntest_input = { \"nums1\": [0,10,5,16,13,20,20,0,15,4,0,4,3,0,0,15,0,24,0], \"nums2\": [16,14,27,0,20,0,23,0,5,10,28,21,9,28,21,8,28,0,27,0] }\nassert my_solution.minSum(**test_input) == 290\n\ntest_input = { \"nums1\": [12,14,25,12,3], \"nums2\": [3,26,0,21,22] }\nassert my_solution.minSum(**test_input) == -1\n\ntest_input = { \"nums1\": [0,1,6,20,13,9,28,30,0,14,6,0,25,25,24,16,2,21], \"nums2\": [5,3,0] }\nassert my_solution.minSum(**test_input) == 243\n\ntest_input = { \"nums1\": [0,12,18,0,2,12,29,0,20,29,26,14], \"nums2\": [1,0,29,14,24] }\nassert my_solution.minSum(**test_input) == 165\n\ntest_input = { \"nums1\": [0,21,18,13,9,0,10], \"nums2\": [0,22,27,1,0,0,23,23] }\nassert my_solution.minSum(**test_input) == 99\n\ntest_input = { \"nums1\": [28,16,0,0,0,0,0,26,3,0,3,7,5,0,19,27,1,7], \"nums2\": [28,9,0,16,14] }\nassert my_solution.minSum(**test_input) == 149\n\ntest_input = { \"nums1\": [9,17,6,0,24,18,14,10,14,10,0,0,12,0,3,28,25,5,0,30], \"nums2\": [13,11,30,30,17,27,0,24,15,0,0] }\nassert my_solution.minSum(**test_input) == 230\n\ntest_input = { \"nums1\": [26,2,0,0,13,14,18,17,0], \"nums2\": [27,30,26,14,10,24,17,2,10,25,27] }\nassert my_solution.minSum(**test_input) == 212\n\ntest_input = { \"nums1\": [9,0,26], \"nums2\": [0,16] }\nassert my_solution.minSum(**test_input) == 36\n\ntest_input = { \"nums1\": [4,17,6,0,1,8,19,30,21,11,26,0,0,19,0,12], \"nums2\": [29,17,7,4,29,5,0,25,11,6,0,0,13,22] }\nassert my_solution.minSum(**test_input) == 178\n\ntest_input = { \"nums1\": [1], \"nums2\": [10,29,23,4,0,6,23,23,0,8,29,16,7,20,15,23] }\nassert my_solution.minSum(**test_input) == -1\n\ntest_input = { \"nums1\": [0,20,12,15,0,1,5,4,16,13,8,8,0,28,2,9,0,12], \"nums2\": [13,21,9,0,11,26,0,16,0,29,7,0,0,7,4,0,28,0,2] }\nassert my_solution.minSum(**test_input) == 180\n\ntest_input = { \"nums1\": [0,20,0,0,8,29,17,25,4,0,0,0,0,7,13,14], \"nums2\": [6,21,24,14,20,19,0,0,7,21,0,11,0,0,0,0,17,16,0,6] }\nassert my_solution.minSum(**test_input) == 190\n\ntest_input = { \"nums1\": [28,25,9,0,10,19,23,21,25,8,24,25,18,5], \"nums2\": [0,3,0] }\nassert my_solution.minSum(**test_input) == 241\n\ntest_input = { \"nums1\": [23,7,15,16,25,9,30,14,8,0,0,2,25,1,7,0,16,0,19], \"nums2\": [3,1,24,0,25,0,7,24,0,0,17,27,0] }\nassert my_solution.minSum(**test_input) == 221\n\ntest_input = { \"nums1\": [0,14,10,29,0,5,13,0,0,1,18,0,0,0,11,3,28,0], \"nums2\": [30,2,24,0,0,0,14,12,23,3,17,12,14,13,0,28,29,0,21] }\nassert my_solution.minSum(**test_input) == 247\n\ntest_input = { \"nums1\": [5,29], \"nums2\": [23,24] }\nassert my_solution.minSum(**test_input) == -1\n\ntest_input = { \"nums1\": [23,2,12,27,0,5,14,0,1,6,30,0,0,2,6,0,11,0], \"nums2\": [1,26,27,5,0,14,28,24,2,2,15,25,7,13,9] }\nassert my_solution.minSum(**test_input) == 199\n\ntest_input = { \"nums1\": [0,10,29,11,11,22,0,0,12,10], \"nums2\": [14,0,1,3,13,29,21] }\nassert my_solution.minSum(**test_input) == 108\n\ntest_input = { \"nums1\": [0,9,22,25,28], \"nums2\": [0,0,0,14,19,6,0,7,19,15,0,30,19,18,11,1,0,15,10,18] }\nassert my_solution.minSum(**test_input) == 208", "start_time": 1698546600} +{"task_id": "weekly-contest-369-minimum-increment-operations-to-make-array-beautiful", "url": "https://leetcode.com/problems/minimum-increment-operations-to-make-array-beautiful", "title": "minimum-increment-operations-to-make-array-beautiful", "meta": {"questionId": "3178", "questionFrontendId": "2919", "title": "Minimum Increment Operations to Make Array Beautiful", "titleSlug": "minimum-increment-operations-to-make-array-beautiful", "isPaidOnly": false, "difficulty": "Medium", "likes": 254, "dislikes": 15, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0 开始、长度为 n 的整数数组 nums ,和一个整数 k 。\n\n你可以执行下述 递增 运算 任意 次(可以是 0 次):\n\n * 从范围 [0, n - 1] 中选择一个下标 i ,并将 nums[i] 的值加 1 。\n\n如果数组中任何长度 大于或等于 3 的子数组,其 最大 元素都大于或等于 k ,则认为数组是一个 美丽数组 。\n\n以整数形式返回使数组变为 美丽数组 需要执行的 最小 递增运算数。\n\n子数组是数组中的一个连续 非空 元素序列。\n\n示例 1:\n\n输入:nums = [2,3,0,0,2], k = 4\n输出:3\n解释:可以执行下述递增运算,使 nums 变为美丽数组:\n选择下标 i = 1 ,并且将 nums[1] 的值加 1 -> [2,4,0,0,2] 。\n选择下标 i = 4 ,并且将 nums[4] 的值加 1 -> [2,4,0,0,3] 。\n选择下标 i = 4 ,并且将 nums[4] 的值加 1 -> [2,4,0,0,4] 。\n长度大于或等于 3 的子数组为 [2,4,0], [4,0,0], [0,0,4], [2,4,0,0], [4,0,0,4], [2,4,0,0,4] 。\n在所有子数组中,最大元素都等于 k = 4 ,所以 nums 现在是美丽数组。\n可以证明无法用少于 3 次递增运算使 nums 变为美丽数组。\n因此,答案为 3 。\n\n示例 2:\n\n输入:nums = [0,1,3,3], k = 5\n输出:2\n解释:可以执行下述递增运算,使 nums 变为美丽数组:\n选择下标 i = 2 ,并且将 nums[2] 的值加 1 -> [0,1,4,3] 。\n选择下标 i = 2 ,并且将 nums[2] 的值加 1 -> [0,1,5,3] 。\n长度大于或等于 3 的子数组为 [0,1,5]、[1,5,3]、[0,1,5,3] 。\n在所有子数组中,最大元素都等于 k = 5 ,所以 nums 现在是美丽数组。\n可以证明无法用少于 2 次递增运算使 nums 变为美丽数组。\n因此,答案为 2 。\n\n示例 3:\n\n输入:nums = [1,1,2], k = 1\n输出:0\n解释:在这个示例中,只有一个长度大于或等于 3 的子数组 [1,1,2] 。\n其最大元素 2 已经大于 k = 1 ,所以无需执行任何增量运算。\n因此,答案为 0 。\n\n\n提示:\n\n * 3 <= n == nums.length <= 105\n * 0 <= nums[i] <= 109\n * 0 <= k <= 109\n\"\"\"\nclass Solution:\n def minIncrementOperations(self, nums: List[int], k: int) -> int:\n ", "prompt_sft": "给你一个下标从 0 开始、长度为 n 的整数数组 nums ,和一个整数 k 。\n\n你可以执行下述 递增 运算 任意 次(可以是 0 次):\n\n * 从范围 [0, n - 1] 中选择一个下标 i ,并将 nums[i] 的值加 1 。\n\n如果数组中任何长度 大于或等于 3 的子数组,其 最大 元素都大于或等于 k ,则认为数组是一个 美丽数组 。\n\n以整数形式返回使数组变为 美丽数组 需要执行的 最小 递增运算数。\n\n子数组是数组中的一个连续 非空 元素序列。\n\n示例 1:\n\n输入:nums = [2,3,0,0,2], k = 4\n输出:3\n解释:可以执行下述递增运算,使 nums 变为美丽数组:\n选择下标 i = 1 ,并且将 nums[1] 的值加 1 -> [2,4,0,0,2] 。\n选择下标 i = 4 ,并且将 nums[4] 的值加 1 -> [2,4,0,0,3] 。\n选择下标 i = 4 ,并且将 nums[4] 的值加 1 -> [2,4,0,0,4] 。\n长度大于或等于 3 的子数组为 [2,4,0], [4,0,0], [0,0,4], [2,4,0,0], [4,0,0,4], [2,4,0,0,4] 。\n在所有子数组中,最大元素都等于 k = 4 ,所以 nums 现在是美丽数组。\n可以证明无法用少于 3 次递增运算使 nums 变为美丽数组。\n因此,答案为 3 。\n\n示例 2:\n\n输入:nums = [0,1,3,3], k = 5\n输出:2\n解释:可以执行下述递增运算,使 nums 变为美丽数组:\n选择下标 i = 2 ,并且将 nums[2] 的值加 1 -> [0,1,4,3] 。\n选择下标 i = 2 ,并且将 nums[2] 的值加 1 -> [0,1,5,3] 。\n长度大于或等于 3 的子数组为 [0,1,5]、[1,5,3]、[0,1,5,3] 。\n在所有子数组中,最大元素都等于 k = 5 ,所以 nums 现在是美丽数组。\n可以证明无法用少于 2 次递增运算使 nums 变为美丽数组。\n因此,答案为 2 。\n\n示例 3:\n\n输入:nums = [1,1,2], k = 1\n输出:0\n解释:在这个示例中,只有一个长度大于或等于 3 的子数组 [1,1,2] 。\n其最大元素 2 已经大于 k = 1 ,所以无需执行任何增量运算。\n因此,答案为 0 。\n\n\n提示:\n\n * 3 <= n == nums.length <= 105\n * 0 <= nums[i] <= 109\n * 0 <= k <= 109\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def minIncrementOperations(self, nums: List[int], k: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [2,3,0,0,2], \"k\": 4 }\nassert my_solution.minIncrementOperations(**test_input) == 3\n\ntest_input = { \"nums\": [0,1,3,3], \"k\": 5 }\nassert my_solution.minIncrementOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,2], \"k\": 1 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [0,5,5], \"k\": 8 }\nassert my_solution.minIncrementOperations(**test_input) == 3\n\ntest_input = { \"nums\": [0,18,28], \"k\": 93 }\nassert my_solution.minIncrementOperations(**test_input) == 65\n\ntest_input = { \"nums\": [0,24,14], \"k\": 7 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [2,3,4], \"k\": 3 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [3,5,9], \"k\": 6 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [4,3,0], \"k\": 2 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [5,6,5], \"k\": 9 }\nassert my_solution.minIncrementOperations(**test_input) == 3\n\ntest_input = { \"nums\": [6,9,6], \"k\": 3 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [7,9,0], \"k\": 6 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [7,47,16], \"k\": 39 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [9,6,1], \"k\": 6 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [41,44,37], \"k\": 55 }\nassert my_solution.minIncrementOperations(**test_input) == 11\n\ntest_input = { \"nums\": [48,3,13], \"k\": 1 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [1,2,6,9], \"k\": 8 }\nassert my_solution.minIncrementOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,3,1,6], \"k\": 6 }\nassert my_solution.minIncrementOperations(**test_input) == 3\n\ntest_input = { \"nums\": [2,35,41,20], \"k\": 4 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [3,9,9,7], \"k\": 6 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [7,7,2,7], \"k\": 9 }\nassert my_solution.minIncrementOperations(**test_input) == 2\n\ntest_input = { \"nums\": [10,2,0,2], \"k\": 6 }\nassert my_solution.minIncrementOperations(**test_input) == 4\n\ntest_input = { \"nums\": [20,2,22,30], \"k\": 67 }\nassert my_solution.minIncrementOperations(**test_input) == 45\n\ntest_input = { \"nums\": [22,49,0,20], \"k\": 52 }\nassert my_solution.minIncrementOperations(**test_input) == 3\n\ntest_input = { \"nums\": [25,2,1,41], \"k\": 9 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [31,86,1,2], \"k\": 354 }\nassert my_solution.minIncrementOperations(**test_input) == 268\n\ntest_input = { \"nums\": [43,31,14,4], \"k\": 73 }\nassert my_solution.minIncrementOperations(**test_input) == 42\n\ntest_input = { \"nums\": [44,24,28,47], \"k\": 16 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [1,9,5,2,0], \"k\": 2 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [3,7,9,6,0], \"k\": 7 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [5,9,0,10,3], \"k\": 3 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [6,2,8,10,6], \"k\": 9 }\nassert my_solution.minIncrementOperations(**test_input) == 1\n\ntest_input = { \"nums\": [6,14,17,4,7], \"k\": 22 }\nassert my_solution.minIncrementOperations(**test_input) == 5\n\ntest_input = { \"nums\": [10,9,5,2,4], \"k\": 1 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [20,38,29,34,6], \"k\": 95 }\nassert my_solution.minIncrementOperations(**test_input) == 66\n\ntest_input = { \"nums\": [21,45,33,14,22], \"k\": 58 }\nassert my_solution.minIncrementOperations(**test_input) == 25\n\ntest_input = { \"nums\": [32,14,31,43,29], \"k\": 46 }\nassert my_solution.minIncrementOperations(**test_input) == 15\n\ntest_input = { \"nums\": [39,21,10,46,40], \"k\": 81 }\nassert my_solution.minIncrementOperations(**test_input) == 71\n\ntest_input = { \"nums\": [42,7,32,19,4], \"k\": 66 }\nassert my_solution.minIncrementOperations(**test_input) == 34\n\ntest_input = { \"nums\": [74,91,93,96,12], \"k\": 964 }\nassert my_solution.minIncrementOperations(**test_input) == 871\n\ntest_input = { \"nums\": [84,17,58,61,72], \"k\": 432 }\nassert my_solution.minIncrementOperations(**test_input) == 374\n\ntest_input = { \"nums\": [4,0,10,2,10,6], \"k\": 8 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [4,0,22,41,29,28], \"k\": 30 }\nassert my_solution.minIncrementOperations(**test_input) == 8\n\ntest_input = { \"nums\": [4,1,8,0,3,9], \"k\": 2 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [4,7,6,9,2,6], \"k\": 1 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [5,1,3,9,8,8], \"k\": 4 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [6,5,8,6,0,9], \"k\": 9 }\nassert my_solution.minIncrementOperations(**test_input) == 1\n\ntest_input = { \"nums\": [7,4,10,2,0,8], \"k\": 7 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [8,10,7,1,9,6], \"k\": 1 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [9,5,0,10,9,0], \"k\": 8 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [13,34,0,13,9,19], \"k\": 82 }\nassert my_solution.minIncrementOperations(**test_input) == 117\n\ntest_input = { \"nums\": [16,50,23,35,38,13], \"k\": 34 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [20,1,40,48,32,24], \"k\": 38 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [28,5,10,26,38,6], \"k\": 17 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [30,42,46,45,23,31], \"k\": 13 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [3,8,0,6,46,24,31], \"k\": 30 }\nassert my_solution.minIncrementOperations(**test_input) == 22\n\ntest_input = { \"nums\": [4,7,2,10,4,10,5], \"k\": 10 }\nassert my_solution.minIncrementOperations(**test_input) == 3\n\ntest_input = { \"nums\": [8,10,1,5,8,9,7], \"k\": 4 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [10,7,2,5,9,6,3], \"k\": 2 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [10,24,21,42,6,10,43], \"k\": 55 }\nassert my_solution.minIncrementOperations(**test_input) == 56\n\ntest_input = { \"nums\": [18,48,1,19,43,25,49], \"k\": 21 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [37,82,95,82,77,87,93], \"k\": 239 }\nassert my_solution.minIncrementOperations(**test_input) == 296\n\ntest_input = { \"nums\": [40,17,28,38,41,32,9], \"k\": 97 }\nassert my_solution.minIncrementOperations(**test_input) == 125\n\ntest_input = { \"nums\": [41,22,4,41,4,47,36], \"k\": 25 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [42,19,52,36,8,5,9], \"k\": 656 }\nassert my_solution.minIncrementOperations(**test_input) == 1252\n\ntest_input = { \"nums\": [45,58,6,16,70,69,87], \"k\": 26 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [48,24,41,16,4,20,38], \"k\": 97 }\nassert my_solution.minIncrementOperations(**test_input) == 133\n\ntest_input = { \"nums\": [50,3,17,36,16,10,2], \"k\": 19 }\nassert my_solution.minIncrementOperations(**test_input) == 3\n\ntest_input = { \"nums\": [57,41,90,16,41,25,2], \"k\": 934 }\nassert my_solution.minIncrementOperations(**test_input) == 1737\n\ntest_input = { \"nums\": [74,33,13,74,75,95,11], \"k\": 426 }\nassert my_solution.minIncrementOperations(**test_input) == 744\n\ntest_input = { \"nums\": [83,54,75,22,32,59,30], \"k\": 298 }\nassert my_solution.minIncrementOperations(**test_input) == 462\n\ntest_input = { \"nums\": [1,9,3,6,3,1,10,4], \"k\": 2 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [1,29,18,3,38,4,7,47], \"k\": 67 }\nassert my_solution.minIncrementOperations(**test_input) == 87\n\ntest_input = { \"nums\": [2,1,1,7,2,3,5,6], \"k\": 9 }\nassert my_solution.minIncrementOperations(**test_input) == 13\n\ntest_input = { \"nums\": [2,3,6,3,0,0,7,4], \"k\": 8 }\nassert my_solution.minIncrementOperations(**test_input) == 8\n\ntest_input = { \"nums\": [2,9,6,9,1,9,4,0], \"k\": 6 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [5,1,6,9,5,4,9,2], \"k\": 10 }\nassert my_solution.minIncrementOperations(**test_input) == 6\n\ntest_input = { \"nums\": [5,10,8,7,6,7,1,10], \"k\": 3 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [6,7,9,5,0,2,7,7], \"k\": 1 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [7,2,2,6,7,5,0,2], \"k\": 3 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [7,12,36,8,27,48,39,35], \"k\": 36 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [15,47,34,46,42,26,23,11], \"k\": 15 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [19,40,43,32,15,7,43,5], \"k\": 85 }\nassert my_solution.minIncrementOperations(**test_input) == 120\n\ntest_input = { \"nums\": [22,45,6,7,7,23,6,3], \"k\": 43 }\nassert my_solution.minIncrementOperations(**test_input) == 56\n\ntest_input = { \"nums\": [25,1,70,71,54,96,46,77], \"k\": 549 }\nassert my_solution.minIncrementOperations(**test_input) == 932\n\ntest_input = { \"nums\": [33,41,14,18,43,20,49,23], \"k\": 25 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [39,26,16,36,19,5,6,28], \"k\": 98 }\nassert my_solution.minIncrementOperations(**test_input) == 175\n\ntest_input = { \"nums\": [44,44,31,36,1,8,39,46], \"k\": 45 }\nassert my_solution.minIncrementOperations(**test_input) == 16\n\ntest_input = { \"nums\": [2,17,43,26,33,12,37,28,34], \"k\": 3 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [3,1,6,1,0,5,4,5,7], \"k\": 10 }\nassert my_solution.minIncrementOperations(**test_input) == 12\n\ntest_input = { \"nums\": [3,10,4,2,9,8,2,1,4], \"k\": 7 }\nassert my_solution.minIncrementOperations(**test_input) == 3\n\ntest_input = { \"nums\": [7,5,4,7,6,5,10,8,8], \"k\": 8 }\nassert my_solution.minIncrementOperations(**test_input) == 2\n\ntest_input = { \"nums\": [7,40,36,45,42,23,10,33,17], \"k\": 25 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [10,4,7,4,8,7,8,4,6], \"k\": 3 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [12,32,12,13,18,38,21,15,13], \"k\": 95 }\nassert my_solution.minIncrementOperations(**test_input) == 214\n\ntest_input = { \"nums\": [17,50,14,27,10,37,24,35,23], \"k\": 45 }\nassert my_solution.minIncrementOperations(**test_input) == 36\n\ntest_input = { \"nums\": [20,17,29,44,18,20,17,26,2], \"k\": 1 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [28,4,38,38,37,13,47,48,49], \"k\": 61 }\nassert my_solution.minIncrementOperations(**test_input) == 60\n\ntest_input = { \"nums\": [29,0,34,5,5,24,43,23,27], \"k\": 98 }\nassert my_solution.minIncrementOperations(**test_input) == 193\n\ntest_input = { \"nums\": [41,53,77,44,79,66,2,46,64], \"k\": 204 }\nassert my_solution.minIncrementOperations(**test_input) == 405", "start_time": 1698546600} +{"task_id": "weekly-contest-369-maximum-points-after-collecting-coins-from-all-nodes", "url": "https://leetcode.com/problems/maximum-points-after-collecting-coins-from-all-nodes", "title": "maximum-points-after-collecting-coins-from-all-nodes", "meta": {"questionId": "3179", "questionFrontendId": "2920", "title": "Maximum Points After Collecting Coins From All Nodes", "titleSlug": "maximum-points-after-collecting-coins-from-all-nodes", "isPaidOnly": false, "difficulty": "Hard", "likes": 161, "dislikes": 11, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n有一棵由 n 个节点组成的无向树,以 0  为根节点,节点编号从 0 到 n - 1 。给你一个长度为 n - 1 的二维 整数 数组 edges ,其中 edges[i] = [ai, bi] 表示在树上的节点 ai 和 bi 之间存在一条边。另给你一个下标从 0 开始、长度为 n 的数组 coins 和一个整数 k ,其中 coins[i] 表示节点 i 处的金币数量。\n\n从根节点开始,你必须收集所有金币。要想收集节点上的金币,必须先收集该节点的祖先节点上的金币。\n\n节点 i 上的金币可以用下述方法之一进行收集:\n\n * 收集所有金币,得到共计 coins[i] - k 点积分。如果 coins[i] - k 是负数,你将会失去 abs(coins[i] - k) 点积分。\n * 收集所有金币,得到共计 floor(coins[i] / 2) 点积分。如果采用这种方法,节点 i 子树中所有节点 j 的金币数 coins[j] 将会减少至 floor(coins[j] / 2) 。\n\n返回收集 所有 树节点的金币之后可以获得的最大积分。\n\n示例 1:\n\n[https://assets.leetcode.com/uploads/2023/09/18/ex1-copy.png]\n\n输入:edges = [[0,1],[1,2],[2,3]], coins = [10,10,3,3], k = 5\n输出:11\n解释:\n使用第一种方法收集节点 0 上的所有金币。总积分 = 10 - 5 = 5 。\n使用第一种方法收集节点 1 上的所有金币。总积分 = 5 + (10 - 5) = 10 。\n使用第二种方法收集节点 2 上的所有金币。所以节点 3 上的金币将会变为 floor(3 / 2) = 1 ,总积分 = 10 + floor(3 / 2) = 11 。\n使用第二种方法收集节点 3 上的所有金币。总积分 = 11 + floor(1 / 2) = 11.\n可以证明收集所有节点上的金币能获得的最大积分是 11 。\n\n示例 2:\n\n[https://assets.leetcode.com/uploads/2023/09/18/ex2.png]\n\n输入:edges = [[0,1],[0,2]], coins = [8,4,4], k = 0\n输出:16\n解释:\n使用第一种方法收集所有节点上的金币,因此,总积分 = (8 - 0) + (4 - 0) + (4 - 0) = 16 。\n\n\n提示:\n\n * n == coins.length\n * 2 <= n <= 105\n * 0 <= coins[i] <= 104\n * edges.length == n - 1\n * 0 <= edges[i][0], edges[i][1] < n\n * 0 <= k <= 104\n\"\"\"\nclass Solution:\n def maximumPoints(self, edges: List[List[int]], coins: List[int], k: int) -> int:\n ", "prompt_sft": "有一棵由 n 个节点组成的无向树,以 0  为根节点,节点编号从 0 到 n - 1 。给你一个长度为 n - 1 的二维 整数 数组 edges ,其中 edges[i] = [ai, bi] 表示在树上的节点 ai 和 bi 之间存在一条边。另给你一个下标从 0 开始、长度为 n 的数组 coins 和一个整数 k ,其中 coins[i] 表示节点 i 处的金币数量。\n\n从根节点开始,你必须收集所有金币。要想收集节点上的金币,必须先收集该节点的祖先节点上的金币。\n\n节点 i 上的金币可以用下述方法之一进行收集:\n\n * 收集所有金币,得到共计 coins[i] - k 点积分。如果 coins[i] - k 是负数,你将会失去 abs(coins[i] - k) 点积分。\n * 收集所有金币,得到共计 floor(coins[i] / 2) 点积分。如果采用这种方法,节点 i 子树中所有节点 j 的金币数 coins[j] 将会减少至 floor(coins[j] / 2) 。\n\n返回收集 所有 树节点的金币之后可以获得的最大积分。\n\n示例 1:\n\n[https://assets.leetcode.com/uploads/2023/09/18/ex1-copy.png]\n\n输入:edges = [[0,1],[1,2],[2,3]], coins = [10,10,3,3], k = 5\n输出:11\n解释:\n使用第一种方法收集节点 0 上的所有金币。总积分 = 10 - 5 = 5 。\n使用第一种方法收集节点 1 上的所有金币。总积分 = 5 + (10 - 5) = 10 。\n使用第二种方法收集节点 2 上的所有金币。所以节点 3 上的金币将会变为 floor(3 / 2) = 1 ,总积分 = 10 + floor(3 / 2) = 11 。\n使用第二种方法收集节点 3 上的所有金币。总积分 = 11 + floor(1 / 2) = 11.\n可以证明收集所有节点上的金币能获得的最大积分是 11 。\n\n示例 2:\n\n[https://assets.leetcode.com/uploads/2023/09/18/ex2.png]\n\n输入:edges = [[0,1],[0,2]], coins = [8,4,4], k = 0\n输出:16\n解释:\n使用第一种方法收集所有节点上的金币,因此,总积分 = (8 - 0) + (4 - 0) + (4 - 0) = 16 。\n\n\n提示:\n\n * n == coins.length\n * 2 <= n <= 105\n * 0 <= coins[i] <= 104\n * edges.length == n - 1\n * 0 <= edges[i][0], edges[i][1] < n\n * 0 <= k <= 104\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def maximumPoints(self, edges: List[List[int]], coins: List[int], k: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"edges\": [[0,1],[1,2],[2,3]], \"coins\": [10,10,3,3], \"k\": 5 }\nassert my_solution.maximumPoints(**test_input) == 11\n\ntest_input = { \"edges\": [[0,1],[0,2]], \"coins\": [8,4,4], \"k\": 0 }\nassert my_solution.maximumPoints(**test_input) == 16\n\ntest_input = { \"edges\": [[0,1],[2,0],[0,3],[4,2]], \"coins\": [7,5,0,9,3], \"k\": 4 }\nassert my_solution.maximumPoints(**test_input) == 10\n\ntest_input = { \"edges\": [[1,0],[0,2],[1,3]], \"coins\": [9,3,8,9], \"k\": 0 }\nassert my_solution.maximumPoints(**test_input) == 29\n\ntest_input = { \"edges\": [[0,1],[0,2],[3,2],[0,4]], \"coins\": [5,6,8,7,4], \"k\": 7 }\nassert my_solution.maximumPoints(**test_input) == 8\n\ntest_input = { \"edges\": [[1,0],[2,1],[3,1]], \"coins\": [8,2,7,1], \"k\": 2 }\nassert my_solution.maximumPoints(**test_input) == 11\n\ntest_input = { \"edges\": [[0,1],[1,2],[0,3]], \"coins\": [6,1,2,3], \"k\": 2 }\nassert my_solution.maximumPoints(**test_input) == 5\n\ntest_input = { \"edges\": [[0,1],[0,2],[0,3],[2,4],[5,4],[6,0],[4,7],[8,5]], \"coins\": [2,3,10,0,0,2,7,3,9], \"k\": 2 }\nassert my_solution.maximumPoints(**test_input) == 20\n\ntest_input = { \"edges\": [[0,1],[0,2],[1,3],[3,4],[0,5],[6,3],[5,7],[3,8],[9,7]], \"coins\": [0,5,10,5,6,5,0,2,0,0], \"k\": 7 }\nassert my_solution.maximumPoints(**test_input) == 4\n\ntest_input = { \"edges\": [[0,1],[2,1],[3,0],[3,4],[5,0],[6,4],[7,1],[6,8],[9,5]], \"coins\": [9,0,9,6,7,6,5,7,1,10], \"k\": 7 }\nassert my_solution.maximumPoints(**test_input) == 14\n\ntest_input = { \"edges\": [[0,1],[2,1],[3,2],[4,0],[5,2],[3,6],[7,2],[8,4],[9,2]], \"coins\": [9,4,0,8,0,7,8,1,10,9], \"k\": 1 }\nassert my_solution.maximumPoints(**test_input) == 46\n\ntest_input = { \"edges\": [[1,0],[2,1],[3,1],[2,4],[5,4],[6,3],[6,7]], \"coins\": [9,9,5,5,7,9,6,9], \"k\": 8 }\nassert my_solution.maximumPoints(**test_input) == 10\n\ntest_input = { \"edges\": [[0,1],[2,1],[2,3],[4,0],[5,2],[6,1]], \"coins\": [1,1,8,6,9,4,1], \"k\": 10 }\nassert my_solution.maximumPoints(**test_input) == 3\n\ntest_input = { \"edges\": [[1,0],[1,2],[0,3]], \"coins\": [10,2,9,3], \"k\": 6 }\nassert my_solution.maximumPoints(**test_input) == 8\n\ntest_input = { \"edges\": [[1,0],[1,2],[1,3],[3,4],[5,3],[4,6],[7,0],[1,8],[9,1]], \"coins\": [2,10,4,0,1,3,6,10,3,6], \"k\": 8 }\nassert my_solution.maximumPoints(**test_input) == 7\n\ntest_input = { \"edges\": [[1,0],[0,2],[3,2],[4,3],[2,5],[1,6],[7,2]], \"coins\": [2,8,3,1,9,4,8,6], \"k\": 6 }\nassert my_solution.maximumPoints(**test_input) == 6\n\ntest_input = { \"edges\": [[1,0],[2,0],[3,0]], \"coins\": [0,0,0,6], \"k\": 0 }\nassert my_solution.maximumPoints(**test_input) == 6\n\ntest_input = { \"edges\": [[1,0],[1,2]], \"coins\": [7,6,0], \"k\": 6 }\nassert my_solution.maximumPoints(**test_input) == 4\n\ntest_input = { \"edges\": [[0,1],[0,2],[1,3],[2,4],[5,4]], \"coins\": [4,2,7,7,4,9], \"k\": 6 }\nassert my_solution.maximumPoints(**test_input) == 5\n\ntest_input = { \"edges\": [[0,1]], \"coins\": [10,9], \"k\": 6 }\nassert my_solution.maximumPoints(**test_input) == 8\n\ntest_input = { \"edges\": [[0,1],[2,1],[3,1],[2,4],[5,0],[6,1]], \"coins\": [6,1,8,10,0,4,10], \"k\": 5 }\nassert my_solution.maximumPoints(**test_input) == 13\n\ntest_input = { \"edges\": [[1,0],[2,0],[0,3],[0,4],[5,1],[6,4],[3,7],[5,8]], \"coins\": [9,0,4,2,0,0,3,1,8], \"k\": 5 }\nassert my_solution.maximumPoints(**test_input) == 8\n\ntest_input = { \"edges\": [[0,1],[1,2],[3,2],[4,0]], \"coins\": [7,5,6,3,6], \"k\": 8 }\nassert my_solution.maximumPoints(**test_input) == 5\n\ntest_input = { \"edges\": [[0,1],[1,2],[3,2],[4,2],[5,3],[6,1],[4,7],[7,8],[2,9]], \"coins\": [4,2,0,8,3,2,7,2,1,6], \"k\": 2 }\nassert my_solution.maximumPoints(**test_input) == 18\n\ntest_input = { \"edges\": [[0,1],[1,2],[1,3],[4,0],[3,5],[6,3],[7,6],[8,0]], \"coins\": [3,3,4,3,1,3,1,6,3], \"k\": 1 }\nassert my_solution.maximumPoints(**test_input) == 18\n\ntest_input = { \"edges\": [[1,0],[2,1],[2,3],[4,1],[4,5],[2,6]], \"coins\": [3,10,1,5,10,1,4], \"k\": 2 }\nassert my_solution.maximumPoints(**test_input) == 21\n\ntest_input = { \"edges\": [[0,1],[2,0]], \"coins\": [7,10,8], \"k\": 10 }\nassert my_solution.maximumPoints(**test_input) == 7\n\ntest_input = { \"edges\": [[1,0],[2,1],[3,1],[4,2],[5,3],[6,0],[7,4]], \"coins\": [1,1,7,10,5,1,7,8], \"k\": 7 }\nassert my_solution.maximumPoints(**test_input) == 2\n\ntest_input = { \"edges\": [[1,0],[0,2],[3,2]], \"coins\": [5,2,10,5], \"k\": 3 }\nassert my_solution.maximumPoints(**test_input) == 12\n\ntest_input = { \"edges\": [[1,0],[2,0],[3,2],[2,4],[4,5],[6,2],[5,7],[8,2]], \"coins\": [4,2,1,4,7,7,2,7,4], \"k\": 2 }\nassert my_solution.maximumPoints(**test_input) == 22\n\ntest_input = { \"edges\": [[1,0]], \"coins\": [8,1], \"k\": 7 }\nassert my_solution.maximumPoints(**test_input) == 4\n\ntest_input = { \"edges\": [[1,0],[0,2],[3,0],[3,4],[3,5],[6,0],[7,5]], \"coins\": [3,9,9,9,5,3,2,0], \"k\": 9 }\nassert my_solution.maximumPoints(**test_input) == 8\n\ntest_input = { \"edges\": [[0,1],[2,1],[3,2],[4,1],[2,5]], \"coins\": [2,10,4,6,7,9], \"k\": 5 }\nassert my_solution.maximumPoints(**test_input) == 11\n\ntest_input = { \"edges\": [[1,0],[2,1],[3,2],[3,4],[5,4],[2,6],[7,3]], \"coins\": [3,3,6,1,10,1,2,5], \"k\": 3 }\nassert my_solution.maximumPoints(**test_input) == 11\n\ntest_input = { \"edges\": [[1,0],[2,0],[0,3],[1,4],[3,5],[0,6],[7,4],[1,8]], \"coins\": [9,7,9,0,3,6,9,4,0], \"k\": 8 }\nassert my_solution.maximumPoints(**test_input) == 13\n\ntest_input = { \"edges\": [[0,1],[2,1],[3,0],[2,4],[1,5],[6,1],[7,3],[5,8]], \"coins\": [4,9,7,6,6,9,0,2,6], \"k\": 2 }\nassert my_solution.maximumPoints(**test_input) == 34\n\ntest_input = { \"edges\": [[1,0],[1,2]], \"coins\": [4,4,6], \"k\": 3 }\nassert my_solution.maximumPoints(**test_input) == 5\n\ntest_input = { \"edges\": [[0,1],[0,2],[3,1],[2,4],[4,5],[6,2],[4,7],[4,8],[9,1]], \"coins\": [8,6,10,9,3,10,3,7,9,1], \"k\": 6 }\nassert my_solution.maximumPoints(**test_input) == 21\n\ntest_input = { \"edges\": [[1,0],[2,1],[0,3],[0,4],[5,3],[6,1],[7,5],[8,2],[9,3]], \"coins\": [1,3,10,0,7,2,8,10,0,5], \"k\": 0 }\nassert my_solution.maximumPoints(**test_input) == 46\n\ntest_input = { \"edges\": [[0,1],[2,0]], \"coins\": [9,4,2], \"k\": 0 }\nassert my_solution.maximumPoints(**test_input) == 15\n\ntest_input = { \"edges\": [[0,1],[2,1]], \"coins\": [0,9,3], \"k\": 3 }\nassert my_solution.maximumPoints(**test_input) == 4\n\ntest_input = { \"edges\": [[1,0],[2,1],[3,2],[4,1],[3,5]], \"coins\": [10,10,8,6,0,0], \"k\": 1 }\nassert my_solution.maximumPoints(**test_input) == 30\n\ntest_input = { \"edges\": [[0,1],[2,0],[3,0],[3,4],[5,1],[6,1],[7,2],[8,3],[0,9]], \"coins\": [6,4,5,2,1,10,10,9,8,10], \"k\": 1 }\nassert my_solution.maximumPoints(**test_input) == 55\n\ntest_input = { \"edges\": [[0,1],[2,1],[3,2],[0,4],[1,5],[6,5],[7,1],[5,8],[1,9]], \"coins\": [8,0,9,5,9,6,2,8,1,8], \"k\": 9 }\nassert my_solution.maximumPoints(**test_input) == 10\n\ntest_input = { \"edges\": [[0,1],[2,1],[2,3],[1,4],[3,5],[6,4],[7,6]], \"coins\": [8,2,3,10,4,5,8,8], \"k\": 1 }\nassert my_solution.maximumPoints(**test_input) == 40\n\ntest_input = { \"edges\": [[0,1],[2,0],[0,3],[4,1],[5,2],[6,1],[7,1]], \"coins\": [3,9,4,4,3,4,10,4], \"k\": 2 }\nassert my_solution.maximumPoints(**test_input) == 25\n\ntest_input = { \"edges\": [[1,0],[1,2],[3,0],[4,1],[5,1],[1,6],[1,7]], \"coins\": [7,4,7,2,5,8,0,7], \"k\": 8 }\nassert my_solution.maximumPoints(**test_input) == 8\n\ntest_input = { \"edges\": [[0,1],[2,1],[3,1],[4,2],[5,4],[6,5],[7,5]], \"coins\": [4,5,7,5,0,4,6,7], \"k\": 4 }\nassert my_solution.maximumPoints(**test_input) == 8\n\ntest_input = { \"edges\": [[1,0],[1,2],[1,3]], \"coins\": [8,4,10,7], \"k\": 1 }\nassert my_solution.maximumPoints(**test_input) == 25\n\ntest_input = { \"edges\": [[0,1],[2,1],[2,3],[3,4],[4,5],[6,3],[3,7],[7,8],[9,8]], \"coins\": [0,2,1,5,8,2,5,3,7,6], \"k\": 10 }\nassert my_solution.maximumPoints(**test_input) == 0\n\ntest_input = { \"edges\": [[1,0],[1,2],[3,0],[4,3],[1,5],[6,2],[7,3],[4,8],[4,9]], \"coins\": [6,5,1,8,8,10,5,7,7,1], \"k\": 5 }\nassert my_solution.maximumPoints(**test_input) == 19\n\ntest_input = { \"edges\": [[0,1],[2,0],[2,3],[4,2],[5,0],[3,6],[7,5],[3,8],[9,8]], \"coins\": [9,6,4,10,4,1,6,1,5,9], \"k\": 6 }\nassert my_solution.maximumPoints(**test_input) == 17\n\ntest_input = { \"edges\": [[0,1],[2,1],[3,1],[0,4],[3,5]], \"coins\": [1,9,3,4,9,3], \"k\": 6 }\nassert my_solution.maximumPoints(**test_input) == 5\n\ntest_input = { \"edges\": [[0,1],[0,2]], \"coins\": [9,3,9], \"k\": 3 }\nassert my_solution.maximumPoints(**test_input) == 13\n\ntest_input = { \"edges\": [[0,1],[2,0],[3,1],[2,4],[5,2],[6,5],[7,3],[8,5],[9,5]], \"coins\": [4,1,3,1,6,1,0,0,0,6], \"k\": 1 }\nassert my_solution.maximumPoints(**test_input) == 15\n\ntest_input = { \"edges\": [[0,1]], \"coins\": [1,7], \"k\": 10 }\nassert my_solution.maximumPoints(**test_input) == 1\n\ntest_input = { \"edges\": [[0,1]], \"coins\": [10,6], \"k\": 10 }\nassert my_solution.maximumPoints(**test_input) == 6\n\ntest_input = { \"edges\": [[1,0],[1,2],[2,3],[0,4]], \"coins\": [6,7,8,1,9], \"k\": 9 }\nassert my_solution.maximumPoints(**test_input) == 7\n\ntest_input = { \"edges\": [[0,1]], \"coins\": [6,6], \"k\": 0 }\nassert my_solution.maximumPoints(**test_input) == 12\n\ntest_input = { \"edges\": [[0,1],[0,2],[0,3],[1,4],[5,4],[2,6]], \"coins\": [9,3,7,2,3,1,2], \"k\": 8 }\nassert my_solution.maximumPoints(**test_input) == 6\n\ntest_input = { \"edges\": [[1,0],[0,2],[3,1],[3,4],[2,5]], \"coins\": [4,0,3,10,5,8], \"k\": 3 }\nassert my_solution.maximumPoints(**test_input) == 12\n\ntest_input = { \"edges\": [[0,1],[2,1],[3,2],[4,1],[4,5],[5,6]], \"coins\": [3,9,2,6,1,9,1], \"k\": 10 }\nassert my_solution.maximumPoints(**test_input) == 3\n\ntest_input = { \"edges\": [[1,0]], \"coins\": [8,8], \"k\": 8 }\nassert my_solution.maximumPoints(**test_input) == 6\n\ntest_input = { \"edges\": [[0,1],[1,2],[1,3],[0,4],[5,2]], \"coins\": [2,3,7,9,7,7], \"k\": 2 }\nassert my_solution.maximumPoints(**test_input) == 23\n\ntest_input = { \"edges\": [[0,1],[2,0],[3,1],[4,0],[3,5],[2,6]], \"coins\": [6,9,7,7,7,9,7], \"k\": 8 }\nassert my_solution.maximumPoints(**test_input) == 11\n\ntest_input = { \"edges\": [[1,0],[2,1],[3,0],[0,4],[5,2],[0,6]], \"coins\": [9,4,7,9,6,2,9], \"k\": 10 }\nassert my_solution.maximumPoints(**test_input) == 13\n\ntest_input = { \"edges\": [[0,1],[1,2],[3,2],[4,2],[0,5],[6,4],[7,3]], \"coins\": [5,5,6,3,0,8,5,7], \"k\": 7 }\nassert my_solution.maximumPoints(**test_input) == 5\n\ntest_input = { \"edges\": [[1,0],[2,0],[2,3],[4,0],[5,2],[2,6],[7,3]], \"coins\": [8,3,4,5,6,1,6,9], \"k\": 6 }\nassert my_solution.maximumPoints(**test_input) == 11\n\ntest_input = { \"edges\": [[0,1],[2,0],[0,3],[4,0],[5,0],[6,1],[7,3],[8,1]], \"coins\": [1,6,3,10,1,9,7,8,7], \"k\": 5 }\nassert my_solution.maximumPoints(**test_input) == 17\n\ntest_input = { \"edges\": [[0,1],[2,0],[3,1],[3,4],[2,5],[6,4],[5,7],[5,8],[6,9]], \"coins\": [3,6,5,6,6,9,5,5,3,10], \"k\": 10 }\nassert my_solution.maximumPoints(**test_input) == 4\n\ntest_input = { \"edges\": [[0,1],[2,0],[3,2],[4,1],[4,5],[6,3],[7,2],[8,2],[3,9]], \"coins\": [2,2,0,0,4,8,8,5,0,10], \"k\": 8 }\nassert my_solution.maximumPoints(**test_input) == 1\n\ntest_input = { \"edges\": [[1,0],[0,2],[3,0],[4,3],[4,5],[6,5],[7,5]], \"coins\": [8,5,7,3,2,3,5,3], \"k\": 6 }\nassert my_solution.maximumPoints(**test_input) == 8\n\ntest_input = { \"edges\": [[0,1],[2,0]], \"coins\": [4,3,8], \"k\": 3 }\nassert my_solution.maximumPoints(**test_input) == 7\n\ntest_input = { \"edges\": [[1,0],[2,1],[3,1],[4,2],[5,0],[4,6],[7,3],[8,2]], \"coins\": [8,9,0,3,9,7,4,8,7], \"k\": 7 }\nassert my_solution.maximumPoints(**test_input) == 12\n\ntest_input = { \"edges\": [[0,1],[2,1]], \"coins\": [1,6,4], \"k\": 4 }\nassert my_solution.maximumPoints(**test_input) == 1\n\ntest_input = { \"edges\": [[0,1],[2,1],[3,1]], \"coins\": [8,9,1,0], \"k\": 3 }\nassert my_solution.maximumPoints(**test_input) == 11\n\ntest_input = { \"edges\": [[1,0],[2,1],[0,3],[4,3],[5,4],[4,6]], \"coins\": [4,1,4,4,0,5,5], \"k\": 8 }\nassert my_solution.maximumPoints(**test_input) == 3\n\ntest_input = { \"edges\": [[1,0],[2,1],[3,2],[3,4],[4,5],[6,5],[7,3]], \"coins\": [10,9,6,8,9,9,0,7], \"k\": 0 }\nassert my_solution.maximumPoints(**test_input) == 58\n\ntest_input = { \"edges\": [[0,1],[1,2],[3,1],[2,4],[3,5],[4,6],[5,7],[1,8],[2,9]], \"coins\": [9,5,7,6,2,5,0,7,5,7], \"k\": 8 }\nassert my_solution.maximumPoints(**test_input) == 8\n\ntest_input = { \"edges\": [[0,1],[1,2],[3,1]], \"coins\": [4,10,2,2], \"k\": 10 }\nassert my_solution.maximumPoints(**test_input) == 4\n\ntest_input = { \"edges\": [[1,0],[1,2],[1,3],[2,4],[3,5],[1,6],[7,4],[8,1],[0,9]], \"coins\": [6,7,1,2,3,7,3,4,8,4], \"k\": 1 }\nassert my_solution.maximumPoints(**test_input) == 35\n\ntest_input = { \"edges\": [[0,1],[2,1]], \"coins\": [4,8,10], \"k\": 6 }\nassert my_solution.maximumPoints(**test_input) == 5\n\ntest_input = { \"edges\": [[0,1],[0,2],[2,3],[2,4],[5,3],[3,6],[7,2],[8,5]], \"coins\": [7,8,4,3,4,8,10,8,1], \"k\": 7 }\nassert my_solution.maximumPoints(**test_input) == 12\n\ntest_input = { \"edges\": [[1,0],[2,1],[3,0],[4,2],[0,5]], \"coins\": [9,9,3,3,4,4], \"k\": 4 }\nassert my_solution.maximumPoints(**test_input) == 15\n\ntest_input = { \"edges\": [[0,1],[0,2],[1,3],[2,4],[5,0]], \"coins\": [7,5,0,10,0,0], \"k\": 8 }\nassert my_solution.maximumPoints(**test_input) == 5\n\ntest_input = { \"edges\": [[1,0],[2,1],[2,3],[4,2],[0,5],[6,2],[4,7],[8,5],[0,9]], \"coins\": [5,2,8,8,6,0,3,2,2,5], \"k\": 3 }\nassert my_solution.maximumPoints(**test_input) == 18\n\ntest_input = { \"edges\": [[1,0],[1,2],[3,0],[4,3],[1,5],[6,1],[7,4],[2,8]], \"coins\": [5,5,2,1,3,8,6,4,3], \"k\": 1 }\nassert my_solution.maximumPoints(**test_input) == 28\n\ntest_input = { \"edges\": [[1,0],[0,2]], \"coins\": [8,2,5], \"k\": 0 }\nassert my_solution.maximumPoints(**test_input) == 15\n\ntest_input = { \"edges\": [[1,0],[1,2],[3,2]], \"coins\": [10,9,2,0], \"k\": 7 }\nassert my_solution.maximumPoints(**test_input) == 7\n\ntest_input = { \"edges\": [[0,1],[2,0],[2,3],[0,4],[2,5],[6,4],[7,1],[8,3]], \"coins\": [10,4,4,8,9,5,5,8,1], \"k\": 0 }\nassert my_solution.maximumPoints(**test_input) == 54\n\ntest_input = { \"edges\": [[0,1],[1,2],[1,3],[2,4],[1,5],[6,2],[3,7],[8,4],[9,3]], \"coins\": [5,1,1,3,5,0,0,1,1,9], \"k\": 5 }\nassert my_solution.maximumPoints(**test_input) == 2\n\ntest_input = { \"edges\": [[0,1],[1,2],[3,1],[1,4],[5,3]], \"coins\": [1,7,1,3,3,7], \"k\": 7 }\nassert my_solution.maximumPoints(**test_input) == 1\n\ntest_input = { \"edges\": [[0,1],[1,2],[3,2],[4,3],[5,2],[0,6],[3,7],[5,8]], \"coins\": [9,1,3,2,1,3,4,2,6], \"k\": 1 }\nassert my_solution.maximumPoints(**test_input) == 22\n\ntest_input = { \"edges\": [[0,1],[0,2]], \"coins\": [5,1,5], \"k\": 10 }\nassert my_solution.maximumPoints(**test_input) == 3\n\ntest_input = { \"edges\": [[0,1],[0,2],[3,1],[1,4],[4,5]], \"coins\": [5,7,8,9,3,10], \"k\": 7 }\nassert my_solution.maximumPoints(**test_input) == 9\n\ntest_input = { \"edges\": [[0,1],[0,2],[0,3],[0,4],[0,5],[5,6],[6,7],[8,5]], \"coins\": [8,3,0,3,4,1,4,0,7], \"k\": 2 }\nassert my_solution.maximumPoints(**test_input) == 16\n\ntest_input = { \"edges\": [[1,0],[0,2],[3,0],[4,3],[2,5],[3,6]], \"coins\": [3,6,7,1,2,8,0], \"k\": 9 }\nassert my_solution.maximumPoints(**test_input) == 4\n\ntest_input = { \"edges\": [[1,0]], \"coins\": [4,0], \"k\": 9 }\nassert my_solution.maximumPoints(**test_input) == 2\n\ntest_input = { \"edges\": [[1,0],[2,0],[3,1],[4,1],[5,2],[6,1],[4,7],[5,8]], \"coins\": [9,7,8,9,6,8,9,1,6], \"k\": 1 }\nassert my_solution.maximumPoints(**test_input) == 54\n\ntest_input = { \"edges\": [[1,0],[0,2],[1,3],[0,4],[5,4],[6,0],[3,7]], \"coins\": [7,10,8,4,6,0,6,2], \"k\": 4 }\nassert my_solution.maximumPoints(**test_input) == 21", "start_time": 1698546600} +{"task_id": "biweekly-contest-116-subarrays-distinct-element-sum-of-squares-i", "url": "https://leetcode.com/problems/subarrays-distinct-element-sum-of-squares-i", "title": "subarrays-distinct-element-sum-of-squares-i", "meta": {"questionId": "3163", "questionFrontendId": "2913", "title": "Subarrays Distinct Element Sum of Squares I", "titleSlug": "subarrays-distinct-element-sum-of-squares-i", "isPaidOnly": false, "difficulty": "Easy", "likes": 82, "dislikes": 9, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0 开始的整数数组 nums 。\n\n定义 nums 一个子数组的 不同计数 值如下:\n\n * 令 nums[i..j] 表示 nums 中所有下标在 i 到 j 范围内的元素构成的子数组(满足 0 <= i <= j < nums.length ),那么我们称子数组 nums[i..j] 中不同值的数目为 nums[i..j] 的不同计数。\n\n请你返回 nums 中所有子数组的 不同计数 的 平方 和。\n\n由于答案可能会很大,请你将它对 109 + 7 取余 后返回。\n\n子数组指的是一个数组里面一段连续 非空 的元素序列。\n\n示例 1:\n\n输入:nums = [1,2,1]\n输出:15\n解释:六个子数组分别为:\n[1]: 1 个互不相同的元素。\n[2]: 1 个互不相同的元素。\n[1]: 1 个互不相同的元素。\n[1,2]: 2 个互不相同的元素。\n[2,1]: 2 个互不相同的元素。\n[1,2,1]: 2 个互不相同的元素。\n所有不同计数的平方和为 12 + 12 + 12 + 22 + 22 + 22 = 15 。\n\n示例 2:\n\n输入:nums = [2,2]\n输出:3\n解释:三个子数组分别为:\n[2]: 1 个互不相同的元素。\n[2]: 1 个互不相同的元素。\n[2,2]: 1 个互不相同的元素。\n所有不同计数的平方和为 12 + 12 + 12 = 3 。\n\n\n提示:\n\n * 1 <= nums.length <= 100\n * 1 <= nums[i] <= 100\n\"\"\"\nclass Solution:\n def sumCounts(self, nums: List[int]) -> int:\n ", "prompt_sft": "给你一个下标从 0 开始的整数数组 nums 。\n\n定义 nums 一个子数组的 不同计数 值如下:\n\n * 令 nums[i..j] 表示 nums 中所有下标在 i 到 j 范围内的元素构成的子数组(满足 0 <= i <= j < nums.length ),那么我们称子数组 nums[i..j] 中不同值的数目为 nums[i..j] 的不同计数。\n\n请你返回 nums 中所有子数组的 不同计数 的 平方 和。\n\n由于答案可能会很大,请你将它对 109 + 7 取余 后返回。\n\n子数组指的是一个数组里面一段连续 非空 的元素序列。\n\n示例 1:\n\n输入:nums = [1,2,1]\n输出:15\n解释:六个子数组分别为:\n[1]: 1 个互不相同的元素。\n[2]: 1 个互不相同的元素。\n[1]: 1 个互不相同的元素。\n[1,2]: 2 个互不相同的元素。\n[2,1]: 2 个互不相同的元素。\n[1,2,1]: 2 个互不相同的元素。\n所有不同计数的平方和为 12 + 12 + 12 + 22 + 22 + 22 = 15 。\n\n示例 2:\n\n输入:nums = [2,2]\n输出:3\n解释:三个子数组分别为:\n[2]: 1 个互不相同的元素。\n[2]: 1 个互不相同的元素。\n[2,2]: 1 个互不相同的元素。\n所有不同计数的平方和为 12 + 12 + 12 = 3 。\n\n\n提示:\n\n * 1 <= nums.length <= 100\n * 1 <= nums[i] <= 100\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def sumCounts(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,2,1] }\nassert my_solution.sumCounts(**test_input) == 15\n\ntest_input = { \"nums\": [1,1] }\nassert my_solution.sumCounts(**test_input) == 3\n\ntest_input = { \"nums\": [2,2,5,5] }\nassert my_solution.sumCounts(**test_input) == 22\n\ntest_input = { \"nums\": [5,2,4,2,1,3,2,4,3,1] }\nassert my_solution.sumCounts(**test_input) == 578\n\ntest_input = { \"nums\": [2,3,2,1,2,5,3,4,5,2] }\nassert my_solution.sumCounts(**test_input) == 629\n\ntest_input = { \"nums\": [5,1,5,2,3,5,1,5,1] }\nassert my_solution.sumCounts(**test_input) == 385\n\ntest_input = { \"nums\": [4,5,4,3,4,2] }\nassert my_solution.sumCounts(**test_input) == 120\n\ntest_input = { \"nums\": [2] }\nassert my_solution.sumCounts(**test_input) == 1\n\ntest_input = { \"nums\": [3,4,2,5,2,4,1,2,2,5] }\nassert my_solution.sumCounts(**test_input) == 535\n\ntest_input = { \"nums\": [4,4,2,4,1] }\nassert my_solution.sumCounts(**test_input) == 57\n\ntest_input = { \"nums\": [2,2,5] }\nassert my_solution.sumCounts(**test_input) == 12\n\ntest_input = { \"nums\": [4,5,1,2,2,1,3,3] }\nassert my_solution.sumCounts(**test_input) == 266\n\ntest_input = { \"nums\": [3,1,5,5,2,3,2,2,1] }\nassert my_solution.sumCounts(**test_input) == 334\n\ntest_input = { \"nums\": [2,5,2,5,3,2,5,2] }\nassert my_solution.sumCounts(**test_input) == 205\n\ntest_input = { \"nums\": [5,4,1,4,5,2,4] }\nassert my_solution.sumCounts(**test_input) == 203\n\ntest_input = { \"nums\": [1,3,3,4,3,1,2,1] }\nassert my_solution.sumCounts(**test_input) == 253\n\ntest_input = { \"nums\": [4] }\nassert my_solution.sumCounts(**test_input) == 1\n\ntest_input = { \"nums\": [1,4,2,1,5,4,3,1,4] }\nassert my_solution.sumCounts(**test_input) == 507\n\ntest_input = { \"nums\": [2,4,5,3,2,5,1,5,4,4] }\nassert my_solution.sumCounts(**test_input) == 626\n\ntest_input = { \"nums\": [3,4,1,4,5,2,2] }\nassert my_solution.sumCounts(**test_input) == 220\n\ntest_input = { \"nums\": [3,5,1,1,3] }\nassert my_solution.sumCounts(**test_input) == 62\n\ntest_input = { \"nums\": [4,3,2,5,3] }\nassert my_solution.sumCounts(**test_input) == 89\n\ntest_input = { \"nums\": [2,5] }\nassert my_solution.sumCounts(**test_input) == 6\n\ntest_input = { \"nums\": [1,5,1,4,5] }\nassert my_solution.sumCounts(**test_input) == 70\n\ntest_input = { \"nums\": [5,1] }\nassert my_solution.sumCounts(**test_input) == 6\n\ntest_input = { \"nums\": [4,5,4,3,3,5,3] }\nassert my_solution.sumCounts(**test_input) == 138\n\ntest_input = { \"nums\": [5,4,3] }\nassert my_solution.sumCounts(**test_input) == 20\n\ntest_input = { \"nums\": [5,5,3,3,4,5,4,5,5] }\nassert my_solution.sumCounts(**test_input) == 234\n\ntest_input = { \"nums\": [3,1,5,5,3,4,5,5,1,4] }\nassert my_solution.sumCounts(**test_input) == 456\n\ntest_input = { \"nums\": [4,2,3,1,1] }\nassert my_solution.sumCounts(**test_input) == 81\n\ntest_input = { \"nums\": [4,5,3,1,2,5,5,3,5] }\nassert my_solution.sumCounts(**test_input) == 434\n\ntest_input = { \"nums\": [3,2,1,2,5,2,4,5,1,5] }\nassert my_solution.sumCounts(**test_input) == 531\n\ntest_input = { \"nums\": [1,3,1,4,4] }\nassert my_solution.sumCounts(**test_input) == 62\n\ntest_input = { \"nums\": [5,1,2,1,2,1,2,3,1] }\nassert my_solution.sumCounts(**test_input) == 257\n\ntest_input = { \"nums\": [2,4] }\nassert my_solution.sumCounts(**test_input) == 6\n\ntest_input = { \"nums\": [4,5,4,5] }\nassert my_solution.sumCounts(**test_input) == 28\n\ntest_input = { \"nums\": [3,1,5,5,5,4,3,3,2] }\nassert my_solution.sumCounts(**test_input) == 334\n\ntest_input = { \"nums\": [3,2,5,2,1,5,3] }\nassert my_solution.sumCounts(**test_input) == 203\n\ntest_input = { \"nums\": [4,4,2,5,5,4,2,2,1] }\nassert my_solution.sumCounts(**test_input) == 294\n\ntest_input = { \"nums\": [1] }\nassert my_solution.sumCounts(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,3,3,3,4,4] }\nassert my_solution.sumCounts(**test_input) == 96\n\ntest_input = { \"nums\": [3,2,2,3,4] }\nassert my_solution.sumCounts(**test_input) == 57\n\ntest_input = { \"nums\": [1,5,3,2,4,4] }\nassert my_solution.sumCounts(**test_input) == 161\n\ntest_input = { \"nums\": [5,4,1,1,3] }\nassert my_solution.sumCounts(**test_input) == 69\n\ntest_input = { \"nums\": [4,3,3,5,3,4,5,3,3,1] }\nassert my_solution.sumCounts(**test_input) == 376\n\ntest_input = { \"nums\": [2,3,4,1,5,1,3,3,4] }\nassert my_solution.sumCounts(**test_input) == 432\n\ntest_input = { \"nums\": [5,1,4,2,1,1] }\nassert my_solution.sumCounts(**test_input) == 129\n\ntest_input = { \"nums\": [5,4,4,1] }\nassert my_solution.sumCounts(**test_input) == 30\n\ntest_input = { \"nums\": [1,5,1,3,2,1] }\nassert my_solution.sumCounts(**test_input) == 139\n\ntest_input = { \"nums\": [5,3] }\nassert my_solution.sumCounts(**test_input) == 6\n\ntest_input = { \"nums\": [4,1,4,3] }\nassert my_solution.sumCounts(**test_input) == 38\n\ntest_input = { \"nums\": [1,5,4,3,4,2,4,5,5,4] }\nassert my_solution.sumCounts(**test_input) == 513\n\ntest_input = { \"nums\": [4,2,3,4,3,2,5,4,4] }\nassert my_solution.sumCounts(**test_input) == 378\n\ntest_input = { \"nums\": [2,3,3,2,1,5,2,2] }\nassert my_solution.sumCounts(**test_input) == 262\n\ntest_input = { \"nums\": [2,1,4,2,4,1,4,3] }\nassert my_solution.sumCounts(**test_input) == 243\n\ntest_input = { \"nums\": [1,4,4,1,3] }\nassert my_solution.sumCounts(**test_input) == 57\n\ntest_input = { \"nums\": [2,3,2,1] }\nassert my_solution.sumCounts(**test_input) == 38\n\ntest_input = { \"nums\": [1,4,2,1] }\nassert my_solution.sumCounts(**test_input) == 43\n\ntest_input = { \"nums\": [2,4,3,2,5,1] }\nassert my_solution.sumCounts(**test_input) == 169\n\ntest_input = { \"nums\": [2,5,3,2,1,3,1,3,2] }\nassert my_solution.sumCounts(**test_input) == 348\n\ntest_input = { \"nums\": [4,1] }\nassert my_solution.sumCounts(**test_input) == 6\n\ntest_input = { \"nums\": [4,3,1,4,3,4,3,4,1] }\nassert my_solution.sumCounts(**test_input) == 263\n\ntest_input = { \"nums\": [5,1,1,1,4,3] }\nassert my_solution.sumCounts(**test_input) == 89\n\ntest_input = { \"nums\": [4,5] }\nassert my_solution.sumCounts(**test_input) == 6\n\ntest_input = { \"nums\": [5,2,2,3,1,2,5,3] }\nassert my_solution.sumCounts(**test_input) == 289\n\ntest_input = { \"nums\": [3,2,4] }\nassert my_solution.sumCounts(**test_input) == 20\n\ntest_input = { \"nums\": [5,3,5,2,3,2] }\nassert my_solution.sumCounts(**test_input) == 106\n\ntest_input = { \"nums\": [3,2,1] }\nassert my_solution.sumCounts(**test_input) == 20\n\ntest_input = { \"nums\": [4,4,2,4,3] }\nassert my_solution.sumCounts(**test_input) == 57\n\ntest_input = { \"nums\": [1,4,4] }\nassert my_solution.sumCounts(**test_input) == 12\n\ntest_input = { \"nums\": [1,4,4,3,1,2,1,4,3] }\nassert my_solution.sumCounts(**test_input) == 387\n\ntest_input = { \"nums\": [1,5,4,2,5,5,5,3] }\nassert my_solution.sumCounts(**test_input) == 249\n\ntest_input = { \"nums\": [2,1,5,3] }\nassert my_solution.sumCounts(**test_input) == 50\n\ntest_input = { \"nums\": [2,3,5,1,5,2,3,2,3,4] }\nassert my_solution.sumCounts(**test_input) == 533\n\ntest_input = { \"nums\": [5,3,4,4,3,5,4,5] }\nassert my_solution.sumCounts(**test_input) == 202\n\ntest_input = { \"nums\": [4,4,2,2,4,1] }\nassert my_solution.sumCounts(**test_input) == 80\n\ntest_input = { \"nums\": [2,3] }\nassert my_solution.sumCounts(**test_input) == 6\n\ntest_input = { \"nums\": [4,2,3,2] }\nassert my_solution.sumCounts(**test_input) == 38\n\ntest_input = { \"nums\": [1,2,2] }\nassert my_solution.sumCounts(**test_input) == 12\n\ntest_input = { \"nums\": [4,1,5,1,5,4,5,1] }\nassert my_solution.sumCounts(**test_input) == 205\n\ntest_input = { \"nums\": [4,5,3,1] }\nassert my_solution.sumCounts(**test_input) == 50\n\ntest_input = { \"nums\": [4,2,3,4,2,4,3,3,2] }\nassert my_solution.sumCounts(**test_input) == 275\n\ntest_input = { \"nums\": [4,3] }\nassert my_solution.sumCounts(**test_input) == 6\n\ntest_input = { \"nums\": [1,3,5,4,4,4] }\nassert my_solution.sumCounts(**test_input) == 113\n\ntest_input = { \"nums\": [1,2,4,2,1,2,2,4,1,3] }\nassert my_solution.sumCounts(**test_input) == 391\n\ntest_input = { \"nums\": [4,2,5,3,2] }\nassert my_solution.sumCounts(**test_input) == 89\n\ntest_input = { \"nums\": [3,4,5,3,2,5] }\nassert my_solution.sumCounts(**test_input) == 144\n\ntest_input = { \"nums\": [5,4,5] }\nassert my_solution.sumCounts(**test_input) == 15\n\ntest_input = { \"nums\": [2,4,5,1] }\nassert my_solution.sumCounts(**test_input) == 50\n\ntest_input = { \"nums\": [5,4,1,4,2,1,5] }\nassert my_solution.sumCounts(**test_input) == 203\n\ntest_input = { \"nums\": [2,3,3,2,2,3,1] }\nassert my_solution.sumCounts(**test_input) == 110\n\ntest_input = { \"nums\": [1,4,2,5] }\nassert my_solution.sumCounts(**test_input) == 50\n\ntest_input = { \"nums\": [3] }\nassert my_solution.sumCounts(**test_input) == 1\n\ntest_input = { \"nums\": [5] }\nassert my_solution.sumCounts(**test_input) == 1\n\ntest_input = { \"nums\": [1,3,5,3,2,1,1,4,3] }\nassert my_solution.sumCounts(**test_input) == 441\n\ntest_input = { \"nums\": [1,5,2,2,3,3,3] }\nassert my_solution.sumCounts(**test_input) == 140\n\ntest_input = { \"nums\": [1,2,1,4,5,5,4,1,1,1] }\nassert my_solution.sumCounts(**test_input) == 407\n\ntest_input = { \"nums\": [2,2,1,1,1,2,5,4,5] }\nassert my_solution.sumCounts(**test_input) == 296\n\ntest_input = { \"nums\": [3,2,3] }\nassert my_solution.sumCounts(**test_input) == 15\n\ntest_input = { \"nums\": [2,1,5,4,3,3,2,1,5,5] }\nassert my_solution.sumCounts(**test_input) == 652", "start_time": 1698503400} +{"task_id": "biweekly-contest-116-minimum-number-of-changes-to-make-binary-string-beautiful", "url": "https://leetcode.com/problems/minimum-number-of-changes-to-make-binary-string-beautiful", "title": "minimum-number-of-changes-to-make-binary-string-beautiful", "meta": {"questionId": "3174", "questionFrontendId": "2914", "title": "Minimum Number of Changes to Make Binary String Beautiful", "titleSlug": "minimum-number-of-changes-to-make-binary-string-beautiful", "isPaidOnly": false, "difficulty": "Medium", "likes": 111, "dislikes": 4, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个长度为偶数下标从 0 开始的二进制字符串 s 。\n\n如果可以将一个字符串分割成一个或者更多满足以下条件的子字符串,那么我们称这个字符串是 美丽的 :\n\n * 每个子字符串的长度都是 偶数 。\n * 每个子字符串都 只 包含 1 或 只 包含 0 。\n\n你可以将 s 中任一字符改成 0 或者 1 。\n\n请你返回让字符串 s 美丽的 最少 字符修改次数。\n\n示例 1:\n\n输入:s = \"1001\"\n输出:2\n解释:我们将 s[1] 改为 1 ,且将 s[3] 改为 0 ,得到字符串 \"1100\" 。\n字符串 \"1100\" 是美丽的,因为我们可以将它分割成 \"11|00\" 。\n将字符串变美丽最少需要 2 次修改。\n\n示例 2:\n\n输入:s = \"10\"\n输出:1\n解释:我们将 s[1] 改为 1 ,得到字符串 \"11\" 。\n字符串 \"11\" 是美丽的,因为它已经是美丽的。\n将字符串变美丽最少需要 1 次修改。\n\n示例 3:\n\n输入:s = \"0000\"\n输出:0\n解释:不需要进行任何修改,字符串 \"0000\" 已经是美丽字符串。\n\n\n提示:\n\n * 2 <= s.length <= 105\n * s 的长度为偶数。\n * s[i] 要么是 '0' ,要么是 '1' 。\n\"\"\"\nclass Solution:\n def minChanges(self, s: str) -> int:\n ", "prompt_sft": "给你一个长度为偶数下标从 0 开始的二进制字符串 s 。\n\n如果可以将一个字符串分割成一个或者更多满足以下条件的子字符串,那么我们称这个字符串是 美丽的 :\n\n * 每个子字符串的长度都是 偶数 。\n * 每个子字符串都 只 包含 1 或 只 包含 0 。\n\n你可以将 s 中任一字符改成 0 或者 1 。\n\n请你返回让字符串 s 美丽的 最少 字符修改次数。\n\n示例 1:\n\n输入:s = \"1001\"\n输出:2\n解释:我们将 s[1] 改为 1 ,且将 s[3] 改为 0 ,得到字符串 \"1100\" 。\n字符串 \"1100\" 是美丽的,因为我们可以将它分割成 \"11|00\" 。\n将字符串变美丽最少需要 2 次修改。\n\n示例 2:\n\n输入:s = \"10\"\n输出:1\n解释:我们将 s[1] 改为 1 ,得到字符串 \"11\" 。\n字符串 \"11\" 是美丽的,因为它已经是美丽的。\n将字符串变美丽最少需要 1 次修改。\n\n示例 3:\n\n输入:s = \"0000\"\n输出:0\n解释:不需要进行任何修改,字符串 \"0000\" 已经是美丽字符串。\n\n\n提示:\n\n * 2 <= s.length <= 105\n * s 的长度为偶数。\n * s[i] 要么是 '0' ,要么是 '1' 。\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def minChanges(self, s: str) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"s\": \"1001\" }\nassert my_solution.minChanges(**test_input) == 2\n\ntest_input = { \"s\": \"10\" }\nassert my_solution.minChanges(**test_input) == 1\n\ntest_input = { \"s\": \"0000\" }\nassert my_solution.minChanges(**test_input) == 0\n\ntest_input = { \"s\": \"11000111\" }\nassert my_solution.minChanges(**test_input) == 1\n\ntest_input = { \"s\": \"01010001\" }\nassert my_solution.minChanges(**test_input) == 3\n\ntest_input = { \"s\": \"010010\" }\nassert my_solution.minChanges(**test_input) == 2\n\ntest_input = { \"s\": \"111111111110010001\" }\nassert my_solution.minChanges(**test_input) == 3\n\ntest_input = { \"s\": \"01010000011001001101\" }\nassert my_solution.minChanges(**test_input) == 6\n\ntest_input = { \"s\": \"011011100001110111\" }\nassert my_solution.minChanges(**test_input) == 5\n\ntest_input = { \"s\": \"1001000010111010\" }\nassert my_solution.minChanges(**test_input) == 5\n\ntest_input = { \"s\": \"0011\" }\nassert my_solution.minChanges(**test_input) == 0\n\ntest_input = { \"s\": \"11100100010010\" }\nassert my_solution.minChanges(**test_input) == 4\n\ntest_input = { \"s\": \"110100\" }\nassert my_solution.minChanges(**test_input) == 1\n\ntest_input = { \"s\": \"01\" }\nassert my_solution.minChanges(**test_input) == 1\n\ntest_input = { \"s\": \"10110010\" }\nassert my_solution.minChanges(**test_input) == 2\n\ntest_input = { \"s\": \"0010\" }\nassert my_solution.minChanges(**test_input) == 1\n\ntest_input = { \"s\": \"01000011000111\" }\nassert my_solution.minChanges(**test_input) == 2\n\ntest_input = { \"s\": \"0001110001\" }\nassert my_solution.minChanges(**test_input) == 2\n\ntest_input = { \"s\": \"000000001010100011\" }\nassert my_solution.minChanges(**test_input) == 3\n\ntest_input = { \"s\": \"100001\" }\nassert my_solution.minChanges(**test_input) == 2\n\ntest_input = { \"s\": \"10010010\" }\nassert my_solution.minChanges(**test_input) == 3\n\ntest_input = { \"s\": \"101100\" }\nassert my_solution.minChanges(**test_input) == 1\n\ntest_input = { \"s\": \"000010\" }\nassert my_solution.minChanges(**test_input) == 1\n\ntest_input = { \"s\": \"011011000001100011\" }\nassert my_solution.minChanges(**test_input) == 4\n\ntest_input = { \"s\": \"01101111\" }\nassert my_solution.minChanges(**test_input) == 2\n\ntest_input = { \"s\": \"000000011101\" }\nassert my_solution.minChanges(**test_input) == 2\n\ntest_input = { \"s\": \"011011011111111011\" }\nassert my_solution.minChanges(**test_input) == 4\n\ntest_input = { \"s\": \"110011\" }\nassert my_solution.minChanges(**test_input) == 0\n\ntest_input = { \"s\": \"1111101111101011\" }\nassert my_solution.minChanges(**test_input) == 3\n\ntest_input = { \"s\": \"11000101011001100110\" }\nassert my_solution.minChanges(**test_input) == 8\n\ntest_input = { \"s\": \"101101101110110010\" }\nassert my_solution.minChanges(**test_input) == 5\n\ntest_input = { \"s\": \"11011110\" }\nassert my_solution.minChanges(**test_input) == 2\n\ntest_input = { \"s\": \"1011100101\" }\nassert my_solution.minChanges(**test_input) == 4\n\ntest_input = { \"s\": \"0011000101001000\" }\nassert my_solution.minChanges(**test_input) == 3\n\ntest_input = { \"s\": \"00\" }\nassert my_solution.minChanges(**test_input) == 0\n\ntest_input = { \"s\": \"10110111010001000010\" }\nassert my_solution.minChanges(**test_input) == 5\n\ntest_input = { \"s\": \"0101\" }\nassert my_solution.minChanges(**test_input) == 2\n\ntest_input = { \"s\": \"0010101100\" }\nassert my_solution.minChanges(**test_input) == 2\n\ntest_input = { \"s\": \"11001110101001\" }\nassert my_solution.minChanges(**test_input) == 4\n\ntest_input = { \"s\": \"010101000011011111\" }\nassert my_solution.minChanges(**test_input) == 4\n\ntest_input = { \"s\": \"0010111010000001\" }\nassert my_solution.minChanges(**test_input) == 4\n\ntest_input = { \"s\": \"0000010101\" }\nassert my_solution.minChanges(**test_input) == 3\n\ntest_input = { \"s\": \"10100011101010\" }\nassert my_solution.minChanges(**test_input) == 5\n\ntest_input = { \"s\": \"101111\" }\nassert my_solution.minChanges(**test_input) == 1\n\ntest_input = { \"s\": \"11\" }\nassert my_solution.minChanges(**test_input) == 0\n\ntest_input = { \"s\": \"110110\" }\nassert my_solution.minChanges(**test_input) == 2\n\ntest_input = { \"s\": \"001001110111010101\" }\nassert my_solution.minChanges(**test_input) == 6\n\ntest_input = { \"s\": \"11110011\" }\nassert my_solution.minChanges(**test_input) == 0\n\ntest_input = { \"s\": \"1100000101101110\" }\nassert my_solution.minChanges(**test_input) == 4\n\ntest_input = { \"s\": \"111010\" }\nassert my_solution.minChanges(**test_input) == 2\n\ntest_input = { \"s\": \"100000100010011100\" }\nassert my_solution.minChanges(**test_input) == 4\n\ntest_input = { \"s\": \"0111\" }\nassert my_solution.minChanges(**test_input) == 1\n\ntest_input = { \"s\": \"0100110011111101\" }\nassert my_solution.minChanges(**test_input) == 2\n\ntest_input = { \"s\": \"010111\" }\nassert my_solution.minChanges(**test_input) == 2\n\ntest_input = { \"s\": \"000100\" }\nassert my_solution.minChanges(**test_input) == 1\n\ntest_input = { \"s\": \"00110111000111110001\" }\nassert my_solution.minChanges(**test_input) == 3\n\ntest_input = { \"s\": \"01010010\" }\nassert my_solution.minChanges(**test_input) == 3\n\ntest_input = { \"s\": \"01110101001001\" }\nassert my_solution.minChanges(**test_input) == 5\n\ntest_input = { \"s\": \"00111100010111\" }\nassert my_solution.minChanges(**test_input) == 2\n\ntest_input = { \"s\": \"001110\" }\nassert my_solution.minChanges(**test_input) == 1\n\ntest_input = { \"s\": \"00010101111101\" }\nassert my_solution.minChanges(**test_input) == 4\n\ntest_input = { \"s\": \"111011\" }\nassert my_solution.minChanges(**test_input) == 1\n\ntest_input = { \"s\": \"011110\" }\nassert my_solution.minChanges(**test_input) == 2\n\ntest_input = { \"s\": \"1010\" }\nassert my_solution.minChanges(**test_input) == 2\n\ntest_input = { \"s\": \"011101010011101011\" }\nassert my_solution.minChanges(**test_input) == 5\n\ntest_input = { \"s\": \"1001110001111100\" }\nassert my_solution.minChanges(**test_input) == 3\n\ntest_input = { \"s\": \"011000101100\" }\nassert my_solution.minChanges(**test_input) == 3\n\ntest_input = { \"s\": \"1110111000111111\" }\nassert my_solution.minChanges(**test_input) == 2\n\ntest_input = { \"s\": \"1110\" }\nassert my_solution.minChanges(**test_input) == 1\n\ntest_input = { \"s\": \"10110110\" }\nassert my_solution.minChanges(**test_input) == 3\n\ntest_input = { \"s\": \"1000\" }\nassert my_solution.minChanges(**test_input) == 1\n\ntest_input = { \"s\": \"0111110110\" }\nassert my_solution.minChanges(**test_input) == 3\n\ntest_input = { \"s\": \"011000011101\" }\nassert my_solution.minChanges(**test_input) == 4\n\ntest_input = { \"s\": \"0100101000010101\" }\nassert my_solution.minChanges(**test_input) == 6\n\ntest_input = { \"s\": \"0100001100\" }\nassert my_solution.minChanges(**test_input) == 1\n\ntest_input = { \"s\": \"100010010010110001\" }\nassert my_solution.minChanges(**test_input) == 5\n\ntest_input = { \"s\": \"101001111001111001\" }\nassert my_solution.minChanges(**test_input) == 7\n\ntest_input = { \"s\": \"111001\" }\nassert my_solution.minChanges(**test_input) == 2\n\ntest_input = { \"s\": \"111010001000\" }\nassert my_solution.minChanges(**test_input) == 3\n\ntest_input = { \"s\": \"0110\" }\nassert my_solution.minChanges(**test_input) == 2\n\ntest_input = { \"s\": \"11011010\" }\nassert my_solution.minChanges(**test_input) == 3\n\ntest_input = { \"s\": \"100111\" }\nassert my_solution.minChanges(**test_input) == 2\n\ntest_input = { \"s\": \"11000110000001\" }\nassert my_solution.minChanges(**test_input) == 3\n\ntest_input = { \"s\": \"010111010011011000\" }\nassert my_solution.minChanges(**test_input) == 5\n\ntest_input = { \"s\": \"000101\" }\nassert my_solution.minChanges(**test_input) == 2\n\ntest_input = { \"s\": \"000010101010101011\" }\nassert my_solution.minChanges(**test_input) == 6\n\ntest_input = { \"s\": \"11011000\" }\nassert my_solution.minChanges(**test_input) == 2\n\ntest_input = { \"s\": \"010101\" }\nassert my_solution.minChanges(**test_input) == 3\n\ntest_input = { \"s\": \"10011010110110101100\" }\nassert my_solution.minChanges(**test_input) == 7\n\ntest_input = { \"s\": \"10100011\" }\nassert my_solution.minChanges(**test_input) == 2\n\ntest_input = { \"s\": \"11010100000000\" }\nassert my_solution.minChanges(**test_input) == 2\n\ntest_input = { \"s\": \"101100101111010011\" }\nassert my_solution.minChanges(**test_input) == 3\n\ntest_input = { \"s\": \"110111111100\" }\nassert my_solution.minChanges(**test_input) == 1\n\ntest_input = { \"s\": \"111110110100\" }\nassert my_solution.minChanges(**test_input) == 2\n\ntest_input = { \"s\": \"011110110101010100\" }\nassert my_solution.minChanges(**test_input) == 6\n\ntest_input = { \"s\": \"000111\" }\nassert my_solution.minChanges(**test_input) == 1\n\ntest_input = { \"s\": \"00000010001101\" }\nassert my_solution.minChanges(**test_input) == 2\n\ntest_input = { \"s\": \"01111001101001\" }\nassert my_solution.minChanges(**test_input) == 6\n\ntest_input = { \"s\": \"010110011101\" }\nassert my_solution.minChanges(**test_input) == 5\n\ntest_input = { \"s\": \"0111011101\" }\nassert my_solution.minChanges(**test_input) == 3", "start_time": 1698503400} +{"task_id": "biweekly-contest-116-length-of-the-longest-subsequence-that-sums-to-target", "url": "https://leetcode.com/problems/length-of-the-longest-subsequence-that-sums-to-target", "title": "length-of-the-longest-subsequence-that-sums-to-target", "meta": {"questionId": "3106", "questionFrontendId": "2915", "title": "Length of the Longest Subsequence That Sums to Target", "titleSlug": "length-of-the-longest-subsequence-that-sums-to-target", "isPaidOnly": false, "difficulty": "Medium", "likes": 141, "dislikes": 19, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0 开始的整数数组 nums 和一个整数 target 。\n\n返回和为 target 的 nums 子序列中,子序列 长度的最大值 。如果不存在和为 target 的子序列,返回 -1 。\n\n子序列 指的是从原数组中删除一些或者不删除任何元素后,剩余元素保持原来的顺序构成的数组。\n\n示例 1:\n\n输入:nums = [1,2,3,4,5], target = 9\n输出:3\n解释:总共有 3 个子序列的和为 9 :[4,5] ,[1,3,5] 和 [2,3,4] 。最长的子序列是 [1,3,5] 和 [2,3,4] 。所以答案为 3 。\n\n示例 2:\n\n输入:nums = [4,1,3,2,1,5], target = 7\n输出:4\n解释:总共有 5 个子序列的和为 7 :[4,3] ,[4,1,2] ,[4,2,1] ,[1,1,5] 和 [1,3,2,1] 。最长子序列为 [1,3,2,1] 。所以答案为 4 。\n\n示例 3:\n\n输入:nums = [1,1,5,4,5], target = 3\n输出:-1\n解释:无法得到和为 3 的子序列。\n\n\n提示:\n\n * 1 <= nums.length <= 1000\n * 1 <= nums[i] <= 1000\n * 1 <= target <= 1000\n\"\"\"\nclass Solution:\n def lengthOfLongestSubsequence(self, nums: List[int], target: int) -> int:\n ", "prompt_sft": "给你一个下标从 0 开始的整数数组 nums 和一个整数 target 。\n\n返回和为 target 的 nums 子序列中,子序列 长度的最大值 。如果不存在和为 target 的子序列,返回 -1 。\n\n子序列 指的是从原数组中删除一些或者不删除任何元素后,剩余元素保持原来的顺序构成的数组。\n\n示例 1:\n\n输入:nums = [1,2,3,4,5], target = 9\n输出:3\n解释:总共有 3 个子序列的和为 9 :[4,5] ,[1,3,5] 和 [2,3,4] 。最长的子序列是 [1,3,5] 和 [2,3,4] 。所以答案为 3 。\n\n示例 2:\n\n输入:nums = [4,1,3,2,1,5], target = 7\n输出:4\n解释:总共有 5 个子序列的和为 7 :[4,3] ,[4,1,2] ,[4,2,1] ,[1,1,5] 和 [1,3,2,1] 。最长子序列为 [1,3,2,1] 。所以答案为 4 。\n\n示例 3:\n\n输入:nums = [1,1,5,4,5], target = 3\n输出:-1\n解释:无法得到和为 3 的子序列。\n\n\n提示:\n\n * 1 <= nums.length <= 1000\n * 1 <= nums[i] <= 1000\n * 1 <= target <= 1000\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def lengthOfLongestSubsequence(self, nums: List[int], target: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,2,3,4,5], \"target\": 9 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 3\n\ntest_input = { \"nums\": [4,1,3,2,1,5], \"target\": 7 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 4\n\ntest_input = { \"nums\": [1,1,5,4,5], \"target\": 3 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == -1\n\ntest_input = { \"nums\": [1000], \"target\": 12 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == -1\n\ntest_input = { \"nums\": [1000], \"target\": 1000 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 1\n\ntest_input = { \"nums\": [1,2], \"target\": 10 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == -1\n\ntest_input = { \"nums\": [1,1000], \"target\": 5 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == -1\n\ntest_input = { \"nums\": [2,3], \"target\": 3 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 1\n\ntest_input = { \"nums\": [2,3], \"target\": 5 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 2\n\ntest_input = { \"nums\": [2,3,5], \"target\": 5 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 2\n\ntest_input = { \"nums\": [1,3,3,7], \"target\": 1000 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == -1\n\ntest_input = { \"nums\": [1,3,3,7], \"target\": 2 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == -1\n\ntest_input = { \"nums\": [1,3,3,8], \"target\": 7 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,2,1], \"target\": 2 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,1,1], \"target\": 5 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,1,2], \"target\": 3 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 3\n\ntest_input = { \"nums\": [9,12,8,4,11,13,15,7,5], \"target\": 84 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 9\n\ntest_input = { \"nums\": [11,5,9,11,12,13,12,5,1,8], \"target\": 87 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 10\n\ntest_input = { \"nums\": [9,11,11,15,4,14,3,2,13,7], \"target\": 89 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 10\n\ntest_input = { \"nums\": [11,13,6,13,10], \"target\": 53 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 5\n\ntest_input = { \"nums\": [10,3,5,11,6,12], \"target\": 47 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 6\n\ntest_input = { \"nums\": [13,3,6,6,6,15,4], \"target\": 53 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 7\n\ntest_input = { \"nums\": [1,6,15,6,14,13,14], \"target\": 69 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 7\n\ntest_input = { \"nums\": [10,7,8,14,15], \"target\": 54 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 5\n\ntest_input = { \"nums\": [14,15,8,10,8,7], \"target\": 62 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 6\n\ntest_input = { \"nums\": [7,9,14,14,9,14,5,12,10], \"target\": 94 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 9\n\ntest_input = { \"nums\": [1,10,6,14,5,13,3,7,10,10], \"target\": 79 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 10\n\ntest_input = { \"nums\": [5,2,8,6,7,12,13,4,1], \"target\": 58 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 9\n\ntest_input = { \"nums\": [12,8,2,4,1], \"target\": 27 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 5\n\ntest_input = { \"nums\": [10,14,11,13,2,11], \"target\": 61 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 6\n\ntest_input = { \"nums\": [10,2,13,5,7,15], \"target\": 52 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 6\n\ntest_input = { \"nums\": [3,1,10,1,10,1,2,9,5,13], \"target\": 55 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 10\n\ntest_input = { \"nums\": [5,13,2,13,9,4,5,7], \"target\": 58 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 8\n\ntest_input = { \"nums\": [1,15,5,12,13,10,14,8], \"target\": 78 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 8\n\ntest_input = { \"nums\": [7,4,14,10,13], \"target\": 48 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 5\n\ntest_input = { \"nums\": [6,14,14,6,2,9,1,4,10], \"target\": 66 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 9\n\ntest_input = { \"nums\": [14,15,7,5,7,10,6,14,10,11], \"target\": 99 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 10\n\ntest_input = { \"nums\": [15,13,8,8,6], \"target\": 50 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 5\n\ntest_input = { \"nums\": [2,6,8,9,13,3], \"target\": 41 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 6\n\ntest_input = { \"nums\": [13,15,9,3,8,1,9,2,15,5], \"target\": 80 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 10\n\ntest_input = { \"nums\": [5,13,9,11,6,1], \"target\": 45 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 6\n\ntest_input = { \"nums\": [7,10,15,7,14,2], \"target\": 55 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 6\n\ntest_input = { \"nums\": [12,14,13,13,13], \"target\": 65 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 5\n\ntest_input = { \"nums\": [12,8,7,9,3,10,3,8,2], \"target\": 62 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 9\n\ntest_input = { \"nums\": [11,1,14,13,14,4,14,11], \"target\": 82 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 8\n\ntest_input = { \"nums\": [5,9,11,2,5,2,7,11,5,3], \"target\": 60 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 10\n\ntest_input = { \"nums\": [5,15,3,13,14,15,10], \"target\": 75 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 7\n\ntest_input = { \"nums\": [10,8,2,2,9], \"target\": 31 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 5\n\ntest_input = { \"nums\": [7,15,4,3,9,15,12,1,12], \"target\": 78 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 9\n\ntest_input = { \"nums\": [3,1,12,15,5,10], \"target\": 46 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 6\n\ntest_input = { \"nums\": [5,3,12,7,5,2,12,10,12,5], \"target\": 73 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 10\n\ntest_input = { \"nums\": [6,10,3,1,7,11,9,8,13,12], \"target\": 80 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 10\n\ntest_input = { \"nums\": [11,3,4,11,9], \"target\": 38 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 5\n\ntest_input = { \"nums\": [15,12,12,13,6,6,4,1], \"target\": 69 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 8\n\ntest_input = { \"nums\": [9,2,10,7,10,11,14,11,8], \"target\": 82 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 9\n\ntest_input = { \"nums\": [4,4,3,9,6,8,4,7,7], \"target\": 52 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 9\n\ntest_input = { \"nums\": [10,14,4,15,9,5], \"target\": 57 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 6\n\ntest_input = { \"nums\": [4,13,2,3,13,11,8,6], \"target\": 60 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 8\n\ntest_input = { \"nums\": [1,7,8,14,15,9,8,10,13,7], \"target\": 92 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 10\n\ntest_input = { \"nums\": [7,7,6,14,7,4], \"target\": 45 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 6\n\ntest_input = { \"nums\": [9,10,9,7,14,3,6,4,6], \"target\": 68 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 9\n\ntest_input = { \"nums\": [15,13,14,5,7,13,11,14], \"target\": 92 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 8\n\ntest_input = { \"nums\": [1,1,10,12,5,6,15,6,8], \"target\": 64 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 9\n\ntest_input = { \"nums\": [14,13,13,11,14,13,8], \"target\": 86 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 7\n\ntest_input = { \"nums\": [3,14,4,2,10,3,7], \"target\": 43 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 7\n\ntest_input = { \"nums\": [6,1,3,11,9,2,10,6,12], \"target\": 60 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 9\n\ntest_input = { \"nums\": [6,2,5,4,12], \"target\": 29 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 5\n\ntest_input = { \"nums\": [7,11,15,1,9,9,11], \"target\": 63 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 7\n\ntest_input = { \"nums\": [7,12,10,15,6,15,14,2], \"target\": 81 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 8\n\ntest_input = { \"nums\": [12,3,10,12,13,3,4,7,15], \"target\": 79 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 9\n\ntest_input = { \"nums\": [14,6,11,2,10,1,12,9,2], \"target\": 67 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 9\n\ntest_input = { \"nums\": [5,8,12,6,15,13,11], \"target\": 70 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 7\n\ntest_input = { \"nums\": [11,6,1,6,2,6,15], \"target\": 47 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 7\n\ntest_input = { \"nums\": [12,7,15,10,5,4,7,12,12], \"target\": 84 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 9\n\ntest_input = { \"nums\": [11,4,4,9,10,7,12], \"target\": 57 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 7\n\ntest_input = { \"nums\": [4,12,15,6,15,1,4,4,2], \"target\": 63 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 9\n\ntest_input = { \"nums\": [3,13,4,15,1], \"target\": 36 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 5\n\ntest_input = { \"nums\": [14,3,7,14,7,7,1,6], \"target\": 59 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 8\n\ntest_input = { \"nums\": [15,13,1,14,6,8], \"target\": 57 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 6\n\ntest_input = { \"nums\": [14,2,3,10,15], \"target\": 44 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 5\n\ntest_input = { \"nums\": [5,5,3,7,12,10,11], \"target\": 53 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 7\n\ntest_input = { \"nums\": [3,7,3,5,3,14,8], \"target\": 43 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 7\n\ntest_input = { \"nums\": [5,7,9,14,9,14,4,1,4], \"target\": 67 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 9\n\ntest_input = { \"nums\": [12,7,8,6,3,9,7,3,4,4], \"target\": 63 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 10\n\ntest_input = { \"nums\": [9,12,1,4,9,6,15,9,7], \"target\": 72 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 9\n\ntest_input = { \"nums\": [9,13,12,10,4,9,9,4,4,13], \"target\": 87 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 10\n\ntest_input = { \"nums\": [13,5,6,8,2,13,1,5,6], \"target\": 59 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 9\n\ntest_input = { \"nums\": [7,9,8,9,9,3,5], \"target\": 50 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 7\n\ntest_input = { \"nums\": [15,1,14,8,2,1,10,15,15], \"target\": 81 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 9\n\ntest_input = { \"nums\": [13,14,1,9,12,2], \"target\": 51 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 6\n\ntest_input = { \"nums\": [13,12,12,13,8,11,3,14,13], \"target\": 99 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 9\n\ntest_input = { \"nums\": [2,2,1,12,10,7,11,5,5], \"target\": 55 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 9\n\ntest_input = { \"nums\": [13,10,3,4,10,3], \"target\": 43 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 6\n\ntest_input = { \"nums\": [8,9,1,5,8,7,6,8], \"target\": 52 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 8\n\ntest_input = { \"nums\": [10,1,4,10,9,13,14], \"target\": 61 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 7\n\ntest_input = { \"nums\": [3,14,11,4,7,9,7,6,8,11], \"target\": 80 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 10\n\ntest_input = { \"nums\": [4,11,6,6,14,12,2,9,1], \"target\": 65 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 9\n\ntest_input = { \"nums\": [9,2,15,12,15,6,4,12], \"target\": 75 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 8\n\ntest_input = { \"nums\": [4,3,5,3,2], \"target\": 17 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 5\n\ntest_input = { \"nums\": [4,3,13,6,9], \"target\": 35 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 5", "start_time": 1698503400} +{"task_id": "biweekly-contest-116-subarrays-distinct-element-sum-of-squares-ii", "url": "https://leetcode.com/problems/subarrays-distinct-element-sum-of-squares-ii", "title": "subarrays-distinct-element-sum-of-squares-ii", "meta": {"questionId": "3139", "questionFrontendId": "2916", "title": "Subarrays Distinct Element Sum of Squares II", "titleSlug": "subarrays-distinct-element-sum-of-squares-ii", "isPaidOnly": false, "difficulty": "Hard", "likes": 115, "dislikes": 6, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0 开始的整数数组 nums 。\n\n定义 nums 一个子数组的 不同计数 值如下:\n\n * 令 nums[i..j] 表示 nums 中所有下标在 i 到 j 范围内的元素构成的子数组(满足 0 <= i <= j < nums.length ),那么我们称子数组 nums[i..j] 中不同值的数目为 nums[i..j] 的不同计数。\n\n请你返回 nums 中所有子数组的 不同计数 的 平方 和。\n\n由于答案可能会很大,请你将它对 109 + 7 取余 后返回。\n\n子数组指的是一个数组里面一段连续 非空 的元素序列。\n\n示例 1:\n\n输入:nums = [1,2,1]\n输出:15\n解释:六个子数组分别为:\n[1]: 1 个互不相同的元素。\n[2]: 1 个互不相同的元素。\n[1]: 1 个互不相同的元素。\n[1,2]: 2 个互不相同的元素。\n[2,1]: 2 个互不相同的元素。\n[1,2,1]: 2 个互不相同的元素。\n所有不同计数的平方和为 12 + 12 + 12 + 22 + 22 + 22 = 15 。\n\n示例 2:\n\n输入:nums = [2,2]\n输出:3\n解释:三个子数组分别为:\n[2]: 1 个互不相同的元素。\n[2]: 1 个互不相同的元素。\n[2,2]: 1 个互不相同的元素。\n所有不同计数的平方和为 12 + 12 + 12 = 3 。\n\n\n提示:\n\n * 1 <= nums.length <= 105\n * 1 <= nums[i] <= 105\n\"\"\"\nclass Solution:\n def sumCounts(self, nums: List[int]) -> int:\n ", "prompt_sft": "给你一个下标从 0 开始的整数数组 nums 。\n\n定义 nums 一个子数组的 不同计数 值如下:\n\n * 令 nums[i..j] 表示 nums 中所有下标在 i 到 j 范围内的元素构成的子数组(满足 0 <= i <= j < nums.length ),那么我们称子数组 nums[i..j] 中不同值的数目为 nums[i..j] 的不同计数。\n\n请你返回 nums 中所有子数组的 不同计数 的 平方 和。\n\n由于答案可能会很大,请你将它对 109 + 7 取余 后返回。\n\n子数组指的是一个数组里面一段连续 非空 的元素序列。\n\n示例 1:\n\n输入:nums = [1,2,1]\n输出:15\n解释:六个子数组分别为:\n[1]: 1 个互不相同的元素。\n[2]: 1 个互不相同的元素。\n[1]: 1 个互不相同的元素。\n[1,2]: 2 个互不相同的元素。\n[2,1]: 2 个互不相同的元素。\n[1,2,1]: 2 个互不相同的元素。\n所有不同计数的平方和为 12 + 12 + 12 + 22 + 22 + 22 = 15 。\n\n示例 2:\n\n输入:nums = [2,2]\n输出:3\n解释:三个子数组分别为:\n[2]: 1 个互不相同的元素。\n[2]: 1 个互不相同的元素。\n[2,2]: 1 个互不相同的元素。\n所有不同计数的平方和为 12 + 12 + 12 = 3 。\n\n\n提示:\n\n * 1 <= nums.length <= 105\n * 1 <= nums[i] <= 105\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def sumCounts(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,2,1] }\nassert my_solution.sumCounts(**test_input) == 15\n\ntest_input = { \"nums\": [2,2] }\nassert my_solution.sumCounts(**test_input) == 3\n\ntest_input = { \"nums\": [2,2,5,5] }\nassert my_solution.sumCounts(**test_input) == 22\n\ntest_input = { \"nums\": [5,2,4,2,1,3,2,4,3,1] }\nassert my_solution.sumCounts(**test_input) == 578\n\ntest_input = { \"nums\": [2,3,2,1,2,5,3,4,5,2] }\nassert my_solution.sumCounts(**test_input) == 629\n\ntest_input = { \"nums\": [5,1,5,2,3,5,1,5,1] }\nassert my_solution.sumCounts(**test_input) == 385\n\ntest_input = { \"nums\": [4,5,4,3,4,2] }\nassert my_solution.sumCounts(**test_input) == 120\n\ntest_input = { \"nums\": [2] }\nassert my_solution.sumCounts(**test_input) == 1\n\ntest_input = { \"nums\": [3,4,2,5,2,4,1,2,2,5] }\nassert my_solution.sumCounts(**test_input) == 535\n\ntest_input = { \"nums\": [4,4,2,4,1] }\nassert my_solution.sumCounts(**test_input) == 57\n\ntest_input = { \"nums\": [2,2,5] }\nassert my_solution.sumCounts(**test_input) == 12\n\ntest_input = { \"nums\": [4,5,1,2,2,1,3,3] }\nassert my_solution.sumCounts(**test_input) == 266\n\ntest_input = { \"nums\": [3,1,5,5,2,3,2,2,1] }\nassert my_solution.sumCounts(**test_input) == 334\n\ntest_input = { \"nums\": [2,5,2,5,3,2,5,2] }\nassert my_solution.sumCounts(**test_input) == 205\n\ntest_input = { \"nums\": [5,4,1,4,5,2,4] }\nassert my_solution.sumCounts(**test_input) == 203\n\ntest_input = { \"nums\": [1,3,3,4,3,1,2,1] }\nassert my_solution.sumCounts(**test_input) == 253\n\ntest_input = { \"nums\": [4] }\nassert my_solution.sumCounts(**test_input) == 1\n\ntest_input = { \"nums\": [1,4,2,1,5,4,3,1,4] }\nassert my_solution.sumCounts(**test_input) == 507\n\ntest_input = { \"nums\": [2,4,5,3,2,5,1,5,4,4] }\nassert my_solution.sumCounts(**test_input) == 626\n\ntest_input = { \"nums\": [3,4,1,4,5,2,2] }\nassert my_solution.sumCounts(**test_input) == 220\n\ntest_input = { \"nums\": [3,5,1,1,3] }\nassert my_solution.sumCounts(**test_input) == 62\n\ntest_input = { \"nums\": [4,3,2,5,3] }\nassert my_solution.sumCounts(**test_input) == 89\n\ntest_input = { \"nums\": [2,5] }\nassert my_solution.sumCounts(**test_input) == 6\n\ntest_input = { \"nums\": [1,5,1,4,5] }\nassert my_solution.sumCounts(**test_input) == 70\n\ntest_input = { \"nums\": [5,1] }\nassert my_solution.sumCounts(**test_input) == 6\n\ntest_input = { \"nums\": [4,5,4,3,3,5,3] }\nassert my_solution.sumCounts(**test_input) == 138\n\ntest_input = { \"nums\": [5,4,3] }\nassert my_solution.sumCounts(**test_input) == 20\n\ntest_input = { \"nums\": [5,5,3,3,4,5,4,5,5] }\nassert my_solution.sumCounts(**test_input) == 234\n\ntest_input = { \"nums\": [3,1,5,5,3,4,5,5,1,4] }\nassert my_solution.sumCounts(**test_input) == 456\n\ntest_input = { \"nums\": [4,2,3,1,1] }\nassert my_solution.sumCounts(**test_input) == 81\n\ntest_input = { \"nums\": [4,5,3,1,2,5,5,3,5] }\nassert my_solution.sumCounts(**test_input) == 434\n\ntest_input = { \"nums\": [3,2,1,2,5,2,4,5,1,5] }\nassert my_solution.sumCounts(**test_input) == 531\n\ntest_input = { \"nums\": [1,3,1,4,4] }\nassert my_solution.sumCounts(**test_input) == 62\n\ntest_input = { \"nums\": [5,1,2,1,2,1,2,3,1] }\nassert my_solution.sumCounts(**test_input) == 257\n\ntest_input = { \"nums\": [2,4] }\nassert my_solution.sumCounts(**test_input) == 6\n\ntest_input = { \"nums\": [4,5,4,5] }\nassert my_solution.sumCounts(**test_input) == 28\n\ntest_input = { \"nums\": [3,1,5,5,5,4,3,3,2] }\nassert my_solution.sumCounts(**test_input) == 334\n\ntest_input = { \"nums\": [3,2,5,2,1,5,3] }\nassert my_solution.sumCounts(**test_input) == 203\n\ntest_input = { \"nums\": [4,4,2,5,5,4,2,2,1] }\nassert my_solution.sumCounts(**test_input) == 294\n\ntest_input = { \"nums\": [1] }\nassert my_solution.sumCounts(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,3,3,3,4,4] }\nassert my_solution.sumCounts(**test_input) == 96\n\ntest_input = { \"nums\": [3,2,2,3,4] }\nassert my_solution.sumCounts(**test_input) == 57\n\ntest_input = { \"nums\": [1,5,3,2,4,4] }\nassert my_solution.sumCounts(**test_input) == 161\n\ntest_input = { \"nums\": [5,4,1,1,3] }\nassert my_solution.sumCounts(**test_input) == 69\n\ntest_input = { \"nums\": [4,3,3,5,3,4,5,3,3,1] }\nassert my_solution.sumCounts(**test_input) == 376\n\ntest_input = { \"nums\": [2,3,4,1,5,1,3,3,4] }\nassert my_solution.sumCounts(**test_input) == 432\n\ntest_input = { \"nums\": [5,1,4,2,1,1] }\nassert my_solution.sumCounts(**test_input) == 129\n\ntest_input = { \"nums\": [5,4,4,1] }\nassert my_solution.sumCounts(**test_input) == 30\n\ntest_input = { \"nums\": [1,5,1,3,2,1] }\nassert my_solution.sumCounts(**test_input) == 139\n\ntest_input = { \"nums\": [5,3] }\nassert my_solution.sumCounts(**test_input) == 6\n\ntest_input = { \"nums\": [4,1,4,3] }\nassert my_solution.sumCounts(**test_input) == 38\n\ntest_input = { \"nums\": [1,5,4,3,4,2,4,5,5,4] }\nassert my_solution.sumCounts(**test_input) == 513\n\ntest_input = { \"nums\": [4,2,3,4,3,2,5,4,4] }\nassert my_solution.sumCounts(**test_input) == 378\n\ntest_input = { \"nums\": [2,3,3,2,1,5,2,2] }\nassert my_solution.sumCounts(**test_input) == 262\n\ntest_input = { \"nums\": [2,1,4,2,4,1,4,3] }\nassert my_solution.sumCounts(**test_input) == 243\n\ntest_input = { \"nums\": [1,4,4,1,3] }\nassert my_solution.sumCounts(**test_input) == 57\n\ntest_input = { \"nums\": [2,3,2,1] }\nassert my_solution.sumCounts(**test_input) == 38\n\ntest_input = { \"nums\": [1,4,2,1] }\nassert my_solution.sumCounts(**test_input) == 43\n\ntest_input = { \"nums\": [2,4,3,2,5,1] }\nassert my_solution.sumCounts(**test_input) == 169\n\ntest_input = { \"nums\": [2,5,3,2,1,3,1,3,2] }\nassert my_solution.sumCounts(**test_input) == 348\n\ntest_input = { \"nums\": [4,1] }\nassert my_solution.sumCounts(**test_input) == 6\n\ntest_input = { \"nums\": [4,3,1,4,3,4,3,4,1] }\nassert my_solution.sumCounts(**test_input) == 263\n\ntest_input = { \"nums\": [5,1,1,1,4,3] }\nassert my_solution.sumCounts(**test_input) == 89\n\ntest_input = { \"nums\": [4,5] }\nassert my_solution.sumCounts(**test_input) == 6\n\ntest_input = { \"nums\": [5,2,2,3,1,2,5,3] }\nassert my_solution.sumCounts(**test_input) == 289\n\ntest_input = { \"nums\": [3,2,4] }\nassert my_solution.sumCounts(**test_input) == 20\n\ntest_input = { \"nums\": [5,3,5,2,3,2] }\nassert my_solution.sumCounts(**test_input) == 106\n\ntest_input = { \"nums\": [3,2,1] }\nassert my_solution.sumCounts(**test_input) == 20\n\ntest_input = { \"nums\": [4,4,2,4,3] }\nassert my_solution.sumCounts(**test_input) == 57\n\ntest_input = { \"nums\": [1,4,4] }\nassert my_solution.sumCounts(**test_input) == 12\n\ntest_input = { \"nums\": [1,4,4,3,1,2,1,4,3] }\nassert my_solution.sumCounts(**test_input) == 387\n\ntest_input = { \"nums\": [1,5,4,2,5,5,5,3] }\nassert my_solution.sumCounts(**test_input) == 249\n\ntest_input = { \"nums\": [2,1,5,3] }\nassert my_solution.sumCounts(**test_input) == 50\n\ntest_input = { \"nums\": [2,3,5,1,5,2,3,2,3,4] }\nassert my_solution.sumCounts(**test_input) == 533\n\ntest_input = { \"nums\": [5,3,4,4,3,5,4,5] }\nassert my_solution.sumCounts(**test_input) == 202\n\ntest_input = { \"nums\": [4,4,2,2,4,1] }\nassert my_solution.sumCounts(**test_input) == 80\n\ntest_input = { \"nums\": [2,3] }\nassert my_solution.sumCounts(**test_input) == 6\n\ntest_input = { \"nums\": [4,2,3,2] }\nassert my_solution.sumCounts(**test_input) == 38\n\ntest_input = { \"nums\": [1,2,2] }\nassert my_solution.sumCounts(**test_input) == 12\n\ntest_input = { \"nums\": [4,1,5,1,5,4,5,1] }\nassert my_solution.sumCounts(**test_input) == 205\n\ntest_input = { \"nums\": [4,5,3,1] }\nassert my_solution.sumCounts(**test_input) == 50\n\ntest_input = { \"nums\": [4,2,3,4,2,4,3,3,2] }\nassert my_solution.sumCounts(**test_input) == 275\n\ntest_input = { \"nums\": [4,3] }\nassert my_solution.sumCounts(**test_input) == 6\n\ntest_input = { \"nums\": [1,3,5,4,4,4] }\nassert my_solution.sumCounts(**test_input) == 113\n\ntest_input = { \"nums\": [1,2,4,2,1,2,2,4,1,3] }\nassert my_solution.sumCounts(**test_input) == 391\n\ntest_input = { \"nums\": [4,2,5,3,2] }\nassert my_solution.sumCounts(**test_input) == 89\n\ntest_input = { \"nums\": [3,4,5,3,2,5] }\nassert my_solution.sumCounts(**test_input) == 144\n\ntest_input = { \"nums\": [5,4,5] }\nassert my_solution.sumCounts(**test_input) == 15\n\ntest_input = { \"nums\": [2,4,5,1] }\nassert my_solution.sumCounts(**test_input) == 50\n\ntest_input = { \"nums\": [5,4,1,4,2,1,5] }\nassert my_solution.sumCounts(**test_input) == 203\n\ntest_input = { \"nums\": [2,3,3,2,2,3,1] }\nassert my_solution.sumCounts(**test_input) == 110\n\ntest_input = { \"nums\": [1,4,2,5] }\nassert my_solution.sumCounts(**test_input) == 50\n\ntest_input = { \"nums\": [3] }\nassert my_solution.sumCounts(**test_input) == 1\n\ntest_input = { \"nums\": [5] }\nassert my_solution.sumCounts(**test_input) == 1\n\ntest_input = { \"nums\": [1,3,5,3,2,1,1,4,3] }\nassert my_solution.sumCounts(**test_input) == 441\n\ntest_input = { \"nums\": [1,5,2,2,3,3,3] }\nassert my_solution.sumCounts(**test_input) == 140\n\ntest_input = { \"nums\": [1,2,1,4,5,5,4,1,1,1] }\nassert my_solution.sumCounts(**test_input) == 407\n\ntest_input = { \"nums\": [2,2,1,1,1,2,5,4,5] }\nassert my_solution.sumCounts(**test_input) == 296\n\ntest_input = { \"nums\": [3,2,3] }\nassert my_solution.sumCounts(**test_input) == 15\n\ntest_input = { \"nums\": [2,1,5,4,3,3,2,1,5,5] }\nassert my_solution.sumCounts(**test_input) == 652", "start_time": 1698503400} +{"task_id": "weekly-contest-368-minimum-sum-of-mountain-triplets-i", "url": "https://leetcode.com/problems/minimum-sum-of-mountain-triplets-i", "title": "minimum-sum-of-mountain-triplets-i", "meta": {"questionId": "3176", "questionFrontendId": "2908", "title": "Minimum Sum of Mountain Triplets I", "titleSlug": "minimum-sum-of-mountain-triplets-i", "isPaidOnly": false, "difficulty": "Easy", "likes": 113, "dislikes": 3, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0 开始的整数数组 nums 。\n\n如果下标三元组 (i, j, k) 满足下述全部条件,则认为它是一个 山形三元组 :\n\n * i < j < k\n * nums[i] < nums[j] 且 nums[k] < nums[j]\n\n请你找出 nums 中 元素和最小 的山形三元组,并返回其 元素和 。如果不存在满足条件的三元组,返回 -1 。\n\n示例 1:\n\n输入:nums = [8,6,1,5,3]\n输出:9\n解释:三元组 (2, 3, 4) 是一个元素和等于 9 的山形三元组,因为:\n- 2 < 3 < 4\n- nums[2] < nums[3] 且 nums[4] < nums[3]\n这个三元组的元素和等于 nums[2] + nums[3] + nums[4] = 9 。可以证明不存在元素和小于 9 的山形三元组。\n\n示例 2:\n\n输入:nums = [5,4,8,7,10,2]\n输出:13\n解释:三元组 (1, 3, 5) 是一个元素和等于 13 的山形三元组,因为:\n- 1 < 3 < 5\n- nums[1] < nums[3] 且 nums[5] < nums[3]\n这个三元组的元素和等于 nums[1] + nums[3] + nums[5] = 13 。可以证明不存在元素和小于 13 的山形三元组。\n\n示例 3:\n\n输入:nums = [6,5,4,3,4,5]\n输出:-1\n解释:可以证明 nums 中不存在山形三元组。\n\n\n提示:\n\n * 3 <= nums.length <= 50\n * 1 <= nums[i] <= 50\n\"\"\"\nclass Solution:\n def minimumSum(self, nums: List[int]) -> int:\n ", "prompt_sft": "给你一个下标从 0 开始的整数数组 nums 。\n\n如果下标三元组 (i, j, k) 满足下述全部条件,则认为它是一个 山形三元组 :\n\n * i < j < k\n * nums[i] < nums[j] 且 nums[k] < nums[j]\n\n请你找出 nums 中 元素和最小 的山形三元组,并返回其 元素和 。如果不存在满足条件的三元组,返回 -1 。\n\n示例 1:\n\n输入:nums = [8,6,1,5,3]\n输出:9\n解释:三元组 (2, 3, 4) 是一个元素和等于 9 的山形三元组,因为:\n- 2 < 3 < 4\n- nums[2] < nums[3] 且 nums[4] < nums[3]\n这个三元组的元素和等于 nums[2] + nums[3] + nums[4] = 9 。可以证明不存在元素和小于 9 的山形三元组。\n\n示例 2:\n\n输入:nums = [5,4,8,7,10,2]\n输出:13\n解释:三元组 (1, 3, 5) 是一个元素和等于 13 的山形三元组,因为:\n- 1 < 3 < 5\n- nums[1] < nums[3] 且 nums[5] < nums[3]\n这个三元组的元素和等于 nums[1] + nums[3] + nums[5] = 13 。可以证明不存在元素和小于 13 的山形三元组。\n\n示例 3:\n\n输入:nums = [6,5,4,3,4,5]\n输出:-1\n解释:可以证明 nums 中不存在山形三元组。\n\n\n提示:\n\n * 3 <= nums.length <= 50\n * 1 <= nums[i] <= 50\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def minimumSum(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [8,6,1,5,3] }\nassert my_solution.minimumSum(**test_input) == 9\n\ntest_input = { \"nums\": [5,4,8,7,10,2] }\nassert my_solution.minimumSum(**test_input) == 13\n\ntest_input = { \"nums\": [6,5,4,3,4,5] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [50,50,50] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [49,50,48] }\nassert my_solution.minimumSum(**test_input) == 147\n\ntest_input = { \"nums\": [48,50,49] }\nassert my_solution.minimumSum(**test_input) == 147\n\ntest_input = { \"nums\": [1,1,1] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,2] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,3] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,2,1] }\nassert my_solution.minimumSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,2] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,2,3] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,3,1] }\nassert my_solution.minimumSum(**test_input) == 5\n\ntest_input = { \"nums\": [1,3,2] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,3,3] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [2,1,1] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [2,1,2] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [2,1,3] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [2,2,1] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [2,2,2] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [2,2,3] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [2,3,1] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [2,3,2] }\nassert my_solution.minimumSum(**test_input) == 7\n\ntest_input = { \"nums\": [2,3,3] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [3,1,1] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [3,1,2] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [3,1,3] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [3,2,1] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [3,2,2] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [3,2,3] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [3,3,1] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [3,3,2] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [3,3,3] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,1,1] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,1,2] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,1,3] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,1,4] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,2,1] }\nassert my_solution.minimumSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,1,2,2] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,2,3] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,2,4] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,3,1] }\nassert my_solution.minimumSum(**test_input) == 5\n\ntest_input = { \"nums\": [1,1,3,2] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,1,3,3] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,3,4] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,4,1] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,1,4,2] }\nassert my_solution.minimumSum(**test_input) == 7\n\ntest_input = { \"nums\": [1,1,4,3] }\nassert my_solution.minimumSum(**test_input) == 8\n\ntest_input = { \"nums\": [1,1,4,4] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,2,1,1] }\nassert my_solution.minimumSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,1,2] }\nassert my_solution.minimumSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,1,3] }\nassert my_solution.minimumSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,1,4] }\nassert my_solution.minimumSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,2,1] }\nassert my_solution.minimumSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,2,2] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,2,2,3] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,2,2,4] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,2,3,1] }\nassert my_solution.minimumSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,3,2] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,2,3,3] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,2,3,4] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,2,4,1] }\nassert my_solution.minimumSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,4,2] }\nassert my_solution.minimumSum(**test_input) == 7\n\ntest_input = { \"nums\": [1,2,4,3] }\nassert my_solution.minimumSum(**test_input) == 8\n\ntest_input = { \"nums\": [1,2,4,4] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,3,1,1] }\nassert my_solution.minimumSum(**test_input) == 5\n\ntest_input = { \"nums\": [1,3,1,2] }\nassert my_solution.minimumSum(**test_input) == 5\n\ntest_input = { \"nums\": [1,3,1,3] }\nassert my_solution.minimumSum(**test_input) == 5\n\ntest_input = { \"nums\": [1,3,1,4] }\nassert my_solution.minimumSum(**test_input) == 5\n\ntest_input = { \"nums\": [1,3,2,1] }\nassert my_solution.minimumSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,3,2,2] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,3,2,3] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,3,2,4] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,3,3,1] }\nassert my_solution.minimumSum(**test_input) == 5\n\ntest_input = { \"nums\": [1,3,3,2] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,3,3,3] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,3,3,4] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,3,4,1] }\nassert my_solution.minimumSum(**test_input) == 5\n\ntest_input = { \"nums\": [1,3,4,2] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,3,4,3] }\nassert my_solution.minimumSum(**test_input) == 8\n\ntest_input = { \"nums\": [1,3,4,4] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,4,1,1] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,4,1,2] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,4,1,3] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,4,1,4] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,4,2,1] }\nassert my_solution.minimumSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,4,2,2] }\nassert my_solution.minimumSum(**test_input) == 7\n\ntest_input = { \"nums\": [1,4,2,3] }\nassert my_solution.minimumSum(**test_input) == 7\n\ntest_input = { \"nums\": [1,4,2,4] }\nassert my_solution.minimumSum(**test_input) == 7\n\ntest_input = { \"nums\": [1,4,3,1] }\nassert my_solution.minimumSum(**test_input) == 5\n\ntest_input = { \"nums\": [1,4,3,2] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,4,3,3] }\nassert my_solution.minimumSum(**test_input) == 8\n\ntest_input = { \"nums\": [1,4,3,4] }\nassert my_solution.minimumSum(**test_input) == 8\n\ntest_input = { \"nums\": [1,4,4,1] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,4,4,2] }\nassert my_solution.minimumSum(**test_input) == 7\n\ntest_input = { \"nums\": [1,4,4,3] }\nassert my_solution.minimumSum(**test_input) == 8\n\ntest_input = { \"nums\": [1,4,4,4] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [2,1,1,1] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [2,1,1,2] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [2,1,1,3] }\nassert my_solution.minimumSum(**test_input) == -1", "start_time": 1697941800} +{"task_id": "weekly-contest-368-minimum-sum-of-mountain-triplets-ii", "url": "https://leetcode.com/problems/minimum-sum-of-mountain-triplets-ii", "title": "minimum-sum-of-mountain-triplets-ii", "meta": {"questionId": "3186", "questionFrontendId": "2909", "title": "Minimum Sum of Mountain Triplets II", "titleSlug": "minimum-sum-of-mountain-triplets-ii", "isPaidOnly": false, "difficulty": "Medium", "likes": 160, "dislikes": 4, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0 开始的整数数组 nums 。\n\n如果下标三元组 (i, j, k) 满足下述全部条件,则认为它是一个 山形三元组 :\n\n * i < j < k\n * nums[i] < nums[j] 且 nums[k] < nums[j]\n\n请你找出 nums 中 元素和最小 的山形三元组,并返回其 元素和 。如果不存在满足条件的三元组,返回 -1 。\n\n示例 1:\n\n输入:nums = [8,6,1,5,3]\n输出:9\n解释:三元组 (2, 3, 4) 是一个元素和等于 9 的山形三元组,因为:\n- 2 < 3 < 4\n- nums[2] < nums[3] 且 nums[4] < nums[3]\n这个三元组的元素和等于 nums[2] + nums[3] + nums[4] = 9 。可以证明不存在元素和小于 9 的山形三元组。\n\n示例 2:\n\n输入:nums = [5,4,8,7,10,2]\n输出:13\n解释:三元组 (1, 3, 5) 是一个元素和等于 13 的山形三元组,因为:\n- 1 < 3 < 5\n- nums[1] < nums[3] 且 nums[5] < nums[3]\n这个三元组的元素和等于 nums[1] + nums[3] + nums[5] = 13 。可以证明不存在元素和小于 13 的山形三元组。\n\n示例 3:\n\n输入:nums = [6,5,4,3,4,5]\n输出:-1\n解释:可以证明 nums 中不存在山形三元组。\n\n\n提示:\n\n * 3 <= nums.length <= 105\n * 1 <= nums[i] <= 108\n\"\"\"\nclass Solution:\n def minimumSum(self, nums: List[int]) -> int:\n ", "prompt_sft": "给你一个下标从 0 开始的整数数组 nums 。\n\n如果下标三元组 (i, j, k) 满足下述全部条件,则认为它是一个 山形三元组 :\n\n * i < j < k\n * nums[i] < nums[j] 且 nums[k] < nums[j]\n\n请你找出 nums 中 元素和最小 的山形三元组,并返回其 元素和 。如果不存在满足条件的三元组,返回 -1 。\n\n示例 1:\n\n输入:nums = [8,6,1,5,3]\n输出:9\n解释:三元组 (2, 3, 4) 是一个元素和等于 9 的山形三元组,因为:\n- 2 < 3 < 4\n- nums[2] < nums[3] 且 nums[4] < nums[3]\n这个三元组的元素和等于 nums[2] + nums[3] + nums[4] = 9 。可以证明不存在元素和小于 9 的山形三元组。\n\n示例 2:\n\n输入:nums = [5,4,8,7,10,2]\n输出:13\n解释:三元组 (1, 3, 5) 是一个元素和等于 13 的山形三元组,因为:\n- 1 < 3 < 5\n- nums[1] < nums[3] 且 nums[5] < nums[3]\n这个三元组的元素和等于 nums[1] + nums[3] + nums[5] = 13 。可以证明不存在元素和小于 13 的山形三元组。\n\n示例 3:\n\n输入:nums = [6,5,4,3,4,5]\n输出:-1\n解释:可以证明 nums 中不存在山形三元组。\n\n\n提示:\n\n * 3 <= nums.length <= 105\n * 1 <= nums[i] <= 108\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def minimumSum(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [8,6,1,5,3] }\nassert my_solution.minimumSum(**test_input) == 9\n\ntest_input = { \"nums\": [5,4,8,7,10,2] }\nassert my_solution.minimumSum(**test_input) == 13\n\ntest_input = { \"nums\": [6,5,4,3,4,5] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [50,50,50] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [49,50,48] }\nassert my_solution.minimumSum(**test_input) == 147\n\ntest_input = { \"nums\": [48,50,49] }\nassert my_solution.minimumSum(**test_input) == 147\n\ntest_input = { \"nums\": [99999999,100000000,99999999] }\nassert my_solution.minimumSum(**test_input) == 299999998\n\ntest_input = { \"nums\": [1,1,1] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,2] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,3] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,2,1] }\nassert my_solution.minimumSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,2] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,2,3] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,3,1] }\nassert my_solution.minimumSum(**test_input) == 5\n\ntest_input = { \"nums\": [1,3,2] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,3,3] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [2,1,1] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [2,1,2] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [2,1,3] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [2,2,1] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [2,2,2] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [2,2,3] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [2,3,1] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [2,3,2] }\nassert my_solution.minimumSum(**test_input) == 7\n\ntest_input = { \"nums\": [2,3,3] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [3,1,1] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [3,1,2] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [3,1,3] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [3,2,1] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [3,2,2] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [3,2,3] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [3,3,1] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [3,3,2] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [3,3,3] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,1,1] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,1,2] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,1,3] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,1,4] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,2,1] }\nassert my_solution.minimumSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,1,2,2] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,2,3] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,2,4] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,3,1] }\nassert my_solution.minimumSum(**test_input) == 5\n\ntest_input = { \"nums\": [1,1,3,2] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,1,3,3] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,3,4] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,4,1] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,1,4,2] }\nassert my_solution.minimumSum(**test_input) == 7\n\ntest_input = { \"nums\": [1,1,4,3] }\nassert my_solution.minimumSum(**test_input) == 8\n\ntest_input = { \"nums\": [1,1,4,4] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,2,3,2] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,2,1,1] }\nassert my_solution.minimumSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,1,2] }\nassert my_solution.minimumSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,1,3] }\nassert my_solution.minimumSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,1,4] }\nassert my_solution.minimumSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,2,1] }\nassert my_solution.minimumSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,2,2] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,2,2,3] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,2,2,4] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,2,3,1] }\nassert my_solution.minimumSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,3,3] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,2,3,4] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,2,4,1] }\nassert my_solution.minimumSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,4,2] }\nassert my_solution.minimumSum(**test_input) == 7\n\ntest_input = { \"nums\": [1,2,4,3] }\nassert my_solution.minimumSum(**test_input) == 8\n\ntest_input = { \"nums\": [1,2,4,4] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,3,1,1] }\nassert my_solution.minimumSum(**test_input) == 5\n\ntest_input = { \"nums\": [1,3,1,2] }\nassert my_solution.minimumSum(**test_input) == 5\n\ntest_input = { \"nums\": [1,3,1,3] }\nassert my_solution.minimumSum(**test_input) == 5\n\ntest_input = { \"nums\": [1,3,1,4] }\nassert my_solution.minimumSum(**test_input) == 5\n\ntest_input = { \"nums\": [1,3,2,1] }\nassert my_solution.minimumSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,3,2,2] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,3,2,3] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,3,2,4] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,3,3,1] }\nassert my_solution.minimumSum(**test_input) == 5\n\ntest_input = { \"nums\": [1,3,3,2] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,3,3,3] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,3,3,4] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,3,4,1] }\nassert my_solution.minimumSum(**test_input) == 5\n\ntest_input = { \"nums\": [1,3,4,2] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,3,4,3] }\nassert my_solution.minimumSum(**test_input) == 8\n\ntest_input = { \"nums\": [1,3,4,4] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,4,1,1] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,4,1,2] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,4,1,3] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,4,1,4] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,4,2,1] }\nassert my_solution.minimumSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,4,2,2] }\nassert my_solution.minimumSum(**test_input) == 7\n\ntest_input = { \"nums\": [1,4,2,3] }\nassert my_solution.minimumSum(**test_input) == 7\n\ntest_input = { \"nums\": [1,4,2,4] }\nassert my_solution.minimumSum(**test_input) == 7\n\ntest_input = { \"nums\": [1,4,3,1] }\nassert my_solution.minimumSum(**test_input) == 5\n\ntest_input = { \"nums\": [1,4,3,2] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,4,3,3] }\nassert my_solution.minimumSum(**test_input) == 8\n\ntest_input = { \"nums\": [1,4,3,4] }\nassert my_solution.minimumSum(**test_input) == 8\n\ntest_input = { \"nums\": [1,4,4,1] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,4,4,2] }\nassert my_solution.minimumSum(**test_input) == 7\n\ntest_input = { \"nums\": [1,4,4,3] }\nassert my_solution.minimumSum(**test_input) == 8\n\ntest_input = { \"nums\": [1,4,4,4] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [2,1,1,1] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [2,1,1,2] }\nassert my_solution.minimumSum(**test_input) == -1", "start_time": 1697941800} +{"task_id": "weekly-contest-368-minimum-number-of-groups-to-create-a-valid-assignment", "url": "https://leetcode.com/problems/minimum-number-of-groups-to-create-a-valid-assignment", "title": "minimum-number-of-groups-to-create-a-valid-assignment", "meta": {"questionId": "3166", "questionFrontendId": "2910", "title": "Minimum Number of Groups to Create a Valid Assignment", "titleSlug": "minimum-number-of-groups-to-create-a-valid-assignment", "isPaidOnly": false, "difficulty": "Medium", "likes": 231, "dislikes": 151, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个长度为 n 下标从 0 开始的整数数组 nums 。\n\n我们想将下标进行分组,使得 [0, n - 1] 内所有下标 i 都 恰好 被分到其中一组。\n\n如果以下条件成立,我们说这个分组方案是合法的:\n\n * 对于每个组 g ,同一组内所有下标在 nums 中对应的数值都相等。\n * 对于任意两个组 g1 和 g2 ,两个组中 下标数量 的 差值不超过 1 。\n\n请你返回一个整数,表示得到一个合法分组方案的 最少 组数。\n\n示例 1:\n\n输入:nums = [3,2,3,2,3]\n输出:2\n解释:一个得到 2 个分组的方案如下,中括号内的数字都是下标:\n组 1 -> [0,2,4]\n组 2 -> [1,3]\n所有下标都只属于一个组。\n组 1 中,nums[0] == nums[2] == nums[4] ,所有下标对应的数值都相等。\n组 2 中,nums[1] == nums[3] ,所有下标对应的数值都相等。\n组 1 中下标数目为 3 ,组 2 中下标数目为 2 。\n两者之差不超过 1 。\n无法得到一个小于 2 组的答案,因为如果只有 1 组,组内所有下标对应的数值都要相等。\n所以答案为 2 。\n\n示例 2:\n\n输入:nums = [10,10,10,3,1,1]\n输出:4\n解释:一个得到 2 个分组的方案如下,中括号内的数字都是下标:\n组 1 -> [0]\n组 2 -> [1,2]\n组 3 -> [3]\n组 4 -> [4,5]\n分组方案满足题目要求的两个条件。\n无法得到一个小于 4 组的答案。\n所以答案为 4 。\n\n提示:\n\n * 1 <= nums.length <= 105\n * 1 <= nums[i] <= 109\n\"\"\"\nclass Solution:\n def minGroupsForValidAssignment(self, nums: List[int]) -> int:\n ", "prompt_sft": "给你一个长度为 n 下标从 0 开始的整数数组 nums 。\n\n我们想将下标进行分组,使得 [0, n - 1] 内所有下标 i 都 恰好 被分到其中一组。\n\n如果以下条件成立,我们说这个分组方案是合法的:\n\n * 对于每个组 g ,同一组内所有下标在 nums 中对应的数值都相等。\n * 对于任意两个组 g1 和 g2 ,两个组中 下标数量 的 差值不超过 1 。\n\n请你返回一个整数,表示得到一个合法分组方案的 最少 组数。\n\n示例 1:\n\n输入:nums = [3,2,3,2,3]\n输出:2\n解释:一个得到 2 个分组的方案如下,中括号内的数字都是下标:\n组 1 -> [0,2,4]\n组 2 -> [1,3]\n所有下标都只属于一个组。\n组 1 中,nums[0] == nums[2] == nums[4] ,所有下标对应的数值都相等。\n组 2 中,nums[1] == nums[3] ,所有下标对应的数值都相等。\n组 1 中下标数目为 3 ,组 2 中下标数目为 2 。\n两者之差不超过 1 。\n无法得到一个小于 2 组的答案,因为如果只有 1 组,组内所有下标对应的数值都要相等。\n所以答案为 2 。\n\n示例 2:\n\n输入:nums = [10,10,10,3,1,1]\n输出:4\n解释:一个得到 2 个分组的方案如下,中括号内的数字都是下标:\n组 1 -> [0]\n组 2 -> [1,2]\n组 3 -> [3]\n组 4 -> [4,5]\n分组方案满足题目要求的两个条件。\n无法得到一个小于 4 组的答案。\n所以答案为 4 。\n\n提示:\n\n * 1 <= nums.length <= 105\n * 1 <= nums[i] <= 109\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def minGroupsForValidAssignment(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [3,2,3,2,3] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [10,10,10,3,1,1] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 4\n\ntest_input = { \"nums\": [1,1] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 1\n\ntest_input = { \"nums\": [1,2] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [1,3] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [2,1] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [2,2] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 1\n\ntest_input = { \"nums\": [3,1] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [3,2] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [3,3] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 1\n\ntest_input = { \"nums\": [3,4] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [10,4] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [10,10] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 1\n\ntest_input = { \"nums\": [14,15] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,1] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,1] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [1,7,10] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 3\n\ntest_input = { \"nums\": [2,1,1] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [2,1,2] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [2,2,1] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [2,2,3] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [2,3,2] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [2,3,3] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [2,8,5] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 3\n\ntest_input = { \"nums\": [3,1,1] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [3,1,3] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [3,2,3] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [3,3,1] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [3,10,3] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [4,2,3] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 3\n\ntest_input = { \"nums\": [5,4,8] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 3\n\ntest_input = { \"nums\": [5,6,8] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 3\n\ntest_input = { \"nums\": [5,9,4] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 3\n\ntest_input = { \"nums\": [6,4,9] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 3\n\ntest_input = { \"nums\": [9,2,2] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [10,5,5] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [14,7,2] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,1,3] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,1,1] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,1,2] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [1,2,3,1] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,3,2] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 3\n\ntest_input = { \"nums\": [1,3,2,3] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 3\n\ntest_input = { \"nums\": [1,3,3,1] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [2,2,1,1] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [2,2,3,3] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [2,3,1,2] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 3\n\ntest_input = { \"nums\": [2,3,2,2] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 3\n\ntest_input = { \"nums\": [2,5,10,4] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 4\n\ntest_input = { \"nums\": [3,2,2,2] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 3\n\ntest_input = { \"nums\": [3,3,2,2] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [5,1,5,1] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [13,11,4,13] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,1,1,1] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,2,3,1] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,2,3,2] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 4\n\ntest_input = { \"nums\": [2,1,1,3,1] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 4\n\ntest_input = { \"nums\": [2,1,3,3,3] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 4\n\ntest_input = { \"nums\": [2,3,1,2,2] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 4\n\ntest_input = { \"nums\": [2,3,2,2,2] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 3\n\ntest_input = { \"nums\": [2,3,3,1,3] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 4\n\ntest_input = { \"nums\": [3,1,1,3,3] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [3,1,3,2,2] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 3\n\ntest_input = { \"nums\": [3,1,3,2,3] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 4\n\ntest_input = { \"nums\": [3,2,2,3,1] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 3\n\ntest_input = { \"nums\": [3,3,1,1,1] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [4,1,7,8,3] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 5\n\ntest_input = { \"nums\": [7,5,9,4,2] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 5\n\ntest_input = { \"nums\": [10,2,2,1,10] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,1,3,1,2] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 4\n\ntest_input = { \"nums\": [1,1,3,1,1,3] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,1,3,3,2] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 3\n\ntest_input = { \"nums\": [1,3,1,2,2,3] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 3\n\ntest_input = { \"nums\": [1,5,12,11,5,9] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 5\n\ntest_input = { \"nums\": [1,6,5,8,7,1] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 5\n\ntest_input = { \"nums\": [2,1,1,1,3,2] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 4\n\ntest_input = { \"nums\": [2,1,2,1,1,1] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 3\n\ntest_input = { \"nums\": [2,1,3,2,1,2] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 4\n\ntest_input = { \"nums\": [2,2,1,1,1,1] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 3\n\ntest_input = { \"nums\": [2,2,1,2,3,3] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 4\n\ntest_input = { \"nums\": [2,3,3,1,2,1] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 3\n\ntest_input = { \"nums\": [2,3,3,1,2,3] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 4\n\ntest_input = { \"nums\": [2,5,9,3,1,4] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 6\n\ntest_input = { \"nums\": [3,2,2,3,3,2] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [3,3,1,2,2,3] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 4\n\ntest_input = { \"nums\": [6,7,4,8,8,10] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 5\n\ntest_input = { \"nums\": [8,5,8,1,4,5] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 4\n\ntest_input = { \"nums\": [8,7,4,5,3,1] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 6\n\ntest_input = { \"nums\": [10,8,3,3,2,3] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 5\n\ntest_input = { \"nums\": [1,2,1,2,1,1,3] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,2,1,1,1,2] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [1,2,3,3,3,3,3] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 5\n\ntest_input = { \"nums\": [1,3,1,7,4,5,8] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 6\n\ntest_input = { \"nums\": [2,1,1,3,3,1,2] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 3\n\ntest_input = { \"nums\": [2,1,3,3,3,1,3] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 4\n\ntest_input = { \"nums\": [2,2,2,1,2,3,1] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 4\n\ntest_input = { \"nums\": [2,2,2,2,2,1,2] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 4\n\ntest_input = { \"nums\": [2,3,1,3,1,3,2] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 3\n\ntest_input = { \"nums\": [2,3,1,3,2,1,3] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 3\n\ntest_input = { \"nums\": [3,1,3,2,3,3,2] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 4", "start_time": 1697941800} +{"task_id": "weekly-contest-368-minimum-changes-to-make-k-semi-palindromes", "url": "https://leetcode.com/problems/minimum-changes-to-make-k-semi-palindromes", "title": "minimum-changes-to-make-k-semi-palindromes", "meta": {"questionId": "2879", "questionFrontendId": "2911", "title": "Minimum Changes to Make K Semi-palindromes", "titleSlug": "minimum-changes-to-make-k-semi-palindromes", "isPaidOnly": false, "difficulty": "Hard", "likes": 50, "dislikes": 78, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个字符串 s 和一个整数 k ,请你将 s 分成 k 个 子字符串 ,使得每个 子字符串 变成 半回文串 需要修改的字符数目最少。\n\n请你返回一个整数,表示需要修改的 最少 字符数目。\n\n注意:\n\n * 如果一个字符串从左往右和从右往左读是一样的,那么它是一个 回文串 。\n * 如果长度为 len 的字符串存在一个满足 1 <= d < len 的正整数 d ,len % d == 0 成立且所有对 d 做除法余数相同的下标对应的字符连起来得到的字符串都是 回文串 ,那么我们说这个字符串是 半回文串 。比方说 \"aa\" ,\"aba\" ,\"adbgad\" 和 \"abab\" 都是 半回文串 ,而 \"a\" ,\"ab\" 和 \"abca\" 不是。\n * 子字符串 指的是一个字符串中一段连续的字符序列。\n\n示例 1:\n\n输入:s = \"abcac\", k = 2\n输出:1\n解释:我们可以将 s 分成子字符串 \"ab\" 和 \"cac\" 。子字符串 \"cac\" 已经是半回文串。如果我们将 \"ab\" 变成 \"aa\" ,它也会变成一个 d = 1 的半回文串。\n该方案是将 s 分成 2 个子字符串的前提下,得到 2 个半回文子字符串需要的最少修改次数。所以答案为 1 。\n\n示例 2:\n\n输入:s = \"abcdef\", k = 2\n输出:2\n解释:我们可以将 s 分成子字符串 \"abc\" 和 \"def\" 。子字符串 \"abc\" 和 \"def\" 都需要修改一个字符得到半回文串,所以我们总共需要 2 次字符修改使所有子字符串变成半回文串。\n该方案是将 s 分成 2 个子字符串的前提下,得到 2 个半回文子字符串需要的最少修改次数。所以答案为 2 。\n\n示例 3:\n\n输入:s = \"aabbaa\", k = 3\n输出:0\n解释:我们可以将 s 分成子字符串 \"aa\" ,\"bb\" 和 \"aa\" 。\n字符串 \"aa\" 和 \"bb\" 都已经是半回文串了。所以答案为 0 。\n\n\n提示:\n\n * 2 <= s.length <= 200\n * 1 <= k <= s.length / 2\n * s 只包含小写英文字母。\n\"\"\"\nclass Solution:\n def minimumChanges(self, s: str, k: int) -> int:\n ", "prompt_sft": "给你一个字符串 s 和一个整数 k ,请你将 s 分成 k 个 子字符串 ,使得每个 子字符串 变成 半回文串 需要修改的字符数目最少。\n\n请你返回一个整数,表示需要修改的 最少 字符数目。\n\n注意:\n\n * 如果一个字符串从左往右和从右往左读是一样的,那么它是一个 回文串 。\n * 如果长度为 len 的字符串存在一个满足 1 <= d < len 的正整数 d ,len % d == 0 成立且所有对 d 做除法余数相同的下标对应的字符连起来得到的字符串都是 回文串 ,那么我们说这个字符串是 半回文串 。比方说 \"aa\" ,\"aba\" ,\"adbgad\" 和 \"abab\" 都是 半回文串 ,而 \"a\" ,\"ab\" 和 \"abca\" 不是。\n * 子字符串 指的是一个字符串中一段连续的字符序列。\n\n示例 1:\n\n输入:s = \"abcac\", k = 2\n输出:1\n解释:我们可以将 s 分成子字符串 \"ab\" 和 \"cac\" 。子字符串 \"cac\" 已经是半回文串。如果我们将 \"ab\" 变成 \"aa\" ,它也会变成一个 d = 1 的半回文串。\n该方案是将 s 分成 2 个子字符串的前提下,得到 2 个半回文子字符串需要的最少修改次数。所以答案为 1 。\n\n示例 2:\n\n输入:s = \"abcdef\", k = 2\n输出:2\n解释:我们可以将 s 分成子字符串 \"abc\" 和 \"def\" 。子字符串 \"abc\" 和 \"def\" 都需要修改一个字符得到半回文串,所以我们总共需要 2 次字符修改使所有子字符串变成半回文串。\n该方案是将 s 分成 2 个子字符串的前提下,得到 2 个半回文子字符串需要的最少修改次数。所以答案为 2 。\n\n示例 3:\n\n输入:s = \"aabbaa\", k = 3\n输出:0\n解释:我们可以将 s 分成子字符串 \"aa\" ,\"bb\" 和 \"aa\" 。\n字符串 \"aa\" 和 \"bb\" 都已经是半回文串了。所以答案为 0 。\n\n\n提示:\n\n * 2 <= s.length <= 200\n * 1 <= k <= s.length / 2\n * s 只包含小写英文字母。\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def minimumChanges(self, s: str, k: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"s\": \"abcac\", \"k\": 2 }\nassert my_solution.minimumChanges(**test_input) == 1\n\ntest_input = { \"s\": \"abcdef\", \"k\": 2 }\nassert my_solution.minimumChanges(**test_input) == 2\n\ntest_input = { \"s\": \"aabbaa\", \"k\": 3 }\nassert my_solution.minimumChanges(**test_input) == 0\n\ntest_input = { \"s\": \"aq\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 1\n\ntest_input = { \"s\": \"bb\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 0\n\ntest_input = { \"s\": \"aac\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 1\n\ntest_input = { \"s\": \"abcc\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 2\n\ntest_input = { \"s\": \"acba\", \"k\": 2 }\nassert my_solution.minimumChanges(**test_input) == 2\n\ntest_input = { \"s\": \"edaswf\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 2\n\ntest_input = { \"s\": \"aabcbaa\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 0\n\ntest_input = { \"s\": \"dqpldq\", \"k\": 3 }\nassert my_solution.minimumChanges(**test_input) == 3\n\ntest_input = { \"s\": \"eksddulf\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 3\n\ntest_input = { \"s\": \"aaaaacabbb\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 3\n\ntest_input = { \"s\": \"aaabacacbb\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 3\n\ntest_input = { \"s\": \"abbbbacaaa\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 3\n\ntest_input = { \"s\": \"abcccbaccb\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 2\n\ntest_input = { \"s\": \"baacbbbaba\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 2\n\ntest_input = { \"s\": \"babcbaccba\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 1\n\ntest_input = { \"s\": \"cabbcabcbc\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 3\n\ntest_input = { \"s\": \"ccbccaaabb\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 4\n\ntest_input = { \"s\": \"cccbabbbbc\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 2\n\ntest_input = { \"s\": \"cccccbaaac\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 3\n\ntest_input = { \"s\": \"dyfnbbbqbm\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 4\n\ntest_input = { \"s\": \"hafrypzupv\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 4\n\ntest_input = { \"s\": \"aabcacccabc\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 4\n\ntest_input = { \"s\": \"abbcaabaaac\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 5\n\ntest_input = { \"s\": \"baabaabbcb\", \"k\": 2 }\nassert my_solution.minimumChanges(**test_input) == 0\n\ntest_input = { \"s\": \"bbbabcbaccb\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 2\n\ntest_input = { \"s\": \"bcababccaa\", \"k\": 2 }\nassert my_solution.minimumChanges(**test_input) == 1\n\ntest_input = { \"s\": \"bcacacacaab\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 1\n\ntest_input = { \"s\": \"bcacccacbaa\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 4\n\ntest_input = { \"s\": \"bccaaccacb\", \"k\": 2 }\nassert my_solution.minimumChanges(**test_input) == 2\n\ntest_input = { \"s\": \"caacbacbaca\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 4\n\ntest_input = { \"s\": \"ccccaaacca\", \"k\": 2 }\nassert my_solution.minimumChanges(**test_input) == 1\n\ntest_input = { \"s\": \"efrsgmjneph\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 5\n\ntest_input = { \"s\": \"ehdvhthgbxq\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 4\n\ntest_input = { \"s\": \"eymakkvrvc\", \"k\": 2 }\nassert my_solution.minimumChanges(**test_input) == 3\n\ntest_input = { \"s\": \"gilkaelnfr\", \"k\": 2 }\nassert my_solution.minimumChanges(**test_input) == 4\n\ntest_input = { \"s\": \"iiaenfiasiv\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 4\n\ntest_input = { \"s\": \"piazrazesdk\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 5\n\ntest_input = { \"s\": \"pypwcllynf\", \"k\": 2 }\nassert my_solution.minimumChanges(**test_input) == 3\n\ntest_input = { \"s\": \"uqicxuvkorn\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 5\n\ntest_input = { \"s\": \"ziirnywodfz\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 4\n\ntest_input = { \"s\": \"zpogsiabazr\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 5\n\ntest_input = { \"s\": \"aacacaacabba\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 2\n\ntest_input = { \"s\": \"abacacabba\", \"k\": 3 }\nassert my_solution.minimumChanges(**test_input) == 0\n\ntest_input = { \"s\": \"acbcbccccba\", \"k\": 2 }\nassert my_solution.minimumChanges(**test_input) == 2\n\ntest_input = { \"s\": \"bbcaaaaacbb\", \"k\": 2 }\nassert my_solution.minimumChanges(**test_input) == 2\n\ntest_input = { \"s\": \"cbabaabccba\", \"k\": 2 }\nassert my_solution.minimumChanges(**test_input) == 1\n\ntest_input = { \"s\": \"cbacccbabcaa\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 3\n\ntest_input = { \"s\": \"cbbcbcacca\", \"k\": 3 }\nassert my_solution.minimumChanges(**test_input) == 1\n\ntest_input = { \"s\": \"ccaabbbccacb\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 3\n\ntest_input = { \"s\": \"ccabcbbcaa\", \"k\": 3 }\nassert my_solution.minimumChanges(**test_input) == 1\n\ntest_input = { \"s\": \"epenvgssid\", \"k\": 3 }\nassert my_solution.minimumChanges(**test_input) == 3\n\ntest_input = { \"s\": \"grllkopehr\", \"k\": 3 }\nassert my_solution.minimumChanges(**test_input) == 3\n\ntest_input = { \"s\": \"iaemfpyhrtgb\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 4\n\ntest_input = { \"s\": \"iqjvqxzhjc\", \"k\": 3 }\nassert my_solution.minimumChanges(**test_input) == 4\n\ntest_input = { \"s\": \"kpkzjgcvgopr\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 4\n\ntest_input = { \"s\": \"neocjmpaltv\", \"k\": 2 }\nassert my_solution.minimumChanges(**test_input) == 4\n\ntest_input = { \"s\": \"uvdbxsjyso\", \"k\": 3 }\nassert my_solution.minimumChanges(**test_input) == 4\n\ntest_input = { \"s\": \"wsezruidpcy\", \"k\": 2 }\nassert my_solution.minimumChanges(**test_input) == 4\n\ntest_input = { \"s\": \"ybexlzsvsi\", \"k\": 3 }\nassert my_solution.minimumChanges(**test_input) == 3\n\ntest_input = { \"s\": \"abacabccaa\", \"k\": 4 }\nassert my_solution.minimumChanges(**test_input) == 1\n\ntest_input = { \"s\": \"abccbacbcbc\", \"k\": 3 }\nassert my_solution.minimumChanges(**test_input) == 1\n\ntest_input = { \"s\": \"abccccbaaba\", \"k\": 3 }\nassert my_solution.minimumChanges(**test_input) == 2\n\ntest_input = { \"s\": \"acabbbacacbb\", \"k\": 2 }\nassert my_solution.minimumChanges(**test_input) == 1\n\ntest_input = { \"s\": \"acbbbbccacc\", \"k\": 3 }\nassert my_solution.minimumChanges(**test_input) == 1\n\ntest_input = { \"s\": \"acbcbbaaca\", \"k\": 4 }\nassert my_solution.minimumChanges(**test_input) == 2\n\ntest_input = { \"s\": \"accbabbbaacaa\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 2\n\ntest_input = { \"s\": \"baaaccbaaa\", \"k\": 4 }\nassert my_solution.minimumChanges(**test_input) == 2\n\ntest_input = { \"s\": \"baababcacc\", \"k\": 4 }\nassert my_solution.minimumChanges(**test_input) == 2\n\ntest_input = { \"s\": \"baabbccbbc\", \"k\": 4 }\nassert my_solution.minimumChanges(**test_input) == 2\n\ntest_input = { \"s\": \"bacbbaaccb\", \"k\": 4 }\nassert my_solution.minimumChanges(**test_input) == 2\n\ntest_input = { \"s\": \"baccbbccab\", \"k\": 4 }\nassert my_solution.minimumChanges(**test_input) == 3\n\ntest_input = { \"s\": \"bbababccabca\", \"k\": 2 }\nassert my_solution.minimumChanges(**test_input) == 2\n\ntest_input = { \"s\": \"bbacbccbca\", \"k\": 4 }\nassert my_solution.minimumChanges(**test_input) == 2\n\ntest_input = { \"s\": \"bbacccbbaabbb\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 4\n\ntest_input = { \"s\": \"bbccbbbcaab\", \"k\": 3 }\nassert my_solution.minimumChanges(**test_input) == 2\n\ntest_input = { \"s\": \"bbccbcccaba\", \"k\": 3 }\nassert my_solution.minimumChanges(**test_input) == 0\n\ntest_input = { \"s\": \"bcaacaabaa\", \"k\": 4 }\nassert my_solution.minimumChanges(**test_input) == 2\n\ntest_input = { \"s\": \"bcbcbabaabaa\", \"k\": 2 }\nassert my_solution.minimumChanges(**test_input) == 1\n\ntest_input = { \"s\": \"bofqvqapnjo\", \"k\": 3 }\nassert my_solution.minimumChanges(**test_input) == 3\n\ntest_input = { \"s\": \"bvatyzbdffqdp\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 6\n\ntest_input = { \"s\": \"cabbcbcbcbcca\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 3\n\ntest_input = { \"s\": \"cbacbbcbccccc\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 3\n\ntest_input = { \"s\": \"ccaccaacbcaac\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 3\n\ntest_input = { \"s\": \"ccbabcbabb\", \"k\": 4 }\nassert my_solution.minimumChanges(**test_input) == 1\n\ntest_input = { \"s\": \"ccbacacbcbac\", \"k\": 2 }\nassert my_solution.minimumChanges(**test_input) == 2\n\ntest_input = { \"s\": \"edulrtnsbb\", \"k\": 4 }\nassert my_solution.minimumChanges(**test_input) == 3\n\ntest_input = { \"s\": \"feecuhvurk\", \"k\": 4 }\nassert my_solution.minimumChanges(**test_input) == 4\n\ntest_input = { \"s\": \"ffqbqdocclh\", \"k\": 3 }\nassert my_solution.minimumChanges(**test_input) == 2\n\ntest_input = { \"s\": \"gceeouniipz\", \"k\": 3 }\nassert my_solution.minimumChanges(**test_input) == 4\n\ntest_input = { \"s\": \"gdlitshyeehtx\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 6\n\ntest_input = { \"s\": \"hpbijyuygkk\", \"k\": 3 }\nassert my_solution.minimumChanges(**test_input) == 3\n\ntest_input = { \"s\": \"kxvwhuewyftpp\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 6\n\ntest_input = { \"s\": \"mrqvwotsqjtfv\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 6\n\ntest_input = { \"s\": \"qhzievvxauf\", \"k\": 3 }\nassert my_solution.minimumChanges(**test_input) == 4\n\ntest_input = { \"s\": \"rbiuxrgidyzuu\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 6\n\ntest_input = { \"s\": \"rkyidomzyud\", \"k\": 3 }\nassert my_solution.minimumChanges(**test_input) == 4\n\ntest_input = { \"s\": \"wvewmaevkzjp\", \"k\": 2 }\nassert my_solution.minimumChanges(**test_input) == 3", "start_time": 1697941800} +{"task_id": "weekly-contest-367-find-indices-with-index-and-value-difference-i", "url": "https://leetcode.com/problems/find-indices-with-index-and-value-difference-i", "title": "find-indices-with-index-and-value-difference-i", "meta": {"questionId": "3165", "questionFrontendId": "2903", "title": "Find Indices With Index and Value Difference I", "titleSlug": "find-indices-with-index-and-value-difference-i", "isPaidOnly": false, "difficulty": "Easy", "likes": 97, "dislikes": 7, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0 开始、长度为 n 的整数数组 nums ,以及整数 indexDifference 和整数 valueDifference 。\n\n你的任务是从范围 [0, n - 1] 内找出  2 个满足下述所有条件的下标 i 和 j :\n\n * abs(i - j) >= indexDifference 且\n * abs(nums[i] - nums[j]) >= valueDifference\n\n返回整数数组 answer。如果存在满足题目要求的两个下标,则 answer = [i, j] ;否则,answer = [-1, -1] 。如果存在多组可供选择的下标对,只需要返回其中任意一组即可。\n\n注意:i 和 j 可能 相等 。\n\n示例 1:\n\n输入:nums = [5,1,4,1], indexDifference = 2, valueDifference = 4\n输出:[0,3]\n解释:在示例中,可以选择 i = 0 和 j = 3 。\nabs(0 - 3) >= 2 且 abs(nums[0] - nums[3]) >= 4 。\n因此,[0,3] 是一个符合题目要求的答案。\n[3,0] 也是符合题目要求的答案。\n\n示例 2:\n\n输入:nums = [2,1], indexDifference = 0, valueDifference = 0\n输出:[0,0]\n解释:\n在示例中,可以选择 i = 0 和 j = 0 。\nabs(0 - 0) >= 0 且 abs(nums[0] - nums[0]) >= 0 。\n因此,[0,0] 是一个符合题目要求的答案。\n[0,1]、[1,0] 和 [1,1] 也是符合题目要求的答案。\n\n示例 3:\n\n输入:nums = [1,2,3], indexDifference = 2, valueDifference = 4\n输出:[-1,-1]\n解释:在示例中,可以证明无法找出 2 个满足所有条件的下标。\n因此,返回 [-1,-1] 。\n\n提示:\n\n * 1 <= n == nums.length <= 100\n * 0 <= nums[i] <= 50\n * 0 <= indexDifference <= 100\n * 0 <= valueDifference <= 50\n\"\"\"\nclass Solution:\n def findIndices(self, nums: List[int], indexDifference: int, valueDifference: int) -> List[int]:\n ", "prompt_sft": "给你一个下标从 0 开始、长度为 n 的整数数组 nums ,以及整数 indexDifference 和整数 valueDifference 。\n\n你的任务是从范围 [0, n - 1] 内找出  2 个满足下述所有条件的下标 i 和 j :\n\n * abs(i - j) >= indexDifference 且\n * abs(nums[i] - nums[j]) >= valueDifference\n\n返回整数数组 answer。如果存在满足题目要求的两个下标,则 answer = [i, j] ;否则,answer = [-1, -1] 。如果存在多组可供选择的下标对,只需要返回其中任意一组即可。\n\n注意:i 和 j 可能 相等 。\n\n示例 1:\n\n输入:nums = [5,1,4,1], indexDifference = 2, valueDifference = 4\n输出:[0,3]\n解释:在示例中,可以选择 i = 0 和 j = 3 。\nabs(0 - 3) >= 2 且 abs(nums[0] - nums[3]) >= 4 。\n因此,[0,3] 是一个符合题目要求的答案。\n[3,0] 也是符合题目要求的答案。\n\n示例 2:\n\n输入:nums = [2,1], indexDifference = 0, valueDifference = 0\n输出:[0,0]\n解释:\n在示例中,可以选择 i = 0 和 j = 0 。\nabs(0 - 0) >= 0 且 abs(nums[0] - nums[0]) >= 0 。\n因此,[0,0] 是一个符合题目要求的答案。\n[0,1]、[1,0] 和 [1,1] 也是符合题目要求的答案。\n\n示例 3:\n\n输入:nums = [1,2,3], indexDifference = 2, valueDifference = 4\n输出:[-1,-1]\n解释:在示例中,可以证明无法找出 2 个满足所有条件的下标。\n因此,返回 [-1,-1] 。\n\n提示:\n\n * 1 <= n == nums.length <= 100\n * 0 <= nums[i] <= 50\n * 0 <= indexDifference <= 100\n * 0 <= valueDifference <= 50\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def findIndices(self, nums: List[int], indexDifference: int, valueDifference: int) -> List[int]:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [5,1,4,1], \"indexDifference\": 2, \"valueDifference\": 4 }\nassert my_solution.findIndices(**test_input) == [0,3]\n\ntest_input = { \"nums\": [2,1], \"indexDifference\": 0, \"valueDifference\": 0 }\nassert my_solution.findIndices(**test_input) == [0,0]\n\ntest_input = { \"nums\": [1,2,3], \"indexDifference\": 2, \"valueDifference\": 4 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [0], \"indexDifference\": 0, \"valueDifference\": 0 }\nassert my_solution.findIndices(**test_input) == [0,0]\n\ntest_input = { \"nums\": [3], \"indexDifference\": 0, \"valueDifference\": 0 }\nassert my_solution.findIndices(**test_input) == [0,0]\n\ntest_input = { \"nums\": [3], \"indexDifference\": 1, \"valueDifference\": 1 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [4], \"indexDifference\": 1, \"valueDifference\": 0 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [5], \"indexDifference\": 1, \"valueDifference\": 3 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [7], \"indexDifference\": 1, \"valueDifference\": 7 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [8], \"indexDifference\": 0, \"valueDifference\": 2 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [8], \"indexDifference\": 1, \"valueDifference\": 7 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [10], \"indexDifference\": 0, \"valueDifference\": 9 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [11], \"indexDifference\": 1, \"valueDifference\": 0 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [18], \"indexDifference\": 1, \"valueDifference\": 4 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [38], \"indexDifference\": 1, \"valueDifference\": 34 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [40], \"indexDifference\": 1, \"valueDifference\": 2 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [5,10], \"indexDifference\": 1, \"valueDifference\": 2 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [5,48], \"indexDifference\": 0, \"valueDifference\": 29 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [6,3], \"indexDifference\": 1, \"valueDifference\": 2 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [7,6], \"indexDifference\": 1, \"valueDifference\": 0 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [8,8], \"indexDifference\": 1, \"valueDifference\": 1 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [17,31], \"indexDifference\": 1, \"valueDifference\": 9 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [21,22], \"indexDifference\": 1, \"valueDifference\": 21 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [48,40], \"indexDifference\": 2, \"valueDifference\": 31 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [2,8,0], \"indexDifference\": 2, \"valueDifference\": 7 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [2,29,0], \"indexDifference\": 0, \"valueDifference\": 12 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [3,0,7], \"indexDifference\": 2, \"valueDifference\": 4 }\nassert my_solution.findIndices(**test_input) == [0,2]\n\ntest_input = { \"nums\": [4,22,43], \"indexDifference\": 0, \"valueDifference\": 34 }\nassert my_solution.findIndices(**test_input) == [0,2]\n\ntest_input = { \"nums\": [5,0,3], \"indexDifference\": 1, \"valueDifference\": 4 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [5,9,2], \"indexDifference\": 0, \"valueDifference\": 1 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [6,2,7], \"indexDifference\": 2, \"valueDifference\": 5 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [6,5,1], \"indexDifference\": 2, \"valueDifference\": 6 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [6,8,0], \"indexDifference\": 1, \"valueDifference\": 3 }\nassert my_solution.findIndices(**test_input) == [0,2]\n\ntest_input = { \"nums\": [7,36,21], \"indexDifference\": 1, \"valueDifference\": 20 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [9,4,7], \"indexDifference\": 0, \"valueDifference\": 9 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [9,50,31], \"indexDifference\": 1, \"valueDifference\": 8 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [31,23,36], \"indexDifference\": 1, \"valueDifference\": 11 }\nassert my_solution.findIndices(**test_input) == [1,2]\n\ntest_input = { \"nums\": [40,21,1], \"indexDifference\": 2, \"valueDifference\": 0 }\nassert my_solution.findIndices(**test_input) == [0,2]\n\ntest_input = { \"nums\": [0,5,10,5], \"indexDifference\": 3, \"valueDifference\": 0 }\nassert my_solution.findIndices(**test_input) == [0,3]\n\ntest_input = { \"nums\": [1,28,24,35], \"indexDifference\": 3, \"valueDifference\": 2 }\nassert my_solution.findIndices(**test_input) == [0,3]\n\ntest_input = { \"nums\": [2,7,10,4], \"indexDifference\": 0, \"valueDifference\": 5 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [3,1,0,3], \"indexDifference\": 2, \"valueDifference\": 0 }\nassert my_solution.findIndices(**test_input) == [0,2]\n\ntest_input = { \"nums\": [7,5,6,2], \"indexDifference\": 2, \"valueDifference\": 2 }\nassert my_solution.findIndices(**test_input) == [0,3]\n\ntest_input = { \"nums\": [9,3,6,4], \"indexDifference\": 1, \"valueDifference\": 5 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [34,46,11,45], \"indexDifference\": 1, \"valueDifference\": 3 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [36,37,40,9], \"indexDifference\": 2, \"valueDifference\": 8 }\nassert my_solution.findIndices(**test_input) == [0,3]\n\ntest_input = { \"nums\": [37,25,48,13], \"indexDifference\": 0, \"valueDifference\": 0 }\nassert my_solution.findIndices(**test_input) == [0,0]\n\ntest_input = { \"nums\": [45,6,29,21], \"indexDifference\": 3, \"valueDifference\": 36 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [1,5,7,9,2], \"indexDifference\": 3, \"valueDifference\": 8 }\nassert my_solution.findIndices(**test_input) == [0,3]\n\ntest_input = { \"nums\": [7,2,1,8,3], \"indexDifference\": 0, \"valueDifference\": 7 }\nassert my_solution.findIndices(**test_input) == [2,3]\n\ntest_input = { \"nums\": [8,9,8,0,4], \"indexDifference\": 1, \"valueDifference\": 6 }\nassert my_solution.findIndices(**test_input) == [0,3]\n\ntest_input = { \"nums\": [9,1,10,0,10], \"indexDifference\": 0, \"valueDifference\": 3 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [9,9,4,5,5], \"indexDifference\": 2, \"valueDifference\": 9 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [10,1,10,12,1], \"indexDifference\": 1, \"valueDifference\": 3 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [17,46,31,28,28], \"indexDifference\": 0, \"valueDifference\": 46 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [17,49,1,47,12], \"indexDifference\": 2, \"valueDifference\": 17 }\nassert my_solution.findIndices(**test_input) == [0,3]\n\ntest_input = { \"nums\": [32,49,3,40,44], \"indexDifference\": 1, \"valueDifference\": 37 }\nassert my_solution.findIndices(**test_input) == [1,2]\n\ntest_input = { \"nums\": [46,43,16,16,34], \"indexDifference\": 3, \"valueDifference\": 13 }\nassert my_solution.findIndices(**test_input) == [0,3]\n\ntest_input = { \"nums\": [49,36,18,4,33], \"indexDifference\": 3, \"valueDifference\": 20 }\nassert my_solution.findIndices(**test_input) == [0,3]\n\ntest_input = { \"nums\": [0,7,10,6,6,5], \"indexDifference\": 1, \"valueDifference\": 5 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [2,0,3,4,0,5], \"indexDifference\": 3, \"valueDifference\": 5 }\nassert my_solution.findIndices(**test_input) == [1,5]\n\ntest_input = { \"nums\": [3,8,9,7,2,3], \"indexDifference\": 3, \"valueDifference\": 6 }\nassert my_solution.findIndices(**test_input) == [1,4]\n\ntest_input = { \"nums\": [3,27,38,47,38,4], \"indexDifference\": 0, \"valueDifference\": 10 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [4,13,48,50,1,26], \"indexDifference\": 4, \"valueDifference\": 34 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [6,1,2,6,4,6], \"indexDifference\": 2, \"valueDifference\": 2 }\nassert my_solution.findIndices(**test_input) == [0,2]\n\ntest_input = { \"nums\": [7,1,0,9,5,9], \"indexDifference\": 2, \"valueDifference\": 5 }\nassert my_solution.findIndices(**test_input) == [0,2]\n\ntest_input = { \"nums\": [7,3,7,5,7,9], \"indexDifference\": 1, \"valueDifference\": 2 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [12,37,7,16,5,34], \"indexDifference\": 3, \"valueDifference\": 27 }\nassert my_solution.findIndices(**test_input) == [1,4]\n\ntest_input = { \"nums\": [17,46,48,25,22,4], \"indexDifference\": 2, \"valueDifference\": 30 }\nassert my_solution.findIndices(**test_input) == [0,2]\n\ntest_input = { \"nums\": [18,18,7,10,9,50], \"indexDifference\": 2, \"valueDifference\": 32 }\nassert my_solution.findIndices(**test_input) == [0,5]\n\ntest_input = { \"nums\": [18,42,37,13,49,42], \"indexDifference\": 3, \"valueDifference\": 46 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [23,31,14,42,0,49], \"indexDifference\": 4, \"valueDifference\": 44 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [50,46,15,16,48,7], \"indexDifference\": 1, \"valueDifference\": 7 }\nassert my_solution.findIndices(**test_input) == [0,2]\n\ntest_input = { \"nums\": [5,6,8,5,6,3,1], \"indexDifference\": 0, \"valueDifference\": 4 }\nassert my_solution.findIndices(**test_input) == [0,6]\n\ntest_input = { \"nums\": [5,50,13,3,44,7,29], \"indexDifference\": 1, \"valueDifference\": 45 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [8,7,18,47,27,25,41], \"indexDifference\": 0, \"valueDifference\": 45 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [9,1,0,6,7,5,8], \"indexDifference\": 1, \"valueDifference\": 1 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [11,3,36,17,13,0,26], \"indexDifference\": 2, \"valueDifference\": 33 }\nassert my_solution.findIndices(**test_input) == [2,5]\n\ntest_input = { \"nums\": [13,0,16,32,47,27,25], \"indexDifference\": 1, \"valueDifference\": 35 }\nassert my_solution.findIndices(**test_input) == [1,4]\n\ntest_input = { \"nums\": [13,16,30,33,50,50,38], \"indexDifference\": 3, \"valueDifference\": 30 }\nassert my_solution.findIndices(**test_input) == [0,4]\n\ntest_input = { \"nums\": [21,44,22,1,21,9,17], \"indexDifference\": 1, \"valueDifference\": 41 }\nassert my_solution.findIndices(**test_input) == [1,3]\n\ntest_input = { \"nums\": [35,31,36,28,49,4,46], \"indexDifference\": 4, \"valueDifference\": 27 }\nassert my_solution.findIndices(**test_input) == [0,5]\n\ntest_input = { \"nums\": [39,18,49,25,40,41,26], \"indexDifference\": 1, \"valueDifference\": 43 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [40,46,11,36,25,46,47], \"indexDifference\": 0, \"valueDifference\": 37 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [46,7,6,3,43,7,48], \"indexDifference\": 0, \"valueDifference\": 48 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [0,1,6,8,8,3,9,10], \"indexDifference\": 2, \"valueDifference\": 6 }\nassert my_solution.findIndices(**test_input) == [0,2]\n\ntest_input = { \"nums\": [1,0,6,4,8,7,2,5], \"indexDifference\": 3, \"valueDifference\": 7 }\nassert my_solution.findIndices(**test_input) == [0,4]\n\ntest_input = { \"nums\": [3,8,3,8,0,5,5,7], \"indexDifference\": 4, \"valueDifference\": 6 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [5,10,4,4,8,6,0,4], \"indexDifference\": 2, \"valueDifference\": 7 }\nassert my_solution.findIndices(**test_input) == [1,6]\n\ntest_input = { \"nums\": [6,1,3,7,4,4,2,1], \"indexDifference\": 0, \"valueDifference\": 5 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [9,36,31,2,46,1,27,37], \"indexDifference\": 3, \"valueDifference\": 45 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [10,4,0,1,4,7,2,0], \"indexDifference\": 5, \"valueDifference\": 8 }\nassert my_solution.findIndices(**test_input) == [0,6]\n\ntest_input = { \"nums\": [26,20,19,36,20,28,33,39], \"indexDifference\": 0, \"valueDifference\": 0 }\nassert my_solution.findIndices(**test_input) == [0,0]\n\ntest_input = { \"nums\": [29,3,30,34,25,40,10,37], \"indexDifference\": 5, \"valueDifference\": 22 }\nassert my_solution.findIndices(**test_input) == [1,7]\n\ntest_input = { \"nums\": [39,26,46,9,5,34,0,20], \"indexDifference\": 0, \"valueDifference\": 24 }\nassert my_solution.findIndices(**test_input) == [0,3]\n\ntest_input = { \"nums\": [46,12,38,21,12,9,18,29], \"indexDifference\": 3, \"valueDifference\": 35 }\nassert my_solution.findIndices(**test_input) == [0,5]\n\ntest_input = { \"nums\": [1,7,7,2,4,10,1,5,9], \"indexDifference\": 4, \"valueDifference\": 4 }\nassert my_solution.findIndices(**test_input) == [0,5]\n\ntest_input = { \"nums\": [2,4,1,5,2,0,3,5,7], \"indexDifference\": 5, \"valueDifference\": 2 }\nassert my_solution.findIndices(**test_input) == [0,5]\n\ntest_input = { \"nums\": [2,5,6,5,9,7,2,3,6], \"indexDifference\": 4, \"valueDifference\": 2 }\nassert my_solution.findIndices(**test_input) == [0,4]\n\ntest_input = { \"nums\": [2,6,9,4,9,4,10,9,2], \"indexDifference\": 0, \"valueDifference\": 4 }\nassert my_solution.findIndices(**test_input) == [0,1]", "start_time": 1697337000} +{"task_id": "weekly-contest-367-shortest-and-lexicographically-smallest-beautiful-string", "url": "https://leetcode.com/problems/shortest-and-lexicographically-smallest-beautiful-string", "title": "shortest-and-lexicographically-smallest-beautiful-string", "meta": {"questionId": "3150", "questionFrontendId": "2904", "title": "Shortest and Lexicographically Smallest Beautiful String", "titleSlug": "shortest-and-lexicographically-smallest-beautiful-string", "isPaidOnly": false, "difficulty": "Medium", "likes": 147, "dislikes": 8, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个二进制字符串 s 和一个正整数 k 。\n\n如果 s 的某个子字符串中 1 的个数恰好等于 k ,则称这个子字符串是一个 美丽子字符串 。\n\n令 len 等于 最短 美丽子字符串的长度。\n\n返回长度等于 len 且字典序 最小 的美丽子字符串。如果 s 中不含美丽子字符串,则返回一个 空 字符串。\n\n对于相同长度的两个字符串 a 和 b ,如果在 a 和 b 出现不同的第一个位置上,a 中该位置上的字符严格大于 b 中的对应字符,则认为字符串 a 字典序 大于 字符串 b 。\n\n * 例如,\"abcd\" 的字典序大于 \"abcc\" ,因为两个字符串出现不同的第一个位置对应第四个字符,而 d 大于 c 。\n\n示例 1:\n\n输入:s = \"100011001\", k = 3\n输出:\"11001\"\n解释:示例中共有 7 个美丽子字符串:\n1. 子字符串 \"100011001\" 。\n2. 子字符串 \"100011001\" 。\n3. 子字符串 \"100011001\" 。\n4. 子字符串 \"100011001\" 。\n5. 子字符串 \"100011001\" 。\n6. 子字符串 \"100011001\" 。\n7. 子字符串 \"100011001\" 。\n最短美丽子字符串的长度是 5 。\n长度为 5 且字典序最小的美丽子字符串是子字符串 \"11001\" 。\n\n示例 2:\n\n输入:s = \"1011\", k = 2\n输出:\"11\"\n解释:示例中共有 3 个美丽子字符串:\n1. 子字符串 \"1011\" 。\n2. 子字符串 \"1011\" 。\n3. 子字符串 \"1011\" 。\n最短美丽子字符串的长度是 2 。\n长度为 2 且字典序最小的美丽子字符串是子字符串 \"11\" 。\n\n示例 3:\n\n输入:s = \"000\", k = 1\n输出:\"\"\n解释:示例中不存在美丽子字符串。\n\n\n提示:\n\n * 1 <= s.length <= 100\n * 1 <= k <= s.length\n\"\"\"\nclass Solution:\n def shortestBeautifulSubstring(self, s: str, k: int) -> str:\n ", "prompt_sft": "给你一个二进制字符串 s 和一个正整数 k 。\n\n如果 s 的某个子字符串中 1 的个数恰好等于 k ,则称这个子字符串是一个 美丽子字符串 。\n\n令 len 等于 最短 美丽子字符串的长度。\n\n返回长度等于 len 且字典序 最小 的美丽子字符串。如果 s 中不含美丽子字符串,则返回一个 空 字符串。\n\n对于相同长度的两个字符串 a 和 b ,如果在 a 和 b 出现不同的第一个位置上,a 中该位置上的字符严格大于 b 中的对应字符,则认为字符串 a 字典序 大于 字符串 b 。\n\n * 例如,\"abcd\" 的字典序大于 \"abcc\" ,因为两个字符串出现不同的第一个位置对应第四个字符,而 d 大于 c 。\n\n示例 1:\n\n输入:s = \"100011001\", k = 3\n输出:\"11001\"\n解释:示例中共有 7 个美丽子字符串:\n1. 子字符串 \"100011001\" 。\n2. 子字符串 \"100011001\" 。\n3. 子字符串 \"100011001\" 。\n4. 子字符串 \"100011001\" 。\n5. 子字符串 \"100011001\" 。\n6. 子字符串 \"100011001\" 。\n7. 子字符串 \"100011001\" 。\n最短美丽子字符串的长度是 5 。\n长度为 5 且字典序最小的美丽子字符串是子字符串 \"11001\" 。\n\n示例 2:\n\n输入:s = \"1011\", k = 2\n输出:\"11\"\n解释:示例中共有 3 个美丽子字符串:\n1. 子字符串 \"1011\" 。\n2. 子字符串 \"1011\" 。\n3. 子字符串 \"1011\" 。\n最短美丽子字符串的长度是 2 。\n长度为 2 且字典序最小的美丽子字符串是子字符串 \"11\" 。\n\n示例 3:\n\n输入:s = \"000\", k = 1\n输出:\"\"\n解释:示例中不存在美丽子字符串。\n\n\n提示:\n\n * 1 <= s.length <= 100\n * 1 <= k <= s.length\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def shortestBeautifulSubstring(self, s: str, k: int) -> str:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"s\": \"100011001\", \"k\": 3 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"11001\"\n\ntest_input = { \"s\": \"1011\", \"k\": 2 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"11\"\n\ntest_input = { \"s\": \"000\", \"k\": 1 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"11000111\", \"k\": 1 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"1\"\n\ntest_input = { \"s\": \"10100010\", \"k\": 5 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"0010111\", \"k\": 7 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"111111110010001010\", \"k\": 11 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"11111111001000101\"\n\ntest_input = { \"s\": \"00000110010011010110\", \"k\": 13 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"1100001110111100100\", \"k\": 8 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"11101111001\"\n\ntest_input = { \"s\": \"01011101000111110\", \"k\": 5 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"11111\"\n\ntest_input = { \"s\": \"10001\", \"k\": 5 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"001011010001101\", \"k\": 11 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"1001000\", \"k\": 4 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"001\", \"k\": 1 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"1\"\n\ntest_input = { \"s\": \"000110001\", \"k\": 6 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"10001\", \"k\": 3 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"100011000000000\", \"k\": 9 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"10101000111\", \"k\": 3 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"111\"\n\ntest_input = { \"s\": \"00\", \"k\": 1 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"1100100101011001001\", \"k\": 7 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"1100100101011\"\n\ntest_input = { \"s\": \"0001001\", \"k\": 7 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"101100000\", \"k\": 6 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"100011\", \"k\": 2 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"11\"\n\ntest_input = { \"s\": \"1101\", \"k\": 4 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"110000\", \"k\": 2 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"11\"\n\ntest_input = { \"s\": \"001110101101101111\", \"k\": 10 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"10101101101111\"\n\ntest_input = { \"s\": \"111011110\", \"k\": 1 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"1\"\n\ntest_input = { \"s\": \"1111111011111\", \"k\": 12 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"1111111011111\"\n\ntest_input = { \"s\": \"0101111000101011001\", \"k\": 9 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"101111000101011\"\n\ntest_input = { \"s\": \"0011010\", \"k\": 4 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"01101101110110010\", \"k\": 16 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"10111101011100101001\", \"k\": 14 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"0\", \"k\": 1 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"0101001000001011011\", \"k\": 12 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"01000100\", \"k\": 1 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"1\"\n\ntest_input = { \"s\": \"01001010010\", \"k\": 6 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"01100110011101010\", \"k\": 3 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"111\"\n\ntest_input = { \"s\": \"10\", \"k\": 2 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"01010000110111110010\", \"k\": 12 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"1101\", \"k\": 2 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"11\"\n\ntest_input = { \"s\": \"00000100000\", \"k\": 9 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"10101101000111\", \"k\": 3 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"111\"\n\ntest_input = { \"s\": \"101010111111110110\", \"k\": 4 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"1111\"\n\ntest_input = { \"s\": \"0100111011101010\", \"k\": 16 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"1111001111\", \"k\": 1 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"1\"\n\ntest_input = { \"s\": \"000010110111011\", \"k\": 8 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"10110111011\"\n\ntest_input = { \"s\": \"010100\", \"k\": 1 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"1\"\n\ntest_input = { \"s\": \"00\", \"k\": 2 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"000100\", \"k\": 5 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"1110001110100110011\", \"k\": 13 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"111011001\", \"k\": 9 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"0111000100001101\", \"k\": 9 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"100011\", \"k\": 5 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"111000101010010011\", \"k\": 10 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"01010\", \"k\": 5 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"0100100111100010\", \"k\": 14 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"110\", \"k\": 1 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"1\"\n\ntest_input = { \"s\": \"111000\", \"k\": 2 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"11\"\n\ntest_input = { \"s\": \"101011\", \"k\": 6 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"11101101110110111101\", \"k\": 17 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"010011101\", \"k\": 4 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"11101\"\n\ntest_input = { \"s\": \"100111010111001\", \"k\": 11 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"110001111100011\", \"k\": 2 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"11\"\n\ntest_input = { \"s\": \"0010110\", \"k\": 1 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"1\"\n\ntest_input = { \"s\": \"11101110001111\", \"k\": 7 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"1110001111\"\n\ntest_input = { \"s\": \"110\", \"k\": 2 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"11\"\n\ntest_input = { \"s\": \"110101\", \"k\": 3 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"1101\"\n\ntest_input = { \"s\": \"0110100\", \"k\": 7 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"00111\", \"k\": 3 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"111\"\n\ntest_input = { \"s\": \"1011001100001110101\", \"k\": 4 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"11101\"\n\ntest_input = { \"s\": \"0101000010101010\", \"k\": 6 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"10100001010101\"\n\ntest_input = { \"s\": \"0011000110001\", \"k\": 2 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"11\"\n\ntest_input = { \"s\": \"01001011000110100\", \"k\": 11 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"11\", \"k\": 2 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"11\"\n\ntest_input = { \"s\": \"00111100\", \"k\": 5 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"1110\", \"k\": 3 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"111\"\n\ntest_input = { \"s\": \"00010000110\", \"k\": 9 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"110110100011\", \"k\": 8 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"00111110001100000\", \"k\": 7 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"1111100011\"\n\ntest_input = { \"s\": \"10100100101\", \"k\": 11 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"110\", \"k\": 3 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"1001101100000010100\", \"k\": 1 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"1\"\n\ntest_input = { \"s\": \"0101010101010111101\", \"k\": 15 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"0000101\", \"k\": 1 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"1\"\n\ntest_input = { \"s\": \"110011010110\", \"k\": 10 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"11010\", \"k\": 4 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"10010100\", \"k\": 1 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"1\"\n\ntest_input = { \"s\": \"1\", \"k\": 1 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"1\"\n\ntest_input = { \"s\": \"11\", \"k\": 1 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"1\"\n\ntest_input = { \"s\": \"101000\", \"k\": 2 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"101\"\n\ntest_input = { \"s\": \"000010110010111\", \"k\": 7 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"10110010111\"\n\ntest_input = { \"s\": \"0100111\", \"k\": 4 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"100111\"\n\ntest_input = { \"s\": \"0111111100011111101\", \"k\": 12 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"111111000111111\"\n\ntest_input = { \"s\": \"010001\", \"k\": 3 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"110110101010100000\", \"k\": 10 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"110000001\", \"k\": 4 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"001101\", \"k\": 6 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"01111001101001010101\", \"k\": 16 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"00111010\", \"k\": 6 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"11011101010100\", \"k\": 7 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"1101110101\"", "start_time": 1697337000} +{"task_id": "weekly-contest-367-find-indices-with-index-and-value-difference-ii", "url": "https://leetcode.com/problems/find-indices-with-index-and-value-difference-ii", "title": "find-indices-with-index-and-value-difference-ii", "meta": {"questionId": "3170", "questionFrontendId": "2905", "title": "Find Indices With Index and Value Difference II", "titleSlug": "find-indices-with-index-and-value-difference-ii", "isPaidOnly": false, "difficulty": "Medium", "likes": 218, "dislikes": 6, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0 开始、长度为 n 的整数数组 nums ,以及整数 indexDifference 和整数 valueDifference 。\n\n你的任务是从范围 [0, n - 1] 内找出  2 个满足下述所有条件的下标 i 和 j :\n\n * abs(i - j) >= indexDifference 且\n * abs(nums[i] - nums[j]) >= valueDifference\n\n返回整数数组 answer。如果存在满足题目要求的两个下标,则 answer = [i, j] ;否则,answer = [-1, -1] 。如果存在多组可供选择的下标对,只需要返回其中任意一组即可。\n\n注意:i 和 j 可能 相等 。\n\n示例 1:\n\n输入:nums = [5,1,4,1], indexDifference = 2, valueDifference = 4\n输出:[0,3]\n解释:在示例中,可以选择 i = 0 和 j = 3 。\nabs(0 - 3) >= 2 且 abs(nums[0] - nums[3]) >= 4 。\n因此,[0,3] 是一个符合题目要求的答案。\n[3,0] 也是符合题目要求的答案。\n\n示例 2:\n\n输入:nums = [2,1], indexDifference = 0, valueDifference = 0\n输出:[0,0]\n解释:\n在示例中,可以选择 i = 0 和 j = 0 。\nabs(0 - 0) >= 0 且 abs(nums[0] - nums[0]) >= 0 。\n因此,[0,0] 是一个符合题目要求的答案。\n[0,1]、[1,0] 和 [1,1] 也是符合题目要求的答案。\n\n示例 3:\n\n输入:nums = [1,2,3], indexDifference = 2, valueDifference = 4\n输出:[-1,-1]\n解释:在示例中,可以证明无法找出 2 个满足所有条件的下标。\n因此,返回 [-1,-1] 。\n\n提示:\n\n * 1 <= n == nums.length <= 105\n * 0 <= nums[i] <= 109\n * 0 <= indexDifference <= 105\n * 0 <= valueDifference <= 109\n\"\"\"\nclass Solution:\n def findIndices(self, nums: List[int], indexDifference: int, valueDifference: int) -> List[int]:\n ", "prompt_sft": "给你一个下标从 0 开始、长度为 n 的整数数组 nums ,以及整数 indexDifference 和整数 valueDifference 。\n\n你的任务是从范围 [0, n - 1] 内找出  2 个满足下述所有条件的下标 i 和 j :\n\n * abs(i - j) >= indexDifference 且\n * abs(nums[i] - nums[j]) >= valueDifference\n\n返回整数数组 answer。如果存在满足题目要求的两个下标,则 answer = [i, j] ;否则,answer = [-1, -1] 。如果存在多组可供选择的下标对,只需要返回其中任意一组即可。\n\n注意:i 和 j 可能 相等 。\n\n示例 1:\n\n输入:nums = [5,1,4,1], indexDifference = 2, valueDifference = 4\n输出:[0,3]\n解释:在示例中,可以选择 i = 0 和 j = 3 。\nabs(0 - 3) >= 2 且 abs(nums[0] - nums[3]) >= 4 。\n因此,[0,3] 是一个符合题目要求的答案。\n[3,0] 也是符合题目要求的答案。\n\n示例 2:\n\n输入:nums = [2,1], indexDifference = 0, valueDifference = 0\n输出:[0,0]\n解释:\n在示例中,可以选择 i = 0 和 j = 0 。\nabs(0 - 0) >= 0 且 abs(nums[0] - nums[0]) >= 0 。\n因此,[0,0] 是一个符合题目要求的答案。\n[0,1]、[1,0] 和 [1,1] 也是符合题目要求的答案。\n\n示例 3:\n\n输入:nums = [1,2,3], indexDifference = 2, valueDifference = 4\n输出:[-1,-1]\n解释:在示例中,可以证明无法找出 2 个满足所有条件的下标。\n因此,返回 [-1,-1] 。\n\n提示:\n\n * 1 <= n == nums.length <= 105\n * 0 <= nums[i] <= 109\n * 0 <= indexDifference <= 105\n * 0 <= valueDifference <= 109\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def findIndices(self, nums: List[int], indexDifference: int, valueDifference: int) -> List[int]:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [5,1,4,1], \"indexDifference\": 2, \"valueDifference\": 4 }\nassert my_solution.findIndices(**test_input) == [0,3]\n\ntest_input = { \"nums\": [2,1], \"indexDifference\": 0, \"valueDifference\": 0 }\nassert my_solution.findIndices(**test_input) == [0,0]\n\ntest_input = { \"nums\": [1,2,3], \"indexDifference\": 2, \"valueDifference\": 4 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [1], \"indexDifference\": 0, \"valueDifference\": 1 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [1], \"indexDifference\": 1, \"valueDifference\": 0 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [2], \"indexDifference\": 0, \"valueDifference\": 2 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [6], \"indexDifference\": 1, \"valueDifference\": 4 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [7], \"indexDifference\": 0, \"valueDifference\": 0 }\nassert my_solution.findIndices(**test_input) == [0,0]\n\ntest_input = { \"nums\": [8], \"indexDifference\": 1, \"valueDifference\": 6 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [9], \"indexDifference\": 0, \"valueDifference\": 1 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [9], \"indexDifference\": 1, \"valueDifference\": 9 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [12], \"indexDifference\": 0, \"valueDifference\": 5 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [16], \"indexDifference\": 0, \"valueDifference\": 16 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [16], \"indexDifference\": 1, \"valueDifference\": 6 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [46], \"indexDifference\": 0, \"valueDifference\": 36 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [0,10], \"indexDifference\": 2, \"valueDifference\": 4 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [2,7], \"indexDifference\": 2, \"valueDifference\": 7 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [5,1], \"indexDifference\": 2, \"valueDifference\": 5 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [5,12], \"indexDifference\": 0, \"valueDifference\": 10 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [8,0], \"indexDifference\": 1, \"valueDifference\": 7 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [8,4], \"indexDifference\": 1, \"valueDifference\": 4 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [9,8], \"indexDifference\": 0, \"valueDifference\": 6 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [15,8], \"indexDifference\": 0, \"valueDifference\": 6 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [20,21], \"indexDifference\": 1, \"valueDifference\": 14 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [23,47], \"indexDifference\": 2, \"valueDifference\": 47 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [32,14], \"indexDifference\": 1, \"valueDifference\": 6 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [36,14], \"indexDifference\": 2, \"valueDifference\": 11 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [40,12], \"indexDifference\": 1, \"valueDifference\": 20 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [45,41], \"indexDifference\": 2, \"valueDifference\": 21 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [50,24], \"indexDifference\": 1, \"valueDifference\": 18 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [2,7,0], \"indexDifference\": 0, \"valueDifference\": 4 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [3,9,3], \"indexDifference\": 0, \"valueDifference\": 3 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [3,12,40], \"indexDifference\": 0, \"valueDifference\": 9 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [4,10,8], \"indexDifference\": 0, \"valueDifference\": 3 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [5,27,26], \"indexDifference\": 1, \"valueDifference\": 15 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [7,8,10], \"indexDifference\": 2, \"valueDifference\": 5 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [8,2,6], \"indexDifference\": 1, \"valueDifference\": 8 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [8,7,5], \"indexDifference\": 2, \"valueDifference\": 3 }\nassert my_solution.findIndices(**test_input) == [0,2]\n\ntest_input = { \"nums\": [9,5,4], \"indexDifference\": 1, \"valueDifference\": 0 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [9,9,8], \"indexDifference\": 1, \"valueDifference\": 3 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [10,4,10], \"indexDifference\": 0, \"valueDifference\": 0 }\nassert my_solution.findIndices(**test_input) == [0,0]\n\ntest_input = { \"nums\": [10,5,2], \"indexDifference\": 2, \"valueDifference\": 5 }\nassert my_solution.findIndices(**test_input) == [0,2]\n\ntest_input = { \"nums\": [37,45,23], \"indexDifference\": 1, \"valueDifference\": 28 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [37,49,25], \"indexDifference\": 1, \"valueDifference\": 29 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [45,32,30], \"indexDifference\": 2, \"valueDifference\": 45 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [0,2,5,8], \"indexDifference\": 1, \"valueDifference\": 3 }\nassert my_solution.findIndices(**test_input) == [0,2]\n\ntest_input = { \"nums\": [0,4,7,2], \"indexDifference\": 2, \"valueDifference\": 7 }\nassert my_solution.findIndices(**test_input) == [0,2]\n\ntest_input = { \"nums\": [1,3,4,4], \"indexDifference\": 2, \"valueDifference\": 2 }\nassert my_solution.findIndices(**test_input) == [0,2]\n\ntest_input = { \"nums\": [1,8,6,10], \"indexDifference\": 2, \"valueDifference\": 5 }\nassert my_solution.findIndices(**test_input) == [0,2]\n\ntest_input = { \"nums\": [2,0,9,2], \"indexDifference\": 2, \"valueDifference\": 4 }\nassert my_solution.findIndices(**test_input) == [0,2]\n\ntest_input = { \"nums\": [7,4,8,3], \"indexDifference\": 3, \"valueDifference\": 7 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [9,4,0,9], \"indexDifference\": 2, \"valueDifference\": 1 }\nassert my_solution.findIndices(**test_input) == [0,2]\n\ntest_input = { \"nums\": [9,9,7,7], \"indexDifference\": 3, \"valueDifference\": 7 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [10,33,39,15], \"indexDifference\": 1, \"valueDifference\": 12 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [22,28,50,25], \"indexDifference\": 0, \"valueDifference\": 28 }\nassert my_solution.findIndices(**test_input) == [0,2]\n\ntest_input = { \"nums\": [36,35,45,34], \"indexDifference\": 1, \"valueDifference\": 31 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [50,21,32,5], \"indexDifference\": 0, \"valueDifference\": 26 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [0,6,2,10,4], \"indexDifference\": 3, \"valueDifference\": 5 }\nassert my_solution.findIndices(**test_input) == [0,3]\n\ntest_input = { \"nums\": [0,8,2,5,10], \"indexDifference\": 0, \"valueDifference\": 10 }\nassert my_solution.findIndices(**test_input) == [0,4]\n\ntest_input = { \"nums\": [0,9,0,5,9], \"indexDifference\": 3, \"valueDifference\": 5 }\nassert my_solution.findIndices(**test_input) == [0,3]\n\ntest_input = { \"nums\": [0,9,4,9,9], \"indexDifference\": 0, \"valueDifference\": 8 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [3,7,7,10,10], \"indexDifference\": 2, \"valueDifference\": 6 }\nassert my_solution.findIndices(**test_input) == [0,3]\n\ntest_input = { \"nums\": [4,0,1,5,0], \"indexDifference\": 0, \"valueDifference\": 3 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [4,1,7,0,3], \"indexDifference\": 1, \"valueDifference\": 0 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [6,0,6,7,9], \"indexDifference\": 0, \"valueDifference\": 0 }\nassert my_solution.findIndices(**test_input) == [0,0]\n\ntest_input = { \"nums\": [6,19,40,41,36], \"indexDifference\": 0, \"valueDifference\": 34 }\nassert my_solution.findIndices(**test_input) == [0,2]\n\ntest_input = { \"nums\": [7,10,4,5,1], \"indexDifference\": 2, \"valueDifference\": 6 }\nassert my_solution.findIndices(**test_input) == [1,4]\n\ntest_input = { \"nums\": [9,1,7,8,5], \"indexDifference\": 2, \"valueDifference\": 1 }\nassert my_solution.findIndices(**test_input) == [0,2]\n\ntest_input = { \"nums\": [10,39,25,12,7], \"indexDifference\": 1, \"valueDifference\": 35 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [15,28,50,37,43], \"indexDifference\": 2, \"valueDifference\": 46 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [0,6,6,0,0,6], \"indexDifference\": 2, \"valueDifference\": 3 }\nassert my_solution.findIndices(**test_input) == [0,2]\n\ntest_input = { \"nums\": [1,7,4,4,5,3], \"indexDifference\": 0, \"valueDifference\": 0 }\nassert my_solution.findIndices(**test_input) == [0,0]\n\ntest_input = { \"nums\": [3,3,1,6,3,3], \"indexDifference\": 3, \"valueDifference\": 6 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [3,3,4,1,3,7], \"indexDifference\": 3, \"valueDifference\": 7 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [4,3,8,6,2,8], \"indexDifference\": 2, \"valueDifference\": 3 }\nassert my_solution.findIndices(**test_input) == [0,2]\n\ntest_input = { \"nums\": [6,1,2,9,6,5], \"indexDifference\": 1, \"valueDifference\": 1 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [6,5,5,10,4,3], \"indexDifference\": 1, \"valueDifference\": 5 }\nassert my_solution.findIndices(**test_input) == [1,3]\n\ntest_input = { \"nums\": [6,7,0,2,2,6], \"indexDifference\": 1, \"valueDifference\": 0 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [7,6,3,5,9,5], \"indexDifference\": 2, \"valueDifference\": 6 }\nassert my_solution.findIndices(**test_input) == [2,4]\n\ntest_input = { \"nums\": [9,1,0,4,3,3], \"indexDifference\": 4, \"valueDifference\": 3 }\nassert my_solution.findIndices(**test_input) == [0,4]\n\ntest_input = { \"nums\": [9,8,8,0,1,4], \"indexDifference\": 3, \"valueDifference\": 9 }\nassert my_solution.findIndices(**test_input) == [0,3]\n\ntest_input = { \"nums\": [25,49,11,15,32,33], \"indexDifference\": 2, \"valueDifference\": 37 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [0,44,42,26,15,37,23], \"indexDifference\": 0, \"valueDifference\": 17 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [3,5,3,44,8,47,10], \"indexDifference\": 3, \"valueDifference\": 7 }\nassert my_solution.findIndices(**test_input) == [0,3]\n\ntest_input = { \"nums\": [3,8,8,0,2,0,10], \"indexDifference\": 4, \"valueDifference\": 2 }\nassert my_solution.findIndices(**test_input) == [0,5]\n\ntest_input = { \"nums\": [5,1,0,7,5,2,0], \"indexDifference\": 4, \"valueDifference\": 3 }\nassert my_solution.findIndices(**test_input) == [0,5]\n\ntest_input = { \"nums\": [9,10,1,3,1,5,0], \"indexDifference\": 2, \"valueDifference\": 2 }\nassert my_solution.findIndices(**test_input) == [0,2]\n\ntest_input = { \"nums\": [13,3,15,48,32,19,33], \"indexDifference\": 1, \"valueDifference\": 25 }\nassert my_solution.findIndices(**test_input) == [1,3]\n\ntest_input = { \"nums\": [29,12,42,16,50,22,10], \"indexDifference\": 2, \"valueDifference\": 29 }\nassert my_solution.findIndices(**test_input) == [1,4]\n\ntest_input = { \"nums\": [30,48,12,15,43,17,13], \"indexDifference\": 3, \"valueDifference\": 7 }\nassert my_solution.findIndices(**test_input) == [0,3]\n\ntest_input = { \"nums\": [31,33,46,4,13,45,37], \"indexDifference\": 0, \"valueDifference\": 7 }\nassert my_solution.findIndices(**test_input) == [0,2]\n\ntest_input = { \"nums\": [43,37,25,44,45,21,47], \"indexDifference\": 1, \"valueDifference\": 37 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [0,4,0,4,1,2,1,9], \"indexDifference\": 1, \"valueDifference\": 7 }\nassert my_solution.findIndices(**test_input) == [0,7]\n\ntest_input = { \"nums\": [0,7,3,2,6,1,7,4], \"indexDifference\": 4, \"valueDifference\": 3 }\nassert my_solution.findIndices(**test_input) == [0,4]\n\ntest_input = { \"nums\": [2,10,2,0,6,0,7,7], \"indexDifference\": 2, \"valueDifference\": 3 }\nassert my_solution.findIndices(**test_input) == [1,3]\n\ntest_input = { \"nums\": [3,9,6,10,10,3,2,9], \"indexDifference\": 5, \"valueDifference\": 10 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [4,4,3,0,6,1,7,8], \"indexDifference\": 3, \"valueDifference\": 6 }\nassert my_solution.findIndices(**test_input) == [3,6]\n\ntest_input = { \"nums\": [4,6,3,4,2,4,5,2], \"indexDifference\": 2, \"valueDifference\": 5 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [6,5,6,3,0,10,9,8], \"indexDifference\": 2, \"valueDifference\": 2 }\nassert my_solution.findIndices(**test_input) == [1,3]\n\ntest_input = { \"nums\": [7,4,3,1,6,6,2,6], \"indexDifference\": 3, \"valueDifference\": 7 }\nassert my_solution.findIndices(**test_input) == [-1,-1]", "start_time": 1697337000} +{"task_id": "weekly-contest-367-construct-product-matrix", "url": "https://leetcode.com/problems/construct-product-matrix", "title": "construct-product-matrix", "meta": {"questionId": "3031", "questionFrontendId": "2906", "title": "Construct Product Matrix", "titleSlug": "construct-product-matrix", "isPaidOnly": false, "difficulty": "Medium", "likes": 187, "dislikes": 11, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0 开始、大小为 n * m 的二维整数矩阵 grid ,定义一个下标从 0 开始、大小为 n * m 的的二维矩阵 p。如果满足以下条件,则称 p 为 grid 的 乘积矩阵 :\n\n * 对于每个元素 p[i][j] ,它的值等于除了 grid[i][j] 外所有元素的乘积。乘积对 12345 取余数。\n\n返回 grid 的乘积矩阵。\n\n示例 1:\n\n输入:grid = [[1,2],[3,4]]\n输出:[[24,12],[8,6]]\n解释:p[0][0] = grid[0][1] * grid[1][0] * grid[1][1] = 2 * 3 * 4 = 24\np[0][1] = grid[0][0] * grid[1][0] * grid[1][1] = 1 * 3 * 4 = 12\np[1][0] = grid[0][0] * grid[0][1] * grid[1][1] = 1 * 2 * 4 = 8\np[1][1] = grid[0][0] * grid[0][1] * grid[1][0] = 1 * 2 * 3 = 6\n所以答案是 [[24,12],[8,6]] 。\n\n示例 2:\n\n输入:grid = [[12345],[2],[1]]\n输出:[[2],[0],[0]]\n解释:p[0][0] = grid[0][1] * grid[0][2] = 2 * 1 = 2\np[0][1] = grid[0][0] * grid[0][2] = 12345 * 1 = 12345. 12345 % 12345 = 0 ,所以 p[0][1] = 0\np[0][2] = grid[0][0] * grid[0][1] = 12345 * 2 = 24690. 24690 % 12345 = 0 ,所以 p[0][2] = 0\n所以答案是 [[2],[0],[0]] 。\n\n提示:\n\n * 1 <= n == grid.length <= 105\n * 1 <= m == grid[i].length <= 105\n * 2 <= n * m <= 105\n * 1 <= grid[i][j] <= 109\n\"\"\"\nclass Solution:\n def constructProductMatrix(self, grid: List[List[int]]) -> List[List[int]]:\n ", "prompt_sft": "给你一个下标从 0 开始、大小为 n * m 的二维整数矩阵 grid ,定义一个下标从 0 开始、大小为 n * m 的的二维矩阵 p。如果满足以下条件,则称 p 为 grid 的 乘积矩阵 :\n\n * 对于每个元素 p[i][j] ,它的值等于除了 grid[i][j] 外所有元素的乘积。乘积对 12345 取余数。\n\n返回 grid 的乘积矩阵。\n\n示例 1:\n\n输入:grid = [[1,2],[3,4]]\n输出:[[24,12],[8,6]]\n解释:p[0][0] = grid[0][1] * grid[1][0] * grid[1][1] = 2 * 3 * 4 = 24\np[0][1] = grid[0][0] * grid[1][0] * grid[1][1] = 1 * 3 * 4 = 12\np[1][0] = grid[0][0] * grid[0][1] * grid[1][1] = 1 * 2 * 4 = 8\np[1][1] = grid[0][0] * grid[0][1] * grid[1][0] = 1 * 2 * 3 = 6\n所以答案是 [[24,12],[8,6]] 。\n\n示例 2:\n\n输入:grid = [[12345],[2],[1]]\n输出:[[2],[0],[0]]\n解释:p[0][0] = grid[0][1] * grid[0][2] = 2 * 1 = 2\np[0][1] = grid[0][0] * grid[0][2] = 12345 * 1 = 12345. 12345 % 12345 = 0 ,所以 p[0][1] = 0\np[0][2] = grid[0][0] * grid[0][1] = 12345 * 2 = 24690. 24690 % 12345 = 0 ,所以 p[0][2] = 0\n所以答案是 [[2],[0],[0]] 。\n\n提示:\n\n * 1 <= n == grid.length <= 105\n * 1 <= m == grid[i].length <= 105\n * 2 <= n * m <= 105\n * 1 <= grid[i][j] <= 109\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def constructProductMatrix(self, grid: List[List[int]]) -> List[List[int]]:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"grid\": [[1,2],[3,4]] }\nassert my_solution.constructProductMatrix(**test_input) == [[24,12],[8,6]]\n\ntest_input = { \"grid\": [[12345],[2],[1]] }\nassert my_solution.constructProductMatrix(**test_input) == [[2],[0],[0]]\n\ntest_input = { \"grid\": [[1],[2]] }\nassert my_solution.constructProductMatrix(**test_input) == [[2],[1]]\n\ntest_input = { \"grid\": [[1,2]] }\nassert my_solution.constructProductMatrix(**test_input) == [[2,1]]\n\ntest_input = { \"grid\": [[12345,12345]] }\nassert my_solution.constructProductMatrix(**test_input) == [[0,0]]\n\ntest_input = { \"grid\": [[1],[4]] }\nassert my_solution.constructProductMatrix(**test_input) == [[4],[1]]\n\ntest_input = { \"grid\": [[3],[4]] }\nassert my_solution.constructProductMatrix(**test_input) == [[4],[3]]\n\ntest_input = { \"grid\": [[4],[3]] }\nassert my_solution.constructProductMatrix(**test_input) == [[3],[4]]\n\ntest_input = { \"grid\": [[1,1,1]] }\nassert my_solution.constructProductMatrix(**test_input) == [[1,1,1]]\n\ntest_input = { \"grid\": [[2,1,1]] }\nassert my_solution.constructProductMatrix(**test_input) == [[1,2,2]]\n\ntest_input = { \"grid\": [[3],[5],[2]] }\nassert my_solution.constructProductMatrix(**test_input) == [[10],[6],[15]]\n\ntest_input = { \"grid\": [[1,2],[1,1],[6,4]] }\nassert my_solution.constructProductMatrix(**test_input) == [[48,24],[48,48],[8,12]]\n\ntest_input = { \"grid\": [[1,2,2],[1,4,3]] }\nassert my_solution.constructProductMatrix(**test_input) == [[48,24,24],[48,12,16]]\n\ntest_input = { \"grid\": [[2],[7],[2],[6]] }\nassert my_solution.constructProductMatrix(**test_input) == [[84],[24],[84],[28]]\n\ntest_input = { \"grid\": [[3],[4],[7],[7]] }\nassert my_solution.constructProductMatrix(**test_input) == [[196],[147],[84],[84]]\n\ntest_input = { \"grid\": [[3,1,1],[1,3,4]] }\nassert my_solution.constructProductMatrix(**test_input) == [[12,36,36],[36,12,9]]\n\ntest_input = { \"grid\": [[4],[8],[3],[7]] }\nassert my_solution.constructProductMatrix(**test_input) == [[168],[84],[224],[96]]\n\ntest_input = { \"grid\": [[5],[8],[8],[3]] }\nassert my_solution.constructProductMatrix(**test_input) == [[192],[120],[120],[320]]\n\ntest_input = { \"grid\": [[6],[5],[8],[5]] }\nassert my_solution.constructProductMatrix(**test_input) == [[200],[240],[150],[240]]\n\ntest_input = { \"grid\": [[8],[1],[3],[8]] }\nassert my_solution.constructProductMatrix(**test_input) == [[24],[192],[64],[24]]\n\ntest_input = { \"grid\": [[1],[10],[3],[10],[9]] }\nassert my_solution.constructProductMatrix(**test_input) == [[2700],[270],[900],[270],[300]]\n\ntest_input = { \"grid\": [[1,1,1,1,1]] }\nassert my_solution.constructProductMatrix(**test_input) == [[1,1,1,1,1]]\n\ntest_input = { \"grid\": [[1,1,2,2,1]] }\nassert my_solution.constructProductMatrix(**test_input) == [[4,4,2,2,4]]\n\ntest_input = { \"grid\": [[1,2,3],[3,3,5],[3,4,2]] }\nassert my_solution.constructProductMatrix(**test_input) == [[6480,3240,2160],[2160,2160,1296],[2160,1620,3240]]\n\ntest_input = { \"grid\": [[2],[7],[5],[3],[4]] }\nassert my_solution.constructProductMatrix(**test_input) == [[420],[120],[168],[280],[210]]\n\ntest_input = { \"grid\": [[2,2,2,2,1]] }\nassert my_solution.constructProductMatrix(**test_input) == [[8,8,8,8,16]]\n\ntest_input = { \"grid\": [[2,2,4,4],[3,2,1,4]] }\nassert my_solution.constructProductMatrix(**test_input) == [[768,768,384,384],[512,768,1536,384]]\n\ntest_input = { \"grid\": [[2,4,1,1],[3,4,4,1]] }\nassert my_solution.constructProductMatrix(**test_input) == [[192,96,384,384],[128,96,96,384]]\n\ntest_input = { \"grid\": [[3,1,1,4],[1,4,1,1]] }\nassert my_solution.constructProductMatrix(**test_input) == [[16,48,48,12],[48,12,48,48]]\n\ntest_input = { \"grid\": [[3,2,5],[6,4,3],[6,3,1]] }\nassert my_solution.constructProductMatrix(**test_input) == [[615,7095,7776],[6480,9720,615],[6480,615,1845]]\n\ntest_input = { \"grid\": [[5,5,5],[4,3,1],[4,5,1]] }\nassert my_solution.constructProductMatrix(**test_input) == [[6000,6000,6000],[7500,10000,5310],[7500,6000,5310]]\n\ntest_input = { \"grid\": [[6,3],[1,5],[2,7],[6,5]] }\nassert my_solution.constructProductMatrix(**test_input) == [[6300,255],[765,7560],[6555,5400],[6300,7560]]\n\ntest_input = { \"grid\": [[6,3,2],[2,3,1],[5,5,4]] }\nassert my_solution.constructProductMatrix(**test_input) == [[3600,7200,10800],[10800,7200,9255],[4320,4320,5400]]\n\ntest_input = { \"grid\": [[6,5,3],[4,4,5],[3,2,5]] }\nassert my_solution.constructProductMatrix(**test_input) == [[11310,6165,10275],[4620,4620,6165],[10275,9240,6165]]\n\ntest_input = { \"grid\": [[8],[5],[5],[9],[8]] }\nassert my_solution.constructProductMatrix(**test_input) == [[1800],[2880],[2880],[1600],[1800]]\n\ntest_input = { \"grid\": [[10],[5],[6],[8],[6]] }\nassert my_solution.constructProductMatrix(**test_input) == [[1440],[2880],[2400],[1800],[2400]]\n\ntest_input = { \"grid\": [[10],[9],[3],[4],[3]] }\nassert my_solution.constructProductMatrix(**test_input) == [[324],[360],[1080],[810],[1080]]\n\ntest_input = { \"grid\": [[1,1,1,2,2,1]] }\nassert my_solution.constructProductMatrix(**test_input) == [[4,4,4,2,2,4]]\n\ntest_input = { \"grid\": [[1,1,2,1,2,1]] }\nassert my_solution.constructProductMatrix(**test_input) == [[4,4,2,4,2,4]]\n\ntest_input = { \"grid\": [[1,1,2,1,2,2]] }\nassert my_solution.constructProductMatrix(**test_input) == [[8,8,4,8,4,4]]\n\ntest_input = { \"grid\": [[1,1,2,2,1,2]] }\nassert my_solution.constructProductMatrix(**test_input) == [[8,8,4,4,8,4]]\n\ntest_input = { \"grid\": [[1,1,2,2,2,2]] }\nassert my_solution.constructProductMatrix(**test_input) == [[16,16,8,8,8,8]]\n\ntest_input = { \"grid\": [[1,1,3,3],[3,4,4,2],[6,6,3,4]] }\nassert my_solution.constructProductMatrix(**test_input) == [[2898,2898,966,966],[966,6897,6897,1449],[483,483,966,6897]]\n\ntest_input = { \"grid\": [[1,2,1,1,1,2]] }\nassert my_solution.constructProductMatrix(**test_input) == [[4,2,4,4,4,2]]\n\ntest_input = { \"grid\": [[1,2,1,1,2,2]] }\nassert my_solution.constructProductMatrix(**test_input) == [[8,4,8,8,4,4]]\n\ntest_input = { \"grid\": [[1,2,2,4,3],[3,4,1,4,2]] }\nassert my_solution.constructProductMatrix(**test_input) == [[4608,2304,2304,1152,1536],[1536,1152,4608,1152,2304]]\n\ntest_input = { \"grid\": [[1,3,1,3,1],[2,1,3,2,3]] }\nassert my_solution.constructProductMatrix(**test_input) == [[324,108,324,108,324],[162,324,108,162,108]]\n\ntest_input = { \"grid\": [[1,3,3,3,4],[2,2,1,4,4]] }\nassert my_solution.constructProductMatrix(**test_input) == [[6912,2304,2304,2304,1728],[3456,3456,6912,1728,1728]]\n\ntest_input = { \"grid\": [[1,4,5],[1,3,2],[7,2,6],[6,2,2]] }\nassert my_solution.constructProductMatrix(**test_input) == [[7365,11100,11349],[7365,6570,9855],[9870,9855,3285],[3285,9855,9855]]\n\ntest_input = { \"grid\": [[1,6,6,4],[4,1,2,5],[5,4,6,2]] }\nassert my_solution.constructProductMatrix(**test_input) == [[12105,8190,8190,12285],[12285,12105,12225,4890],[4890,12285,8190,12225]]\n\ntest_input = { \"grid\": [[2,1,3,2,1],[3,1,3,1,2]] }\nassert my_solution.constructProductMatrix(**test_input) == [[108,216,72,108,216],[72,216,72,216,108]]\n\ntest_input = { \"grid\": [[2,2,2,1,1,1]] }\nassert my_solution.constructProductMatrix(**test_input) == [[4,4,4,8,8,8]]\n\ntest_input = { \"grid\": [[2,2,2,2,1,2]] }\nassert my_solution.constructProductMatrix(**test_input) == [[16,16,16,16,32,16]]\n\ntest_input = { \"grid\": [[2,2,3,2,3],[3,1,3,2,4]] }\nassert my_solution.constructProductMatrix(**test_input) == [[2592,2592,1728,2592,1728],[1728,5184,1728,2592,1296]]\n\ntest_input = { \"grid\": [[2,3,4],[2,4,2],[1,8,1],[8,8,8]] }\nassert my_solution.constructProductMatrix(**test_input) == [[8697,5798,10521],[8697,10521,8697],[5049,11433,5049],[11433,11433,11433]]\n\ntest_input = { \"grid\": [[2,4,4,5],[5,5,1,4],[4,2,2,5]] }\nassert my_solution.constructProductMatrix(**test_input) == [[10405,11375,11375,9100],[9100,9100,8465,11375],[11375,10405,10405,9100]]\n\ntest_input = { \"grid\": [[3,4,1,1],[3,1,4,4],[1,5,1,5]] }\nassert my_solution.constructProductMatrix(**test_input) == [[4800,3600,2055,2055],[4800,2055,3600,3600],[2055,2880,2055,2880]]\n\ntest_input = { \"grid\": [[3,4,6,3],[4,5,4,4],[5,2,6,3]] }\nassert my_solution.constructProductMatrix(**test_input) == [[11625,11805,11985,11625],[11805,6975,11805,11805],[6975,11265,11985,11625]]\n\ntest_input = { \"grid\": [[4,1,4,4,4],[2,2,2,3,3]] }\nassert my_solution.constructProductMatrix(**test_input) == [[4608,6087,4608,4608,4608],[9216,9216,9216,6144,6144]]\n\ntest_input = { \"grid\": [[4,8,8],[6,2,5],[7,3,7],[6,3,5]] }\nassert my_solution.constructProductMatrix(**test_input) == [[3525,7935,7935],[6465,7050,2820],[7305,585,7305],[6465,585,2820]]\n\ntest_input = { \"grid\": [[6],[8],[2],[12],[6],[4]] }\nassert my_solution.constructProductMatrix(**test_input) == [[4608],[3456],[1479],[2304],[4608],[6912]]\n\ntest_input = { \"grid\": [[6,2,5,2],[5,5,2,3],[4,6,5,2]] }\nassert my_solution.constructProductMatrix(**test_input) == [[3990,11970,12195,11970],[12195,12195,11970,7980],[5985,3990,12195,11970]]\n\ntest_input = { \"grid\": [[6,3,4,3],[6,4,2,5],[3,3,6,1]] }\nassert my_solution.constructProductMatrix(**test_input) == [[9795,7245,8520,7245],[9795,8520,4695,4347],[7245,7245,9795,9390]]\n\ntest_input = { \"grid\": [[6,5,6,6],[3,2,6,4],[1,3,4,1]] }\nassert my_solution.constructProductMatrix(**test_input) == [[2415,2898,2415,2415],[4830,7245,2415,9795],[2145,4830,9795,2145]]\n\ntest_input = { \"grid\": [[7],[11],[12],[7],[12],[7]] }\nassert my_solution.constructProductMatrix(**test_input) == [[3546],[12],[8241],[3546],[8241],[3546]]\n\ntest_input = { \"grid\": [[7,4,5],[2,1,2],[5,3,8],[3,6,7]] }\nassert my_solution.constructProductMatrix(**test_input) == [[12135,5805,2175],[11610,10875,11610],[2175,7740,9075],[7740,3870,12135]]\n\ntest_input = { \"grid\": [[8],[6],[7],[2],[7],[4]] }\nassert my_solution.constructProductMatrix(**test_input) == [[2352],[3136],[2688],[9408],[2688],[4704]]\n\ntest_input = { \"grid\": [[8],[6],[7],[5],[3],[6]] }\nassert my_solution.constructProductMatrix(**test_input) == [[3780],[5040],[4320],[6048],[10080],[5040]]\n\ntest_input = { \"grid\": [[8,1],[9,6],[2,4],[1,3],[3,6]] }\nassert my_solution.constructProductMatrix(**test_input) == [[10983,1449],[8391,6414],[6897,9621],[1449,483],[483,6414]]\n\ntest_input = { \"grid\": [[8,4,3],[7,7,4],[1,2,3],[5,2,4]] }\nassert my_solution.constructProductMatrix(**test_input) == [[8955,5565,11535],[3180,3180,5565],[9915,11130,11535],[1983,11130,5565]]\n\ntest_input = { \"grid\": [[12],[8],[4],[3],[9],[5]] }\nassert my_solution.constructProductMatrix(**test_input) == [[4320],[6480],[615],[4935],[5760],[10368]]\n\ntest_input = { \"grid\": [[1,1,1,1,2,2,2]] }\nassert my_solution.constructProductMatrix(**test_input) == [[8,8,8,8,4,4,4]]\n\ntest_input = { \"grid\": [[1,1,1,2,1,1,1]] }\nassert my_solution.constructProductMatrix(**test_input) == [[2,2,2,1,2,2,2]]\n\ntest_input = { \"grid\": [[1,1,2,1,2,1,2]] }\nassert my_solution.constructProductMatrix(**test_input) == [[8,8,4,8,4,8,4]]\n\ntest_input = { \"grid\": [[1,1,6,5,6],[1,6,6,2,5],[3,4,1,1,4]] }\nassert my_solution.constructProductMatrix(**test_input) == [[11805,11805,12255,4830,12255],[11805,12255,12255,12075,4830],[12165,12210,11805,11805,12210]]\n\ntest_input = { \"grid\": [[1,2,1,1,1,2,2]] }\nassert my_solution.constructProductMatrix(**test_input) == [[8,4,8,8,8,4,4]]\n\ntest_input = { \"grid\": [[1,2,1,2,2,1,1]] }\nassert my_solution.constructProductMatrix(**test_input) == [[8,4,8,4,4,8,8]]\n\ntest_input = { \"grid\": [[1,3,1,2,1,2],[3,2,3,4,2,3]] }\nassert my_solution.constructProductMatrix(**test_input) == [[5184,1728,5184,2592,5184,2592],[1728,2592,1728,1296,2592,1728]]\n\ntest_input = { \"grid\": [[1,3,5,2],[1,3,6,5],[8,1,2,7],[6,2,3,5]] }\nassert my_solution.constructProductMatrix(**test_input) == [[2895,9195,10455,7620],[2895,9195,10770,10455],[1905,2895,7620,10995],[10770,7620,9195,10455]]\n\ntest_input = { \"grid\": [[1,4,4,4,3,3],[1,1,3,4,4,1]] }\nassert my_solution.constructProductMatrix(**test_input) == [[2958,6912,6912,6912,9216,9216],[2958,2958,9216,6912,6912,2958]]\n\ntest_input = { \"grid\": [[1,5,5,6],[4,7,6,1],[2,3,3,6],[3,6,3,7]] }\nassert my_solution.constructProductMatrix(**test_input) == [[6570,11190,11190,1095],[7815,11520,1095,6570],[3285,2190,2190,1095],[2190,1095,2190,11520]]\n\ntest_input = { \"grid\": [[1,6,4,4,1],[6,2,5,1,4],[6,4,3,5,6]] }\nassert my_solution.constructProductMatrix(**test_input) == [[3705,10905,10185,10185,3705],[10905,8025,3210,3705,10185],[10905,10185,9465,3210,10905]]\n\ntest_input = { \"grid\": [[1,7,2,8],[3,7,2,5],[2,3,5,6],[5,4,2,7]] }\nassert my_solution.constructProductMatrix(**test_input) == [[4065,7635,8205,11310],[9585,7635,8205,8220],[8205,9585,8220,10965],[8220,10275,8205,7635]]\n\ntest_input = { \"grid\": [[2,1,1,1,1,2,2]] }\nassert my_solution.constructProductMatrix(**test_input) == [[4,8,8,8,8,4,4]]\n\ntest_input = { \"grid\": [[2,1,1,1,2,2,1]] }\nassert my_solution.constructProductMatrix(**test_input) == [[4,8,8,8,4,4,8]]\n\ntest_input = { \"grid\": [[2,1,2,2,2,2,2]] }\nassert my_solution.constructProductMatrix(**test_input) == [[32,64,32,32,32,32,32]]\n\ntest_input = { \"grid\": [[2,1,3,2,4,4],[1,3,2,2,4,1]] }\nassert my_solution.constructProductMatrix(**test_input) == [[4608,9216,3072,4608,2304,2304],[9216,3072,4608,4608,2304,9216]]\n\ntest_input = { \"grid\": [[2,2,2,2,1,2,1]] }\nassert my_solution.constructProductMatrix(**test_input) == [[16,16,16,16,32,16,32]]\n\ntest_input = { \"grid\": [[2,4,3,3,3,4],[3,1,4,3,4,2]] }\nassert my_solution.constructProductMatrix(**test_input) == [[966,483,8874,8874,8874,483],[8874,1932,483,8874,483,966]]\n\ntest_input = { \"grid\": [[2,5,4,8],[4,6,3,3],[1,5,1,4],[8,6,6,5]] }\nassert my_solution.constructProductMatrix(**test_input) == [[30,4950,15,6180],[15,4125,8250,8250],[60,4950,60,15],[6180,4125,4125,4950]]\n\ntest_input = { \"grid\": [[2,7],[10,12],[2,4],[8,11],[2,12],[11,2]] }\nassert my_solution.constructProductMatrix(**test_input) == [[8340,5910],[6606,5505],[8340,4170],[2085,8250],[8340,5505],[8250,8340]]\n\ntest_input = { \"grid\": [[2,9],[1,4],[10,12],[2,7],[4,10],[10,8]] }\nassert my_solution.constructProductMatrix(**test_input) == [[3435,10365],[6870,7890],[5625,10860],[3435,2745],[7890,5625],[5625,3945]]\n\ntest_input = { \"grid\": [[3],[9],[5],[1],[4],[14],[12]] }\nassert my_solution.constructProductMatrix(**test_input) == [[5550],[10080],[5799],[4305],[10335],[6480],[7560]]\n\ntest_input = { \"grid\": [[3,2,2,2,4,3],[4,1,3,1,1,2]] }\nassert my_solution.constructProductMatrix(**test_input) == [[2304,3456,3456,3456,1728,2304],[1728,6912,2304,6912,6912,3456]]\n\ntest_input = { \"grid\": [[3,2,4,2,2,3],[2,2,4,1,2,3]] }\nassert my_solution.constructProductMatrix(**test_input) == [[9216,1479,6912,1479,1479,9216],[1479,1479,6912,2958,1479,9216]]\n\ntest_input = { \"grid\": [[3,6,2,2,5],[1,4,3,4,1],[4,5,2,4,4]] }\nassert my_solution.constructProductMatrix(**test_input) == [[7590,3795,11385,11385,2085],[10425,11865,7590,11865,10425],[11865,2085,11385,11865,11865]]\n\ntest_input = { \"grid\": [[4,1,5,4,5],[6,5,3,4,4],[3,2,6,2,3]] }\nassert my_solution.constructProductMatrix(**test_input) == [[6945,3090,8025,6945,8025],[8745,8025,5145,6945,6945],[5145,1545,8745,1545,5145]]\n\ntest_input = { \"grid\": [[4,3,9],[3,9,10],[9,7,8],[8,4,7],[6,1,3]] }\nassert my_solution.constructProductMatrix(**test_input) == [[3255,225,75],[225,75,11178],[75,1860,7800],[7800,3255,1860],[6285,675,225]]\n\ntest_input = { \"grid\": [[5,1,1,1,5],[3,4,2,6,6],[3,3,2,5,1]] }\nassert my_solution.constructProductMatrix(**test_input) == [[6105,5835,5835,5835,6105],[6060,4545,9090,3030,3030],[6060,6060,9090,6105,5835]]\n\ntest_input = { \"grid\": [[5,3],[9,2],[2,6],[4,9],[12,2],[10,4]] }\nassert my_solution.constructProductMatrix(**test_input) == [[1050,5865],[10185,2625],[2625,9105],[7485,10185],[10725,2625],[525,7485]]", "start_time": 1697337000} +{"task_id": "biweekly-contest-115-last-visited-integers", "url": "https://leetcode.com/problems/last-visited-integers", "title": "last-visited-integers", "meta": {"questionId": "3164", "questionFrontendId": "2899", "title": "Last Visited Integers", "titleSlug": "last-visited-integers", "isPaidOnly": false, "difficulty": "Easy", "likes": 74, "dislikes": 139, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0 开始的字符串数组 words ,其中 words[i] 要么是一个字符串形式的正整数,要么是字符串 \"prev\" 。\n\n我们从数组的开头开始遍历,对于 words 中的每个 \"prev\" 字符串,找到 words 中的 上一个遍历的整数 ,定义如下:\n\n * k 表示到当前位置为止的连续 \"prev\" 字符串数目(包含当前字符串),令下标从 0 开始的 整数 数组 nums 表示目前为止遍历过的所有整数,同时用 nums_reverse 表示 nums 反转得到的数组,那么当前 \"prev\" 对应的 上一个遍历的整数 是 nums_reverse 数组中下标为 (k - 1) 的整数。\n * 如果 k 比目前为止遍历过的整数数目 更多 ,那么上一个遍历的整数为 -1 。\n\n请你返回一个整数数组,包含所有上一个遍历的整数。\n\n示例 1:\n\n输入:words = [\"1\",\"2\",\"prev\",\"prev\",\"prev\"]\n输出:[2,1,-1]\n解释:\n对于下标为 2 处的 \"prev\" ,上一个遍历的整数是 2 ,因为连续 \"prev\" 数目为 1 ,同时在数组 reverse_nums 中,第一个元素是 2 。\n对于下标为 3 处的 \"prev\" ,上一个遍历的整数是 1 ,因为连续 \"prev\" 数目为 2 ,同时在数组 reverse_nums 中,第二个元素是 1 。\n对于下标为 4 处的 \"prev\" ,上一个遍历的整数是 -1 ,因为连续 \"prev\" 数目为 3 ,但总共只遍历过 2 个整数。\n\n示例 2:\n\n输入:words = [\"1\",\"prev\",\"2\",\"prev\",\"prev\"]\n输出:[1,2,1]\n解释:\n对于下标为 1 处的 \"prev\" ,上一个遍历的整数是 1 。\n对于下标为 3 处的 \"prev\" ,上一个遍历的整数是 2 。\n对于下标为 4 处的 \"prev\" ,上一个遍历的整数是 1 ,因为连续 \"prev\" 数目为 2 ,同时在数组 reverse_nums 中,第二个元素是 1 。\n\n\n提示:\n\n * 1 <= words.length <= 100\n * words[i] == \"prev\" 或 1 <= int(words[i]) <= 100\n\"\"\"\nclass Solution:\n def lastVisitedIntegers(self, words: List[str]) -> List[int]:\n ", "prompt_sft": "给你一个下标从 0 开始的字符串数组 words ,其中 words[i] 要么是一个字符串形式的正整数,要么是字符串 \"prev\" 。\n\n我们从数组的开头开始遍历,对于 words 中的每个 \"prev\" 字符串,找到 words 中的 上一个遍历的整数 ,定义如下:\n\n * k 表示到当前位置为止的连续 \"prev\" 字符串数目(包含当前字符串),令下标从 0 开始的 整数 数组 nums 表示目前为止遍历过的所有整数,同时用 nums_reverse 表示 nums 反转得到的数组,那么当前 \"prev\" 对应的 上一个遍历的整数 是 nums_reverse 数组中下标为 (k - 1) 的整数。\n * 如果 k 比目前为止遍历过的整数数目 更多 ,那么上一个遍历的整数为 -1 。\n\n请你返回一个整数数组,包含所有上一个遍历的整数。\n\n示例 1:\n\n输入:words = [\"1\",\"2\",\"prev\",\"prev\",\"prev\"]\n输出:[2,1,-1]\n解释:\n对于下标为 2 处的 \"prev\" ,上一个遍历的整数是 2 ,因为连续 \"prev\" 数目为 1 ,同时在数组 reverse_nums 中,第一个元素是 2 。\n对于下标为 3 处的 \"prev\" ,上一个遍历的整数是 1 ,因为连续 \"prev\" 数目为 2 ,同时在数组 reverse_nums 中,第二个元素是 1 。\n对于下标为 4 处的 \"prev\" ,上一个遍历的整数是 -1 ,因为连续 \"prev\" 数目为 3 ,但总共只遍历过 2 个整数。\n\n示例 2:\n\n输入:words = [\"1\",\"prev\",\"2\",\"prev\",\"prev\"]\n输出:[1,2,1]\n解释:\n对于下标为 1 处的 \"prev\" ,上一个遍历的整数是 1 。\n对于下标为 3 处的 \"prev\" ,上一个遍历的整数是 2 。\n对于下标为 4 处的 \"prev\" ,上一个遍历的整数是 1 ,因为连续 \"prev\" 数目为 2 ,同时在数组 reverse_nums 中,第二个元素是 1 。\n\n\n提示:\n\n * 1 <= words.length <= 100\n * words[i] == \"prev\" 或 1 <= int(words[i]) <= 100\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def lastVisitedIntegers(self, words: List[str]) -> List[int]:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"words\": [\"1\",\"2\",\"prev\",\"prev\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [2,1,-1]\n\ntest_input = { \"words\": [\"1\",\"prev\",\"2\",\"prev\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [1,2,1]\n\ntest_input = { \"words\": [\"prev\",\"prev\",\"prev\",\"27\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,-1,-1]\n\ntest_input = { \"words\": [\"17\",\"42\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == []\n\ntest_input = { \"words\": [\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1]\n\ntest_input = { \"words\": [\"prev\",\"prev\",\"prev\",\"52\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,-1,-1,52]\n\ntest_input = { \"words\": [\"prev\",\"prev\",\"68\",\"prev\",\"prev\",\"53\",\"40\",\"23\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,-1,68,-1,23]\n\ntest_input = { \"words\": [\"99\",\"23\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [23]\n\ntest_input = { \"words\": [\"prev\",\"prev\",\"prev\",\"58\",\"99\",\"prev\",\"10\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,-1,-1,99,10]\n\ntest_input = { \"words\": [\"prev\",\"51\",\"prev\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,51,-1]\n\ntest_input = { \"words\": [\"prev\",\"46\",\"9\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,9]\n\ntest_input = { \"words\": [\"prev\",\"prev\",\"prev\",\"prev\",\"prev\",\"26\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,-1,-1,-1,-1]\n\ntest_input = { \"words\": [\"prev\",\"21\",\"prev\",\"76\",\"82\",\"prev\",\"96\",\"prev\",\"57\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,21,82,96,57]\n\ntest_input = { \"words\": [\"52\",\"4\",\"prev\",\"prev\",\"prev\",\"69\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [4,52,-1]\n\ntest_input = { \"words\": [\"24\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [24]\n\ntest_input = { \"words\": [\"46\",\"prev\",\"78\",\"prev\",\"83\",\"21\",\"prev\",\"94\",\"50\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [46,78,21]\n\ntest_input = { \"words\": [\"14\",\"66\",\"prev\",\"prev\",\"46\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [66,14,46]\n\ntest_input = { \"words\": [\"35\",\"90\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == []\n\ntest_input = { \"words\": [\"prev\",\"9\",\"prev\",\"8\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,9,8]\n\ntest_input = { \"words\": [\"prev\",\"prev\",\"88\",\"71\",\"47\",\"65\",\"24\",\"39\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,-1]\n\ntest_input = { \"words\": [\"45\",\"73\",\"78\",\"2\",\"54\",\"prev\",\"85\",\"62\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [54,62]\n\ntest_input = { \"words\": [\"prev\",\"prev\",\"80\",\"9\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,-1,9]\n\ntest_input = { \"words\": [\"79\",\"19\",\"prev\",\"prev\",\"prev\",\"67\",\"prev\",\"16\",\"2\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [19,79,-1,67]\n\ntest_input = { \"words\": [\"94\",\"prev\",\"prev\",\"prev\",\"prev\",\"prev\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [94,-1,-1,-1,-1,-1]\n\ntest_input = { \"words\": [\"prev\",\"prev\",\"prev\",\"82\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,-1,-1,82]\n\ntest_input = { \"words\": [\"94\",\"14\",\"81\",\"43\",\"prev\",\"43\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [43,43]\n\ntest_input = { \"words\": [\"prev\",\"prev\",\"94\",\"56\",\"prev\",\"32\",\"prev\",\"prev\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,-1,56,32,56,94]\n\ntest_input = { \"words\": [\"93\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == []\n\ntest_input = { \"words\": [\"46\",\"91\",\"3\",\"40\",\"31\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [31]\n\ntest_input = { \"words\": [\"41\",\"prev\",\"17\",\"58\",\"78\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [41]\n\ntest_input = { \"words\": [\"prev\",\"prev\",\"82\",\"41\",\"96\",\"89\",\"71\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,-1]\n\ntest_input = { \"words\": [\"4\",\"prev\",\"50\",\"prev\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [4,50,4]\n\ntest_input = { \"words\": [\"59\",\"76\",\"prev\",\"29\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [76,29]\n\ntest_input = { \"words\": [\"prev\",\"62\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1]\n\ntest_input = { \"words\": [\"6\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [6]\n\ntest_input = { \"words\": [\"prev\",\"prev\",\"prev\",\"prev\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,-1,-1,-1,-1]\n\ntest_input = { \"words\": [\"28\",\"5\",\"35\",\"prev\",\"41\",\"27\",\"70\",\"65\",\"84\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [35]\n\ntest_input = { \"words\": [\"94\",\"45\",\"prev\",\"61\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [45]\n\ntest_input = { \"words\": [\"prev\",\"34\",\"prev\",\"prev\",\"prev\",\"prev\",\"21\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,34,-1,-1,-1,21]\n\ntest_input = { \"words\": [\"prev\",\"12\",\"100\",\"33\",\"prev\",\"85\",\"93\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,33]\n\ntest_input = { \"words\": [\"26\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == []\n\ntest_input = { \"words\": [\"27\",\"prev\",\"prev\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [27,-1,-1]\n\ntest_input = { \"words\": [\"prev\",\"prev\",\"22\",\"33\",\"prev\",\"prev\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,-1,33,22,-1]\n\ntest_input = { \"words\": [\"30\",\"prev\",\"87\",\"prev\",\"19\",\"prev\",\"8\",\"prev\",\"81\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [30,87,19,8]\n\ntest_input = { \"words\": [\"35\",\"prev\",\"47\",\"82\",\"86\",\"84\",\"prev\",\"76\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [35,84,76]\n\ntest_input = { \"words\": [\"prev\",\"87\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1]\n\ntest_input = { \"words\": [\"prev\",\"69\",\"78\",\"prev\",\"prev\",\"16\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,78,69]\n\ntest_input = { \"words\": [\"22\",\"97\",\"prev\",\"2\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [97]\n\ntest_input = { \"words\": [\"72\",\"74\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == []\n\ntest_input = { \"words\": [\"84\",\"prev\",\"prev\",\"21\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [84,-1]\n\ntest_input = { \"words\": [\"64\",\"24\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == []\n\ntest_input = { \"words\": [\"17\",\"prev\",\"59\",\"prev\",\"51\",\"11\",\"prev\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [17,59,11,51]\n\ntest_input = { \"words\": [\"57\",\"prev\",\"27\",\"30\",\"prev\",\"prev\",\"75\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [57,30,27]\n\ntest_input = { \"words\": [\"65\",\"prev\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [65,-1]\n\ntest_input = { \"words\": [\"prev\",\"53\",\"76\",\"54\",\"94\",\"77\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1]\n\ntest_input = { \"words\": [\"89\",\"51\",\"prev\",\"prev\",\"12\",\"prev\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [51,89,12,51]\n\ntest_input = { \"words\": [\"prev\",\"28\",\"25\",\"prev\",\"prev\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,25,28,-1]\n\ntest_input = { \"words\": [\"51\",\"prev\",\"prev\",\"76\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [51,-1]\n\ntest_input = { \"words\": [\"2\",\"24\",\"63\",\"prev\",\"43\",\"19\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [63,19]\n\ntest_input = { \"words\": [\"prev\",\"38\",\"1\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1]\n\ntest_input = { \"words\": [\"56\",\"75\",\"prev\",\"prev\",\"94\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [75,56]\n\ntest_input = { \"words\": [\"prev\",\"prev\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,-1,-1]\n\ntest_input = { \"words\": [\"prev\",\"37\",\"25\",\"31\",\"prev\",\"prev\",\"42\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,31,25]\n\ntest_input = { \"words\": [\"73\",\"30\",\"prev\",\"20\",\"prev\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [30,20,30]\n\ntest_input = { \"words\": [\"85\",\"prev\",\"prev\",\"78\",\"prev\",\"100\",\"8\",\"17\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [85,-1,78,17]\n\ntest_input = { \"words\": [\"prev\",\"55\",\"prev\",\"87\",\"19\",\"prev\",\"13\",\"prev\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,55,19,13,19]\n\ntest_input = { \"words\": [\"prev\",\"prev\",\"5\",\"prev\",\"prev\",\"prev\",\"80\",\"17\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,-1,5,-1,-1]\n\ntest_input = { \"words\": [\"100\",\"3\",\"prev\",\"prev\",\"93\",\"35\",\"prev\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [3,100,35,93]\n\ntest_input = { \"words\": [\"75\",\"7\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == []\n\ntest_input = { \"words\": [\"prev\",\"prev\",\"prev\",\"prev\",\"prev\",\"prev\",\"71\",\"prev\",\"27\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,-1,-1,-1,-1,-1,71]\n\ntest_input = { \"words\": [\"prev\",\"prev\",\"prev\",\"91\",\"44\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,-1,-1,44]\n\ntest_input = { \"words\": [\"prev\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,-1]\n\ntest_input = { \"words\": [\"11\",\"prev\",\"87\",\"prev\",\"prev\",\"94\",\"prev\",\"68\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [11,87,11,94]\n\ntest_input = { \"words\": [\"78\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == []\n\ntest_input = { \"words\": [\"prev\",\"prev\",\"73\",\"prev\",\"prev\",\"27\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,-1,73,-1,27]\n\ntest_input = { \"words\": [\"prev\",\"70\",\"prev\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,70,-1]\n\ntest_input = { \"words\": [\"68\",\"prev\",\"38\",\"prev\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [68,38,68]\n\ntest_input = { \"words\": [\"prev\",\"prev\",\"36\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,-1]\n\ntest_input = { \"words\": [\"prev\",\"prev\",\"36\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,-1,36]\n\ntest_input = { \"words\": [\"18\",\"58\",\"41\",\"prev\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [41,58]\n\ntest_input = { \"words\": [\"prev\",\"prev\",\"35\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,-1]\n\ntest_input = { \"words\": [\"prev\",\"72\",\"prev\",\"96\",\"9\",\"50\",\"prev\",\"52\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,72,50]\n\ntest_input = { \"words\": [\"92\",\"95\",\"47\",\"48\",\"prev\",\"50\",\"34\",\"prev\",\"prev\",\"46\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [48,34,50]\n\ntest_input = { \"words\": [\"36\",\"88\",\"15\",\"99\",\"48\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == []\n\ntest_input = { \"words\": [\"93\",\"prev\",\"2\",\"58\",\"83\",\"90\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [93,90]\n\ntest_input = { \"words\": [\"prev\",\"68\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,68]\n\ntest_input = { \"words\": [\"prev\",\"56\",\"prev\",\"prev\",\"36\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,56,-1,36]\n\ntest_input = { \"words\": [\"53\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [53]\n\ntest_input = { \"words\": [\"5\",\"29\",\"94\",\"3\",\"48\",\"prev\",\"59\",\"90\",\"prev\",\"69\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [48,90]\n\ntest_input = { \"words\": [\"89\",\"prev\",\"prev\",\"75\",\"prev\",\"98\",\"80\",\"prev\",\"68\",\"33\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [89,-1,75,80]\n\ntest_input = { \"words\": [\"prev\",\"93\",\"prev\",\"74\",\"33\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,93]\n\ntest_input = { \"words\": [\"prev\",\"prev\",\"10\",\"25\",\"prev\",\"54\",\"prev\",\"prev\",\"prev\",\"76\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,-1,25,54,25,10]\n\ntest_input = { \"words\": [\"9\",\"prev\",\"14\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [9,14]\n\ntest_input = { \"words\": [\"prev\",\"prev\",\"prev\",\"18\",\"66\",\"92\",\"prev\",\"87\",\"85\",\"25\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,-1,-1,92]\n\ntest_input = { \"words\": [\"prev\",\"prev\",\"prev\",\"16\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,-1,-1,16]\n\ntest_input = { \"words\": [\"prev\",\"prev\",\"99\",\"prev\",\"82\",\"prev\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,-1,99,82,99]\n\ntest_input = { \"words\": [\"prev\",\"5\",\"90\",\"71\",\"prev\",\"prev\",\"61\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,71,90]\n\ntest_input = { \"words\": [\"prev\",\"prev\",\"71\",\"54\",\"prev\",\"20\",\"65\",\"prev\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,-1,54,65,20]\n\ntest_input = { \"words\": [\"prev\",\"85\",\"prev\",\"93\",\"prev\",\"98\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,85,93,98]\n\ntest_input = { \"words\": [\"prev\",\"prev\",\"34\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,-1,34]", "start_time": 1697293800} +{"task_id": "biweekly-contest-115-longest-unequal-adjacent-groups-subsequence-i", "url": "https://leetcode.com/problems/longest-unequal-adjacent-groups-subsequence-i", "title": "longest-unequal-adjacent-groups-subsequence-i", "meta": {"questionId": "3143", "questionFrontendId": "2900", "title": "Longest Unequal Adjacent Groups Subsequence I", "titleSlug": "longest-unequal-adjacent-groups-subsequence-i", "isPaidOnly": false, "difficulty": "Medium", "likes": 86, "dislikes": 26, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个整数 n 和一个下标从 0 开始的字符串数组 words ,和一个下标从 0 开始的 二进制 数组 groups ,两个数组长度都是 n 。\n\n你需要从下标 [0, 1, ..., n - 1] 中选出一个 最长子序列 ,将这个子序列记作长度为 k 的 [i0, i1, ..., ik - 1] ,对于所有满足 0 < j + 1 < k 的 j 都有 groups[ij] != groups[ij + 1] 。\n\n请你返回一个字符串数组,它是下标子序列 依次 对应 words 数组中的字符串连接形成的字符串数组。如果有多个答案,返回任意一个。\n\n子序列 指的是从原数组中删掉一些(也可能一个也不删掉)元素,剩余元素不改变相对位置得到的新的数组。\n\n注意:words 中的字符串长度可能 不相等 。\n\n示例 1:\n\n输入:n = 3, words = [\"e\",\"a\",\"b\"], groups = [0,0,1]\n输出:[\"e\",\"b\"]\n解释:一个可行的子序列是 [0,2] ,因为 groups[0] != groups[2] 。\n所以一个可行的答案是 [words[0],words[2]] = [\"e\",\"b\"] 。\n另一个可行的子序列是 [1,2] ,因为 groups[1] != groups[2] 。\n得到答案为 [words[1],words[2]] = [\"a\",\"b\"] 。\n这也是一个可行的答案。\n符合题意的最长子序列的长度为 2 。\n\n示例 2:\n\n输入:n = 4, words = [\"a\",\"b\",\"c\",\"d\"], groups = [1,0,1,1]\n输出:[\"a\",\"b\",\"c\"]\n解释:一个可行的子序列为 [0,1,2] 因为 groups[0] != groups[1] 且 groups[1] != groups[2] 。\n所以一个可行的答案是 [words[0],words[1],words[2]] = [\"a\",\"b\",\"c\"] 。\n另一个可行的子序列为 [0,1,3] 因为 groups[0] != groups[1] 且 groups[1] != groups[3] 。\n得到答案为 [words[0],words[1],words[3]] = [\"a\",\"b\",\"d\"] 。\n这也是一个可行的答案。\n符合题意的最长子序列的长度为 3 。\n\n提示:\n\n * 1 <= n == words.length == groups.length <= 100\n * 1 <= words[i].length <= 10\n * 0 <= groups[i] < 2\n * words 中的字符串 互不相同 。\n * words[i] 只包含小写英文字母。\n\"\"\"\nclass Solution:\n def getWordsInLongestSubsequence(self, n: int, words: List[str], groups: List[int]) -> List[str]:\n ", "prompt_sft": "给你一个整数 n 和一个下标从 0 开始的字符串数组 words ,和一个下标从 0 开始的 二进制 数组 groups ,两个数组长度都是 n 。\n\n你需要从下标 [0, 1, ..., n - 1] 中选出一个 最长子序列 ,将这个子序列记作长度为 k 的 [i0, i1, ..., ik - 1] ,对于所有满足 0 < j + 1 < k 的 j 都有 groups[ij] != groups[ij + 1] 。\n\n请你返回一个字符串数组,它是下标子序列 依次 对应 words 数组中的字符串连接形成的字符串数组。如果有多个答案,返回任意一个。\n\n子序列 指的是从原数组中删掉一些(也可能一个也不删掉)元素,剩余元素不改变相对位置得到的新的数组。\n\n注意:words 中的字符串长度可能 不相等 。\n\n示例 1:\n\n输入:n = 3, words = [\"e\",\"a\",\"b\"], groups = [0,0,1]\n输出:[\"e\",\"b\"]\n解释:一个可行的子序列是 [0,2] ,因为 groups[0] != groups[2] 。\n所以一个可行的答案是 [words[0],words[2]] = [\"e\",\"b\"] 。\n另一个可行的子序列是 [1,2] ,因为 groups[1] != groups[2] 。\n得到答案为 [words[1],words[2]] = [\"a\",\"b\"] 。\n这也是一个可行的答案。\n符合题意的最长子序列的长度为 2 。\n\n示例 2:\n\n输入:n = 4, words = [\"a\",\"b\",\"c\",\"d\"], groups = [1,0,1,1]\n输出:[\"a\",\"b\",\"c\"]\n解释:一个可行的子序列为 [0,1,2] 因为 groups[0] != groups[1] 且 groups[1] != groups[2] 。\n所以一个可行的答案是 [words[0],words[1],words[2]] = [\"a\",\"b\",\"c\"] 。\n另一个可行的子序列为 [0,1,3] 因为 groups[0] != groups[1] 且 groups[1] != groups[3] 。\n得到答案为 [words[0],words[1],words[3]] = [\"a\",\"b\",\"d\"] 。\n这也是一个可行的答案。\n符合题意的最长子序列的长度为 3 。\n\n提示:\n\n * 1 <= n == words.length == groups.length <= 100\n * 1 <= words[i].length <= 10\n * 0 <= groups[i] < 2\n * words 中的字符串 互不相同 。\n * words[i] 只包含小写英文字母。\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def getWordsInLongestSubsequence(self, n: int, words: List[str], groups: List[int]) -> List[str]:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"n\": 3, \"words\": [\"e\",\"a\",\"b\"], \"groups\": [0,0,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"e\",\"b\"]\n\ntest_input = { \"n\": 4, \"words\": [\"a\",\"b\",\"c\",\"d\"], \"groups\": [1,0,1,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"a\",\"b\",\"c\"]\n\ntest_input = { \"n\": 1, \"words\": [\"c\"], \"groups\": [0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"c\"]\n\ntest_input = { \"n\": 1, \"words\": [\"d\"], \"groups\": [1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"d\"]\n\ntest_input = { \"n\": 1, \"words\": [\"e\"], \"groups\": [0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"e\"]\n\ntest_input = { \"n\": 1, \"words\": [\"fe\"], \"groups\": [0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"fe\"]\n\ntest_input = { \"n\": 1, \"words\": [\"frl\"], \"groups\": [1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"frl\"]\n\ntest_input = { \"n\": 1, \"words\": [\"ha\"], \"groups\": [1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ha\"]\n\ntest_input = { \"n\": 1, \"words\": [\"l\"], \"groups\": [0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"l\"]\n\ntest_input = { \"n\": 1, \"words\": [\"n\"], \"groups\": [1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"n\"]\n\ntest_input = { \"n\": 1, \"words\": [\"s\"], \"groups\": [1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"s\"]\n\ntest_input = { \"n\": 2, \"words\": [\"d\",\"g\"], \"groups\": [0,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"d\",\"g\"]\n\ntest_input = { \"n\": 2, \"words\": [\"lr\",\"h\"], \"groups\": [0,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"lr\"]\n\ntest_input = { \"n\": 2, \"words\": [\"wx\",\"h\"], \"groups\": [0,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"wx\",\"h\"]\n\ntest_input = { \"n\": 2, \"words\": [\"yw\",\"n\"], \"groups\": [0,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"yw\",\"n\"]\n\ntest_input = { \"n\": 2, \"words\": [\"z\",\"n\"], \"groups\": [0,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"z\"]\n\ntest_input = { \"n\": 2, \"words\": [\"zr\",\"a\"], \"groups\": [0,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"zr\"]\n\ntest_input = { \"n\": 3, \"words\": [\"h\",\"vv\",\"kp\"], \"groups\": [0,1,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"h\",\"vv\",\"kp\"]\n\ntest_input = { \"n\": 3, \"words\": [\"m\",\"v\",\"y\"], \"groups\": [0,1,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"m\",\"v\",\"y\"]\n\ntest_input = { \"n\": 3, \"words\": [\"o\",\"cfy\",\"en\"], \"groups\": [1,0,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"o\",\"cfy\"]\n\ntest_input = { \"n\": 3, \"words\": [\"tu\",\"rv\",\"bn\"], \"groups\": [0,0,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"tu\"]\n\ntest_input = { \"n\": 4, \"words\": [\"c\",\"f\",\"y\",\"i\"], \"groups\": [1,0,1,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"c\",\"f\",\"y\"]\n\ntest_input = { \"n\": 4, \"words\": [\"c\",\"w\",\"h\",\"s\"], \"groups\": [0,0,0,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"c\",\"s\"]\n\ntest_input = { \"n\": 4, \"words\": [\"d\",\"a\",\"v\",\"b\"], \"groups\": [1,0,0,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"d\",\"a\",\"b\"]\n\ntest_input = { \"n\": 4, \"words\": [\"hh\",\"svj\",\"a\",\"nr\"], \"groups\": [1,1,1,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"hh\"]\n\ntest_input = { \"n\": 4, \"words\": [\"im\",\"j\",\"xq\",\"cjs\"], \"groups\": [1,0,0,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"im\",\"j\",\"cjs\"]\n\ntest_input = { \"n\": 4, \"words\": [\"m\",\"dkg\",\"r\",\"h\"], \"groups\": [1,1,1,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"m\",\"h\"]\n\ntest_input = { \"n\": 4, \"words\": [\"ow\",\"qay\",\"r\",\"j\"], \"groups\": [1,1,1,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ow\"]\n\ntest_input = { \"n\": 4, \"words\": [\"r\",\"k\",\"pb\",\"x\"], \"groups\": [0,0,1,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"r\",\"pb\",\"x\"]\n\ntest_input = { \"n\": 4, \"words\": [\"sq\",\"do\",\"bcj\",\"nm\"], \"groups\": [0,1,1,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"sq\",\"do\",\"nm\"]\n\ntest_input = { \"n\": 4, \"words\": [\"sz\",\"mq\",\"j\",\"u\"], \"groups\": [0,0,1,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"sz\",\"j\",\"u\"]\n\ntest_input = { \"n\": 4, \"words\": [\"x\",\"nf\",\"p\",\"asn\"], \"groups\": [1,1,1,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"x\"]\n\ntest_input = { \"n\": 4, \"words\": [\"z\",\"tkt\",\"x\",\"swy\"], \"groups\": [1,0,1,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"z\",\"tkt\",\"x\"]\n\ntest_input = { \"n\": 5, \"words\": [\"ht\",\"lw\",\"ax\",\"vi\",\"fo\"], \"groups\": [0,0,1,0,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ht\",\"ax\",\"vi\"]\n\ntest_input = { \"n\": 5, \"words\": [\"mc\",\"kh\",\"x\",\"q\",\"z\"], \"groups\": [0,0,1,1,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"mc\",\"x\",\"z\"]\n\ntest_input = { \"n\": 5, \"words\": [\"n\",\"fg\",\"fy\",\"tv\",\"gv\"], \"groups\": [1,1,1,1,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"n\"]\n\ntest_input = { \"n\": 5, \"words\": [\"n\",\"l\",\"e\",\"d\",\"m\"], \"groups\": [1,1,0,1,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"n\",\"e\",\"d\"]\n\ntest_input = { \"n\": 5, \"words\": [\"n\",\"m\",\"g\",\"b\",\"d\"], \"groups\": [0,0,1,0,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"n\",\"g\",\"b\"]\n\ntest_input = { \"n\": 5, \"words\": [\"nz\",\"zwt\",\"hig\",\"s\",\"jze\"], \"groups\": [1,1,1,0,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"nz\",\"s\",\"jze\"]\n\ntest_input = { \"n\": 5, \"words\": [\"o\",\"i\",\"b\",\"k\",\"kz\"], \"groups\": [0,0,1,1,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"o\",\"b\"]\n\ntest_input = { \"n\": 5, \"words\": [\"r\",\"o\",\"k\",\"d\",\"f\"], \"groups\": [0,0,0,1,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"r\",\"d\"]\n\ntest_input = { \"n\": 5, \"words\": [\"sfh\",\"exd\",\"j\",\"w\",\"gc\"], \"groups\": [1,0,1,1,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"sfh\",\"exd\",\"j\"]\n\ntest_input = { \"n\": 5, \"words\": [\"v\",\"f\",\"k\",\"l\",\"p\"], \"groups\": [0,0,1,0,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"v\",\"k\",\"l\"]\n\ntest_input = { \"n\": 5, \"words\": [\"vbd\",\"ua\",\"muo\",\"mu\",\"qi\"], \"groups\": [0,0,0,1,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"vbd\",\"mu\",\"qi\"]\n\ntest_input = { \"n\": 5, \"words\": [\"we\",\"ch\",\"tl\",\"yx\",\"utx\"], \"groups\": [1,0,0,1,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"we\",\"ch\",\"yx\"]\n\ntest_input = { \"n\": 5, \"words\": [\"x\",\"vlk\",\"tds\",\"dfn\",\"kr\"], \"groups\": [0,0,1,1,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"x\",\"tds\",\"kr\"]\n\ntest_input = { \"n\": 5, \"words\": [\"y\",\"j\",\"u\",\"r\",\"f\"], \"groups\": [0,0,1,1,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"y\",\"u\",\"f\"]\n\ntest_input = { \"n\": 5, \"words\": [\"y\",\"r\",\"z\",\"x\",\"q\"], \"groups\": [0,1,0,1,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"y\",\"r\",\"z\",\"x\"]\n\ntest_input = { \"n\": 5, \"words\": [\"yc\",\"fgq\",\"gg\",\"og\",\"tca\"], \"groups\": [0,1,1,1,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"yc\",\"fgq\",\"tca\"]\n\ntest_input = { \"n\": 5, \"words\": [\"z\",\"d\",\"p\",\"c\",\"m\"], \"groups\": [0,0,0,0,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"z\"]\n\ntest_input = { \"n\": 6, \"words\": [\"c\",\"i\",\"to\",\"kv\",\"op\",\"u\"], \"groups\": [0,0,1,0,0,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"c\",\"to\",\"kv\"]\n\ntest_input = { \"n\": 6, \"words\": [\"d\",\"h\",\"e\",\"k\",\"j\",\"r\"], \"groups\": [0,1,1,0,1,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"d\",\"h\",\"k\",\"j\",\"r\"]\n\ntest_input = { \"n\": 6, \"words\": [\"l\",\"f\",\"v\",\"b\",\"w\",\"k\"], \"groups\": [1,0,1,1,0,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"l\",\"f\",\"v\",\"w\"]\n\ntest_input = { \"n\": 6, \"words\": [\"lj\",\"vf\",\"pa\",\"w\",\"z\",\"q\"], \"groups\": [0,0,1,0,0,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"lj\",\"pa\",\"w\"]\n\ntest_input = { \"n\": 7, \"words\": [\"cd\",\"oki\",\"ho\",\"oi\",\"m\",\"yvy\",\"i\"], \"groups\": [1,1,0,1,1,1,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"cd\",\"ho\",\"oi\"]\n\ntest_input = { \"n\": 7, \"words\": [\"exb\",\"c\",\"oq\",\"lq\",\"xh\",\"zmo\",\"aug\"], \"groups\": [1,1,0,1,1,0,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"exb\",\"oq\",\"lq\",\"zmo\"]\n\ntest_input = { \"n\": 7, \"words\": [\"f\",\"r\",\"k\",\"h\",\"m\",\"v\",\"p\"], \"groups\": [1,0,0,0,1,0,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"f\",\"r\",\"m\",\"v\"]\n\ntest_input = { \"n\": 7, \"words\": [\"fd\",\"fc\",\"jm\",\"z\",\"lg\",\"kl\",\"ux\"], \"groups\": [0,1,0,1,0,1,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"fd\",\"fc\",\"jm\",\"z\",\"lg\",\"kl\",\"ux\"]\n\ntest_input = { \"n\": 7, \"words\": [\"ft\",\"iw\",\"m\",\"v\",\"gx\",\"d\",\"pm\"], \"groups\": [1,1,1,0,1,1,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ft\",\"v\",\"gx\"]\n\ntest_input = { \"n\": 7, \"words\": [\"lma\",\"i\",\"rt\",\"xar\",\"bfx\",\"np\",\"x\"], \"groups\": [1,1,1,1,1,0,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"lma\",\"np\",\"x\"]\n\ntest_input = { \"n\": 7, \"words\": [\"nsv\",\"r\",\"o\",\"qo\",\"pb\",\"xqv\",\"clb\"], \"groups\": [1,1,0,0,0,0,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"nsv\",\"o\"]\n\ntest_input = { \"n\": 7, \"words\": [\"p\",\"qdb\",\"zcd\",\"l\",\"tv\",\"ln\",\"ogb\"], \"groups\": [1,1,0,1,0,0,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"p\",\"zcd\",\"l\",\"tv\",\"ogb\"]\n\ntest_input = { \"n\": 7, \"words\": [\"z\",\"cee\",\"j\",\"jqu\",\"w\",\"ljr\",\"k\"], \"groups\": [1,0,1,1,0,0,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"z\",\"cee\",\"j\",\"w\",\"k\"]\n\ntest_input = { \"n\": 8, \"words\": [\"h\",\"p\",\"q\",\"t\",\"j\",\"a\",\"c\",\"n\"], \"groups\": [0,1,1,1,0,0,1,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"h\",\"p\",\"j\",\"c\"]\n\ntest_input = { \"n\": 8, \"words\": [\"r\",\"v\",\"c\",\"t\",\"d\",\"a\",\"x\",\"o\"], \"groups\": [1,1,0,1,1,0,0,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"r\",\"c\",\"t\",\"a\",\"o\"]\n\ntest_input = { \"n\": 8, \"words\": [\"u\",\"l\",\"a\",\"y\",\"j\",\"s\",\"h\",\"q\"], \"groups\": [0,0,0,0,0,1,0,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"u\",\"s\",\"h\"]\n\ntest_input = { \"n\": 8, \"words\": [\"x\",\"mr\",\"yyf\",\"l\",\"z\",\"q\",\"zvj\",\"zqt\"], \"groups\": [0,1,1,1,0,1,1,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"x\",\"mr\",\"z\",\"q\",\"zqt\"]\n\ntest_input = { \"n\": 8, \"words\": [\"y\",\"x\",\"i\",\"xtm\",\"ze\",\"n\",\"cma\",\"dgk\"], \"groups\": [0,1,0,0,1,1,0,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"y\",\"x\",\"i\",\"ze\",\"cma\"]\n\ntest_input = { \"n\": 8, \"words\": [\"yun\",\"x\",\"zpp\",\"bpr\",\"ii\",\"ezg\",\"dn\",\"k\"], \"groups\": [0,1,1,1,1,0,1,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"yun\",\"x\",\"ezg\",\"dn\",\"k\"]\n\ntest_input = { \"n\": 9, \"words\": [\"ckr\",\"iz\",\"top\",\"of\",\"sb\",\"wv\",\"hb\",\"da\",\"wd\"], \"groups\": [1,1,0,1,1,0,0,0,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ckr\",\"top\",\"of\",\"wv\",\"wd\"]\n\ntest_input = { \"n\": 9, \"words\": [\"g\",\"h\",\"u\",\"n\",\"w\",\"o\",\"f\",\"p\",\"m\"], \"groups\": [1,0,0,1,1,0,0,1,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"g\",\"h\",\"n\",\"o\",\"p\",\"m\"]\n\ntest_input = { \"n\": 9, \"words\": [\"ilw\",\"t\",\"dyy\",\"irz\",\"oxy\",\"k\",\"rfj\",\"hi\",\"zxe\"], \"groups\": [1,1,1,0,1,1,0,1,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ilw\",\"irz\",\"oxy\",\"rfj\",\"hi\"]\n\ntest_input = { \"n\": 9, \"words\": [\"l\",\"iuz\",\"d\",\"tfw\",\"mu\",\"a\",\"rp\",\"mrb\",\"wnl\"], \"groups\": [1,1,1,1,1,0,1,1,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"l\",\"a\",\"rp\",\"wnl\"]\n\ntest_input = { \"n\": 9, \"words\": [\"mc\",\"b\",\"yr\",\"cj\",\"zk\",\"wi\",\"esm\",\"yu\",\"cw\"], \"groups\": [0,0,1,1,0,0,1,1,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"mc\",\"yr\",\"zk\",\"esm\",\"cw\"]\n\ntest_input = { \"n\": 9, \"words\": [\"nw\",\"hx\",\"ygc\",\"vjo\",\"jmv\",\"p\",\"juv\",\"b\",\"y\"], \"groups\": [0,1,0,0,1,0,0,1,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"nw\",\"hx\",\"ygc\",\"jmv\",\"p\",\"b\",\"y\"]\n\ntest_input = { \"n\": 9, \"words\": [\"osq\",\"qiw\",\"h\",\"tc\",\"xg\",\"tvt\",\"fqp\",\"zq\",\"b\"], \"groups\": [0,0,1,0,1,1,0,1,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"osq\",\"h\",\"tc\",\"xg\",\"fqp\",\"zq\"]\n\ntest_input = { \"n\": 9, \"words\": [\"vr\",\"lw\",\"e\",\"g\",\"dz\",\"kf\",\"qe\",\"h\",\"p\"], \"groups\": [1,0,0,1,1,0,0,0,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"vr\",\"lw\",\"g\",\"kf\"]\n\ntest_input = { \"n\": 10, \"words\": [\"gy\",\"nd\",\"l\",\"hr\",\"i\",\"qf\",\"zz\",\"nq\",\"e\",\"oa\"], \"groups\": [0,1,0,0,1,0,1,1,1,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"gy\",\"nd\",\"l\",\"i\",\"qf\",\"zz\",\"oa\"]\n\ntest_input = { \"n\": 10, \"words\": [\"j\",\"r\",\"h\",\"t\",\"z\",\"b\",\"a\",\"s\",\"v\",\"q\"], \"groups\": [1,0,1,1,1,1,0,0,0,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"j\",\"r\",\"h\",\"a\",\"q\"]\n\ntest_input = { \"n\": 10, \"words\": [\"k\",\"f\",\"u\",\"h\",\"x\",\"w\",\"c\",\"e\",\"l\",\"p\"], \"groups\": [0,1,1,1,1,1,1,1,1,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"k\",\"f\",\"p\"]\n\ntest_input = { \"n\": 10, \"words\": [\"lj\",\"huy\",\"lg\",\"h\",\"o\",\"b\",\"ava\",\"ay\",\"r\",\"us\"], \"groups\": [1,1,1,1,0,0,1,1,1,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"lj\",\"o\",\"ava\"]\n\ntest_input = { \"n\": 10, \"words\": [\"m\",\"d\",\"xv\",\"dp\",\"nq\",\"xi\",\"e\",\"g\",\"n\",\"qw\"], \"groups\": [1,0,1,1,1,1,0,1,0,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"m\",\"d\",\"xv\",\"e\",\"g\",\"n\",\"qw\"]\n\ntest_input = { \"n\": 10, \"words\": [\"n\",\"c\",\"y\",\"h\",\"w\",\"m\",\"g\",\"t\",\"x\",\"v\"], \"groups\": [1,1,1,0,0,1,0,0,0,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"n\",\"h\",\"m\",\"g\",\"v\"]\n\ntest_input = { \"n\": 10, \"words\": [\"o\",\"w\",\"l\",\"g\",\"m\",\"x\",\"f\",\"q\",\"c\",\"v\"], \"groups\": [1,1,1,0,1,1,1,0,0,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"o\",\"g\",\"m\",\"q\",\"v\"]\n\ntest_input = { \"n\": 10, \"words\": [\"p\",\"mw\",\"m\",\"xld\",\"j\",\"jv\",\"n\",\"so\",\"pkd\",\"rwt\"], \"groups\": [0,0,1,0,1,1,0,0,1,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"p\",\"m\",\"xld\",\"j\",\"n\",\"pkd\"]\n\ntest_input = { \"n\": 10, \"words\": [\"vyv\",\"msl\",\"d\",\"bu\",\"ubl\",\"bgk\",\"sz\",\"njv\",\"pf\",\"s\"], \"groups\": [1,0,1,1,0,0,1,0,1,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"vyv\",\"msl\",\"d\",\"ubl\",\"sz\",\"njv\",\"pf\",\"s\"]\n\ntest_input = { \"n\": 10, \"words\": [\"y\",\"mz\",\"lt\",\"ur\",\"o\",\"m\",\"djh\",\"tb\",\"w\",\"j\"], \"groups\": [0,0,1,0,1,1,0,1,0,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"y\",\"lt\",\"ur\",\"o\",\"djh\",\"tb\",\"w\"]\n\ntest_input = { \"n\": 10, \"words\": [\"y\",\"s\",\"i\",\"v\",\"a\",\"w\",\"l\",\"q\",\"k\",\"t\"], \"groups\": [0,1,1,1,0,1,1,1,0,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"y\",\"s\",\"a\",\"w\",\"k\"]\n\ntest_input = { \"n\": 11, \"words\": [\"a\",\"tea\",\"ldt\",\"ybm\",\"zkw\",\"r\",\"d\",\"dms\",\"le\",\"u\",\"ze\"], \"groups\": [1,1,0,0,0,1,1,1,1,0,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"a\",\"ldt\",\"r\",\"u\",\"ze\"]\n\ntest_input = { \"n\": 11, \"words\": [\"c\",\"o\",\"e\",\"r\",\"x\",\"w\",\"b\",\"d\",\"h\",\"y\",\"z\"], \"groups\": [1,0,1,0,1,0,1,1,1,0,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"c\",\"o\",\"e\",\"r\",\"x\",\"w\",\"b\",\"y\",\"z\"]\n\ntest_input = { \"n\": 11, \"words\": [\"chu\",\"a\",\"qdx\",\"fgd\",\"qe\",\"bqc\",\"x\",\"kbx\",\"sv\",\"ly\",\"br\"], \"groups\": [1,0,0,0,0,0,1,0,1,1,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"chu\",\"a\",\"x\",\"kbx\",\"sv\",\"br\"]\n\ntest_input = { \"n\": 11, \"words\": [\"ec\",\"jdf\",\"b\",\"wa\",\"kjd\",\"bb\",\"ty\",\"yi\",\"ybw\",\"ilj\",\"cv\"], \"groups\": [0,1,0,1,1,1,1,1,1,0,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ec\",\"jdf\",\"b\",\"wa\",\"ilj\",\"cv\"]\n\ntest_input = { \"n\": 11, \"words\": [\"ew\",\"isn\",\"fl\",\"mg\",\"pdg\",\"d\",\"p\",\"hh\",\"e\",\"y\",\"whm\"], \"groups\": [0,0,1,1,0,0,0,0,0,1,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ew\",\"fl\",\"pdg\",\"y\"]\n\ntest_input = { \"n\": 11, \"words\": [\"h\",\"o\",\"d\",\"y\",\"r\",\"c\",\"p\",\"b\",\"g\",\"j\",\"k\"], \"groups\": [1,1,0,1,1,0,1,1,0,0,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"h\",\"d\",\"y\",\"c\",\"p\",\"g\"]\n\ntest_input = { \"n\": 11, \"words\": [\"ipr\",\"l\",\"zy\",\"j\",\"h\",\"hdt\",\"m\",\"d\",\"pd\",\"nv\",\"wy\"], \"groups\": [1,1,1,1,0,1,0,1,1,1,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ipr\",\"h\",\"hdt\",\"m\",\"d\"]\n\ntest_input = { \"n\": 11, \"words\": [\"j\",\"g\",\"go\",\"a\",\"f\",\"bg\",\"o\",\"l\",\"ze\",\"kq\",\"w\"], \"groups\": [0,0,1,0,1,0,0,0,1,0,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"j\",\"go\",\"a\",\"f\",\"bg\",\"ze\",\"kq\",\"w\"]\n\ntest_input = { \"n\": 11, \"words\": [\"j\",\"r\",\"a\",\"g\",\"x\",\"b\",\"y\",\"v\",\"k\",\"i\",\"c\"], \"groups\": [0,1,0,0,0,0,1,1,0,0,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"j\",\"r\",\"a\",\"y\",\"k\"]\n\ntest_input = { \"n\": 11, \"words\": [\"kgo\",\"han\",\"nlu\",\"tv\",\"us\",\"pk\",\"xw\",\"cxc\",\"eml\",\"v\",\"msz\"], \"groups\": [1,0,0,1,0,0,1,0,1,1,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"kgo\",\"han\",\"tv\",\"us\",\"xw\",\"cxc\",\"eml\",\"msz\"]\n\ntest_input = { \"n\": 11, \"words\": [\"kh\",\"op\",\"ij\",\"te\",\"hk\",\"pmt\",\"v\",\"ne\",\"en\",\"b\",\"zuj\"], \"groups\": [0,0,1,1,1,0,1,1,0,1,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"kh\",\"ij\",\"pmt\",\"v\",\"en\",\"b\"]\n\ntest_input = { \"n\": 11, \"words\": [\"ms\",\"t\",\"oz\",\"x\",\"pw\",\"ik\",\"d\",\"gj\",\"z\",\"ps\",\"i\"], \"groups\": [1,1,0,1,0,0,1,1,0,0,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ms\",\"oz\",\"x\",\"pw\",\"d\",\"z\",\"i\"]", "start_time": 1697293800} +{"task_id": "biweekly-contest-115-longest-unequal-adjacent-groups-subsequence-ii", "url": "https://leetcode.com/problems/longest-unequal-adjacent-groups-subsequence-ii", "title": "longest-unequal-adjacent-groups-subsequence-ii", "meta": {"questionId": "3142", "questionFrontendId": "2901", "title": "Longest Unequal Adjacent Groups Subsequence II", "titleSlug": "longest-unequal-adjacent-groups-subsequence-ii", "isPaidOnly": false, "difficulty": "Medium", "likes": 172, "dislikes": 16, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个整数 n 和一个下标从 0 开始的字符串数组 words ,和一个下标从 0 开始的数组 groups ,两个数组长度都是 n 。\n\n两个长度相等字符串的 汉明距离 定义为对应位置字符 不同 的数目。\n\n你需要从下标 [0, 1, ..., n - 1] 中选出一个 最长子序列 ,将这个子序列记作长度为 k 的 [i0, i1, ..., ik - 1] ,它需要满足以下条件:\n\n * 相邻 下标对应的 groups 值 不同。即,对于所有满足 0 < j + 1 < k 的 j 都有 groups[ij] != groups[ij + 1] 。\n * 对于所有 0 < j + 1 < k 的下标 j ,都满足 words[ij] 和 words[ij + 1] 的长度 相等 ,且两个字符串之间的 汉明距离 为 1 。\n\n请你返回一个字符串数组,它是下标子序列 依次 对应 words 数组中的字符串连接形成的字符串数组。如果有多个答案,返回任意一个。\n\n子序列 指的是从原数组中删掉一些(也可能一个也不删掉)元素,剩余元素不改变相对位置得到的新的数组。\n\n注意:words 中的字符串长度可能 不相等 。\n\n示例 1:\n\n输入:n = 3, words = [\"bab\",\"dab\",\"cab\"], groups = [1,2,2]\n输出:[\"bab\",\"cab\"]\n解释:一个可行的子序列是 [0,2] 。\n- groups[0] != groups[2]\n- words[0].length == words[2].length 且它们之间的汉明距离为 1 。\n所以一个可行的答案是 [words[0],words[2]] = [\"bab\",\"cab\"] 。\n另一个可行的子序列是 [0,1] 。\n- groups[0] != groups[1]\n- words[0].length = words[1].length 且它们之间的汉明距离为 1 。\n所以另一个可行的答案是 [words[0],words[1]] = [\"bab\",\"dab\"] 。\n符合题意的最长子序列的长度为 2 。\n\n示例 2:\n\n输入:n = 4, words = [\"a\",\"b\",\"c\",\"d\"], groups = [1,2,3,4]\n输出:[\"a\",\"b\",\"c\",\"d\"]\n解释:我们选择子序列 [0,1,2,3] 。\n它同时满足两个条件。\n所以答案为 [words[0],words[1],words[2],words[3]] = [\"a\",\"b\",\"c\",\"d\"] 。\n它是所有下标子序列里最长且满足所有条件的。\n所以它是唯一的答案。\n\n\n提示:\n\n * 1 <= n == words.length == groups.length <= 1000\n * 1 <= words[i].length <= 10\n * 1 <= groups[i] <= n\n * words 中的字符串 互不相同 。\n * words[i] 只包含小写英文字母。\n\"\"\"\nclass Solution:\n def getWordsInLongestSubsequence(self, n: int, words: List[str], groups: List[int]) -> List[str]:\n ", "prompt_sft": "给你一个整数 n 和一个下标从 0 开始的字符串数组 words ,和一个下标从 0 开始的数组 groups ,两个数组长度都是 n 。\n\n两个长度相等字符串的 汉明距离 定义为对应位置字符 不同 的数目。\n\n你需要从下标 [0, 1, ..., n - 1] 中选出一个 最长子序列 ,将这个子序列记作长度为 k 的 [i0, i1, ..., ik - 1] ,它需要满足以下条件:\n\n * 相邻 下标对应的 groups 值 不同。即,对于所有满足 0 < j + 1 < k 的 j 都有 groups[ij] != groups[ij + 1] 。\n * 对于所有 0 < j + 1 < k 的下标 j ,都满足 words[ij] 和 words[ij + 1] 的长度 相等 ,且两个字符串之间的 汉明距离 为 1 。\n\n请你返回一个字符串数组,它是下标子序列 依次 对应 words 数组中的字符串连接形成的字符串数组。如果有多个答案,返回任意一个。\n\n子序列 指的是从原数组中删掉一些(也可能一个也不删掉)元素,剩余元素不改变相对位置得到的新的数组。\n\n注意:words 中的字符串长度可能 不相等 。\n\n示例 1:\n\n输入:n = 3, words = [\"bab\",\"dab\",\"cab\"], groups = [1,2,2]\n输出:[\"bab\",\"cab\"]\n解释:一个可行的子序列是 [0,2] 。\n- groups[0] != groups[2]\n- words[0].length == words[2].length 且它们之间的汉明距离为 1 。\n所以一个可行的答案是 [words[0],words[2]] = [\"bab\",\"cab\"] 。\n另一个可行的子序列是 [0,1] 。\n- groups[0] != groups[1]\n- words[0].length = words[1].length 且它们之间的汉明距离为 1 。\n所以另一个可行的答案是 [words[0],words[1]] = [\"bab\",\"dab\"] 。\n符合题意的最长子序列的长度为 2 。\n\n示例 2:\n\n输入:n = 4, words = [\"a\",\"b\",\"c\",\"d\"], groups = [1,2,3,4]\n输出:[\"a\",\"b\",\"c\",\"d\"]\n解释:我们选择子序列 [0,1,2,3] 。\n它同时满足两个条件。\n所以答案为 [words[0],words[1],words[2],words[3]] = [\"a\",\"b\",\"c\",\"d\"] 。\n它是所有下标子序列里最长且满足所有条件的。\n所以它是唯一的答案。\n\n\n提示:\n\n * 1 <= n == words.length == groups.length <= 1000\n * 1 <= words[i].length <= 10\n * 1 <= groups[i] <= n\n * words 中的字符串 互不相同 。\n * words[i] 只包含小写英文字母。\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def getWordsInLongestSubsequence(self, n: int, words: List[str], groups: List[int]) -> List[str]:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"n\": 3, \"words\": [\"bab\",\"dab\",\"cab\"], \"groups\": [1,2,2] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"bab\",\"cab\"]\n\ntest_input = { \"n\": 4, \"words\": [\"a\",\"b\",\"c\",\"d\"], \"groups\": [1,2,3,4] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"a\",\"b\",\"c\",\"d\"]\n\ntest_input = { \"n\": 1, \"words\": [\"abbbb\"], \"groups\": [1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"abbbb\"]\n\ntest_input = { \"n\": 1, \"words\": [\"ad\"], \"groups\": [1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ad\"]\n\ntest_input = { \"n\": 1, \"words\": [\"baaccb\"], \"groups\": [1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"baaccb\"]\n\ntest_input = { \"n\": 1, \"words\": [\"bc\"], \"groups\": [1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"bc\"]\n\ntest_input = { \"n\": 1, \"words\": [\"bdb\"], \"groups\": [1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"bdb\"]\n\ntest_input = { \"n\": 1, \"words\": [\"cc\"], \"groups\": [1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"cc\"]\n\ntest_input = { \"n\": 1, \"words\": [\"cd\"], \"groups\": [1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"cd\"]\n\ntest_input = { \"n\": 1, \"words\": [\"cdb\"], \"groups\": [1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"cdb\"]\n\ntest_input = { \"n\": 1, \"words\": [\"cea\"], \"groups\": [1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"cea\"]\n\ntest_input = { \"n\": 1, \"words\": [\"cebbbb\"], \"groups\": [1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"cebbbb\"]\n\ntest_input = { \"n\": 1, \"words\": [\"da\"], \"groups\": [1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"da\"]\n\ntest_input = { \"n\": 1, \"words\": [\"daab\"], \"groups\": [1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"daab\"]\n\ntest_input = { \"n\": 2, \"words\": [\"adbe\",\"acace\"], \"groups\": [2,2] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"acace\"]\n\ntest_input = { \"n\": 2, \"words\": [\"ba\",\"dc\"], \"groups\": [1,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"dc\"]\n\ntest_input = { \"n\": 2, \"words\": [\"baa\",\"ada\"], \"groups\": [1,2] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ada\"]\n\ntest_input = { \"n\": 2, \"words\": [\"bebea\",\"ddecc\"], \"groups\": [1,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ddecc\"]\n\ntest_input = { \"n\": 2, \"words\": [\"cedbca\",\"db\"], \"groups\": [1,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"db\"]\n\ntest_input = { \"n\": 2, \"words\": [\"dbcdd\",\"baba\"], \"groups\": [2,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"baba\"]\n\ntest_input = { \"n\": 2, \"words\": [\"ddb\",\"bdb\"], \"groups\": [1,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"bdb\"]\n\ntest_input = { \"n\": 2, \"words\": [\"dee\",\"bb\"], \"groups\": [2,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"bb\"]\n\ntest_input = { \"n\": 2, \"words\": [\"ecd\",\"dbeed\"], \"groups\": [1,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"dbeed\"]\n\ntest_input = { \"n\": 3, \"words\": [\"aaac\",\"dbede\",\"cbdeee\"], \"groups\": [2,2,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"cbdeee\"]\n\ntest_input = { \"n\": 3, \"words\": [\"aab\",\"ca\",\"cbd\"], \"groups\": [3,3,2] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"cbd\"]\n\ntest_input = { \"n\": 3, \"words\": [\"aeb\",\"bc\",\"abdb\"], \"groups\": [2,3,2] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"abdb\"]\n\ntest_input = { \"n\": 3, \"words\": [\"bdb\",\"aaa\",\"ada\"], \"groups\": [2,1,3] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"aaa\",\"ada\"]\n\ntest_input = { \"n\": 3, \"words\": [\"cc\",\"aa\",\"dda\"], \"groups\": [2,2,2] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"dda\"]\n\ntest_input = { \"n\": 3, \"words\": [\"cc\",\"aba\",\"dbd\"], \"groups\": [1,1,2] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"dbd\"]\n\ntest_input = { \"n\": 3, \"words\": [\"ccd\",\"bb\",\"ccc\"], \"groups\": [1,1,2] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ccd\",\"ccc\"]\n\ntest_input = { \"n\": 3, \"words\": [\"cda\",\"bb\",\"bdc\"], \"groups\": [3,1,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"bdc\"]\n\ntest_input = { \"n\": 3, \"words\": [\"ceea\",\"ade\",\"aeacba\"], \"groups\": [2,1,2] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"aeacba\"]\n\ntest_input = { \"n\": 3, \"words\": [\"db\",\"ccce\",\"edbac\"], \"groups\": [3,2,2] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"edbac\"]\n\ntest_input = { \"n\": 3, \"words\": [\"dba\",\"bb\",\"aa\"], \"groups\": [2,2,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"aa\"]\n\ntest_input = { \"n\": 3, \"words\": [\"dbdaad\",\"daca\",\"cdbdb\"], \"groups\": [1,1,3] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"cdbdb\"]\n\ntest_input = { \"n\": 3, \"words\": [\"dc\",\"bca\",\"ddd\"], \"groups\": [1,3,2] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ddd\"]\n\ntest_input = { \"n\": 3, \"words\": [\"dd\",\"bb\",\"aac\"], \"groups\": [3,3,2] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"aac\"]\n\ntest_input = { \"n\": 3, \"words\": [\"dedcc\",\"cbac\",\"dab\"], \"groups\": [1,3,2] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"dab\"]\n\ntest_input = { \"n\": 3, \"words\": [\"eee\",\"abecab\",\"dc\"], \"groups\": [2,2,3] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"dc\"]\n\ntest_input = { \"n\": 4, \"words\": [\"ac\",\"caa\",\"cda\",\"ba\"], \"groups\": [3,1,2,3] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"caa\",\"cda\"]\n\ntest_input = { \"n\": 4, \"words\": [\"bab\",\"bac\",\"dbd\",\"dd\"], \"groups\": [1,1,3,4] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"dd\"]\n\ntest_input = { \"n\": 4, \"words\": [\"bab\",\"bdd\",\"bca\",\"dab\"], \"groups\": [2,4,1,2] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"dab\"]\n\ntest_input = { \"n\": 4, \"words\": [\"bbbd\",\"babca\",\"ebddde\",\"cce\"], \"groups\": [3,4,3,3] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"cce\"]\n\ntest_input = { \"n\": 4, \"words\": [\"beb\",\"eacedc\",\"aeeb\",\"cdd\"], \"groups\": [1,4,3,2] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"cdd\"]\n\ntest_input = { \"n\": 4, \"words\": [\"cac\",\"aaa\",\"dd\",\"cda\"], \"groups\": [1,4,2,3] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"cda\"]\n\ntest_input = { \"n\": 4, \"words\": [\"cbb\",\"db\",\"bdd\",\"bd\"], \"groups\": [2,3,4,3] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"bd\"]\n\ntest_input = { \"n\": 4, \"words\": [\"cdc\",\"dc\",\"bd\",\"aca\"], \"groups\": [3,2,2,3] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"aca\"]\n\ntest_input = { \"n\": 4, \"words\": [\"ceacd\",\"ac\",\"bebdae\",\"dbbbcb\"], \"groups\": [2,3,1,2] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"dbbbcb\"]\n\ntest_input = { \"n\": 4, \"words\": [\"dcaacc\",\"da\",\"ddcbd\",\"dd\"], \"groups\": [2,3,1,4] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"da\",\"dd\"]\n\ntest_input = { \"n\": 4, \"words\": [\"deeb\",\"edbea\",\"ad\",\"ecedd\"], \"groups\": [1,1,1,2] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ecedd\"]\n\ntest_input = { \"n\": 4, \"words\": [\"ebe\",\"bcca\",\"caabaa\",\"abb\"], \"groups\": [1,4,4,2] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"abb\"]\n\ntest_input = { \"n\": 5, \"words\": [\"abd\",\"bab\",\"bc\",\"ac\",\"acd\"], \"groups\": [3,5,3,3,4] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"abd\",\"acd\"]\n\ntest_input = { \"n\": 5, \"words\": [\"acc\",\"ab\",\"baa\",\"dac\",\"aa\"], \"groups\": [3,1,2,3,3] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ab\",\"aa\"]\n\ntest_input = { \"n\": 5, \"words\": [\"acda\",\"caae\",\"ccad\",\"ac\",\"ddeedb\"], \"groups\": [4,2,4,1,3] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ddeedb\"]\n\ntest_input = { \"n\": 5, \"words\": [\"ade\",\"ea\",\"aabd\",\"bc\",\"aaaabe\"], \"groups\": [4,2,4,4,3] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"aaaabe\"]\n\ntest_input = { \"n\": 5, \"words\": [\"ba\",\"ee\",\"ed\",\"ddddd\",\"ce\"], \"groups\": [4,4,4,5,5] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ee\",\"ce\"]\n\ntest_input = { \"n\": 5, \"words\": [\"bacd\",\"adbbab\",\"ba\",\"ec\",\"deecbe\"], \"groups\": [4,4,5,5,4] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"deecbe\"]\n\ntest_input = { \"n\": 5, \"words\": [\"bad\",\"cab\",\"abb\",\"cd\",\"ba\"], \"groups\": [2,5,3,4,2] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ba\"]\n\ntest_input = { \"n\": 5, \"words\": [\"ca\",\"cb\",\"bcd\",\"bb\",\"ddc\"], \"groups\": [2,4,2,5,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ca\",\"cb\",\"bb\"]\n\ntest_input = { \"n\": 5, \"words\": [\"ccb\",\"ac\",\"aa\",\"bad\",\"ab\"], \"groups\": [3,5,2,2,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ac\",\"aa\",\"ab\"]\n\ntest_input = { \"n\": 5, \"words\": [\"cd\",\"dd\",\"ad\",\"aaa\",\"db\"], \"groups\": [2,3,3,5,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"cd\",\"dd\",\"db\"]\n\ntest_input = { \"n\": 5, \"words\": [\"cda\",\"ab\",\"cb\",\"ccb\",\"baa\"], \"groups\": [3,1,2,1,2] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ab\",\"cb\"]\n\ntest_input = { \"n\": 5, \"words\": [\"dc\",\"eca\",\"cdade\",\"aaaccd\",\"deb\"], \"groups\": [3,2,3,1,4] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"deb\"]\n\ntest_input = { \"n\": 5, \"words\": [\"dceba\",\"dbcab\",\"bacd\",\"bacdab\",\"bdeca\"], \"groups\": [4,3,5,3,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"bdeca\"]\n\ntest_input = { \"n\": 5, \"words\": [\"deeb\",\"ee\",\"bbbbe\",\"bddba\",\"cdb\"], \"groups\": [4,4,1,3,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"cdb\"]\n\ntest_input = { \"n\": 6, \"words\": [\"aab\",\"cab\",\"ba\",\"dba\",\"daa\",\"bca\"], \"groups\": [4,3,4,6,4,3] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"dba\",\"daa\"]\n\ntest_input = { \"n\": 6, \"words\": [\"aca\",\"dd\",\"aab\",\"dac\",\"adb\",\"bad\"], \"groups\": [2,6,2,1,4,3] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"aab\",\"adb\"]\n\ntest_input = { \"n\": 6, \"words\": [\"ad\",\"bb\",\"cc\",\"bc\",\"bcb\",\"abc\"], \"groups\": [3,5,5,5,1,5] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"abc\"]\n\ntest_input = { \"n\": 6, \"words\": [\"bcb\",\"cba\",\"cab\",\"cca\",\"ad\",\"cd\"], \"groups\": [6,5,1,5,5,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ad\",\"cd\"]\n\ntest_input = { \"n\": 6, \"words\": [\"bdaaee\",\"cb\",\"ecaad\",\"accdd\",\"ba\",\"adad\"], \"groups\": [2,4,4,6,1,5] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"adad\"]\n\ntest_input = { \"n\": 6, \"words\": [\"bdccb\",\"cece\",\"dbdda\",\"bbc\",\"bcbae\",\"badc\"], \"groups\": [4,2,4,1,1,6] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"badc\"]\n\ntest_input = { \"n\": 6, \"words\": [\"cba\",\"cc\",\"cd\",\"ccc\",\"aba\",\"ac\"], \"groups\": [3,6,2,4,2,6] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"cba\",\"aba\"]\n\ntest_input = { \"n\": 6, \"words\": [\"ccd\",\"db\",\"cbb\",\"cb\",\"cab\",\"acd\"], \"groups\": [5,1,5,5,6,6] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ccd\",\"acd\"]\n\ntest_input = { \"n\": 6, \"words\": [\"eb\",\"eaab\",\"accdba\",\"ecba\",\"aec\",\"dacacd\"], \"groups\": [4,6,1,6,2,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"dacacd\"]\n\ntest_input = { \"n\": 6, \"words\": [\"ee\",\"aab\",\"db\",\"cc\",\"dead\",\"aee\"], \"groups\": [5,5,4,2,5,6] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"aee\"]\n\ntest_input = { \"n\": 7, \"words\": [\"aad\",\"cba\",\"bda\",\"dc\",\"aba\",\"dbc\",\"ac\"], \"groups\": [6,4,1,7,5,2,6] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"dc\",\"ac\"]\n\ntest_input = { \"n\": 7, \"words\": [\"adcaa\",\"db\",\"dced\",\"ded\",\"eeadce\",\"bdbbe\",\"acaadc\"], \"groups\": [7,5,4,2,1,5,3] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"acaadc\"]\n\ntest_input = { \"n\": 7, \"words\": [\"bcabd\",\"cd\",\"cbaadc\",\"cda\",\"bcde\",\"ccedca\",\"ba\"], \"groups\": [7,3,6,7,1,7,5] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ba\"]\n\ntest_input = { \"n\": 7, \"words\": [\"bd\",\"dbd\",\"dcc\",\"cb\",\"ac\",\"abd\",\"bb\"], \"groups\": [1,3,3,6,6,4,5] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"cb\",\"bb\"]\n\ntest_input = { \"n\": 7, \"words\": [\"cbde\",\"aad\",\"dbdceb\",\"ae\",\"eca\",\"bd\",\"bba\"], \"groups\": [7,5,7,6,4,5,3] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"bba\"]\n\ntest_input = { \"n\": 7, \"words\": [\"cdcdad\",\"baaee\",\"cba\",\"ceae\",\"ab\",\"bedbab\",\"eb\"], \"groups\": [5,3,7,1,7,6,7] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"eb\"]\n\ntest_input = { \"n\": 7, \"words\": [\"dabbdb\",\"eacbdb\",\"bbdea\",\"cdcaa\",\"eaeeb\",\"cebabe\",\"ad\"], \"groups\": [3,5,5,6,3,4,2] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ad\"]\n\ntest_input = { \"n\": 7, \"words\": [\"dbcca\",\"dcdd\",\"bebbc\",\"cbed\",\"cb\",\"abed\",\"ac\"], \"groups\": [4,6,6,6,3,7,6] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"cbed\",\"abed\"]\n\ntest_input = { \"n\": 7, \"words\": [\"dcc\",\"cba\",\"ab\",\"cb\",\"aac\",\"aba\",\"db\"], \"groups\": [3,2,1,6,2,6,6] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ab\",\"db\"]\n\ntest_input = { \"n\": 7, \"words\": [\"ddd\",\"cd\",\"adb\",\"bcc\",\"da\",\"ab\",\"ad\"], \"groups\": [2,3,6,7,3,7,2] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ab\",\"ad\"]\n\ntest_input = { \"n\": 7, \"words\": [\"edded\",\"ab\",\"bc\",\"aeac\",\"ec\",\"db\",\"be\"], \"groups\": [3,2,3,6,3,4,3] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ab\",\"db\"]\n\ntest_input = { \"n\": 8, \"words\": [\"addb\",\"beeddc\",\"dcdce\",\"ddaeed\",\"ddbbb\",\"aeea\",\"adee\",\"dbcbdc\"], \"groups\": [1,5,7,1,5,7,7,4] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"dbcbdc\"]\n\ntest_input = { \"n\": 8, \"words\": [\"ba\",\"cca\",\"dcb\",\"cd\",\"aa\",\"bd\",\"cda\",\"bcb\"], \"groups\": [6,1,2,2,3,7,7,7] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"dcb\",\"bcb\"]\n\ntest_input = { \"n\": 8, \"words\": [\"baa\",\"cb\",\"aab\",\"ddc\",\"bba\",\"cdb\",\"abb\",\"dc\"], \"groups\": [1,8,1,1,8,6,1,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"baa\",\"bba\"]\n\ntest_input = { \"n\": 8, \"words\": [\"bbde\",\"edea\",\"dcd\",\"eebbed\",\"ddab\",\"ae\",\"ec\",\"ade\"], \"groups\": [7,3,2,4,7,3,6,4] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ade\"]\n\ntest_input = { \"n\": 8, \"words\": [\"bc\",\"aa\",\"cb\",\"dd\",\"aaa\",\"ccb\",\"da\",\"bbb\"], \"groups\": [5,4,6,8,6,7,7,6] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"dd\",\"da\"]\n\ntest_input = { \"n\": 8, \"words\": [\"bcc\",\"aac\",\"ac\",\"dd\",\"bdd\",\"ada\",\"bbb\",\"db\"], \"groups\": [7,7,1,7,1,1,6,7] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"db\"]\n\ntest_input = { \"n\": 8, \"words\": [\"cb\",\"dcc\",\"da\",\"cbb\",\"bd\",\"dbc\",\"ab\",\"db\"], \"groups\": [4,5,5,7,8,1,3,4] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"cb\",\"ab\",\"db\"]\n\ntest_input = { \"n\": 8, \"words\": [\"cbaeeb\",\"decd\",\"dbc\",\"cbdcca\",\"acbcbe\",\"adccc\",\"eb\",\"ecbbea\"], \"groups\": [6,7,8,6,3,5,1,7] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ecbbea\"]\n\ntest_input = { \"n\": 8, \"words\": [\"cc\",\"aa\",\"cab\",\"dbc\",\"bbb\",\"adc\",\"cba\",\"cca\"], \"groups\": [6,1,6,6,4,8,1,5] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"cba\",\"cca\"]\n\ntest_input = { \"n\": 8, \"words\": [\"cc\",\"dcd\",\"dac\",\"dc\",\"ac\",\"ad\",\"bbb\",\"cbb\"], \"groups\": [7,7,2,5,4,1,6,2] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"cc\",\"dc\",\"ac\",\"ad\"]\n\ntest_input = { \"n\": 8, \"words\": [\"ccdbdc\",\"dcce\",\"ebedde\",\"ceb\",\"edee\",\"ca\",\"ad\",\"dddee\"], \"groups\": [6,6,3,4,7,1,5,6] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"dddee\"]\n\ntest_input = { \"n\": 8, \"words\": [\"cd\",\"bd\",\"ada\",\"ba\",\"ac\",\"bac\",\"aad\",\"ccb\"], \"groups\": [3,4,8,7,6,7,2,4] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"cd\",\"bd\",\"ba\"]\n\ntest_input = { \"n\": 8, \"words\": [\"da\",\"bd\",\"ccd\",\"dd\",\"ab\",\"cc\",\"aab\",\"ac\"], \"groups\": [6,5,4,8,8,2,2,6] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"cc\",\"ac\"]\n\ntest_input = { \"n\": 8, \"words\": [\"dab\",\"ecedc\",\"badca\",\"cedacb\",\"bdeab\",\"bccedc\",\"bebc\",\"aeade\"], \"groups\": [3,7,6,8,6,6,7,5] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"aeade\"]", "start_time": 1697293800} +{"task_id": "biweekly-contest-115-count-of-sub-multisets-with-bounded-sum", "url": "https://leetcode.com/problems/count-of-sub-multisets-with-bounded-sum", "title": "count-of-sub-multisets-with-bounded-sum", "meta": {"questionId": "3091", "questionFrontendId": "2902", "title": "Count of Sub-Multisets With Bounded Sum", "titleSlug": "count-of-sub-multisets-with-bounded-sum", "isPaidOnly": false, "difficulty": "Hard", "likes": 125, "dislikes": 19, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0 开始的非负整数数组 nums 和两个整数 l 和 r 。\n\n请你返回 nums 中子多重集合的和在闭区间 [l, r] 之间的 子多重集合的数目 。\n\n由于答案可能很大,请你将答案对 109 + 7 取余后返回。\n\n子多重集合 指的是从数组中选出一些元素构成的 无序 集合,每个元素 x 出现的次数可以是 0, 1, ..., occ[x] 次,其中 occ[x] 是元素 x 在数组中的出现次数。\n\n注意:\n\n * 如果两个子多重集合中的元素排序后一模一样,那么它们两个是相同的 子多重集合 。\n * 空 集合的和是 0 。\n\n示例 1:\n\n输入:nums = [1,2,2,3], l = 6, r = 6\n输出:1\n解释:唯一和为 6 的子集合是 {1, 2, 3} 。\n\n示例 2:\n\n输入:nums = [2,1,4,2,7], l = 1, r = 5\n输出:7\n解释:和在闭区间 [1, 5] 之间的子多重集合为 {1} ,{2} ,{4} ,{2, 2} ,{1, 2} ,{1, 4} 和 {1, 2, 2} 。\n\n示例 3:\n\n输入:nums = [1,2,1,3,5,2], l = 3, r = 5\n输出:9\n解释:和在闭区间 [3, 5] 之间的子多重集合为 {3} ,{5} ,{1, 2} ,{1, 3} ,{2, 2} ,{2, 3} ,{1, 1, 2} ,{1, 1, 3} 和 {1, 2, 2} 。\n\n提示:\n\n * 1 <= nums.length <= 2 * 104\n * 0 <= nums[i] <= 2 * 104\n * nums 的和不超过 2 * 104 。\n * 0 <= l <= r <= 2 * 104\n\"\"\"\nclass Solution:\n def countSubMultisets(self, nums: List[int], l: int, r: int) -> int:\n ", "prompt_sft": "给你一个下标从 0 开始的非负整数数组 nums 和两个整数 l 和 r 。\n\n请你返回 nums 中子多重集合的和在闭区间 [l, r] 之间的 子多重集合的数目 。\n\n由于答案可能很大,请你将答案对 109 + 7 取余后返回。\n\n子多重集合 指的是从数组中选出一些元素构成的 无序 集合,每个元素 x 出现的次数可以是 0, 1, ..., occ[x] 次,其中 occ[x] 是元素 x 在数组中的出现次数。\n\n注意:\n\n * 如果两个子多重集合中的元素排序后一模一样,那么它们两个是相同的 子多重集合 。\n * 空 集合的和是 0 。\n\n示例 1:\n\n输入:nums = [1,2,2,3], l = 6, r = 6\n输出:1\n解释:唯一和为 6 的子集合是 {1, 2, 3} 。\n\n示例 2:\n\n输入:nums = [2,1,4,2,7], l = 1, r = 5\n输出:7\n解释:和在闭区间 [1, 5] 之间的子多重集合为 {1} ,{2} ,{4} ,{2, 2} ,{1, 2} ,{1, 4} 和 {1, 2, 2} 。\n\n示例 3:\n\n输入:nums = [1,2,1,3,5,2], l = 3, r = 5\n输出:9\n解释:和在闭区间 [3, 5] 之间的子多重集合为 {3} ,{5} ,{1, 2} ,{1, 3} ,{2, 2} ,{2, 3} ,{1, 1, 2} ,{1, 1, 3} 和 {1, 2, 2} 。\n\n提示:\n\n * 1 <= nums.length <= 2 * 104\n * 0 <= nums[i] <= 2 * 104\n * nums 的和不超过 2 * 104 。\n * 0 <= l <= r <= 2 * 104\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def countSubMultisets(self, nums: List[int], l: int, r: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,2,2,3], \"l\": 6, \"r\": 6 }\nassert my_solution.countSubMultisets(**test_input) == 1\n\ntest_input = { \"nums\": [2,1,4,2,7], \"l\": 1, \"r\": 5 }\nassert my_solution.countSubMultisets(**test_input) == 7\n\ntest_input = { \"nums\": [1,2,1,3,5,2], \"l\": 3, \"r\": 5 }\nassert my_solution.countSubMultisets(**test_input) == 9\n\ntest_input = { \"nums\": [0,0,1,2,3], \"l\": 2, \"r\": 3 }\nassert my_solution.countSubMultisets(**test_input) == 9\n\ntest_input = { \"nums\": [0,0,0,0,0], \"l\": 0, \"r\": 0 }\nassert my_solution.countSubMultisets(**test_input) == 6\n\ntest_input = { \"nums\": [0,0,0,1,2,5,2,3], \"l\": 0, \"r\": 3 }\nassert my_solution.countSubMultisets(**test_input) == 20\n\ntest_input = { \"nums\": [1,1], \"l\": 2, \"r\": 2 }\nassert my_solution.countSubMultisets(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,1], \"l\": 2, \"r\": 2 }\nassert my_solution.countSubMultisets(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,2], \"l\": 2, \"r\": 4 }\nassert my_solution.countSubMultisets(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,1], \"l\": 2, \"r\": 2 }\nassert my_solution.countSubMultisets(**test_input) == 2\n\ntest_input = { \"nums\": [1,2,2], \"l\": 3, \"r\": 5 }\nassert my_solution.countSubMultisets(**test_input) == 3\n\ntest_input = { \"nums\": [2,1,1], \"l\": 1, \"r\": 2 }\nassert my_solution.countSubMultisets(**test_input) == 3\n\ntest_input = { \"nums\": [2,1,2], \"l\": 2, \"r\": 2 }\nassert my_solution.countSubMultisets(**test_input) == 1\n\ntest_input = { \"nums\": [2,2,1], \"l\": 4, \"r\": 5 }\nassert my_solution.countSubMultisets(**test_input) == 2\n\ntest_input = { \"nums\": [2,2,2], \"l\": 3, \"r\": 6 }\nassert my_solution.countSubMultisets(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,1,1], \"l\": 3, \"r\": 3 }\nassert my_solution.countSubMultisets(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,1,2], \"l\": 1, \"r\": 1 }\nassert my_solution.countSubMultisets(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,1,3], \"l\": 4, \"r\": 4 }\nassert my_solution.countSubMultisets(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,2,1], \"l\": 3, \"r\": 4 }\nassert my_solution.countSubMultisets(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,2,2], \"l\": 2, \"r\": 3 }\nassert my_solution.countSubMultisets(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,2,3], \"l\": 4, \"r\": 5 }\nassert my_solution.countSubMultisets(**test_input) == 4\n\ntest_input = { \"nums\": [1,1,3,1], \"l\": 2, \"r\": 3 }\nassert my_solution.countSubMultisets(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,3,2], \"l\": 6, \"r\": 6 }\nassert my_solution.countSubMultisets(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,3,3], \"l\": 8, \"r\": 8 }\nassert my_solution.countSubMultisets(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,1,1], \"l\": 3, \"r\": 3 }\nassert my_solution.countSubMultisets(**test_input) == 2\n\ntest_input = { \"nums\": [1,2,1,2], \"l\": 4, \"r\": 5 }\nassert my_solution.countSubMultisets(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,1,3], \"l\": 4, \"r\": 7 }\nassert my_solution.countSubMultisets(**test_input) == 6\n\ntest_input = { \"nums\": [1,2,2,1], \"l\": 4, \"r\": 5 }\nassert my_solution.countSubMultisets(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,2,2], \"l\": 1, \"r\": 7 }\nassert my_solution.countSubMultisets(**test_input) == 7\n\ntest_input = { \"nums\": [1,2,2,3], \"l\": 3, \"r\": 8 }\nassert my_solution.countSubMultisets(**test_input) == 9\n\ntest_input = { \"nums\": [1,2,3,1], \"l\": 1, \"r\": 4 }\nassert my_solution.countSubMultisets(**test_input) == 7\n\ntest_input = { \"nums\": [1,2,3,2], \"l\": 4, \"r\": 8 }\nassert my_solution.countSubMultisets(**test_input) == 7\n\ntest_input = { \"nums\": [1,2,3,3], \"l\": 6, \"r\": 6 }\nassert my_solution.countSubMultisets(**test_input) == 2\n\ntest_input = { \"nums\": [1,3,1,1], \"l\": 6, \"r\": 6 }\nassert my_solution.countSubMultisets(**test_input) == 1\n\ntest_input = { \"nums\": [1,3,1,2], \"l\": 7, \"r\": 7 }\nassert my_solution.countSubMultisets(**test_input) == 1\n\ntest_input = { \"nums\": [1,3,1,3], \"l\": 5, \"r\": 6 }\nassert my_solution.countSubMultisets(**test_input) == 2\n\ntest_input = { \"nums\": [1,3,2,1], \"l\": 2, \"r\": 2 }\nassert my_solution.countSubMultisets(**test_input) == 2\n\ntest_input = { \"nums\": [1,3,2,2], \"l\": 7, \"r\": 8 }\nassert my_solution.countSubMultisets(**test_input) == 2\n\ntest_input = { \"nums\": [1,3,2,3], \"l\": 1, \"r\": 9 }\nassert my_solution.countSubMultisets(**test_input) == 11\n\ntest_input = { \"nums\": [1,3,3,1], \"l\": 7, \"r\": 7 }\nassert my_solution.countSubMultisets(**test_input) == 1\n\ntest_input = { \"nums\": [1,3,3,2], \"l\": 1, \"r\": 6 }\nassert my_solution.countSubMultisets(**test_input) == 8\n\ntest_input = { \"nums\": [1,3,3,3], \"l\": 9, \"r\": 10 }\nassert my_solution.countSubMultisets(**test_input) == 2\n\ntest_input = { \"nums\": [2,1,1,1], \"l\": 2, \"r\": 3 }\nassert my_solution.countSubMultisets(**test_input) == 4\n\ntest_input = { \"nums\": [2,1,1,2], \"l\": 1, \"r\": 4 }\nassert my_solution.countSubMultisets(**test_input) == 6\n\ntest_input = { \"nums\": [2,1,1,3], \"l\": 7, \"r\": 7 }\nassert my_solution.countSubMultisets(**test_input) == 1\n\ntest_input = { \"nums\": [2,1,2,1], \"l\": 3, \"r\": 3 }\nassert my_solution.countSubMultisets(**test_input) == 1\n\ntest_input = { \"nums\": [2,1,2,2], \"l\": 6, \"r\": 7 }\nassert my_solution.countSubMultisets(**test_input) == 2\n\ntest_input = { \"nums\": [2,1,2,3], \"l\": 7, \"r\": 7 }\nassert my_solution.countSubMultisets(**test_input) == 1\n\ntest_input = { \"nums\": [2,1,3,1], \"l\": 4, \"r\": 4 }\nassert my_solution.countSubMultisets(**test_input) == 2\n\ntest_input = { \"nums\": [2,1,3,2], \"l\": 3, \"r\": 4 }\nassert my_solution.countSubMultisets(**test_input) == 4\n\ntest_input = { \"nums\": [2,1,3,3], \"l\": 1, \"r\": 5 }\nassert my_solution.countSubMultisets(**test_input) == 6\n\ntest_input = { \"nums\": [2,2,1,1], \"l\": 6, \"r\": 6 }\nassert my_solution.countSubMultisets(**test_input) == 1\n\ntest_input = { \"nums\": [2,2,1,2], \"l\": 2, \"r\": 4 }\nassert my_solution.countSubMultisets(**test_input) == 3\n\ntest_input = { \"nums\": [2,2,1,3], \"l\": 6, \"r\": 8 }\nassert my_solution.countSubMultisets(**test_input) == 3\n\ntest_input = { \"nums\": [2,2,2,1], \"l\": 4, \"r\": 7 }\nassert my_solution.countSubMultisets(**test_input) == 4\n\ntest_input = { \"nums\": [2,2,2,2], \"l\": 3, \"r\": 7 }\nassert my_solution.countSubMultisets(**test_input) == 2\n\ntest_input = { \"nums\": [2,2,2,3], \"l\": 5, \"r\": 6 }\nassert my_solution.countSubMultisets(**test_input) == 2\n\ntest_input = { \"nums\": [2,2,3,1], \"l\": 7, \"r\": 7 }\nassert my_solution.countSubMultisets(**test_input) == 1\n\ntest_input = { \"nums\": [2,2,3,2], \"l\": 5, \"r\": 9 }\nassert my_solution.countSubMultisets(**test_input) == 4\n\ntest_input = { \"nums\": [2,2,3,3], \"l\": 4, \"r\": 10 }\nassert my_solution.countSubMultisets(**test_input) == 6\n\ntest_input = { \"nums\": [2,3,1,1], \"l\": 4, \"r\": 6 }\nassert my_solution.countSubMultisets(**test_input) == 5\n\ntest_input = { \"nums\": [2,3,1,2], \"l\": 3, \"r\": 4 }\nassert my_solution.countSubMultisets(**test_input) == 4\n\ntest_input = { \"nums\": [2,3,1,3], \"l\": 2, \"r\": 8 }\nassert my_solution.countSubMultisets(**test_input) == 9\n\ntest_input = { \"nums\": [2,3,2,1], \"l\": 3, \"r\": 3 }\nassert my_solution.countSubMultisets(**test_input) == 2\n\ntest_input = { \"nums\": [2,3,2,2], \"l\": 3, \"r\": 3 }\nassert my_solution.countSubMultisets(**test_input) == 1\n\ntest_input = { \"nums\": [2,3,2,3], \"l\": 5, \"r\": 6 }\nassert my_solution.countSubMultisets(**test_input) == 2\n\ntest_input = { \"nums\": [2,3,3,1], \"l\": 9, \"r\": 9 }\nassert my_solution.countSubMultisets(**test_input) == 1\n\ntest_input = { \"nums\": [2,3,3,2], \"l\": 8, \"r\": 8 }\nassert my_solution.countSubMultisets(**test_input) == 1\n\ntest_input = { \"nums\": [2,3,3,3], \"l\": 3, \"r\": 5 }\nassert my_solution.countSubMultisets(**test_input) == 2\n\ntest_input = { \"nums\": [3,1,1,1], \"l\": 4, \"r\": 4 }\nassert my_solution.countSubMultisets(**test_input) == 1\n\ntest_input = { \"nums\": [3,1,1,2], \"l\": 7, \"r\": 7 }\nassert my_solution.countSubMultisets(**test_input) == 1\n\ntest_input = { \"nums\": [3,1,1,3], \"l\": 1, \"r\": 1 }\nassert my_solution.countSubMultisets(**test_input) == 1\n\ntest_input = { \"nums\": [3,1,2,1], \"l\": 4, \"r\": 4 }\nassert my_solution.countSubMultisets(**test_input) == 2\n\ntest_input = { \"nums\": [3,1,2,2], \"l\": 3, \"r\": 8 }\nassert my_solution.countSubMultisets(**test_input) == 9\n\ntest_input = { \"nums\": [3,1,2,3], \"l\": 5, \"r\": 9 }\nassert my_solution.countSubMultisets(**test_input) == 6\n\ntest_input = { \"nums\": [3,1,3,1], \"l\": 1, \"r\": 4 }\nassert my_solution.countSubMultisets(**test_input) == 4\n\ntest_input = { \"nums\": [3,1,3,2], \"l\": 3, \"r\": 5 }\nassert my_solution.countSubMultisets(**test_input) == 4\n\ntest_input = { \"nums\": [3,1,3,3], \"l\": 9, \"r\": 10 }\nassert my_solution.countSubMultisets(**test_input) == 2\n\ntest_input = { \"nums\": [3,2,1,1], \"l\": 1, \"r\": 5 }\nassert my_solution.countSubMultisets(**test_input) == 9\n\ntest_input = { \"nums\": [3,2,1,2], \"l\": 1, \"r\": 6 }\nassert my_solution.countSubMultisets(**test_input) == 9\n\ntest_input = { \"nums\": [3,2,1,3], \"l\": 5, \"r\": 7 }\nassert my_solution.countSubMultisets(**test_input) == 4\n\ntest_input = { \"nums\": [3,2,2,1], \"l\": 4, \"r\": 4 }\nassert my_solution.countSubMultisets(**test_input) == 2\n\ntest_input = { \"nums\": [3,2,2,2], \"l\": 6, \"r\": 7 }\nassert my_solution.countSubMultisets(**test_input) == 2\n\ntest_input = { \"nums\": [3,2,2,3], \"l\": 2, \"r\": 7 }\nassert my_solution.countSubMultisets(**test_input) == 6\n\ntest_input = { \"nums\": [3,2,3,1], \"l\": 2, \"r\": 3 }\nassert my_solution.countSubMultisets(**test_input) == 3\n\ntest_input = { \"nums\": [3,2,3,2], \"l\": 8, \"r\": 10 }\nassert my_solution.countSubMultisets(**test_input) == 2\n\ntest_input = { \"nums\": [3,2,3,3], \"l\": 1, \"r\": 11 }\nassert my_solution.countSubMultisets(**test_input) == 7\n\ntest_input = { \"nums\": [3,3,1,1], \"l\": 8, \"r\": 8 }\nassert my_solution.countSubMultisets(**test_input) == 1\n\ntest_input = { \"nums\": [3,3,1,2], \"l\": 2, \"r\": 5 }\nassert my_solution.countSubMultisets(**test_input) == 5\n\ntest_input = { \"nums\": [3,3,1,3], \"l\": 1, \"r\": 7 }\nassert my_solution.countSubMultisets(**test_input) == 5\n\ntest_input = { \"nums\": [3,3,2,1], \"l\": 4, \"r\": 6 }\nassert my_solution.countSubMultisets(**test_input) == 4\n\ntest_input = { \"nums\": [3,3,2,2], \"l\": 7, \"r\": 10 }\nassert my_solution.countSubMultisets(**test_input) == 3\n\ntest_input = { \"nums\": [3,3,2,3], \"l\": 4, \"r\": 10 }\nassert my_solution.countSubMultisets(**test_input) == 4\n\ntest_input = { \"nums\": [3,3,3,1], \"l\": 6, \"r\": 9 }\nassert my_solution.countSubMultisets(**test_input) == 3\n\ntest_input = { \"nums\": [3,3,3,2], \"l\": 11, \"r\": 11 }\nassert my_solution.countSubMultisets(**test_input) == 1\n\ntest_input = { \"nums\": [3,3,3,3], \"l\": 8, \"r\": 9 }\nassert my_solution.countSubMultisets(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,1,1,1], \"l\": 3, \"r\": 5 }\nassert my_solution.countSubMultisets(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,1,1,2], \"l\": 2, \"r\": 5 }\nassert my_solution.countSubMultisets(**test_input) == 7\n\ntest_input = { \"nums\": [1,1,1,1,3], \"l\": 6, \"r\": 7 }\nassert my_solution.countSubMultisets(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,1,1,4], \"l\": 8, \"r\": 8 }\nassert my_solution.countSubMultisets(**test_input) == 1", "start_time": 1697293800} +{"task_id": "weekly-contest-366-divisible-and-non-divisible-sums-difference", "url": "https://leetcode.com/problems/divisible-and-non-divisible-sums-difference", "title": "divisible-and-non-divisible-sums-difference", "meta": {"questionId": "3172", "questionFrontendId": "2894", "title": "Divisible and Non-divisible Sums Difference", "titleSlug": "divisible-and-non-divisible-sums-difference", "isPaidOnly": false, "difficulty": "Easy", "likes": 115, "dislikes": 10, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你两个正整数 n 和 m 。\n\n现定义两个整数 num1 和 num2 ,如下所示:\n\n * num1:范围 [1, n] 内所有 无法被 m 整除 的整数之和。\n * num2:范围 [1, n] 内所有 能够被 m 整除 的整数之和。\n\n返回整数 num1 - num2 。\n\n示例 1:\n\n输入:n = 10, m = 3\n输出:19\n解释:在这个示例中:\n- 范围 [1, 10] 内无法被 3 整除的整数为 [1,2,4,5,7,8,10] ,num1 = 这些整数之和 = 37 。\n- 范围 [1, 10] 内能够被 3 整除的整数为 [3,6,9] ,num2 = 这些整数之和 = 18 。\n返回 37 - 18 = 19 作为答案。\n\n示例 2:\n\n输入:n = 5, m = 6\n输出:15\n解释:在这个示例中:\n- 范围 [1, 5] 内无法被 6 整除的整数为 [1,2,3,4,5] ,num1 = 这些整数之和 = 15 。\n- 范围 [1, 5] 内能够被 6 整除的整数为 [] ,num2 = 这些整数之和 = 0 。\n返回 15 - 0 = 15 作为答案。\n\n示例 3:\n\n输入:n = 5, m = 1\n输出:-15\n解释:在这个示例中:\n- 范围 [1, 5] 内无法被 1 整除的整数为 [] ,num1 = 这些整数之和 = 0 。\n- 范围 [1, 5] 内能够被 1 整除的整数为 [1,2,3,4,5] ,num2 = 这些整数之和 = 15 。\n返回 0 - 15 = -15 作为答案。\n\n\n提示:\n\n * 1 <= n, m <= 1000\n\"\"\"\nclass Solution:\n def differenceOfSums(self, n: int, m: int) -> int:\n ", "prompt_sft": "给你两个正整数 n 和 m 。\n\n现定义两个整数 num1 和 num2 ,如下所示:\n\n * num1:范围 [1, n] 内所有 无法被 m 整除 的整数之和。\n * num2:范围 [1, n] 内所有 能够被 m 整除 的整数之和。\n\n返回整数 num1 - num2 。\n\n示例 1:\n\n输入:n = 10, m = 3\n输出:19\n解释:在这个示例中:\n- 范围 [1, 10] 内无法被 3 整除的整数为 [1,2,4,5,7,8,10] ,num1 = 这些整数之和 = 37 。\n- 范围 [1, 10] 内能够被 3 整除的整数为 [3,6,9] ,num2 = 这些整数之和 = 18 。\n返回 37 - 18 = 19 作为答案。\n\n示例 2:\n\n输入:n = 5, m = 6\n输出:15\n解释:在这个示例中:\n- 范围 [1, 5] 内无法被 6 整除的整数为 [1,2,3,4,5] ,num1 = 这些整数之和 = 15 。\n- 范围 [1, 5] 内能够被 6 整除的整数为 [] ,num2 = 这些整数之和 = 0 。\n返回 15 - 0 = 15 作为答案。\n\n示例 3:\n\n输入:n = 5, m = 1\n输出:-15\n解释:在这个示例中:\n- 范围 [1, 5] 内无法被 1 整除的整数为 [] ,num1 = 这些整数之和 = 0 。\n- 范围 [1, 5] 内能够被 1 整除的整数为 [1,2,3,4,5] ,num2 = 这些整数之和 = 15 。\n返回 0 - 15 = -15 作为答案。\n\n\n提示:\n\n * 1 <= n, m <= 1000\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def differenceOfSums(self, n: int, m: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"n\": 10, \"m\": 3 }\nassert my_solution.differenceOfSums(**test_input) == 19\n\ntest_input = { \"n\": 5, \"m\": 6 }\nassert my_solution.differenceOfSums(**test_input) == 15\n\ntest_input = { \"n\": 5, \"m\": 1 }\nassert my_solution.differenceOfSums(**test_input) == -15\n\ntest_input = { \"n\": 15, \"m\": 9 }\nassert my_solution.differenceOfSums(**test_input) == 102\n\ntest_input = { \"n\": 8, \"m\": 10 }\nassert my_solution.differenceOfSums(**test_input) == 36\n\ntest_input = { \"n\": 23, \"m\": 36 }\nassert my_solution.differenceOfSums(**test_input) == 276\n\ntest_input = { \"n\": 1, \"m\": 32 }\nassert my_solution.differenceOfSums(**test_input) == 1\n\ntest_input = { \"n\": 36, \"m\": 7 }\nassert my_solution.differenceOfSums(**test_input) == 456\n\ntest_input = { \"n\": 3, \"m\": 8 }\nassert my_solution.differenceOfSums(**test_input) == 6\n\ntest_input = { \"n\": 4, \"m\": 2 }\nassert my_solution.differenceOfSums(**test_input) == -2\n\ntest_input = { \"n\": 9, \"m\": 7 }\nassert my_solution.differenceOfSums(**test_input) == 31\n\ntest_input = { \"n\": 20, \"m\": 9 }\nassert my_solution.differenceOfSums(**test_input) == 156\n\ntest_input = { \"n\": 3, \"m\": 19 }\nassert my_solution.differenceOfSums(**test_input) == 6\n\ntest_input = { \"n\": 6, \"m\": 16 }\nassert my_solution.differenceOfSums(**test_input) == 21\n\ntest_input = { \"n\": 6, \"m\": 1 }\nassert my_solution.differenceOfSums(**test_input) == -21\n\ntest_input = { \"n\": 5, \"m\": 25 }\nassert my_solution.differenceOfSums(**test_input) == 15\n\ntest_input = { \"n\": 9, \"m\": 3 }\nassert my_solution.differenceOfSums(**test_input) == 9\n\ntest_input = { \"n\": 8, \"m\": 23 }\nassert my_solution.differenceOfSums(**test_input) == 36\n\ntest_input = { \"n\": 17, \"m\": 1 }\nassert my_solution.differenceOfSums(**test_input) == -153\n\ntest_input = { \"n\": 18, \"m\": 9 }\nassert my_solution.differenceOfSums(**test_input) == 117\n\ntest_input = { \"n\": 22, \"m\": 30 }\nassert my_solution.differenceOfSums(**test_input) == 253\n\ntest_input = { \"n\": 1, \"m\": 42 }\nassert my_solution.differenceOfSums(**test_input) == 1\n\ntest_input = { \"n\": 33, \"m\": 19 }\nassert my_solution.differenceOfSums(**test_input) == 523\n\ntest_input = { \"n\": 7, \"m\": 19 }\nassert my_solution.differenceOfSums(**test_input) == 28\n\ntest_input = { \"n\": 12, \"m\": 24 }\nassert my_solution.differenceOfSums(**test_input) == 78\n\ntest_input = { \"n\": 26, \"m\": 25 }\nassert my_solution.differenceOfSums(**test_input) == 301\n\ntest_input = { \"n\": 9, \"m\": 16 }\nassert my_solution.differenceOfSums(**test_input) == 45\n\ntest_input = { \"n\": 1, \"m\": 8 }\nassert my_solution.differenceOfSums(**test_input) == 1\n\ntest_input = { \"n\": 29, \"m\": 42 }\nassert my_solution.differenceOfSums(**test_input) == 435\n\ntest_input = { \"n\": 2, \"m\": 11 }\nassert my_solution.differenceOfSums(**test_input) == 3\n\ntest_input = { \"n\": 36, \"m\": 10 }\nassert my_solution.differenceOfSums(**test_input) == 546\n\ntest_input = { \"n\": 45, \"m\": 4 }\nassert my_solution.differenceOfSums(**test_input) == 507\n\ntest_input = { \"n\": 3, \"m\": 7 }\nassert my_solution.differenceOfSums(**test_input) == 6\n\ntest_input = { \"n\": 6, \"m\": 12 }\nassert my_solution.differenceOfSums(**test_input) == 21\n\ntest_input = { \"n\": 3, \"m\": 4 }\nassert my_solution.differenceOfSums(**test_input) == 6\n\ntest_input = { \"n\": 8, \"m\": 28 }\nassert my_solution.differenceOfSums(**test_input) == 36\n\ntest_input = { \"n\": 18, \"m\": 23 }\nassert my_solution.differenceOfSums(**test_input) == 171\n\ntest_input = { \"n\": 11, \"m\": 6 }\nassert my_solution.differenceOfSums(**test_input) == 54\n\ntest_input = { \"n\": 35, \"m\": 10 }\nassert my_solution.differenceOfSums(**test_input) == 510\n\ntest_input = { \"n\": 29, \"m\": 18 }\nassert my_solution.differenceOfSums(**test_input) == 399\n\ntest_input = { \"n\": 1, \"m\": 1 }\nassert my_solution.differenceOfSums(**test_input) == -1\n\ntest_input = { \"n\": 12, \"m\": 8 }\nassert my_solution.differenceOfSums(**test_input) == 62\n\ntest_input = { \"n\": 7, \"m\": 12 }\nassert my_solution.differenceOfSums(**test_input) == 28\n\ntest_input = { \"n\": 17, \"m\": 3 }\nassert my_solution.differenceOfSums(**test_input) == 63\n\ntest_input = { \"n\": 16, \"m\": 15 }\nassert my_solution.differenceOfSums(**test_input) == 106\n\ntest_input = { \"n\": 18, \"m\": 3 }\nassert my_solution.differenceOfSums(**test_input) == 45\n\ntest_input = { \"n\": 4, \"m\": 12 }\nassert my_solution.differenceOfSums(**test_input) == 10\n\ntest_input = { \"n\": 3, \"m\": 21 }\nassert my_solution.differenceOfSums(**test_input) == 6\n\ntest_input = { \"n\": 15, \"m\": 4 }\nassert my_solution.differenceOfSums(**test_input) == 72\n\ntest_input = { \"n\": 9, \"m\": 39 }\nassert my_solution.differenceOfSums(**test_input) == 45\n\ntest_input = { \"n\": 19, \"m\": 18 }\nassert my_solution.differenceOfSums(**test_input) == 154\n\ntest_input = { \"n\": 2, \"m\": 4 }\nassert my_solution.differenceOfSums(**test_input) == 3\n\ntest_input = { \"n\": 41, \"m\": 1 }\nassert my_solution.differenceOfSums(**test_input) == -861\n\ntest_input = { \"n\": 3, \"m\": 1 }\nassert my_solution.differenceOfSums(**test_input) == -6\n\ntest_input = { \"n\": 16, \"m\": 13 }\nassert my_solution.differenceOfSums(**test_input) == 110\n\ntest_input = { \"n\": 32, \"m\": 10 }\nassert my_solution.differenceOfSums(**test_input) == 408\n\ntest_input = { \"n\": 41, \"m\": 34 }\nassert my_solution.differenceOfSums(**test_input) == 793\n\ntest_input = { \"n\": 33, \"m\": 40 }\nassert my_solution.differenceOfSums(**test_input) == 561\n\ntest_input = { \"n\": 36, \"m\": 8 }\nassert my_solution.differenceOfSums(**test_input) == 506\n\ntest_input = { \"n\": 8, \"m\": 34 }\nassert my_solution.differenceOfSums(**test_input) == 36\n\ntest_input = { \"n\": 40, \"m\": 12 }\nassert my_solution.differenceOfSums(**test_input) == 676\n\ntest_input = { \"n\": 28, \"m\": 9 }\nassert my_solution.differenceOfSums(**test_input) == 298\n\ntest_input = { \"n\": 20, \"m\": 6 }\nassert my_solution.differenceOfSums(**test_input) == 138\n\ntest_input = { \"n\": 13, \"m\": 6 }\nassert my_solution.differenceOfSums(**test_input) == 55\n\ntest_input = { \"n\": 2, \"m\": 37 }\nassert my_solution.differenceOfSums(**test_input) == 3\n\ntest_input = { \"n\": 14, \"m\": 17 }\nassert my_solution.differenceOfSums(**test_input) == 105\n\ntest_input = { \"n\": 35, \"m\": 4 }\nassert my_solution.differenceOfSums(**test_input) == 342\n\ntest_input = { \"n\": 2, \"m\": 14 }\nassert my_solution.differenceOfSums(**test_input) == 3\n\ntest_input = { \"n\": 5, \"m\": 2 }\nassert my_solution.differenceOfSums(**test_input) == 3\n\ntest_input = { \"n\": 7, \"m\": 7 }\nassert my_solution.differenceOfSums(**test_input) == 14\n\ntest_input = { \"n\": 12, \"m\": 26 }\nassert my_solution.differenceOfSums(**test_input) == 78\n\ntest_input = { \"n\": 14, \"m\": 1 }\nassert my_solution.differenceOfSums(**test_input) == -105\n\ntest_input = { \"n\": 2, \"m\": 1 }\nassert my_solution.differenceOfSums(**test_input) == -3\n\ntest_input = { \"n\": 20, \"m\": 3 }\nassert my_solution.differenceOfSums(**test_input) == 84\n\ntest_input = { \"n\": 8, \"m\": 27 }\nassert my_solution.differenceOfSums(**test_input) == 36\n\ntest_input = { \"n\": 1, \"m\": 12 }\nassert my_solution.differenceOfSums(**test_input) == 1\n\ntest_input = { \"n\": 13, \"m\": 19 }\nassert my_solution.differenceOfSums(**test_input) == 91\n\ntest_input = { \"n\": 7, \"m\": 1 }\nassert my_solution.differenceOfSums(**test_input) == -28\n\ntest_input = { \"n\": 31, \"m\": 4 }\nassert my_solution.differenceOfSums(**test_input) == 272\n\ntest_input = { \"n\": 11, \"m\": 25 }\nassert my_solution.differenceOfSums(**test_input) == 66\n\ntest_input = { \"n\": 5, \"m\": 19 }\nassert my_solution.differenceOfSums(**test_input) == 15\n\ntest_input = { \"n\": 33, \"m\": 12 }\nassert my_solution.differenceOfSums(**test_input) == 489\n\ntest_input = { \"n\": 4, \"m\": 26 }\nassert my_solution.differenceOfSums(**test_input) == 10\n\ntest_input = { \"n\": 1, \"m\": 24 }\nassert my_solution.differenceOfSums(**test_input) == 1\n\ntest_input = { \"n\": 13, \"m\": 20 }\nassert my_solution.differenceOfSums(**test_input) == 91\n\ntest_input = { \"n\": 6, \"m\": 8 }\nassert my_solution.differenceOfSums(**test_input) == 21\n\ntest_input = { \"n\": 8, \"m\": 26 }\nassert my_solution.differenceOfSums(**test_input) == 36\n\ntest_input = { \"n\": 4, \"m\": 1 }\nassert my_solution.differenceOfSums(**test_input) == -10\n\ntest_input = { \"n\": 1, \"m\": 6 }\nassert my_solution.differenceOfSums(**test_input) == 1\n\ntest_input = { \"n\": 2, \"m\": 25 }\nassert my_solution.differenceOfSums(**test_input) == 3\n\ntest_input = { \"n\": 4, \"m\": 4 }\nassert my_solution.differenceOfSums(**test_input) == 2\n\ntest_input = { \"n\": 8, \"m\": 2 }\nassert my_solution.differenceOfSums(**test_input) == -4\n\ntest_input = { \"n\": 15, \"m\": 21 }\nassert my_solution.differenceOfSums(**test_input) == 120\n\ntest_input = { \"n\": 1, \"m\": 2 }\nassert my_solution.differenceOfSums(**test_input) == 1\n\ntest_input = { \"n\": 12, \"m\": 2 }\nassert my_solution.differenceOfSums(**test_input) == -6\n\ntest_input = { \"n\": 40, \"m\": 14 }\nassert my_solution.differenceOfSums(**test_input) == 736\n\ntest_input = { \"n\": 14, \"m\": 19 }\nassert my_solution.differenceOfSums(**test_input) == 105\n\ntest_input = { \"n\": 18, \"m\": 1 }\nassert my_solution.differenceOfSums(**test_input) == -171\n\ntest_input = { \"n\": 1, \"m\": 28 }\nassert my_solution.differenceOfSums(**test_input) == 1\n\ntest_input = { \"n\": 31, \"m\": 18 }\nassert my_solution.differenceOfSums(**test_input) == 460", "start_time": 1696732200} +{"task_id": "weekly-contest-366-minimum-processing-time", "url": "https://leetcode.com/problems/minimum-processing-time", "title": "minimum-processing-time", "meta": {"questionId": "3151", "questionFrontendId": "2895", "title": "Minimum Processing Time", "titleSlug": "minimum-processing-time", "isPaidOnly": false, "difficulty": "Medium", "likes": 119, "dislikes": 22, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n你有 n 颗处理器,每颗处理器都有 4 个核心。现有 n * 4 个待执行任务,每个核心只执行 一个 任务。\n\n给你一个下标从 0 开始的整数数组 processorTime ,表示每颗处理器最早空闲时间。另给你一个下标从 0 开始的整数数组 tasks ,表示执行每个任务所需的时间。返回所有任务都执行完毕需要的 最小时间 。\n\n注意:每个核心独立执行任务。\n\n示例 1:\n\n输入:processorTime = [8,10], tasks = [2,2,3,1,8,7,4,5]\n输出:16\n解释:\n最优的方案是将下标为 4, 5, 6, 7 的任务分配给第一颗处理器(最早空闲时间 time = 8),下标为 0, 1, 2, 3 的任务分配给第二颗处理器(最早空闲时间 time = 10)。\n第一颗处理器执行完所有任务需要花费的时间 = max(8 + 8, 8 + 7, 8 + 4, 8 + 5) = 16 。\n第二颗处理器执行完所有任务需要花费的时间 = max(10 + 2, 10 + 2, 10 + 3, 10 + 1) = 13 。\n因此,可以证明执行完所有任务需要花费的最小时间是 16 。\n\n示例 2:\n\n输入:processorTime = [10,20], tasks = [2,3,1,2,5,8,4,3]\n输出:23\n解释:\n最优的方案是将下标为 1, 4, 5, 6 的任务分配给第一颗处理器(最早空闲时间 time = 10),下标为 0, 2, 3, 7 的任务分配给第二颗处理器(最早空闲时间 time = 20)。\n第一颗处理器执行完所有任务需要花费的时间 = max(10 + 3, 10 + 5, 10 + 8, 10 + 4) = 18 。\n第二颗处理器执行完所有任务需要花费的时间 = max(20 + 2, 20 + 1, 20 + 2, 20 + 3) = 23 。\n因此,可以证明执行完所有任务需要花费的最小时间是 23 。\n\n\n提示:\n\n * 1 <= n == processorTime.length <= 25000\n * 1 <= tasks.length <= 105\n * 0 <= processorTime[i] <= 109\n * 1 <= tasks[i] <= 109\n * tasks.length == 4 * n\n\"\"\"\nclass Solution:\n def minProcessingTime(self, processorTime: List[int], tasks: List[int]) -> int:\n ", "prompt_sft": "你有 n 颗处理器,每颗处理器都有 4 个核心。现有 n * 4 个待执行任务,每个核心只执行 一个 任务。\n\n给你一个下标从 0 开始的整数数组 processorTime ,表示每颗处理器最早空闲时间。另给你一个下标从 0 开始的整数数组 tasks ,表示执行每个任务所需的时间。返回所有任务都执行完毕需要的 最小时间 。\n\n注意:每个核心独立执行任务。\n\n示例 1:\n\n输入:processorTime = [8,10], tasks = [2,2,3,1,8,7,4,5]\n输出:16\n解释:\n最优的方案是将下标为 4, 5, 6, 7 的任务分配给第一颗处理器(最早空闲时间 time = 8),下标为 0, 1, 2, 3 的任务分配给第二颗处理器(最早空闲时间 time = 10)。\n第一颗处理器执行完所有任务需要花费的时间 = max(8 + 8, 8 + 7, 8 + 4, 8 + 5) = 16 。\n第二颗处理器执行完所有任务需要花费的时间 = max(10 + 2, 10 + 2, 10 + 3, 10 + 1) = 13 。\n因此,可以证明执行完所有任务需要花费的最小时间是 16 。\n\n示例 2:\n\n输入:processorTime = [10,20], tasks = [2,3,1,2,5,8,4,3]\n输出:23\n解释:\n最优的方案是将下标为 1, 4, 5, 6 的任务分配给第一颗处理器(最早空闲时间 time = 10),下标为 0, 2, 3, 7 的任务分配给第二颗处理器(最早空闲时间 time = 20)。\n第一颗处理器执行完所有任务需要花费的时间 = max(10 + 3, 10 + 5, 10 + 8, 10 + 4) = 18 。\n第二颗处理器执行完所有任务需要花费的时间 = max(20 + 2, 20 + 1, 20 + 2, 20 + 3) = 23 。\n因此,可以证明执行完所有任务需要花费的最小时间是 23 。\n\n\n提示:\n\n * 1 <= n == processorTime.length <= 25000\n * 1 <= tasks.length <= 105\n * 0 <= processorTime[i] <= 109\n * 1 <= tasks[i] <= 109\n * tasks.length == 4 * n\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def minProcessingTime(self, processorTime: List[int], tasks: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"processorTime\": [8,10], \"tasks\": [2,2,3,1,8,7,4,5] }\nassert my_solution.minProcessingTime(**test_input) == 16\n\ntest_input = { \"processorTime\": [10,20], \"tasks\": [2,3,1,2,5,8,4,3] }\nassert my_solution.minProcessingTime(**test_input) == 23\n\ntest_input = { \"processorTime\": [121,99], \"tasks\": [287,315,293,260,333,362,69,233] }\nassert my_solution.minProcessingTime(**test_input) == 461\n\ntest_input = { \"processorTime\": [33,320], \"tasks\": [132,68,232,166,30,300,112,138] }\nassert my_solution.minProcessingTime(**test_input) == 452\n\ntest_input = { \"processorTime\": [50,82], \"tasks\": [288,138,205,295,367,100,258,308] }\nassert my_solution.minProcessingTime(**test_input) == 417\n\ntest_input = { \"processorTime\": [291], \"tasks\": [125,169,269,32] }\nassert my_solution.minProcessingTime(**test_input) == 560\n\ntest_input = { \"processorTime\": [55,350,166,210,389], \"tasks\": [276,253,157,237,92,396,331,19,82,301,136,396,251,92,280,70,253,47,81,84] }\nassert my_solution.minProcessingTime(**test_input) == 470\n\ntest_input = { \"processorTime\": [143,228,349,231,392], \"tasks\": [102,365,363,211,38,96,98,79,365,289,252,201,259,346,21,68,128,56,167,183] }\nassert my_solution.minProcessingTime(**test_input) == 517\n\ntest_input = { \"processorTime\": [168,32,299,303,96], \"tasks\": [382,183,337,73,115,350,6,18,93,238,102,302,96,381,327,385,387,288,138,83] }\nassert my_solution.minProcessingTime(**test_input) == 456\n\ntest_input = { \"processorTime\": [324,117,374,219,303], \"tasks\": [374,202,328,11,353,208,383,287,107,236,226,387,21,183,352,164,207,182,15,65] }\nassert my_solution.minProcessingTime(**test_input) == 571\n\ntest_input = { \"processorTime\": [376], \"tasks\": [21,247,274,38] }\nassert my_solution.minProcessingTime(**test_input) == 650\n\ntest_input = { \"processorTime\": [93,3,281,218], \"tasks\": [182,16,241,312,81,339,207,330,306,166,82,290,7,317,396,389] }\nassert my_solution.minProcessingTime(**test_input) == 459\n\ntest_input = { \"processorTime\": [374,250,197,170], \"tasks\": [247,56,330,361,240,261,67,65,138,181,308,26,59,150,137,244] }\nassert my_solution.minProcessingTime(**test_input) == 531\n\ntest_input = { \"processorTime\": [115,271,137], \"tasks\": [34,72,328,312,159,32,283,6,234,280,46,349] }\nassert my_solution.minProcessingTime(**test_input) == 464\n\ntest_input = { \"processorTime\": [47,217,349,233,283], \"tasks\": [195,188,181,259,145,96,298,322,213,154,278,292,315,191,177,228,291,204,310,266] }\nassert my_solution.minProcessingTime(**test_input) == 526\n\ntest_input = { \"processorTime\": [177,6,326,318,294], \"tasks\": [136,215,260,259,35,248,340,377,144,248,83,150,63,48,269,197,317,135,36,344] }\nassert my_solution.minProcessingTime(**test_input) == 542\n\ntest_input = { \"processorTime\": [266,372], \"tasks\": [260,325,159,316,296,366,335,146] }\nassert my_solution.minProcessingTime(**test_input) == 668\n\ntest_input = { \"processorTime\": [63,339], \"tasks\": [79,316,98,354,220,267,333,11] }\nassert my_solution.minProcessingTime(**test_input) == 559\n\ntest_input = { \"processorTime\": [149,60,172,5,212], \"tasks\": [230,374,276,281,55,96,52,83,56,399,69,333,145,6,50,101,216,327,120,209] }\nassert my_solution.minProcessingTime(**test_input) == 404\n\ntest_input = { \"processorTime\": [220,375,285,267,150], \"tasks\": [53,317,367,258,337,280,232,322,153,169,121,211,171,345,76,370,265,107,45,320] }\nassert my_solution.minProcessingTime(**test_input) == 542\n\ntest_input = { \"processorTime\": [373,367,267], \"tasks\": [214,221,78,330,340,309,330,338,396,337,285,207] }\nassert my_solution.minProcessingTime(**test_input) == 697\n\ntest_input = { \"processorTime\": [92,20], \"tasks\": [11,354,399,11,20,9,217,372] }\nassert my_solution.minProcessingTime(**test_input) == 419\n\ntest_input = { \"processorTime\": [51], \"tasks\": [349,186,191,183] }\nassert my_solution.minProcessingTime(**test_input) == 400\n\ntest_input = { \"processorTime\": [362,220,10,219], \"tasks\": [160,369,385,145,122,124,147,231,162,37,293,160,68,232,232,130] }\nassert my_solution.minProcessingTime(**test_input) == 486\n\ntest_input = { \"processorTime\": [210,348,3,57,174], \"tasks\": [328,296,222,161,190,381,283,137,353,227,284,134,170,13,275,113,148,198,33,260] }\nassert my_solution.minProcessingTime(**test_input) == 482\n\ntest_input = { \"processorTime\": [153], \"tasks\": [342,166,234,175] }\nassert my_solution.minProcessingTime(**test_input) == 495\n\ntest_input = { \"processorTime\": [23,204,114,380,3], \"tasks\": [40,105,311,221,247,34,399,190,23,289,16,129,68,12,32,364,364,111,361,49] }\nassert my_solution.minProcessingTime(**test_input) == 412\n\ntest_input = { \"processorTime\": [167,110,221,19,211], \"tasks\": [140,351,307,4,262,228,161,200,108,206,280,266,240,258,396,194,333,328,121,179] }\nassert my_solution.minProcessingTime(**test_input) == 425\n\ntest_input = { \"processorTime\": [179,127,280,242], \"tasks\": [244,243,92,188,134,84,22,258,100,77,237,83,41,396,218,87] }\nassert my_solution.minProcessingTime(**test_input) == 523\n\ntest_input = { \"processorTime\": [45,249,396,163], \"tasks\": [131,365,52,366,229,340,242,371,20,181,103,97,141,106,46,119] }\nassert my_solution.minProcessingTime(**test_input) == 493\n\ntest_input = { \"processorTime\": [205], \"tasks\": [117,63,174,87] }\nassert my_solution.minProcessingTime(**test_input) == 379\n\ntest_input = { \"processorTime\": [128,101,302,53], \"tasks\": [265,96,358,287,148,117,331,47,173,347,62,145,73,47,206,29] }\nassert my_solution.minProcessingTime(**test_input) == 411\n\ntest_input = { \"processorTime\": [228], \"tasks\": [321,378,268,351] }\nassert my_solution.minProcessingTime(**test_input) == 606\n\ntest_input = { \"processorTime\": [136,22,229,187], \"tasks\": [246,326,188,341,375,207,334,1,189,301,62,39,44,239,346,376] }\nassert my_solution.minProcessingTime(**test_input) == 470\n\ntest_input = { \"processorTime\": [47,238,274], \"tasks\": [251,312,87,111,142,62,112,325,305,164,85,338] }\nassert my_solution.minProcessingTime(**test_input) == 489\n\ntest_input = { \"processorTime\": [386,121,249], \"tasks\": [5,376,53,187,287,369,400,178,293,121,164,336] }\nassert my_solution.minProcessingTime(**test_input) == 550\n\ntest_input = { \"processorTime\": [82,152], \"tasks\": [82,46,149,255,225,93,227,131] }\nassert my_solution.minProcessingTime(**test_input) == 337\n\ntest_input = { \"processorTime\": [394,6], \"tasks\": [231,236,288,35,247,204,141,41] }\nassert my_solution.minProcessingTime(**test_input) == 598\n\ntest_input = { \"processorTime\": [389,54], \"tasks\": [353,358,211,133,225,358,19,310] }\nassert my_solution.minProcessingTime(**test_input) == 614\n\ntest_input = { \"processorTime\": [106,291,291,301], \"tasks\": [192,120,93,5,293,147,299,81,334,137,259,48,296,117,379,182] }\nassert my_solution.minProcessingTime(**test_input) == 584\n\ntest_input = { \"processorTime\": [320,139], \"tasks\": [210,255,304,181,216,255,375,360] }\nassert my_solution.minProcessingTime(**test_input) == 575\n\ntest_input = { \"processorTime\": [306,207,295], \"tasks\": [335,188,355,209,201,113,122,206,46,355,350,38] }\nassert my_solution.minProcessingTime(**test_input) == 562\n\ntest_input = { \"processorTime\": [175,111], \"tasks\": [225,110,163,100,353,77,12,124] }\nassert my_solution.minProcessingTime(**test_input) == 464\n\ntest_input = { \"processorTime\": [233,201], \"tasks\": [1,389,291,333,42,399,399,300] }\nassert my_solution.minProcessingTime(**test_input) == 600\n\ntest_input = { \"processorTime\": [302,5,102,195], \"tasks\": [311,144,7,277,253,96,136,251,81,195,171,140,73,2,84,42] }\nassert my_solution.minProcessingTime(**test_input) == 375\n\ntest_input = { \"processorTime\": [151,185,3,137], \"tasks\": [294,230,221,216,299,24,79,194,375,387,77,388,366,51,117,126] }\nassert my_solution.minProcessingTime(**test_input) == 436\n\ntest_input = { \"processorTime\": [39,141,145,199], \"tasks\": [99,257,161,121,56,80,235,168,171,228,290,180,118,307,66,151] }\nassert my_solution.minProcessingTime(**test_input) == 369\n\ntest_input = { \"processorTime\": [40,67], \"tasks\": [259,217,337,295,126,335,369,123] }\nassert my_solution.minProcessingTime(**test_input) == 409\n\ntest_input = { \"processorTime\": [310,56,207,396], \"tasks\": [260,255,30,243,66,11,285,31,358,219,218,90,176,346,134,74] }\nassert my_solution.minProcessingTime(**test_input) == 486\n\ntest_input = { \"processorTime\": [174,48], \"tasks\": [106,323,4,247,70,281,348,12] }\nassert my_solution.minProcessingTime(**test_input) == 396\n\ntest_input = { \"processorTime\": [16,52,13], \"tasks\": [281,261,55,165,317,150,68,26,52,227,176,399] }\nassert my_solution.minProcessingTime(**test_input) == 412\n\ntest_input = { \"processorTime\": [8,315,115,123], \"tasks\": [134,371,160,138,289,330,48,349,376,88,46,235,298,321,343,365] }\nassert my_solution.minProcessingTime(**test_input) == 458\n\ntest_input = { \"processorTime\": [221,24,372,6,50], \"tasks\": [274,79,78,37,57,39,102,272,242,283,95,155,105,363,174,1,333,400,375,376] }\nassert my_solution.minProcessingTime(**test_input) == 429\n\ntest_input = { \"processorTime\": [289,98,7,303,219], \"tasks\": [363,140,173,92,52,348,350,316,281,327,40,259,39,235,263,244,42,354,11,232] }\nassert my_solution.minProcessingTime(**test_input) == 478\n\ntest_input = { \"processorTime\": [348,268], \"tasks\": [104,397,333,188,373,325,57,202] }\nassert my_solution.minProcessingTime(**test_input) == 665\n\ntest_input = { \"processorTime\": [18,377,305,188,311], \"tasks\": [207,365,369,66,263,47,257,317,221,292,386,308,357,105,99,314,133,106,311,90] }\nassert my_solution.minProcessingTime(**test_input) == 597\n\ntest_input = { \"processorTime\": [44,254], \"tasks\": [277,361,398,276,84,105,350,134] }\nassert my_solution.minProcessingTime(**test_input) == 530\n\ntest_input = { \"processorTime\": [270,257,58], \"tasks\": [212,151,50,78,91,110,399,360,108,192,142,115] }\nassert my_solution.minProcessingTime(**test_input) == 457\n\ntest_input = { \"processorTime\": [108,301], \"tasks\": [150,143,119,160,340,139,72,349] }\nassert my_solution.minProcessingTime(**test_input) == 457\n\ntest_input = { \"processorTime\": [231,207,162,49], \"tasks\": [318,289,351,103,19,77,65,116,94,234,139,246,80,184,286,397] }\nassert my_solution.minProcessingTime(**test_input) == 448\n\ntest_input = { \"processorTime\": [252], \"tasks\": [384,281,207,33] }\nassert my_solution.minProcessingTime(**test_input) == 636\n\ntest_input = { \"processorTime\": [199,8,129,204], \"tasks\": [308,133,366,272,373,343,357,159,378,149,185,248,190,1,142,199] }\nassert my_solution.minProcessingTime(**test_input) == 472\n\ntest_input = { \"processorTime\": [135,65,19,225], \"tasks\": [183,135,138,142,282,141,349,236,57,333,258,353,152,396,152,191] }\nassert my_solution.minProcessingTime(**test_input) == 415\n\ntest_input = { \"processorTime\": [199,371,283,70], \"tasks\": [244,7,226,230,331,232,332,288,151,360,26,87,49,188,269,375] }\nassert my_solution.minProcessingTime(**test_input) == 513\n\ntest_input = { \"processorTime\": [184,378], \"tasks\": [105,239,221,343,276,359,86,84] }\nassert my_solution.minProcessingTime(**test_input) == 599\n\ntest_input = { \"processorTime\": [297,229,142,8,47], \"tasks\": [373,256,210,92,304,134,20,246,116,139,376,139,10,210,192,43,282,278,322,167] }\nassert my_solution.minProcessingTime(**test_input) == 389\n\ntest_input = { \"processorTime\": [224,358,58,352], \"tasks\": [177,274,306,295,142,353,44,111,325,328,394,168,300,15,252,389] }\nassert my_solution.minProcessingTime(**test_input) == 626\n\ntest_input = { \"processorTime\": [318,321,264,259], \"tasks\": [316,284,127,227,269,332,317,364,220,130,330,155,45,205,369,42] }\nassert my_solution.minProcessingTime(**test_input) == 628\n\ntest_input = { \"processorTime\": [295,214,130], \"tasks\": [316,395,280,122,27,224,40,210,99,366,55,183] }\nassert my_solution.minProcessingTime(**test_input) == 525\n\ntest_input = { \"processorTime\": [81,38,313,121], \"tasks\": [158,304,127,214,34,298,95,188,56,391,317,99,304,101,266,302] }\nassert my_solution.minProcessingTime(**test_input) == 429\n\ntest_input = { \"processorTime\": [8,400,28,348,193], \"tasks\": [72,391,149,264,370,183,365,102,201,348,341,176,338,186,97,156,47,125,61,202] }\nassert my_solution.minProcessingTime(**test_input) == 504\n\ntest_input = { \"processorTime\": [0], \"tasks\": [8,369,353,14] }\nassert my_solution.minProcessingTime(**test_input) == 369\n\ntest_input = { \"processorTime\": [55,364,28,246], \"tasks\": [396,357,37,400,239,327,5,387,70,389,323,213,322,111,179,19] }\nassert my_solution.minProcessingTime(**test_input) == 485\n\ntest_input = { \"processorTime\": [288,219,356,146,282], \"tasks\": [390,46,24,391,222,241,281,33,400,312,290,11,147,282,204,214,22,178,77,156] }\nassert my_solution.minProcessingTime(**test_input) == 546\n\ntest_input = { \"processorTime\": [60,309,40,219,294], \"tasks\": [267,94,238,338,279,48,164,371,302,110,247,392,83,107,389,46,92,273,131,136] }\nassert my_solution.minProcessingTime(**test_input) == 466\n\ntest_input = { \"processorTime\": [357], \"tasks\": [211,344,270,324] }\nassert my_solution.minProcessingTime(**test_input) == 701\n\ntest_input = { \"processorTime\": [220,355,190,393], \"tasks\": [158,27,113,335,382,172,285,373,104,177,247,321,197,22,347,136] }\nassert my_solution.minProcessingTime(**test_input) == 572\n\ntest_input = { \"processorTime\": [67,105,290,26,343], \"tasks\": [50,118,302,74,198,56,292,46,337,27,394,69,109,287,274,283,346,132,77,352] }\nassert my_solution.minProcessingTime(**test_input) == 420\n\ntest_input = { \"processorTime\": [77,143,142,23], \"tasks\": [336,190,105,87,102,254,295,243,400,254,96,303,350,191,331,70] }\nassert my_solution.minProcessingTime(**test_input) == 423\n\ntest_input = { \"processorTime\": [319,58,155,360], \"tasks\": [311,257,35,330,235,159,293,204,298,240,233,250,309,242,262,324] }\nassert my_solution.minProcessingTime(**test_input) == 593\n\ntest_input = { \"processorTime\": [28,225,347], \"tasks\": [176,57,60,81,161,66,13,294,145,239,295,210] }\nassert my_solution.minProcessingTime(**test_input) == 413\n\ntest_input = { \"processorTime\": [291,337], \"tasks\": [210,378,169,400,182,290,386,360] }\nassert my_solution.minProcessingTime(**test_input) == 691\n\ntest_input = { \"processorTime\": [141,310], \"tasks\": [396,56,241,289,21,254,196,165] }\nassert my_solution.minProcessingTime(**test_input) == 537\n\ntest_input = { \"processorTime\": [204,390,104], \"tasks\": [355,4,287,161,230,242,218,12,321,28,341,326] }\nassert my_solution.minProcessingTime(**test_input) == 551\n\ntest_input = { \"processorTime\": [299,258], \"tasks\": [20,44,341,172,118,185,369,249] }\nassert my_solution.minProcessingTime(**test_input) == 627\n\ntest_input = { \"processorTime\": [107,141,178,211,62], \"tasks\": [215,318,196,251,71,144,10,208,113,17,13,263,367,42,85,267,212,54,36,54] }\nassert my_solution.minProcessingTime(**test_input) == 429\n\ntest_input = { \"processorTime\": [101,383,326,62], \"tasks\": [304,256,281,240,180,387,318,368,331,267,14,91,93,147,156,394] }\nassert my_solution.minProcessingTime(**test_input) == 582\n\ntest_input = { \"processorTime\": [221,62,187,104,266], \"tasks\": [284,378,9,288,173,327,329,202,3,383,105,213,175,201,196,305,162,161,127,347] }\nassert my_solution.minProcessingTime(**test_input) == 445\n\ntest_input = { \"processorTime\": [328,162,249,357,35], \"tasks\": [77,275,231,298,273,257,88,339,261,147,229,392,156,63,90,97,219,353,66,91] }\nassert my_solution.minProcessingTime(**test_input) == 480\n\ntest_input = { \"processorTime\": [7], \"tasks\": [132,278,270,176] }\nassert my_solution.minProcessingTime(**test_input) == 285\n\ntest_input = { \"processorTime\": [326], \"tasks\": [269,211,137,244] }\nassert my_solution.minProcessingTime(**test_input) == 595\n\ntest_input = { \"processorTime\": [310,44], \"tasks\": [109,250,222,275,268,332,146,328] }\nassert my_solution.minProcessingTime(**test_input) == 560\n\ntest_input = { \"processorTime\": [184,254,121,90,389], \"tasks\": [124,365,400,167,109,207,369,37,174,287,41,114,388,158,125,283,119,254,210,399] }\nassert my_solution.minProcessingTime(**test_input) == 503\n\ntest_input = { \"processorTime\": [94,171,66], \"tasks\": [261,134,26,281,29,253,84,333,90,157,382,263] }\nassert my_solution.minProcessingTime(**test_input) == 448\n\ntest_input = { \"processorTime\": [5,99,318,252,151], \"tasks\": [264,235,250,347,376,57,73,7,178,45,220,148,159,379,89,73,159,172,228,39] }\nassert my_solution.minProcessingTime(**test_input) == 400\n\ntest_input = { \"processorTime\": [303,52,2,118,305], \"tasks\": [398,173,5,301,169,389,126,212,384,359,222,340,267,173,264,238,141,44,144,148] }\nassert my_solution.minProcessingTime(**test_input) == 476\n\ntest_input = { \"processorTime\": [177], \"tasks\": [164,277,289,197] }\nassert my_solution.minProcessingTime(**test_input) == 466\n\ntest_input = { \"processorTime\": [297,259,318,30,213], \"tasks\": [162,97,265,153,216,233,286,346,389,208,55,345,308,197,266,292,369,320,1,235] }\nassert my_solution.minProcessingTime(**test_input) == 533\n\ntest_input = { \"processorTime\": [290], \"tasks\": [333,282,72,362] }\nassert my_solution.minProcessingTime(**test_input) == 652\n\ntest_input = { \"processorTime\": [372,189,344], \"tasks\": [191,26,247,99,395,270,192,340,60,78,260,395] }\nassert my_solution.minProcessingTime(**test_input) == 604", "start_time": 1696732200} +{"task_id": "weekly-contest-366-apply-operations-to-make-two-strings-equal", "url": "https://leetcode.com/problems/apply-operations-to-make-two-strings-equal", "title": "apply-operations-to-make-two-strings-equal", "meta": {"questionId": "3033", "questionFrontendId": "2896", "title": "Apply Operations to Make Two Strings Equal", "titleSlug": "apply-operations-to-make-two-strings-equal", "isPaidOnly": false, "difficulty": "Medium", "likes": 291, "dislikes": 62, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你两个下标从 0 开始的二进制字符串 s1 和 s2 ,两个字符串的长度都是 n ,再给你一个正整数 x 。\n\n你可以对字符串 s1 执行以下操作 任意次 :\n\n * 选择两个下标 i 和 j ,将 s1[i] 和 s1[j] 都反转,操作的代价为 x 。\n * 选择满足 i < n - 1 的下标 i ,反转 s1[i] 和 s1[i + 1] ,操作的代价为 1 。\n\n请你返回使字符串 s1 和 s2 相等的 最小 操作代价之和,如果无法让二者相等,返回 -1 。\n\n注意 ,反转字符的意思是将 0 变成 1 ,或者 1 变成 0 。\n\n示例 1:\n\n输入:s1 = \"1100011000\", s2 = \"0101001010\", x = 2\n输出:4\n解释:我们可以执行以下操作:\n- 选择 i = 3 执行第二个操作。结果字符串是 s1 = \"1101111000\" 。\n- 选择 i = 4 执行第二个操作。结果字符串是 s1 = \"1101001000\" 。\n- 选择 i = 0 和 j = 8 ,执行第一个操作。结果字符串是 s1 = \"0101001010\" = s2 。\n总代价是 1 + 1 + 2 = 4 。这是最小代价和。\n\n示例 2:\n\n输入:s1 = \"10110\", s2 = \"00011\", x = 4\n输出:-1\n解释:无法使两个字符串相等。\n\n\n提示:\n\n * n == s1.length == s2.length\n * 1 <= n, x <= 500\n * s1 和 s2 只包含字符 '0' 和 '1' 。\n\"\"\"\nclass Solution:\n def minOperations(self, s1: str, s2: str, x: int) -> int:\n ", "prompt_sft": "给你两个下标从 0 开始的二进制字符串 s1 和 s2 ,两个字符串的长度都是 n ,再给你一个正整数 x 。\n\n你可以对字符串 s1 执行以下操作 任意次 :\n\n * 选择两个下标 i 和 j ,将 s1[i] 和 s1[j] 都反转,操作的代价为 x 。\n * 选择满足 i < n - 1 的下标 i ,反转 s1[i] 和 s1[i + 1] ,操作的代价为 1 。\n\n请你返回使字符串 s1 和 s2 相等的 最小 操作代价之和,如果无法让二者相等,返回 -1 。\n\n注意 ,反转字符的意思是将 0 变成 1 ,或者 1 变成 0 。\n\n示例 1:\n\n输入:s1 = \"1100011000\", s2 = \"0101001010\", x = 2\n输出:4\n解释:我们可以执行以下操作:\n- 选择 i = 3 执行第二个操作。结果字符串是 s1 = \"1101111000\" 。\n- 选择 i = 4 执行第二个操作。结果字符串是 s1 = \"1101001000\" 。\n- 选择 i = 0 和 j = 8 ,执行第一个操作。结果字符串是 s1 = \"0101001010\" = s2 。\n总代价是 1 + 1 + 2 = 4 。这是最小代价和。\n\n示例 2:\n\n输入:s1 = \"10110\", s2 = \"00011\", x = 4\n输出:-1\n解释:无法使两个字符串相等。\n\n\n提示:\n\n * n == s1.length == s2.length\n * 1 <= n, x <= 500\n * s1 和 s2 只包含字符 '0' 和 '1' 。\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def minOperations(self, s1: str, s2: str, x: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"s1\": \"1100011000\", \"s2\": \"0101001010\", \"x\": 2 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"s1\": \"10110\", \"s2\": \"00011\", \"x\": 4 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"101101\", \"s2\": \"000000\", \"x\": 6 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"s1\": \"0\", \"s2\": \"1\", \"x\": 2 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"1011100100111000\", \"s2\": \"1001010001011100\", \"x\": 19 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"00101101100010\", \"s2\": \"00001010001111\", \"x\": 30 }\nassert my_solution.minOperations(**test_input) == 8\n\ntest_input = { \"s1\": \"1011000\", \"s2\": \"0001101\", \"x\": 30 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"s1\": \"1111110101010110\", \"s2\": \"1000100111100101\", \"x\": 19 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"1011100000100100101\", \"s2\": \"1110001001110000011\", \"x\": 14 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"0\", \"s2\": \"1\", \"x\": 17 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"0\", \"s2\": \"1\", \"x\": 3 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"0001110010\", \"s2\": \"0110100111\", \"x\": 29 }\nassert my_solution.minOperations(**test_input) == 5\n\ntest_input = { \"s1\": \"01111101010100110100\", \"s2\": \"10010011011001011000\", \"x\": 21 }\nassert my_solution.minOperations(**test_input) == 7\n\ntest_input = { \"s1\": \"00000101\", \"s2\": \"01001010\", \"x\": 10 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"01\", \"s2\": \"00\", \"x\": 30 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"11111\", \"s2\": \"01011\", \"x\": 4 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"s1\": \"001010101011001\", \"s2\": \"110111000101110\", \"x\": 14 }\nassert my_solution.minOperations(**test_input) == 7\n\ntest_input = { \"s1\": \"010011101\", \"s2\": \"101111000\", \"x\": 17 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"s1\": \"11110111\", \"s2\": \"10011111\", \"x\": 16 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"0011\", \"s2\": \"1100\", \"x\": 14 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"s1\": \"000011\", \"s2\": \"010101\", \"x\": 27 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"01111010\", \"s2\": \"10110011\", \"x\": 21 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"s1\": \"10010111001\", \"s2\": \"11101011110\", \"x\": 1 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"s1\": \"10001\", \"s2\": \"11000\", \"x\": 11 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"s1\": \"11001011111\", \"s2\": \"01111000110\", \"x\": 2 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"s1\": \"111010100001011\", \"s2\": \"100000101100111\", \"x\": 29 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"010000110111000111\", \"s2\": \"100011100010010111\", \"x\": 15 }\nassert my_solution.minOperations(**test_input) == 6\n\ntest_input = { \"s1\": \"010010111\", \"s2\": \"011100010\", \"x\": 21 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"01011111\", \"s2\": \"11110101\", \"x\": 7 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"s1\": \"00001011110000\", \"s2\": \"01011110001001\", \"x\": 12 }\nassert my_solution.minOperations(**test_input) == 8\n\ntest_input = { \"s1\": \"1100110100001001\", \"s2\": \"0100111010111001\", \"x\": 18 }\nassert my_solution.minOperations(**test_input) == 8\n\ntest_input = { \"s1\": \"00101101\", \"s2\": \"10010101\", \"x\": 6 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"s1\": \"110010\", \"s2\": \"011011\", \"x\": 21 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"00101\", \"s2\": \"11000\", \"x\": 25 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"s1\": \"110\", \"s2\": \"100\", \"x\": 27 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"1101\", \"s2\": \"0000\", \"x\": 9 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"11\", \"s2\": \"01\", \"x\": 7 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"100000000\", \"s2\": \"001011111\", \"x\": 26 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"0111001011\", \"s2\": \"0010011111\", \"x\": 21 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"s1\": \"10\", \"s2\": \"00\", \"x\": 19 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"110111\", \"s2\": \"101101\", \"x\": 3 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"1010111\", \"s2\": \"0110011\", \"x\": 25 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"001\", \"s2\": \"101\", \"x\": 19 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"111100000100111\", \"s2\": \"110100010110001\", \"x\": 7 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"111\", \"s2\": \"110\", \"x\": 4 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"10000010010\", \"s2\": \"11100000010\", \"x\": 22 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"00100110\", \"s2\": \"10101111\", \"x\": 16 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"0110010001101011010\", \"s2\": \"1011110101000001100\", \"x\": 3 }\nassert my_solution.minOperations(**test_input) == 8\n\ntest_input = { \"s1\": \"0001100000001\", \"s2\": \"0011000011101\", \"x\": 28 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"0000110011\", \"s2\": \"0000000011\", \"x\": 3 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"s1\": \"11101100\", \"s2\": \"11111011\", \"x\": 10 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"s1\": \"011101110001001010\", \"s2\": \"111000011001101010\", \"x\": 30 }\nassert my_solution.minOperations(**test_input) == 8\n\ntest_input = { \"s1\": \"1111111100\", \"s2\": \"1010001010\", \"x\": 5 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"s1\": \"111011\", \"s2\": \"111010\", \"x\": 19 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"00010\", \"s2\": \"00010\", \"x\": 9 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"s1\": \"11100000\", \"s2\": \"11110010\", \"x\": 13 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"s1\": \"111101000111\", \"s2\": \"101111010010\", \"x\": 16 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"0\", \"s2\": \"0\", \"x\": 20 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"s1\": \"0011111100011\", \"s2\": \"1001100101000\", \"x\": 26 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"1000101111101001\", \"s2\": \"0110000010110010\", \"x\": 25 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"11000010000\", \"s2\": \"11111000001\", \"x\": 17 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"1110111001000001\", \"s2\": \"0110011110101101\", \"x\": 1 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"s1\": \"0111101101\", \"s2\": \"0000111001\", \"x\": 2 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"000001110\", \"s2\": \"000101001\", \"x\": 22 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"s1\": \"1110000000\", \"s2\": \"1100111100\", \"x\": 5 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"1101101010\", \"s2\": \"0101010011\", \"x\": 15 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"0010011011000101001\", \"s2\": \"1110101001110100010\", \"x\": 19 }\nassert my_solution.minOperations(**test_input) == 9\n\ntest_input = { \"s1\": \"11010011101011110111\", \"s2\": \"11101111011010010011\", \"x\": 8 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"101100010\", \"s2\": \"100011110\", \"x\": 29 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"00100001\", \"s2\": \"10011101\", \"x\": 29 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"111111110110010\", \"s2\": \"111011111010001\", \"x\": 29 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"11011110110010\", \"s2\": \"01010100000111\", \"x\": 9 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"011101010101\", \"s2\": \"111001010100\", \"x\": 19 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"00001\", \"s2\": \"11111\", \"x\": 27 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"s1\": \"110\", \"s2\": \"101\", \"x\": 15 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"s1\": \"11011001111000111001\", \"s2\": \"11100011111011110001\", \"x\": 12 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"1010100\", \"s2\": \"0100111\", \"x\": 2 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"000\", \"s2\": \"010\", \"x\": 21 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"1011010100111101\", \"s2\": \"1010001100110110\", \"x\": 18 }\nassert my_solution.minOperations(**test_input) == 9\n\ntest_input = { \"s1\": \"111\", \"s2\": \"000\", \"x\": 4 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"00101100110110010\", \"s2\": \"00001111111011011\", \"x\": 22 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"000110011\", \"s2\": \"010010001\", \"x\": 8 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"1011000000\", \"s2\": \"0001010010\", \"x\": 16 }\nassert my_solution.minOperations(**test_input) == 5\n\ntest_input = { \"s1\": \"01101100110011011011\", \"s2\": \"10101101010011001011\", \"x\": 5 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"00010\", \"s2\": \"00011\", \"x\": 8 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"1010110111000111\", \"s2\": \"1110110001001000\", \"x\": 22 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"011110100000\", \"s2\": \"101100010100\", \"x\": 21 }\nassert my_solution.minOperations(**test_input) == 5\n\ntest_input = { \"s1\": \"1011010010100101101\", \"s2\": \"1001001110101100000\", \"x\": 29 }\nassert my_solution.minOperations(**test_input) == 9\n\ntest_input = { \"s1\": \"1111100\", \"s2\": \"0010100\", \"x\": 20 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"0100100110001\", \"s2\": \"1001111110001\", \"x\": 4 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"110\", \"s2\": \"011\", \"x\": 2 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"s1\": \"111111010101\", \"s2\": \"000011101101\", \"x\": 30 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"101111110110010100\", \"s2\": \"010001111100000100\", \"x\": 3 }\nassert my_solution.minOperations(**test_input) == 7\n\ntest_input = { \"s1\": \"0110111\", \"s2\": \"0111010\", \"x\": 19 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"1101010101\", \"s2\": \"1011000110\", \"x\": 14 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"01100101\", \"s2\": \"11010111\", \"x\": 17 }\nassert my_solution.minOperations(**test_input) == 5\n\ntest_input = { \"s1\": \"0011111\", \"s2\": \"0110101\", \"x\": 13 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"11110110111111011\", \"s2\": \"11101101111010110\", \"x\": 19 }\nassert my_solution.minOperations(**test_input) == 6\n\ntest_input = { \"s1\": \"110100\", \"s2\": \"000011\", \"x\": 20 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"0101\", \"s2\": \"0010\", \"x\": 29 }\nassert my_solution.minOperations(**test_input) == -1", "start_time": 1696732200} +{"task_id": "weekly-contest-366-apply-operations-on-array-to-maximize-sum-of-squares", "url": "https://leetcode.com/problems/apply-operations-on-array-to-maximize-sum-of-squares", "title": "apply-operations-on-array-to-maximize-sum-of-squares", "meta": {"questionId": "3153", "questionFrontendId": "2897", "title": "Apply Operations on Array to Maximize Sum of Squares", "titleSlug": "apply-operations-on-array-to-maximize-sum-of-squares", "isPaidOnly": false, "difficulty": "Hard", "likes": 159, "dislikes": 3, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0 开始的整数数组 nums 和一个 正 整数 k 。\n\n你可以对数组执行以下操作 任意次 :\n\n * 选择两个互不相同的下标 i 和 j ,同时 将 nums[i] 更新为 (nums[i] AND nums[j]) 且将 nums[j] 更新为 (nums[i] OR nums[j]) ,OR 表示按位 或 运算,AND 表示按位 与 运算。\n\n你需要从最终的数组里选择 k 个元素,并计算它们的 平方 之和。\n\n请你返回你可以得到的 最大 平方和。\n\n由于答案可能会很大,将答案对 109 + 7 取余 后返回。\n\n示例 1:\n\n输入:nums = [2,6,5,8], k = 2\n输出:261\n解释:我们可以对数组执行以下操作:\n- 选择 i = 0 和 j = 3 ,同时将 nums[0] 变为 (2 AND 8) = 0 且 nums[3] 变为 (2 OR 8) = 10 ,结果数组为 nums = [0,6,5,10] 。\n- 选择 i = 2 和 j = 3 ,同时将 nums[2] 变为 (5 AND 10) = 0 且 nums[3] 变为 (5 OR 10) = 15 ,结果数组为 nums = [0,6,0,15] 。\n从最终数组里选择元素 15 和 6 ,平方和为 152 + 62 = 261 。\n261 是可以得到的最大结果。\n\n示例 2:\n\n输入:nums = [4,5,4,7], k = 3\n输出:90\n解释:不需要执行任何操作。\n选择元素 7 ,5 和 4 ,平方和为 72 + 52 + 42 = 90 。\n90 是可以得到的最大结果。\n\n\n提示:\n\n * 1 <= k <= nums.length <= 105\n * 1 <= nums[i] <= 109\n\"\"\"\nclass Solution:\n def maxSum(self, nums: List[int], k: int) -> int:\n ", "prompt_sft": "给你一个下标从 0 开始的整数数组 nums 和一个 正 整数 k 。\n\n你可以对数组执行以下操作 任意次 :\n\n * 选择两个互不相同的下标 i 和 j ,同时 将 nums[i] 更新为 (nums[i] AND nums[j]) 且将 nums[j] 更新为 (nums[i] OR nums[j]) ,OR 表示按位 或 运算,AND 表示按位 与 运算。\n\n你需要从最终的数组里选择 k 个元素,并计算它们的 平方 之和。\n\n请你返回你可以得到的 最大 平方和。\n\n由于答案可能会很大,将答案对 109 + 7 取余 后返回。\n\n示例 1:\n\n输入:nums = [2,6,5,8], k = 2\n输出:261\n解释:我们可以对数组执行以下操作:\n- 选择 i = 0 和 j = 3 ,同时将 nums[0] 变为 (2 AND 8) = 0 且 nums[3] 变为 (2 OR 8) = 10 ,结果数组为 nums = [0,6,5,10] 。\n- 选择 i = 2 和 j = 3 ,同时将 nums[2] 变为 (5 AND 10) = 0 且 nums[3] 变为 (5 OR 10) = 15 ,结果数组为 nums = [0,6,0,15] 。\n从最终数组里选择元素 15 和 6 ,平方和为 152 + 62 = 261 。\n261 是可以得到的最大结果。\n\n示例 2:\n\n输入:nums = [4,5,4,7], k = 3\n输出:90\n解释:不需要执行任何操作。\n选择元素 7 ,5 和 4 ,平方和为 72 + 52 + 42 = 90 。\n90 是可以得到的最大结果。\n\n\n提示:\n\n * 1 <= k <= nums.length <= 105\n * 1 <= nums[i] <= 109\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def maxSum(self, nums: List[int], k: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [2,6,5,8], \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 261\n\ntest_input = { \"nums\": [4,5,4,7], \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 90\n\ntest_input = { \"nums\": [32,85,61], \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 15625\n\ntest_input = { \"nums\": [123], \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 15129\n\ntest_input = { \"nums\": [96,66,60,58,32,17,63,21,30,44,15,8,98,93], \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 32258\n\ntest_input = { \"nums\": [30,8,63,69,52,94,41,28,94,86,28,13,68,38,53,11,21,33], \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 32258\n\ntest_input = { \"nums\": [2,38,15,2,73,100,47,14,25,58,40,64,23,9,53,38,91,75,9,2], \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 48387\n\ntest_input = { \"nums\": [25,52,75,65], \"k\": 4 }\nassert my_solution.maxSum(**test_input) == 24051\n\ntest_input = { \"nums\": [96,36,72,61,13,25,5,33,9,51,9,78,40], \"k\": 13 }\nassert my_solution.maxSum(**test_input) == 53776\n\ntest_input = { \"nums\": [38,21,15,84,65,35,57,82,94,26,27,89,73,22,25,6,97,17], \"k\": 4 }\nassert my_solution.maxSum(**test_input) == 64516\n\ntest_input = { \"nums\": [18,72,52,56,7,21,55,68,98,31,35,49,100,49,64,20], \"k\": 4 }\nassert my_solution.maxSum(**test_input) == 62548\n\ntest_input = { \"nums\": [2,73,75], \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 11250\n\ntest_input = { \"nums\": [73,37,41,84], \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 27506\n\ntest_input = { \"nums\": [62,83,11,3,53], \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 20459\n\ntest_input = { \"nums\": [53,59,71,38,5,15,98,86,9,8,35,54,65,77,3,68,11,5,41,18], \"k\": 9 }\nassert my_solution.maxSum(**test_input) == 95273\n\ntest_input = { \"nums\": [53,67,91,79,21,27,63,34,60,94,51], \"k\": 4 }\nassert my_solution.maxSum(**test_input) == 64516\n\ntest_input = { \"nums\": [41,15,6,31,40,97,11,45,81,91,91,62], \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 48387\n\ntest_input = { \"nums\": [10,9], \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 185\n\ntest_input = { \"nums\": [9,6,8,32,92,12,47,45,62,96,5,66,82,90,34,39,49,86,16], \"k\": 13 }\nassert my_solution.maxSum(**test_input) == 102770\n\ntest_input = { \"nums\": [1,19,29,30,68,13,80,16,71,32,8,76,41,24,16,2,30], \"k\": 14 }\nassert my_solution.maxSum(**test_input) == 53470\n\ntest_input = { \"nums\": [22,64,30,71,28,69,86,12,26,39,69,92], \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 25154\n\ntest_input = { \"nums\": [91,26,29,38,97,40,1,18,15,3,43,37,9,55,4,46], \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 32258\n\ntest_input = { \"nums\": [27,73], \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 8281\n\ntest_input = { \"nums\": [12,33,29,75,94,48,25,21], \"k\": 8 }\nassert my_solution.maxSum(**test_input) == 34565\n\ntest_input = { \"nums\": [39,91,84,10,65,28,94,28,62,77,78,50,93,65,21,16,5,35,81], \"k\": 14 }\nassert my_solution.maxSum(**test_input) == 110106\n\ntest_input = { \"nums\": [14,45,76,33,35,53,67,19,6,31,33], \"k\": 10 }\nassert my_solution.maxSum(**test_input) == 40008\n\ntest_input = { \"nums\": [59,88,2,47,75], \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 31258\n\ntest_input = { \"nums\": [96,77,77,33,5,86,90,21,84,73,86,45,88,35,93,14,63,25], \"k\": 17 }\nassert my_solution.maxSum(**test_input) == 121571\n\ntest_input = { \"nums\": [35,5,21,65,34,90,60,8,34,35,28,78,77], \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 16129\n\ntest_input = { \"nums\": [14,10,19], \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 1061\n\ntest_input = { \"nums\": [100,4,88,29,13,78,89,11,62,63,66,46,99,87,41,29,36,71,57], \"k\": 18 }\nassert my_solution.maxSum(**test_input) == 129739\n\ntest_input = { \"nums\": [86,52,100,68,30,40,49,28,61,30,3,80], \"k\": 11 }\nassert my_solution.maxSum(**test_input) == 69063\n\ntest_input = { \"nums\": [29,30,61,12,98,95], \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 32258\n\ntest_input = { \"nums\": [23,13,35,41,29,57,84,67,70,96,55,85,15,72,23,52,1,11,62,1], \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 16129\n\ntest_input = { \"nums\": [34,60,85,22,83], \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 30290\n\ntest_input = { \"nums\": [65,26,44,70,79,65,46,18], \"k\": 8 }\nassert my_solution.maxSum(**test_input) == 44587\n\ntest_input = { \"nums\": [99,50,13,62,12,60,6,29], \"k\": 6 }\nassert my_solution.maxSum(**test_input) == 28071\n\ntest_input = { \"nums\": [73,66,75,44], \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 23130\n\ntest_input = { \"nums\": [43,85,7,66,16,96], \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 16129\n\ntest_input = { \"nums\": [45,5,3,84,81,54,21,37,99,60], \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 32258\n\ntest_input = { \"nums\": [97,6,44,57,63,5], \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 16129\n\ntest_input = { \"nums\": [65,43,82,46,34,42,65,67,8,67,3,83,87,71,98,31,15,22], \"k\": 5 }\nassert my_solution.maxSum(**test_input) == 80645\n\ntest_input = { \"nums\": [79,33,75,32,64,68,30,46,60,50,6,54,18,34,43,11,84,78,54,4], \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 16129\n\ntest_input = { \"nums\": [17,9,3,23,33,99,94,15,93,17,39,55,13,26,22,44,13], \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 48387\n\ntest_input = { \"nums\": [83,29,2,67,79,88,71,98,70], \"k\": 4 }\nassert my_solution.maxSum(**test_input) == 39220\n\ntest_input = { \"nums\": [60,81,60,88,37,38,10,42,84,70], \"k\": 10 }\nassert my_solution.maxSum(**test_input) == 67626\n\ntest_input = { \"nums\": [33,51,100,33,46], \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 18739\n\ntest_input = { \"nums\": [29,4,67,44,74,62,41,86,91,11,26,58,59,48,46,41,26,68,4,81], \"k\": 4 }\nassert my_solution.maxSum(**test_input) == 64516\n\ntest_input = { \"nums\": [86,54,20,57,87,63,2,24,73,87,7,16,50,1,58], \"k\": 7 }\nassert my_solution.maxSum(**test_input) == 69543\n\ntest_input = { \"nums\": [91,2,16,77,2], \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 9025\n\ntest_input = { \"nums\": [19,94], \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 9349\n\ntest_input = { \"nums\": [14,67,79,58], \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 22370\n\ntest_input = { \"nums\": [44,17,10,19,3,97,45,65,98,7,73,30,76,5,52,33,62], \"k\": 4 }\nassert my_solution.maxSum(**test_input) == 64516\n\ntest_input = { \"nums\": [8,80,93], \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 8649\n\ntest_input = { \"nums\": [51,79,26,30,41,74,6,11,10,66,61,25,41,32,83,52,71,70], \"k\": 18 }\nassert my_solution.maxSum(**test_input) == 98085\n\ntest_input = { \"nums\": [15,58,38,69,71,43], \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 16129\n\ntest_input = { \"nums\": [13,57,34,69,80,98,63,22,29,38,70,94,79,95,13,76,39,22], \"k\": 5 }\nassert my_solution.maxSum(**test_input) == 80645\n\ntest_input = { \"nums\": [98,88,17,85,57,97,42,15,25,71,31,72,76,89,28,47,73,85], \"k\": 9 }\nassert my_solution.maxSum(**test_input) == 114889\n\ntest_input = { \"nums\": [95,28,26,65,87,4,14,25,47,97,67,48,29,14,96,76,77,25], \"k\": 9 }\nassert my_solution.maxSum(**test_input) == 100409\n\ntest_input = { \"nums\": [37,16,76,9,88,44,71,61,95,32,63,10,29,33], \"k\": 11 }\nassert my_solution.maxSum(**test_input) == 72360\n\ntest_input = { \"nums\": [54,96,73,18,15,35,79,96,2,12,50,75,7,93,66,35,40,16], \"k\": 18 }\nassert my_solution.maxSum(**test_input) == 104436\n\ntest_input = { \"nums\": [66,84,85,7,45,34,61,91,83,13,87,89,51,52,65], \"k\": 6 }\nassert my_solution.maxSum(**test_input) == 88214\n\ntest_input = { \"nums\": [76,22,86,88,58,10,61,21,42], \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 32258\n\ntest_input = { \"nums\": [16,52,8,99,68,73], \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 31754\n\ntest_input = { \"nums\": [46,91,73,38,36,79,24,78,24,42], \"k\": 8 }\nassert my_solution.maxSum(**test_input) == 60911\n\ntest_input = { \"nums\": [5,100,85,52,5,28,79,30,9,67,87,50,17,29,99,57], \"k\": 14 }\nassert my_solution.maxSum(**test_input) == 91019\n\ntest_input = { \"nums\": [52,57,77,95,79,28,9,94,70,8,89,75,27,53,41,88,68,8,10,59], \"k\": 5 }\nassert my_solution.maxSum(**test_input) == 80645\n\ntest_input = { \"nums\": [66,64,52,90,73,84,2], \"k\": 6 }\nassert my_solution.maxSum(**test_input) == 39881\n\ntest_input = { \"nums\": [97,100], \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 10201\n\ntest_input = { \"nums\": [27,85,57,44,16,55,77,77,24,62,72], \"k\": 10 }\nassert my_solution.maxSum(**test_input) == 66334\n\ntest_input = { \"nums\": [15,6,18,22,72,63,38,72,4,84,9,19,70,76,72,98,35,51,11,9], \"k\": 20 }\nassert my_solution.maxSum(**test_input) == 96344\n\ntest_input = { \"nums\": [10,67,54,100,6,93,91,4,59], \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 48387\n\ntest_input = { \"nums\": [90,48,91,62,39,94,75,8,21,72,9,55,16,30,27,73,81,39,97], \"k\": 8 }\nassert my_solution.maxSum(**test_input) == 114080\n\ntest_input = { \"nums\": [43,58,51,40,39,92,36,57], \"k\": 4 }\nassert my_solution.maxSum(**test_input) == 27548\n\ntest_input = { \"nums\": [85,51,49,13,7,66,21,59,100,14,5,66], \"k\": 8 }\nassert my_solution.maxSum(**test_input) == 63152\n\ntest_input = { \"nums\": [54,52,36,17,34,100,81,82,16,46,26,73,77,55,43,53], \"k\": 14 }\nassert my_solution.maxSum(**test_input) == 91703\n\ntest_input = { \"nums\": [97,1,30,41,82,77,99,56,21,68,14,39,15,26,72], \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 16129\n\ntest_input = { \"nums\": [17,10,28,78,68,68,29,44], \"k\": 5 }\nassert my_solution.maxSum(**test_input) == 33906\n\ntest_input = { \"nums\": [59,30,26,58,87,1,6,98,29,50,57,64,64], \"k\": 10 }\nassert my_solution.maxSum(**test_input) == 69321\n\ntest_input = { \"nums\": [77,23,43,94,74,41,26,39,83,57,85,49,83,34,63,37,42,55,20,18], \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 48387\n\ntest_input = { \"nums\": [54,19,69,95,26,59,68,90,77,62,67,54,42,25,50,23,30,53,29,78], \"k\": 12 }\nassert my_solution.maxSum(**test_input) == 117170\n\ntest_input = { \"nums\": [54,17,16,30,35,63,34,38,26,41,33], \"k\": 9 }\nassert my_solution.maxSum(**test_input) == 22133\n\ntest_input = { \"nums\": [17,24,8,57,68,54,64,53], \"k\": 6 }\nassert my_solution.maxSum(**test_input) == 35987\n\ntest_input = { \"nums\": [11,90,27,72,22,24,54,64,68,94,1,20,45,5,63], \"k\": 10 }\nassert my_solution.maxSum(**test_input) == 69082\n\ntest_input = { \"nums\": [92,84,89,72,80,1,8], \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 25042\n\ntest_input = { \"nums\": [29,14,37,61,7,10,53,95,47,81,1,59,18,25,3,53,43,64,33], \"k\": 5 }\nassert my_solution.maxSum(**test_input) == 56325\n\ntest_input = { \"nums\": [44,94,83,38,63,16,45,90,74,20], \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 16129\n\ntest_input = { \"nums\": [13,65], \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 5930\n\ntest_input = { \"nums\": [16,9,2,66], \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 8285\n\ntest_input = { \"nums\": [30,68,85,13,49,96,59,61,39], \"k\": 7 }\nassert my_solution.maxSum(**test_input) == 54942\n\ntest_input = { \"nums\": [29,47,38,4], \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 6178\n\ntest_input = { \"nums\": [49,30], \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 4225\n\ntest_input = { \"nums\": [64,71,33,46,77,45,33,55,84,30,1,40,2,92,54,88], \"k\": 8 }\nassert my_solution.maxSum(**test_input) == 98815\n\ntest_input = { \"nums\": [55,72,75], \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 16129\n\ntest_input = { \"nums\": [3,34,63,27,49,28,86], \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 24067\n\ntest_input = { \"nums\": [99,29,94,21,54,43,20,79,27,40,90,76,55,27,40,46,76,70,34], \"k\": 13 }\nassert my_solution.maxSum(**test_input) == 118264\n\ntest_input = { \"nums\": [64,11,2,12,11,82,10,42,63,98,99,13], \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 16129\n\ntest_input = { \"nums\": [23,25,45,88,88,93,91,25,34,83,9,85,18], \"k\": 8 }\nassert my_solution.maxSum(**test_input) == 67760\n\ntest_input = { \"nums\": [84,95,7,53,19,46,41,48,48,38], \"k\": 7 }\nassert my_solution.maxSum(**test_input) == 44981\n\ntest_input = { \"nums\": [92,88,27,34], \"k\": 4 }\nassert my_solution.maxSum(**test_input) == 24805", "start_time": 1696732200} +{"task_id": "weekly-contest-365-maximum-value-of-an-ordered-triplet-i", "url": "https://leetcode.com/problems/maximum-value-of-an-ordered-triplet-i", "title": "maximum-value-of-an-ordered-triplet-i", "meta": {"questionId": "3154", "questionFrontendId": "2873", "title": "Maximum Value of an Ordered Triplet I", "titleSlug": "maximum-value-of-an-ordered-triplet-i", "isPaidOnly": false, "difficulty": "Easy", "likes": 130, "dislikes": 10, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0 开始的整数数组 nums 。\n\n请你从所有满足 i < j < k 的下标三元组 (i, j, k) 中,找出并返回下标三元组的最大值。如果所有满足条件的三元组的值都是负数,则返回 0 。\n\n下标三元组 (i, j, k) 的值等于 (nums[i] - nums[j]) * nums[k] 。\n\n示例 1:\n\n输入:nums = [12,6,1,2,7]\n输出:77\n解释:下标三元组 (0, 2, 4) 的值是 (nums[0] - nums[2]) * nums[4] = 77 。\n可以证明不存在值大于 77 的有序下标三元组。\n\n示例 2:\n\n输入:nums = [1,10,3,4,19]\n输出:133\n解释:下标三元组 (1, 2, 4) 的值是 (nums[1] - nums[2]) * nums[4] = 133 。\n可以证明不存在值大于 133 的有序下标三元组。\n\n示例 3:\n\n输入:nums = [1,2,3]\n输出:0\n解释:唯一的下标三元组 (0, 1, 2) 的值是一个负数,(nums[0] - nums[1]) * nums[2] = -3 。因此,答案是 0 。\n\n\n提示:\n\n * 3 <= nums.length <= 100\n * 1 <= nums[i] <= 106\n\"\"\"\nclass Solution:\n def maximumTripletValue(self, nums: List[int]) -> int:\n ", "prompt_sft": "给你一个下标从 0 开始的整数数组 nums 。\n\n请你从所有满足 i < j < k 的下标三元组 (i, j, k) 中,找出并返回下标三元组的最大值。如果所有满足条件的三元组的值都是负数,则返回 0 。\n\n下标三元组 (i, j, k) 的值等于 (nums[i] - nums[j]) * nums[k] 。\n\n示例 1:\n\n输入:nums = [12,6,1,2,7]\n输出:77\n解释:下标三元组 (0, 2, 4) 的值是 (nums[0] - nums[2]) * nums[4] = 77 。\n可以证明不存在值大于 77 的有序下标三元组。\n\n示例 2:\n\n输入:nums = [1,10,3,4,19]\n输出:133\n解释:下标三元组 (1, 2, 4) 的值是 (nums[1] - nums[2]) * nums[4] = 133 。\n可以证明不存在值大于 133 的有序下标三元组。\n\n示例 3:\n\n输入:nums = [1,2,3]\n输出:0\n解释:唯一的下标三元组 (0, 1, 2) 的值是一个负数,(nums[0] - nums[1]) * nums[2] = -3 。因此,答案是 0 。\n\n\n提示:\n\n * 3 <= nums.length <= 100\n * 1 <= nums[i] <= 106\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def maximumTripletValue(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [12,6,1,2,7] }\nassert my_solution.maximumTripletValue(**test_input) == 77\n\ntest_input = { \"nums\": [1,10,3,4,19] }\nassert my_solution.maximumTripletValue(**test_input) == 133\n\ntest_input = { \"nums\": [1,2,3] }\nassert my_solution.maximumTripletValue(**test_input) == 0\n\ntest_input = { \"nums\": [2,3,1] }\nassert my_solution.maximumTripletValue(**test_input) == 0\n\ntest_input = { \"nums\": [5,7,8,4] }\nassert my_solution.maximumTripletValue(**test_input) == 0\n\ntest_input = { \"nums\": [1000000,1,1000000] }\nassert my_solution.maximumTripletValue(**test_input) == 999999000000\n\ntest_input = { \"nums\": [18,15,8,13,10,9,17,10,2,16,17] }\nassert my_solution.maximumTripletValue(**test_input) == 272\n\ntest_input = { \"nums\": [8,6,3,13,2,12,19,5,19,6,10,11,9] }\nassert my_solution.maximumTripletValue(**test_input) == 266\n\ntest_input = { \"nums\": [6,11,12,12,7,9,2,11,12,4,19,14,16,8,16] }\nassert my_solution.maximumTripletValue(**test_input) == 190\n\ntest_input = { \"nums\": [15,14,17,13,18,17,10,19,2,20,12,9] }\nassert my_solution.maximumTripletValue(**test_input) == 340\n\ntest_input = { \"nums\": [6,14,20,19,19,10,3,15,12,13,8,1,2,15,3] }\nassert my_solution.maximumTripletValue(**test_input) == 285\n\ntest_input = { \"nums\": [2,7,19,4,8,20] }\nassert my_solution.maximumTripletValue(**test_input) == 300\n\ntest_input = { \"nums\": [10,13,6,2] }\nassert my_solution.maximumTripletValue(**test_input) == 14\n\ntest_input = { \"nums\": [1,19,1,3,18,10,16,9,3,17,8,9] }\nassert my_solution.maximumTripletValue(**test_input) == 324\n\ntest_input = { \"nums\": [16,2,10,20,16,2,13,8,19] }\nassert my_solution.maximumTripletValue(**test_input) == 342\n\ntest_input = { \"nums\": [19,11,12,4,17,1,7,20,13,10,14,20,11,19,3] }\nassert my_solution.maximumTripletValue(**test_input) == 360\n\ntest_input = { \"nums\": [16,15,12,5,4,12,15,17,5,18,6,16,1,17,4] }\nassert my_solution.maximumTripletValue(**test_input) == 289\n\ntest_input = { \"nums\": [8,10,17,11,2,8,13] }\nassert my_solution.maximumTripletValue(**test_input) == 195\n\ntest_input = { \"nums\": [13,4,3,19,16,14,17,6,20,6,16,4] }\nassert my_solution.maximumTripletValue(**test_input) == 260\n\ntest_input = { \"nums\": [1,8,9,18,4,10,3,13,9] }\nassert my_solution.maximumTripletValue(**test_input) == 195\n\ntest_input = { \"nums\": [10,10,5,19,2] }\nassert my_solution.maximumTripletValue(**test_input) == 95\n\ntest_input = { \"nums\": [15,3,3,18,19,13,7,5,18,1,8,5] }\nassert my_solution.maximumTripletValue(**test_input) == 252\n\ntest_input = { \"nums\": [10,20,10] }\nassert my_solution.maximumTripletValue(**test_input) == 0\n\ntest_input = { \"nums\": [14,9,4,20,9] }\nassert my_solution.maximumTripletValue(**test_input) == 200\n\ntest_input = { \"nums\": [12,20,5,2,13,17,16,1,5,8,18,15,12] }\nassert my_solution.maximumTripletValue(**test_input) == 342\n\ntest_input = { \"nums\": [7,1,17,17,4,20,14,20] }\nassert my_solution.maximumTripletValue(**test_input) == 260\n\ntest_input = { \"nums\": [16,19,8,8,5,18,12,16,8,14,14,7,19] }\nassert my_solution.maximumTripletValue(**test_input) == 266\n\ntest_input = { \"nums\": [17,9,13,7,3,5] }\nassert my_solution.maximumTripletValue(**test_input) == 104\n\ntest_input = { \"nums\": [15,12,2,14,15,18,15,20,14,5,14,14,11,13,7] }\nassert my_solution.maximumTripletValue(**test_input) == 260\n\ntest_input = { \"nums\": [17,20,17,13,5,12,8,12,14,10,14,20] }\nassert my_solution.maximumTripletValue(**test_input) == 300\n\ntest_input = { \"nums\": [1,19,10] }\nassert my_solution.maximumTripletValue(**test_input) == 0\n\ntest_input = { \"nums\": [11,16,10,15,10,5,7,3] }\nassert my_solution.maximumTripletValue(**test_input) == 90\n\ntest_input = { \"nums\": [5,14,19,12,2,5,18,3,20,12,1,11] }\nassert my_solution.maximumTripletValue(**test_input) == 340\n\ntest_input = { \"nums\": [10,8,12,14] }\nassert my_solution.maximumTripletValue(**test_input) == 28\n\ntest_input = { \"nums\": [2,17,18,16,14,20,11,3,18,5,20,6,7] }\nassert my_solution.maximumTripletValue(**test_input) == 340\n\ntest_input = { \"nums\": [19,12,3,19,2,18,3,12,9] }\nassert my_solution.maximumTripletValue(**test_input) == 306\n\ntest_input = { \"nums\": [12,9,11,2,11,3,11,17,13,19] }\nassert my_solution.maximumTripletValue(**test_input) == 190\n\ntest_input = { \"nums\": [8,13,9,8,7,18,20] }\nassert my_solution.maximumTripletValue(**test_input) == 120\n\ntest_input = { \"nums\": [20,8,12,1,7,8,3,3,6] }\nassert my_solution.maximumTripletValue(**test_input) == 152\n\ntest_input = { \"nums\": [8,2,16,6,14,14,13,2,11,5,2,12,15,3,3] }\nassert my_solution.maximumTripletValue(**test_input) == 210\n\ntest_input = { \"nums\": [19,9,9,9,5] }\nassert my_solution.maximumTripletValue(**test_input) == 90\n\ntest_input = { \"nums\": [19,10,5,13,6,9,5,15,19] }\nassert my_solution.maximumTripletValue(**test_input) == 266\n\ntest_input = { \"nums\": [14,18,17,8,2,8,14] }\nassert my_solution.maximumTripletValue(**test_input) == 224\n\ntest_input = { \"nums\": [11,5,17,13,5,8,8,19,17,1] }\nassert my_solution.maximumTripletValue(**test_input) == 228\n\ntest_input = { \"nums\": [18,12,18,14,17,19] }\nassert my_solution.maximumTripletValue(**test_input) == 114\n\ntest_input = { \"nums\": [18,17,8,8,18,9] }\nassert my_solution.maximumTripletValue(**test_input) == 180\n\ntest_input = { \"nums\": [15,3,2,10,11,10,13,18] }\nassert my_solution.maximumTripletValue(**test_input) == 234\n\ntest_input = { \"nums\": [17,17,5,10,19,1,16,3,1,19] }\nassert my_solution.maximumTripletValue(**test_input) == 342\n\ntest_input = { \"nums\": [1,18,4,20,16] }\nassert my_solution.maximumTripletValue(**test_input) == 280\n\ntest_input = { \"nums\": [6,20,4,4,2,19,14,10,9,7,20,5,8] }\nassert my_solution.maximumTripletValue(**test_input) == 360\n\ntest_input = { \"nums\": [5,14,15,18,2,9,15,13,11,16,12,20] }\nassert my_solution.maximumTripletValue(**test_input) == 320\n\ntest_input = { \"nums\": [7,19,17] }\nassert my_solution.maximumTripletValue(**test_input) == 0\n\ntest_input = { \"nums\": [5,7,14,18,13,11,15,20,8,11,12,4,17,2,16] }\nassert my_solution.maximumTripletValue(**test_input) == 288\n\ntest_input = { \"nums\": [4,12,7,2,8,6,9,5,4,1,8] }\nassert my_solution.maximumTripletValue(**test_input) == 90\n\ntest_input = { \"nums\": [11,17,2,18,5] }\nassert my_solution.maximumTripletValue(**test_input) == 270\n\ntest_input = { \"nums\": [19,13,2,2,19] }\nassert my_solution.maximumTripletValue(**test_input) == 323\n\ntest_input = { \"nums\": [14,11,7,6,2,20,16,14,4,12,1,9,16,7,10] }\nassert my_solution.maximumTripletValue(**test_input) == 304\n\ntest_input = { \"nums\": [8,15,6,16,16,9,6,14,4] }\nassert my_solution.maximumTripletValue(**test_input) == 144\n\ntest_input = { \"nums\": [16,19,1,7,18,6,18,5,19,18,19] }\nassert my_solution.maximumTripletValue(**test_input) == 342\n\ntest_input = { \"nums\": [16,14,11,2,17,9,10] }\nassert my_solution.maximumTripletValue(**test_input) == 238\n\ntest_input = { \"nums\": [3,4,18,2,20,1,1,16,15,8,7,14,19,6] }\nassert my_solution.maximumTripletValue(**test_input) == 361\n\ntest_input = { \"nums\": [12,20,14,18,11,16,16,9,12,5,14,17] }\nassert my_solution.maximumTripletValue(**test_input) == 255\n\ntest_input = { \"nums\": [12,19,2,9,6] }\nassert my_solution.maximumTripletValue(**test_input) == 153\n\ntest_input = { \"nums\": [17,19,14,7,10,18] }\nassert my_solution.maximumTripletValue(**test_input) == 216\n\ntest_input = { \"nums\": [3,4,19,10,16,13,6,20] }\nassert my_solution.maximumTripletValue(**test_input) == 260\n\ntest_input = { \"nums\": [11,6,8,9] }\nassert my_solution.maximumTripletValue(**test_input) == 45\n\ntest_input = { \"nums\": [7,12,9,19,10,18,16,2,1,3,7,9,7,7] }\nassert my_solution.maximumTripletValue(**test_input) == 162\n\ntest_input = { \"nums\": [20,9,20,7,3,7,19] }\nassert my_solution.maximumTripletValue(**test_input) == 323\n\ntest_input = { \"nums\": [10,11,3,3,3,2,9,8] }\nassert my_solution.maximumTripletValue(**test_input) == 81\n\ntest_input = { \"nums\": [4,20,15,1,17,2,2,4,10,15,2,8,16,6] }\nassert my_solution.maximumTripletValue(**test_input) == 323\n\ntest_input = { \"nums\": [15,10,1,18,18,16,7,13,9,11] }\nassert my_solution.maximumTripletValue(**test_input) == 252\n\ntest_input = { \"nums\": [10,6,17,11,15,15,18] }\nassert my_solution.maximumTripletValue(**test_input) == 108\n\ntest_input = { \"nums\": [3,6,18] }\nassert my_solution.maximumTripletValue(**test_input) == 0\n\ntest_input = { \"nums\": [4,7,20] }\nassert my_solution.maximumTripletValue(**test_input) == 0\n\ntest_input = { \"nums\": [16,12,5] }\nassert my_solution.maximumTripletValue(**test_input) == 20\n\ntest_input = { \"nums\": [4,17,15,12,2,16,16,13,6,20,14,17,18,16] }\nassert my_solution.maximumTripletValue(**test_input) == 300\n\ntest_input = { \"nums\": [1,7,18,3,1,11,7,17] }\nassert my_solution.maximumTripletValue(**test_input) == 289\n\ntest_input = { \"nums\": [18,16,10,2] }\nassert my_solution.maximumTripletValue(**test_input) == 20\n\ntest_input = { \"nums\": [3,10,18,10,7,8] }\nassert my_solution.maximumTripletValue(**test_input) == 88\n\ntest_input = { \"nums\": [8,6,20,20,4,12,14,7,13,16,12,15,12] }\nassert my_solution.maximumTripletValue(**test_input) == 256\n\ntest_input = { \"nums\": [5,19,11,18,19,14,8,11,4,10] }\nassert my_solution.maximumTripletValue(**test_input) == 152\n\ntest_input = { \"nums\": [17,1,16] }\nassert my_solution.maximumTripletValue(**test_input) == 256\n\ntest_input = { \"nums\": [20,8,17,14,15,2,7,9,1,10,10,4,19,2,1] }\nassert my_solution.maximumTripletValue(**test_input) == 361\n\ntest_input = { \"nums\": [9,16,16] }\nassert my_solution.maximumTripletValue(**test_input) == 0\n\ntest_input = { \"nums\": [2,16,2,19,5,20,2,20,6,6] }\nassert my_solution.maximumTripletValue(**test_input) == 360\n\ntest_input = { \"nums\": [18,3,6,17,4,20,14,6,13,9,5,11] }\nassert my_solution.maximumTripletValue(**test_input) == 300\n\ntest_input = { \"nums\": [12,2,19,15,4,3,18,6,11,9,9,6,15] }\nassert my_solution.maximumTripletValue(**test_input) == 288\n\ntest_input = { \"nums\": [10,15,10,13,7,18,18,3,13,15,20,4,6,15] }\nassert my_solution.maximumTripletValue(**test_input) == 300\n\ntest_input = { \"nums\": [10,15,4,19,6,17,7,10,4,12,14,16,9,14] }\nassert my_solution.maximumTripletValue(**test_input) == 240\n\ntest_input = { \"nums\": [17,6,3,8,13] }\nassert my_solution.maximumTripletValue(**test_input) == 182\n\ntest_input = { \"nums\": [6,18,8,8,16,14,7,18] }\nassert my_solution.maximumTripletValue(**test_input) == 198\n\ntest_input = { \"nums\": [7,7,2,19,16,11,3,15,3,15,16,17] }\nassert my_solution.maximumTripletValue(**test_input) == 272\n\ntest_input = { \"nums\": [9,3,3,12,9,12,5,7,6,2,9,9,14,9,5] }\nassert my_solution.maximumTripletValue(**test_input) == 140\n\ntest_input = { \"nums\": [19,14,15,1,20,10,20,4,10,20,15,15,2,7] }\nassert my_solution.maximumTripletValue(**test_input) == 360\n\ntest_input = { \"nums\": [17,4,10,16,8,20,4,9,11,15,2,7] }\nassert my_solution.maximumTripletValue(**test_input) == 260\n\ntest_input = { \"nums\": [3,8,17,10,10,20,20,8,14,20,1,10,1] }\nassert my_solution.maximumTripletValue(**test_input) == 240\n\ntest_input = { \"nums\": [3,4,11,18,10,19,9,11,14,11,18,15,17,19,3] }\nassert my_solution.maximumTripletValue(**test_input) == 190\n\ntest_input = { \"nums\": [18,10,5,16,13,1,19,10,17,14,14,20] }\nassert my_solution.maximumTripletValue(**test_input) == 340\n\ntest_input = { \"nums\": [18,3,16,14,15,9,13,2,3] }\nassert my_solution.maximumTripletValue(**test_input) == 240\n\ntest_input = { \"nums\": [2,6,19,10,19,14,18,8,3,2] }\nassert my_solution.maximumTripletValue(**test_input) == 171", "start_time": 1696127400} +{"task_id": "weekly-contest-365-maximum-value-of-an-ordered-triplet-ii", "url": "https://leetcode.com/problems/maximum-value-of-an-ordered-triplet-ii", "title": "maximum-value-of-an-ordered-triplet-ii", "meta": {"questionId": "3152", "questionFrontendId": "2874", "title": "Maximum Value of an Ordered Triplet II", "titleSlug": "maximum-value-of-an-ordered-triplet-ii", "isPaidOnly": false, "difficulty": "Medium", "likes": 238, "dislikes": 8, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0 开始的整数数组 nums 。\n\n请你从所有满足 i < j < k 的下标三元组 (i, j, k) 中,找出并返回下标三元组的最大值。如果所有满足条件的三元组的值都是负数,则返回 0 。\n\n下标三元组 (i, j, k) 的值等于 (nums[i] - nums[j]) * nums[k] 。\n\n示例 1:\n\n输入:nums = [12,6,1,2,7]\n输出:77\n解释:下标三元组 (0, 2, 4) 的值是 (nums[0] - nums[2]) * nums[4] = 77 。\n可以证明不存在值大于 77 的有序下标三元组。\n\n示例 2:\n\n输入:nums = [1,10,3,4,19]\n输出:133\n解释:下标三元组 (1, 2, 4) 的值是 (nums[1] - nums[2]) * nums[4] = 133 。\n可以证明不存在值大于 133 的有序下标三元组。\n\n示例 3:\n\n输入:nums = [1,2,3]\n输出:0\n解释:唯一的下标三元组 (0, 1, 2) 的值是一个负数,(nums[0] - nums[1]) * nums[2] = -3 。因此,答案是 0 。\n\n\n提示:\n\n * 3 <= nums.length <= 105\n * 1 <= nums[i] <= 106\n\"\"\"\nclass Solution:\n def maximumTripletValue(self, nums: List[int]) -> int:\n ", "prompt_sft": "给你一个下标从 0 开始的整数数组 nums 。\n\n请你从所有满足 i < j < k 的下标三元组 (i, j, k) 中,找出并返回下标三元组的最大值。如果所有满足条件的三元组的值都是负数,则返回 0 。\n\n下标三元组 (i, j, k) 的值等于 (nums[i] - nums[j]) * nums[k] 。\n\n示例 1:\n\n输入:nums = [12,6,1,2,7]\n输出:77\n解释:下标三元组 (0, 2, 4) 的值是 (nums[0] - nums[2]) * nums[4] = 77 。\n可以证明不存在值大于 77 的有序下标三元组。\n\n示例 2:\n\n输入:nums = [1,10,3,4,19]\n输出:133\n解释:下标三元组 (1, 2, 4) 的值是 (nums[1] - nums[2]) * nums[4] = 133 。\n可以证明不存在值大于 133 的有序下标三元组。\n\n示例 3:\n\n输入:nums = [1,2,3]\n输出:0\n解释:唯一的下标三元组 (0, 1, 2) 的值是一个负数,(nums[0] - nums[1]) * nums[2] = -3 。因此,答案是 0 。\n\n\n提示:\n\n * 3 <= nums.length <= 105\n * 1 <= nums[i] <= 106\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def maximumTripletValue(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [12,6,1,2,7] }\nassert my_solution.maximumTripletValue(**test_input) == 77\n\ntest_input = { \"nums\": [1,10,3,4,19] }\nassert my_solution.maximumTripletValue(**test_input) == 133\n\ntest_input = { \"nums\": [1,2,3] }\nassert my_solution.maximumTripletValue(**test_input) == 0\n\ntest_input = { \"nums\": [2,3,1] }\nassert my_solution.maximumTripletValue(**test_input) == 0\n\ntest_input = { \"nums\": [5,7,8,4] }\nassert my_solution.maximumTripletValue(**test_input) == 0\n\ntest_input = { \"nums\": [1000000,1,1000000] }\nassert my_solution.maximumTripletValue(**test_input) == 999999000000\n\ntest_input = { \"nums\": [18,15,8,13,10,9,17,10,2,16,17] }\nassert my_solution.maximumTripletValue(**test_input) == 272\n\ntest_input = { \"nums\": [8,6,3,13,2,12,19,5,19,6,10,11,9] }\nassert my_solution.maximumTripletValue(**test_input) == 266\n\ntest_input = { \"nums\": [6,11,12,12,7,9,2,11,12,4,19,14,16,8,16] }\nassert my_solution.maximumTripletValue(**test_input) == 190\n\ntest_input = { \"nums\": [15,14,17,13,18,17,10,19,2,20,12,9] }\nassert my_solution.maximumTripletValue(**test_input) == 340\n\ntest_input = { \"nums\": [6,14,20,19,19,10,3,15,12,13,8,1,2,15,3] }\nassert my_solution.maximumTripletValue(**test_input) == 285\n\ntest_input = { \"nums\": [2,7,19,4,8,20] }\nassert my_solution.maximumTripletValue(**test_input) == 300\n\ntest_input = { \"nums\": [10,13,6,2] }\nassert my_solution.maximumTripletValue(**test_input) == 14\n\ntest_input = { \"nums\": [1,19,1,3,18,10,16,9,3,17,8,9] }\nassert my_solution.maximumTripletValue(**test_input) == 324\n\ntest_input = { \"nums\": [16,2,10,20,16,2,13,8,19] }\nassert my_solution.maximumTripletValue(**test_input) == 342\n\ntest_input = { \"nums\": [19,11,12,4,17,1,7,20,13,10,14,20,11,19,3] }\nassert my_solution.maximumTripletValue(**test_input) == 360\n\ntest_input = { \"nums\": [16,15,12,5,4,12,15,17,5,18,6,16,1,17,4] }\nassert my_solution.maximumTripletValue(**test_input) == 289\n\ntest_input = { \"nums\": [8,10,17,11,2,8,13] }\nassert my_solution.maximumTripletValue(**test_input) == 195\n\ntest_input = { \"nums\": [13,4,3,19,16,14,17,6,20,6,16,4] }\nassert my_solution.maximumTripletValue(**test_input) == 260\n\ntest_input = { \"nums\": [1,8,9,18,4,10,3,13,9] }\nassert my_solution.maximumTripletValue(**test_input) == 195\n\ntest_input = { \"nums\": [10,10,5,19,2] }\nassert my_solution.maximumTripletValue(**test_input) == 95\n\ntest_input = { \"nums\": [15,3,3,18,19,13,7,5,18,1,8,5] }\nassert my_solution.maximumTripletValue(**test_input) == 252\n\ntest_input = { \"nums\": [10,20,10] }\nassert my_solution.maximumTripletValue(**test_input) == 0\n\ntest_input = { \"nums\": [14,9,4,20,9] }\nassert my_solution.maximumTripletValue(**test_input) == 200\n\ntest_input = { \"nums\": [12,20,5,2,13,17,16,1,5,8,18,15,12] }\nassert my_solution.maximumTripletValue(**test_input) == 342\n\ntest_input = { \"nums\": [7,1,17,17,4,20,14,20] }\nassert my_solution.maximumTripletValue(**test_input) == 260\n\ntest_input = { \"nums\": [16,19,8,8,5,18,12,16,8,14,14,7,19] }\nassert my_solution.maximumTripletValue(**test_input) == 266\n\ntest_input = { \"nums\": [17,9,13,7,3,5] }\nassert my_solution.maximumTripletValue(**test_input) == 104\n\ntest_input = { \"nums\": [15,12,2,14,15,18,15,20,14,5,14,14,11,13,7] }\nassert my_solution.maximumTripletValue(**test_input) == 260\n\ntest_input = { \"nums\": [17,20,17,13,5,12,8,12,14,10,14,20] }\nassert my_solution.maximumTripletValue(**test_input) == 300\n\ntest_input = { \"nums\": [1,19,10] }\nassert my_solution.maximumTripletValue(**test_input) == 0\n\ntest_input = { \"nums\": [11,16,10,15,10,5,7,3] }\nassert my_solution.maximumTripletValue(**test_input) == 90\n\ntest_input = { \"nums\": [5,14,19,12,2,5,18,3,20,12,1,11] }\nassert my_solution.maximumTripletValue(**test_input) == 340\n\ntest_input = { \"nums\": [10,8,12,14] }\nassert my_solution.maximumTripletValue(**test_input) == 28\n\ntest_input = { \"nums\": [2,17,18,16,14,20,11,3,18,5,20,6,7] }\nassert my_solution.maximumTripletValue(**test_input) == 340\n\ntest_input = { \"nums\": [19,12,3,19,2,18,3,12,9] }\nassert my_solution.maximumTripletValue(**test_input) == 306\n\ntest_input = { \"nums\": [12,9,11,2,11,3,11,17,13,19] }\nassert my_solution.maximumTripletValue(**test_input) == 190\n\ntest_input = { \"nums\": [8,13,9,8,7,18,20] }\nassert my_solution.maximumTripletValue(**test_input) == 120\n\ntest_input = { \"nums\": [20,8,12,1,7,8,3,3,6] }\nassert my_solution.maximumTripletValue(**test_input) == 152\n\ntest_input = { \"nums\": [8,2,16,6,14,14,13,2,11,5,2,12,15,3,3] }\nassert my_solution.maximumTripletValue(**test_input) == 210\n\ntest_input = { \"nums\": [19,9,9,9,5] }\nassert my_solution.maximumTripletValue(**test_input) == 90\n\ntest_input = { \"nums\": [19,10,5,13,6,9,5,15,19] }\nassert my_solution.maximumTripletValue(**test_input) == 266\n\ntest_input = { \"nums\": [14,18,17,8,2,8,14] }\nassert my_solution.maximumTripletValue(**test_input) == 224\n\ntest_input = { \"nums\": [11,5,17,13,5,8,8,19,17,1] }\nassert my_solution.maximumTripletValue(**test_input) == 228\n\ntest_input = { \"nums\": [18,12,18,14,17,19] }\nassert my_solution.maximumTripletValue(**test_input) == 114\n\ntest_input = { \"nums\": [18,17,8,8,18,9] }\nassert my_solution.maximumTripletValue(**test_input) == 180\n\ntest_input = { \"nums\": [15,3,2,10,11,10,13,18] }\nassert my_solution.maximumTripletValue(**test_input) == 234\n\ntest_input = { \"nums\": [17,17,5,10,19,1,16,3,1,19] }\nassert my_solution.maximumTripletValue(**test_input) == 342\n\ntest_input = { \"nums\": [1,18,4,20,16] }\nassert my_solution.maximumTripletValue(**test_input) == 280\n\ntest_input = { \"nums\": [6,20,4,4,2,19,14,10,9,7,20,5,8] }\nassert my_solution.maximumTripletValue(**test_input) == 360\n\ntest_input = { \"nums\": [5,14,15,18,2,9,15,13,11,16,12,20] }\nassert my_solution.maximumTripletValue(**test_input) == 320\n\ntest_input = { \"nums\": [7,19,17] }\nassert my_solution.maximumTripletValue(**test_input) == 0\n\ntest_input = { \"nums\": [5,7,14,18,13,11,15,20,8,11,12,4,17,2,16] }\nassert my_solution.maximumTripletValue(**test_input) == 288\n\ntest_input = { \"nums\": [4,12,7,2,8,6,9,5,4,1,8] }\nassert my_solution.maximumTripletValue(**test_input) == 90\n\ntest_input = { \"nums\": [11,17,2,18,5] }\nassert my_solution.maximumTripletValue(**test_input) == 270\n\ntest_input = { \"nums\": [19,13,2,2,19] }\nassert my_solution.maximumTripletValue(**test_input) == 323\n\ntest_input = { \"nums\": [14,11,7,6,2,20,16,14,4,12,1,9,16,7,10] }\nassert my_solution.maximumTripletValue(**test_input) == 304\n\ntest_input = { \"nums\": [8,15,6,16,16,9,6,14,4] }\nassert my_solution.maximumTripletValue(**test_input) == 144\n\ntest_input = { \"nums\": [16,19,1,7,18,6,18,5,19,18,19] }\nassert my_solution.maximumTripletValue(**test_input) == 342\n\ntest_input = { \"nums\": [16,14,11,2,17,9,10] }\nassert my_solution.maximumTripletValue(**test_input) == 238\n\ntest_input = { \"nums\": [3,4,18,2,20,1,1,16,15,8,7,14,19,6] }\nassert my_solution.maximumTripletValue(**test_input) == 361\n\ntest_input = { \"nums\": [12,20,14,18,11,16,16,9,12,5,14,17] }\nassert my_solution.maximumTripletValue(**test_input) == 255\n\ntest_input = { \"nums\": [12,19,2,9,6] }\nassert my_solution.maximumTripletValue(**test_input) == 153\n\ntest_input = { \"nums\": [17,19,14,7,10,18] }\nassert my_solution.maximumTripletValue(**test_input) == 216\n\ntest_input = { \"nums\": [3,4,19,10,16,13,6,20] }\nassert my_solution.maximumTripletValue(**test_input) == 260\n\ntest_input = { \"nums\": [11,6,8,9] }\nassert my_solution.maximumTripletValue(**test_input) == 45\n\ntest_input = { \"nums\": [7,12,9,19,10,18,16,2,1,3,7,9,7,7] }\nassert my_solution.maximumTripletValue(**test_input) == 162\n\ntest_input = { \"nums\": [20,9,20,7,3,7,19] }\nassert my_solution.maximumTripletValue(**test_input) == 323\n\ntest_input = { \"nums\": [10,11,3,3,3,2,9,8] }\nassert my_solution.maximumTripletValue(**test_input) == 81\n\ntest_input = { \"nums\": [4,20,15,1,17,2,2,4,10,15,2,8,16,6] }\nassert my_solution.maximumTripletValue(**test_input) == 323\n\ntest_input = { \"nums\": [15,10,1,18,18,16,7,13,9,11] }\nassert my_solution.maximumTripletValue(**test_input) == 252\n\ntest_input = { \"nums\": [10,6,17,11,15,15,18] }\nassert my_solution.maximumTripletValue(**test_input) == 108\n\ntest_input = { \"nums\": [3,6,18] }\nassert my_solution.maximumTripletValue(**test_input) == 0\n\ntest_input = { \"nums\": [4,7,20] }\nassert my_solution.maximumTripletValue(**test_input) == 0\n\ntest_input = { \"nums\": [16,12,5] }\nassert my_solution.maximumTripletValue(**test_input) == 20\n\ntest_input = { \"nums\": [4,17,15,12,2,16,16,13,6,20,14,17,18,16] }\nassert my_solution.maximumTripletValue(**test_input) == 300\n\ntest_input = { \"nums\": [1,7,18,3,1,11,7,17] }\nassert my_solution.maximumTripletValue(**test_input) == 289\n\ntest_input = { \"nums\": [18,16,10,2] }\nassert my_solution.maximumTripletValue(**test_input) == 20\n\ntest_input = { \"nums\": [3,10,18,10,7,8] }\nassert my_solution.maximumTripletValue(**test_input) == 88\n\ntest_input = { \"nums\": [8,6,20,20,4,12,14,7,13,16,12,15,12] }\nassert my_solution.maximumTripletValue(**test_input) == 256\n\ntest_input = { \"nums\": [5,19,11,18,19,14,8,11,4,10] }\nassert my_solution.maximumTripletValue(**test_input) == 152\n\ntest_input = { \"nums\": [17,1,16] }\nassert my_solution.maximumTripletValue(**test_input) == 256\n\ntest_input = { \"nums\": [20,8,17,14,15,2,7,9,1,10,10,4,19,2,1] }\nassert my_solution.maximumTripletValue(**test_input) == 361\n\ntest_input = { \"nums\": [9,16,16] }\nassert my_solution.maximumTripletValue(**test_input) == 0\n\ntest_input = { \"nums\": [2,16,2,19,5,20,2,20,6,6] }\nassert my_solution.maximumTripletValue(**test_input) == 360\n\ntest_input = { \"nums\": [18,3,6,17,4,20,14,6,13,9,5,11] }\nassert my_solution.maximumTripletValue(**test_input) == 300\n\ntest_input = { \"nums\": [12,2,19,15,4,3,18,6,11,9,9,6,15] }\nassert my_solution.maximumTripletValue(**test_input) == 288\n\ntest_input = { \"nums\": [10,15,10,13,7,18,18,3,13,15,20,4,6,15] }\nassert my_solution.maximumTripletValue(**test_input) == 300\n\ntest_input = { \"nums\": [10,15,4,19,6,17,7,10,4,12,14,16,9,14] }\nassert my_solution.maximumTripletValue(**test_input) == 240\n\ntest_input = { \"nums\": [17,6,3,8,13] }\nassert my_solution.maximumTripletValue(**test_input) == 182\n\ntest_input = { \"nums\": [6,18,8,8,16,14,7,18] }\nassert my_solution.maximumTripletValue(**test_input) == 198\n\ntest_input = { \"nums\": [7,7,2,19,16,11,3,15,3,15,16,17] }\nassert my_solution.maximumTripletValue(**test_input) == 272\n\ntest_input = { \"nums\": [9,3,3,12,9,12,5,7,6,2,9,9,14,9,5] }\nassert my_solution.maximumTripletValue(**test_input) == 140\n\ntest_input = { \"nums\": [19,14,15,1,20,10,20,4,10,20,15,15,2,7] }\nassert my_solution.maximumTripletValue(**test_input) == 360\n\ntest_input = { \"nums\": [17,4,10,16,8,20,4,9,11,15,2,7] }\nassert my_solution.maximumTripletValue(**test_input) == 260\n\ntest_input = { \"nums\": [3,8,17,10,10,20,20,8,14,20,1,10,1] }\nassert my_solution.maximumTripletValue(**test_input) == 240\n\ntest_input = { \"nums\": [3,4,11,18,10,19,9,11,14,11,18,15,17,19,3] }\nassert my_solution.maximumTripletValue(**test_input) == 190\n\ntest_input = { \"nums\": [18,10,5,16,13,1,19,10,17,14,14,20] }\nassert my_solution.maximumTripletValue(**test_input) == 340\n\ntest_input = { \"nums\": [18,3,16,14,15,9,13,2,3] }\nassert my_solution.maximumTripletValue(**test_input) == 240\n\ntest_input = { \"nums\": [2,6,19,10,19,14,18,8,3,2] }\nassert my_solution.maximumTripletValue(**test_input) == 171", "start_time": 1696127400} +{"task_id": "weekly-contest-365-minimum-size-subarray-in-infinite-array", "url": "https://leetcode.com/problems/minimum-size-subarray-in-infinite-array", "title": "minimum-size-subarray-in-infinite-array", "meta": {"questionId": "3141", "questionFrontendId": "2875", "title": "Minimum Size Subarray in Infinite Array", "titleSlug": "minimum-size-subarray-in-infinite-array", "isPaidOnly": false, "difficulty": "Medium", "likes": 309, "dislikes": 19, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0 开始的数组 nums 和一个整数 target 。\n\n下标从 0 开始的数组 infinite_nums 是通过无限地将 nums 的元素追加到自己之后生成的。\n\n请你从 infinite_nums 中找出满足 元素和 等于 target 的 最短 子数组,并返回该子数组的长度。如果不存在满足条件的子数组,返回 -1 。\n\n示例 1:\n\n输入:nums = [1,2,3], target = 5\n输出:2\n解释:在这个例子中 infinite_nums = [1,2,3,1,2,3,1,2,...] 。\n区间 [1,2] 内的子数组的元素和等于 target = 5 ,且长度 length = 2 。\n可以证明,当元素和等于目标值 target = 5 时,2 是子数组的最短长度。\n\n示例 2:\n\n输入:nums = [1,1,1,2,3], target = 4\n输出:2\n解释:在这个例子中 infinite_nums = [1,1,1,2,3,1,1,1,2,3,1,1,...].\n区间 [4,5] 内的子数组的元素和等于 target = 4 ,且长度 length = 2 。\n可以证明,当元素和等于目标值 target = 4 时,2 是子数组的最短长度。\n\n示例 3:\n\n输入:nums = [2,4,6,8], target = 3\n输出:-1\n解释:在这个例子中 infinite_nums = [2,4,6,8,2,4,6,8,...] 。\n可以证明,不存在元素和等于目标值 target = 3 的子数组。\n\n\n提示:\n\n * 1 <= nums.length <= 105\n * 1 <= nums[i] <= 105\n * 1 <= target <= 109\n\"\"\"\nclass Solution:\n def minSizeSubarray(self, nums: List[int], target: int) -> int:\n ", "prompt_sft": "给你一个下标从 0 开始的数组 nums 和一个整数 target 。\n\n下标从 0 开始的数组 infinite_nums 是通过无限地将 nums 的元素追加到自己之后生成的。\n\n请你从 infinite_nums 中找出满足 元素和 等于 target 的 最短 子数组,并返回该子数组的长度。如果不存在满足条件的子数组,返回 -1 。\n\n示例 1:\n\n输入:nums = [1,2,3], target = 5\n输出:2\n解释:在这个例子中 infinite_nums = [1,2,3,1,2,3,1,2,...] 。\n区间 [1,2] 内的子数组的元素和等于 target = 5 ,且长度 length = 2 。\n可以证明,当元素和等于目标值 target = 5 时,2 是子数组的最短长度。\n\n示例 2:\n\n输入:nums = [1,1,1,2,3], target = 4\n输出:2\n解释:在这个例子中 infinite_nums = [1,1,1,2,3,1,1,1,2,3,1,1,...].\n区间 [4,5] 内的子数组的元素和等于 target = 4 ,且长度 length = 2 。\n可以证明,当元素和等于目标值 target = 4 时,2 是子数组的最短长度。\n\n示例 3:\n\n输入:nums = [2,4,6,8], target = 3\n输出:-1\n解释:在这个例子中 infinite_nums = [2,4,6,8,2,4,6,8,...] 。\n可以证明,不存在元素和等于目标值 target = 3 的子数组。\n\n\n提示:\n\n * 1 <= nums.length <= 105\n * 1 <= nums[i] <= 105\n * 1 <= target <= 109\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def minSizeSubarray(self, nums: List[int], target: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,2,3], \"target\": 5 }\nassert my_solution.minSizeSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,1,2,3], \"target\": 4 }\nassert my_solution.minSizeSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [2,4,6,8], \"target\": 3 }\nassert my_solution.minSizeSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [2,1,5,7,7,1,6,3], \"target\": 39 }\nassert my_solution.minSizeSubarray(**test_input) == 9\n\ntest_input = { \"nums\": [17,4,3,14,17,6,15], \"target\": 85 }\nassert my_solution.minSizeSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [18,3,11,19,7,16,6,7,3,6,18,9,9,1,14,17,15,14,12,10], \"target\": 7 }\nassert my_solution.minSizeSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [2,3,5,2,3,4,4,1,3,5,2,2,5,1,1,2,5], \"target\": 19 }\nassert my_solution.minSizeSubarray(**test_input) == 6\n\ntest_input = { \"nums\": [4,1,5,7,1,6,1,7,2,2,5,5,5,6,3], \"target\": 20 }\nassert my_solution.minSizeSubarray(**test_input) == 5\n\ntest_input = { \"nums\": [7,3,5], \"target\": 36 }\nassert my_solution.minSizeSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [1,11,6,4,13], \"target\": 22 }\nassert my_solution.minSizeSubarray(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,2,2,1,2,1,2,1,2,1], \"target\": 83 }\nassert my_solution.minSizeSubarray(**test_input) == 53\n\ntest_input = { \"nums\": [4,3,5,4,5,4,4,4,5,7,4,5,6,3,1,4,6,3,7], \"target\": 15 }\nassert my_solution.minSizeSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,3,2,1,5,3,4,5], \"target\": 53 }\nassert my_solution.minSizeSubarray(**test_input) == 19\n\ntest_input = { \"nums\": [2,5,6,4], \"target\": 95 }\nassert my_solution.minSizeSubarray(**test_input) == 22\n\ntest_input = { \"nums\": [6,6,4,5,2,8,1,8,7,6,6,7,4,1,9,6,8,8], \"target\": 55 }\nassert my_solution.minSizeSubarray(**test_input) == 9\n\ntest_input = { \"nums\": [1,2,8,19,17,2,3,11,8,12,16,18,7], \"target\": 36 }\nassert my_solution.minSizeSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [12,14,4,14,13,16,5], \"target\": 36 }\nassert my_solution.minSizeSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], \"target\": 37 }\nassert my_solution.minSizeSubarray(**test_input) == 37\n\ntest_input = { \"nums\": [5,7,2,6,4,1,6,7,1,4,7,6,7,7,6,6,4,6,8], \"target\": 90 }\nassert my_solution.minSizeSubarray(**test_input) == 17\n\ntest_input = { \"nums\": [3,5,15,17,6,17,10,15,10,4,6], \"target\": 25 }\nassert my_solution.minSizeSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [14,5], \"target\": 23 }\nassert my_solution.minSizeSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,5,9], \"target\": 68 }\nassert my_solution.minSizeSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [11,1,17,14,9,16,5,3,7,16,14,18,17,10], \"target\": 82 }\nassert my_solution.minSizeSubarray(**test_input) == 6\n\ntest_input = { \"nums\": [9,6,8,4,3,4,6,4,7,2,6,9,2,4,5,4], \"target\": 71 }\nassert my_solution.minSizeSubarray(**test_input) == 14\n\ntest_input = { \"nums\": [2,4,4,3,2,3,2,5,3,1,5,1,4,2,6], \"target\": 23 }\nassert my_solution.minSizeSubarray(**test_input) == 7\n\ntest_input = { \"nums\": [3,6], \"target\": 66 }\nassert my_solution.minSizeSubarray(**test_input) == 15\n\ntest_input = { \"nums\": [1,4,8,5,9,8,8,2,3,1,6,2,7,5,5,3,3,5,6], \"target\": 57 }\nassert my_solution.minSizeSubarray(**test_input) == 10\n\ntest_input = { \"nums\": [1,6,5,5,1,1,2,5,3,1,5,3,2,4,6,6], \"target\": 56 }\nassert my_solution.minSizeSubarray(**test_input) == 16\n\ntest_input = { \"nums\": [5,3,5,4,3,1,3,3,1,3,3,5,5,4,5,5,5,5], \"target\": 8 }\nassert my_solution.minSizeSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [2,2,1,3,2,2,2,3,3,2,1,3,3,2,3,3], \"target\": 93 }\nassert my_solution.minSizeSubarray(**test_input) == 40\n\ntest_input = { \"nums\": [5,1,4,1,5,6], \"target\": 71 }\nassert my_solution.minSizeSubarray(**test_input) == 19\n\ntest_input = { \"nums\": [3,5,6,6,1,8,4,9,6,2,3,9,6,8,7,3,6,1,8,6], \"target\": 60 }\nassert my_solution.minSizeSubarray(**test_input) == 11\n\ntest_input = { \"nums\": [12,15,9,3,3,12,13,14,7,11,7,15,12,5,11], \"target\": 18 }\nassert my_solution.minSizeSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [3,11,10,12,9,13,9], \"target\": 19 }\nassert my_solution.minSizeSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [3,4,4], \"target\": 35 }\nassert my_solution.minSizeSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [4,5,2,5,5,5,1], \"target\": 87 }\nassert my_solution.minSizeSubarray(**test_input) == 23\n\ntest_input = { \"nums\": [2,13,15,3,6,7,16,7,9,10,4,3,12,9,13,2,9,13,15], \"target\": 4 }\nassert my_solution.minSizeSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,16,10,15,15,13,11,10,6,12,15,9], \"target\": 30 }\nassert my_solution.minSizeSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [3,5], \"target\": 85 }\nassert my_solution.minSizeSubarray(**test_input) == 21\n\ntest_input = { \"nums\": [1,4,3,1,4,4,2,3], \"target\": 6 }\nassert my_solution.minSizeSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [2,10,12,10,4,4,12,5,12,12,5], \"target\": 33 }\nassert my_solution.minSizeSubarray(**test_input) == 4\n\ntest_input = { \"nums\": [5,9,7,10,4,7,9,11,6,3,1,8,6,1,11,1,1], \"target\": 72 }\nassert my_solution.minSizeSubarray(**test_input) == 11\n\ntest_input = { \"nums\": [19,18,6], \"target\": 56 }\nassert my_solution.minSizeSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [3,5,7,6,5,3,7,7,1,5,3,1,5,6,3,1,6,1,3], \"target\": 20 }\nassert my_solution.minSizeSubarray(**test_input) == 4\n\ntest_input = { \"nums\": [5,5,4,1,2,2,2,3,2,4,2,5], \"target\": 56 }\nassert my_solution.minSizeSubarray(**test_input) == 16\n\ntest_input = { \"nums\": [1,1,1,1,1,1,1,1], \"target\": 22 }\nassert my_solution.minSizeSubarray(**test_input) == 22\n\ntest_input = { \"nums\": [1,2], \"target\": 72 }\nassert my_solution.minSizeSubarray(**test_input) == 48\n\ntest_input = { \"nums\": [4,3,6,6,2,6,1,6,7,5,7,6,1,5,7], \"target\": 82 }\nassert my_solution.minSizeSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [4,1,5,2,3,1,2,4,1,5,3,3,5,2,6,6,5,2,1], \"target\": 63 }\nassert my_solution.minSizeSubarray(**test_input) == 20\n\ntest_input = { \"nums\": [8,2,5,4,1,6,6,6,6,4,4,5,5,9,6,6,9,2], \"target\": 4 }\nassert my_solution.minSizeSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [18,12,13,9,17,11], \"target\": 82 }\nassert my_solution.minSizeSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [13,3,1,5,13,7,12,5], \"target\": 35 }\nassert my_solution.minSizeSubarray(**test_input) == 5\n\ntest_input = { \"nums\": [4,10,12,6,2,2,4,12,6,1,1,2,2,10,6,11,5,4,9], \"target\": 49 }\nassert my_solution.minSizeSubarray(**test_input) == 7\n\ntest_input = { \"nums\": [8], \"target\": 68 }\nassert my_solution.minSizeSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [7,2,6,7,6,4,4,1,6,4,1,7,7,2,2,4,4,4], \"target\": 29 }\nassert my_solution.minSizeSubarray(**test_input) == 6\n\ntest_input = { \"nums\": [4,7,6,12,10,13,7,6,6,1,15,2,4,8,12], \"target\": 43 }\nassert my_solution.minSizeSubarray(**test_input) == 6\n\ntest_input = { \"nums\": [4,10], \"target\": 10 }\nassert my_solution.minSizeSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [4,3,2,4,5,3,7,12,2,2,10], \"target\": 43 }\nassert my_solution.minSizeSubarray(**test_input) == 8\n\ntest_input = { \"nums\": [1,1,1,1,1,1,1,1,1,1,1,1], \"target\": 58 }\nassert my_solution.minSizeSubarray(**test_input) == 58\n\ntest_input = { \"nums\": [1,1,1,1,1], \"target\": 20 }\nassert my_solution.minSizeSubarray(**test_input) == 20\n\ntest_input = { \"nums\": [4,3], \"target\": 23 }\nassert my_solution.minSizeSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [3,2,1,3,2,1,3,1,1,1,2,1,2,1,2,3,3,1], \"target\": 78 }\nassert my_solution.minSizeSubarray(**test_input) == 41\n\ntest_input = { \"nums\": [3,2,4,2,4,2,5,4,5,3,4,4,2,4,4,1], \"target\": 19 }\nassert my_solution.minSizeSubarray(**test_input) == 5\n\ntest_input = { \"nums\": [17], \"target\": 1 }\nassert my_solution.minSizeSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [10,12,1,11,9,5,4,5,1,10,8,12,5,4], \"target\": 82 }\nassert my_solution.minSizeSubarray(**test_input) == 10\n\ntest_input = { \"nums\": [6], \"target\": 44 }\nassert my_solution.minSizeSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [4,6,2,6,3,5,2,5,5,4,3,1,5,4,5,5,4,5,5,6], \"target\": 12 }\nassert my_solution.minSizeSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [14,4,13,12,18,8,4,15,4,14,17,4,2], \"target\": 8 }\nassert my_solution.minSizeSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [4,4,6,5,3,4,1,4,2,6,3], \"target\": 32 }\nassert my_solution.minSizeSubarray(**test_input) == 9\n\ntest_input = { \"nums\": [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], \"target\": 28 }\nassert my_solution.minSizeSubarray(**test_input) == 28\n\ntest_input = { \"nums\": [5,10,1,3,14,7,13,6,5,7,10,3,10,5,8,5,7,5,6,7], \"target\": 25 }\nassert my_solution.minSizeSubarray(**test_input) == 4\n\ntest_input = { \"nums\": [12,3,4,10,5,8,12,7,12,7,5,8,4,8,11,11], \"target\": 48 }\nassert my_solution.minSizeSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [3,11,5,5,3,10,12,12,12,3,10], \"target\": 88 }\nassert my_solution.minSizeSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [8,2,10,5], \"target\": 28 }\nassert my_solution.minSizeSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [3,5,1,4,5,2,5,3,1,2,1,1,1,3,3,3,5], \"target\": 68 }\nassert my_solution.minSizeSubarray(**test_input) == 23\n\ntest_input = { \"nums\": [1,4,1,4,4], \"target\": 21 }\nassert my_solution.minSizeSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [15,8,8,19,8,12,15,3,15,8,10,9], \"target\": 77 }\nassert my_solution.minSizeSubarray(**test_input) == 7\n\ntest_input = { \"nums\": [4,4], \"target\": 80 }\nassert my_solution.minSizeSubarray(**test_input) == 20\n\ntest_input = { \"nums\": [4,9,3,7,5,4,5,1,3,5], \"target\": 69 }\nassert my_solution.minSizeSubarray(**test_input) == 14\n\ntest_input = { \"nums\": [2,8,2,8,1,5,8,9,3,4,6,6,6,1,7,9], \"target\": 93 }\nassert my_solution.minSizeSubarray(**test_input) == 17\n\ntest_input = { \"nums\": [7,11,14,12,3,16,11,9], \"target\": 10 }\nassert my_solution.minSizeSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [2,1,2,1,3,2,1,1,2], \"target\": 17 }\nassert my_solution.minSizeSubarray(**test_input) == 10\n\ntest_input = { \"nums\": [5,20,18,2,8], \"target\": 45 }\nassert my_solution.minSizeSubarray(**test_input) == 4\n\ntest_input = { \"nums\": [2,1,2,1,2,1,1,1,2,2], \"target\": 58 }\nassert my_solution.minSizeSubarray(**test_input) == 38\n\ntest_input = { \"nums\": [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], \"target\": 17 }\nassert my_solution.minSizeSubarray(**test_input) == 17\n\ntest_input = { \"nums\": [18,6,8,17,3,10,14,12,4,13,12,10,5,18,11], \"target\": 95 }\nassert my_solution.minSizeSubarray(**test_input) == 9\n\ntest_input = { \"nums\": [19,12,14], \"target\": 57 }\nassert my_solution.minSizeSubarray(**test_input) == 4\n\ntest_input = { \"nums\": [3,13,14], \"target\": 11 }\nassert my_solution.minSizeSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [17,6,8,7,4,6,6,3,8,1,8,10,18,13,2], \"target\": 32 }\nassert my_solution.minSizeSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [3,12,4,9,5,2,2,9,9,6,9,11,9], \"target\": 41 }\nassert my_solution.minSizeSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [3,14,2,9,5,14,15,4,3,4,17,11], \"target\": 3 }\nassert my_solution.minSizeSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [2,5,3,6,3,6,1,1,5,1], \"target\": 37 }\nassert my_solution.minSizeSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [13,6,4,7,3,6,4,10,13,10,5,4,2,1,7,11,3,3,12], \"target\": 51 }\nassert my_solution.minSizeSubarray(**test_input) == 7\n\ntest_input = { \"nums\": [1,10,9,16,3,10,2,5,1,10], \"target\": 83 }\nassert my_solution.minSizeSubarray(**test_input) == 11\n\ntest_input = { \"nums\": [2,10,13,3,4,19,14,20,11,15,4,3,17,8,2,3,1,13,8], \"target\": 1 }\nassert my_solution.minSizeSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [4,5,5,3,5,4,2,11,5,9,4,6], \"target\": 41 }\nassert my_solution.minSizeSubarray(**test_input) == 7\n\ntest_input = { \"nums\": [2,8,9,6,11,17,3,6,9,7,2,8,9,11,19], \"target\": 39 }\nassert my_solution.minSizeSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [8,13,9,5,8,6,17,16,14,7,10,15,16], \"target\": 8 }\nassert my_solution.minSizeSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [10,20,16,1,11,18,13,6,13,6,9,14,16,12,13,7,19], \"target\": 59 }\nassert my_solution.minSizeSubarray(**test_input) == 5\n\ntest_input = { \"nums\": [1,1,1,1,1,1,1,1,1,1,1,1], \"target\": 6 }\nassert my_solution.minSizeSubarray(**test_input) == 6", "start_time": 1696127400} +{"task_id": "weekly-contest-365-count-visited-nodes-in-a-directed-graph", "url": "https://leetcode.com/problems/count-visited-nodes-in-a-directed-graph", "title": "count-visited-nodes-in-a-directed-graph", "meta": {"questionId": "3140", "questionFrontendId": "2876", "title": "Count Visited Nodes in a Directed Graph", "titleSlug": "count-visited-nodes-in-a-directed-graph", "isPaidOnly": false, "difficulty": "Hard", "likes": 274, "dislikes": 4, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n现有一个有向图,其中包含 n 个节点,节点编号从 0 到 n - 1 。此外,该图还包含了 n 条有向边。\n\n给你一个下标从 0 开始的数组 edges ,其中 edges[i] 表示存在一条从节点 i 到节点 edges[i] 的边。\n\n想象在图上发生以下过程:\n\n * 你从节点 x 开始,通过边访问其他节点,直到你在 此过程 中再次访问到之前已经访问过的节点。\n\n返回数组 answer 作为答案,其中 answer[i] 表示如果从节点 i 开始执行该过程,你可以访问到的不同节点数。\n\n示例 1:\n\n[https://assets.leetcode.com/uploads/2023/08/31/graaphdrawio-1.png]\n\n输入:edges = [1,2,0,0]\n输出:[3,3,3,4]\n解释:从每个节点开始执行该过程,记录如下:\n- 从节点 0 开始,访问节点 0 -> 1 -> 2 -> 0 。访问的不同节点数是 3 。\n- 从节点 1 开始,访问节点 1 -> 2 -> 0 -> 1 。访问的不同节点数是 3 。\n- 从节点 2 开始,访问节点 2 -> 0 -> 1 -> 2 。访问的不同节点数是 3 。\n- 从节点 3 开始,访问节点 3 -> 0 -> 1 -> 2 -> 0 。访问的不同节点数是 4 。\n\n示例 2:\n\n[https://assets.leetcode.com/uploads/2023/08/31/graaph2drawio.png]\n\n输入:edges = [1,2,3,4,0]\n输出:[5,5,5,5,5]\n解释:无论从哪个节点开始,在这个过程中,都可以访问到图中的每一个节点。\n\n\n提示:\n\n * n == edges.length\n * 2 <= n <= 105\n * 0 <= edges[i] <= n - 1\n * edges[i] != i\n\"\"\"\nclass Solution:\n def countVisitedNodes(self, edges: List[int]) -> List[int]:\n ", "prompt_sft": "现有一个有向图,其中包含 n 个节点,节点编号从 0 到 n - 1 。此外,该图还包含了 n 条有向边。\n\n给你一个下标从 0 开始的数组 edges ,其中 edges[i] 表示存在一条从节点 i 到节点 edges[i] 的边。\n\n想象在图上发生以下过程:\n\n * 你从节点 x 开始,通过边访问其他节点,直到你在 此过程 中再次访问到之前已经访问过的节点。\n\n返回数组 answer 作为答案,其中 answer[i] 表示如果从节点 i 开始执行该过程,你可以访问到的不同节点数。\n\n示例 1:\n\n[https://assets.leetcode.com/uploads/2023/08/31/graaphdrawio-1.png]\n\n输入:edges = [1,2,0,0]\n输出:[3,3,3,4]\n解释:从每个节点开始执行该过程,记录如下:\n- 从节点 0 开始,访问节点 0 -> 1 -> 2 -> 0 。访问的不同节点数是 3 。\n- 从节点 1 开始,访问节点 1 -> 2 -> 0 -> 1 。访问的不同节点数是 3 。\n- 从节点 2 开始,访问节点 2 -> 0 -> 1 -> 2 。访问的不同节点数是 3 。\n- 从节点 3 开始,访问节点 3 -> 0 -> 1 -> 2 -> 0 。访问的不同节点数是 4 。\n\n示例 2:\n\n[https://assets.leetcode.com/uploads/2023/08/31/graaph2drawio.png]\n\n输入:edges = [1,2,3,4,0]\n输出:[5,5,5,5,5]\n解释:无论从哪个节点开始,在这个过程中,都可以访问到图中的每一个节点。\n\n\n提示:\n\n * n == edges.length\n * 2 <= n <= 105\n * 0 <= edges[i] <= n - 1\n * edges[i] != i\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def countVisitedNodes(self, edges: List[int]) -> List[int]:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"edges\": [1,2,0,0] }\nassert my_solution.countVisitedNodes(**test_input) == [3,3,3,4]\n\ntest_input = { \"edges\": [1,2,3,4,0] }\nassert my_solution.countVisitedNodes(**test_input) == [5,5,5,5,5]\n\ntest_input = { \"edges\": [3,6,1,0,5,7,4,3] }\nassert my_solution.countVisitedNodes(**test_input) == [2,7,8,2,5,4,6,3]\n\ntest_input = { \"edges\": [7,0,7,0,5,3,3,0] }\nassert my_solution.countVisitedNodes(**test_input) == [2,3,3,3,5,4,4,2]\n\ntest_input = { \"edges\": [6,3,6,1,0,8,0,6,6] }\nassert my_solution.countVisitedNodes(**test_input) == [2,2,3,2,3,4,2,3,3]\n\ntest_input = { \"edges\": [8,17,14,8,14,12,16,11,4,14,19,6,8,8,2,10,2,1,1,18] }\nassert my_solution.countVisitedNodes(**test_input) == [5,2,2,5,3,6,4,6,4,3,5,5,5,5,2,6,3,2,3,4]\n\ntest_input = { \"edges\": [11,9,6,8,3,2,8,11,14,2,3,7,2,2,1] }\nassert my_solution.countVisitedNodes(**test_input) == [3,6,6,7,8,7,6,2,6,6,8,2,7,7,6]\n\ntest_input = { \"edges\": [9,4,4,8,5,2,3,6,5,5] }\nassert my_solution.countVisitedNodes(**test_input) == [5,4,3,5,3,3,6,7,4,4]\n\ntest_input = { \"edges\": [1,0,1,1] }\nassert my_solution.countVisitedNodes(**test_input) == [2,2,3,3]\n\ntest_input = { \"edges\": [4,0,3,2,3] }\nassert my_solution.countVisitedNodes(**test_input) == [4,5,2,2,3]\n\ntest_input = { \"edges\": [7,7,0,9,5,6,10,16,7,4,15,13,2,16,1,7,6] }\nassert my_solution.countVisitedNodes(**test_input) == [6,6,7,9,7,6,5,5,6,8,5,7,8,6,7,5,5]\n\ntest_input = { \"edges\": [2,6,3,1,5,3,5] }\nassert my_solution.countVisitedNodes(**test_input) == [6,4,5,4,5,4,4]\n\ntest_input = { \"edges\": [15,4,13,12,12,2,11,6,14,10,15,3,5,5,2,4] }\nassert my_solution.countVisitedNodes(**test_input) == [7,6,3,5,5,3,7,8,5,8,7,6,4,3,4,6]\n\ntest_input = { \"edges\": [1,5,0,5,2,7,1,2] }\nassert my_solution.countVisitedNodes(**test_input) == [5,5,5,6,6,5,6,5]\n\ntest_input = { \"edges\": [9,6,13,1,11,4,17,9,2,18,15,4,14,15,7,2,18,16,1] }\nassert my_solution.countVisitedNodes(**test_input) == [7,5,3,6,2,3,5,7,4,6,4,2,9,3,8,3,5,5,5]\n\ntest_input = { \"edges\": [18,18,4,6,1,8,14,4,16,11,13,6,10,10,6,18,14,11,4] }\nassert my_solution.countVisitedNodes(**test_input) == [4,3,4,3,3,5,2,4,4,4,2,3,3,2,2,4,3,4,3]\n\ntest_input = { \"edges\": [5,4,1,6,3,10,3,10,11,10,8,1] }\nassert my_solution.countVisitedNodes(**test_input) == [9,4,5,2,3,8,2,8,6,8,7,5]\n\ntest_input = { \"edges\": [8,6,3,1,0,6,8,1,4,7,8] }\nassert my_solution.countVisitedNodes(**test_input) == [3,5,7,6,3,5,4,6,3,7,4]\n\ntest_input = { \"edges\": [9,5,18,15,8,4,3,3,18,5,13,0,1,18,9,6,18,9,14,15] }\nassert my_solution.countVisitedNodes(**test_input) == [7,7,7,3,6,6,3,4,6,6,8,8,8,7,6,3,7,7,6,4]\n\ntest_input = { \"edges\": [5,2,1,0,6,9,10,12,12,2,16,2,9,17,0,4,9,6] }\nassert my_solution.countVisitedNodes(**test_input) == [5,2,2,6,7,4,6,5,5,3,5,3,4,8,6,8,4,7]\n\ntest_input = { \"edges\": [6,4,1,2,3,2,0] }\nassert my_solution.countVisitedNodes(**test_input) == [2,4,4,4,4,5,2]\n\ntest_input = { \"edges\": [1,13,4,12,15,11,1,8,15,10,1,3,0,3,2,2] }\nassert my_solution.countVisitedNodes(**test_input) == [5,5,3,5,3,7,6,5,4,7,6,6,5,5,4,3]\n\ntest_input = { \"edges\": [2,2,0] }\nassert my_solution.countVisitedNodes(**test_input) == [2,3,2]\n\ntest_input = { \"edges\": [11,8,8,11,5,8,9,11,6,8,0,12,9,12] }\nassert my_solution.countVisitedNodes(**test_input) == [6,4,4,6,5,4,3,6,3,3,7,5,4,5]\n\ntest_input = { \"edges\": [2,3,6,8,0,4,8,6,1] }\nassert my_solution.countVisitedNodes(**test_input) == [6,3,5,3,7,8,4,5,3]\n\ntest_input = { \"edges\": [2,7,17,14,3,14,11,12,9,0,15,18,1,18,0,19,11,4,1,0] }\nassert my_solution.countVisitedNodes(**test_input) == [6,3,6,6,6,7,6,3,8,7,9,5,3,5,6,8,6,6,4,7]\n\ntest_input = { \"edges\": [5,17,10,13,16,4,7,10,19,6,15,6,9,0,1,0,12,18,10,16] }\nassert my_solution.countVisitedNodes(**test_input) == [10,13,11,12,10,10,10,10,12,10,10,11,10,11,14,10,10,12,11,11]\n\ntest_input = { \"edges\": [1,2,6,6,1,4,4] }\nassert my_solution.countVisitedNodes(**test_input) == [5,4,4,5,4,5,4]\n\ntest_input = { \"edges\": [2,0,0,2] }\nassert my_solution.countVisitedNodes(**test_input) == [2,3,2,3]\n\ntest_input = { \"edges\": [12,10,5,0,12,8,0,4,3,1,9,4,6] }\nassert my_solution.countVisitedNodes(**test_input) == [3,3,7,4,4,6,3,5,5,3,3,5,3]\n\ntest_input = { \"edges\": [8,4,0,0,8,2,3,8,7] }\nassert my_solution.countVisitedNodes(**test_input) == [3,4,4,4,3,5,5,2,2]\n\ntest_input = { \"edges\": [6,7,1,10,2,10,3,5,10,4,2] }\nassert my_solution.countVisitedNodes(**test_input) == [8,5,5,6,6,5,7,5,6,7,5]\n\ntest_input = { \"edges\": [2,7,5,4,8,7,2,3,0] }\nassert my_solution.countVisitedNodes(**test_input) == [7,8,7,7,7,7,8,7,7]\n\ntest_input = { \"edges\": [2,3,1,1,0,4] }\nassert my_solution.countVisitedNodes(**test_input) == [4,2,3,2,5,6]\n\ntest_input = { \"edges\": [5,2,3,1,3,1] }\nassert my_solution.countVisitedNodes(**test_input) == [5,3,3,3,4,4]\n\ntest_input = { \"edges\": [7,6,12,0,1,9,13,6,9,6,0,0,3,9,12,13,0] }\nassert my_solution.countVisitedNodes(**test_input) == [5,4,8,6,5,4,3,4,4,3,6,6,7,3,8,4,6]\n\ntest_input = { \"edges\": [1,4,9,11,11,11,14,10,11,14,2,0,14,5,10] }\nassert my_solution.countVisitedNodes(**test_input) == [4,4,4,5,4,5,5,5,5,4,4,4,5,6,4]\n\ntest_input = { \"edges\": [4,3,3,1,3] }\nassert my_solution.countVisitedNodes(**test_input) == [4,2,3,2,3]\n\ntest_input = { \"edges\": [7,7,6,8,0,7,8,0,0,10,9] }\nassert my_solution.countVisitedNodes(**test_input) == [2,3,5,4,3,3,4,2,3,2,2]\n\ntest_input = { \"edges\": [16,5,11,9,7,17,16,8,14,5,5,1,0,8,0,16,14,15,19,4] }\nassert my_solution.countVisitedNodes(**test_input) == [3,7,9,8,6,6,4,5,4,7,7,8,4,5,3,4,3,5,8,7]\n\ntest_input = { \"edges\": [1,8,10,6,2,1,8,9,6,12,5,10,3] }\nassert my_solution.countVisitedNodes(**test_input) == [4,3,6,3,7,4,2,6,2,5,5,6,4]\n\ntest_input = { \"edges\": [4,0,1,5,0,2] }\nassert my_solution.countVisitedNodes(**test_input) == [2,3,4,6,2,5]\n\ntest_input = { \"edges\": [9,13,1,2,13,1,0,5,10,8,2,2,3,12] }\nassert my_solution.countVisitedNodes(**test_input) == [9,5,5,5,6,6,10,7,7,8,6,6,5,5]\n\ntest_input = { \"edges\": [12,13,16,11,17,11,2,15,12,14,4,9,3,4,17,3,4,9] }\nassert my_solution.countVisitedNodes(**test_input) == [7,6,6,5,4,5,7,7,7,3,5,4,6,5,3,6,5,3]\n\ntest_input = { \"edges\": [2,0,1] }\nassert my_solution.countVisitedNodes(**test_input) == [3,3,3]\n\ntest_input = { \"edges\": [7,10,15,18,7,1,7,16,11,8,2,13,13,15,16,0,18,5,16] }\nassert my_solution.countVisitedNodes(**test_input) == [4,8,6,3,4,9,4,3,8,9,7,7,7,6,3,5,2,10,2]\n\ntest_input = { \"edges\": [1,2,0] }\nassert my_solution.countVisitedNodes(**test_input) == [3,3,3]\n\ntest_input = { \"edges\": [10,13,4,11,11,6,9,2,7,4,5,7,0,11] }\nassert my_solution.countVisitedNodes(**test_input) == [9,6,4,5,4,7,6,4,5,5,8,4,10,5]\n\ntest_input = { \"edges\": [12,15,15,2,10,1,5,6,1,2,11,13,10,4,2,0,1] }\nassert my_solution.countVisitedNodes(**test_input) == [6,8,8,9,4,9,10,11,9,9,4,4,5,4,9,7,9]\n\ntest_input = { \"edges\": [1,0] }\nassert my_solution.countVisitedNodes(**test_input) == [2,2]\n\ntest_input = { \"edges\": [7,17,3,7,7,12,15,1,14,15,16,3,13,0,3,8,0,11,1] }\nassert my_solution.countVisitedNodes(**test_input) == [6,5,6,5,6,9,9,5,7,9,8,5,8,7,6,8,7,5,6]\n\ntest_input = { \"edges\": [9,4,6,2,8,6,7,4,9,8,0,2,7] }\nassert my_solution.countVisitedNodes(**test_input) == [3,4,6,7,3,6,5,4,2,2,4,7,5]\n\ntest_input = { \"edges\": [13,10,6,12,12,3,4,3,10,12,1,7,8,12,9] }\nassert my_solution.countVisitedNodes(**test_input) == [6,2,7,5,5,6,6,6,3,5,2,7,4,5,6]\n\ntest_input = { \"edges\": [10,3,4,4,5,7,2,9,7,0,5] }\nassert my_solution.countVisitedNodes(**test_input) == [5,8,7,7,6,5,8,5,6,5,5]\n\ntest_input = { \"edges\": [2,4,0,4,2] }\nassert my_solution.countVisitedNodes(**test_input) == [2,4,2,4,3]\n\ntest_input = { \"edges\": [2,2,1] }\nassert my_solution.countVisitedNodes(**test_input) == [3,2,2]\n\ntest_input = { \"edges\": [19,15,1,6,8,15,5,6,4,4,19,13,3,0,15,10,13,5,6,3] }\nassert my_solution.countVisitedNodes(**test_input) == [7,7,8,6,2,6,6,7,2,3,6,9,7,8,7,6,9,7,7,6]\n\ntest_input = { \"edges\": [11,9,5,0,5,3,9,8,1,10,4,4] }\nassert my_solution.countVisitedNodes(**test_input) == [5,8,6,5,5,5,8,10,9,7,6,5]\n\ntest_input = { \"edges\": [13,10,12,11,5,17,0,10,7,16,5,4,9,3,15,5,4,1] }\nassert my_solution.countVisitedNodes(**test_input) == [9,4,9,7,5,4,10,5,6,7,4,6,8,8,6,5,6,4]\n\ntest_input = { \"edges\": [7,0,9,0,7,6,2,0,7,7] }\nassert my_solution.countVisitedNodes(**test_input) == [2,3,4,3,3,6,5,2,3,3]\n\ntest_input = { \"edges\": [1,0,0] }\nassert my_solution.countVisitedNodes(**test_input) == [2,2,3]\n\ntest_input = { \"edges\": [5,9,10,17,12,3,15,5,0,3,15,5,5,15,17,5,13,15,1] }\nassert my_solution.countVisitedNodes(**test_input) == [5,6,6,4,6,4,5,5,6,5,5,5,5,5,5,4,6,4,7]\n\ntest_input = { \"edges\": [1,5,1,8,1,0,1,4,6] }\nassert my_solution.countVisitedNodes(**test_input) == [3,3,4,6,4,3,4,5,5]\n\ntest_input = { \"edges\": [5,3,3,4,1,4] }\nassert my_solution.countVisitedNodes(**test_input) == [5,3,4,3,3,4]\n\ntest_input = { \"edges\": [7,12,12,5,10,11,5,0,3,12,12,9,1,3,7] }\nassert my_solution.countVisitedNodes(**test_input) == [2,2,3,6,4,5,6,2,7,3,3,4,2,7,3]\n\ntest_input = { \"edges\": [3,3,3,1] }\nassert my_solution.countVisitedNodes(**test_input) == [3,2,3,2]\n\ntest_input = { \"edges\": [13,3,15,10,12,7,13,15,3,0,1,5,15,12,10,9] }\nassert my_solution.countVisitedNodes(**test_input) == [5,3,6,3,6,7,6,6,4,5,3,8,5,5,4,5]\n\ntest_input = { \"edges\": [8,9,0,9,0,0,9,0,7,6,5,0] }\nassert my_solution.countVisitedNodes(**test_input) == [3,3,4,3,4,4,2,3,3,2,5,4]\n\ntest_input = { \"edges\": [2,0,7,7,3,3,0,4,5,8] }\nassert my_solution.countVisitedNodes(**test_input) == [5,6,4,3,3,4,6,3,5,6]\n\ntest_input = { \"edges\": [13,8,7,13,10,6,11,13,13,6,8,6,0,10] }\nassert my_solution.countVisitedNodes(**test_input) == [4,4,5,4,4,3,2,4,3,3,3,2,5,3]\n\ntest_input = { \"edges\": [12,14,5,17,7,0,15,18,5,10,6,18,10,11,1,1,18,16,0] }\nassert my_solution.countVisitedNodes(**test_input) == [7,2,9,11,10,8,4,9,9,6,5,9,6,10,2,3,9,10,8]\n\ntest_input = { \"edges\": [8,6,17,7,12,10,13,14,10,10,2,15,11,5,4,13,12,12] }\nassert my_solution.countVisitedNodes(**test_input) == [10,10,8,12,9,8,9,11,9,9,8,8,8,8,10,8,9,8]\n\ntest_input = { \"edges\": [1,0,1,1,1] }\nassert my_solution.countVisitedNodes(**test_input) == [2,2,3,3,3]\n\ntest_input = { \"edges\": [17,16,15,5,11,4,4,10,14,1,17,1,4,3,12,17,14,10] }\nassert my_solution.countVisitedNodes(**test_input) == [3,6,4,8,6,7,7,3,7,7,2,6,6,9,6,3,6,2]\n\ntest_input = { \"edges\": [14,10,16,16,12,13,13,16,13,14,15,14,1,4,13,11,4,7] }\nassert my_solution.countVisitedNodes(**test_input) == [9,8,10,10,8,9,9,10,9,9,8,8,8,8,8,8,9,11]\n\ntest_input = { \"edges\": [2,3,0,1] }\nassert my_solution.countVisitedNodes(**test_input) == [2,2,2,2]\n\ntest_input = { \"edges\": [8,0,11,2,0,12,0,4,11,12,0,7,3] }\nassert my_solution.countVisitedNodes(**test_input) == [5,6,6,7,5,9,6,5,5,9,6,5,8]\n\ntest_input = { \"edges\": [3,0,1,0] }\nassert my_solution.countVisitedNodes(**test_input) == [2,3,4,2]\n\ntest_input = { \"edges\": [1,3,0,1,10,11,2,6,0,5,1,4] }\nassert my_solution.countVisitedNodes(**test_input) == [3,2,4,2,4,6,5,6,4,7,3,5]\n\ntest_input = { \"edges\": [1,16,10,6,15,10,7,9,2,15,5,6,13,1,0,16,13] }\nassert my_solution.countVisitedNodes(**test_input) == [4,3,3,8,5,2,7,6,4,5,2,8,4,3,5,4,3]\n\ntest_input = { \"edges\": [4,15,10,11,0,7,9,10,1,2,9,12,5,10,6,13] }\nassert my_solution.countVisitedNodes(**test_input) == [2,6,3,8,2,5,4,4,7,3,3,7,6,4,5,5]\n\ntest_input = { \"edges\": [4,9,8,9,1,4,7,11,5,6,4,6,4,4,2] }\nassert my_solution.countVisitedNodes(**test_input) == [7,5,9,5,6,7,3,3,8,4,7,3,7,7,10]\n\ntest_input = { \"edges\": [16,14,1,6,6,1,1,15,16,16,13,14,9,3,3,11,10] }\nassert my_solution.countVisitedNodes(**test_input) == [8,4,5,4,5,5,4,7,8,8,6,5,9,5,4,6,7]\n\ntest_input = { \"edges\": [6,11,15,7,5,8,11,5,14,2,6,0,8,5,13,5] }\nassert my_solution.countVisitedNodes(**test_input) == [3,4,6,6,5,4,3,5,4,7,4,3,5,4,4,5]\n\ntest_input = { \"edges\": [14,17,11,8,5,4,10,17,3,3,2,17,13,1,17,5,5,0] }\nassert my_solution.countVisitedNodes(**test_input) == [3,4,5,2,2,2,7,4,2,3,6,4,6,5,3,3,3,3]\n\ntest_input = { \"edges\": [1,6,8,6,2,4,2,5,9,3] }\nassert my_solution.countVisitedNodes(**test_input) == [7,6,5,5,6,7,5,8,5,5]\n\ntest_input = { \"edges\": [1,5,4,1,5,3,4,0] }\nassert my_solution.countVisitedNodes(**test_input) == [4,3,5,3,4,3,5,5]\n\ntest_input = { \"edges\": [17,4,3,7,3,1,15,15,13,18,4,14,1,10,13,1,0,15,16] }\nassert my_solution.countVisitedNodes(**test_input) == [7,5,6,5,5,6,6,5,8,10,6,9,6,7,8,5,8,6,9]\n\ntest_input = { \"edges\": [12,2,6,6,7,8,8,13,1,12,15,1,8,3,8,2,6] }\nassert my_solution.countVisitedNodes(**test_input) == [6,4,4,5,8,5,4,7,4,6,6,5,5,6,5,5,5]\n\ntest_input = { \"edges\": [3,0,0,2] }\nassert my_solution.countVisitedNodes(**test_input) == [3,4,3,3]\n\ntest_input = { \"edges\": [5,0,1,1,2,0] }\nassert my_solution.countVisitedNodes(**test_input) == [2,3,4,4,5,2]\n\ntest_input = { \"edges\": [16,2,13,6,7,10,1,1,7,14,7,13,9,16,4,8,15] }\nassert my_solution.countVisitedNodes(**test_input) == [8,7,7,9,8,9,8,7,7,10,8,8,11,7,9,7,7]\n\ntest_input = { \"edges\": [14,5,0,16,7,15,1,18,18,6,11,15,0,2,3,0,17,4,12] }\nassert my_solution.countVisitedNodes(**test_input) == [9,12,10,9,9,11,13,9,10,14,12,11,9,11,9,10,9,9,9]\n\ntest_input = { \"edges\": [7,8,1,9,7,10,1,4,2,0,9] }\nassert my_solution.countVisitedNodes(**test_input) == [3,3,3,5,2,6,4,2,3,4,5]\n\ntest_input = { \"edges\": [5,3,6,2,1,3,1,3] }\nassert my_solution.countVisitedNodes(**test_input) == [6,4,4,4,5,5,4,5]\n\ntest_input = { \"edges\": [8,14,5,13,6,9,8,11,9,4,11,14,5,12,10,10,12] }\nassert my_solution.countVisitedNodes(**test_input) == [5,4,6,8,4,5,4,4,4,4,3,3,6,7,3,4,7]\n\ntest_input = { \"edges\": [6,13,11,11,6,3,3,6,1,12,4,7,14,11,0,10] }\nassert my_solution.countVisitedNodes(**test_input) == [5,6,5,4,5,5,4,4,7,8,6,4,7,5,6,7]\n\ntest_input = { \"edges\": [12,8,6,1,5,0,1,1,11,0,12,2,0] }\nassert my_solution.countVisitedNodes(**test_input) == [2,5,5,6,4,3,5,6,5,3,3,5,2]\n\ntest_input = { \"edges\": [8,2,7,17,5,1,5,17,10,2,12,3,1,0,11,3,7,4] }\nassert my_solution.countVisitedNodes(**test_input) == [10,6,6,7,6,6,7,6,9,7,8,8,7,11,9,8,7,6]\n\ntest_input = { \"edges\": [4,2,4,2,3] }\nassert my_solution.countVisitedNodes(**test_input) == [4,4,3,3,3]", "start_time": 1696127400} +{"task_id": "biweekly-contest-114-minimum-operations-to-collect-elements", "url": "https://leetcode.com/problems/minimum-operations-to-collect-elements", "title": "minimum-operations-to-collect-elements", "meta": {"questionId": "3044", "questionFrontendId": "2869", "title": "Minimum Operations to Collect Elements", "titleSlug": "minimum-operations-to-collect-elements", "isPaidOnly": false, "difficulty": "Easy", "likes": 130, "dislikes": 10, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个正整数数组 nums 和一个整数 k 。\n\n一次操作中,你可以将数组的最后一个元素删除,将该元素添加到一个集合中。\n\n请你返回收集元素 1, 2, ..., k 需要的 最少操作次数 。\n\n示例 1:\n\n输入:nums = [3,1,5,4,2], k = 2\n输出:4\n解释:4 次操作后,集合中的元素依次添加了 2 ,4 ,5 和 1 。此时集合中包含元素 1 和 2 ,所以答案为 4 。\n\n示例 2:\n\n输入:nums = [3,1,5,4,2], k = 5\n输出:5\n解释:5 次操作后,集合中的元素依次添加了 2 ,4 ,5 ,1 和 3 。此时集合中包含元素 1 到 5 ,所以答案为 5 。\n\n示例 3:\n\n输入:nums = [3,2,5,3,1], k = 3\n输出:4\n解释:4 次操作后,集合中的元素依次添加了 1 ,3 ,5 和 2 。此时集合中包含元素 1 到 3 ,所以答案为 4 。\n\n\n提示:\n\n * 1 <= nums.length <= 50\n * 1 <= nums[i] <= nums.length\n * 1 <= k <= nums.length\n * 输入保证你可以收集到元素 1, 2, ..., k 。\n\"\"\"\nclass Solution:\n def minOperations(self, nums: List[int], k: int) -> int:\n ", "prompt_sft": "给你一个正整数数组 nums 和一个整数 k 。\n\n一次操作中,你可以将数组的最后一个元素删除,将该元素添加到一个集合中。\n\n请你返回收集元素 1, 2, ..., k 需要的 最少操作次数 。\n\n示例 1:\n\n输入:nums = [3,1,5,4,2], k = 2\n输出:4\n解释:4 次操作后,集合中的元素依次添加了 2 ,4 ,5 和 1 。此时集合中包含元素 1 和 2 ,所以答案为 4 。\n\n示例 2:\n\n输入:nums = [3,1,5,4,2], k = 5\n输出:5\n解释:5 次操作后,集合中的元素依次添加了 2 ,4 ,5 ,1 和 3 。此时集合中包含元素 1 到 5 ,所以答案为 5 。\n\n示例 3:\n\n输入:nums = [3,2,5,3,1], k = 3\n输出:4\n解释:4 次操作后,集合中的元素依次添加了 1 ,3 ,5 和 2 。此时集合中包含元素 1 到 3 ,所以答案为 4 。\n\n\n提示:\n\n * 1 <= nums.length <= 50\n * 1 <= nums[i] <= nums.length\n * 1 <= k <= nums.length\n * 输入保证你可以收集到元素 1, 2, ..., k 。\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def minOperations(self, nums: List[int], k: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [3,1,5,4,2], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [3,1,5,4,2], \"k\": 5 }\nassert my_solution.minOperations(**test_input) == 5\n\ntest_input = { \"nums\": [3,2,5,3,1], \"k\": 3 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [1], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,1], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,2], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,2], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [2,1], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [2,1], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,1], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,2], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,2], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,3], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,2,1], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,1], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,2,2], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,2], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,3], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,3], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,3], \"k\": 3 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,3,1], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,3,2], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,3,2], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,3,2], \"k\": 3 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,3,3], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [2,1,1], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [2,1,1], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [2,1,2], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [2,1,2], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [2,1,3], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [2,1,3], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [2,1,3], \"k\": 3 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [2,2,1], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [2,2,1], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [2,3,1], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [2,3,1], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [2,3,1], \"k\": 3 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [3,1,1], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [3,1,2], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [3,1,2], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [3,1,2], \"k\": 3 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [3,1,3], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [3,2,1], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [3,2,1], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [3,2,1], \"k\": 3 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [3,3,1], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,1,1], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,1,2], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,1,2], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,1,3], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,1,4], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,2,1], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,2,1], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,2,2], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,2,2], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,2,3], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,2,3], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,2,3], \"k\": 3 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,2,4], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,2,4], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,3,1], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,3,2], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,3,2], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,3,2], \"k\": 3 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,3,3], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,3,4], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,4,1], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,4,2], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,4,2], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,4,3], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,4,4], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,1,1], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,1,1], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,1,2], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,2,1,2], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,2,1,3], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,2,1,3], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,1,3], \"k\": 3 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,1,4], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,2,1,4], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,2,1], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,2,1], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,2,2,2], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,2,2], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,2,3], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,2,3], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,2,3], \"k\": 3 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,2,4], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,2,4], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,3,1], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,3,1], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,3,1], \"k\": 3 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,3,2], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,3,2], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,3,2], \"k\": 3 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,3,3], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,3,3], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,3,3], \"k\": 3 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,3,4], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,3,4], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 4", "start_time": 1696084200} +{"task_id": "biweekly-contest-114-minimum-number-of-operations-to-make-array-empty", "url": "https://leetcode.com/problems/minimum-number-of-operations-to-make-array-empty", "title": "minimum-number-of-operations-to-make-array-empty", "meta": {"questionId": "3094", "questionFrontendId": "2870", "title": "Minimum Number of Operations to Make Array Empty", "titleSlug": "minimum-number-of-operations-to-make-array-empty", "isPaidOnly": false, "difficulty": "Medium", "likes": 147, "dislikes": 5, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0 开始的正整数数组 nums 。\n\n你可以对数组执行以下两种操作 任意次 :\n\n * 从数组中选择 两个 值 相等 的元素,并将它们从数组中 删除 。\n * 从数组中选择 三个 值 相等 的元素,并将它们从数组中 删除 。\n\n请你返回使数组为空的 最少 操作次数,如果无法达成,请返回 -1 。\n\n示例 1:\n\n输入:nums = [2,3,3,2,2,4,2,3,4]\n输出:4\n解释:我们可以执行以下操作使数组为空:\n- 对下标为 0 和 3 的元素执行第一种操作,得到 nums = [3,3,2,4,2,3,4] 。\n- 对下标为 2 和 4 的元素执行第一种操作,得到 nums = [3,3,4,3,4] 。\n- 对下标为 0 ,1 和 3 的元素执行第二种操作,得到 nums = [4,4] 。\n- 对下标为 0 和 1 的元素执行第一种操作,得到 nums = [] 。\n至少需要 4 步操作使数组为空。\n\n示例 2:\n\n输入:nums = [2,1,2,2,3,3]\n输出:-1\n解释:无法使数组为空。\n\n\n提示:\n\n * 2 <= nums.length <= 105\n * 1 <= nums[i] <= 106\n\"\"\"\nclass Solution:\n def minOperations(self, nums: List[int]) -> int:\n ", "prompt_sft": "给你一个下标从 0 开始的正整数数组 nums 。\n\n你可以对数组执行以下两种操作 任意次 :\n\n * 从数组中选择 两个 值 相等 的元素,并将它们从数组中 删除 。\n * 从数组中选择 三个 值 相等 的元素,并将它们从数组中 删除 。\n\n请你返回使数组为空的 最少 操作次数,如果无法达成,请返回 -1 。\n\n示例 1:\n\n输入:nums = [2,3,3,2,2,4,2,3,4]\n输出:4\n解释:我们可以执行以下操作使数组为空:\n- 对下标为 0 和 3 的元素执行第一种操作,得到 nums = [3,3,2,4,2,3,4] 。\n- 对下标为 2 和 4 的元素执行第一种操作,得到 nums = [3,3,4,3,4] 。\n- 对下标为 0 ,1 和 3 的元素执行第二种操作,得到 nums = [4,4] 。\n- 对下标为 0 和 1 的元素执行第一种操作,得到 nums = [] 。\n至少需要 4 步操作使数组为空。\n\n示例 2:\n\n输入:nums = [2,1,2,2,3,3]\n输出:-1\n解释:无法使数组为空。\n\n\n提示:\n\n * 2 <= nums.length <= 105\n * 1 <= nums[i] <= 106\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def minOperations(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [2,3,3,2,2,4,2,3,4] }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [2,1,2,2,3,3] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [3,3] }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [14,12,14,14,12,14,14,12,12,12,12,14,14,12,14,14,14,12,12] }\nassert my_solution.minOperations(**test_input) == 7\n\ntest_input = { \"nums\": [2,2,2,2,2,2,2,2,2] }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [15,3,3,15,15,13,8,15,6,15,3,1,8,8,15] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [19,19,19,19,19,19,19,19,19,19,19,19,19] }\nassert my_solution.minOperations(**test_input) == 5\n\ntest_input = { \"nums\": [13,7,13,7,13,7,13,13,7] }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [5,5] }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [3,3,3,3,3,3,3,3,3,3,3,3,3,3,3] }\nassert my_solution.minOperations(**test_input) == 5\n\ntest_input = { \"nums\": [3,14,3,14,3,14,14,3,3,14,14,14,3,14,14,3,14,14,14,3] }\nassert my_solution.minOperations(**test_input) == 7\n\ntest_input = { \"nums\": [16,16,16,19,16,3,16,8,16,16,16,19,3,16,16] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [11,11,11,11,19,11,11,11,11,11,19,11,11,11,11,11,19] }\nassert my_solution.minOperations(**test_input) == 6\n\ntest_input = { \"nums\": [1,1,1,5,1,5,1,1,1,1,1,1,1] }\nassert my_solution.minOperations(**test_input) == 5\n\ntest_input = { \"nums\": [16,16,16,3,16,16,3] }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [14,4,4,19,19] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [1,14,1,1,1] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [3,10,11,3,3,11,3,3,3,3,3,3,3,3,10,3,3,3] }\nassert my_solution.minOperations(**test_input) == 7\n\ntest_input = { \"nums\": [3,8,8,8,8,3,8,8,8,8,8,8,8,8] }\nassert my_solution.minOperations(**test_input) == 5\n\ntest_input = { \"nums\": [9,9,9] }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [6,6,6,6,6,8,8,8,8,6,8,6,15,15,6,15,6,6] }\nassert my_solution.minOperations(**test_input) == 7\n\ntest_input = { \"nums\": [9,19,19,19,9,9,19,19,19,9,9,19,9,19,19,19] }\nassert my_solution.minOperations(**test_input) == 6\n\ntest_input = { \"nums\": [9,4,9,20,20,4,20] }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [6,9,18,16,18,1,9,1,1,1,1,16,1,6,1,1,9,6] }\nassert my_solution.minOperations(**test_input) == 7\n\ntest_input = { \"nums\": [11,18,11,18,11,18,11] }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [20,20,20,20,20] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [12,7,7] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [10,7,9,9,10,9,9,10,10,9,10,9,10,10] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [9,9,9,8,9,9,9,9,2,9,9,9,9,9] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [5,5,18,1,5,5] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [13,13,16,4,16,13,2,16,16,16,2,16,6,16,13,18,9] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [8,8,8,8,8,8,8,8,8,7,8,8,8,8,8,7,8] }\nassert my_solution.minOperations(**test_input) == 6\n\ntest_input = { \"nums\": [20,20,19,19,20,19,20,20,20,19,20,20,20,20,20,20,20,20,20] }\nassert my_solution.minOperations(**test_input) == 7\n\ntest_input = { \"nums\": [4,4,20,20,4,20,1,4,4,4,4,4,4,4,20,4,4] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [16,17,17,8,17,17,16,8,17,16,17] }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [10,10,10,9,10,10,10,9,10,18,10,4,20,2,10,10] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [11,20,20,11,11,20,14,20,11,11,20,1] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [14,14,14,14,15,20,15] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [17,7,17,5,17,17,17,7,17,17,17,17,5,17,17,7,5] }\nassert my_solution.minOperations(**test_input) == 6\n\ntest_input = { \"nums\": [4,4,4,4,4,4,4,4,4] }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [17,17] }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [15,2,15,2,8,15,15,15,15,15,15,8,2] }\nassert my_solution.minOperations(**test_input) == 5\n\ntest_input = { \"nums\": [1,12,12,1,1,1,1,12,1] }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [12,4,9,10,17,12,5,17,4,12,12,12,4,10,4] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [7,7,7,7,7,7,7,16,7,7,7,16,7,16,7,16,16,16,16,7] }\nassert my_solution.minOperations(**test_input) == 8\n\ntest_input = { \"nums\": [20,20,20,20,19] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [13,13,13,13,13,13,13,13] }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [15,12,18,18,15,15,15,12,12,12,12,12,12,15,18] }\nassert my_solution.minOperations(**test_input) == 6\n\ntest_input = { \"nums\": [14,14,14,1] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [2,2,2,2,2,2,8,2,8,2,2,2,2] }\nassert my_solution.minOperations(**test_input) == 5\n\ntest_input = { \"nums\": [10,16,6,6,10,6] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [18,17,3,18,6,13,3,6,14,6,15,3] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [15,15] }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [9,9,9,9,9,9,9,9,9,9,9] }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [11,4,4,18,11,12,18,18,12,4,4,12,4] }\nassert my_solution.minOperations(**test_input) == 5\n\ntest_input = { \"nums\": [2,5,20,20,5,20,20,16,20,20,20,20,20,20,3,20,20,20] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [12,13,13,13,12,13,13,13,13,13,11,13,13,13] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,1,1] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [10,10,10,10,3,10,10,3,10] }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [7,14,7,7,2,2,7] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [1,10,1,10,1] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [11,11,11,11,11,11,11,11,11,11] }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18] }\nassert my_solution.minOperations(**test_input) == 7\n\ntest_input = { \"nums\": [13,13,13,13,13,13,13] }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [19,19,19,19,18,19,15,7,19,19,15,5] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [2,12,12,12,17,12,12,12,12,12,12,12,12,12,12] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [19,16,19,19,16,16,16,16] }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [15,15,15,15,15,15,11,13,15,15,11,15,13,15,11,13] }\nassert my_solution.minOperations(**test_input) == 6\n\ntest_input = { \"nums\": [15,16,16,15,16] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [9,7,14,9,14,7,7,9,9,9,9,9,9,14,14] }\nassert my_solution.minOperations(**test_input) == 6\n\ntest_input = { \"nums\": [12,16,5,5,7,10,2,16,12,7,2,12,5,16,2,11] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11] }\nassert my_solution.minOperations(**test_input) == 6\n\ntest_input = { \"nums\": [18,13,13,18,18,13,13,18,13,13] }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [4,4,8,10,8,10,19,19,19,19,8,8,19,4] }\nassert my_solution.minOperations(**test_input) == 6\n\ntest_input = { \"nums\": [1,18,14,16,14] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [7,7,7,7,3,7,7,3,7,7] }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [13,13] }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [6,11,6,8,6,13,17,14] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [10,2,2,10] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [19,17,17,17,17,17,17,17,19,19,19,17,19,17] }\nassert my_solution.minOperations(**test_input) == 5\n\ntest_input = { \"nums\": [4,16,12,7,16,16,16] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [11,11,11,11,11,11,11,11,11,11,11,11,11,11,11] }\nassert my_solution.minOperations(**test_input) == 5\n\ntest_input = { \"nums\": [6,6,6,13,6,18,13,18,5,18,12,3,12,12,18,6,18,3,18,6] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [4,4,3,3,4,4] }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [11,11,11,11,9,11,9,9,11,11,9,9,11,11,9] }\nassert my_solution.minOperations(**test_input) == 5\n\ntest_input = { \"nums\": [16,16] }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [4,4,4,4,4,4,4,4,4,4,4,4,4,4] }\nassert my_solution.minOperations(**test_input) == 5\n\ntest_input = { \"nums\": [17,16,16,17,16,16,16] }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [10,18,10,10] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [8,8] }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [8,6,6,6,8,8,6,8,8,6,8,6,8,8,6,6,6,8] }\nassert my_solution.minOperations(**test_input) == 6\n\ntest_input = { \"nums\": [15,14,20,15,20,14,14,14,20,14,20,20] }\nassert my_solution.minOperations(**test_input) == 5\n\ntest_input = { \"nums\": [19,3,3,3,3,3,3,15,17,3,3,18,10,17,17,15,17,3,3] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,16,2,16,1,2,2,2,2,2,1,2,2,2,16] }\nassert my_solution.minOperations(**test_input) == 6\n\ntest_input = { \"nums\": [1,1,4,4,4] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1] }\nassert my_solution.minOperations(**test_input) == 7\n\ntest_input = { \"nums\": [16,18,18,20] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [2,2,2,20,15,2,20,15,2,15] }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [16,16,16,16,16] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,14,14,14,14,1,14,14,1,14,14,14,14,1,14,14,1,14] }\nassert my_solution.minOperations(**test_input) == 7", "start_time": 1696084200} +{"task_id": "biweekly-contest-114-split-array-into-maximum-number-of-subarrays", "url": "https://leetcode.com/problems/split-array-into-maximum-number-of-subarrays", "title": "split-array-into-maximum-number-of-subarrays", "meta": {"questionId": "3080", "questionFrontendId": "2871", "title": "Split Array Into Maximum Number of Subarrays", "titleSlug": "split-array-into-maximum-number-of-subarrays", "isPaidOnly": false, "difficulty": "Medium", "likes": 188, "dislikes": 24, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个只包含 非负 整数的数组 nums 。\n\n我们定义满足 l <= r 的子数组 nums[l..r] 的分数为 nums[l] AND nums[l + 1] AND ... AND nums[r] ,其中 AND 是按位与运算。\n\n请你将数组分割成一个或者更多子数组,满足:\n\n * 每个 元素都 只 属于一个子数组。\n * 子数组分数之和尽可能 小 。\n\n请你在满足以上要求的条件下,返回 最多 可以得到多少个子数组。\n\n一个 子数组 是一个数组中一段连续的元素。\n\n示例 1:\n\n输入:nums = [1,0,2,0,1,2]\n输出:3\n解释:我们可以将数组分割成以下子数组:\n- [1,0] 。子数组分数为 1 AND 0 = 0 。\n- [2,0] 。子数组分数为 2 AND 0 = 0 。\n- [1,2] 。子数组分数为 1 AND 2 = 0 。\n分数之和为 0 + 0 + 0 = 0 ,是我们可以得到的最小分数之和。\n在分数之和为 0 的前提下,最多可以将数组分割成 3 个子数组。所以返回 3 。\n\n示例 2:\n\n输入:nums = [5,7,1,3]\n输出:1\n解释:我们可以将数组分割成一个子数组:[5,7,1,3] ,分数为 1 ,这是可以得到的最小总分数。\n在总分数为 1 的前提下,最多可以将数组分割成 1 个子数组。所以返回 1 。\n\n\n提示:\n\n * 1 <= nums.length <= 105\n * 0 <= nums[i] <= 106\n\"\"\"\nclass Solution:\n def maxSubarrays(self, nums: List[int]) -> int:\n ", "prompt_sft": "给你一个只包含 非负 整数的数组 nums 。\n\n我们定义满足 l <= r 的子数组 nums[l..r] 的分数为 nums[l] AND nums[l + 1] AND ... AND nums[r] ,其中 AND 是按位与运算。\n\n请你将数组分割成一个或者更多子数组,满足:\n\n * 每个 元素都 只 属于一个子数组。\n * 子数组分数之和尽可能 小 。\n\n请你在满足以上要求的条件下,返回 最多 可以得到多少个子数组。\n\n一个 子数组 是一个数组中一段连续的元素。\n\n示例 1:\n\n输入:nums = [1,0,2,0,1,2]\n输出:3\n解释:我们可以将数组分割成以下子数组:\n- [1,0] 。子数组分数为 1 AND 0 = 0 。\n- [2,0] 。子数组分数为 2 AND 0 = 0 。\n- [1,2] 。子数组分数为 1 AND 2 = 0 。\n分数之和为 0 + 0 + 0 = 0 ,是我们可以得到的最小分数之和。\n在分数之和为 0 的前提下,最多可以将数组分割成 3 个子数组。所以返回 3 。\n\n示例 2:\n\n输入:nums = [5,7,1,3]\n输出:1\n解释:我们可以将数组分割成一个子数组:[5,7,1,3] ,分数为 1 ,这是可以得到的最小总分数。\n在总分数为 1 的前提下,最多可以将数组分割成 1 个子数组。所以返回 1 。\n\n\n提示:\n\n * 1 <= nums.length <= 105\n * 0 <= nums[i] <= 106\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def maxSubarrays(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,0,2,0,1,2] }\nassert my_solution.maxSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [5,7,1,3] }\nassert my_solution.maxSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [1,0,2,1] }\nassert my_solution.maxSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [0] }\nassert my_solution.maxSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [0,0] }\nassert my_solution.maxSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [100000] }\nassert my_solution.maxSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,2,1] }\nassert my_solution.maxSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [30,18,19,20,11,21,12,22,26] }\nassert my_solution.maxSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [0,8,0,0,0,23] }\nassert my_solution.maxSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [8,10,23,26,21,28,21,14,21,14,9,16,24,29,7,26] }\nassert my_solution.maxSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [18,12,16,28,7,15,24,7,8,26,22,6,23,7,17,1,16] }\nassert my_solution.maxSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [22] }\nassert my_solution.maxSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [15,24,20,28,11,16,0,0,0,22,7,18] }\nassert my_solution.maxSubarrays(**test_input) == 5\n\ntest_input = { \"nums\": [0,0,27] }\nassert my_solution.maxSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [18,7,20,10,0,14,0,28,7,0,0,9,12,0] }\nassert my_solution.maxSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [0,29,16,0,6,17] }\nassert my_solution.maxSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [4,7,13,0,23,6,4] }\nassert my_solution.maxSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [4,27] }\nassert my_solution.maxSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [29,5,0,25,0,15,19,24,20,0,23] }\nassert my_solution.maxSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [24,6] }\nassert my_solution.maxSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [13,20,16,16,27,0,7,18,3,0,23,16,25,0,5,1,4] }\nassert my_solution.maxSubarrays(**test_input) == 5\n\ntest_input = { \"nums\": [0,0,30,20,6,13] }\nassert my_solution.maxSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [21,24,8,8,20,12,24,28,17,9,17] }\nassert my_solution.maxSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [0,0,18,0,0,4,5,25,0,0,0,30,0,18,0,0,12,21,21,18] }\nassert my_solution.maxSubarrays(**test_input) == 12\n\ntest_input = { \"nums\": [12,3,0,27,23,0,29,18,0,0,0,20,29,0,2,0,17,10,0,0] }\nassert my_solution.maxSubarrays(**test_input) == 11\n\ntest_input = { \"nums\": [26,28,7,14,24,15,1,16,5,24,4,10,24] }\nassert my_solution.maxSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [30,11,0,9,15,0,0,0] }\nassert my_solution.maxSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [16,18,14,6,25,30,7,0,22,0,15,0] }\nassert my_solution.maxSubarrays(**test_input) == 5\n\ntest_input = { \"nums\": [16,12,6,21,26,25,2,0,6,0,13] }\nassert my_solution.maxSubarrays(**test_input) == 5\n\ntest_input = { \"nums\": [13,1,13,18,2,15,15,27,3,3,14,12,23,8,29,10,29,15,10] }\nassert my_solution.maxSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [0,29,0,28,20,0,21,8,0,0,26,8,0,0,8,12] }\nassert my_solution.maxSubarrays(**test_input) == 8\n\ntest_input = { \"nums\": [0,18,0,0,0,22,0,15] }\nassert my_solution.maxSubarrays(**test_input) == 5\n\ntest_input = { \"nums\": [0,30,26] }\nassert my_solution.maxSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [0,1,3,29,16,0,0,0,11] }\nassert my_solution.maxSubarrays(**test_input) == 5\n\ntest_input = { \"nums\": [0,10,11,14,0,19,1,0,28,10,27,27,25,17,0,25,19] }\nassert my_solution.maxSubarrays(**test_input) == 5\n\ntest_input = { \"nums\": [18,4,0,6,0,10,23,3,26,0] }\nassert my_solution.maxSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [11,22,22,22,18,15,8,8,19,12,20,11] }\nassert my_solution.maxSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [0,23,0,0,0,17,0,0] }\nassert my_solution.maxSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [0,23,0,14,4,5,23,23,8,8,15,0,0,13,6,26,0] }\nassert my_solution.maxSubarrays(**test_input) == 7\n\ntest_input = { \"nums\": [0,3,0,16,15,0,1,0,24,16,27,0,23,15,0,13,0,0] }\nassert my_solution.maxSubarrays(**test_input) == 9\n\ntest_input = { \"nums\": [12,0,16,0,0,0,29,18] }\nassert my_solution.maxSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [0,27,15,13] }\nassert my_solution.maxSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [15,10,0,2,0,3,8,0,0,26,25,27,0,0,0,28,0,10,27,3] }\nassert my_solution.maxSubarrays(**test_input) == 9\n\ntest_input = { \"nums\": [11,10,12,6,15,25,17,21,22] }\nassert my_solution.maxSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [2,19,13] }\nassert my_solution.maxSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [27,4] }\nassert my_solution.maxSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [0,0,12,0,7,0,18,26,9,29,0,4,30,21,0,1] }\nassert my_solution.maxSubarrays(**test_input) == 7\n\ntest_input = { \"nums\": [6,8,0,0,25,0,30,18,18,0] }\nassert my_solution.maxSubarrays(**test_input) == 5\n\ntest_input = { \"nums\": [21,5,18,18,18,0,0,17,0] }\nassert my_solution.maxSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [25,29,23,27] }\nassert my_solution.maxSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [28,28,0,16,21,27,12,3,10,0,19,0,0] }\nassert my_solution.maxSubarrays(**test_input) == 5\n\ntest_input = { \"nums\": [9,2,22,14,17,3,21,1,29,3,30,13,16,17,25,26,17] }\nassert my_solution.maxSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [0,9,4,25,21,0,25,11,13,9,0,0,19,0,16,8,17,26,0,0] }\nassert my_solution.maxSubarrays(**test_input) == 9\n\ntest_input = { \"nums\": [11,0,0,2,3,0,9,26,0,0,25,7,1,12,16,14] }\nassert my_solution.maxSubarrays(**test_input) == 7\n\ntest_input = { \"nums\": [7,11,27,13,23,16,13,5,27,5,16] }\nassert my_solution.maxSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [18] }\nassert my_solution.maxSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [20,19,2,20,26,1,17,6,23,25,7,14,16,8] }\nassert my_solution.maxSubarrays(**test_input) == 5\n\ntest_input = { \"nums\": [28,0,29,9,0,11,13,22,10,16,21,30,18,19,0,0,0] }\nassert my_solution.maxSubarrays(**test_input) == 7\n\ntest_input = { \"nums\": [20,26,0,0,0,11,30] }\nassert my_solution.maxSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [16,12,0,2,15,30,0,16,7,25] }\nassert my_solution.maxSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [0,7,16,17,29,0,18,0,14,21,17,2,28,7,26,0,14] }\nassert my_solution.maxSubarrays(**test_input) == 7\n\ntest_input = { \"nums\": [29,0,19,23,13] }\nassert my_solution.maxSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [0,13,1,12,18,24,11,26,7] }\nassert my_solution.maxSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [7,26,28,12,24,10,11,26,19,29,1,26] }\nassert my_solution.maxSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [28,15,24,9,0] }\nassert my_solution.maxSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [22,6,21,16,24,7,18,25,25,26,15,10,26,22,23,15] }\nassert my_solution.maxSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [0,23,0,1,26,5,18,12,25,23,5,19] }\nassert my_solution.maxSubarrays(**test_input) == 5\n\ntest_input = { \"nums\": [16,19,0,0] }\nassert my_solution.maxSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [13] }\nassert my_solution.maxSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [8,9] }\nassert my_solution.maxSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [0,0,0,11,0,24,8,0,0,17,21,7,0,25,25] }\nassert my_solution.maxSubarrays(**test_input) == 7\n\ntest_input = { \"nums\": [0,0,10,0,0,30,5,0] }\nassert my_solution.maxSubarrays(**test_input) == 5\n\ntest_input = { \"nums\": [29,22,30,22,19,26] }\nassert my_solution.maxSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [17,15,14,24,30,14,25,28,10,11] }\nassert my_solution.maxSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [0,0,13,2,12,2,27] }\nassert my_solution.maxSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [0,18,9,0,20,0,30,22,0] }\nassert my_solution.maxSubarrays(**test_input) == 5\n\ntest_input = { \"nums\": [2,6,23,0,0,6,12,22,0,19,18,0,0,14,19,3,11,28,0,17] }\nassert my_solution.maxSubarrays(**test_input) == 7\n\ntest_input = { \"nums\": [16,12,7] }\nassert my_solution.maxSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [0,22,0,0,0,26,7] }\nassert my_solution.maxSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [0,19,5,25,0,0,4,0,0,1,0,10,25,2,3] }\nassert my_solution.maxSubarrays(**test_input) == 7\n\ntest_input = { \"nums\": [7,8,18,14,4,6,22,22,7] }\nassert my_solution.maxSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [8,9,13,0,0,20] }\nassert my_solution.maxSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [29,20,13,11,19,27,20,4,24,20,10,21,18,26,3,23,15,18,23,25] }\nassert my_solution.maxSubarrays(**test_input) == 5\n\ntest_input = { \"nums\": [25,0,18,13,22,5,0,0] }\nassert my_solution.maxSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [9,3,0,2,18,11,15,1,10,0,0,16,0,11] }\nassert my_solution.maxSubarrays(**test_input) == 5\n\ntest_input = { \"nums\": [9,0,0,11,14,0,23,0] }\nassert my_solution.maxSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [6,3,22,28,0,0,25,2,23,0,0,23,15,0] }\nassert my_solution.maxSubarrays(**test_input) == 7\n\ntest_input = { \"nums\": [0,10,11,25,14] }\nassert my_solution.maxSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [26,9,27,25,30,25,10,3,14,29,2,6,5,7,8,18] }\nassert my_solution.maxSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [5,9,0,28,23,11,1,3] }\nassert my_solution.maxSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [0,22,3,0,15,0,11,3,20,23,0,7,13,20,11,6,19] }\nassert my_solution.maxSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [0,16,6] }\nassert my_solution.maxSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [26,9,20,26,22,12,18,21,23,30,3,9,12,19,16] }\nassert my_solution.maxSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [14,10,8] }\nassert my_solution.maxSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [0,0,0,19,0] }\nassert my_solution.maxSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [3,27] }\nassert my_solution.maxSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [7,14,27] }\nassert my_solution.maxSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [16,4,29,17,0,0,13,22,1,6,0,29,1,3,0,7] }\nassert my_solution.maxSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [5,0,0,9,0,0,19,0,0,0,0,7,19,14,3,0,10,29] }\nassert my_solution.maxSubarrays(**test_input) == 9\n\ntest_input = { \"nums\": [16,22,0,0,0,0,27,0,0,0,24,22,0,0] }\nassert my_solution.maxSubarrays(**test_input) == 9", "start_time": 1696084200} +{"task_id": "biweekly-contest-114-maximum-number-of-k-divisible-components", "url": "https://leetcode.com/problems/maximum-number-of-k-divisible-components", "title": "maximum-number-of-k-divisible-components", "meta": {"questionId": "3058", "questionFrontendId": "2872", "title": "Maximum Number of K-Divisible Components", "titleSlug": "maximum-number-of-k-divisible-components", "isPaidOnly": false, "difficulty": "Hard", "likes": 170, "dislikes": 3, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一棵 n 个节点的无向树,节点编号为 0 到 n - 1 。给你整数 n 和一个长度为 n - 1 的二维整数数组 edges ,其中 edges[i] = [ai, bi] 表示树中节点 ai 和 bi 有一条边。\n\n同时给你一个下标从 0 开始长度为 n 的整数数组 values ,其中 values[i] 是第 i 个节点的 值 。再给你一个整数 k 。\n\n你可以从树中删除一些边,也可以一条边也不删,得到若干连通块。一个 连通块的值 定义为连通块中所有节点值之和。如果所有连通块的值都可以被 k 整除,那么我们说这是一个 合法分割 。\n\n请你返回所有合法分割中,连通块数目的最大值 。\n\n示例 1:\n\n[https://assets.leetcode.com/uploads/2023/08/07/example12-cropped2svg.jpg]\n\n输入:n = 5, edges = [[0,2],[1,2],[1,3],[2,4]], values = [1,8,1,4,4], k = 6\n输出:2\n解释:我们删除节点 1 和 2 之间的边。这是一个合法分割,因为:\n- 节点 1 和 3 所在连通块的值为 values[1] + values[3] = 12 。\n- 节点 0 ,2 和 4 所在连通块的值为 values[0] + values[2] + values[4] = 6 。\n最多可以得到 2 个连通块的合法分割。\n\n示例 2:\n\n[https://assets.leetcode.com/uploads/2023/08/07/example21svg-1.jpg]\n\n输入:n = 7, edges = [[0,1],[0,2],[1,3],[1,4],[2,5],[2,6]], values = [3,0,6,1,5,2,1], k = 3\n输出:3\n解释:我们删除节点 0 和 2 ,以及节点 0 和 1 之间的边。这是一个合法分割,因为:\n- 节点 0 的连通块的值为 values[0] = 3 。\n- 节点 2 ,5 和 6 所在连通块的值为 values[2] + values[5] + values[6] = 9 。\n- 节点 1 ,3 和 4 的连通块的值为 values[1] + values[3] + values[4] = 6 。\n最多可以得到 3 个连通块的合法分割。\n\n\n提示:\n\n * 1 <= n <= 3 * 104\n * edges.length == n - 1\n * edges[i].length == 2\n * 0 <= ai, bi < n\n * values.length == n\n * 0 <= values[i] <= 109\n * 1 <= k <= 109\n * values 之和可以被 k 整除。\n * 输入保证 edges 是一棵无向树。\n\"\"\"\nclass Solution:\n def maxKDivisibleComponents(self, n: int, edges: List[List[int]], values: List[int], k: int) -> int:\n ", "prompt_sft": "给你一棵 n 个节点的无向树,节点编号为 0 到 n - 1 。给你整数 n 和一个长度为 n - 1 的二维整数数组 edges ,其中 edges[i] = [ai, bi] 表示树中节点 ai 和 bi 有一条边。\n\n同时给你一个下标从 0 开始长度为 n 的整数数组 values ,其中 values[i] 是第 i 个节点的 值 。再给你一个整数 k 。\n\n你可以从树中删除一些边,也可以一条边也不删,得到若干连通块。一个 连通块的值 定义为连通块中所有节点值之和。如果所有连通块的值都可以被 k 整除,那么我们说这是一个 合法分割 。\n\n请你返回所有合法分割中,连通块数目的最大值 。\n\n示例 1:\n\n[https://assets.leetcode.com/uploads/2023/08/07/example12-cropped2svg.jpg]\n\n输入:n = 5, edges = [[0,2],[1,2],[1,3],[2,4]], values = [1,8,1,4,4], k = 6\n输出:2\n解释:我们删除节点 1 和 2 之间的边。这是一个合法分割,因为:\n- 节点 1 和 3 所在连通块的值为 values[1] + values[3] = 12 。\n- 节点 0 ,2 和 4 所在连通块的值为 values[0] + values[2] + values[4] = 6 。\n最多可以得到 2 个连通块的合法分割。\n\n示例 2:\n\n[https://assets.leetcode.com/uploads/2023/08/07/example21svg-1.jpg]\n\n输入:n = 7, edges = [[0,1],[0,2],[1,3],[1,4],[2,5],[2,6]], values = [3,0,6,1,5,2,1], k = 3\n输出:3\n解释:我们删除节点 0 和 2 ,以及节点 0 和 1 之间的边。这是一个合法分割,因为:\n- 节点 0 的连通块的值为 values[0] = 3 。\n- 节点 2 ,5 和 6 所在连通块的值为 values[2] + values[5] + values[6] = 9 。\n- 节点 1 ,3 和 4 的连通块的值为 values[1] + values[3] + values[4] = 6 。\n最多可以得到 3 个连通块的合法分割。\n\n\n提示:\n\n * 1 <= n <= 3 * 104\n * edges.length == n - 1\n * edges[i].length == 2\n * 0 <= ai, bi < n\n * values.length == n\n * 0 <= values[i] <= 109\n * 1 <= k <= 109\n * values 之和可以被 k 整除。\n * 输入保证 edges 是一棵无向树。\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def maxKDivisibleComponents(self, n: int, edges: List[List[int]], values: List[int], k: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"n\": 5, \"edges\": [[0,2],[1,2],[1,3],[2,4]], \"values\": [1,8,1,4,4], \"k\": 6 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 2\n\ntest_input = { \"n\": 7, \"edges\": [[0,1],[0,2],[1,3],[1,4],[2,5],[2,6]], \"values\": [3,0,6,1,5,2,1], \"k\": 3 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 3\n\ntest_input = { \"n\": 1, \"edges\": [], \"values\": [0], \"k\": 1 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 1\n\ntest_input = { \"n\": 1, \"edges\": [], \"values\": [10000], \"k\": 100 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 1\n\ntest_input = { \"n\": 2, \"edges\": [[1,0]], \"values\": [0,0], \"k\": 100000000 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 2\n\ntest_input = { \"n\": 2, \"edges\": [[0,1]], \"values\": [1,2], \"k\": 1 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 2\n\ntest_input = { \"n\": 2, \"edges\": [[1,0]], \"values\": [10000,10000], \"k\": 4 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 2\n\ntest_input = { \"n\": 3, \"edges\": [[0,2],[2,1]], \"values\": [0,0,0], \"k\": 1 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 3\n\ntest_input = { \"n\": 3, \"edges\": [[1,0],[2,0]], \"values\": [1,1,2], \"k\": 2 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 2\n\ntest_input = { \"n\": 3, \"edges\": [[1,2],[2,0]], \"values\": [0,2,2], \"k\": 4 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 2\n\ntest_input = { \"n\": 3, \"edges\": [[1,0],[0,2]], \"values\": [0,1,2], \"k\": 3 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 1\n\ntest_input = { \"n\": 4, \"edges\": [[0,1],[1,2],[2,3]], \"values\": [0,0,0,0], \"k\": 9999999 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 4\n\ntest_input = { \"n\": 9, \"edges\": [[1,2],[1,7],[0,6],[0,8],[0,3],[3,4],[0,5],[2,5]], \"values\": [1,4,4,0,2,1,1,6,2], \"k\": 7 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 2\n\ntest_input = { \"n\": 9, \"edges\": [[5,0],[5,1],[1,6],[1,7],[5,8],[0,3],[2,4],[5,2]], \"values\": [3,0,10,0,6,1,1,3,0], \"k\": 8 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 4\n\ntest_input = { \"n\": 6, \"edges\": [[5,0],[1,4],[4,3],[4,2],[5,4]], \"values\": [1,2,2,2,0,2], \"k\": 3 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 2\n\ntest_input = { \"n\": 4, \"edges\": [[0,3],[1,2],[0,2]], \"values\": [12,6,0,18], \"k\": 6 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 4\n\ntest_input = { \"n\": 10, \"edges\": [[8,7],[8,3],[7,6],[6,2],[6,4],[3,9],[4,1],[6,0],[2,5]], \"values\": [2,2,2,0,1,3,1,0,3,1], \"k\": 1 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 10\n\ntest_input = { \"n\": 8, \"edges\": [[0,4],[4,1],[0,3],[1,2],[0,5],[5,7],[1,6]], \"values\": [2,6,2,2,2,0,0,0], \"k\": 7 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 4\n\ntest_input = { \"n\": 9, \"edges\": [[1,5],[5,2],[1,8],[2,0],[2,6],[1,7],[6,4],[7,3]], \"values\": [8,8,12,12,8,8,8,8,4], \"k\": 4 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 9\n\ntest_input = { \"n\": 7, \"edges\": [[0,3],[3,2],[3,5],[0,6],[0,1],[6,4]], \"values\": [12,6,6,12,18,18,12], \"k\": 6 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 7\n\ntest_input = { \"n\": 4, \"edges\": [[1,3],[0,2],[1,0]], \"values\": [2,6,1,9], \"k\": 3 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 3\n\ntest_input = { \"n\": 5, \"edges\": [[2,0],[0,1],[2,3],[2,4]], \"values\": [0,2,10,0,18], \"k\": 6 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 3\n\ntest_input = { \"n\": 6, \"edges\": [[3,5],[3,0],[5,2],[5,4],[3,1]], \"values\": [3,3,0,18,0,0], \"k\": 8 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 4\n\ntest_input = { \"n\": 10, \"edges\": [[9,5],[4,9],[5,8],[3,6],[8,6],[0,1],[9,0],[6,2],[3,7]], \"values\": [10,14,12,4,12,1,8,36,12,11], \"k\": 12 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 7\n\ntest_input = { \"n\": 7, \"edges\": [[3,0],[0,4],[2,6],[3,6],[2,1],[1,5]], \"values\": [5,36,21,7,36,36,15], \"k\": 12 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 5\n\ntest_input = { \"n\": 5, \"edges\": [[2,3],[2,0],[2,4],[3,1]], \"values\": [3,0,3,15,3], \"k\": 8 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 2\n\ntest_input = { \"n\": 10, \"edges\": [[9,1],[1,7],[7,3],[3,6],[1,8],[9,4],[3,0],[3,5],[9,2]], \"values\": [9,9,18,9,9,18,9,9,18,27], \"k\": 9 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 10\n\ntest_input = { \"n\": 4, \"edges\": [[2,1],[2,0],[2,3]], \"values\": [2,0,8,10], \"k\": 5 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 3\n\ntest_input = { \"n\": 5, \"edges\": [[2,4],[4,0],[0,1],[0,3]], \"values\": [10,20,10,30,30], \"k\": 10 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 5\n\ntest_input = { \"n\": 10, \"edges\": [[5,6],[5,4],[5,1],[5,0],[1,7],[0,8],[0,2],[8,9],[3,8]], \"values\": [4,0,2,9,2,8,0,2,0,0], \"k\": 9 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 5\n\ntest_input = { \"n\": 9, \"edges\": [[5,6],[5,1],[6,0],[6,8],[8,2],[7,3],[8,3],[8,4]], \"values\": [33,11,33,6,11,11,33,16,33], \"k\": 11 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 8\n\ntest_input = { \"n\": 4, \"edges\": [[3,0],[0,2],[3,1]], \"values\": [8,8,12,4], \"k\": 4 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 4\n\ntest_input = { \"n\": 8, \"edges\": [[1,6],[5,7],[6,7],[3,2],[3,4],[4,0],[1,2]], \"values\": [6,6,6,6,3,8,15,6], \"k\": 7 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 3\n\ntest_input = { \"n\": 9, \"edges\": [[7,8],[4,6],[8,6],[3,0],[3,5],[5,1],[1,2],[7,0]], \"values\": [5,0,1,1,1,3,9,30,10], \"k\": 10 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 4\n\ntest_input = { \"n\": 4, \"edges\": [[2,1],[1,0],[2,3]], \"values\": [1,0,1,2], \"k\": 2 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 2\n\ntest_input = { \"n\": 4, \"edges\": [[1,2],[1,0],[2,3]], \"values\": [2,1,0,1], \"k\": 1 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 4\n\ntest_input = { \"n\": 4, \"edges\": [[2,1],[2,3],[2,0]], \"values\": [3,6,9,6], \"k\": 3 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 4\n\ntest_input = { \"n\": 7, \"edges\": [[0,4],[0,1],[4,6],[4,3],[6,5],[2,4]], \"values\": [2,0,2,0,0,0,0], \"k\": 2 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 7\n\ntest_input = { \"n\": 9, \"edges\": [[6,0],[1,2],[6,2],[2,3],[3,7],[3,8],[0,5],[3,4]], \"values\": [1,1,0,3,3,3,1,1,3], \"k\": 1 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 9\n\ntest_input = { \"n\": 5, \"edges\": [[0,4],[0,1],[1,3],[0,2]], \"values\": [2,12,14,0,0], \"k\": 7 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 4\n\ntest_input = { \"n\": 6, \"edges\": [[1,2],[0,5],[5,4],[0,3],[2,0]], \"values\": [2,2,2,0,0,2], \"k\": 2 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 6\n\ntest_input = { \"n\": 10, \"edges\": [[3,1],[1,4],[4,5],[3,0],[4,7],[7,2],[0,9],[0,8],[1,6]], \"values\": [0,0,0,1,0,0,0,0,0,0], \"k\": 1 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 10\n\ntest_input = { \"n\": 5, \"edges\": [[3,1],[0,3],[4,2],[1,2]], \"values\": [3,1,3,2,6], \"k\": 3 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 4\n\ntest_input = { \"n\": 10, \"edges\": [[6,3],[3,9],[3,7],[3,4],[7,8],[8,0],[8,5],[3,2],[0,1]], \"values\": [0,0,0,0,0,0,2,0,0,0], \"k\": 1 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 10\n\ntest_input = { \"n\": 5, \"edges\": [[4,3],[3,1],[1,2],[1,0]], \"values\": [8,6,0,8,2], \"k\": 8 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 3\n\ntest_input = { \"n\": 8, \"edges\": [[1,3],[0,3],[7,4],[4,6],[0,7],[0,2],[4,5]], \"values\": [12,10,6,2,6,12,3,9], \"k\": 6 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 5\n\ntest_input = { \"n\": 9, \"edges\": [[5,4],[2,1],[2,0],[0,7],[7,8],[5,2],[6,3],[2,3]], \"values\": [1,2,3,2,2,4,4,0,0], \"k\": 6 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 5\n\ntest_input = { \"n\": 7, \"edges\": [[4,6],[4,2],[2,1],[2,5],[4,3],[0,5]], \"values\": [27,0,1,1,4,2,1], \"k\": 9 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 3\n\ntest_input = { \"n\": 7, \"edges\": [[4,6],[0,2],[0,5],[2,3],[3,1],[4,2]], \"values\": [1,0,0,1,2,0,0], \"k\": 2 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 5\n\ntest_input = { \"n\": 9, \"edges\": [[3,2],[2,1],[1,4],[4,6],[4,8],[6,0],[0,5],[5,7]], \"values\": [10,10,15,5,5,15,15,10,15], \"k\": 5 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 9\n\ntest_input = { \"n\": 10, \"edges\": [[9,6],[9,0],[9,3],[3,8],[6,5],[0,7],[8,2],[6,4],[4,1]], \"values\": [0,0,3,0,0,0,3,0,3,3], \"k\": 4 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 6\n\ntest_input = { \"n\": 8, \"edges\": [[4,3],[3,6],[6,1],[6,7],[1,2],[7,0],[4,5]], \"values\": [30,10,10,20,10,10,30,10], \"k\": 10 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 8\n\ntest_input = { \"n\": 4, \"edges\": [[2,1],[1,0],[0,3]], \"values\": [9,6,6,9], \"k\": 3 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 4\n\ntest_input = { \"n\": 5, \"edges\": [[3,4],[3,2],[4,0],[2,1]], \"values\": [3,2,2,3,1], \"k\": 1 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 5\n\ntest_input = { \"n\": 5, \"edges\": [[1,3],[3,4],[4,2],[2,0]], \"values\": [27,14,0,0,4], \"k\": 9 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 3\n\ntest_input = { \"n\": 4, \"edges\": [[1,2],[2,0],[0,3]], \"values\": [3,1,2,3], \"k\": 1 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 4\n\ntest_input = { \"n\": 7, \"edges\": [[6,1],[6,4],[1,3],[3,0],[2,5],[4,2]], \"values\": [33,18,7,22,11,4,4], \"k\": 11 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 5\n\ntest_input = { \"n\": 10, \"edges\": [[6,2],[5,2],[0,3],[0,7],[0,1],[6,7],[2,4],[8,9],[5,9]], \"values\": [3,0,1,0,3,3,2,0,6,3], \"k\": 3 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 9\n\ntest_input = { \"n\": 8, \"edges\": [[6,1],[0,5],[5,7],[5,2],[5,4],[1,4],[0,3]], \"values\": [15,24,9,12,0,3,24,9], \"k\": 12 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 5\n\ntest_input = { \"n\": 6, \"edges\": [[3,1],[3,5],[1,4],[1,0],[3,2]], \"values\": [12,12,36,12,24,36], \"k\": 12 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 6\n\ntest_input = { \"n\": 7, \"edges\": [[6,4],[6,5],[3,1],[1,0],[0,2],[4,2]], \"values\": [0,0,0,1,0,0,1], \"k\": 1 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 7\n\ntest_input = { \"n\": 8, \"edges\": [[6,1],[2,0],[0,7],[1,2],[4,5],[7,5],[1,3]], \"values\": [1,14,5,21,18,3,7,1], \"k\": 7 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 5\n\ntest_input = { \"n\": 4, \"edges\": [[1,3],[1,0],[1,2]], \"values\": [18,18,9,27], \"k\": 9 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 4\n\ntest_input = { \"n\": 5, \"edges\": [[1,2],[1,3],[3,4],[1,0]], \"values\": [2,3,0,0,0], \"k\": 1 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 5\n\ntest_input = { \"n\": 5, \"edges\": [[2,3],[2,4],[4,1],[2,0]], \"values\": [0,0,1,0,0], \"k\": 1 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 5\n\ntest_input = { \"n\": 6, \"edges\": [[1,4],[1,3],[1,2],[4,0],[2,5]], \"values\": [0,3,0,0,0,0], \"k\": 1 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 6\n\ntest_input = { \"n\": 6, \"edges\": [[4,1],[0,2],[4,2],[3,5],[1,5]], \"values\": [3,9,6,3,9,6], \"k\": 3 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 6\n\ntest_input = { \"n\": 4, \"edges\": [[1,3],[0,2],[1,2]], \"values\": [4,1,0,3], \"k\": 4 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 3\n\ntest_input = { \"n\": 7, \"edges\": [[4,5],[5,2],[2,0],[0,6],[5,3],[2,1]], \"values\": [15,15,10,5,2,8,5], \"k\": 5 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 6\n\ntest_input = { \"n\": 5, \"edges\": [[2,4],[2,0],[0,3],[2,1]], \"values\": [36,24,10,24,2], \"k\": 12 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 4\n\ntest_input = { \"n\": 7, \"edges\": [[2,4],[2,1],[2,5],[1,3],[4,0],[1,6]], \"values\": [2,0,2,2,0,2,0], \"k\": 4 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 2\n\ntest_input = { \"n\": 4, \"edges\": [[3,2],[2,1],[2,0]], \"values\": [6,2,2,6], \"k\": 8 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 1\n\ntest_input = { \"n\": 10, \"edges\": [[7,4],[7,2],[4,1],[6,5],[6,0],[7,6],[1,8],[9,3],[7,9]], \"values\": [12,4,3,2,1,18,3,3,22,20], \"k\": 11 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 4\n\ntest_input = { \"n\": 5, \"edges\": [[0,3],[3,2],[3,1],[0,4]], \"values\": [12,36,36,36,12], \"k\": 12 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 5\n\ntest_input = { \"n\": 5, \"edges\": [[0,1],[1,2],[2,3],[3,4]], \"values\": [3,0,0,18,3], \"k\": 8 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 1\n\ntest_input = { \"n\": 4, \"edges\": [[3,2],[3,0],[3,1]], \"values\": [9,0,15,3], \"k\": 9 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 3\n\ntest_input = { \"n\": 5, \"edges\": [[0,2],[0,3],[3,4],[1,3]], \"values\": [3,3,0,0,0], \"k\": 1 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 5\n\ntest_input = { \"n\": 5, \"edges\": [[1,4],[1,3],[0,3],[1,2]], \"values\": [10,2,15,2,1], \"k\": 5 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 3\n\ntest_input = { \"n\": 6, \"edges\": [[1,4],[4,5],[0,3],[1,0],[0,2]], \"values\": [6,9,6,3,6,3], \"k\": 3 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 6\n\ntest_input = { \"n\": 6, \"edges\": [[5,1],[0,1],[2,4],[2,3],[1,4]], \"values\": [21,4,3,1,3,3], \"k\": 7 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 3\n\ntest_input = { \"n\": 6, \"edges\": [[5,1],[1,2],[5,3],[1,4],[2,0]], \"values\": [0,4,0,2,0,2], \"k\": 4 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 5\n\ntest_input = { \"n\": 10, \"edges\": [[3,6],[3,4],[6,0],[3,9],[5,7],[6,5],[0,2],[6,1],[9,8]], \"values\": [0,12,12,3,9,8,3,4,12,3], \"k\": 6 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 6\n\ntest_input = { \"n\": 7, \"edges\": [[0,2],[2,5],[2,3],[5,4],[2,1],[3,6]], \"values\": [9,9,3,6,3,0,0], \"k\": 10 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 2\n\ntest_input = { \"n\": 6, \"edges\": [[4,1],[4,5],[4,2],[4,0],[3,1]], \"values\": [0,6,6,22,2,8], \"k\": 11 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 3\n\ntest_input = { \"n\": 8, \"edges\": [[2,7],[1,4],[2,4],[4,3],[2,5],[7,0],[7,6]], \"values\": [12,3,12,4,1,8,12,12], \"k\": 4 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 7\n\ntest_input = { \"n\": 5, \"edges\": [[0,3],[0,1],[0,2],[0,4]], \"values\": [3,3,0,18,0], \"k\": 8 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 3\n\ntest_input = { \"n\": 4, \"edges\": [[2,0],[2,1],[0,3]], \"values\": [10,15,5,15], \"k\": 5 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 4\n\ntest_input = { \"n\": 7, \"edges\": [[2,5],[5,1],[5,4],[1,6],[4,3],[3,0]], \"values\": [0,0,6,2,0,2,2], \"k\": 6 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 3\n\ntest_input = { \"n\": 8, \"edges\": [[5,2],[2,4],[5,1],[5,3],[1,0],[2,6],[2,7]], \"values\": [18,9,9,9,27,9,9,18], \"k\": 9 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 8\n\ntest_input = { \"n\": 7, \"edges\": [[5,6],[6,4],[5,2],[6,3],[1,0],[5,1]], \"values\": [9,21,6,20,2,8,4], \"k\": 10 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 3\n\ntest_input = { \"n\": 8, \"edges\": [[3,1],[3,0],[0,4],[3,5],[7,6],[1,6],[6,2]], \"values\": [10,10,5,15,5,15,3,2], \"k\": 5 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 7\n\ntest_input = { \"n\": 5, \"edges\": [[2,4],[2,1],[2,0],[0,3]], \"values\": [1,2,1,0,2], \"k\": 6 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 2\n\ntest_input = { \"n\": 8, \"edges\": [[1,0],[0,2],[0,6],[2,5],[1,3],[2,4],[2,7]], \"values\": [0,3,18,9,0,0,0,3], \"k\": 11 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 4\n\ntest_input = { \"n\": 9, \"edges\": [[5,0],[2,4],[0,2],[2,3],[4,1],[2,7],[8,6],[0,8]], \"values\": [10,10,2,20,18,20,6,10,24], \"k\": 10 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 7\n\ntest_input = { \"n\": 10, \"edges\": [[0,9],[9,7],[1,4],[0,4],[8,2],[4,2],[2,3],[3,5],[0,6]], \"values\": [6,4,6,18,8,18,12,18,6,12], \"k\": 6 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 9\n\ntest_input = { \"n\": 7, \"edges\": [[4,2],[6,4],[5,3],[3,1],[4,5],[2,0]], \"values\": [9,3,0,9,9,15,18], \"k\": 9 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 5\n\ntest_input = { \"n\": 5, \"edges\": [[2,3],[3,1],[3,0],[1,4]], \"values\": [0,0,3,0,3], \"k\": 2 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 2\n\ntest_input = { \"n\": 10, \"edges\": [[3,6],[4,3],[0,8],[0,5],[8,9],[0,1],[8,7],[5,2],[3,8]], \"values\": [6,6,0,4,7,0,3,0,3,6], \"k\": 7 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 6\n\ntest_input = { \"n\": 6, \"edges\": [[2,3],[4,5],[4,1],[2,4],[2,0]], \"values\": [20,0,30,30,12,8], \"k\": 10 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 5\n\ntest_input = { \"n\": 9, \"edges\": [[5,7],[5,4],[5,6],[7,2],[7,1],[4,3],[2,0],[3,8]], \"values\": [6,6,6,18,6,12,18,6,6], \"k\": 6 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 9", "start_time": 1696084200} +{"task_id": "weekly-contest-364-maximum-odd-binary-number", "url": "https://leetcode.com/problems/maximum-odd-binary-number", "title": "maximum-odd-binary-number", "meta": {"questionId": "3055", "questionFrontendId": "2864", "title": "Maximum Odd Binary Number", "titleSlug": "maximum-odd-binary-number", "isPaidOnly": false, "difficulty": "Easy", "likes": 149, "dislikes": 1, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个 二进制 字符串 s ,其中至少包含一个 '1' 。\n\n你必须按某种方式 重新排列 字符串中的位,使得到的二进制数字是可以由该组合生成的 最大二进制奇数 。\n\n以字符串形式,表示并返回可以由给定组合生成的最大二进制奇数。\n\n注意 返回的结果字符串 可以 含前导零。\n\n示例 1:\n\n输入:s = \"010\"\n输出:\"001\"\n解释:因为字符串 s 中仅有一个 '1' ,其必须出现在最后一位上。所以答案是 \"001\" 。\n\n示例 2:\n\n输入:s = \"0101\"\n输出:\"1001\"\n解释:其中一个 '1' 必须出现在最后一位上。而由剩下的数字可以生产的最大数字是 \"100\" 。所以答案是 \"1001\" 。\n\n\n提示:\n\n * 1 <= s.length <= 100\n * s 仅由 '0' 和 '1' 组成\n * s 中至少包含一个 '1'\n\"\"\"\nclass Solution:\n def maximumOddBinaryNumber(self, s: str) -> str:\n ", "prompt_sft": "给你一个 二进制 字符串 s ,其中至少包含一个 '1' 。\n\n你必须按某种方式 重新排列 字符串中的位,使得到的二进制数字是可以由该组合生成的 最大二进制奇数 。\n\n以字符串形式,表示并返回可以由给定组合生成的最大二进制奇数。\n\n注意 返回的结果字符串 可以 含前导零。\n\n示例 1:\n\n输入:s = \"010\"\n输出:\"001\"\n解释:因为字符串 s 中仅有一个 '1' ,其必须出现在最后一位上。所以答案是 \"001\" 。\n\n示例 2:\n\n输入:s = \"0101\"\n输出:\"1001\"\n解释:其中一个 '1' 必须出现在最后一位上。而由剩下的数字可以生产的最大数字是 \"100\" 。所以答案是 \"1001\" 。\n\n\n提示:\n\n * 1 <= s.length <= 100\n * s 仅由 '0' 和 '1' 组成\n * s 中至少包含一个 '1'\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def maximumOddBinaryNumber(self, s: str) -> str:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"s\": \"010\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"001\"\n\ntest_input = { \"s\": \"0101\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1001\"\n\ntest_input = { \"s\": \"1\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1\"\n\ntest_input = { \"s\": \"01\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"01\"\n\ntest_input = { \"s\": \"10\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"01\"\n\ntest_input = { \"s\": \"11\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"11\"\n\ntest_input = { \"s\": \"001\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"001\"\n\ntest_input = { \"s\": \"011\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"101\"\n\ntest_input = { \"s\": \"100\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"001\"\n\ntest_input = { \"s\": \"101\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"101\"\n\ntest_input = { \"s\": \"110\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"101\"\n\ntest_input = { \"s\": \"111\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"111\"\n\ntest_input = { \"s\": \"0010\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"0001\"\n\ntest_input = { \"s\": \"0011\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1001\"\n\ntest_input = { \"s\": \"0100\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"0001\"\n\ntest_input = { \"s\": \"0111\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1101\"\n\ntest_input = { \"s\": \"1000\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"0001\"\n\ntest_input = { \"s\": \"1001\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1001\"\n\ntest_input = { \"s\": \"1011\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1101\"\n\ntest_input = { \"s\": \"1100\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1001\"\n\ntest_input = { \"s\": \"1101\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1101\"\n\ntest_input = { \"s\": \"1111\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1111\"\n\ntest_input = { \"s\": \"00001\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"00001\"\n\ntest_input = { \"s\": \"00011\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"10001\"\n\ntest_input = { \"s\": \"00100\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"00001\"\n\ntest_input = { \"s\": \"00101\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"10001\"\n\ntest_input = { \"s\": \"00111\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"11001\"\n\ntest_input = { \"s\": \"01011\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"11001\"\n\ntest_input = { \"s\": \"01100\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"10001\"\n\ntest_input = { \"s\": \"01110\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"11001\"\n\ntest_input = { \"s\": \"01111\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"11101\"\n\ntest_input = { \"s\": \"10000\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"00001\"\n\ntest_input = { \"s\": \"10100\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"10001\"\n\ntest_input = { \"s\": \"11010\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"11001\"\n\ntest_input = { \"s\": \"11011\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"11101\"\n\ntest_input = { \"s\": \"11110\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"11101\"\n\ntest_input = { \"s\": \"000001\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"000001\"\n\ntest_input = { \"s\": \"000100\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"000001\"\n\ntest_input = { \"s\": \"000101\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"100001\"\n\ntest_input = { \"s\": \"000110\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"100001\"\n\ntest_input = { \"s\": \"000111\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"110001\"\n\ntest_input = { \"s\": \"001100\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"100001\"\n\ntest_input = { \"s\": \"001110\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"110001\"\n\ntest_input = { \"s\": \"001111\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"111001\"\n\ntest_input = { \"s\": \"010001\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"100001\"\n\ntest_input = { \"s\": \"010101\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"110001\"\n\ntest_input = { \"s\": \"010111\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"111001\"\n\ntest_input = { \"s\": \"011010\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"110001\"\n\ntest_input = { \"s\": \"011100\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"110001\"\n\ntest_input = { \"s\": \"011111\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"111101\"\n\ntest_input = { \"s\": \"100100\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"100001\"\n\ntest_input = { \"s\": \"100101\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"110001\"\n\ntest_input = { \"s\": \"100111\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"111001\"\n\ntest_input = { \"s\": \"101010\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"110001\"\n\ntest_input = { \"s\": \"101100\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"110001\"\n\ntest_input = { \"s\": \"101101\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"111001\"\n\ntest_input = { \"s\": \"110000\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"100001\"\n\ntest_input = { \"s\": \"110010\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"110001\"\n\ntest_input = { \"s\": \"110011\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"111001\"\n\ntest_input = { \"s\": \"110100\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"110001\"\n\ntest_input = { \"s\": \"110101\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"111001\"\n\ntest_input = { \"s\": \"110110\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"111001\"\n\ntest_input = { \"s\": \"111000\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"110001\"\n\ntest_input = { \"s\": \"111010\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"111001\"\n\ntest_input = { \"s\": \"111101\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"111101\"\n\ntest_input = { \"s\": \"111111\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"111111\"\n\ntest_input = { \"s\": \"0000010\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"0000001\"\n\ntest_input = { \"s\": \"0000100\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"0000001\"\n\ntest_input = { \"s\": \"0001001\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1000001\"\n\ntest_input = { \"s\": \"0001110\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1100001\"\n\ntest_input = { \"s\": \"0010000\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"0000001\"\n\ntest_input = { \"s\": \"0010101\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1100001\"\n\ntest_input = { \"s\": \"0010110\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1100001\"\n\ntest_input = { \"s\": \"0010111\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1110001\"\n\ntest_input = { \"s\": \"0011101\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1110001\"\n\ntest_input = { \"s\": \"0011111\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1111001\"\n\ntest_input = { \"s\": \"0100100\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1000001\"\n\ntest_input = { \"s\": \"0101001\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1100001\"\n\ntest_input = { \"s\": \"0110010\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1100001\"\n\ntest_input = { \"s\": \"0110110\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1110001\"\n\ntest_input = { \"s\": \"0110111\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1111001\"\n\ntest_input = { \"s\": \"0111011\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1111001\"\n\ntest_input = { \"s\": \"0111101\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1111001\"\n\ntest_input = { \"s\": \"1000011\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1100001\"\n\ntest_input = { \"s\": \"1000100\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1000001\"\n\ntest_input = { \"s\": \"1000101\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1100001\"\n\ntest_input = { \"s\": \"1000111\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1110001\"\n\ntest_input = { \"s\": \"1001100\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1100001\"\n\ntest_input = { \"s\": \"1001101\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1110001\"\n\ntest_input = { \"s\": \"1010000\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1000001\"\n\ntest_input = { \"s\": \"1010100\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1100001\"\n\ntest_input = { \"s\": \"1010111\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1111001\"\n\ntest_input = { \"s\": \"1011000\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1100001\"\n\ntest_input = { \"s\": \"1011010\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1110001\"\n\ntest_input = { \"s\": \"1011011\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1111001\"\n\ntest_input = { \"s\": \"1100100\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1100001\"\n\ntest_input = { \"s\": \"1100101\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1110001\"\n\ntest_input = { \"s\": \"1101010\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1110001\"\n\ntest_input = { \"s\": \"1101011\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1111001\"\n\ntest_input = { \"s\": \"1101110\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1111001\"", "start_time": 1695522600} +{"task_id": "weekly-contest-364-beautiful-towers-i", "url": "https://leetcode.com/problems/beautiful-towers-i", "title": "beautiful-towers-i", "meta": {"questionId": "3114", "questionFrontendId": "2865", "title": "Beautiful Towers I", "titleSlug": "beautiful-towers-i", "isPaidOnly": false, "difficulty": "Medium", "likes": 160, "dislikes": 26, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个长度为 n 下标从 0 开始的整数数组 maxHeights 。\n\n你的任务是在坐标轴上建 n 座塔。第 i 座塔的下标为 i ,高度为 heights[i] 。\n\n如果以下条件满足,我们称这些塔是 美丽 的:\n\n 1. 1 <= heights[i] <= maxHeights[i]\n 2. heights 是一个 山状 数组。\n\n如果存在下标 i 满足以下条件,那么我们称数组 heights 是一个 山状 数组:\n\n * 对于所有 0 < j <= i ,都有 heights[j - 1] <= heights[j]\n * 对于所有 i <= k < n - 1 ,都有 heights[k + 1] <= heights[k]\n\n请你返回满足 美丽塔 要求的方案中,高度和的最大值 。\n\n示例 1:\n\n输入:maxHeights = [5,3,4,1,1]\n输出:13\n解释:和最大的美丽塔方案为 heights = [5,3,3,1,1] ,这是一个美丽塔方案,因为:\n- 1 <= heights[i] <= maxHeights[i]\n- heights 是个山状数组,峰值在 i = 0 处。\n13 是所有美丽塔方案中的最大高度和。\n\n示例 2:\n\n输入:maxHeights = [6,5,3,9,2,7]\n输出:22\n解释: 和最大的美丽塔方案为 heights = [3,3,3,9,2,2] ,这是一个美丽塔方案,因为:\n- 1 <= heights[i] <= maxHeights[i]\n- heights 是个山状数组,峰值在 i = 3 处。\n22 是所有美丽塔方案中的最大高度和。\n\n示例 3:\n\n输入:maxHeights = [3,2,5,5,2,3]\n输出:18\n解释:和最大的美丽塔方案为 heights = [2,2,5,5,2,2] ,这是一个美丽塔方案,因为:\n- 1 <= heights[i] <= maxHeights[i]\n- heights 是个山状数组,最大值在 i = 2 处。\n注意,在这个方案中,i = 3 也是一个峰值。\n18 是所有美丽塔方案中的最大高度和。\n\n\n提示:\n\n * 1 <= n == maxHeights <= 103\n * 1 <= maxHeights[i] <= 109\n\"\"\"\nclass Solution:\n def maximumSumOfHeights(self, maxHeights: List[int]) -> int:\n ", "prompt_sft": "给你一个长度为 n 下标从 0 开始的整数数组 maxHeights 。\n\n你的任务是在坐标轴上建 n 座塔。第 i 座塔的下标为 i ,高度为 heights[i] 。\n\n如果以下条件满足,我们称这些塔是 美丽 的:\n\n 1. 1 <= heights[i] <= maxHeights[i]\n 2. heights 是一个 山状 数组。\n\n如果存在下标 i 满足以下条件,那么我们称数组 heights 是一个 山状 数组:\n\n * 对于所有 0 < j <= i ,都有 heights[j - 1] <= heights[j]\n * 对于所有 i <= k < n - 1 ,都有 heights[k + 1] <= heights[k]\n\n请你返回满足 美丽塔 要求的方案中,高度和的最大值 。\n\n示例 1:\n\n输入:maxHeights = [5,3,4,1,1]\n输出:13\n解释:和最大的美丽塔方案为 heights = [5,3,3,1,1] ,这是一个美丽塔方案,因为:\n- 1 <= heights[i] <= maxHeights[i]\n- heights 是个山状数组,峰值在 i = 0 处。\n13 是所有美丽塔方案中的最大高度和。\n\n示例 2:\n\n输入:maxHeights = [6,5,3,9,2,7]\n输出:22\n解释: 和最大的美丽塔方案为 heights = [3,3,3,9,2,2] ,这是一个美丽塔方案,因为:\n- 1 <= heights[i] <= maxHeights[i]\n- heights 是个山状数组,峰值在 i = 3 处。\n22 是所有美丽塔方案中的最大高度和。\n\n示例 3:\n\n输入:maxHeights = [3,2,5,5,2,3]\n输出:18\n解释:和最大的美丽塔方案为 heights = [2,2,5,5,2,2] ,这是一个美丽塔方案,因为:\n- 1 <= heights[i] <= maxHeights[i]\n- heights 是个山状数组,最大值在 i = 2 处。\n注意,在这个方案中,i = 3 也是一个峰值。\n18 是所有美丽塔方案中的最大高度和。\n\n\n提示:\n\n * 1 <= n == maxHeights <= 103\n * 1 <= maxHeights[i] <= 109\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def maximumSumOfHeights(self, maxHeights: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"maxHeights\": [5,3,4,1,1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 13\n\ntest_input = { \"maxHeights\": [6,5,3,9,2,7] }\nassert my_solution.maximumSumOfHeights(**test_input) == 22\n\ntest_input = { \"maxHeights\": [3,2,5,5,2,3] }\nassert my_solution.maximumSumOfHeights(**test_input) == 18\n\ntest_input = { \"maxHeights\": [1000000000] }\nassert my_solution.maximumSumOfHeights(**test_input) == 1000000000\n\ntest_input = { \"maxHeights\": [1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 1\n\ntest_input = { \"maxHeights\": [933754743] }\nassert my_solution.maximumSumOfHeights(**test_input) == 933754743\n\ntest_input = { \"maxHeights\": [1,1000000000] }\nassert my_solution.maximumSumOfHeights(**test_input) == 1000000001\n\ntest_input = { \"maxHeights\": [1000000000,1000000000] }\nassert my_solution.maximumSumOfHeights(**test_input) == 2000000000\n\ntest_input = { \"maxHeights\": [999999999,1000000000] }\nassert my_solution.maximumSumOfHeights(**test_input) == 1999999999\n\ntest_input = { \"maxHeights\": [1000000000,999999999] }\nassert my_solution.maximumSumOfHeights(**test_input) == 1999999999\n\ntest_input = { \"maxHeights\": [30,1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 31\n\ntest_input = { \"maxHeights\": [1,12,19] }\nassert my_solution.maximumSumOfHeights(**test_input) == 32\n\ntest_input = { \"maxHeights\": [1000000000,1000000000,1000000000] }\nassert my_solution.maximumSumOfHeights(**test_input) == 3000000000\n\ntest_input = { \"maxHeights\": [999999999,1000000000,999999999] }\nassert my_solution.maximumSumOfHeights(**test_input) == 2999999998\n\ntest_input = { \"maxHeights\": [1000000000,999999999,999999998] }\nassert my_solution.maximumSumOfHeights(**test_input) == 2999999997\n\ntest_input = { \"maxHeights\": [999999998,999999999,1000000000] }\nassert my_solution.maximumSumOfHeights(**test_input) == 2999999997\n\ntest_input = { \"maxHeights\": [1,1,1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 3\n\ntest_input = { \"maxHeights\": [1,1,4,3,3,3,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 20\n\ntest_input = { \"maxHeights\": [2,4,1,3,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 11\n\ntest_input = { \"maxHeights\": [1,5,2,5,6,4,6,3,4,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 33\n\ntest_input = { \"maxHeights\": [3,6,3,5,5,1,2,5,5,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 24\n\ntest_input = { \"maxHeights\": [1,6,5,6,2,4,1,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 23\n\ntest_input = { \"maxHeights\": [5,1,6,5,4,4,2] }\nassert my_solution.maximumSumOfHeights(**test_input) == 23\n\ntest_input = { \"maxHeights\": [3,4,3,1,1,3] }\nassert my_solution.maximumSumOfHeights(**test_input) == 13\n\ntest_input = { \"maxHeights\": [4,1,6,5,3,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 19\n\ntest_input = { \"maxHeights\": [3,5,5,6,4,6,5,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 35\n\ntest_input = { \"maxHeights\": [6,4,3,3] }\nassert my_solution.maximumSumOfHeights(**test_input) == 16\n\ntest_input = { \"maxHeights\": [6,4,3,6,1,2,2,3] }\nassert my_solution.maximumSumOfHeights(**test_input) == 20\n\ntest_input = { \"maxHeights\": [6,5,1,4,6,1,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 16\n\ntest_input = { \"maxHeights\": [2,3,4,4,3,2,3,5,5,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 30\n\ntest_input = { \"maxHeights\": [5,4,6,1,2] }\nassert my_solution.maximumSumOfHeights(**test_input) == 16\n\ntest_input = { \"maxHeights\": [1,4,2] }\nassert my_solution.maximumSumOfHeights(**test_input) == 7\n\ntest_input = { \"maxHeights\": [5,2,4,4] }\nassert my_solution.maximumSumOfHeights(**test_input) == 12\n\ntest_input = { \"maxHeights\": [1,5,5,3,3] }\nassert my_solution.maximumSumOfHeights(**test_input) == 17\n\ntest_input = { \"maxHeights\": [3,1,1,4,5,5,4,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 25\n\ntest_input = { \"maxHeights\": [1,4,3,4,5,1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 17\n\ntest_input = { \"maxHeights\": [5,5,3,1,1,2,5,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 18\n\ntest_input = { \"maxHeights\": [3,1,3,2,6,1,4,4,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 20\n\ntest_input = { \"maxHeights\": [5,3,3] }\nassert my_solution.maximumSumOfHeights(**test_input) == 11\n\ntest_input = { \"maxHeights\": [5,2,1,4,3,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 14\n\ntest_input = { \"maxHeights\": [1,3,2,1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 7\n\ntest_input = { \"maxHeights\": [1,3,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 10\n\ntest_input = { \"maxHeights\": [5,5,5,3,3,3,3] }\nassert my_solution.maximumSumOfHeights(**test_input) == 27\n\ntest_input = { \"maxHeights\": [1,3,3,2,1,2] }\nassert my_solution.maximumSumOfHeights(**test_input) == 11\n\ntest_input = { \"maxHeights\": [5,5,4,1,4,4,5,6,4] }\nassert my_solution.maximumSumOfHeights(**test_input) == 27\n\ntest_input = { \"maxHeights\": [3,5,5,6,2] }\nassert my_solution.maximumSumOfHeights(**test_input) == 21\n\ntest_input = { \"maxHeights\": [4,6,6,1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 17\n\ntest_input = { \"maxHeights\": [4,2,6,1,4,1,5,3,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 18\n\ntest_input = { \"maxHeights\": [4,1,6,3,6,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 20\n\ntest_input = { \"maxHeights\": [5,2,1,4,1,6,1,5,3,4] }\nassert my_solution.maximumSumOfHeights(**test_input) == 18\n\ntest_input = { \"maxHeights\": [1,4,6,3,5,1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 18\n\ntest_input = { \"maxHeights\": [6,1,2,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 9\n\ntest_input = { \"maxHeights\": [6,1,5,1,6,2,2] }\nassert my_solution.maximumSumOfHeights(**test_input) == 14\n\ntest_input = { \"maxHeights\": [6,1,2,3,4,4] }\nassert my_solution.maximumSumOfHeights(**test_input) == 15\n\ntest_input = { \"maxHeights\": [6,1,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 8\n\ntest_input = { \"maxHeights\": [1,6,6,3,5,6,1,1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 24\n\ntest_input = { \"maxHeights\": [2,6,1,5,1,2,3] }\nassert my_solution.maximumSumOfHeights(**test_input) == 13\n\ntest_input = { \"maxHeights\": [3,5,1,6,3,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 15\n\ntest_input = { \"maxHeights\": [4,4,5,3] }\nassert my_solution.maximumSumOfHeights(**test_input) == 16\n\ntest_input = { \"maxHeights\": [3,5,4,4,3,1,1,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 22\n\ntest_input = { \"maxHeights\": [5,6,4,4,5,1,2,3,5,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 28\n\ntest_input = { \"maxHeights\": [2,5,1,5,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 13\n\ntest_input = { \"maxHeights\": [1,2,6,2,6,5,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 23\n\ntest_input = { \"maxHeights\": [1,1,6,4,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 16\n\ntest_input = { \"maxHeights\": [3,4,1,6,2] }\nassert my_solution.maximumSumOfHeights(**test_input) == 11\n\ntest_input = { \"maxHeights\": [1,3,3,5,6,4,6,5,2,2] }\nassert my_solution.maximumSumOfHeights(**test_input) == 34\n\ntest_input = { \"maxHeights\": [2,4,6,4,6,3,1,5,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 26\n\ntest_input = { \"maxHeights\": [1,6,1,6,4] }\nassert my_solution.maximumSumOfHeights(**test_input) == 13\n\ntest_input = { \"maxHeights\": [4,2,1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 7\n\ntest_input = { \"maxHeights\": [1,2,4,1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 8\n\ntest_input = { \"maxHeights\": [1,3,3,2,5,1,4,3,1,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 17\n\ntest_input = { \"maxHeights\": [4,3,1,4] }\nassert my_solution.maximumSumOfHeights(**test_input) == 9\n\ntest_input = { \"maxHeights\": [5,1,3,4,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 14\n\ntest_input = { \"maxHeights\": [1,5,4,2] }\nassert my_solution.maximumSumOfHeights(**test_input) == 12\n\ntest_input = { \"maxHeights\": [2,6,4,3,2,2,2,5,6,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 30\n\ntest_input = { \"maxHeights\": [2,6,1,2,1,1,2,4] }\nassert my_solution.maximumSumOfHeights(**test_input) == 14\n\ntest_input = { \"maxHeights\": [1,2,5,3,3,3,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 20\n\ntest_input = { \"maxHeights\": [2,5,2,2,1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 12\n\ntest_input = { \"maxHeights\": [3,5,3,4] }\nassert my_solution.maximumSumOfHeights(**test_input) == 14\n\ntest_input = { \"maxHeights\": [4,6,6,3,4,1,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 24\n\ntest_input = { \"maxHeights\": [2,3,5,3,4,1,1,1,3,2] }\nassert my_solution.maximumSumOfHeights(**test_input) == 21\n\ntest_input = { \"maxHeights\": [6,6,5,3,5,4,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 29\n\ntest_input = { \"maxHeights\": [5,5,2,2,4,2,3,2,4,4] }\nassert my_solution.maximumSumOfHeights(**test_input) == 26\n\ntest_input = { \"maxHeights\": [1,2,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 8\n\ntest_input = { \"maxHeights\": [3,6,2,4,5,2,2,5,1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 22\n\ntest_input = { \"maxHeights\": [6,2,6,3,4,6,2] }\nassert my_solution.maximumSumOfHeights(**test_input) == 22\n\ntest_input = { \"maxHeights\": [6,2,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 10\n\ntest_input = { \"maxHeights\": [5,4,2,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 13\n\ntest_input = { \"maxHeights\": [2,6,5,3] }\nassert my_solution.maximumSumOfHeights(**test_input) == 16\n\ntest_input = { \"maxHeights\": [4,5,4,1,6,5,1,3] }\nassert my_solution.maximumSumOfHeights(**test_input) == 18\n\ntest_input = { \"maxHeights\": [4,1,2,4,6,2,6,3] }\nassert my_solution.maximumSumOfHeights(**test_input) == 20\n\ntest_input = { \"maxHeights\": [6,4,4,4,2] }\nassert my_solution.maximumSumOfHeights(**test_input) == 20\n\ntest_input = { \"maxHeights\": [5,5,4,2] }\nassert my_solution.maximumSumOfHeights(**test_input) == 16\n\ntest_input = { \"maxHeights\": [5,3,3,4,2,2,1,4] }\nassert my_solution.maximumSumOfHeights(**test_input) == 20\n\ntest_input = { \"maxHeights\": [6,5,6,6,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 28\n\ntest_input = { \"maxHeights\": [6,3,5,6,2,2,3] }\nassert my_solution.maximumSumOfHeights(**test_input) == 23\n\ntest_input = { \"maxHeights\": [4,6,4,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 18\n\ntest_input = { \"maxHeights\": [3,5,4,2,1,1,5,6,1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 19\n\ntest_input = { \"maxHeights\": [2,3,5,6,2,4] }\nassert my_solution.maximumSumOfHeights(**test_input) == 20\n\ntest_input = { \"maxHeights\": [4,5,2,1,4,6,6,1,6,2] }\nassert my_solution.maximumSumOfHeights(**test_input) == 23", "start_time": 1695522600} +{"task_id": "weekly-contest-364-beautiful-towers-ii", "url": "https://leetcode.com/problems/beautiful-towers-ii", "title": "beautiful-towers-ii", "meta": {"questionId": "3113", "questionFrontendId": "2866", "title": "Beautiful Towers II", "titleSlug": "beautiful-towers-ii", "isPaidOnly": false, "difficulty": "Medium", "likes": 348, "dislikes": 22, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个长度为 n 下标从 0 开始的整数数组 maxHeights 。\n\n你的任务是在坐标轴上建 n 座塔。第 i 座塔的下标为 i ,高度为 heights[i] 。\n\n如果以下条件满足,我们称这些塔是 美丽 的:\n\n 1. 1 <= heights[i] <= maxHeights[i]\n 2. heights 是一个 山状 数组。\n\n如果存在下标 i 满足以下条件,那么我们称数组 heights 是一个 山状 数组:\n\n * 对于所有 0 < j <= i ,都有 heights[j - 1] <= heights[j]\n * 对于所有 i <= k < n - 1 ,都有 heights[k + 1] <= heights[k]\n\n请你返回满足 美丽塔 要求的方案中,高度和的最大值 。\n\n示例 1:\n\n输入:maxHeights = [5,3,4,1,1]\n输出:13\n解释:和最大的美丽塔方案为 heights = [5,3,3,1,1] ,这是一个美丽塔方案,因为:\n- 1 <= heights[i] <= maxHeights[i]\n- heights 是个山状数组,峰值在 i = 0 处。\n13 是所有美丽塔方案中的最大高度和。\n\n示例 2:\n\n输入:maxHeights = [6,5,3,9,2,7]\n输出:22\n解释: 和最大的美丽塔方案为 heights = [3,3,3,9,2,2] ,这是一个美丽塔方案,因为:\n- 1 <= heights[i] <= maxHeights[i]\n- heights 是个山状数组,峰值在 i = 3 处。\n22 是所有美丽塔方案中的最大高度和。\n\n示例 3:\n\n输入:maxHeights = [3,2,5,5,2,3]\n输出:18\n解释:和最大的美丽塔方案为 heights = [2,2,5,5,2,2] ,这是一个美丽塔方案,因为:\n- 1 <= heights[i] <= maxHeights[i]\n- heights 是个山状数组,最大值在 i = 2 处。\n注意,在这个方案中,i = 3 也是一个峰值。\n18 是所有美丽塔方案中的最大高度和。\n\n\n提示:\n\n * 1 <= n == maxHeights <= 105\n * 1 <= maxHeights[i] <= 109\n\"\"\"\nclass Solution:\n def maximumSumOfHeights(self, maxHeights: List[int]) -> int:\n ", "prompt_sft": "给你一个长度为 n 下标从 0 开始的整数数组 maxHeights 。\n\n你的任务是在坐标轴上建 n 座塔。第 i 座塔的下标为 i ,高度为 heights[i] 。\n\n如果以下条件满足,我们称这些塔是 美丽 的:\n\n 1. 1 <= heights[i] <= maxHeights[i]\n 2. heights 是一个 山状 数组。\n\n如果存在下标 i 满足以下条件,那么我们称数组 heights 是一个 山状 数组:\n\n * 对于所有 0 < j <= i ,都有 heights[j - 1] <= heights[j]\n * 对于所有 i <= k < n - 1 ,都有 heights[k + 1] <= heights[k]\n\n请你返回满足 美丽塔 要求的方案中,高度和的最大值 。\n\n示例 1:\n\n输入:maxHeights = [5,3,4,1,1]\n输出:13\n解释:和最大的美丽塔方案为 heights = [5,3,3,1,1] ,这是一个美丽塔方案,因为:\n- 1 <= heights[i] <= maxHeights[i]\n- heights 是个山状数组,峰值在 i = 0 处。\n13 是所有美丽塔方案中的最大高度和。\n\n示例 2:\n\n输入:maxHeights = [6,5,3,9,2,7]\n输出:22\n解释: 和最大的美丽塔方案为 heights = [3,3,3,9,2,2] ,这是一个美丽塔方案,因为:\n- 1 <= heights[i] <= maxHeights[i]\n- heights 是个山状数组,峰值在 i = 3 处。\n22 是所有美丽塔方案中的最大高度和。\n\n示例 3:\n\n输入:maxHeights = [3,2,5,5,2,3]\n输出:18\n解释:和最大的美丽塔方案为 heights = [2,2,5,5,2,2] ,这是一个美丽塔方案,因为:\n- 1 <= heights[i] <= maxHeights[i]\n- heights 是个山状数组,最大值在 i = 2 处。\n注意,在这个方案中,i = 3 也是一个峰值。\n18 是所有美丽塔方案中的最大高度和。\n\n\n提示:\n\n * 1 <= n == maxHeights <= 105\n * 1 <= maxHeights[i] <= 109\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def maximumSumOfHeights(self, maxHeights: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"maxHeights\": [5,3,4,1,1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 13\n\ntest_input = { \"maxHeights\": [6,5,3,9,2,7] }\nassert my_solution.maximumSumOfHeights(**test_input) == 22\n\ntest_input = { \"maxHeights\": [3,2,5,5,2,3] }\nassert my_solution.maximumSumOfHeights(**test_input) == 18\n\ntest_input = { \"maxHeights\": [1000000000] }\nassert my_solution.maximumSumOfHeights(**test_input) == 1000000000\n\ntest_input = { \"maxHeights\": [1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 1\n\ntest_input = { \"maxHeights\": [352939501] }\nassert my_solution.maximumSumOfHeights(**test_input) == 352939501\n\ntest_input = { \"maxHeights\": [1,1000000000] }\nassert my_solution.maximumSumOfHeights(**test_input) == 1000000001\n\ntest_input = { \"maxHeights\": [1000000000,1000000000] }\nassert my_solution.maximumSumOfHeights(**test_input) == 2000000000\n\ntest_input = { \"maxHeights\": [999999999,1000000000] }\nassert my_solution.maximumSumOfHeights(**test_input) == 1999999999\n\ntest_input = { \"maxHeights\": [1000000000,999999999] }\nassert my_solution.maximumSumOfHeights(**test_input) == 1999999999\n\ntest_input = { \"maxHeights\": [2,1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 3\n\ntest_input = { \"maxHeights\": [26,30,30] }\nassert my_solution.maximumSumOfHeights(**test_input) == 86\n\ntest_input = { \"maxHeights\": [1000000000,1000000000,1000000000] }\nassert my_solution.maximumSumOfHeights(**test_input) == 3000000000\n\ntest_input = { \"maxHeights\": [999999999,1000000000,999999999] }\nassert my_solution.maximumSumOfHeights(**test_input) == 2999999998\n\ntest_input = { \"maxHeights\": [1000000000,999999999,999999998] }\nassert my_solution.maximumSumOfHeights(**test_input) == 2999999997\n\ntest_input = { \"maxHeights\": [999999998,999999999,1000000000] }\nassert my_solution.maximumSumOfHeights(**test_input) == 2999999997\n\ntest_input = { \"maxHeights\": [1,1,1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 3\n\ntest_input = { \"maxHeights\": [1,1,5,6,2,2,3] }\nassert my_solution.maximumSumOfHeights(**test_input) == 19\n\ntest_input = { \"maxHeights\": [3,5,3,5,1,5,4,4,4] }\nassert my_solution.maximumSumOfHeights(**test_input) == 22\n\ntest_input = { \"maxHeights\": [4,2,4,2,1,5,4,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 19\n\ntest_input = { \"maxHeights\": [5,3,2,4,6,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 21\n\ntest_input = { \"maxHeights\": [6,5,2,1,5,4,4,2] }\nassert my_solution.maximumSumOfHeights(**test_input) == 19\n\ntest_input = { \"maxHeights\": [4,3,2,4,6,3] }\nassert my_solution.maximumSumOfHeights(**test_input) == 19\n\ntest_input = { \"maxHeights\": [2,6,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 13\n\ntest_input = { \"maxHeights\": [6,5,3,4,6,1,2,3,2,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 25\n\ntest_input = { \"maxHeights\": [2,1,6,2,3] }\nassert my_solution.maximumSumOfHeights(**test_input) == 12\n\ntest_input = { \"maxHeights\": [6,5,1,5,4,3,4,2,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 22\n\ntest_input = { \"maxHeights\": [1,1,6,4,2,2,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 18\n\ntest_input = { \"maxHeights\": [2,2,2,5,6,1,4,3] }\nassert my_solution.maximumSumOfHeights(**test_input) == 20\n\ntest_input = { \"maxHeights\": [3,1,5,3,6,5,1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 20\n\ntest_input = { \"maxHeights\": [1,4,6,1,4,6,1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 15\n\ntest_input = { \"maxHeights\": [4,4,2,3,3,2,2] }\nassert my_solution.maximumSumOfHeights(**test_input) == 18\n\ntest_input = { \"maxHeights\": [4,4,1,6,2,1,2] }\nassert my_solution.maximumSumOfHeights(**test_input) == 13\n\ntest_input = { \"maxHeights\": [6,3,3,5,4,1,5,2,4,1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 23\n\ntest_input = { \"maxHeights\": [3,2,4] }\nassert my_solution.maximumSumOfHeights(**test_input) == 8\n\ntest_input = { \"maxHeights\": [3,1,4,3,2,3] }\nassert my_solution.maximumSumOfHeights(**test_input) == 13\n\ntest_input = { \"maxHeights\": [3,1,4,5,4,4,6,4] }\nassert my_solution.maximumSumOfHeights(**test_input) == 28\n\ntest_input = { \"maxHeights\": [1,2,5,5,5,6,5,6,3] }\nassert my_solution.maximumSumOfHeights(**test_input) == 37\n\ntest_input = { \"maxHeights\": [6,1,1,6,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 14\n\ntest_input = { \"maxHeights\": [1,6,6,6,2,6,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 25\n\ntest_input = { \"maxHeights\": [4,1,4,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 11\n\ntest_input = { \"maxHeights\": [1,5,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 12\n\ntest_input = { \"maxHeights\": [1,4,4,5,6,6,2,4,1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 31\n\ntest_input = { \"maxHeights\": [2,6,6,4,6,1,6,2,1,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 27\n\ntest_input = { \"maxHeights\": [2,4,6,4,4] }\nassert my_solution.maximumSumOfHeights(**test_input) == 20\n\ntest_input = { \"maxHeights\": [5,2,6,1,6,6,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 21\n\ntest_input = { \"maxHeights\": [3,6,1,4,5,5,2,5,1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 22\n\ntest_input = { \"maxHeights\": [3,2,6,5,6,6,2,1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 29\n\ntest_input = { \"maxHeights\": [1,4,2,1,6,3,2,1,2,2] }\nassert my_solution.maximumSumOfHeights(**test_input) == 18\n\ntest_input = { \"maxHeights\": [3,3,4,3,5,6,1,3] }\nassert my_solution.maximumSumOfHeights(**test_input) == 25\n\ntest_input = { \"maxHeights\": [4,4,2,4,1,4,5,5,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 25\n\ntest_input = { \"maxHeights\": [6,5,3] }\nassert my_solution.maximumSumOfHeights(**test_input) == 14\n\ntest_input = { \"maxHeights\": [2,2,4] }\nassert my_solution.maximumSumOfHeights(**test_input) == 8\n\ntest_input = { \"maxHeights\": [6,2,6,5,3,6,2,5,1,2] }\nassert my_solution.maximumSumOfHeights(**test_input) == 27\n\ntest_input = { \"maxHeights\": [4,6,3,4,6,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 25\n\ntest_input = { \"maxHeights\": [6,4,6,3] }\nassert my_solution.maximumSumOfHeights(**test_input) == 17\n\ntest_input = { \"maxHeights\": [4,3,5,1,4] }\nassert my_solution.maximumSumOfHeights(**test_input) == 13\n\ntest_input = { \"maxHeights\": [3,5,6,6,3,6,1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 27\n\ntest_input = { \"maxHeights\": [6,1,6,5,5,1,1,2] }\nassert my_solution.maximumSumOfHeights(**test_input) == 21\n\ntest_input = { \"maxHeights\": [4,3,3,1,5,3,3,6,3,3] }\nassert my_solution.maximumSumOfHeights(**test_input) == 25\n\ntest_input = { \"maxHeights\": [1,4,6,1,6,4] }\nassert my_solution.maximumSumOfHeights(**test_input) == 14\n\ntest_input = { \"maxHeights\": [6,2,1,4,2] }\nassert my_solution.maximumSumOfHeights(**test_input) == 11\n\ntest_input = { \"maxHeights\": [1,4,6,4,2,6,6,5,5,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 36\n\ntest_input = { \"maxHeights\": [6,1,2,1,3,3,1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 12\n\ntest_input = { \"maxHeights\": [6,4,3,3,6,1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 20\n\ntest_input = { \"maxHeights\": [3,1,4,4] }\nassert my_solution.maximumSumOfHeights(**test_input) == 10\n\ntest_input = { \"maxHeights\": [2,4,1,6,5,3,2] }\nassert my_solution.maximumSumOfHeights(**test_input) == 19\n\ntest_input = { \"maxHeights\": [2,5,5,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 18\n\ntest_input = { \"maxHeights\": [5,2,1,4] }\nassert my_solution.maximumSumOfHeights(**test_input) == 9\n\ntest_input = { \"maxHeights\": [5,5,3,3,3,3,1,3,2] }\nassert my_solution.maximumSumOfHeights(**test_input) == 25\n\ntest_input = { \"maxHeights\": [5,6,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 16\n\ntest_input = { \"maxHeights\": [1,1,6,2,3,1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 13\n\ntest_input = { \"maxHeights\": [2,4,2,2,2,6,1,4,4] }\nassert my_solution.maximumSumOfHeights(**test_input) == 19\n\ntest_input = { \"maxHeights\": [6,2,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 10\n\ntest_input = { \"maxHeights\": [5,6,1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 12\n\ntest_input = { \"maxHeights\": [6,6,4,3,6,3,6,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 31\n\ntest_input = { \"maxHeights\": [3,2,4,2,3,2,3,6,1,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 23\n\ntest_input = { \"maxHeights\": [6,3,3,3,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 18\n\ntest_input = { \"maxHeights\": [5,5,2,1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 13\n\ntest_input = { \"maxHeights\": [3,5,4,5,5,4] }\nassert my_solution.maximumSumOfHeights(**test_input) == 25\n\ntest_input = { \"maxHeights\": [3,4,6,3,1,5,5,2] }\nassert my_solution.maximumSumOfHeights(**test_input) == 20\n\ntest_input = { \"maxHeights\": [4,3,6,6,5,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 28\n\ntest_input = { \"maxHeights\": [3,5,5,2,2,3,4,1,1,4] }\nassert my_solution.maximumSumOfHeights(**test_input) == 24\n\ntest_input = { \"maxHeights\": [5,6,1,2,5,1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 15\n\ntest_input = { \"maxHeights\": [6,3,3,6,4,4,2,1,6,4] }\nassert my_solution.maximumSumOfHeights(**test_input) == 28\n\ntest_input = { \"maxHeights\": [1,5,3,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 13\n\ntest_input = { \"maxHeights\": [5,2,3,5,3,2,5,5,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 28\n\ntest_input = { \"maxHeights\": [5,4,2,6,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 18\n\ntest_input = { \"maxHeights\": [5,5,4,4,1,4,3,1,4,2] }\nassert my_solution.maximumSumOfHeights(**test_input) == 24\n\ntest_input = { \"maxHeights\": [4,4,4,6,4] }\nassert my_solution.maximumSumOfHeights(**test_input) == 22\n\ntest_input = { \"maxHeights\": [3,3,3,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 14\n\ntest_input = { \"maxHeights\": [2,2,2] }\nassert my_solution.maximumSumOfHeights(**test_input) == 6\n\ntest_input = { \"maxHeights\": [4,4,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 13\n\ntest_input = { \"maxHeights\": [1,1,6,5,4,6,6,2,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 30\n\ntest_input = { \"maxHeights\": [6,6,3,3,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 21\n\ntest_input = { \"maxHeights\": [1,3,2,5,2,1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 13\n\ntest_input = { \"maxHeights\": [1,5,3,3,1,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 14\n\ntest_input = { \"maxHeights\": [4,2,4,3] }\nassert my_solution.maximumSumOfHeights(**test_input) == 11\n\ntest_input = { \"maxHeights\": [6,4,5,1,2,3,1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 18\n\ntest_input = { \"maxHeights\": [4,4,1,6,1,4] }\nassert my_solution.maximumSumOfHeights(**test_input) == 12", "start_time": 1695522600} +{"task_id": "weekly-contest-364-count-valid-paths-in-a-tree", "url": "https://leetcode.com/problems/count-valid-paths-in-a-tree", "title": "count-valid-paths-in-a-tree", "meta": {"questionId": "3112", "questionFrontendId": "2867", "title": "Count Valid Paths in a Tree", "titleSlug": "count-valid-paths-in-a-tree", "isPaidOnly": false, "difficulty": "Hard", "likes": 212, "dislikes": 5, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一棵 n 个节点的无向树,节点编号为 1 到 n 。给你一个整数 n 和一个长度为 n - 1 的二维整数数组 edges ,其中 edges[i] = [ui, vi] 表示节点 ui 和 vi 在树中有一条边。\n\n请你返回树中的 合法路径数目 。\n\n如果在节点 a 到节点 b 之间 恰好有一个 节点的编号是质数,那么我们称路径 (a, b) 是 合法的 。\n\n注意:\n\n * 路径 (a, b) 指的是一条从节点 a 开始到节点 b 结束的一个节点序列,序列中的节点 互不相同 ,且相邻节点之间在树上有一条边。\n * 路径 (a, b) 和路径 (b, a) 视为 同一条 路径,且只计入答案 一次 。\n\n示例 1:\n\n[https://assets.leetcode.com/uploads/2023/08/27/example1.png]\n\n输入:n = 5, edges = [[1,2],[1,3],[2,4],[2,5]]\n输出:4\n解释:恰好有一个质数编号的节点路径有:\n- (1, 2) 因为路径 1 到 2 只包含一个质数 2 。\n- (1, 3) 因为路径 1 到 3 只包含一个质数 3 。\n- (1, 4) 因为路径 1 到 4 只包含一个质数 2 。\n- (2, 4) 因为路径 2 到 4 只包含一个质数 2 。\n只有 4 条合法路径。\n\n示例 2:\n\n[https://assets.leetcode.com/uploads/2023/08/27/example2.png]\n\n输入:n = 6, edges = [[1,2],[1,3],[2,4],[3,5],[3,6]]\n输出:6\n解释:恰好有一个质数编号的节点路径有:\n- (1, 2) 因为路径 1 到 2 只包含一个质数 2 。\n- (1, 3) 因为路径 1 到 3 只包含一个质数 3 。\n- (1, 4) 因为路径 1 到 4 只包含一个质数 2 。\n- (1, 6) 因为路径 1 到 6 只包含一个质数 3 。\n- (2, 4) 因为路径 2 到 4 只包含一个质数 2 。\n- (3, 6) 因为路径 3 到 6 只包含一个质数 3 。\n只有 6 条合法路径。\n\n\n提示:\n\n * 1 <= n <= 105\n * edges.length == n - 1\n * edges[i].length == 2\n * 1 <= ui, vi <= n\n * 输入保证 edges 形成一棵合法的树。\n\"\"\"\nclass Solution:\n def countPaths(self, n: int, edges: List[List[int]]) -> int:\n ", "prompt_sft": "给你一棵 n 个节点的无向树,节点编号为 1 到 n 。给你一个整数 n 和一个长度为 n - 1 的二维整数数组 edges ,其中 edges[i] = [ui, vi] 表示节点 ui 和 vi 在树中有一条边。\n\n请你返回树中的 合法路径数目 。\n\n如果在节点 a 到节点 b 之间 恰好有一个 节点的编号是质数,那么我们称路径 (a, b) 是 合法的 。\n\n注意:\n\n * 路径 (a, b) 指的是一条从节点 a 开始到节点 b 结束的一个节点序列,序列中的节点 互不相同 ,且相邻节点之间在树上有一条边。\n * 路径 (a, b) 和路径 (b, a) 视为 同一条 路径,且只计入答案 一次 。\n\n示例 1:\n\n[https://assets.leetcode.com/uploads/2023/08/27/example1.png]\n\n输入:n = 5, edges = [[1,2],[1,3],[2,4],[2,5]]\n输出:4\n解释:恰好有一个质数编号的节点路径有:\n- (1, 2) 因为路径 1 到 2 只包含一个质数 2 。\n- (1, 3) 因为路径 1 到 3 只包含一个质数 3 。\n- (1, 4) 因为路径 1 到 4 只包含一个质数 2 。\n- (2, 4) 因为路径 2 到 4 只包含一个质数 2 。\n只有 4 条合法路径。\n\n示例 2:\n\n[https://assets.leetcode.com/uploads/2023/08/27/example2.png]\n\n输入:n = 6, edges = [[1,2],[1,3],[2,4],[3,5],[3,6]]\n输出:6\n解释:恰好有一个质数编号的节点路径有:\n- (1, 2) 因为路径 1 到 2 只包含一个质数 2 。\n- (1, 3) 因为路径 1 到 3 只包含一个质数 3 。\n- (1, 4) 因为路径 1 到 4 只包含一个质数 2 。\n- (1, 6) 因为路径 1 到 6 只包含一个质数 3 。\n- (2, 4) 因为路径 2 到 4 只包含一个质数 2 。\n- (3, 6) 因为路径 3 到 6 只包含一个质数 3 。\n只有 6 条合法路径。\n\n\n提示:\n\n * 1 <= n <= 105\n * edges.length == n - 1\n * edges[i].length == 2\n * 1 <= ui, vi <= n\n * 输入保证 edges 形成一棵合法的树。\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def countPaths(self, n: int, edges: List[List[int]]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"n\": 5, \"edges\": [[1,2],[1,3],[2,4],[2,5]] }\nassert my_solution.countPaths(**test_input) == 4\n\ntest_input = { \"n\": 6, \"edges\": [[1,2],[1,3],[2,4],[3,5],[3,6]] }\nassert my_solution.countPaths(**test_input) == 6\n\ntest_input = { \"n\": 1, \"edges\": [] }\nassert my_solution.countPaths(**test_input) == 0\n\ntest_input = { \"n\": 2, \"edges\": [[2,1]] }\nassert my_solution.countPaths(**test_input) == 1\n\ntest_input = { \"n\": 4, \"edges\": [[1,2],[4,1],[3,4]] }\nassert my_solution.countPaths(**test_input) == 4\n\ntest_input = { \"n\": 5, \"edges\": [[1,3],[4,3],[2,3],[5,2]] }\nassert my_solution.countPaths(**test_input) == 3\n\ntest_input = { \"n\": 5, \"edges\": [[1,5],[2,1],[4,5],[3,2]] }\nassert my_solution.countPaths(**test_input) == 4\n\ntest_input = { \"n\": 5, \"edges\": [[2,3],[4,2],[1,3],[5,1]] }\nassert my_solution.countPaths(**test_input) == 3\n\ntest_input = { \"n\": 5, \"edges\": [[4,1],[5,4],[2,1],[3,4]] }\nassert my_solution.countPaths(**test_input) == 6\n\ntest_input = { \"n\": 5, \"edges\": [[3,5],[1,5],[4,3],[2,5]] }\nassert my_solution.countPaths(**test_input) == 2\n\ntest_input = { \"n\": 4, \"edges\": [[2,1],[4,2],[3,2]] }\nassert my_solution.countPaths(**test_input) == 3\n\ntest_input = { \"n\": 5, \"edges\": [[1,4],[2,4],[3,2],[5,4]] }\nassert my_solution.countPaths(**test_input) == 4\n\ntest_input = { \"n\": 5, \"edges\": [[5,4],[3,4],[1,4],[2,4]] }\nassert my_solution.countPaths(**test_input) == 6\n\ntest_input = { \"n\": 4, \"edges\": [[3,4],[1,3],[2,4]] }\nassert my_solution.countPaths(**test_input) == 4\n\ntest_input = { \"n\": 10, \"edges\": [[10,9],[2,10],[1,10],[3,2],[6,10],[4,3],[8,6],[5,8],[7,6]] }\nassert my_solution.countPaths(**test_input) == 16\n\ntest_input = { \"n\": 8, \"edges\": [[7,2],[6,2],[5,2],[1,2],[4,7],[8,1],[3,6]] }\nassert my_solution.countPaths(**test_input) == 7\n\ntest_input = { \"n\": 5, \"edges\": [[3,2],[4,3],[5,4],[1,4]] }\nassert my_solution.countPaths(**test_input) == 4\n\ntest_input = { \"n\": 9, \"edges\": [[7,4],[3,4],[5,4],[1,5],[6,4],[9,5],[8,7],[2,8]] }\nassert my_solution.countPaths(**test_input) == 17\n\ntest_input = { \"n\": 9, \"edges\": [[1,8],[5,8],[4,8],[6,5],[3,1],[9,1],[7,4],[2,8]] }\nassert my_solution.countPaths(**test_input) == 21\n\ntest_input = { \"n\": 10, \"edges\": [[2,9],[7,2],[10,9],[5,7],[4,5],[6,7],[8,2],[1,5],[3,10]] }\nassert my_solution.countPaths(**test_input) == 11\n\ntest_input = { \"n\": 8, \"edges\": [[6,1],[8,1],[3,6],[4,1],[7,3],[2,8],[5,1]] }\nassert my_solution.countPaths(**test_input) == 12\n\ntest_input = { \"n\": 10, \"edges\": [[9,1],[8,9],[5,9],[10,8],[7,5],[2,8],[3,8],[6,7],[4,1]] }\nassert my_solution.countPaths(**test_input) == 16\n\ntest_input = { \"n\": 5, \"edges\": [[5,3],[4,5],[2,5],[1,4]] }\nassert my_solution.countPaths(**test_input) == 2\n\ntest_input = { \"n\": 7, \"edges\": [[7,6],[2,6],[5,2],[3,5],[4,5],[1,6]] }\nassert my_solution.countPaths(**test_input) == 5\n\ntest_input = { \"n\": 8, \"edges\": [[4,5],[8,4],[6,4],[2,5],[1,6],[3,1],[7,8]] }\nassert my_solution.countPaths(**test_input) == 12\n\ntest_input = { \"n\": 10, \"edges\": [[9,6],[5,6],[10,6],[8,5],[4,8],[3,9],[1,3],[2,6],[7,1]] }\nassert my_solution.countPaths(**test_input) == 22\n\ntest_input = { \"n\": 5, \"edges\": [[1,4],[2,4],[5,4],[3,4]] }\nassert my_solution.countPaths(**test_input) == 6\n\ntest_input = { \"n\": 10, \"edges\": [[9,4],[7,9],[10,9],[6,7],[8,7],[2,7],[3,2],[1,9],[5,10]] }\nassert my_solution.countPaths(**test_input) == 19\n\ntest_input = { \"n\": 7, \"edges\": [[4,7],[6,7],[1,7],[3,7],[2,6],[5,6]] }\nassert my_solution.countPaths(**test_input) == 8\n\ntest_input = { \"n\": 5, \"edges\": [[1,4],[2,1],[5,2],[3,1]] }\nassert my_solution.countPaths(**test_input) == 4\n\ntest_input = { \"n\": 5, \"edges\": [[4,5],[2,5],[1,4],[3,1]] }\nassert my_solution.countPaths(**test_input) == 4\n\ntest_input = { \"n\": 10, \"edges\": [[4,3],[5,3],[1,4],[7,5],[6,3],[8,3],[9,1],[10,8],[2,10]] }\nassert my_solution.countPaths(**test_input) == 19\n\ntest_input = { \"n\": 5, \"edges\": [[1,3],[4,1],[2,1],[5,1]] }\nassert my_solution.countPaths(**test_input) == 6\n\ntest_input = { \"n\": 7, \"edges\": [[5,2],[3,5],[4,5],[1,2],[6,2],[7,2]] }\nassert my_solution.countPaths(**test_input) == 4\n\ntest_input = { \"n\": 5, \"edges\": [[3,4],[1,4],[5,3],[2,5]] }\nassert my_solution.countPaths(**test_input) == 2\n\ntest_input = { \"n\": 8, \"edges\": [[1,8],[2,1],[6,8],[3,6],[4,3],[5,8],[7,2]] }\nassert my_solution.countPaths(**test_input) == 13\n\ntest_input = { \"n\": 9, \"edges\": [[2,1],[6,1],[8,2],[9,8],[4,9],[7,9],[3,1],[5,2]] }\nassert my_solution.countPaths(**test_input) == 16\n\ntest_input = { \"n\": 5, \"edges\": [[4,3],[5,4],[1,5],[2,3]] }\nassert my_solution.countPaths(**test_input) == 4\n\ntest_input = { \"n\": 8, \"edges\": [[2,4],[3,4],[6,4],[7,3],[8,7],[5,6],[1,5]] }\nassert my_solution.countPaths(**test_input) == 10\n\ntest_input = { \"n\": 6, \"edges\": [[3,6],[1,3],[2,3],[5,2],[4,5]] }\nassert my_solution.countPaths(**test_input) == 4\n\ntest_input = { \"n\": 10, \"edges\": [[7,5],[4,7],[10,5],[6,5],[8,6],[2,8],[9,4],[3,10],[1,9]] }\nassert my_solution.countPaths(**test_input) == 11\n\ntest_input = { \"n\": 8, \"edges\": [[3,2],[8,3],[7,3],[6,2],[4,7],[5,6],[1,8]] }\nassert my_solution.countPaths(**test_input) == 5\n\ntest_input = { \"n\": 8, \"edges\": [[2,6],[3,6],[5,2],[1,6],[7,2],[8,1],[4,1]] }\nassert my_solution.countPaths(**test_input) == 8\n\ntest_input = { \"n\": 9, \"edges\": [[3,7],[6,7],[4,7],[1,6],[8,4],[9,1],[2,7],[5,2]] }\nassert my_solution.countPaths(**test_input) == 11\n\ntest_input = { \"n\": 6, \"edges\": [[6,2],[5,6],[1,2],[3,2],[4,3]] }\nassert my_solution.countPaths(**test_input) == 5\n\ntest_input = { \"n\": 6, \"edges\": [[6,2],[1,6],[3,1],[5,3],[4,3]] }\nassert my_solution.countPaths(**test_input) == 7\n\ntest_input = { \"n\": 8, \"edges\": [[2,3],[8,3],[5,3],[6,3],[4,3],[7,8],[1,2]] }\nassert my_solution.countPaths(**test_input) == 8\n\ntest_input = { \"n\": 7, \"edges\": [[4,6],[5,6],[7,6],[3,4],[2,6],[1,5]] }\nassert my_solution.countPaths(**test_input) == 11\n\ntest_input = { \"n\": 6, \"edges\": [[4,2],[5,4],[1,5],[6,1],[3,1]] }\nassert my_solution.countPaths(**test_input) == 8\n\ntest_input = { \"n\": 6, \"edges\": [[4,1],[6,1],[5,4],[3,5],[2,1]] }\nassert my_solution.countPaths(**test_input) == 6\n\ntest_input = { \"n\": 7, \"edges\": [[6,7],[1,6],[4,6],[2,7],[3,2],[5,7]] }\nassert my_solution.countPaths(**test_input) == 3\n\ntest_input = { \"n\": 6, \"edges\": [[4,3],[5,3],[6,5],[2,4],[1,5]] }\nassert my_solution.countPaths(**test_input) == 5\n\ntest_input = { \"n\": 10, \"edges\": [[2,5],[3,5],[10,2],[8,3],[7,5],[4,3],[1,8],[9,5],[6,8]] }\nassert my_solution.countPaths(**test_input) == 9\n\ntest_input = { \"n\": 8, \"edges\": [[2,8],[1,8],[5,2],[4,5],[6,5],[7,2],[3,5]] }\nassert my_solution.countPaths(**test_input) == 5\n\ntest_input = { \"n\": 8, \"edges\": [[7,2],[6,7],[5,7],[8,6],[1,7],[3,5],[4,2]] }\nassert my_solution.countPaths(**test_input) == 6\n\ntest_input = { \"n\": 7, \"edges\": [[5,7],[3,5],[2,7],[4,3],[6,3],[1,4]] }\nassert my_solution.countPaths(**test_input) == 5\n\ntest_input = { \"n\": 7, \"edges\": [[2,3],[1,3],[7,3],[4,1],[6,3],[5,1]] }\nassert my_solution.countPaths(**test_input) == 7\n\ntest_input = { \"n\": 7, \"edges\": [[4,2],[6,4],[1,6],[7,6],[5,2],[3,7]] }\nassert my_solution.countPaths(**test_input) == 6\n\ntest_input = { \"n\": 6, \"edges\": [[3,4],[6,3],[1,4],[5,4],[2,6]] }\nassert my_solution.countPaths(**test_input) == 8\n\ntest_input = { \"n\": 10, \"edges\": [[2,7],[1,2],[8,7],[4,2],[6,8],[10,7],[5,4],[9,8],[3,6]] }\nassert my_solution.countPaths(**test_input) == 14\n\ntest_input = { \"n\": 8, \"edges\": [[6,2],[7,2],[5,6],[8,2],[3,6],[1,8],[4,2]] }\nassert my_solution.countPaths(**test_input) == 11\n\ntest_input = { \"n\": 10, \"edges\": [[9,6],[1,9],[2,1],[8,1],[10,6],[7,6],[3,8],[4,3],[5,3]] }\nassert my_solution.countPaths(**test_input) == 21\n\ntest_input = { \"n\": 8, \"edges\": [[4,6],[1,6],[7,6],[2,1],[8,7],[5,6],[3,5]] }\nassert my_solution.countPaths(**test_input) == 13\n\ntest_input = { \"n\": 7, \"edges\": [[3,7],[6,7],[4,6],[1,3],[5,3],[2,3]] }\nassert my_solution.countPaths(**test_input) == 3\n\ntest_input = { \"n\": 10, \"edges\": [[2,9],[3,9],[8,9],[10,3],[1,9],[4,8],[7,10],[6,1],[5,10]] }\nassert my_solution.countPaths(**test_input) == 18\n\ntest_input = { \"n\": 8, \"edges\": [[5,6],[3,6],[7,5],[4,6],[8,6],[2,3],[1,3]] }\nassert my_solution.countPaths(**test_input) == 10\n\ntest_input = { \"n\": 9, \"edges\": [[9,3],[4,3],[2,9],[7,3],[8,7],[1,7],[5,4],[6,2]] }\nassert my_solution.countPaths(**test_input) == 10\n\ntest_input = { \"n\": 6, \"edges\": [[5,1],[2,1],[4,2],[6,5],[3,4]] }\nassert my_solution.countPaths(**test_input) == 7\n\ntest_input = { \"n\": 7, \"edges\": [[3,6],[2,6],[5,6],[7,2],[1,6],[4,2]] }\nassert my_solution.countPaths(**test_input) == 9\n\ntest_input = { \"n\": 5, \"edges\": [[1,5],[3,5],[4,3],[2,5]] }\nassert my_solution.countPaths(**test_input) == 2\n\ntest_input = { \"n\": 8, \"edges\": [[2,8],[6,2],[1,2],[4,1],[7,2],[3,2],[5,7]] }\nassert my_solution.countPaths(**test_input) == 9\n\ntest_input = { \"n\": 9, \"edges\": [[5,3],[1,3],[7,3],[4,5],[6,7],[8,7],[9,5],[2,5]] }\nassert my_solution.countPaths(**test_input) == 7\n\ntest_input = { \"n\": 10, \"edges\": [[8,10],[3,10],[1,8],[7,8],[6,10],[2,3],[5,8],[9,5],[4,6]] }\nassert my_solution.countPaths(**test_input) == 21\n\ntest_input = { \"n\": 10, \"edges\": [[4,8],[6,8],[9,4],[1,6],[5,8],[2,8],[10,9],[7,6],[3,5]] }\nassert my_solution.countPaths(**test_input) == 18\n\ntest_input = { \"n\": 9, \"edges\": [[4,6],[9,4],[3,6],[7,6],[1,4],[5,9],[2,7],[8,4]] }\nassert my_solution.countPaths(**test_input) == 15\n\ntest_input = { \"n\": 7, \"edges\": [[7,6],[2,6],[1,7],[3,2],[5,2],[4,5]] }\nassert my_solution.countPaths(**test_input) == 5\n\ntest_input = { \"n\": 9, \"edges\": [[1,8],[5,8],[3,8],[2,1],[9,2],[7,1],[6,5],[4,9]] }\nassert my_solution.countPaths(**test_input) == 17\n\ntest_input = { \"n\": 7, \"edges\": [[3,5],[4,3],[6,5],[2,4],[7,3],[1,4]] }\nassert my_solution.countPaths(**test_input) == 5\n\ntest_input = { \"n\": 10, \"edges\": [[5,2],[8,5],[10,5],[3,8],[4,2],[1,4],[9,10],[7,5],[6,8]] }\nassert my_solution.countPaths(**test_input) == 12\n\ntest_input = { \"n\": 8, \"edges\": [[7,4],[1,4],[5,7],[6,1],[8,5],[3,8],[2,6]] }\nassert my_solution.countPaths(**test_input) == 8\n\ntest_input = { \"n\": 10, \"edges\": [[8,2],[7,8],[9,2],[4,2],[6,4],[3,9],[5,4],[1,9],[10,8]] }\nassert my_solution.countPaths(**test_input) == 24\n\ntest_input = { \"n\": 8, \"edges\": [[3,8],[2,8],[1,8],[6,8],[4,3],[7,6],[5,2]] }\nassert my_solution.countPaths(**test_input) == 13\n\ntest_input = { \"n\": 9, \"edges\": [[5,4],[2,4],[9,5],[3,2],[7,3],[1,4],[8,2],[6,4]] }\nassert my_solution.countPaths(**test_input) == 14\n\ntest_input = { \"n\": 10, \"edges\": [[10,8],[5,10],[1,10],[3,10],[7,3],[2,10],[6,8],[9,6],[4,6]] }\nassert my_solution.countPaths(**test_input) == 18\n\ntest_input = { \"n\": 9, \"edges\": [[6,7],[5,7],[8,7],[9,6],[2,5],[4,5],[1,8],[3,6]] }\nassert my_solution.countPaths(**test_input) == 11\n\ntest_input = { \"n\": 10, \"edges\": [[1,6],[9,1],[5,9],[10,6],[4,9],[8,9],[7,8],[2,1],[3,1]] }\nassert my_solution.countPaths(**test_input) == 24\n\ntest_input = { \"n\": 8, \"edges\": [[4,5],[3,4],[6,5],[1,4],[2,3],[8,4],[7,3]] }\nassert my_solution.countPaths(**test_input) == 10\n\ntest_input = { \"n\": 7, \"edges\": [[7,4],[6,4],[2,6],[5,6],[3,2],[1,5]] }\nassert my_solution.countPaths(**test_input) == 9\n\ntest_input = { \"n\": 10, \"edges\": [[3,2],[5,3],[1,2],[9,5],[7,5],[6,3],[4,3],[8,6],[10,1]] }\nassert my_solution.countPaths(**test_input) == 8\n\ntest_input = { \"n\": 8, \"edges\": [[2,8],[5,2],[4,2],[7,4],[3,2],[1,3],[6,3]] }\nassert my_solution.countPaths(**test_input) == 7\n\ntest_input = { \"n\": 6, \"edges\": [[6,3],[2,3],[4,2],[5,2],[1,6]] }\nassert my_solution.countPaths(**test_input) == 3\n\ntest_input = { \"n\": 9, \"edges\": [[7,3],[5,3],[4,3],[9,7],[6,5],[8,3],[2,4],[1,5]] }\nassert my_solution.countPaths(**test_input) == 8\n\ntest_input = { \"n\": 5, \"edges\": [[1,2],[5,1],[4,5],[3,4]] }\nassert my_solution.countPaths(**test_input) == 5\n\ntest_input = { \"n\": 9, \"edges\": [[8,3],[6,8],[2,8],[4,3],[5,4],[7,5],[9,4],[1,5]] }\nassert my_solution.countPaths(**test_input) == 15\n\ntest_input = { \"n\": 5, \"edges\": [[2,1],[4,2],[5,1],[3,2]] }\nassert my_solution.countPaths(**test_input) == 4\n\ntest_input = { \"n\": 6, \"edges\": [[4,2],[6,2],[3,2],[1,6],[5,2]] }\nassert my_solution.countPaths(**test_input) == 5\n\ntest_input = { \"n\": 10, \"edges\": [[10,5],[3,10],[4,3],[8,3],[7,4],[1,7],[6,5],[9,1],[2,5]] }\nassert my_solution.countPaths(**test_input) == 14\n\ntest_input = { \"n\": 9, \"edges\": [[4,7],[6,4],[8,4],[2,8],[5,2],[9,7],[1,6],[3,7]] }\nassert my_solution.countPaths(**test_input) == 13\n\ntest_input = { \"n\": 10, \"edges\": [[7,3],[1,3],[2,3],[10,2],[4,2],[8,1],[9,4],[5,3],[6,3]] }\nassert my_solution.countPaths(**test_input) == 10\n\ntest_input = { \"n\": 7, \"edges\": [[4,7],[2,7],[3,4],[1,7],[6,4],[5,4]] }\nassert my_solution.countPaths(**test_input) == 9", "start_time": 1695522600} +{"task_id": "weekly-contest-363-sum-of-values-at-indices-with-k-set-bits", "url": "https://leetcode.com/problems/sum-of-values-at-indices-with-k-set-bits", "title": "sum-of-values-at-indices-with-k-set-bits", "meta": {"questionId": "3093", "questionFrontendId": "2859", "title": "Sum of Values at Indices With K Set Bits", "titleSlug": "sum-of-values-at-indices-with-k-set-bits", "isPaidOnly": false, "difficulty": "Easy", "likes": 154, "dislikes": 16, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0 开始的整数数组 nums 和一个整数 k 。\n\n请你用整数形式返回 nums 中的特定元素之 和 ,这些特定元素满足:其对应下标的二进制表示中恰存在 k 个置位。\n\n整数的二进制表示中的 1 就是这个整数的 置位 。\n\n例如,21 的二进制表示为 10101 ,其中有 3 个置位。\n\n示例 1:\n\n输入:nums = [5,10,1,5,2], k = 1\n输出:13\n解释:下标的二进制表示是:\n0 = 0002\n1 = 0012\n2 = 0102\n3 = 0112\n4 = 1002\n下标 1、2 和 4 在其二进制表示中都存在 k = 1 个置位。\n因此,答案为 nums[1] + nums[2] + nums[4] = 13 。\n\n示例 2:\n\n输入:nums = [4,3,2,1], k = 2\n输出:1\n解释:下标的二进制表示是:\n0 = 002\n1 = 012\n2 = 102\n3 = 112\n只有下标 3 的二进制表示中存在 k = 2 个置位。\n因此,答案为 nums[3] = 1 。\n\n\n提示:\n\n * 1 <= nums.length <= 1000\n * 1 <= nums[i] <= 105\n * 0 <= k <= 10\n\"\"\"\nclass Solution:\n def sumIndicesWithKSetBits(self, nums: List[int], k: int) -> int:\n ", "prompt_sft": "给你一个下标从 0 开始的整数数组 nums 和一个整数 k 。\n\n请你用整数形式返回 nums 中的特定元素之 和 ,这些特定元素满足:其对应下标的二进制表示中恰存在 k 个置位。\n\n整数的二进制表示中的 1 就是这个整数的 置位 。\n\n例如,21 的二进制表示为 10101 ,其中有 3 个置位。\n\n示例 1:\n\n输入:nums = [5,10,1,5,2], k = 1\n输出:13\n解释:下标的二进制表示是:\n0 = 0002\n1 = 0012\n2 = 0102\n3 = 0112\n4 = 1002\n下标 1、2 和 4 在其二进制表示中都存在 k = 1 个置位。\n因此,答案为 nums[1] + nums[2] + nums[4] = 13 。\n\n示例 2:\n\n输入:nums = [4,3,2,1], k = 2\n输出:1\n解释:下标的二进制表示是:\n0 = 002\n1 = 012\n2 = 102\n3 = 112\n只有下标 3 的二进制表示中存在 k = 2 个置位。\n因此,答案为 nums[3] = 1 。\n\n\n提示:\n\n * 1 <= nums.length <= 1000\n * 1 <= nums[i] <= 105\n * 0 <= k <= 10\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def sumIndicesWithKSetBits(self, nums: List[int], k: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [5,10,1,5,2], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 13\n\ntest_input = { \"nums\": [4,3,2,1], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 1\n\ntest_input = { \"nums\": [1], \"k\": 0 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 1\n\ntest_input = { \"nums\": [100000], \"k\": 0 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 100000\n\ntest_input = { \"nums\": [2,2], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 2\n\ntest_input = { \"nums\": [2,4], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 4\n\ntest_input = { \"nums\": [2,7], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 7\n\ntest_input = { \"nums\": [3,3], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 3\n\ntest_input = { \"nums\": [3,9], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 9\n\ntest_input = { \"nums\": [4,7], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 7\n\ntest_input = { \"nums\": [4,8], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 8\n\ntest_input = { \"nums\": [6,6], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 6\n\ntest_input = { \"nums\": [7,2], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 2\n\ntest_input = { \"nums\": [7,4], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 4\n\ntest_input = { \"nums\": [8,4], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 4\n\ntest_input = { \"nums\": [8,9], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 9\n\ntest_input = { \"nums\": [9,9], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 9\n\ntest_input = { \"nums\": [15,43], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 43\n\ntest_input = { \"nums\": [35,86], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 86\n\ntest_input = { \"nums\": [36,14], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 14\n\ntest_input = { \"nums\": [47,61], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 61\n\ntest_input = { \"nums\": [60,46], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 46\n\ntest_input = { \"nums\": [70,7], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 7\n\ntest_input = { \"nums\": [1,51,55], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 106\n\ntest_input = { \"nums\": [2,2,5], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 7\n\ntest_input = { \"nums\": [2,3,2], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 5\n\ntest_input = { \"nums\": [3,2,5], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 7\n\ntest_input = { \"nums\": [3,7,5], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 12\n\ntest_input = { \"nums\": [4,5,9], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 14\n\ntest_input = { \"nums\": [5,5,5], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 10\n\ntest_input = { \"nums\": [5,7,7], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 14\n\ntest_input = { \"nums\": [6,2,1], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 3\n\ntest_input = { \"nums\": [6,9,8], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 17\n\ntest_input = { \"nums\": [7,1,2], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 3\n\ntest_input = { \"nums\": [7,9,1], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 10\n\ntest_input = { \"nums\": [8,5,4], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 9\n\ntest_input = { \"nums\": [9,1,6], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 7\n\ntest_input = { \"nums\": [9,3,5], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 8\n\ntest_input = { \"nums\": [57,48,69], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 117\n\ntest_input = { \"nums\": [78,37,59], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 96\n\ntest_input = { \"nums\": [96,71,53], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 124\n\ntest_input = { \"nums\": [900,914,367], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 1281\n\ntest_input = { \"nums\": [1,4,9,2], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 2\n\ntest_input = { \"nums\": [1,5,9,5], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 5\n\ntest_input = { \"nums\": [1,8,5,6], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 13\n\ntest_input = { \"nums\": [2,2,1,2], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 3\n\ntest_input = { \"nums\": [2,4,5,2], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 2\n\ntest_input = { \"nums\": [2,5,8,1], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 13\n\ntest_input = { \"nums\": [2,7,3,9], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 10\n\ntest_input = { \"nums\": [3,5,4,2], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 2\n\ntest_input = { \"nums\": [4,1,6,3], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 3\n\ntest_input = { \"nums\": [6,3,8,8], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 8\n\ntest_input = { \"nums\": [6,6,1,4], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 4\n\ntest_input = { \"nums\": [7,1,9,6], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 6\n\ntest_input = { \"nums\": [7,5,2,1], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 7\n\ntest_input = { \"nums\": [7,5,3,4], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 8\n\ntest_input = { \"nums\": [7,8,6,2], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 14\n\ntest_input = { \"nums\": [8,3,9,8], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 8\n\ntest_input = { \"nums\": [8,7,3,2], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 2\n\ntest_input = { \"nums\": [9,4,2,2], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 6\n\ntest_input = { \"nums\": [9,6,8,8], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 14\n\ntest_input = { \"nums\": [9,7,8,9], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 9\n\ntest_input = { \"nums\": [9,40,73,19], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 19\n\ntest_input = { \"nums\": [41,51,58,2], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 109\n\ntest_input = { \"nums\": [44,96,36,56], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 56\n\ntest_input = { \"nums\": [1,1,3,1,6], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 1\n\ntest_input = { \"nums\": [2,1,1,3,5], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 7\n\ntest_input = { \"nums\": [2,5,4,3,1], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 3\n\ntest_input = { \"nums\": [3,2,7,1,5], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 14\n\ntest_input = { \"nums\": [4,2,8,8,2], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 8\n\ntest_input = { \"nums\": [4,3,7,8,8], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 8\n\ntest_input = { \"nums\": [4,6,2,2,7], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 15\n\ntest_input = { \"nums\": [4,7,5,1,1], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 1\n\ntest_input = { \"nums\": [5,6,6,6,3], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 15\n\ntest_input = { \"nums\": [6,4,8,4,2], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 4\n\ntest_input = { \"nums\": [7,7,9,5,8], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 24\n\ntest_input = { \"nums\": [7,9,1,3,2], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 3\n\ntest_input = { \"nums\": [8,5,6,9,7], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 9\n\ntest_input = { \"nums\": [8,6,9,4,4], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 4\n\ntest_input = { \"nums\": [8,8,2,9,2], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 12\n\ntest_input = { \"nums\": [9,3,7,9,6], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 16\n\ntest_input = { \"nums\": [9,5,5,5,5], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 15\n\ntest_input = { \"nums\": [27,73,37,82,78], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 188\n\ntest_input = { \"nums\": [36,28,94,49,79], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 49\n\ntest_input = { \"nums\": [48,54,75,72,77], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 206\n\ntest_input = { \"nums\": [574,419,838,216,442], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 1699\n\ntest_input = { \"nums\": [1,1,1,2,5,7], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 9\n\ntest_input = { \"nums\": [2,6,6,8,6,4], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 12\n\ntest_input = { \"nums\": [2,8,2,9,2,8], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 17\n\ntest_input = { \"nums\": [2,9,1,6,5,7], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 13\n\ntest_input = { \"nums\": [2,9,1,6,6,7], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 13\n\ntest_input = { \"nums\": [3,5,4,5,8,9], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 17\n\ntest_input = { \"nums\": [5,5,3,7,9,7], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 17\n\ntest_input = { \"nums\": [5,9,4,8,7,2], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 10\n\ntest_input = { \"nums\": [5,9,6,6,4,5], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 11\n\ntest_input = { \"nums\": [6,4,7,8,4,7], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 15\n\ntest_input = { \"nums\": [6,8,6,2,7,3], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 5\n\ntest_input = { \"nums\": [7,2,5,4,4,4], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 11\n\ntest_input = { \"nums\": [7,2,9,7,8,7], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 14\n\ntest_input = { \"nums\": [7,6,6,7,6,1], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 8", "start_time": 1694917800} +{"task_id": "weekly-contest-363-happy-students", "url": "https://leetcode.com/problems/happy-students", "title": "happy-students", "meta": {"questionId": "3104", "questionFrontendId": "2860", "title": "Happy Students", "titleSlug": "happy-students", "isPaidOnly": false, "difficulty": "Medium", "likes": 144, "dislikes": 272, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0 开始、长度为 n 的整数数组 nums ,其中 n 是班级中学生的总数。班主任希望能够在让所有学生保持开心的情况下选出一组学生:\n\n如果能够满足下述两个条件之一,则认为第 i 位学生将会保持开心:\n\n * 这位学生被选中,并且被选中的学生人数 严格大于 nums[i] 。\n * 这位学生没有被选中,并且被选中的学生人数 严格小于 nums[i] 。\n\n返回能够满足让所有学生保持开心的分组方法的数目。\n\n示例 1:\n\n输入:nums = [1,1]\n输出:2\n解释:\n有两种可行的方法:\n班主任没有选中学生。\n班主任选中所有学生形成一组。\n如果班主任仅选中一个学生来完成分组,那么两个学生都无法保持开心。因此,仅存在两种可行的方法。\n\n示例 2:\n\n输入:nums = [6,0,3,3,6,7,2,7]\n输出:3\n解释:\n存在三种可行的方法:\n班主任选中下标为 1 的学生形成一组。\n班主任选中下标为 1、2、3、6 的学生形成一组。\n班主任选中所有学生形成一组。\n\n\n提示:\n\n * 1 <= nums.length <= 105\n * 0 <= nums[i] < nums.length\n\"\"\"\nclass Solution:\n def countWays(self, nums: List[int]) -> int:\n ", "prompt_sft": "给你一个下标从 0 开始、长度为 n 的整数数组 nums ,其中 n 是班级中学生的总数。班主任希望能够在让所有学生保持开心的情况下选出一组学生:\n\n如果能够满足下述两个条件之一,则认为第 i 位学生将会保持开心:\n\n * 这位学生被选中,并且被选中的学生人数 严格大于 nums[i] 。\n * 这位学生没有被选中,并且被选中的学生人数 严格小于 nums[i] 。\n\n返回能够满足让所有学生保持开心的分组方法的数目。\n\n示例 1:\n\n输入:nums = [1,1]\n输出:2\n解释:\n有两种可行的方法:\n班主任没有选中学生。\n班主任选中所有学生形成一组。\n如果班主任仅选中一个学生来完成分组,那么两个学生都无法保持开心。因此,仅存在两种可行的方法。\n\n示例 2:\n\n输入:nums = [6,0,3,3,6,7,2,7]\n输出:3\n解释:\n存在三种可行的方法:\n班主任选中下标为 1 的学生形成一组。\n班主任选中下标为 1、2、3、6 的学生形成一组。\n班主任选中所有学生形成一组。\n\n\n提示:\n\n * 1 <= nums.length <= 105\n * 0 <= nums[i] < nums.length\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def countWays(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,1] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [6,0,3,3,6,7,2,7] }\nassert my_solution.countWays(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,0,1] }\nassert my_solution.countWays(**test_input) == 1\n\ntest_input = { \"nums\": [5,0,3,4,2,1,2,4] }\nassert my_solution.countWays(**test_input) == 1\n\ntest_input = { \"nums\": [0,4,4,4,4,4,2] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [0,1,5,6,8,7,4,7,2] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [0] }\nassert my_solution.countWays(**test_input) == 1\n\ntest_input = { \"nums\": [2,2,7,1,2,2,4,7] }\nassert my_solution.countWays(**test_input) == 3\n\ntest_input = { \"nums\": [0,2,2,2,3,3,3,3] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [7,7,7,7,7,7,7,7,2] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [4,2,3,6,6,0,6,8,3] }\nassert my_solution.countWays(**test_input) == 3\n\ntest_input = { \"nums\": [0,0,1,7,2,0,6,5] }\nassert my_solution.countWays(**test_input) == 1\n\ntest_input = { \"nums\": [6,6,6,6,6,6,6,7,1,7] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [2,2,4,5,0,1,4,4,7] }\nassert my_solution.countWays(**test_input) == 1\n\ntest_input = { \"nums\": [4,4,4,4,4] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [0,4,0,3,4] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [6,5,5,8,4,2,6,4,8] }\nassert my_solution.countWays(**test_input) == 3\n\ntest_input = { \"nums\": [0,9,4,6,8,8,1,7,4,7] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [1,0,0] }\nassert my_solution.countWays(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,2,2,2,3,3,3,3] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [4,5,0,4,2,0,2] }\nassert my_solution.countWays(**test_input) == 1\n\ntest_input = { \"nums\": [8,1,2,1,2,1,2,4,0] }\nassert my_solution.countWays(**test_input) == 1\n\ntest_input = { \"nums\": [0,1] }\nassert my_solution.countWays(**test_input) == 1\n\ntest_input = { \"nums\": [8,4,1,8,8,7,4,5,3] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,0,2,5,5,4] }\nassert my_solution.countWays(**test_input) == 1\n\ntest_input = { \"nums\": [6,3,1,5,5,4,5] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [0,1,1,5,5,5,5,5,5] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [2,3,5,3,0,3] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [2,2,2,0,2] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,1] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [7,7,7,7,7,7,7,7,4,5] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [2,2,2,2,4] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [3,3,3,3] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [1,0] }\nassert my_solution.countWays(**test_input) == 1\n\ntest_input = { \"nums\": [6,6,6,6,6,6,6,0,4,9] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [4,4,4,4,4,5] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [2,3,2,1] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [3,3,3,3,2,2,2,2,1] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [1,5,3,0,3,6,2] }\nassert my_solution.countWays(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,1,1,1] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [0,0] }\nassert my_solution.countWays(**test_input) == 1\n\ntest_input = { \"nums\": [4,4,4,4,4,0,1] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [4,3,1,5,1,4,2,1,6] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [6,4,0,7,5,7,5,6,0] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [5,5,5,5,5,5] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [0,3,4,3,4,1] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,1,3] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [0,1,0] }\nassert my_solution.countWays(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,0] }\nassert my_solution.countWays(**test_input) == 1\n\ntest_input = { \"nums\": [1,7,6,4,1,2,1,6,4] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [2,2,2,4,4,4,4,4] }\nassert my_solution.countWays(**test_input) == 3\n\ntest_input = { \"nums\": [1,3,5,2,4,6,7,5,6] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,1,1,2,2,2,3] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [3,5,3,2,0,3,3,7] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [6,6,6,6,6,6,6] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [7,9,0,3,6,9,4,0,8,7] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [0,0,0] }\nassert my_solution.countWays(**test_input) == 1\n\ntest_input = { \"nums\": [2,2,2,2,1,3,3,6] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [2,2,2,2,2,2,6] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [5,3,9,2,4,2,1,2,8,6] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [2,2,2,0,0,6,6,2,5,4] }\nassert my_solution.countWays(**test_input) == 1\n\ntest_input = { \"nums\": [2,0,1] }\nassert my_solution.countWays(**test_input) == 1\n\ntest_input = { \"nums\": [2,2,0] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [2,2,2,2,1,0] }\nassert my_solution.countWays(**test_input) == 1\n\ntest_input = { \"nums\": [2,2,2,2,4,5,0] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [0,1,2] }\nassert my_solution.countWays(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,3,3,3,3,7,8,2] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [1,2,0,4,4] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,0,0] }\nassert my_solution.countWays(**test_input) == 1\n\ntest_input = { \"nums\": [1,7,8,7,1,0,7,3,8] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [2,2,2,1] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [1,8,6,3,3,4,3,2,3] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [8,1,6,4,1,2,2,3,3] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [2,2,2,1,1,5] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [1,3,3,3,2] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [1,3,2,3] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,2] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [0,3,6,3,0,2,3] }\nassert my_solution.countWays(**test_input) == 1\n\ntest_input = { \"nums\": [7,7,7,7,7,7,7,7,2,0] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [5,4,4,4,4,7,1,4] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [3,3,3,3,0] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [7,7,4,0,2,1,5,2] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [0,2,2] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [7,7,7,7,7,7,7,7] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [2,2,0,3] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [3,3,3,3,0,5] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [4,4,4,2,5,0] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,3,2] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [0,3,0,2,4] }\nassert my_solution.countWays(**test_input) == 1\n\ntest_input = { \"nums\": [0,3,3,3,3,1,1] }\nassert my_solution.countWays(**test_input) == 1\n\ntest_input = { \"nums\": [0,4,1,2,0,6,6] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [4,4,4,4,4,5,3,6,5,5] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [2,0,1,0] }\nassert my_solution.countWays(**test_input) == 1\n\ntest_input = { \"nums\": [0,5,5,5,5,5,5] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [0,5,4,4,3,5] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [6,6,6,6,6,6,6,2,7] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [1,5,3,7,2,3,1,2,8] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [3,3,3,3,2] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [3,3,3,3,0,2] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [2,3,9,0,1,3,9,2,6,1] }\nassert my_solution.countWays(**test_input) == 2", "start_time": 1694917800} +{"task_id": "weekly-contest-363-maximum-number-of-alloys", "url": "https://leetcode.com/problems/maximum-number-of-alloys", "title": "maximum-number-of-alloys", "meta": {"questionId": "3095", "questionFrontendId": "2861", "title": "Maximum Number of Alloys", "titleSlug": "maximum-number-of-alloys", "isPaidOnly": false, "difficulty": "Medium", "likes": 227, "dislikes": 36, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n假设你是一家合金制造公司的老板,你的公司使用多种金属来制造合金。现在共有 n 种不同类型的金属可以使用,并且你可以使用 k 台机器来制造合金。每台机器都需要特定数量的每种金属来创建合金。\n\n对于第 i 台机器而言,创建合金需要 composition[i][j] 份 j 类型金属。最初,你拥有 stock[i] 份 i 类型金属,而每购入一份 i 类型金属需要花费 cost[i] 的金钱。\n\n给你整数 n、k、budget,下标从 1 开始的二维数组 composition,两个下标从 1 开始的数组 stock 和 cost,请你在预算不超过 budget 金钱的前提下,最大化 公司制造合金的数量。\n\n所有合金都需要由同一台机器制造。\n\n返回公司可以制造的最大合金数。\n\n示例 1:\n\n输入:n = 3, k = 2, budget = 15, composition = [[1,1,1],[1,1,10]], stock = [0,0,0], cost = [1,2,3]\n输出:2\n解释:最优的方法是使用第 1 台机器来制造合金。\n要想制造 2 份合金,我们需要购买:\n- 2 份第 1 类金属。\n- 2 份第 2 类金属。\n- 2 份第 3 类金属。\n总共需要 2 * 1 + 2 * 2 + 2 * 3 = 12 的金钱,小于等于预算 15 。\n注意,我们最开始时候没有任何一类金属,所以必须买齐所有需要的金属。\n可以证明在示例条件下最多可以制造 2 份合金。\n\n示例 2:\n\n输入:n = 3, k = 2, budget = 15, composition = [[1,1,1],[1,1,10]], stock = [0,0,100], cost = [1,2,3]\n输出:5\n解释:最优的方法是使用第 2 台机器来制造合金。\n要想制造 5 份合金,我们需要购买:\n- 5 份第 1 类金属。\n- 5 份第 2 类金属。\n- 0 份第 3 类金属。\n总共需要 5 * 1 + 5 * 2 + 0 * 3 = 15 的金钱,小于等于预算 15 。\n可以证明在示例条件下最多可以制造 5 份合金。\n\n示例 3:\n\n输入:n = 2, k = 3, budget = 10, composition = [[2,1],[1,2],[1,1]], stock = [1,1], cost = [5,5]\n输出:2\n解释:最优的方法是使用第 3 台机器来制造合金。\n要想制造 2 份合金,我们需要购买:\n- 1 份第 1 类金属。\n- 1 份第 2 类金属。\n总共需要 1 * 5 + 1 * 5 = 10 的金钱,小于等于预算 10 。\n可以证明在示例条件下最多可以制造 2 份合金。\n\n\n提示:\n\n * 1 <= n, k <= 100\n * 0 <= budget <= 108\n * composition.length == k\n * composition[i].length == n\n * 1 <= composition[i][j] <= 100\n * stock.length == cost.length == n\n * 0 <= stock[i] <= 108\n * 1 <= cost[i] <= 100\n\"\"\"\nclass Solution:\n def maxNumberOfAlloys(self, n: int, k: int, budget: int, composition: List[List[int]], stock: List[int], cost: List[int]) -> int:\n ", "prompt_sft": "假设你是一家合金制造公司的老板,你的公司使用多种金属来制造合金。现在共有 n 种不同类型的金属可以使用,并且你可以使用 k 台机器来制造合金。每台机器都需要特定数量的每种金属来创建合金。\n\n对于第 i 台机器而言,创建合金需要 composition[i][j] 份 j 类型金属。最初,你拥有 stock[i] 份 i 类型金属,而每购入一份 i 类型金属需要花费 cost[i] 的金钱。\n\n给你整数 n、k、budget,下标从 1 开始的二维数组 composition,两个下标从 1 开始的数组 stock 和 cost,请你在预算不超过 budget 金钱的前提下,最大化 公司制造合金的数量。\n\n所有合金都需要由同一台机器制造。\n\n返回公司可以制造的最大合金数。\n\n示例 1:\n\n输入:n = 3, k = 2, budget = 15, composition = [[1,1,1],[1,1,10]], stock = [0,0,0], cost = [1,2,3]\n输出:2\n解释:最优的方法是使用第 1 台机器来制造合金。\n要想制造 2 份合金,我们需要购买:\n- 2 份第 1 类金属。\n- 2 份第 2 类金属。\n- 2 份第 3 类金属。\n总共需要 2 * 1 + 2 * 2 + 2 * 3 = 12 的金钱,小于等于预算 15 。\n注意,我们最开始时候没有任何一类金属,所以必须买齐所有需要的金属。\n可以证明在示例条件下最多可以制造 2 份合金。\n\n示例 2:\n\n输入:n = 3, k = 2, budget = 15, composition = [[1,1,1],[1,1,10]], stock = [0,0,100], cost = [1,2,3]\n输出:5\n解释:最优的方法是使用第 2 台机器来制造合金。\n要想制造 5 份合金,我们需要购买:\n- 5 份第 1 类金属。\n- 5 份第 2 类金属。\n- 0 份第 3 类金属。\n总共需要 5 * 1 + 5 * 2 + 0 * 3 = 15 的金钱,小于等于预算 15 。\n可以证明在示例条件下最多可以制造 5 份合金。\n\n示例 3:\n\n输入:n = 2, k = 3, budget = 10, composition = [[2,1],[1,2],[1,1]], stock = [1,1], cost = [5,5]\n输出:2\n解释:最优的方法是使用第 3 台机器来制造合金。\n要想制造 2 份合金,我们需要购买:\n- 1 份第 1 类金属。\n- 1 份第 2 类金属。\n总共需要 1 * 5 + 1 * 5 = 10 的金钱,小于等于预算 10 。\n可以证明在示例条件下最多可以制造 2 份合金。\n\n\n提示:\n\n * 1 <= n, k <= 100\n * 0 <= budget <= 108\n * composition.length == k\n * composition[i].length == n\n * 1 <= composition[i][j] <= 100\n * stock.length == cost.length == n\n * 0 <= stock[i] <= 108\n * 1 <= cost[i] <= 100\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def maxNumberOfAlloys(self, n: int, k: int, budget: int, composition: List[List[int]], stock: List[int], cost: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"n\": 3, \"k\": 2, \"budget\": 15, \"composition\": [[1,1,1],[1,1,10]], \"stock\": [0,0,0], \"cost\": [1,2,3] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 2\n\ntest_input = { \"n\": 3, \"k\": 2, \"budget\": 15, \"composition\": [[1,1,1],[1,1,10]], \"stock\": [0,0,100], \"cost\": [1,2,3] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 5\n\ntest_input = { \"n\": 2, \"k\": 3, \"budget\": 10, \"composition\": [[2,1],[1,2],[1,1]], \"stock\": [1,1], \"cost\": [5,5] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 2\n\ntest_input = { \"n\": 4, \"k\": 4, \"budget\": 17, \"composition\": [[10,10,1,5],[9,7,7,1],[6,3,5,9],[2,10,2,7]], \"stock\": [9,8,2,7], \"cost\": [9,2,6,10] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 4, \"k\": 9, \"budget\": 55, \"composition\": [[8,3,4,2],[3,9,5,5],[1,7,9,8],[7,6,5,1],[4,6,9,4],[6,8,7,1],[5,10,3,4],[10,1,2,4],[10,3,7,2]], \"stock\": [9,1,10,0], \"cost\": [3,4,9,9] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 10, \"k\": 10, \"budget\": 142, \"composition\": [[5,3,7,3,5,5,1,6,4,3],[4,8,10,8,8,3,10,6,3,8],[10,2,5,10,9,2,8,5,10,7],[10,8,8,8,10,8,9,6,1,8],[6,2,2,3,6,3,1,10,5,8],[10,7,3,10,7,6,6,10,4,5],[10,2,8,10,1,8,7,6,6,7],[4,1,9,6,8,8,7,1,1,4],[10,9,1,2,6,4,6,8,9,4],[5,6,7,2,7,10,7,8,3,5]], \"stock\": [0,6,3,0,0,8,1,2,8,6], \"cost\": [2,2,2,7,4,2,10,8,9,8] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 9, \"k\": 3, \"budget\": 90, \"composition\": [[10,9,1,3,3,5,5,10,7],[2,6,4,9,9,1,9,6,7],[1,4,7,6,7,7,10,6,6]], \"stock\": [3,10,10,8,10,5,7,1,2], \"cost\": [9,8,10,9,9,3,9,5,8] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 8, \"k\": 4, \"budget\": 196, \"composition\": [[5,2,3,4,7,3,3,1],[1,5,9,9,6,1,9,7],[5,8,3,10,2,4,8,7],[9,9,5,9,6,8,4,3]], \"stock\": [3,5,3,6,1,5,8,1], \"cost\": [4,5,4,9,4,8,7,5] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 2\n\ntest_input = { \"n\": 2, \"k\": 5, \"budget\": 48, \"composition\": [[6,3],[9,5],[1,9],[1,8],[3,3]], \"stock\": [4,8], \"cost\": [10,1] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 5\n\ntest_input = { \"n\": 3, \"k\": 8, \"budget\": 50, \"composition\": [[10,8,5],[9,8,8],[2,3,1],[6,2,7],[5,5,3],[3,5,6],[8,2,9],[10,2,1]], \"stock\": [3,9,5], \"cost\": [1,10,6] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 4\n\ntest_input = { \"n\": 6, \"k\": 1, \"budget\": 195, \"composition\": [[4,7,7,9,6,9]], \"stock\": [7,4,1,4,4,0], \"cost\": [6,6,9,10,7,9] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 0\n\ntest_input = { \"n\": 10, \"k\": 4, \"budget\": 149, \"composition\": [[9,10,1,7,6,4,9,5,7,8],[9,7,2,10,7,9,10,10,1,8],[1,10,9,3,5,6,6,1,8,4],[9,6,2,3,9,10,6,8,7,3]], \"stock\": [5,0,7,5,7,8,2,2,6,10], \"cost\": [7,5,3,3,10,9,9,3,6,8] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 5, \"k\": 3, \"budget\": 110, \"composition\": [[5,8,9,3,10],[10,10,2,1,9],[7,8,2,3,4]], \"stock\": [7,3,4,8,4], \"cost\": [2,2,6,5,7] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 2\n\ntest_input = { \"n\": 2, \"k\": 3, \"budget\": 12, \"composition\": [[5,9],[7,8],[1,1]], \"stock\": [0,9], \"cost\": [8,5] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 9, \"k\": 5, \"budget\": 172, \"composition\": [[8,8,7,6,5,3,6,10,8],[9,5,4,5,9,9,2,8,5],[1,9,7,8,4,10,5,1,2],[10,10,4,4,5,5,5,5,9],[7,10,4,7,9,6,3,1,8]], \"stock\": [5,0,10,0,0,8,10,9,8], \"cost\": [3,7,6,10,10,5,2,10,6] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 0\n\ntest_input = { \"n\": 7, \"k\": 10, \"budget\": 31, \"composition\": [[10,6,2,1,6,3,9],[9,7,1,4,3,3,6],[4,8,3,10,7,2,10],[8,1,3,3,9,3,6],[6,3,2,4,9,7,5],[4,2,10,2,9,8,2],[9,3,6,1,3,8,1],[9,5,6,9,4,10,3],[1,8,8,2,5,4,10],[1,6,6,6,10,6,4]], \"stock\": [3,9,10,4,4,8,9], \"cost\": [6,6,9,2,1,9,6] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 4, \"k\": 9, \"budget\": 103, \"composition\": [[5,9,6,3],[1,5,7,5],[5,4,10,6],[2,2,4,6],[1,1,2,2],[10,6,5,4],[9,7,8,9],[3,7,8,2],[8,2,4,4]], \"stock\": [7,7,7,3], \"cost\": [4,7,6,10] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 5\n\ntest_input = { \"n\": 10, \"k\": 1, \"budget\": 197, \"composition\": [[7,6,6,1,2,4,8,6,4,10]], \"stock\": [1,3,2,1,3,4,2,6,1,1], \"cost\": [10,6,2,1,6,2,6,5,9,8] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 0\n\ntest_input = { \"n\": 10, \"k\": 4, \"budget\": 152, \"composition\": [[1,7,1,3,9,6,8,9,10,4],[8,8,9,3,10,10,4,3,2,2],[3,6,4,6,1,9,4,1,4,5],[2,5,1,8,3,10,6,3,8,4]], \"stock\": [7,2,9,6,9,4,6,6,3,6], \"cost\": [8,2,3,9,1,10,1,9,5,4] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 6, \"k\": 9, \"budget\": 72, \"composition\": [[1,10,8,5,4,3],[6,7,3,6,10,3],[10,9,8,6,2,10],[8,9,10,7,9,10],[2,7,2,7,6,9],[4,2,8,2,7,9],[2,1,1,8,8,9],[5,7,1,7,3,5],[4,4,4,3,10,4]], \"stock\": [3,3,1,6,10,8], \"cost\": [1,8,9,8,3,3] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 10, \"budget\": 177, \"composition\": [[6],[3],[8],[8],[7],[7],[4],[5],[10],[1]], \"stock\": [2], \"cost\": [7] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 27\n\ntest_input = { \"n\": 2, \"k\": 6, \"budget\": 196, \"composition\": [[6,5],[7,10],[3,10],[5,8],[5,7],[5,6]], \"stock\": [6,3], \"cost\": [3,4] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 5\n\ntest_input = { \"n\": 7, \"k\": 9, \"budget\": 148, \"composition\": [[5,8,7,7,5,8,4],[8,6,2,6,3,3,2],[5,6,9,6,6,2,5],[8,2,10,5,4,5,10],[2,8,10,4,9,6,1],[4,1,2,2,5,5,5],[9,9,1,4,1,4,4],[3,8,4,4,10,4,6],[8,2,8,4,5,5,10]], \"stock\": [7,8,7,9,3,8,2], \"cost\": [7,5,4,5,1,3,10] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 2\n\ntest_input = { \"n\": 8, \"k\": 5, \"budget\": 151, \"composition\": [[5,9,10,2,8,10,2,8],[1,5,8,9,3,4,6,6],[10,10,10,6,1,7,9,4],[6,7,6,2,10,8,6,10],[5,2,6,2,8,1,6,2]], \"stock\": [0,6,2,2,9,8,0,3], \"cost\": [6,7,4,6,10,3,5,1] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 8, \"k\": 3, \"budget\": 187, \"composition\": [[1,4,8,6,8,5,1,4],[10,9,4,3,1,2,5,9],[4,10,7,8,7,7,1,9]], \"stock\": [2,6,4,0,2,8,2,3], \"cost\": [9,2,5,7,6,10,2,7] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 3, \"budget\": 90, \"composition\": [[5],[3],[9]], \"stock\": [5], \"cost\": [10] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 4\n\ntest_input = { \"n\": 10, \"k\": 5, \"budget\": 91, \"composition\": [[7,8,3,2,9,3,4,4,2,3],[3,2,4,1,4,5,10,9,10,7],[1,4,3,4,9,5,2,2,9,9],[6,9,9,6,2,7,1,10,5,3],[10,7,8,2,2,2,9,6,1,4]], \"stock\": [9,5,5,0,0,8,1,4,5,3], \"cost\": [7,3,6,4,10,10,5,4,2,1] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 0\n\ntest_input = { \"n\": 8, \"k\": 3, \"budget\": 97, \"composition\": [[3,3,7,1,5,5,8,2],[10,5,1,3,1,5,1,5],[7,2,2,10,7,10,6,8]], \"stock\": [1,1,8,3,0,1,0,6], \"cost\": [4,1,4,5,5,3,5,4] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 9, \"k\": 3, \"budget\": 19, \"composition\": [[5,9,4,6,6,1,4,5,3],[6,9,2,3,5,4,1,4,5],[6,10,5,4,7,5,3,4,3]], \"stock\": [8,7,6,3,4,7,7,0,4], \"cost\": [10,8,1,6,9,7,3,7,3] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 0\n\ntest_input = { \"n\": 8, \"k\": 2, \"budget\": 168, \"composition\": [[5,7,8,6,7,4,10,8],[3,7,7,4,8,9,9,9]], \"stock\": [6,4,5,10,2,5,3,8], \"cost\": [5,1,10,3,4,4,7,4] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 3, \"k\": 3, \"budget\": 108, \"composition\": [[6,1,10],[5,3,6],[2,8,7]], \"stock\": [3,9,7], \"cost\": [4,2,3] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 3\n\ntest_input = { \"n\": 10, \"k\": 5, \"budget\": 197, \"composition\": [[7,2,9,6,2,3,8,9,10,10],[2,1,7,7,3,1,3,8,1,2],[4,5,1,3,6,3,2,4,4,6],[8,5,9,10,8,3,7,10,1,7],[8,3,2,4,1,5,3,6,9,6]], \"stock\": [5,2,9,8,1,3,6,4,2,3], \"cost\": [6,6,10,4,9,5,2,6,4,6] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 2\n\ntest_input = { \"n\": 8, \"k\": 8, \"budget\": 90, \"composition\": [[6,6,9,7,6,7,7,5],[5,10,4,2,8,5,6,6],[7,7,1,10,3,3,2,2],[7,9,8,10,7,10,8,2],[7,1,2,2,1,2,3,6],[2,8,10,10,6,2,6,3],[3,2,2,2,4,7,4,3],[2,5,3,2,3,7,6,4]], \"stock\": [1,1,6,10,3,0,8,6], \"cost\": [3,2,1,3,2,3,8,7] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 2\n\ntest_input = { \"n\": 4, \"k\": 7, \"budget\": 87, \"composition\": [[8,8,5,3],[7,8,8,9],[1,7,3,10],[4,3,9,8],[4,7,2,2],[5,8,2,2],[6,1,2,7]], \"stock\": [3,7,9,8], \"cost\": [6,3,1,4] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 2\n\ntest_input = { \"n\": 2, \"k\": 3, \"budget\": 184, \"composition\": [[7,1],[6,7],[4,6]], \"stock\": [1,6], \"cost\": [8,2] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 4\n\ntest_input = { \"n\": 4, \"k\": 3, \"budget\": 25, \"composition\": [[7,4,5,3],[10,8,1,2],[6,4,3,4]], \"stock\": [1,3,0,5], \"cost\": [1,2,6,4] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 10, \"k\": 8, \"budget\": 33, \"composition\": [[3,2,9,8,3,7,10,2,6,7],[6,6,5,6,3,3,4,6,5,7],[6,8,5,10,8,4,1,8,4,2],[7,10,7,10,4,4,10,7,5,3],[2,6,3,3,8,8,2,6,4,2],[2,2,2,4,8,2,7,3,7,4],[10,9,7,9,9,2,3,9,2,1],[8,9,10,7,10,9,7,2,3,8]], \"stock\": [0,2,5,5,8,2,5,9,1,1], \"cost\": [3,4,10,5,8,8,8,9,8,7] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 0\n\ntest_input = { \"n\": 7, \"k\": 9, \"budget\": 8, \"composition\": [[5,4,8,9,2,2,2],[2,8,7,6,8,10,3],[6,8,4,4,5,4,10],[5,3,7,8,2,2,9],[8,4,3,2,6,4,3],[5,2,8,5,4,5,10],[9,5,4,9,6,5,7],[10,1,6,7,2,7,5],[3,6,9,9,3,7,6]], \"stock\": [3,9,1,5,1,7,9], \"cost\": [5,7,1,6,8,3,9] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 0\n\ntest_input = { \"n\": 1, \"k\": 3, \"budget\": 96, \"composition\": [[4],[8],[3]], \"stock\": [0], \"cost\": [6] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 5\n\ntest_input = { \"n\": 4, \"k\": 2, \"budget\": 113, \"composition\": [[6,9,5,7],[4,9,7,1]], \"stock\": [4,1,0,4], \"cost\": [9,2,3,5] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 2\n\ntest_input = { \"n\": 6, \"k\": 6, \"budget\": 97, \"composition\": [[9,3,10,2,6,3],[9,4,3,7,1,7],[10,10,9,2,1,6],[4,5,2,3,3,10],[2,6,8,3,6,1],[4,9,6,10,3,10]], \"stock\": [2,8,10,8,9,0], \"cost\": [4,5,6,3,10,1] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 2\n\ntest_input = { \"n\": 9, \"k\": 6, \"budget\": 18, \"composition\": [[5,10,2,4,3,3,2,10,3],[2,7,1,7,10,7,8,8,7],[6,2,10,2,4,3,4,8,9],[5,7,2,10,6,10,4,10,3],[1,9,4,4,9,9,4,2,6],[7,5,1,4,10,9,2,2,3]], \"stock\": [5,4,0,1,1,6,1,8,0], \"cost\": [8,1,6,5,10,4,10,9,7] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 0\n\ntest_input = { \"n\": 2, \"k\": 10, \"budget\": 197, \"composition\": [[8,1],[7,4],[2,3],[10,3],[6,3],[9,8],[8,7],[3,4],[2,6],[4,5]], \"stock\": [5,9], \"cost\": [10,2] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 10\n\ntest_input = { \"n\": 10, \"k\": 4, \"budget\": 115, \"composition\": [[4,6,5,10,9,5,2,2,10,1],[6,7,2,2,4,10,3,8,3,7],[1,9,10,5,4,6,2,1,8,4],[7,10,9,5,10,6,9,5,8,4]], \"stock\": [7,8,8,8,6,10,7,8,2,3], \"cost\": [3,5,1,8,7,7,10,4,7,8] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 6, \"k\": 3, \"budget\": 168, \"composition\": [[1,2,10,5,5,8],[1,3,6,1,3,6],[8,5,6,6,5,10]], \"stock\": [7,0,3,1,6,8], \"cost\": [5,6,2,5,3,1] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 4\n\ntest_input = { \"n\": 4, \"k\": 1, \"budget\": 13, \"composition\": [[6,10,1,10]], \"stock\": [2,9,7,3], \"cost\": [7,8,5,5] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 0\n\ntest_input = { \"n\": 1, \"k\": 3, \"budget\": 144, \"composition\": [[4],[10],[9]], \"stock\": [10], \"cost\": [1] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 38\n\ntest_input = { \"n\": 8, \"k\": 4, \"budget\": 34, \"composition\": [[9,1,1,9,1,10,6,4],[10,8,6,5,7,5,2,9],[7,4,5,10,7,2,6,2],[3,8,3,6,9,9,10,5]], \"stock\": [9,9,6,5,5,7,5,4], \"cost\": [7,4,2,2,8,10,10,4] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 0\n\ntest_input = { \"n\": 10, \"k\": 3, \"budget\": 64, \"composition\": [[7,2,7,4,4,6,8,3,5,6],[10,10,6,5,4,7,5,1,3,2],[10,10,8,4,6,8,9,1,8,10]], \"stock\": [8,9,7,3,10,6,6,0,6,10], \"cost\": [7,8,4,6,9,7,7,8,2,9] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 9, \"k\": 5, \"budget\": 37, \"composition\": [[7,5,8,5,3,1,4,10,6],[4,5,5,5,7,4,2,8,1],[3,8,3,6,7,9,10,2,7],[5,3,5,1,10,3,4,10,6],[6,2,9,3,10,6,3,9,7]], \"stock\": [1,4,1,7,10,8,8,3,6], \"cost\": [7,4,2,7,3,10,9,8,10] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 0\n\ntest_input = { \"n\": 3, \"k\": 10, \"budget\": 67, \"composition\": [[5,3,10],[7,5,4],[3,9,9],[10,2,9],[9,4,8],[8,5,7],[5,2,3],[1,7,2],[3,9,1],[7,1,4]], \"stock\": [2,9,4], \"cost\": [4,9,1] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 3\n\ntest_input = { \"n\": 4, \"k\": 7, \"budget\": 113, \"composition\": [[6,10,4,10],[7,8,1,1],[1,5,4,1],[4,7,8,9],[7,9,2,4],[5,1,10,4],[3,3,9,4]], \"stock\": [0,5,5,10], \"cost\": [1,10,8,4] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 2\n\ntest_input = { \"n\": 10, \"k\": 7, \"budget\": 128, \"composition\": [[5,1,1,4,5,9,2,9,2,2],[6,10,4,8,3,10,8,4,5,10],[3,3,8,5,2,6,4,5,4,8],[5,5,4,1,3,2,10,5,3,10],[9,4,2,4,2,4,7,7,1,4],[9,2,10,5,1,5,5,9,5,6],[10,7,9,1,4,7,6,7,5,7]], \"stock\": [3,8,4,5,3,5,4,10,4,9], \"cost\": [4,1,8,4,2,9,1,2,1,10] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 2\n\ntest_input = { \"n\": 1, \"k\": 7, \"budget\": 48, \"composition\": [[1],[5],[9],[6],[4],[2],[4]], \"stock\": [6], \"cost\": [1] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 54\n\ntest_input = { \"n\": 9, \"k\": 4, \"budget\": 21, \"composition\": [[7,2,7,7,8,1,6,7,3],[8,10,4,3,7,2,3,2,5],[6,9,3,2,7,6,10,6,5],[10,2,4,10,7,9,5,8,6]], \"stock\": [9,10,5,2,10,9,8,10,10], \"cost\": [6,5,2,8,10,1,2,7,1] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 8, \"k\": 8, \"budget\": 164, \"composition\": [[8,8,7,7,4,8,8,3],[8,1,5,9,4,5,10,8],[6,3,7,5,5,5,8,7],[7,1,6,2,6,10,5,6],[9,10,1,10,3,8,9,9],[1,5,5,4,5,10,5,9],[8,3,5,3,5,4,7,1],[10,2,3,6,2,4,8,6]], \"stock\": [10,3,10,2,1,4,8,8], \"cost\": [2,9,7,7,4,3,2,10] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 2\n\ntest_input = { \"n\": 1, \"k\": 6, \"budget\": 149, \"composition\": [[4],[8],[1],[9],[1],[9]], \"stock\": [6], \"cost\": [7] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 27\n\ntest_input = { \"n\": 6, \"k\": 7, \"budget\": 136, \"composition\": [[8,9,8,5,9,8],[4,2,1,9,3,8],[6,8,3,1,9,9],[8,1,4,5,2,7],[4,5,6,3,4,9],[5,9,8,2,1,10],[10,10,9,9,2,8]], \"stock\": [4,1,2,9,9,2], \"cost\": [8,1,7,8,1,1] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 2\n\ntest_input = { \"n\": 6, \"k\": 1, \"budget\": 55, \"composition\": [[3,5,3,8,9,8]], \"stock\": [9,7,0,1,9,4], \"cost\": [3,3,1,1,1,2] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 3, \"k\": 1, \"budget\": 195, \"composition\": [[7,3,7]], \"stock\": [0,10,7], \"cost\": [7,6,10] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 2\n\ntest_input = { \"n\": 1, \"k\": 8, \"budget\": 69, \"composition\": [[8],[9],[10],[10],[4],[4],[7],[6]], \"stock\": [10], \"cost\": [9] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 4\n\ntest_input = { \"n\": 9, \"k\": 2, \"budget\": 176, \"composition\": [[8,10,1,2,6,3,5,7,7],[4,6,4,8,4,5,3,6,6]], \"stock\": [10,9,1,3,10,1,10,5,2], \"cost\": [3,8,8,2,5,6,5,8,1] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 8, \"k\": 3, \"budget\": 17, \"composition\": [[3,1,4,8,7,8,5,5],[7,10,6,6,3,10,10,9],[5,6,7,1,4,7,5,1]], \"stock\": [0,4,0,4,4,9,2,1], \"cost\": [10,1,3,9,9,3,1,10] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 0\n\ntest_input = { \"n\": 1, \"k\": 9, \"budget\": 109, \"composition\": [[8],[10],[4],[3],[9],[7],[9],[8],[7]], \"stock\": [10], \"cost\": [9] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 7\n\ntest_input = { \"n\": 7, \"k\": 6, \"budget\": 130, \"composition\": [[4,2,10,2,2,9,4],[9,4,8,8,4,9,9],[9,10,7,8,7,1,4],[8,2,5,5,6,4,7],[9,8,4,3,8,6,2],[1,2,3,9,4,10,1]], \"stock\": [10,1,7,10,1,10,5], \"cost\": [3,7,6,5,1,5,7] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 2\n\ntest_input = { \"n\": 1, \"k\": 8, \"budget\": 48, \"composition\": [[5],[6],[10],[9],[2],[8],[9],[8]], \"stock\": [9], \"cost\": [5] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 9\n\ntest_input = { \"n\": 10, \"k\": 3, \"budget\": 124, \"composition\": [[5,8,7,1,7,7,5,4,5,2],[9,1,2,8,2,8,3,5,2,4],[7,4,6,4,4,2,4,10,4,8]], \"stock\": [9,8,7,0,9,1,4,3,1,1], \"cost\": [9,3,5,4,3,5,2,10,7,4] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 7, \"k\": 10, \"budget\": 177, \"composition\": [[1,8,4,1,9,7,4],[8,1,3,3,9,4,5],[8,5,4,2,9,9,10],[2,10,3,3,3,10,8],[6,3,1,3,7,1,7],[3,5,7,6,8,10,10],[2,10,10,2,2,7,7],[3,2,10,9,4,1,2],[2,7,1,8,2,7,10],[10,9,2,8,10,1,4]], \"stock\": [0,3,5,10,0,9,9], \"cost\": [3,5,4,8,10,1,2] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 6, \"k\": 3, \"budget\": 135, \"composition\": [[7,8,3,4,10,5],[6,5,10,3,1,1],[5,2,9,9,8,1]], \"stock\": [10,0,5,1,0,7], \"cost\": [3,10,3,3,3,8] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 10, \"k\": 1, \"budget\": 131, \"composition\": [[10,2,8,4,3,6,10,8,8,6]], \"stock\": [1,7,10,1,4,8,4,6,7,0], \"cost\": [1,10,9,3,9,8,3,2,9,6] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 10, \"k\": 7, \"budget\": 79, \"composition\": [[3,8,9,10,7,3,8,4,2,2],[7,9,1,1,2,1,8,7,5,7],[5,9,6,2,9,4,10,1,8,5],[4,3,7,2,4,7,4,6,2,10],[4,5,2,5,5,2,7,7,1,8],[9,2,9,4,9,4,7,3,4,4],[8,4,10,8,2,8,7,5,6,10]], \"stock\": [0,4,5,5,7,9,9,7,3,0], \"cost\": [10,8,1,2,7,7,4,7,6,6] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 0\n\ntest_input = { \"n\": 8, \"k\": 7, \"budget\": 86, \"composition\": [[10,5,6,8,9,10,6,5],[7,8,9,9,3,3,9,4],[5,4,4,4,10,2,6,3],[9,7,1,10,10,4,4,6],[10,9,10,3,4,2,9,4],[2,1,4,8,3,6,4,1],[1,8,2,2,3,3,10,8]], \"stock\": [0,6,0,5,6,0,10,1], \"cost\": [7,9,10,10,5,5,7,1] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 6, \"k\": 8, \"budget\": 48, \"composition\": [[10,2,1,4,9,1],[5,10,6,3,3,9],[10,10,10,9,2,9],[1,5,2,2,10,9],[7,9,10,5,10,3],[3,3,10,5,6,2],[6,6,6,8,9,9],[2,4,2,7,3,3]], \"stock\": [5,6,5,1,3,5], \"cost\": [4,3,8,6,1,7] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 2, \"k\": 8, \"budget\": 44, \"composition\": [[8,5],[1,6],[3,10],[4,6],[5,8],[10,5],[7,5],[5,1]], \"stock\": [8,0], \"cost\": [8,6] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 2\n\ntest_input = { \"n\": 9, \"k\": 3, \"budget\": 107, \"composition\": [[8,1,9,10,10,5,4,9,1],[8,10,6,8,10,2,10,9,4],[9,6,4,7,10,2,7,4,2]], \"stock\": [9,2,4,1,1,3,8,9,0], \"cost\": [6,2,8,3,1,3,5,9,9] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 3, \"k\": 5, \"budget\": 125, \"composition\": [[10,8,9],[10,7,8],[7,7,6],[9,2,5],[8,4,6]], \"stock\": [8,3,1], \"cost\": [4,10,10] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 6, \"k\": 10, \"budget\": 118, \"composition\": [[10,7,8,10,5,9],[2,4,4,5,4,2],[6,7,2,6,3,10],[3,8,10,8,1,6],[2,9,3,8,5,5],[1,6,8,1,7,7],[4,9,1,8,9,5],[9,4,10,4,1,4],[1,5,10,2,5,3],[2,1,3,3,2,9]], \"stock\": [9,6,2,2,6,5], \"cost\": [2,1,7,5,10,9] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 2\n\ntest_input = { \"n\": 1, \"k\": 2, \"budget\": 148, \"composition\": [[1],[8]], \"stock\": [4], \"cost\": [2] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 78\n\ntest_input = { \"n\": 5, \"k\": 5, \"budget\": 91, \"composition\": [[2,4,10,5,5],[4,3,8,8,10],[9,6,2,7,3],[7,7,3,6,6],[6,4,5,3,4]], \"stock\": [6,4,7,3,3], \"cost\": [4,10,9,7,3] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 8, \"k\": 5, \"budget\": 143, \"composition\": [[8,3,3,6,2,5,8,9],[6,8,3,6,4,10,10,6],[9,6,10,9,6,5,1,1],[1,1,10,3,4,10,2,2],[10,6,4,9,9,3,9,2]], \"stock\": [2,1,4,5,6,8,2,8], \"cost\": [1,8,3,9,9,7,1,8] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 4, \"k\": 9, \"budget\": 172, \"composition\": [[9,2,2,2],[4,5,3,2],[4,6,1,9],[5,3,3,5],[2,4,3,9],[7,4,4,3],[1,3,2,6],[7,2,5,4],[4,4,2,2]], \"stock\": [6,7,5,2], \"cost\": [2,8,5,2] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 5\n\ntest_input = { \"n\": 5, \"k\": 2, \"budget\": 110, \"composition\": [[2,8,10,7,4],[5,3,5,5,5]], \"stock\": [6,8,8,1,6], \"cost\": [8,5,8,6,7] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 3, \"k\": 10, \"budget\": 21, \"composition\": [[9,8,5],[2,9,9],[2,6,8],[7,4,10],[10,8,6],[2,6,5],[6,6,8],[4,7,7],[8,9,10],[6,1,7]], \"stock\": [6,4,10], \"cost\": [7,9,4] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 5, \"k\": 1, \"budget\": 176, \"composition\": [[5,6,2,5,4]], \"stock\": [1,4,3,10,7], \"cost\": [10,9,9,8,10] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 9, \"k\": 1, \"budget\": 112, \"composition\": [[10,4,3,5,2,10,10,8,9]], \"stock\": [4,4,3,0,5,0,7,6,2], \"cost\": [7,9,8,9,2,6,10,5,5] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 0\n\ntest_input = { \"n\": 8, \"k\": 9, \"budget\": 41, \"composition\": [[10,6,7,3,6,9,9,8],[5,9,5,2,4,10,2,5],[4,10,9,3,5,10,7,1],[8,3,1,4,2,5,3,1],[1,10,10,10,7,1,10,4],[6,9,7,10,8,7,6,9],[4,9,10,4,10,7,1,7],[3,5,9,5,2,8,3,10],[8,7,1,9,3,8,6,3]], \"stock\": [5,4,10,10,7,8,7,6], \"cost\": [5,1,10,4,9,9,4,6] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 2, \"k\": 10, \"budget\": 2, \"composition\": [[9,6],[10,1],[7,3],[5,5],[7,6],[10,2],[7,3],[7,6],[7,3],[2,7]], \"stock\": [6,10], \"cost\": [1,4] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 2, \"k\": 7, \"budget\": 168, \"composition\": [[8,2],[4,7],[8,3],[1,6],[3,3],[9,7],[8,4]], \"stock\": [1,7], \"cost\": [5,3] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 8\n\ntest_input = { \"n\": 8, \"k\": 9, \"budget\": 195, \"composition\": [[2,5,4,2,2,4,4,1],[5,4,5,8,9,1,2,5],[1,10,3,9,6,7,1,3],[4,10,3,3,6,4,7,6],[4,3,10,2,7,8,4,9],[4,1,6,2,8,7,3,3],[10,7,5,2,1,5,4,5],[7,4,3,10,4,10,1,2],[9,7,9,8,9,2,3,10]], \"stock\": [1,1,7,10,1,6,3,9], \"cost\": [1,4,7,6,4,5,5,2] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 3\n\ntest_input = { \"n\": 7, \"k\": 6, \"budget\": 167, \"composition\": [[2,2,3,4,6,2,4],[5,7,3,7,4,6,7],[5,7,4,10,5,1,1],[2,3,10,6,9,5,6],[3,9,7,8,5,10,2],[6,7,8,8,1,6,6]], \"stock\": [10,10,8,9,7,8,4], \"cost\": [2,6,1,9,9,9,8] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 2\n\ntest_input = { \"n\": 6, \"k\": 9, \"budget\": 73, \"composition\": [[1,1,9,4,1,7],[6,8,7,7,6,2],[2,1,5,10,2,5],[3,10,7,7,5,10],[6,1,6,8,4,6],[3,10,10,9,8,2],[10,8,7,7,4,2],[10,2,3,8,7,4],[7,5,9,10,4,3]], \"stock\": [1,9,8,6,10,6], \"cost\": [6,3,9,7,1,4] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 5, \"k\": 3, \"budget\": 128, \"composition\": [[4,6,5,5,1],[1,4,8,8,7],[3,3,5,4,5]], \"stock\": [6,8,8,0,2], \"cost\": [2,4,9,7,6] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 2\n\ntest_input = { \"n\": 10, \"k\": 7, \"budget\": 96, \"composition\": [[9,3,10,2,8,6,1,7,2,4],[2,10,4,5,5,3,7,5,2,10],[8,7,7,10,6,6,3,2,3,8],[8,1,5,4,7,8,1,9,2,10],[6,7,10,9,8,8,8,3,1,2],[1,6,9,1,8,4,9,4,9,7],[5,6,5,2,1,8,9,4,3,6]], \"stock\": [4,6,3,0,7,0,7,10,8,10], \"cost\": [4,3,6,5,6,2,7,3,1,3] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 5, \"k\": 9, \"budget\": 81, \"composition\": [[4,4,9,5,5],[7,9,10,6,8],[4,7,4,2,10],[2,9,6,9,8],[2,5,7,3,4],[4,9,9,2,5],[5,6,1,2,9],[5,3,8,7,8],[8,6,9,9,3]], \"stock\": [2,9,6,5,3], \"cost\": [3,3,8,7,6] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 10, \"k\": 10, \"budget\": 102, \"composition\": [[9,4,10,4,9,4,3,2,2,4],[10,8,3,4,5,6,4,10,2,7],[4,1,10,9,4,5,7,9,6,8],[1,5,9,7,8,5,10,3,8,7],[6,2,10,2,8,10,7,5,10,7],[7,2,2,6,8,7,9,10,6,8],[9,4,8,3,10,3,2,5,6,6],[3,1,3,5,10,5,8,8,1,10],[6,4,3,9,3,8,8,6,3,5],[8,9,1,2,7,8,1,10,8,1]], \"stock\": [3,6,1,3,3,7,7,2,2,2], \"cost\": [3,10,9,7,1,3,2,9,7,3] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 0\n\ntest_input = { \"n\": 6, \"k\": 6, \"budget\": 115, \"composition\": [[2,5,8,6,2,3],[7,10,7,2,10,5],[2,7,10,10,3,8],[3,3,8,4,3,10],[10,10,4,10,4,3],[8,9,9,5,7,5]], \"stock\": [7,1,10,7,6,2], \"cost\": [3,8,9,7,8,4] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 8, \"k\": 10, \"budget\": 19, \"composition\": [[7,6,3,10,2,9,7,2],[5,10,3,3,10,6,6,10],[10,4,9,10,10,7,7,9],[10,6,9,3,4,9,9,5],[7,1,3,4,8,2,8,8],[9,2,3,1,1,2,2,5],[2,6,9,3,7,9,5,8],[3,10,5,2,8,5,8,10],[8,10,1,1,2,1,7,8],[10,8,4,8,5,5,10,2]], \"stock\": [6,0,9,2,5,0,10,8], \"cost\": [2,4,9,8,4,10,3,1] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 0\n\ntest_input = { \"n\": 7, \"k\": 10, \"budget\": 179, \"composition\": [[10,5,2,6,5,2,7],[1,6,8,2,4,8,3],[8,6,1,2,7,7,4],[4,1,9,6,3,8,10],[7,6,3,5,3,4,2],[8,10,9,3,8,1,5],[5,4,1,7,7,6,3],[10,9,8,1,10,4,8],[9,4,6,2,3,3,9],[6,5,2,3,10,6,8]], \"stock\": [9,0,2,10,3,7,6], \"cost\": [6,2,7,10,1,2,7] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 2\n\ntest_input = { \"n\": 9, \"k\": 10, \"budget\": 123, \"composition\": [[4,9,5,9,9,4,8,10,10],[3,1,5,8,4,4,8,6,3],[5,7,2,8,2,7,3,9,5],[9,4,6,7,2,3,4,3,3],[3,6,2,1,3,7,10,7,3],[2,6,9,7,5,7,3,10,1],[1,7,10,6,9,6,6,9,8],[10,8,2,1,6,8,3,8,6],[6,5,1,3,5,1,2,3,1],[8,2,6,1,8,8,3,2,1]], \"stock\": [2,6,3,4,6,1,7,2,6], \"cost\": [5,5,9,1,5,10,4,1,2] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 2\n\ntest_input = { \"n\": 6, \"k\": 1, \"budget\": 161, \"composition\": [[4,6,9,8,5,5]], \"stock\": [7,4,5,1,9,4], \"cost\": [6,5,5,6,3,1] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1", "start_time": 1694917800} +{"task_id": "weekly-contest-363-maximum-element-sum-of-a-complete-subset-of-indices", "url": "https://leetcode.com/problems/maximum-element-sum-of-a-complete-subset-of-indices", "title": "maximum-element-sum-of-a-complete-subset-of-indices", "meta": {"questionId": "3047", "questionFrontendId": "2862", "title": "Maximum Element-Sum of a Complete Subset of Indices", "titleSlug": "maximum-element-sum-of-a-complete-subset-of-indices", "isPaidOnly": false, "difficulty": "Hard", "likes": 157, "dislikes": 27, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 1 开始、由 n 个整数组成的数组。\n\n如果一组数字中每对元素的乘积都是一个完全平方数,则称这组数字是一个 完全集 。\n\n下标集 {1, 2, ..., n} 的子集可以表示为 {i1, i2, ..., ik},我们定义对应该子集的 元素和 为 nums[i1] + nums[i2] + ... + nums[ik] 。\n\n返回下标集 {1, 2, ..., n} 的 完全子集 所能取到的 最大元素和 。\n\n完全平方数是指可以表示为一个整数和其自身相乘的数。\n\n示例 1:\n\n输入:nums = [8,7,3,5,7,2,4,9]\n输出:16\n解释:除了由单个下标组成的子集之外,还有两个下标集的完全子集:{1,4} 和 {2,8} 。\n与下标 1 和 4 对应的元素和等于 nums[1] + nums[4] = 8 + 5 = 13 。\n与下标 2 和 8 对应的元素和等于 nums[2] + nums[8] = 7 + 9 = 16 。\n因此,下标集的完全子集可以取到的最大元素和为 16 。\n\n示例 2:\n\n输入:nums = [5,10,3,10,1,13,7,9,4]\n输出:19\n解释:除了由单个下标组成的子集之外,还有四个下标集的完全子集:{1,4}、{1,9}、{2,8}、{4,9} 和 {1,4,9} 。\n与下标 1 和 4 对应的元素和等于 nums[1] + nums[4] = 5 + 10 = 15 。\n与下标 1 和 9 对应的元素和等于 nums[1] + nums[9] = 5 + 4 = 9 。\n与下标 2 和 8 对应的元素和等于 nums[2] + nums[8] = 10 + 9 = 19 。\n与下标 4 和 9 对应的元素和等于 nums[4] + nums[9] = 10 + 4 = 14 。\n与下标 1、4 和 9 对应的元素和等于 nums[1] + nums[4] + nums[9] = 5 + 10 + 4 = 19 。\n因此,下标集的完全子集可以取到的最大元素和为 19 。\n\n\n提示:\n\n * 1 <= n == nums.length <= 104\n * 1 <= nums[i] <= 109\n\"\"\"\nclass Solution:\n def maximumSum(self, nums: List[int]) -> int:\n ", "prompt_sft": "给你一个下标从 1 开始、由 n 个整数组成的数组。\n\n如果一组数字中每对元素的乘积都是一个完全平方数,则称这组数字是一个 完全集 。\n\n下标集 {1, 2, ..., n} 的子集可以表示为 {i1, i2, ..., ik},我们定义对应该子集的 元素和 为 nums[i1] + nums[i2] + ... + nums[ik] 。\n\n返回下标集 {1, 2, ..., n} 的 完全子集 所能取到的 最大元素和 。\n\n完全平方数是指可以表示为一个整数和其自身相乘的数。\n\n示例 1:\n\n输入:nums = [8,7,3,5,7,2,4,9]\n输出:16\n解释:除了由单个下标组成的子集之外,还有两个下标集的完全子集:{1,4} 和 {2,8} 。\n与下标 1 和 4 对应的元素和等于 nums[1] + nums[4] = 8 + 5 = 13 。\n与下标 2 和 8 对应的元素和等于 nums[2] + nums[8] = 7 + 9 = 16 。\n因此,下标集的完全子集可以取到的最大元素和为 16 。\n\n示例 2:\n\n输入:nums = [5,10,3,10,1,13,7,9,4]\n输出:19\n解释:除了由单个下标组成的子集之外,还有四个下标集的完全子集:{1,4}、{1,9}、{2,8}、{4,9} 和 {1,4,9} 。\n与下标 1 和 4 对应的元素和等于 nums[1] + nums[4] = 5 + 10 = 15 。\n与下标 1 和 9 对应的元素和等于 nums[1] + nums[9] = 5 + 4 = 9 。\n与下标 2 和 8 对应的元素和等于 nums[2] + nums[8] = 10 + 9 = 19 。\n与下标 4 和 9 对应的元素和等于 nums[4] + nums[9] = 10 + 4 = 14 。\n与下标 1、4 和 9 对应的元素和等于 nums[1] + nums[4] + nums[9] = 5 + 10 + 4 = 19 。\n因此,下标集的完全子集可以取到的最大元素和为 19 。\n\n\n提示:\n\n * 1 <= n == nums.length <= 104\n * 1 <= nums[i] <= 109\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def maximumSum(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [8,7,3,5,7,2,4,9] }\nassert my_solution.maximumSum(**test_input) == 16\n\ntest_input = { \"nums\": [5,10,3,10,1,13,7,9,4] }\nassert my_solution.maximumSum(**test_input) == 19\n\ntest_input = { \"nums\": [1,1,1,1] }\nassert my_solution.maximumSum(**test_input) == 2\n\ntest_input = { \"nums\": [1,100,100,1] }\nassert my_solution.maximumSum(**test_input) == 100\n\ntest_input = { \"nums\": [998244353,998244353,998244353,998244353] }\nassert my_solution.maximumSum(**test_input) == 1996488706\n\ntest_input = { \"nums\": [1000000000,1,1,1000000000] }\nassert my_solution.maximumSum(**test_input) == 2000000000\n\ntest_input = { \"nums\": [1,1,1000000000,1] }\nassert my_solution.maximumSum(**test_input) == 1000000000\n\ntest_input = { \"nums\": [5,10,3,10,1,13,7,20,4] }\nassert my_solution.maximumSum(**test_input) == 30\n\ntest_input = { \"nums\": [5,3,3,10,1,13,7,67,4] }\nassert my_solution.maximumSum(**test_input) == 70\n\ntest_input = { \"nums\": [35,45,29,16,42,49,25,19,46] }\nassert my_solution.maximumSum(**test_input) == 97\n\ntest_input = { \"nums\": [34,43,47,50,45] }\nassert my_solution.maximumSum(**test_input) == 84\n\ntest_input = { \"nums\": [4,31,45,34,44] }\nassert my_solution.maximumSum(**test_input) == 45\n\ntest_input = { \"nums\": [12,5,49,26] }\nassert my_solution.maximumSum(**test_input) == 49\n\ntest_input = { \"nums\": [41] }\nassert my_solution.maximumSum(**test_input) == 41\n\ntest_input = { \"nums\": [38,9,37,11,20,43] }\nassert my_solution.maximumSum(**test_input) == 49\n\ntest_input = { \"nums\": [47,50,17,49,12,22] }\nassert my_solution.maximumSum(**test_input) == 96\n\ntest_input = { \"nums\": [23,13,17,3,21,23] }\nassert my_solution.maximumSum(**test_input) == 26\n\ntest_input = { \"nums\": [38,28] }\nassert my_solution.maximumSum(**test_input) == 38\n\ntest_input = { \"nums\": [16,31,37,29,28,34,25,36] }\nassert my_solution.maximumSum(**test_input) == 67\n\ntest_input = { \"nums\": [19,46,37,44,4,40,24,17,49] }\nassert my_solution.maximumSum(**test_input) == 112\n\ntest_input = { \"nums\": [28,40,37] }\nassert my_solution.maximumSum(**test_input) == 40\n\ntest_input = { \"nums\": [19,6,30,23,25,45,15,2,3,46] }\nassert my_solution.maximumSum(**test_input) == 46\n\ntest_input = { \"nums\": [5,16,4,13,37,44,49,7] }\nassert my_solution.maximumSum(**test_input) == 49\n\ntest_input = { \"nums\": [40,8,19,26] }\nassert my_solution.maximumSum(**test_input) == 66\n\ntest_input = { \"nums\": [3,37,2] }\nassert my_solution.maximumSum(**test_input) == 37\n\ntest_input = { \"nums\": [1,5,35,20,32,18,6,49,34,15] }\nassert my_solution.maximumSum(**test_input) == 55\n\ntest_input = { \"nums\": [25,31,4,20,45] }\nassert my_solution.maximumSum(**test_input) == 45\n\ntest_input = { \"nums\": [32,3,25,15,37,37,21,24,8,33] }\nassert my_solution.maximumSum(**test_input) == 55\n\ntest_input = { \"nums\": [13] }\nassert my_solution.maximumSum(**test_input) == 13\n\ntest_input = { \"nums\": [41,25,20,28,40,22,37,43,6,32] }\nassert my_solution.maximumSum(**test_input) == 75\n\ntest_input = { \"nums\": [23,9,7,24,30,34,10,47] }\nassert my_solution.maximumSum(**test_input) == 56\n\ntest_input = { \"nums\": [11,31,1,34,8,20,15,20,49] }\nassert my_solution.maximumSum(**test_input) == 94\n\ntest_input = { \"nums\": [41,21,4,15,25,38,26,7,6] }\nassert my_solution.maximumSum(**test_input) == 62\n\ntest_input = { \"nums\": [46,31,28,34,12,40,11,31,8,25] }\nassert my_solution.maximumSum(**test_input) == 88\n\ntest_input = { \"nums\": [50] }\nassert my_solution.maximumSum(**test_input) == 50\n\ntest_input = { \"nums\": [41,43,17,35] }\nassert my_solution.maximumSum(**test_input) == 76\n\ntest_input = { \"nums\": [20,6] }\nassert my_solution.maximumSum(**test_input) == 20\n\ntest_input = { \"nums\": [43,18,10,19,20,9,49] }\nassert my_solution.maximumSum(**test_input) == 62\n\ntest_input = { \"nums\": [3,39,29,5,6,36,38,26,14,10] }\nassert my_solution.maximumSum(**test_input) == 65\n\ntest_input = { \"nums\": [47,2,48,16,10,3,45,20,39] }\nassert my_solution.maximumSum(**test_input) == 102\n\ntest_input = { \"nums\": [11,47,27,17,7] }\nassert my_solution.maximumSum(**test_input) == 47\n\ntest_input = { \"nums\": [48,17,41,23,40,9,3,26,44,34] }\nassert my_solution.maximumSum(**test_input) == 115\n\ntest_input = { \"nums\": [47,2,42,10,15,44,35,50] }\nassert my_solution.maximumSum(**test_input) == 57\n\ntest_input = { \"nums\": [45,48,50,24,23,14,2,33] }\nassert my_solution.maximumSum(**test_input) == 81\n\ntest_input = { \"nums\": [7,39,27,39,43,42,31,37,15] }\nassert my_solution.maximumSum(**test_input) == 76\n\ntest_input = { \"nums\": [10,36,23,31] }\nassert my_solution.maximumSum(**test_input) == 41\n\ntest_input = { \"nums\": [27,27,13,37] }\nassert my_solution.maximumSum(**test_input) == 64\n\ntest_input = { \"nums\": [34,17,26,13] }\nassert my_solution.maximumSum(**test_input) == 47\n\ntest_input = { \"nums\": [9,42] }\nassert my_solution.maximumSum(**test_input) == 42\n\ntest_input = { \"nums\": [23,42,4,28,30,36,30,39] }\nassert my_solution.maximumSum(**test_input) == 81\n\ntest_input = { \"nums\": [10,28,28,21,25,14,38] }\nassert my_solution.maximumSum(**test_input) == 38\n\ntest_input = { \"nums\": [40,34,26,9,23,15,23,27,49] }\nassert my_solution.maximumSum(**test_input) == 98\n\ntest_input = { \"nums\": [27,42,40,2,1] }\nassert my_solution.maximumSum(**test_input) == 42\n\ntest_input = { \"nums\": [48,19,21,21,32,20,50,41,49,30] }\nassert my_solution.maximumSum(**test_input) == 118\n\ntest_input = { \"nums\": [10,13,6,39,9] }\nassert my_solution.maximumSum(**test_input) == 49\n\ntest_input = { \"nums\": [50,37,24,4,10,43,35] }\nassert my_solution.maximumSum(**test_input) == 54\n\ntest_input = { \"nums\": [39,24] }\nassert my_solution.maximumSum(**test_input) == 39\n\ntest_input = { \"nums\": [21] }\nassert my_solution.maximumSum(**test_input) == 21\n\ntest_input = { \"nums\": [20,15] }\nassert my_solution.maximumSum(**test_input) == 20\n\ntest_input = { \"nums\": [23,27,42,3,33,36,43,32,27,48,40,22,5,36,48] }\nassert my_solution.maximumSum(**test_input) == 64\n\ntest_input = { \"nums\": [39,46,12,14,25,37,24,44,6,38,4] }\nassert my_solution.maximumSum(**test_input) == 90\n\ntest_input = { \"nums\": [36,5,23,17,32,47,23,41,18,44,21,4,22,6,21] }\nassert my_solution.maximumSum(**test_input) == 71\n\ntest_input = { \"nums\": [46,26,37,17,15,26,45,45,17,42,16,14,36,40] }\nassert my_solution.maximumSum(**test_input) == 80\n\ntest_input = { \"nums\": [46,40,16,48,24,1,13,15,6,5,12,15,4] }\nassert my_solution.maximumSum(**test_input) == 100\n\ntest_input = { \"nums\": [11,27,28,26,4,22,10,49,4,23,30,6,5] }\nassert my_solution.maximumSum(**test_input) == 76\n\ntest_input = { \"nums\": [37,17,17,18,10,28,47,38,43,20,10] }\nassert my_solution.maximumSum(**test_input) == 98\n\ntest_input = { \"nums\": [12,17,9,30,38,20,28,36,34,15,4,15,48] }\nassert my_solution.maximumSum(**test_input) == 76\n\ntest_input = { \"nums\": [28,32,22,9,33,26,10,15,15,37,33,48,2,14,35] }\nassert my_solution.maximumSum(**test_input) == 70\n\ntest_input = { \"nums\": [35,28,45,34,49,45,38,15,36,33,15,16] }\nassert my_solution.maximumSum(**test_input) == 105\n\ntest_input = { \"nums\": [50,18,24,30,6,49,3,20,22,19,25,35,30,33] }\nassert my_solution.maximumSum(**test_input) == 102\n\ntest_input = { \"nums\": [10,19,37,1,31,6,2,37,10,1,36,48,7,40] }\nassert my_solution.maximumSum(**test_input) == 85\n\ntest_input = { \"nums\": [45,49,32,44,12,39,8,7,3,48,37,27,41,20,18] }\nassert my_solution.maximumSum(**test_input) == 92\n\ntest_input = { \"nums\": [40,9,16,40,9,28,29,36,4,17,29] }\nassert my_solution.maximumSum(**test_input) == 84\n\ntest_input = { \"nums\": [21,32,24,39,2,13,37,33,50,43,9,43,14] }\nassert my_solution.maximumSum(**test_input) == 110\n\ntest_input = { \"nums\": [36,25,21,29,42,40,16,41,22,24,45,7,33] }\nassert my_solution.maximumSum(**test_input) == 87\n\ntest_input = { \"nums\": [32,33,7,45,23,13,45,4,15,12] }\nassert my_solution.maximumSum(**test_input) == 92\n\ntest_input = { \"nums\": [10,7,1,15,12,22,34,3,36,44,10,12] }\nassert my_solution.maximumSum(**test_input) == 61\n\ntest_input = { \"nums\": [26,4,44,3,37,50,27,22,48,14,12,3,39,31] }\nassert my_solution.maximumSum(**test_input) == 77\n\ntest_input = { \"nums\": [47,48,8,24,1,17,32,13,19,25,15,30,12] }\nassert my_solution.maximumSum(**test_input) == 90\n\ntest_input = { \"nums\": [31,18,11,28,7,34,32,38,47,44,1,13,46] }\nassert my_solution.maximumSum(**test_input) == 106\n\ntest_input = { \"nums\": [47,12,35,10,37,36,44,38,19,31,28,21,3,34] }\nassert my_solution.maximumSum(**test_input) == 76\n\ntest_input = { \"nums\": [19,47,46,5,7,42,35,3,39,2,1,31] }\nassert my_solution.maximumSum(**test_input) == 77\n\ntest_input = { \"nums\": [15,50,14,27,37,44,11,38,23,39,27,36,22] }\nassert my_solution.maximumSum(**test_input) == 88\n\ntest_input = { \"nums\": [31,31,18,24,9,27,33,10,23,38,44,4,17,11,14] }\nassert my_solution.maximumSum(**test_input) == 78\n\ntest_input = { \"nums\": [38,27,13,20,36,23,6,7,37,20,49,31,25,12] }\nassert my_solution.maximumSum(**test_input) == 95\n\ntest_input = { \"nums\": [6,21,11,15,17,47,50,14,24,18,38,19,48,43] }\nassert my_solution.maximumSum(**test_input) == 50\n\ntest_input = { \"nums\": [31,4,1,5,50,46,14,17,13,14,17,39,46,18] }\nassert my_solution.maximumSum(**test_input) == 50\n\ntest_input = { \"nums\": [39,13,6,45,44,14,44,37,24,20,21,47,6,6,5] }\nassert my_solution.maximumSum(**test_input) == 108\n\ntest_input = { \"nums\": [17,16,48,41,7,39,50,29,2,33] }\nassert my_solution.maximumSum(**test_input) == 60\n\ntest_input = { \"nums\": [3,8,19,47,29,4,16,31,11,30] }\nassert my_solution.maximumSum(**test_input) == 61\n\ntest_input = { \"nums\": [20,1,46,36,35,32,49,14,48,25,17,50,22] }\nassert my_solution.maximumSum(**test_input) == 104\n\ntest_input = { \"nums\": [49,20,12,42,33,21,29,30,35,4,5,50] }\nassert my_solution.maximumSum(**test_input) == 126\n\ntest_input = { \"nums\": [36,1,8,14,39,2,31,23,10,46,42] }\nassert my_solution.maximumSum(**test_input) == 60\n\ntest_input = { \"nums\": [33,29,23,4,48,31,31,26,11,39] }\nassert my_solution.maximumSum(**test_input) == 55\n\ntest_input = { \"nums\": [33,36,31,21,2,41,14,36,6,1,22,13,34] }\nassert my_solution.maximumSum(**test_input) == 72\n\ntest_input = { \"nums\": [35,32,43,20,4,13,6,19,36,20] }\nassert my_solution.maximumSum(**test_input) == 91\n\ntest_input = { \"nums\": [16,41,16,41,11,39,40,7,24,28,13] }\nassert my_solution.maximumSum(**test_input) == 81\n\ntest_input = { \"nums\": [32,24,29,24,29,45,10,37,22,35,37,28,15] }\nassert my_solution.maximumSum(**test_input) == 78\n\ntest_input = { \"nums\": [45,8,19,1,33,2,32,40,16,33,44,27] }\nassert my_solution.maximumSum(**test_input) == 62\n\ntest_input = { \"nums\": [3,42,14,18,1,20,19,7,37,3,2,3,48] }\nassert my_solution.maximumSum(**test_input) == 58", "start_time": 1694917800} +{"task_id": "biweekly-contest-113-minimum-right-shifts-to-sort-the-array", "url": "https://leetcode.com/problems/minimum-right-shifts-to-sort-the-array", "title": "minimum-right-shifts-to-sort-the-array", "meta": {"questionId": "3045", "questionFrontendId": "2855", "title": "Minimum Right Shifts to Sort the Array", "titleSlug": "minimum-right-shifts-to-sort-the-array", "isPaidOnly": false, "difficulty": "Easy", "likes": 169, "dislikes": 6, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个长度为 n 下标从 0 开始的数组 nums ,数组中的元素为 互不相同 的正整数。请你返回让 nums 成为递增数组的 最少右移 次数,如果无法得到递增数组,返回 -1 。\n\n一次 右移 指的是同时对所有下标进行操作,将下标为 i 的元素移动到下标 (i + 1) % n 处。\n\n示例 1:\n\n输入:nums = [3,4,5,1,2]\n输出:2\n解释:\n第一次右移后,nums = [2,3,4,5,1] 。\n第二次右移后,nums = [1,2,3,4,5] 。\n现在 nums 是递增数组了,所以答案为 2 。\n\n示例 2:\n\n输入:nums = [1,3,5]\n输出:0\n解释:nums 已经是递增数组了,所以答案为 0 。\n\n示例 3:\n\n输入:nums = [2,1,4]\n输出:-1\n解释:无法将数组变为递增数组。\n\n\n提示:\n\n * 1 <= nums.length <= 100\n * 1 <= nums[i] <= 100\n * nums 中的整数互不相同。\n\"\"\"\nclass Solution:\n def minimumRightShifts(self, nums: List[int]) -> int:\n ", "prompt_sft": "给你一个长度为 n 下标从 0 开始的数组 nums ,数组中的元素为 互不相同 的正整数。请你返回让 nums 成为递增数组的 最少右移 次数,如果无法得到递增数组,返回 -1 。\n\n一次 右移 指的是同时对所有下标进行操作,将下标为 i 的元素移动到下标 (i + 1) % n 处。\n\n示例 1:\n\n输入:nums = [3,4,5,1,2]\n输出:2\n解释:\n第一次右移后,nums = [2,3,4,5,1] 。\n第二次右移后,nums = [1,2,3,4,5] 。\n现在 nums 是递增数组了,所以答案为 2 。\n\n示例 2:\n\n输入:nums = [1,3,5]\n输出:0\n解释:nums 已经是递增数组了,所以答案为 0 。\n\n示例 3:\n\n输入:nums = [2,1,4]\n输出:-1\n解释:无法将数组变为递增数组。\n\n\n提示:\n\n * 1 <= nums.length <= 100\n * 1 <= nums[i] <= 100\n * nums 中的整数互不相同。\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def minimumRightShifts(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [3,4,5,1,2] }\nassert my_solution.minimumRightShifts(**test_input) == 2\n\ntest_input = { \"nums\": [1,3,5] }\nassert my_solution.minimumRightShifts(**test_input) == 0\n\ntest_input = { \"nums\": [2,1,4] }\nassert my_solution.minimumRightShifts(**test_input) == -1\n\ntest_input = { \"nums\": [31,72,79,25] }\nassert my_solution.minimumRightShifts(**test_input) == 1\n\ntest_input = { \"nums\": [27,33,42,58,81,8,9,17] }\nassert my_solution.minimumRightShifts(**test_input) == 3\n\ntest_input = { \"nums\": [72,13,21,35,52] }\nassert my_solution.minimumRightShifts(**test_input) == 4\n\ntest_input = { \"nums\": [65,73,77,1] }\nassert my_solution.minimumRightShifts(**test_input) == 1\n\ntest_input = { \"nums\": [100,8,14,68,80,84] }\nassert my_solution.minimumRightShifts(**test_input) == 5\n\ntest_input = { \"nums\": [53,60,64,69,98,40] }\nassert my_solution.minimumRightShifts(**test_input) == 1\n\ntest_input = { \"nums\": [21] }\nassert my_solution.minimumRightShifts(**test_input) == 0\n\ntest_input = { \"nums\": [78,12,18,21,23,36,64,70] }\nassert my_solution.minimumRightShifts(**test_input) == 7\n\ntest_input = { \"nums\": [25,26,53,91,92,99,10,24] }\nassert my_solution.minimumRightShifts(**test_input) == 2\n\ntest_input = { \"nums\": [63,51,65,87,6,17,32,14,42,46] }\nassert my_solution.minimumRightShifts(**test_input) == -1\n\ntest_input = { \"nums\": [43,46,75,76,85,96,9,19,25] }\nassert my_solution.minimumRightShifts(**test_input) == 3\n\ntest_input = { \"nums\": [5] }\nassert my_solution.minimumRightShifts(**test_input) == 0\n\ntest_input = { \"nums\": [35,72,76,82,96,97,24,26] }\nassert my_solution.minimumRightShifts(**test_input) == 2\n\ntest_input = { \"nums\": [82,30,94,55,76,51,3,89,52,96] }\nassert my_solution.minimumRightShifts(**test_input) == -1\n\ntest_input = { \"nums\": [57,59,88,97,6,27,41,46,52] }\nassert my_solution.minimumRightShifts(**test_input) == 5\n\ntest_input = { \"nums\": [17] }\nassert my_solution.minimumRightShifts(**test_input) == 0\n\ntest_input = { \"nums\": [62] }\nassert my_solution.minimumRightShifts(**test_input) == 0\n\ntest_input = { \"nums\": [24,46,55,61,71,78,1,4] }\nassert my_solution.minimumRightShifts(**test_input) == 2\n\ntest_input = { \"nums\": [83,2,21,42,73,77,80] }\nassert my_solution.minimumRightShifts(**test_input) == 6\n\ntest_input = { \"nums\": [83,94,14,43,50,62,63] }\nassert my_solution.minimumRightShifts(**test_input) == 5\n\ntest_input = { \"nums\": [38,46,66,77,7,15,17,35] }\nassert my_solution.minimumRightShifts(**test_input) == 4\n\ntest_input = { \"nums\": [35,68,82,90,9,18,29,34] }\nassert my_solution.minimumRightShifts(**test_input) == 4\n\ntest_input = { \"nums\": [71] }\nassert my_solution.minimumRightShifts(**test_input) == 0\n\ntest_input = { \"nums\": [71,73,88,12,49,55,59,70] }\nassert my_solution.minimumRightShifts(**test_input) == 5\n\ntest_input = { \"nums\": [54,65,75,81,24,37] }\nassert my_solution.minimumRightShifts(**test_input) == 2\n\ntest_input = { \"nums\": [57,67,73,78,79,2,45,48,51] }\nassert my_solution.minimumRightShifts(**test_input) == 4\n\ntest_input = { \"nums\": [36,62,65,85,95,9,21] }\nassert my_solution.minimumRightShifts(**test_input) == 2\n\ntest_input = { \"nums\": [68,12] }\nassert my_solution.minimumRightShifts(**test_input) == 1\n\ntest_input = { \"nums\": [34,9,86,20,67,94,65,82,40,79] }\nassert my_solution.minimumRightShifts(**test_input) == -1\n\ntest_input = { \"nums\": [92,84,37,19,16,85,20,79,25,89] }\nassert my_solution.minimumRightShifts(**test_input) == -1\n\ntest_input = { \"nums\": [3,16,38,44,67,79,84] }\nassert my_solution.minimumRightShifts(**test_input) == 0\n\ntest_input = { \"nums\": [14,24,58,69,71,94,13] }\nassert my_solution.minimumRightShifts(**test_input) == 1\n\ntest_input = { \"nums\": [100,18] }\nassert my_solution.minimumRightShifts(**test_input) == 1\n\ntest_input = { \"nums\": [13] }\nassert my_solution.minimumRightShifts(**test_input) == 0\n\ntest_input = { \"nums\": [94,30,53,56,67,72,82] }\nassert my_solution.minimumRightShifts(**test_input) == 6\n\ntest_input = { \"nums\": [92,14,65,80,85] }\nassert my_solution.minimumRightShifts(**test_input) == 4\n\ntest_input = { \"nums\": [43,53,81,87,93,19,31,39] }\nassert my_solution.minimumRightShifts(**test_input) == 3\n\ntest_input = { \"nums\": [80,38] }\nassert my_solution.minimumRightShifts(**test_input) == 1\n\ntest_input = { \"nums\": [52,72,78,83,85,99,20] }\nassert my_solution.minimumRightShifts(**test_input) == 1\n\ntest_input = { \"nums\": [3,6,89] }\nassert my_solution.minimumRightShifts(**test_input) == 0\n\ntest_input = { \"nums\": [3] }\nassert my_solution.minimumRightShifts(**test_input) == 0\n\ntest_input = { \"nums\": [55,56,63,91,3,46] }\nassert my_solution.minimumRightShifts(**test_input) == 2\n\ntest_input = { \"nums\": [58,10,31,37,41] }\nassert my_solution.minimumRightShifts(**test_input) == 4\n\ntest_input = { \"nums\": [17,33,53,58,78] }\nassert my_solution.minimumRightShifts(**test_input) == 0\n\ntest_input = { \"nums\": [82,44] }\nassert my_solution.minimumRightShifts(**test_input) == 1\n\ntest_input = { \"nums\": [89,96,35,48,57,71] }\nassert my_solution.minimumRightShifts(**test_input) == 4\n\ntest_input = { \"nums\": [43,69,4,29,37] }\nassert my_solution.minimumRightShifts(**test_input) == 3\n\ntest_input = { \"nums\": [65,88] }\nassert my_solution.minimumRightShifts(**test_input) == 0\n\ntest_input = { \"nums\": [42,44,59,76,86] }\nassert my_solution.minimumRightShifts(**test_input) == 0\n\ntest_input = { \"nums\": [29,56,78,96,1,10,27] }\nassert my_solution.minimumRightShifts(**test_input) == 3\n\ntest_input = { \"nums\": [48,100] }\nassert my_solution.minimumRightShifts(**test_input) == 0\n\ntest_input = { \"nums\": [4,33,17,3,8,91,28,13,72,42] }\nassert my_solution.minimumRightShifts(**test_input) == -1\n\ntest_input = { \"nums\": [5,35,53,56] }\nassert my_solution.minimumRightShifts(**test_input) == 0\n\ntest_input = { \"nums\": [65,67,70,27,41,50,52,57,60] }\nassert my_solution.minimumRightShifts(**test_input) == 6\n\ntest_input = { \"nums\": [94,32,45,62] }\nassert my_solution.minimumRightShifts(**test_input) == 3\n\ntest_input = { \"nums\": [23,25,34,47,61,65,6,21] }\nassert my_solution.minimumRightShifts(**test_input) == 2\n\ntest_input = { \"nums\": [99,11,12,21,22,55,62,83] }\nassert my_solution.minimumRightShifts(**test_input) == 7\n\ntest_input = { \"nums\": [92,13,33,58,61,85] }\nassert my_solution.minimumRightShifts(**test_input) == 5\n\ntest_input = { \"nums\": [46] }\nassert my_solution.minimumRightShifts(**test_input) == 0\n\ntest_input = { \"nums\": [12,27,30,36] }\nassert my_solution.minimumRightShifts(**test_input) == 0\n\ntest_input = { \"nums\": [33,44,57,16,22,26,30] }\nassert my_solution.minimumRightShifts(**test_input) == 4\n\ntest_input = { \"nums\": [67,24] }\nassert my_solution.minimumRightShifts(**test_input) == 1\n\ntest_input = { \"nums\": [12,44,83,87] }\nassert my_solution.minimumRightShifts(**test_input) == 0\n\ntest_input = { \"nums\": [19,52,3,8,12] }\nassert my_solution.minimumRightShifts(**test_input) == 3\n\ntest_input = { \"nums\": [82,86,88,6,35,47,52,58,62] }\nassert my_solution.minimumRightShifts(**test_input) == 6\n\ntest_input = { \"nums\": [48] }\nassert my_solution.minimumRightShifts(**test_input) == 0\n\ntest_input = { \"nums\": [60,11] }\nassert my_solution.minimumRightShifts(**test_input) == 1\n\ntest_input = { \"nums\": [69,60] }\nassert my_solution.minimumRightShifts(**test_input) == 1\n\ntest_input = { \"nums\": [22,28,36,16,82,77,41,85,44,97] }\nassert my_solution.minimumRightShifts(**test_input) == -1\n\ntest_input = { \"nums\": [63,94,2,14] }\nassert my_solution.minimumRightShifts(**test_input) == 2\n\ntest_input = { \"nums\": [41,45,74,84,90,93,100,18,31] }\nassert my_solution.minimumRightShifts(**test_input) == 2\n\ntest_input = { \"nums\": [21,38,57,64,12] }\nassert my_solution.minimumRightShifts(**test_input) == 1\n\ntest_input = { \"nums\": [99,2,9,17,33,58,59,72] }\nassert my_solution.minimumRightShifts(**test_input) == 7\n\ntest_input = { \"nums\": [36,89,90,98,11,14,23] }\nassert my_solution.minimumRightShifts(**test_input) == 3\n\ntest_input = { \"nums\": [84,90,5,57,78] }\nassert my_solution.minimumRightShifts(**test_input) == 3\n\ntest_input = { \"nums\": [48,73,76,30] }\nassert my_solution.minimumRightShifts(**test_input) == 1\n\ntest_input = { \"nums\": [74] }\nassert my_solution.minimumRightShifts(**test_input) == 0\n\ntest_input = { \"nums\": [21,84,35,65,12,74,30,95,46,23] }\nassert my_solution.minimumRightShifts(**test_input) == -1\n\ntest_input = { \"nums\": [64,76,46,53,54] }\nassert my_solution.minimumRightShifts(**test_input) == 3\n\ntest_input = { \"nums\": [77,84,89,47,52,74] }\nassert my_solution.minimumRightShifts(**test_input) == 3\n\ntest_input = { \"nums\": [12,29,31,52,88,89,10] }\nassert my_solution.minimumRightShifts(**test_input) == 1\n\ntest_input = { \"nums\": [20,25,28,41,57,89] }\nassert my_solution.minimumRightShifts(**test_input) == 0\n\ntest_input = { \"nums\": [1,28,51,59] }\nassert my_solution.minimumRightShifts(**test_input) == 0\n\ntest_input = { \"nums\": [59,76,2,26,49,78,36,70,64,24] }\nassert my_solution.minimumRightShifts(**test_input) == -1\n\ntest_input = { \"nums\": [35,43,49,63,21] }\nassert my_solution.minimumRightShifts(**test_input) == 1\n\ntest_input = { \"nums\": [1,35,38,47,54,56,58,74] }\nassert my_solution.minimumRightShifts(**test_input) == 0\n\ntest_input = { \"nums\": [49,94,97] }\nassert my_solution.minimumRightShifts(**test_input) == 0\n\ntest_input = { \"nums\": [32,30] }\nassert my_solution.minimumRightShifts(**test_input) == 1\n\ntest_input = { \"nums\": [37,36] }\nassert my_solution.minimumRightShifts(**test_input) == 1\n\ntest_input = { \"nums\": [31,41,65,14] }\nassert my_solution.minimumRightShifts(**test_input) == 1\n\ntest_input = { \"nums\": [45,57,73,77,17,30,42,43] }\nassert my_solution.minimumRightShifts(**test_input) == 4\n\ntest_input = { \"nums\": [17,65,11] }\nassert my_solution.minimumRightShifts(**test_input) == 1\n\ntest_input = { \"nums\": [32,84,93,31,61,78,15,52,100,65] }\nassert my_solution.minimumRightShifts(**test_input) == -1\n\ntest_input = { \"nums\": [61,72,90,3,8,17,23,55] }\nassert my_solution.minimumRightShifts(**test_input) == 5\n\ntest_input = { \"nums\": [19,30,44,95,13] }\nassert my_solution.minimumRightShifts(**test_input) == 1\n\ntest_input = { \"nums\": [42,46,66,71,87,3,4,5,14] }\nassert my_solution.minimumRightShifts(**test_input) == 4\n\ntest_input = { \"nums\": [13,57,7] }\nassert my_solution.minimumRightShifts(**test_input) == 1", "start_time": 1694874600} +{"task_id": "biweekly-contest-113-minimum-array-length-after-pair-removals", "url": "https://leetcode.com/problems/minimum-array-length-after-pair-removals", "title": "minimum-array-length-after-pair-removals", "meta": {"questionId": "3081", "questionFrontendId": "2856", "title": "Minimum Array Length After Pair Removals", "titleSlug": "minimum-array-length-after-pair-removals", "isPaidOnly": false, "difficulty": "Medium", "likes": 259, "dislikes": 88, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0 开始的 非递减 整数数组 nums 。\n\n你可以执行以下操作任意次:\n\n * 选择 两个 下标 i 和 j ,满足 i < j 且 nums[i] < nums[j] 。\n * 将 nums 中下标在 i 和 j 处的元素删除。剩余元素按照原来的顺序组成新的数组,下标也重新从 0 开始编号。\n\n请你返回一个整数,表示执行以上操作任意次后(可以执行 0 次),nums 数组的 最小 数组长度。\n\n请注意,nums 数组是按 非降序 排序的。\n\n示例 1:\n\n输入:nums = [1,3,4,9]\n输出:0\n解释:一开始,nums = [1, 3, 4, 9] 。\n第一次操作,我们选择下标 0 和 1 ,满足 nums[0] < nums[1] <=> 1 < 3 。\n删除下标 0 和 1 处的元素,nums 变成 [4, 9] 。\n下一次操作,我们选择下标 0 和 1 ,满足 nums[0] < nums[1] <=> 4 < 9 。\n删除下标 0 和 1 处的元素,nums 变成空数组 [] 。\n所以,可以得到的最小数组长度为 0 。\n\n示例 2:\n\n输入:nums = [2,3,6,9]\n输出:0\n解释:一开始,nums = [2, 3, 6, 9] 。\n第一次操作,我们选择下标 0 和 2 ,满足 nums[0] < nums[2] <=> 2 < 6 。\n删除下标 0 和 2 处的元素,nums 变成 [3, 9] 。\n下一次操作,我们选择下标 0 和 1 ,满足 nums[0] < nums[1] <=> 3 < 9 。\n删除下标 0 和 1 处的元素,nums 变成空数组 [] 。\n所以,可以得到的最小数组长度为 0 。\n\n示例 3:\n\n输入:nums = [1,1,2]\n输出:1\n解释:一开始,nums = [1, 1, 2] 。\n第一次操作,我们选择下标 0 和 2 ,满足 nums[0] < nums[2] <=> 1 < 2 。\n删除下标 0 和 2 处的元素,nums 变成 [1] 。\n无法对数组再执行操作。\n所以,可以得到的最小数组长度为 1 。\n\n\n提示:\n\n * 1 <= nums.length <= 105\n * 1 <= nums[i] <= 109\n * nums 是 非递减 数组。\n\"\"\"\nclass Solution:\n def minLengthAfterRemovals(self, nums: List[int]) -> int:\n ", "prompt_sft": "给你一个下标从 0 开始的 非递减 整数数组 nums 。\n\n你可以执行以下操作任意次:\n\n * 选择 两个 下标 i 和 j ,满足 i < j 且 nums[i] < nums[j] 。\n * 将 nums 中下标在 i 和 j 处的元素删除。剩余元素按照原来的顺序组成新的数组,下标也重新从 0 开始编号。\n\n请你返回一个整数,表示执行以上操作任意次后(可以执行 0 次),nums 数组的 最小 数组长度。\n\n请注意,nums 数组是按 非降序 排序的。\n\n示例 1:\n\n输入:nums = [1,3,4,9]\n输出:0\n解释:一开始,nums = [1, 3, 4, 9] 。\n第一次操作,我们选择下标 0 和 1 ,满足 nums[0] < nums[1] <=> 1 < 3 。\n删除下标 0 和 1 处的元素,nums 变成 [4, 9] 。\n下一次操作,我们选择下标 0 和 1 ,满足 nums[0] < nums[1] <=> 4 < 9 。\n删除下标 0 和 1 处的元素,nums 变成空数组 [] 。\n所以,可以得到的最小数组长度为 0 。\n\n示例 2:\n\n输入:nums = [2,3,6,9]\n输出:0\n解释:一开始,nums = [2, 3, 6, 9] 。\n第一次操作,我们选择下标 0 和 2 ,满足 nums[0] < nums[2] <=> 2 < 6 。\n删除下标 0 和 2 处的元素,nums 变成 [3, 9] 。\n下一次操作,我们选择下标 0 和 1 ,满足 nums[0] < nums[1] <=> 3 < 9 。\n删除下标 0 和 1 处的元素,nums 变成空数组 [] 。\n所以,可以得到的最小数组长度为 0 。\n\n示例 3:\n\n输入:nums = [1,1,2]\n输出:1\n解释:一开始,nums = [1, 1, 2] 。\n第一次操作,我们选择下标 0 和 2 ,满足 nums[0] < nums[2] <=> 1 < 2 。\n删除下标 0 和 2 处的元素,nums 变成 [1] 。\n无法对数组再执行操作。\n所以,可以得到的最小数组长度为 1 。\n\n\n提示:\n\n * 1 <= nums.length <= 105\n * 1 <= nums[i] <= 109\n * nums 是 非递减 数组。\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def minLengthAfterRemovals(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,3,4,9] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [2,3,6,9] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,2] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [1] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [2] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [3] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [5] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [1,1] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 2\n\ntest_input = { \"nums\": [1,2] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [1,4] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [2,3] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [3,3] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 2\n\ntest_input = { \"nums\": [4,5] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,1] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,2] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [1,3,3] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [2,2,2] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 3\n\ntest_input = { \"nums\": [2,3,3] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [2,3,4] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [3,4,5] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,1,1] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 4\n\ntest_input = { \"nums\": [1,1,2,2] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,3,3] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [2,3,3,3] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,1,1,1] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 5\n\ntest_input = { \"nums\": [1,1,2,3,3] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,2,5,6] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [1,3,3,3,4] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [2,3,4,4,4] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,1,1,1,1] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 6\n\ntest_input = { \"nums\": [1,1,2,3,4,4] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,4,4,5,5] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [1,2,2,2,3,3] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [1,2,3,3,3,3] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 2\n\ntest_input = { \"nums\": [3,4,7,8,9,9] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,1,1,1,1,1] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 7\n\ntest_input = { \"nums\": [1,1,1,1,2,2,2] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,1,1,2,3,3] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,1,2,2,3,3] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,1,3,3,3,3] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,2,2,3,3,4] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,2,3,4,5,5] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,3,3,3,3,3] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 3\n\ntest_input = { \"nums\": [2,2,2,3,3,3,3] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,1,1,1,1,1,1] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 8\n\ntest_input = { \"nums\": [1,1,1,1,2,2,2,2] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,2,2,3,3,4,5] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,3,4,4,4,5,5] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [1,2,2,2,4,4,4,5] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [2,3,3,3,4,4,5,5] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,1,1,1,1,1,1,1] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 9\n\ntest_input = { \"nums\": [1,1,1,1,1,1,1,2,2] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 5\n\ntest_input = { \"nums\": [1,1,1,1,2,2,2,3,3] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,1,2,2,2,2,2,2] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,1,5,5,5,5,5,5] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,2,2,2,2,3,3,3] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,2,2,2,3,3,3,3] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,4,4,5,5,5,6,6] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,1,1,1,1,1,1,1,1] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 10\n\ntest_input = { \"nums\": [1,1,1,1,1,2,2,2,3,4] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,1,1,2,2,2,2,2,2] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,2,2,2,3,3,3,3,3] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,2,2,2,3,3,3,3,4] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [1,2,2,4,5,6,6,7,7,8] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,1,1,1,1,1,1,1,1,1] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 11\n\ntest_input = { \"nums\": [1,1,1,1,1,1,2,2,2,2,2] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,1,2,2,2,2,2,2,2,2] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 5\n\ntest_input = { \"nums\": [1,1,1,2,2,2,3,3,3,3,3] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,1,2,2,3,4,6,6,8,8] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,2,2,2,2,2,3,3,3,3] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,2,2,2,2,3,3,3,3,3] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,2,2,2,2,3,3,3,4,4] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,2,2,3,3,4,5,5,6,6] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,1,1,1,1,1,1,1,1,1,1] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 12\n\ntest_input = { \"nums\": [1,1,1,1,1,1,1,1,1,2,2,2] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 6\n\ntest_input = { \"nums\": [1,1,1,1,1,2,2,3,3,4,4,4] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,1,2,2,2,2,2,2,2,2,2] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 6\n\ntest_input = { \"nums\": [1,1,1,2,2,3,3,3,4,5,5,5] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,1,2,4,4,4,4,4,5,6,6] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,2,2,2,2,2,2,2,2,3,3] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 4\n\ntest_input = { \"nums\": [1,1,2,2,2,2,2,3,3,3,5,5] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,2,2,2,3,3,4,4,4,5,5] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,1,1,1,1,1,1,1,1,1,1,1] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 13\n\ntest_input = { \"nums\": [1,1,1,1,1,1,1,2,2,4,4,4,4] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,1,1,1,2,3,3,3,3,3,3,5] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,1,1,2,2,2,2,2,3,3,3,3] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,2,2,3,3,3,3,4,4,4,6,7] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,2,2,2,2,2,3,3,4,6,7,7] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,1,1,1,1,1,1,1,1,1,1,1,1] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 14\n\ntest_input = { \"nums\": [1,1,1,1,1,1,2,2,2,2,3,3,3,3] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,1,1,1,2,2,2,2,2,2,2,2,2] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 4\n\ntest_input = { \"nums\": [1,1,1,2,2,2,3,3,3,4,4,4,5,5] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,1,2,2,3,3,3,3,4,4,5,5,6] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,2,2,2,3,3,3,5,6,7,9,9,10] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [1,3,3,3,3,3,3,3,4,4,4,4,5,5] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [2,2,2,2,2,2,2,3,3,3,3,3,3,3] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,1,1,1,1,1,1,1,1,2,2,2,2,2] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 5\n\ntest_input = { \"nums\": [1,1,1,1,1,1,1,1,1,2,2,2,2,2,2] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,1,1,1,1,2,2,2,4,4,4,5,5,5] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,1,3,5,6,6,7,7,8,8,8,8,9,9] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1", "start_time": 1694874600} +{"task_id": "biweekly-contest-113-count-pairs-of-points-with-distance-k", "url": "https://leetcode.com/problems/count-pairs-of-points-with-distance-k", "title": "count-pairs-of-points-with-distance-k", "meta": {"questionId": "2953", "questionFrontendId": "2857", "title": "Count Pairs of Points With Distance k", "titleSlug": "count-pairs-of-points-with-distance-k", "isPaidOnly": false, "difficulty": "Medium", "likes": 238, "dislikes": 34, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个 二维 整数数组 coordinates 和一个整数 k ,其中 coordinates[i] = [xi, yi] 是第 i 个点在二维平面里的坐标。\n\n我们定义两个点 (x1, y1) 和 (x2, y2) 的 距离 为 (x1 XOR x2) + (y1 XOR y2) ,XOR 指的是按位异或运算。\n\n请你返回满足 i < j 且点 i 和点 j之间距离为 k 的点对数目。\n\n示例 1:\n\n输入:coordinates = [[1,2],[4,2],[1,3],[5,2]], k = 5\n输出:2\n解释:以下点对距离为 k :\n- (0, 1):(1 XOR 4) + (2 XOR 2) = 5 。\n- (2, 3):(1 XOR 5) + (3 XOR 2) = 5 。\n\n示例 2:\n\n输入:coordinates = [[1,3],[1,3],[1,3],[1,3],[1,3]], k = 0\n输出:10\n解释:任何两个点之间的距离都为 0 ,所以总共有 10 组点对。\n\n\n提示:\n\n * 2 <= coordinates.length <= 50000\n * 0 <= xi, yi <= 106\n * 0 <= k <= 100\n\"\"\"\nclass Solution:\n def countPairs(self, coordinates: List[List[int]], k: int) -> int:\n ", "prompt_sft": "给你一个 二维 整数数组 coordinates 和一个整数 k ,其中 coordinates[i] = [xi, yi] 是第 i 个点在二维平面里的坐标。\n\n我们定义两个点 (x1, y1) 和 (x2, y2) 的 距离 为 (x1 XOR x2) + (y1 XOR y2) ,XOR 指的是按位异或运算。\n\n请你返回满足 i < j 且点 i 和点 j之间距离为 k 的点对数目。\n\n示例 1:\n\n输入:coordinates = [[1,2],[4,2],[1,3],[5,2]], k = 5\n输出:2\n解释:以下点对距离为 k :\n- (0, 1):(1 XOR 4) + (2 XOR 2) = 5 。\n- (2, 3):(1 XOR 5) + (3 XOR 2) = 5 。\n\n示例 2:\n\n输入:coordinates = [[1,3],[1,3],[1,3],[1,3],[1,3]], k = 0\n输出:10\n解释:任何两个点之间的距离都为 0 ,所以总共有 10 组点对。\n\n\n提示:\n\n * 2 <= coordinates.length <= 50000\n * 0 <= xi, yi <= 106\n * 0 <= k <= 100\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def countPairs(self, coordinates: List[List[int]], k: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"coordinates\": [[1,2],[4,2],[1,3],[5,2]], \"k\": 5 }\nassert my_solution.countPairs(**test_input) == 2\n\ntest_input = { \"coordinates\": [[1,3],[1,3],[1,3],[1,3],[1,3]], \"k\": 0 }\nassert my_solution.countPairs(**test_input) == 10\n\ntest_input = { \"coordinates\": [[27,94],[61,68],[47,0],[100,4],[127,89],[61,103],[26,4],[51,54],[91,26],[98,23],[80,74],[19,93]], \"k\": 95 }\nassert my_solution.countPairs(**test_input) == 5\n\ntest_input = { \"coordinates\": [[39,29],[98,59],[65,77],[41,26],[95,12],[71,66],[41,93],[28,33],[96,40],[39,8],[106,54],[8,49],[68,59],[21,15],[3,66],[77,85],[111,51]], \"k\": 21 }\nassert my_solution.countPairs(**test_input) == 6\n\ntest_input = { \"coordinates\": [[100,32],[69,8],[85,31],[69,47],[62,34],[102,43],[81,39],[90,0],[123,6],[79,18],[21,94],[13,36],[49,97],[76,59],[42,74],[60,68],[21,11],[71,21],[64,13],[64,95],[5,85],[118,53],[70,44],[38,57],[32,119],[80,61],[13,68],[43,108],[86,49]], \"k\": 39 }\nassert my_solution.countPairs(**test_input) == 20\n\ntest_input = { \"coordinates\": [[60,55],[35,32],[99,2],[58,57],[16,2],[43,28],[30,35],[35,83],[104,41],[20,69],[58,14],[12,92],[71,49],[7,82],[65,68],[9,40],[15,56],[57,46],[21,8],[37,64],[42,94],[73,91],[12,121],[10,21],[41,89]], \"k\": 54 }\nassert my_solution.countPairs(**test_input) == 10\n\ntest_input = { \"coordinates\": [[94,23],[86,58],[126,55],[107,23],[121,60],[89,28],[123,15],[127,3],[100,49],[5,3],[81,49],[93,0],[95,37],[92,25]], \"k\": 53 }\nassert my_solution.countPairs(**test_input) == 18\n\ntest_input = { \"coordinates\": [[40,54],[8,68],[33,11],[51,93],[95,95],[17,53],[35,39],[59,42],[28,63],[41,63],[54,0],[88,31],[5,107],[32,124],[74,64],[15,27],[61,92],[16,47],[62,22],[2,28],[27,14],[53,39],[21,91],[7,11]], \"k\": 60 }\nassert my_solution.countPairs(**test_input) == 11\n\ntest_input = { \"coordinates\": [[28,14],[2,13],[28,14],[4,7],[23,1],[54,0],[43,22],[98,16]], \"k\": 33 }\nassert my_solution.countPairs(**test_input) == 5\n\ntest_input = { \"coordinates\": [[84,92],[84,92],[84,92],[84,92],[84,92],[54,59],[84,92],[93,44]], \"k\": 0 }\nassert my_solution.countPairs(**test_input) == 15\n\ntest_input = { \"coordinates\": [[10,57],[12,62],[92,44],[7,60],[8,55],[13,50],[5,55],[71,82],[64,26],[68,43],[61,88],[9,44],[95,16],[17,16],[12,53],[9,59],[81,44],[3,56],[70,94],[0,58],[84,29],[13,63],[79,87],[19,39],[74,35],[92,7],[31,6],[2,50]], \"k\": 13 }\nassert my_solution.countPairs(**test_input) == 19\n\ntest_input = { \"coordinates\": [[56,47],[26,50],[51,2],[40,7],[24,34],[55,2],[13,92],[57,50],[47,35],[32,96],[14,0],[4,84],[86,95]], \"k\": 56 }\nassert my_solution.countPairs(**test_input) == 4\n\ntest_input = { \"coordinates\": [[34,60],[17,93],[87,90],[32,125],[71,27],[27,26],[127,115],[91,27],[63,68],[97,48],[69,73],[120,78],[43,55],[101,125],[86,87],[12,35],[5,20],[46,12],[17,24],[107,62],[86,88],[26,80],[30,41],[110,114]], \"k\": 81 }\nassert my_solution.countPairs(**test_input) == 17\n\ntest_input = { \"coordinates\": [[65,19],[12,80],[90,64],[38,68],[17,25],[49,36],[91,47],[20,31],[81,54],[83,20],[90,100],[0,6],[93,121]], \"k\": 36 }\nassert my_solution.countPairs(**test_input) == 3\n\ntest_input = { \"coordinates\": [[24,75],[22,67]], \"k\": 23 }\nassert my_solution.countPairs(**test_input) == 0\n\ntest_input = { \"coordinates\": [[42,32],[62,60],[57,61],[100,56],[91,62],[57,21],[100,56],[63,63],[45,52],[59,75],[32,61],[57,43],[61,57],[64,52],[24,54],[92,15],[53,25],[84,63],[1,18],[21,57],[29,9],[68,91],[22,43],[105,27]], \"k\": 48 }\nassert my_solution.countPairs(**test_input) == 18\n\ntest_input = { \"coordinates\": [[70,98],[79,66],[71,63],[111,94],[3,50],[64,111],[98,67],[23,41],[66,14],[40,19],[15,13],[32,86],[59,58],[73,94],[18,10],[77,50],[20,60],[66,8],[15,30],[71,2],[55,9]], \"k\": 60 }\nassert my_solution.countPairs(**test_input) == 7\n\ntest_input = { \"coordinates\": [[5,100],[60,9],[84,65],[38,66],[83,35],[17,80],[88,76],[80,101],[55,74],[46,62],[28,73],[54,40],[119,71],[10,94],[45,82],[20,90],[47,27],[41,97],[66,5],[33,0],[101,5],[89,125],[6,58],[61,107],[25,17],[104,0],[29,2]], \"k\": 73 }\nassert my_solution.countPairs(**test_input) == 15\n\ntest_input = { \"coordinates\": [[29,23],[8,19],[26,5],[12,25],[37,2],[37,27],[18,68],[3,53],[81,85],[27,94],[29,39],[41,64],[26,28],[23,80],[13,46],[5,68],[16,18],[21,77]], \"k\": 25 }\nassert my_solution.countPairs(**test_input) == 8\n\ntest_input = { \"coordinates\": [[90,31],[113,54],[92,36],[67,49],[123,124],[127,112],[16,24],[85,50],[58,94],[115,48],[83,30],[51,112],[39,23],[0,21],[27,44],[99,100],[122,63],[34,39],[25,48],[44,49],[84,97],[31,61]], \"k\": 84 }\nassert my_solution.countPairs(**test_input) == 10\n\ntest_input = { \"coordinates\": [[51,47],[51,47],[8,14],[82,68],[55,85],[8,14],[51,47],[87,97],[75,65],[78,10],[51,47],[87,97],[74,19],[51,47],[56,66],[8,14],[78,10],[74,66],[65,92],[51,47],[3,31]], \"k\": 0 }\nassert my_solution.countPairs(**test_input) == 20\n\ntest_input = { \"coordinates\": [[25,82],[86,89],[25,82],[47,118],[14,58],[22,51],[0,93],[26,9],[67,27],[43,22],[78,49],[82,15],[93,22],[67,34],[54,43],[61,55],[74,77],[115,108],[54,55],[9,30],[31,3],[26,5],[60,49]], \"k\": 90 }\nassert my_solution.countPairs(**test_input) == 22\n\ntest_input = { \"coordinates\": [[29,23],[48,3],[58,62],[16,19],[0,30],[59,5],[96,50],[7,46],[5,18],[42,32],[78,55]], \"k\": 17 }\nassert my_solution.countPairs(**test_input) == 3\n\ntest_input = { \"coordinates\": [[47,68],[55,68],[36,73],[33,70],[36,81],[60,81],[32,18],[38,95],[34,75],[33,5],[33,78],[32,10],[36,93],[56,77],[43,17],[99,70],[15,77],[42,87],[30,18],[36,56],[47,68],[45,70],[48,77],[53,94],[0,86],[53,9],[68,35],[32,77],[95,90]], \"k\": 24 }\nassert my_solution.countPairs(**test_input) == 31\n\ntest_input = { \"coordinates\": [[5,100],[19,21],[83,36],[24,59],[92,49],[6,73],[57,78],[69,33],[3,81],[53,59],[23,40],[6,21],[57,55],[98,43],[33,15],[8,83],[29,29],[85,41],[47,64],[10,32],[82,94],[14,29],[13,99],[19,20],[85,108],[41,9]], \"k\": 78 }\nassert my_solution.countPairs(**test_input) == 12\n\ntest_input = { \"coordinates\": [[8,94],[19,13],[72,75],[17,8],[57,45],[17,15],[14,95],[74,78],[17,15],[9,95],[79,76],[13,91],[28,76],[94,12],[11,90],[94,11],[94,11],[15,89],[20,13],[23,14],[22,8],[21,71]], \"k\": 7 }\nassert my_solution.countPairs(**test_input) == 24\n\ntest_input = { \"coordinates\": [[37,76],[109,71],[66,1],[55,6],[90,22],[71,24],[3,19],[46,24],[74,74],[85,94],[2,96],[1,48],[31,86],[22,78],[93,80],[3,112],[11,11],[98,18],[81,86],[55,54],[82,18],[127,23]], \"k\": 83 }\nassert my_solution.countPairs(**test_input) == 11\n\ntest_input = { \"coordinates\": [[9,25],[56,25],[7,58],[9,48],[77,55],[6,10],[33,98],[22,26],[41,57],[18,4],[40,74]], \"k\": 49 }\nassert my_solution.countPairs(**test_input) == 8\n\ntest_input = { \"coordinates\": [[91,12],[86,8],[74,12],[85,58],[65,10],[49,51],[43,83],[34,91],[89,63],[26,44],[68,6],[71,8],[92,12],[49,79],[64,26],[0,87],[22,85],[15,72],[17,54],[33,37],[70,9],[88,95],[85,67],[32,85],[94,69],[87,77]], \"k\": 17 }\nassert my_solution.countPairs(**test_input) == 16\n\ntest_input = { \"coordinates\": [[54,60],[31,62],[76,56],[79,44]], \"k\": 52 }\nassert my_solution.countPairs(**test_input) == 0\n\ntest_input = { \"coordinates\": [[41,13],[15,74],[43,51],[44,10],[49,72],[63,48],[50,40],[90,86],[105,13],[11,118],[55,8],[3,39],[27,3],[55,72],[33,98],[10,59],[40,45],[10,59],[40,30],[97,43],[96,55],[47,32],[43,86],[57,61],[1,64]], \"k\": 64 }\nassert my_solution.countPairs(**test_input) == 23\n\ntest_input = { \"coordinates\": [[29,96],[82,101],[1,88],[9,100],[55,42],[37,77],[89,95],[40,10],[111,114],[89,53],[91,33],[93,18],[90,14],[50,49],[27,91],[99,92],[26,15],[69,17],[61,64]], \"k\": 84 }\nassert my_solution.countPairs(**test_input) == 7\n\ntest_input = { \"coordinates\": [[57,88],[83,2],[82,23],[19,7],[43,84],[54,87],[51,38],[61,68],[68,31],[74,49],[64,80],[2,19],[18,73],[52,73],[75,26],[32,71],[91,83],[84,15],[49,76]], \"k\": 30 }\nassert my_solution.countPairs(**test_input) == 8\n\ntest_input = { \"coordinates\": [[34,96],[53,25],[97,70],[48,31],[48,20],[54,26],[42,99],[52,24],[56,100],[35,106],[16,71],[34,69],[42,72],[28,8],[35,97],[103,67],[12,81],[8,86]], \"k\": 11 }\nassert my_solution.countPairs(**test_input) == 10\n\ntest_input = { \"coordinates\": [[60,56],[48,34],[21,82],[63,26],[97,51],[35,63],[39,29],[5,46],[16,115],[19,71],[34,54],[6,65],[11,21],[54,66],[2,103],[13,64],[30,73],[23,58],[31,75],[6,63],[16,66],[21,100]], \"k\": 38 }\nassert my_solution.countPairs(**test_input) == 10\n\ntest_input = { \"coordinates\": [[5,28],[16,39],[38,16],[21,34],[5,22],[73,52],[3,24],[24,37],[11,26]], \"k\": 10 }\nassert my_solution.countPairs(**test_input) == 5\n\ntest_input = { \"coordinates\": [[34,76],[50,71],[55,74],[36,6],[56,77],[56,86],[9,25],[7,38],[34,76],[96,85],[29,32]], \"k\": 27 }\nassert my_solution.countPairs(**test_input) == 8\n\ntest_input = { \"coordinates\": [[69,99],[60,80],[59,72],[74,67],[34,78],[73,95],[65,72],[86,64],[42,89],[90,25],[84,48]], \"k\": 31 }\nassert my_solution.countPairs(**test_input) == 8\n\ntest_input = { \"coordinates\": [[50,75],[84,10],[3,1],[8,12],[41,82],[68,39],[55,31],[4,103],[50,19],[15,85],[20,50],[118,81],[47,14],[1,40],[1,58],[8,58],[18,110],[62,10],[98,69],[25,31],[99,10],[74,29],[124,73]], \"k\": 98 }\nassert my_solution.countPairs(**test_input) == 15\n\ntest_input = { \"coordinates\": [[65,100],[43,13],[80,116],[40,82],[50,5],[53,14],[62,16],[38,8],[83,107],[56,11],[82,92],[62,16],[59,21],[38,8],[55,50],[67,76],[36,65]], \"k\": 33 }\nassert my_solution.countPairs(**test_input) == 14\n\ntest_input = { \"coordinates\": [[52,32],[42,21],[1,56],[93,52],[85,87],[14,58],[39,21],[3,105],[18,13],[5,119],[108,77],[91,81],[22,71],[76,39],[2,59],[23,54],[83,26],[28,23],[33,69],[27,91],[92,19],[53,5],[39,32],[14,124]], \"k\": 83 }\nassert my_solution.countPairs(**test_input) == 21\n\ntest_input = { \"coordinates\": [[84,63],[92,55],[56,94],[89,27],[53,93],[85,80],[65,91],[77,16],[28,99],[48,86],[54,44],[33,47],[47,10],[11,62],[2,17]], \"k\": 16 }\nassert my_solution.countPairs(**test_input) == 4\n\ntest_input = { \"coordinates\": [[78,84],[91,79],[1,35],[73,76],[89,92],[69,94],[78,1],[27,71],[17,58],[18,33],[82,67],[24,59],[23,53],[82,86]], \"k\": 21 }\nassert my_solution.countPairs(**test_input) == 8\n\ntest_input = { \"coordinates\": [[29,53],[40,74],[42,73],[24,53],[79,50],[13,7],[43,72],[26,54],[41,75],[66,27],[43,72],[81,75],[47,73],[74,43],[97,60],[42,76],[46,77],[21,69],[88,77]], \"k\": 5 }\nassert my_solution.countPairs(**test_input) == 16\n\ntest_input = { \"coordinates\": [[21,95],[53,15],[71,7],[22,40],[8,89],[66,62]], \"k\": 74 }\nassert my_solution.countPairs(**test_input) == 1\n\ntest_input = { \"coordinates\": [[93,3],[89,13],[70,48],[75,6],[43,82],[121,49],[80,1],[122,45],[57,45],[96,96],[86,82],[46,62],[63,79],[10,6],[55,36],[63,61],[79,99]], \"k\": 92 }\nassert my_solution.countPairs(**test_input) == 8\n\ntest_input = { \"coordinates\": [[0,36],[77,49],[25,41]], \"k\": 98 }\nassert my_solution.countPairs(**test_input) == 1\n\ntest_input = { \"coordinates\": [[42,18],[48,0],[64,62],[61,7],[33,51],[50,26],[1,91],[24,92]], \"k\": 44 }\nassert my_solution.countPairs(**test_input) == 4\n\ntest_input = { \"coordinates\": [[69,94],[83,39],[2,37],[117,117],[82,54],[20,84],[91,88],[67,63],[43,69],[109,42],[9,69],[46,42],[60,99],[69,74],[81,80],[12,19]], \"k\": 91 }\nassert my_solution.countPairs(**test_input) == 11\n\ntest_input = { \"coordinates\": [[75,44],[90,42],[62,96],[80,91],[82,78],[77,42]], \"k\": 23 }\nassert my_solution.countPairs(**test_input) == 3\n\ntest_input = { \"coordinates\": [[81,20],[74,53],[70,49],[99,66],[11,88]], \"k\": 60 }\nassert my_solution.countPairs(**test_input) == 2\n\ntest_input = { \"coordinates\": [[33,37],[35,52],[49,38],[47,32],[98,98],[84,83],[50,54],[45,34],[105,106],[54,44],[80,57],[96,80],[83,81],[36,22]], \"k\": 19 }\nassert my_solution.countPairs(**test_input) == 7\n\ntest_input = { \"coordinates\": [[45,38],[47,5],[13,69],[88,65],[123,11],[15,30],[91,45],[66,100],[25,50],[63,10],[46,70],[36,77],[27,9],[78,91]], \"k\": 98 }\nassert my_solution.countPairs(**test_input) == 6\n\ntest_input = { \"coordinates\": [[71,58],[60,37],[27,97],[7,56],[56,126],[24,59],[46,76],[15,79],[18,3],[98,8],[110,62],[76,30],[38,63]], \"k\": 66 }\nassert my_solution.countPairs(**test_input) == 8\n\ntest_input = { \"coordinates\": [[21,80],[17,111],[0,126],[20,81],[50,76],[80,32],[7,97],[21,19],[50,91],[58,68],[55,4],[37,56],[20,42],[6,35],[38,72],[96,6],[11,70],[10,91],[11,94],[46,88],[81,64],[37,78],[15,75],[90,79],[13,103],[46,66],[2,95]], \"k\": 67 }\nassert my_solution.countPairs(**test_input) == 26\n\ntest_input = { \"coordinates\": [[65,15],[73,72],[60,97],[101,107],[3,2],[4,20],[90,74],[71,7],[113,95],[39,17],[87,56],[2,76],[27,122],[48,41]], \"k\": 79 }\nassert my_solution.countPairs(**test_input) == 9\n\ntest_input = { \"coordinates\": [[82,41],[27,65],[94,92],[15,82],[56,69],[30,57],[28,28],[5,53],[100,2],[112,44],[23,6],[92,29],[18,69],[124,26],[125,88],[97,54],[7,31],[50,80]], \"k\": 39 }\nassert my_solution.countPairs(**test_input) == 7\n\ntest_input = { \"coordinates\": [[72,31],[86,19],[63,97],[11,118],[8,67],[14,6],[6,69],[51,1],[70,34],[98,68],[84,29],[47,37],[94,75],[73,15],[34,59],[71,42],[45,98],[22,52],[70,94],[67,78],[64,110],[104,5],[65,28],[87,100],[93,10]], \"k\": 75 }\nassert my_solution.countPairs(**test_input) == 10\n\ntest_input = { \"coordinates\": [[90,16],[30,5],[16,71],[21,75],[33,55],[76,76],[16,50],[19,42],[18,59],[30,46],[6,21],[19,73],[35,78],[36,98],[30,77],[6,65],[87,31],[69,46],[62,42],[14,50],[44,29],[86,56]], \"k\": 17 }\nassert my_solution.countPairs(**test_input) == 5\n\ntest_input = { \"coordinates\": [[27,30],[15,52],[26,30],[26,30],[15,53],[75,57],[27,30],[95,67],[26,31],[27,31],[15,53],[90,84],[27,30],[90,85],[10,3],[48,59]], \"k\": 1 }\nassert my_solution.countPairs(**test_input) == 15\n\ntest_input = { \"coordinates\": [[6,12],[53,6],[16,65],[22,42],[66,85]], \"k\": 54 }\nassert my_solution.countPairs(**test_input) == 1\n\ntest_input = { \"coordinates\": [[45,11],[43,19],[35,27],[43,13],[38,28],[41,59],[68,39],[29,47]], \"k\": 30 }\nassert my_solution.countPairs(**test_input) == 5\n\ntest_input = { \"coordinates\": [[39,98],[1,97],[41,90],[1,83],[65,2],[7,27],[79,51],[124,88],[32,97]], \"k\": 87 }\nassert my_solution.countPairs(**test_input) == 2\n\ntest_input = { \"coordinates\": [[54,49],[98,5],[98,25],[75,53],[117,42],[111,6],[31,85],[124,49],[120,115]], \"k\": 70 }\nassert my_solution.countPairs(**test_input) == 4\n\ntest_input = { \"coordinates\": [[33,9],[59,5],[71,12],[36,2],[6,92],[32,81],[45,72],[54,67],[17,83],[64,19],[24,68],[58,56],[69,87],[76,23],[86,14],[40,25],[50,38],[50,71]], \"k\": 38 }\nassert my_solution.countPairs(**test_input) == 8\n\ntest_input = { \"coordinates\": [[7,7],[44,51],[93,41],[43,37],[31,2],[39,52],[12,68],[92,78],[59,78],[95,70],[62,45],[30,79],[7,17],[3,89],[60,35]], \"k\": 29 }\nassert my_solution.countPairs(**test_input) == 6\n\ntest_input = { \"coordinates\": [[77,91],[3,84],[91,18],[83,18],[56,94],[92,19],[69,83],[88,0],[73,95],[65,87],[95,89],[90,90],[19,36],[94,1],[20,18],[14,62],[77,62],[76,92],[14,55],[22,39],[75,95],[94,17],[21,38]], \"k\": 8 }\nassert my_solution.countPairs(**test_input) == 10\n\ntest_input = { \"coordinates\": [[27,49],[44,38],[99,7],[32,33],[60,98],[98,84],[93,89],[85,80]], \"k\": 95 }\nassert my_solution.countPairs(**test_input) == 1\n\ntest_input = { \"coordinates\": [[86,74],[117,67],[106,78],[66,82],[15,75],[76,72],[116,64],[85,51],[109,87],[75,69],[103,89],[80,20],[101,95],[124,76],[91,53],[100,84],[112,108],[45,94],[14,96]], \"k\": 44 }\nassert my_solution.countPairs(**test_input) == 19\n\ntest_input = { \"coordinates\": [[43,81],[53,103],[106,66],[75,67],[88,96],[112,90],[23,87],[26,70],[75,78],[102,100],[82,15],[69,5],[32,106],[38,116],[10,32],[48,46],[7,93],[61,43],[11,38],[4,99],[58,4],[29,10],[28,6],[40,80],[7,110],[95,91],[24,56],[92,53]], \"k\": 84 }\nassert my_solution.countPairs(**test_input) == 19\n\ntest_input = { \"coordinates\": [[28,78],[90,77],[51,40],[67,125],[31,62],[19,116],[3,79],[61,5],[39,7],[27,9],[56,33],[100,69],[30,72],[0,66],[17,54],[123,6],[87,72],[11,25],[24,49],[103,81],[37,58],[26,53],[23,45],[120,1],[39,96],[58,84],[97,5]], \"k\": 73 }\nassert my_solution.countPairs(**test_input) == 17\n\ntest_input = { \"coordinates\": [[63,22],[10,98],[61,3],[7,4],[0,111],[56,17],[50,11],[30,97],[16,2],[59,77],[4,48],[42,94],[63,1],[42,3],[13,9],[27,100],[60,30],[1,34],[54,43],[3,32],[15,60],[39,9],[52,82],[19,7],[42,82],[88,96]], \"k\": 23 }\nassert my_solution.countPairs(**test_input) == 18\n\ntest_input = { \"coordinates\": [[76,84],[58,43],[15,66],[83,35],[38,10],[12,44],[70,34],[20,36],[13,29],[17,24],[53,100]], \"k\": 61 }\nassert my_solution.countPairs(**test_input) == 3\n\ntest_input = { \"coordinates\": [[5,32],[28,98],[26,96],[30,100],[29,101],[32,50],[0,73],[29,101],[65,92],[54,15],[1,36],[68,46],[98,62],[67,90],[28,98],[12,81],[16,83],[55,77],[49,14],[0,12],[25,101],[27,99],[4,47],[19,99],[63,62],[56,92]], \"k\": 8 }\nassert my_solution.countPairs(**test_input) == 18\n\ntest_input = { \"coordinates\": [[95,54],[53,94],[90,47],[89,90],[90,47],[73,36],[73,84],[72,49],[63,91],[39,66],[57,80],[80,59]], \"k\": 30 }\nassert my_solution.countPairs(**test_input) == 8\n\ntest_input = { \"coordinates\": [[66,53],[64,2],[94,55],[85,23],[74,7],[18,83],[32,95],[55,13],[81,34],[25,125],[73,75],[49,32],[57,19],[0,19],[72,79],[65,8],[118,38],[44,44],[68,16],[62,62],[0,116],[60,21]], \"k\": 57 }\nassert my_solution.countPairs(**test_input) == 7\n\ntest_input = { \"coordinates\": [[38,73],[37,117],[95,92],[28,22],[16,64],[53,0],[65,85],[91,16],[82,28],[57,9],[53,75],[47,45],[30,43],[91,47],[56,94],[53,39]], \"k\": 63 }\nassert my_solution.countPairs(**test_input) == 5\n\ntest_input = { \"coordinates\": [[11,11],[96,86],[86,64],[94,11],[121,100],[68,1],[84,54],[21,40],[8,3],[96,44],[96,127],[42,25],[43,119],[94,10],[71,0],[84,96],[79,73],[37,11],[74,15],[4,53],[27,59],[0,67]], \"k\": 83 }\nassert my_solution.countPairs(**test_input) == 13\n\ntest_input = { \"coordinates\": [[0,8],[45,94],[87,72],[12,98],[4,16],[91,88],[26,100],[8,31],[56,89],[13,54],[22,26],[2,18],[7,36],[19,13],[61,72],[44,10],[44,87],[1,38],[25,23],[24,36],[21,50],[27,13],[95,68],[15,13],[54,68],[5,62]], \"k\": 28 }\nassert my_solution.countPairs(**test_input) == 17\n\ntest_input = { \"coordinates\": [[97,95],[100,90],[99,87],[100,80],[102,82],[4,7],[0,69],[99,89]], \"k\": 10 }\nassert my_solution.countPairs(**test_input) == 6\n\ntest_input = { \"coordinates\": [[22,68],[75,70],[67,78]], \"k\": 95 }\nassert my_solution.countPairs(**test_input) == 2\n\ntest_input = { \"coordinates\": [[36,33],[73,78],[41,27],[58,34],[10,67]], \"k\": 80 }\nassert my_solution.countPairs(**test_input) == 1\n\ntest_input = { \"coordinates\": [[2,37],[39,2],[12,57],[33,38],[73,36],[85,22],[9,95],[31,64],[22,3]], \"k\": 76 }\nassert my_solution.countPairs(**test_input) == 4\n\ntest_input = { \"coordinates\": [[44,0],[95,53],[37,6],[40,4],[5,73],[33,2],[16,71],[36,8],[87,50],[31,71],[83,57],[4,31],[35,79],[12,70],[93,55],[21,77],[97,9],[95,53],[10,73],[78,100],[22,48],[87,50],[74,64]], \"k\": 15 }\nassert my_solution.countPairs(**test_input) == 17\n\ntest_input = { \"coordinates\": [[16,39],[17,57],[14,38],[22,62],[69,40],[2,53],[23,63],[20,35],[25,49]], \"k\": 31 }\nassert my_solution.countPairs(**test_input) == 15\n\ntest_input = { \"coordinates\": [[0,46],[13,69],[38,80],[60,17],[72,83],[27,78],[21,9],[9,29],[84,39],[59,117],[79,65],[1,116],[90,71],[53,91],[46,3],[100,73],[105,23],[12,81],[113,84],[111,25],[27,1],[48,49],[51,53],[93,83],[48,29],[27,21],[9,71]], \"k\": 91 }\nassert my_solution.countPairs(**test_input) == 19\n\ntest_input = { \"coordinates\": [[50,93],[12,98],[26,22],[50,19],[20,70],[53,119],[1,127],[38,100],[52,116],[89,71],[9,98],[34,94],[12,98],[29,119],[60,29],[97,81],[102,84],[13,15],[10,28],[40,26],[16,87],[45,83],[55,83],[62,35],[30,94],[7,75],[14,86],[16,12],[73,88],[60,124]], \"k\": 78 }\nassert my_solution.countPairs(**test_input) == 26\n\ntest_input = { \"coordinates\": [[19,26],[2,28],[3,10],[42,61],[56,56]], \"k\": 23 }\nassert my_solution.countPairs(**test_input) == 3\n\ntest_input = { \"coordinates\": [[56,55],[42,83],[35,97],[28,32],[52,76],[34,20],[68,88],[90,38],[99,76],[32,20],[22,85],[50,34],[4,11],[17,92],[59,80],[66,65],[47,60]], \"k\": 59 }\nassert my_solution.countPairs(**test_input) == 6\n\ntest_input = { \"coordinates\": [[87,78],[72,88],[82,69],[88,79],[36,24],[42,15],[66,94],[32,10],[92,71],[46,89],[74,86],[37,23],[61,44],[66,87],[35,17],[91,78],[43,15],[61,75],[62,70],[61,70],[34,7],[85,64],[35,20],[42,22],[41,27],[82,85],[90,89],[41,13]], \"k\": 16 }\nassert my_solution.countPairs(**test_input) == 20\n\ntest_input = { \"coordinates\": [[48,86],[98,33],[46,68],[91,21],[39,73]], \"k\": 22 }\nassert my_solution.countPairs(**test_input) == 1\n\ntest_input = { \"coordinates\": [[71,47],[68,44],[65,45],[97,43],[97,45],[97,45],[71,41],[103,43],[96,20],[99,41],[57,4],[17,77],[68,44],[16,72],[17,75],[64,69],[19,75],[99,41],[2,21],[71,47],[91,4],[57,2]], \"k\": 6 }\nassert my_solution.countPairs(**test_input) == 21\n\ntest_input = { \"coordinates\": [[5,11],[16,87],[48,55],[26,15],[41,58],[12,14],[81,66],[30,5]], \"k\": 14 }\nassert my_solution.countPairs(**test_input) == 2\n\ntest_input = { \"coordinates\": [[85,89],[119,89],[34,16],[54,41],[55,29],[33,34],[54,30],[80,74],[12,92],[42,49],[69,7],[47,13],[26,38],[39,96],[61,58],[24,48],[46,47]], \"k\": 34 }\nassert my_solution.countPairs(**test_input) == 6\n\ntest_input = { \"coordinates\": [[35,45],[58,17],[64,60],[117,23],[18,63],[26,55],[65,54]], \"k\": 85 }\nassert my_solution.countPairs(**test_input) == 4\n\ntest_input = { \"coordinates\": [[60,1],[57,6],[39,3],[58,7],[61,14],[19,80],[46,0],[84,35],[43,3],[46,4],[48,71],[48,75],[85,40],[46,45],[6,20],[35,7],[57,6],[51,78],[68,25],[17,0]], \"k\": 12 }\nassert my_solution.countPairs(**test_input) == 12\n\ntest_input = { \"coordinates\": [[95,0],[36,24],[68,27],[80,14],[39,2],[93,52],[107,52],[86,63],[82,13],[55,14],[8,52],[99,20],[101,36],[50,70],[26,98],[95,41]], \"k\": 54 }\nassert my_solution.countPairs(**test_input) == 8\n\ntest_input = { \"coordinates\": [[43,14],[55,83],[33,89],[44,74],[46,84],[51,87],[61,69],[1,89]], \"k\": 32 }\nassert my_solution.countPairs(**test_input) == 10\n\ntest_input = { \"coordinates\": [[88,15],[93,65],[52,39],[20,24],[100,36],[39,17],[26,77],[52,39],[47,83],[98,99],[43,28],[72,29],[21,48],[43,32],[60,108],[44,47],[45,125],[84,94]], \"k\": 83 }\nassert my_solution.countPairs(**test_input) == 13\n\ntest_input = { \"coordinates\": [[12,2],[43,87],[21,100],[79,63],[5,6],[70,75],[20,55],[23,55],[17,31],[121,89],[27,71],[27,22],[42,34],[15,14],[16,40],[49,68],[30,48],[45,43],[88,23],[47,15],[16,41],[8,5]], \"k\": 81 }\nassert my_solution.countPairs(**test_input) == 8", "start_time": 1694874600} +{"task_id": "biweekly-contest-113-minimum-edge-reversals-so-every-node-is-reachable", "url": "https://leetcode.com/problems/minimum-edge-reversals-so-every-node-is-reachable", "title": "minimum-edge-reversals-so-every-node-is-reachable", "meta": {"questionId": "3105", "questionFrontendId": "2858", "title": "Minimum Edge Reversals So Every Node Is Reachable", "titleSlug": "minimum-edge-reversals-so-every-node-is-reachable", "isPaidOnly": false, "difficulty": "Hard", "likes": 227, "dislikes": 3, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个 n 个点的 简单有向图 (没有重复边的有向图),节点编号为 0 到 n - 1 。如果这些边是双向边,那么这个图形成一棵 树 。\n\n给你一个整数 n 和一个 二维 整数数组 edges ,其中 edges[i] = [ui, vi] 表示从节点 ui 到节点 vi 有一条 有向边 。\n\n边反转 指的是将一条边的方向反转,也就是说一条从节点 ui 到节点 vi 的边会变为一条从节点 vi 到节点 ui 的边。\n\n对于范围 [0, n - 1] 中的每一个节点 i ,你的任务是分别 独立 计算 最少 需要多少次 边反转 ,从节点 i 出发经过 一系列有向边 ,可以到达所有的节点。\n\n请你返回一个长度为 n 的整数数组 answer ,其中 answer[i]表示从节点 i 出发,可以到达所有节点的 最少边反转 次数。\n\n示例 1:\n\n[https://assets.leetcode.com/uploads/2023/08/26/image-20230826221104-3.png]\n\n输入:n = 4, edges = [[2,0],[2,1],[1,3]]\n输出:[1,1,0,2]\n解释:上图表示了与输入对应的简单有向图。\n对于节点 0 :反转 [2,0] ,从节点 0 出发可以到达所有节点。\n所以 answer[0] = 1 。\n对于节点 1 :反转 [2,1] ,从节点 1 出发可以到达所有节点。\n所以 answer[1] = 1 。\n对于节点 2 :不需要反转就可以从节点 2 出发到达所有节点。\n所以 answer[2] = 0 。\n对于节点 3 :反转 [1,3] 和 [2,1] ,从节点 3 出发可以到达所有节点。\n所以 answer[3] = 2 。\n\n示例 2:\n\n[https://assets.leetcode.com/uploads/2023/08/26/image-20230826225541-2.png]\n\n输入:n = 3, edges = [[1,2],[2,0]]\n输出:[2,0,1]\n解释:上图表示了与输入对应的简单有向图。\n对于节点 0 :反转 [2,0] 和 [1,2] ,从节点 0 出发可以到达所有节点。\n所以 answer[0] = 2 。\n对于节点 1 :不需要反转就可以从节点 2 出发到达所有节点。\n所以 answer[1] = 0 。\n对于节点 2 :反转 [1,2] ,从节点 2 出发可以到达所有节点。\n所以 answer[2] = 1 。\n\n\n提示:\n\n * 2 <= n <= 105\n * edges.length == n - 1\n * edges[i].length == 2\n * 0 <= ui == edges[i][0] < n\n * 0 <= vi == edges[i][1] < n\n * ui != vi\n * 输入保证如果边是双向边,可以得到一棵树。\n\"\"\"\nclass Solution:\n def minEdgeReversals(self, n: int, edges: List[List[int]]) -> List[int]:\n ", "prompt_sft": "给你一个 n 个点的 简单有向图 (没有重复边的有向图),节点编号为 0 到 n - 1 。如果这些边是双向边,那么这个图形成一棵 树 。\n\n给你一个整数 n 和一个 二维 整数数组 edges ,其中 edges[i] = [ui, vi] 表示从节点 ui 到节点 vi 有一条 有向边 。\n\n边反转 指的是将一条边的方向反转,也就是说一条从节点 ui 到节点 vi 的边会变为一条从节点 vi 到节点 ui 的边。\n\n对于范围 [0, n - 1] 中的每一个节点 i ,你的任务是分别 独立 计算 最少 需要多少次 边反转 ,从节点 i 出发经过 一系列有向边 ,可以到达所有的节点。\n\n请你返回一个长度为 n 的整数数组 answer ,其中 answer[i]表示从节点 i 出发,可以到达所有节点的 最少边反转 次数。\n\n示例 1:\n\n[https://assets.leetcode.com/uploads/2023/08/26/image-20230826221104-3.png]\n\n输入:n = 4, edges = [[2,0],[2,1],[1,3]]\n输出:[1,1,0,2]\n解释:上图表示了与输入对应的简单有向图。\n对于节点 0 :反转 [2,0] ,从节点 0 出发可以到达所有节点。\n所以 answer[0] = 1 。\n对于节点 1 :反转 [2,1] ,从节点 1 出发可以到达所有节点。\n所以 answer[1] = 1 。\n对于节点 2 :不需要反转就可以从节点 2 出发到达所有节点。\n所以 answer[2] = 0 。\n对于节点 3 :反转 [1,3] 和 [2,1] ,从节点 3 出发可以到达所有节点。\n所以 answer[3] = 2 。\n\n示例 2:\n\n[https://assets.leetcode.com/uploads/2023/08/26/image-20230826225541-2.png]\n\n输入:n = 3, edges = [[1,2],[2,0]]\n输出:[2,0,1]\n解释:上图表示了与输入对应的简单有向图。\n对于节点 0 :反转 [2,0] 和 [1,2] ,从节点 0 出发可以到达所有节点。\n所以 answer[0] = 2 。\n对于节点 1 :不需要反转就可以从节点 2 出发到达所有节点。\n所以 answer[1] = 0 。\n对于节点 2 :反转 [1,2] ,从节点 2 出发可以到达所有节点。\n所以 answer[2] = 1 。\n\n\n提示:\n\n * 2 <= n <= 105\n * edges.length == n - 1\n * edges[i].length == 2\n * 0 <= ui == edges[i][0] < n\n * 0 <= vi == edges[i][1] < n\n * ui != vi\n * 输入保证如果边是双向边,可以得到一棵树。\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def minEdgeReversals(self, n: int, edges: List[List[int]]) -> List[int]:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"n\": 4, \"edges\": [[2,0],[2,1],[1,3]] }\nassert my_solution.minEdgeReversals(**test_input) == [1,1,0,2]\n\ntest_input = { \"n\": 3, \"edges\": [[1,2],[2,0]] }\nassert my_solution.minEdgeReversals(**test_input) == [2,0,1]\n\ntest_input = { \"n\": 2, \"edges\": [[0,1]] }\nassert my_solution.minEdgeReversals(**test_input) == [0,1]\n\ntest_input = { \"n\": 3, \"edges\": [[2,0],[2,1]] }\nassert my_solution.minEdgeReversals(**test_input) == [1,1,0]\n\ntest_input = { \"n\": 4, \"edges\": [[0,1],[3,0],[2,3]] }\nassert my_solution.minEdgeReversals(**test_input) == [2,3,0,1]\n\ntest_input = { \"n\": 4, \"edges\": [[0,2],[0,3],[3,1]] }\nassert my_solution.minEdgeReversals(**test_input) == [0,2,1,1]\n\ntest_input = { \"n\": 4, \"edges\": [[0,3],[1,2],[2,3]] }\nassert my_solution.minEdgeReversals(**test_input) == [2,1,2,3]\n\ntest_input = { \"n\": 4, \"edges\": [[0,3],[1,2],[3,1]] }\nassert my_solution.minEdgeReversals(**test_input) == [0,2,3,1]\n\ntest_input = { \"n\": 4, \"edges\": [[0,3],[2,1],[3,1]] }\nassert my_solution.minEdgeReversals(**test_input) == [1,3,2,2]\n\ntest_input = { \"n\": 4, \"edges\": [[1,0],[2,0],[3,2]] }\nassert my_solution.minEdgeReversals(**test_input) == [3,2,2,1]\n\ntest_input = { \"n\": 5, \"edges\": [[0,1],[0,4],[2,3],[4,2]] }\nassert my_solution.minEdgeReversals(**test_input) == [0,1,2,3,1]\n\ntest_input = { \"n\": 5, \"edges\": [[0,1],[2,0],[0,4],[3,4]] }\nassert my_solution.minEdgeReversals(**test_input) == [2,3,1,2,3]\n\ntest_input = { \"n\": 5, \"edges\": [[0,2],[0,1],[3,1],[4,1]] }\nassert my_solution.minEdgeReversals(**test_input) == [2,3,3,2,2]\n\ntest_input = { \"n\": 5, \"edges\": [[0,2],[0,1],[3,1],[4,3]] }\nassert my_solution.minEdgeReversals(**test_input) == [2,3,3,2,1]\n\ntest_input = { \"n\": 5, \"edges\": [[0,2],[1,3],[1,4],[2,4]] }\nassert my_solution.minEdgeReversals(**test_input) == [1,2,2,3,3]\n\ntest_input = { \"n\": 5, \"edges\": [[0,2],[1,3],[2,3],[4,2]] }\nassert my_solution.minEdgeReversals(**test_input) == [2,3,3,4,2]\n\ntest_input = { \"n\": 5, \"edges\": [[0,2],[2,1],[2,3],[4,3]] }\nassert my_solution.minEdgeReversals(**test_input) == [1,3,2,3,2]\n\ntest_input = { \"n\": 5, \"edges\": [[0,3],[0,4],[1,2],[4,1]] }\nassert my_solution.minEdgeReversals(**test_input) == [0,2,3,1,1]\n\ntest_input = { \"n\": 5, \"edges\": [[1,0],[3,0],[0,4],[2,3]] }\nassert my_solution.minEdgeReversals(**test_input) == [3,2,1,2,4]\n\ntest_input = { \"n\": 5, \"edges\": [[3,0],[0,4],[1,3],[2,3]] }\nassert my_solution.minEdgeReversals(**test_input) == [3,1,1,2,4]\n\ntest_input = { \"n\": 6, \"edges\": [[0,1],[0,5],[1,2],[3,2],[2,4]] }\nassert my_solution.minEdgeReversals(**test_input) == [1,2,3,2,4,2]\n\ntest_input = { \"n\": 6, \"edges\": [[0,1],[2,1],[1,5],[2,3],[4,3]] }\nassert my_solution.minEdgeReversals(**test_input) == [2,3,2,3,2,4]\n\ntest_input = { \"n\": 6, \"edges\": [[0,2],[0,3],[0,1],[0,5],[1,4]] }\nassert my_solution.minEdgeReversals(**test_input) == [0,1,1,1,2,1]\n\ntest_input = { \"n\": 6, \"edges\": [[0,2],[1,3],[1,2],[2,4],[2,5]] }\nassert my_solution.minEdgeReversals(**test_input) == [1,1,2,2,3,3]\n\ntest_input = { \"n\": 6, \"edges\": [[0,4],[1,2],[3,1],[5,1],[4,5]] }\nassert my_solution.minEdgeReversals(**test_input) == [1,4,5,3,2,3]\n\ntest_input = { \"n\": 6, \"edges\": [[1,0],[0,4],[2,4],[2,3],[3,5]] }\nassert my_solution.minEdgeReversals(**test_input) == [2,1,2,3,3,4]\n\ntest_input = { \"n\": 6, \"edges\": [[1,0],[3,1],[1,4],[2,5],[4,5]] }\nassert my_solution.minEdgeReversals(**test_input) == [3,2,3,1,3,4]\n\ntest_input = { \"n\": 7, \"edges\": [[0,5],[2,0],[1,3],[6,2],[4,3],[3,5]] }\nassert my_solution.minEdgeReversals(**test_input) == [5,4,4,5,4,6,3]\n\ntest_input = { \"n\": 7, \"edges\": [[0,6],[2,1],[6,1],[2,5],[5,3],[6,4]] }\nassert my_solution.minEdgeReversals(**test_input) == [1,3,2,4,3,3,2]\n\ntest_input = { \"n\": 7, \"edges\": [[5,0],[2,0],[6,1],[2,4],[2,3],[3,6]] }\nassert my_solution.minEdgeReversals(**test_input) == [2,4,1,2,2,1,3]\n\ntest_input = { \"n\": 8, \"edges\": [[0,4],[0,3],[7,0],[1,4],[2,5],[2,3],[6,5]] }\nassert my_solution.minEdgeReversals(**test_input) == [4,4,4,5,5,5,4,3]\n\ntest_input = { \"n\": 8, \"edges\": [[0,5],[1,0],[1,6],[1,2],[2,3],[2,7],[4,7]] }\nassert my_solution.minEdgeReversals(**test_input) == [2,1,2,3,2,3,2,3]\n\ntest_input = { \"n\": 8, \"edges\": [[1,0],[7,1],[2,6],[5,2],[3,6],[5,4],[5,7]] }\nassert my_solution.minEdgeReversals(**test_input) == [4,3,2,2,2,1,3,2]\n\ntest_input = { \"n\": 8, \"edges\": [[2,0],[5,0],[3,1],[1,4],[6,2],[4,5],[7,5]] }\nassert my_solution.minEdgeReversals(**test_input) == [7,4,6,3,5,6,5,5]\n\ntest_input = { \"n\": 8, \"edges\": [[4,0],[0,1],[1,3],[3,2],[6,2],[2,7],[5,7]] }\nassert my_solution.minEdgeReversals(**test_input) == [3,4,6,5,2,6,5,7]\n\ntest_input = { \"n\": 8, \"edges\": [[4,0],[7,1],[2,3],[7,2],[5,3],[4,6],[7,6]] }\nassert my_solution.minEdgeReversals(**test_input) == [3,3,3,4,2,3,3,2]\n\ntest_input = { \"n\": 9, \"edges\": [[0,5],[0,2],[0,7],[0,4],[7,1],[3,2],[6,3],[8,4]] }\nassert my_solution.minEdgeReversals(**test_input) == [3,5,4,3,4,4,2,4,3]\n\ntest_input = { \"n\": 9, \"edges\": [[0,5],[0,6],[0,2],[5,1],[7,2],[4,2],[3,6],[8,4]] }\nassert my_solution.minEdgeReversals(**test_input) == [4,6,5,4,4,5,5,4,3]\n\ntest_input = { \"n\": 9, \"edges\": [[0,5],[7,0],[1,6],[1,3],[2,8],[3,4],[3,7],[7,8]] }\nassert my_solution.minEdgeReversals(**test_input) == [4,1,3,2,3,5,2,3,4]\n\ntest_input = { \"n\": 9, \"edges\": [[2,0],[1,6],[1,5],[2,3],[2,5],[4,5],[5,7],[8,7]] }\nassert my_solution.minEdgeReversals(**test_input) == [4,3,3,4,3,4,4,5,4]\n\ntest_input = { \"n\": 9, \"edges\": [[7,0],[0,6],[1,2],[2,6],[3,6],[4,5],[5,8],[8,6]] }\nassert my_solution.minEdgeReversals(**test_input) == [7,6,7,7,5,6,8,6,7]\n\ntest_input = { \"n\": 10, \"edges\": [[0,1],[0,2],[2,4],[6,2],[3,9],[5,4],[4,8],[5,7],[9,6]] }\nassert my_solution.minEdgeReversals(**test_input) == [4,5,5,2,6,5,4,6,7,3]\n\ntest_input = { \"n\": 10, \"edges\": [[0,3],[0,5],[0,1],[8,1],[6,1],[2,3],[4,6],[9,4],[5,7]] }\nassert my_solution.minEdgeReversals(**test_input) == [5,6,5,6,4,6,5,7,5,3]\n\ntest_input = { \"n\": 10, \"edges\": [[0,5],[1,3],[1,9],[2,7],[4,2],[6,3],[3,4],[5,4],[7,8]] }\nassert my_solution.minEdgeReversals(**test_input) == [3,3,6,4,5,4,3,7,8,4]\n\ntest_input = { \"n\": 10, \"edges\": [[1,0],[0,5],[6,0],[2,3],[4,2],[2,6],[8,2],[2,9],[8,7]] }\nassert my_solution.minEdgeReversals(**test_input) == [5,4,3,4,2,6,4,3,2,4]\n\ntest_input = { \"n\": 10, \"edges\": [[6,0],[7,0],[4,1],[1,9],[2,7],[9,2],[3,7],[5,7],[8,9]] }\nassert my_solution.minEdgeReversals(**test_input) == [9,5,7,7,4,7,8,8,5,6]\n\ntest_input = { \"n\": 10, \"edges\": [[7,0],[1,2],[1,9],[2,3],[2,8],[5,3],[4,6],[6,7],[7,9]] }\nassert my_solution.minEdgeReversals(**test_input) == [5,4,5,6,2,5,3,4,6,5]\n\ntest_input = { \"n\": 10, \"edges\": [[7,0],[1,5],[2,6],[8,2],[7,3],[4,5],[5,6],[9,7],[8,9]] }\nassert my_solution.minEdgeReversals(**test_input) == [6,3,4,6,3,4,5,5,3,4]\n\ntest_input = { \"n\": 11, \"edges\": [[0,1],[1,2],[8,1],[2,4],[3,9],[3,7],[6,4],[5,7],[5,6],[10,8]] }\nassert my_solution.minEdgeReversals(**test_input) == [5,6,7,6,8,6,7,7,5,7,4]\n\ntest_input = { \"n\": 11, \"edges\": [[0,3],[0,2],[1,4],[1,5],[2,9],[3,5],[7,6],[7,9],[7,8],[8,10]] }\nassert my_solution.minEdgeReversals(**test_input) == [2,3,3,3,4,4,4,3,4,4,5]\n\ntest_input = { \"n\": 11, \"edges\": [[0,3],[0,7],[0,9],[0,10],[1,4],[4,2],[2,6],[6,3],[5,6],[7,8]] }\nassert my_solution.minEdgeReversals(**test_input) == [5,2,4,6,3,4,5,6,7,6,6]\n\ntest_input = { \"n\": 11, \"edges\": [[2,0],[0,9],[1,5],[2,8],[3,5],[3,8],[9,4],[9,6],[6,10],[7,10]] }\nassert my_solution.minEdgeReversals(**test_input) == [4,3,3,3,6,4,6,6,4,5,7]\n\ntest_input = { \"n\": 11, \"edges\": [[6,0],[0,1],[1,4],[2,8],[9,3],[4,10],[5,8],[5,6],[6,9],[10,7]] }\nassert my_solution.minEdgeReversals(**test_input) == [3,4,1,4,5,1,2,7,2,3,6]\n\ntest_input = { \"n\": 11, \"edges\": [[7,0],[1,0],[1,6],[5,1],[4,2],[8,2],[9,2],[7,3],[5,9],[10,5]] }\nassert my_solution.minEdgeReversals(**test_input) == [6,5,6,6,5,4,6,5,5,5,3]\n\ntest_input = { \"n\": 11, \"edges\": [[8,0],[6,1],[7,1],[1,10],[3,2],[4,3],[3,8],[5,8],[8,9],[9,10]] }\nassert my_solution.minEdgeReversals(**test_input) == [7,7,6,5,4,5,6,6,6,7,8]\n\ntest_input = { \"n\": 11, \"edges\": [[10,0],[1,2],[1,10],[2,8],[3,9],[3,5],[4,6],[7,4],[4,8],[5,8]] }\nassert my_solution.minEdgeReversals(**test_input) == [6,4,5,4,5,5,6,4,6,5,5]\n\ntest_input = { \"n\": 12, \"edges\": [[0,10],[1,3],[1,10],[2,7],[2,11],[3,4],[5,9],[5,11],[6,9],[9,8],[9,10]] }\nassert my_solution.minEdgeReversals(**test_input) == [5,5,4,6,7,4,4,5,6,5,6,5]\n\ntest_input = { \"n\": 12, \"edges\": [[3,0],[10,0],[6,0],[1,9],[3,2],[4,6],[4,7],[5,11],[11,7],[8,10],[9,11]] }\nassert my_solution.minEdgeReversals(**test_input) == [9,5,9,8,7,6,8,8,7,6,8,7]\n\ntest_input = { \"n\": 12, \"edges\": [[4,0],[11,0],[1,9],[1,3],[6,2],[2,7],[2,3],[3,10],[4,10],[5,6],[10,8]] }\nassert my_solution.minEdgeReversals(**test_input) == [7,5,5,6,6,3,4,6,8,6,7,6]\n\ntest_input = { \"n\": 12, \"edges\": [[10,0],[0,3],[1,6],[1,8],[1,5],[2,3],[2,4],[3,5],[4,7],[4,11],[10,9]] }\nassert my_solution.minEdgeReversals(**test_input) == [3,4,3,4,4,5,5,5,5,3,2,5]\n\ntest_input = { \"n\": 13, \"edges\": [[0,5],[1,10],[2,4],[2,7],[10,2],[3,5],[5,12],[11,6],[6,12],[8,10],[8,11],[10,9]] }\nassert my_solution.minEdgeReversals(**test_input) == [5,4,6,5,7,6,6,7,4,6,5,5,7]\n\ntest_input = { \"n\": 13, \"edges\": [[0,11],[1,4],[1,8],[1,3],[3,2],[10,3],[12,3],[12,5],[6,11],[10,7],[9,10],[11,12]] }\nassert my_solution.minEdgeReversals(**test_input) == [4,6,8,7,7,7,4,7,7,5,6,5,6]\n\ntest_input = { \"n\": 13, \"edges\": [[5,0],[0,2],[0,9],[10,1],[6,1],[7,2],[2,6],[3,7],[8,4],[4,11],[4,12],[9,12]] }\nassert my_solution.minEdgeReversals(**test_input) == [6,9,7,5,7,5,8,6,6,7,8,8,8]\n\ntest_input = { \"n\": 13, \"edges\": [[7,0],[3,1],[2,4],[2,8],[10,2],[3,10],[9,5],[5,7],[6,11],[6,12],[12,7],[10,12]] }\nassert my_solution.minEdgeReversals(**test_input) == [7,4,5,3,6,5,4,6,6,4,4,5,5]\n\ntest_input = { \"n\": 14, \"edges\": [[0,1],[0,7],[2,6],[2,8],[11,3],[4,12],[4,11],[5,10],[7,11],[13,7],[8,10],[10,9],[9,12]] }\nassert my_solution.minEdgeReversals(**test_input) == [7,8,5,10,8,6,6,8,6,8,7,9,9,7]\n\ntest_input = { \"n\": 14, \"edges\": [[0,1],[1,2],[2,8],[9,2],[6,2],[13,2],[3,4],[5,4],[7,5],[6,10],[12,6],[11,7],[11,10]] }\nassert my_solution.minEdgeReversals(**test_input) == [6,7,8,9,10,9,7,8,9,7,8,7,6,7]\n\ntest_input = { \"n\": 14, \"edges\": [[0,2],[0,3],[0,13],[1,3],[2,4],[8,2],[11,3],[12,3],[4,6],[5,7],[7,9],[7,11],[10,12]] }\nassert my_solution.minEdgeReversals(**test_input) == [7,7,8,8,9,5,10,6,7,7,6,7,7,8]\n\ntest_input = { \"n\": 14, \"edges\": [[0,4],[0,8],[1,3],[1,13],[2,9],[4,11],[4,12],[5,11],[8,6],[13,6],[7,9],[7,8],[10,8]] }\nassert my_solution.minEdgeReversals(**test_input) == [6,6,6,7,7,7,8,6,7,7,6,8,8,7]\n\ntest_input = { \"n\": 14, \"edges\": [[0,6],[5,0],[2,0],[12,1],[13,2],[12,3],[4,7],[5,7],[7,12],[8,13],[9,11],[9,10],[10,13]] }\nassert my_solution.minEdgeReversals(**test_input) == [7,9,6,9,6,6,8,7,4,3,4,4,8,5]\n\ntest_input = { \"n\": 14, \"edges\": [[0,9],[0,11],[0,5],[1,6],[1,11],[7,2],[3,5],[3,12],[3,13],[11,4],[6,10],[9,7],[11,8]] }\nassert my_solution.minEdgeReversals(**test_input) == [2,2,5,2,4,3,3,4,4,3,4,3,3,3]\n\ntest_input = { \"n\": 14, \"edges\": [[0,11],[1,2],[1,10],[1,6],[3,6],[4,11],[10,4],[5,12],[13,6],[8,7],[8,9],[8,12],[8,13]] }\nassert my_solution.minEdgeReversals(**test_input) == [7,5,6,5,7,4,6,5,4,5,6,8,5,5]\n\ntest_input = { \"n\": 14, \"edges\": [[1,0],[1,8],[7,2],[2,11],[2,13],[3,9],[8,3],[3,11],[4,12],[4,8],[5,11],[6,10],[10,12]] }\nassert my_solution.minEdgeReversals(**test_input) == [7,6,8,8,6,8,5,7,7,9,6,9,7,9]\n\ntest_input = { \"n\": 14, \"edges\": [[1,0],[11,0],[6,0],[7,2],[2,8],[10,3],[4,10],[5,12],[12,6],[13,6],[7,10],[9,8],[8,12]] }\nassert my_solution.minEdgeReversals(**test_input) == [11,10,7,8,6,8,10,6,8,7,7,10,9,9]\n\ntest_input = { \"n\": 14, \"edges\": [[3,0],[5,0],[0,7],[1,8],[1,4],[12,2],[4,3],[10,3],[12,5],[13,6],[7,13],[9,10],[10,11]] }\nassert my_solution.minEdgeReversals(**test_input) == [7,4,6,6,5,6,10,8,5,4,5,6,5,9]\n\ntest_input = { \"n\": 15, \"edges\": [[0,5],[1,9],[4,1],[1,5],[14,1],[2,5],[4,3],[4,6],[5,11],[5,7],[10,6],[7,8],[13,7],[14,12]] }\nassert my_solution.minEdgeReversals(**test_input) == [6,6,6,6,5,7,6,8,9,7,5,8,6,7,5]\n\ntest_input = { \"n\": 15, \"edges\": [[0,6],[13,0],[1,2],[10,1],[3,12],[4,11],[5,12],[10,7],[9,7],[7,13],[11,8],[8,9],[12,11],[13,14]] }\nassert my_solution.minEdgeReversals(**test_input) == [10,8,9,3,4,3,11,8,6,7,7,5,4,9,10]\n\ntest_input = { \"n\": 15, \"edges\": [[0,7],[12,1],[5,2],[4,2],[3,8],[3,14],[12,4],[4,7],[5,6],[10,5],[11,5],[6,9],[7,14],[13,12]] }\nassert my_solution.minEdgeReversals(**test_input) == [7,7,8,8,7,7,8,8,9,9,6,6,6,5,9]\n\ntest_input = { \"n\": 15, \"edges\": [[1,0],[10,1],[2,8],[2,3],[5,3],[4,8],[9,5],[6,12],[7,12],[8,7],[9,11],[11,10],[10,13],[10,14]] }\nassert my_solution.minEdgeReversals(**test_input) == [7,6,4,5,4,4,6,6,5,3,5,4,7,6,6]\n\ntest_input = { \"n\": 15, \"edges\": [[2,0],[0,7],[0,5],[1,6],[1,7],[3,4],[8,4],[10,4],[5,12],[5,10],[11,7],[9,13],[10,14],[13,14]] }\nassert my_solution.minEdgeReversals(**test_input) == [7,7,6,9,10,8,8,8,9,8,9,7,9,9,10]\n\ntest_input = { \"n\": 15, \"edges\": [[8,0],[1,0],[1,13],[1,14],[9,2],[3,13],[4,11],[4,14],[5,8],[12,6],[9,6],[7,8],[14,9],[10,13]] }\nassert my_solution.minEdgeReversals(**test_input) == [8,7,10,7,7,6,10,6,7,9,7,8,9,8,8]\n\ntest_input = { \"n\": 15, \"edges\": [[12,0],[0,8],[1,3],[2,1],[2,7],[12,2],[9,3],[4,11],[11,5],[5,7],[6,13],[6,9],[8,14],[10,12]] }\nassert my_solution.minEdgeReversals(**test_input) == [7,8,7,9,5,7,7,8,8,8,5,6,6,8,9]\n\ntest_input = { \"n\": 15, \"edges\": [[12,0],[1,12],[1,7],[2,12],[3,7],[3,14],[4,6],[5,6],[5,7],[6,8],[6,10],[11,6],[7,13],[9,14]] }\nassert my_solution.minEdgeReversals(**test_input) == [8,6,6,6,6,6,7,7,8,6,8,6,7,8,7]\n\ntest_input = { \"n\": 16, \"edges\": [[0,1],[5,0],[0,2],[0,4],[2,12],[10,3],[3,15],[4,7],[8,6],[6,9],[7,14],[7,13],[11,9],[13,9],[10,13]] }\nassert my_solution.minEdgeReversals(**test_input) == [5,6,6,8,6,4,8,7,7,9,7,8,7,8,8,9]\n\ntest_input = { \"n\": 16, \"edges\": [[2,0],[0,4],[4,1],[1,11],[5,2],[8,3],[4,3],[4,13],[14,4],[7,5],[5,12],[6,9],[12,9],[10,14],[11,15]] }\nassert my_solution.minEdgeReversals(**test_input) == [7,9,6,9,8,5,6,4,8,7,6,10,6,9,7,11]\n\ntest_input = { \"n\": 16, \"edges\": [[8,0],[1,6],[10,1],[8,2],[3,15],[14,4],[12,5],[13,5],[8,6],[6,9],[6,13],[11,7],[7,13],[15,10],[11,14]] }\nassert my_solution.minEdgeReversals(**test_input) == [8,7,8,4,9,10,8,8,7,9,6,7,9,9,8,5]\n\ntest_input = { \"n\": 17, \"edges\": [[0,4],[0,9],[13,1],[5,1],[6,2],[13,2],[3,8],[3,15],[3,9],[4,5],[5,10],[11,6],[7,16],[12,9],[16,9],[12,14]] }\nassert my_solution.minEdgeReversals(**test_input) == [7,10,10,7,8,9,9,6,8,8,10,8,7,9,8,8,7]\n\ntest_input = { \"n\": 17, \"edges\": [[0,7],[15,1],[2,3],[2,7],[3,8],[15,3],[5,4],[4,16],[6,14],[16,7],[16,9],[10,14],[10,16],[16,11],[12,14],[15,13]] }\nassert my_solution.minEdgeReversals(**test_input) == [8,9,8,9,7,6,7,9,10,9,7,9,7,9,8,8,8]\n\ntest_input = { \"n\": 17, \"edges\": [[0,10],[12,0],[0,14],[0,7],[0,16],[1,8],[1,7],[2,8],[3,5],[4,15],[5,9],[11,5],[14,6],[11,7],[15,8],[13,16]] }\nassert my_solution.minEdgeReversals(**test_input) == [8,8,8,8,7,9,10,9,9,10,9,8,7,8,9,8,9]\n\ntest_input = { \"n\": 17, \"edges\": [[0,12],[1,2],[1,13],[1,14],[4,3],[3,15],[5,4],[10,6],[14,6],[6,15],[7,11],[8,11],[13,9],[10,11],[15,12],[16,15]] }\nassert my_solution.minEdgeReversals(**test_input) == [11,8,9,10,9,8,10,9,9,10,9,10,12,9,9,11,10]\n\ntest_input = { \"n\": 17, \"edges\": [[0,13],[15,0],[1,5],[1,6],[11,1],[1,13],[8,2],[3,16],[4,16],[7,14],[11,8],[9,10],[9,16],[14,12],[14,15],[15,16]] }\nassert my_solution.minEdgeReversals(**test_input) == [8,8,9,7,7,9,9,5,8,7,8,7,7,9,6,7,8]\n\ntest_input = { \"n\": 17, \"edges\": [[8,0],[0,10],[6,1],[1,15],[15,2],[3,2],[12,3],[9,4],[5,7],[13,7],[9,10],[10,11],[10,14],[13,12],[16,12],[14,15]] }\nassert my_solution.minEdgeReversals(**test_input) == [9,11,13,12,10,10,10,11,8,9,10,11,11,10,11,12,10]\n\ntest_input = { \"n\": 17, \"edges\": [[10,0],[0,5],[1,8],[1,16],[7,2],[2,8],[3,5],[8,3],[4,11],[13,4],[16,6],[16,9],[14,12],[14,13],[14,15],[15,16]] }\nassert my_solution.minEdgeReversals(**test_input) == [8,6,6,8,7,9,8,5,7,8,7,8,6,6,5,6,7]\n\ntest_input = { \"n\": 18, \"edges\": [[0,3],[16,1],[1,10],[2,13],[2,8],[14,3],[4,12],[5,10],[13,6],[7,11],[10,7],[9,7],[14,8],[9,8],[9,17],[12,14],[13,15]] }\nassert my_solution.minEdgeReversals(**test_input) == [9,8,9,10,7,8,11,10,10,9,9,11,8,10,9,11,7,10]\n\ntest_input = { \"n\": 18, \"edges\": [[0,10],[0,17],[1,3],[1,2],[2,9],[2,17],[16,3],[4,7],[4,13],[4,6],[5,12],[5,17],[6,17],[8,15],[11,8],[16,11],[13,14]] }\nassert my_solution.minEdgeReversals(**test_input) == [6,5,6,6,5,6,6,6,7,7,7,6,7,6,7,8,5,7]\n\ntest_input = { \"n\": 18, \"edges\": [[11,0],[5,1],[1,10],[1,3],[1,17],[14,2],[2,13],[3,13],[4,7],[4,12],[4,17],[6,17],[7,8],[15,9],[16,11],[11,14],[14,15]] }\nassert my_solution.minEdgeReversals(**test_input) == [7,7,8,8,7,6,7,8,9,9,8,6,8,9,7,8,5,8]\n\ntest_input = { \"n\": 19, \"edges\": [[0,3],[0,5],[4,0],[12,1],[1,5],[2,17],[2,4],[3,13],[4,8],[5,7],[18,6],[18,8],[14,9],[9,15],[16,9],[10,12],[11,17],[12,16]] }\nassert my_solution.minEdgeReversals(**test_input) == [8,8,6,9,7,9,8,10,8,9,6,6,7,10,8,10,8,7,7]\n\ntest_input = { \"n\": 19, \"edges\": [[0,5],[0,9],[14,1],[2,11],[3,12],[3,8],[10,3],[4,13],[4,12],[6,17],[10,7],[7,14],[8,11],[16,8],[9,14],[9,17],[15,17],[15,18]] }\nassert my_solution.minEdgeReversals(**test_input) == [7,10,9,8,8,8,8,8,9,8,7,10,9,9,9,8,8,9,9]\n\ntest_input = { \"n\": 19, \"edges\": [[0,12],[13,1],[12,1],[14,2],[2,11],[3,9],[11,3],[15,4],[4,11],[5,12],[17,6],[8,7],[8,10],[16,8],[9,12],[11,18],[16,18],[17,18]] }\nassert my_solution.minEdgeReversals(**test_input) == [11,13,8,10,8,11,10,11,10,11,11,9,12,12,7,7,9,9,10]\n\ntest_input = { \"n\": 19, \"edges\": [[0,18],[8,1],[5,1],[9,2],[6,2],[3,11],[17,3],[4,12],[4,6],[18,4],[14,5],[5,16],[6,7],[16,7],[17,7],[15,8],[10,14],[14,13]] }\nassert my_solution.minEdgeReversals(**test_input) == [8,11,12,12,10,10,11,12,10,11,8,13,11,10,9,9,11,11,9]\n\ntest_input = { \"n\": 19, \"edges\": [[1,0],[0,13],[15,0],[1,9],[5,2],[2,13],[3,12],[3,16],[4,12],[5,7],[8,6],[12,8],[16,10],[13,10],[17,11],[13,11],[14,13],[15,18]] }\nassert my_solution.minEdgeReversals(**test_input) == [9,8,9,9,9,8,12,9,11,9,11,11,10,10,9,8,10,10,9]", "start_time": 1694874600} +{"task_id": "weekly-contest-362-points-that-intersect-with-cars", "url": "https://leetcode.com/problems/points-that-intersect-with-cars", "title": "points-that-intersect-with-cars", "meta": {"questionId": "3034", "questionFrontendId": "2848", "title": "Points That Intersect With Cars", "titleSlug": "points-that-intersect-with-cars", "isPaidOnly": false, "difficulty": "Easy", "likes": 211, "dislikes": 13, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0 开始的二维整数数组 nums 表示汽车停放在数轴上的坐标。对于任意下标 i,nums[i] = [starti, endi] ,其中 starti 是第 i 辆车的起点,endi 是第 i 辆车的终点。\n\n返回数轴上被车 任意部分 覆盖的整数点的数目。\n\n示例 1:\n\n输入:nums = [[3,6],[1,5],[4,7]]\n输出:7\n解释:从 1 到 7 的所有点都至少与一辆车相交,因此答案为 7 。\n\n示例 2:\n\n输入:nums = [[1,3],[5,8]]\n输出:7\n解释:1、2、3、5、6、7、8 共计 7 个点满足至少与一辆车相交,因此答案为 7 。\n\n\n提示:\n\n * 1 <= nums.length <= 100\n * nums[i].length == 2\n * 1 <= starti <= endi <= 100\n\"\"\"\nclass Solution:\n def numberOfPoints(self, nums: List[List[int]]) -> int:\n ", "prompt_sft": "给你一个下标从 0 开始的二维整数数组 nums 表示汽车停放在数轴上的坐标。对于任意下标 i,nums[i] = [starti, endi] ,其中 starti 是第 i 辆车的起点,endi 是第 i 辆车的终点。\n\n返回数轴上被车 任意部分 覆盖的整数点的数目。\n\n示例 1:\n\n输入:nums = [[3,6],[1,5],[4,7]]\n输出:7\n解释:从 1 到 7 的所有点都至少与一辆车相交,因此答案为 7 。\n\n示例 2:\n\n输入:nums = [[1,3],[5,8]]\n输出:7\n解释:1、2、3、5、6、7、8 共计 7 个点满足至少与一辆车相交,因此答案为 7 。\n\n\n提示:\n\n * 1 <= nums.length <= 100\n * nums[i].length == 2\n * 1 <= starti <= endi <= 100\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def numberOfPoints(self, nums: List[List[int]]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [[3,6],[1,5],[4,7]] }\nassert my_solution.numberOfPoints(**test_input) == 7\n\ntest_input = { \"nums\": [[1,3],[5,8]] }\nassert my_solution.numberOfPoints(**test_input) == 7\n\ntest_input = { \"nums\": [[4,4],[9,10],[9,10],[3,8]] }\nassert my_solution.numberOfPoints(**test_input) == 8\n\ntest_input = { \"nums\": [[2,5],[3,8],[1,6],[4,10]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[2,3],[3,9],[5,7],[4,10],[9,10]] }\nassert my_solution.numberOfPoints(**test_input) == 9\n\ntest_input = { \"nums\": [[4,10]] }\nassert my_solution.numberOfPoints(**test_input) == 7\n\ntest_input = { \"nums\": [[1,9],[2,10],[6,7],[8,9],[5,8],[1,3]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[5,10],[3,8],[3,9]] }\nassert my_solution.numberOfPoints(**test_input) == 8\n\ntest_input = { \"nums\": [[2,3],[3,10],[5,8],[4,8],[2,7],[3,4],[3,10],[7,8]] }\nassert my_solution.numberOfPoints(**test_input) == 9\n\ntest_input = { \"nums\": [[1,3],[2,4],[6,6],[6,9],[2,10],[4,10],[3,6],[1,4],[1,3]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[4,10],[3,9],[3,5],[4,10],[7,10],[1,7],[7,9],[4,8]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[1,6],[6,7],[1,6],[1,3],[1,8],[2,9],[3,8],[1,9]] }\nassert my_solution.numberOfPoints(**test_input) == 9\n\ntest_input = { \"nums\": [[1,6],[8,10],[3,7],[6,10],[3,10],[1,10],[7,8]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[6,8],[2,8],[3,9],[3,5],[6,10],[1,2],[5,5]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[4,5],[5,9],[2,3],[5,10],[1,9],[1,8],[2,9],[2,10]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[8,9],[6,7],[6,9],[3,5],[7,10],[5,9],[10,10]] }\nassert my_solution.numberOfPoints(**test_input) == 8\n\ntest_input = { \"nums\": [[6,8],[7,10],[9,10],[6,10],[1,10],[5,10]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[9,9],[2,8],[5,8],[3,5],[2,2],[7,9],[5,10]] }\nassert my_solution.numberOfPoints(**test_input) == 9\n\ntest_input = { \"nums\": [[3,9],[5,9]] }\nassert my_solution.numberOfPoints(**test_input) == 7\n\ntest_input = { \"nums\": [[5,10],[2,3],[3,10],[4,7],[1,9],[5,10],[2,6],[1,7],[8,9],[2,9]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[2,3],[2,3],[1,5]] }\nassert my_solution.numberOfPoints(**test_input) == 5\n\ntest_input = { \"nums\": [[4,7],[4,7]] }\nassert my_solution.numberOfPoints(**test_input) == 4\n\ntest_input = { \"nums\": [[7,9],[5,9],[2,10],[9,9],[5,8],[4,6],[6,7],[3,9],[2,4]] }\nassert my_solution.numberOfPoints(**test_input) == 9\n\ntest_input = { \"nums\": [[5,9],[7,7],[3,10],[7,9],[3,4],[1,1],[1,1],[1,7],[1,2],[6,6]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[7,8],[1,7],[5,5],[4,4],[5,8],[2,6]] }\nassert my_solution.numberOfPoints(**test_input) == 8\n\ntest_input = { \"nums\": [[3,5],[8,8],[5,10],[1,7],[2,6],[7,10],[6,6],[5,9],[8,9],[5,6]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[4,9]] }\nassert my_solution.numberOfPoints(**test_input) == 6\n\ntest_input = { \"nums\": [[2,7],[1,9],[5,6],[6,8],[1,10]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[1,4],[2,4],[7,10],[2,8],[1,6],[1,10],[3,5]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[1,4]] }\nassert my_solution.numberOfPoints(**test_input) == 4\n\ntest_input = { \"nums\": [[6,9],[4,7]] }\nassert my_solution.numberOfPoints(**test_input) == 6\n\ntest_input = { \"nums\": [[5,7]] }\nassert my_solution.numberOfPoints(**test_input) == 3\n\ntest_input = { \"nums\": [[1,9],[6,8],[4,7],[7,9],[8,9],[7,9],[4,6],[6,8],[4,9],[8,8]] }\nassert my_solution.numberOfPoints(**test_input) == 9\n\ntest_input = { \"nums\": [[3,6],[3,5],[1,9],[3,4],[3,8],[2,7],[3,8],[2,8]] }\nassert my_solution.numberOfPoints(**test_input) == 9\n\ntest_input = { \"nums\": [[2,5],[8,8],[1,6],[4,4],[4,5],[2,4]] }\nassert my_solution.numberOfPoints(**test_input) == 7\n\ntest_input = { \"nums\": [[4,7],[2,6]] }\nassert my_solution.numberOfPoints(**test_input) == 6\n\ntest_input = { \"nums\": [[5,8],[4,10],[2,9]] }\nassert my_solution.numberOfPoints(**test_input) == 9\n\ntest_input = { \"nums\": [[5,9],[2,4],[2,6]] }\nassert my_solution.numberOfPoints(**test_input) == 8\n\ntest_input = { \"nums\": [[2,3],[1,7],[1,8],[7,9],[1,5]] }\nassert my_solution.numberOfPoints(**test_input) == 9\n\ntest_input = { \"nums\": [[6,8],[6,7],[1,6],[2,10],[2,2],[6,8],[2,8],[8,9]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[3,4],[2,5],[4,10],[3,6],[4,6],[1,8],[2,6],[6,9],[4,10],[3,6]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[3,5],[2,5],[8,8]] }\nassert my_solution.numberOfPoints(**test_input) == 5\n\ntest_input = { \"nums\": [[5,8],[1,3],[8,8]] }\nassert my_solution.numberOfPoints(**test_input) == 7\n\ntest_input = { \"nums\": [[2,8],[5,7],[2,3],[2,7],[5,8],[1,10],[4,7],[10,10],[6,10]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[1,3],[5,10],[3,10],[5,9]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[4,10],[3,6]] }\nassert my_solution.numberOfPoints(**test_input) == 8\n\ntest_input = { \"nums\": [[7,8],[6,10],[7,8],[6,10],[7,10]] }\nassert my_solution.numberOfPoints(**test_input) == 5\n\ntest_input = { \"nums\": [[7,7],[4,4],[2,7],[2,3],[4,6],[4,8]] }\nassert my_solution.numberOfPoints(**test_input) == 7\n\ntest_input = { \"nums\": [[3,4],[1,4],[4,8],[1,7],[2,10],[8,10]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[1,4],[7,10],[1,5],[8,9],[3,5],[3,8],[6,7],[3,5],[1,3],[2,8]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[1,6],[5,10],[7,8],[7,10],[1,3]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[2,3],[4,4],[2,7],[5,5],[4,7],[6,9],[2,4]] }\nassert my_solution.numberOfPoints(**test_input) == 8\n\ntest_input = { \"nums\": [[6,8],[6,8],[6,10]] }\nassert my_solution.numberOfPoints(**test_input) == 5\n\ntest_input = { \"nums\": [[3,10],[3,5],[2,3],[7,9]] }\nassert my_solution.numberOfPoints(**test_input) == 9\n\ntest_input = { \"nums\": [[4,4],[8,10],[2,7],[8,9],[1,8],[1,3],[1,9],[7,7],[3,6],[3,5]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[2,6],[1,4],[3,8],[1,9]] }\nassert my_solution.numberOfPoints(**test_input) == 9\n\ntest_input = { \"nums\": [[1,2],[1,9],[2,9],[6,10],[3,5],[1,2]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[6,7],[1,10],[4,4],[5,5],[5,10],[2,3],[2,8],[9,10]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[1,1],[2,9],[3,3],[2,2],[2,4],[8,9],[3,9]] }\nassert my_solution.numberOfPoints(**test_input) == 9\n\ntest_input = { \"nums\": [[4,6],[1,10],[4,10],[1,10],[5,7]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[2,3],[9,10],[2,9],[2,8],[8,9],[1,2]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[4,9],[4,6],[2,7],[1,9],[6,10],[7,10],[3,9],[2,9]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[7,10],[4,10],[4,10],[4,5],[3,10],[2,4],[8,9],[3,9],[4,5],[6,9]] }\nassert my_solution.numberOfPoints(**test_input) == 9\n\ntest_input = { \"nums\": [[2,7],[2,5],[3,3],[4,4],[5,6],[3,4],[4,10],[5,5],[4,5]] }\nassert my_solution.numberOfPoints(**test_input) == 9\n\ntest_input = { \"nums\": [[3,7],[7,8],[2,6],[10,10],[1,4]] }\nassert my_solution.numberOfPoints(**test_input) == 9\n\ntest_input = { \"nums\": [[3,4],[3,8],[5,8]] }\nassert my_solution.numberOfPoints(**test_input) == 6\n\ntest_input = { \"nums\": [[6,9],[1,8],[7,9]] }\nassert my_solution.numberOfPoints(**test_input) == 9\n\ntest_input = { \"nums\": [[7,8],[1,5]] }\nassert my_solution.numberOfPoints(**test_input) == 7\n\ntest_input = { \"nums\": [[5,10],[5,9],[5,6],[6,8],[1,5],[7,8],[3,5]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[6,8]] }\nassert my_solution.numberOfPoints(**test_input) == 3\n\ntest_input = { \"nums\": [[5,5],[5,9],[2,8],[5,9],[5,6]] }\nassert my_solution.numberOfPoints(**test_input) == 8\n\ntest_input = { \"nums\": [[7,9],[3,8],[1,8],[8,8],[5,9],[1,3],[2,6]] }\nassert my_solution.numberOfPoints(**test_input) == 9\n\ntest_input = { \"nums\": [[3,6],[4,8],[7,9],[3,3],[9,10],[5,8],[1,2],[7,8],[3,10]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[1,8],[4,5],[1,5],[6,7],[2,9]] }\nassert my_solution.numberOfPoints(**test_input) == 9\n\ntest_input = { \"nums\": [[6,8],[2,8],[6,9],[10,10],[2,5],[4,6],[1,10],[8,8],[9,10]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[9,10],[4,8],[9,10],[5,7],[2,5],[2,7],[6,10],[5,7],[9,10]] }\nassert my_solution.numberOfPoints(**test_input) == 9\n\ntest_input = { \"nums\": [[1,7],[2,7],[2,4],[6,7]] }\nassert my_solution.numberOfPoints(**test_input) == 7\n\ntest_input = { \"nums\": [[2,10],[4,5],[4,10]] }\nassert my_solution.numberOfPoints(**test_input) == 9\n\ntest_input = { \"nums\": [[2,10],[3,6],[2,10],[4,10],[4,9],[10,10],[1,1]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[3,5],[6,9],[4,7],[6,6],[4,5],[2,4],[2,7]] }\nassert my_solution.numberOfPoints(**test_input) == 8\n\ntest_input = { \"nums\": [[1,1],[1,7]] }\nassert my_solution.numberOfPoints(**test_input) == 7\n\ntest_input = { \"nums\": [[1,8],[2,8]] }\nassert my_solution.numberOfPoints(**test_input) == 8\n\ntest_input = { \"nums\": [[3,7]] }\nassert my_solution.numberOfPoints(**test_input) == 5\n\ntest_input = { \"nums\": [[1,6],[10,10],[5,7],[2,9]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[7,8]] }\nassert my_solution.numberOfPoints(**test_input) == 2\n\ntest_input = { \"nums\": [[2,10],[1,10],[5,9],[7,7],[1,6],[3,5],[2,9],[2,10],[7,10]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[3,8],[2,9],[6,10],[4,8],[3,4],[2,3],[5,9],[1,5],[7,9]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[6,7],[1,5],[4,6],[4,9],[6,8],[1,7],[5,10],[3,4]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[1,2],[4,10],[3,7],[2,10],[1,2],[3,4],[9,9],[5,9],[3,7],[3,5]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[1,6],[3,4],[4,8],[8,10],[3,8]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[3,6],[8,10],[2,5],[9,10],[2,8],[5,10],[7,10],[8,8],[8,10],[8,9]] }\nassert my_solution.numberOfPoints(**test_input) == 9\n\ntest_input = { \"nums\": [[1,8],[2,6],[2,3],[3,6],[1,10],[5,8]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[3,7],[7,10],[6,6],[4,10],[5,10],[2,8],[1,10],[7,8],[6,6],[4,7]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[6,9]] }\nassert my_solution.numberOfPoints(**test_input) == 4\n\ntest_input = { \"nums\": [[7,8],[1,1],[4,10],[1,9],[2,6],[4,6],[8,9],[4,5]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[2,7],[7,10],[7,8],[3,5],[1,7],[1,4]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[2,9]] }\nassert my_solution.numberOfPoints(**test_input) == 8\n\ntest_input = { \"nums\": [[7,9],[2,2],[2,7]] }\nassert my_solution.numberOfPoints(**test_input) == 8\n\ntest_input = { \"nums\": [[2,10],[8,9],[6,8],[9,10]] }\nassert my_solution.numberOfPoints(**test_input) == 9\n\ntest_input = { \"nums\": [[3,3]] }\nassert my_solution.numberOfPoints(**test_input) == 1", "start_time": 1694313000} +{"task_id": "weekly-contest-362-determine-if-a-cell-is-reachable-at-a-given-time", "url": "https://leetcode.com/problems/determine-if-a-cell-is-reachable-at-a-given-time", "title": "determine-if-a-cell-is-reachable-at-a-given-time", "meta": {"questionId": "3056", "questionFrontendId": "2849", "title": "Determine if a Cell Is Reachable at a Given Time", "titleSlug": "determine-if-a-cell-is-reachable-at-a-given-time", "isPaidOnly": false, "difficulty": "Medium", "likes": 782, "dislikes": 730, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你四个整数 sx、sy、fx、fy  以及一个 非负整数 t 。\n\n在一个无限的二维网格中,你从单元格 (sx, sy) 开始出发。每一秒,你 必须 移动到任一与之前所处单元格相邻的单元格中。\n\n如果你能在 恰好 t 秒 后到达单元格 (fx, fy) ,返回 true ;否则,返回  false 。\n\n单元格的 相邻单元格 是指该单元格周围与其至少共享一个角的 8 个单元格。你可以多次访问同一个单元格。\n\n示例 1:\n\n[https://assets.leetcode.com/uploads/2023/08/05/example2.svg]\n\n输入:sx = 2, sy = 4, fx = 7, fy = 7, t = 6\n输出:true\n解释:从单元格 (2, 4) 开始出发,穿过上图标注的单元格,可以在恰好 6 秒后到达单元格 (7, 7) 。\n\n示例 2:\n\n[https://assets.leetcode.com/uploads/2023/08/05/example1.svg]\n\n输入:sx = 3, sy = 1, fx = 7, fy = 3, t = 3\n输出:false\n解释:从单元格 (3, 1) 开始出发,穿过上图标注的单元格,至少需要 4 秒后到达单元格 (7, 3) 。 因此,无法在 3 秒后到达单元格 (7, 3) 。\n\n\n提示:\n\n * 1 <= sx, sy, fx, fy <= 109\n * 0 <= t <= 109\n\"\"\"\nclass Solution:\n def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n ", "prompt_sft": "给你四个整数 sx、sy、fx、fy  以及一个 非负整数 t 。\n\n在一个无限的二维网格中,你从单元格 (sx, sy) 开始出发。每一秒,你 必须 移动到任一与之前所处单元格相邻的单元格中。\n\n如果你能在 恰好 t 秒 后到达单元格 (fx, fy) ,返回 true ;否则,返回  false 。\n\n单元格的 相邻单元格 是指该单元格周围与其至少共享一个角的 8 个单元格。你可以多次访问同一个单元格。\n\n示例 1:\n\n[https://assets.leetcode.com/uploads/2023/08/05/example2.svg]\n\n输入:sx = 2, sy = 4, fx = 7, fy = 7, t = 6\n输出:true\n解释:从单元格 (2, 4) 开始出发,穿过上图标注的单元格,可以在恰好 6 秒后到达单元格 (7, 7) 。\n\n示例 2:\n\n[https://assets.leetcode.com/uploads/2023/08/05/example1.svg]\n\n输入:sx = 3, sy = 1, fx = 7, fy = 3, t = 3\n输出:false\n解释:从单元格 (3, 1) 开始出发,穿过上图标注的单元格,至少需要 4 秒后到达单元格 (7, 3) 。 因此,无法在 3 秒后到达单元格 (7, 3) 。\n\n\n提示:\n\n * 1 <= sx, sy, fx, fy <= 109\n * 0 <= t <= 109\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"sx\": 3, \"sy\": 1, \"fx\": 7, \"fy\": 3, \"t\": 3 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 2, \"sy\": 4, \"fx\": 7, \"fy\": 7, \"t\": 6 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 1, \"fx\": 1, \"fy\": 2, \"t\": 0 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 1, \"fx\": 2, \"fy\": 4, \"t\": 0 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 1, \"fx\": 3, \"fy\": 4, \"t\": 1 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 1, \"fx\": 3, \"fy\": 5, \"t\": 1 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 1, \"fx\": 1, \"fy\": 1, \"t\": 3 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 1, \"fx\": 1, \"fy\": 3, \"t\": 2 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 1, \"fx\": 4, \"fy\": 1, \"t\": 0 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 1, \"fx\": 4, \"fy\": 2, \"t\": 1 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 1, \"fx\": 1, \"fy\": 4, \"t\": 3 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 1, \"fx\": 1, \"fy\": 5, \"t\": 8 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 1, \"fx\": 2, \"fy\": 1, \"t\": 2 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 1, \"fx\": 4, \"fy\": 3, \"t\": 2 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 1, \"fx\": 2, \"fy\": 2, \"t\": 1 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 1, \"fx\": 4, \"fy\": 4, \"t\": 0 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 1, \"fx\": 5, \"fy\": 1, \"t\": 0 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 1, \"fx\": 2, \"fy\": 3, \"t\": 2 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 1, \"fx\": 5, \"fy\": 2, \"t\": 0 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 1, \"fx\": 2, \"fy\": 5, \"t\": 6 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 1, \"fx\": 3, \"fy\": 1, \"t\": 3 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 1, \"fx\": 3, \"fy\": 2, \"t\": 4 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 1, \"fx\": 3, \"fy\": 3, \"t\": 9 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 1, \"fx\": 4, \"fy\": 5, \"t\": 9 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 1, \"fx\": 5, \"fy\": 3, \"t\": 9 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 1, \"fx\": 5, \"fy\": 4, \"t\": 0 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 2, \"fx\": 1, \"fy\": 1, \"t\": 2 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 1, \"fx\": 5, \"fy\": 5, \"t\": 0 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 2, \"fx\": 1, \"fy\": 2, \"t\": 1 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 2, \"fx\": 1, \"fy\": 3, \"t\": 6 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 2, \"fx\": 1, \"fy\": 4, \"t\": 4 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 2, \"fx\": 2, \"fy\": 5, \"t\": 0 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 2, \"fx\": 3, \"fy\": 4, \"t\": 0 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 2, \"fx\": 1, \"fy\": 5, \"t\": 5 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 2, \"fx\": 3, \"fy\": 5, \"t\": 0 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 2, \"fx\": 4, \"fy\": 1, \"t\": 0 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 2, \"fx\": 2, \"fy\": 1, \"t\": 10 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 2, \"fx\": 2, \"fy\": 2, \"t\": 9 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 2, \"fx\": 2, \"fy\": 3, \"t\": 1 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 2, \"fx\": 4, \"fy\": 2, \"t\": 1 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 2, \"fx\": 2, \"fy\": 4, \"t\": 2 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 2, \"fx\": 4, \"fy\": 3, \"t\": 1 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 2, \"fx\": 4, \"fy\": 4, \"t\": 0 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 2, \"fx\": 3, \"fy\": 1, \"t\": 2 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 2, \"fx\": 3, \"fy\": 2, \"t\": 2 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 2, \"fx\": 4, \"fy\": 5, \"t\": 2 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 2, \"fx\": 3, \"fy\": 3, \"t\": 4 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 2, \"fx\": 5, \"fy\": 1, \"t\": 0 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 2, \"fx\": 5, \"fy\": 3, \"t\": 0 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 2, \"fx\": 5, \"fy\": 2, \"t\": 4 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 2, \"fx\": 5, \"fy\": 4, \"t\": 0 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 3, \"fx\": 1, \"fy\": 1, \"t\": 2 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 3, \"fx\": 1, \"fy\": 2, \"t\": 3 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 2, \"fx\": 5, \"fy\": 5, \"t\": 2 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 3, \"fx\": 2, \"fy\": 1, \"t\": 0 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 3, \"fx\": 2, \"fy\": 4, \"t\": 0 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 3, \"fx\": 1, \"fy\": 3, \"t\": 0 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 3, \"fx\": 1, \"fy\": 4, \"t\": 4 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 3, \"fx\": 1, \"fy\": 5, \"t\": 4 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 3, \"fx\": 2, \"fy\": 2, \"t\": 2 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 3, \"fx\": 2, \"fy\": 3, \"t\": 3 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 3, \"fx\": 3, \"fy\": 1, \"t\": 3 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 3, \"fx\": 2, \"fy\": 5, \"t\": 0 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 3, \"fx\": 4, \"fy\": 1, \"t\": 1 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 3, \"fx\": 3, \"fy\": 2, \"t\": 2 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 3, \"fx\": 3, \"fy\": 3, \"t\": 8 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 3, \"fx\": 4, \"fy\": 5, \"t\": 1 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 3, \"fx\": 5, \"fy\": 1, \"t\": 3 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 3, \"fx\": 5, \"fy\": 2, \"t\": 2 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 3, \"fx\": 5, \"fy\": 3, \"t\": 3 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 3, \"fx\": 5, \"fy\": 4, \"t\": 3 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 3, \"fx\": 5, \"fy\": 5, \"t\": 1 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 3, \"fx\": 3, \"fy\": 4, \"t\": 4 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 3, \"fx\": 3, \"fy\": 5, \"t\": 2 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 4, \"fx\": 1, \"fy\": 2, \"t\": 1 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 3, \"fx\": 4, \"fy\": 2, \"t\": 3 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 3, \"fx\": 4, \"fy\": 3, \"t\": 10 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 3, \"fx\": 4, \"fy\": 4, \"t\": 10 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 4, \"fx\": 1, \"fy\": 1, \"t\": 4 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 4, \"fx\": 1, \"fy\": 3, \"t\": 1 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 4, \"fx\": 1, \"fy\": 4, \"t\": 6 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 4, \"fx\": 2, \"fy\": 2, \"t\": 0 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 4, \"fx\": 1, \"fy\": 5, \"t\": 6 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 4, \"fx\": 2, \"fy\": 4, \"t\": 0 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 4, \"fx\": 2, \"fy\": 1, \"t\": 4 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 4, \"fx\": 3, \"fy\": 3, \"t\": 0 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 4, \"fx\": 2, \"fy\": 3, \"t\": 3 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 4, \"fx\": 2, \"fy\": 5, \"t\": 3 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 4, \"fx\": 3, \"fy\": 1, \"t\": 4 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 4, \"fx\": 3, \"fy\": 2, \"t\": 5 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 4, \"fx\": 4, \"fy\": 1, \"t\": 7 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 4, \"fx\": 3, \"fy\": 4, \"t\": 1 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 4, \"fx\": 4, \"fy\": 4, \"t\": 10 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 4, \"fx\": 4, \"fy\": 5, \"t\": 3 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 4, \"fx\": 3, \"fy\": 5, \"t\": 0 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 4, \"fx\": 4, \"fy\": 2, \"t\": 0 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 4, \"fx\": 4, \"fy\": 3, \"t\": 1 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 4, \"fx\": 5, \"fy\": 2, \"t\": 1 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 4, \"fx\": 5, \"fy\": 4, \"t\": 3 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 4, \"fx\": 5, \"fy\": 5, \"t\": 0 }\nassert my_solution.isReachableAtTime(**test_input) == False", "start_time": 1694313000} +{"task_id": "weekly-contest-362-minimum-moves-to-spread-stones-over-grid", "url": "https://leetcode.com/problems/minimum-moves-to-spread-stones-over-grid", "title": "minimum-moves-to-spread-stones-over-grid", "meta": {"questionId": "3092", "questionFrontendId": "2850", "title": "Minimum Moves to Spread Stones Over Grid", "titleSlug": "minimum-moves-to-spread-stones-over-grid", "isPaidOnly": false, "difficulty": "Medium", "likes": 419, "dislikes": 43, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个大小为 3 * 3 ,下标从 0 开始的二维整数矩阵 grid ,分别表示每一个格子里石头的数目。网格图中总共恰好有 9 个石头,一个格子里可能会有 多个 石头。\n\n每一次操作中,你可以将一个石头从它当前所在格子移动到一个至少有一条公共边的相邻格子。\n\n请你返回每个格子恰好有一个石头的 最少移动次数 。\n\n示例 1:\n\n[https://assets.leetcode.com/uploads/2023/08/23/example1-3.svg]\n\n输入:grid = [[1,1,0],[1,1,1],[1,2,1]]\n输出:3\n解释:让每个格子都有一个石头的一个操作序列为:\n1 - 将一个石头从格子 (2,1) 移动到 (2,2) 。\n2 - 将一个石头从格子 (2,2) 移动到 (1,2) 。\n3 - 将一个石头从格子 (1,2) 移动到 (0,2) 。\n总共需要 3 次操作让每个格子都有一个石头。\n让每个格子都有一个石头的最少操作次数为 3 。\n\n示例 2:\n\n[https://assets.leetcode.com/uploads/2023/08/23/example2-2.svg]\n\n输入:grid = [[1,3,0],[1,0,0],[1,0,3]]\n输出:4\n解释:让每个格子都有一个石头的一个操作序列为:\n1 - 将一个石头从格子 (0,1) 移动到 (0,2) 。\n2 - 将一个石头从格子 (0,1) 移动到 (1,1) 。\n3 - 将一个石头从格子 (2,2) 移动到 (1,2) 。\n4 - 将一个石头从格子 (2,2) 移动到 (2,1) 。\n总共需要 4 次操作让每个格子都有一个石头。\n让每个格子都有一个石头的最少操作次数为 4 。\n\n\n提示:\n\n * grid.length == grid[i].length == 3\n * 0 <= grid[i][j] <= 9\n * grid 中元素之和为 9 。\n\"\"\"\nclass Solution:\n def minimumMoves(self, grid: List[List[int]]) -> int:\n ", "prompt_sft": "给你一个大小为 3 * 3 ,下标从 0 开始的二维整数矩阵 grid ,分别表示每一个格子里石头的数目。网格图中总共恰好有 9 个石头,一个格子里可能会有 多个 石头。\n\n每一次操作中,你可以将一个石头从它当前所在格子移动到一个至少有一条公共边的相邻格子。\n\n请你返回每个格子恰好有一个石头的 最少移动次数 。\n\n示例 1:\n\n[https://assets.leetcode.com/uploads/2023/08/23/example1-3.svg]\n\n输入:grid = [[1,1,0],[1,1,1],[1,2,1]]\n输出:3\n解释:让每个格子都有一个石头的一个操作序列为:\n1 - 将一个石头从格子 (2,1) 移动到 (2,2) 。\n2 - 将一个石头从格子 (2,2) 移动到 (1,2) 。\n3 - 将一个石头从格子 (1,2) 移动到 (0,2) 。\n总共需要 3 次操作让每个格子都有一个石头。\n让每个格子都有一个石头的最少操作次数为 3 。\n\n示例 2:\n\n[https://assets.leetcode.com/uploads/2023/08/23/example2-2.svg]\n\n输入:grid = [[1,3,0],[1,0,0],[1,0,3]]\n输出:4\n解释:让每个格子都有一个石头的一个操作序列为:\n1 - 将一个石头从格子 (0,1) 移动到 (0,2) 。\n2 - 将一个石头从格子 (0,1) 移动到 (1,1) 。\n3 - 将一个石头从格子 (2,2) 移动到 (1,2) 。\n4 - 将一个石头从格子 (2,2) 移动到 (2,1) 。\n总共需要 4 次操作让每个格子都有一个石头。\n让每个格子都有一个石头的最少操作次数为 4 。\n\n\n提示:\n\n * grid.length == grid[i].length == 3\n * 0 <= grid[i][j] <= 9\n * grid 中元素之和为 9 。\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def minimumMoves(self, grid: List[List[int]]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"grid\": [[1,1,0],[1,1,1],[1,2,1]] }\nassert my_solution.minimumMoves(**test_input) == 3\n\ntest_input = { \"grid\": [[1,3,0],[1,0,0],[1,0,3]] }\nassert my_solution.minimumMoves(**test_input) == 4\n\ntest_input = { \"grid\": [[1,2,2],[1,1,0],[0,1,1]] }\nassert my_solution.minimumMoves(**test_input) == 4\n\ntest_input = { \"grid\": [[1,3,3],[1,0,0],[0,1,0]] }\nassert my_solution.minimumMoves(**test_input) == 7\n\ntest_input = { \"grid\": [[3,2,0],[0,1,0],[0,3,0]] }\nassert my_solution.minimumMoves(**test_input) == 7\n\ntest_input = { \"grid\": [[1,0,4],[2,0,0],[2,0,0]] }\nassert my_solution.minimumMoves(**test_input) == 6\n\ntest_input = { \"grid\": [[0,1,3],[3,1,0],[0,1,0]] }\nassert my_solution.minimumMoves(**test_input) == 5\n\ntest_input = { \"grid\": [[3,0,0],[0,2,1],[1,0,2]] }\nassert my_solution.minimumMoves(**test_input) == 5\n\ntest_input = { \"grid\": [[1,0,0],[4,1,1],[0,2,0]] }\nassert my_solution.minimumMoves(**test_input) == 7\n\ntest_input = { \"grid\": [[0,2,3],[2,0,1],[0,1,0]] }\nassert my_solution.minimumMoves(**test_input) == 6\n\ntest_input = { \"grid\": [[4,0,0],[0,0,2],[3,0,0]] }\nassert my_solution.minimumMoves(**test_input) == 8\n\ntest_input = { \"grid\": [[3,0,0],[4,1,0],[1,0,0]] }\nassert my_solution.minimumMoves(**test_input) == 10\n\ntest_input = { \"grid\": [[0,2,1],[1,2,0],[3,0,0]] }\nassert my_solution.minimumMoves(**test_input) == 5\n\ntest_input = { \"grid\": [[1,3,0],[0,0,1],[2,1,1]] }\nassert my_solution.minimumMoves(**test_input) == 3\n\ntest_input = { \"grid\": [[3,0,0],[1,0,1],[0,2,2]] }\nassert my_solution.minimumMoves(**test_input) == 6\n\ntest_input = { \"grid\": [[4,2,2],[0,1,0],[0,0,0]] }\nassert my_solution.minimumMoves(**test_input) == 10\n\ntest_input = { \"grid\": [[3,2,1],[1,1,0],[1,0,0]] }\nassert my_solution.minimumMoves(**test_input) == 9\n\ntest_input = { \"grid\": [[0,3,0],[2,0,0],[1,3,0]] }\nassert my_solution.minimumMoves(**test_input) == 6\n\ntest_input = { \"grid\": [[0,0,0],[3,0,0],[4,2,0]] }\nassert my_solution.minimumMoves(**test_input) == 13\n\ntest_input = { \"grid\": [[1,1,2],[0,0,0],[0,4,1]] }\nassert my_solution.minimumMoves(**test_input) == 5\n\ntest_input = { \"grid\": [[4,0,0],[0,0,0],[1,2,2]] }\nassert my_solution.minimumMoves(**test_input) == 6\n\ntest_input = { \"grid\": [[1,3,1],[0,0,0],[1,2,1]] }\nassert my_solution.minimumMoves(**test_input) == 5\n\ntest_input = { \"grid\": [[3,1,0],[1,2,2],[0,0,0]] }\nassert my_solution.minimumMoves(**test_input) == 6\n\ntest_input = { \"grid\": [[2,3,2],[0,1,0],[0,0,1]] }\nassert my_solution.minimumMoves(**test_input) == 7\n\ntest_input = { \"grid\": [[0,1,4],[0,3,0],[0,1,0]] }\nassert my_solution.minimumMoves(**test_input) == 8\n\ntest_input = { \"grid\": [[0,1,0],[1,4,0],[0,3,0]] }\nassert my_solution.minimumMoves(**test_input) == 7\n\ntest_input = { \"grid\": [[0,0,1],[0,0,3],[2,2,1]] }\nassert my_solution.minimumMoves(**test_input) == 7\n\ntest_input = { \"grid\": [[1,0,1],[1,2,0],[1,0,3]] }\nassert my_solution.minimumMoves(**test_input) == 3\n\ntest_input = { \"grid\": [[0,0,0],[4,1,2],[1,1,0]] }\nassert my_solution.minimumMoves(**test_input) == 7\n\ntest_input = { \"grid\": [[2,2,1],[0,2,1],[0,1,0]] }\nassert my_solution.minimumMoves(**test_input) == 6\n\ntest_input = { \"grid\": [[1,0,0],[0,2,0],[4,2,0]] }\nassert my_solution.minimumMoves(**test_input) == 10\n\ntest_input = { \"grid\": [[2,0,1],[4,0,0],[0,2,0]] }\nassert my_solution.minimumMoves(**test_input) == 6\n\ntest_input = { \"grid\": [[0,0,3],[0,2,0],[1,3,0]] }\nassert my_solution.minimumMoves(**test_input) == 7\n\ntest_input = { \"grid\": [[2,0,1],[1,0,0],[4,0,1]] }\nassert my_solution.minimumMoves(**test_input) == 7\n\ntest_input = { \"grid\": [[0,1,0],[1,0,3],[0,3,1]] }\nassert my_solution.minimumMoves(**test_input) == 6\n\ntest_input = { \"grid\": [[0,3,1],[0,0,0],[3,1,1]] }\nassert my_solution.minimumMoves(**test_input) == 6\n\ntest_input = { \"grid\": [[3,0,1],[0,3,1],[0,0,1]] }\nassert my_solution.minimumMoves(**test_input) == 5\n\ntest_input = { \"grid\": [[0,4,0],[1,0,0],[0,2,2]] }\nassert my_solution.minimumMoves(**test_input) == 5\n\ntest_input = { \"grid\": [[4,2,0],[0,0,0],[1,1,1]] }\nassert my_solution.minimumMoves(**test_input) == 7\n\ntest_input = { \"grid\": [[0,2,0],[2,1,2],[0,2,0]] }\nassert my_solution.minimumMoves(**test_input) == 4\n\ntest_input = { \"grid\": [[0,1,0],[2,1,1],[4,0,0]] }\nassert my_solution.minimumMoves(**test_input) == 8\n\ntest_input = { \"grid\": [[0,4,1],[1,0,1],[0,0,2]] }\nassert my_solution.minimumMoves(**test_input) == 6\n\ntest_input = { \"grid\": [[1,0,0],[0,0,0],[1,3,4]] }\nassert my_solution.minimumMoves(**test_input) == 9\n\ntest_input = { \"grid\": [[0,7,1],[0,1,0],[0,0,0]] }\nassert my_solution.minimumMoves(**test_input) == 13\n\ntest_input = { \"grid\": [[0,1,1],[0,2,1],[2,0,2]] }\nassert my_solution.minimumMoves(**test_input) == 4\n\ntest_input = { \"grid\": [[0,2,0],[3,0,0],[3,1,0]] }\nassert my_solution.minimumMoves(**test_input) == 8\n\ntest_input = { \"grid\": [[0,0,0],[2,0,2],[0,2,3]] }\nassert my_solution.minimumMoves(**test_input) == 8\n\ntest_input = { \"grid\": [[0,3,4],[0,1,0],[1,0,0]] }\nassert my_solution.minimumMoves(**test_input) == 9\n\ntest_input = { \"grid\": [[1,0,0],[0,0,1],[7,0,0]] }\nassert my_solution.minimumMoves(**test_input) == 13\n\ntest_input = { \"grid\": [[0,0,2],[2,0,0],[1,4,0]] }\nassert my_solution.minimumMoves(**test_input) == 6\n\ntest_input = { \"grid\": [[2,0,1],[1,3,0],[0,2,0]] }\nassert my_solution.minimumMoves(**test_input) == 5\n\ntest_input = { \"grid\": [[1,0,2],[2,3,0],[1,0,0]] }\nassert my_solution.minimumMoves(**test_input) == 6\n\ntest_input = { \"grid\": [[1,1,2],[0,0,0],[3,1,1]] }\nassert my_solution.minimumMoves(**test_input) == 4\n\ntest_input = { \"grid\": [[0,2,0],[0,1,0],[0,0,6]] }\nassert my_solution.minimumMoves(**test_input) == 10\n\ntest_input = { \"grid\": [[1,1,1],[3,0,0],[2,1,0]] }\nassert my_solution.minimumMoves(**test_input) == 5\n\ntest_input = { \"grid\": [[2,0,0],[2,0,1],[3,1,0]] }\nassert my_solution.minimumMoves(**test_input) == 8\n\ntest_input = { \"grid\": [[1,1,0],[0,2,2],[0,3,0]] }\nassert my_solution.minimumMoves(**test_input) == 4\n\ntest_input = { \"grid\": [[1,0,3],[1,1,0],[1,0,2]] }\nassert my_solution.minimumMoves(**test_input) == 3\n\ntest_input = { \"grid\": [[1,3,0],[2,0,0],[3,0,0]] }\nassert my_solution.minimumMoves(**test_input) == 7\n\ntest_input = { \"grid\": [[1,0,1],[0,0,1],[0,1,5]] }\nassert my_solution.minimumMoves(**test_input) == 10\n\ntest_input = { \"grid\": [[2,0,0],[0,2,1],[1,1,2]] }\nassert my_solution.minimumMoves(**test_input) == 4\n\ntest_input = { \"grid\": [[1,2,3],[1,0,1],[0,0,1]] }\nassert my_solution.minimumMoves(**test_input) == 8\n\ntest_input = { \"grid\": [[0,2,3],[1,0,0],[0,1,2]] }\nassert my_solution.minimumMoves(**test_input) == 6\n\ntest_input = { \"grid\": [[4,1,0],[0,1,1],[2,0,0]] }\nassert my_solution.minimumMoves(**test_input) == 8\n\ntest_input = { \"grid\": [[2,0,1],[1,0,1],[1,2,1]] }\nassert my_solution.minimumMoves(**test_input) == 2\n\ntest_input = { \"grid\": [[3,0,3],[0,0,0],[1,1,1]] }\nassert my_solution.minimumMoves(**test_input) == 5\n\ntest_input = { \"grid\": [[0,0,0],[3,4,2],[0,0,0]] }\nassert my_solution.minimumMoves(**test_input) == 7\n\ntest_input = { \"grid\": [[2,1,2],[0,0,1],[3,0,0]] }\nassert my_solution.minimumMoves(**test_input) == 6\n\ntest_input = { \"grid\": [[1,0,0],[0,3,3],[0,0,2]] }\nassert my_solution.minimumMoves(**test_input) == 7\n\ntest_input = { \"grid\": [[0,2,0],[1,0,1],[1,3,1]] }\nassert my_solution.minimumMoves(**test_input) == 5\n\ntest_input = { \"grid\": [[0,1,0],[2,0,4],[1,0,1]] }\nassert my_solution.minimumMoves(**test_input) == 5\n\ntest_input = { \"grid\": [[1,0,3],[0,0,2],[0,1,2]] }\nassert my_solution.minimumMoves(**test_input) == 7\n\ntest_input = { \"grid\": [[2,1,1],[0,0,0],[0,1,4]] }\nassert my_solution.minimumMoves(**test_input) == 6\n\ntest_input = { \"grid\": [[2,0,1],[0,2,0],[1,3,0]] }\nassert my_solution.minimumMoves(**test_input) == 5\n\ntest_input = { \"grid\": [[2,0,2],[0,0,2],[0,0,3]] }\nassert my_solution.minimumMoves(**test_input) == 6\n\ntest_input = { \"grid\": [[0,2,2],[2,0,1],[1,1,0]] }\nassert my_solution.minimumMoves(**test_input) == 4\n\ntest_input = { \"grid\": [[0,0,1],[2,3,2],[1,0,0]] }\nassert my_solution.minimumMoves(**test_input) == 4\n\ntest_input = { \"grid\": [[1,1,0],[3,0,4],[0,0,0]] }\nassert my_solution.minimumMoves(**test_input) == 6\n\ntest_input = { \"grid\": [[1,0,0],[0,0,0],[5,1,2]] }\nassert my_solution.minimumMoves(**test_input) == 11\n\ntest_input = { \"grid\": [[1,0,0],[3,5,0],[0,0,0]] }\nassert my_solution.minimumMoves(**test_input) == 9\n\ntest_input = { \"grid\": [[3,1,1],[1,1,0],[2,0,0]] }\nassert my_solution.minimumMoves(**test_input) == 8\n\ntest_input = { \"grid\": [[0,1,3],[0,0,1],[1,2,1]] }\nassert my_solution.minimumMoves(**test_input) == 6\n\ntest_input = { \"grid\": [[0,0,0],[1,2,0],[3,0,3]] }\nassert my_solution.minimumMoves(**test_input) == 7\n\ntest_input = { \"grid\": [[0,0,0],[1,2,2],[2,0,2]] }\nassert my_solution.minimumMoves(**test_input) == 5\n\ntest_input = { \"grid\": [[4,0,0],[2,3,0],[0,0,0]] }\nassert my_solution.minimumMoves(**test_input) == 10\n\ntest_input = { \"grid\": [[1,1,0],[1,0,1],[4,1,0]] }\nassert my_solution.minimumMoves(**test_input) == 8\n\ntest_input = { \"grid\": [[0,0,1],[0,1,2],[1,0,4]] }\nassert my_solution.minimumMoves(**test_input) == 10\n\ntest_input = { \"grid\": [[0,1,3],[2,0,0],[0,3,0]] }\nassert my_solution.minimumMoves(**test_input) == 6\n\ntest_input = { \"grid\": [[0,0,0],[5,0,1],[1,1,1]] }\nassert my_solution.minimumMoves(**test_input) == 7\n\ntest_input = { \"grid\": [[0,1,1],[0,0,3],[2,1,1]] }\nassert my_solution.minimumMoves(**test_input) == 5\n\ntest_input = { \"grid\": [[2,0,1],[0,0,1],[2,2,1]] }\nassert my_solution.minimumMoves(**test_input) == 3\n\ntest_input = { \"grid\": [[3,0,2],[2,1,0],[0,0,1]] }\nassert my_solution.minimumMoves(**test_input) == 6\n\ntest_input = { \"grid\": [[0,0,2],[0,0,2],[4,0,1]] }\nassert my_solution.minimumMoves(**test_input) == 6\n\ntest_input = { \"grid\": [[3,0,0],[0,2,0],[0,0,4]] }\nassert my_solution.minimumMoves(**test_input) == 8\n\ntest_input = { \"grid\": [[0,1,3],[1,0,0],[0,4,0]] }\nassert my_solution.minimumMoves(**test_input) == 6\n\ntest_input = { \"grid\": [[2,1,2],[0,2,1],[1,0,0]] }\nassert my_solution.minimumMoves(**test_input) == 4\n\ntest_input = { \"grid\": [[0,0,2],[1,0,3],[1,0,2]] }\nassert my_solution.minimumMoves(**test_input) == 6\n\ntest_input = { \"grid\": [[0,2,2],[0,1,4],[0,0,0]] }\nassert my_solution.minimumMoves(**test_input) == 10\n\ntest_input = { \"grid\": [[1,0,1],[0,0,5],[1,1,0]] }\nassert my_solution.minimumMoves(**test_input) == 6\n\ntest_input = { \"grid\": [[3,1,0],[0,0,0],[0,1,4]] }\nassert my_solution.minimumMoves(**test_input) == 8", "start_time": 1694313000} +{"task_id": "weekly-contest-362-string-transformation", "url": "https://leetcode.com/problems/string-transformation", "title": "string-transformation", "meta": {"questionId": "3024", "questionFrontendId": "2851", "title": "String Transformation", "titleSlug": "string-transformation", "isPaidOnly": false, "difficulty": "Hard", "likes": 140, "dislikes": 19, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你两个长度都为 n 的字符串 s 和 t 。你可以对字符串 s 执行以下操作:\n\n * 将 s 长度为 l (0 < l < n)的 后缀字符串 删除,并将它添加在 s 的开头。\n 比方说,s = 'abcd' ,那么一次操作中,你可以删除后缀 'cd' ,并将它添加到 s 的开头,得到 s = 'cdab' 。\n\n给你一个整数 k ,请你返回 恰好 k 次操作将 s 变为 t 的方案数。\n\n由于答案可能很大,返回答案对 109 + 7 取余 后的结果。\n\n示例 1:\n\n输入:s = \"abcd\", t = \"cdab\", k = 2\n输出:2\n解释:\n第一种方案:\n第一次操作,选择 index = 3 开始的后缀,得到 s = \"dabc\" 。\n第二次操作,选择 index = 3 开始的后缀,得到 s = \"cdab\" 。\n\n第二种方案:\n第一次操作,选择 index = 1 开始的后缀,得到 s = \"bcda\" 。\n第二次操作,选择 index = 1 开始的后缀,得到 s = \"cdab\" 。\n\n示例 2:\n\n输入:s = \"ababab\", t = \"ababab\", k = 1\n输出:2\n解释:\n第一种方案:\n选择 index = 2 开始的后缀,得到 s = \"ababab\" 。\n\n第二种方案:\n选择 index = 4 开始的后缀,得到 s = \"ababab\" 。\n\n\n提示:\n\n * 2 <= s.length <= 5 * 105\n * 1 <= k <= 1015\n * s.length == t.length\n * s 和 t 都只包含小写英文字母。\n\"\"\"\nclass Solution:\n def numberOfWays(self, s: str, t: str, k: int) -> int:\n ", "prompt_sft": "给你两个长度都为 n 的字符串 s 和 t 。你可以对字符串 s 执行以下操作:\n\n * 将 s 长度为 l (0 < l < n)的 后缀字符串 删除,并将它添加在 s 的开头。\n 比方说,s = 'abcd' ,那么一次操作中,你可以删除后缀 'cd' ,并将它添加到 s 的开头,得到 s = 'cdab' 。\n\n给你一个整数 k ,请你返回 恰好 k 次操作将 s 变为 t 的方案数。\n\n由于答案可能很大,返回答案对 109 + 7 取余 后的结果。\n\n示例 1:\n\n输入:s = \"abcd\", t = \"cdab\", k = 2\n输出:2\n解释:\n第一种方案:\n第一次操作,选择 index = 3 开始的后缀,得到 s = \"dabc\" 。\n第二次操作,选择 index = 3 开始的后缀,得到 s = \"cdab\" 。\n\n第二种方案:\n第一次操作,选择 index = 1 开始的后缀,得到 s = \"bcda\" 。\n第二次操作,选择 index = 1 开始的后缀,得到 s = \"cdab\" 。\n\n示例 2:\n\n输入:s = \"ababab\", t = \"ababab\", k = 1\n输出:2\n解释:\n第一种方案:\n选择 index = 2 开始的后缀,得到 s = \"ababab\" 。\n\n第二种方案:\n选择 index = 4 开始的后缀,得到 s = \"ababab\" 。\n\n\n提示:\n\n * 2 <= s.length <= 5 * 105\n * 1 <= k <= 1015\n * s.length == t.length\n * s 和 t 都只包含小写英文字母。\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def numberOfWays(self, s: str, t: str, k: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"s\": \"abcd\", \"t\": \"cdab\", \"k\": 2 }\nassert my_solution.numberOfWays(**test_input) == 2\n\ntest_input = { \"s\": \"ababab\", \"t\": \"ababab\", \"k\": 1 }\nassert my_solution.numberOfWays(**test_input) == 2\n\ntest_input = { \"s\": \"goxoq\", \"t\": \"dfqgl\", \"k\": 244326024901249 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"s\": \"ceoceo\", \"t\": \"eoceoc\", \"k\": 4 }\nassert my_solution.numberOfWays(**test_input) == 208\n\ntest_input = { \"s\": \"ib\", \"t\": \"ib\", \"k\": 10 }\nassert my_solution.numberOfWays(**test_input) == 1\n\ntest_input = { \"s\": \"ttttttt\", \"t\": \"ttttttt\", \"k\": 5 }\nassert my_solution.numberOfWays(**test_input) == 7776\n\ntest_input = { \"s\": \"aaaa\", \"t\": \"aaaa\", \"k\": 8 }\nassert my_solution.numberOfWays(**test_input) == 6561\n\ntest_input = { \"s\": \"meplrmeplr\", \"t\": \"eplrmeplrm\", \"k\": 7 }\nassert my_solution.numberOfWays(**test_input) == 956594\n\ntest_input = { \"s\": \"dsmn\", \"t\": \"smnd\", \"k\": 3 }\nassert my_solution.numberOfWays(**test_input) == 7\n\ntest_input = { \"s\": \"jjj\", \"t\": \"jjj\", \"k\": 10 }\nassert my_solution.numberOfWays(**test_input) == 1024\n\ntest_input = { \"s\": \"rrrrr\", \"t\": \"rrrrr\", \"k\": 1 }\nassert my_solution.numberOfWays(**test_input) == 4\n\ntest_input = { \"s\": \"fefe\", \"t\": \"fefe\", \"k\": 9 }\nassert my_solution.numberOfWays(**test_input) == 9841\n\ntest_input = { \"s\": \"pfly\", \"t\": \"wvqr\", \"k\": 840550364246523 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"s\": \"ltjwwltjww\", \"t\": \"jwwltjwwlt\", \"k\": 1 }\nassert my_solution.numberOfWays(**test_input) == 2\n\ntest_input = { \"s\": \"mb\", \"t\": \"mb\", \"k\": 3 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"s\": \"jjjjjjjjjj\", \"t\": \"jjjjjjjjjj\", \"k\": 3 }\nassert my_solution.numberOfWays(**test_input) == 729\n\ntest_input = { \"s\": \"oqytlmi\", \"t\": \"lmioqyt\", \"k\": 8 }\nassert my_solution.numberOfWays(**test_input) == 239945\n\ntest_input = { \"s\": \"hpcg\", \"t\": \"pcgh\", \"k\": 5 }\nassert my_solution.numberOfWays(**test_input) == 61\n\ntest_input = { \"s\": \"bqbqbqbqbq\", \"t\": \"bqbqbqbqbq\", \"k\": 9 }\nassert my_solution.numberOfWays(**test_input) == 193710244\n\ntest_input = { \"s\": \"ccccccccc\", \"t\": \"ccccccccc\", \"k\": 7 }\nassert my_solution.numberOfWays(**test_input) == 2097152\n\ntest_input = { \"s\": \"jjjjjjjjjj\", \"t\": \"jjjjjjjjjj\", \"k\": 9 }\nassert my_solution.numberOfWays(**test_input) == 387420489\n\ntest_input = { \"s\": \"qqqq\", \"t\": \"qqqq\", \"k\": 9 }\nassert my_solution.numberOfWays(**test_input) == 19683\n\ntest_input = { \"s\": \"loppaqg\", \"t\": \"nvbxtmh\", \"k\": 104865546226045 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"s\": \"qqqqqqqqqq\", \"t\": \"qqqqqqqqqq\", \"k\": 3 }\nassert my_solution.numberOfWays(**test_input) == 729\n\ntest_input = { \"s\": \"qsqsqsqsqs\", \"t\": \"qsqsqsqsqs\", \"k\": 2 }\nassert my_solution.numberOfWays(**test_input) == 41\n\ntest_input = { \"s\": \"nnnnn\", \"t\": \"nnnnn\", \"k\": 5 }\nassert my_solution.numberOfWays(**test_input) == 1024\n\ntest_input = { \"s\": \"klncccd\", \"t\": \"klncccd\", \"k\": 1 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"s\": \"qqqqq\", \"t\": \"qqqqq\", \"k\": 9 }\nassert my_solution.numberOfWays(**test_input) == 262144\n\ntest_input = { \"s\": \"qvxrlh\", \"t\": \"hqvxrl\", \"k\": 6 }\nassert my_solution.numberOfWays(**test_input) == 2604\n\ntest_input = { \"s\": \"uuuu\", \"t\": \"uuuu\", \"k\": 9 }\nassert my_solution.numberOfWays(**test_input) == 19683\n\ntest_input = { \"s\": \"sss\", \"t\": \"sss\", \"k\": 7 }\nassert my_solution.numberOfWays(**test_input) == 128\n\ntest_input = { \"s\": \"gggggggggg\", \"t\": \"gggggggggg\", \"k\": 1 }\nassert my_solution.numberOfWays(**test_input) == 9\n\ntest_input = { \"s\": \"ks\", \"t\": \"cj\", \"k\": 400700574233583 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"s\": \"lllllllll\", \"t\": \"lllllllll\", \"k\": 5 }\nassert my_solution.numberOfWays(**test_input) == 32768\n\ntest_input = { \"s\": \"uhixx\", \"t\": \"xxuhi\", \"k\": 3 }\nassert my_solution.numberOfWays(**test_input) == 13\n\ntest_input = { \"s\": \"vkrvkrvkr\", \"t\": \"rvkrvkrvk\", \"k\": 2 }\nassert my_solution.numberOfWays(**test_input) == 21\n\ntest_input = { \"s\": \"xtxtxtxt\", \"t\": \"xtxtxtxt\", \"k\": 8 }\nassert my_solution.numberOfWays(**test_input) == 2882401\n\ntest_input = { \"s\": \"nzybrhi\", \"t\": \"rhinzyb\", \"k\": 6 }\nassert my_solution.numberOfWays(**test_input) == 6665\n\ntest_input = { \"s\": \"ff\", \"t\": \"ff\", \"k\": 4 }\nassert my_solution.numberOfWays(**test_input) == 1\n\ntest_input = { \"s\": \"ubagdasws\", \"t\": \"aswsubagd\", \"k\": 9 }\nassert my_solution.numberOfWays(**test_input) == 14913081\n\ntest_input = { \"s\": \"aaaaa\", \"t\": \"aaaaa\", \"k\": 10 }\nassert my_solution.numberOfWays(**test_input) == 1048576\n\ntest_input = { \"s\": \"iiiiiiiiii\", \"t\": \"iiiiiiiiii\", \"k\": 4 }\nassert my_solution.numberOfWays(**test_input) == 6561\n\ntest_input = { \"s\": \"nnjqjmgome\", \"t\": \"gbfuecwlqc\", \"k\": 359221508193514 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"s\": \"slmzyj\", \"t\": \"slmzyj\", \"k\": 4 }\nassert my_solution.numberOfWays(**test_input) == 105\n\ntest_input = { \"s\": \"vfyxl\", \"t\": \"vfyxl\", \"k\": 10 }\nassert my_solution.numberOfWays(**test_input) == 209716\n\ntest_input = { \"s\": \"sxzfvsxzfv\", \"t\": \"vsxzfvsxzf\", \"k\": 2 }\nassert my_solution.numberOfWays(**test_input) == 16\n\ntest_input = { \"s\": \"kalt\", \"t\": \"ltka\", \"k\": 7 }\nassert my_solution.numberOfWays(**test_input) == 547\n\ntest_input = { \"s\": \"jj\", \"t\": \"jj\", \"k\": 7 }\nassert my_solution.numberOfWays(**test_input) == 1\n\ntest_input = { \"s\": \"bcriunp\", \"t\": \"criunpb\", \"k\": 2 }\nassert my_solution.numberOfWays(**test_input) == 5\n\ntest_input = { \"s\": \"rutmzyj\", \"t\": \"zyjrutm\", \"k\": 6 }\nassert my_solution.numberOfWays(**test_input) == 6665\n\ntest_input = { \"s\": \"vvvvv\", \"t\": \"vvvvv\", \"k\": 3 }\nassert my_solution.numberOfWays(**test_input) == 64\n\ntest_input = { \"s\": \"hlld\", \"t\": \"hlld\", \"k\": 9 }\nassert my_solution.numberOfWays(**test_input) == 4920\n\ntest_input = { \"s\": \"kctcsgswa\", \"t\": \"qfyyjeohe\", \"k\": 966836940319300 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"s\": \"otwqxmpktt\", \"t\": \"totwqxmpkt\", \"k\": 7 }\nassert my_solution.numberOfWays(**test_input) == 478297\n\ntest_input = { \"s\": \"kkkkkkk\", \"t\": \"kkkkkkk\", \"k\": 7 }\nassert my_solution.numberOfWays(**test_input) == 279936\n\ntest_input = { \"s\": \"iyl\", \"t\": \"iyl\", \"k\": 6 }\nassert my_solution.numberOfWays(**test_input) == 22\n\ntest_input = { \"s\": \"glao\", \"t\": \"ogla\", \"k\": 10 }\nassert my_solution.numberOfWays(**test_input) == 14762\n\ntest_input = { \"s\": \"jp\", \"t\": \"jp\", \"k\": 8 }\nassert my_solution.numberOfWays(**test_input) == 1\n\ntest_input = { \"s\": \"uuuuuu\", \"t\": \"uuuuuu\", \"k\": 7 }\nassert my_solution.numberOfWays(**test_input) == 78125\n\ntest_input = { \"s\": \"achach\", \"t\": \"achach\", \"k\": 10 }\nassert my_solution.numberOfWays(**test_input) == 3255209\n\ntest_input = { \"s\": \"uuuuuuuu\", \"t\": \"uuuuuuuu\", \"k\": 7 }\nassert my_solution.numberOfWays(**test_input) == 823543\n\ntest_input = { \"s\": \"gjh\", \"t\": \"jhg\", \"k\": 9 }\nassert my_solution.numberOfWays(**test_input) == 171\n\ntest_input = { \"s\": \"cliuw\", \"t\": \"fphcn\", \"k\": 647756904366432 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"s\": \"zmcum\", \"t\": \"mzmcu\", \"k\": 1 }\nassert my_solution.numberOfWays(**test_input) == 1\n\ntest_input = { \"s\": \"ll\", \"t\": \"ll\", \"k\": 5 }\nassert my_solution.numberOfWays(**test_input) == 1\n\ntest_input = { \"s\": \"ccccc\", \"t\": \"ccccc\", \"k\": 1 }\nassert my_solution.numberOfWays(**test_input) == 4\n\ntest_input = { \"s\": \"rrrr\", \"t\": \"rrrr\", \"k\": 1 }\nassert my_solution.numberOfWays(**test_input) == 3\n\ntest_input = { \"s\": \"ih\", \"t\": \"hi\", \"k\": 8 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"s\": \"qfgihqrw\", \"t\": \"rwqfgihq\", \"k\": 8 }\nassert my_solution.numberOfWays(**test_input) == 720600\n\ntest_input = { \"s\": \"cd\", \"t\": \"cd\", \"k\": 2 }\nassert my_solution.numberOfWays(**test_input) == 1\n\ntest_input = { \"s\": \"oooooooooo\", \"t\": \"oooooooooo\", \"k\": 4 }\nassert my_solution.numberOfWays(**test_input) == 6561\n\ntest_input = { \"s\": \"wp\", \"t\": \"wp\", \"k\": 6 }\nassert my_solution.numberOfWays(**test_input) == 1\n\ntest_input = { \"s\": \"rqq\", \"t\": \"nln\", \"k\": 776508964349618 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"s\": \"rr\", \"t\": \"rr\", \"k\": 9 }\nassert my_solution.numberOfWays(**test_input) == 1\n\ntest_input = { \"s\": \"knwppsd\", \"t\": \"psdknwp\", \"k\": 2 }\nassert my_solution.numberOfWays(**test_input) == 5\n\ntest_input = { \"s\": \"epfeepfe\", \"t\": \"feepfeep\", \"k\": 9 }\nassert my_solution.numberOfWays(**test_input) == 10088402\n\ntest_input = { \"s\": \"wwwww\", \"t\": \"wwwww\", \"k\": 9 }\nassert my_solution.numberOfWays(**test_input) == 262144\n\ntest_input = { \"s\": \"cdcdcdcd\", \"t\": \"cdcdcdcd\", \"k\": 6 }\nassert my_solution.numberOfWays(**test_input) == 58825\n\ntest_input = { \"s\": \"uphfr\", \"t\": \"fruph\", \"k\": 7 }\nassert my_solution.numberOfWays(**test_input) == 3277\n\ntest_input = { \"s\": \"cocococo\", \"t\": \"cocococo\", \"k\": 3 }\nassert my_solution.numberOfWays(**test_input) == 171\n\ntest_input = { \"s\": \"vhzjo\", \"t\": \"jovhz\", \"k\": 1 }\nassert my_solution.numberOfWays(**test_input) == 1\n\ntest_input = { \"s\": \"bbbbbbbbbb\", \"t\": \"bbbbbbbbbb\", \"k\": 1 }\nassert my_solution.numberOfWays(**test_input) == 9\n\ntest_input = { \"s\": \"pgnrstuh\", \"t\": \"yjzhldlg\", \"k\": 618648276258027 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"s\": \"cccccc\", \"t\": \"cccccc\", \"k\": 5 }\nassert my_solution.numberOfWays(**test_input) == 3125\n\ntest_input = { \"s\": \"kkkkkkk\", \"t\": \"kkkkkkk\", \"k\": 3 }\nassert my_solution.numberOfWays(**test_input) == 216\n\ntest_input = { \"s\": \"lxqqzsvej\", \"t\": \"svejlxqqz\", \"k\": 3 }\nassert my_solution.numberOfWays(**test_input) == 57\n\ntest_input = { \"s\": \"lllll\", \"t\": \"lllll\", \"k\": 3 }\nassert my_solution.numberOfWays(**test_input) == 64\n\ntest_input = { \"s\": \"hhhhhhhhhh\", \"t\": \"hhhhhhhhhh\", \"k\": 8 }\nassert my_solution.numberOfWays(**test_input) == 43046721\n\ntest_input = { \"s\": \"gggg\", \"t\": \"gggg\", \"k\": 5 }\nassert my_solution.numberOfWays(**test_input) == 243\n\ntest_input = { \"s\": \"jj\", \"t\": \"jj\", \"k\": 6 }\nassert my_solution.numberOfWays(**test_input) == 1\n\ntest_input = { \"s\": \"uuuuuuuuu\", \"t\": \"uuuuuuuuu\", \"k\": 10 }\nassert my_solution.numberOfWays(**test_input) == 73741817\n\ntest_input = { \"s\": \"qvx\", \"t\": \"vxq\", \"k\": 8 }\nassert my_solution.numberOfWays(**test_input) == 85\n\ntest_input = { \"s\": \"nolnqlgqcs\", \"t\": \"jkguybcfcu\", \"k\": 179216079747558 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"s\": \"xpk\", \"t\": \"xpk\", \"k\": 6 }\nassert my_solution.numberOfWays(**test_input) == 22\n\ntest_input = { \"s\": \"xzoyb\", \"t\": \"bxzoy\", \"k\": 5 }\nassert my_solution.numberOfWays(**test_input) == 205\n\ntest_input = { \"s\": \"krxjvvg\", \"t\": \"krxjvvg\", \"k\": 2 }\nassert my_solution.numberOfWays(**test_input) == 6\n\ntest_input = { \"s\": \"ks\", \"t\": \"sk\", \"k\": 2 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"s\": \"ty\", \"t\": \"ty\", \"k\": 6 }\nassert my_solution.numberOfWays(**test_input) == 1\n\ntest_input = { \"s\": \"otototot\", \"t\": \"totototo\", \"k\": 7 }\nassert my_solution.numberOfWays(**test_input) == 411772\n\ntest_input = { \"s\": \"uoaowbdznp\", \"t\": \"npuoaowbdz\", \"k\": 10 }\nassert my_solution.numberOfWays(**test_input) == 348678440", "start_time": 1694313000} +{"task_id": "weekly-contest-361-count-symmetric-integers", "url": "https://leetcode.com/problems/count-symmetric-integers", "title": "count-symmetric-integers", "meta": {"questionId": "2998", "questionFrontendId": "2843", "title": " Count Symmetric Integers", "titleSlug": "count-symmetric-integers", "isPaidOnly": false, "difficulty": "Easy", "likes": 210, "dislikes": 9, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你两个正整数 low 和 high 。\n\n对于一个由 2 * n 位数字组成的整数 x ,如果其前 n 位数字之和与后 n 位数字之和相等,则认为这个数字是一个对称整数。\n\n返回在 [low, high] 范围内的 对称整数的数目 。\n\n示例 1:\n\n输入:low = 1, high = 100\n输出:9\n解释:在 1 到 100 范围内共有 9 个对称整数:11、22、33、44、55、66、77、88 和 99 。\n\n示例 2:\n\n输入:low = 1200, high = 1230\n输出:4\n解释:在 1200 到 1230 范围内共有 4 个对称整数:1203、1212、1221 和 1230 。\n\n\n提示:\n\n * 1 <= low <= high <= 104\n\"\"\"\nclass Solution:\n def countSymmetricIntegers(self, low: int, high: int) -> int:\n ", "prompt_sft": "给你两个正整数 low 和 high 。\n\n对于一个由 2 * n 位数字组成的整数 x ,如果其前 n 位数字之和与后 n 位数字之和相等,则认为这个数字是一个对称整数。\n\n返回在 [low, high] 范围内的 对称整数的数目 。\n\n示例 1:\n\n输入:low = 1, high = 100\n输出:9\n解释:在 1 到 100 范围内共有 9 个对称整数:11、22、33、44、55、66、77、88 和 99 。\n\n示例 2:\n\n输入:low = 1200, high = 1230\n输出:4\n解释:在 1200 到 1230 范围内共有 4 个对称整数:1203、1212、1221 和 1230 。\n\n\n提示:\n\n * 1 <= low <= high <= 104\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def countSymmetricIntegers(self, low: int, high: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"low\": 1, \"high\": 100 }\nassert my_solution.countSymmetricIntegers(**test_input) == 9\n\ntest_input = { \"low\": 1200, \"high\": 1230 }\nassert my_solution.countSymmetricIntegers(**test_input) == 4\n\ntest_input = { \"low\": 1, \"high\": 1 }\nassert my_solution.countSymmetricIntegers(**test_input) == 0\n\ntest_input = { \"low\": 1, \"high\": 2 }\nassert my_solution.countSymmetricIntegers(**test_input) == 0\n\ntest_input = { \"low\": 1, \"high\": 3 }\nassert my_solution.countSymmetricIntegers(**test_input) == 0\n\ntest_input = { \"low\": 1, \"high\": 4 }\nassert my_solution.countSymmetricIntegers(**test_input) == 0\n\ntest_input = { \"low\": 1, \"high\": 5 }\nassert my_solution.countSymmetricIntegers(**test_input) == 0\n\ntest_input = { \"low\": 1, \"high\": 6 }\nassert my_solution.countSymmetricIntegers(**test_input) == 0\n\ntest_input = { \"low\": 1, \"high\": 7 }\nassert my_solution.countSymmetricIntegers(**test_input) == 0\n\ntest_input = { \"low\": 1, \"high\": 8 }\nassert my_solution.countSymmetricIntegers(**test_input) == 0\n\ntest_input = { \"low\": 1, \"high\": 9 }\nassert my_solution.countSymmetricIntegers(**test_input) == 0\n\ntest_input = { \"low\": 1, \"high\": 10 }\nassert my_solution.countSymmetricIntegers(**test_input) == 0\n\ntest_input = { \"low\": 1, \"high\": 11 }\nassert my_solution.countSymmetricIntegers(**test_input) == 1\n\ntest_input = { \"low\": 1, \"high\": 12 }\nassert my_solution.countSymmetricIntegers(**test_input) == 1\n\ntest_input = { \"low\": 1, \"high\": 13 }\nassert my_solution.countSymmetricIntegers(**test_input) == 1\n\ntest_input = { \"low\": 1, \"high\": 14 }\nassert my_solution.countSymmetricIntegers(**test_input) == 1\n\ntest_input = { \"low\": 1, \"high\": 15 }\nassert my_solution.countSymmetricIntegers(**test_input) == 1\n\ntest_input = { \"low\": 1, \"high\": 16 }\nassert my_solution.countSymmetricIntegers(**test_input) == 1\n\ntest_input = { \"low\": 1, \"high\": 17 }\nassert my_solution.countSymmetricIntegers(**test_input) == 1\n\ntest_input = { \"low\": 1, \"high\": 18 }\nassert my_solution.countSymmetricIntegers(**test_input) == 1\n\ntest_input = { \"low\": 1, \"high\": 19 }\nassert my_solution.countSymmetricIntegers(**test_input) == 1\n\ntest_input = { \"low\": 1, \"high\": 20 }\nassert my_solution.countSymmetricIntegers(**test_input) == 1\n\ntest_input = { \"low\": 1, \"high\": 21 }\nassert my_solution.countSymmetricIntegers(**test_input) == 1\n\ntest_input = { \"low\": 1, \"high\": 22 }\nassert my_solution.countSymmetricIntegers(**test_input) == 2\n\ntest_input = { \"low\": 1, \"high\": 23 }\nassert my_solution.countSymmetricIntegers(**test_input) == 2\n\ntest_input = { \"low\": 1, \"high\": 24 }\nassert my_solution.countSymmetricIntegers(**test_input) == 2\n\ntest_input = { \"low\": 1, \"high\": 25 }\nassert my_solution.countSymmetricIntegers(**test_input) == 2\n\ntest_input = { \"low\": 1, \"high\": 26 }\nassert my_solution.countSymmetricIntegers(**test_input) == 2\n\ntest_input = { \"low\": 1, \"high\": 27 }\nassert my_solution.countSymmetricIntegers(**test_input) == 2\n\ntest_input = { \"low\": 1, \"high\": 28 }\nassert my_solution.countSymmetricIntegers(**test_input) == 2\n\ntest_input = { \"low\": 1, \"high\": 29 }\nassert my_solution.countSymmetricIntegers(**test_input) == 2\n\ntest_input = { \"low\": 1, \"high\": 30 }\nassert my_solution.countSymmetricIntegers(**test_input) == 2\n\ntest_input = { \"low\": 1, \"high\": 31 }\nassert my_solution.countSymmetricIntegers(**test_input) == 2\n\ntest_input = { \"low\": 1, \"high\": 32 }\nassert my_solution.countSymmetricIntegers(**test_input) == 2\n\ntest_input = { \"low\": 1, \"high\": 33 }\nassert my_solution.countSymmetricIntegers(**test_input) == 3\n\ntest_input = { \"low\": 1, \"high\": 34 }\nassert my_solution.countSymmetricIntegers(**test_input) == 3\n\ntest_input = { \"low\": 1, \"high\": 35 }\nassert my_solution.countSymmetricIntegers(**test_input) == 3\n\ntest_input = { \"low\": 1, \"high\": 36 }\nassert my_solution.countSymmetricIntegers(**test_input) == 3\n\ntest_input = { \"low\": 1, \"high\": 37 }\nassert my_solution.countSymmetricIntegers(**test_input) == 3\n\ntest_input = { \"low\": 1, \"high\": 38 }\nassert my_solution.countSymmetricIntegers(**test_input) == 3\n\ntest_input = { \"low\": 1, \"high\": 39 }\nassert my_solution.countSymmetricIntegers(**test_input) == 3\n\ntest_input = { \"low\": 1, \"high\": 40 }\nassert my_solution.countSymmetricIntegers(**test_input) == 3\n\ntest_input = { \"low\": 1, \"high\": 41 }\nassert my_solution.countSymmetricIntegers(**test_input) == 3\n\ntest_input = { \"low\": 1, \"high\": 42 }\nassert my_solution.countSymmetricIntegers(**test_input) == 3\n\ntest_input = { \"low\": 1, \"high\": 43 }\nassert my_solution.countSymmetricIntegers(**test_input) == 3\n\ntest_input = { \"low\": 1, \"high\": 44 }\nassert my_solution.countSymmetricIntegers(**test_input) == 4\n\ntest_input = { \"low\": 1, \"high\": 45 }\nassert my_solution.countSymmetricIntegers(**test_input) == 4\n\ntest_input = { \"low\": 1, \"high\": 46 }\nassert my_solution.countSymmetricIntegers(**test_input) == 4\n\ntest_input = { \"low\": 1, \"high\": 47 }\nassert my_solution.countSymmetricIntegers(**test_input) == 4\n\ntest_input = { \"low\": 1, \"high\": 48 }\nassert my_solution.countSymmetricIntegers(**test_input) == 4\n\ntest_input = { \"low\": 100, \"high\": 1782 }\nassert my_solution.countSymmetricIntegers(**test_input) == 44\n\ntest_input = { \"low\": 1, \"high\": 49 }\nassert my_solution.countSymmetricIntegers(**test_input) == 4\n\ntest_input = { \"low\": 1, \"high\": 50 }\nassert my_solution.countSymmetricIntegers(**test_input) == 4\n\ntest_input = { \"low\": 1, \"high\": 51 }\nassert my_solution.countSymmetricIntegers(**test_input) == 4\n\ntest_input = { \"low\": 1, \"high\": 52 }\nassert my_solution.countSymmetricIntegers(**test_input) == 4\n\ntest_input = { \"low\": 1, \"high\": 53 }\nassert my_solution.countSymmetricIntegers(**test_input) == 4\n\ntest_input = { \"low\": 1, \"high\": 54 }\nassert my_solution.countSymmetricIntegers(**test_input) == 4\n\ntest_input = { \"low\": 1, \"high\": 55 }\nassert my_solution.countSymmetricIntegers(**test_input) == 5\n\ntest_input = { \"low\": 1, \"high\": 56 }\nassert my_solution.countSymmetricIntegers(**test_input) == 5\n\ntest_input = { \"low\": 1, \"high\": 57 }\nassert my_solution.countSymmetricIntegers(**test_input) == 5\n\ntest_input = { \"low\": 1, \"high\": 58 }\nassert my_solution.countSymmetricIntegers(**test_input) == 5\n\ntest_input = { \"low\": 1, \"high\": 59 }\nassert my_solution.countSymmetricIntegers(**test_input) == 5\n\ntest_input = { \"low\": 1, \"high\": 60 }\nassert my_solution.countSymmetricIntegers(**test_input) == 5\n\ntest_input = { \"low\": 2, \"high\": 2 }\nassert my_solution.countSymmetricIntegers(**test_input) == 0\n\ntest_input = { \"low\": 2, \"high\": 3 }\nassert my_solution.countSymmetricIntegers(**test_input) == 0\n\ntest_input = { \"low\": 2, \"high\": 4 }\nassert my_solution.countSymmetricIntegers(**test_input) == 0\n\ntest_input = { \"low\": 2, \"high\": 5 }\nassert my_solution.countSymmetricIntegers(**test_input) == 0\n\ntest_input = { \"low\": 2, \"high\": 6 }\nassert my_solution.countSymmetricIntegers(**test_input) == 0\n\ntest_input = { \"low\": 2, \"high\": 7 }\nassert my_solution.countSymmetricIntegers(**test_input) == 0\n\ntest_input = { \"low\": 2, \"high\": 8 }\nassert my_solution.countSymmetricIntegers(**test_input) == 0\n\ntest_input = { \"low\": 2, \"high\": 9 }\nassert my_solution.countSymmetricIntegers(**test_input) == 0\n\ntest_input = { \"low\": 2, \"high\": 10 }\nassert my_solution.countSymmetricIntegers(**test_input) == 0\n\ntest_input = { \"low\": 2, \"high\": 11 }\nassert my_solution.countSymmetricIntegers(**test_input) == 1\n\ntest_input = { \"low\": 2, \"high\": 12 }\nassert my_solution.countSymmetricIntegers(**test_input) == 1\n\ntest_input = { \"low\": 2, \"high\": 13 }\nassert my_solution.countSymmetricIntegers(**test_input) == 1\n\ntest_input = { \"low\": 2, \"high\": 14 }\nassert my_solution.countSymmetricIntegers(**test_input) == 1\n\ntest_input = { \"low\": 2, \"high\": 15 }\nassert my_solution.countSymmetricIntegers(**test_input) == 1\n\ntest_input = { \"low\": 2, \"high\": 16 }\nassert my_solution.countSymmetricIntegers(**test_input) == 1\n\ntest_input = { \"low\": 2, \"high\": 17 }\nassert my_solution.countSymmetricIntegers(**test_input) == 1\n\ntest_input = { \"low\": 2, \"high\": 18 }\nassert my_solution.countSymmetricIntegers(**test_input) == 1\n\ntest_input = { \"low\": 2, \"high\": 19 }\nassert my_solution.countSymmetricIntegers(**test_input) == 1\n\ntest_input = { \"low\": 2, \"high\": 20 }\nassert my_solution.countSymmetricIntegers(**test_input) == 1\n\ntest_input = { \"low\": 2, \"high\": 21 }\nassert my_solution.countSymmetricIntegers(**test_input) == 1\n\ntest_input = { \"low\": 2, \"high\": 22 }\nassert my_solution.countSymmetricIntegers(**test_input) == 2\n\ntest_input = { \"low\": 2, \"high\": 23 }\nassert my_solution.countSymmetricIntegers(**test_input) == 2\n\ntest_input = { \"low\": 2, \"high\": 24 }\nassert my_solution.countSymmetricIntegers(**test_input) == 2\n\ntest_input = { \"low\": 2, \"high\": 25 }\nassert my_solution.countSymmetricIntegers(**test_input) == 2\n\ntest_input = { \"low\": 2, \"high\": 26 }\nassert my_solution.countSymmetricIntegers(**test_input) == 2\n\ntest_input = { \"low\": 2, \"high\": 27 }\nassert my_solution.countSymmetricIntegers(**test_input) == 2\n\ntest_input = { \"low\": 2, \"high\": 28 }\nassert my_solution.countSymmetricIntegers(**test_input) == 2\n\ntest_input = { \"low\": 2, \"high\": 29 }\nassert my_solution.countSymmetricIntegers(**test_input) == 2\n\ntest_input = { \"low\": 2, \"high\": 30 }\nassert my_solution.countSymmetricIntegers(**test_input) == 2\n\ntest_input = { \"low\": 2, \"high\": 31 }\nassert my_solution.countSymmetricIntegers(**test_input) == 2\n\ntest_input = { \"low\": 2, \"high\": 32 }\nassert my_solution.countSymmetricIntegers(**test_input) == 2\n\ntest_input = { \"low\": 2, \"high\": 33 }\nassert my_solution.countSymmetricIntegers(**test_input) == 3\n\ntest_input = { \"low\": 2, \"high\": 34 }\nassert my_solution.countSymmetricIntegers(**test_input) == 3\n\ntest_input = { \"low\": 2, \"high\": 35 }\nassert my_solution.countSymmetricIntegers(**test_input) == 3\n\ntest_input = { \"low\": 2, \"high\": 36 }\nassert my_solution.countSymmetricIntegers(**test_input) == 3\n\ntest_input = { \"low\": 2, \"high\": 37 }\nassert my_solution.countSymmetricIntegers(**test_input) == 3\n\ntest_input = { \"low\": 2, \"high\": 38 }\nassert my_solution.countSymmetricIntegers(**test_input) == 3", "start_time": 1693708200} +{"task_id": "weekly-contest-361-minimum-operations-to-make-a-special-number", "url": "https://leetcode.com/problems/minimum-operations-to-make-a-special-number", "title": "minimum-operations-to-make-a-special-number", "meta": {"questionId": "3046", "questionFrontendId": "2844", "title": "Minimum Operations to Make a Special Number", "titleSlug": "minimum-operations-to-make-a-special-number", "isPaidOnly": false, "difficulty": "Medium", "likes": 317, "dislikes": 48, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0 开始的字符串 num ,表示一个非负整数。\n\n在一次操作中,您可以选择 num 的任意一位数字并将其删除。请注意,如果你删除 num 中的所有数字,则 num 变为 0。\n\n返回最少需要多少次操作可以使 num 变成特殊数字。\n\n如果整数 x 能被 25 整除,则该整数 x 被认为是特殊数字。\n\n\n示例 1:\n\n输入:num = \"2245047\"\n输出:2\n解释:删除数字 num[5] 和 num[6] ,得到数字 \"22450\" ,可以被 25 整除。\n可以证明要使数字变成特殊数字,最少需要删除 2 位数字。\n\n示例 2:\n\n输入:num = \"2908305\"\n输出:3\n解释:删除 num[3]、num[4] 和 num[6] ,得到数字 \"2900\" ,可以被 25 整除。\n可以证明要使数字变成特殊数字,最少需要删除 3 位数字。\n\n示例 3:\n\n输入:num = \"10\"\n输出:1\n解释:删除 num[0] ,得到数字 \"0\" ,可以被 25 整除。\n可以证明要使数字变成特殊数字,最少需要删除 1 位数字。\n\n\n提示\n\n * 1 <= num.length <= 100\n * num 仅由数字 '0' 到 '9' 组成\n * num 不含任何前导零\n\"\"\"\nclass Solution:\n def minimumOperations(self, num: str) -> int:\n ", "prompt_sft": "给你一个下标从 0 开始的字符串 num ,表示一个非负整数。\n\n在一次操作中,您可以选择 num 的任意一位数字并将其删除。请注意,如果你删除 num 中的所有数字,则 num 变为 0。\n\n返回最少需要多少次操作可以使 num 变成特殊数字。\n\n如果整数 x 能被 25 整除,则该整数 x 被认为是特殊数字。\n\n\n示例 1:\n\n输入:num = \"2245047\"\n输出:2\n解释:删除数字 num[5] 和 num[6] ,得到数字 \"22450\" ,可以被 25 整除。\n可以证明要使数字变成特殊数字,最少需要删除 2 位数字。\n\n示例 2:\n\n输入:num = \"2908305\"\n输出:3\n解释:删除 num[3]、num[4] 和 num[6] ,得到数字 \"2900\" ,可以被 25 整除。\n可以证明要使数字变成特殊数字,最少需要删除 3 位数字。\n\n示例 3:\n\n输入:num = \"10\"\n输出:1\n解释:删除 num[0] ,得到数字 \"0\" ,可以被 25 整除。\n可以证明要使数字变成特殊数字,最少需要删除 1 位数字。\n\n\n提示\n\n * 1 <= num.length <= 100\n * num 仅由数字 '0' 到 '9' 组成\n * num 不含任何前导零\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def minimumOperations(self, num: str) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"num\": \"2245047\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"2908305\" }\nassert my_solution.minimumOperations(**test_input) == 3\n\ntest_input = { \"num\": \"10\" }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"num\": \"1\" }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"num\": \"2\" }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"num\": \"3\" }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"num\": \"4\" }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"num\": \"5\" }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"num\": \"6\" }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"num\": \"7\" }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"num\": \"8\" }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"num\": \"9\" }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"num\": \"11\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"12\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"13\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"14\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"15\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"16\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"17\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"18\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"19\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"20\" }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"num\": \"21\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"22\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"23\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"24\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"25\" }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"num\": \"26\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"27\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"28\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"29\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"30\" }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"num\": \"31\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"32\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"33\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"34\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"35\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"36\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"37\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"38\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"39\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"40\" }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"num\": \"41\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"42\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"43\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"44\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"45\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"46\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"47\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"48\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"49\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"50\" }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"num\": \"51\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"52\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"53\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"54\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"55\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"56\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"57\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"58\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"59\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"60\" }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"num\": \"61\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"62\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"63\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"64\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"65\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"66\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"67\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"68\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"69\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"70\" }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"num\": \"71\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"72\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"73\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"74\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"75\" }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"num\": \"76\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"77\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"78\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"79\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"80\" }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"num\": \"81\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"82\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"83\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"84\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"85\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"86\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"87\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"88\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"89\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"90\" }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"num\": \"91\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"92\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"93\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"94\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"95\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"96\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"97\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"98\" }\nassert my_solution.minimumOperations(**test_input) == 2", "start_time": 1693708200} +{"task_id": "weekly-contest-361-count-of-interesting-subarrays", "url": "https://leetcode.com/problems/count-of-interesting-subarrays", "title": "count-of-interesting-subarrays", "meta": {"questionId": "2915", "questionFrontendId": "2845", "title": "Count of Interesting Subarrays", "titleSlug": "count-of-interesting-subarrays", "isPaidOnly": false, "difficulty": "Medium", "likes": 449, "dislikes": 62, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0 开始的整数数组 nums ,以及整数 modulo 和整数 k 。\n\n请你找出并统计数组中 趣味子数组 的数目。\n\n如果 子数组 nums[l..r] 满足下述条件,则称其为 趣味子数组 :\n\n * 在范围 [l, r] 内,设 cnt 为满足 nums[i] % modulo == k 的索引 i 的数量。并且 cnt % modulo == k 。\n\n以整数形式表示并返回趣味子数组的数目。\n\n注意:子数组是数组中的一个连续非空的元素序列。\n\n示例 1:\n\n输入:nums = [3,2,4], modulo = 2, k = 1\n输出:3\n解释:在这个示例中,趣味子数组分别是:\n子数组 nums[0..0] ,也就是 [3] 。\n- 在范围 [0, 0] 内,只存在 1 个下标 i = 0 满足 nums[i] % modulo == k 。\n- 因此 cnt = 1 ,且 cnt % modulo == k 。\n子数组 nums[0..1] ,也就是 [3,2] 。\n- 在范围 [0, 1] 内,只存在 1 个下标 i = 0 满足 nums[i] % modulo == k 。\n- 因此 cnt = 1 ,且 cnt % modulo == k 。\n子数组 nums[0..2] ,也就是 [3,2,4] 。\n- 在范围 [0, 2] 内,只存在 1 个下标 i = 0 满足 nums[i] % modulo == k 。\n- 因此 cnt = 1 ,且 cnt % modulo == k 。\n可以证明不存在其他趣味子数组。因此,答案为 3 。\n\n示例 2:\n\n输入:nums = [3,1,9,6], modulo = 3, k = 0\n输出:2\n解释:在这个示例中,趣味子数组分别是:\n子数组 nums[0..3] ,也就是 [3,1,9,6] 。\n- 在范围 [0, 3] 内,只存在 3 个下标 i = 0, 2, 3 满足 nums[i] % modulo == k 。\n- 因此 cnt = 3 ,且 cnt % modulo == k 。\n子数组 nums[1..1] ,也就是 [1] 。\n- 在范围 [1, 1] 内,不存在下标满足 nums[i] % modulo == k 。\n- 因此 cnt = 0 ,且 cnt % modulo == k 。\n可以证明不存在其他趣味子数组,因此答案为 2 。\n\n提示:\n\n * 1 <= nums.length <= 105\n * 1 <= nums[i] <= 109\n * 1 <= modulo <= 109\n * 0 <= k < modulo\n\"\"\"\nclass Solution:\n def countInterestingSubarrays(self, nums: List[int], modulo: int, k: int) -> int:\n ", "prompt_sft": "给你一个下标从 0 开始的整数数组 nums ,以及整数 modulo 和整数 k 。\n\n请你找出并统计数组中 趣味子数组 的数目。\n\n如果 子数组 nums[l..r] 满足下述条件,则称其为 趣味子数组 :\n\n * 在范围 [l, r] 内,设 cnt 为满足 nums[i] % modulo == k 的索引 i 的数量。并且 cnt % modulo == k 。\n\n以整数形式表示并返回趣味子数组的数目。\n\n注意:子数组是数组中的一个连续非空的元素序列。\n\n示例 1:\n\n输入:nums = [3,2,4], modulo = 2, k = 1\n输出:3\n解释:在这个示例中,趣味子数组分别是:\n子数组 nums[0..0] ,也就是 [3] 。\n- 在范围 [0, 0] 内,只存在 1 个下标 i = 0 满足 nums[i] % modulo == k 。\n- 因此 cnt = 1 ,且 cnt % modulo == k 。\n子数组 nums[0..1] ,也就是 [3,2] 。\n- 在范围 [0, 1] 内,只存在 1 个下标 i = 0 满足 nums[i] % modulo == k 。\n- 因此 cnt = 1 ,且 cnt % modulo == k 。\n子数组 nums[0..2] ,也就是 [3,2,4] 。\n- 在范围 [0, 2] 内,只存在 1 个下标 i = 0 满足 nums[i] % modulo == k 。\n- 因此 cnt = 1 ,且 cnt % modulo == k 。\n可以证明不存在其他趣味子数组。因此,答案为 3 。\n\n示例 2:\n\n输入:nums = [3,1,9,6], modulo = 3, k = 0\n输出:2\n解释:在这个示例中,趣味子数组分别是:\n子数组 nums[0..3] ,也就是 [3,1,9,6] 。\n- 在范围 [0, 3] 内,只存在 3 个下标 i = 0, 2, 3 满足 nums[i] % modulo == k 。\n- 因此 cnt = 3 ,且 cnt % modulo == k 。\n子数组 nums[1..1] ,也就是 [1] 。\n- 在范围 [1, 1] 内,不存在下标满足 nums[i] % modulo == k 。\n- 因此 cnt = 0 ,且 cnt % modulo == k 。\n可以证明不存在其他趣味子数组,因此答案为 2 。\n\n提示:\n\n * 1 <= nums.length <= 105\n * 1 <= nums[i] <= 109\n * 1 <= modulo <= 109\n * 0 <= k < modulo\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def countInterestingSubarrays(self, nums: List[int], modulo: int, k: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [3,2,4], \"modulo\": 2, \"k\": 1 }\nassert my_solution.countInterestingSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [3,1,9,6], \"modulo\": 3, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [11,12,21,31], \"modulo\": 10, \"k\": 1 }\nassert my_solution.countInterestingSubarrays(**test_input) == 5\n\ntest_input = { \"nums\": [2,4], \"modulo\": 7, \"k\": 2 }\nassert my_solution.countInterestingSubarrays(**test_input) == 0\n\ntest_input = { \"nums\": [2,7], \"modulo\": 7, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [2,45], \"modulo\": 13, \"k\": 2 }\nassert my_solution.countInterestingSubarrays(**test_input) == 0\n\ntest_input = { \"nums\": [3,3], \"modulo\": 5, \"k\": 3 }\nassert my_solution.countInterestingSubarrays(**test_input) == 0\n\ntest_input = { \"nums\": [3,4], \"modulo\": 8, \"k\": 3 }\nassert my_solution.countInterestingSubarrays(**test_input) == 0\n\ntest_input = { \"nums\": [4,5], \"modulo\": 1, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [5,1], \"modulo\": 6, \"k\": 1 }\nassert my_solution.countInterestingSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [7,2], \"modulo\": 7, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [7,4], \"modulo\": 7, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [8,8], \"modulo\": 4, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 0\n\ntest_input = { \"nums\": [9,2], \"modulo\": 2, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [18,43], \"modulo\": 3, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [19,67], \"modulo\": 47, \"k\": 19 }\nassert my_solution.countInterestingSubarrays(**test_input) == 0\n\ntest_input = { \"nums\": [20,8], \"modulo\": 41, \"k\": 8 }\nassert my_solution.countInterestingSubarrays(**test_input) == 0\n\ntest_input = { \"nums\": [26,5], \"modulo\": 21, \"k\": 5 }\nassert my_solution.countInterestingSubarrays(**test_input) == 0\n\ntest_input = { \"nums\": [81,36], \"modulo\": 4, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [2,1,5], \"modulo\": 9, \"k\": 1 }\nassert my_solution.countInterestingSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [2,2,5], \"modulo\": 3, \"k\": 2 }\nassert my_solution.countInterestingSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [2,2,5], \"modulo\": 4, \"k\": 2 }\nassert my_solution.countInterestingSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [2,3,2], \"modulo\": 6, \"k\": 2 }\nassert my_solution.countInterestingSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [3,2,5], \"modulo\": 1, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [5,1,6], \"modulo\": 2, \"k\": 1 }\nassert my_solution.countInterestingSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [5,2,8], \"modulo\": 2, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [6,5,6], \"modulo\": 6, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [7,1,2], \"modulo\": 1, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [7,2,9], \"modulo\": 4, \"k\": 1 }\nassert my_solution.countInterestingSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [7,5,6], \"modulo\": 4, \"k\": 1 }\nassert my_solution.countInterestingSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [9,1,6], \"modulo\": 7, \"k\": 1 }\nassert my_solution.countInterestingSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [40,1,24], \"modulo\": 41, \"k\": 1 }\nassert my_solution.countInterestingSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [48,36,27], \"modulo\": 9, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [1,9,6,1], \"modulo\": 2, \"k\": 1 }\nassert my_solution.countInterestingSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [2,2,1,2], \"modulo\": 3, \"k\": 2 }\nassert my_solution.countInterestingSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [3,5,4,2], \"modulo\": 5, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [4,18,38,15], \"modulo\": 21, \"k\": 4 }\nassert my_solution.countInterestingSubarrays(**test_input) == 0\n\ntest_input = { \"nums\": [6,6,1,4], \"modulo\": 7, \"k\": 6 }\nassert my_solution.countInterestingSubarrays(**test_input) == 0\n\ntest_input = { \"nums\": [7,5,2,1], \"modulo\": 1, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 10\n\ntest_input = { \"nums\": [7,5,3,4], \"modulo\": 3, \"k\": 1 }\nassert my_solution.countInterestingSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [8,6,5,6], \"modulo\": 3, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [8,7,3,2], \"modulo\": 6, \"k\": 2 }\nassert my_solution.countInterestingSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [9,2,2,6], \"modulo\": 7, \"k\": 2 }\nassert my_solution.countInterestingSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [9,7,4,1], \"modulo\": 2, \"k\": 1 }\nassert my_solution.countInterestingSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [9,7,8,9], \"modulo\": 5, \"k\": 4 }\nassert my_solution.countInterestingSubarrays(**test_input) == 0\n\ntest_input = { \"nums\": [9,48,32,11], \"modulo\": 2, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [53,44,40,37], \"modulo\": 2, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [91,5,60,93], \"modulo\": 59, \"k\": 1 }\nassert my_solution.countInterestingSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [2,1,1,3,5], \"modulo\": 4, \"k\": 1 }\nassert my_solution.countInterestingSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [2,2,5,4,3], \"modulo\": 5, \"k\": 2 }\nassert my_solution.countInterestingSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [2,2,5,6,1], \"modulo\": 1, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 15\n\ntest_input = { \"nums\": [2,6,2,3,1], \"modulo\": 9, \"k\": 2 }\nassert my_solution.countInterestingSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [2,7,4,8,5], \"modulo\": 2, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 7\n\ntest_input = { \"nums\": [4,2,1,8,8], \"modulo\": 3, \"k\": 2 }\nassert my_solution.countInterestingSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [4,2,8,8,2], \"modulo\": 9, \"k\": 2 }\nassert my_solution.countInterestingSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [5,6,3,9,3], \"modulo\": 9, \"k\": 3 }\nassert my_solution.countInterestingSubarrays(**test_input) == 0\n\ntest_input = { \"nums\": [6,7,1,9,2], \"modulo\": 1, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 15\n\ntest_input = { \"nums\": [6,9,5,1,6], \"modulo\": 5, \"k\": 1 }\nassert my_solution.countInterestingSubarrays(**test_input) == 7\n\ntest_input = { \"nums\": [7,3,6,2,6], \"modulo\": 1, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 15\n\ntest_input = { \"nums\": [7,7,9,5,8], \"modulo\": 4, \"k\": 1 }\nassert my_solution.countInterestingSubarrays(**test_input) == 5\n\ntest_input = { \"nums\": [7,9,1,3,2], \"modulo\": 8, \"k\": 1 }\nassert my_solution.countInterestingSubarrays(**test_input) == 5\n\ntest_input = { \"nums\": [8,6,9,4,4], \"modulo\": 9, \"k\": 4 }\nassert my_solution.countInterestingSubarrays(**test_input) == 0\n\ntest_input = { \"nums\": [8,8,6,8,9], \"modulo\": 9, \"k\": 8 }\nassert my_solution.countInterestingSubarrays(**test_input) == 0\n\ntest_input = { \"nums\": [9,7,8,7,8], \"modulo\": 7, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [26,9,14,4,24], \"modulo\": 26, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 10\n\ntest_input = { \"nums\": [31,30,24,34,20], \"modulo\": 22, \"k\": 2 }\nassert my_solution.countInterestingSubarrays(**test_input) == 0\n\ntest_input = { \"nums\": [39,41,6,30,38], \"modulo\": 43, \"k\": 6 }\nassert my_solution.countInterestingSubarrays(**test_input) == 0\n\ntest_input = { \"nums\": [1,2,7,1,6,6], \"modulo\": 5, \"k\": 1 }\nassert my_solution.countInterestingSubarrays(**test_input) == 8\n\ntest_input = { \"nums\": [1,6,2,1,9,7], \"modulo\": 3, \"k\": 1 }\nassert my_solution.countInterestingSubarrays(**test_input) == 11\n\ntest_input = { \"nums\": [1,7,8,2,5,9], \"modulo\": 7, \"k\": 1 }\nassert my_solution.countInterestingSubarrays(**test_input) == 10\n\ntest_input = { \"nums\": [2,4,6,6,5,1], \"modulo\": 8, \"k\": 6 }\nassert my_solution.countInterestingSubarrays(**test_input) == 0\n\ntest_input = { \"nums\": [2,8,2,9,2,8], \"modulo\": 5, \"k\": 2 }\nassert my_solution.countInterestingSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [2,9,1,6,5,7], \"modulo\": 7, \"k\": 2 }\nassert my_solution.countInterestingSubarrays(**test_input) == 5\n\ntest_input = { \"nums\": [2,9,1,6,6,7], \"modulo\": 9, \"k\": 6 }\nassert my_solution.countInterestingSubarrays(**test_input) == 0\n\ntest_input = { \"nums\": [2,9,6,8,8,3], \"modulo\": 1, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 21\n\ntest_input = { \"nums\": [4,8,4,3,7,5], \"modulo\": 4, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [4,9,4,9,7,7], \"modulo\": 9, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 5\n\ntest_input = { \"nums\": [5,3,7,9,8,7], \"modulo\": 3, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 5\n\ntest_input = { \"nums\": [7,1,6,1,7,2], \"modulo\": 6, \"k\": 1 }\nassert my_solution.countInterestingSubarrays(**test_input) == 7\n\ntest_input = { \"nums\": [7,3,1,9,1,3], \"modulo\": 5, \"k\": 1 }\nassert my_solution.countInterestingSubarrays(**test_input) == 10\n\ntest_input = { \"nums\": [7,4,9,8,3,4], \"modulo\": 1, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 21\n\ntest_input = { \"nums\": [7,5,1,7,7,7], \"modulo\": 8, \"k\": 7 }\nassert my_solution.countInterestingSubarrays(**test_input) == 0\n\ntest_input = { \"nums\": [8,4,5,6,7,4], \"modulo\": 4, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [8,7,3,8,4,8], \"modulo\": 8, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [8,7,5,5,2,1], \"modulo\": 5, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [8,18,36,50,12,37], \"modulo\": 18, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 7\n\ntest_input = { \"nums\": [9,9,6,7,2,3], \"modulo\": 5, \"k\": 2 }\nassert my_solution.countInterestingSubarrays(**test_input) == 8\n\ntest_input = { \"nums\": [16,1,33,39,15,1], \"modulo\": 30, \"k\": 1 }\nassert my_solution.countInterestingSubarrays(**test_input) == 12\n\ntest_input = { \"nums\": [17,25,9,20,41,26], \"modulo\": 38, \"k\": 3 }\nassert my_solution.countInterestingSubarrays(**test_input) == 0\n\ntest_input = { \"nums\": [21,26,39,21,31,49], \"modulo\": 22, \"k\": 21 }\nassert my_solution.countInterestingSubarrays(**test_input) == 0\n\ntest_input = { \"nums\": [37,44,17,22,50,15], \"modulo\": 6, \"k\": 2 }\nassert my_solution.countInterestingSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [40,10,31,40,30,32], \"modulo\": 50, \"k\": 40 }\nassert my_solution.countInterestingSubarrays(**test_input) == 0\n\ntest_input = { \"nums\": [40,22,22,35,2,16], \"modulo\": 24, \"k\": 16 }\nassert my_solution.countInterestingSubarrays(**test_input) == 0\n\ntest_input = { \"nums\": [98,23,66,13,70,34], \"modulo\": 74, \"k\": 13 }\nassert my_solution.countInterestingSubarrays(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,4,8,3,2,7], \"modulo\": 9, \"k\": 1 }\nassert my_solution.countInterestingSubarrays(**test_input) == 7\n\ntest_input = { \"nums\": [1,8,6,3,2,8,8], \"modulo\": 2, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 13\n\ntest_input = { \"nums\": [1,9,2,1,5,4,8], \"modulo\": 4, \"k\": 1 }\nassert my_solution.countInterestingSubarrays(**test_input) == 8\n\ntest_input = { \"nums\": [4,6,8,3,4,3,4], \"modulo\": 7, \"k\": 4 }\nassert my_solution.countInterestingSubarrays(**test_input) == 0\n\ntest_input = { \"nums\": [5,4,5,8,9,1,9], \"modulo\": 4, \"k\": 1 }\nassert my_solution.countInterestingSubarrays(**test_input) == 11\n\ntest_input = { \"nums\": [5,4,6,1,3,2,7], \"modulo\": 9, \"k\": 1 }\nassert my_solution.countInterestingSubarrays(**test_input) == 16", "start_time": 1693708200} +{"task_id": "weekly-contest-361-minimum-edge-weight-equilibrium-queries-in-a-tree", "url": "https://leetcode.com/problems/minimum-edge-weight-equilibrium-queries-in-a-tree", "title": "minimum-edge-weight-equilibrium-queries-in-a-tree", "meta": {"questionId": "3079", "questionFrontendId": "2846", "title": "Minimum Edge Weight Equilibrium Queries in a Tree", "titleSlug": "minimum-edge-weight-equilibrium-queries-in-a-tree", "isPaidOnly": false, "difficulty": "Hard", "likes": 260, "dislikes": 4, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n现有一棵由 n 个节点组成的无向树,节点按从 0 到 n - 1 编号。给你一个整数 n 和一个长度为 n - 1 的二维整数数组 edges ,其中 edges[i] = [ui, vi, wi] 表示树中存在一条位于节点 ui 和节点 vi 之间、权重为 wi 的边。\n\n另给你一个长度为 m 的二维整数数组 queries ,其中 queries[i] = [ai, bi] 。对于每条查询,请你找出使从 ai 到 bi 路径上每条边的权重相等所需的 最小操作次数 。在一次操作中,你可以选择树上的任意一条边,并将其权重更改为任意值。\n\n注意:\n\n * 查询之间 相互独立 的,这意味着每条新的查询时,树都会回到 初始状态 。\n * 从 ai 到 bi的路径是一个由 不同 节点组成的序列,从节点 ai 开始,到节点 bi 结束,且序列中相邻的两个节点在树中共享一条边。\n\n返回一个长度为 m 的数组 answer ,其中 answer[i] 是第 i 条查询的答案。\n\n示例 1:\n\n[https://assets.leetcode.com/uploads/2023/08/11/graph-6-1.png]\n\n输入:n = 7, edges = [[0,1,1],[1,2,1],[2,3,1],[3,4,2],[4,5,2],[5,6,2]], queries = [[0,3],[3,6],[2,6],[0,6]]\n输出:[0,0,1,3]\n解释:第 1 条查询,从节点 0 到节点 3 的路径中的所有边的权重都是 1 。因此,答案为 0 。\n第 2 条查询,从节点 3 到节点 6 的路径中的所有边的权重都是 2 。因此,答案为 0 。\n第 3 条查询,将边 [2,3] 的权重变更为 2 。在这次操作之后,从节点 2 到节点 6 的路径中的所有边的权重都是 2 。因此,答案为 1 。\n第 4 条查询,将边 [0,1]、[1,2]、[2,3] 的权重变更为 2 。在这次操作之后,从节点 0 到节点 6 的路径中的所有边的权重都是 2 。因此,答案为 3 。\n对于每条查询 queries[i] ,可以证明 answer[i] 是使从 ai 到 bi 的路径中的所有边的权重相等的最小操作次数。\n\n示例 2:\n\n[https://assets.leetcode.com/uploads/2023/08/11/graph-9-1.png]\n\n输入:n = 8, edges = [[1,2,6],[1,3,4],[2,4,6],[2,5,3],[3,6,6],[3,0,8],[7,0,2]], queries = [[4,6],[0,4],[6,5],[7,4]]\n输出:[1,2,2,3]\n解释:第 1 条查询,将边 [1,3] 的权重变更为 6 。在这次操作之后,从节点 4 到节点 6 的路径中的所有边的权重都是 6 。因此,答案为 1 。\n第 2 条查询,将边 [0,3]、[3,1] 的权重变更为 6 。在这次操作之后,从节点 0 到节点 4 的路径中的所有边的权重都是 6 。因此,答案为 2 。\n第 3 条查询,将边 [1,3]、[5,2] 的权重变更为 6 。在这次操作之后,从节点 6 到节点 5 的路径中的所有边的权重都是 6 。因此,答案为 2 。\n第 4 条查询,将边 [0,7]、[0,3]、[1,3] 的权重变更为 6 。在这次操作之后,从节点 7 到节点 4 的路径中的所有边的权重都是 6 。因此,答案为 3 。\n对于每条查询 queries[i] ,可以证明 answer[i] 是使从 ai 到 bi 的路径中的所有边的权重相等的最小操作次数。\n\n\n提示:\n\n * 1 <= n <= 104\n * edges.length == n - 1\n * edges[i].length == 3\n * 0 <= ui, vi < n\n * 1 <= wi <= 26\n * 生成的输入满足 edges 表示一棵有效的树\n * 1 <= queries.length == m <= 2 * 104\n * queries[i].length == 2\n * 0 <= ai, bi < n\n\"\"\"\nclass Solution:\n def minOperationsQueries(self, n: int, edges: List[List[int]], queries: List[List[int]]) -> List[int]:\n ", "prompt_sft": "现有一棵由 n 个节点组成的无向树,节点按从 0 到 n - 1 编号。给你一个整数 n 和一个长度为 n - 1 的二维整数数组 edges ,其中 edges[i] = [ui, vi, wi] 表示树中存在一条位于节点 ui 和节点 vi 之间、权重为 wi 的边。\n\n另给你一个长度为 m 的二维整数数组 queries ,其中 queries[i] = [ai, bi] 。对于每条查询,请你找出使从 ai 到 bi 路径上每条边的权重相等所需的 最小操作次数 。在一次操作中,你可以选择树上的任意一条边,并将其权重更改为任意值。\n\n注意:\n\n * 查询之间 相互独立 的,这意味着每条新的查询时,树都会回到 初始状态 。\n * 从 ai 到 bi的路径是一个由 不同 节点组成的序列,从节点 ai 开始,到节点 bi 结束,且序列中相邻的两个节点在树中共享一条边。\n\n返回一个长度为 m 的数组 answer ,其中 answer[i] 是第 i 条查询的答案。\n\n示例 1:\n\n[https://assets.leetcode.com/uploads/2023/08/11/graph-6-1.png]\n\n输入:n = 7, edges = [[0,1,1],[1,2,1],[2,3,1],[3,4,2],[4,5,2],[5,6,2]], queries = [[0,3],[3,6],[2,6],[0,6]]\n输出:[0,0,1,3]\n解释:第 1 条查询,从节点 0 到节点 3 的路径中的所有边的权重都是 1 。因此,答案为 0 。\n第 2 条查询,从节点 3 到节点 6 的路径中的所有边的权重都是 2 。因此,答案为 0 。\n第 3 条查询,将边 [2,3] 的权重变更为 2 。在这次操作之后,从节点 2 到节点 6 的路径中的所有边的权重都是 2 。因此,答案为 1 。\n第 4 条查询,将边 [0,1]、[1,2]、[2,3] 的权重变更为 2 。在这次操作之后,从节点 0 到节点 6 的路径中的所有边的权重都是 2 。因此,答案为 3 。\n对于每条查询 queries[i] ,可以证明 answer[i] 是使从 ai 到 bi 的路径中的所有边的权重相等的最小操作次数。\n\n示例 2:\n\n[https://assets.leetcode.com/uploads/2023/08/11/graph-9-1.png]\n\n输入:n = 8, edges = [[1,2,6],[1,3,4],[2,4,6],[2,5,3],[3,6,6],[3,0,8],[7,0,2]], queries = [[4,6],[0,4],[6,5],[7,4]]\n输出:[1,2,2,3]\n解释:第 1 条查询,将边 [1,3] 的权重变更为 6 。在这次操作之后,从节点 4 到节点 6 的路径中的所有边的权重都是 6 。因此,答案为 1 。\n第 2 条查询,将边 [0,3]、[3,1] 的权重变更为 6 。在这次操作之后,从节点 0 到节点 4 的路径中的所有边的权重都是 6 。因此,答案为 2 。\n第 3 条查询,将边 [1,3]、[5,2] 的权重变更为 6 。在这次操作之后,从节点 6 到节点 5 的路径中的所有边的权重都是 6 。因此,答案为 2 。\n第 4 条查询,将边 [0,7]、[0,3]、[1,3] 的权重变更为 6 。在这次操作之后,从节点 7 到节点 4 的路径中的所有边的权重都是 6 。因此,答案为 3 。\n对于每条查询 queries[i] ,可以证明 answer[i] 是使从 ai 到 bi 的路径中的所有边的权重相等的最小操作次数。\n\n\n提示:\n\n * 1 <= n <= 104\n * edges.length == n - 1\n * edges[i].length == 3\n * 0 <= ui, vi < n\n * 1 <= wi <= 26\n * 生成的输入满足 edges 表示一棵有效的树\n * 1 <= queries.length == m <= 2 * 104\n * queries[i].length == 2\n * 0 <= ai, bi < n\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def minOperationsQueries(self, n: int, edges: List[List[int]], queries: List[List[int]]) -> List[int]:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"n\": 7, \"edges\": [[0,1,1],[1,2,1],[2,3,1],[3,4,2],[4,5,2],[5,6,2]], \"queries\": [[0,3],[3,6],[2,6],[0,6]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,0,1,3]\n\ntest_input = { \"n\": 8, \"edges\": [[1,2,6],[1,3,4],[2,4,6],[2,5,3],[3,6,6],[3,0,8],[7,0,2]], \"queries\": [[4,6],[0,4],[6,5],[7,4]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,2,2,3]\n\ntest_input = { \"n\": 1, \"edges\": [], \"queries\": [[0,0]] }\nassert my_solution.minOperationsQueries(**test_input) == [0]\n\ntest_input = { \"n\": 2, \"edges\": [[0,1,26]], \"queries\": [[0,1],[0,0],[1,1]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,0,0]\n\ntest_input = { \"n\": 3, \"edges\": [[2,1,1],[2,0,2]], \"queries\": [[0,1],[0,2],[1,2],[0,0],[1,1],[2,2]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,0,0,0,0,0]\n\ntest_input = { \"n\": 6, \"edges\": [[1,3,3],[4,1,3],[0,3,5],[5,4,2],[2,5,1]], \"queries\": [[2,1],[2,0],[3,0],[2,2],[2,5],[4,1],[5,2]] }\nassert my_solution.minOperationsQueries(**test_input) == [2,3,0,0,0,0,0]\n\ntest_input = { \"n\": 7, \"edges\": [[2,1,2],[4,2,4],[5,2,4],[3,4,5],[6,3,5],[0,6,5]], \"queries\": [[4,4],[6,2],[3,4],[6,1],[2,0],[4,2],[5,0],[3,2],[3,5]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,1,0,2,1,0,2,1,1]\n\ntest_input = { \"n\": 5, \"edges\": [[1,2,1],[4,1,5],[3,2,3],[0,1,2]], \"queries\": [[1,2],[0,4],[0,0],[4,3],[4,2],[0,2],[3,3],[3,2]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,1,0,2,1,1,0,0]\n\ntest_input = { \"n\": 10, \"edges\": [[9,7,1],[5,9,2],[0,9,4],[3,9,5],[1,9,5],[4,0,4],[2,0,2],[8,7,4],[6,3,2]], \"queries\": [[4,3],[8,1],[9,6],[7,0],[1,1],[5,0],[4,8],[3,6],[8,2],[9,7]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,2,1,1,0,1,1,0,2,0]\n\ntest_input = { \"n\": 10, \"edges\": [[7,1,2],[9,7,3],[8,7,1],[3,7,4],[4,8,2],[5,7,2],[6,4,5],[0,1,4],[2,1,5]], \"queries\": [[0,4],[9,6],[8,0],[2,6],[5,9],[3,2],[4,1],[9,4]] }\nassert my_solution.minOperationsQueries(**test_input) == [2,3,2,3,1,2,1,2]\n\ntest_input = { \"n\": 5, \"edges\": [[4,2,4],[3,4,3],[0,4,1],[1,3,1]], \"queries\": [[4,3],[3,1],[1,1],[4,2],[1,4],[2,3],[3,3],[4,1]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,0,0,0,1,1,0,1]\n\ntest_input = { \"n\": 6, \"edges\": [[4,0,4],[1,0,5],[3,4,4],[5,0,4],[2,4,4]], \"queries\": [[4,4],[1,2],[4,0],[0,4],[4,3],[1,4],[3,2],[3,5],[5,2]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,1,0,0,0,1,0,0,0]\n\ntest_input = { \"n\": 6, \"edges\": [[4,3,2],[5,3,2],[1,4,5],[0,4,2],[2,1,1]], \"queries\": [[0,4],[2,1],[5,4],[2,0],[4,2],[4,5],[3,3],[5,0],[3,5],[5,2]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,0,0,2,1,0,0,0,0,2]\n\ntest_input = { \"n\": 5, \"edges\": [[0,1,5],[2,0,1],[3,0,1],[4,2,1]], \"queries\": [[2,1],[4,3],[4,2],[1,4],[0,2],[2,2],[3,2],[1,3]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,0,0,1,0,0,0,1]\n\ntest_input = { \"n\": 9, \"edges\": [[6,2,1],[5,2,1],[4,2,2],[7,4,4],[1,7,4],[0,1,4],[3,2,2],[8,3,1]], \"queries\": [[4,4],[7,4],[2,4],[6,2],[1,1],[6,8],[5,7],[4,2],[2,6]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,0,0,0,0,1,2,0,0]\n\ntest_input = { \"n\": 8, \"edges\": [[6,1,2],[2,1,5],[3,6,1],[7,1,3],[5,7,4],[4,7,5],[0,5,5]], \"queries\": [[4,0],[7,1],[3,4],[4,6],[5,7],[4,5],[3,3],[0,2],[7,2],[1,0]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,0,3,2,0,1,0,2,1,2]\n\ntest_input = { \"n\": 10, \"edges\": [[5,3,5],[6,3,1],[1,6,4],[2,6,3],[9,1,5],[4,3,5],[7,3,4],[0,1,1],[8,6,4]], \"queries\": [[6,5],[6,8],[0,3],[5,1],[5,7],[2,3],[7,9],[9,8],[5,9],[3,5]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,0,1,2,1,1,2,1,2,0]\n\ntest_input = { \"n\": 5, \"edges\": [[0,3,2],[4,3,2],[2,3,3],[1,4,5]], \"queries\": [[2,1],[0,0],[4,3],[1,1],[2,0],[3,0],[2,3],[1,0]] }\nassert my_solution.minOperationsQueries(**test_input) == [2,0,0,0,1,0,0,1]\n\ntest_input = { \"n\": 7, \"edges\": [[1,2,4],[3,2,4],[6,2,4],[0,6,5],[4,6,1],[5,1,5]], \"queries\": [[4,4],[5,5],[0,4],[0,0],[5,4],[5,1],[2,3],[2,2],[3,2],[4,1]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,0,1,0,2,0,0,0,0,1]\n\ntest_input = { \"n\": 10, \"edges\": [[7,0,2],[4,0,2],[6,7,3],[1,6,4],[9,1,3],[8,1,4],[3,6,3],[2,7,5],[5,7,5]], \"queries\": [[6,2],[0,4],[5,1],[2,3],[4,7],[8,9],[4,8],[9,1],[6,3],[1,9]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,0,2,1,0,1,3,0,0,0]\n\ntest_input = { \"n\": 9, \"edges\": [[1,5,4],[4,5,1],[0,4,2],[8,0,2],[6,1,5],[3,8,5],[2,3,2],[7,5,2]], \"queries\": [[0,1],[0,4],[3,1],[1,1],[5,4],[7,0],[5,1],[8,0],[0,3],[4,7]] }\nassert my_solution.minOperationsQueries(**test_input) == [2,0,3,0,0,1,0,0,1,1]\n\ntest_input = { \"n\": 10, \"edges\": [[4,8,4],[5,4,3],[6,5,3],[7,4,3],[2,8,5],[9,4,4],[1,6,1],[3,9,5],[0,8,2]], \"queries\": [[8,8],[9,0],[6,2],[2,1],[7,7],[8,7],[9,6],[5,0],[7,5]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,1,2,3,0,1,1,2,0]\n\ntest_input = { \"n\": 10, \"edges\": [[4,3,1],[9,3,1],[2,3,5],[1,4,2],[5,4,2],[0,2,5],[7,1,3],[6,2,2],[8,0,4]], \"queries\": [[0,7],[9,3],[5,8],[9,6],[5,7],[1,4],[2,9],[0,8],[3,5]] }\nassert my_solution.minOperationsQueries(**test_input) == [3,0,3,2,1,0,1,0,1]\n\ntest_input = { \"n\": 10, \"edges\": [[4,0,1],[7,4,1],[3,0,3],[1,7,4],[6,7,1],[9,7,5],[5,4,5],[2,9,1],[8,9,2]], \"queries\": [[6,2],[8,1],[1,1],[6,4],[2,9],[5,0],[2,5],[9,7],[1,9],[2,8]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,2,0,0,0,1,2,0,1,1]\n\ntest_input = { \"n\": 7, \"edges\": [[6,5,4],[0,5,5],[4,0,1],[1,6,4],[3,1,5],[2,3,1]], \"queries\": [[4,1],[0,2],[3,3],[2,6],[5,6],[0,5],[5,3],[1,3],[5,2]] }\nassert my_solution.minOperationsQueries(**test_input) == [2,3,0,2,0,0,1,0,2]\n\ntest_input = { \"n\": 7, \"edges\": [[2,3,2],[4,2,2],[0,2,4],[5,3,5],[6,3,2],[1,3,4]], \"queries\": [[6,2],[4,6],[2,0],[3,0],[0,2],[0,5],[5,3],[3,5]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,0,0,1,0,2,0,0]\n\ntest_input = { \"n\": 9, \"edges\": [[7,6,2],[3,7,5],[4,3,4],[2,6,5],[8,4,5],[5,2,3],[1,2,4],[0,6,2]], \"queries\": [[4,4],[3,8],[0,4],[8,1],[3,1],[7,0],[4,5],[3,6],[4,7]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,1,2,3,2,0,3,1,1]\n\ntest_input = { \"n\": 6, \"edges\": [[4,1,3],[2,4,4],[5,2,5],[3,1,5],[0,4,2]], \"queries\": [[3,4],[4,3],[0,3],[4,2],[3,0],[3,3],[5,3],[5,2]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,1,2,0,2,0,2,0]\n\ntest_input = { \"n\": 8, \"edges\": [[0,3,3],[4,0,5],[5,4,2],[6,3,1],[1,3,3],[2,3,2],[7,3,4]], \"queries\": [[6,2],[4,0],[3,4],[2,7],[4,3],[7,0],[7,3],[7,6],[6,3],[4,1]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,0,1,1,1,1,0,1,0,1]\n\ntest_input = { \"n\": 5, \"edges\": [[0,3,2],[2,0,2],[4,3,3],[1,2,3]], \"queries\": [[0,1],[2,1],[4,3],[1,4],[2,3],[0,2],[3,3],[3,2],[1,3]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,0,0,2,0,0,0,0,1]\n\ntest_input = { \"n\": 10, \"edges\": [[8,0,5],[6,0,4],[7,6,3],[3,7,5],[5,3,5],[2,8,5],[1,8,4],[4,6,3],[9,4,4]], \"queries\": [[9,0],[3,4],[6,5],[0,3],[2,3],[1,7],[7,6],[5,0],[2,5]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,1,1,2,2,2,0,2,2]\n\ntest_input = { \"n\": 9, \"edges\": [[2,3,1],[4,2,1],[1,3,3],[0,4,3],[5,2,3],[7,2,1],[8,5,3],[6,4,2]], \"queries\": [[7,7],[4,3],[3,1],[5,4],[1,8],[1,4],[7,3],[7,6],[8,2],[3,5]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,0,0,1,1,1,0,1,0,1]\n\ntest_input = { \"n\": 5, \"edges\": [[4,1,4],[3,1,5],[0,4,3],[2,1,4]], \"queries\": [[0,1],[2,4],[1,2],[0,4],[3,4],[0,0],[1,1]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,0,0,0,1,0,0]\n\ntest_input = { \"n\": 4, \"edges\": [[1,2,4],[3,2,5],[0,1,5]], \"queries\": [[1,2],[3,1],[1,1],[2,0],[3,0],[3,3]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,1,0,1,1,0]\n\ntest_input = { \"n\": 4, \"edges\": [[1,2,3],[0,2,1],[3,2,5]], \"queries\": [[3,1],[1,1],[3,0],[2,3],[3,3],[2,2],[1,0],[3,2]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,0,1,0,0,0,1,0]\n\ntest_input = { \"n\": 8, \"edges\": [[4,6,3],[7,4,1],[3,7,4],[1,4,1],[0,6,4],[5,7,3],[2,1,3]], \"queries\": [[2,4],[6,2],[7,1],[5,1],[4,2],[1,7],[1,3],[3,5]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,1,0,1,1,0,1,1]\n\ntest_input = { \"n\": 9, \"edges\": [[1,7,4],[5,1,2],[6,1,4],[2,5,2],[3,2,5],[8,3,2],[0,3,2],[4,5,2]], \"queries\": [[7,4],[4,0],[3,4],[6,1],[0,3],[3,3],[6,0],[5,3],[3,2],[6,3]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,1,1,0,0,0,2,1,0,2]\n\ntest_input = { \"n\": 5, \"edges\": [[0,3,4],[2,0,5],[4,2,1],[1,4,4]], \"queries\": [[0,1],[0,4],[4,1],[2,0],[4,2],[0,2],[3,3],[1,0],[1,3]] }\nassert my_solution.minOperationsQueries(**test_input) == [2,1,0,0,0,0,0,2,2]\n\ntest_input = { \"n\": 8, \"edges\": [[5,4,1],[0,5,3],[2,0,5],[3,5,4],[7,2,4],[1,7,5],[6,5,2]], \"queries\": [[2,4],[4,0],[6,5],[5,4],[5,1],[0,6],[6,0],[3,5]] }\nassert my_solution.minOperationsQueries(**test_input) == [2,1,0,0,2,1,1,0]\n\ntest_input = { \"n\": 8, \"edges\": [[4,2,3],[3,2,3],[6,3,3],[7,4,5],[5,3,4],[0,6,5],[1,5,3]], \"queries\": [[0,1],[2,4],[3,4],[4,2],[7,3],[4,5],[3,6],[6,6],[6,3]] }\nassert my_solution.minOperationsQueries(**test_input) == [2,0,0,0,1,1,0,0,0]\n\ntest_input = { \"n\": 10, \"edges\": [[2,4,2],[1,2,4],[5,2,1],[0,1,1],[9,4,4],[7,9,1],[3,9,5],[8,5,1],[6,2,5]], \"queries\": [[1,2],[4,0],[8,4],[0,3],[6,7],[3,3],[1,6],[3,2],[9,1],[7,8]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,2,1,3,3,0,1,2,1,2]\n\ntest_input = { \"n\": 5, \"edges\": [[0,1,5],[4,1,5],[3,4,4],[2,0,2]], \"queries\": [[2,4],[1,2],[0,4],[3,4],[0,0],[4,3],[1,1],[1,4],[3,0],[0,2]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,1,0,0,0,0,0,0,1,0]\n\ntest_input = { \"n\": 8, \"edges\": [[0,2,5],[7,2,2],[1,7,4],[5,0,1],[4,2,2],[3,2,3],[6,4,3]], \"queries\": [[7,4],[0,4],[6,5],[0,0],[6,1],[2,0],[5,7],[7,2],[2,2],[1,0]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,1,3,0,2,0,2,0,0,2]\n\ntest_input = { \"n\": 8, \"edges\": [[7,5,4],[0,5,3],[6,7,5],[3,0,3],[2,6,3],[4,2,4],[1,4,3]], \"queries\": [[5,5],[7,1],[3,4],[2,7],[4,3],[6,1],[1,4],[3,0],[6,0]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,2,3,1,3,1,0,0,2]\n\ntest_input = { \"n\": 5, \"edges\": [[4,0,4],[2,4,4],[3,2,1],[1,4,4]], \"queries\": [[0,1],[0,4],[3,4],[4,3],[1,1],[1,4],[0,2],[3,3],[1,3]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,0,1,1,0,0,0,0,1]\n\ntest_input = { \"n\": 4, \"edges\": [[0,2,1],[3,2,2],[1,2,1]], \"queries\": [[0,3],[2,3],[0,2],[3,3],[2,2],[1,0]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,0,0,0,0,0]\n\ntest_input = { \"n\": 5, \"edges\": [[4,2,5],[1,4,5],[0,4,4],[3,4,4]], \"queries\": [[0,1],[0,4],[3,1],[0,3],[4,2],[3,0],[1,4],[1,0]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,0,1,0,0,0,0,1]\n\ntest_input = { \"n\": 4, \"edges\": [[1,3,4],[2,3,5],[0,3,2]], \"queries\": [[1,2],[0,3],[2,0],[3,0],[0,2],[2,2],[3,2],[1,3]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,0,1,0,1,0,0,0]\n\ntest_input = { \"n\": 9, \"edges\": [[5,8,2],[3,8,3],[6,5,3],[7,5,3],[1,6,1],[0,8,1],[4,5,2],[2,1,4]], \"queries\": [[8,8],[3,4],[6,5],[2,7],[8,1],[6,7],[2,5],[3,5]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,1,0,2,2,0,2,1]\n\ntest_input = { \"n\": 10, \"edges\": [[4,5,5],[1,4,3],[8,4,5],[2,1,3],[0,1,2],[6,0,1],[7,0,1],[3,7,4],[9,2,1]], \"queries\": [[3,8],[1,5],[0,3],[4,6],[4,2],[2,3],[6,3],[2,5],[9,1],[1,9]] }\nassert my_solution.minOperationsQueries(**test_input) == [4,1,1,2,0,3,1,1,1,1]\n\ntest_input = { \"n\": 8, \"edges\": [[0,5,5],[2,0,2],[3,5,2],[1,5,1],[7,1,5],[4,0,4],[6,2,4]], \"queries\": [[7,4],[0,4],[7,1],[6,4],[5,0],[5,6],[2,2],[2,5]] }\nassert my_solution.minOperationsQueries(**test_input) == [2,0,0,1,0,2,0,1]\n\ntest_input = { \"n\": 9, \"edges\": [[0,3,1],[4,0,5],[8,4,5],[5,8,4],[1,4,3],[6,4,4],[7,0,1],[2,5,5]], \"queries\": [[1,2],[8,4],[2,1],[6,5],[3,4],[4,0],[2,0],[6,0],[7,8],[2,8]] }\nassert my_solution.minOperationsQueries(**test_input) == [2,0,2,1,1,0,1,1,1,1]\n\ntest_input = { \"n\": 5, \"edges\": [[1,2,5],[4,2,5],[0,4,2],[3,1,1]], \"queries\": [[0,4],[0,0],[4,3],[1,4],[3,0],[2,3],[2,2],[1,0],[1,3]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,0,1,0,2,1,0,1,0]\n\ntest_input = { \"n\": 7, \"edges\": [[4,1,3],[5,4,5],[0,1,2],[2,4,3],[3,4,2],[6,1,5]], \"queries\": [[2,4],[4,0],[1,2],[3,4],[1,5],[6,1],[2,0],[3,5]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,1,0,0,1,0,1,1]\n\ntest_input = { \"n\": 9, \"edges\": [[8,5,5],[0,5,3],[4,5,3],[6,5,2],[1,0,2],[3,6,4],[2,4,2],[7,3,3]], \"queries\": [[0,4],[7,7],[1,5],[8,7],[1,1],[5,1],[2,3],[8,3],[3,6],[3,2]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,0,1,3,0,1,2,2,0,2]\n\ntest_input = { \"n\": 9, \"edges\": [[6,3,1],[1,6,1],[8,3,2],[7,1,1],[0,8,2],[5,3,2],[4,3,5],[2,6,4]], \"queries\": [[8,1],[8,7],[6,1],[7,3],[1,0],[1,6],[0,8],[1,3],[5,2]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,1,0,0,2,0,0,0,2]\n\ntest_input = { \"n\": 9, \"edges\": [[2,0,1],[5,0,1],[3,2,4],[4,5,2],[1,4,3],[7,3,5],[6,1,1],[8,5,5]], \"queries\": [[4,0],[7,1],[6,5],[4,1],[8,7],[5,7],[2,3],[1,7],[1,3],[5,2]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,4,2,0,3,2,0,4,3,0]\n\ntest_input = { \"n\": 5, \"edges\": [[3,4,2],[2,3,2],[0,4,3],[1,0,1]], \"queries\": [[4,4],[0,1],[4,0],[1,2],[0,0],[1,4],[2,3],[0,2]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,0,0,2,0,1,0,1]\n\ntest_input = { \"n\": 4, \"edges\": [[3,2,1],[0,3,2],[1,3,4]], \"queries\": [[0,1],[1,2],[3,1],[1,1],[2,0],[0,2],[2,2],[1,0]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,1,0,0,1,1,0,1]\n\ntest_input = { \"n\": 5, \"edges\": [[0,2,2],[4,0,5],[3,2,2],[1,3,3]], \"queries\": [[2,4],[1,2],[0,0],[0,3],[4,2],[3,0],[1,0],[3,2],[1,3]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,1,0,0,1,0,1,0,0]\n\ntest_input = { \"n\": 7, \"edges\": [[5,2,2],[3,5,2],[1,5,2],[0,3,4],[6,2,2],[4,0,4]], \"queries\": [[1,5],[2,0],[6,4],[0,5],[2,2],[5,3],[1,3],[3,5]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,1,2,1,0,0,0,0]\n\ntest_input = { \"n\": 4, \"edges\": [[0,3,3],[1,3,1],[2,1,2]], \"queries\": [[0,1],[1,2],[2,1],[0,0],[3,1],[1,1],[0,2],[2,2],[1,0],[3,2]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,0,0,0,0,0,2,0,1,1]\n\ntest_input = { \"n\": 6, \"edges\": [[0,5,3],[2,5,4],[4,5,1],[3,4,4],[1,3,5]], \"queries\": [[4,4],[2,1],[4,1],[3,1],[0,3],[2,2],[1,0],[1,3]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,2,1,0,2,0,3,0]\n\ntest_input = { \"n\": 8, \"edges\": [[0,7,1],[4,7,4],[3,7,5],[1,3,2],[5,4,3],[2,3,3],[6,0,4]], \"queries\": [[4,4],[7,4],[1,2],[7,7],[0,0],[6,1],[0,6],[2,6],[4,1],[4,7]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,0,1,0,0,3,0,3,2,0]\n\ntest_input = { \"n\": 5, \"edges\": [[0,3,3],[2,0,1],[1,2,5],[4,0,3]], \"queries\": [[0,4],[2,1],[3,4],[0,0],[4,3],[3,1],[1,1],[0,2],[4,1]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,0,0,0,0,2,0,0,2]\n\ntest_input = { \"n\": 7, \"edges\": [[4,1,3],[2,1,2],[0,4,3],[6,0,3],[3,4,2],[5,0,5]], \"queries\": [[0,1],[6,2],[5,4],[1,4],[3,0],[0,2],[5,6],[3,6],[1,0],[6,3]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,1,1,0,1,1,1,1,0,1]\n\ntest_input = { \"n\": 9, \"edges\": [[8,0,4],[4,8,5],[1,8,1],[7,0,2],[2,7,4],[3,0,1],[6,0,1],[5,2,1]], \"queries\": [[4,4],[0,4],[3,4],[2,7],[0,0],[8,7],[8,6],[0,5],[6,6],[8,5]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,1,2,0,0,1,1,2,0,2]\n\ntest_input = { \"n\": 9, \"edges\": [[0,4,2],[5,4,3],[8,5,1],[2,5,5],[7,2,5],[1,0,5],[3,4,1],[6,2,5]], \"queries\": [[6,5],[8,1],[0,0],[1,4],[7,3],[8,6],[4,8],[1,0],[3,5]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,3,0,1,2,1,1,0,1]\n\ntest_input = { \"n\": 7, \"edges\": [[0,5,2],[2,5,5],[4,2,3],[3,5,2],[6,3,5],[1,3,4]], \"queries\": [[0,1],[3,4],[4,1],[4,2],[3,0],[4,5],[0,5],[3,2],[1,3]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,2,3,0,0,1,0,1,0]\n\ntest_input = { \"n\": 9, \"edges\": [[0,6,3],[1,0,1],[4,1,5],[3,1,4],[2,3,4],[5,6,2],[8,0,2],[7,5,4]], \"queries\": [[7,4],[3,8],[8,4],[2,1],[6,8],[1,4],[7,6],[4,1],[7,8],[5,2]] }\nassert my_solution.minOperationsQueries(**test_input) == [4,2,2,0,1,0,1,0,2,3]\n\ntest_input = { \"n\": 6, \"edges\": [[0,4,5],[1,0,3],[5,0,5],[2,1,3],[3,4,2]], \"queries\": [[1,2],[5,5],[4,3],[2,0],[5,1],[0,5],[5,3],[5,2]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,0,0,0,1,0,1,1]\n\ntest_input = { \"n\": 10, \"edges\": [[6,7,1],[5,7,1],[0,5,1],[8,7,2],[3,6,2],[4,8,2],[1,3,1],[2,6,4],[9,6,5]], \"queries\": [[0,7],[7,7],[4,3],[4,9],[9,8],[0,5],[9,1],[4,7],[9,4]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,0,1,2,2,0,2,0,2]\n\ntest_input = { \"n\": 4, \"edges\": [[3,0,5],[1,0,5],[2,0,5]], \"queries\": [[0,1],[1,2],[2,1],[3,1],[1,1],[3,0],[2,3]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,0,0,0,0,0,0]\n\ntest_input = { \"n\": 9, \"edges\": [[6,8,4],[7,6,2],[1,7,1],[4,6,4],[0,7,2],[5,4,5],[3,5,2],[2,0,5]], \"queries\": [[4,3],[6,4],[1,4],[2,2],[7,5],[1,3],[7,8],[0,8]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,0,2,0,2,3,1,1]\n\ntest_input = { \"n\": 8, \"edges\": [[5,3,1],[0,5,3],[1,5,2],[7,3,5],[4,0,2],[6,4,4],[2,0,1]], \"queries\": [[0,7],[2,7],[5,4],[4,6],[5,1],[0,2],[5,0],[5,6],[2,2],[1,6]] }\nassert my_solution.minOperationsQueries(**test_input) == [2,2,1,0,0,0,0,2,0,2]\n\ntest_input = { \"n\": 7, \"edges\": [[2,5,2],[6,2,1],[3,6,2],[1,5,1],[4,3,3],[0,2,2]], \"queries\": [[0,4],[2,1],[6,1],[5,4],[0,3],[6,4],[0,5],[3,2],[6,3]] }\nassert my_solution.minOperationsQueries(**test_input) == [2,1,1,2,1,1,0,1,0]\n\ntest_input = { \"n\": 7, \"edges\": [[2,3,5],[6,2,1],[0,3,4],[1,0,4],[5,1,1],[4,2,1]], \"queries\": [[4,4],[0,4],[3,4],[0,0],[1,1],[0,3],[0,6],[0,2],[3,3],[6,0]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,2,1,0,0,0,2,1,0,2]\n\ntest_input = { \"n\": 6, \"edges\": [[0,2,2],[4,2,1],[5,4,5],[1,0,4],[3,4,5]], \"queries\": [[0,4],[3,4],[3,1],[1,1],[5,4],[2,0],[2,2],[5,2]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,0,3,0,0,0,0,1]\n\ntest_input = { \"n\": 9, \"edges\": [[3,7,2],[1,7,3],[4,3,5],[6,4,3],[8,1,2],[5,1,2],[2,6,1],[0,5,2]], \"queries\": [[3,8],[2,4],[8,1],[6,8],[7,3],[3,0],[1,0],[8,2],[7,5],[8,5]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,1,0,3,0,1,0,4,1,0]\n\ntest_input = { \"n\": 9, \"edges\": [[1,4,3],[3,4,3],[8,4,4],[7,1,5],[2,7,3],[5,8,4],[6,7,4],[0,2,4]], \"queries\": [[4,4],[0,7],[1,8],[8,3],[3,3],[5,0],[7,6],[6,6],[2,5],[4,1]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,1,1,1,0,3,0,0,3,0]\n\ntest_input = { \"n\": 9, \"edges\": [[6,5,3],[3,5,3],[2,5,5],[1,5,2],[8,2,3],[7,6,3],[4,7,2],[0,7,4]], \"queries\": [[2,4],[8,1],[8,7],[6,1],[4,6],[0,3],[3,2],[3,0],[0,8],[3,5]] }\nassert my_solution.minOperationsQueries(**test_input) == [2,2,1,1,1,1,1,1,2,0]\n\ntest_input = { \"n\": 6, \"edges\": [[3,5,4],[4,3,5],[0,5,2],[1,4,3],[2,5,4]], \"queries\": [[1,2],[1,5],[5,4],[5,1],[1,4],[0,2],[0,5],[2,5],[1,3],[5,2]] }\nassert my_solution.minOperationsQueries(**test_input) == [2,2,1,2,0,1,0,0,1,0]\n\ntest_input = { \"n\": 5, \"edges\": [[3,0,1],[2,3,1],[4,2,1],[1,0,3]], \"queries\": [[4,0],[3,4],[4,3],[3,1],[2,0],[3,3],[3,2],[1,3]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,0,0,1,0,0,0,1]\n\ntest_input = { \"n\": 6, \"edges\": [[4,2,1],[3,4,4],[1,2,5],[5,2,3],[0,3,5]], \"queries\": [[5,5],[0,4],[3,1],[5,4],[0,3],[1,4],[0,5],[3,2],[2,5]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,1,2,1,0,1,3,1,0]\n\ntest_input = { \"n\": 6, \"edges\": [[3,5,2],[1,3,5],[2,3,4],[0,1,5],[4,1,3]], \"queries\": [[0,1],[1,1],[5,3],[5,1],[4,5],[0,2],[3,3],[0,5],[1,0],[3,5]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,0,0,1,2,1,0,1,0,0]\n\ntest_input = { \"n\": 7, \"edges\": [[2,3,3],[1,2,1],[0,3,5],[5,1,2],[6,5,4],[4,6,2]], \"queries\": [[6,2],[4,0],[0,4],[2,3],[0,2],[3,3],[5,0],[0,5],[1,3],[3,5]] }\nassert my_solution.minOperationsQueries(**test_input) == [2,4,4,0,1,0,3,3,1,2]\n\ntest_input = { \"n\": 7, \"edges\": [[2,5,1],[1,2,2],[3,2,4],[0,5,1],[4,5,1],[6,3,2]], \"queries\": [[2,4],[3,1],[0,3],[5,1],[4,2],[5,0],[2,2],[1,3]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,1,1,1,0,0,0,1]\n\ntest_input = { \"n\": 8, \"edges\": [[5,6,2],[7,6,1],[3,5,2],[1,6,3],[0,1,1],[4,6,5],[2,7,3]], \"queries\": [[6,2],[7,1],[7,7],[4,2],[3,0],[2,3],[7,6],[5,3],[7,5]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,1,0,2,2,2,0,0,1]\n\ntest_input = { \"n\": 5, \"edges\": [[3,1,5],[0,1,3],[2,3,5],[4,3,3]], \"queries\": [[0,1],[4,0],[0,4],[4,3],[0,3],[1,4],[0,2],[3,3],[2,2],[1,3]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,1,1,0,1,1,1,0,0,0]\n\ntest_input = { \"n\": 6, \"edges\": [[2,0,1],[1,0,1],[3,2,5],[5,2,4],[4,2,4]], \"queries\": [[2,4],[3,4],[0,0],[4,1],[0,3],[5,1],[0,2],[4,5],[0,5],[1,3]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,1,0,1,1,1,0,0,1,1]\n\ntest_input = { \"n\": 10, \"edges\": [[2,9,2],[5,2,3],[7,5,1],[0,5,1],[8,2,3],[4,9,3],[3,5,2],[1,0,4],[6,4,3]], \"queries\": [[9,3],[0,0],[9,9],[4,1],[9,6],[3,7],[4,2],[9,7],[5,2]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,0,0,3,0,1,1,2,0]\n\ntest_input = { \"n\": 5, \"edges\": [[4,0,4],[2,0,1],[3,0,4],[1,3,5]], \"queries\": [[3,4],[0,0],[3,1],[2,0],[2,3],[3,3],[1,3]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,0,0,0,1,0,0]\n\ntest_input = { \"n\": 8, \"edges\": [[5,3,2],[2,3,2],[0,5,4],[1,5,1],[4,0,3],[6,1,1],[7,3,3]], \"queries\": [[0,1],[5,5],[7,7],[2,1],[3,1],[4,6],[2,0],[7,6],[5,3],[7,5]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,0,0,1,1,2,1,2,0,1]\n\ntest_input = { \"n\": 5, \"edges\": [[0,3,1],[2,0,2],[1,3,2],[4,1,4]], \"queries\": [[0,4],[3,4],[0,0],[1,1],[2,0],[3,0],[2,3],[4,1]] }\nassert my_solution.minOperationsQueries(**test_input) == [2,1,0,0,0,0,1,0]\n\ntest_input = { \"n\": 5, \"edges\": [[3,4,3],[0,3,1],[1,4,3],[2,0,1]], \"queries\": [[0,1],[4,4],[4,0],[2,1],[4,3],[3,1],[0,2],[3,3],[1,3]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,0,1,2,0,0,0,0,0]\n\ntest_input = { \"n\": 7, \"edges\": [[1,0,2],[4,1,5],[5,0,2],[6,5,3],[2,5,5],[3,4,3]], \"queries\": [[4,4],[2,4],[6,4],[1,4],[5,0],[5,6],[2,2],[1,3]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,2,2,0,0,0,0,1]\n\ntest_input = { \"n\": 9, \"edges\": [[6,8,1],[1,6,2],[0,8,2],[4,8,5],[3,4,4],[5,8,4],[2,5,2],[7,1,2]], \"queries\": [[0,0],[8,1],[8,3],[1,7],[2,6],[3,3],[0,5],[2,2],[7,5],[2,5]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,1,1,0,2,0,1,0,2,0]\n\ntest_input = { \"n\": 9, \"edges\": [[0,1,5],[8,1,4],[2,8,1],[3,2,1],[6,3,2],[4,2,3],[7,8,2],[5,2,3]], \"queries\": [[8,8],[6,2],[3,7],[1,8],[2,0],[1,4],[6,3],[7,8],[5,2]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,1,1,0,2,2,0,0,0]\n\ntest_input = { \"n\": 8, \"edges\": [[4,5,2],[7,4,2],[0,5,2],[6,0,1],[2,6,1],[3,2,1],[1,7,5]], \"queries\": [[4,4],[3,7],[4,6],[5,7],[3,0],[0,2],[1,7],[3,6],[4,7]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,3,1,0,0,0,0,0,0]\n\ntest_input = { \"n\": 9, \"edges\": [[5,8,1],[4,8,2],[1,5,1],[7,8,5],[0,8,2],[6,1,5],[2,8,3],[3,1,2]], \"queries\": [[6,2],[2,7],[5,4],[1,8],[5,7],[3,0],[6,6],[0,8]] }\nassert my_solution.minOperationsQueries(**test_input) == [2,1,1,0,1,2,0,0]", "start_time": 1693708200} +{"task_id": "biweekly-contest-112-check-if-strings-can-be-made-equal-with-operations-i", "url": "https://leetcode.com/problems/check-if-strings-can-be-made-equal-with-operations-i", "title": "check-if-strings-can-be-made-equal-with-operations-i", "meta": {"questionId": "2999", "questionFrontendId": "2839", "title": "Check if Strings Can be Made Equal With Operations I", "titleSlug": "check-if-strings-can-be-made-equal-with-operations-i", "isPaidOnly": false, "difficulty": "Easy", "likes": 164, "dislikes": 20, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你两个字符串 s1 和 s2 ,两个字符串的长度都为 4 ,且只包含 小写 英文字母。\n\n你可以对两个字符串中的 任意一个 执行以下操作 任意 次:\n\n * 选择两个下标 i 和 j 且满足 j - i = 2 ,然后 交换 这个字符串中两个下标对应的字符。\n\n如果你可以让字符串 s1 和 s2 相等,那么返回 true ,否则返回 false 。\n\n示例 1:\n\n输入:s1 = \"abcd\", s2 = \"cdab\"\n输出:true\n解释: 我们可以对 s1 执行以下操作:\n- 选择下标 i = 0 ,j = 2 ,得到字符串 s1 = \"cbad\" 。\n- 选择下标 i = 1 ,j = 3 ,得到字符串 s1 = \"cdab\" = s2 。\n\n示例 2:\n\n输入:s1 = \"abcd\", s2 = \"dacb\"\n输出:false\n解释:无法让两个字符串相等。\n\n\n提示:\n\n * s1.length == s2.length == 4\n * s1 和 s2 只包含小写英文字母。\n\"\"\"\nclass Solution:\n def canBeEqual(self, s1: str, s2: str) -> bool:\n ", "prompt_sft": "给你两个字符串 s1 和 s2 ,两个字符串的长度都为 4 ,且只包含 小写 英文字母。\n\n你可以对两个字符串中的 任意一个 执行以下操作 任意 次:\n\n * 选择两个下标 i 和 j 且满足 j - i = 2 ,然后 交换 这个字符串中两个下标对应的字符。\n\n如果你可以让字符串 s1 和 s2 相等,那么返回 true ,否则返回 false 。\n\n示例 1:\n\n输入:s1 = \"abcd\", s2 = \"cdab\"\n输出:true\n解释: 我们可以对 s1 执行以下操作:\n- 选择下标 i = 0 ,j = 2 ,得到字符串 s1 = \"cbad\" 。\n- 选择下标 i = 1 ,j = 3 ,得到字符串 s1 = \"cdab\" = s2 。\n\n示例 2:\n\n输入:s1 = \"abcd\", s2 = \"dacb\"\n输出:false\n解释:无法让两个字符串相等。\n\n\n提示:\n\n * s1.length == s2.length == 4\n * s1 和 s2 只包含小写英文字母。\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def canBeEqual(self, s1: str, s2: str) -> bool:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"s1\": \"abcd\", \"s2\": \"cdab\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"abcd\", \"s2\": \"dacb\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"gudo\", \"s2\": \"ogdu\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"bnxw\", \"s2\": \"bwxn\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"zzon\", \"s2\": \"zozn\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"cmpr\", \"s2\": \"rmcp\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"qnde\", \"s2\": \"flsi\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"vofo\", \"s2\": \"oofv\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"xsvc\", \"s2\": \"vcxs\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"hvsz\", \"s2\": \"hzsv\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"ifjz\", \"s2\": \"jzfi\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"zrmq\", \"s2\": \"mrzq\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"hazw\", \"s2\": \"pfmp\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"kina\", \"s2\": \"kina\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"fymg\", \"s2\": \"famj\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"riti\", \"s2\": \"riti\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"goze\", \"s2\": \"gezo\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"seeo\", \"s2\": \"vfvm\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"ybyd\", \"s2\": \"himj\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"gcdm\", \"s2\": \"dmgc\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"kvne\", \"s2\": \"nekv\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"cbyo\", \"s2\": \"cbyo\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"fezu\", \"s2\": \"zufe\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"homs\", \"s2\": \"fhdu\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"zlek\", \"s2\": \"zlek\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"bxqt\", \"s2\": \"xbtq\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"waso\", \"s2\": \"wyjd\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"nibi\", \"s2\": \"seua\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"oynw\", \"s2\": \"sgxl\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"ehui\", \"s2\": \"uhei\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"vchn\", \"s2\": \"jfwr\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"zgmt\", \"s2\": \"zgmt\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"eobz\", \"s2\": \"boez\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"zpzg\", \"s2\": \"zzpg\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"bbfp\", \"s2\": \"fbbp\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"vxqp\", \"s2\": \"xpvq\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"ihtv\", \"s2\": \"ixji\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"ahsk\", \"s2\": \"aksh\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"zexw\", \"s2\": \"miva\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"iicq\", \"s2\": \"ihda\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"kunv\", \"s2\": \"ziac\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"gqzd\", \"s2\": \"gqzd\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"ppeb\", \"s2\": \"ebpp\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"uouc\", \"s2\": \"ucuo\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"laxa\", \"s2\": \"xala\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"rbwe\", \"s2\": \"wbre\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"mswt\", \"s2\": \"wsmt\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"yfyz\", \"s2\": \"deyv\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"jlai\", \"s2\": \"alji\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"uliu\", \"s2\": \"bsmu\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"bhag\", \"s2\": \"kuws\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"bvwr\", \"s2\": \"wrbv\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"safs\", \"s2\": \"safs\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"hzfp\", \"s2\": \"hpfz\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"xide\", \"s2\": \"dixe\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"qpye\", \"s2\": \"qpye\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"zaus\", \"s2\": \"zsua\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"lpsc\", \"s2\": \"cslp\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"taxc\", \"s2\": \"taxc\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"kkjc\", \"s2\": \"kcjk\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"pshr\", \"s2\": \"prhs\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"kpdr\", \"s2\": \"djoe\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"vzla\", \"s2\": \"lzva\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"tcar\", \"s2\": \"tacr\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"zkyt\", \"s2\": \"yfzr\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"puwg\", \"s2\": \"pgwu\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"ownv\", \"s2\": \"ovnw\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"rayz\", \"s2\": \"bpnf\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"zbwg\", \"s2\": \"wbzg\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"rypk\", \"s2\": \"pyrk\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"qchw\", \"s2\": \"bcqn\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"qtpf\", \"s2\": \"qfpt\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"apnl\", \"s2\": \"nlap\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"pkmh\", \"s2\": \"mkph\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"ouxw\", \"s2\": \"xuow\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"dlgd\", \"s2\": \"gdld\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"xbcx\", \"s2\": \"cxxb\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"eaba\", \"s2\": \"uaul\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"fyro\", \"s2\": \"rofy\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"bzqb\", \"s2\": \"bzqb\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"zyjv\", \"s2\": \"xjzr\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"jdvv\", \"s2\": \"djvv\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"nyxb\", \"s2\": \"ocry\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"gxlx\", \"s2\": \"lxgx\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"kgkr\", \"s2\": \"krkg\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"edfw\", \"s2\": \"fdew\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"vxkq\", \"s2\": \"kqxv\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"qnjc\", \"s2\": \"jivc\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"zzaf\", \"s2\": \"azzf\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"esgr\", \"s2\": \"gres\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"meuu\", \"s2\": \"yqlh\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"gjda\", \"s2\": \"djga\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"qaqz\", \"s2\": \"qaqz\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"legy\", \"s2\": \"lyge\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"eeum\", \"s2\": \"emue\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"vsvs\", \"s2\": \"vsvs\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"mxlk\", \"s2\": \"mxlk\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"nbre\", \"s2\": \"renb\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"erfk\", \"s2\": \"gmfy\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"gsic\", \"s2\": \"snvs\" }\nassert my_solution.canBeEqual(**test_input) == False", "start_time": 1693665000} +{"task_id": "biweekly-contest-112-check-if-strings-can-be-made-equal-with-operations-ii", "url": "https://leetcode.com/problems/check-if-strings-can-be-made-equal-with-operations-ii", "title": "check-if-strings-can-be-made-equal-with-operations-ii", "meta": {"questionId": "2978", "questionFrontendId": "2840", "title": "Check if Strings Can be Made Equal With Operations II", "titleSlug": "check-if-strings-can-be-made-equal-with-operations-ii", "isPaidOnly": false, "difficulty": "Medium", "likes": 231, "dislikes": 2, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你两个字符串 s1 和 s2 ,两个字符串长度都为 n ,且只包含 小写 英文字母。\n\n你可以对两个字符串中的 任意一个 执行以下操作 任意 次:\n\n * 选择两个下标 i 和 j ,满足 i < j 且 j - i 是 偶数,然后 交换 这个字符串中两个下标对应的字符。\n\n如果你可以让字符串 s1 和 s2 相等,那么返回 true ,否则返回 false 。\n\n\n示例 1:\n\n输入:s1 = \"abcdba\", s2 = \"cabdab\"\n输出:true\n解释:我们可以对 s1 执行以下操作:\n- 选择下标 i = 0 ,j = 2 ,得到字符串 s1 = \"cbadba\" 。\n- 选择下标 i = 2 ,j = 4 ,得到字符串 s1 = \"cbbdaa\" 。\n- 选择下标 i = 1 ,j = 5 ,得到字符串 s1 = \"cabdab\" = s2 。\n\n示例 2:\n\n输入:s1 = \"abe\", s2 = \"bea\"\n输出:false\n解释:无法让两个字符串相等。\n\n\n提示:\n\n * n == s1.length == s2.length\n * 1 <= n <= 105\n * s1 和 s2 只包含小写英文字母。\n\"\"\"\nclass Solution:\n def checkStrings(self, s1: str, s2: str) -> bool:\n ", "prompt_sft": "给你两个字符串 s1 和 s2 ,两个字符串长度都为 n ,且只包含 小写 英文字母。\n\n你可以对两个字符串中的 任意一个 执行以下操作 任意 次:\n\n * 选择两个下标 i 和 j ,满足 i < j 且 j - i 是 偶数,然后 交换 这个字符串中两个下标对应的字符。\n\n如果你可以让字符串 s1 和 s2 相等,那么返回 true ,否则返回 false 。\n\n\n示例 1:\n\n输入:s1 = \"abcdba\", s2 = \"cabdab\"\n输出:true\n解释:我们可以对 s1 执行以下操作:\n- 选择下标 i = 0 ,j = 2 ,得到字符串 s1 = \"cbadba\" 。\n- 选择下标 i = 2 ,j = 4 ,得到字符串 s1 = \"cbbdaa\" 。\n- 选择下标 i = 1 ,j = 5 ,得到字符串 s1 = \"cabdab\" = s2 。\n\n示例 2:\n\n输入:s1 = \"abe\", s2 = \"bea\"\n输出:false\n解释:无法让两个字符串相等。\n\n\n提示:\n\n * n == s1.length == s2.length\n * 1 <= n <= 105\n * s1 和 s2 只包含小写英文字母。\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def checkStrings(self, s1: str, s2: str) -> bool:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"s1\": \"abe\", \"s2\": \"bea\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"abcdba\", \"s2\": \"cabdab\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"ublnlasppynwgx\", \"s2\": \"ganplbuylnswpx\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"jghn\", \"s2\": \"jghn\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"pqtsprqmvi\", \"s2\": \"qrvqpitmps\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"aavizsxpqhxztrwi\", \"s2\": \"zvisqatzpaxhixwr\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"slmqqdbrwyvm\", \"s2\": \"qyldmmwsrqvb\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"shvqocguj\", \"s2\": \"vqsghujco\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"ktjpralqanofuuqsyal\", \"s2\": \"qjlornpasktfuyluaqa\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"mgflranpdjdkrh\", \"s2\": \"fpcgobmkdxbzyl\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"usvpwcehhvlg\", \"s2\": \"ehuvvshcwplg\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"jh\", \"s2\": \"fy\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"kfqofkvsoiiirznw\", \"s2\": \"hosthwbinxrsikkf\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"ppmfd\", \"s2\": \"pfdpm\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"ntuuwwh\", \"s2\": \"jyjwmdf\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"lcgcm\", \"s2\": \"brdxe\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"hjswnccgwjcapko\", \"s2\": \"acwjnjoscchgwpk\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"epjtzubboiallzd\", \"s2\": \"dboilpzzjteualb\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"c\", \"s2\": \"c\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"oziiqbotydegrm\", \"s2\": \"ytizriobogqmed\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"ztmuzn\", \"s2\": \"muztzn\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"jkzcqlh\", \"s2\": \"hkqczlj\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"qnh\", \"s2\": \"cmq\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"azagmtvhske\", \"s2\": \"mkazstvhage\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"jitb\", \"s2\": \"zqbg\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"tgznpamgczyvqjzvp\", \"s2\": \"mpyzvzzjvaqntgpgc\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"tcl\", \"s2\": \"lct\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"datuhdkoqe\", \"s2\": \"hetddokuqa\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"ztnpdilyrxz\", \"s2\": \"yxzitnrdlzp\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"vx\", \"s2\": \"zv\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"tpfcyceq\", \"s2\": \"fceqtpyc\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"rcugebinbszkhy\", \"s2\": \"zkebryhcbginus\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"ryykp\", \"s2\": \"rkpyy\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"lpyfmysemgoxgawwr\", \"s2\": \"wfoyspygralemxgwm\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"bfylavpyffcnj\", \"s2\": \"cljfbfyvpnayf\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"chhbmikpp\", \"s2\": \"hpcimbkhp\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"nateujd\", \"s2\": \"jeutnad\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"sxrjofoedghtplnex\", \"s2\": \"sgdeolnepthfojrxx\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"ajvfujrczdciilihi\", \"s2\": \"jcriaviuiflicdhzj\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"gajpuahzcexdunltldh\", \"s2\": \"xxatubgvqzmxjvzcxah\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"hnisnfvikgrhkfoe\", \"s2\": \"hgkivsifrekfonnh\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"fvfsxftpuemgpnkzz\", \"s2\": \"mgknxpuztffvzepsf\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"zrwzpibwp\", \"s2\": \"pwpiwzbrz\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"zoqpcssnhugxffcptsj\", \"s2\": \"chgospjssfxnfpcuqzt\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"ldpjhj\", \"s2\": \"jdlpjh\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"zodbh\", \"s2\": \"pqdpy\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"mdcvitezgqur\", \"s2\": \"mvigcqrdeztu\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"rdyau\", \"s2\": \"dyrau\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"pyymcw\", \"s2\": \"ptlqxp\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"ebicv\", \"s2\": \"vibce\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"xkzknvrbvajwbj\", \"s2\": \"rnkwzbvvxkjbja\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"zoxpiqxvnk\", \"s2\": \"xvkpxinqoz\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"obhmqltgmoszljeyh\", \"s2\": \"ogmmlbhoeysjtlhzq\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"wfsdirrheuglhfkbjk\", \"s2\": \"wfsuhhglifkrebrdjk\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"shn\", \"s2\": \"hsn\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"xdicugry\", \"s2\": \"igucxdry\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"bkfmkrbybim\", \"s2\": \"brbimkkmbyf\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"dwowyfgreakdvfi\", \"s2\": \"yfiddfvwerkaowg\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"bdywnvbgmum\", \"s2\": \"guymbwdbnmv\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"tmujoqerfvupnyy\", \"s2\": \"uvortyfmuqypnje\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"hggckwudke\", \"s2\": \"ylkgulkehd\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"zrppcm\", \"s2\": \"okurkg\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"ennl\", \"s2\": \"ennl\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"spznlxodciidngyvvkl\", \"s2\": \"lnvnzdixivoglydscpk\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"nxezcoklmdbekyjp\", \"s2\": \"cdkenlkyeomxjzbp\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"yui\", \"s2\": \"iyu\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"zphe\", \"s2\": \"hpze\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"oyjngnej\", \"s2\": \"oynjjeng\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"kvwdssgl\", \"s2\": \"wskxsdgv\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"ozzfbhzkowpcv\", \"s2\": \"vzpwzkbhzfoco\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"h\", \"s2\": \"h\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"mqkdv\", \"s2\": \"kqvdm\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"hphfqesitgprud\", \"s2\": \"tpisuhqhfgdrpe\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"yrbto\", \"s2\": \"orytb\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"lvahby\", \"s2\": \"ilbyaz\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"bbaiabphflgyfo\", \"s2\": \"bhglybaoaipbff\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"uielps\", \"s2\": \"uselpi\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"ftyhgkgwg\", \"s2\": \"gtfhgwgky\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"mzrfxrwlliuoi\", \"s2\": \"llrouzirwimfx\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"drofbzocwolcznzfi\", \"s2\": \"wzocdnirzfbclozfo\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"popefwbkepdxy\", \"s2\": \"pxbwpeekfoypd\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"swgzqluzcvhskegvdry\", \"s2\": \"seuwkvclqzyvdsgrgzh\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"hik\", \"s2\": \"ihk\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"zq\", \"s2\": \"zq\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"igdzd\", \"s2\": \"phcyi\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"cazutcxkhcklpuogt\", \"s2\": \"ockghuukctcztxapl\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"bx\", \"s2\": \"bx\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"bkujvjwgjzxdzuw\", \"s2\": \"zgjubjwkwzxdujv\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"ujpudt\", \"s2\": \"dtujpu\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"hkalpd\", \"s2\": \"hlpkad\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"kbcpjzadbv\", \"s2\": \"dsgzcapzao\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"rubbbf\", \"s2\": \"rbbubf\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"ybudbyrlmiddsxks\", \"s2\": \"nuyyabyisyptvdnb\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"wiijtcgqez\", \"s2\": \"ctqzwjgiei\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"bgalfvefwmhodexazkd\", \"s2\": \"fbgmdfholzakvxaweed\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"oxlphorosradotpshnt\", \"s2\": \"hdotpaoorosrlhtsxpn\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"mnvnzakjaymsxhojq\", \"s2\": \"oaxjoeanksmyqmglm\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"hsm\", \"s2\": \"hsm\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"qgloiyhewunm\", \"s2\": \"qehuwonmiylg\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"drdu\", \"s2\": \"dudr\" }\nassert my_solution.checkStrings(**test_input) == True", "start_time": 1693665000} +{"task_id": "biweekly-contest-112-maximum-sum-of-almost-unique-subarray", "url": "https://leetcode.com/problems/maximum-sum-of-almost-unique-subarray", "title": "maximum-sum-of-almost-unique-subarray", "meta": {"questionId": "2954", "questionFrontendId": "2841", "title": "Maximum Sum of Almost Unique Subarray", "titleSlug": "maximum-sum-of-almost-unique-subarray", "isPaidOnly": false, "difficulty": "Medium", "likes": 230, "dislikes": 133, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个整数数组 nums 和两个正整数 m 和 k 。\n\n请你返回 nums 中长度为 k 的 几乎唯一 子数组的 最大和 ,如果不存在几乎唯一子数组,请你返回 0 。\n\n如果 nums 的一个子数组有至少 m 个互不相同的元素,我们称它是 几乎唯一 子数组。\n\n子数组指的是一个数组中一段连续 非空 的元素序列。\n\n示例 1:\n\n输入:nums = [2,6,7,3,1,7], m = 3, k = 4\n输出:18\n解释:总共有 3 个长度为 k = 4 的几乎唯一子数组。分别为 [2, 6, 7, 3] ,[6, 7, 3, 1] 和 [7, 3, 1, 7] 。这些子数组中,和最大的是 [2, 6, 7, 3] ,和为 18 。\n\n示例 2:\n\n输入:nums = [5,9,9,2,4,5,4], m = 1, k = 3\n输出:23\n解释:总共有 5 个长度为 k = 3 的几乎唯一子数组。分别为 [5, 9, 9] ,[9, 9, 2] ,[9, 2, 4] ,[2, 4, 5] 和 [4, 5, 4] 。这些子数组中,和最大的是 [5, 9, 9] ,和为 23 。\n\n示例 3:\n\n输入:nums = [1,2,1,2,1,2,1], m = 3, k = 3\n输出:0\n解释:输入数组中不存在长度为 k = 3 的子数组含有至少 m = 3 个互不相同元素的子数组。所以不存在几乎唯一子数组,最大和为 0 。\n\n\n提示:\n\n * 1 <= nums.length <= 2 * 104\n * 1 <= m <= k <= nums.length\n * 1 <= nums[i] <= 109\n\"\"\"\nclass Solution:\n def maxSum(self, nums: List[int], m: int, k: int) -> int:\n ", "prompt_sft": "给你一个整数数组 nums 和两个正整数 m 和 k 。\n\n请你返回 nums 中长度为 k 的 几乎唯一 子数组的 最大和 ,如果不存在几乎唯一子数组,请你返回 0 。\n\n如果 nums 的一个子数组有至少 m 个互不相同的元素,我们称它是 几乎唯一 子数组。\n\n子数组指的是一个数组中一段连续 非空 的元素序列。\n\n示例 1:\n\n输入:nums = [2,6,7,3,1,7], m = 3, k = 4\n输出:18\n解释:总共有 3 个长度为 k = 4 的几乎唯一子数组。分别为 [2, 6, 7, 3] ,[6, 7, 3, 1] 和 [7, 3, 1, 7] 。这些子数组中,和最大的是 [2, 6, 7, 3] ,和为 18 。\n\n示例 2:\n\n输入:nums = [5,9,9,2,4,5,4], m = 1, k = 3\n输出:23\n解释:总共有 5 个长度为 k = 3 的几乎唯一子数组。分别为 [5, 9, 9] ,[9, 9, 2] ,[9, 2, 4] ,[2, 4, 5] 和 [4, 5, 4] 。这些子数组中,和最大的是 [5, 9, 9] ,和为 23 。\n\n示例 3:\n\n输入:nums = [1,2,1,2,1,2,1], m = 3, k = 3\n输出:0\n解释:输入数组中不存在长度为 k = 3 的子数组含有至少 m = 3 个互不相同元素的子数组。所以不存在几乎唯一子数组,最大和为 0 。\n\n\n提示:\n\n * 1 <= nums.length <= 2 * 104\n * 1 <= m <= k <= nums.length\n * 1 <= nums[i] <= 109\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def maxSum(self, nums: List[int], m: int, k: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [2,6,7,3,1,7], \"m\": 3, \"k\": 4 }\nassert my_solution.maxSum(**test_input) == 18\n\ntest_input = { \"nums\": [5,9,9,2,4,5,4], \"m\": 1, \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 23\n\ntest_input = { \"nums\": [1,2,1,2,1,2,1], \"m\": 3, \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 0\n\ntest_input = { \"nums\": [1], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 1\n\ntest_input = { \"nums\": [1,1], \"m\": 2, \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,1], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,1,1], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,1,2], \"m\": 2, \"k\": 4 }\nassert my_solution.maxSum(**test_input) == 5\n\ntest_input = { \"nums\": [1,1,1,3], \"m\": 2, \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,1,1,4], \"m\": 2, \"k\": 4 }\nassert my_solution.maxSum(**test_input) == 7\n\ntest_input = { \"nums\": [1,1,2], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,2,1], \"m\": 2, \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,2,2], \"m\": 1, \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 5\n\ntest_input = { \"nums\": [1,1,2,3], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,2,4], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,1,3], \"m\": 1, \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,1,3,1], \"m\": 2, \"k\": 4 }\nassert my_solution.maxSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,1,3,2], \"m\": 1, \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 5\n\ntest_input = { \"nums\": [1,1,3,3], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,3,4], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,1,4], \"m\": 1, \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,1,4,1], \"m\": 1, \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,1,4,2], \"m\": 2, \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,1,4,3], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,1,4,4], \"m\": 3, \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 0\n\ntest_input = { \"nums\": [1,2], \"m\": 1, \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,1], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 2\n\ntest_input = { \"nums\": [1,2,1,1], \"m\": 1, \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,1,2], \"m\": 2, \"k\": 4 }\nassert my_solution.maxSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,2,1,3], \"m\": 1, \"k\": 4 }\nassert my_solution.maxSum(**test_input) == 7\n\ntest_input = { \"nums\": [1,2,1,4], \"m\": 2, \"k\": 4 }\nassert my_solution.maxSum(**test_input) == 8\n\ntest_input = { \"nums\": [1,2,2], \"m\": 2, \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,2,1], \"m\": 2, \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,2,2], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 2\n\ntest_input = { \"nums\": [1,2,2,3], \"m\": 3, \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 0\n\ntest_input = { \"nums\": [1,2,2,4], \"m\": 1, \"k\": 4 }\nassert my_solution.maxSum(**test_input) == 9\n\ntest_input = { \"nums\": [1,2,3], \"m\": 1, \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 5\n\ntest_input = { \"nums\": [1,2,3,1], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,3,2], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,3,3], \"m\": 2, \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 8\n\ntest_input = { \"nums\": [1,2,3,4], \"m\": 1, \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 7\n\ntest_input = { \"nums\": [1,2,4], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,4,1], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,4,2], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,4,3], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,4,4], \"m\": 1, \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 8\n\ntest_input = { \"nums\": [1,3], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 3\n\ntest_input = { \"nums\": [1,3,1], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 3\n\ntest_input = { \"nums\": [1,3,1,1], \"m\": 2, \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 5\n\ntest_input = { \"nums\": [1,3,1,2], \"m\": 4, \"k\": 4 }\nassert my_solution.maxSum(**test_input) == 0\n\ntest_input = { \"nums\": [1,3,1,3], \"m\": 2, \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,3,1,4], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,3,2], \"m\": 1, \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 5\n\ntest_input = { \"nums\": [1,3,2,1], \"m\": 2, \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 5\n\ntest_input = { \"nums\": [1,3,2,2], \"m\": 1, \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 5\n\ntest_input = { \"nums\": [1,3,2,3], \"m\": 1, \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 8\n\ntest_input = { \"nums\": [1,3,2,4], \"m\": 3, \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 9\n\ntest_input = { \"nums\": [1,3,3], \"m\": 2, \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 7\n\ntest_input = { \"nums\": [1,3,3,1], \"m\": 2, \"k\": 4 }\nassert my_solution.maxSum(**test_input) == 8\n\ntest_input = { \"nums\": [1,3,3,2], \"m\": 2, \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 8\n\ntest_input = { \"nums\": [1,3,3,3], \"m\": 1, \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,3,3,4], \"m\": 2, \"k\": 4 }\nassert my_solution.maxSum(**test_input) == 11\n\ntest_input = { \"nums\": [1,3,4], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,3,4,1], \"m\": 2, \"k\": 4 }\nassert my_solution.maxSum(**test_input) == 9\n\ntest_input = { \"nums\": [1,3,4,2], \"m\": 3, \"k\": 4 }\nassert my_solution.maxSum(**test_input) == 10\n\ntest_input = { \"nums\": [1,3,4,3], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,3,4,4], \"m\": 1, \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 8\n\ntest_input = { \"nums\": [1,4], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,4,1], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,4,1,1], \"m\": 1, \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,4,1,2], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,4,1,3], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,4,1,4], \"m\": 2, \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 9\n\ntest_input = { \"nums\": [1,4,2], \"m\": 3, \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 7\n\ntest_input = { \"nums\": [1,4,2,1], \"m\": 2, \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,4,2,2], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,4,2,3], \"m\": 3, \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 9\n\ntest_input = { \"nums\": [1,4,2,4], \"m\": 1, \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 10\n\ntest_input = { \"nums\": [1,4,3], \"m\": 3, \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 8\n\ntest_input = { \"nums\": [1,4,3,1], \"m\": 1, \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 7\n\ntest_input = { \"nums\": [1,4,3,2], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,4,3,3], \"m\": 2, \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 7\n\ntest_input = { \"nums\": [1,4,3,4], \"m\": 3, \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 8\n\ntest_input = { \"nums\": [1,4,4], \"m\": 2, \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 9\n\ntest_input = { \"nums\": [1,4,4,1], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,4,4,2], \"m\": 1, \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 8\n\ntest_input = { \"nums\": [1,4,4,3], \"m\": 3, \"k\": 4 }\nassert my_solution.maxSum(**test_input) == 12\n\ntest_input = { \"nums\": [1,4,4,4], \"m\": 3, \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 0\n\ntest_input = { \"nums\": [2], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 2\n\ntest_input = { \"nums\": [2,1], \"m\": 2, \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 3\n\ntest_input = { \"nums\": [2,1,1], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 2\n\ntest_input = { \"nums\": [2,1,1,1], \"m\": 4, \"k\": 4 }\nassert my_solution.maxSum(**test_input) == 0\n\ntest_input = { \"nums\": [2,1,1,2], \"m\": 2, \"k\": 4 }\nassert my_solution.maxSum(**test_input) == 6\n\ntest_input = { \"nums\": [2,1,1,3], \"m\": 3, \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 0\n\ntest_input = { \"nums\": [2,1,1,4], \"m\": 2, \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 5\n\ntest_input = { \"nums\": [2,1,2], \"m\": 1, \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 5\n\ntest_input = { \"nums\": [2,1,2,1], \"m\": 2, \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 3\n\ntest_input = { \"nums\": [2,1,2,2], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 2\n\ntest_input = { \"nums\": [2,1,2,3], \"m\": 1, \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 6\n\ntest_input = { \"nums\": [2,1,2,4], \"m\": 1, \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 7", "start_time": 1693665000} +{"task_id": "biweekly-contest-112-count-k-subsequences-of-a-string-with-maximum-beauty", "url": "https://leetcode.com/problems/count-k-subsequences-of-a-string-with-maximum-beauty", "title": "count-k-subsequences-of-a-string-with-maximum-beauty", "meta": {"questionId": "3057", "questionFrontendId": "2842", "title": "Count K-Subsequences of a String With Maximum Beauty", "titleSlug": "count-k-subsequences-of-a-string-with-maximum-beauty", "isPaidOnly": false, "difficulty": "Hard", "likes": 286, "dislikes": 21, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个字符串 s 和一个整数 k 。\n\nk 子序列指的是 s 的一个长度为 k 的 子序列 ,且所有字符都是 唯一 的,也就是说每个字符在子序列里只出现过一次。\n\n定义 f(c) 为字符 c 在 s 中出现的次数。\n\nk 子序列的 美丽值 定义为这个子序列中每一个字符 c 的 f(c) 之 和 。\n\n比方说,s = \"abbbdd\" 和 k = 2 ,我们有:\n\n * f('a') = 1, f('b') = 3, f('d') = 2\n * s 的部分 k 子序列为:\n * \"abbbdd\" -> \"ab\" ,美丽值为 f('a') + f('b') = 4\n * \"abbbdd\" -> \"ad\" ,美丽值为 f('a') + f('d') = 3\n * \"abbbdd\" -> \"bd\" ,美丽值为 f('b') + f('d') = 5\n\n请你返回一个整数,表示所有 k 子序列 里面 美丽值 是 最大值 的子序列数目。由于答案可能很大,将结果对 109 + 7 取余后返回。\n\n一个字符串的子序列指的是从原字符串里面删除一些字符(也可能一个字符也不删除),不改变剩下字符顺序连接得到的新字符串。\n\n注意:\n\n * f(c) 指的是字符 c 在字符串 s 的出现次数,不是在 k 子序列里的出现次数。\n * 两个 k 子序列如果有任何一个字符在原字符串中的下标不同,则它们是两个不同的子序列。所以两个不同的 k 子序列可能产生相同的字符串。\n\n示例 1:\n\n输入:s = \"bcca\", k = 2\n输出:4\n解释:s 中我们有 f('a') = 1 ,f('b') = 1 和 f('c') = 2 。\ns 的 k 子序列为:\nbcca ,美丽值为 f('b') + f('c') = 3\nbcca ,美丽值为 f('b') + f('c') = 3\nbcca ,美丽值为 f('b') + f('a') = 2\nbcca ,美丽值为 f('c') + f('a') = 3\nbcca ,美丽值为 f('c') + f('a') = 3\n总共有 4 个 k 子序列美丽值为最大值 3 。\n所以答案为 4 。\n\n示例 2:\n\n输入:s = \"abbcd\", k = 4\n输出:2\n解释:s 中我们有 f('a') = 1 ,f('b') = 2 ,f('c') = 1 和 f('d') = 1 。\ns 的 k 子序列为:\nabbcd ,美丽值为 f('a') + f('b') + f('c') + f('d') = 5\nabbcd ,美丽值为 f('a') + f('b') + f('c') + f('d') = 5\n总共有 2 个 k 子序列美丽值为最大值 5 。\n所以答案为 2 。\n\n\n提示:\n\n * 1 <= s.length <= 2 * 105\n * 1 <= k <= s.length\n * s 只包含小写英文字母。\n\"\"\"\nclass Solution:\n def countKSubsequencesWithMaxBeauty(self, s: str, k: int) -> int:\n ", "prompt_sft": "给你一个字符串 s 和一个整数 k 。\n\nk 子序列指的是 s 的一个长度为 k 的 子序列 ,且所有字符都是 唯一 的,也就是说每个字符在子序列里只出现过一次。\n\n定义 f(c) 为字符 c 在 s 中出现的次数。\n\nk 子序列的 美丽值 定义为这个子序列中每一个字符 c 的 f(c) 之 和 。\n\n比方说,s = \"abbbdd\" 和 k = 2 ,我们有:\n\n * f('a') = 1, f('b') = 3, f('d') = 2\n * s 的部分 k 子序列为:\n * \"abbbdd\" -> \"ab\" ,美丽值为 f('a') + f('b') = 4\n * \"abbbdd\" -> \"ad\" ,美丽值为 f('a') + f('d') = 3\n * \"abbbdd\" -> \"bd\" ,美丽值为 f('b') + f('d') = 5\n\n请你返回一个整数,表示所有 k 子序列 里面 美丽值 是 最大值 的子序列数目。由于答案可能很大,将结果对 109 + 7 取余后返回。\n\n一个字符串的子序列指的是从原字符串里面删除一些字符(也可能一个字符也不删除),不改变剩下字符顺序连接得到的新字符串。\n\n注意:\n\n * f(c) 指的是字符 c 在字符串 s 的出现次数,不是在 k 子序列里的出现次数。\n * 两个 k 子序列如果有任何一个字符在原字符串中的下标不同,则它们是两个不同的子序列。所以两个不同的 k 子序列可能产生相同的字符串。\n\n示例 1:\n\n输入:s = \"bcca\", k = 2\n输出:4\n解释:s 中我们有 f('a') = 1 ,f('b') = 1 和 f('c') = 2 。\ns 的 k 子序列为:\nbcca ,美丽值为 f('b') + f('c') = 3\nbcca ,美丽值为 f('b') + f('c') = 3\nbcca ,美丽值为 f('b') + f('a') = 2\nbcca ,美丽值为 f('c') + f('a') = 3\nbcca ,美丽值为 f('c') + f('a') = 3\n总共有 4 个 k 子序列美丽值为最大值 3 。\n所以答案为 4 。\n\n示例 2:\n\n输入:s = \"abbcd\", k = 4\n输出:2\n解释:s 中我们有 f('a') = 1 ,f('b') = 2 ,f('c') = 1 和 f('d') = 1 。\ns 的 k 子序列为:\nabbcd ,美丽值为 f('a') + f('b') + f('c') + f('d') = 5\nabbcd ,美丽值为 f('a') + f('b') + f('c') + f('d') = 5\n总共有 2 个 k 子序列美丽值为最大值 5 。\n所以答案为 2 。\n\n\n提示:\n\n * 1 <= s.length <= 2 * 105\n * 1 <= k <= s.length\n * s 只包含小写英文字母。\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def countKSubsequencesWithMaxBeauty(self, s: str, k: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"s\": \"bcca\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 4\n\ntest_input = { \"s\": \"abbcd\", \"k\": 4 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 2\n\ntest_input = { \"s\": \"am\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1\n\ntest_input = { \"s\": \"az\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1\n\ntest_input = { \"s\": \"ci\", \"k\": 1 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 2\n\ntest_input = { \"s\": \"dd\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 0\n\ntest_input = { \"s\": \"di\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1\n\ntest_input = { \"s\": \"dw\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1\n\ntest_input = { \"s\": \"ef\", \"k\": 1 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 2\n\ntest_input = { \"s\": \"gq\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1\n\ntest_input = { \"s\": \"hj\", \"k\": 1 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 2\n\ntest_input = { \"s\": \"hx\", \"k\": 1 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 2\n\ntest_input = { \"s\": \"ii\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 0\n\ntest_input = { \"s\": \"il\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1\n\ntest_input = { \"s\": \"jb\", \"k\": 1 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 2\n\ntest_input = { \"s\": \"kx\", \"k\": 1 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 2\n\ntest_input = { \"s\": \"qh\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1\n\ntest_input = { \"s\": \"qk\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1\n\ntest_input = { \"s\": \"qr\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1\n\ntest_input = { \"s\": \"rg\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1\n\ntest_input = { \"s\": \"rn\", \"k\": 1 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 2\n\ntest_input = { \"s\": \"st\", \"k\": 1 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 2\n\ntest_input = { \"s\": \"tb\", \"k\": 1 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 2\n\ntest_input = { \"s\": \"tl\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1\n\ntest_input = { \"s\": \"xc\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1\n\ntest_input = { \"s\": \"auy\", \"k\": 1 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 3\n\ntest_input = { \"s\": \"axm\", \"k\": 3 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1\n\ntest_input = { \"s\": \"dqc\", \"k\": 1 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 3\n\ntest_input = { \"s\": \"fkp\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 3\n\ntest_input = { \"s\": \"fmk\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 3\n\ntest_input = { \"s\": \"fvl\", \"k\": 3 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1\n\ntest_input = { \"s\": \"hcx\", \"k\": 3 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1\n\ntest_input = { \"s\": \"iua\", \"k\": 3 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1\n\ntest_input = { \"s\": \"kzb\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 3\n\ntest_input = { \"s\": \"mhb\", \"k\": 3 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1\n\ntest_input = { \"s\": \"nzo\", \"k\": 1 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 3\n\ntest_input = { \"s\": \"oof\", \"k\": 3 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 0\n\ntest_input = { \"s\": \"rfh\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 3\n\ntest_input = { \"s\": \"sty\", \"k\": 1 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 3\n\ntest_input = { \"s\": \"sue\", \"k\": 3 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1\n\ntest_input = { \"s\": \"tba\", \"k\": 3 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1\n\ntest_input = { \"s\": \"tmc\", \"k\": 1 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 3\n\ntest_input = { \"s\": \"wes\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 3\n\ntest_input = { \"s\": \"wvl\", \"k\": 1 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 3\n\ntest_input = { \"s\": \"xho\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 3\n\ntest_input = { \"s\": \"xke\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 3\n\ntest_input = { \"s\": \"ysu\", \"k\": 3 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1\n\ntest_input = { \"s\": \"yxn\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 3\n\ntest_input = { \"s\": \"zco\", \"k\": 1 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 3\n\ntest_input = { \"s\": \"zpq\", \"k\": 3 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1\n\ntest_input = { \"s\": \"axgn\", \"k\": 4 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1\n\ntest_input = { \"s\": \"dfyq\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 6\n\ntest_input = { \"s\": \"dogq\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 6\n\ntest_input = { \"s\": \"drbs\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 6\n\ntest_input = { \"s\": \"elex\", \"k\": 4 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 0\n\ntest_input = { \"s\": \"fsaj\", \"k\": 1 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 4\n\ntest_input = { \"s\": \"fxau\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 6\n\ntest_input = { \"s\": \"glbq\", \"k\": 4 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1\n\ntest_input = { \"s\": \"hzcj\", \"k\": 4 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1\n\ntest_input = { \"s\": \"minc\", \"k\": 3 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 4\n\ntest_input = { \"s\": \"nkim\", \"k\": 1 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 4\n\ntest_input = { \"s\": \"otpl\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 6\n\ntest_input = { \"s\": \"pvrz\", \"k\": 4 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1\n\ntest_input = { \"s\": \"qwmy\", \"k\": 4 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1\n\ntest_input = { \"s\": \"rliu\", \"k\": 4 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1\n\ntest_input = { \"s\": \"tpig\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 6\n\ntest_input = { \"s\": \"ucvh\", \"k\": 4 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1\n\ntest_input = { \"s\": \"vevt\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 4\n\ntest_input = { \"s\": \"xstt\", \"k\": 3 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 2\n\ntest_input = { \"s\": \"ypmv\", \"k\": 3 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 4\n\ntest_input = { \"s\": \"znoq\", \"k\": 3 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 4\n\ntest_input = { \"s\": \"bicnt\", \"k\": 1 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 5\n\ntest_input = { \"s\": \"bnhom\", \"k\": 5 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1\n\ntest_input = { \"s\": \"culhr\", \"k\": 5 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1\n\ntest_input = { \"s\": \"dpfki\", \"k\": 1 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 5\n\ntest_input = { \"s\": \"dscbu\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 10\n\ntest_input = { \"s\": \"edwlo\", \"k\": 3 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 10\n\ntest_input = { \"s\": \"ggsgo\", \"k\": 3 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 3\n\ntest_input = { \"s\": \"guzzf\", \"k\": 4 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 2\n\ntest_input = { \"s\": \"gzzzl\", \"k\": 3 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 3\n\ntest_input = { \"s\": \"kjojr\", \"k\": 3 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 6\n\ntest_input = { \"s\": \"kvsds\", \"k\": 5 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 0\n\ntest_input = { \"s\": \"ljdvp\", \"k\": 1 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 5\n\ntest_input = { \"s\": \"mdccc\", \"k\": 5 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 0\n\ntest_input = { \"s\": \"mmqny\", \"k\": 4 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 2\n\ntest_input = { \"s\": \"mrbrj\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 6\n\ntest_input = { \"s\": \"pwtbx\", \"k\": 4 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 5\n\ntest_input = { \"s\": \"qcxkr\", \"k\": 3 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 10\n\ntest_input = { \"s\": \"qvauy\", \"k\": 1 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 5\n\ntest_input = { \"s\": \"tzwoq\", \"k\": 3 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 10\n\ntest_input = { \"s\": \"ufxge\", \"k\": 4 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 5\n\ntest_input = { \"s\": \"unzxd\", \"k\": 4 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 5\n\ntest_input = { \"s\": \"vhqqj\", \"k\": 3 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 6\n\ntest_input = { \"s\": \"vnkbt\", \"k\": 1 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 5\n\ntest_input = { \"s\": \"wpbkz\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 10\n\ntest_input = { \"s\": \"xdgvy\", \"k\": 1 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 5\n\ntest_input = { \"s\": \"yelem\", \"k\": 5 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 0\n\ntest_input = { \"s\": \"zwkhq\", \"k\": 3 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 10\n\ntest_input = { \"s\": \"anxnfi\", \"k\": 5 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 2\n\ntest_input = { \"s\": \"cfbyuf\", \"k\": 5 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 2", "start_time": 1693665000} +{"task_id": "weekly-contest-360-furthest-point-from-origin", "url": "https://leetcode.com/problems/furthest-point-from-origin", "title": "furthest-point-from-origin", "meta": {"questionId": "3019", "questionFrontendId": "2833", "title": "Furthest Point From Origin", "titleSlug": "furthest-point-from-origin", "isPaidOnly": false, "difficulty": "Easy", "likes": 203, "dislikes": 29, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个长度为 n 的字符串 moves ,该字符串仅由字符 'L'、'R' 和 '_' 组成。字符串表示你在一条原点为 0 的数轴上的若干次移动。\n\n你的初始位置就在原点(0),第 i 次移动过程中,你可以根据对应字符选择移动方向:\n\n * 如果 moves[i] = 'L' 或 moves[i] = '_' ,可以选择向左移动一个单位距离\n * 如果 moves[i] = 'R' 或 moves[i] = '_' ,可以选择向右移动一个单位距离\n\n移动 n 次之后,请你找出可以到达的距离原点 最远 的点,并返回 从原点到这一点的距离 。\n\n示例 1:\n\n输入:moves = \"L_RL__R\"\n输出:3\n解释:可以到达的距离原点 0 最远的点是 -3 ,移动的序列为 \"LLRLLLR\" 。\n\n示例 2:\n\n输入:moves = \"_R__LL_\"\n输出:5\n解释:可以到达的距离原点 0 最远的点是 -5 ,移动的序列为 \"LRLLLLL\" 。\n\n示例 3:\n\n输入:moves = \"_______\"\n输出:7\n解释:可以到达的距离原点 0 最远的点是 7 ,移动的序列为 \"RRRRRRR\" 。\n\n\n提示:\n\n * 1 <= moves.length == n <= 50\n * moves 仅由字符 'L'、'R' 和 '_' 组成\n\"\"\"\nclass Solution:\n def furthestDistanceFromOrigin(self, moves: str) -> int:\n ", "prompt_sft": "给你一个长度为 n 的字符串 moves ,该字符串仅由字符 'L'、'R' 和 '_' 组成。字符串表示你在一条原点为 0 的数轴上的若干次移动。\n\n你的初始位置就在原点(0),第 i 次移动过程中,你可以根据对应字符选择移动方向:\n\n * 如果 moves[i] = 'L' 或 moves[i] = '_' ,可以选择向左移动一个单位距离\n * 如果 moves[i] = 'R' 或 moves[i] = '_' ,可以选择向右移动一个单位距离\n\n移动 n 次之后,请你找出可以到达的距离原点 最远 的点,并返回 从原点到这一点的距离 。\n\n示例 1:\n\n输入:moves = \"L_RL__R\"\n输出:3\n解释:可以到达的距离原点 0 最远的点是 -3 ,移动的序列为 \"LLRLLLR\" 。\n\n示例 2:\n\n输入:moves = \"_R__LL_\"\n输出:5\n解释:可以到达的距离原点 0 最远的点是 -5 ,移动的序列为 \"LRLLLLL\" 。\n\n示例 3:\n\n输入:moves = \"_______\"\n输出:7\n解释:可以到达的距离原点 0 最远的点是 7 ,移动的序列为 \"RRRRRRR\" 。\n\n\n提示:\n\n * 1 <= moves.length == n <= 50\n * moves 仅由字符 'L'、'R' 和 '_' 组成\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def furthestDistanceFromOrigin(self, moves: str) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"moves\": \"L_RL__R\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 3\n\ntest_input = { \"moves\": \"_R__LL_\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 5\n\ntest_input = { \"moves\": \"_______\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 7\n\ntest_input = { \"moves\": \"L\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 1\n\ntest_input = { \"moves\": \"R\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 1\n\ntest_input = { \"moves\": \"_\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 1\n\ntest_input = { \"moves\": \"LL\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"LR\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 0\n\ntest_input = { \"moves\": \"L_\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"RL\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 0\n\ntest_input = { \"moves\": \"RR\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"R_\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"_L\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"_R\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"__\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"LLL\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 3\n\ntest_input = { \"moves\": \"LLR\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 1\n\ntest_input = { \"moves\": \"LL_\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 3\n\ntest_input = { \"moves\": \"LRL\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 1\n\ntest_input = { \"moves\": \"LRR\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 1\n\ntest_input = { \"moves\": \"LR_\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 1\n\ntest_input = { \"moves\": \"L_L\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 3\n\ntest_input = { \"moves\": \"L_R\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 1\n\ntest_input = { \"moves\": \"L__\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 3\n\ntest_input = { \"moves\": \"RLL\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 1\n\ntest_input = { \"moves\": \"RLR\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 1\n\ntest_input = { \"moves\": \"RL_\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 1\n\ntest_input = { \"moves\": \"RRL\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 1\n\ntest_input = { \"moves\": \"RRR\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 3\n\ntest_input = { \"moves\": \"RR_\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 3\n\ntest_input = { \"moves\": \"R_L\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 1\n\ntest_input = { \"moves\": \"R_R\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 3\n\ntest_input = { \"moves\": \"R__\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 3\n\ntest_input = { \"moves\": \"_LL\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 3\n\ntest_input = { \"moves\": \"_LR\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 1\n\ntest_input = { \"moves\": \"_L_\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 3\n\ntest_input = { \"moves\": \"_RL\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 1\n\ntest_input = { \"moves\": \"_RR\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 3\n\ntest_input = { \"moves\": \"_R_\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 3\n\ntest_input = { \"moves\": \"__L\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 3\n\ntest_input = { \"moves\": \"__R\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 3\n\ntest_input = { \"moves\": \"___\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 3\n\ntest_input = { \"moves\": \"LLLL\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 4\n\ntest_input = { \"moves\": \"LLLR\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"LLL_\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 4\n\ntest_input = { \"moves\": \"LLRL\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"LLRR\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 0\n\ntest_input = { \"moves\": \"LLR_\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"LL_L\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 4\n\ntest_input = { \"moves\": \"LL_R\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"LL__\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 4\n\ntest_input = { \"moves\": \"LRLL\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"LRLR\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 0\n\ntest_input = { \"moves\": \"LRL_\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"LRRL\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 0\n\ntest_input = { \"moves\": \"LRRR\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"LRR_\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"LR_L\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"LR_R\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"LR__\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"L_LL\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 4\n\ntest_input = { \"moves\": \"L_LR\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"L_L_\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 4\n\ntest_input = { \"moves\": \"L_RL\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"L_RR\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"L_R_\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"L__L\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 4\n\ntest_input = { \"moves\": \"L__R\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"L___\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 4\n\ntest_input = { \"moves\": \"RLLL\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"RLLR\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 0\n\ntest_input = { \"moves\": \"RLL_\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"RLRL\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 0\n\ntest_input = { \"moves\": \"RLRR\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"RLR_\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"RL_L\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"RL_R\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"RL__\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"RRLL\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 0\n\ntest_input = { \"moves\": \"RRLR\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"RRL_\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"RRRL\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"RRRR\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 4\n\ntest_input = { \"moves\": \"RRR_\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 4\n\ntest_input = { \"moves\": \"RR_L\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"RR_R\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 4\n\ntest_input = { \"moves\": \"RR__\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 4\n\ntest_input = { \"moves\": \"R_LL\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"R_LR\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"R_L_\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"R_RL\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"R_RR\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 4\n\ntest_input = { \"moves\": \"R_R_\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 4\n\ntest_input = { \"moves\": \"R__L\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"R__R\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 4\n\ntest_input = { \"moves\": \"R___\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 4\n\ntest_input = { \"moves\": \"_LLL\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 4\n\ntest_input = { \"moves\": \"_LLR\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"_LL_\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 4\n\ntest_input = { \"moves\": \"_LRL\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2", "start_time": 1693103400} +{"task_id": "weekly-contest-360-find-the-minimum-possible-sum-of-a-beautiful-array", "url": "https://leetcode.com/problems/find-the-minimum-possible-sum-of-a-beautiful-array", "title": "find-the-minimum-possible-sum-of-a-beautiful-array", "meta": {"questionId": "3026", "questionFrontendId": "2834", "title": "Find the Minimum Possible Sum of a Beautiful Array", "titleSlug": "find-the-minimum-possible-sum-of-a-beautiful-array", "isPaidOnly": false, "difficulty": "Medium", "likes": 276, "dislikes": 37, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你两个正整数:n 和 target 。\n\n如果数组 nums 满足下述条件,则称其为 美丽数组 。\n\n * nums.length == n.\n * nums 由两两互不相同的正整数组成。\n * 在范围 [0, n-1] 内,不存在 两个 不同 下标 i 和 j ,使得 nums[i] + nums[j] == target 。\n\n返回符合条件的美丽数组所可能具备的 最小 和,并对结果进行取模 109 + 7。\n\n示例 1:\n\n输入:n = 2, target = 3\n输出:4\n解释:nums = [1,3] 是美丽数组。\n- nums 的长度为 n = 2 。\n- nums 由两两互不相同的正整数组成。\n- 不存在两个不同下标 i 和 j ,使得 nums[i] + nums[j] == 3 。\n可以证明 4 是符合条件的美丽数组所可能具备的最小和。\n\n示例 2:\n\n输入:n = 3, target = 3\n输出:8\n解释:\nnums = [1,3,4] 是美丽数组。\n- nums 的长度为 n = 3 。\n- nums 由两两互不相同的正整数组成。\n- 不存在两个不同下标 i 和 j ,使得 nums[i] + nums[j] == 3 。\n可以证明 8 是符合条件的美丽数组所可能具备的最小和。\n\n示例 3:\n\n输入:n = 1, target = 1\n输出:1\n解释:nums = [1] 是美丽数组。\n\n\n提示:\n\n * 1 <= n <= 109\n * 1 <= target <= 109\n\"\"\"\nclass Solution:\n def minimumPossibleSum(self, n: int, target: int) -> int:\n ", "prompt_sft": "给你两个正整数:n 和 target 。\n\n如果数组 nums 满足下述条件,则称其为 美丽数组 。\n\n * nums.length == n.\n * nums 由两两互不相同的正整数组成。\n * 在范围 [0, n-1] 内,不存在 两个 不同 下标 i 和 j ,使得 nums[i] + nums[j] == target 。\n\n返回符合条件的美丽数组所可能具备的 最小 和,并对结果进行取模 109 + 7。\n\n示例 1:\n\n输入:n = 2, target = 3\n输出:4\n解释:nums = [1,3] 是美丽数组。\n- nums 的长度为 n = 2 。\n- nums 由两两互不相同的正整数组成。\n- 不存在两个不同下标 i 和 j ,使得 nums[i] + nums[j] == 3 。\n可以证明 4 是符合条件的美丽数组所可能具备的最小和。\n\n示例 2:\n\n输入:n = 3, target = 3\n输出:8\n解释:\nnums = [1,3,4] 是美丽数组。\n- nums 的长度为 n = 3 。\n- nums 由两两互不相同的正整数组成。\n- 不存在两个不同下标 i 和 j ,使得 nums[i] + nums[j] == 3 。\n可以证明 8 是符合条件的美丽数组所可能具备的最小和。\n\n示例 3:\n\n输入:n = 1, target = 1\n输出:1\n解释:nums = [1] 是美丽数组。\n\n\n提示:\n\n * 1 <= n <= 109\n * 1 <= target <= 109\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def minimumPossibleSum(self, n: int, target: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"n\": 2, \"target\": 3 }\nassert my_solution.minimumPossibleSum(**test_input) == 4\n\ntest_input = { \"n\": 3, \"target\": 3 }\nassert my_solution.minimumPossibleSum(**test_input) == 8\n\ntest_input = { \"n\": 1, \"target\": 1 }\nassert my_solution.minimumPossibleSum(**test_input) == 1\n\ntest_input = { \"n\": 16, \"target\": 6 }\nassert my_solution.minimumPossibleSum(**test_input) == 162\n\ntest_input = { \"n\": 16, \"target\": 32 }\nassert my_solution.minimumPossibleSum(**test_input) == 136\n\ntest_input = { \"n\": 13, \"target\": 50 }\nassert my_solution.minimumPossibleSum(**test_input) == 91\n\ntest_input = { \"n\": 36, \"target\": 21 }\nassert my_solution.minimumPossibleSum(**test_input) == 926\n\ntest_input = { \"n\": 40, \"target\": 17 }\nassert my_solution.minimumPossibleSum(**test_input) == 1076\n\ntest_input = { \"n\": 37, \"target\": 46 }\nassert my_solution.minimumPossibleSum(**test_input) == 1011\n\ntest_input = { \"n\": 33, \"target\": 7 }\nassert my_solution.minimumPossibleSum(**test_input) == 651\n\ntest_input = { \"n\": 42, \"target\": 46 }\nassert my_solution.minimumPossibleSum(**test_input) == 1321\n\ntest_input = { \"n\": 46, \"target\": 29 }\nassert my_solution.minimumPossibleSum(**test_input) == 1529\n\ntest_input = { \"n\": 9, \"target\": 43 }\nassert my_solution.minimumPossibleSum(**test_input) == 45\n\ntest_input = { \"n\": 30, \"target\": 31 }\nassert my_solution.minimumPossibleSum(**test_input) == 690\n\ntest_input = { \"n\": 14, \"target\": 47 }\nassert my_solution.minimumPossibleSum(**test_input) == 105\n\ntest_input = { \"n\": 5, \"target\": 3 }\nassert my_solution.minimumPossibleSum(**test_input) == 19\n\ntest_input = { \"n\": 41, \"target\": 23 }\nassert my_solution.minimumPossibleSum(**test_input) == 1191\n\ntest_input = { \"n\": 17, \"target\": 13 }\nassert my_solution.minimumPossibleSum(**test_input) == 219\n\ntest_input = { \"n\": 9, \"target\": 13 }\nassert my_solution.minimumPossibleSum(**test_input) == 63\n\ntest_input = { \"n\": 29, \"target\": 18 }\nassert my_solution.minimumPossibleSum(**test_input) == 595\n\ntest_input = { \"n\": 21, \"target\": 14 }\nassert my_solution.minimumPossibleSum(**test_input) == 315\n\ntest_input = { \"n\": 4, \"target\": 6 }\nassert my_solution.minimumPossibleSum(**test_input) == 12\n\ntest_input = { \"n\": 38, \"target\": 15 }\nassert my_solution.minimumPossibleSum(**test_input) == 958\n\ntest_input = { \"n\": 14, \"target\": 7 }\nassert my_solution.minimumPossibleSum(**test_input) == 138\n\ntest_input = { \"n\": 18, \"target\": 26 }\nassert my_solution.minimumPossibleSum(**test_input) == 231\n\ntest_input = { \"n\": 11, \"target\": 15 }\nassert my_solution.minimumPossibleSum(**test_input) == 94\n\ntest_input = { \"n\": 7, \"target\": 8 }\nassert my_solution.minimumPossibleSum(**test_input) == 37\n\ntest_input = { \"n\": 11, \"target\": 22 }\nassert my_solution.minimumPossibleSum(**test_input) == 66\n\ntest_input = { \"n\": 36, \"target\": 11 }\nassert my_solution.minimumPossibleSum(**test_input) == 821\n\ntest_input = { \"n\": 18, \"target\": 29 }\nassert my_solution.minimumPossibleSum(**test_input) == 227\n\ntest_input = { \"n\": 26, \"target\": 17 }\nassert my_solution.minimumPossibleSum(**test_input) == 495\n\ntest_input = { \"n\": 37, \"target\": 13 }\nassert my_solution.minimumPossibleSum(**test_input) == 889\n\ntest_input = { \"n\": 46, \"target\": 38 }\nassert my_solution.minimumPossibleSum(**test_input) == 1567\n\ntest_input = { \"n\": 13, \"target\": 7 }\nassert my_solution.minimumPossibleSum(**test_input) == 121\n\ntest_input = { \"n\": 33, \"target\": 34 }\nassert my_solution.minimumPossibleSum(**test_input) == 817\n\ntest_input = { \"n\": 39, \"target\": 12 }\nassert my_solution.minimumPossibleSum(**test_input) == 945\n\ntest_input = { \"n\": 1, \"target\": 45 }\nassert my_solution.minimumPossibleSum(**test_input) == 1\n\ntest_input = { \"n\": 37, \"target\": 36 }\nassert my_solution.minimumPossibleSum(**test_input) == 1026\n\ntest_input = { \"n\": 16, \"target\": 19 }\nassert my_solution.minimumPossibleSum(**test_input) == 199\n\ntest_input = { \"n\": 22, \"target\": 15 }\nassert my_solution.minimumPossibleSum(**test_input) == 358\n\ntest_input = { \"n\": 34, \"target\": 42 }\nassert my_solution.minimumPossibleSum(**test_input) == 855\n\ntest_input = { \"n\": 50, \"target\": 22 }\nassert my_solution.minimumPossibleSum(**test_input) == 1665\n\ntest_input = { \"n\": 42, \"target\": 44 }\nassert my_solution.minimumPossibleSum(**test_input) == 1323\n\ntest_input = { \"n\": 40, \"target\": 8 }\nassert my_solution.minimumPossibleSum(**test_input) == 928\n\ntest_input = { \"n\": 7, \"target\": 19 }\nassert my_solution.minimumPossibleSum(**test_input) == 28\n\ntest_input = { \"n\": 44, \"target\": 10 }\nassert my_solution.minimumPossibleSum(**test_input) == 1146\n\ntest_input = { \"n\": 21, \"target\": 6 }\nassert my_solution.minimumPossibleSum(**test_input) == 267\n\ntest_input = { \"n\": 27, \"target\": 26 }\nassert my_solution.minimumPossibleSum(**test_input) == 546\n\ntest_input = { \"n\": 49, \"target\": 4 }\nassert my_solution.minimumPossibleSum(**test_input) == 1272\n\ntest_input = { \"n\": 35, \"target\": 2 }\nassert my_solution.minimumPossibleSum(**test_input) == 630\n\ntest_input = { \"n\": 32, \"target\": 29 }\nassert my_solution.minimumPossibleSum(**test_input) == 780\n\ntest_input = { \"n\": 20, \"target\": 41 }\nassert my_solution.minimumPossibleSum(**test_input) == 210\n\ntest_input = { \"n\": 30, \"target\": 48 }\nassert my_solution.minimumPossibleSum(**test_input) == 603\n\ntest_input = { \"n\": 12, \"target\": 34 }\nassert my_solution.minimumPossibleSum(**test_input) == 78\n\ntest_input = { \"n\": 50, \"target\": 44 }\nassert my_solution.minimumPossibleSum(**test_input) == 1863\n\ntest_input = { \"n\": 42, \"target\": 26 }\nassert my_solution.minimumPossibleSum(**test_input) == 1251\n\ntest_input = { \"n\": 3, \"target\": 18 }\nassert my_solution.minimumPossibleSum(**test_input) == 6\n\ntest_input = { \"n\": 11, \"target\": 3 }\nassert my_solution.minimumPossibleSum(**test_input) == 76\n\ntest_input = { \"n\": 38, \"target\": 29 }\nassert my_solution.minimumPossibleSum(**test_input) == 1077\n\ntest_input = { \"n\": 17, \"target\": 24 }\nassert my_solution.minimumPossibleSum(**test_input) == 208\n\ntest_input = { \"n\": 50, \"target\": 31 }\nassert my_solution.minimumPossibleSum(**test_input) == 1800\n\ntest_input = { \"n\": 32, \"target\": 41 }\nassert my_solution.minimumPossibleSum(**test_input) == 768\n\ntest_input = { \"n\": 12, \"target\": 24 }\nassert my_solution.minimumPossibleSum(**test_input) == 78\n\ntest_input = { \"n\": 35, \"target\": 43 }\nassert my_solution.minimumPossibleSum(**test_input) == 924\n\ntest_input = { \"n\": 9, \"target\": 47 }\nassert my_solution.minimumPossibleSum(**test_input) == 45\n\ntest_input = { \"n\": 32, \"target\": 26 }\nassert my_solution.minimumPossibleSum(**test_input) == 756\n\ntest_input = { \"n\": 6, \"target\": 42 }\nassert my_solution.minimumPossibleSum(**test_input) == 21\n\ntest_input = { \"n\": 11, \"target\": 1 }\nassert my_solution.minimumPossibleSum(**test_input) == 66\n\ntest_input = { \"n\": 11, \"target\": 24 }\nassert my_solution.minimumPossibleSum(**test_input) == 66\n\ntest_input = { \"n\": 39, \"target\": 38 }\nassert my_solution.minimumPossibleSum(**test_input) == 1140\n\ntest_input = { \"n\": 18, \"target\": 8 }\nassert my_solution.minimumPossibleSum(**test_input) == 213\n\ntest_input = { \"n\": 29, \"target\": 5 }\nassert my_solution.minimumPossibleSum(**test_input) == 489\n\ntest_input = { \"n\": 44, \"target\": 6 }\nassert my_solution.minimumPossibleSum(**test_input) == 1072\n\ntest_input = { \"n\": 29, \"target\": 30 }\nassert my_solution.minimumPossibleSum(**test_input) == 631\n\ntest_input = { \"n\": 13, \"target\": 47 }\nassert my_solution.minimumPossibleSum(**test_input) == 91\n\ntest_input = { \"n\": 46, \"target\": 21 }\nassert my_solution.minimumPossibleSum(**test_input) == 1441\n\ntest_input = { \"n\": 46, \"target\": 6 }\nassert my_solution.minimumPossibleSum(**test_input) == 1167\n\ntest_input = { \"n\": 27, \"target\": 30 }\nassert my_solution.minimumPossibleSum(**test_input) == 546\n\ntest_input = { \"n\": 5, \"target\": 35 }\nassert my_solution.minimumPossibleSum(**test_input) == 15\n\ntest_input = { \"n\": 12, \"target\": 32 }\nassert my_solution.minimumPossibleSum(**test_input) == 78\n\ntest_input = { \"n\": 13, \"target\": 39 }\nassert my_solution.minimumPossibleSum(**test_input) == 91\n\ntest_input = { \"n\": 10, \"target\": 11 }\nassert my_solution.minimumPossibleSum(**test_input) == 80\n\ntest_input = { \"n\": 46, \"target\": 14 }\nassert my_solution.minimumPossibleSum(**test_input) == 1315\n\ntest_input = { \"n\": 37, \"target\": 18 }\nassert my_solution.minimumPossibleSum(**test_input) == 927\n\ntest_input = { \"n\": 32, \"target\": 8 }\nassert my_solution.minimumPossibleSum(**test_input) == 612\n\ntest_input = { \"n\": 26, \"target\": 14 }\nassert my_solution.minimumPossibleSum(**test_input) == 465\n\ntest_input = { \"n\": 33, \"target\": 41 }\nassert my_solution.minimumPossibleSum(**test_input) == 821\n\ntest_input = { \"n\": 44, \"target\": 39 }\nassert my_solution.minimumPossibleSum(**test_input) == 1465\n\ntest_input = { \"n\": 3, \"target\": 21 }\nassert my_solution.minimumPossibleSum(**test_input) == 6\n\ntest_input = { \"n\": 9, \"target\": 11 }\nassert my_solution.minimumPossibleSum(**test_input) == 65\n\ntest_input = { \"n\": 16, \"target\": 43 }\nassert my_solution.minimumPossibleSum(**test_input) == 136\n\ntest_input = { \"n\": 7, \"target\": 22 }\nassert my_solution.minimumPossibleSum(**test_input) == 28\n\ntest_input = { \"n\": 21, \"target\": 49 }\nassert my_solution.minimumPossibleSum(**test_input) == 231\n\ntest_input = { \"n\": 23, \"target\": 16 }\nassert my_solution.minimumPossibleSum(**test_input) == 381\n\ntest_input = { \"n\": 33, \"target\": 32 }\nassert my_solution.minimumPossibleSum(**test_input) == 816\n\ntest_input = { \"n\": 22, \"target\": 1 }\nassert my_solution.minimumPossibleSum(**test_input) == 253\n\ntest_input = { \"n\": 5, \"target\": 47 }\nassert my_solution.minimumPossibleSum(**test_input) == 15\n\ntest_input = { \"n\": 38, \"target\": 7 }\nassert my_solution.minimumPossibleSum(**test_input) == 846\n\ntest_input = { \"n\": 38, \"target\": 24 }\nassert my_solution.minimumPossibleSum(**test_input) == 1027\n\ntest_input = { \"n\": 13, \"target\": 36 }\nassert my_solution.minimumPossibleSum(**test_input) == 91", "start_time": 1693103400} +{"task_id": "weekly-contest-360-minimum-operations-to-form-subsequence-with-target-sum", "url": "https://leetcode.com/problems/minimum-operations-to-form-subsequence-with-target-sum", "title": "minimum-operations-to-form-subsequence-with-target-sum", "meta": {"questionId": "3025", "questionFrontendId": "2835", "title": "Minimum Operations to Form Subsequence With Target Sum", "titleSlug": "minimum-operations-to-form-subsequence-with-target-sum", "isPaidOnly": false, "difficulty": "Hard", "likes": 503, "dislikes": 125, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0 开始的数组 nums ,它包含 非负 整数,且全部为 2 的幂,同时给你一个整数 target 。\n\n一次操作中,你必须对数组做以下修改:\n\n * 选择数组中一个元素 nums[i] ,满足 nums[i] > 1 。\n * 将 nums[i] 从数组中删除。\n * 在 nums 的 末尾 添加 两个 数,值都为 nums[i] / 2 。\n\n你的目标是让 nums 的一个 子序列 的元素和等于 target ,请你返回达成这一目标的 最少操作次数 。如果无法得到这样的子序列,请你返回 -1 。\n\n数组中一个 子序列 是通过删除原数组中一些元素,并且不改变剩余元素顺序得到的剩余数组。\n\n示例 1:\n\n输入:nums = [1,2,8], target = 7\n输出:1\n解释:第一次操作中,我们选择元素 nums[2] 。数组变为 nums = [1,2,4,4] 。\n这时候,nums 包含子序列 [1,2,4] ,和为 7 。\n无法通过更少的操作得到和为 7 的子序列。\n\n示例 2:\n\n输入:nums = [1,32,1,2], target = 12\n输出:2\n解释:第一次操作中,我们选择元素 nums[1] 。数组变为 nums = [1,1,2,16,16] 。\n第二次操作中,我们选择元素 nums[3] 。数组变为 nums = [1,1,2,16,8,8] 。\n这时候,nums 包含子序列 [1,1,2,8] ,和为 12 。\n无法通过更少的操作得到和为 12 的子序列。\n\n示例 3:\n\n输入:nums = [1,32,1], target = 35\n输出:-1\n解释:无法得到和为 35 的子序列。\n\n\n提示:\n\n * 1 <= nums.length <= 1000\n * 1 <= nums[i] <= 230\n * nums 只包含非负整数,且均为 2 的幂。\n * 1 <= target < 231\n\"\"\"\nclass Solution:\n def minOperations(self, nums: List[int], target: int) -> int:\n ", "prompt_sft": "给你一个下标从 0 开始的数组 nums ,它包含 非负 整数,且全部为 2 的幂,同时给你一个整数 target 。\n\n一次操作中,你必须对数组做以下修改:\n\n * 选择数组中一个元素 nums[i] ,满足 nums[i] > 1 。\n * 将 nums[i] 从数组中删除。\n * 在 nums 的 末尾 添加 两个 数,值都为 nums[i] / 2 。\n\n你的目标是让 nums 的一个 子序列 的元素和等于 target ,请你返回达成这一目标的 最少操作次数 。如果无法得到这样的子序列,请你返回 -1 。\n\n数组中一个 子序列 是通过删除原数组中一些元素,并且不改变剩余元素顺序得到的剩余数组。\n\n示例 1:\n\n输入:nums = [1,2,8], target = 7\n输出:1\n解释:第一次操作中,我们选择元素 nums[2] 。数组变为 nums = [1,2,4,4] 。\n这时候,nums 包含子序列 [1,2,4] ,和为 7 。\n无法通过更少的操作得到和为 7 的子序列。\n\n示例 2:\n\n输入:nums = [1,32,1,2], target = 12\n输出:2\n解释:第一次操作中,我们选择元素 nums[1] 。数组变为 nums = [1,1,2,16,16] 。\n第二次操作中,我们选择元素 nums[3] 。数组变为 nums = [1,1,2,16,8,8] 。\n这时候,nums 包含子序列 [1,1,2,8] ,和为 12 。\n无法通过更少的操作得到和为 12 的子序列。\n\n示例 3:\n\n输入:nums = [1,32,1], target = 35\n输出:-1\n解释:无法得到和为 35 的子序列。\n\n\n提示:\n\n * 1 <= nums.length <= 1000\n * 1 <= nums[i] <= 230\n * nums 只包含非负整数,且均为 2 的幂。\n * 1 <= target < 231\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def minOperations(self, nums: List[int], target: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,2,8], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,32,1,2], \"target\": 12 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,32,1], \"target\": 35 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [1], \"target\": 1 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [16,128,32], \"target\": 1 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [1,1], \"target\": 2 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [64,128,128], \"target\": 2 }\nassert my_solution.minOperations(**test_input) == 5\n\ntest_input = { \"nums\": [2], \"target\": 2 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [32,256,4], \"target\": 2 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,1], \"target\": 3 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [1,256,16,128], \"target\": 3 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,2], \"target\": 3 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [16,16,4], \"target\": 3 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,1,1], \"target\": 4 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [128,1,128,1,64], \"target\": 4 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [2,1,1], \"target\": 4 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [8,2,64,32], \"target\": 4 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [16,128,8,1,1], \"target\": 4 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,1], \"target\": 4 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [128,8,8,2], \"target\": 4 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [2,2], \"target\": 4 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [128,32,16], \"target\": 4 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [4], \"target\": 4 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [128,32,256], \"target\": 4 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,1,1,1], \"target\": 5 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,128,256,1,16], \"target\": 5 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [2,1,1,1], \"target\": 5 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [32,1,8,1,64], \"target\": 5 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [128,256,32,1,1,1], \"target\": 5 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,2,1], \"target\": 5 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [16,16,1,1,128], \"target\": 5 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [2,2,1], \"target\": 5 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [64,32,2,8], \"target\": 5 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,4], \"target\": 5 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [8,64,128], \"target\": 5 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,1,1,1,1], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [128,1,256,1,1,1,32], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,1,1,2], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [1,256,1,1,8,64], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,128,1,128,1,8,1], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,1,2,1], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [64,1,16,1,1,64], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [2,1,2,1], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [2,1,8,64,64], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [4,1,1], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [16,64,4,128], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,1,8,128,1,8], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,1,1,1], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [64,128,1,32,1,2], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,1,256,1,8,64], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,128,1,256,32,1], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,1,2], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [256,2,32,32,1], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,16,1,1,1,16,256], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,2,1,1], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,64,8,16,1], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,16,128,1,1,32,1], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [128,1,1,1,64,32], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [64,16,16,1,1], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [32,1,1,32,1,64,1], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [8,64,2,1,1,8], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,256,1,64,1,128], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [1,1,64,64,32,2], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [2,32,128,1,64], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [2,2,2], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [64,8,2,128], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [4,2], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [8,8,16], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,1,1,1,1,1], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,1,1,128,1,64,8], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [2,1,1,1,1,1], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [1,2,64,32,16,1,1], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,1,16,128,256,1,1], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,1,2,1,1], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [2,8,8,1,128,1,1], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,1,1,2], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [32,1,2,1,256,128], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,1,4], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [1,8,256,32,1], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [64,1,1,1,16,1,64,1], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,1,1,2,1], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [1,256,1,8,1,2,16], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [32,1,1,1,32,32,1,1], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,1,1,1,1], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [64,1,32,256,1,1,1], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [2,1,2,1,1], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [2,32,32,32,2,1], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,8,1,1,64,1,128], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,1,1,1,2], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [64,128,2,128,1,1,1], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [1,1,1,128,8,32,1,1], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [64,256,1,1,1,32,2], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,2,1,1], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [1,256,64,2,1,128], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [256,1,1,1,64,1,1,64], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [2,1,8,256,1,128,1], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,16,1,1,256,1,128], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,8,128,1,1,1,256], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [2,2,1,1,1], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [64,2,64,1,32,1], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 3", "start_time": 1693103400} +{"task_id": "weekly-contest-360-maximize-value-of-function-in-a-ball-passing-game", "url": "https://leetcode.com/problems/maximize-value-of-function-in-a-ball-passing-game", "title": "maximize-value-of-function-in-a-ball-passing-game", "meta": {"questionId": "3032", "questionFrontendId": "2836", "title": "Maximize Value of Function in a Ball Passing Game", "titleSlug": "maximize-value-of-function-in-a-ball-passing-game", "isPaidOnly": false, "difficulty": "Hard", "likes": 202, "dislikes": 85, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个长度为 n 下标从 0 开始的整数数组 receiver 和一个整数 k 。\n\n总共有 n 名玩家,玩家 编号 互不相同,且为 [0, n - 1] 中的整数。这些玩家玩一个传球游戏,receiver[i] 表示编号为 i 的玩家会传球给编号为 receiver[i] 的玩家。玩家可以传球给自己,也就是说 receiver[i] 可能等于 i 。\n\n你需要从 n 名玩家中选择一名玩家作为游戏开始时唯一手中有球的玩家,球会被传 恰好 k 次。\n\n如果选择编号为 x 的玩家作为开始玩家,定义函数 f(x) 表示从编号为 x 的玩家开始,k 次传球内所有接触过球玩家的编号之 和 ,如果有玩家多次触球,则 累加多次 。换句话说, f(x) = x + receiver[x] + receiver[receiver[x]] + ... + receiver(k)[x] 。\n\n你的任务时选择开始玩家 x ,目的是 最大化 f(x) 。\n\n请你返回函数的 最大值 。\n\n注意:receiver 可能含有重复元素。\n\n示例 1:\n\n传递次数 传球者编号 接球者编号 x + 所有接球者编号       2 1 2 1 3 2 1 0 3 3 0 2 5 4 2 1 6\n\n\n输入:receiver = [2,0,1], k = 4\n输出:6\n解释:上表展示了从编号为 x = 2 开始的游戏过程。\n从表中可知,f(2) 等于 6 。\n6 是能得到最大的函数值。\n所以输出为 6 。\n\n示例 2:\n\n传递次数 传球者编号 接球者编号 x + 所有接球者编号       4 1 4 3 7 2 3 2 9 3 2 1 10\n\n\n输入:receiver = [1,1,1,2,3], k = 3\n输出:10\n解释:上表展示了从编号为 x = 4 开始的游戏过程。\n从表中可知,f(4) 等于 10 。\n10 是能得到最大的函数值。\n所以输出为 10 。\n\n\n提示:\n\n * 1 <= receiver.length == n <= 105\n * 0 <= receiver[i] <= n - 1\n * 1 <= k <= 1010\n\"\"\"\nclass Solution:\n def getMaxFunctionValue(self, receiver: List[int], k: int) -> int:\n ", "prompt_sft": "给你一个长度为 n 下标从 0 开始的整数数组 receiver 和一个整数 k 。\n\n总共有 n 名玩家,玩家 编号 互不相同,且为 [0, n - 1] 中的整数。这些玩家玩一个传球游戏,receiver[i] 表示编号为 i 的玩家会传球给编号为 receiver[i] 的玩家。玩家可以传球给自己,也就是说 receiver[i] 可能等于 i 。\n\n你需要从 n 名玩家中选择一名玩家作为游戏开始时唯一手中有球的玩家,球会被传 恰好 k 次。\n\n如果选择编号为 x 的玩家作为开始玩家,定义函数 f(x) 表示从编号为 x 的玩家开始,k 次传球内所有接触过球玩家的编号之 和 ,如果有玩家多次触球,则 累加多次 。换句话说, f(x) = x + receiver[x] + receiver[receiver[x]] + ... + receiver(k)[x] 。\n\n你的任务时选择开始玩家 x ,目的是 最大化 f(x) 。\n\n请你返回函数的 最大值 。\n\n注意:receiver 可能含有重复元素。\n\n示例 1:\n\n传递次数 传球者编号 接球者编号 x + 所有接球者编号       2 1 2 1 3 2 1 0 3 3 0 2 5 4 2 1 6\n\n\n输入:receiver = [2,0,1], k = 4\n输出:6\n解释:上表展示了从编号为 x = 2 开始的游戏过程。\n从表中可知,f(2) 等于 6 。\n6 是能得到最大的函数值。\n所以输出为 6 。\n\n示例 2:\n\n传递次数 传球者编号 接球者编号 x + 所有接球者编号       4 1 4 3 7 2 3 2 9 3 2 1 10\n\n\n输入:receiver = [1,1,1,2,3], k = 3\n输出:10\n解释:上表展示了从编号为 x = 4 开始的游戏过程。\n从表中可知,f(4) 等于 10 。\n10 是能得到最大的函数值。\n所以输出为 10 。\n\n\n提示:\n\n * 1 <= receiver.length == n <= 105\n * 0 <= receiver[i] <= n - 1\n * 1 <= k <= 1010\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def getMaxFunctionValue(self, receiver: List[int], k: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"receiver\": [2,0,1], \"k\": 4 }\nassert my_solution.getMaxFunctionValue(**test_input) == 6\n\ntest_input = { \"receiver\": [1,1,1,2,3], \"k\": 3 }\nassert my_solution.getMaxFunctionValue(**test_input) == 10\n\ntest_input = { \"receiver\": [0], \"k\": 1 }\nassert my_solution.getMaxFunctionValue(**test_input) == 0\n\ntest_input = { \"receiver\": [0], \"k\": 2 }\nassert my_solution.getMaxFunctionValue(**test_input) == 0\n\ntest_input = { \"receiver\": [0], \"k\": 3 }\nassert my_solution.getMaxFunctionValue(**test_input) == 0\n\ntest_input = { \"receiver\": [0], \"k\": 100 }\nassert my_solution.getMaxFunctionValue(**test_input) == 0\n\ntest_input = { \"receiver\": [0,0], \"k\": 1 }\nassert my_solution.getMaxFunctionValue(**test_input) == 1\n\ntest_input = { \"receiver\": [0,0], \"k\": 7 }\nassert my_solution.getMaxFunctionValue(**test_input) == 1\n\ntest_input = { \"receiver\": [0,0], \"k\": 10 }\nassert my_solution.getMaxFunctionValue(**test_input) == 1\n\ntest_input = { \"receiver\": [0,0], \"k\": 13 }\nassert my_solution.getMaxFunctionValue(**test_input) == 1\n\ntest_input = { \"receiver\": [0,0], \"k\": 16 }\nassert my_solution.getMaxFunctionValue(**test_input) == 1\n\ntest_input = { \"receiver\": [0,1], \"k\": 1 }\nassert my_solution.getMaxFunctionValue(**test_input) == 2\n\ntest_input = { \"receiver\": [0,1], \"k\": 3 }\nassert my_solution.getMaxFunctionValue(**test_input) == 4\n\ntest_input = { \"receiver\": [0,1], \"k\": 5 }\nassert my_solution.getMaxFunctionValue(**test_input) == 6\n\ntest_input = { \"receiver\": [0,1], \"k\": 8 }\nassert my_solution.getMaxFunctionValue(**test_input) == 9\n\ntest_input = { \"receiver\": [0,1], \"k\": 13 }\nassert my_solution.getMaxFunctionValue(**test_input) == 14\n\ntest_input = { \"receiver\": [0,1], \"k\": 14 }\nassert my_solution.getMaxFunctionValue(**test_input) == 15\n\ntest_input = { \"receiver\": [0,1], \"k\": 15 }\nassert my_solution.getMaxFunctionValue(**test_input) == 16\n\ntest_input = { \"receiver\": [1,0], \"k\": 5 }\nassert my_solution.getMaxFunctionValue(**test_input) == 3\n\ntest_input = { \"receiver\": [1,0], \"k\": 6 }\nassert my_solution.getMaxFunctionValue(**test_input) == 4\n\ntest_input = { \"receiver\": [1,0], \"k\": 7 }\nassert my_solution.getMaxFunctionValue(**test_input) == 4\n\ntest_input = { \"receiver\": [1,0], \"k\": 10 }\nassert my_solution.getMaxFunctionValue(**test_input) == 6\n\ntest_input = { \"receiver\": [1,0], \"k\": 12 }\nassert my_solution.getMaxFunctionValue(**test_input) == 7\n\ntest_input = { \"receiver\": [1,0], \"k\": 14 }\nassert my_solution.getMaxFunctionValue(**test_input) == 8\n\ntest_input = { \"receiver\": [1,0], \"k\": 57 }\nassert my_solution.getMaxFunctionValue(**test_input) == 29\n\ntest_input = { \"receiver\": [1,1], \"k\": 1 }\nassert my_solution.getMaxFunctionValue(**test_input) == 2\n\ntest_input = { \"receiver\": [1,1], \"k\": 2 }\nassert my_solution.getMaxFunctionValue(**test_input) == 3\n\ntest_input = { \"receiver\": [1,1], \"k\": 7 }\nassert my_solution.getMaxFunctionValue(**test_input) == 8\n\ntest_input = { \"receiver\": [0,0,0], \"k\": 1 }\nassert my_solution.getMaxFunctionValue(**test_input) == 2\n\ntest_input = { \"receiver\": [0,0,0], \"k\": 4 }\nassert my_solution.getMaxFunctionValue(**test_input) == 2\n\ntest_input = { \"receiver\": [0,0,0], \"k\": 6 }\nassert my_solution.getMaxFunctionValue(**test_input) == 2\n\ntest_input = { \"receiver\": [0,0,0], \"k\": 10 }\nassert my_solution.getMaxFunctionValue(**test_input) == 2\n\ntest_input = { \"receiver\": [0,0,1], \"k\": 3 }\nassert my_solution.getMaxFunctionValue(**test_input) == 3\n\ntest_input = { \"receiver\": [0,0,1], \"k\": 9 }\nassert my_solution.getMaxFunctionValue(**test_input) == 3\n\ntest_input = { \"receiver\": [0,0,2], \"k\": 11 }\nassert my_solution.getMaxFunctionValue(**test_input) == 24\n\ntest_input = { \"receiver\": [0,0,2], \"k\": 14 }\nassert my_solution.getMaxFunctionValue(**test_input) == 30\n\ntest_input = { \"receiver\": [0,0,2], \"k\": 82 }\nassert my_solution.getMaxFunctionValue(**test_input) == 166\n\ntest_input = { \"receiver\": [0,1,0], \"k\": 5 }\nassert my_solution.getMaxFunctionValue(**test_input) == 6\n\ntest_input = { \"receiver\": [0,1,1], \"k\": 2 }\nassert my_solution.getMaxFunctionValue(**test_input) == 4\n\ntest_input = { \"receiver\": [0,1,2], \"k\": 3 }\nassert my_solution.getMaxFunctionValue(**test_input) == 8\n\ntest_input = { \"receiver\": [0,1,2], \"k\": 6 }\nassert my_solution.getMaxFunctionValue(**test_input) == 14\n\ntest_input = { \"receiver\": [1,0,0], \"k\": 6 }\nassert my_solution.getMaxFunctionValue(**test_input) == 5\n\ntest_input = { \"receiver\": [1,0,1], \"k\": 2 }\nassert my_solution.getMaxFunctionValue(**test_input) == 3\n\ntest_input = { \"receiver\": [1,0,2], \"k\": 10 }\nassert my_solution.getMaxFunctionValue(**test_input) == 22\n\ntest_input = { \"receiver\": [1,1,1], \"k\": 4 }\nassert my_solution.getMaxFunctionValue(**test_input) == 6\n\ntest_input = { \"receiver\": [1,1,1], \"k\": 6 }\nassert my_solution.getMaxFunctionValue(**test_input) == 8\n\ntest_input = { \"receiver\": [1,1,2], \"k\": 8 }\nassert my_solution.getMaxFunctionValue(**test_input) == 18\n\ntest_input = { \"receiver\": [1,2,0], \"k\": 3 }\nassert my_solution.getMaxFunctionValue(**test_input) == 5\n\ntest_input = { \"receiver\": [1,2,0], \"k\": 8 }\nassert my_solution.getMaxFunctionValue(**test_input) == 9\n\ntest_input = { \"receiver\": [1,2,1], \"k\": 6 }\nassert my_solution.getMaxFunctionValue(**test_input) == 11\n\ntest_input = { \"receiver\": [1,2,2], \"k\": 7 }\nassert my_solution.getMaxFunctionValue(**test_input) == 16\n\ntest_input = { \"receiver\": [2,0,2], \"k\": 6 }\nassert my_solution.getMaxFunctionValue(**test_input) == 14\n\ntest_input = { \"receiver\": [2,1,0], \"k\": 3 }\nassert my_solution.getMaxFunctionValue(**test_input) == 4\n\ntest_input = { \"receiver\": [2,1,0], \"k\": 8 }\nassert my_solution.getMaxFunctionValue(**test_input) == 10\n\ntest_input = { \"receiver\": [2,1,0], \"k\": 10 }\nassert my_solution.getMaxFunctionValue(**test_input) == 12\n\ntest_input = { \"receiver\": [2,1,1], \"k\": 4 }\nassert my_solution.getMaxFunctionValue(**test_input) == 6\n\ntest_input = { \"receiver\": [2,1,2], \"k\": 2 }\nassert my_solution.getMaxFunctionValue(**test_input) == 6\n\ntest_input = { \"receiver\": [2,1,2], \"k\": 15 }\nassert my_solution.getMaxFunctionValue(**test_input) == 32\n\ntest_input = { \"receiver\": [2,2,0], \"k\": 4 }\nassert my_solution.getMaxFunctionValue(**test_input) == 6\n\ntest_input = { \"receiver\": [2,2,0], \"k\": 9 }\nassert my_solution.getMaxFunctionValue(**test_input) == 11\n\ntest_input = { \"receiver\": [2,2,1], \"k\": 1 }\nassert my_solution.getMaxFunctionValue(**test_input) == 3\n\ntest_input = { \"receiver\": [2,2,1], \"k\": 10 }\nassert my_solution.getMaxFunctionValue(**test_input) == 17\n\ntest_input = { \"receiver\": [2,2,2], \"k\": 15 }\nassert my_solution.getMaxFunctionValue(**test_input) == 32\n\ntest_input = { \"receiver\": [0,0,3,0], \"k\": 4 }\nassert my_solution.getMaxFunctionValue(**test_input) == 5\n\ntest_input = { \"receiver\": [0,1,0,1], \"k\": 11 }\nassert my_solution.getMaxFunctionValue(**test_input) == 14\n\ntest_input = { \"receiver\": [0,1,1,3], \"k\": 5 }\nassert my_solution.getMaxFunctionValue(**test_input) == 18\n\ntest_input = { \"receiver\": [0,2,1,3], \"k\": 5 }\nassert my_solution.getMaxFunctionValue(**test_input) == 18\n\ntest_input = { \"receiver\": [0,2,3,1], \"k\": 6 }\nassert my_solution.getMaxFunctionValue(**test_input) == 15\n\ntest_input = { \"receiver\": [0,2,3,3], \"k\": 8 }\nassert my_solution.getMaxFunctionValue(**test_input) == 27\n\ntest_input = { \"receiver\": [0,2,3,3], \"k\": 15 }\nassert my_solution.getMaxFunctionValue(**test_input) == 48\n\ntest_input = { \"receiver\": [0,3,3,0], \"k\": 10 }\nassert my_solution.getMaxFunctionValue(**test_input) == 5\n\ntest_input = { \"receiver\": [1,0,0,2], \"k\": 9 }\nassert my_solution.getMaxFunctionValue(**test_input) == 9\n\ntest_input = { \"receiver\": [1,0,1,2], \"k\": 15 }\nassert my_solution.getMaxFunctionValue(**test_input) == 12\n\ntest_input = { \"receiver\": [1,0,3,1], \"k\": 6 }\nassert my_solution.getMaxFunctionValue(**test_input) == 8\n\ntest_input = { \"receiver\": [1,0,3,2], \"k\": 2 }\nassert my_solution.getMaxFunctionValue(**test_input) == 8\n\ntest_input = { \"receiver\": [1,1,0,0], \"k\": 2 }\nassert my_solution.getMaxFunctionValue(**test_input) == 4\n\ntest_input = { \"receiver\": [1,1,0,3], \"k\": 3 }\nassert my_solution.getMaxFunctionValue(**test_input) == 12\n\ntest_input = { \"receiver\": [1,1,1,3], \"k\": 7 }\nassert my_solution.getMaxFunctionValue(**test_input) == 24\n\ntest_input = { \"receiver\": [1,2,0,0], \"k\": 14 }\nassert my_solution.getMaxFunctionValue(**test_input) == 16\n\ntest_input = { \"receiver\": [1,2,0,1], \"k\": 5 }\nassert my_solution.getMaxFunctionValue(**test_input) == 9\n\ntest_input = { \"receiver\": [1,2,3,1], \"k\": 47 }\nassert my_solution.getMaxFunctionValue(**test_input) == 96\n\ntest_input = { \"receiver\": [1,3,0,1], \"k\": 2 }\nassert my_solution.getMaxFunctionValue(**test_input) == 7\n\ntest_input = { \"receiver\": [1,3,3,0], \"k\": 7 }\nassert my_solution.getMaxFunctionValue(**test_input) == 13\n\ntest_input = { \"receiver\": [2,0,0,1], \"k\": 9 }\nassert my_solution.getMaxFunctionValue(**test_input) == 12\n\ntest_input = { \"receiver\": [2,0,0,2], \"k\": 12 }\nassert my_solution.getMaxFunctionValue(**test_input) == 15\n\ntest_input = { \"receiver\": [2,0,2,0], \"k\": 5 }\nassert my_solution.getMaxFunctionValue(**test_input) == 12\n\ntest_input = { \"receiver\": [2,1,0,0], \"k\": 8 }\nassert my_solution.getMaxFunctionValue(**test_input) == 11\n\ntest_input = { \"receiver\": [2,1,0,1], \"k\": 97 }\nassert my_solution.getMaxFunctionValue(**test_input) == 100\n\ntest_input = { \"receiver\": [2,2,2,0], \"k\": 1 }\nassert my_solution.getMaxFunctionValue(**test_input) == 4\n\ntest_input = { \"receiver\": [2,2,3,2], \"k\": 8 }\nassert my_solution.getMaxFunctionValue(**test_input) == 23\n\ntest_input = { \"receiver\": [2,3,2,1], \"k\": 56 }\nassert my_solution.getMaxFunctionValue(**test_input) == 115\n\ntest_input = { \"receiver\": [2,3,3,1], \"k\": 15 }\nassert my_solution.getMaxFunctionValue(**test_input) == 33\n\ntest_input = { \"receiver\": [2,3,3,3], \"k\": 2 }\nassert my_solution.getMaxFunctionValue(**test_input) == 9\n\ntest_input = { \"receiver\": [3,0,0,1], \"k\": 4 }\nassert my_solution.getMaxFunctionValue(**test_input) == 8\n\ntest_input = { \"receiver\": [3,0,0,2], \"k\": 85 }\nassert my_solution.getMaxFunctionValue(**test_input) == 145\n\ntest_input = { \"receiver\": [3,0,1,3], \"k\": 9 }\nassert my_solution.getMaxFunctionValue(**test_input) == 30\n\ntest_input = { \"receiver\": [3,1,1,2], \"k\": 7 }\nassert my_solution.getMaxFunctionValue(**test_input) == 11\n\ntest_input = { \"receiver\": [3,1,2,0], \"k\": 60 }\nassert my_solution.getMaxFunctionValue(**test_input) == 122\n\ntest_input = { \"receiver\": [3,2,0,3], \"k\": 12 }\nassert my_solution.getMaxFunctionValue(**test_input) == 39\n\ntest_input = { \"receiver\": [3,3,0,1], \"k\": 1 }\nassert my_solution.getMaxFunctionValue(**test_input) == 4", "start_time": 1693103400} +{"task_id": "weekly-contest-359-check-if-a-string-is-an-acronym-of-words", "url": "https://leetcode.com/problems/check-if-a-string-is-an-acronym-of-words", "title": "check-if-a-string-is-an-acronym-of-words", "meta": {"questionId": "2977", "questionFrontendId": "2828", "title": "Check if a String Is an Acronym of Words", "titleSlug": "check-if-a-string-is-an-acronym-of-words", "isPaidOnly": false, "difficulty": "Easy", "likes": 257, "dislikes": 7, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个字符串数组 words 和一个字符串 s ,请你判断 s 是不是 words 的 首字母缩略词 。\n\n如果可以按顺序串联 words 中每个字符串的第一个字符形成字符串 s ,则认为 s 是 words 的首字母缩略词。例如,\"ab\" 可以由 [\"apple\", \"banana\"] 形成,但是无法从 [\"bear\", \"aardvark\"] 形成。\n\n如果 s 是 words 的首字母缩略词,返回 true ;否则,返回 false 。\n\n示例 1:\n\n输入:words = [\"alice\",\"bob\",\"charlie\"], s = \"abc\"\n输出:true\n解释:words 中 \"alice\"、\"bob\" 和 \"charlie\" 的第一个字符分别是 'a'、'b' 和 'c'。因此,s = \"abc\" 是首字母缩略词。\n\n示例 2:\n\n输入:words = [\"an\",\"apple\"], s = \"a\"\n输出:false\n解释:words 中 \"an\" 和 \"apple\" 的第一个字符分别是 'a' 和 'a'。\n串联这些字符形成的首字母缩略词是 \"aa\" 。\n因此,s = \"a\" 不是首字母缩略词。\n\n示例 3:\n\n输入:words = [\"never\",\"gonna\",\"give\",\"up\",\"on\",\"you\"], s = \"ngguoy\"\n输出:true\n解释:串联数组 words 中每个字符串的第一个字符,得到字符串 \"ngguoy\" 。\n因此,s = \"ngguoy\" 是首字母缩略词。\n\n\n提示:\n\n * 1 <= words.length <= 100\n * 1 <= words[i].length <= 10\n * 1 <= s.length <= 100\n * words[i] 和 s 由小写英文字母组成\n\"\"\"\nclass Solution:\n def isAcronym(self, words: List[str], s: str) -> bool:\n ", "prompt_sft": "给你一个字符串数组 words 和一个字符串 s ,请你判断 s 是不是 words 的 首字母缩略词 。\n\n如果可以按顺序串联 words 中每个字符串的第一个字符形成字符串 s ,则认为 s 是 words 的首字母缩略词。例如,\"ab\" 可以由 [\"apple\", \"banana\"] 形成,但是无法从 [\"bear\", \"aardvark\"] 形成。\n\n如果 s 是 words 的首字母缩略词,返回 true ;否则,返回 false 。\n\n示例 1:\n\n输入:words = [\"alice\",\"bob\",\"charlie\"], s = \"abc\"\n输出:true\n解释:words 中 \"alice\"、\"bob\" 和 \"charlie\" 的第一个字符分别是 'a'、'b' 和 'c'。因此,s = \"abc\" 是首字母缩略词。\n\n示例 2:\n\n输入:words = [\"an\",\"apple\"], s = \"a\"\n输出:false\n解释:words 中 \"an\" 和 \"apple\" 的第一个字符分别是 'a' 和 'a'。\n串联这些字符形成的首字母缩略词是 \"aa\" 。\n因此,s = \"a\" 不是首字母缩略词。\n\n示例 3:\n\n输入:words = [\"never\",\"gonna\",\"give\",\"up\",\"on\",\"you\"], s = \"ngguoy\"\n输出:true\n解释:串联数组 words 中每个字符串的第一个字符,得到字符串 \"ngguoy\" 。\n因此,s = \"ngguoy\" 是首字母缩略词。\n\n\n提示:\n\n * 1 <= words.length <= 100\n * 1 <= words[i].length <= 10\n * 1 <= s.length <= 100\n * words[i] 和 s 由小写英文字母组成\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def isAcronym(self, words: List[str], s: str) -> bool:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"words\": [\"an\",\"apple\"], \"s\": \"a\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"alice\",\"bob\",\"charlie\"], \"s\": \"abc\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"never\",\"gonna\",\"give\",\"up\",\"on\",\"you\"], \"s\": \"ngguoy\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"ad\",\"uadhrwxki\"], \"s\": \"au\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"afqcpzsx\",\"icenu\"], \"s\": \"yi\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"afkc\",\"icxufam\"], \"s\": \"ai\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"ahbibag\",\"aoximesw\"], \"s\": \"aa\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"auqoc\",\"koioxa\"], \"s\": \"ak\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"b\",\"x\"], \"s\": \"bx\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"c\",\"df\"], \"s\": \"bd\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"dv\",\"g\"], \"s\": \"sg\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"dvn\",\"acafe\"], \"s\": \"dp\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"bpctc\",\"kaqquqbpmw\"], \"s\": \"bk\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"c\",\"evlvvhrsqa\"], \"s\": \"ce\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"dwrvgkxdtm\",\"wy\"], \"s\": \"hw\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"eceekigel\",\"gmgdfvsrkw\"], \"s\": \"wg\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"cfsrsyt\",\"md\"], \"s\": \"cm\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"envpklvi\",\"jpymde\"], \"s\": \"en\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"espleklys\",\"dg\"], \"s\": \"ea\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"euptjhixnu\",\"fwci\"], \"s\": \"kf\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"ddnlfpvy\",\"exs\"], \"s\": \"de\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"deacf\",\"hldiauk\"], \"s\": \"dh\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"dllcn\",\"tnzrnzypg\"], \"s\": \"dt\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"dmekslxlpo\",\"wqdgxqwdk\"], \"s\": \"dw\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"eyzywjsxza\",\"jxeimcc\"], \"s\": \"ex\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"f\",\"oylvtltvo\"], \"s\": \"ho\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"eo\",\"e\"], \"s\": \"ee\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"eucvcqdgg\",\"qtdwhygerb\"], \"s\": \"eq\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"fnpow\",\"ysqwqli\"], \"s\": \"jy\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"gpqyvv\",\"kihi\"], \"s\": \"ik\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"exrgiw\",\"irexgmrl\"], \"s\": \"ei\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"ez\",\"acnmits\"], \"s\": \"ea\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"fvkekkv\",\"jfbv\"], \"s\": \"fj\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"kncge\",\"nje\"], \"s\": \"kw\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"fyocwzlz\",\"lz\"], \"s\": \"fl\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"mnh\",\"clep\"], \"s\": \"pc\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"mnpdwq\",\"hziusbxr\"], \"s\": \"mg\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"g\",\"r\"], \"s\": \"gr\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"n\",\"fddigeie\"], \"s\": \"hf\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"gle\",\"irt\"], \"s\": \"gi\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"h\",\"xhtkcj\"], \"s\": \"hx\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"n\",\"ityua\"], \"s\": \"ei\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"nmxysdim\",\"xnpqsauh\"], \"s\": \"ne\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"ovdhflcck\",\"ndd\"], \"s\": \"oi\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"piiyodecdf\",\"wdwfxsjfou\"], \"s\": \"pp\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"hdmwkr\",\"jfrqh\"], \"s\": \"hj\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"hflf\",\"fvnotmdcpw\"], \"s\": \"hf\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"hnwphhozqw\",\"cfhsjlqj\"], \"s\": \"hc\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"pxcsaaa\",\"lrvxsc\"], \"s\": \"pz\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"htlsq\",\"y\"], \"s\": \"hy\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"iakfeop\",\"pd\"], \"s\": \"ip\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"qir\",\"qyyzmntl\"], \"s\": \"qa\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"iakfmr\",\"gzggxzwor\"], \"s\": \"ig\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"jna\",\"rjdbu\"], \"s\": \"jr\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"qunqyc\",\"ouzjotitvn\"], \"s\": \"co\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"rdednrsn\",\"yfrgdeapme\"], \"s\": \"ny\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"rtnbfaemv\",\"kgpcwaoik\"], \"s\": \"rf\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"s\",\"n\"], \"s\": \"sx\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"siiyqtkyis\",\"mogzgabcgk\"], \"s\": \"fm\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"tit\",\"pmuqzrs\"], \"s\": \"tz\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"uip\",\"hhstwupgg\"], \"s\": \"eh\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"uyj\",\"jlfnksqlt\"], \"s\": \"ur\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"kabfejv\",\"g\"], \"s\": \"kg\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"w\",\"eshensjifo\"], \"s\": \"ez\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"khhhdsaevp\",\"dnod\"], \"s\": \"kd\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"wefmc\",\"tmunsmg\"], \"s\": \"jt\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"wo\",\"jhaabx\"], \"s\": \"wx\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"kltil\",\"mubemf\"], \"s\": \"km\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"kxkvhylsh\",\"gyshntskq\"], \"s\": \"kg\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"wseopbedw\",\"iihrgujev\"], \"s\": \"wq\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"kzxp\",\"fy\"], \"s\": \"kf\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"wvdx\",\"jerzn\"], \"s\": \"cj\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"y\",\"qppnclhhbd\"], \"s\": \"mq\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"yegnsnddq\",\"kusrkz\"], \"s\": \"bk\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"couqsa\",\"sncuru\",\"jhgxpxipg\"], \"s\": \"csa\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"csm\",\"hexhvojfj\",\"l\"], \"s\": \"chh\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"lbor\",\"zx\"], \"s\": \"lz\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"losinu\",\"ptsjoihvj\"], \"s\": \"lp\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"maczdfm\",\"ywj\"], \"s\": \"my\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"d\",\"geviina\",\"tyljs\"], \"s\": \"dvt\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"mammhva\",\"igyzbwpj\"], \"s\": \"mi\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"ecmlkida\",\"vrjwdpe\",\"vocff\"], \"s\": \"hvv\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"emqlklvrw\",\"das\",\"bzuq\"], \"s\": \"edm\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"hawikjbs\",\"qi\",\"ssvgttkzd\"], \"s\": \"rornirdphvargyce\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"hd\",\"f\",\"meivn\"], \"s\": \"hpm\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"mqhptbyzzv\",\"mfubjraiqz\"], \"s\": \"mm\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"mvftnzftb\",\"ga\"], \"s\": \"mg\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"ncgutvi\",\"rsh\"], \"s\": \"nr\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"ntf\",\"txayzc\"], \"s\": \"nt\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"nubibbe\",\"wzwdrjcck\"], \"s\": \"nw\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"hphfek\",\"kezkkq\",\"oh\"], \"s\": \"hmo\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"odtclcvcj\",\"ufhrhk\"], \"s\": \"ou\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"ojcn\",\"naujlz\"], \"s\": \"on\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"iho\",\"ignyipken\",\"q\"], \"s\": \"wiq\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"olynt\",\"xf\"], \"s\": \"ox\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"ir\",\"wzhmxee\",\"kjfwful\"], \"s\": \"iwn\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"ixo\",\"wigba\",\"raaphui\"], \"s\": \"dwr\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"opup\",\"eme\"], \"s\": \"oe\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"kmmoq\",\"aoh\",\"hznkpurdh\"], \"s\": \"kar\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"ottxwi\",\"akpixfvbel\"], \"s\": \"oa\" }\nassert my_solution.isAcronym(**test_input) == True", "start_time": 1692498600} +{"task_id": "weekly-contest-359-determine-the-minimum-sum-of-a-k-avoiding-array", "url": "https://leetcode.com/problems/determine-the-minimum-sum-of-a-k-avoiding-array", "title": "determine-the-minimum-sum-of-a-k-avoiding-array", "meta": {"questionId": "2811", "questionFrontendId": "2829", "title": "Determine the Minimum Sum of a k-avoiding Array", "titleSlug": "determine-the-minimum-sum-of-a-k-avoiding-array", "isPaidOnly": false, "difficulty": "Medium", "likes": 305, "dislikes": 8, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你两个整数 n 和 k 。\n\n对于一个由 不同 正整数组成的数组,如果其中不存在任何求和等于 k 的不同元素对,则称其为 k-avoiding 数组。\n\n返回长度为 n 的 k-avoiding 数组的可能的最小总和。\n\n示例 1:\n\n输入:n = 5, k = 4\n输出:18\n解释:设若 k-avoiding 数组为 [1,2,4,5,6] ,其元素总和为 18 。\n可以证明不存在总和小于 18 的 k-avoiding 数组。\n\n示例 2:\n\n输入:n = 2, k = 6\n输出:3\n解释:可以构造数组 [1,2] ,其元素总和为 3 。\n可以证明不存在总和小于 3 的 k-avoiding 数组。\n\n\n提示:\n\n * 1 <= n, k <= 50\n\"\"\"\nclass Solution:\n def minimumSum(self, n: int, k: int) -> int:\n ", "prompt_sft": "给你两个整数 n 和 k 。\n\n对于一个由 不同 正整数组成的数组,如果其中不存在任何求和等于 k 的不同元素对,则称其为 k-avoiding 数组。\n\n返回长度为 n 的 k-avoiding 数组的可能的最小总和。\n\n示例 1:\n\n输入:n = 5, k = 4\n输出:18\n解释:设若 k-avoiding 数组为 [1,2,4,5,6] ,其元素总和为 18 。\n可以证明不存在总和小于 18 的 k-avoiding 数组。\n\n示例 2:\n\n输入:n = 2, k = 6\n输出:3\n解释:可以构造数组 [1,2] ,其元素总和为 3 。\n可以证明不存在总和小于 3 的 k-avoiding 数组。\n\n\n提示:\n\n * 1 <= n, k <= 50\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def minimumSum(self, n: int, k: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"n\": 5, \"k\": 4 }\nassert my_solution.minimumSum(**test_input) == 18\n\ntest_input = { \"n\": 2, \"k\": 6 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 1, \"k\": 1 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 2 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 3 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 4 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 5 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 6 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 7 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 8 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 9 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 10 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 11 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 12 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 13 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 14 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 15 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 16 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 17 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 18 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 19 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 20 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 21 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 22 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 23 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 24 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 25 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 26 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 27 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 28 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 29 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 30 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 31 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 32 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 33 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 34 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 35 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 36 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 37 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 38 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 39 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 40 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 41 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 42 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 43 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 44 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 45 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 46 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 47 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 48 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 49 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 50 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 2, \"k\": 1 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 2 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 3 }\nassert my_solution.minimumSum(**test_input) == 4\n\ntest_input = { \"n\": 2, \"k\": 4 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 5 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 7 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 8 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 9 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 10 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 11 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 12 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 13 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 14 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 15 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 16 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 17 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 18 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 19 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 20 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 21 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 22 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 23 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 24 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 25 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 26 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 27 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 28 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 29 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 30 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 31 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 32 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 33 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 34 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 35 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 36 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 37 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 38 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 39 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 40 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 41 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 42 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 43 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 44 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 45 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 46 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 47 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 48 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 49 }\nassert my_solution.minimumSum(**test_input) == 3", "start_time": 1692498600} +{"task_id": "weekly-contest-359-maximize-the-profit-as-the-salesman", "url": "https://leetcode.com/problems/maximize-the-profit-as-the-salesman", "title": "maximize-the-profit-as-the-salesman", "meta": {"questionId": "2979", "questionFrontendId": "2830", "title": "Maximize the Profit as the Salesman", "titleSlug": "maximize-the-profit-as-the-salesman", "isPaidOnly": false, "difficulty": "Medium", "likes": 603, "dislikes": 19, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个整数 n 表示数轴上的房屋数量,编号从 0 到 n - 1 。\n\n另给你一个二维整数数组 offers ,其中 offers[i] = [starti, endi, goldi] 表示第 i 个买家想要以 goldi 枚金币的价格购买从 starti 到 endi 的所有房屋。\n\n作为一名销售,你需要有策略地选择并销售房屋使自己的收入最大化。\n\n返回你可以赚取的金币的最大数目。\n\n注意 同一所房屋不能卖给不同的买家,并且允许保留一些房屋不进行出售。\n\n示例 1:\n\n输入:n = 5, offers = [[0,0,1],[0,2,2],[1,3,2]]\n输出:3\n解释:\n有 5 所房屋,编号从 0 到 4 ,共有 3 个购买要约。\n将位于 [0,0] 范围内的房屋以 1 金币的价格出售给第 1 位买家,并将位于 [1,3] 范围内的房屋以 2 金币的价格出售给第 3 位买家。\n可以证明我们最多只能获得 3 枚金币。\n\n示例 2:\n\n输入:n = 5, offers = [[0,0,1],[0,2,10],[1,3,2]]\n输出:10\n解释:有 5 所房屋,编号从 0 到 4 ,共有 3 个购买要约。\n将位于 [0,2] 范围内的房屋以 10 金币的价格出售给第 2 位买家。\n可以证明我们最多只能获得 10 枚金币。\n\n提示:\n\n * 1 <= n <= 105\n * 1 <= offers.length <= 105\n * offers[i].length == 3\n * 0 <= starti <= endi <= n - 1\n * 1 <= goldi <= 103\n\"\"\"\nclass Solution:\n def maximizeTheProfit(self, n: int, offers: List[List[int]]) -> int:\n ", "prompt_sft": "给你一个整数 n 表示数轴上的房屋数量,编号从 0 到 n - 1 。\n\n另给你一个二维整数数组 offers ,其中 offers[i] = [starti, endi, goldi] 表示第 i 个买家想要以 goldi 枚金币的价格购买从 starti 到 endi 的所有房屋。\n\n作为一名销售,你需要有策略地选择并销售房屋使自己的收入最大化。\n\n返回你可以赚取的金币的最大数目。\n\n注意 同一所房屋不能卖给不同的买家,并且允许保留一些房屋不进行出售。\n\n示例 1:\n\n输入:n = 5, offers = [[0,0,1],[0,2,2],[1,3,2]]\n输出:3\n解释:\n有 5 所房屋,编号从 0 到 4 ,共有 3 个购买要约。\n将位于 [0,0] 范围内的房屋以 1 金币的价格出售给第 1 位买家,并将位于 [1,3] 范围内的房屋以 2 金币的价格出售给第 3 位买家。\n可以证明我们最多只能获得 3 枚金币。\n\n示例 2:\n\n输入:n = 5, offers = [[0,0,1],[0,2,10],[1,3,2]]\n输出:10\n解释:有 5 所房屋,编号从 0 到 4 ,共有 3 个购买要约。\n将位于 [0,2] 范围内的房屋以 10 金币的价格出售给第 2 位买家。\n可以证明我们最多只能获得 10 枚金币。\n\n提示:\n\n * 1 <= n <= 105\n * 1 <= offers.length <= 105\n * offers[i].length == 3\n * 0 <= starti <= endi <= n - 1\n * 1 <= goldi <= 103\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def maximizeTheProfit(self, n: int, offers: List[List[int]]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"n\": 5, \"offers\": [[0,0,1],[0,2,2],[1,3,2]] }\nassert my_solution.maximizeTheProfit(**test_input) == 3\n\ntest_input = { \"n\": 5, \"offers\": [[0,0,1],[0,2,10],[1,3,2]] }\nassert my_solution.maximizeTheProfit(**test_input) == 10\n\ntest_input = { \"n\": 4, \"offers\": [[1,3,10],[1,3,3],[0,0,1],[0,0,7]] }\nassert my_solution.maximizeTheProfit(**test_input) == 17\n\ntest_input = { \"n\": 4, \"offers\": [[0,0,6],[1,2,8],[0,3,7],[2,2,5],[0,1,5],[2,3,2],[0,2,8],[2,3,10],[0,3,2]] }\nassert my_solution.maximizeTheProfit(**test_input) == 16\n\ntest_input = { \"n\": 15, \"offers\": [[5,5,10],[2,6,6],[8,11,5],[7,11,9],[2,4,1],[3,8,5],[0,6,9],[0,10,5],[5,10,8],[4,5,1]] }\nassert my_solution.maximizeTheProfit(**test_input) == 20\n\ntest_input = { \"n\": 10, \"offers\": [[1,6,1],[0,1,10],[3,6,2],[0,5,10],[0,0,3],[0,0,4],[1,1,4],[0,6,7],[4,4,1]] }\nassert my_solution.maximizeTheProfit(**test_input) == 12\n\ntest_input = { \"n\": 11, \"offers\": [[7,8,6],[6,6,4],[4,6,9],[6,7,4],[5,5,8],[1,5,9],[7,7,8],[1,2,5],[0,2,9],[1,3,8],[0,2,7],[2,2,8]] }\nassert my_solution.maximizeTheProfit(**test_input) == 29\n\ntest_input = { \"n\": 3, \"offers\": [[0,0,6],[0,1,8],[1,2,1],[0,1,4],[0,1,2],[0,0,7],[0,0,6],[0,0,5]] }\nassert my_solution.maximizeTheProfit(**test_input) == 8\n\ntest_input = { \"n\": 4, \"offers\": [[0,1,9],[1,1,4]] }\nassert my_solution.maximizeTheProfit(**test_input) == 9\n\ntest_input = { \"n\": 11, \"offers\": [[1,10,6],[1,10,5],[0,2,7],[0,0,8],[8,10,7]] }\nassert my_solution.maximizeTheProfit(**test_input) == 15\n\ntest_input = { \"n\": 3, \"offers\": [[0,1,8],[1,1,6],[2,2,7],[0,2,6],[0,2,2],[0,0,6],[0,0,9],[0,1,4]] }\nassert my_solution.maximizeTheProfit(**test_input) == 22\n\ntest_input = { \"n\": 6, \"offers\": [[0,2,4]] }\nassert my_solution.maximizeTheProfit(**test_input) == 4\n\ntest_input = { \"n\": 10, \"offers\": [[5,9,3],[1,5,8],[0,0,6],[5,8,10]] }\nassert my_solution.maximizeTheProfit(**test_input) == 16\n\ntest_input = { \"n\": 5, \"offers\": [[1,1,3],[1,1,3],[0,0,8],[1,3,8],[0,2,1],[3,3,9],[0,0,7],[0,2,3],[0,0,5],[0,3,10],[1,3,10],[4,4,6],[0,1,1],[2,4,10]] }\nassert my_solution.maximizeTheProfit(**test_input) == 26\n\ntest_input = { \"n\": 13, \"offers\": [[2,2,5],[1,8,10],[2,3,3]] }\nassert my_solution.maximizeTheProfit(**test_input) == 10\n\ntest_input = { \"n\": 2, \"offers\": [[1,1,8],[1,1,8],[1,1,10],[1,1,7],[0,0,7],[0,0,3],[0,1,8],[0,0,4],[0,0,4],[0,0,7],[0,0,10],[0,1,4],[1,1,1],[0,1,5]] }\nassert my_solution.maximizeTheProfit(**test_input) == 20\n\ntest_input = { \"n\": 3, \"offers\": [[0,1,7],[1,1,3],[0,0,2],[1,1,6],[0,0,10],[1,1,7],[0,2,3],[0,1,2],[0,0,7]] }\nassert my_solution.maximizeTheProfit(**test_input) == 17\n\ntest_input = { \"n\": 5, \"offers\": [[0,0,5],[1,3,9],[0,2,2],[1,1,6],[1,2,10],[0,2,10],[1,1,3]] }\nassert my_solution.maximizeTheProfit(**test_input) == 15\n\ntest_input = { \"n\": 10, \"offers\": [[0,1,9],[5,6,10],[1,3,8],[1,9,7],[7,8,1],[2,7,1],[0,8,7],[1,6,6],[1,4,4],[0,5,4],[0,0,3],[0,8,6]] }\nassert my_solution.maximizeTheProfit(**test_input) == 22\n\ntest_input = { \"n\": 4, \"offers\": [[0,0,1],[0,0,10],[0,2,1],[0,0,6],[0,3,10],[0,1,5],[1,2,10],[0,0,2],[3,3,1],[0,0,9],[0,1,2],[0,0,4],[1,3,5],[1,1,1]] }\nassert my_solution.maximizeTheProfit(**test_input) == 21\n\ntest_input = { \"n\": 9, \"offers\": [[0,3,10],[5,6,5],[1,5,2],[1,8,9],[1,1,9],[1,7,1],[3,7,9],[2,3,2],[4,6,1],[4,5,7],[2,2,2],[6,8,10],[1,3,10],[1,4,10]] }\nassert my_solution.maximizeTheProfit(**test_input) == 28\n\ntest_input = { \"n\": 10, \"offers\": [[0,2,2]] }\nassert my_solution.maximizeTheProfit(**test_input) == 2\n\ntest_input = { \"n\": 10, \"offers\": [[2,7,4],[2,4,9],[1,8,7],[0,4,3]] }\nassert my_solution.maximizeTheProfit(**test_input) == 9\n\ntest_input = { \"n\": 6, \"offers\": [[0,1,4],[1,2,4],[0,1,10],[1,2,4],[2,2,5],[1,1,8],[2,3,2],[4,4,4],[0,0,3]] }\nassert my_solution.maximizeTheProfit(**test_input) == 20\n\ntest_input = { \"n\": 1, \"offers\": [[0,0,8],[0,0,3],[0,0,8],[0,0,8],[0,0,5],[0,0,9],[0,0,6],[0,0,1],[0,0,8],[0,0,1],[0,0,5],[0,0,9],[0,0,2]] }\nassert my_solution.maximizeTheProfit(**test_input) == 9\n\ntest_input = { \"n\": 15, \"offers\": [[8,10,5],[4,12,6],[6,11,7],[8,11,3],[7,13,1],[7,7,8],[8,10,5],[0,11,3],[1,1,9],[2,11,6],[3,11,8]] }\nassert my_solution.maximizeTheProfit(**test_input) == 22\n\ntest_input = { \"n\": 10, \"offers\": [[5,6,9],[0,2,9]] }\nassert my_solution.maximizeTheProfit(**test_input) == 18\n\ntest_input = { \"n\": 11, \"offers\": [[7,9,5],[0,0,8],[6,6,3],[4,9,1],[3,7,5],[0,4,7]] }\nassert my_solution.maximizeTheProfit(**test_input) == 16\n\ntest_input = { \"n\": 7, \"offers\": [[0,2,9],[2,4,8],[0,3,6],[4,4,10],[2,2,2],[1,1,10],[0,0,8],[4,4,9],[4,4,4],[3,3,5],[2,5,2],[0,3,6],[3,4,5]] }\nassert my_solution.maximizeTheProfit(**test_input) == 35\n\ntest_input = { \"n\": 9, \"offers\": [[3,8,1],[0,6,7],[0,3,6],[1,6,2],[2,3,10],[3,3,2],[1,2,2],[1,3,9],[0,0,7],[1,2,9],[5,5,4],[5,6,6],[1,5,5],[0,1,2],[0,6,1]] }\nassert my_solution.maximizeTheProfit(**test_input) == 24\n\ntest_input = { \"n\": 8, \"offers\": [[0,0,7],[0,1,8],[1,1,1],[2,2,7],[2,3,1]] }\nassert my_solution.maximizeTheProfit(**test_input) == 15\n\ntest_input = { \"n\": 8, \"offers\": [[6,6,5],[0,1,7],[1,7,10]] }\nassert my_solution.maximizeTheProfit(**test_input) == 12\n\ntest_input = { \"n\": 13, \"offers\": [[0,9,5],[6,8,7],[0,0,3],[4,4,2],[1,9,7],[9,12,9],[1,2,9],[1,1,10],[3,3,3],[0,3,3],[4,8,5],[0,0,9],[7,10,7]] }\nassert my_solution.maximizeTheProfit(**test_input) == 40\n\ntest_input = { \"n\": 11, \"offers\": [[2,5,1]] }\nassert my_solution.maximizeTheProfit(**test_input) == 1\n\ntest_input = { \"n\": 3, \"offers\": [[0,0,9],[0,2,6],[1,1,1],[1,2,10],[0,0,10],[0,0,4],[0,2,7],[0,0,1],[0,0,9],[2,2,5]] }\nassert my_solution.maximizeTheProfit(**test_input) == 20\n\ntest_input = { \"n\": 5, \"offers\": [[1,1,3],[1,2,1],[0,2,3],[1,1,10],[3,3,3],[2,4,3],[0,3,5],[4,4,2],[2,3,10],[3,3,8],[3,3,9],[0,2,8],[0,2,2],[1,1,3],[0,0,8]] }\nassert my_solution.maximizeTheProfit(**test_input) == 30\n\ntest_input = { \"n\": 13, \"offers\": [[6,9,3],[6,9,6],[5,12,10],[11,12,4],[4,4,2],[0,7,8],[2,6,6],[6,6,4]] }\nassert my_solution.maximizeTheProfit(**test_input) == 12\n\ntest_input = { \"n\": 3, \"offers\": [[0,2,9],[1,1,8],[0,1,1],[2,2,4],[2,2,1],[0,0,4],[1,1,9],[0,0,6],[0,1,7]] }\nassert my_solution.maximizeTheProfit(**test_input) == 19\n\ntest_input = { \"n\": 3, \"offers\": [[1,2,8],[0,0,1],[0,1,1],[0,0,3],[1,2,2],[0,0,7],[0,0,10],[1,1,6]] }\nassert my_solution.maximizeTheProfit(**test_input) == 18\n\ntest_input = { \"n\": 2, \"offers\": [[0,0,3],[1,1,10],[0,1,6]] }\nassert my_solution.maximizeTheProfit(**test_input) == 13\n\ntest_input = { \"n\": 3, \"offers\": [[0,0,9],[1,1,1],[0,2,7],[1,1,7],[1,2,6],[0,0,8],[0,2,3],[1,2,10],[2,2,3],[2,2,5]] }\nassert my_solution.maximizeTheProfit(**test_input) == 21\n\ntest_input = { \"n\": 5, \"offers\": [[2,3,2],[0,1,7],[0,1,1],[0,0,9],[2,4,1],[3,4,5],[1,3,10],[0,0,8]] }\nassert my_solution.maximizeTheProfit(**test_input) == 19\n\ntest_input = { \"n\": 15, \"offers\": [[4,6,9],[4,10,9],[3,5,4],[0,2,6],[3,13,7],[1,11,6],[1,8,4],[4,12,4],[3,8,8],[13,13,7],[4,12,3]] }\nassert my_solution.maximizeTheProfit(**test_input) == 22\n\ntest_input = { \"n\": 8, \"offers\": [[1,5,9],[0,4,9],[0,0,3],[1,2,9],[0,0,10],[4,7,9],[7,7,2],[0,2,6],[1,1,5],[1,4,3],[2,4,8],[0,1,1],[2,3,1]] }\nassert my_solution.maximizeTheProfit(**test_input) == 28\n\ntest_input = { \"n\": 4, \"offers\": [[0,2,7],[2,3,9],[2,3,2],[1,2,1],[1,2,9],[0,3,7],[0,2,9],[1,2,8],[0,3,10],[0,3,8],[0,0,5],[2,2,6]] }\nassert my_solution.maximizeTheProfit(**test_input) == 14\n\ntest_input = { \"n\": 12, \"offers\": [[0,0,4],[5,8,2],[2,2,10],[3,5,7],[1,2,1],[5,7,8],[8,11,3]] }\nassert my_solution.maximizeTheProfit(**test_input) == 25\n\ntest_input = { \"n\": 2, \"offers\": [[0,0,7],[0,1,3],[0,0,8]] }\nassert my_solution.maximizeTheProfit(**test_input) == 8\n\ntest_input = { \"n\": 4, \"offers\": [[2,3,8],[0,1,1],[3,3,2]] }\nassert my_solution.maximizeTheProfit(**test_input) == 9\n\ntest_input = { \"n\": 14, \"offers\": [[2,12,4],[7,11,4],[4,4,5],[0,1,6],[3,4,1],[4,11,9],[10,12,7],[7,12,1],[11,11,1],[0,0,5],[12,12,8],[6,7,6]] }\nassert my_solution.maximizeTheProfit(**test_input) == 26\n\ntest_input = { \"n\": 10, \"offers\": [[1,4,6],[7,9,9],[1,4,5],[8,8,2],[4,7,1],[6,8,8],[2,3,1],[0,1,4]] }\nassert my_solution.maximizeTheProfit(**test_input) == 15\n\ntest_input = { \"n\": 7, \"offers\": [[2,5,5],[1,2,9],[1,3,7],[2,4,3],[0,0,6],[0,0,1],[4,4,9],[1,5,7],[2,2,10]] }\nassert my_solution.maximizeTheProfit(**test_input) == 25\n\ntest_input = { \"n\": 11, \"offers\": [[0,4,10]] }\nassert my_solution.maximizeTheProfit(**test_input) == 10\n\ntest_input = { \"n\": 3, \"offers\": [[0,1,10],[1,2,2],[0,2,6],[0,0,1],[0,0,3],[0,1,8],[0,0,2],[2,2,8],[0,0,3],[2,2,3],[1,2,6],[0,0,4],[1,2,5]] }\nassert my_solution.maximizeTheProfit(**test_input) == 18\n\ntest_input = { \"n\": 14, \"offers\": [[11,11,4],[1,11,10],[11,12,2],[7,8,2]] }\nassert my_solution.maximizeTheProfit(**test_input) == 10\n\ntest_input = { \"n\": 2, \"offers\": [[0,0,1],[0,0,1],[1,1,9],[0,0,1],[1,1,2],[0,1,10]] }\nassert my_solution.maximizeTheProfit(**test_input) == 10\n\ntest_input = { \"n\": 6, \"offers\": [[0,5,6],[1,2,10],[0,2,4],[2,4,5],[4,4,6],[2,2,2],[0,0,7],[2,5,9],[2,2,3]] }\nassert my_solution.maximizeTheProfit(**test_input) == 23\n\ntest_input = { \"n\": 6, \"offers\": [[0,0,7],[2,5,5]] }\nassert my_solution.maximizeTheProfit(**test_input) == 12\n\ntest_input = { \"n\": 10, \"offers\": [[2,3,2],[0,1,6],[0,0,2],[1,1,5],[3,3,8],[2,8,7],[1,7,8],[0,1,4],[7,7,8],[1,3,7],[5,5,10],[2,6,6],[0,0,4],[5,7,4],[1,9,4]] }\nassert my_solution.maximizeTheProfit(**test_input) == 35\n\ntest_input = { \"n\": 10, \"offers\": [[0,2,4],[1,4,7],[0,1,10],[0,5,1]] }\nassert my_solution.maximizeTheProfit(**test_input) == 10\n\ntest_input = { \"n\": 12, \"offers\": [[0,5,6],[4,10,9],[7,11,10],[10,11,1],[6,10,1],[2,2,6]] }\nassert my_solution.maximizeTheProfit(**test_input) == 16\n\ntest_input = { \"n\": 11, \"offers\": [[3,7,8],[2,7,10],[3,9,3]] }\nassert my_solution.maximizeTheProfit(**test_input) == 10\n\ntest_input = { \"n\": 4, \"offers\": [[0,0,3],[0,2,6],[0,0,1],[1,1,2],[0,2,8],[1,1,3],[1,3,8],[1,1,10],[1,2,7],[1,1,8],[0,0,9]] }\nassert my_solution.maximizeTheProfit(**test_input) == 19\n\ntest_input = { \"n\": 1, \"offers\": [[0,0,9]] }\nassert my_solution.maximizeTheProfit(**test_input) == 9\n\ntest_input = { \"n\": 3, \"offers\": [[0,1,5],[0,0,5],[0,0,6],[0,1,6],[0,2,10],[1,2,6],[0,0,9],[1,2,9]] }\nassert my_solution.maximizeTheProfit(**test_input) == 18\n\ntest_input = { \"n\": 4, \"offers\": [[0,0,2],[2,3,9],[0,1,8],[0,0,9],[0,0,1],[3,3,9],[1,2,1],[1,3,5],[0,1,4],[0,1,4]] }\nassert my_solution.maximizeTheProfit(**test_input) == 19\n\ntest_input = { \"n\": 3, \"offers\": [[0,0,7],[2,2,1],[1,1,3],[0,0,3],[1,1,7],[0,1,5],[0,2,3],[1,1,5],[0,1,10],[1,1,5],[1,1,6],[0,1,3],[0,0,8],[1,2,7],[1,1,4]] }\nassert my_solution.maximizeTheProfit(**test_input) == 16\n\ntest_input = { \"n\": 14, \"offers\": [[5,7,2],[1,5,3],[11,13,2],[12,12,5],[4,5,6],[5,10,2],[4,10,8],[1,1,4],[4,4,2],[3,7,9],[5,10,1],[0,3,2]] }\nassert my_solution.maximizeTheProfit(**test_input) == 18\n\ntest_input = { \"n\": 11, \"offers\": [[1,1,5],[4,4,9],[0,0,1],[1,3,3],[3,7,4],[3,9,6],[7,10,2],[3,7,5],[4,4,8],[7,8,10],[1,3,7],[1,4,5],[0,0,10]] }\nassert my_solution.maximizeTheProfit(**test_input) == 36\n\ntest_input = { \"n\": 13, \"offers\": [[4,9,9],[1,9,8],[1,9,8],[0,0,8],[8,11,3],[2,3,6],[9,9,10],[5,12,1],[4,6,4]] }\nassert my_solution.maximizeTheProfit(**test_input) == 28\n\ntest_input = { \"n\": 5, \"offers\": [[2,2,7],[0,2,10],[2,3,10]] }\nassert my_solution.maximizeTheProfit(**test_input) == 10\n\ntest_input = { \"n\": 10, \"offers\": [[0,4,6],[1,1,1],[0,5,1],[1,6,3],[8,9,1],[2,3,7],[2,3,10],[1,2,1],[0,0,8],[3,5,5],[0,0,10]] }\nassert my_solution.maximizeTheProfit(**test_input) == 22\n\ntest_input = { \"n\": 4, \"offers\": [[0,1,1],[0,0,9],[1,1,8],[3,3,1],[1,1,5],[0,0,9],[0,1,9],[0,0,7],[2,2,2],[2,3,5],[1,1,10],[1,2,8]] }\nassert my_solution.maximizeTheProfit(**test_input) == 24\n\ntest_input = { \"n\": 7, \"offers\": [[0,1,9],[0,1,4],[0,0,3],[0,0,1],[1,6,5],[4,6,9],[4,5,7],[0,0,3],[1,5,9],[0,2,2]] }\nassert my_solution.maximizeTheProfit(**test_input) == 18\n\ntest_input = { \"n\": 12, \"offers\": [[8,8,6],[8,8,6],[1,10,7],[0,0,3],[9,10,7],[1,7,2],[1,1,1],[2,3,6],[0,11,1],[1,8,5],[1,5,7],[1,2,4],[9,9,5],[0,3,1]] }\nassert my_solution.maximizeTheProfit(**test_input) == 23\n\ntest_input = { \"n\": 15, \"offers\": [[5,6,3],[2,2,7],[0,0,5],[1,7,10],[11,14,5],[13,14,1],[2,12,1],[0,4,5],[0,6,2],[6,9,10],[3,5,2],[0,1,1],[1,14,1],[1,6,1]] }\nassert my_solution.maximizeTheProfit(**test_input) == 29\n\ntest_input = { \"n\": 7, \"offers\": [[1,1,5],[1,1,4],[0,0,9],[1,1,6],[0,6,4],[2,6,3],[2,5,9],[0,6,3],[0,2,1],[1,1,6],[4,5,5]] }\nassert my_solution.maximizeTheProfit(**test_input) == 24\n\ntest_input = { \"n\": 1, \"offers\": [[0,0,5],[0,0,3],[0,0,4],[0,0,8],[0,0,10],[0,0,6],[0,0,7],[0,0,7],[0,0,7],[0,0,3],[0,0,4],[0,0,5]] }\nassert my_solution.maximizeTheProfit(**test_input) == 10\n\ntest_input = { \"n\": 7, \"offers\": [[2,2,3],[2,6,4],[4,6,5],[0,0,4],[1,1,4],[2,3,1],[2,4,3],[0,2,8],[1,3,10],[1,3,2],[1,6,7],[0,6,9],[2,2,2],[1,1,9],[4,4,2]] }\nassert my_solution.maximizeTheProfit(**test_input) == 21\n\ntest_input = { \"n\": 12, \"offers\": [[0,0,7],[0,2,3],[0,7,2],[2,3,1],[2,11,6],[2,10,2],[1,3,6],[4,7,9],[7,9,3],[4,6,1],[5,6,8],[0,2,4],[0,0,3],[5,5,9],[2,5,3]] }\nassert my_solution.maximizeTheProfit(**test_input) == 25\n\ntest_input = { \"n\": 9, \"offers\": [[1,8,4],[5,6,5],[0,2,6],[4,5,4]] }\nassert my_solution.maximizeTheProfit(**test_input) == 11\n\ntest_input = { \"n\": 8, \"offers\": [[0,4,6],[2,3,6],[2,5,9],[2,6,7],[6,6,5],[4,4,4],[1,1,5],[2,5,7]] }\nassert my_solution.maximizeTheProfit(**test_input) == 20\n\ntest_input = { \"n\": 13, \"offers\": [[0,6,10]] }\nassert my_solution.maximizeTheProfit(**test_input) == 10\n\ntest_input = { \"n\": 6, \"offers\": [[0,1,2],[0,0,9],[3,3,10],[0,3,7],[0,0,2],[0,0,3],[2,2,2],[2,3,2],[5,5,6],[0,1,2],[0,5,2]] }\nassert my_solution.maximizeTheProfit(**test_input) == 27\n\ntest_input = { \"n\": 14, \"offers\": [[3,12,7],[1,3,2],[4,11,3],[0,1,7],[1,5,2],[1,1,4]] }\nassert my_solution.maximizeTheProfit(**test_input) == 14\n\ntest_input = { \"n\": 14, \"offers\": [[0,0,3],[0,1,3],[1,11,3],[6,7,6],[7,7,5],[1,2,8],[7,10,9]] }\nassert my_solution.maximizeTheProfit(**test_input) == 20\n\ntest_input = { \"n\": 13, \"offers\": [[0,12,7],[2,2,4],[2,2,8],[3,3,2],[1,11,5],[1,7,2]] }\nassert my_solution.maximizeTheProfit(**test_input) == 10\n\ntest_input = { \"n\": 1, \"offers\": [[0,0,2],[0,0,8],[0,0,1]] }\nassert my_solution.maximizeTheProfit(**test_input) == 8\n\ntest_input = { \"n\": 1, \"offers\": [[0,0,1],[0,0,4],[0,0,7],[0,0,2],[0,0,5],[0,0,1],[0,0,4],[0,0,2],[0,0,6],[0,0,6],[0,0,3],[0,0,3]] }\nassert my_solution.maximizeTheProfit(**test_input) == 7\n\ntest_input = { \"n\": 1, \"offers\": [[0,0,6],[0,0,6],[0,0,3],[0,0,6],[0,0,6],[0,0,10],[0,0,1],[0,0,2]] }\nassert my_solution.maximizeTheProfit(**test_input) == 10\n\ntest_input = { \"n\": 9, \"offers\": [[4,6,7],[1,3,10]] }\nassert my_solution.maximizeTheProfit(**test_input) == 17\n\ntest_input = { \"n\": 13, \"offers\": [[2,6,3],[1,12,6],[2,11,3],[7,7,2],[5,12,4],[0,1,2],[0,1,8],[1,1,3],[6,6,4],[8,9,7],[8,8,2],[2,2,2],[0,0,9],[9,11,7],[8,9,7]] }\nassert my_solution.maximizeTheProfit(**test_input) == 29\n\ntest_input = { \"n\": 8, \"offers\": [[0,1,8],[0,0,6],[5,5,9]] }\nassert my_solution.maximizeTheProfit(**test_input) == 17\n\ntest_input = { \"n\": 1, \"offers\": [[0,0,10],[0,0,3],[0,0,8],[0,0,9],[0,0,1],[0,0,8],[0,0,2],[0,0,7],[0,0,10],[0,0,8],[0,0,5],[0,0,3],[0,0,2],[0,0,4]] }\nassert my_solution.maximizeTheProfit(**test_input) == 10\n\ntest_input = { \"n\": 9, \"offers\": [[0,2,6],[1,3,5],[1,1,5],[2,3,10],[4,8,4],[5,8,5],[6,6,10]] }\nassert my_solution.maximizeTheProfit(**test_input) == 25\n\ntest_input = { \"n\": 6, \"offers\": [[0,0,7]] }\nassert my_solution.maximizeTheProfit(**test_input) == 7\n\ntest_input = { \"n\": 8, \"offers\": [[1,1,5],[1,2,9],[1,2,6],[0,3,6],[1,1,10],[3,4,1],[3,5,3],[1,5,8],[0,2,6],[5,7,9]] }\nassert my_solution.maximizeTheProfit(**test_input) == 20\n\ntest_input = { \"n\": 14, \"offers\": [[3,4,4],[6,8,1],[0,4,1]] }\nassert my_solution.maximizeTheProfit(**test_input) == 5\n\ntest_input = { \"n\": 11, \"offers\": [[4,4,2],[1,2,7],[2,8,10],[1,1,3],[8,10,4],[1,2,1],[4,6,10]] }\nassert my_solution.maximizeTheProfit(**test_input) == 21\n\ntest_input = { \"n\": 11, \"offers\": [[1,8,1],[1,5,5],[0,1,3],[10,10,10],[1,1,8],[1,2,1],[2,3,10],[2,10,10],[2,2,9],[0,9,4]] }\nassert my_solution.maximizeTheProfit(**test_input) == 28\n\ntest_input = { \"n\": 6, \"offers\": [[2,2,6],[0,1,2],[2,2,2]] }\nassert my_solution.maximizeTheProfit(**test_input) == 8", "start_time": 1692498600} +{"task_id": "weekly-contest-359-find-the-longest-equal-subarray", "url": "https://leetcode.com/problems/find-the-longest-equal-subarray", "title": "find-the-longest-equal-subarray", "meta": {"questionId": "2832", "questionFrontendId": "2831", "title": "Find the Longest Equal Subarray", "titleSlug": "find-the-longest-equal-subarray", "isPaidOnly": false, "difficulty": "Medium", "likes": 579, "dislikes": 14, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0 开始的整数数组 nums 和一个整数 k 。\n\n如果子数组中所有元素都相等,则认为子数组是一个 等值子数组 。注意,空数组是 等值子数组 。\n\n从 nums 中删除最多 k 个元素后,返回可能的最长等值子数组的长度。\n\n子数组 是数组中一个连续且可能为空的元素序列。\n\n示例 1:\n\n输入:nums = [1,3,2,3,1,3], k = 3\n输出:3\n解释:最优的方案是删除下标 2 和下标 4 的元素。\n删除后,nums 等于 [1, 3, 3, 3] 。\n最长等值子数组从 i = 1 开始到 j = 3 结束,长度等于 3 。\n可以证明无法创建更长的等值子数组。\n\n示例 2:\n\n输入:nums = [1,1,2,2,1,1], k = 2\n输出:4\n解释:最优的方案是删除下标 2 和下标 3 的元素。\n删除后,nums 等于 [1, 1, 1, 1] 。\n数组自身就是等值子数组,长度等于 4 。\n可以证明无法创建更长的等值子数组。\n\n\n提示:\n\n * 1 <= nums.length <= 105\n * 1 <= nums[i] <= nums.length\n * 0 <= k <= nums.length\n\"\"\"\nclass Solution:\n def longestEqualSubarray(self, nums: List[int], k: int) -> int:\n ", "prompt_sft": "给你一个下标从 0 开始的整数数组 nums 和一个整数 k 。\n\n如果子数组中所有元素都相等,则认为子数组是一个 等值子数组 。注意,空数组是 等值子数组 。\n\n从 nums 中删除最多 k 个元素后,返回可能的最长等值子数组的长度。\n\n子数组 是数组中一个连续且可能为空的元素序列。\n\n示例 1:\n\n输入:nums = [1,3,2,3,1,3], k = 3\n输出:3\n解释:最优的方案是删除下标 2 和下标 4 的元素。\n删除后,nums 等于 [1, 3, 3, 3] 。\n最长等值子数组从 i = 1 开始到 j = 3 结束,长度等于 3 。\n可以证明无法创建更长的等值子数组。\n\n示例 2:\n\n输入:nums = [1,1,2,2,1,1], k = 2\n输出:4\n解释:最优的方案是删除下标 2 和下标 3 的元素。\n删除后,nums 等于 [1, 1, 1, 1] 。\n数组自身就是等值子数组,长度等于 4 。\n可以证明无法创建更长的等值子数组。\n\n\n提示:\n\n * 1 <= nums.length <= 105\n * 1 <= nums[i] <= nums.length\n * 0 <= k <= nums.length\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def longestEqualSubarray(self, nums: List[int], k: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,3,2,3,1,3], \"k\": 3 }\nassert my_solution.longestEqualSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,2,2,1,1], \"k\": 2 }\nassert my_solution.longestEqualSubarray(**test_input) == 4\n\ntest_input = { \"nums\": [1], \"k\": 0 }\nassert my_solution.longestEqualSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [1], \"k\": 1 }\nassert my_solution.longestEqualSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [2,1], \"k\": 1 }\nassert my_solution.longestEqualSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [2,2], \"k\": 1 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [1,1], \"k\": 0 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [2,1], \"k\": 0 }\nassert my_solution.longestEqualSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [1,2], \"k\": 1 }\nassert my_solution.longestEqualSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [2,2], \"k\": 2 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [2,3,2], \"k\": 1 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [3,2,2], \"k\": 1 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [3,1,1], \"k\": 2 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [1,2,3], \"k\": 2 }\nassert my_solution.longestEqualSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,3], \"k\": 3 }\nassert my_solution.longestEqualSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [2,3,1], \"k\": 2 }\nassert my_solution.longestEqualSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [2,2,1], \"k\": 1 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [1,3,2], \"k\": 3 }\nassert my_solution.longestEqualSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [2,3,3], \"k\": 3 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [3,2,3], \"k\": 3 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [2,2,3], \"k\": 0 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [2,2,2], \"k\": 1 }\nassert my_solution.longestEqualSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,1], \"k\": 0 }\nassert my_solution.longestEqualSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [3,3,3], \"k\": 2 }\nassert my_solution.longestEqualSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,2], \"k\": 1 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,3], \"k\": 1 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [1,2,3], \"k\": 1 }\nassert my_solution.longestEqualSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,2], \"k\": 3 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [3,2,4,2], \"k\": 1 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [3,4,2,1], \"k\": 0 }\nassert my_solution.longestEqualSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [1,3,4,2], \"k\": 0 }\nassert my_solution.longestEqualSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [2,4,2,2], \"k\": 3 }\nassert my_solution.longestEqualSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [4,2,2,3], \"k\": 1 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [4,1,3,2], \"k\": 4 }\nassert my_solution.longestEqualSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,2,1], \"k\": 4 }\nassert my_solution.longestEqualSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [2,4,1,3], \"k\": 3 }\nassert my_solution.longestEqualSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,1,2], \"k\": 3 }\nassert my_solution.longestEqualSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [4,2,1,4], \"k\": 4 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,4,1], \"k\": 4 }\nassert my_solution.longestEqualSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [2,1,4,1], \"k\": 4 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [2,4,3,3], \"k\": 2 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [1,2,2,4], \"k\": 3 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [2,2,2,4], \"k\": 3 }\nassert my_solution.longestEqualSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [2,3,3,1], \"k\": 3 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [2,4,1,4], \"k\": 1 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [3,4,1,4], \"k\": 2 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [3,2,3,1], \"k\": 3 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [3,1,1,3], \"k\": 3 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [2,3,2,5,1], \"k\": 0 }\nassert my_solution.longestEqualSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [5,3,3,1,3], \"k\": 3 }\nassert my_solution.longestEqualSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [4,4,2,2,4], \"k\": 1 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [5,4,2,3,3], \"k\": 5 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [4,4,4,3,4], \"k\": 1 }\nassert my_solution.longestEqualSubarray(**test_input) == 4\n\ntest_input = { \"nums\": [1,5,5,5,3], \"k\": 2 }\nassert my_solution.longestEqualSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [2,1,4,5,2], \"k\": 1 }\nassert my_solution.longestEqualSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [5,1,5,2,3], \"k\": 3 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [5,3,2,3,4], \"k\": 1 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [3,2,1,4,1], \"k\": 0 }\nassert my_solution.longestEqualSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [3,2,2,5,3], \"k\": 5 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [2,2,4,4,2], \"k\": 1 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [4,3,3,4,3], \"k\": 2 }\nassert my_solution.longestEqualSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [1,5,4,3,4], \"k\": 0 }\nassert my_solution.longestEqualSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [4,4,2,5,3], \"k\": 0 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [3,3,5,2,3], \"k\": 4 }\nassert my_solution.longestEqualSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,1,1,3], \"k\": 5 }\nassert my_solution.longestEqualSubarray(**test_input) == 4\n\ntest_input = { \"nums\": [1,3,2,5,1], \"k\": 1 }\nassert my_solution.longestEqualSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [3,3,1,4,5], \"k\": 2 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [1,2,5,5,4], \"k\": 3 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [3,1,5,3,1,1], \"k\": 0 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [6,4,1,5,5,3], \"k\": 0 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [2,2,2,1,2,4], \"k\": 4 }\nassert my_solution.longestEqualSubarray(**test_input) == 4\n\ntest_input = { \"nums\": [1,1,2,2,6,2], \"k\": 1 }\nassert my_solution.longestEqualSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,3,6,6,2], \"k\": 4 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [2,4,5,1,4,1], \"k\": 2 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [1,5,6,4,6,3], \"k\": 3 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [5,4,2,4,1,3], \"k\": 2 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [2,1,1,3,1,3], \"k\": 2 }\nassert my_solution.longestEqualSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [2,4,6,6,6,4], \"k\": 3 }\nassert my_solution.longestEqualSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [3,6,2,5,4,5], \"k\": 1 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,5,6,1,4], \"k\": 4 }\nassert my_solution.longestEqualSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [4,6,6,6,2,4], \"k\": 3 }\nassert my_solution.longestEqualSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [2,5,5,5,6,4], \"k\": 1 }\nassert my_solution.longestEqualSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [2,3,3,2,3,3], \"k\": 2 }\nassert my_solution.longestEqualSubarray(**test_input) == 4\n\ntest_input = { \"nums\": [5,2,5,3,3,2], \"k\": 6 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [3,5,3,2,3,6], \"k\": 6 }\nassert my_solution.longestEqualSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [4,3,2,5,4,2], \"k\": 4 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [1,2,4,2,1,3], \"k\": 3 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [3,1,3,4,1,6], \"k\": 6 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [2,3,7,7,3,2,2], \"k\": 7 }\nassert my_solution.longestEqualSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [5,6,7,7,4,4,2], \"k\": 5 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [7,2,4,1,3,3,4], \"k\": 4 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [5,3,1,7,5,5,7], \"k\": 6 }\nassert my_solution.longestEqualSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [4,2,6,2,3,4,6], \"k\": 6 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [2,7,6,7,3,7,4], \"k\": 5 }\nassert my_solution.longestEqualSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [3,2,5,1,4,3,4], \"k\": 4 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [2,3,3,7,2,5,1], \"k\": 2 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [4,1,6,7,5,3,5], \"k\": 1 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [3,1,4,1,5,5,6], \"k\": 6 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [1,5,5,7,7,7,4], \"k\": 0 }\nassert my_solution.longestEqualSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [5,7,4,4,1,6,7], \"k\": 5 }\nassert my_solution.longestEqualSubarray(**test_input) == 2", "start_time": 1692498600} +{"task_id": "biweekly-contest-111-count-pairs-whose-sum-is-less-than-target", "url": "https://leetcode.com/problems/count-pairs-whose-sum-is-less-than-target", "title": "count-pairs-whose-sum-is-less-than-target", "meta": {"questionId": "2917", "questionFrontendId": "2824", "title": "Count Pairs Whose Sum is Less than Target", "titleSlug": "count-pairs-whose-sum-is-less-than-target", "isPaidOnly": false, "difficulty": "Easy", "likes": 358, "dislikes": 23, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0 开始长度为 n 的整数数组 nums 和一个整数 target ,请你返回满足 0 <= i < j < n 且 nums[i] + nums[j] < target 的下标对 (i, j) 的数目。\n\n示例 1:\n\n输入:nums = [-1,1,2,3,1], target = 2\n输出:3\n解释:总共有 3 个下标对满足题目描述:\n- (0, 1) ,0 < 1 且 nums[0] + nums[1] = 0 < target\n- (0, 2) ,0 < 2 且 nums[0] + nums[2] = 1 < target\n- (0, 4) ,0 < 4 且 nums[0] + nums[4] = 0 < target\n注意 (0, 3) 不计入答案因为 nums[0] + nums[3] 不是严格小于 target 。\n\n示例 2:\n\n输入:nums = [-6,2,5,-2,-7,-1,3], target = -2\n输出:10\n解释:总共有 10 个下标对满足题目描述:\n- (0, 1) ,0 < 1 且 nums[0] + nums[1] = -4 < target\n- (0, 3) ,0 < 3 且 nums[0] + nums[3] = -8 < target\n- (0, 4) ,0 < 4 且 nums[0] + nums[4] = -13 < target\n- (0, 5) ,0 < 5 且 nums[0] + nums[5] = -7 < target\n- (0, 6) ,0 < 6 且 nums[0] + nums[6] = -3 < target\n- (1, 4) ,1 < 4 且 nums[1] + nums[4] = -5 < target\n- (3, 4) ,3 < 4 且 nums[3] + nums[4] = -9 < target\n- (3, 5) ,3 < 5 且 nums[3] + nums[5] = -3 < target\n- (4, 5) ,4 < 5 且 nums[4] + nums[5] = -8 < target\n- (4, 6) ,4 < 6 且 nums[4] + nums[6] = -4 < target\n\n\n提示:\n\n * 1 <= nums.length == n <= 50\n * -50 <= nums[i], target <= 50\n\"\"\"\nclass Solution:\n def countPairs(self, nums: List[int], target: int) -> int:\n ", "prompt_sft": "给你一个下标从 0 开始长度为 n 的整数数组 nums 和一个整数 target ,请你返回满足 0 <= i < j < n 且 nums[i] + nums[j] < target 的下标对 (i, j) 的数目。\n\n示例 1:\n\n输入:nums = [-1,1,2,3,1], target = 2\n输出:3\n解释:总共有 3 个下标对满足题目描述:\n- (0, 1) ,0 < 1 且 nums[0] + nums[1] = 0 < target\n- (0, 2) ,0 < 2 且 nums[0] + nums[2] = 1 < target\n- (0, 4) ,0 < 4 且 nums[0] + nums[4] = 0 < target\n注意 (0, 3) 不计入答案因为 nums[0] + nums[3] 不是严格小于 target 。\n\n示例 2:\n\n输入:nums = [-6,2,5,-2,-7,-1,3], target = -2\n输出:10\n解释:总共有 10 个下标对满足题目描述:\n- (0, 1) ,0 < 1 且 nums[0] + nums[1] = -4 < target\n- (0, 3) ,0 < 3 且 nums[0] + nums[3] = -8 < target\n- (0, 4) ,0 < 4 且 nums[0] + nums[4] = -13 < target\n- (0, 5) ,0 < 5 且 nums[0] + nums[5] = -7 < target\n- (0, 6) ,0 < 6 且 nums[0] + nums[6] = -3 < target\n- (1, 4) ,1 < 4 且 nums[1] + nums[4] = -5 < target\n- (3, 4) ,3 < 4 且 nums[3] + nums[4] = -9 < target\n- (3, 5) ,3 < 5 且 nums[3] + nums[5] = -3 < target\n- (4, 5) ,4 < 5 且 nums[4] + nums[5] = -8 < target\n- (4, 6) ,4 < 6 且 nums[4] + nums[6] = -4 < target\n\n\n提示:\n\n * 1 <= nums.length == n <= 50\n * -50 <= nums[i], target <= 50\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def countPairs(self, nums: List[int], target: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [-1,1,2,3,1], \"target\": 2 }\nassert my_solution.countPairs(**test_input) == 3\n\ntest_input = { \"nums\": [-6,2,5,-2,-7,-1,3], \"target\": -2 }\nassert my_solution.countPairs(**test_input) == 10\n\ntest_input = { \"nums\": [9,-5,-5,5,-5,-4,-6,6,-6], \"target\": 3 }\nassert my_solution.countPairs(**test_input) == 27\n\ntest_input = { \"nums\": [-8,-5,5,-4,10], \"target\": 2 }\nassert my_solution.countPairs(**test_input) == 6\n\ntest_input = { \"nums\": [-5,0,-7,-1,9,8,-9,9], \"target\": -14 }\nassert my_solution.countPairs(**test_input) == 1\n\ntest_input = { \"nums\": [6,-1,7,4,2,3], \"target\": 8 }\nassert my_solution.countPairs(**test_input) == 8\n\ntest_input = { \"nums\": [2,8,2,8,7], \"target\": 10 }\nassert my_solution.countPairs(**test_input) == 3\n\ntest_input = { \"nums\": [-6,1,1,-1,-10,-7,1,-5,-4,0], \"target\": -15 }\nassert my_solution.countPairs(**test_input) == 2\n\ntest_input = { \"nums\": [10,-2,-1,7,8,5,3,-4,-9], \"target\": -10 }\nassert my_solution.countPairs(**test_input) == 2\n\ntest_input = { \"nums\": [3,8,-3,4,10,-6], \"target\": 1 }\nassert my_solution.countPairs(**test_input) == 4\n\ntest_input = { \"nums\": [-4,-6,-7,8], \"target\": -13 }\nassert my_solution.countPairs(**test_input) == 0\n\ntest_input = { \"nums\": [-4,0,10,8,-2], \"target\": 0 }\nassert my_solution.countPairs(**test_input) == 3\n\ntest_input = { \"nums\": [-8,-5,-3,1,-7], \"target\": -6 }\nassert my_solution.countPairs(**test_input) == 7\n\ntest_input = { \"nums\": [4,-8,-2,5,2,-9,6,5,-4], \"target\": -4 }\nassert my_solution.countPairs(**test_input) == 9\n\ntest_input = { \"nums\": [-1,-5,4,4,-10], \"target\": -6 }\nassert my_solution.countPairs(**test_input) == 2\n\ntest_input = { \"nums\": [-5,4,-6,-5,-10,-1,10,3], \"target\": 6 }\nassert my_solution.countPairs(**test_input) == 24\n\ntest_input = { \"nums\": [-9,6,-4,10,1,8], \"target\": 11 }\nassert my_solution.countPairs(**test_input) == 11\n\ntest_input = { \"nums\": [-10,-6,-8,-9,6,6,-6,-6,-3], \"target\": -2 }\nassert my_solution.countPairs(**test_input) == 25\n\ntest_input = { \"nums\": [-7,7,6,-9,-4,10,8,-8,2,2], \"target\": -1 }\nassert my_solution.countPairs(**test_input) == 17\n\ntest_input = { \"nums\": [0,-1,0,-6,-9], \"target\": -9 }\nassert my_solution.countPairs(**test_input) == 2\n\ntest_input = { \"nums\": [8,-10,-9,6,-3,5,-2,-2,-7], \"target\": -4 }\nassert my_solution.countPairs(**test_input) == 15\n\ntest_input = { \"nums\": [-1,3,8,3], \"target\": 2 }\nassert my_solution.countPairs(**test_input) == 0\n\ntest_input = { \"nums\": [7,2,9,-10,-4,4,-3,0], \"target\": -20 }\nassert my_solution.countPairs(**test_input) == 0\n\ntest_input = { \"nums\": [6,4,1,-7], \"target\": 7 }\nassert my_solution.countPairs(**test_input) == 4\n\ntest_input = { \"nums\": [3,8,6,-2,6,1,7], \"target\": 7 }\nassert my_solution.countPairs(**test_input) == 7\n\ntest_input = { \"nums\": [1,3,-10,5,-8,0,-5,-9], \"target\": -7 }\nassert my_solution.countPairs(**test_input) == 11\n\ntest_input = { \"nums\": [-6,9,2,4,-9,2,4,-6,6,-9], \"target\": 11 }\nassert my_solution.countPairs(**test_input) == 40\n\ntest_input = { \"nums\": [-10,-7,-5,-1,2,4,-6,6], \"target\": -3 }\nassert my_solution.countPairs(**test_input) == 15\n\ntest_input = { \"nums\": [-1,0,1,9,-2,-8,-8,7], \"target\": 1 }\nassert my_solution.countPairs(**test_input) == 16\n\ntest_input = { \"nums\": [1,9,3,2,9,-5,6,0,-6,6], \"target\": 9 }\nassert my_solution.countPairs(**test_input) == 29\n\ntest_input = { \"nums\": [-3,-3,-4,1,4,9], \"target\": 6 }\nassert my_solution.countPairs(**test_input) == 11\n\ntest_input = { \"nums\": [-10,3,-5,2,-10,7,9], \"target\": 4 }\nassert my_solution.countPairs(**test_input) == 14\n\ntest_input = { \"nums\": [7,10,9,8,-9,1,-7,10,-4,2], \"target\": 4 }\nassert my_solution.countPairs(**test_input) == 21\n\ntest_input = { \"nums\": [9,-9,0,5,4], \"target\": 14 }\nassert my_solution.countPairs(**test_input) == 9\n\ntest_input = { \"nums\": [7,9,7,-10,-6,-8,-5], \"target\": 2 }\nassert my_solution.countPairs(**test_input) == 14\n\ntest_input = { \"nums\": [8,-5,0,4], \"target\": 0 }\nassert my_solution.countPairs(**test_input) == 2\n\ntest_input = { \"nums\": [5,2,-1,9,-1,-1], \"target\": 4 }\nassert my_solution.countPairs(**test_input) == 6\n\ntest_input = { \"nums\": [-7,-4,3,9,10,5,-1,1,-7], \"target\": -4 }\nassert my_solution.countPairs(**test_input) == 8\n\ntest_input = { \"nums\": [0,8,9,-9,8,-2,-1,2,5], \"target\": -1 }\nassert my_solution.countPairs(**test_input) == 7\n\ntest_input = { \"nums\": [10,4,-9,8,-10,3], \"target\": -7 }\nassert my_solution.countPairs(**test_input) == 1\n\ntest_input = { \"nums\": [-6,-6,6,-4,-5,-1,10,-8,1], \"target\": -13 }\nassert my_solution.countPairs(**test_input) == 2\n\ntest_input = { \"nums\": [7,3,-4,1,-9,-8,10,4,-1], \"target\": -2 }\nassert my_solution.countPairs(**test_input) == 13\n\ntest_input = { \"nums\": [4,3,-3,1,-3,-1], \"target\": -2 }\nassert my_solution.countPairs(**test_input) == 3\n\ntest_input = { \"nums\": [10,-8,-9,-7,2,-10,4,7,6,6], \"target\": 14 }\nassert my_solution.countPairs(**test_input) == 41\n\ntest_input = { \"nums\": [9,-5,-4,-2,9], \"target\": 4 }\nassert my_solution.countPairs(**test_input) == 3\n\ntest_input = { \"nums\": [-1,2,-3,-4,-10,-8,2], \"target\": -1 }\nassert my_solution.countPairs(**test_input) == 16\n\ntest_input = { \"nums\": [-8,-9,-10,0,-5,-5], \"target\": -15 }\nassert my_solution.countPairs(**test_input) == 3\n\ntest_input = { \"nums\": [-8,9,-10,2,-10,-6,-1,-8], \"target\": -4 }\nassert my_solution.countPairs(**test_input) == 19\n\ntest_input = { \"nums\": [4,-7,8,7,-4,3,7,7,-2,-10], \"target\": 4 }\nassert my_solution.countPairs(**test_input) == 25\n\ntest_input = { \"nums\": [6,3,4,5,-4], \"target\": 0 }\nassert my_solution.countPairs(**test_input) == 1\n\ntest_input = { \"nums\": [2,-4,5,3,7,10,9,-1,9,0], \"target\": 9 }\nassert my_solution.countPairs(**test_input) == 23\n\ntest_input = { \"nums\": [-2,-5,9,-3,-8,5,-1,3,-9], \"target\": 1 }\nassert my_solution.countPairs(**test_input) == 23\n\ntest_input = { \"nums\": [0,-2,-3,-1,-6,-7,3], \"target\": -10 }\nassert my_solution.countPairs(**test_input) == 1\n\ntest_input = { \"nums\": [10,4,-3,9,-8,6], \"target\": 14 }\nassert my_solution.countPairs(**test_input) == 11\n\ntest_input = { \"nums\": [-10,-6,6,-7,1,-7,9,3,1], \"target\": 15 }\nassert my_solution.countPairs(**test_input) == 35\n\ntest_input = { \"nums\": [2,-3,-6,-2,5], \"target\": -4 }\nassert my_solution.countPairs(**test_input) == 3\n\ntest_input = { \"nums\": [-10,-8,8,-2], \"target\": 0 }\nassert my_solution.countPairs(**test_input) == 4\n\ntest_input = { \"nums\": [-2,2,-7,-5,1,6,8], \"target\": 0 }\nassert my_solution.countPairs(**test_input) == 9\n\ntest_input = { \"nums\": [4,-4,-5,-8,9], \"target\": -10 }\nassert my_solution.countPairs(**test_input) == 2\n\ntest_input = { \"nums\": [-5,-4,-6,-7,9,-10,0,4,9,-1], \"target\": -7 }\nassert my_solution.countPairs(**test_input) == 13\n\ntest_input = { \"nums\": [-10,-6,6,-3,10,-6,4,-8], \"target\": -9 }\nassert my_solution.countPairs(**test_input) == 8\n\ntest_input = { \"nums\": [-8,-1,-9,1], \"target\": -17 }\nassert my_solution.countPairs(**test_input) == 0\n\ntest_input = { \"nums\": [6,-4,2,1,10,-1], \"target\": 1 }\nassert my_solution.countPairs(**test_input) == 4\n\ntest_input = { \"nums\": [9,4,-8,8,9,-4], \"target\": -16 }\nassert my_solution.countPairs(**test_input) == 0\n\ntest_input = { \"nums\": [9,-4,8,-9,-2,-2], \"target\": -11 }\nassert my_solution.countPairs(**test_input) == 1\n\ntest_input = { \"nums\": [-7,1,3,7,6,3], \"target\": 10 }\nassert my_solution.countPairs(**test_input) == 12\n\ntest_input = { \"nums\": [10,10,-2,-4], \"target\": 8 }\nassert my_solution.countPairs(**test_input) == 3\n\ntest_input = { \"nums\": [-3,2,6,-6,9], \"target\": 3 }\nassert my_solution.countPairs(**test_input) == 4\n\ntest_input = { \"nums\": [5,0,2,4,2,-7], \"target\": 2 }\nassert my_solution.countPairs(**test_input) == 5\n\ntest_input = { \"nums\": [4,-5,-4,-2,-9,-6,-10,-10,2,-8], \"target\": -19 }\nassert my_solution.countPairs(**test_input) == 1\n\ntest_input = { \"nums\": [-10,10,-9,-2,3,-2,-7,-1,-6,7], \"target\": -17 }\nassert my_solution.countPairs(**test_input) == 1\n\ntest_input = { \"nums\": [-9,-9,3,7,-9,-10,2,3,-4], \"target\": -13 }\nassert my_solution.countPairs(**test_input) == 7\n\ntest_input = { \"nums\": [-5,-4,-10,7], \"target\": 14 }\nassert my_solution.countPairs(**test_input) == 6\n\ntest_input = { \"nums\": [-3,4,-6,-6,1,-10,-1,-8], \"target\": -11 }\nassert my_solution.countPairs(**test_input) == 7\n\ntest_input = { \"nums\": [-7,1,-5,8,-7,-3,2,-2,-2,7], \"target\": -5 }\nassert my_solution.countPairs(**test_input) == 14\n\ntest_input = { \"nums\": [8,0,-8,-8,-1,5], \"target\": 0 }\nassert my_solution.countPairs(**test_input) == 8\n\ntest_input = { \"nums\": [9,7,2,4,3], \"target\": 7 }\nassert my_solution.countPairs(**test_input) == 2\n\ntest_input = { \"nums\": [8,-1,-5,7,7,5,-6,2], \"target\": -2 }\nassert my_solution.countPairs(**test_input) == 5\n\ntest_input = { \"nums\": [-1,3,3,3,9], \"target\": 8 }\nassert my_solution.countPairs(**test_input) == 6\n\ntest_input = { \"nums\": [-8,0,-1,-6,-9,2,3,1], \"target\": -9 }\nassert my_solution.countPairs(**test_input) == 4\n\ntest_input = { \"nums\": [3,-3,-7,-6,-5,-2], \"target\": -2 }\nassert my_solution.countPairs(**test_input) == 12\n\ntest_input = { \"nums\": [3,6,0,-4,-2,5], \"target\": -6 }\nassert my_solution.countPairs(**test_input) == 0\n\ntest_input = { \"nums\": [-8,9,2,5,9,-4,3], \"target\": 6 }\nassert my_solution.countPairs(**test_input) == 12\n\ntest_input = { \"nums\": [0,-6,-5,-8,-4,0,7], \"target\": 7 }\nassert my_solution.countPairs(**test_input) == 19\n\ntest_input = { \"nums\": [0,9,2,-4], \"target\": -8 }\nassert my_solution.countPairs(**test_input) == 0\n\ntest_input = { \"nums\": [-7,9,-3,-5,-9,-3,-8,-2,1,2], \"target\": -8 }\nassert my_solution.countPairs(**test_input) == 15\n\ntest_input = { \"nums\": [4,10,-7,0,-3,5,9,6,8,-4], \"target\": 13 }\nassert my_solution.countPairs(**test_input) == 34\n\ntest_input = { \"nums\": [2,-6,0,5,-9,-8,6,5], \"target\": -3 }\nassert my_solution.countPairs(**test_input) == 11\n\ntest_input = { \"nums\": [-4,6,-2,10,-5,-7,-8,-1], \"target\": -5 }\nassert my_solution.countPairs(**test_input) == 13\n\ntest_input = { \"nums\": [10,4,8,-1,9,-5,-1,-7,-9], \"target\": 19 }\nassert my_solution.countPairs(**test_input) == 35\n\ntest_input = { \"nums\": [-6,5,3,-2,0,3,-7,-7], \"target\": -8 }\nassert my_solution.countPairs(**test_input) == 5\n\ntest_input = { \"nums\": [-3,-1,7,4,-10,-6,2], \"target\": -4 }\nassert my_solution.countPairs(**test_input) == 7\n\ntest_input = { \"nums\": [-7,8,3,-1,2,1,-10], \"target\": -7 }\nassert my_solution.countPairs(**test_input) == 5\n\ntest_input = { \"nums\": [7,-3,-5,9,-10,-1,-3,-3,-3,1], \"target\": 6 }\nassert my_solution.countPairs(**test_input) == 36\n\ntest_input = { \"nums\": [-5,-10,-7,-3,-2,-2], \"target\": -15 }\nassert my_solution.countPairs(**test_input) == 1\n\ntest_input = { \"nums\": [-4,6,-9,-8,-9,-9], \"target\": -17 }\nassert my_solution.countPairs(**test_input) == 3\n\ntest_input = { \"nums\": [-3,-8,-6,-4,-8,-10,-2,5,-2], \"target\": 1 }\nassert my_solution.countPairs(**test_input) == 32\n\ntest_input = { \"nums\": [1,1,-6,8,2,10,-7,-9,-9], \"target\": -7 }\nassert my_solution.countPairs(**test_input) == 10\n\ntest_input = { \"nums\": [-9,-6,-3,5,-4], \"target\": 2 }\nassert my_solution.countPairs(**test_input) == 9\n\ntest_input = { \"nums\": [-5,10,-5,1,7,-8,8,-6,-6], \"target\": 2 }\nassert my_solution.countPairs(**test_input) == 19", "start_time": 1692455400} +{"task_id": "biweekly-contest-111-make-string-a-subsequence-using-cyclic-increments", "url": "https://leetcode.com/problems/make-string-a-subsequence-using-cyclic-increments", "title": "make-string-a-subsequence-using-cyclic-increments", "meta": {"questionId": "3018", "questionFrontendId": "2825", "title": "Make String a Subsequence Using Cyclic Increments", "titleSlug": "make-string-a-subsequence-using-cyclic-increments", "isPaidOnly": false, "difficulty": "Medium", "likes": 273, "dislikes": 9, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0 开始的字符串 str1 和 str2 。\n\n一次操作中,你选择 str1 中的若干下标。对于选中的每一个下标 i ,你将 str1[i] 循环 递增,变成下一个字符。也就是说 'a' 变成 'b' ,'b' 变成 'c' ,以此类推,'z' 变成 'a' 。\n\n如果执行以上操作 至多一次 ,可以让 str2 成为 str1 的子序列,请你返回 true ,否则返回 false 。\n\n注意:一个字符串的子序列指的是从原字符串中删除一些(可以一个字符也不删)字符后,剩下字符按照原本先后顺序组成的新字符串。\n\n示例 1:\n\n输入:str1 = \"abc\", str2 = \"ad\"\n输出:true\n解释:选择 str1 中的下标 2 。\n将 str1[2] 循环递增,得到 'd' 。\n因此,str1 变成 \"abd\" 且 str2 现在是一个子序列。所以返回 true 。\n\n示例 2:\n\n输入:str1 = \"zc\", str2 = \"ad\"\n输出:true\n解释:选择 str1 中的下标 0 和 1 。\n将 str1[0] 循环递增得到 'a' 。\n将 str1[1] 循环递增得到 'd' 。\n因此,str1 变成 \"ad\" 且 str2 现在是一个子序列。所以返回 true 。\n\n示例 3:\n\n输入:str1 = \"ab\", str2 = \"d\"\n输出:false\n解释:这个例子中,没法在执行一次操作的前提下,将 str2 变为 str1 的子序列。\n所以返回 false 。\n\n提示:\n\n * 1 <= str1.length <= 105\n * 1 <= str2.length <= 105\n * str1 和 str2 只包含小写英文字母。\n\"\"\"\nclass Solution:\n def canMakeSubsequence(self, str1: str, str2: str) -> bool:\n ", "prompt_sft": "给你一个下标从 0 开始的字符串 str1 和 str2 。\n\n一次操作中,你选择 str1 中的若干下标。对于选中的每一个下标 i ,你将 str1[i] 循环 递增,变成下一个字符。也就是说 'a' 变成 'b' ,'b' 变成 'c' ,以此类推,'z' 变成 'a' 。\n\n如果执行以上操作 至多一次 ,可以让 str2 成为 str1 的子序列,请你返回 true ,否则返回 false 。\n\n注意:一个字符串的子序列指的是从原字符串中删除一些(可以一个字符也不删)字符后,剩下字符按照原本先后顺序组成的新字符串。\n\n示例 1:\n\n输入:str1 = \"abc\", str2 = \"ad\"\n输出:true\n解释:选择 str1 中的下标 2 。\n将 str1[2] 循环递增,得到 'd' 。\n因此,str1 变成 \"abd\" 且 str2 现在是一个子序列。所以返回 true 。\n\n示例 2:\n\n输入:str1 = \"zc\", str2 = \"ad\"\n输出:true\n解释:选择 str1 中的下标 0 和 1 。\n将 str1[0] 循环递增得到 'a' 。\n将 str1[1] 循环递增得到 'd' 。\n因此,str1 变成 \"ad\" 且 str2 现在是一个子序列。所以返回 true 。\n\n示例 3:\n\n输入:str1 = \"ab\", str2 = \"d\"\n输出:false\n解释:这个例子中,没法在执行一次操作的前提下,将 str2 变为 str1 的子序列。\n所以返回 false 。\n\n提示:\n\n * 1 <= str1.length <= 105\n * 1 <= str2.length <= 105\n * str1 和 str2 只包含小写英文字母。\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def canMakeSubsequence(self, str1: str, str2: str) -> bool:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"str1\": \"ab\", \"str2\": \"d\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"a\", \"str2\": \"d\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"abc\", \"str2\": \"ad\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"b\", \"str2\": \"v\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"c\", \"str2\": \"b\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"c\", \"str2\": \"k\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"zc\", \"str2\": \"ad\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"b\", \"str2\": \"c\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"c\", \"str2\": \"m\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"d\", \"str2\": \"h\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"f\", \"str2\": \"f\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"f\", \"str2\": \"g\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"d\", \"str2\": \"m\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"g\", \"str2\": \"g\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"h\", \"str2\": \"i\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"d\", \"str2\": \"x\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"i\", \"str2\": \"j\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"j\", \"str2\": \"j\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"j\", \"str2\": \"k\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"f\", \"str2\": \"s\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"i\", \"str2\": \"e\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"k\", \"str2\": \"k\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"l\", \"str2\": \"d\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"k\", \"str2\": \"l\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"m\", \"str2\": \"e\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"l\", \"str2\": \"l\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"m\", \"str2\": \"n\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"o\", \"str2\": \"p\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"o\", \"str2\": \"c\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"o\", \"str2\": \"n\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"p\", \"str2\": \"a\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"p\", \"str2\": \"s\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"q\", \"str2\": \"q\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"q\", \"str2\": \"j\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"s\", \"str2\": \"f\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"s\", \"str2\": \"u\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"r\", \"str2\": \"s\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"t\", \"str2\": \"h\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"t\", \"str2\": \"k\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"t\", \"str2\": \"u\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"u\", \"str2\": \"w\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"u\", \"str2\": \"u\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"w\", \"str2\": \"y\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"u\", \"str2\": \"v\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"at\", \"str2\": \"se\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"cl\", \"str2\": \"qs\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"v\", \"str2\": \"v\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"w\", \"str2\": \"w\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"cq\", \"str2\": \"xz\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"y\", \"str2\": \"y\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"ct\", \"str2\": \"xb\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"z\", \"str2\": \"a\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"fs\", \"str2\": \"rd\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"z\", \"str2\": \"z\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"gq\", \"str2\": \"kn\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"hq\", \"str2\": \"dk\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"dm\", \"str2\": \"e\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"eh\", \"str2\": \"e\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"ir\", \"str2\": \"ka\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"is\", \"str2\": \"af\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"ja\", \"str2\": \"zz\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"jq\", \"str2\": \"zi\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"ke\", \"str2\": \"qw\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"fp\", \"str2\": \"p\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"hz\", \"str2\": \"z\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"ia\", \"str2\": \"a\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"lo\", \"str2\": \"fa\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"km\", \"str2\": \"l\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"mu\", \"str2\": \"za\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"np\", \"str2\": \"q\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"nh\", \"str2\": \"pa\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"oj\", \"str2\": \"j\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"oh\", \"str2\": \"hu\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"pg\", \"str2\": \"xb\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"uq\", \"str2\": \"v\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"pl\", \"str2\": \"yi\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"ww\", \"str2\": \"x\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"xh\", \"str2\": \"x\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"yg\", \"str2\": \"y\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"px\", \"str2\": \"dh\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"rm\", \"str2\": \"au\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"se\", \"str2\": \"vs\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"yw\", \"str2\": \"w\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"st\", \"str2\": \"zf\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"dby\", \"str2\": \"z\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"sx\", \"str2\": \"fx\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"ei\", \"str2\": \"ei\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"ff\", \"str2\": \"fg\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"to\", \"str2\": \"yv\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"tv\", \"str2\": \"ei\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"va\", \"str2\": \"ow\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"jc\", \"str2\": \"jd\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"jrg\", \"str2\": \"h\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"lf\", \"str2\": \"lg\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"agb\", \"str2\": \"vgz\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"amk\", \"str2\": \"nto\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"atd\", \"str2\": \"xrr\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"pc\", \"str2\": \"qc\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"ayt\", \"str2\": \"nov\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"qv\", \"str2\": \"rv\" }\nassert my_solution.canMakeSubsequence(**test_input) == True", "start_time": 1692455400} +{"task_id": "biweekly-contest-111-sorting-three-groups", "url": "https://leetcode.com/problems/sorting-three-groups", "title": "sorting-three-groups", "meta": {"questionId": "2904", "questionFrontendId": "2826", "title": "Sorting Three Groups", "titleSlug": "sorting-three-groups", "isPaidOnly": false, "difficulty": "Medium", "likes": 347, "dislikes": 72, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0 开始长度为 n 的整数数组 nums 。\n\n从 0 到 n - 1 的数字被分为编号从 1 到 3 的三个组,数字 i 属于组 nums[i] 。注意,有的组可能是 空的 。\n\n你可以执行以下操作任意次:\n\n * 选择数字 x 并改变它的组。更正式的,你可以将 nums[x] 改为数字 1 到 3 中的任意一个。\n\n你将按照以下过程构建一个新的数组 res :\n\n 1. 将每个组中的数字分别排序。\n 2. 将组 1 ,2 和 3 中的元素 依次 连接以得到 res 。\n\n如果得到的 res 是 非递减顺序的,那么我们称数组 nums 是 美丽数组 。\n\n请你返回将 nums 变为 美丽数组 需要的最少步数。\n\n示例 1:\n\n输入:nums = [2,1,3,2,1]\n输出:3\n解释:以下三步操作是最优方案:\n1. 将 nums[0] 变为 1 。\n2. 将 nums[2] 变为 1 。\n3. 将 nums[3] 变为 1 。\n执行以上操作后,将每组中的数字排序,组 1 为 [0,1,2,3,4] ,组 2 和组 3 都为空。所以 res 等于 [0,1,2,3,4] ,它是非递减顺序的。\n三步操作是最少需要的步数。\n\n示例 2:\n\n输入:nums = [1,3,2,1,3,3]\n输出:2\n解释:以下两步操作是最优方案:\n1. 将 nums[1] 变为 1 。\n2. 将 nums[2] 变为 1 。\n执行以上操作后,将每组中的数字排序,组 1 为 [0,1,2,3] ,组 2 为空,组 3 为 [4,5] 。所以 res 等于 [0,1,2,3,4,5] ,它是非递减顺序的。\n两步操作是最少需要的步数。\n\n示例 3:\n\n输入:nums = [2,2,2,2,3,3]\n输出:0\n解释:不需要执行任何操作。\n组 1 为空,组 2 为 [0,1,2,3] ,组 3 为 [4,5] 。所以 res 等于 [0,1,2,3,4,5] ,它是非递减顺序的。\n\n\n提示:\n\n * 1 <= nums.length <= 100\n * 1 <= nums[i] <= 3\n\"\"\"\nclass Solution:\n def minimumOperations(self, nums: List[int]) -> int:\n ", "prompt_sft": "给你一个下标从 0 开始长度为 n 的整数数组 nums 。\n\n从 0 到 n - 1 的数字被分为编号从 1 到 3 的三个组,数字 i 属于组 nums[i] 。注意,有的组可能是 空的 。\n\n你可以执行以下操作任意次:\n\n * 选择数字 x 并改变它的组。更正式的,你可以将 nums[x] 改为数字 1 到 3 中的任意一个。\n\n你将按照以下过程构建一个新的数组 res :\n\n 1. 将每个组中的数字分别排序。\n 2. 将组 1 ,2 和 3 中的元素 依次 连接以得到 res 。\n\n如果得到的 res 是 非递减顺序的,那么我们称数组 nums 是 美丽数组 。\n\n请你返回将 nums 变为 美丽数组 需要的最少步数。\n\n示例 1:\n\n输入:nums = [2,1,3,2,1]\n输出:3\n解释:以下三步操作是最优方案:\n1. 将 nums[0] 变为 1 。\n2. 将 nums[2] 变为 1 。\n3. 将 nums[3] 变为 1 。\n执行以上操作后,将每组中的数字排序,组 1 为 [0,1,2,3,4] ,组 2 和组 3 都为空。所以 res 等于 [0,1,2,3,4] ,它是非递减顺序的。\n三步操作是最少需要的步数。\n\n示例 2:\n\n输入:nums = [1,3,2,1,3,3]\n输出:2\n解释:以下两步操作是最优方案:\n1. 将 nums[1] 变为 1 。\n2. 将 nums[2] 变为 1 。\n执行以上操作后,将每组中的数字排序,组 1 为 [0,1,2,3] ,组 2 为空,组 3 为 [4,5] 。所以 res 等于 [0,1,2,3,4,5] ,它是非递减顺序的。\n两步操作是最少需要的步数。\n\n示例 3:\n\n输入:nums = [2,2,2,2,3,3]\n输出:0\n解释:不需要执行任何操作。\n组 1 为空,组 2 为 [0,1,2,3] ,组 3 为 [4,5] 。所以 res 等于 [0,1,2,3,4,5] ,它是非递减顺序的。\n\n\n提示:\n\n * 1 <= nums.length <= 100\n * 1 <= nums[i] <= 3\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def minimumOperations(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [2,1,3,2,1] }\nassert my_solution.minimumOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,3,2,1,3,3] }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"nums\": [2,2,2,2,3,3] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [1] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [2] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [3] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [1,2] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [2,2] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [3,2] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,3] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [2,3] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [3,3] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,2] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [2,1,2] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [3,1,2] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,2] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [2,2,2] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [3,2,2] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,3,2] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [2,3,2] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [3,3,2] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,3] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [2,1,3] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [3,1,3] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,3] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [2,2,3] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [3,2,3] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,3,3] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [2,3,3] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [3,3,3] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,1,2] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [2,1,1,2] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [3,1,1,2] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,1,2] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [2,2,1,2] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [3,2,1,2] }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,3,1,2] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [2,3,1,2] }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"nums\": [3,3,1,2] }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,2,2] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [2,1,2,2] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [3,1,2,2] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,2,2] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [2,2,2,2] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [3,2,2,2] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,3,2,2] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [2,3,2,2] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [3,3,2,2] }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,3,2] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [2,1,3,2] }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"nums\": [3,1,3,2] }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,2,3,2] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [2,2,3,2] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [3,2,3,2] }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,3,3,2] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [2,3,3,2] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [3,3,3,2] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,1,3] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [2,1,1,3] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [3,1,1,3] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,1,3] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [2,2,1,3] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [3,2,1,3] }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,3,1,3] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [2,3,1,3] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [3,3,1,3] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,2,3] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [2,1,2,3] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [3,1,2,3] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,2,3] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [2,2,2,3] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [3,2,2,3] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,3,2,3] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [2,3,2,3] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [3,3,2,3] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,3,3] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [2,1,3,3] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [3,1,3,3] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,3,3] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [2,2,3,3] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [3,2,3,3] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,3,3,3] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [2,3,3,3] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [3,3,3,3] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,1,1,2] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [2,1,1,1,2] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [3,1,1,1,2] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,1,1,2] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [2,2,1,1,2] }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"nums\": [3,2,1,1,2] }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,3,1,1,2] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [2,3,1,1,2] }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"nums\": [3,3,1,1,2] }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,2,1,2] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [2,1,2,1,2] }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"nums\": [3,1,2,1,2] }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,2,2,1,2] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [2,2,2,1,2] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [3,2,2,1,2] }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,3,2,1,2] }\nassert my_solution.minimumOperations(**test_input) == 2", "start_time": 1692455400} +{"task_id": "biweekly-contest-111-number-of-beautiful-integers-in-the-range", "url": "https://leetcode.com/problems/number-of-beautiful-integers-in-the-range", "title": "number-of-beautiful-integers-in-the-range", "meta": {"questionId": "3017", "questionFrontendId": "2827", "title": "Number of Beautiful Integers in the Range", "titleSlug": "number-of-beautiful-integers-in-the-range", "isPaidOnly": false, "difficulty": "Hard", "likes": 313, "dislikes": 24, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你正整数 low ,high 和 k 。\n\n如果一个数满足以下两个条件,那么它是 美丽的 :\n\n * 偶数数位的数目与奇数数位的数目相同。\n * 这个整数可以被 k 整除。\n\n请你返回范围 [low, high] 中美丽整数的数目。\n\n示例 1:\n\n输入:low = 10, high = 20, k = 3\n输出:2\n解释:给定范围中有 2 个美丽数字:[12,18]\n- 12 是美丽整数,因为它有 1 个奇数数位和 1 个偶数数位,而且可以被 k = 3 整除。\n- 18 是美丽整数,因为它有 1 个奇数数位和 1 个偶数数位,而且可以被 k = 3 整除。\n以下是一些不是美丽整数的例子:\n- 16 不是美丽整数,因为它不能被 k = 3 整除。\n- 15 不是美丽整数,因为它的奇数数位和偶数数位的数目不相等。\n给定范围内总共有 2 个美丽整数。\n\n示例 2:\n\n输入:low = 1, high = 10, k = 1\n输出:1\n解释:给定范围中有 1 个美丽数字:[10]\n- 10 是美丽整数,因为它有 1 个奇数数位和 1 个偶数数位,而且可以被 k = 1 整除。\n给定范围内总共有 1 个美丽整数。\n\n示例 3:\n\n输入:low = 5, high = 5, k = 2\n输出:0\n解释:给定范围中有 0 个美丽数字。\n- 5 不是美丽整数,因为它的奇数数位和偶数数位的数目不相等。\n\n\n提示:\n\n * 0 < low <= high <= 109\n * 0 < k <= 20\n\"\"\"\nclass Solution:\n def numberOfBeautifulIntegers(self, low: int, high: int, k: int) -> int:\n ", "prompt_sft": "给你正整数 low ,high 和 k 。\n\n如果一个数满足以下两个条件,那么它是 美丽的 :\n\n * 偶数数位的数目与奇数数位的数目相同。\n * 这个整数可以被 k 整除。\n\n请你返回范围 [low, high] 中美丽整数的数目。\n\n示例 1:\n\n输入:low = 10, high = 20, k = 3\n输出:2\n解释:给定范围中有 2 个美丽数字:[12,18]\n- 12 是美丽整数,因为它有 1 个奇数数位和 1 个偶数数位,而且可以被 k = 3 整除。\n- 18 是美丽整数,因为它有 1 个奇数数位和 1 个偶数数位,而且可以被 k = 3 整除。\n以下是一些不是美丽整数的例子:\n- 16 不是美丽整数,因为它不能被 k = 3 整除。\n- 15 不是美丽整数,因为它的奇数数位和偶数数位的数目不相等。\n给定范围内总共有 2 个美丽整数。\n\n示例 2:\n\n输入:low = 1, high = 10, k = 1\n输出:1\n解释:给定范围中有 1 个美丽数字:[10]\n- 10 是美丽整数,因为它有 1 个奇数数位和 1 个偶数数位,而且可以被 k = 1 整除。\n给定范围内总共有 1 个美丽整数。\n\n示例 3:\n\n输入:low = 5, high = 5, k = 2\n输出:0\n解释:给定范围中有 0 个美丽数字。\n- 5 不是美丽整数,因为它的奇数数位和偶数数位的数目不相等。\n\n\n提示:\n\n * 0 < low <= high <= 109\n * 0 < k <= 20\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def numberOfBeautifulIntegers(self, low: int, high: int, k: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"low\": 10, \"high\": 20, \"k\": 3 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 2\n\ntest_input = { \"low\": 1, \"high\": 10, \"k\": 1 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 1\n\ntest_input = { \"low\": 5, \"high\": 5, \"k\": 2 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 3, \"high\": 31, \"k\": 16 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 1\n\ntest_input = { \"low\": 25, \"high\": 31, \"k\": 11 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 9, \"high\": 25, \"k\": 4 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 2\n\ntest_input = { \"low\": 58, \"high\": 72, \"k\": 16 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 5, \"high\": 79, \"k\": 12 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 3\n\ntest_input = { \"low\": 26, \"high\": 74, \"k\": 7 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 4\n\ntest_input = { \"low\": 36, \"high\": 65, \"k\": 7 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 3\n\ntest_input = { \"low\": 12, \"high\": 84, \"k\": 8 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 4\n\ntest_input = { \"low\": 13, \"high\": 91, \"k\": 13 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 3\n\ntest_input = { \"low\": 8, \"high\": 18, \"k\": 4 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 2\n\ntest_input = { \"low\": 22, \"high\": 59, \"k\": 6 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 3\n\ntest_input = { \"low\": 15, \"high\": 27, \"k\": 9 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 2\n\ntest_input = { \"low\": 4, \"high\": 9, \"k\": 19 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 14, \"high\": 81, \"k\": 17 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 1\n\ntest_input = { \"low\": 12, \"high\": 33, \"k\": 18 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 1\n\ntest_input = { \"low\": 10, \"high\": 17, \"k\": 8 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 1\n\ntest_input = { \"low\": 42, \"high\": 58, \"k\": 3 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 2\n\ntest_input = { \"low\": 22, \"high\": 42, \"k\": 4 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 2\n\ntest_input = { \"low\": 5, \"high\": 8, \"k\": 5 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 12, \"high\": 75, \"k\": 13 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 2\n\ntest_input = { \"low\": 2, \"high\": 28, \"k\": 1 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 9\n\ntest_input = { \"low\": 29, \"high\": 35, \"k\": 17 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 1\n\ntest_input = { \"low\": 13, \"high\": 21, \"k\": 9 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 1\n\ntest_input = { \"low\": 1, \"high\": 13, \"k\": 15 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 12, \"high\": 21, \"k\": 16 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 1\n\ntest_input = { \"low\": 47, \"high\": 72, \"k\": 13 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 2\n\ntest_input = { \"low\": 1, \"high\": 35, \"k\": 12 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 1\n\ntest_input = { \"low\": 38, \"high\": 52, \"k\": 4 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 1\n\ntest_input = { \"low\": 10, \"high\": 74, \"k\": 3 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 11\n\ntest_input = { \"low\": 60, \"high\": 92, \"k\": 11 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 3, \"high\": 25, \"k\": 15 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 63, \"high\": 65, \"k\": 20 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 22, \"high\": 77, \"k\": 7 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 4\n\ntest_input = { \"low\": 1, \"high\": 1, \"k\": 4 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 28, \"high\": 73, \"k\": 20 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 21, \"high\": 32, \"k\": 6 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 1\n\ntest_input = { \"low\": 43, \"high\": 43, \"k\": 11 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 31, \"high\": 68, \"k\": 16 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 1\n\ntest_input = { \"low\": 1, \"high\": 8, \"k\": 4 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 47, \"high\": 100, \"k\": 18 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 3\n\ntest_input = { \"low\": 45, \"high\": 84, \"k\": 19 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 1\n\ntest_input = { \"low\": 31, \"high\": 80, \"k\": 11 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 14, \"high\": 14, \"k\": 5 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 21, \"high\": 88, \"k\": 10 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 3\n\ntest_input = { \"low\": 11, \"high\": 42, \"k\": 3 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 6\n\ntest_input = { \"low\": 19, \"high\": 53, \"k\": 16 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 1\n\ntest_input = { \"low\": 57, \"high\": 98, \"k\": 6 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 4\n\ntest_input = { \"low\": 57, \"high\": 69, \"k\": 9 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 1\n\ntest_input = { \"low\": 17, \"high\": 64, \"k\": 1 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 23\n\ntest_input = { \"low\": 29, \"high\": 40, \"k\": 15 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 1\n\ntest_input = { \"low\": 36, \"high\": 60, \"k\": 3 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 3\n\ntest_input = { \"low\": 16, \"high\": 23, \"k\": 13 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 36, \"high\": 99, \"k\": 3 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 11\n\ntest_input = { \"low\": 23, \"high\": 83, \"k\": 4 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 6\n\ntest_input = { \"low\": 4, \"high\": 5, \"k\": 9 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 15, \"high\": 21, \"k\": 2 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 2\n\ntest_input = { \"low\": 51, \"high\": 76, \"k\": 7 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 3\n\ntest_input = { \"low\": 24, \"high\": 34, \"k\": 8 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 1\n\ntest_input = { \"low\": 24, \"high\": 99, \"k\": 1 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 38\n\ntest_input = { \"low\": 37, \"high\": 63, \"k\": 10 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 1\n\ntest_input = { \"low\": 19, \"high\": 23, \"k\": 6 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 35, \"high\": 70, \"k\": 17 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 3, \"high\": 18, \"k\": 19 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 30, \"high\": 64, \"k\": 12 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 1\n\ntest_input = { \"low\": 3, \"high\": 12, \"k\": 9 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 14, \"high\": 21, \"k\": 16 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 1\n\ntest_input = { \"low\": 19, \"high\": 21, \"k\": 12 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 54, \"high\": 78, \"k\": 16 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 24, \"high\": 36, \"k\": 20 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 54, \"high\": 58, \"k\": 13 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 74, \"high\": 88, \"k\": 12 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 45, \"high\": 58, \"k\": 14 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 1\n\ntest_input = { \"low\": 51, \"high\": 99, \"k\": 8 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 3\n\ntest_input = { \"low\": 8, \"high\": 26, \"k\": 13 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 12, \"high\": 92, \"k\": 3 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 15\n\ntest_input = { \"low\": 18, \"high\": 91, \"k\": 11 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 14, \"high\": 53, \"k\": 15 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 2\n\ntest_input = { \"low\": 4, \"high\": 10, \"k\": 11 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 7, \"high\": 24, \"k\": 5 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 1\n\ntest_input = { \"low\": 1, \"high\": 25, \"k\": 8 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 1\n\ntest_input = { \"low\": 7, \"high\": 20, \"k\": 15 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 51, \"high\": 92, \"k\": 1 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 21\n\ntest_input = { \"low\": 73, \"high\": 73, \"k\": 3 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 50, \"high\": 63, \"k\": 19 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 30, \"high\": 51, \"k\": 19 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 1\n\ntest_input = { \"low\": 2, \"high\": 65, \"k\": 7 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 5\n\ntest_input = { \"low\": 49, \"high\": 87, \"k\": 20 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 3, \"high\": 6, \"k\": 1 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 16, \"high\": 17, \"k\": 6 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 17, \"high\": 32, \"k\": 16 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 1\n\ntest_input = { \"low\": 13, \"high\": 14, \"k\": 6 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 25, \"high\": 42, \"k\": 11 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 18, \"high\": 46, \"k\": 5 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 3\n\ntest_input = { \"low\": 1, \"high\": 65, \"k\": 6 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 5\n\ntest_input = { \"low\": 6, \"high\": 43, \"k\": 15 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 1\n\ntest_input = { \"low\": 5, \"high\": 9, \"k\": 12 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 1, \"high\": 75, \"k\": 9 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 7", "start_time": 1692455400} +{"task_id": "weekly-contest-358-max-pair-sum-in-an-array", "url": "https://leetcode.com/problems/max-pair-sum-in-an-array", "title": "max-pair-sum-in-an-array", "meta": {"questionId": "2902", "questionFrontendId": "2815", "title": "Max Pair Sum in an Array", "titleSlug": "max-pair-sum-in-an-array", "isPaidOnly": false, "difficulty": "Easy", "likes": 274, "dislikes": 91, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0 开始的整数数组 nums 。请你从 nums 中找出和 最大 的一对数,且这两个数数位上最大的数字相等。\n\n返回最大和,如果不存在满足题意的数字对,返回 -1 。\n\n示例 1:\n\n输入:nums = [51,71,17,24,42]\n输出:88\n解释:\ni = 1 和 j = 2 ,nums[i] 和 nums[j] 数位上最大的数字相等,且这一对的总和 71 + 17 = 88 。\ni = 3 和 j = 4 ,nums[i] 和 nums[j] 数位上最大的数字相等,且这一对的总和 24 + 42 = 66 。\n可以证明不存在其他数对满足数位上最大的数字相等,所以答案是 88 。\n\n示例 2:\n\n输入:nums = [1,2,3,4]\n输出:-1\n解释:不存在数对满足数位上最大的数字相等。\n\n\n提示:\n\n * 2 <= nums.length <= 100\n * 1 <= nums[i] <= 104\n\"\"\"\nclass Solution:\n def maxSum(self, nums: List[int]) -> int:\n ", "prompt_sft": "给你一个下标从 0 开始的整数数组 nums 。请你从 nums 中找出和 最大 的一对数,且这两个数数位上最大的数字相等。\n\n返回最大和,如果不存在满足题意的数字对,返回 -1 。\n\n示例 1:\n\n输入:nums = [51,71,17,24,42]\n输出:88\n解释:\ni = 1 和 j = 2 ,nums[i] 和 nums[j] 数位上最大的数字相等,且这一对的总和 71 + 17 = 88 。\ni = 3 和 j = 4 ,nums[i] 和 nums[j] 数位上最大的数字相等,且这一对的总和 24 + 42 = 66 。\n可以证明不存在其他数对满足数位上最大的数字相等,所以答案是 88 。\n\n示例 2:\n\n输入:nums = [1,2,3,4]\n输出:-1\n解释:不存在数对满足数位上最大的数字相等。\n\n\n提示:\n\n * 2 <= nums.length <= 100\n * 1 <= nums[i] <= 104\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def maxSum(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [51,71,17,24,42] }\nassert my_solution.maxSum(**test_input) == 88\n\ntest_input = { \"nums\": [1,2,3,4] }\nassert my_solution.maxSum(**test_input) == -1\n\ntest_input = { \"nums\": [31,25,72,79,74] }\nassert my_solution.maxSum(**test_input) == 146\n\ntest_input = { \"nums\": [84,91,18,59,27,9,81,33,17,58] }\nassert my_solution.maxSum(**test_input) == 165\n\ntest_input = { \"nums\": [8,75,28,35,21,13,21] }\nassert my_solution.maxSum(**test_input) == 42\n\ntest_input = { \"nums\": [35,52,74,92,25,65,77,1,73,32] }\nassert my_solution.maxSum(**test_input) == 151\n\ntest_input = { \"nums\": [68,8,100,84,80,14,88] }\nassert my_solution.maxSum(**test_input) == 172\n\ntest_input = { \"nums\": [53,98,69,64,40,60,23] }\nassert my_solution.maxSum(**test_input) == 167\n\ntest_input = { \"nums\": [21,76] }\nassert my_solution.maxSum(**test_input) == -1\n\ntest_input = { \"nums\": [99,63,23,70,18,64] }\nassert my_solution.maxSum(**test_input) == 127\n\ntest_input = { \"nums\": [21,21,78] }\nassert my_solution.maxSum(**test_input) == 42\n\ntest_input = { \"nums\": [58,88,58,99,26,92] }\nassert my_solution.maxSum(**test_input) == 191\n\ntest_input = { \"nums\": [10,24,25,20,92,73,63,51] }\nassert my_solution.maxSum(**test_input) == 76\n\ntest_input = { \"nums\": [87,6,17,32,14,42,46,65,43,9] }\nassert my_solution.maxSum(**test_input) == 111\n\ntest_input = { \"nums\": [96,46,85,19,29] }\nassert my_solution.maxSum(**test_input) == 125\n\ntest_input = { \"nums\": [5,24] }\nassert my_solution.maxSum(**test_input) == -1\n\ntest_input = { \"nums\": [26,76,24,96,82,97,97,72,35] }\nassert my_solution.maxSum(**test_input) == 194\n\ntest_input = { \"nums\": [77,82,30,94] }\nassert my_solution.maxSum(**test_input) == -1\n\ntest_input = { \"nums\": [76,94,51,82,3,89,52,96] }\nassert my_solution.maxSum(**test_input) == 190\n\ntest_input = { \"nums\": [27,59,57,97,6,46,88,41,52,46] }\nassert my_solution.maxSum(**test_input) == 156\n\ntest_input = { \"nums\": [17,2] }\nassert my_solution.maxSum(**test_input) == -1\n\ntest_input = { \"nums\": [62,69] }\nassert my_solution.maxSum(**test_input) == -1\n\ntest_input = { \"nums\": [63,24,1] }\nassert my_solution.maxSum(**test_input) == -1\n\ntest_input = { \"nums\": [55,46,4,61,78,21,85,52,83,77] }\nassert my_solution.maxSum(**test_input) == 168\n\ntest_input = { \"nums\": [21,73,2,80,99,98,89] }\nassert my_solution.maxSum(**test_input) == 197\n\ntest_input = { \"nums\": [94,63,50,43,62,14,83,91] }\nassert my_solution.maxSum(**test_input) == 185\n\ntest_input = { \"nums\": [66,17,17,35,46,77,7,15,38] }\nassert my_solution.maxSum(**test_input) == 112\n\ntest_input = { \"nums\": [61,90,34,29,68,35] }\nassert my_solution.maxSum(**test_input) == 119\n\ntest_input = { \"nums\": [18,82,78] }\nassert my_solution.maxSum(**test_input) == 160\n\ntest_input = { \"nums\": [8,71,2,59,70,12] }\nassert my_solution.maxSum(**test_input) == 141\n\ntest_input = { \"nums\": [55,88,59] }\nassert my_solution.maxSum(**test_input) == -1\n\ntest_input = { \"nums\": [49,47,46,65,37,24,75,81,54,39] }\nassert my_solution.maxSum(**test_input) == 122\n\ntest_input = { \"nums\": [73,79,48,45,57,73,51,78,67,78] }\nassert my_solution.maxSum(**test_input) == 156\n\ntest_input = { \"nums\": [2,82,80,74,34,54,65] }\nassert my_solution.maxSum(**test_input) == 162\n\ntest_input = { \"nums\": [9,62,85,95,36,62,21,38,16,12] }\nassert my_solution.maxSum(**test_input) == 124\n\ntest_input = { \"nums\": [50,80,34,9,86,20,67,94,65,82] }\nassert my_solution.maxSum(**test_input) == 168\n\ntest_input = { \"nums\": [79,74,92,84,37,19] }\nassert my_solution.maxSum(**test_input) == 171\n\ntest_input = { \"nums\": [85,20,79] }\nassert my_solution.maxSum(**test_input) == -1\n\ntest_input = { \"nums\": [89,55,67,84,3] }\nassert my_solution.maxSum(**test_input) == -1\n\ntest_input = { \"nums\": [16,44,2,54,58,94] }\nassert my_solution.maxSum(**test_input) == -1\n\ntest_input = { \"nums\": [71,14,24,13,21,14,100,18,84,37] }\nassert my_solution.maxSum(**test_input) == 108\n\ntest_input = { \"nums\": [13,26] }\nassert my_solution.maxSum(**test_input) == -1\n\ntest_input = { \"nums\": [82,30,53,72,56,94,72,67] }\nassert my_solution.maxSum(**test_input) == 144\n\ntest_input = { \"nums\": [14,80,92,65,85,70] }\nassert my_solution.maxSum(**test_input) == 165\n\ntest_input = { \"nums\": [81,39,43,31,53,43,87,19,93] }\nassert my_solution.maxSum(**test_input) == 168\n\ntest_input = { \"nums\": [27,12,80,38,94,92,67,54,56,20] }\nassert my_solution.maxSum(**test_input) == 186\n\ntest_input = { \"nums\": [52,32,24,6,3,89,100,3,5,3] }\nassert my_solution.maxSum(**test_input) == 57\n\ntest_input = { \"nums\": [93,1,13,88,47,48,46,63] }\nassert my_solution.maxSum(**test_input) == 136\n\ntest_input = { \"nums\": [3,55,40,93,97,37,31,31] }\nassert my_solution.maxSum(**test_input) == 190\n\ntest_input = { \"nums\": [58,41,10,74,40,17] }\nassert my_solution.maxSum(**test_input) == 91\n\ntest_input = { \"nums\": [58,33,78,53,88,1,15,44,82] }\nassert my_solution.maxSum(**test_input) == 170\n\ntest_input = { \"nums\": [41,48,96,71,35,89,57,71] }\nassert my_solution.maxSum(**test_input) == 185\n\ntest_input = { \"nums\": [43,4,69,29,37,50] }\nassert my_solution.maxSum(**test_input) == 98\n\ntest_input = { \"nums\": [65,88,2] }\nassert my_solution.maxSum(**test_input) == -1\n\ntest_input = { \"nums\": [86,42,59,44,76,6] }\nassert my_solution.maxSum(**test_input) == 86\n\ntest_input = { \"nums\": [29,96,1,10,27,78,56,62] }\nassert my_solution.maxSum(**test_input) == 125\n\ntest_input = { \"nums\": [100,48,6] }\nassert my_solution.maxSum(**test_input) == -1\n\ntest_input = { \"nums\": [33,17] }\nassert my_solution.maxSum(**test_input) == -1\n\ntest_input = { \"nums\": [8,91] }\nassert my_solution.maxSum(**test_input) == -1\n\ntest_input = { \"nums\": [91,13,72,42,28] }\nassert my_solution.maxSum(**test_input) == -1\n\ntest_input = { \"nums\": [5,53,35,88,77,1,66,57] }\nassert my_solution.maxSum(**test_input) == 134\n\ntest_input = { \"nums\": [50,27,52,70,67,60,65] }\nassert my_solution.maxSum(**test_input) == 137\n\ntest_input = { \"nums\": [84,82,31,45,94,62,45,32] }\nassert my_solution.maxSum(**test_input) == 166\n\ntest_input = { \"nums\": [61,61,61,23,47,34,21,6,65,25] }\nassert my_solution.maxSum(**test_input) == 126\n\ntest_input = { \"nums\": [60,21,11,99] }\nassert my_solution.maxSum(**test_input) == -1\n\ntest_input = { \"nums\": [22,83,62,12,63,100,41,33] }\nassert my_solution.maxSum(**test_input) == 125\n\ntest_input = { \"nums\": [92,58,85] }\nassert my_solution.maxSum(**test_input) == 143\n\ntest_input = { \"nums\": [93,5,46,26,25,36,27,12,30] }\nassert my_solution.maxSum(**test_input) == 82\n\ntest_input = { \"nums\": [52,30,16] }\nassert my_solution.maxSum(**test_input) == -1\n\ntest_input = { \"nums\": [22,57,33,26,76,14,67] }\nassert my_solution.maxSum(**test_input) == 143\n\ntest_input = { \"nums\": [90,72,37,30] }\nassert my_solution.maxSum(**test_input) == 109\n\ntest_input = { \"nums\": [44,87,16] }\nassert my_solution.maxSum(**test_input) == -1\n\ntest_input = { \"nums\": [19,12,52,8,3,58] }\nassert my_solution.maxSum(**test_input) == 66\n\ntest_input = { \"nums\": [88,52,35,6,58,47,62,82,47,86] }\nassert my_solution.maxSum(**test_input) == 174\n\ntest_input = { \"nums\": [84,1,48,76,16,10,11,60] }\nassert my_solution.maxSum(**test_input) == 132\n\ntest_input = { \"nums\": [12,60,69,63,78,22,28] }\nassert my_solution.maxSum(**test_input) == 123\n\ntest_input = { \"nums\": [16,28,82,77,41,22] }\nassert my_solution.maxSum(**test_input) == 110\n\ntest_input = { \"nums\": [97,31,63,2,94,14,47] }\nassert my_solution.maxSum(**test_input) == 191\n\ntest_input = { \"nums\": [93,100,45,74,31,41,84,90,18,21] }\nassert my_solution.maxSum(**test_input) == 183\n\ntest_input = { \"nums\": [21,12,38,64,57,24] }\nassert my_solution.maxSum(**test_input) == 33\n\ntest_input = { \"nums\": [33,17,99,2,58,59,72,9,62] }\nassert my_solution.maxSum(**test_input) == 158\n\ntest_input = { \"nums\": [36,11,23,98,14,89,90,53] }\nassert my_solution.maxSum(**test_input) == 188\n\ntest_input = { \"nums\": [57,90,5,78,84,51] }\nassert my_solution.maxSum(**test_input) == 162\n\ntest_input = { \"nums\": [73,73,76,48,30] }\nassert my_solution.maxSum(**test_input) == 149\n\ntest_input = { \"nums\": [2,74,37,75] }\nassert my_solution.maxSum(**test_input) == 149\n\ntest_input = { \"nums\": [84,35,65,12] }\nassert my_solution.maxSum(**test_input) == -1\n\ntest_input = { \"nums\": [95,46,23,81,35] }\nassert my_solution.maxSum(**test_input) == -1\n\ntest_input = { \"nums\": [64,76,46,54,64,94,90,95] }\nassert my_solution.maxSum(**test_input) == 189\n\ntest_input = { \"nums\": [77,52,74,84,47,89,53] }\nassert my_solution.maxSum(**test_input) == 151\n\ntest_input = { \"nums\": [29,31,52,12,89,88,10,18] }\nassert my_solution.maxSum(**test_input) == 118\n\ntest_input = { \"nums\": [28,57,28,41,25,89,20] }\nassert my_solution.maxSum(**test_input) == 56\n\ntest_input = { \"nums\": [31,28] }\nassert my_solution.maxSum(**test_input) == -1\n\ntest_input = { \"nums\": [51,1,98,73,84,11,100,100,75] }\nassert my_solution.maxSum(**test_input) == 200\n\ntest_input = { \"nums\": [76,2,26,49,78,36,2,70,64] }\nassert my_solution.maxSum(**test_input) == 146\n\ntest_input = { \"nums\": [34,63,21,49] }\nassert my_solution.maxSum(**test_input) == -1\n\ntest_input = { \"nums\": [35,19,1,21,11,59,38] }\nassert my_solution.maxSum(**test_input) == 78\n\ntest_input = { \"nums\": [1,35,74,58,56,54,75] }\nassert my_solution.maxSum(**test_input) == 149\n\ntest_input = { \"nums\": [20,49] }\nassert my_solution.maxSum(**test_input) == -1\n\ntest_input = { \"nums\": [97,92,13,30] }\nassert my_solution.maxSum(**test_input) == 189\n\ntest_input = { \"nums\": [89,49,10,36,37] }\nassert my_solution.maxSum(**test_input) == 138", "start_time": 1691893800} +{"task_id": "weekly-contest-358-double-a-number-represented-as-a-linked-list", "url": "https://leetcode.com/problems/double-a-number-represented-as-a-linked-list", "title": "double-a-number-represented-as-a-linked-list", "meta": {"questionId": "2871", "questionFrontendId": "2816", "title": "Double a Number Represented as a Linked List", "titleSlug": "double-a-number-represented-as-a-linked-list", "isPaidOnly": false, "difficulty": "Medium", "likes": 397, "dislikes": 5, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个 非空 链表的头节点 head ,表示一个不含前导零的非负数整数。\n\n将链表 翻倍 后,返回头节点 head 。\n\n示例 1:\n\n[https://assets.leetcode.com/uploads/2023/05/28/example.png]\n\n输入:head = [1,8,9]\n输出:[3,7,8]\n解释:上图中给出的链表,表示数字 189 。返回的链表表示数字 189 * 2 = 378 。\n\n示例 2:\n\n[https://assets.leetcode.com/uploads/2023/05/28/example2.png]\n\n输入:head = [9,9,9]\n输出:[1,9,9,8]\n解释:上图中给出的链表,表示数字 999 。返回的链表表示数字 999 * 2 = 1998 。\n\n\n提示:\n\n * 链表中节点的数目在范围 [1, 104] 内\n * 0 <= Node.val <= 9\n * 生成的输入满足:链表表示一个不含前导零的数字,除了数字 0 本身。\n\"\"\"\n# Definition for singly-linked list.\nclass ListNode:\n def __init__(self, val=0, next=None):\n self.val = val\n self.next = next\nclass Solution:\n def doubleIt(self, head: Optional[ListNode]) -> Optional[ListNode]:\n ", "prompt_sft": "给你一个 非空 链表的头节点 head ,表示一个不含前导零的非负数整数。\n\n将链表 翻倍 后,返回头节点 head 。\n\n示例 1:\n\n[https://assets.leetcode.com/uploads/2023/05/28/example.png]\n\n输入:head = [1,8,9]\n输出:[3,7,8]\n解释:上图中给出的链表,表示数字 189 。返回的链表表示数字 189 * 2 = 378 。\n\n示例 2:\n\n[https://assets.leetcode.com/uploads/2023/05/28/example2.png]\n\n输入:head = [9,9,9]\n输出:[1,9,9,8]\n解释:上图中给出的链表,表示数字 999 。返回的链表表示数字 999 * 2 = 1998 。\n\n\n提示:\n\n * 链表中节点的数目在范围 [1, 104] 内\n * 0 <= Node.val <= 9\n * 生成的输入满足:链表表示一个不含前导零的数字,除了数字 0 本身。\n\n\n请完成下面的代码来解决上述问题:\n```python\n# Definition for singly-linked list.\nclass ListNode:\n def __init__(self, val=0, next=None):\n self.val = val\n self.next = next\nclass Solution:\n def doubleIt(self, head: Optional[ListNode]) -> Optional[ListNode]:\n \n```", "test": "\nmy_solution = Solution()\n\n_f1 = lambda lst: ListNode(lst[0], _f1(lst[1:])) if lst else None\n_f2 = lambda node: [node.val] + _f2(node.next) if node else []\n\n\ntest_input = { \"head\": _f1([1,8,9]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [3,7,8]\n\ntest_input = { \"head\": _f1([9,9,9]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,9,9,8]\n\ntest_input = { \"head\": _f1([0]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [0]\n\ntest_input = { \"head\": _f1([1]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [2]\n\ntest_input = { \"head\": _f1([2]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [4]\n\ntest_input = { \"head\": _f1([3]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [6]\n\ntest_input = { \"head\": _f1([4]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [8]\n\ntest_input = { \"head\": _f1([5]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,0]\n\ntest_input = { \"head\": _f1([6]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,2]\n\ntest_input = { \"head\": _f1([7]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,4]\n\ntest_input = { \"head\": _f1([8]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,6]\n\ntest_input = { \"head\": _f1([9]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,8]\n\ntest_input = { \"head\": _f1([1,0]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [2,0]\n\ntest_input = { \"head\": _f1([1,1]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [2,2]\n\ntest_input = { \"head\": _f1([1,2]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [2,4]\n\ntest_input = { \"head\": _f1([1,3]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [2,6]\n\ntest_input = { \"head\": _f1([1,4]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [2,8]\n\ntest_input = { \"head\": _f1([1,5]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [3,0]\n\ntest_input = { \"head\": _f1([1,6]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [3,2]\n\ntest_input = { \"head\": _f1([1,7]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [3,4]\n\ntest_input = { \"head\": _f1([1,8]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [3,6]\n\ntest_input = { \"head\": _f1([1,9]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [3,8]\n\ntest_input = { \"head\": _f1([2,0]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [4,0]\n\ntest_input = { \"head\": _f1([2,1]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [4,2]\n\ntest_input = { \"head\": _f1([2,2]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [4,4]\n\ntest_input = { \"head\": _f1([2,3]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [4,6]\n\ntest_input = { \"head\": _f1([2,4]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [4,8]\n\ntest_input = { \"head\": _f1([2,5]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [5,0]\n\ntest_input = { \"head\": _f1([2,6]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [5,2]\n\ntest_input = { \"head\": _f1([2,7]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [5,4]\n\ntest_input = { \"head\": _f1([2,8]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [5,6]\n\ntest_input = { \"head\": _f1([2,9]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [5,8]\n\ntest_input = { \"head\": _f1([3,0]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [6,0]\n\ntest_input = { \"head\": _f1([3,1]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [6,2]\n\ntest_input = { \"head\": _f1([3,2]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [6,4]\n\ntest_input = { \"head\": _f1([3,3]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [6,6]\n\ntest_input = { \"head\": _f1([3,4]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [6,8]\n\ntest_input = { \"head\": _f1([3,5]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [7,0]\n\ntest_input = { \"head\": _f1([3,6]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [7,2]\n\ntest_input = { \"head\": _f1([3,7]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [7,4]\n\ntest_input = { \"head\": _f1([3,8]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [7,6]\n\ntest_input = { \"head\": _f1([3,9]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [7,8]\n\ntest_input = { \"head\": _f1([4,0]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [8,0]\n\ntest_input = { \"head\": _f1([4,1]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [8,2]\n\ntest_input = { \"head\": _f1([4,2]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [8,4]\n\ntest_input = { \"head\": _f1([4,3]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [8,6]\n\ntest_input = { \"head\": _f1([4,4]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [8,8]\n\ntest_input = { \"head\": _f1([4,5]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [9,0]\n\ntest_input = { \"head\": _f1([4,6]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [9,2]\n\ntest_input = { \"head\": _f1([4,7]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [9,4]\n\ntest_input = { \"head\": _f1([4,8]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [9,6]\n\ntest_input = { \"head\": _f1([4,9]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [9,8]\n\ntest_input = { \"head\": _f1([5,0]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,0,0]\n\ntest_input = { \"head\": _f1([5,1]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,0,2]\n\ntest_input = { \"head\": _f1([5,2]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,0,4]\n\ntest_input = { \"head\": _f1([5,3]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,0,6]\n\ntest_input = { \"head\": _f1([5,4]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,0,8]\n\ntest_input = { \"head\": _f1([5,5]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,1,0]\n\ntest_input = { \"head\": _f1([5,6]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,1,2]\n\ntest_input = { \"head\": _f1([5,7]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,1,4]\n\ntest_input = { \"head\": _f1([5,8]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,1,6]\n\ntest_input = { \"head\": _f1([5,9]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,1,8]\n\ntest_input = { \"head\": _f1([6,0]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,2,0]\n\ntest_input = { \"head\": _f1([6,1]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,2,2]\n\ntest_input = { \"head\": _f1([6,2]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,2,4]\n\ntest_input = { \"head\": _f1([6,3]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,2,6]\n\ntest_input = { \"head\": _f1([6,4]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,2,8]\n\ntest_input = { \"head\": _f1([6,5]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,3,0]\n\ntest_input = { \"head\": _f1([6,6]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,3,2]\n\ntest_input = { \"head\": _f1([6,7]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,3,4]\n\ntest_input = { \"head\": _f1([6,8]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,3,6]\n\ntest_input = { \"head\": _f1([6,9]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,3,8]\n\ntest_input = { \"head\": _f1([7,0]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,4,0]\n\ntest_input = { \"head\": _f1([7,1]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,4,2]\n\ntest_input = { \"head\": _f1([7,2]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,4,4]\n\ntest_input = { \"head\": _f1([7,3]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,4,6]\n\ntest_input = { \"head\": _f1([7,4]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,4,8]\n\ntest_input = { \"head\": _f1([7,5]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,5,0]\n\ntest_input = { \"head\": _f1([7,6]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,5,2]\n\ntest_input = { \"head\": _f1([7,7]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,5,4]\n\ntest_input = { \"head\": _f1([7,8]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,5,6]\n\ntest_input = { \"head\": _f1([7,9]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,5,8]\n\ntest_input = { \"head\": _f1([8,0]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,6,0]\n\ntest_input = { \"head\": _f1([8,1]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,6,2]\n\ntest_input = { \"head\": _f1([8,2]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,6,4]\n\ntest_input = { \"head\": _f1([8,3]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,6,6]\n\ntest_input = { \"head\": _f1([8,4]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,6,8]\n\ntest_input = { \"head\": _f1([8,5]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,7,0]\n\ntest_input = { \"head\": _f1([8,6]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,7,2]\n\ntest_input = { \"head\": _f1([8,7]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,7,4]\n\ntest_input = { \"head\": _f1([8,8]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,7,6]\n\ntest_input = { \"head\": _f1([8,9]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,7,8]\n\ntest_input = { \"head\": _f1([9,0]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,8,0]\n\ntest_input = { \"head\": _f1([9,1]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,8,2]\n\ntest_input = { \"head\": _f1([9,2]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,8,4]\n\ntest_input = { \"head\": _f1([9,3]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,8,6]\n\ntest_input = { \"head\": _f1([9,4]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,8,8]\n\ntest_input = { \"head\": _f1([9,5]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,9,0]\n\ntest_input = { \"head\": _f1([9,6]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,9,2]\n\ntest_input = { \"head\": _f1([9,7]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,9,4]", "start_time": 1691893800} +{"task_id": "weekly-contest-358-minimum-absolute-difference-between-elements-with-constraint", "url": "https://leetcode.com/problems/minimum-absolute-difference-between-elements-with-constraint", "title": "minimum-absolute-difference-between-elements-with-constraint", "meta": {"questionId": "3000", "questionFrontendId": "2817", "title": "Minimum Absolute Difference Between Elements With Constraint", "titleSlug": "minimum-absolute-difference-between-elements-with-constraint", "isPaidOnly": false, "difficulty": "Medium", "likes": 618, "dislikes": 64, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0 开始的整数数组 nums 和一个整数 x 。\n\n请你找到数组中下标距离至少为 x 的两个元素的 差值绝对值 的 最小值 。\n\n换言之,请你找到两个下标 i 和 j ,满足 abs(i - j) >= x 且 abs(nums[i] - nums[j]) 的值最小。\n\n请你返回一个整数,表示下标距离至少为 x 的两个元素之间的差值绝对值的 最小值 。\n\n示例 1:\n\n输入:nums = [4,3,2,4], x = 2\n输出:0\n解释:我们选择 nums[0] = 4 和 nums[3] = 4 。\n它们下标距离满足至少为 2 ,差值绝对值为最小值 0 。\n0 是最优解。\n\n示例 2:\n\n输入:nums = [5,3,2,10,15], x = 1\n输出:1\n解释:我们选择 nums[1] = 3 和 nums[2] = 2 。\n它们下标距离满足至少为 1 ,差值绝对值为最小值 1 。\n1 是最优解。\n\n示例 3:\n\n输入:nums = [1,2,3,4], x = 3\n输出:3\n解释:我们选择 nums[0] = 1 和 nums[3] = 4 。\n它们下标距离满足至少为 3 ,差值绝对值为最小值 3 。\n3 是最优解。\n\n\n提示:\n\n * 1 <= nums.length <= 105\n * 1 <= nums[i] <= 109\n * 0 <= x < nums.length\n\"\"\"\nclass Solution:\n def minAbsoluteDifference(self, nums: List[int], x: int) -> int:\n ", "prompt_sft": "给你一个下标从 0 开始的整数数组 nums 和一个整数 x 。\n\n请你找到数组中下标距离至少为 x 的两个元素的 差值绝对值 的 最小值 。\n\n换言之,请你找到两个下标 i 和 j ,满足 abs(i - j) >= x 且 abs(nums[i] - nums[j]) 的值最小。\n\n请你返回一个整数,表示下标距离至少为 x 的两个元素之间的差值绝对值的 最小值 。\n\n示例 1:\n\n输入:nums = [4,3,2,4], x = 2\n输出:0\n解释:我们选择 nums[0] = 4 和 nums[3] = 4 。\n它们下标距离满足至少为 2 ,差值绝对值为最小值 0 。\n0 是最优解。\n\n示例 2:\n\n输入:nums = [5,3,2,10,15], x = 1\n输出:1\n解释:我们选择 nums[1] = 3 和 nums[2] = 2 。\n它们下标距离满足至少为 1 ,差值绝对值为最小值 1 。\n1 是最优解。\n\n示例 3:\n\n输入:nums = [1,2,3,4], x = 3\n输出:3\n解释:我们选择 nums[0] = 1 和 nums[3] = 4 。\n它们下标距离满足至少为 3 ,差值绝对值为最小值 3 。\n3 是最优解。\n\n\n提示:\n\n * 1 <= nums.length <= 105\n * 1 <= nums[i] <= 109\n * 0 <= x < nums.length\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def minAbsoluteDifference(self, nums: List[int], x: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [4,3,2,4], \"x\": 2 }\nassert my_solution.minAbsoluteDifference(**test_input) == 0\n\ntest_input = { \"nums\": [5,3,2,10,15], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,3,4], \"x\": 3 }\nassert my_solution.minAbsoluteDifference(**test_input) == 3\n\ntest_input = { \"nums\": [1,67], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 66\n\ntest_input = { \"nums\": [7,398], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 391\n\ntest_input = { \"nums\": [12,141], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 129\n\ntest_input = { \"nums\": [21,75], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 54\n\ntest_input = { \"nums\": [22,147], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 125\n\ntest_input = { \"nums\": [25,197], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 172\n\ntest_input = { \"nums\": [27,275], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 248\n\ntest_input = { \"nums\": [37,192], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 155\n\ntest_input = { \"nums\": [41,163], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 122\n\ntest_input = { \"nums\": [45,49], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 4\n\ntest_input = { \"nums\": [48,195], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 147\n\ntest_input = { \"nums\": [68,68], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 0\n\ntest_input = { \"nums\": [71,4], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 67\n\ntest_input = { \"nums\": [72,169], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 97\n\ntest_input = { \"nums\": [74,62], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 12\n\ntest_input = { \"nums\": [75,1], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 74\n\ntest_input = { \"nums\": [76,49], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 27\n\ntest_input = { \"nums\": [88,72], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 16\n\ntest_input = { \"nums\": [99,370], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 271\n\ntest_input = { \"nums\": [103,39], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 64\n\ntest_input = { \"nums\": [109,99], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 10\n\ntest_input = { \"nums\": [111,161], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 50\n\ntest_input = { \"nums\": [113,117], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 4\n\ntest_input = { \"nums\": [119,184], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 65\n\ntest_input = { \"nums\": [122,118], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 4\n\ntest_input = { \"nums\": [123,13], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 110\n\ntest_input = { \"nums\": [123,162], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 39\n\ntest_input = { \"nums\": [126,69], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 57\n\ntest_input = { \"nums\": [127,18], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 109\n\ntest_input = { \"nums\": [127,346], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 219\n\ntest_input = { \"nums\": [132,110], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 22\n\ntest_input = { \"nums\": [134,23], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 111\n\ntest_input = { \"nums\": [136,150], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 14\n\ntest_input = { \"nums\": [139,215], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 76\n\ntest_input = { \"nums\": [153,3], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 150\n\ntest_input = { \"nums\": [156,67], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 89\n\ntest_input = { \"nums\": [160,168], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 8\n\ntest_input = { \"nums\": [161,93], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 68\n\ntest_input = { \"nums\": [164,81], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 83\n\ntest_input = { \"nums\": [167,83], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 84\n\ntest_input = { \"nums\": [174,58], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 116\n\ntest_input = { \"nums\": [174,102], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 72\n\ntest_input = { \"nums\": [175,137], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 38\n\ntest_input = { \"nums\": [176,99], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 77\n\ntest_input = { \"nums\": [178,179], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 1\n\ntest_input = { \"nums\": [228,359], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 131\n\ntest_input = { \"nums\": [243,280], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 37\n\ntest_input = { \"nums\": [283,62], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 221\n\ntest_input = { \"nums\": [288,149], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 139\n\ntest_input = { \"nums\": [293,278], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 15\n\ntest_input = { \"nums\": [327,425], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 98\n\ntest_input = { \"nums\": [337,187], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 150\n\ntest_input = { \"nums\": [346,160], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 186\n\ntest_input = { \"nums\": [347,369], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 22\n\ntest_input = { \"nums\": [355,199], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 156\n\ntest_input = { \"nums\": [413,311], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 102\n\ntest_input = { \"nums\": [417,320], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 97\n\ntest_input = { \"nums\": [418,131], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 287\n\ntest_input = { \"nums\": [3274,71], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 3203\n\ntest_input = { \"nums\": [5,14,81], \"x\": 2 }\nassert my_solution.minAbsoluteDifference(**test_input) == 76\n\ntest_input = { \"nums\": [9,25,15], \"x\": 2 }\nassert my_solution.minAbsoluteDifference(**test_input) == 6\n\ntest_input = { \"nums\": [9,113,136], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 23\n\ntest_input = { \"nums\": [13,19,12], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 1\n\ntest_input = { \"nums\": [13,94,59], \"x\": 2 }\nassert my_solution.minAbsoluteDifference(**test_input) == 46\n\ntest_input = { \"nums\": [14,111,16], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 2\n\ntest_input = { \"nums\": [17,173,69], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 52\n\ntest_input = { \"nums\": [24,39,28], \"x\": 2 }\nassert my_solution.minAbsoluteDifference(**test_input) == 4\n\ntest_input = { \"nums\": [32,129,93], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 36\n\ntest_input = { \"nums\": [33,18,131], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 15\n\ntest_input = { \"nums\": [36,19,27], \"x\": 2 }\nassert my_solution.minAbsoluteDifference(**test_input) == 9\n\ntest_input = { \"nums\": [40,18,17], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 1\n\ntest_input = { \"nums\": [43,49,20], \"x\": 2 }\nassert my_solution.minAbsoluteDifference(**test_input) == 23\n\ntest_input = { \"nums\": [44,186,163], \"x\": 2 }\nassert my_solution.minAbsoluteDifference(**test_input) == 119\n\ntest_input = { \"nums\": [56,23,158], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 33\n\ntest_input = { \"nums\": [62,37,182], \"x\": 2 }\nassert my_solution.minAbsoluteDifference(**test_input) == 120\n\ntest_input = { \"nums\": [63,116,12], \"x\": 2 }\nassert my_solution.minAbsoluteDifference(**test_input) == 51\n\ntest_input = { \"nums\": [66,345,278], \"x\": 2 }\nassert my_solution.minAbsoluteDifference(**test_input) == 212\n\ntest_input = { \"nums\": [67,81,165], \"x\": 2 }\nassert my_solution.minAbsoluteDifference(**test_input) == 98\n\ntest_input = { \"nums\": [70,184,70], \"x\": 2 }\nassert my_solution.minAbsoluteDifference(**test_input) == 0\n\ntest_input = { \"nums\": [73,106,172], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 33\n\ntest_input = { \"nums\": [74,199,57], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 17\n\ntest_input = { \"nums\": [83,14,14], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 0\n\ntest_input = { \"nums\": [86,1,129], \"x\": 2 }\nassert my_solution.minAbsoluteDifference(**test_input) == 43\n\ntest_input = { \"nums\": [87,194,107], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 20\n\ntest_input = { \"nums\": [88,75,122], \"x\": 2 }\nassert my_solution.minAbsoluteDifference(**test_input) == 34\n\ntest_input = { \"nums\": [93,96,28], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 3\n\ntest_input = { \"nums\": [95,86,132], \"x\": 2 }\nassert my_solution.minAbsoluteDifference(**test_input) == 37\n\ntest_input = { \"nums\": [96,41,24], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 17\n\ntest_input = { \"nums\": [116,6,3], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 3\n\ntest_input = { \"nums\": [120,102,184], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 18\n\ntest_input = { \"nums\": [123,113,20], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 10\n\ntest_input = { \"nums\": [125,14,141], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 16\n\ntest_input = { \"nums\": [126,2,180], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 54\n\ntest_input = { \"nums\": [136,24,114], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 22\n\ntest_input = { \"nums\": [136,177,98], \"x\": 2 }\nassert my_solution.minAbsoluteDifference(**test_input) == 38\n\ntest_input = { \"nums\": [136,177,123], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 13\n\ntest_input = { \"nums\": [136,178,18], \"x\": 2 }\nassert my_solution.minAbsoluteDifference(**test_input) == 118", "start_time": 1691893800} +{"task_id": "weekly-contest-358-apply-operations-to-maximize-score", "url": "https://leetcode.com/problems/apply-operations-to-maximize-score", "title": "apply-operations-to-maximize-score", "meta": {"questionId": "3001", "questionFrontendId": "2818", "title": "Apply Operations to Maximize Score", "titleSlug": "apply-operations-to-maximize-score", "isPaidOnly": false, "difficulty": "Hard", "likes": 301, "dislikes": 9, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个长度为 n 的正整数数组 nums 和一个整数 k 。\n\n一开始,你的分数为 1 。你可以进行以下操作至多 k 次,目标是使你的分数最大:\n\n * 选择一个之前没有选过的 非空 子数组 nums[l, ..., r] 。\n * 从 nums[l, ..., r] 里面选择一个 质数分数 最高的元素 x 。如果多个元素质数分数相同且最高,选择下标最小的一个。\n * 将你的分数乘以 x 。\n\nnums[l, ..., r] 表示 nums 中起始下标为 l ,结束下标为 r 的子数组,两个端点都包含。\n\n一个整数的 质数分数 等于 x 不同质因子的数目。比方说, 300 的质数分数为 3 ,因为 300 = 2 * 2 * 3 * 5 * 5 。\n\n请你返回进行至多 k 次操作后,可以得到的 最大分数 。\n\n由于答案可能很大,请你将结果对 109 + 7 取余后返回。\n\n示例 1:\n\n输入:nums = [8,3,9,3,8], k = 2\n输出:81\n解释:进行以下操作可以得到分数 81 :\n- 选择子数组 nums[2, ..., 2] 。nums[2] 是子数组中唯一的元素。所以我们将分数乘以 nums[2] ,分数变为 1 * 9 = 9 。\n- 选择子数组 nums[2, ..., 3] 。nums[2] 和 nums[3] 质数分数都为 1 ,但是 nums[2] 下标更小。所以我们将分数乘以 nums[2] ,分数变为 9 * 9 = 81 。\n81 是可以得到的最高得分。\n\n示例 2:\n\n输入:nums = [19,12,14,6,10,18], k = 3\n输出:4788\n解释:进行以下操作可以得到分数 4788 :\n- 选择子数组 nums[0, ..., 0] 。nums[0] 是子数组中唯一的元素。所以我们将分数乘以 nums[0] ,分数变为 1 * 19 = 19 。\n- 选择子数组 nums[5, ..., 5] 。nums[5] 是子数组中唯一的元素。所以我们将分数乘以 nums[5] ,分数变为 19 * 18 = 342 。\n- 选择子数组 nums[2, ..., 3] 。nums[2] 和 nums[3] 质数分数都为 2,但是 nums[2] 下标更小。所以我们将分数乘以 nums[2] ,分数变为 342 * 14 = 4788 。\n4788 是可以得到的最高的分。\n\n\n提示:\n\n * 1 <= nums.length == n <= 105\n * 1 <= nums[i] <= 105\n * 1 <= k <= min(n * (n + 1) / 2, 109)\n\"\"\"\nclass Solution:\n def maximumScore(self, nums: List[int], k: int) -> int:\n ", "prompt_sft": "给你一个长度为 n 的正整数数组 nums 和一个整数 k 。\n\n一开始,你的分数为 1 。你可以进行以下操作至多 k 次,目标是使你的分数最大:\n\n * 选择一个之前没有选过的 非空 子数组 nums[l, ..., r] 。\n * 从 nums[l, ..., r] 里面选择一个 质数分数 最高的元素 x 。如果多个元素质数分数相同且最高,选择下标最小的一个。\n * 将你的分数乘以 x 。\n\nnums[l, ..., r] 表示 nums 中起始下标为 l ,结束下标为 r 的子数组,两个端点都包含。\n\n一个整数的 质数分数 等于 x 不同质因子的数目。比方说, 300 的质数分数为 3 ,因为 300 = 2 * 2 * 3 * 5 * 5 。\n\n请你返回进行至多 k 次操作后,可以得到的 最大分数 。\n\n由于答案可能很大,请你将结果对 109 + 7 取余后返回。\n\n示例 1:\n\n输入:nums = [8,3,9,3,8], k = 2\n输出:81\n解释:进行以下操作可以得到分数 81 :\n- 选择子数组 nums[2, ..., 2] 。nums[2] 是子数组中唯一的元素。所以我们将分数乘以 nums[2] ,分数变为 1 * 9 = 9 。\n- 选择子数组 nums[2, ..., 3] 。nums[2] 和 nums[3] 质数分数都为 1 ,但是 nums[2] 下标更小。所以我们将分数乘以 nums[2] ,分数变为 9 * 9 = 81 。\n81 是可以得到的最高得分。\n\n示例 2:\n\n输入:nums = [19,12,14,6,10,18], k = 3\n输出:4788\n解释:进行以下操作可以得到分数 4788 :\n- 选择子数组 nums[0, ..., 0] 。nums[0] 是子数组中唯一的元素。所以我们将分数乘以 nums[0] ,分数变为 1 * 19 = 19 。\n- 选择子数组 nums[5, ..., 5] 。nums[5] 是子数组中唯一的元素。所以我们将分数乘以 nums[5] ,分数变为 19 * 18 = 342 。\n- 选择子数组 nums[2, ..., 3] 。nums[2] 和 nums[3] 质数分数都为 2,但是 nums[2] 下标更小。所以我们将分数乘以 nums[2] ,分数变为 342 * 14 = 4788 。\n4788 是可以得到的最高的分。\n\n\n提示:\n\n * 1 <= nums.length == n <= 105\n * 1 <= nums[i] <= 105\n * 1 <= k <= min(n * (n + 1) / 2, 109)\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def maximumScore(self, nums: List[int], k: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [8,3,9,3,8], \"k\": 2 }\nassert my_solution.maximumScore(**test_input) == 81\n\ntest_input = { \"nums\": [19,12,14,6,10,18], \"k\": 3 }\nassert my_solution.maximumScore(**test_input) == 4788\n\ntest_input = { \"nums\": [3289,2832,14858,22011], \"k\": 6 }\nassert my_solution.maximumScore(**test_input) == 256720975\n\ntest_input = { \"nums\": [1,7,11,1,5], \"k\": 14 }\nassert my_solution.maximumScore(**test_input) == 823751938\n\ntest_input = { \"nums\": [1,1,2,18,1,9,3,1], \"k\": 32 }\nassert my_solution.maximumScore(**test_input) == 346264255\n\ntest_input = { \"nums\": [1,1,1], \"k\": 2 }\nassert my_solution.maximumScore(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,1,12,1,3], \"k\": 3 }\nassert my_solution.maximumScore(**test_input) == 1728\n\ntest_input = { \"nums\": [12,5,1,6,9,1,17,14], \"k\": 12 }\nassert my_solution.maximumScore(**test_input) == 62996359\n\ntest_input = { \"nums\": [1], \"k\": 1 }\nassert my_solution.maximumScore(**test_input) == 1\n\ntest_input = { \"nums\": [1,10,15,1,3], \"k\": 13 }\nassert my_solution.maximumScore(**test_input) == 499978741\n\ntest_input = { \"nums\": [6,1,13,10,1,17,6], \"k\": 27 }\nassert my_solution.maximumScore(**test_input) == 630596200\n\ntest_input = { \"nums\": [1,14], \"k\": 1 }\nassert my_solution.maximumScore(**test_input) == 14\n\ntest_input = { \"nums\": [2,1,14,5,18,1,8,5], \"k\": 34 }\nassert my_solution.maximumScore(**test_input) == 799392504\n\ntest_input = { \"nums\": [5,12,11,15,10,18], \"k\": 18 }\nassert my_solution.maximumScore(**test_input) == 557423913\n\ntest_input = { \"nums\": [4,1], \"k\": 3 }\nassert my_solution.maximumScore(**test_input) == 16\n\ntest_input = { \"nums\": [1,2,5,1,10,1,1], \"k\": 20 }\nassert my_solution.maximumScore(**test_input) == 600000014\n\ntest_input = { \"nums\": [13,16,12,15,12,1,13,1,18,1], \"k\": 46 }\nassert my_solution.maximumScore(**test_input) == 912532739\n\ntest_input = { \"nums\": [10,11], \"k\": 3 }\nassert my_solution.maximumScore(**test_input) == 1100\n\ntest_input = { \"nums\": [15,16,12,1,10,14], \"k\": 19 }\nassert my_solution.maximumScore(**test_input) == 311972352\n\ntest_input = { \"nums\": [14,12,5,2,14], \"k\": 6 }\nassert my_solution.maximumScore(**test_input) == 7529536\n\ntest_input = { \"nums\": [1,13,12,1,9,12,1,18], \"k\": 31 }\nassert my_solution.maximumScore(**test_input) == 846374420\n\ntest_input = { \"nums\": [1,6,14,10,16], \"k\": 4 }\nassert my_solution.maximumScore(**test_input) == 43904\n\ntest_input = { \"nums\": [14,1,9,1,10], \"k\": 3 }\nassert my_solution.maximumScore(**test_input) == 2744\n\ntest_input = { \"nums\": [13,1,1,15,9,1,1], \"k\": 22 }\nassert my_solution.maximumScore(**test_input) == 925331761\n\ntest_input = { \"nums\": [1,17,3,9,10,17,1,1,1,11], \"k\": 22 }\nassert my_solution.maximumScore(**test_input) == 407065837\n\ntest_input = { \"nums\": [1,1,1], \"k\": 5 }\nassert my_solution.maximumScore(**test_input) == 1\n\ntest_input = { \"nums\": [1,13,4,1,1], \"k\": 14 }\nassert my_solution.maximumScore(**test_input) == 206765780\n\ntest_input = { \"nums\": [3,1,3,10,2,16], \"k\": 16 }\nassert my_solution.maximumScore(**test_input) == 996976007\n\ntest_input = { \"nums\": [1,2,1,1,16,8,11,6], \"k\": 27 }\nassert my_solution.maximumScore(**test_input) == 33977400\n\ntest_input = { \"nums\": [1,10,13,1,9,15,1], \"k\": 2 }\nassert my_solution.maximumScore(**test_input) == 225\n\ntest_input = { \"nums\": [18,1], \"k\": 3 }\nassert my_solution.maximumScore(**test_input) == 324\n\ntest_input = { \"nums\": [16], \"k\": 1 }\nassert my_solution.maximumScore(**test_input) == 16\n\ntest_input = { \"nums\": [14,6,18,10,1,8,1,17], \"k\": 25 }\nassert my_solution.maximumScore(**test_input) == 677968714\n\ntest_input = { \"nums\": [15,16,12], \"k\": 6 }\nassert my_solution.maximumScore(**test_input) == 7776000\n\ntest_input = { \"nums\": [1,10,1,2], \"k\": 7 }\nassert my_solution.maximumScore(**test_input) == 2000000\n\ntest_input = { \"nums\": [13,1,10,1,15,6,1,12,6], \"k\": 10 }\nassert my_solution.maximumScore(**test_input) == 650386593\n\ntest_input = { \"nums\": [1,15,5,1,1,15,1,1], \"k\": 17 }\nassert my_solution.maximumScore(**test_input) == 10486853\n\ntest_input = { \"nums\": [1,9], \"k\": 2 }\nassert my_solution.maximumScore(**test_input) == 81\n\ntest_input = { \"nums\": [13,8,14,6,3,14,13,10,1], \"k\": 21 }\nassert my_solution.maximumScore(**test_input) == 247566578\n\ntest_input = { \"nums\": [4], \"k\": 1 }\nassert my_solution.maximumScore(**test_input) == 4\n\ntest_input = { \"nums\": [1,12,5,1,12], \"k\": 15 }\nassert my_solution.maximumScore(**test_input) == 209137175\n\ntest_input = { \"nums\": [1,5,1,11], \"k\": 4 }\nassert my_solution.maximumScore(**test_input) == 3025\n\ntest_input = { \"nums\": [3,6,17,1,1,17,18,12,16,5], \"k\": 9 }\nassert my_solution.maximumScore(**test_input) == 359288982\n\ntest_input = { \"nums\": [2,2,15,2,15,15], \"k\": 10 }\nassert my_solution.maximumScore(**test_input) == 650386593\n\ntest_input = { \"nums\": [1,12], \"k\": 1 }\nassert my_solution.maximumScore(**test_input) == 12\n\ntest_input = { \"nums\": [2,11,1,1], \"k\": 2 }\nassert my_solution.maximumScore(**test_input) == 121\n\ntest_input = { \"nums\": [11,15,18,4,11,7,1,1], \"k\": 32 }\nassert my_solution.maximumScore(**test_input) == 179964426\n\ntest_input = { \"nums\": [10,1,15], \"k\": 1 }\nassert my_solution.maximumScore(**test_input) == 15\n\ntest_input = { \"nums\": [10,1,1,9,14,6,4,18,8], \"k\": 10 }\nassert my_solution.maximumScore(**test_input) == 420565606\n\ntest_input = { \"nums\": [6,8], \"k\": 3 }\nassert my_solution.maximumScore(**test_input) == 288\n\ntest_input = { \"nums\": [13,1,10,6], \"k\": 4 }\nassert my_solution.maximumScore(**test_input) == 16900\n\ntest_input = { \"nums\": [8,10,16,1,1,1], \"k\": 2 }\nassert my_solution.maximumScore(**test_input) == 256\n\ntest_input = { \"nums\": [11,2,1], \"k\": 4 }\nassert my_solution.maximumScore(**test_input) == 2662\n\ntest_input = { \"nums\": [15], \"k\": 1 }\nassert my_solution.maximumScore(**test_input) == 15\n\ntest_input = { \"nums\": [5,5,16,12,8,1,1,7,12], \"k\": 34 }\nassert my_solution.maximumScore(**test_input) == 15762264\n\ntest_input = { \"nums\": [1,1], \"k\": 1 }\nassert my_solution.maximumScore(**test_input) == 1\n\ntest_input = { \"nums\": [3,18,12,8,1,3,6], \"k\": 23 }\nassert my_solution.maximumScore(**test_input) == 18966086\n\ntest_input = { \"nums\": [13,1,5,6], \"k\": 8 }\nassert my_solution.maximumScore(**test_input) == 14236560\n\ntest_input = { \"nums\": [1,1,15,1,9,1,1], \"k\": 23 }\nassert my_solution.maximumScore(**test_input) == 929527145\n\ntest_input = { \"nums\": [6,2,1,17,9,14,1], \"k\": 25 }\nassert my_solution.maximumScore(**test_input) == 808455901\n\ntest_input = { \"nums\": [1,18], \"k\": 3 }\nassert my_solution.maximumScore(**test_input) == 324\n\ntest_input = { \"nums\": [1,10], \"k\": 2 }\nassert my_solution.maximumScore(**test_input) == 100\n\ntest_input = { \"nums\": [17], \"k\": 1 }\nassert my_solution.maximumScore(**test_input) == 17\n\ntest_input = { \"nums\": [18,13,12,1,11], \"k\": 8 }\nassert my_solution.maximumScore(**test_input) == 537271275\n\ntest_input = { \"nums\": [10,14,18,6,12,14,3,13], \"k\": 23 }\nassert my_solution.maximumScore(**test_input) == 795923147\n\ntest_input = { \"nums\": [16,1,14,13,3,1], \"k\": 6 }\nassert my_solution.maximumScore(**test_input) == 9834496\n\ntest_input = { \"nums\": [10,4,4,3,10,1], \"k\": 15 }\nassert my_solution.maximumScore(**test_input) == 997200007\n\ntest_input = { \"nums\": [2,4,1,5,14,13,13,17], \"k\": 19 }\nassert my_solution.maximumScore(**test_input) == 241329678\n\ntest_input = { \"nums\": [6,1,15,1,13], \"k\": 12 }\nassert my_solution.maximumScore(**test_input) == 820232542\n\ntest_input = { \"nums\": [14,13,1,14], \"k\": 5 }\nassert my_solution.maximumScore(**test_input) == 537824\n\ntest_input = { \"nums\": [10,4,12,12,16,9,1,18], \"k\": 36 }\nassert my_solution.maximumScore(**test_input) == 892891506\n\ntest_input = { \"nums\": [6], \"k\": 1 }\nassert my_solution.maximumScore(**test_input) == 6\n\ntest_input = { \"nums\": [12], \"k\": 1 }\nassert my_solution.maximumScore(**test_input) == 12\n\ntest_input = { \"nums\": [10,17,17,15,1,15,1], \"k\": 19 }\nassert my_solution.maximumScore(**test_input) == 301460564\n\ntest_input = { \"nums\": [10,3,1,1,4,2,14], \"k\": 10 }\nassert my_solution.maximumScore(**test_input) == 295359475\n\ntest_input = { \"nums\": [10,12], \"k\": 3 }\nassert my_solution.maximumScore(**test_input) == 1200\n\ntest_input = { \"nums\": [9,10,2,3,2,1,11,1,1,13], \"k\": 49 }\nassert my_solution.maximumScore(**test_input) == 900432644\n\ntest_input = { \"nums\": [1,10,18,18,3,1,8,1,15,15], \"k\": 18 }\nassert my_solution.maximumScore(**test_input) == 38759446\n\ntest_input = { \"nums\": [15,1,11,13,16], \"k\": 14 }\nassert my_solution.maximumScore(**test_input) == 753886562\n\ntest_input = { \"nums\": [12,1,6,1,1,4,8,17,18,1], \"k\": 2 }\nassert my_solution.maximumScore(**test_input) == 324\n\ntest_input = { \"nums\": [1,1,1,17,8,18,8,1], \"k\": 14 }\nassert my_solution.maximumScore(**test_input) == 958387476\n\ntest_input = { \"nums\": [7,1,6,9,11,7,13,12,1], \"k\": 39 }\nassert my_solution.maximumScore(**test_input) == 21295572\n\ntest_input = { \"nums\": [12,1,1,15,2,1,1,16,1,1], \"k\": 8 }\nassert my_solution.maximumScore(**test_input) == 294967268\n\ntest_input = { \"nums\": [3,14,13,1,11,1,1,1], \"k\": 22 }\nassert my_solution.maximumScore(**test_input) == 810815174\n\ntest_input = { \"nums\": [14,3,6,6,1,7,13,16], \"k\": 28 }\nassert my_solution.maximumScore(**test_input) == 312142986\n\ntest_input = { \"nums\": [3,4,4,15,18,12,6], \"k\": 8 }\nassert my_solution.maximumScore(**test_input) == 428674972\n\ntest_input = { \"nums\": [6,15,17,9,9,17], \"k\": 5 }\nassert my_solution.maximumScore(**test_input) == 1419857\n\ntest_input = { \"nums\": [2,12,1,11,12], \"k\": 5 }\nassert my_solution.maximumScore(**test_input) == 248832\n\ntest_input = { \"nums\": [1,15,15], \"k\": 4 }\nassert my_solution.maximumScore(**test_input) == 50625\n\ntest_input = { \"nums\": [7,11,3,1,12,10], \"k\": 15 }\nassert my_solution.maximumScore(**test_input) == 784368200\n\ntest_input = { \"nums\": [18,1,11,15,16,18,18,13,10,10], \"k\": 41 }\nassert my_solution.maximumScore(**test_input) == 911212578\n\ntest_input = { \"nums\": [11,15,2,14,6,15], \"k\": 2 }\nassert my_solution.maximumScore(**test_input) == 225\n\ntest_input = { \"nums\": [11,2,15,1,1,11,7,1], \"k\": 16 }\nassert my_solution.maximumScore(**test_input) == 734032462\n\ntest_input = { \"nums\": [1,6,12,4,10,13,7,6,17,1], \"k\": 50 }\nassert my_solution.maximumScore(**test_input) == 377786273\n\ntest_input = { \"nums\": [1,5,4,18,12,1,1,1,7,12], \"k\": 3 }\nassert my_solution.maximumScore(**test_input) == 5832\n\ntest_input = { \"nums\": [5,1,17,10,12], \"k\": 9 }\nassert my_solution.maximumScore(**test_input) == 467999979\n\ntest_input = { \"nums\": [6,1,1,4,10,15,16,8], \"k\": 12 }\nassert my_solution.maximumScore(**test_input) == 999939527\n\ntest_input = { \"nums\": [1,1], \"k\": 3 }\nassert my_solution.maximumScore(**test_input) == 1\n\ntest_input = { \"nums\": [8], \"k\": 1 }\nassert my_solution.maximumScore(**test_input) == 8\n\ntest_input = { \"nums\": [9,8,14,1,14,14,5,1,6], \"k\": 44 }\nassert my_solution.maximumScore(**test_input) == 439903801", "start_time": 1691893800} +{"task_id": "weekly-contest-357-faulty-keyboard", "url": "https://leetcode.com/problems/faulty-keyboard", "title": "faulty-keyboard", "meta": {"questionId": "2886", "questionFrontendId": "2810", "title": "Faulty Keyboard", "titleSlug": "faulty-keyboard", "isPaidOnly": false, "difficulty": "Easy", "likes": 343, "dislikes": 5, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n你的笔记本键盘存在故障,每当你在上面输入字符 'i' 时,它会反转你所写的字符串。而输入其他字符则可以正常工作。\n\n给你一个下标从 0 开始的字符串 s ,请你用故障键盘依次输入每个字符。\n\n返回最终笔记本屏幕上输出的字符串。\n\n示例 1:\n\n输入:s = \"string\"\n输出:\"rtsng\"\n解释:\n输入第 1 个字符后,屏幕上的文本是:\"s\" 。\n输入第 2 个字符后,屏幕上的文本是:\"st\" 。\n输入第 3 个字符后,屏幕上的文本是:\"str\" 。\n因为第 4 个字符是 'i' ,屏幕上的文本被反转,变成 \"rts\" 。\n输入第 5 个字符后,屏幕上的文本是:\"rtsn\" 。\n输入第 6 个字符后,屏幕上的文本是: \"rtsng\" 。\n因此,返回 \"rtsng\" 。\n\n示例 2:\n\n输入:s = \"poiinter\"\n输出:\"ponter\"\n解释:\n输入第 1 个字符后,屏幕上的文本是:\"p\" 。\n输入第 2 个字符后,屏幕上的文本是:\"po\" 。\n因为第 3 个字符是 'i' ,屏幕上的文本被反转,变成 \"op\" 。\n因为第 4 个字符是 'i' ,屏幕上的文本被反转,变成 \"po\" 。\n输入第 5 个字符后,屏幕上的文本是:\"pon\" 。\n输入第 6 个字符后,屏幕上的文本是:\"pont\" 。\n输入第 7 个字符后,屏幕上的文本是:\"ponte\" 。\n输入第 8 个字符后,屏幕上的文本是:\"ponter\" 。\n因此,返回 \"ponter\" 。\n\n提示:\n\n * 1 <= s.length <= 100\n * s 由小写英文字母组成\n * s[0] != 'i'\n\"\"\"\nclass Solution:\n def finalString(self, s: str) -> str:\n ", "prompt_sft": "你的笔记本键盘存在故障,每当你在上面输入字符 'i' 时,它会反转你所写的字符串。而输入其他字符则可以正常工作。\n\n给你一个下标从 0 开始的字符串 s ,请你用故障键盘依次输入每个字符。\n\n返回最终笔记本屏幕上输出的字符串。\n\n示例 1:\n\n输入:s = \"string\"\n输出:\"rtsng\"\n解释:\n输入第 1 个字符后,屏幕上的文本是:\"s\" 。\n输入第 2 个字符后,屏幕上的文本是:\"st\" 。\n输入第 3 个字符后,屏幕上的文本是:\"str\" 。\n因为第 4 个字符是 'i' ,屏幕上的文本被反转,变成 \"rts\" 。\n输入第 5 个字符后,屏幕上的文本是:\"rtsn\" 。\n输入第 6 个字符后,屏幕上的文本是: \"rtsng\" 。\n因此,返回 \"rtsng\" 。\n\n示例 2:\n\n输入:s = \"poiinter\"\n输出:\"ponter\"\n解释:\n输入第 1 个字符后,屏幕上的文本是:\"p\" 。\n输入第 2 个字符后,屏幕上的文本是:\"po\" 。\n因为第 3 个字符是 'i' ,屏幕上的文本被反转,变成 \"op\" 。\n因为第 4 个字符是 'i' ,屏幕上的文本被反转,变成 \"po\" 。\n输入第 5 个字符后,屏幕上的文本是:\"pon\" 。\n输入第 6 个字符后,屏幕上的文本是:\"pont\" 。\n输入第 7 个字符后,屏幕上的文本是:\"ponte\" 。\n输入第 8 个字符后,屏幕上的文本是:\"ponter\" 。\n因此,返回 \"ponter\" 。\n\n提示:\n\n * 1 <= s.length <= 100\n * s 由小写英文字母组成\n * s[0] != 'i'\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def finalString(self, s: str) -> str:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"s\": \"string\" }\nassert my_solution.finalString(**test_input) == \"rtsng\"\n\ntest_input = { \"s\": \"poiinter\" }\nassert my_solution.finalString(**test_input) == \"ponter\"\n\ntest_input = { \"s\": \"goci\" }\nassert my_solution.finalString(**test_input) == \"cog\"\n\ntest_input = { \"s\": \"ksi\" }\nassert my_solution.finalString(**test_input) == \"sk\"\n\ntest_input = { \"s\": \"fii\" }\nassert my_solution.finalString(**test_input) == \"f\"\n\ntest_input = { \"s\": \"qskyviiiii\" }\nassert my_solution.finalString(**test_input) == \"vyksq\"\n\ntest_input = { \"s\": \"pft\" }\nassert my_solution.finalString(**test_input) == \"pft\"\n\ntest_input = { \"s\": \"viwif\" }\nassert my_solution.finalString(**test_input) == \"wvf\"\n\ntest_input = { \"s\": \"wiie\" }\nassert my_solution.finalString(**test_input) == \"we\"\n\ntest_input = { \"s\": \"kiis\" }\nassert my_solution.finalString(**test_input) == \"ks\"\n\ntest_input = { \"s\": \"xihbosxitx\" }\nassert my_solution.finalString(**test_input) == \"xsobhxtx\"\n\ntest_input = { \"s\": \"uwioili\" }\nassert my_solution.finalString(**test_input) == \"lwuo\"\n\ntest_input = { \"s\": \"aapziai\" }\nassert my_solution.finalString(**test_input) == \"aaapz\"\n\ntest_input = { \"s\": \"pviist\" }\nassert my_solution.finalString(**test_input) == \"pvst\"\n\ntest_input = { \"s\": \"miiuiei\" }\nassert my_solution.finalString(**test_input) == \"emu\"\n\ntest_input = { \"s\": \"diiiiq\" }\nassert my_solution.finalString(**test_input) == \"dq\"\n\ntest_input = { \"s\": \"eirov\" }\nassert my_solution.finalString(**test_input) == \"erov\"\n\ntest_input = { \"s\": \"niiiiisiii\" }\nassert my_solution.finalString(**test_input) == \"sn\"\n\ntest_input = { \"s\": \"siiuii\" }\nassert my_solution.finalString(**test_input) == \"su\"\n\ntest_input = { \"s\": \"piijciivq\" }\nassert my_solution.finalString(**test_input) == \"pjcvq\"\n\ntest_input = { \"s\": \"tidtwitik\" }\nassert my_solution.finalString(**test_input) == \"ttdtwk\"\n\ntest_input = { \"s\": \"z\" }\nassert my_solution.finalString(**test_input) == \"z\"\n\ntest_input = { \"s\": \"ffyuidnn\" }\nassert my_solution.finalString(**test_input) == \"uyffdnn\"\n\ntest_input = { \"s\": \"xitiiinix\" }\nassert my_solution.finalString(**test_input) == \"nxtx\"\n\ntest_input = { \"s\": \"ciiiuifab\" }\nassert my_solution.finalString(**test_input) == \"ucfab\"\n\ntest_input = { \"s\": \"x\" }\nassert my_solution.finalString(**test_input) == \"x\"\n\ntest_input = { \"s\": \"v\" }\nassert my_solution.finalString(**test_input) == \"v\"\n\ntest_input = { \"s\": \"liinii\" }\nassert my_solution.finalString(**test_input) == \"ln\"\n\ntest_input = { \"s\": \"ziii\" }\nassert my_solution.finalString(**test_input) == \"z\"\n\ntest_input = { \"s\": \"ei\" }\nassert my_solution.finalString(**test_input) == \"e\"\n\ntest_input = { \"s\": \"tidiiiii\" }\nassert my_solution.finalString(**test_input) == \"dt\"\n\ntest_input = { \"s\": \"krjiqjii\" }\nassert my_solution.finalString(**test_input) == \"jrkqj\"\n\ntest_input = { \"s\": \"mxczii\" }\nassert my_solution.finalString(**test_input) == \"mxcz\"\n\ntest_input = { \"s\": \"bz\" }\nassert my_solution.finalString(**test_input) == \"bz\"\n\ntest_input = { \"s\": \"zbwri\" }\nassert my_solution.finalString(**test_input) == \"rwbz\"\n\ntest_input = { \"s\": \"biiq\" }\nassert my_solution.finalString(**test_input) == \"bq\"\n\ntest_input = { \"s\": \"mmiiliir\" }\nassert my_solution.finalString(**test_input) == \"mmlr\"\n\ntest_input = { \"s\": \"plibeici\" }\nassert my_solution.finalString(**test_input) == \"clpbe\"\n\ntest_input = { \"s\": \"cii\" }\nassert my_solution.finalString(**test_input) == \"c\"\n\ntest_input = { \"s\": \"wiilg\" }\nassert my_solution.finalString(**test_input) == \"wlg\"\n\ntest_input = { \"s\": \"cdidi\" }\nassert my_solution.finalString(**test_input) == \"dcd\"\n\ntest_input = { \"s\": \"fsq\" }\nassert my_solution.finalString(**test_input) == \"fsq\"\n\ntest_input = { \"s\": \"hkjciaiii\" }\nassert my_solution.finalString(**test_input) == \"ahkjc\"\n\ntest_input = { \"s\": \"l\" }\nassert my_solution.finalString(**test_input) == \"l\"\n\ntest_input = { \"s\": \"vilcoizi\" }\nassert my_solution.finalString(**test_input) == \"zvlco\"\n\ntest_input = { \"s\": \"tgigivipx\" }\nassert my_solution.finalString(**test_input) == \"vgtgpx\"\n\ntest_input = { \"s\": \"ri\" }\nassert my_solution.finalString(**test_input) == \"r\"\n\ntest_input = { \"s\": \"kficiiioiy\" }\nassert my_solution.finalString(**test_input) == \"ofkcy\"\n\ntest_input = { \"s\": \"o\" }\nassert my_solution.finalString(**test_input) == \"o\"\n\ntest_input = { \"s\": \"piifwiiit\" }\nassert my_solution.finalString(**test_input) == \"wfpt\"\n\ntest_input = { \"s\": \"sifsiui\" }\nassert my_solution.finalString(**test_input) == \"usfs\"\n\ntest_input = { \"s\": \"sxiuiiiii\" }\nassert my_solution.finalString(**test_input) == \"usx\"\n\ntest_input = { \"s\": \"tiiiihiw\" }\nassert my_solution.finalString(**test_input) == \"htw\"\n\ntest_input = { \"s\": \"ko\" }\nassert my_solution.finalString(**test_input) == \"ko\"\n\ntest_input = { \"s\": \"gagi\" }\nassert my_solution.finalString(**test_input) == \"gag\"\n\ntest_input = { \"s\": \"yyigiir\" }\nassert my_solution.finalString(**test_input) == \"yygr\"\n\ntest_input = { \"s\": \"jimiiaci\" }\nassert my_solution.finalString(**test_input) == \"camj\"\n\ntest_input = { \"s\": \"xiiiei\" }\nassert my_solution.finalString(**test_input) == \"ex\"\n\ntest_input = { \"s\": \"hwi\" }\nassert my_solution.finalString(**test_input) == \"wh\"\n\ntest_input = { \"s\": \"ji\" }\nassert my_solution.finalString(**test_input) == \"j\"\n\ntest_input = { \"s\": \"heii\" }\nassert my_solution.finalString(**test_input) == \"he\"\n\ntest_input = { \"s\": \"zitjcq\" }\nassert my_solution.finalString(**test_input) == \"ztjcq\"\n\ntest_input = { \"s\": \"upmipaw\" }\nassert my_solution.finalString(**test_input) == \"mpupaw\"\n\ntest_input = { \"s\": \"fiixkgp\" }\nassert my_solution.finalString(**test_input) == \"fxkgp\"\n\ntest_input = { \"s\": \"ldr\" }\nassert my_solution.finalString(**test_input) == \"ldr\"\n\ntest_input = { \"s\": \"kiboiithi\" }\nassert my_solution.finalString(**test_input) == \"htobk\"\n\ntest_input = { \"s\": \"svcii\" }\nassert my_solution.finalString(**test_input) == \"svc\"\n\ntest_input = { \"s\": \"d\" }\nassert my_solution.finalString(**test_input) == \"d\"\n\ntest_input = { \"s\": \"edgijwiua\" }\nassert my_solution.finalString(**test_input) == \"wjedgua\"\n\ntest_input = { \"s\": \"wiidqoiwov\" }\nassert my_solution.finalString(**test_input) == \"oqdwwov\"\n\ntest_input = { \"s\": \"zimxiiqqi\" }\nassert my_solution.finalString(**test_input) == \"qqxmz\"\n\ntest_input = { \"s\": \"githpgiini\" }\nassert my_solution.finalString(**test_input) == \"ngphtg\"\n\ntest_input = { \"s\": \"fy\" }\nassert my_solution.finalString(**test_input) == \"fy\"\n\ntest_input = { \"s\": \"hesi\" }\nassert my_solution.finalString(**test_input) == \"seh\"\n\ntest_input = { \"s\": \"eiiii\" }\nassert my_solution.finalString(**test_input) == \"e\"\n\ntest_input = { \"s\": \"be\" }\nassert my_solution.finalString(**test_input) == \"be\"\n\ntest_input = { \"s\": \"rpi\" }\nassert my_solution.finalString(**test_input) == \"pr\"\n\ntest_input = { \"s\": \"mi\" }\nassert my_solution.finalString(**test_input) == \"m\"\n\ntest_input = { \"s\": \"wiiiiii\" }\nassert my_solution.finalString(**test_input) == \"w\"\n\ntest_input = { \"s\": \"rbiiiii\" }\nassert my_solution.finalString(**test_input) == \"br\"\n\ntest_input = { \"s\": \"diiii\" }\nassert my_solution.finalString(**test_input) == \"d\"\n\ntest_input = { \"s\": \"poiiifl\" }\nassert my_solution.finalString(**test_input) == \"opfl\"\n\ntest_input = { \"s\": \"loifiicii\" }\nassert my_solution.finalString(**test_input) == \"olfc\"\n\ntest_input = { \"s\": \"bii\" }\nassert my_solution.finalString(**test_input) == \"b\"\n\ntest_input = { \"s\": \"nirii\" }\nassert my_solution.finalString(**test_input) == \"nr\"\n\ntest_input = { \"s\": \"wiigipio\" }\nassert my_solution.finalString(**test_input) == \"pwgo\"\n\ntest_input = { \"s\": \"gimliibin\" }\nassert my_solution.finalString(**test_input) == \"blmgn\"\n\ntest_input = { \"s\": \"zi\" }\nassert my_solution.finalString(**test_input) == \"z\"\n\ntest_input = { \"s\": \"tjn\" }\nassert my_solution.finalString(**test_input) == \"tjn\"\n\ntest_input = { \"s\": \"ly\" }\nassert my_solution.finalString(**test_input) == \"ly\"\n\ntest_input = { \"s\": \"sqzviyiimi\" }\nassert my_solution.finalString(**test_input) == \"mysqzv\"\n\ntest_input = { \"s\": \"jhmaxm\" }\nassert my_solution.finalString(**test_input) == \"jhmaxm\"\n\ntest_input = { \"s\": \"py\" }\nassert my_solution.finalString(**test_input) == \"py\"\n\ntest_input = { \"s\": \"yyilwiib\" }\nassert my_solution.finalString(**test_input) == \"yylwb\"\n\ntest_input = { \"s\": \"ryjiilj\" }\nassert my_solution.finalString(**test_input) == \"ryjlj\"\n\ntest_input = { \"s\": \"tnokpgfii\" }\nassert my_solution.finalString(**test_input) == \"tnokpgf\"\n\ntest_input = { \"s\": \"niihiliiv\" }\nassert my_solution.finalString(**test_input) == \"hnlv\"\n\ntest_input = { \"s\": \"gvhms\" }\nassert my_solution.finalString(**test_input) == \"gvhms\"\n\ntest_input = { \"s\": \"yg\" }\nassert my_solution.finalString(**test_input) == \"yg\"\n\ntest_input = { \"s\": \"eiiiuizgi\" }\nassert my_solution.finalString(**test_input) == \"gzeu\"", "start_time": 1691289000} +{"task_id": "weekly-contest-357-check-if-it-is-possible-to-split-array", "url": "https://leetcode.com/problems/check-if-it-is-possible-to-split-array", "title": "check-if-it-is-possible-to-split-array", "meta": {"questionId": "2916", "questionFrontendId": "2811", "title": "Check if it is Possible to Split Array", "titleSlug": "check-if-it-is-possible-to-split-array", "isPaidOnly": false, "difficulty": "Medium", "likes": 425, "dislikes": 84, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个长度为 n 的数组 nums 和一个整数 m 。请你判断能否执行一系列操作,将数组拆分成 n 个 非空 数组。\n\n在每一步操作中,你可以选择一个 长度至少为 2 的现有数组(之前步骤的结果) 并将其拆分成 2 个子数组,而得到的 每个 子数组,至少 需要满足以下条件之一:\n\n * 子数组的长度为 1 ,或者\n * 子数组元素之和 大于或等于  m 。\n\n如果你可以将给定数组拆分成 n 个满足要求的数组,返回 true ;否则,返回 false 。\n\n注意:子数组是数组中的一个连续非空元素序列。\n\n示例 1:\n\n输入:nums = [2, 2, 1], m = 4\n输出:true\n解释:\n第 1 步,将数组 nums 拆分成 [2, 2] 和 [1] 。\n第 2 步,将数组 [2, 2] 拆分成 [2] 和 [2] 。\n因此,答案为 true 。\n\n示例 2:\n\n输入:nums = [2, 1, 3], m = 5\n输出:false\n解释:\n存在两种不同的拆分方法:\n第 1 种,将数组 nums 拆分成 [2, 1] 和 [3] 。\n第 2 种,将数组 nums 拆分成 [2] 和 [1, 3] 。\n然而,这两种方法都不满足题意。因此,答案为 false 。\n\n示例 3:\n\n输入:nums = [2, 3, 3, 2, 3], m = 6\n输出:true\n解释:\n第 1 步,将数组 nums 拆分成 [2, 3, 3, 2] 和 [3] 。\n第 2 步,将数组 [2, 3, 3, 2] 拆分成 [2, 3, 3] 和 [2] 。\n第 3 步,将数组 [2, 3, 3] 拆分成 [2] 和 [3, 3] 。\n第 4 步,将数组 [3, 3] 拆分成 [3] 和 [3] 。\n因此,答案为 true 。\n\n提示:\n\n * 1 <= n == nums.length <= 100\n * 1 <= nums[i] <= 100\n * 1 <= m <= 200\n\"\"\"\nclass Solution:\n def canSplitArray(self, nums: List[int], m: int) -> bool:\n ", "prompt_sft": "给你一个长度为 n 的数组 nums 和一个整数 m 。请你判断能否执行一系列操作,将数组拆分成 n 个 非空 数组。\n\n在每一步操作中,你可以选择一个 长度至少为 2 的现有数组(之前步骤的结果) 并将其拆分成 2 个子数组,而得到的 每个 子数组,至少 需要满足以下条件之一:\n\n * 子数组的长度为 1 ,或者\n * 子数组元素之和 大于或等于  m 。\n\n如果你可以将给定数组拆分成 n 个满足要求的数组,返回 true ;否则,返回 false 。\n\n注意:子数组是数组中的一个连续非空元素序列。\n\n示例 1:\n\n输入:nums = [2, 2, 1], m = 4\n输出:true\n解释:\n第 1 步,将数组 nums 拆分成 [2, 2] 和 [1] 。\n第 2 步,将数组 [2, 2] 拆分成 [2] 和 [2] 。\n因此,答案为 true 。\n\n示例 2:\n\n输入:nums = [2, 1, 3], m = 5\n输出:false\n解释:\n存在两种不同的拆分方法:\n第 1 种,将数组 nums 拆分成 [2, 1] 和 [3] 。\n第 2 种,将数组 nums 拆分成 [2] 和 [1, 3] 。\n然而,这两种方法都不满足题意。因此,答案为 false 。\n\n示例 3:\n\n输入:nums = [2, 3, 3, 2, 3], m = 6\n输出:true\n解释:\n第 1 步,将数组 nums 拆分成 [2, 3, 3, 2] 和 [3] 。\n第 2 步,将数组 [2, 3, 3, 2] 拆分成 [2, 3, 3] 和 [2] 。\n第 3 步,将数组 [2, 3, 3] 拆分成 [2] 和 [3, 3] 。\n第 4 步,将数组 [3, 3] 拆分成 [3] 和 [3] 。\n因此,答案为 true 。\n\n提示:\n\n * 1 <= n == nums.length <= 100\n * 1 <= nums[i] <= 100\n * 1 <= m <= 200\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def canSplitArray(self, nums: List[int], m: int) -> bool:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [2, 2, 1], \"m\": 4 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [2, 3, 3, 2, 3], \"m\": 6 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [1], \"m\": 1 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [2, 1, 3], \"m\": 5 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [1, 1, 1], \"m\": 3 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [2], \"m\": 1 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [2, 1, 2], \"m\": 4 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [1, 2, 1], \"m\": 5 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [2, 2, 2], \"m\": 5 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [3, 1, 2], \"m\": 5 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [3], \"m\": 1 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [1], \"m\": 2 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [2], \"m\": 2 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [1, 3, 1], \"m\": 6 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [1, 3, 2], \"m\": 6 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [2, 1, 1], \"m\": 6 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [2, 2, 1], \"m\": 6 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [2, 2, 3], \"m\": 6 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [3], \"m\": 2 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [3, 1, 1], \"m\": 6 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [3, 1, 3], \"m\": 6 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [3], \"m\": 3 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [7], \"m\": 5 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [4], \"m\": 7 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [9], \"m\": 7 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [2], \"m\": 8 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [3, 2, 2], \"m\": 6 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [4], \"m\": 8 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [10], \"m\": 11 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [6], \"m\": 12 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [3, 2, 3], \"m\": 6 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [3, 3, 6], \"m\": 10 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [2], \"m\": 14 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [5, 3, 6], \"m\": 10 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [3], \"m\": 18 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [4, 6, 5], \"m\": 12 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [9, 7], \"m\": 1 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [1, 2], \"m\": 2 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [9, 1, 7], \"m\": 14 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [8, 2, 4], \"m\": 16 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [1, 3], \"m\": 2 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [2, 1], \"m\": 2 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [9, 5, 7], \"m\": 20 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [2, 3], \"m\": 2 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [1, 2, 1, 1], \"m\": 4 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [1, 2, 2, 5], \"m\": 8 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [4, 4, 4, 2], \"m\": 9 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [3, 2], \"m\": 2 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [8, 1, 2, 5], \"m\": 10 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [10, 2, 9, 3], \"m\": 14 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [3, 3], \"m\": 2 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [10, 4, 8, 6], \"m\": 16 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [14, 1, 1, 15], \"m\": 17 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [6, 11, 2, 12], \"m\": 18 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [14, 3, 12, 3], \"m\": 18 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [1, 1], \"m\": 3 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [1, 2], \"m\": 3 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [1, 1, 2, 2, 1], \"m\": 5 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [2, 2, 1, 3, 1], \"m\": 5 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [1, 3], \"m\": 3 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [3, 1, 1, 3, 1], \"m\": 5 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [2, 2], \"m\": 3 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [2, 3], \"m\": 3 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [2, 10], \"m\": 3 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [3, 1], \"m\": 3 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [3, 3], \"m\": 3 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [7, 9], \"m\": 3 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [3, 3, 1, 5, 1], \"m\": 7 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [1, 4, 2, 4, 2], \"m\": 8 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [2, 9, 2, 3, 2], \"m\": 12 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [1, 3], \"m\": 4 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [2, 2], \"m\": 4 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [4, 4, 4, 7, 5], \"m\": 13 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [5, 2, 6, 5, 4], \"m\": 13 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [2, 3], \"m\": 4 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [3, 1], \"m\": 4 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [13, 2, 13, 4, 11], \"m\": 18 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [5, 6, 10, 7, 4], \"m\": 19 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [16, 1, 12, 6, 7], \"m\": 19 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [3, 3], \"m\": 4 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [9, 9, 8, 10, 8], \"m\": 20 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [9, 4], \"m\": 5 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [10, 2], \"m\": 5 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [16, 2, 2, 16, 2], \"m\": 20 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [6, 2], \"m\": 7 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [1, 3, 1, 2, 1, 4], \"m\": 6 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [5, 1], \"m\": 8 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [1, 4, 4, 2, 1, 5], \"m\": 9 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [2, 5], \"m\": 12 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [10, 9], \"m\": 15 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [8, 4], \"m\": 18 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [3, 4, 3, 5, 2, 1], \"m\": 9 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [3, 7, 2, 8, 2, 4], \"m\": 11 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [8, 1], \"m\": 19 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [1, 1, 2], \"m\": 3 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [5, 1, 1, 9, 1, 5], \"m\": 11 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [1, 1, 3], \"m\": 3 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [6, 4, 7, 2, 5, 4], \"m\": 12 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [1, 2, 1], \"m\": 3 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [1, 3, 1], \"m\": 3 }\nassert my_solution.canSplitArray(**test_input) == True", "start_time": 1691289000} +{"task_id": "weekly-contest-357-find-the-safest-path-in-a-grid", "url": "https://leetcode.com/problems/find-the-safest-path-in-a-grid", "title": "find-the-safest-path-in-a-grid", "meta": {"questionId": "2914", "questionFrontendId": "2812", "title": "Find the Safest Path in a Grid", "titleSlug": "find-the-safest-path-in-a-grid", "isPaidOnly": false, "difficulty": "Medium", "likes": 706, "dislikes": 68, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0 开始、大小为 n x n 的二维矩阵 grid ,其中 (r, c) 表示:\n\n * 如果 grid[r][c] = 1 ,则表示一个存在小偷的单元格\n * 如果 grid[r][c] = 0 ,则表示一个空单元格\n\n你最开始位于单元格 (0, 0) 。在一步移动中,你可以移动到矩阵中的任一相邻单元格,包括存在小偷的单元格。\n\n矩阵中路径的 安全系数 定义为:从路径中任一单元格到矩阵中任一小偷所在单元格的 最小 曼哈顿距离。\n\n返回所有通向单元格 (n - 1, n - 1) 的路径中的 最大安全系数 。\n\n单元格 (r, c) 的某个 相邻 单元格,是指在矩阵中存在的 (r, c + 1)、(r, c - 1)、(r + 1, c) 和 (r - 1, c) 之一。\n\n两个单元格 (a, b) 和 (x, y) 之间的 曼哈顿距离 等于 | a - x | + | b - y | ,其中 |val| 表示 val 的绝对值。\n\n示例 1:\n\n[https://assets.leetcode.com/uploads/2023/07/02/example1.png]\n\n输入:grid = [[1,0,0],[0,0,0],[0,0,1]]\n输出:0\n解释:从 (0, 0) 到 (n - 1, n - 1) 的每条路径都经过存在小偷的单元格 (0, 0) 和 (n - 1, n - 1) 。\n\n示例 2:\n\n[https://assets.leetcode.com/uploads/2023/07/02/example2.png]\n\n输入:grid = [[0,0,1],[0,0,0],[0,0,0]]\n输出:2\n解释:\n上图所示路径的安全系数为 2:\n- 该路径上距离小偷所在单元格(0,2)最近的单元格是(0,0)。它们之间的曼哈顿距离为 | 0 - 0 | + | 0 - 2 | = 2 。\n可以证明,不存在安全系数更高的其他路径。\n\n示例 3:\n\n[https://assets.leetcode.com/uploads/2023/07/02/example3.png]\n\n输入:grid = [[0,0,0,1],[0,0,0,0],[0,0,0,0],[1,0,0,0]]\n输出:2\n解释:\n上图所示路径的安全系数为 2:\n- 该路径上距离小偷所在单元格(0,3)最近的单元格是(1,2)。它们之间的曼哈顿距离为 | 0 - 1 | + | 3 - 2 | = 2 。\n- 该路径上距离小偷所在单元格(3,0)最近的单元格是(3,2)。它们之间的曼哈顿距离为 | 3 - 3 | + | 0 - 2 | = 2 。\n可以证明,不存在安全系数更高的其他路径。\n\n提示:\n\n * 1 <= grid.length == n <= 400\n * grid[i].length == n\n * grid[i][j] 为 0 或 1\n * grid 至少存在一个小偷\n\"\"\"\nclass Solution:\n def maximumSafenessFactor(self, grid: List[List[int]]) -> int:\n ", "prompt_sft": "给你一个下标从 0 开始、大小为 n x n 的二维矩阵 grid ,其中 (r, c) 表示:\n\n * 如果 grid[r][c] = 1 ,则表示一个存在小偷的单元格\n * 如果 grid[r][c] = 0 ,则表示一个空单元格\n\n你最开始位于单元格 (0, 0) 。在一步移动中,你可以移动到矩阵中的任一相邻单元格,包括存在小偷的单元格。\n\n矩阵中路径的 安全系数 定义为:从路径中任一单元格到矩阵中任一小偷所在单元格的 最小 曼哈顿距离。\n\n返回所有通向单元格 (n - 1, n - 1) 的路径中的 最大安全系数 。\n\n单元格 (r, c) 的某个 相邻 单元格,是指在矩阵中存在的 (r, c + 1)、(r, c - 1)、(r + 1, c) 和 (r - 1, c) 之一。\n\n两个单元格 (a, b) 和 (x, y) 之间的 曼哈顿距离 等于 | a - x | + | b - y | ,其中 |val| 表示 val 的绝对值。\n\n示例 1:\n\n[https://assets.leetcode.com/uploads/2023/07/02/example1.png]\n\n输入:grid = [[1,0,0],[0,0,0],[0,0,1]]\n输出:0\n解释:从 (0, 0) 到 (n - 1, n - 1) 的每条路径都经过存在小偷的单元格 (0, 0) 和 (n - 1, n - 1) 。\n\n示例 2:\n\n[https://assets.leetcode.com/uploads/2023/07/02/example2.png]\n\n输入:grid = [[0,0,1],[0,0,0],[0,0,0]]\n输出:2\n解释:\n上图所示路径的安全系数为 2:\n- 该路径上距离小偷所在单元格(0,2)最近的单元格是(0,0)。它们之间的曼哈顿距离为 | 0 - 0 | + | 0 - 2 | = 2 。\n可以证明,不存在安全系数更高的其他路径。\n\n示例 3:\n\n[https://assets.leetcode.com/uploads/2023/07/02/example3.png]\n\n输入:grid = [[0,0,0,1],[0,0,0,0],[0,0,0,0],[1,0,0,0]]\n输出:2\n解释:\n上图所示路径的安全系数为 2:\n- 该路径上距离小偷所在单元格(0,3)最近的单元格是(1,2)。它们之间的曼哈顿距离为 | 0 - 1 | + | 3 - 2 | = 2 。\n- 该路径上距离小偷所在单元格(3,0)最近的单元格是(3,2)。它们之间的曼哈顿距离为 | 3 - 3 | + | 0 - 2 | = 2 。\n可以证明,不存在安全系数更高的其他路径。\n\n提示:\n\n * 1 <= grid.length == n <= 400\n * grid[i].length == n\n * grid[i][j] 为 0 或 1\n * grid 至少存在一个小偷\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def maximumSafenessFactor(self, grid: List[List[int]]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"grid\": [[1,0,0],[0,0,0],[0,0,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[0,0,1],[0,0,0],[0,0,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 2\n\ntest_input = { \"grid\": [[0,0,0,1],[0,0,0,0],[0,0,0,0],[1,0,0,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 2\n\ntest_input = { \"grid\": [[1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1],[1,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,1,1],[1,1,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,1,1],[1,1,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,1,1],[1,0,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,1,1],[1,0,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,1,1],[0,1,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,1,1],[0,1,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,1,1],[0,0,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,1,1],[0,0,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,1,0],[1,1,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,1,0],[1,1,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,1,0],[1,0,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,1,0],[1,0,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,1,0],[0,1,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,1,0],[0,1,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,1,0],[0,0,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,1,0],[0,0,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,0,1],[1,1,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,0,1],[1,1,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,0,1],[1,0,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,0,1],[1,0,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,0,1],[0,1,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,0,1],[0,1,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,0,1],[0,0,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,0,1],[0,0,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,0,0],[1,1,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,0,0],[1,1,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,0,0],[1,0,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,0,0],[1,0,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,0,0],[0,1,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,0,0],[0,1,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,0,0],[0,0,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,0,0],[0,0,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1],[1,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,1,1],[1,1,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,1,1],[1,1,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,1,1],[1,0,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,1,1],[1,0,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,1,1],[0,1,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,1,1],[0,1,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,1,1],[0,0,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,1,1],[0,0,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,1,0],[1,1,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,1,0],[1,1,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,1,0],[1,0,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,1,0],[1,0,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,1,0],[0,1,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,1,0],[0,1,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,1,0],[0,0,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,1,0],[0,0,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,0,1],[1,1,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,0,1],[1,1,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,0,1],[1,0,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,0,1],[1,0,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,0,1],[0,1,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,0,1],[0,1,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,0,1],[0,0,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,0,1],[0,0,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,0,0],[1,1,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,0,0],[1,1,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,0,0],[1,0,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,0,0],[1,0,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,0,0],[0,1,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,0,0],[0,1,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,0,0],[0,0,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,0,0],[0,0,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1],[0,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,0],[1,1,1],[1,1,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,0],[1,1,1],[1,1,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,0],[1,1,1],[1,0,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,0],[1,1,1],[1,0,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,0],[1,1,1],[0,1,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,0],[1,1,1],[0,1,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,0],[1,1,1],[0,0,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,0],[1,1,1],[0,0,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,0],[1,1,0],[1,1,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,0],[1,1,0],[1,1,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,0],[1,1,0],[1,0,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,0],[1,1,0],[1,0,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,0],[1,1,0],[0,1,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,0],[1,1,0],[0,1,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,0],[1,1,0],[0,0,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,0],[1,1,0],[0,0,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,0],[1,0,1],[1,1,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,0],[1,0,1],[1,1,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,0],[1,0,1],[1,0,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,0],[1,0,1],[1,0,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,0],[1,0,1],[0,1,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,0],[1,0,1],[0,1,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,0],[1,0,1],[0,0,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,0],[1,0,1],[0,0,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,0],[1,0,0],[1,1,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,0],[1,0,0],[1,1,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,0],[1,0,0],[1,0,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,0],[1,0,0],[1,0,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,0],[1,0,0],[0,1,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0", "start_time": 1691289000} +{"task_id": "weekly-contest-357-maximum-elegance-of-a-k-length-subsequence", "url": "https://leetcode.com/problems/maximum-elegance-of-a-k-length-subsequence", "title": "maximum-elegance-of-a-k-length-subsequence", "meta": {"questionId": "2894", "questionFrontendId": "2813", "title": "Maximum Elegance of a K-Length Subsequence", "titleSlug": "maximum-elegance-of-a-k-length-subsequence", "isPaidOnly": false, "difficulty": "Hard", "likes": 270, "dislikes": 3, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个长度为 n 的二维整数数组 items 和一个整数 k 。\n\nitems[i] = [profiti, categoryi],其中 profiti 和 categoryi 分别表示第 i 个项目的利润和类别。\n\n现定义 items 的 子序列 的 优雅度 可以用 total_profit + distinct_categories2 计算,其中 total_profit 是子序列中所有项目的利润总和,distinct_categories 是所选子序列所含的所有类别中不同类别的数量。\n\n你的任务是从 items 所有长度为 k 的子序列中,找出 最大优雅度 。\n\n用整数形式表示并返回 items 中所有长度恰好为 k 的子序列的最大优雅度。\n\n注意:数组的子序列是经由原数组删除一些元素(可能不删除)而产生的新数组,且删除不改变其余元素相对顺序。\n\n示例 1:\n\n输入:items = [[3,2],[5,1],[10,1]], k = 2\n输出:17\n解释:\n在这个例子中,我们需要选出长度为 2 的子序列。\n其中一种方案是 items[0] = [3,2] 和 items[2] = [10,1] 。\n子序列的总利润为 3 + 10 = 13 ,子序列包含 2 种不同类别 [2,1] 。\n因此,优雅度为 13 + 22 = 17 ,可以证明 17 是可以获得的最大优雅度。\n\n示例 2:\n\n输入:items = [[3,1],[3,1],[2,2],[5,3]], k = 3\n输出:19\n解释:\n在这个例子中,我们需要选出长度为 3 的子序列。\n其中一种方案是 items[0] = [3,1] ,items[2] = [2,2] 和 items[3] = [5,3] 。\n子序列的总利润为 3 + 2 + 5 = 10 ,子序列包含 3 种不同类别 [1, 2, 3] 。\n因此,优雅度为 10 + 32 = 19 ,可以证明 19 是可以获得的最大优雅度。\n\n示例 3:\n\n输入:items = [[1,1],[2,1],[3,1]], k = 3\n输出:7\n解释:\n在这个例子中,我们需要选出长度为 3 的子序列。\n我们需要选中所有项目。\n子序列的总利润为 1 + 2 + 3 = 6,子序列包含 1 种不同类别 [1] 。\n因此,最大优雅度为 6 + 12 = 7 。\n\n提示:\n\n * 1 <= items.length == n <= 105\n * items[i].length == 2\n * items[i][0] == profiti\n * items[i][1] == categoryi\n * 1 <= profiti <= 109\n * 1 <= categoryi <= n\n * 1 <= k <= n\n\"\"\"\nclass Solution:\n def findMaximumElegance(self, items: List[List[int]], k: int) -> int:\n ", "prompt_sft": "给你一个长度为 n 的二维整数数组 items 和一个整数 k 。\n\nitems[i] = [profiti, categoryi],其中 profiti 和 categoryi 分别表示第 i 个项目的利润和类别。\n\n现定义 items 的 子序列 的 优雅度 可以用 total_profit + distinct_categories2 计算,其中 total_profit 是子序列中所有项目的利润总和,distinct_categories 是所选子序列所含的所有类别中不同类别的数量。\n\n你的任务是从 items 所有长度为 k 的子序列中,找出 最大优雅度 。\n\n用整数形式表示并返回 items 中所有长度恰好为 k 的子序列的最大优雅度。\n\n注意:数组的子序列是经由原数组删除一些元素(可能不删除)而产生的新数组,且删除不改变其余元素相对顺序。\n\n示例 1:\n\n输入:items = [[3,2],[5,1],[10,1]], k = 2\n输出:17\n解释:\n在这个例子中,我们需要选出长度为 2 的子序列。\n其中一种方案是 items[0] = [3,2] 和 items[2] = [10,1] 。\n子序列的总利润为 3 + 10 = 13 ,子序列包含 2 种不同类别 [2,1] 。\n因此,优雅度为 13 + 22 = 17 ,可以证明 17 是可以获得的最大优雅度。\n\n示例 2:\n\n输入:items = [[3,1],[3,1],[2,2],[5,3]], k = 3\n输出:19\n解释:\n在这个例子中,我们需要选出长度为 3 的子序列。\n其中一种方案是 items[0] = [3,1] ,items[2] = [2,2] 和 items[3] = [5,3] 。\n子序列的总利润为 3 + 2 + 5 = 10 ,子序列包含 3 种不同类别 [1, 2, 3] 。\n因此,优雅度为 10 + 32 = 19 ,可以证明 19 是可以获得的最大优雅度。\n\n示例 3:\n\n输入:items = [[1,1],[2,1],[3,1]], k = 3\n输出:7\n解释:\n在这个例子中,我们需要选出长度为 3 的子序列。\n我们需要选中所有项目。\n子序列的总利润为 1 + 2 + 3 = 6,子序列包含 1 种不同类别 [1] 。\n因此,最大优雅度为 6 + 12 = 7 。\n\n提示:\n\n * 1 <= items.length == n <= 105\n * items[i].length == 2\n * items[i][0] == profiti\n * items[i][1] == categoryi\n * 1 <= profiti <= 109\n * 1 <= categoryi <= n\n * 1 <= k <= n\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def findMaximumElegance(self, items: List[List[int]], k: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"items\": [[3,2],[5,1],[10,1]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 17\n\ntest_input = { \"items\": [[3,1],[3,1],[2,2],[5,3]], \"k\": 3 }\nassert my_solution.findMaximumElegance(**test_input) == 19\n\ntest_input = { \"items\": [[1,1],[2,1],[3,1]], \"k\": 3 }\nassert my_solution.findMaximumElegance(**test_input) == 7\n\ntest_input = { \"items\": [[1,1],[1,2]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 6\n\ntest_input = { \"items\": [[1,1],[4,1]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 5\n\ntest_input = { \"items\": [[1,1],[4,1]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 6\n\ntest_input = { \"items\": [[1,1],[6,1]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 7\n\ntest_input = { \"items\": [[1,1],[6,1]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 8\n\ntest_input = { \"items\": [[1,1],[8,2]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 13\n\ntest_input = { \"items\": [[1,2],[6,2]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 7\n\ntest_input = { \"items\": [[1,2],[10,1]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 11\n\ntest_input = { \"items\": [[2,1],[6,1]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 9\n\ntest_input = { \"items\": [[2,1],[7,1]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 10\n\ntest_input = { \"items\": [[2,1],[9,2]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 10\n\ntest_input = { \"items\": [[2,2],[2,2]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 3\n\ntest_input = { \"items\": [[2,2],[2,2]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 5\n\ntest_input = { \"items\": [[2,2],[3,1]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 9\n\ntest_input = { \"items\": [[2,2],[6,1]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 12\n\ntest_input = { \"items\": [[3,1],[1,2]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 8\n\ntest_input = { \"items\": [[3,1],[9,1]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 13\n\ntest_input = { \"items\": [[3,1],[9,2]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 10\n\ntest_input = { \"items\": [[3,1],[10,2]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 17\n\ntest_input = { \"items\": [[3,2],[3,1]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 4\n\ntest_input = { \"items\": [[3,2],[5,2]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 6\n\ntest_input = { \"items\": [[3,2],[10,1]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 17\n\ntest_input = { \"items\": [[3,2],[10,2]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 14\n\ntest_input = { \"items\": [[4,1],[7,2]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 15\n\ntest_input = { \"items\": [[4,1],[9,2]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 10\n\ntest_input = { \"items\": [[4,2],[2,1]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 10\n\ntest_input = { \"items\": [[4,2],[3,1]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 11\n\ntest_input = { \"items\": [[4,2],[5,2]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 6\n\ntest_input = { \"items\": [[4,2],[7,2]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 8\n\ntest_input = { \"items\": [[4,2],[8,1]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 16\n\ntest_input = { \"items\": [[4,2],[10,1]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 18\n\ntest_input = { \"items\": [[5,1],[4,2]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 6\n\ntest_input = { \"items\": [[5,1],[8,1]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 14\n\ntest_input = { \"items\": [[5,1],[8,2]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 9\n\ntest_input = { \"items\": [[5,1],[9,1]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 10\n\ntest_input = { \"items\": [[5,2],[2,1]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 6\n\ntest_input = { \"items\": [[5,2],[4,2]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 10\n\ntest_input = { \"items\": [[5,2],[5,1]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 14\n\ntest_input = { \"items\": [[6,1],[1,1]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 7\n\ntest_input = { \"items\": [[6,1],[4,1]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 7\n\ntest_input = { \"items\": [[6,1],[7,1]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 8\n\ntest_input = { \"items\": [[6,1],[7,2]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 17\n\ntest_input = { \"items\": [[6,1],[8,1]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 15\n\ntest_input = { \"items\": [[6,1],[8,2]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 18\n\ntest_input = { \"items\": [[6,1],[9,1]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 10\n\ntest_input = { \"items\": [[6,2],[2,1]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 7\n\ntest_input = { \"items\": [[6,2],[4,2]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 7\n\ntest_input = { \"items\": [[6,2],[5,1]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 7\n\ntest_input = { \"items\": [[6,2],[6,2]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 7\n\ntest_input = { \"items\": [[6,2],[6,2]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 13\n\ntest_input = { \"items\": [[6,2],[7,1]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 8\n\ntest_input = { \"items\": [[6,2],[7,1]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 17\n\ntest_input = { \"items\": [[6,2],[8,2]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 15\n\ntest_input = { \"items\": [[6,2],[10,2]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 17\n\ntest_input = { \"items\": [[7,1],[1,1]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 8\n\ntest_input = { \"items\": [[7,1],[3,2]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 8\n\ntest_input = { \"items\": [[7,1],[6,1]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 14\n\ntest_input = { \"items\": [[7,2],[5,1]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 16\n\ntest_input = { \"items\": [[7,2],[5,2]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 8\n\ntest_input = { \"items\": [[7,2],[7,2]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 15\n\ntest_input = { \"items\": [[7,2],[10,2]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 18\n\ntest_input = { \"items\": [[8,1],[2,1]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 9\n\ntest_input = { \"items\": [[8,1],[2,2]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 9\n\ntest_input = { \"items\": [[8,1],[4,2]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 9\n\ntest_input = { \"items\": [[8,1],[5,1]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 9\n\ntest_input = { \"items\": [[8,1],[6,2]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 9\n\ntest_input = { \"items\": [[8,1],[8,1]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 17\n\ntest_input = { \"items\": [[8,1],[9,1]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 10\n\ntest_input = { \"items\": [[8,1],[9,2]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 21\n\ntest_input = { \"items\": [[8,2],[1,1]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 9\n\ntest_input = { \"items\": [[8,2],[1,2]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 9\n\ntest_input = { \"items\": [[8,2],[2,1]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 9\n\ntest_input = { \"items\": [[8,2],[8,2]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 9\n\ntest_input = { \"items\": [[8,2],[9,1]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 21\n\ntest_input = { \"items\": [[8,2],[9,2]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 18\n\ntest_input = { \"items\": [[8,2],[10,1]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 22\n\ntest_input = { \"items\": [[9,1],[1,1]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 10\n\ntest_input = { \"items\": [[9,1],[3,2]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 16\n\ntest_input = { \"items\": [[9,1],[4,2]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 17\n\ntest_input = { \"items\": [[9,1],[6,2]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 10\n\ntest_input = { \"items\": [[9,1],[9,2]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 10\n\ntest_input = { \"items\": [[9,1],[10,2]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 11\n\ntest_input = { \"items\": [[9,2],[1,2]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 10\n\ntest_input = { \"items\": [[9,2],[2,1]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 15\n\ntest_input = { \"items\": [[9,2],[6,1]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 19\n\ntest_input = { \"items\": [[9,2],[6,2]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 16\n\ntest_input = { \"items\": [[9,2],[8,2]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 10\n\ntest_input = { \"items\": [[10,1],[2,2]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 11\n\ntest_input = { \"items\": [[10,1],[4,2]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 11\n\ntest_input = { \"items\": [[10,1],[5,1]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 16\n\ntest_input = { \"items\": [[10,1],[5,2]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 19\n\ntest_input = { \"items\": [[10,1],[7,1]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 11\n\ntest_input = { \"items\": [[10,2],[1,2]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 11\n\ntest_input = { \"items\": [[10,2],[4,1]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 11\n\ntest_input = { \"items\": [[10,2],[5,1]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 11\n\ntest_input = { \"items\": [[10,2],[7,1]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 11\n\ntest_input = { \"items\": [[10,2],[8,2]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 19", "start_time": 1691289000} +{"task_id": "biweekly-contest-110-account-balance-after-rounded-purchase", "url": "https://leetcode.com/problems/account-balance-after-rounded-purchase", "title": "account-balance-after-rounded-purchase", "meta": {"questionId": "2955", "questionFrontendId": "2806", "title": "Account Balance After Rounded Purchase", "titleSlug": "account-balance-after-rounded-purchase", "isPaidOnly": false, "difficulty": "Easy", "likes": 178, "dislikes": 37, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n一开始,你的银行账户里有 100 块钱。\n\n给你一个整数purchaseAmount ,它表示你在一次购买中愿意支出的金额。\n\n在一个商店里,你进行一次购买,实际支出的金额会向 最近 的 10 的 倍数 取整。换句话说,你实际会支付一个 非负 金额 roundedAmount ,满足 roundedAmount 是 10 的倍数且 abs(roundedAmount - purchaseAmount) 的值 最小 。\n\n如果存在多于一个最接近的 10 的倍数,较大的倍数 是你的实际支出金额。\n\n请你返回一个整数,表示你在愿意支出金额为 purchaseAmount 块钱的前提下,购买之后剩下的余额。\n\n注意: 0 也是 10 的倍数。\n\n示例 1:\n\n输入:purchaseAmount = 9\n输出:90\n解释:这个例子中,最接近 9 的 10 的倍数是 10 。所以你的账户余额为 100 - 10 = 90 。\n\n示例 2:\n\n输入:purchaseAmount = 15\n输出:80\n解释:这个例子中,有 2 个最接近 15 的 10 的倍数:10 和 20,较大的数 20 是你的实际开销。\n所以你的账户余额为 100 - 20 = 80 。\n\n\n提示:\n\n * 0 <= purchaseAmount <= 100\n\"\"\"\nclass Solution:\n def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n ", "prompt_sft": "一开始,你的银行账户里有 100 块钱。\n\n给你一个整数purchaseAmount ,它表示你在一次购买中愿意支出的金额。\n\n在一个商店里,你进行一次购买,实际支出的金额会向 最近 的 10 的 倍数 取整。换句话说,你实际会支付一个 非负 金额 roundedAmount ,满足 roundedAmount 是 10 的倍数且 abs(roundedAmount - purchaseAmount) 的值 最小 。\n\n如果存在多于一个最接近的 10 的倍数,较大的倍数 是你的实际支出金额。\n\n请你返回一个整数,表示你在愿意支出金额为 purchaseAmount 块钱的前提下,购买之后剩下的余额。\n\n注意: 0 也是 10 的倍数。\n\n示例 1:\n\n输入:purchaseAmount = 9\n输出:90\n解释:这个例子中,最接近 9 的 10 的倍数是 10 。所以你的账户余额为 100 - 10 = 90 。\n\n示例 2:\n\n输入:purchaseAmount = 15\n输出:80\n解释:这个例子中,有 2 个最接近 15 的 10 的倍数:10 和 20,较大的数 20 是你的实际开销。\n所以你的账户余额为 100 - 20 = 80 。\n\n\n提示:\n\n * 0 <= purchaseAmount <= 100\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"purchaseAmount\": 9 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 90\n\ntest_input = { \"purchaseAmount\": 15 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 80\n\ntest_input = { \"purchaseAmount\": 10 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 90\n\ntest_input = { \"purchaseAmount\": 11 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 90\n\ntest_input = { \"purchaseAmount\": 12 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 90\n\ntest_input = { \"purchaseAmount\": 13 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 90\n\ntest_input = { \"purchaseAmount\": 14 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 90\n\ntest_input = { \"purchaseAmount\": 16 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 80\n\ntest_input = { \"purchaseAmount\": 17 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 80\n\ntest_input = { \"purchaseAmount\": 18 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 80\n\ntest_input = { \"purchaseAmount\": 19 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 80\n\ntest_input = { \"purchaseAmount\": 1 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 100\n\ntest_input = { \"purchaseAmount\": 2 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 100\n\ntest_input = { \"purchaseAmount\": 3 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 100\n\ntest_input = { \"purchaseAmount\": 4 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 100\n\ntest_input = { \"purchaseAmount\": 5 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 90\n\ntest_input = { \"purchaseAmount\": 6 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 90\n\ntest_input = { \"purchaseAmount\": 7 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 90\n\ntest_input = { \"purchaseAmount\": 8 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 90\n\ntest_input = { \"purchaseAmount\": 20 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 80\n\ntest_input = { \"purchaseAmount\": 21 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 80\n\ntest_input = { \"purchaseAmount\": 22 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 80\n\ntest_input = { \"purchaseAmount\": 23 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 80\n\ntest_input = { \"purchaseAmount\": 24 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 80\n\ntest_input = { \"purchaseAmount\": 25 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 70\n\ntest_input = { \"purchaseAmount\": 26 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 70\n\ntest_input = { \"purchaseAmount\": 27 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 70\n\ntest_input = { \"purchaseAmount\": 28 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 70\n\ntest_input = { \"purchaseAmount\": 29 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 70\n\ntest_input = { \"purchaseAmount\": 30 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 70\n\ntest_input = { \"purchaseAmount\": 31 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 70\n\ntest_input = { \"purchaseAmount\": 32 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 70\n\ntest_input = { \"purchaseAmount\": 33 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 70\n\ntest_input = { \"purchaseAmount\": 34 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 70\n\ntest_input = { \"purchaseAmount\": 35 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 60\n\ntest_input = { \"purchaseAmount\": 36 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 60\n\ntest_input = { \"purchaseAmount\": 37 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 60\n\ntest_input = { \"purchaseAmount\": 38 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 60\n\ntest_input = { \"purchaseAmount\": 39 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 60\n\ntest_input = { \"purchaseAmount\": 40 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 60\n\ntest_input = { \"purchaseAmount\": 41 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 60\n\ntest_input = { \"purchaseAmount\": 42 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 60\n\ntest_input = { \"purchaseAmount\": 43 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 60\n\ntest_input = { \"purchaseAmount\": 44 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 60\n\ntest_input = { \"purchaseAmount\": 45 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 50\n\ntest_input = { \"purchaseAmount\": 46 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 50\n\ntest_input = { \"purchaseAmount\": 47 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 50\n\ntest_input = { \"purchaseAmount\": 48 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 50\n\ntest_input = { \"purchaseAmount\": 49 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 50\n\ntest_input = { \"purchaseAmount\": 50 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 50\n\ntest_input = { \"purchaseAmount\": 51 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 50\n\ntest_input = { \"purchaseAmount\": 52 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 50\n\ntest_input = { \"purchaseAmount\": 53 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 50\n\ntest_input = { \"purchaseAmount\": 54 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 50\n\ntest_input = { \"purchaseAmount\": 55 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 40\n\ntest_input = { \"purchaseAmount\": 56 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 40\n\ntest_input = { \"purchaseAmount\": 57 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 40\n\ntest_input = { \"purchaseAmount\": 58 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 40\n\ntest_input = { \"purchaseAmount\": 59 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 40\n\ntest_input = { \"purchaseAmount\": 60 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 40\n\ntest_input = { \"purchaseAmount\": 61 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 40\n\ntest_input = { \"purchaseAmount\": 62 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 40\n\ntest_input = { \"purchaseAmount\": 63 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 40\n\ntest_input = { \"purchaseAmount\": 64 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 40\n\ntest_input = { \"purchaseAmount\": 65 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 30\n\ntest_input = { \"purchaseAmount\": 66 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 30\n\ntest_input = { \"purchaseAmount\": 67 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 30\n\ntest_input = { \"purchaseAmount\": 68 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 30\n\ntest_input = { \"purchaseAmount\": 69 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 30\n\ntest_input = { \"purchaseAmount\": 70 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 30\n\ntest_input = { \"purchaseAmount\": 71 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 30\n\ntest_input = { \"purchaseAmount\": 72 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 30\n\ntest_input = { \"purchaseAmount\": 73 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 30\n\ntest_input = { \"purchaseAmount\": 74 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 30\n\ntest_input = { \"purchaseAmount\": 75 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 20\n\ntest_input = { \"purchaseAmount\": 76 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 20\n\ntest_input = { \"purchaseAmount\": 77 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 20\n\ntest_input = { \"purchaseAmount\": 78 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 20\n\ntest_input = { \"purchaseAmount\": 79 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 20\n\ntest_input = { \"purchaseAmount\": 80 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 20\n\ntest_input = { \"purchaseAmount\": 81 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 20\n\ntest_input = { \"purchaseAmount\": 82 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 20\n\ntest_input = { \"purchaseAmount\": 83 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 20\n\ntest_input = { \"purchaseAmount\": 84 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 20\n\ntest_input = { \"purchaseAmount\": 85 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 10\n\ntest_input = { \"purchaseAmount\": 86 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 10\n\ntest_input = { \"purchaseAmount\": 87 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 10\n\ntest_input = { \"purchaseAmount\": 88 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 10\n\ntest_input = { \"purchaseAmount\": 89 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 10\n\ntest_input = { \"purchaseAmount\": 90 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 10\n\ntest_input = { \"purchaseAmount\": 91 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 10\n\ntest_input = { \"purchaseAmount\": 92 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 10\n\ntest_input = { \"purchaseAmount\": 93 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 10\n\ntest_input = { \"purchaseAmount\": 94 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 10\n\ntest_input = { \"purchaseAmount\": 95 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 0\n\ntest_input = { \"purchaseAmount\": 96 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 0\n\ntest_input = { \"purchaseAmount\": 97 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 0\n\ntest_input = { \"purchaseAmount\": 98 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 0\n\ntest_input = { \"purchaseAmount\": 99 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 0\n\ntest_input = { \"purchaseAmount\": 100 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 0", "start_time": 1691245800} +{"task_id": "biweekly-contest-110-insert-greatest-common-divisors-in-linked-list", "url": "https://leetcode.com/problems/insert-greatest-common-divisors-in-linked-list", "title": "insert-greatest-common-divisors-in-linked-list", "meta": {"questionId": "2903", "questionFrontendId": "2807", "title": "Insert Greatest Common Divisors in Linked List", "titleSlug": "insert-greatest-common-divisors-in-linked-list", "isPaidOnly": false, "difficulty": "Medium", "likes": 390, "dislikes": 12, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个链表的头 head ,每个结点包含一个整数值。\n\n在相邻结点之间,请你插入一个新的结点,结点值为这两个相邻结点值的 最大公约数 。\n\n请你返回插入之后的链表。\n\n两个数的 最大公约数 是可以被两个数字整除的最大正整数。\n\n示例 1:\n\n[https://assets.leetcode.com/uploads/2023/07/18/ex1_copy.png]\n\n输入:head = [18,6,10,3]\n输出:[18,6,6,2,10,1,3]\n解释:第一幅图是一开始的链表,第二幅图是插入新结点后的图(蓝色结点为新插入结点)。\n- 18 和 6 的最大公约数为 6 ,插入第一和第二个结点之间。\n- 6 和 10 的最大公约数为 2 ,插入第二和第三个结点之间。\n- 10 和 3 的最大公约数为 1 ,插入第三和第四个结点之间。\n所有相邻结点之间都插入完毕,返回链表。\n\n示例 2:\n\n[https://assets.leetcode.com/uploads/2023/07/18/ex2_copy1.png]\n\n输入:head = [7]\n输出:[7]\n解释:第一幅图是一开始的链表,第二幅图是插入新结点后的图(蓝色结点为新插入结点)。\n没有相邻结点,所以返回初始链表。\n\n\n提示:\n\n * 链表中结点数目在 [1, 5000] 之间。\n * 1 <= Node.val <= 1000\n\"\"\"\n# Definition for singly-linked list.\nclass ListNode:\n def __init__(self, val=0, next=None):\n self.val = val\n self.next = next\nclass Solution:\n def insertGreatestCommonDivisors(self, head: Optional[ListNode]) -> Optional[ListNode]:\n ", "prompt_sft": "给你一个链表的头 head ,每个结点包含一个整数值。\n\n在相邻结点之间,请你插入一个新的结点,结点值为这两个相邻结点值的 最大公约数 。\n\n请你返回插入之后的链表。\n\n两个数的 最大公约数 是可以被两个数字整除的最大正整数。\n\n示例 1:\n\n[https://assets.leetcode.com/uploads/2023/07/18/ex1_copy.png]\n\n输入:head = [18,6,10,3]\n输出:[18,6,6,2,10,1,3]\n解释:第一幅图是一开始的链表,第二幅图是插入新结点后的图(蓝色结点为新插入结点)。\n- 18 和 6 的最大公约数为 6 ,插入第一和第二个结点之间。\n- 6 和 10 的最大公约数为 2 ,插入第二和第三个结点之间。\n- 10 和 3 的最大公约数为 1 ,插入第三和第四个结点之间。\n所有相邻结点之间都插入完毕,返回链表。\n\n示例 2:\n\n[https://assets.leetcode.com/uploads/2023/07/18/ex2_copy1.png]\n\n输入:head = [7]\n输出:[7]\n解释:第一幅图是一开始的链表,第二幅图是插入新结点后的图(蓝色结点为新插入结点)。\n没有相邻结点,所以返回初始链表。\n\n\n提示:\n\n * 链表中结点数目在 [1, 5000] 之间。\n * 1 <= Node.val <= 1000\n\n\n请完成下面的代码来解决上述问题:\n```python\n# Definition for singly-linked list.\nclass ListNode:\n def __init__(self, val=0, next=None):\n self.val = val\n self.next = next\nclass Solution:\n def insertGreatestCommonDivisors(self, head: Optional[ListNode]) -> Optional[ListNode]:\n \n```", "test": "\nmy_solution = Solution()\n\n_f1 = lambda lst: ListNode(lst[0], _f1(lst[1:])) if lst else None\n_f2 = lambda node: [node.val] + _f2(node.next) if node else []\n\n\ntest_input = { \"head\": _f1([18,6,10,3]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [18,6,6,2,10,1,3]\n\ntest_input = { \"head\": _f1([7]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [7]\n\ntest_input = { \"head\": _f1([19]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [19]\n\ntest_input = { \"head\": _f1([2]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [2]\n\ntest_input = { \"head\": _f1([13]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [13]\n\ntest_input = { \"head\": _f1([8]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [8]\n\ntest_input = { \"head\": _f1([1]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [1]\n\ntest_input = { \"head\": _f1([3]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [3]\n\ntest_input = { \"head\": _f1([20]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [20]\n\ntest_input = { \"head\": _f1([14]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [14]\n\ntest_input = { \"head\": _f1([16]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [16]\n\ntest_input = { \"head\": _f1([12]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [12]\n\ntest_input = { \"head\": _f1([9]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [9]\n\ntest_input = { \"head\": _f1([5]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [5]\n\ntest_input = { \"head\": _f1([4]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [4]\n\ntest_input = { \"head\": _f1([18]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [18]\n\ntest_input = { \"head\": _f1([11]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [11]\n\ntest_input = { \"head\": _f1([17]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [17]\n\ntest_input = { \"head\": _f1([15]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [15]\n\ntest_input = { \"head\": _f1([11,13]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [11,1,13]\n\ntest_input = { \"head\": _f1([7,13]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [7,1,13]\n\ntest_input = { \"head\": _f1([18,17]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [18,1,17]\n\ntest_input = { \"head\": _f1([15,17]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [15,1,17]\n\ntest_input = { \"head\": _f1([13,8]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [13,1,8]\n\ntest_input = { \"head\": _f1([12,16]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [12,4,16]\n\ntest_input = { \"head\": _f1([12,8]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [12,4,8]\n\ntest_input = { \"head\": _f1([18,16]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [18,2,16]\n\ntest_input = { \"head\": _f1([16,16]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [16,16,16]\n\ntest_input = { \"head\": _f1([6,12]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [6,6,12]\n\ntest_input = { \"head\": _f1([9,6]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [9,3,6]\n\ntest_input = { \"head\": _f1([2,17]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [2,1,17]\n\ntest_input = { \"head\": _f1([7,5]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [7,1,5]\n\ntest_input = { \"head\": _f1([15,6]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [15,3,6]\n\ntest_input = { \"head\": _f1([3,14]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [3,1,14]\n\ntest_input = { \"head\": _f1([6,16]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [6,2,16]\n\ntest_input = { \"head\": _f1([3,16]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [3,1,16]\n\ntest_input = { \"head\": _f1([11,9]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [11,1,9]\n\ntest_input = { \"head\": _f1([4,15]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [4,1,15]\n\ntest_input = { \"head\": _f1([16,2]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [16,2,2]\n\ntest_input = { \"head\": _f1([12,7]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [12,1,7]\n\ntest_input = { \"head\": _f1([7,9]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [7,1,9]\n\ntest_input = { \"head\": _f1([7,3]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [7,1,3]\n\ntest_input = { \"head\": _f1([8,4]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [8,4,4]\n\ntest_input = { \"head\": _f1([4,11]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [4,1,11]\n\ntest_input = { \"head\": _f1([6,15]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [6,3,15]\n\ntest_input = { \"head\": _f1([9,7]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [9,1,7]\n\ntest_input = { \"head\": _f1([19,4]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [19,1,4]\n\ntest_input = { \"head\": _f1([17,6,18]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [17,1,6,6,18]\n\ntest_input = { \"head\": _f1([10,8,3]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [10,2,8,1,3]\n\ntest_input = { \"head\": _f1([11,4,10]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [11,1,4,2,10]\n\ntest_input = { \"head\": _f1([5,3,13]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [5,1,3,1,13]\n\ntest_input = { \"head\": _f1([2,1,15]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [2,1,1,1,15]\n\ntest_input = { \"head\": _f1([17,13,9]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [17,1,13,1,9]\n\ntest_input = { \"head\": _f1([2,15,12]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [2,1,15,3,12]\n\ntest_input = { \"head\": _f1([16,12,13]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [16,4,12,1,13]\n\ntest_input = { \"head\": _f1([1,12,19]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [1,1,12,1,19]\n\ntest_input = { \"head\": _f1([4,3,3]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [4,1,3,3,3]\n\ntest_input = { \"head\": _f1([15,11,3]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [15,1,11,1,3]\n\ntest_input = { \"head\": _f1([15,18,16]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [15,3,18,2,16]\n\ntest_input = { \"head\": _f1([20,6,7]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [20,2,6,1,7]\n\ntest_input = { \"head\": _f1([9,4,7]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [9,1,4,1,7]\n\ntest_input = { \"head\": _f1([20,11,6]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [20,1,11,1,6]\n\ntest_input = { \"head\": _f1([11,8,16]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [11,1,8,8,16]\n\ntest_input = { \"head\": _f1([1,4,12]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [1,1,4,4,12]\n\ntest_input = { \"head\": _f1([18,12,19]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [18,6,12,1,19]\n\ntest_input = { \"head\": _f1([8,11,5]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [8,1,11,1,5]\n\ntest_input = { \"head\": _f1([6,10,6]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [6,2,10,2,6]\n\ntest_input = { \"head\": _f1([3,10,16]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [3,1,10,2,16]\n\ntest_input = { \"head\": _f1([15,6,15]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [15,3,6,3,15]\n\ntest_input = { \"head\": _f1([9,5,1]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [9,1,5,1,1]\n\ntest_input = { \"head\": _f1([15,15,18]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [15,15,15,3,18]\n\ntest_input = { \"head\": _f1([3,16,13]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [3,1,16,1,13]\n\ntest_input = { \"head\": _f1([9,3,6]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [9,3,3,3,6]\n\ntest_input = { \"head\": _f1([4,14,9]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [4,2,14,1,9]\n\ntest_input = { \"head\": _f1([15,2,20]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [15,1,2,2,20]\n\ntest_input = { \"head\": _f1([13,7,19]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [13,1,7,1,19]\n\ntest_input = { \"head\": _f1([19,19,12]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [19,19,19,1,12]\n\ntest_input = { \"head\": _f1([8,6,1]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [8,2,6,1,1]\n\ntest_input = { \"head\": _f1([19,10,19]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [19,1,10,1,19]\n\ntest_input = { \"head\": _f1([6,9,17]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [6,3,9,1,17]\n\ntest_input = { \"head\": _f1([3,19,8]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [3,1,19,1,8]\n\ntest_input = { \"head\": _f1([12,6,9]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [12,6,6,3,9]\n\ntest_input = { \"head\": _f1([14,16,19]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [14,2,16,1,19]\n\ntest_input = { \"head\": _f1([12,14,16,12]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [12,2,14,2,16,4,12]\n\ntest_input = { \"head\": _f1([20,13,19,12]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [20,1,13,1,19,1,12]\n\ntest_input = { \"head\": _f1([14,13,8,8]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [14,1,13,1,8,8,8]\n\ntest_input = { \"head\": _f1([13,3,3,5]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [13,1,3,3,3,1,5]\n\ntest_input = { \"head\": _f1([11,7,15,7]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [11,1,7,1,15,1,7]\n\ntest_input = { \"head\": _f1([11,7,5,1]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [11,1,7,1,5,1,1]\n\ntest_input = { \"head\": _f1([8,7,15,13]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [8,1,7,1,15,1,13]\n\ntest_input = { \"head\": _f1([1,19,3,19]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [1,1,19,1,3,1,19]\n\ntest_input = { \"head\": _f1([15,19,1,7]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [15,1,19,1,1,1,7]\n\ntest_input = { \"head\": _f1([13,20,9,1]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [13,1,20,1,9,1,1]\n\ntest_input = { \"head\": _f1([18,16,6,9]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [18,2,16,2,6,3,9]\n\ntest_input = { \"head\": _f1([16,6,13,11]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [16,2,6,1,13,1,11]\n\ntest_input = { \"head\": _f1([9,5,1,6]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [9,1,5,1,1,1,6]\n\ntest_input = { \"head\": _f1([3,15,10,12]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [3,3,15,5,10,2,12]\n\ntest_input = { \"head\": _f1([1,9,19,15]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [1,1,9,1,19,1,15]\n\ntest_input = { \"head\": _f1([14,14,19,2]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [14,14,14,1,19,1,2]\n\ntest_input = { \"head\": _f1([5,13,5,4]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [5,1,13,1,5,1,4]", "start_time": 1691245800} +{"task_id": "biweekly-contest-110-minimum-seconds-to-equalize-a-circular-array", "url": "https://leetcode.com/problems/minimum-seconds-to-equalize-a-circular-array", "title": "minimum-seconds-to-equalize-a-circular-array", "meta": {"questionId": "2920", "questionFrontendId": "2808", "title": "Minimum Seconds to Equalize a Circular Array", "titleSlug": "minimum-seconds-to-equalize-a-circular-array", "isPaidOnly": false, "difficulty": "Medium", "likes": 481, "dislikes": 25, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0 开始长度为 n 的数组 nums 。\n\n每一秒,你可以对数组执行以下操作:\n\n * 对于范围在 [0, n - 1] 内的每一个下标 i ,将 nums[i] 替换成 nums[i] ,nums[(i - 1 + n) % n] 或者 nums[(i + 1) % n] 三者之一。\n\n注意,所有元素会被同时替换。\n\n请你返回将数组 nums 中所有元素变成相等元素所需要的 最少 秒数。\n\n示例 1:\n\n输入:nums = [1,2,1,2]\n输出:1\n解释:我们可以在 1 秒内将数组变成相等元素:\n- 第 1 秒,将每个位置的元素分别变为 [nums[3],nums[1],nums[3],nums[3]] 。变化后,nums = [2,2,2,2] 。\n1 秒是将数组变成相等元素所需要的最少秒数。\n\n示例 2:\n\n输入:nums = [2,1,3,3,2]\n输出:2\n解释:我们可以在 2 秒内将数组变成相等元素:\n- 第 1 秒,将每个位置的元素分别变为 [nums[0],nums[2],nums[2],nums[2],nums[3]] 。变化后,nums = [2,3,3,3,3] 。\n- 第 2 秒,将每个位置的元素分别变为 [nums[1],nums[1],nums[2],nums[3],nums[4]] 。变化后,nums = [3,3,3,3,3] 。\n2 秒是将数组变成相等元素所需要的最少秒数。\n\n示例 3:\n\n输入:nums = [5,5,5,5]\n输出:0\n解释:不需要执行任何操作,因为一开始数组中的元素已经全部相等。\n\n\n提示:\n\n * 1 <= n == nums.length <= 105\n * 1 <= nums[i] <= 109\n\"\"\"\nclass Solution:\n def minimumSeconds(self, nums: List[int]) -> int:\n ", "prompt_sft": "给你一个下标从 0 开始长度为 n 的数组 nums 。\n\n每一秒,你可以对数组执行以下操作:\n\n * 对于范围在 [0, n - 1] 内的每一个下标 i ,将 nums[i] 替换成 nums[i] ,nums[(i - 1 + n) % n] 或者 nums[(i + 1) % n] 三者之一。\n\n注意,所有元素会被同时替换。\n\n请你返回将数组 nums 中所有元素变成相等元素所需要的 最少 秒数。\n\n示例 1:\n\n输入:nums = [1,2,1,2]\n输出:1\n解释:我们可以在 1 秒内将数组变成相等元素:\n- 第 1 秒,将每个位置的元素分别变为 [nums[3],nums[1],nums[3],nums[3]] 。变化后,nums = [2,2,2,2] 。\n1 秒是将数组变成相等元素所需要的最少秒数。\n\n示例 2:\n\n输入:nums = [2,1,3,3,2]\n输出:2\n解释:我们可以在 2 秒内将数组变成相等元素:\n- 第 1 秒,将每个位置的元素分别变为 [nums[0],nums[2],nums[2],nums[2],nums[3]] 。变化后,nums = [2,3,3,3,3] 。\n- 第 2 秒,将每个位置的元素分别变为 [nums[1],nums[1],nums[2],nums[3],nums[4]] 。变化后,nums = [3,3,3,3,3] 。\n2 秒是将数组变成相等元素所需要的最少秒数。\n\n示例 3:\n\n输入:nums = [5,5,5,5]\n输出:0\n解释:不需要执行任何操作,因为一开始数组中的元素已经全部相等。\n\n\n提示:\n\n * 1 <= n == nums.length <= 105\n * 1 <= nums[i] <= 109\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def minimumSeconds(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,2,1,2] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [2,1,3,3,2] }\nassert my_solution.minimumSeconds(**test_input) == 2\n\ntest_input = { \"nums\": [5,5,5,5] }\nassert my_solution.minimumSeconds(**test_input) == 0\n\ntest_input = { \"nums\": [4,18] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [11,7] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [14,2] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [14,9] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [20,1] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [17,15] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [11,13] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [7,13] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [18,17] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [15,17] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [13,8] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [12,16] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [12,8] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [18,16] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [16,16] }\nassert my_solution.minimumSeconds(**test_input) == 0\n\ntest_input = { \"nums\": [6,12] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [9,6] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [2,17] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [7,5] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [15,6] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [3,14] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [6,16] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [3,16] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [11,9] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [4,15] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [16,2] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [12,7] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [7,9] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [7,3] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [8,4] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [4,11] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [6,15] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [9,7] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [19,4] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [17,6] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [18,10] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [8,3] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [11,4,10] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [5,3,13] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [2,1,15] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [17,13,9] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [2,15,12] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [16,12,13] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [1,12,19] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [4,3,3] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [15,11,3] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [15,18,16] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [20,6,7] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [9,4,7] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [20,11,6] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [11,8,16] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [1,4,12] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [18,12,19] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [8,11,5] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [6,10,6] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [3,10,16] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [15,6,15] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [9,5,1] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [15,15,18] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [3,16,13] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [9,3,6] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [4,14,9] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [15,2,20] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [13,7,19] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [19,19,12] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [8,6,1] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [19,10,19] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [6,9,17] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [3,19,8,12] }\nassert my_solution.minimumSeconds(**test_input) == 2\n\ntest_input = { \"nums\": [6,9,14,16] }\nassert my_solution.minimumSeconds(**test_input) == 2\n\ntest_input = { \"nums\": [19,12,14,16] }\nassert my_solution.minimumSeconds(**test_input) == 2\n\ntest_input = { \"nums\": [12,20,13,19] }\nassert my_solution.minimumSeconds(**test_input) == 2\n\ntest_input = { \"nums\": [12,14,13,8] }\nassert my_solution.minimumSeconds(**test_input) == 2\n\ntest_input = { \"nums\": [8,13,3,3] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [5,11,7,15] }\nassert my_solution.minimumSeconds(**test_input) == 2\n\ntest_input = { \"nums\": [7,11,7,5] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [1,8,7,15] }\nassert my_solution.minimumSeconds(**test_input) == 2\n\ntest_input = { \"nums\": [13,1,19,3] }\nassert my_solution.minimumSeconds(**test_input) == 2\n\ntest_input = { \"nums\": [19,15,19,1] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [7,13,20,9] }\nassert my_solution.minimumSeconds(**test_input) == 2\n\ntest_input = { \"nums\": [1,18,16,6] }\nassert my_solution.minimumSeconds(**test_input) == 2\n\ntest_input = { \"nums\": [9,16,6,13] }\nassert my_solution.minimumSeconds(**test_input) == 2\n\ntest_input = { \"nums\": [11,9,5,1] }\nassert my_solution.minimumSeconds(**test_input) == 2\n\ntest_input = { \"nums\": [6,3,15,10] }\nassert my_solution.minimumSeconds(**test_input) == 2\n\ntest_input = { \"nums\": [12,1,9,19] }\nassert my_solution.minimumSeconds(**test_input) == 2\n\ntest_input = { \"nums\": [15,14,14,19] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [2,5,13,5] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [4,8,8,13] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [3,9,10,13] }\nassert my_solution.minimumSeconds(**test_input) == 2\n\ntest_input = { \"nums\": [7,17,11,8] }\nassert my_solution.minimumSeconds(**test_input) == 2\n\ntest_input = { \"nums\": [4,5,15,11] }\nassert my_solution.minimumSeconds(**test_input) == 2\n\ntest_input = { \"nums\": [11,15,19,12] }\nassert my_solution.minimumSeconds(**test_input) == 2\n\ntest_input = { \"nums\": [8,20,5,10] }\nassert my_solution.minimumSeconds(**test_input) == 2\n\ntest_input = { \"nums\": [5,3,5,17] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [14,19,8,8] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [16,20,4,13] }\nassert my_solution.minimumSeconds(**test_input) == 2\n\ntest_input = { \"nums\": [17,16,2,16] }\nassert my_solution.minimumSeconds(**test_input) == 1", "start_time": 1691245800} +{"task_id": "biweekly-contest-110-minimum-time-to-make-array-sum-at-most-x", "url": "https://leetcode.com/problems/minimum-time-to-make-array-sum-at-most-x", "title": "minimum-time-to-make-array-sum-at-most-x", "meta": {"questionId": "2952", "questionFrontendId": "2809", "title": "Minimum Time to Make Array Sum At Most x", "titleSlug": "minimum-time-to-make-array-sum-at-most-x", "isPaidOnly": false, "difficulty": "Hard", "likes": 207, "dislikes": 10, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你两个长度相等下标从 0 开始的整数数组 nums1 和 nums2 。每一秒,对于所有下标 0 <= i < nums1.length ,nums1[i] 的值都增加 nums2[i] 。操作 完成后 ,你可以进行如下操作:\n\n * 选择任一满足 0 <= i < nums1.length 的下标 i ,并使 nums1[i] = 0 。\n\n同时给你一个整数 x 。\n\n请你返回使 nums1 中所有元素之和 小于等于 x 所需要的 最少 时间,如果无法实现,那么返回 -1 。\n\n示例 1:\n\n输入:nums1 = [1,2,3], nums2 = [1,2,3], x = 4\n输出:3\n解释:\n第 1 秒,我们对 i = 0 进行操作,得到 nums1 = [0,2+2,3+3] = [0,4,6] 。\n第 2 秒,我们对 i = 1 进行操作,得到 nums1 = [0+1,0,6+3] = [1,0,9] 。\n第 3 秒,我们对 i = 2 进行操作,得到 nums1 = [1+1,0+2,0] = [2,2,0] 。\n现在 nums1 的和为 4 。不存在更少次数的操作,所以我们返回 3 。\n\n示例 2:\n\n输入:nums1 = [1,2,3], nums2 = [3,3,3], x = 4\n输出:-1\n解释:不管如何操作,nums1 的和总是会超过 x 。\n\n\n提示:\n\n * 1 <= nums1.length <= 103\n * 1 <= nums1[i] <= 103\n * 0 <= nums2[i] <= 103\n * nums1.length == nums2.length\n * 0 <= x <= 106\n\"\"\"\nclass Solution:\n def minimumTime(self, nums1: List[int], nums2: List[int], x: int) -> int:\n ", "prompt_sft": "给你两个长度相等下标从 0 开始的整数数组 nums1 和 nums2 。每一秒,对于所有下标 0 <= i < nums1.length ,nums1[i] 的值都增加 nums2[i] 。操作 完成后 ,你可以进行如下操作:\n\n * 选择任一满足 0 <= i < nums1.length 的下标 i ,并使 nums1[i] = 0 。\n\n同时给你一个整数 x 。\n\n请你返回使 nums1 中所有元素之和 小于等于 x 所需要的 最少 时间,如果无法实现,那么返回 -1 。\n\n示例 1:\n\n输入:nums1 = [1,2,3], nums2 = [1,2,3], x = 4\n输出:3\n解释:\n第 1 秒,我们对 i = 0 进行操作,得到 nums1 = [0,2+2,3+3] = [0,4,6] 。\n第 2 秒,我们对 i = 1 进行操作,得到 nums1 = [0+1,0,6+3] = [1,0,9] 。\n第 3 秒,我们对 i = 2 进行操作,得到 nums1 = [1+1,0+2,0] = [2,2,0] 。\n现在 nums1 的和为 4 。不存在更少次数的操作,所以我们返回 3 。\n\n示例 2:\n\n输入:nums1 = [1,2,3], nums2 = [3,3,3], x = 4\n输出:-1\n解释:不管如何操作,nums1 的和总是会超过 x 。\n\n\n提示:\n\n * 1 <= nums1.length <= 103\n * 1 <= nums1[i] <= 103\n * 0 <= nums2[i] <= 103\n * nums1.length == nums2.length\n * 0 <= x <= 106\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def minimumTime(self, nums1: List[int], nums2: List[int], x: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums1\": [1,2,3], \"nums2\": [1,2,3], \"x\": 4 }\nassert my_solution.minimumTime(**test_input) == 3\n\ntest_input = { \"nums1\": [1,2,3], \"nums2\": [3,3,3], \"x\": 4 }\nassert my_solution.minimumTime(**test_input) == -1\n\ntest_input = { \"nums1\": [4,4,9,10], \"nums2\": [4,4,1,3], \"x\": 16 }\nassert my_solution.minimumTime(**test_input) == 4\n\ntest_input = { \"nums1\": [5,3], \"nums2\": [3,2], \"x\": 4 }\nassert my_solution.minimumTime(**test_input) == 2\n\ntest_input = { \"nums1\": [4,5,3,2,3,9,5,7,10,4], \"nums2\": [4,4,0,4,1,2,4,0,4,0], \"x\": 47 }\nassert my_solution.minimumTime(**test_input) == -1\n\ntest_input = { \"nums1\": [7,9,8,5,8,3], \"nums2\": [0,1,4,2,3,1], \"x\": 37 }\nassert my_solution.minimumTime(**test_input) == 2\n\ntest_input = { \"nums1\": [8,2,3], \"nums2\": [1,4,2], \"x\": 13 }\nassert my_solution.minimumTime(**test_input) == 0\n\ntest_input = { \"nums1\": [4,7,2,3,4,3,10,8], \"nums2\": [3,4,0,1,1,0,2,2], \"x\": 36 }\nassert my_solution.minimumTime(**test_input) == 4\n\ntest_input = { \"nums1\": [2,10,10,4,6,3], \"nums2\": [1,0,0,1,3,1], \"x\": 35 }\nassert my_solution.minimumTime(**test_input) == 0\n\ntest_input = { \"nums1\": [9,5,3], \"nums2\": [4,1,3], \"x\": 17 }\nassert my_solution.minimumTime(**test_input) == 0\n\ntest_input = { \"nums1\": [1,7,9,4,8,8,1], \"nums2\": [2,2,3,2,0,1,0], \"x\": 20 }\nassert my_solution.minimumTime(**test_input) == 6\n\ntest_input = { \"nums1\": [9,2,8,3,1,9,7,6], \"nums2\": [0,3,4,1,3,4,2,1], \"x\": 40 }\nassert my_solution.minimumTime(**test_input) == 8\n\ntest_input = { \"nums1\": [10], \"nums2\": [3], \"x\": 10 }\nassert my_solution.minimumTime(**test_input) == 0\n\ntest_input = { \"nums1\": [7,6,8,2,8,9,3,3], \"nums2\": [2,2,4,0,0,2,2,3], \"x\": 45 }\nassert my_solution.minimumTime(**test_input) == 5\n\ntest_input = { \"nums1\": [4,9,5,2,3], \"nums2\": [4,2,0,4,0], \"x\": 18 }\nassert my_solution.minimumTime(**test_input) == 3\n\ntest_input = { \"nums1\": [2,10,2,7,8,9,7,6,6], \"nums2\": [4,2,1,4,3,2,4,4,4], \"x\": 55 }\nassert my_solution.minimumTime(**test_input) == -1\n\ntest_input = { \"nums1\": [6,8,10,7,10,9], \"nums2\": [4,2,0,4,4,2], \"x\": 38 }\nassert my_solution.minimumTime(**test_input) == 5\n\ntest_input = { \"nums1\": [9,2,8,5,8,3,5,2,2], \"nums2\": [4,3,4,2,0,1,4,4,2], \"x\": 41 }\nassert my_solution.minimumTime(**test_input) == -1\n\ntest_input = { \"nums1\": [5,3,2,3,10,4,7,9,1,10], \"nums2\": [2,0,2,0,3,3,4,4,0,1], \"x\": 30 }\nassert my_solution.minimumTime(**test_input) == -1\n\ntest_input = { \"nums1\": [2,3,5], \"nums2\": [0,0,1], \"x\": 8 }\nassert my_solution.minimumTime(**test_input) == 1\n\ntest_input = { \"nums1\": [7,9,7,9], \"nums2\": [4,2,0,4], \"x\": 32 }\nassert my_solution.minimumTime(**test_input) == 0\n\ntest_input = { \"nums1\": [8,5,6,4,7,6,3,9,4], \"nums2\": [0,4,2,4,3,3,1,4,4], \"x\": 38 }\nassert my_solution.minimumTime(**test_input) == -1\n\ntest_input = { \"nums1\": [3,1,1,1], \"nums2\": [0,0,3,0], \"x\": 3 }\nassert my_solution.minimumTime(**test_input) == 2\n\ntest_input = { \"nums1\": [6,6,8,7,1,7], \"nums2\": [2,2,1,1,2,3], \"x\": 27 }\nassert my_solution.minimumTime(**test_input) == 5\n\ntest_input = { \"nums1\": [10,5], \"nums2\": [1,3], \"x\": 14 }\nassert my_solution.minimumTime(**test_input) == 1\n\ntest_input = { \"nums1\": [10,7,1,2,6], \"nums2\": [4,3,2,2,4], \"x\": 17 }\nassert my_solution.minimumTime(**test_input) == -1\n\ntest_input = { \"nums1\": [9,5,6,1,9,4,5,7], \"nums2\": [0,4,0,2,2,3,2,4], \"x\": 24 }\nassert my_solution.minimumTime(**test_input) == -1\n\ntest_input = { \"nums1\": [4,1,2,4,10,7,8], \"nums2\": [0,2,0,4,0,2,1], \"x\": 18 }\nassert my_solution.minimumTime(**test_input) == 5\n\ntest_input = { \"nums1\": [4], \"nums2\": [0], \"x\": 4 }\nassert my_solution.minimumTime(**test_input) == 0\n\ntest_input = { \"nums1\": [4,7,1,7,5,10], \"nums2\": [0,4,3,2,3,1], \"x\": 29 }\nassert my_solution.minimumTime(**test_input) == 4\n\ntest_input = { \"nums1\": [9,8,9,7,4,6,8,6,4], \"nums2\": [4,3,3,3,1,2,2,1,0], \"x\": 42 }\nassert my_solution.minimumTime(**test_input) == -1\n\ntest_input = { \"nums1\": [8,3,2], \"nums2\": [3,1,3], \"x\": 7 }\nassert my_solution.minimumTime(**test_input) == 3\n\ntest_input = { \"nums1\": [6,5,2,8,8,1,6,4], \"nums2\": [1,2,1,0,1,0,3,1], \"x\": 23 }\nassert my_solution.minimumTime(**test_input) == 6\n\ntest_input = { \"nums1\": [3,8,5,4,10,2], \"nums2\": [4,1,4,2,1,0], \"x\": 26 }\nassert my_solution.minimumTime(**test_input) == 4\n\ntest_input = { \"nums1\": [5,3], \"nums2\": [0,3], \"x\": 4 }\nassert my_solution.minimumTime(**test_input) == 2\n\ntest_input = { \"nums1\": [8], \"nums2\": [4], \"x\": 7 }\nassert my_solution.minimumTime(**test_input) == 1\n\ntest_input = { \"nums1\": [1,8,6,8,6], \"nums2\": [3,0,2,4,0], \"x\": 16 }\nassert my_solution.minimumTime(**test_input) == 4\n\ntest_input = { \"nums1\": [8,6], \"nums2\": [0,3], \"x\": 14 }\nassert my_solution.minimumTime(**test_input) == 0\n\ntest_input = { \"nums1\": [3,4,5,2,4,10,6,3,6,4], \"nums2\": [3,0,0,2,4,2,4,1,2,1], \"x\": 28 }\nassert my_solution.minimumTime(**test_input) == -1\n\ntest_input = { \"nums1\": [3,2,5,8,8], \"nums2\": [1,3,2,1,0], \"x\": 20 }\nassert my_solution.minimumTime(**test_input) == 3\n\ntest_input = { \"nums1\": [9,2,8,7,5,2,3,2], \"nums2\": [3,2,3,0,4,3,1,4], \"x\": 37 }\nassert my_solution.minimumTime(**test_input) == -1\n\ntest_input = { \"nums1\": [6,4,3,1,10,5,10,3,5,9], \"nums2\": [0,4,1,2,1,2,3,3,4,2], \"x\": 41 }\nassert my_solution.minimumTime(**test_input) == -1\n\ntest_input = { \"nums1\": [6,10,7,10,6,7,7,4], \"nums2\": [1,3,0,0,1,2,1,3], \"x\": 55 }\nassert my_solution.minimumTime(**test_input) == 1\n\ntest_input = { \"nums1\": [6,4,3,1], \"nums2\": [1,1,3,3], \"x\": 7 }\nassert my_solution.minimumTime(**test_input) == -1\n\ntest_input = { \"nums1\": [2,10,8,10,1,4,7,10,5,1], \"nums2\": [4,3,1,2,3,1,3,2,2,1], \"x\": 29 }\nassert my_solution.minimumTime(**test_input) == -1\n\ntest_input = { \"nums1\": [2,8,5], \"nums2\": [2,0,2], \"x\": 14 }\nassert my_solution.minimumTime(**test_input) == 1\n\ntest_input = { \"nums1\": [7,10,1,3,7,3,2], \"nums2\": [1,1,3,0,2,2,3], \"x\": 22 }\nassert my_solution.minimumTime(**test_input) == 7\n\ntest_input = { \"nums1\": [6,4,2,3,8,6,6,8,10], \"nums2\": [2,1,4,1,2,1,0,1,4], \"x\": 39 }\nassert my_solution.minimumTime(**test_input) == 9\n\ntest_input = { \"nums1\": [4,4,8,10,2,7,9,8,1,8], \"nums2\": [1,0,4,0,3,3,1,2,2,1], \"x\": 44 }\nassert my_solution.minimumTime(**test_input) == 10\n\ntest_input = { \"nums1\": [2,4,1,8,3,9], \"nums2\": [0,2,0,0,0,4], \"x\": 21 }\nassert my_solution.minimumTime(**test_input) == 1\n\ntest_input = { \"nums1\": [6,10], \"nums2\": [2,1], \"x\": 8 }\nassert my_solution.minimumTime(**test_input) == 1\n\ntest_input = { \"nums1\": [8,6], \"nums2\": [3,0], \"x\": 10 }\nassert my_solution.minimumTime(**test_input) == 1\n\ntest_input = { \"nums1\": [5,5,5,10], \"nums2\": [0,1,0,3], \"x\": 21 }\nassert my_solution.minimumTime(**test_input) == 1\n\ntest_input = { \"nums1\": [7,1,1,2,9,3,3,2,2], \"nums2\": [0,1,4,3,4,1,2,1,2], \"x\": 15 }\nassert my_solution.minimumTime(**test_input) == -1\n\ntest_input = { \"nums1\": [10,4,1,10,7,5,6,3,2,10], \"nums2\": [4,0,4,0,3,4,3,0,0,3], \"x\": 50 }\nassert my_solution.minimumTime(**test_input) == 9\n\ntest_input = { \"nums1\": [9,4,6,2], \"nums2\": [3,4,0,4], \"x\": 15 }\nassert my_solution.minimumTime(**test_input) == 4\n\ntest_input = { \"nums1\": [7,3,9,2,9,10,7,10,10,4], \"nums2\": [1,4,2,1,4,1,1,0,3,4], \"x\": 69 }\nassert my_solution.minimumTime(**test_input) == 8\n\ntest_input = { \"nums1\": [4,5,6], \"nums2\": [4,4,0], \"x\": 13 }\nassert my_solution.minimumTime(**test_input) == 2\n\ntest_input = { \"nums1\": [2,3,3,4,4], \"nums2\": [2,2,1,1,1], \"x\": 12 }\nassert my_solution.minimumTime(**test_input) == 5\n\ntest_input = { \"nums1\": [4,5,5,3,7], \"nums2\": [3,3,2,0,4], \"x\": 21 }\nassert my_solution.minimumTime(**test_input) == 4\n\ntest_input = { \"nums1\": [1,3,3,4], \"nums2\": [1,3,2,3], \"x\": 6 }\nassert my_solution.minimumTime(**test_input) == -1\n\ntest_input = { \"nums1\": [9,1,8,9,7,2], \"nums2\": [3,3,0,2,3,4], \"x\": 26 }\nassert my_solution.minimumTime(**test_input) == 6\n\ntest_input = { \"nums1\": [5,5,6,8,6,1,5,7,8], \"nums2\": [2,1,0,3,2,2,2,2,4], \"x\": 33 }\nassert my_solution.minimumTime(**test_input) == -1\n\ntest_input = { \"nums1\": [2,9,5,5,6,7,7,9], \"nums2\": [1,3,0,3,3,3,4,2], \"x\": 47 }\nassert my_solution.minimumTime(**test_input) == 8\n\ntest_input = { \"nums1\": [3], \"nums2\": [0], \"x\": 2 }\nassert my_solution.minimumTime(**test_input) == 1\n\ntest_input = { \"nums1\": [3,6,4,8,7,9,3,3,9], \"nums2\": [4,3,2,0,0,3,3,1,4], \"x\": 34 }\nassert my_solution.minimumTime(**test_input) == -1\n\ntest_input = { \"nums1\": [8], \"nums2\": [1], \"x\": 6 }\nassert my_solution.minimumTime(**test_input) == 1\n\ntest_input = { \"nums1\": [1,7,6,2,9], \"nums2\": [4,2,3,3,0], \"x\": 23 }\nassert my_solution.minimumTime(**test_input) == 4\n\ntest_input = { \"nums1\": [9,10,10,5,2,4], \"nums2\": [2,4,0,3,3,4], \"x\": 40 }\nassert my_solution.minimumTime(**test_input) == 0\n\ntest_input = { \"nums1\": [9,10,9,4,8,9,10,7,5], \"nums2\": [2,0,3,0,2,4,3,2,4], \"x\": 69 }\nassert my_solution.minimumTime(**test_input) == 7\n\ntest_input = { \"nums1\": [1,7,2,7], \"nums2\": [1,0,2,3], \"x\": 10 }\nassert my_solution.minimumTime(**test_input) == 2\n\ntest_input = { \"nums1\": [10,4], \"nums2\": [2,4], \"x\": 10 }\nassert my_solution.minimumTime(**test_input) == 1\n\ntest_input = { \"nums1\": [2,10,3,6,2,10,4], \"nums2\": [4,1,4,4,4,0,0], \"x\": 30 }\nassert my_solution.minimumTime(**test_input) == 7\n\ntest_input = { \"nums1\": [5,9,6], \"nums2\": [1,3,2], \"x\": 20 }\nassert my_solution.minimumTime(**test_input) == 0\n\ntest_input = { \"nums1\": [4,5,2,4,2,7], \"nums2\": [0,0,0,0,3,0], \"x\": 23 }\nassert my_solution.minimumTime(**test_input) == 1\n\ntest_input = { \"nums1\": [8], \"nums2\": [0], \"x\": 7 }\nassert my_solution.minimumTime(**test_input) == 1\n\ntest_input = { \"nums1\": [3], \"nums2\": [3], \"x\": 3 }\nassert my_solution.minimumTime(**test_input) == 0\n\ntest_input = { \"nums1\": [6,1,10,10], \"nums2\": [3,2,4,0], \"x\": 13 }\nassert my_solution.minimumTime(**test_input) == 3\n\ntest_input = { \"nums1\": [8,9,2,10,10,1,5], \"nums2\": [4,3,3,0,2,1,2], \"x\": 38 }\nassert my_solution.minimumTime(**test_input) == 5\n\ntest_input = { \"nums1\": [10,2], \"nums2\": [3,4], \"x\": 10 }\nassert my_solution.minimumTime(**test_input) == 1\n\ntest_input = { \"nums1\": [8,9,2], \"nums2\": [2,4,1], \"x\": 16 }\nassert my_solution.minimumTime(**test_input) == 1\n\ntest_input = { \"nums1\": [4,2,3], \"nums2\": [4,2,2], \"x\": 4 }\nassert my_solution.minimumTime(**test_input) == -1\n\ntest_input = { \"nums1\": [9,8,7,6,5,1,4], \"nums2\": [2,4,1,2,3,3,0], \"x\": 28 }\nassert my_solution.minimumTime(**test_input) == 7\n\ntest_input = { \"nums1\": [3,4,10,1,2,4,10,3,7,2], \"nums2\": [4,0,0,1,1,4,4,4,2,1], \"x\": 44 }\nassert my_solution.minimumTime(**test_input) == -1\n\ntest_input = { \"nums1\": [3,5,5,1,6,4,3], \"nums2\": [1,3,4,3,3,1,4], \"x\": 23 }\nassert my_solution.minimumTime(**test_input) == -1\n\ntest_input = { \"nums1\": [3,8,10,2,5,10], \"nums2\": [4,0,3,2,4,3], \"x\": 37 }\nassert my_solution.minimumTime(**test_input) == 4\n\ntest_input = { \"nums1\": [8,8,10,8,9,6,1,8], \"nums2\": [2,0,0,1,2,1,0,4], \"x\": 38 }\nassert my_solution.minimumTime(**test_input) == 4\n\ntest_input = { \"nums1\": [10,7,3,10,7,6,6,10], \"nums2\": [1,2,4,0,3,4,0,3], \"x\": 41 }\nassert my_solution.minimumTime(**test_input) == 7\n\ntest_input = { \"nums1\": [6,7,4,1,9,6], \"nums2\": [3,3,3,0,0,1], \"x\": 32 }\nassert my_solution.minimumTime(**test_input) == 2\n\ntest_input = { \"nums1\": [2], \"nums2\": [2], \"x\": 1 }\nassert my_solution.minimumTime(**test_input) == 1\n\ntest_input = { \"nums1\": [8,9,4,5,6,7], \"nums2\": [0,3,4,3,3,1], \"x\": 27 }\nassert my_solution.minimumTime(**test_input) == 6\n\ntest_input = { \"nums1\": [7], \"nums2\": [1], \"x\": 3 }\nassert my_solution.minimumTime(**test_input) == 1\n\ntest_input = { \"nums1\": [9], \"nums2\": [0], \"x\": 5 }\nassert my_solution.minimumTime(**test_input) == 1\n\ntest_input = { \"nums1\": [7,2,2,2,7,4,2,10,8], \"nums2\": [4,3,2,4,4,0,1,1,2], \"x\": 31 }\nassert my_solution.minimumTime(**test_input) == -1\n\ntest_input = { \"nums1\": [7,2,6,4,9,9,1,9,6,7], \"nums2\": [0,1,3,2,3,3,4,2,2,1], \"x\": 58 }\nassert my_solution.minimumTime(**test_input) == -1\n\ntest_input = { \"nums1\": [6,8,2,3,9,8,10,9,9], \"nums2\": [1,4,2,3,2,0,1,1,3], \"x\": 40 }\nassert my_solution.minimumTime(**test_input) == -1\n\ntest_input = { \"nums1\": [1,1,5], \"nums2\": [4,4,2], \"x\": 3 }\nassert my_solution.minimumTime(**test_input) == -1\n\ntest_input = { \"nums1\": [7,5,8,3,10,2,4,8,7], \"nums2\": [4,4,2,4,2,3,1,1,1], \"x\": 49 }\nassert my_solution.minimumTime(**test_input) == -1\n\ntest_input = { \"nums1\": [4,7,2,6,9,2], \"nums2\": [1,2,1,4,1,3], \"x\": 28 }\nassert my_solution.minimumTime(**test_input) == 3\n\ntest_input = { \"nums1\": [3,6,3,9,5], \"nums2\": [0,4,0,3,1], \"x\": 23 }\nassert my_solution.minimumTime(**test_input) == 1", "start_time": 1691245800} +{"task_id": "weekly-contest-356-number-of-employees-who-met-the-target", "url": "https://leetcode.com/problems/number-of-employees-who-met-the-target", "title": "number-of-employees-who-met-the-target", "meta": {"questionId": "2876", "questionFrontendId": "2798", "title": "Number of Employees Who Met the Target", "titleSlug": "number-of-employees-who-met-the-target", "isPaidOnly": false, "difficulty": "Easy", "likes": 362, "dislikes": 46, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n公司里共有 n 名员工,按从 0 到 n - 1 编号。每个员工 i 已经在公司工作了 hours[i] 小时。\n\n公司要求每位员工工作 至少 target 小时。\n\n给你一个下标从 0 开始、长度为 n 的非负整数数组 hours 和一个非负整数 target 。\n\n请你用整数表示并返回工作至少 target 小时的员工数。\n\n示例 1:\n\n输入:hours = [0,1,2,3,4], target = 2\n输出:3\n解释:公司要求每位员工工作至少 2 小时。\n- 员工 0 工作 0 小时,不满足要求。\n- 员工 1 工作 1 小时,不满足要求。\n- 员工 2 工作 2 小时,满足要求。\n- 员工 3 工作 3 小时,满足要求。\n- 员工 4 工作 4 小时,满足要求。\n共有 3 位满足要求的员工。\n\n示例 2:\n\n输入:hours = [5,1,4,2,2], target = 6\n输出:0\n解释:公司要求每位员工工作至少 6 小时。\n共有 0 位满足要求的员工。\n\n\n提示:\n\n * 1 <= n == hours.length <= 50\n * 0 <= hours[i], target <= 105\n\"\"\"\nclass Solution:\n def numberOfEmployeesWhoMetTarget(self, hours: List[int], target: int) -> int:\n ", "prompt_sft": "公司里共有 n 名员工,按从 0 到 n - 1 编号。每个员工 i 已经在公司工作了 hours[i] 小时。\n\n公司要求每位员工工作 至少 target 小时。\n\n给你一个下标从 0 开始、长度为 n 的非负整数数组 hours 和一个非负整数 target 。\n\n请你用整数表示并返回工作至少 target 小时的员工数。\n\n示例 1:\n\n输入:hours = [0,1,2,3,4], target = 2\n输出:3\n解释:公司要求每位员工工作至少 2 小时。\n- 员工 0 工作 0 小时,不满足要求。\n- 员工 1 工作 1 小时,不满足要求。\n- 员工 2 工作 2 小时,满足要求。\n- 员工 3 工作 3 小时,满足要求。\n- 员工 4 工作 4 小时,满足要求。\n共有 3 位满足要求的员工。\n\n示例 2:\n\n输入:hours = [5,1,4,2,2], target = 6\n输出:0\n解释:公司要求每位员工工作至少 6 小时。\n共有 0 位满足要求的员工。\n\n\n提示:\n\n * 1 <= n == hours.length <= 50\n * 0 <= hours[i], target <= 105\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def numberOfEmployeesWhoMetTarget(self, hours: List[int], target: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"hours\": [0,1,2,3,4], \"target\": 2 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 3\n\ntest_input = { \"hours\": [5,1,4,2,2], \"target\": 6 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [98], \"target\": 5 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [19], \"target\": 13 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [70], \"target\": 13 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [26], \"target\": 14 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [2], \"target\": 16 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [77], \"target\": 19 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [6], \"target\": 21 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [27], \"target\": 21 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [36], \"target\": 22 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [42], \"target\": 25 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [70], \"target\": 27 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [2], \"target\": 28 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [14], \"target\": 31 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [45], \"target\": 34 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [44], \"target\": 35 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [11], \"target\": 39 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [71], \"target\": 39 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [91], \"target\": 45 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [81], \"target\": 51 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [15], \"target\": 52 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [90], \"target\": 59 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [40], \"target\": 64 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [12], \"target\": 69 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [83], \"target\": 70 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [38], \"target\": 74 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [18], \"target\": 78 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [60], \"target\": 83 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [50], \"target\": 87 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [75], \"target\": 92 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [91], \"target\": 96 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [11], \"target\": 97 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [48,28], \"target\": 2 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 2\n\ntest_input = { \"hours\": [38,46], \"target\": 3 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 2\n\ntest_input = { \"hours\": [30,79], \"target\": 6 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 2\n\ntest_input = { \"hours\": [45,78], \"target\": 6 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 2\n\ntest_input = { \"hours\": [20,69], \"target\": 10 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 2\n\ntest_input = { \"hours\": [82,67], \"target\": 11 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 2\n\ntest_input = { \"hours\": [29,75], \"target\": 12 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 2\n\ntest_input = { \"hours\": [97,37], \"target\": 17 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 2\n\ntest_input = { \"hours\": [42,100], \"target\": 20 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 2\n\ntest_input = { \"hours\": [11,58], \"target\": 21 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [12,46], \"target\": 21 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [70,84], \"target\": 37 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 2\n\ntest_input = { \"hours\": [7,100], \"target\": 38 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [47,94], \"target\": 40 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 2\n\ntest_input = { \"hours\": [18,34], \"target\": 50 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [47,79], \"target\": 55 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [74,99], \"target\": 56 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 2\n\ntest_input = { \"hours\": [53,81], \"target\": 67 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [36,61], \"target\": 68 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [48,98], \"target\": 71 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [71,94], \"target\": 72 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [60,99], \"target\": 73 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [12,12], \"target\": 74 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [100,87], \"target\": 75 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 2\n\ntest_input = { \"hours\": [12,56], \"target\": 77 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [15,36], \"target\": 86 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [53,45], \"target\": 86 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [4,77], \"target\": 89 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [23,29], \"target\": 93 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [76,62,96], \"target\": 5 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 3\n\ntest_input = { \"hours\": [82,67,33], \"target\": 5 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 3\n\ntest_input = { \"hours\": [28,96,39], \"target\": 10 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 3\n\ntest_input = { \"hours\": [42,93,58], \"target\": 13 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 3\n\ntest_input = { \"hours\": [53,22,48], \"target\": 13 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 3\n\ntest_input = { \"hours\": [68,81,61], \"target\": 13 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 3\n\ntest_input = { \"hours\": [68,32,33], \"target\": 22 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 3\n\ntest_input = { \"hours\": [59,65,70], \"target\": 26 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 3\n\ntest_input = { \"hours\": [15,43,21], \"target\": 29 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [40,80,75], \"target\": 33 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 3\n\ntest_input = { \"hours\": [64,11,73], \"target\": 34 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 2\n\ntest_input = { \"hours\": [1,74,34], \"target\": 44 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [96,79,91], \"target\": 44 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 3\n\ntest_input = { \"hours\": [59,9,9], \"target\": 48 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [79,48,62], \"target\": 53 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 2\n\ntest_input = { \"hours\": [58,83,2], \"target\": 54 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 2\n\ntest_input = { \"hours\": [51,40,12], \"target\": 57 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [54,2,80], \"target\": 60 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [92,45,91], \"target\": 65 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 2\n\ntest_input = { \"hours\": [93,23,46], \"target\": 67 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [17,60,1], \"target\": 70 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [9,63,77], \"target\": 73 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [44,86,37], \"target\": 73 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [75,37,68], \"target\": 73 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [33,26,77], \"target\": 78 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [11,88,27], \"target\": 79 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [12,48,44], \"target\": 80 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [19,88,13], \"target\": 82 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [61,56,67], \"target\": 82 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [46,24,38], \"target\": 84 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [93,51,83], \"target\": 85 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [58,14,83], \"target\": 87 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [52,33,56], \"target\": 89 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [34,73,46], \"target\": 91 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [26,59,55], \"target\": 94 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [41,89,34], \"target\": 100 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [9,26,77,55], \"target\": 0 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 4\n\ntest_input = { \"hours\": [24,79,63,37], \"target\": 1 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 4", "start_time": 1690684200} +{"task_id": "weekly-contest-356-count-complete-subarrays-in-an-array", "url": "https://leetcode.com/problems/count-complete-subarrays-in-an-array", "title": "count-complete-subarrays-in-an-array", "meta": {"questionId": "2856", "questionFrontendId": "2799", "title": "Count Complete Subarrays in an Array", "titleSlug": "count-complete-subarrays-in-an-array", "isPaidOnly": false, "difficulty": "Medium", "likes": 464, "dislikes": 9, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个由 正 整数组成的数组 nums 。\n\n如果数组中的某个子数组满足下述条件,则称之为 完全子数组 :\n\n * 子数组中 不同 元素的数目等于整个数组不同元素的数目。\n\n返回数组中 完全子数组 的数目。\n\n子数组 是数组中的一个连续非空序列。\n\n示例 1:\n\n输入:nums = [1,3,1,2,2]\n输出:4\n解释:完全子数组有:[1,3,1,2]、[1,3,1,2,2]、[3,1,2] 和 [3,1,2,2] 。\n\n示例 2:\n\n输入:nums = [5,5,5,5]\n输出:10\n解释:数组仅由整数 5 组成,所以任意子数组都满足完全子数组的条件。子数组的总数为 10 。\n\n\n提示:\n\n * 1 <= nums.length <= 1000\n * 1 <= nums[i] <= 2000\n\"\"\"\nclass Solution:\n def countCompleteSubarrays(self, nums: List[int]) -> int:\n ", "prompt_sft": "给你一个由 正 整数组成的数组 nums 。\n\n如果数组中的某个子数组满足下述条件,则称之为 完全子数组 :\n\n * 子数组中 不同 元素的数目等于整个数组不同元素的数目。\n\n返回数组中 完全子数组 的数目。\n\n子数组 是数组中的一个连续非空序列。\n\n示例 1:\n\n输入:nums = [1,3,1,2,2]\n输出:4\n解释:完全子数组有:[1,3,1,2]、[1,3,1,2,2]、[3,1,2] 和 [3,1,2,2] 。\n\n示例 2:\n\n输入:nums = [5,5,5,5]\n输出:10\n解释:数组仅由整数 5 组成,所以任意子数组都满足完全子数组的条件。子数组的总数为 10 。\n\n\n提示:\n\n * 1 <= nums.length <= 1000\n * 1 <= nums[i] <= 2000\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def countCompleteSubarrays(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,3,1,2,2] }\nassert my_solution.countCompleteSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [5,5,5,5] }\nassert my_solution.countCompleteSubarrays(**test_input) == 10\n\ntest_input = { \"nums\": [459,459,962,1579,1435,756,1872,1597] }\nassert my_solution.countCompleteSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [1786,1786,1786,114] }\nassert my_solution.countCompleteSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [1632,1632,528,359,1671,1632,511,1087,424,1684] }\nassert my_solution.countCompleteSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [1430,12,1430,1075,1722] }\nassert my_solution.countCompleteSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [1917,1917,608,608,1313,751,558,1561,608] }\nassert my_solution.countCompleteSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [254,1690,1690,1068,1779] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [1116] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [1677,1677,1352,1219,1666,1677,1892,1892,319] }\nassert my_solution.countCompleteSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [1386,1997,1997,574,574,1360,989] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [50,48,1118,540,1248,1984,1698,41,1984,186] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [273,524,40,1323,1323] }\nassert my_solution.countCompleteSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [246,376,828,191,1942,210] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [463,1497,1676,127,1379,17,1075,190] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [765,1370] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [1110,804,1110,839,728,839] }\nassert my_solution.countCompleteSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [1001] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [665,867,954,1411,728,1006,372,1411] }\nassert my_solution.countCompleteSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [1213,1203,1277,369,1277] }\nassert my_solution.countCompleteSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [1898,370,822,1659,1360,128,370,360,261,1898] }\nassert my_solution.countCompleteSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [1881,1446] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [474,315,155,155,1986] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [1389,1817,401,1067,1356,1997] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [1586,1332,1055,1586,1586,1861,892,1445] }\nassert my_solution.countCompleteSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [1601,1601] }\nassert my_solution.countCompleteSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [1417,1417,1160,387,928,1572,1832] }\nassert my_solution.countCompleteSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [1497,1237,1237,946,682,331,742] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [377,377] }\nassert my_solution.countCompleteSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [356,356,356,356,356,315] }\nassert my_solution.countCompleteSubarrays(**test_input) == 5\n\ntest_input = { \"nums\": [285] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [211,211,731,226] }\nassert my_solution.countCompleteSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [1253,188,188,5,1393,1696,1062] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [90,1297,482,482,90,1836,1045,1497,482] }\nassert my_solution.countCompleteSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [1857,273,609,609,1803,1491,223,609,1857,1052] }\nassert my_solution.countCompleteSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [617,1014,679,934,955] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [577,577] }\nassert my_solution.countCompleteSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [1793,997,1082,1411,997,546,224,336,307,336] }\nassert my_solution.countCompleteSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [1150,1150] }\nassert my_solution.countCompleteSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [634] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [1454,1789,1454] }\nassert my_solution.countCompleteSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [1657,1090,1682,1376,547,547,407,755,1124,1376] }\nassert my_solution.countCompleteSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [379] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [1673,1584,1584,1055,1971,1122,1086,1692,75] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [722,1427] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [1641,448,1641,1437,448,1406,1437] }\nassert my_solution.countCompleteSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [1440,704,1440,1440,749] }\nassert my_solution.countCompleteSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [832,832] }\nassert my_solution.countCompleteSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [1635,1759,1759,1976,700] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [1577,1674,1745,156,596,1973,1390,156,1497,415] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [1646,1991] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [1613,881,1660,1270,1783,881,773,1783,1229,111] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [431] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [113] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [151] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [999,701,389,999,409,488,993,999,517,1860] }\nassert my_solution.countCompleteSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [236,596,1263,1563,860,596,1184,575] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [278,338] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [939] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [1293,564,614,694,1386,564] }\nassert my_solution.countCompleteSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [681,448] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [1563,558,1778,1404,1973] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [1508,1508,649] }\nassert my_solution.countCompleteSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [1077,445,1947,445,789,789,789,956,1988,189] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [1984,526,30,1205,1691,1984,1241,280,280,1984] }\nassert my_solution.countCompleteSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [1802,1876,1143,1802,1012,1876,1802,1821] }\nassert my_solution.countCompleteSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [1338,901,613,575,613] }\nassert my_solution.countCompleteSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [406,406,242,242,770,1063,1436,1063,1063] }\nassert my_solution.countCompleteSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [1235,1235] }\nassert my_solution.countCompleteSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [1337,1088,1088,892,1209,1269] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [1941,1941] }\nassert my_solution.countCompleteSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [319] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [1891,1891,1748,1748,923,1748,923,763,1062,1748] }\nassert my_solution.countCompleteSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [1111,503,1980] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [213,1666,469,1675] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [769,1774,1654,928,1204] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [294,294,294,294,1351,294,1351,62,585] }\nassert my_solution.countCompleteSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [1197] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [21,1549,21,1549,1998,1219,1549,1021] }\nassert my_solution.countCompleteSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [1124,1124,556,1322,556] }\nassert my_solution.countCompleteSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [908,908,863,1977,908,8,427,1322] }\nassert my_solution.countCompleteSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [770] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [517,1497,334,334,996,1497,1394,534] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [564,750,750,750,1965,1965,1402] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [403,1080,365,1962,1589,1740,1335,1335,1589] }\nassert my_solution.countCompleteSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [1712,1621,1295,522,1734,522,1371,1935,684] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [270,1443,807,1704,1487] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [1880,1880,1880,604,1634,1412,1880,67,1759,1488] }\nassert my_solution.countCompleteSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [540,1799,1784,1799,972,1786,1578,1480,178,532] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [1235,471,367] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [1887,1373,190,1764,1764,959,959,1373,17] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [1313,910,1172,1541,1758,140,1380,492,240,1664] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [381,1304,381,758,1304,381,758] }\nassert my_solution.countCompleteSubarrays(**test_input) == 14\n\ntest_input = { \"nums\": [1517,665] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [1555,223,379,223,379,1982] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [1268,1268,1268,1268] }\nassert my_solution.countCompleteSubarrays(**test_input) == 10\n\ntest_input = { \"nums\": [1051,266,266,94,761,1051,255] }\nassert my_solution.countCompleteSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [420,945,3,172] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [1045,1120,1045,511,1045,1777,1224,336,560,153] }\nassert my_solution.countCompleteSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [627,592,592,1416,370,229,526,633] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1", "start_time": 1690684200} +{"task_id": "weekly-contest-356-shortest-string-that-contains-three-strings", "url": "https://leetcode.com/problems/shortest-string-that-contains-three-strings", "title": "shortest-string-that-contains-three-strings", "meta": {"questionId": "2877", "questionFrontendId": "2800", "title": "Shortest String That Contains Three Strings", "titleSlug": "shortest-string-that-contains-three-strings", "isPaidOnly": false, "difficulty": "Medium", "likes": 301, "dislikes": 244, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你三个字符串 a ,b 和 c , 你的任务是找到长度 最短 的字符串,且这三个字符串都是它的 子字符串 。\n\n如果有多个这样的字符串,请你返回 字典序最小 的一个。\n\n请你返回满足题目要求的字符串。\n\n注意:\n\n * 两个长度相同的字符串 a 和 b ,如果在第一个不相同的字符处,a 的字母在字母表中比 b 的字母 靠前 ,那么字符串 a 比字符串 b 字典序小 。\n * 子字符串 是一个字符串中一段连续的字符序列。\n\n示例 1:\n\n输入:a = \"abc\", b = \"bca\", c = \"aaa\"\n输出:\"aaabca\"\n解释:字符串 \"aaabca\" 包含所有三个字符串:a = ans[2...4] ,b = ans[3..5] ,c = ans[0..2] 。结果字符串的长度至少为 6 ,且\"aaabca\" 是字典序最小的一个。\n\n示例 2:\n\n输入:a = \"ab\", b = \"ba\", c = \"aba\"\n输出:\"aba\"\n解释:字符串 \"aba\" 包含所有三个字符串:a = ans[0..1] ,b = ans[1..2] ,c = ans[0..2] 。由于 c 的长度为 3 ,结果字符串的长度至少为 3 。\"aba\" 是字典序最小的一个。\n\n\n提示:\n\n * 1 <= a.length, b.length, c.length <= 100\n * a ,b ,c 只包含小写英文字母。\n\"\"\"\nclass Solution:\n def minimumString(self, a: str, b: str, c: str) -> str:\n ", "prompt_sft": "给你三个字符串 a ,b 和 c , 你的任务是找到长度 最短 的字符串,且这三个字符串都是它的 子字符串 。\n\n如果有多个这样的字符串,请你返回 字典序最小 的一个。\n\n请你返回满足题目要求的字符串。\n\n注意:\n\n * 两个长度相同的字符串 a 和 b ,如果在第一个不相同的字符处,a 的字母在字母表中比 b 的字母 靠前 ,那么字符串 a 比字符串 b 字典序小 。\n * 子字符串 是一个字符串中一段连续的字符序列。\n\n示例 1:\n\n输入:a = \"abc\", b = \"bca\", c = \"aaa\"\n输出:\"aaabca\"\n解释:字符串 \"aaabca\" 包含所有三个字符串:a = ans[2...4] ,b = ans[3..5] ,c = ans[0..2] 。结果字符串的长度至少为 6 ,且\"aaabca\" 是字典序最小的一个。\n\n示例 2:\n\n输入:a = \"ab\", b = \"ba\", c = \"aba\"\n输出:\"aba\"\n解释:字符串 \"aba\" 包含所有三个字符串:a = ans[0..1] ,b = ans[1..2] ,c = ans[0..2] 。由于 c 的长度为 3 ,结果字符串的长度至少为 3 。\"aba\" 是字典序最小的一个。\n\n\n提示:\n\n * 1 <= a.length, b.length, c.length <= 100\n * a ,b ,c 只包含小写英文字母。\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def minimumString(self, a: str, b: str, c: str) -> str:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"a\": \"abc\", \"b\": \"bca\", \"c\": \"aaa\" }\nassert my_solution.minimumString(**test_input) == \"aaabca\"\n\ntest_input = { \"a\": \"ab\", \"b\": \"ba\", \"c\": \"aba\" }\nassert my_solution.minimumString(**test_input) == \"aba\"\n\ntest_input = { \"a\": \"xyyyz\", \"b\": \"xzyz\", \"c\": \"zzz\" }\nassert my_solution.minimumString(**test_input) == \"xyyyzxzyzzz\"\n\ntest_input = { \"a\": \"a\", \"b\": \"a\", \"c\": \"a\" }\nassert my_solution.minimumString(**test_input) == \"a\"\n\ntest_input = { \"a\": \"a\", \"b\": \"a\", \"c\": \"b\" }\nassert my_solution.minimumString(**test_input) == \"ab\"\n\ntest_input = { \"a\": \"a\", \"b\": \"c\", \"c\": \"a\" }\nassert my_solution.minimumString(**test_input) == \"ac\"\n\ntest_input = { \"a\": \"a\", \"b\": \"b\", \"c\": \"b\" }\nassert my_solution.minimumString(**test_input) == \"ab\"\n\ntest_input = { \"a\": \"a\", \"b\": \"a\", \"c\": \"c\" }\nassert my_solution.minimumString(**test_input) == \"ac\"\n\ntest_input = { \"a\": \"a\", \"b\": \"c\", \"c\": \"b\" }\nassert my_solution.minimumString(**test_input) == \"abc\"\n\ntest_input = { \"a\": \"c\", \"b\": \"c\", \"c\": \"a\" }\nassert my_solution.minimumString(**test_input) == \"ac\"\n\ntest_input = { \"a\": \"k\", \"b\": \"e\", \"c\": \"a\" }\nassert my_solution.minimumString(**test_input) == \"aek\"\n\ntest_input = { \"a\": \"a\", \"b\": \"b\", \"c\": \"a\" }\nassert my_solution.minimumString(**test_input) == \"ab\"\n\ntest_input = { \"a\": \"b\", \"b\": \"b\", \"c\": \"a\" }\nassert my_solution.minimumString(**test_input) == \"ab\"\n\ntest_input = { \"a\": \"b\", \"b\": \"b\", \"c\": \"b\" }\nassert my_solution.minimumString(**test_input) == \"b\"\n\ntest_input = { \"a\": \"b\", \"b\": \"b\", \"c\": \"c\" }\nassert my_solution.minimumString(**test_input) == \"bc\"\n\ntest_input = { \"a\": \"c\", \"b\": \"b\", \"c\": \"b\" }\nassert my_solution.minimumString(**test_input) == \"bc\"\n\ntest_input = { \"a\": \"b\", \"b\": \"c\", \"c\": \"c\" }\nassert my_solution.minimumString(**test_input) == \"bc\"\n\ntest_input = { \"a\": \"b\", \"b\": \"c\", \"c\": \"a\" }\nassert my_solution.minimumString(**test_input) == \"abc\"\n\ntest_input = { \"a\": \"c\", \"b\": \"a\", \"c\": \"c\" }\nassert my_solution.minimumString(**test_input) == \"ac\"\n\ntest_input = { \"a\": \"c\", \"b\": \"b\", \"c\": \"c\" }\nassert my_solution.minimumString(**test_input) == \"bc\"\n\ntest_input = { \"a\": \"c\", \"b\": \"c\", \"c\": \"c\" }\nassert my_solution.minimumString(**test_input) == \"c\"\n\ntest_input = { \"a\": \"e\", \"b\": \"k\", \"c\": \"y\" }\nassert my_solution.minimumString(**test_input) == \"eky\"\n\ntest_input = { \"a\": \"z\", \"b\": \"p\", \"c\": \"m\" }\nassert my_solution.minimumString(**test_input) == \"mpz\"\n\ntest_input = { \"a\": \"a\", \"b\": \"aa\", \"c\": \"a\" }\nassert my_solution.minimumString(**test_input) == \"aa\"\n\ntest_input = { \"a\": \"ac\", \"b\": \"a\", \"c\": \"a\" }\nassert my_solution.minimumString(**test_input) == \"ac\"\n\ntest_input = { \"a\": \"ca\", \"b\": \"a\", \"c\": \"a\" }\nassert my_solution.minimumString(**test_input) == \"ca\"\n\ntest_input = { \"a\": \"a\", \"b\": \"cc\", \"c\": \"a\" }\nassert my_solution.minimumString(**test_input) == \"acc\"\n\ntest_input = { \"a\": \"a\", \"b\": \"a\", \"c\": \"aa\" }\nassert my_solution.minimumString(**test_input) == \"aa\"\n\ntest_input = { \"a\": \"c\", \"b\": \"a\", \"c\": \"aa\" }\nassert my_solution.minimumString(**test_input) == \"aac\"\n\ntest_input = { \"a\": \"a\", \"b\": \"ab\", \"c\": \"a\" }\nassert my_solution.minimumString(**test_input) == \"ab\"\n\ntest_input = { \"a\": \"ab\", \"b\": \"b\", \"c\": \"a\" }\nassert my_solution.minimumString(**test_input) == \"ab\"\n\ntest_input = { \"a\": \"ab\", \"b\": \"a\", \"c\": \"c\" }\nassert my_solution.minimumString(**test_input) == \"abc\"\n\ntest_input = { \"a\": \"c\", \"b\": \"ac\", \"c\": \"a\" }\nassert my_solution.minimumString(**test_input) == \"ac\"\n\ntest_input = { \"a\": \"ab\", \"b\": \"a\", \"c\": \"b\" }\nassert my_solution.minimumString(**test_input) == \"ab\"\n\ntest_input = { \"a\": \"b\", \"b\": \"a\", \"c\": \"ba\" }\nassert my_solution.minimumString(**test_input) == \"ba\"\n\ntest_input = { \"a\": \"ba\", \"b\": \"a\", \"c\": \"a\" }\nassert my_solution.minimumString(**test_input) == \"ba\"\n\ntest_input = { \"a\": \"b\", \"b\": \"ba\", \"c\": \"a\" }\nassert my_solution.minimumString(**test_input) == \"ba\"\n\ntest_input = { \"a\": \"a\", \"b\": \"bc\", \"c\": \"a\" }\nassert my_solution.minimumString(**test_input) == \"abc\"\n\ntest_input = { \"a\": \"c\", \"b\": \"a\", \"c\": \"bc\" }\nassert my_solution.minimumString(**test_input) == \"abc\"\n\ntest_input = { \"a\": \"a\", \"b\": \"c\", \"c\": \"ab\" }\nassert my_solution.minimumString(**test_input) == \"abc\"\n\ntest_input = { \"a\": \"c\", \"b\": \"a\", \"c\": \"ac\" }\nassert my_solution.minimumString(**test_input) == \"ac\"\n\ntest_input = { \"a\": \"a\", \"b\": \"c\", \"c\": \"ca\" }\nassert my_solution.minimumString(**test_input) == \"ca\"\n\ntest_input = { \"a\": \"c\", \"b\": \"a\", \"c\": \"cc\" }\nassert my_solution.minimumString(**test_input) == \"acc\"\n\ntest_input = { \"a\": \"a\", \"b\": \"ca\", \"c\": \"a\" }\nassert my_solution.minimumString(**test_input) == \"ca\"\n\ntest_input = { \"a\": \"a\", \"b\": \"cc\", \"c\": \"c\" }\nassert my_solution.minimumString(**test_input) == \"acc\"\n\ntest_input = { \"a\": \"aa\", \"b\": \"a\", \"c\": \"a\" }\nassert my_solution.minimumString(**test_input) == \"aa\"\n\ntest_input = { \"a\": \"aa\", \"b\": \"b\", \"c\": \"a\" }\nassert my_solution.minimumString(**test_input) == \"aab\"\n\ntest_input = { \"a\": \"a\", \"b\": \"aa\", \"c\": \"c\" }\nassert my_solution.minimumString(**test_input) == \"aac\"\n\ntest_input = { \"a\": \"b\", \"b\": \"c\", \"c\": \"aa\" }\nassert my_solution.minimumString(**test_input) == \"aabc\"\n\ntest_input = { \"a\": \"b\", \"b\": \"b\", \"c\": \"ab\" }\nassert my_solution.minimumString(**test_input) == \"ab\"\n\ntest_input = { \"a\": \"ab\", \"b\": \"b\", \"c\": \"c\" }\nassert my_solution.minimumString(**test_input) == \"abc\"\n\ntest_input = { \"a\": \"ac\", \"b\": \"c\", \"c\": \"b\" }\nassert my_solution.minimumString(**test_input) == \"acb\"\n\ntest_input = { \"a\": \"c\", \"b\": \"c\", \"c\": \"ac\" }\nassert my_solution.minimumString(**test_input) == \"ac\"\n\ntest_input = { \"a\": \"ba\", \"b\": \"b\", \"c\": \"a\" }\nassert my_solution.minimumString(**test_input) == \"ba\"\n\ntest_input = { \"a\": \"a\", \"b\": \"b\", \"c\": \"ca\" }\nassert my_solution.minimumString(**test_input) == \"bca\"\n\ntest_input = { \"a\": \"b\", \"b\": \"a\", \"c\": \"aa\" }\nassert my_solution.minimumString(**test_input) == \"aab\"\n\ntest_input = { \"a\": \"b\", \"b\": \"b\", \"c\": \"aa\" }\nassert my_solution.minimumString(**test_input) == \"aab\"\n\ntest_input = { \"a\": \"b\", \"b\": \"ab\", \"c\": \"a\" }\nassert my_solution.minimumString(**test_input) == \"ab\"\n\ntest_input = { \"a\": \"b\", \"b\": \"ab\", \"c\": \"b\" }\nassert my_solution.minimumString(**test_input) == \"ab\"\n\ntest_input = { \"a\": \"ac\", \"b\": \"b\", \"c\": \"a\" }\nassert my_solution.minimumString(**test_input) == \"acb\"\n\ntest_input = { \"a\": \"b\", \"b\": \"b\", \"c\": \"ac\" }\nassert my_solution.minimumString(**test_input) == \"acb\"\n\ntest_input = { \"a\": \"bb\", \"b\": \"b\", \"c\": \"b\" }\nassert my_solution.minimumString(**test_input) == \"bb\"\n\ntest_input = { \"a\": \"b\", \"b\": \"bc\", \"c\": \"b\" }\nassert my_solution.minimumString(**test_input) == \"bc\"\n\ntest_input = { \"a\": \"b\", \"b\": \"b\", \"c\": \"ca\" }\nassert my_solution.minimumString(**test_input) == \"bca\"\n\ntest_input = { \"a\": \"cb\", \"b\": \"b\", \"c\": \"b\" }\nassert my_solution.minimumString(**test_input) == \"cb\"\n\ntest_input = { \"a\": \"b\", \"b\": \"b\", \"c\": \"bb\" }\nassert my_solution.minimumString(**test_input) == \"bb\"\n\ntest_input = { \"a\": \"b\", \"b\": \"a\", \"c\": \"bc\" }\nassert my_solution.minimumString(**test_input) == \"abc\"\n\ntest_input = { \"a\": \"b\", \"b\": \"bc\", \"c\": \"c\" }\nassert my_solution.minimumString(**test_input) == \"bc\"\n\ntest_input = { \"a\": \"b\", \"b\": \"ab\", \"c\": \"c\" }\nassert my_solution.minimumString(**test_input) == \"abc\"\n\ntest_input = { \"a\": \"b\", \"b\": \"bb\", \"c\": \"c\" }\nassert my_solution.minimumString(**test_input) == \"bbc\"\n\ntest_input = { \"a\": \"c\", \"b\": \"b\", \"c\": \"bc\" }\nassert my_solution.minimumString(**test_input) == \"bc\"\n\ntest_input = { \"a\": \"b\", \"b\": \"cb\", \"c\": \"c\" }\nassert my_solution.minimumString(**test_input) == \"cb\"\n\ntest_input = { \"a\": \"b\", \"b\": \"cc\", \"c\": \"c\" }\nassert my_solution.minimumString(**test_input) == \"bcc\"\n\ntest_input = { \"a\": \"b\", \"b\": \"cb\", \"c\": \"a\" }\nassert my_solution.minimumString(**test_input) == \"acb\"\n\ntest_input = { \"a\": \"b\", \"b\": \"b\", \"c\": \"cb\" }\nassert my_solution.minimumString(**test_input) == \"cb\"\n\ntest_input = { \"a\": \"c\", \"b\": \"b\", \"c\": \"cb\" }\nassert my_solution.minimumString(**test_input) == \"cb\"\n\ntest_input = { \"a\": \"a\", \"b\": \"ba\", \"c\": \"b\" }\nassert my_solution.minimumString(**test_input) == \"ba\"\n\ntest_input = { \"a\": \"ba\", \"b\": \"a\", \"c\": \"b\" }\nassert my_solution.minimumString(**test_input) == \"ba\"\n\ntest_input = { \"a\": \"ba\", \"b\": \"b\", \"c\": \"b\" }\nassert my_solution.minimumString(**test_input) == \"ba\"\n\ntest_input = { \"a\": \"b\", \"b\": \"ba\", \"c\": \"c\" }\nassert my_solution.minimumString(**test_input) == \"bac\"\n\ntest_input = { \"a\": \"c\", \"b\": \"ba\", \"c\": \"b\" }\nassert my_solution.minimumString(**test_input) == \"bac\"\n\ntest_input = { \"a\": \"c\", \"b\": \"c\", \"c\": \"ba\" }\nassert my_solution.minimumString(**test_input) == \"bac\"\n\ntest_input = { \"a\": \"bb\", \"b\": \"a\", \"c\": \"b\" }\nassert my_solution.minimumString(**test_input) == \"abb\"\n\ntest_input = { \"a\": \"b\", \"b\": \"bb\", \"c\": \"b\" }\nassert my_solution.minimumString(**test_input) == \"bb\"\n\ntest_input = { \"a\": \"c\", \"b\": \"bb\", \"c\": \"b\" }\nassert my_solution.minimumString(**test_input) == \"bbc\"\n\ntest_input = { \"a\": \"a\", \"b\": \"bc\", \"c\": \"b\" }\nassert my_solution.minimumString(**test_input) == \"abc\"\n\ntest_input = { \"a\": \"bc\", \"b\": \"b\", \"c\": \"c\" }\nassert my_solution.minimumString(**test_input) == \"bc\"\n\ntest_input = { \"a\": \"bc\", \"b\": \"c\", \"c\": \"b\" }\nassert my_solution.minimumString(**test_input) == \"bc\"\n\ntest_input = { \"a\": \"bc\", \"b\": \"c\", \"c\": \"c\" }\nassert my_solution.minimumString(**test_input) == \"bc\"\n\ntest_input = { \"a\": \"ac\", \"b\": \"a\", \"c\": \"c\" }\nassert my_solution.minimumString(**test_input) == \"ac\"\n\ntest_input = { \"a\": \"c\", \"b\": \"c\", \"c\": \"aa\" }\nassert my_solution.minimumString(**test_input) == \"aac\"\n\ntest_input = { \"a\": \"cb\", \"b\": \"b\", \"c\": \"c\" }\nassert my_solution.minimumString(**test_input) == \"cb\"\n\ntest_input = { \"a\": \"c\", \"b\": \"b\", \"c\": \"cc\" }\nassert my_solution.minimumString(**test_input) == \"bcc\"\n\ntest_input = { \"a\": \"ba\", \"b\": \"b\", \"c\": \"c\" }\nassert my_solution.minimumString(**test_input) == \"bac\"\n\ntest_input = { \"a\": \"aa\", \"b\": \"c\", \"c\": \"c\" }\nassert my_solution.minimumString(**test_input) == \"aac\"\n\ntest_input = { \"a\": \"c\", \"b\": \"bc\", \"c\": \"c\" }\nassert my_solution.minimumString(**test_input) == \"bc\"\n\ntest_input = { \"a\": \"c\", \"b\": \"ca\", \"c\": \"c\" }\nassert my_solution.minimumString(**test_input) == \"ca\"\n\ntest_input = { \"a\": \"c\", \"b\": \"cb\", \"c\": \"c\" }\nassert my_solution.minimumString(**test_input) == \"cb\"\n\ntest_input = { \"a\": \"c\", \"b\": \"c\", \"c\": \"cc\" }\nassert my_solution.minimumString(**test_input) == \"cc\"\n\ntest_input = { \"a\": \"ca\", \"b\": \"c\", \"c\": \"a\" }\nassert my_solution.minimumString(**test_input) == \"ca\"", "start_time": 1690684200} +{"task_id": "weekly-contest-356-count-stepping-numbers-in-range", "url": "https://leetcode.com/problems/count-stepping-numbers-in-range", "title": "count-stepping-numbers-in-range", "meta": {"questionId": "2921", "questionFrontendId": "2801", "title": "Count Stepping Numbers in Range", "titleSlug": "count-stepping-numbers-in-range", "isPaidOnly": false, "difficulty": "Hard", "likes": 312, "dislikes": 8, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你两个正整数 low 和 high ,都用字符串表示,请你统计闭区间 [low, high] 内的 步进数字 数目。\n\n如果一个整数相邻数位之间差的绝对值都 恰好 是 1 ,那么这个数字被称为 步进数字 。\n\n请你返回一个整数,表示闭区间 [low, high] 之间步进数字的数目。\n\n由于答案可能很大,请你将它对 109 + 7 取余 后返回。\n\n注意:步进数字不能有前导 0 。\n\n示例 1:\n\n输入:low = \"1\", high = \"11\"\n输出:10\n解释:区间 [1,11] 内的步进数字为 1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 和 10 。总共有 10 个步进数字。所以输出为 10 。\n\n示例 2:\n\n输入:low = \"90\", high = \"101\"\n输出:2\n解释:区间 [90,101] 内的步进数字为 98 和 101 。总共有 2 个步进数字。所以输出为 2 。\n\n提示:\n\n * 1 <= int(low) <= int(high) < 10100\n * 1 <= low.length, high.length <= 100\n * low 和 high 只包含数字。\n * low 和 high 都不含前导 0 。\n\"\"\"\nclass Solution:\n def countSteppingNumbers(self, low: str, high: str) -> int:\n ", "prompt_sft": "给你两个正整数 low 和 high ,都用字符串表示,请你统计闭区间 [low, high] 内的 步进数字 数目。\n\n如果一个整数相邻数位之间差的绝对值都 恰好 是 1 ,那么这个数字被称为 步进数字 。\n\n请你返回一个整数,表示闭区间 [low, high] 之间步进数字的数目。\n\n由于答案可能很大,请你将它对 109 + 7 取余 后返回。\n\n注意:步进数字不能有前导 0 。\n\n示例 1:\n\n输入:low = \"1\", high = \"11\"\n输出:10\n解释:区间 [1,11] 内的步进数字为 1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 和 10 。总共有 10 个步进数字。所以输出为 10 。\n\n示例 2:\n\n输入:low = \"90\", high = \"101\"\n输出:2\n解释:区间 [90,101] 内的步进数字为 98 和 101 。总共有 2 个步进数字。所以输出为 2 。\n\n提示:\n\n * 1 <= int(low) <= int(high) < 10100\n * 1 <= low.length, high.length <= 100\n * low 和 high 只包含数字。\n * low 和 high 都不含前导 0 。\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def countSteppingNumbers(self, low: str, high: str) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"low\": \"1\", \"high\": \"11\" }\nassert my_solution.countSteppingNumbers(**test_input) == 10\n\ntest_input = { \"low\": \"90\", \"high\": \"101\" }\nassert my_solution.countSteppingNumbers(**test_input) == 2\n\ntest_input = { \"low\": \"2\", \"high\": \"40\" }\nassert my_solution.countSteppingNumbers(**test_input) == 14\n\ntest_input = { \"low\": \"26\", \"high\": \"60\" }\nassert my_solution.countSteppingNumbers(**test_input) == 6\n\ntest_input = { \"low\": \"40\", \"high\": \"70\" }\nassert my_solution.countSteppingNumbers(**test_input) == 6\n\ntest_input = { \"low\": \"46\", \"high\": \"66\" }\nassert my_solution.countSteppingNumbers(**test_input) == 3\n\ntest_input = { \"low\": \"58\", \"high\": \"58\" }\nassert my_solution.countSteppingNumbers(**test_input) == 0\n\ntest_input = { \"low\": \"23\", \"high\": \"99\" }\nassert my_solution.countSteppingNumbers(**test_input) == 14\n\ntest_input = { \"low\": \"44\", \"high\": \"86\" }\nassert my_solution.countSteppingNumbers(**test_input) == 7\n\ntest_input = { \"low\": \"20\", \"high\": \"111\" }\nassert my_solution.countSteppingNumbers(**test_input) == 16\n\ntest_input = { \"low\": \"70\", \"high\": \"75\" }\nassert my_solution.countSteppingNumbers(**test_input) == 0\n\ntest_input = { \"low\": \"37\", \"high\": \"111\" }\nassert my_solution.countSteppingNumbers(**test_input) == 12\n\ntest_input = { \"low\": \"17\", \"high\": \"149\" }\nassert my_solution.countSteppingNumbers(**test_input) == 18\n\ntest_input = { \"low\": \"21\", \"high\": \"145\" }\nassert my_solution.countSteppingNumbers(**test_input) == 18\n\ntest_input = { \"low\": \"47\", \"high\": \"124\" }\nassert my_solution.countSteppingNumbers(**test_input) == 12\n\ntest_input = { \"low\": \"81\", \"high\": \"91\" }\nassert my_solution.countSteppingNumbers(**test_input) == 2\n\ntest_input = { \"low\": \"18\", \"high\": \"159\" }\nassert my_solution.countSteppingNumbers(**test_input) == 18\n\ntest_input = { \"low\": \"85\", \"high\": \"92\" }\nassert my_solution.countSteppingNumbers(**test_input) == 2\n\ntest_input = { \"low\": \"66\", \"high\": \"112\" }\nassert my_solution.countSteppingNumbers(**test_input) == 7\n\ntest_input = { \"low\": \"84\", \"high\": \"102\" }\nassert my_solution.countSteppingNumbers(**test_input) == 4\n\ntest_input = { \"low\": \"41\", \"high\": \"156\" }\nassert my_solution.countSteppingNumbers(**test_input) == 14\n\ntest_input = { \"low\": \"64\", \"high\": \"135\" }\nassert my_solution.countSteppingNumbers(**test_input) == 10\n\ntest_input = { \"low\": \"57\", \"high\": \"143\" }\nassert my_solution.countSteppingNumbers(**test_input) == 10\n\ntest_input = { \"low\": \"85\", \"high\": \"116\" }\nassert my_solution.countSteppingNumbers(**test_input) == 4\n\ntest_input = { \"low\": \"103\", \"high\": \"104\" }\nassert my_solution.countSteppingNumbers(**test_input) == 0\n\ntest_input = { \"low\": \"98\", \"high\": \"118\" }\nassert my_solution.countSteppingNumbers(**test_input) == 2\n\ntest_input = { \"low\": \"28\", \"high\": \"197\" }\nassert my_solution.countSteppingNumbers(**test_input) == 16\n\ntest_input = { \"low\": \"6\", \"high\": \"220\" }\nassert my_solution.countSteppingNumbers(**test_input) == 26\n\ntest_input = { \"low\": \"106\", \"high\": \"121\" }\nassert my_solution.countSteppingNumbers(**test_input) == 1\n\ntest_input = { \"low\": \"7\", \"high\": \"226\" }\nassert my_solution.countSteppingNumbers(**test_input) == 25\n\ntest_input = { \"low\": \"105\", \"high\": \"136\" }\nassert my_solution.countSteppingNumbers(**test_input) == 2\n\ntest_input = { \"low\": \"30\", \"high\": \"221\" }\nassert my_solution.countSteppingNumbers(**test_input) == 18\n\ntest_input = { \"low\": \"113\", \"high\": \"139\" }\nassert my_solution.countSteppingNumbers(**test_input) == 2\n\ntest_input = { \"low\": \"44\", \"high\": \"210\" }\nassert my_solution.countSteppingNumbers(**test_input) == 14\n\ntest_input = { \"low\": \"13\", \"high\": \"242\" }\nassert my_solution.countSteppingNumbers(**test_input) == 22\n\ntest_input = { \"low\": \"12\", \"high\": \"257\" }\nassert my_solution.countSteppingNumbers(**test_input) == 23\n\ntest_input = { \"low\": \"70\", \"high\": \"205\" }\nassert my_solution.countSteppingNumbers(**test_input) == 8\n\ntest_input = { \"low\": \"55\", \"high\": \"229\" }\nassert my_solution.countSteppingNumbers(**test_input) == 13\n\ntest_input = { \"low\": \"16\", \"high\": \"276\" }\nassert my_solution.countSteppingNumbers(**test_input) == 22\n\ntest_input = { \"low\": \"140\", \"high\": \"153\" }\nassert my_solution.countSteppingNumbers(**test_input) == 0\n\ntest_input = { \"low\": \"79\", \"high\": \"218\" }\nassert my_solution.countSteppingNumbers(**test_input) == 8\n\ntest_input = { \"low\": \"99\", \"high\": \"200\" }\nassert my_solution.countSteppingNumbers(**test_input) == 3\n\ntest_input = { \"low\": \"90\", \"high\": \"210\" }\nassert my_solution.countSteppingNumbers(**test_input) == 5\n\ntest_input = { \"low\": \"123\", \"high\": \"186\" }\nassert my_solution.countSteppingNumbers(**test_input) == 1\n\ntest_input = { \"low\": \"149\", \"high\": \"160\" }\nassert my_solution.countSteppingNumbers(**test_input) == 0\n\ntest_input = { \"low\": \"138\", \"high\": \"180\" }\nassert my_solution.countSteppingNumbers(**test_input) == 0\n\ntest_input = { \"low\": \"160\", \"high\": \"163\" }\nassert my_solution.countSteppingNumbers(**test_input) == 0\n\ntest_input = { \"low\": \"79\", \"high\": \"246\" }\nassert my_solution.countSteppingNumbers(**test_input) == 10\n\ntest_input = { \"low\": \"137\", \"high\": \"189\" }\nassert my_solution.countSteppingNumbers(**test_input) == 0\n\ntest_input = { \"low\": \"163\", \"high\": \"163\" }\nassert my_solution.countSteppingNumbers(**test_input) == 0\n\ntest_input = { \"low\": \"37\", \"high\": \"289\" }\nassert my_solution.countSteppingNumbers(**test_input) == 18\n\ntest_input = { \"low\": \"79\", \"high\": \"255\" }\nassert my_solution.countSteppingNumbers(**test_input) == 10\n\ntest_input = { \"low\": \"140\", \"high\": \"197\" }\nassert my_solution.countSteppingNumbers(**test_input) == 0\n\ntest_input = { \"low\": \"22\", \"high\": \"317\" }\nassert my_solution.countSteppingNumbers(**test_input) == 21\n\ntest_input = { \"low\": \"146\", \"high\": \"199\" }\nassert my_solution.countSteppingNumbers(**test_input) == 0\n\ntest_input = { \"low\": \"57\", \"high\": \"288\" }\nassert my_solution.countSteppingNumbers(**test_input) == 14\n\ntest_input = { \"low\": \"109\", \"high\": \"237\" }\nassert my_solution.countSteppingNumbers(**test_input) == 6\n\ntest_input = { \"low\": \"48\", \"high\": \"299\" }\nassert my_solution.countSteppingNumbers(**test_input) == 16\n\ntest_input = { \"low\": \"158\", \"high\": \"194\" }\nassert my_solution.countSteppingNumbers(**test_input) == 0\n\ntest_input = { \"low\": \"29\", \"high\": \"326\" }\nassert my_solution.countSteppingNumbers(**test_input) == 22\n\ntest_input = { \"low\": \"133\", \"high\": \"223\" }\nassert my_solution.countSteppingNumbers(**test_input) == 2\n\ntest_input = { \"low\": \"109\", \"high\": \"249\" }\nassert my_solution.countSteppingNumbers(**test_input) == 6\n\ntest_input = { \"low\": \"20\", \"high\": \"341\" }\nassert my_solution.countSteppingNumbers(**test_input) == 24\n\ntest_input = { \"low\": \"9\", \"high\": \"352\" }\nassert my_solution.countSteppingNumbers(**test_input) == 29\n\ntest_input = { \"low\": \"115\", \"high\": \"253\" }\nassert my_solution.countSteppingNumbers(**test_input) == 6\n\ntest_input = { \"low\": \"181\", \"high\": \"188\" }\nassert my_solution.countSteppingNumbers(**test_input) == 0\n\ntest_input = { \"low\": \"120\", \"high\": \"250\" }\nassert my_solution.countSteppingNumbers(**test_input) == 6\n\ntest_input = { \"low\": \"100\", \"high\": \"273\" }\nassert my_solution.countSteppingNumbers(**test_input) == 7\n\ntest_input = { \"low\": \"105\", \"high\": \"269\" }\nassert my_solution.countSteppingNumbers(**test_input) == 6\n\ntest_input = { \"low\": \"189\", \"high\": \"190\" }\nassert my_solution.countSteppingNumbers(**test_input) == 0\n\ntest_input = { \"low\": \"148\", \"high\": \"237\" }\nassert my_solution.countSteppingNumbers(**test_input) == 4\n\ntest_input = { \"low\": \"126\", \"high\": \"267\" }\nassert my_solution.countSteppingNumbers(**test_input) == 4\n\ntest_input = { \"low\": \"141\", \"high\": \"252\" }\nassert my_solution.countSteppingNumbers(**test_input) == 4\n\ntest_input = { \"low\": \"185\", \"high\": \"209\" }\nassert my_solution.countSteppingNumbers(**test_input) == 0\n\ntest_input = { \"low\": \"14\", \"high\": \"381\" }\nassert my_solution.countSteppingNumbers(**test_input) == 26\n\ntest_input = { \"low\": \"7\", \"high\": \"388\" }\nassert my_solution.countSteppingNumbers(**test_input) == 31\n\ntest_input = { \"low\": \"15\", \"high\": \"383\" }\nassert my_solution.countSteppingNumbers(**test_input) == 26\n\ntest_input = { \"low\": \"78\", \"high\": \"325\" }\nassert my_solution.countSteppingNumbers(**test_input) == 13\n\ntest_input = { \"low\": \"131\", \"high\": \"274\" }\nassert my_solution.countSteppingNumbers(**test_input) == 4\n\ntest_input = { \"low\": \"177\", \"high\": \"230\" }\nassert my_solution.countSteppingNumbers(**test_input) == 2\n\ntest_input = { \"low\": \"66\", \"high\": \"346\" }\nassert my_solution.countSteppingNumbers(**test_input) == 17\n\ntest_input = { \"low\": \"144\", \"high\": \"271\" }\nassert my_solution.countSteppingNumbers(**test_input) == 4\n\ntest_input = { \"low\": \"96\", \"high\": \"322\" }\nassert my_solution.countSteppingNumbers(**test_input) == 9\n\ntest_input = { \"low\": \"112\", \"high\": \"307\" }\nassert my_solution.countSteppingNumbers(**test_input) == 6\n\ntest_input = { \"low\": \"73\", \"high\": \"349\" }\nassert my_solution.countSteppingNumbers(**test_input) == 16\n\ntest_input = { \"low\": \"128\", \"high\": \"296\" }\nassert my_solution.countSteppingNumbers(**test_input) == 4\n\ntest_input = { \"low\": \"189\", \"high\": \"237\" }\nassert my_solution.countSteppingNumbers(**test_input) == 4\n\ntest_input = { \"low\": \"141\", \"high\": \"286\" }\nassert my_solution.countSteppingNumbers(**test_input) == 4\n\ntest_input = { \"low\": \"47\", \"high\": \"382\" }\nassert my_solution.countSteppingNumbers(**test_input) == 20\n\ntest_input = { \"low\": \"27\", \"high\": \"411\" }\nassert my_solution.countSteppingNumbers(**test_input) == 24\n\ntest_input = { \"low\": \"16\", \"high\": \"423\" }\nassert my_solution.countSteppingNumbers(**test_input) == 26\n\ntest_input = { \"low\": \"22\", \"high\": \"417\" }\nassert my_solution.countSteppingNumbers(**test_input) == 25\n\ntest_input = { \"low\": \"174\", \"high\": \"266\" }\nassert my_solution.countSteppingNumbers(**test_input) == 4\n\ntest_input = { \"low\": \"101\", \"high\": \"342\" }\nassert my_solution.countSteppingNumbers(**test_input) == 9\n\ntest_input = { \"low\": \"76\", \"high\": \"370\" }\nassert my_solution.countSteppingNumbers(**test_input) == 16\n\ntest_input = { \"low\": \"147\", \"high\": \"301\" }\nassert my_solution.countSteppingNumbers(**test_input) == 4\n\ntest_input = { \"low\": \"72\", \"high\": \"376\" }\nassert my_solution.countSteppingNumbers(**test_input) == 16\n\ntest_input = { \"low\": \"154\", \"high\": \"297\" }\nassert my_solution.countSteppingNumbers(**test_input) == 4\n\ntest_input = { \"low\": \"15\", \"high\": \"439\" }\nassert my_solution.countSteppingNumbers(**test_input) == 28\n\ntest_input = { \"low\": \"73\", \"high\": \"381\" }\nassert my_solution.countSteppingNumbers(**test_input) == 16", "start_time": 1690684200} +{"task_id": "weekly-contest-355-split-strings-by-separator", "url": "https://leetcode.com/problems/split-strings-by-separator", "title": "split-strings-by-separator", "meta": {"questionId": "2881", "questionFrontendId": "2788", "title": "Split Strings by Separator", "titleSlug": "split-strings-by-separator", "isPaidOnly": false, "difficulty": "Easy", "likes": 262, "dislikes": 4, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个字符串数组 words 和一个字符 separator ,请你按 separator 拆分 words 中的每个字符串。\n\n返回一个由拆分后的新字符串组成的字符串数组,不包括空字符串 。\n\n注意\n\n * separator 用于决定拆分发生的位置,但它不包含在结果字符串中。\n * 拆分可能形成两个以上的字符串。\n * 结果字符串必须保持初始相同的先后顺序。\n\n示例 1:\n\n输入:words = [\"one.two.three\",\"four.five\",\"six\"], separator = \".\"\n输出:[\"one\",\"two\",\"three\",\"four\",\"five\",\"six\"]\n解释:在本示例中,我们进行下述拆分:\n\n\"one.two.three\" 拆分为 \"one\", \"two\", \"three\"\n\"four.five\" 拆分为 \"four\", \"five\"\n\"six\" 拆分为 \"six\"\n\n因此,结果数组为 [\"one\",\"two\",\"three\",\"four\",\"five\",\"six\"] 。\n\n示例 2:\n\n输入:words = [\"$easy$\",\"$problem$\"], separator = \"$\"\n输出:[\"easy\",\"problem\"]\n解释:在本示例中,我们进行下述拆分:\n\n\"$easy$\" 拆分为 \"easy\"(不包括空字符串)\n\"$problem$\" 拆分为 \"problem\"(不包括空字符串)\n\n因此,结果数组为 [\"easy\",\"problem\"] 。\n\n示例 3:\n\n输入:words = [\"|||\"], separator = \"|\"\n输出:[]\n解释:在本示例中,\"|||\" 的拆分结果将只包含一些空字符串,所以我们返回一个空数组 [] 。\n\n提示:\n\n * 1 <= words.length <= 100\n * 1 <= words[i].length <= 20\n * words[i] 中的字符要么是小写英文字母,要么就是字符串 \".,|$#@\" 中的字符(不包括引号)\n * separator 是字符串 \".,|$#@\" 中的某个字符(不包括引号)\n\"\"\"\nclass Solution:\n def splitWordsBySeparator(self, words: List[str], separator: str) -> List[str]:\n ", "prompt_sft": "给你一个字符串数组 words 和一个字符 separator ,请你按 separator 拆分 words 中的每个字符串。\n\n返回一个由拆分后的新字符串组成的字符串数组,不包括空字符串 。\n\n注意\n\n * separator 用于决定拆分发生的位置,但它不包含在结果字符串中。\n * 拆分可能形成两个以上的字符串。\n * 结果字符串必须保持初始相同的先后顺序。\n\n示例 1:\n\n输入:words = [\"one.two.three\",\"four.five\",\"six\"], separator = \".\"\n输出:[\"one\",\"two\",\"three\",\"four\",\"five\",\"six\"]\n解释:在本示例中,我们进行下述拆分:\n\n\"one.two.three\" 拆分为 \"one\", \"two\", \"three\"\n\"four.five\" 拆分为 \"four\", \"five\"\n\"six\" 拆分为 \"six\"\n\n因此,结果数组为 [\"one\",\"two\",\"three\",\"four\",\"five\",\"six\"] 。\n\n示例 2:\n\n输入:words = [\"$easy$\",\"$problem$\"], separator = \"$\"\n输出:[\"easy\",\"problem\"]\n解释:在本示例中,我们进行下述拆分:\n\n\"$easy$\" 拆分为 \"easy\"(不包括空字符串)\n\"$problem$\" 拆分为 \"problem\"(不包括空字符串)\n\n因此,结果数组为 [\"easy\",\"problem\"] 。\n\n示例 3:\n\n输入:words = [\"|||\"], separator = \"|\"\n输出:[]\n解释:在本示例中,\"|||\" 的拆分结果将只包含一些空字符串,所以我们返回一个空数组 [] 。\n\n提示:\n\n * 1 <= words.length <= 100\n * 1 <= words[i].length <= 20\n * words[i] 中的字符要么是小写英文字母,要么就是字符串 \".,|$#@\" 中的字符(不包括引号)\n * separator 是字符串 \".,|$#@\" 中的某个字符(不包括引号)\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def splitWordsBySeparator(self, words: List[str], separator: str) -> List[str]:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"words\": [\"one.two.three\",\"four.five\",\"six\"], \"separator\": \".\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"one\",\"two\",\"three\",\"four\",\"five\",\"six\"]\n\ntest_input = { \"words\": [\"$easy$\",\"$problem$\"], \"separator\": \"$\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"easy\",\"problem\"]\n\ntest_input = { \"words\": [\"|||\"], \"separator\": \"|\" }\nassert my_solution.splitWordsBySeparator(**test_input) == []\n\ntest_input = { \"words\": [\"stars.bars.$\"], \"separator\": \".\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"stars\",\"bars\",\"$\"]\n\ntest_input = { \"words\": [\"###x#i@f\"], \"separator\": \"#\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"x\",\"i@f\"]\n\ntest_input = { \"words\": [\"##q@t#\"], \"separator\": \"#\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"q@t\"]\n\ntest_input = { \"words\": [\"#,\"], \"separator\": \"#\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\",\"]\n\ntest_input = { \"words\": [\"#@\"], \"separator\": \"@\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"#\"]\n\ntest_input = { \"words\": [\"#a$f$nwgq#vw\"], \"separator\": \"$\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"#a\",\"f\",\"nwgq#vw\"]\n\ntest_input = { \"words\": [\"#uyddd,trxiwfv\"], \"separator\": \",\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"#uyddd\",\"trxiwfv\"]\n\ntest_input = { \"words\": [\"#x\"], \"separator\": \"$\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"#x\"]\n\ntest_input = { \"words\": [\"#x#,\"], \"separator\": \",\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"#x#\"]\n\ntest_input = { \"words\": [\"#|\"], \"separator\": \"#\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"|\"]\n\ntest_input = { \"words\": [\"#|a|b|##|#|#g#u|\"], \"separator\": \"|\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"#\",\"a\",\"b\",\"##\",\"#\",\"#g#u\"]\n\ntest_input = { \"words\": [\"$$.o.$$.\"], \"separator\": \"$\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\".o.\",\".\"]\n\ntest_input = { \"words\": [\"$,,\"], \"separator\": \",\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"$\"]\n\ntest_input = { \"words\": [\"$j@@@\"], \"separator\": \"@\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"$j\"]\n\ntest_input = { \"words\": [\",$$\"], \"separator\": \"$\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\",\"]\n\ntest_input = { \"words\": [\",,\"], \"separator\": \"|\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\",,\"]\n\ntest_input = { \"words\": [\",,,@@n\"], \"separator\": \",\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"@@n\"]\n\ntest_input = { \"words\": [\",,,@o,\"], \"separator\": \",\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"@o\"]\n\ntest_input = { \"words\": [\",,,p,#r#\"], \"separator\": \",\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"p\",\"#r#\"]\n\ntest_input = { \"words\": [\",,.\"], \"separator\": \",\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\".\"]\n\ntest_input = { \"words\": [\",,ulxh|,u|ustg||ulo\"], \"separator\": \"|\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\",,ulxh\",\",u\",\"ustg\",\"ulo\"]\n\ntest_input = { \"words\": [\",esplco\"], \"separator\": \".\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\",esplco\"]\n\ntest_input = { \"words\": [\",g#,,,#\"], \"separator\": \",\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"g#\",\"#\"]\n\ntest_input = { \"words\": [\",gko\"], \"separator\": \".\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\",gko\"]\n\ntest_input = { \"words\": [\",h,u.f\"], \"separator\": \",\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"h\",\"u.f\"]\n\ntest_input = { \"words\": [\",y|z|bg,\"], \"separator\": \"|\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\",y\",\"z\",\"bg,\"]\n\ntest_input = { \"words\": [\".#z.###b\"], \"separator\": \"#\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\".\",\"z.\",\"b\"]\n\ntest_input = { \"words\": [\"..\"], \"separator\": \".\" }\nassert my_solution.splitWordsBySeparator(**test_input) == []\n\ntest_input = { \"words\": [\".@\"], \"separator\": \".\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"@\"]\n\ntest_input = { \"words\": [\".n#.#..\"], \"separator\": \"#\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\".n\",\".\",\"..\"]\n\ntest_input = { \"words\": [\".trs.t..cvvw.,..p\"], \"separator\": \".\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"trs\",\"t\",\"cvvw\",\",\",\"p\"]\n\ntest_input = { \"words\": [\".vy.$$.qw\"], \"separator\": \".\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"vy\",\"$$\",\"qw\"]\n\ntest_input = { \"words\": [\"@,,\"], \"separator\": \"@\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\",,\"]\n\ntest_input = { \"words\": [\"@..@@.s.@u@.@\"], \"separator\": \".\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"@\",\"@@\",\"s\",\"@u@\",\"@\"]\n\ntest_input = { \"words\": [\"@@..@@@.@vn@\"], \"separator\": \".\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"@@\",\"@@@\",\"@vn@\"]\n\ntest_input = { \"words\": [\"@@@@@@@...@@@\"], \"separator\": \".\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"@@@@@@@\",\"@@@\"]\n\ntest_input = { \"words\": [\"@@@@@@g@@v\"], \"separator\": \"@\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"g\",\"v\"]\n\ntest_input = { \"words\": [\"@@||@\"], \"separator\": \"|\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"@@\",\"@\"]\n\ntest_input = { \"words\": [\"@acp.@\"], \"separator\": \".\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"@acp\",\"@\"]\n\ntest_input = { \"words\": [\"@iw\"], \"separator\": \"|\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"@iw\"]\n\ntest_input = { \"words\": [\"@z#y@@ni\"], \"separator\": \"#\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"@z\",\"y@@ni\"]\n\ntest_input = { \"words\": [\"aovx\"], \"separator\": \"$\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"aovx\"]\n\ntest_input = { \"words\": [\"b\"], \"separator\": \"|\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"b\"]\n\ntest_input = { \"words\": [\"b,,\"], \"separator\": \".\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"b,,\"]\n\ntest_input = { \"words\": [\"b,s\"], \"separator\": \",\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"b\",\"s\"]\n\ntest_input = { \"words\": [\"bqukl,bv\"], \"separator\": \",\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"bqukl\",\"bv\"]\n\ntest_input = { \"words\": [\"cmypa#\"], \"separator\": \"#\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"cmypa\"]\n\ntest_input = { \"words\": [\"cq,,,,y\"], \"separator\": \"$\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"cq,,,,y\"]\n\ntest_input = { \"words\": [\"d,,,@d\"], \"separator\": \",\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"d\",\"@d\"]\n\ntest_input = { \"words\": [\"dgjtc\"], \"separator\": \".\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"dgjtc\"]\n\ntest_input = { \"words\": [\"e$,$,w$,,z,,$$,\"], \"separator\": \",\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"e$\",\"$\",\"w$\",\"z\",\"$$\"]\n\ntest_input = { \"words\": [\"e,,$,$,,,\"], \"separator\": \",\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"e\",\"$\",\"$\"]\n\ntest_input = { \"words\": [\"edz.\"], \"separator\": \"$\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"edz.\"]\n\ntest_input = { \"words\": [\"f\"], \"separator\": \".\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"f\"]\n\ntest_input = { \"words\": [\"f.\"], \"separator\": \"|\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"f.\"]\n\ntest_input = { \"words\": [\"g\"], \"separator\": \"|\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"g\"]\n\ntest_input = { \"words\": [\"g###\"], \"separator\": \"@\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"g###\"]\n\ntest_input = { \"words\": [\"g|@@@@@|\"], \"separator\": \"@\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"g|\",\"|\"]\n\ntest_input = { \"words\": [\"h\"], \"separator\": \".\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"h\"]\n\ntest_input = { \"words\": [\"h#\"], \"separator\": \"#\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"h\"]\n\ntest_input = { \"words\": [\"hpo\"], \"separator\": \",\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"hpo\"]\n\ntest_input = { \"words\": [\"imq#zect\"], \"separator\": \",\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"imq#zect\"]\n\ntest_input = { \"words\": [\"io@\"], \"separator\": \".\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"io@\"]\n\ntest_input = { \"words\": [\"j@..@f.v@.\"], \"separator\": \"@\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"j\",\"..\",\"f.v\",\".\"]\n\ntest_input = { \"words\": [\"jxe|xfim\"], \"separator\": \"|\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"jxe\",\"xfim\"]\n\ntest_input = { \"words\": [\"lyegjxsg\"], \"separator\": \",\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"lyegjxsg\"]\n\ntest_input = { \"words\": [\"l|\"], \"separator\": \"$\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"l|\"]\n\ntest_input = { \"words\": [\"mm..,.j..\"], \"separator\": \".\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"mm\",\",\",\"j\"]\n\ntest_input = { \"words\": [\"n.\"], \"separator\": \".\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"n\"]\n\ntest_input = { \"words\": [\"no#\"], \"separator\": \",\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"no#\"]\n\ntest_input = { \"words\": [\"nyy|\"], \"separator\": \"|\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"nyy\"]\n\ntest_input = { \"words\": [\"pfx|ons\"], \"separator\": \"@\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"pfx|ons\"]\n\ntest_input = { \"words\": [\"pl\"], \"separator\": \"#\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"pl\"]\n\ntest_input = { \"words\": [\"q\"], \"separator\": \"@\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"q\"]\n\ntest_input = { \"words\": [\"q\"], \"separator\": \"|\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"q\"]\n\ntest_input = { \"words\": [\"qv\"], \"separator\": \"$\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"qv\"]\n\ntest_input = { \"words\": [\"r\"], \"separator\": \"@\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"r\"]\n\ntest_input = { \"words\": [\"rxs|$mg\"], \"separator\": \"$\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"rxs|\",\"mg\"]\n\ntest_input = { \"words\": [\"sls,l,xn\"], \"separator\": \",\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"sls\",\"l\",\"xn\"]\n\ntest_input = { \"words\": [\"t@\"], \"separator\": \"@\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"t\"]\n\ntest_input = { \"words\": [\"tsklm|dhmsr\"], \"separator\": \"|\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"tsklm\",\"dhmsr\"]\n\ntest_input = { \"words\": [\"t|@@w||\"], \"separator\": \"|\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"t\",\"@@w\"]\n\ntest_input = { \"words\": [\"u\"], \"separator\": \"|\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"u\"]\n\ntest_input = { \"words\": [\"ufjvddie\"], \"separator\": \"|\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"ufjvddie\"]\n\ntest_input = { \"words\": [\"unvywqeuqvdq\"], \"separator\": \"$\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"unvywqeuqvdq\"]\n\ntest_input = { \"words\": [\"vt@\"], \"separator\": \"@\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"vt\"]\n\ntest_input = { \"words\": [\"w,xu#v,m,jh,\"], \"separator\": \",\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"w\",\"xu#v\",\"m\",\"jh\"]\n\ntest_input = { \"words\": [\"w|vip|\"], \"separator\": \"|\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"w\",\"vip\"]\n\ntest_input = { \"words\": [\"xjmjh$@\"], \"separator\": \"@\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"xjmjh$\"]\n\ntest_input = { \"words\": [\"xm,tjd$\"], \"separator\": \"$\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"xm,tjd\"]\n\ntest_input = { \"words\": [\"yww\"], \"separator\": \"@\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"yww\"]\n\ntest_input = { \"words\": [\"z\"], \"separator\": \"$\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"z\"]\n\ntest_input = { \"words\": [\"z#|||###\"], \"separator\": \"|\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"z#\",\"###\"]\n\ntest_input = { \"words\": [\"zb@\"], \"separator\": \",\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"zb@\"]\n\ntest_input = { \"words\": [\"|,,|,|||\"], \"separator\": \"|\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\",,\",\",\"]\n\ntest_input = { \"words\": [\"|,r,fg\"], \"separator\": \"|\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\",r,fg\"]\n\ntest_input = { \"words\": [\"|.\"], \"separator\": \"|\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\".\"]", "start_time": 1690079400} +{"task_id": "weekly-contest-355-largest-element-in-an-array-after-merge-operations", "url": "https://leetcode.com/problems/largest-element-in-an-array-after-merge-operations", "title": "largest-element-in-an-array-after-merge-operations", "meta": {"questionId": "2872", "questionFrontendId": "2789", "title": "Largest Element in an Array after Merge Operations", "titleSlug": "largest-element-in-an-array-after-merge-operations", "isPaidOnly": false, "difficulty": "Medium", "likes": 413, "dislikes": 26, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0 开始、由正整数组成的数组 nums 。\n\n你可以在数组上执行下述操作 任意 次:\n\n * 选中一个同时满足 0 <= i < nums.length - 1 和 nums[i] <= nums[i + 1] 的整数 i 。将元素 nums[i + 1] 替换为 nums[i] + nums[i + 1] ,并从数组中删除元素 nums[i] 。\n\n返回你可以从最终数组中获得的 最大 元素的值。\n\n示例 1:\n\n输入:nums = [2,3,7,9,3]\n输出:21\n解释:我们可以在数组上执行下述操作:\n- 选中 i = 0 ,得到数组 nums = [5,7,9,3] 。\n- 选中 i = 1 ,得到数组 nums = [5,16,3] 。\n- 选中 i = 0 ,得到数组 nums = [21,3] 。\n最终数组中的最大元素是 21 。可以证明我们无法获得更大的元素。\n\n示例 2:\n\n输入:nums = [5,3,3]\n输出:11\n解释:我们可以在数组上执行下述操作:\n- 选中 i = 1 ,得到数组 nums = [5,6] 。\n- 选中 i = 0 ,得到数组 nums = [11] 。\n最终数组中只有一个元素,即 11 。\n\n\n提示:\n\n * 1 <= nums.length <= 105\n * 1 <= nums[i] <= 106\n\"\"\"\nclass Solution:\n def maxArrayValue(self, nums: List[int]) -> int:\n ", "prompt_sft": "给你一个下标从 0 开始、由正整数组成的数组 nums 。\n\n你可以在数组上执行下述操作 任意 次:\n\n * 选中一个同时满足 0 <= i < nums.length - 1 和 nums[i] <= nums[i + 1] 的整数 i 。将元素 nums[i + 1] 替换为 nums[i] + nums[i + 1] ,并从数组中删除元素 nums[i] 。\n\n返回你可以从最终数组中获得的 最大 元素的值。\n\n示例 1:\n\n输入:nums = [2,3,7,9,3]\n输出:21\n解释:我们可以在数组上执行下述操作:\n- 选中 i = 0 ,得到数组 nums = [5,7,9,3] 。\n- 选中 i = 1 ,得到数组 nums = [5,16,3] 。\n- 选中 i = 0 ,得到数组 nums = [21,3] 。\n最终数组中的最大元素是 21 。可以证明我们无法获得更大的元素。\n\n示例 2:\n\n输入:nums = [5,3,3]\n输出:11\n解释:我们可以在数组上执行下述操作:\n- 选中 i = 1 ,得到数组 nums = [5,6] 。\n- 选中 i = 0 ,得到数组 nums = [11] 。\n最终数组中只有一个元素,即 11 。\n\n\n提示:\n\n * 1 <= nums.length <= 105\n * 1 <= nums[i] <= 106\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def maxArrayValue(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [2,3,7,9,3] }\nassert my_solution.maxArrayValue(**test_input) == 21\n\ntest_input = { \"nums\": [5,3,3] }\nassert my_solution.maxArrayValue(**test_input) == 11\n\ntest_input = { \"nums\": [77] }\nassert my_solution.maxArrayValue(**test_input) == 77\n\ntest_input = { \"nums\": [34,95,50,12,25,100,21,3,25,16,76,73,93,46,18] }\nassert my_solution.maxArrayValue(**test_input) == 623\n\ntest_input = { \"nums\": [40,15,35,98,77,79,24,62,53,84,97,16,30,22,49] }\nassert my_solution.maxArrayValue(**test_input) == 781\n\ntest_input = { \"nums\": [64,35,42,19,95,8,83,89,33,21,97,11,51,93,36,34,67,53] }\nassert my_solution.maxArrayValue(**test_input) == 878\n\ntest_input = { \"nums\": [65,68,55,6,79,30,81,25,61,2,28,59,63,15,35,8,10,83] }\nassert my_solution.maxArrayValue(**test_input) == 773\n\ntest_input = { \"nums\": [56] }\nassert my_solution.maxArrayValue(**test_input) == 56\n\ntest_input = { \"nums\": [100] }\nassert my_solution.maxArrayValue(**test_input) == 100\n\ntest_input = { \"nums\": [35,23,71,38] }\nassert my_solution.maxArrayValue(**test_input) == 129\n\ntest_input = { \"nums\": [56,67,18,81,95,41,39,56,63,70,56,31,84,46,28,38,27,56,13,10,58,16,85,21,63,8] }\nassert my_solution.maxArrayValue(**test_input) == 1134\n\ntest_input = { \"nums\": [72,72] }\nassert my_solution.maxArrayValue(**test_input) == 144\n\ntest_input = { \"nums\": [16,31,55] }\nassert my_solution.maxArrayValue(**test_input) == 102\n\ntest_input = { \"nums\": [6,65,68,7,35,19,28] }\nassert my_solution.maxArrayValue(**test_input) == 228\n\ntest_input = { \"nums\": [38,37,88,60,93,4,5,65,74,25,59,28,86,33,28,33,93] }\nassert my_solution.maxArrayValue(**test_input) == 849\n\ntest_input = { \"nums\": [29,9,3,55,25,38,88,39,38,73,47,57,40,56,4,52,1,44,88,20,18,8] }\nassert my_solution.maxArrayValue(**test_input) == 786\n\ntest_input = { \"nums\": [34,92,42,24,98,87,40,82,51,67,70,75,45,57,67] }\nassert my_solution.maxArrayValue(**test_input) == 931\n\ntest_input = { \"nums\": [31,75,44,92,13,10,3,41,47,89,5,92,17,62,65,40,43,68,30,45,85,24,40,77,80,65] }\nassert my_solution.maxArrayValue(**test_input) == 1218\n\ntest_input = { \"nums\": [63,58,61,58,82,48,83,24,24,61,31,16,26,50] }\nassert my_solution.maxArrayValue(**test_input) == 685\n\ntest_input = { \"nums\": [10,82,74,54,20,43,74,95,17,28,44,74,25,19,75,2,84,99] }\nassert my_solution.maxArrayValue(**test_input) == 919\n\ntest_input = { \"nums\": [91,32,21,55,44,29,82,75,66,29,77,62,55,94,49,80,12,46,80,64,88,51,2,24,11,10,86,39,16] }\nassert my_solution.maxArrayValue(**test_input) == 1415\n\ntest_input = { \"nums\": [18,16,56,64,82,25,16,2,19] }\nassert my_solution.maxArrayValue(**test_input) == 236\n\ntest_input = { \"nums\": [29,79,47,55,13,47,48,91,29,28,34,85,98,44,93,56,24,77,61] }\nassert my_solution.maxArrayValue(**test_input) == 977\n\ntest_input = { \"nums\": [74,8,1,57,25,62] }\nassert my_solution.maxArrayValue(**test_input) == 227\n\ntest_input = { \"nums\": [25,36,55,32,15,16,73,67,82,23,17,29,78,34,4,91,1,1,55,65] }\nassert my_solution.maxArrayValue(**test_input) == 799\n\ntest_input = { \"nums\": [6,36,69,97,86,44,27,46] }\nassert my_solution.maxArrayValue(**test_input) == 411\n\ntest_input = { \"nums\": [18,36,100,34,31,89,96,6,73,10,82,20,26,13,24,51,87,70,63,36] }\nassert my_solution.maxArrayValue(**test_input) == 796\n\ntest_input = { \"nums\": [86,57,57,56,38,97,82,48,33,55,19,21,57,85,11,11,71,94,61,41,1,78,39,45] }\nassert my_solution.maxArrayValue(**test_input) == 1243\n\ntest_input = { \"nums\": [33,9,11,6,68,43,76,40,91] }\nassert my_solution.maxArrayValue(**test_input) == 377\n\ntest_input = { \"nums\": [89,45,50,98,23,79,10,98,69,65,47,46,95] }\nassert my_solution.maxArrayValue(**test_input) == 814\n\ntest_input = { \"nums\": [58,95] }\nassert my_solution.maxArrayValue(**test_input) == 153\n\ntest_input = { \"nums\": [91,50] }\nassert my_solution.maxArrayValue(**test_input) == 91\n\ntest_input = { \"nums\": [99,82,49,52,5,69,65,94,94,57,46,26,28,84,42,61,19,87,71,66,1,72] }\nassert my_solution.maxArrayValue(**test_input) == 1269\n\ntest_input = { \"nums\": [75,75,93,44,16,27,43,71,65,90,100,97,39,100,55,15,10,7,25,23,47] }\nassert my_solution.maxArrayValue(**test_input) == 1117\n\ntest_input = { \"nums\": [65] }\nassert my_solution.maxArrayValue(**test_input) == 65\n\ntest_input = { \"nums\": [50] }\nassert my_solution.maxArrayValue(**test_input) == 50\n\ntest_input = { \"nums\": [56,8,10,87,83,79,33,72,32,59,75,2,46,9] }\nassert my_solution.maxArrayValue(**test_input) == 594\n\ntest_input = { \"nums\": [26,77,78,94,90,90,57,100,60,1,98,85,78,77,63,30,88,60,41,55] }\nassert my_solution.maxArrayValue(**test_input) == 1348\n\ntest_input = { \"nums\": [65,53,93,76,75,18,32,88,4] }\nassert my_solution.maxArrayValue(**test_input) == 500\n\ntest_input = { \"nums\": [24,89,92,48,81,49,83,4,53,39,48,10,53,51,41,23,83,8,53,91,43,58,82] }\nassert my_solution.maxArrayValue(**test_input) == 1206\n\ntest_input = { \"nums\": [59,17,33] }\nassert my_solution.maxArrayValue(**test_input) == 59\n\ntest_input = { \"nums\": [15,35,97,93,34,34,90,2,21] }\nassert my_solution.maxArrayValue(**test_input) == 398\n\ntest_input = { \"nums\": [87,64,21,27,41,63,28,75,64,22,30,76,77,91,84,81,99,86,1,74,46,4,7] }\nassert my_solution.maxArrayValue(**test_input) == 1030\n\ntest_input = { \"nums\": [89,49,59,59,2,77,55,44,51,47,100,77,30,71,47,100,13,17,12,38,26,55,89,41] }\nassert my_solution.maxArrayValue(**test_input) == 1207\n\ntest_input = { \"nums\": [71,4,53,51,9,92,91,86,84,58,31,39,38,49,56,27,91,17,10,56,52,78,35,76,39] }\nassert my_solution.maxArrayValue(**test_input) == 1254\n\ntest_input = { \"nums\": [9,46,6,42,81,7,61,88,37,15,20,67] }\nassert my_solution.maxArrayValue(**test_input) == 479\n\ntest_input = { \"nums\": [50,64,31,70,46,30,41,69,80,45,73,4,100,88,7,3,59] }\nassert my_solution.maxArrayValue(**test_input) == 703\n\ntest_input = { \"nums\": [20,41,58,61,79,7,58,42,89,39] }\nassert my_solution.maxArrayValue(**test_input) == 455\n\ntest_input = { \"nums\": [68,86,34,99,4,6,24,88,26,83,2,33,37,79,30,60,56,44,53,4,86,60,13,81,95,28,83,24] }\nassert my_solution.maxArrayValue(**test_input) == 1362\n\ntest_input = { \"nums\": [5,61,59,13,21,90,32,93,84,16,71,78,53,90,5,50,47,85,83,72,88,20,97,28,73,75,59,34,21] }\nassert my_solution.maxArrayValue(**test_input) == 1489\n\ntest_input = { \"nums\": [99,57,14,77,78,88,47,12,45,72,70,73,75,35,50,88,26,38,77,23,86,27,9,16] }\nassert my_solution.maxArrayValue(**test_input) == 1230\n\ntest_input = { \"nums\": [68,65,95,53,51,26,2,3,17,26,15,37,50,79,20,71,99,72,82,37,29,34,74,93] }\nassert my_solution.maxArrayValue(**test_input) == 1198\n\ntest_input = { \"nums\": [68,21,61,74,38,91,99,32,98,12,52] }\nassert my_solution.maxArrayValue(**test_input) == 582\n\ntest_input = { \"nums\": [98,95,15,53,31,15,9,24,59] }\nassert my_solution.maxArrayValue(**test_input) == 399\n\ntest_input = { \"nums\": [51,18,21,99,6,55,41,20,74,43,98,41,58,29,75,16,8,83,23,79,73,68,95,10,67] }\nassert my_solution.maxArrayValue(**test_input) == 1174\n\ntest_input = { \"nums\": [78,91,52,92,42,53,77,88,40,33,86,70,85,50,65,43,75,60,28,97,95,95] }\nassert my_solution.maxArrayValue(**test_input) == 1495\n\ntest_input = { \"nums\": [99,6] }\nassert my_solution.maxArrayValue(**test_input) == 99\n\ntest_input = { \"nums\": [59,50,38,100,42,42,99,7] }\nassert my_solution.maxArrayValue(**test_input) == 430\n\ntest_input = { \"nums\": [35,23,73,45,29,94,1,18,46,7,52,6,47,47,19,93,48,70,85,98,50,89,23] }\nassert my_solution.maxArrayValue(**test_input) == 1075\n\ntest_input = { \"nums\": [2,55,19,10,28,45,86,31,45,32,38,95,65,23,50,39,51,24,40,15,16] }\nassert my_solution.maxArrayValue(**test_input) == 778\n\ntest_input = { \"nums\": [31,59,12,90,39] }\nassert my_solution.maxArrayValue(**test_input) == 192\n\ntest_input = { \"nums\": [53,87,11,58,79,42,44,24,68,61] }\nassert my_solution.maxArrayValue(**test_input) == 466\n\ntest_input = { \"nums\": [20,45] }\nassert my_solution.maxArrayValue(**test_input) == 65\n\ntest_input = { \"nums\": [85,36,99,11,91,88,55,25,68,88,27,98,7,14,40,27,18,51,90,21,77,12,87,11,37,80,70] }\nassert my_solution.maxArrayValue(**test_input) == 1343\n\ntest_input = { \"nums\": [43,50,40,92,31,2,92] }\nassert my_solution.maxArrayValue(**test_input) == 350\n\ntest_input = { \"nums\": [79,90,32,30,33,18,55,96] }\nassert my_solution.maxArrayValue(**test_input) == 433\n\ntest_input = { \"nums\": [65,15,18,94,96,22,37,19,23,11,27,94,5,99] }\nassert my_solution.maxArrayValue(**test_input) == 625\n\ntest_input = { \"nums\": [74,26,11,96,49,19,25,77,47,31,87,96,19,40,95,91,48,79,33,96] }\nassert my_solution.maxArrayValue(**test_input) == 1139\n\ntest_input = { \"nums\": [17,90,66] }\nassert my_solution.maxArrayValue(**test_input) == 107\n\ntest_input = { \"nums\": [60,11,95,75,10,64,62,20] }\nassert my_solution.maxArrayValue(**test_input) == 166\n\ntest_input = { \"nums\": [99,6,67,44,84,29,87,13,44,12,92,53,26,47,88,44,75,33,19] }\nassert my_solution.maxArrayValue(**test_input) == 910\n\ntest_input = { \"nums\": [69,21,11,10,42,3,38,36,50,28,25,93,37,45,73,37,97] }\nassert my_solution.maxArrayValue(**test_input) == 715\n\ntest_input = { \"nums\": [32,76,65,61,84,11,94,96,17,14,79,15,62] }\nassert my_solution.maxArrayValue(**test_input) == 629\n\ntest_input = { \"nums\": [59,91,27,74,57,30,51,67,88,26,89,10,70,31,32,26,42] }\nassert my_solution.maxArrayValue(**test_input) == 870\n\ntest_input = { \"nums\": [8,73,22,37,39,1,66,59,5,20,16,68,55,50,48,6,8,46,93,76,48,14,92] }\nassert my_solution.maxArrayValue(**test_input) == 950\n\ntest_input = { \"nums\": [58,34,72,5,33,34,68,96,63,85,84,74,87,33,75,43,36,28,62,44,95,39,2] }\nassert my_solution.maxArrayValue(**test_input) == 1209\n\ntest_input = { \"nums\": [49,88,44,17,36,65,94,92,75,23,67,55,68,80,95,11,68,66,77,66,3,32,16,81,34,20,56,87,87,29] }\nassert my_solution.maxArrayValue(**test_input) == 1652\n\ntest_input = { \"nums\": [94,27,5,47] }\nassert my_solution.maxArrayValue(**test_input) == 94\n\ntest_input = { \"nums\": [83,85,59,55] }\nassert my_solution.maxArrayValue(**test_input) == 168\n\ntest_input = { \"nums\": [72,56,30,65,94,91,12,99,9] }\nassert my_solution.maxArrayValue(**test_input) == 519\n\ntest_input = { \"nums\": [9,99,20,61,57,88,50,36,21,100,62,98,94,81,96,3,98,37,88] }\nassert my_solution.maxArrayValue(**test_input) == 1198\n\ntest_input = { \"nums\": [45,18,13,66,54,45,64,70,94,67,26,48,84,57,81,85,35,17,20,84,78,24,63,9] }\nassert my_solution.maxArrayValue(**test_input) == 1238\n\ntest_input = { \"nums\": [5,38,82,83,92,97] }\nassert my_solution.maxArrayValue(**test_input) == 397\n\ntest_input = { \"nums\": [95,15,19,26,59,58] }\nassert my_solution.maxArrayValue(**test_input) == 214\n\ntest_input = { \"nums\": [94,75,16,33,2,70,56,4,64] }\nassert my_solution.maxArrayValue(**test_input) == 414\n\ntest_input = { \"nums\": [64,50,26,66] }\nassert my_solution.maxArrayValue(**test_input) == 206\n\ntest_input = { \"nums\": [3,48,11,71,57,72,83,61,59,25,36,29,11,69,75,48,44,44] }\nassert my_solution.maxArrayValue(**test_input) == 846\n\ntest_input = { \"nums\": [88,7,38,15,43,8,87,7,25,2,51,29,74,34,84,87,83,34,74,22,45,96,71,4,23,28,27,68,61] }\nassert my_solution.maxArrayValue(**test_input) == 1254\n\ntest_input = { \"nums\": [30,58,2,20,54] }\nassert my_solution.maxArrayValue(**test_input) == 164\n\ntest_input = { \"nums\": [17,34,71,23,88,84,35,49,89,39,33,13,87,49,48,97] }\nassert my_solution.maxArrayValue(**test_input) == 856\n\ntest_input = { \"nums\": [50,67,98,47,18,91,80,3,19,74,40,89,85,99,95,81,72,96,56,15,48,93,64] }\nassert my_solution.maxArrayValue(**test_input) == 1416\n\ntest_input = { \"nums\": [58,10,99,6,16,94,45,47,4,30,58] }\nassert my_solution.maxArrayValue(**test_input) == 467\n\ntest_input = { \"nums\": [92,58,90,38,37,95,47,82,6,86,99,9,91,80,73,54,45] }\nassert my_solution.maxArrayValue(**test_input) == 830\n\ntest_input = { \"nums\": [31,100,59,88,81,74,49,21,31,53,9,89,67,4,84,46,41] }\nassert my_solution.maxArrayValue(**test_input) == 840\n\ntest_input = { \"nums\": [25,3,94,55,70,23,43,8,65,34,83,60,53,62,97,55,3,10] }\nassert my_solution.maxArrayValue(**test_input) == 775\n\ntest_input = { \"nums\": [27,53,99,55,15,59,85,40,46,45,45,71,42,67] }\nassert my_solution.maxArrayValue(**test_input) == 749\n\ntest_input = { \"nums\": [8,62,12,10,79,36,59,73,76,24,45,98,72,83,61,6,19,49] }\nassert my_solution.maxArrayValue(**test_input) == 872\n\ntest_input = { \"nums\": [2,24,30,18,94,26,22,60,50,3,27,31] }\nassert my_solution.maxArrayValue(**test_input) == 387\n\ntest_input = { \"nums\": [64,17,57,72,24,88,29,2,23,82,15,69,80,93,38,47,9,10,68,89,65,16] }\nassert my_solution.maxArrayValue(**test_input) == 976\n\ntest_input = { \"nums\": [99,58,59,5,67,15,6,91,71,75,79,59,40,1,18,49,48,75,92,72,81,43,31,31,29,94,39] }\nassert my_solution.maxArrayValue(**test_input) == 1388", "start_time": 1690079400} +{"task_id": "weekly-contest-355-maximum-number-of-groups-with-increasing-length", "url": "https://leetcode.com/problems/maximum-number-of-groups-with-increasing-length", "title": "maximum-number-of-groups-with-increasing-length", "meta": {"questionId": "2919", "questionFrontendId": "2790", "title": "Maximum Number of Groups With Increasing Length", "titleSlug": "maximum-number-of-groups-with-increasing-length", "isPaidOnly": false, "difficulty": "Hard", "likes": 383, "dislikes": 38, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0 开始、长度为 n 的数组 usageLimits 。\n\n你的任务是使用从 0 到 n - 1 的数字创建若干组,并确保每个数字 i 在 所有组 中使用的次数总共不超过 usageLimits[i] 次。此外,还必须满足以下条件:\n\n * 每个组必须由 不同 的数字组成,也就是说,单个组内不能存在重复的数字。\n * 每个组(除了第一个)的长度必须 严格大于 前一个组。\n\n在满足所有条件的情况下,以整数形式返回可以创建的最大组数。\n\n示例 1:\n\n输入:usageLimits = [1,2,5]\n输出:3\n解释:在这个示例中,我们可以使用 0 至多一次,使用 1 至多 2 次,使用 2 至多 5 次。\n一种既能满足所有条件,又能创建最多组的方式是:\n组 1 包含数字 [2] 。\n组 2 包含数字 [1,2] 。\n组 3 包含数字 [0,1,2] 。\n可以证明能够创建的最大组数是 3 。\n所以,输出是 3 。\n\n示例 2:\n\n输入:usageLimits = [2,1,2]\n输出:2\n解释:在这个示例中,我们可以使用 0 至多 2 次,使用 1 至多 1 次,使用 2 至多 2 次。\n一种既能满足所有条件,又能创建最多组的方式是:\n组 1 包含数字 [0] 。\n组 2 包含数字 [1,2] 。\n可以证明能够创建的最大组数是 2 。\n所以,输出是 2 。\n\n示例 3:\n\n输入:usageLimits = [1,1]\n输出:1\n解释:在这个示例中,我们可以使用 0 和 1 至多 1 次。\n一种既能满足所有条件,又能创建最多组的方式是:\n组 1 包含数字 [0] 。\n可以证明能够创建的最大组数是 1 。\n所以,输出是 1 。\n\n\n提示:\n\n * 1 <= usageLimits.length <= 105\n * 1 <= usageLimits[i] <= 109\n\"\"\"\nclass Solution:\n def maxIncreasingGroups(self, usageLimits: List[int]) -> int:\n ", "prompt_sft": "给你一个下标从 0 开始、长度为 n 的数组 usageLimits 。\n\n你的任务是使用从 0 到 n - 1 的数字创建若干组,并确保每个数字 i 在 所有组 中使用的次数总共不超过 usageLimits[i] 次。此外,还必须满足以下条件:\n\n * 每个组必须由 不同 的数字组成,也就是说,单个组内不能存在重复的数字。\n * 每个组(除了第一个)的长度必须 严格大于 前一个组。\n\n在满足所有条件的情况下,以整数形式返回可以创建的最大组数。\n\n示例 1:\n\n输入:usageLimits = [1,2,5]\n输出:3\n解释:在这个示例中,我们可以使用 0 至多一次,使用 1 至多 2 次,使用 2 至多 5 次。\n一种既能满足所有条件,又能创建最多组的方式是:\n组 1 包含数字 [2] 。\n组 2 包含数字 [1,2] 。\n组 3 包含数字 [0,1,2] 。\n可以证明能够创建的最大组数是 3 。\n所以,输出是 3 。\n\n示例 2:\n\n输入:usageLimits = [2,1,2]\n输出:2\n解释:在这个示例中,我们可以使用 0 至多 2 次,使用 1 至多 1 次,使用 2 至多 2 次。\n一种既能满足所有条件,又能创建最多组的方式是:\n组 1 包含数字 [0] 。\n组 2 包含数字 [1,2] 。\n可以证明能够创建的最大组数是 2 。\n所以,输出是 2 。\n\n示例 3:\n\n输入:usageLimits = [1,1]\n输出:1\n解释:在这个示例中,我们可以使用 0 和 1 至多 1 次。\n一种既能满足所有条件,又能创建最多组的方式是:\n组 1 包含数字 [0] 。\n可以证明能够创建的最大组数是 1 。\n所以,输出是 1 。\n\n\n提示:\n\n * 1 <= usageLimits.length <= 105\n * 1 <= usageLimits[i] <= 109\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def maxIncreasingGroups(self, usageLimits: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"usageLimits\": [1,2,5] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [2,1,2] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [1,1] }\nassert my_solution.maxIncreasingGroups(**test_input) == 1\n\ntest_input = { \"usageLimits\": [1,4] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [1,5] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [1,7] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [1,8] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [2,1] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [2,2] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [2,3] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [2,4] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [2,5] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [2,7] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [2,8] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [2,9] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [3,1] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [3,4] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [3,7] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [3,10] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [4,1] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [4,2] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [4,4] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [4,5] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [4,7] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [4,10] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [5,8] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [5,10] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [6,2] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [6,3] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [6,4] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [6,5] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [6,6] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [6,7] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [6,9] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [6,19] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [7,1] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [7,2] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [7,3] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [7,4] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [7,7] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [7,13] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [8,3] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [8,6] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [9,1] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [9,3] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [9,4] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [9,6] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [9,8] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [9,10] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [10,2] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [10,3] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [10,8] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [10,11] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [13,11] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [13,13] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [16,9] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [18,6] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [32,42] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [1,1,5] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [1,1,10] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [1,4,3] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [1,4,5] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [1,6,4] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [1,6,8] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [1,7,19] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [1,8,6] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [1,9,5] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [1,9,6] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [1,10,6] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [2,2,2] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [2,3,8] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [2,6,10] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [2,7,2] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [2,7,7] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [2,8,7] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [2,9,9] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [3,1,1] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [3,5,5] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [3,5,8] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [3,6,5] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [3,7,4] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [3,7,10] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [3,8,1] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [3,9,9] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [3,10,9] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [4,2,5] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [4,2,15] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [4,5,5] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [4,7,9] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [4,8,2] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [4,8,4] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [4,10,3] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [4,10,4] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [5,1,5] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [5,2,9] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [5,2,10] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [5,6,1] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [5,6,5] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [5,7,4] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [5,10,3] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3", "start_time": 1690079400} +{"task_id": "weekly-contest-355-count-paths-that-can-form-a-palindrome-in-a-tree", "url": "https://leetcode.com/problems/count-paths-that-can-form-a-palindrome-in-a-tree", "title": "count-paths-that-can-form-a-palindrome-in-a-tree", "meta": {"questionId": "2905", "questionFrontendId": "2791", "title": "Count Paths That Can Form a Palindrome in a Tree", "titleSlug": "count-paths-that-can-form-a-palindrome-in-a-tree", "isPaidOnly": false, "difficulty": "Hard", "likes": 343, "dislikes": 4, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一棵 树(即,一个连通、无向且无环的图),根 节点为 0 ,由编号从 0 到 n - 1 的 n 个节点组成。这棵树用一个长度为 n 、下标从 0 开始的数组 parent 表示,其中 parent[i] 为节点 i 的父节点,由于节点 0 为根节点,所以 parent[0] == -1 。\n\n另给你一个长度为 n 的字符串 s ,其中 s[i] 是分配给 i 和 parent[i] 之间的边的字符。s[0] 可以忽略。\n\n找出满足 u < v ,且从 u 到 v 的路径上分配的字符可以 重新排列 形成 回文 的所有节点对 (u, v) ,并返回节点对的数目。\n\n如果一个字符串正着读和反着读都相同,那么这个字符串就是一个 回文 。\n\n示例 1:\n\n[https://assets.leetcode.com/uploads/2023/07/15/treedrawio-8drawio.png]\n\n输入:parent = [-1,0,0,1,1,2], s = \"acaabc\"\n输出:8\n解释:符合题目要求的节点对分别是:\n- (0,1)、(0,2)、(1,3)、(1,4) 和 (2,5) ,路径上只有一个字符,满足回文定义。\n- (2,3),路径上字符形成的字符串是 \"aca\" ,满足回文定义。\n- (1,5),路径上字符形成的字符串是 \"cac\" ,满足回文定义。\n- (3,5),路径上字符形成的字符串是 \"acac\" ,可以重排形成回文 \"acca\" 。\n\n示例 2:\n\n输入:parent = [-1,0,0,0,0], s = \"aaaaa\"\n输出:10\n解释:任何满足 u < v 的节点对 (u,v) 都符合题目要求。\n\n\n提示:\n\n * n == parent.length == s.length\n * 1 <= n <= 105\n * 对于所有 i >= 1 ,0 <= parent[i] <= n - 1 均成立\n * parent[0] == -1\n * parent 表示一棵有效的树\n * s 仅由小写英文字母组成\n\"\"\"\nclass Solution:\n def countPalindromePaths(self, parent: List[int], s: str) -> int:\n ", "prompt_sft": "给你一棵 树(即,一个连通、无向且无环的图),根 节点为 0 ,由编号从 0 到 n - 1 的 n 个节点组成。这棵树用一个长度为 n 、下标从 0 开始的数组 parent 表示,其中 parent[i] 为节点 i 的父节点,由于节点 0 为根节点,所以 parent[0] == -1 。\n\n另给你一个长度为 n 的字符串 s ,其中 s[i] 是分配给 i 和 parent[i] 之间的边的字符。s[0] 可以忽略。\n\n找出满足 u < v ,且从 u 到 v 的路径上分配的字符可以 重新排列 形成 回文 的所有节点对 (u, v) ,并返回节点对的数目。\n\n如果一个字符串正着读和反着读都相同,那么这个字符串就是一个 回文 。\n\n示例 1:\n\n[https://assets.leetcode.com/uploads/2023/07/15/treedrawio-8drawio.png]\n\n输入:parent = [-1,0,0,1,1,2], s = \"acaabc\"\n输出:8\n解释:符合题目要求的节点对分别是:\n- (0,1)、(0,2)、(1,3)、(1,4) 和 (2,5) ,路径上只有一个字符,满足回文定义。\n- (2,3),路径上字符形成的字符串是 \"aca\" ,满足回文定义。\n- (1,5),路径上字符形成的字符串是 \"cac\" ,满足回文定义。\n- (3,5),路径上字符形成的字符串是 \"acac\" ,可以重排形成回文 \"acca\" 。\n\n示例 2:\n\n输入:parent = [-1,0,0,0,0], s = \"aaaaa\"\n输出:10\n解释:任何满足 u < v 的节点对 (u,v) 都符合题目要求。\n\n\n提示:\n\n * n == parent.length == s.length\n * 1 <= n <= 105\n * 对于所有 i >= 1 ,0 <= parent[i] <= n - 1 均成立\n * parent[0] == -1\n * parent 表示一棵有效的树\n * s 仅由小写英文字母组成\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def countPalindromePaths(self, parent: List[int], s: str) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"parent\": [-1,0,0,1,1,2], \"s\": \"acaabc\" }\nassert my_solution.countPalindromePaths(**test_input) == 8\n\ntest_input = { \"parent\": [-1,0,0,0,0], \"s\": \"aaaaa\" }\nassert my_solution.countPalindromePaths(**test_input) == 10\n\ntest_input = { \"parent\": [-1,0], \"s\": \"pi\" }\nassert my_solution.countPalindromePaths(**test_input) == 1\n\ntest_input = { \"parent\": [-1,5,0,5,5,2], \"s\": \"xsbcqq\" }\nassert my_solution.countPalindromePaths(**test_input) == 7\n\ntest_input = { \"parent\": [-1,6,8,5,0,4,2,0,4], \"s\": \"tiaiaivea\" }\nassert my_solution.countPalindromePaths(**test_input) == 20\n\ntest_input = { \"parent\": [-1,0,0,0,1,3,7,2], \"s\": \"pxxgtgpp\" }\nassert my_solution.countPalindromePaths(**test_input) == 18\n\ntest_input = { \"parent\": [-1,0,1,4,1,0], \"s\": \"hfhmmf\" }\nassert my_solution.countPalindromePaths(**test_input) == 12\n\ntest_input = { \"parent\": [-1,0,1], \"s\": \"cri\" }\nassert my_solution.countPalindromePaths(**test_input) == 2\n\ntest_input = { \"parent\": [-1,0,0,5,7,0,0,1,2,0], \"s\": \"snlzlzngna\" }\nassert my_solution.countPalindromePaths(**test_input) == 19\n\ntest_input = { \"parent\": [-1,0,0], \"s\": \"sat\" }\nassert my_solution.countPalindromePaths(**test_input) == 2\n\ntest_input = { \"parent\": [-1,0], \"s\": \"ko\" }\nassert my_solution.countPalindromePaths(**test_input) == 1\n\ntest_input = { \"parent\": [-1,0,6,4,1,6,3,1], \"s\": \"jibwrfoi\" }\nassert my_solution.countPalindromePaths(**test_input) == 8\n\ntest_input = { \"parent\": [-1,4,0,4,6,0,5,5], \"s\": \"bhrlorou\" }\nassert my_solution.countPalindromePaths(**test_input) == 18\n\ntest_input = { \"parent\": [-1,4,4,6,0,7,1,1], \"s\": \"boqvndoo\" }\nassert my_solution.countPalindromePaths(**test_input) == 18\n\ntest_input = { \"parent\": [-1,2,0,1,0], \"s\": \"eixnx\" }\nassert my_solution.countPalindromePaths(**test_input) == 6\n\ntest_input = { \"parent\": [-1,5,0,2,2,3], \"s\": \"jwlllw\" }\nassert my_solution.countPalindromePaths(**test_input) == 14\n\ntest_input = { \"parent\": [-1,2,6,2,5,2,7,0], \"s\": \"pipfippl\" }\nassert my_solution.countPalindromePaths(**test_input) == 15\n\ntest_input = { \"parent\": [-1,6,0,6,5,6,2,6,5,6], \"s\": \"zwrdhnhwtf\" }\nassert my_solution.countPalindromePaths(**test_input) == 11\n\ntest_input = { \"parent\": [-1,4,1,1,5,0], \"s\": \"gndfnj\" }\nassert my_solution.countPalindromePaths(**test_input) == 9\n\ntest_input = { \"parent\": [-1,0,0,0,1], \"s\": \"crwkr\" }\nassert my_solution.countPalindromePaths(**test_input) == 7\n\ntest_input = { \"parent\": [-1,4,4,4,0,2,0], \"s\": \"wwwwewd\" }\nassert my_solution.countPalindromePaths(**test_input) == 13\n\ntest_input = { \"parent\": [-1,2,0], \"s\": \"mwz\" }\nassert my_solution.countPalindromePaths(**test_input) == 2\n\ntest_input = { \"parent\": [-1,0,1,6,5,0,1,1,1,0], \"s\": \"mqgmjzrwuq\" }\nassert my_solution.countPalindromePaths(**test_input) == 14\n\ntest_input = { \"parent\": [-1,2,3,0,3,3,3,3], \"s\": \"bnievjov\" }\nassert my_solution.countPalindromePaths(**test_input) == 8\n\ntest_input = { \"parent\": [-1,0,0], \"s\": \"kyr\" }\nassert my_solution.countPalindromePaths(**test_input) == 2\n\ntest_input = { \"parent\": [-1,0,5,1,2,3,2,3,9,4], \"s\": \"xukzwzsnww\" }\nassert my_solution.countPalindromePaths(**test_input) == 18\n\ntest_input = { \"parent\": [-1,6,0,1,5,0,2,2,6,0], \"s\": \"snlpzocqpt\" }\nassert my_solution.countPalindromePaths(**test_input) == 10\n\ntest_input = { \"parent\": [-1,3,0,5,5,2], \"s\": \"pxlxpl\" }\nassert my_solution.countPalindromePaths(**test_input) == 12\n\ntest_input = { \"parent\": [-1,5,5,5,5,0], \"s\": \"ketewj\" }\nassert my_solution.countPalindromePaths(**test_input) == 6\n\ntest_input = { \"parent\": [-1,0,4,0,0], \"s\": \"zrrqq\" }\nassert my_solution.countPalindromePaths(**test_input) == 7\n\ntest_input = { \"parent\": [-1,0,0], \"s\": \"qlw\" }\nassert my_solution.countPalindromePaths(**test_input) == 2\n\ntest_input = { \"parent\": [-1,0,0], \"s\": \"bds\" }\nassert my_solution.countPalindromePaths(**test_input) == 2\n\ntest_input = { \"parent\": [-1,2,6,6,0,4,4,2], \"s\": \"odggsrsp\" }\nassert my_solution.countPalindromePaths(**test_input) == 13\n\ntest_input = { \"parent\": [-1,0,1], \"s\": \"ldk\" }\nassert my_solution.countPalindromePaths(**test_input) == 2\n\ntest_input = { \"parent\": [-1,0,7,0,6,2,3,3,3], \"s\": \"elllffflv\" }\nassert my_solution.countPalindromePaths(**test_input) == 28\n\ntest_input = { \"parent\": [-1,4,4,0,0], \"s\": \"ntzhc\" }\nassert my_solution.countPalindromePaths(**test_input) == 4\n\ntest_input = { \"parent\": [-1,5,4,1,1,0,4], \"s\": \"gmcmavf\" }\nassert my_solution.countPalindromePaths(**test_input) == 8\n\ntest_input = { \"parent\": [-1,0,0,4,0], \"s\": \"aogkg\" }\nassert my_solution.countPalindromePaths(**test_input) == 6\n\ntest_input = { \"parent\": [-1,2,0], \"s\": \"xmt\" }\nassert my_solution.countPalindromePaths(**test_input) == 2\n\ntest_input = { \"parent\": [-1,2,0], \"s\": \"dff\" }\nassert my_solution.countPalindromePaths(**test_input) == 3\n\ntest_input = { \"parent\": [-1,0,1,1], \"s\": \"lsvw\" }\nassert my_solution.countPalindromePaths(**test_input) == 3\n\ntest_input = { \"parent\": [-1,0,0], \"s\": \"ovi\" }\nassert my_solution.countPalindromePaths(**test_input) == 2\n\ntest_input = { \"parent\": [-1,6,0,5,2,2,0,3], \"s\": \"lpnfznpf\" }\nassert my_solution.countPalindromePaths(**test_input) == 19\n\ntest_input = { \"parent\": [-1,7,5,5,0,0,2,2], \"s\": \"hqitxxwi\" }\nassert my_solution.countPalindromePaths(**test_input) == 16\n\ntest_input = { \"parent\": [-1,2,0], \"s\": \"pyw\" }\nassert my_solution.countPalindromePaths(**test_input) == 2\n\ntest_input = { \"parent\": [-1,0,0,0], \"s\": \"ybfa\" }\nassert my_solution.countPalindromePaths(**test_input) == 3\n\ntest_input = { \"parent\": [-1,3,6,6,6,0,0,4], \"s\": \"ulicllkc\" }\nassert my_solution.countPalindromePaths(**test_input) == 11\n\ntest_input = { \"parent\": [-1,3,1,0], \"s\": \"ukne\" }\nassert my_solution.countPalindromePaths(**test_input) == 3\n\ntest_input = { \"parent\": [-1,2,0,1,0,0], \"s\": \"rhlxdd\" }\nassert my_solution.countPalindromePaths(**test_input) == 6\n\ntest_input = { \"parent\": [-1,4,5,0,2,0], \"s\": \"zenbnb\" }\nassert my_solution.countPalindromePaths(**test_input) == 12\n\ntest_input = { \"parent\": [-1,0,5,4,5,1,3,9,7,4], \"s\": \"jigognjnlb\" }\nassert my_solution.countPalindromePaths(**test_input) == 12\n\ntest_input = { \"parent\": [-1,4,4,6,3,0,5,3,6], \"s\": \"imrcmdkew\" }\nassert my_solution.countPalindromePaths(**test_input) == 11\n\ntest_input = { \"parent\": [-1,4,4,0,6,4,0,0], \"s\": \"dqpipiyz\" }\nassert my_solution.countPalindromePaths(**test_input) == 9\n\ntest_input = { \"parent\": [-1,0,0], \"s\": \"mgm\" }\nassert my_solution.countPalindromePaths(**test_input) == 2\n\ntest_input = { \"parent\": [-1,0,4,0,1], \"s\": \"pzlob\" }\nassert my_solution.countPalindromePaths(**test_input) == 4\n\ntest_input = { \"parent\": [-1,8,0,8,8,3,4,4,0,6], \"s\": \"vvbvyovyvy\" }\nassert my_solution.countPalindromePaths(**test_input) == 30\n\ntest_input = { \"parent\": [-1,0,4,0,5,1,1], \"s\": \"dvrvpea\" }\nassert my_solution.countPalindromePaths(**test_input) == 9\n\ntest_input = { \"parent\": [-1,0,1], \"s\": \"jnx\" }\nassert my_solution.countPalindromePaths(**test_input) == 2\n\ntest_input = { \"parent\": [-1,0,1,2], \"s\": \"wxjj\" }\nassert my_solution.countPalindromePaths(**test_input) == 5\n\ntest_input = { \"parent\": [-1,3,3,0,1,2,1], \"s\": \"erorchx\" }\nassert my_solution.countPalindromePaths(**test_input) == 9\n\ntest_input = { \"parent\": [-1,0,4,1,1,4,3], \"s\": \"ywzwzcw\" }\nassert my_solution.countPalindromePaths(**test_input) == 14\n\ntest_input = { \"parent\": [-1,4,6,2,3,3,0], \"s\": \"bititzq\" }\nassert my_solution.countPalindromePaths(**test_input) == 10\n\ntest_input = { \"parent\": [-1,2,0], \"s\": \"uup\" }\nassert my_solution.countPalindromePaths(**test_input) == 2\n\ntest_input = { \"parent\": [-1,2,3,0,0], \"s\": \"siiou\" }\nassert my_solution.countPalindromePaths(**test_input) == 6\n\ntest_input = { \"parent\": [-1,2,0,2,0], \"s\": \"dilfs\" }\nassert my_solution.countPalindromePaths(**test_input) == 4\n\ntest_input = { \"parent\": [-1,3,7,0,1,0,2,3,0], \"s\": \"wqojvjoqq\" }\nassert my_solution.countPalindromePaths(**test_input) == 22\n\ntest_input = { \"parent\": [-1,0], \"s\": \"hi\" }\nassert my_solution.countPalindromePaths(**test_input) == 1\n\ntest_input = { \"parent\": [-1,3,1,4,0,6,3,1], \"s\": \"fwvwwqqw\" }\nassert my_solution.countPalindromePaths(**test_input) == 21\n\ntest_input = { \"parent\": [-1,0,4,2,1,1,1], \"s\": \"hkmmkmk\" }\nassert my_solution.countPalindromePaths(**test_input) == 16\n\ntest_input = { \"parent\": [-1,4,3,1,0], \"s\": \"bzeez\" }\nassert my_solution.countPalindromePaths(**test_input) == 9\n\ntest_input = { \"parent\": [-1,3,3,0], \"s\": \"zyuj\" }\nassert my_solution.countPalindromePaths(**test_input) == 3\n\ntest_input = { \"parent\": [-1,0,1,4,6,2,2], \"s\": \"tlcpcll\" }\nassert my_solution.countPalindromePaths(**test_input) == 13\n\ntest_input = { \"parent\": [-1,2,0], \"s\": \"vjw\" }\nassert my_solution.countPalindromePaths(**test_input) == 2\n\ntest_input = { \"parent\": [-1,0], \"s\": \"nz\" }\nassert my_solution.countPalindromePaths(**test_input) == 1\n\ntest_input = { \"parent\": [-1,0,0], \"s\": \"iot\" }\nassert my_solution.countPalindromePaths(**test_input) == 2\n\ntest_input = { \"parent\": [-1,2,8,8,3,1,2,0,0], \"s\": \"rlurrluxm\" }\nassert my_solution.countPalindromePaths(**test_input) == 19\n\ntest_input = { \"parent\": [-1,5,0,0,0,4], \"s\": \"zxrddx\" }\nassert my_solution.countPalindromePaths(**test_input) == 10\n\ntest_input = { \"parent\": [-1,0,1,2], \"s\": \"tffc\" }\nassert my_solution.countPalindromePaths(**test_input) == 5\n\ntest_input = { \"parent\": [-1,5,3,0,3,0], \"s\": \"ltdewr\" }\nassert my_solution.countPalindromePaths(**test_input) == 5\n\ntest_input = { \"parent\": [-1,0,4,5,0,1], \"s\": \"gjwwjv\" }\nassert my_solution.countPalindromePaths(**test_input) == 9\n\ntest_input = { \"parent\": [-1,7,7,0,8,2,2,4,3,8], \"s\": \"cnssgsoogy\" }\nassert my_solution.countPalindromePaths(**test_input) == 20\n\ntest_input = { \"parent\": [-1,7,1,6,0,0,7,0], \"s\": \"zaceoxax\" }\nassert my_solution.countPalindromePaths(**test_input) == 13\n\ntest_input = { \"parent\": [-1,0,1,0,3,0], \"s\": \"zrvyyc\" }\nassert my_solution.countPalindromePaths(**test_input) == 8\n\ntest_input = { \"parent\": [-1,4,9,0,3,3,7,4,2,0], \"s\": \"qxixxxxxix\" }\nassert my_solution.countPalindromePaths(**test_input) == 41\n\ntest_input = { \"parent\": [-1,2,0,5,5,2,5], \"s\": \"hoptvuu\" }\nassert my_solution.countPalindromePaths(**test_input) == 9\n\ntest_input = { \"parent\": [-1,7,3,0,3,1,0,3], \"s\": \"kopflpao\" }\nassert my_solution.countPalindromePaths(**test_input) == 13\n\ntest_input = { \"parent\": [-1,0,1,6,1,1,1], \"s\": \"bhhslhl\" }\nassert my_solution.countPalindromePaths(**test_input) == 11\n\ntest_input = { \"parent\": [-1,0,0,1,2], \"s\": \"khhch\" }\nassert my_solution.countPalindromePaths(**test_input) == 8\n\ntest_input = { \"parent\": [-1,0,3,0], \"s\": \"koss\" }\nassert my_solution.countPalindromePaths(**test_input) == 5\n\ntest_input = { \"parent\": [-1,3,4,4,0], \"s\": \"owzoq\" }\nassert my_solution.countPalindromePaths(**test_input) == 4\n\ntest_input = { \"parent\": [-1,2,0,1,1], \"s\": \"zqqww\" }\nassert my_solution.countPalindromePaths(**test_input) == 8\n\ntest_input = { \"parent\": [-1,0,1,1,1,2,2], \"s\": \"lacccdb\" }\nassert my_solution.countPalindromePaths(**test_input) == 13\n\ntest_input = { \"parent\": [-1,4,3,4,6,6,7,0,6], \"s\": \"sjoooorrm\" }\nassert my_solution.countPalindromePaths(**test_input) == 24\n\ntest_input = { \"parent\": [-1,7,4,2,0,6,2,3,7], \"s\": \"guqyxxtau\" }\nassert my_solution.countPalindromePaths(**test_input) == 9\n\ntest_input = { \"parent\": [-1,4,4,0,0], \"s\": \"scicc\" }\nassert my_solution.countPalindromePaths(**test_input) == 8\n\ntest_input = { \"parent\": [-1,5,8,6,3,0,2,3,1], \"s\": \"naphhahhp\" }\nassert my_solution.countPalindromePaths(**test_input) == 29\n\ntest_input = { \"parent\": [-1,3,8,8,5,0,4,0,0,2], \"s\": \"ciiyggofij\" }\nassert my_solution.countPalindromePaths(**test_input) == 23\n\ntest_input = { \"parent\": [-1,2,0,2,2,3,7,8,4,2], \"s\": \"stthtthddt\" }\nassert my_solution.countPalindromePaths(**test_input) == 34\n\ntest_input = { \"parent\": [-1,2,0,7,3,7,4,0], \"s\": \"mjjsjdsj\" }\nassert my_solution.countPalindromePaths(**test_input) == 18\n\ntest_input = { \"parent\": [-1,0], \"s\": \"ey\" }\nassert my_solution.countPalindromePaths(**test_input) == 1", "start_time": 1690079400} +{"task_id": "biweekly-contest-109-check-if-array-is-good", "url": "https://leetcode.com/problems/check-if-array-is-good", "title": "check-if-array-is-good", "meta": {"questionId": "2892", "questionFrontendId": "2784", "title": "Check if Array is Good", "titleSlug": "check-if-array-is-good", "isPaidOnly": false, "difficulty": "Easy", "likes": 233, "dislikes": 43, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个整数数组 nums ,如果它是数组 base[n] 的一个排列,我们称它是个 好 数组。\n\nbase[n] = [1, 2, ..., n - 1, n, n] (换句话说,它是一个长度为 n + 1 且包含 1 到 n - 1 恰好各一次,包含 n  两次的一个数组)。比方说,base[1] = [1, 1] ,base[3] = [1, 2, 3, 3] 。\n\n如果数组是一个好数组,请你返回 true ,否则返回 false 。\n\n注意:数组的排列是这些数字按任意顺序排布后重新得到的数组。\n\n示例 1:\n\n输入:nums = [2, 1, 3]\n输出:false\n解释:因为数组的最大元素是 3 ,唯一可以构成这个数组的 base[n] 对应的 n = 3 。但是 base[3] 有 4 个元素,但数组 nums 只有 3 个元素,所以无法得到 base[3] = [1, 2, 3, 3] 的排列,所以答案为 false 。\n\n示例 2:\n\n输入:nums = [1, 3, 3, 2]\n输出:true\n解释:因为数组的最大元素是 3 ,唯一可以构成这个数组的 base[n] 对应的 n = 3 ,可以看出数组是 base[3] = [1, 2, 3, 3] 的一个排列(交换 nums 中第二个和第四个元素)。所以答案为 true 。\n\n示例 3:\n\n输入:nums = [1, 1]\n输出:true\n解释:因为数组的最大元素是 1 ,唯一可以构成这个数组的 base[n] 对应的 n = 1,可以看出数组是 base[1] = [1, 1] 的一个排列。所以答案为 true 。\n\n示例 4:\n\n输入:nums = [3, 4, 4, 1, 2, 1]\n输出:false\n解释:因为数组的最大元素是 4 ,唯一可以构成这个数组的 base[n] 对应的 n = 4 。但是 base[n] 有 5 个元素而 nums 有 6 个元素。所以答案为 false 。\n\n\n提示:\n\n * 1 <= nums.length <= 100\n * 1 <= num[i] <= 200\n\"\"\"\nclass Solution:\n def isGood(self, nums: List[int]) -> bool:\n ", "prompt_sft": "给你一个整数数组 nums ,如果它是数组 base[n] 的一个排列,我们称它是个 好 数组。\n\nbase[n] = [1, 2, ..., n - 1, n, n] (换句话说,它是一个长度为 n + 1 且包含 1 到 n - 1 恰好各一次,包含 n  两次的一个数组)。比方说,base[1] = [1, 1] ,base[3] = [1, 2, 3, 3] 。\n\n如果数组是一个好数组,请你返回 true ,否则返回 false 。\n\n注意:数组的排列是这些数字按任意顺序排布后重新得到的数组。\n\n示例 1:\n\n输入:nums = [2, 1, 3]\n输出:false\n解释:因为数组的最大元素是 3 ,唯一可以构成这个数组的 base[n] 对应的 n = 3 。但是 base[3] 有 4 个元素,但数组 nums 只有 3 个元素,所以无法得到 base[3] = [1, 2, 3, 3] 的排列,所以答案为 false 。\n\n示例 2:\n\n输入:nums = [1, 3, 3, 2]\n输出:true\n解释:因为数组的最大元素是 3 ,唯一可以构成这个数组的 base[n] 对应的 n = 3 ,可以看出数组是 base[3] = [1, 2, 3, 3] 的一个排列(交换 nums 中第二个和第四个元素)。所以答案为 true 。\n\n示例 3:\n\n输入:nums = [1, 1]\n输出:true\n解释:因为数组的最大元素是 1 ,唯一可以构成这个数组的 base[n] 对应的 n = 1,可以看出数组是 base[1] = [1, 1] 的一个排列。所以答案为 true 。\n\n示例 4:\n\n输入:nums = [3, 4, 4, 1, 2, 1]\n输出:false\n解释:因为数组的最大元素是 4 ,唯一可以构成这个数组的 base[n] 对应的 n = 4 。但是 base[n] 有 5 个元素而 nums 有 6 个元素。所以答案为 false 。\n\n\n提示:\n\n * 1 <= nums.length <= 100\n * 1 <= num[i] <= 200\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def isGood(self, nums: List[int]) -> bool:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1, 3, 3, 2] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [2, 1, 3] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [1, 1] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [1, 2, 2] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [3, 4, 4, 1, 2, 1] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [2, 2, 1] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [1] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [2] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [3] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [3, 3, 1, 2] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [1, 3, 4, 4, 2] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [4] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [1, 4, 2, 4, 3] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [5] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [4, 4, 1, 2, 3] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [6] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [4, 4, 2, 3, 1] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [8] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [9] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [5, 5, 1, 3, 2, 4] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [1, 5, 3, 6, 6, 4, 2] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [5, 4, 6, 6, 3, 2, 1] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [10] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [6, 3, 6, 4, 2, 1, 5] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [6, 3, 6, 5, 1, 2, 4] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [12] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [7, 2, 5, 7, 3, 6, 1, 4] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [1, 2, 8, 8, 6, 5, 4, 3, 7] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [1, 8, 4, 8, 2, 7, 6, 3, 5] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [13] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [14] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [2, 8, 6, 1, 7, 5, 3, 4, 8] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [4, 1, 3, 2, 8, 5, 8, 6, 7] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [15] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [7, 2, 1, 5, 6, 8, 8, 4, 3] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [82] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [1, 8] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [8, 6, 2, 5, 7, 4, 1, 8, 3] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [4, 6, 1, 9, 8, 9, 5, 7, 3, 2] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [1, 13] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [2, 3] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [9, 5, 8, 9, 6, 1, 2, 7, 4, 3] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [1, 2, 10, 9, 10, 5, 6, 4, 8, 7, 3] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [1, 9, 2, 6, 5, 4, 7, 10, 3, 10, 8] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [1, 10, 7, 8, 10, 4, 6, 3, 5, 2, 9] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [8, 2, 1, 4, 3, 10, 9, 5, 10, 7, 6] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [10, 9, 5, 3, 6, 4, 2, 10, 8, 7, 1] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [2, 9] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [1, 4, 5, 10, 11, 2, 9, 7, 6, 11, 3, 8] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [2, 11] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [11, 5, 9, 10, 3, 11, 1, 2, 8, 4, 7, 6] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [11, 9, 8, 1, 12, 4, 2, 15, 16, 10, 13, 6, 3, 16, 7, 5, 14] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [11, 16, 9, 5, 14, 13, 4, 1, 3, 16, 15, 8, 10, 7, 12, 2, 6] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [2, 12] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [17, 1, 18, 11, 9, 4, 7, 6, 3, 21, 16, 14, 10, 8, 20, 21, 5, 2, 12, 19, 15, 13] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [3, 1] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [20, 13, 7, 10, 16, 12, 19, 2, 21, 17, 3, 11, 5, 15, 21, 1, 18, 6, 8, 14, 9, 4] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [8, 19, 16, 17, 20, 15, 11, 4, 22, 3, 13, 10, 1, 18, 9, 12, 22, 7, 6, 2, 5, 21, 14] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [22, 1, 17, 13, 8, 22, 9, 5, 21, 6, 14, 12, 10, 11, 2, 18, 4, 7, 19, 20, 3, 15, 16] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [21, 15, 16, 13, 3, 4, 11, 22, 7, 14, 20, 10, 18, 17, 6, 8, 9, 1, 19, 5, 2, 12, 23, 24, 24] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [22, 24, 24, 12, 17, 15, 14, 16, 8, 11, 23, 5, 2, 10, 6, 21, 9, 13, 3, 20, 19, 7, 4, 18, 1] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [3, 2] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [6, 16, 26, 9, 4, 24, 12, 26, 22, 3, 11, 23, 15, 2, 17, 5, 1, 21, 14, 19, 18, 20, 13, 25, 8, 7, 10] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [29, 24, 5, 6, 4, 25, 9, 8, 21, 13, 27, 7, 20, 18, 3, 15, 23, 28, 29, 19, 17, 10, 22, 26, 1, 11, 12, 14, 16, 2] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [25, 21, 6, 10, 20, 15, 16, 26, 7, 3, 30, 1, 12, 29, 11, 30, 14, 19, 2, 28, 23, 9, 8, 24, 17, 5, 4, 27, 22, 18, 13] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [3, 11] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [2, 25, 20, 30, 4, 6, 1, 29, 15, 11, 10, 19, 14, 12, 32, 3, 21, 27, 16, 17, 28, 13, 5, 32, 8, 24, 22, 7, 31, 23, 18, 26, 9] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [4, 10] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [4, 12] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [5, 9] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [5, 12] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [5, 13] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [4, 29, 5, 24, 19, 1, 8, 31, 18, 21, 9, 28, 32, 27, 10, 17, 22, 2, 11, 15, 13, 23, 6, 16, 7, 30, 12, 33, 14, 25, 33, 26, 3, 20] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [6, 1] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [30, 32, 1, 35, 19, 34, 4, 23, 18, 6, 11, 8, 22, 33, 31, 16, 17, 20, 24, 10, 21, 7, 14, 15, 29, 9, 12, 2, 36, 3, 26, 36, 5, 13, 25, 27, 28] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [5, 34, 42, 17, 9, 44, 40, 24, 38, 21, 30, 14, 39, 11, 18, 36, 4, 43, 12, 32, 2, 6, 45, 46, 37, 47, 8, 3, 26, 1, 31, 28, 16, 20, 22, 35, 25, 15, 10, 29, 7, 27, 19, 33, 41, 47, 23, 13] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [6, 7] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [5, 41, 8, 2, 32, 24, 9, 44, 27, 6, 22, 36, 14, 21, 43, 28, 45, 37, 17, 18, 20, 26, 3, 12, 10, 33, 30, 13, 29, 38, 4, 47, 46, 15, 25, 11, 1, 19, 47, 16, 39, 31, 40, 34, 23, 7, 42, 35] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [6, 10] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [6, 12] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [6, 15] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [7, 9] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [8, 4] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [8, 6] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [26, 35, 9, 3, 46, 33, 13, 8, 47, 27, 17, 40, 15, 20, 37, 12, 16, 44, 34, 2, 14, 30, 1, 29, 10, 11, 25, 18, 43, 42, 6, 5, 47, 38, 41, 32, 24, 31, 7, 4, 45, 19, 39, 22, 28, 36, 21, 23] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [8, 9] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [8, 10] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [8, 13] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [32, 39, 25, 49, 6, 48, 9, 7, 34, 3, 8, 26, 14, 27, 43, 30, 1, 21, 36, 10, 31, 38, 40, 12, 2, 46, 20, 15, 11, 24, 22, 28, 33, 4, 19, 18, 44, 41, 35, 29, 16, 37, 45, 47, 49, 23, 42, 13, 5, 17] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [9, 7] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [18, 35, 44, 41, 8, 33, 28, 9, 3, 14, 43, 56, 6, 10, 25, 53, 61, 22, 17, 23, 32, 50, 31, 13, 1, 29, 45, 34, 30, 48, 36, 58, 46, 15, 4, 7, 52, 60, 16, 12, 54, 19, 24, 40, 26, 55, 49, 42, 21, 38, 2, 20, 57, 61, 5, 37, 47, 27, 39, 11, 51, 59] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [9, 9] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [10, 4] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [10, 11] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [11, 1] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [60, 62, 16, 59, 8, 49, 51, 41, 42, 40, 46, 3, 10, 13, 53, 2, 63, 54, 32, 33, 31, 14, 12, 15, 1, 66, 61, 18, 52, 4, 55, 11, 26, 28, 47, 21, 25, 43, 65, 58, 45, 50, 17, 64, 23, 22, 30, 9, 38, 19, 24, 44, 37, 39, 48, 20, 35, 36, 27, 34, 56, 57, 29, 5, 7, 6, 66] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [46, 9, 21, 14, 24, 15, 6, 58, 22, 40, 63, 39, 49, 65, 30, 5, 43, 36, 29, 55, 67, 45, 61, 35, 67, 56, 16, 23, 50, 17, 19, 13, 26, 66, 47, 59, 2, 51, 27, 28, 31, 1, 44, 42, 53, 57, 11, 25, 4, 54, 37, 20, 48, 52, 41, 32, 10, 7, 64, 34, 60, 12, 33, 38, 3, 18, 62, 8] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [11, 5] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [57, 40, 35, 55, 42, 24, 43, 29, 30, 59, 21, 52, 67, 72, 32, 78, 13, 51, 36, 48, 74, 64, 69, 65, 9, 4, 37, 31, 6, 27, 7, 2, 38, 61, 15, 19, 71, 49, 44, 47, 46, 54, 76, 26, 63, 17, 22, 3, 16, 12, 18, 41, 25, 62, 8, 10, 23, 50, 56, 11, 20, 5, 28, 77, 66, 53, 14, 33, 68, 34, 73, 45, 1, 78, 39, 70, 75, 60, 58] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [14, 38, 18, 10, 21, 9, 67, 68, 23, 19, 80, 13, 74, 75, 32, 55, 65, 45, 5, 28, 43, 8, 17, 42, 40, 44, 31, 1, 7, 25, 6, 47, 27, 50, 4, 76, 63, 52, 71, 34, 83, 56, 77, 81, 16, 12, 60, 79, 46, 41, 24, 35, 33, 2, 49, 70, 78, 36, 48, 69, 26, 66, 37, 72, 61, 30, 22, 58, 20, 39, 82, 64, 73, 59, 57, 3, 51, 29, 83, 53, 15, 54, 11, 62] }\nassert my_solution.isGood(**test_input) == True", "start_time": 1690036200} +{"task_id": "biweekly-contest-109-sort-vowels-in-a-string", "url": "https://leetcode.com/problems/sort-vowels-in-a-string", "title": "sort-vowels-in-a-string", "meta": {"questionId": "2887", "questionFrontendId": "2785", "title": "Sort Vowels in a String", "titleSlug": "sort-vowels-in-a-string", "isPaidOnly": false, "difficulty": "Medium", "likes": 883, "dislikes": 50, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0 开始的字符串 s ,将 s 中的元素重新 排列 得到新的字符串 t ,它满足:\n\n * 所有辅音字母都在原来的位置上。更正式的,如果满足 0 <= i < s.length 的下标 i 处的 s[i] 是个辅音字母,那么 t[i] = s[i] 。\n * 元音字母都必须以他们的 ASCII 值按 非递减 顺序排列。更正式的,对于满足 0 <= i < j < s.length 的下标 i 和 j  ,如果 s[i] 和 s[j] 都是元音字母,那么 t[i] 的 ASCII 值不能大于 t[j] 的 ASCII 值。\n\n请你返回结果字母串。\n\n元音字母为 'a' ,'e' ,'i' ,'o' 和 'u' ,它们可能是小写字母也可能是大写字母,辅音字母是除了这 5 个字母以外的所有字母。\n\n示例 1:\n\n输入:s = \"lEetcOde\"\n输出:\"lEOtcede\"\n解释:'E' ,'O' 和 'e' 是 s 中的元音字母,'l' ,'t' ,'c' 和 'd' 是所有的辅音。将元音字母按照 ASCII 值排序,辅音字母留在原地。\n\n示例 2:\n\n输入:s = \"lYmpH\"\n输出:\"lYmpH\"\n解释:s 中没有元音字母(s 中都为辅音字母),所以我们返回 \"lYmpH\" 。\n\n\n提示:\n\n * 1 <= s.length <= 105\n * s 只包含英语字母表中的 大写 和 小写 字母。\n\"\"\"\nclass Solution:\n def sortVowels(self, s: str) -> str:\n ", "prompt_sft": "给你一个下标从 0 开始的字符串 s ,将 s 中的元素重新 排列 得到新的字符串 t ,它满足:\n\n * 所有辅音字母都在原来的位置上。更正式的,如果满足 0 <= i < s.length 的下标 i 处的 s[i] 是个辅音字母,那么 t[i] = s[i] 。\n * 元音字母都必须以他们的 ASCII 值按 非递减 顺序排列。更正式的,对于满足 0 <= i < j < s.length 的下标 i 和 j  ,如果 s[i] 和 s[j] 都是元音字母,那么 t[i] 的 ASCII 值不能大于 t[j] 的 ASCII 值。\n\n请你返回结果字母串。\n\n元音字母为 'a' ,'e' ,'i' ,'o' 和 'u' ,它们可能是小写字母也可能是大写字母,辅音字母是除了这 5 个字母以外的所有字母。\n\n示例 1:\n\n输入:s = \"lEetcOde\"\n输出:\"lEOtcede\"\n解释:'E' ,'O' 和 'e' 是 s 中的元音字母,'l' ,'t' ,'c' 和 'd' 是所有的辅音。将元音字母按照 ASCII 值排序,辅音字母留在原地。\n\n示例 2:\n\n输入:s = \"lYmpH\"\n输出:\"lYmpH\"\n解释:s 中没有元音字母(s 中都为辅音字母),所以我们返回 \"lYmpH\" 。\n\n\n提示:\n\n * 1 <= s.length <= 105\n * s 只包含英语字母表中的 大写 和 小写 字母。\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def sortVowels(self, s: str) -> str:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"s\": \"lEetcOde\" }\nassert my_solution.sortVowels(**test_input) == \"lEOtcede\"\n\ntest_input = { \"s\": \"lYmpH\" }\nassert my_solution.sortVowels(**test_input) == \"lYmpH\"\n\ntest_input = { \"s\": \"mDVD\" }\nassert my_solution.sortVowels(**test_input) == \"mDVD\"\n\ntest_input = { \"s\": \"xdX\" }\nassert my_solution.sortVowels(**test_input) == \"xdX\"\n\ntest_input = { \"s\": \"xdE\" }\nassert my_solution.sortVowels(**test_input) == \"xdE\"\n\ntest_input = { \"s\": \"RiQYo\" }\nassert my_solution.sortVowels(**test_input) == \"RiQYo\"\n\ntest_input = { \"s\": \"LQRamBOHfq\" }\nassert my_solution.sortVowels(**test_input) == \"LQROmBaHfq\"\n\ntest_input = { \"s\": \"UpjPbEnOj\" }\nassert my_solution.sortVowels(**test_input) == \"EpjPbOnUj\"\n\ntest_input = { \"s\": \"ziF\" }\nassert my_solution.sortVowels(**test_input) == \"ziF\"\n\ntest_input = { \"s\": \"WxkKdjhL\" }\nassert my_solution.sortVowels(**test_input) == \"WxkKdjhL\"\n\ntest_input = { \"s\": \"uZcPmqAd\" }\nassert my_solution.sortVowels(**test_input) == \"AZcPmqud\"\n\ntest_input = { \"s\": \"UjshJXjkjS\" }\nassert my_solution.sortVowels(**test_input) == \"UjshJXjkjS\"\n\ntest_input = { \"s\": \"nElwWTQHJ\" }\nassert my_solution.sortVowels(**test_input) == \"nElwWTQHJ\"\n\ntest_input = { \"s\": \"kwcJqvsgM\" }\nassert my_solution.sortVowels(**test_input) == \"kwcJqvsgM\"\n\ntest_input = { \"s\": \"z\" }\nassert my_solution.sortVowels(**test_input) == \"z\"\n\ntest_input = { \"s\": \"Pz\" }\nassert my_solution.sortVowels(**test_input) == \"Pz\"\n\ntest_input = { \"s\": \"T\" }\nassert my_solution.sortVowels(**test_input) == \"T\"\n\ntest_input = { \"s\": \"syRWvFi\" }\nassert my_solution.sortVowels(**test_input) == \"syRWvFi\"\n\ntest_input = { \"s\": \"G\" }\nassert my_solution.sortVowels(**test_input) == \"G\"\n\ntest_input = { \"s\": \"MuQYHVy\" }\nassert my_solution.sortVowels(**test_input) == \"MuQYHVy\"\n\ntest_input = { \"s\": \"gsc\" }\nassert my_solution.sortVowels(**test_input) == \"gsc\"\n\ntest_input = { \"s\": \"nynBd\" }\nassert my_solution.sortVowels(**test_input) == \"nynBd\"\n\ntest_input = { \"s\": \"qUSUCJeJZt\" }\nassert my_solution.sortVowels(**test_input) == \"qUSUCJeJZt\"\n\ntest_input = { \"s\": \"PoEvPD\" }\nassert my_solution.sortVowels(**test_input) == \"PEovPD\"\n\ntest_input = { \"s\": \"SrSuArHDvA\" }\nassert my_solution.sortVowels(**test_input) == \"SrSAArHDvu\"\n\ntest_input = { \"s\": \"zI\" }\nassert my_solution.sortVowels(**test_input) == \"zI\"\n\ntest_input = { \"s\": \"zpVZt\" }\nassert my_solution.sortVowels(**test_input) == \"zpVZt\"\n\ntest_input = { \"s\": \"dZVLG\" }\nassert my_solution.sortVowels(**test_input) == \"dZVLG\"\n\ntest_input = { \"s\": \"EHhQZGJBbp\" }\nassert my_solution.sortVowels(**test_input) == \"EHhQZGJBbp\"\n\ntest_input = { \"s\": \"aPLCji\" }\nassert my_solution.sortVowels(**test_input) == \"aPLCji\"\n\ntest_input = { \"s\": \"HSe\" }\nassert my_solution.sortVowels(**test_input) == \"HSe\"\n\ntest_input = { \"s\": \"HvDMPPU\" }\nassert my_solution.sortVowels(**test_input) == \"HvDMPPU\"\n\ntest_input = { \"s\": \"LYACGrvJLZ\" }\nassert my_solution.sortVowels(**test_input) == \"LYACGrvJLZ\"\n\ntest_input = { \"s\": \"RepLvwHFI\" }\nassert my_solution.sortVowels(**test_input) == \"RIpLvwHFe\"\n\ntest_input = { \"s\": \"vjbObvLfs\" }\nassert my_solution.sortVowels(**test_input) == \"vjbObvLfs\"\n\ntest_input = { \"s\": \"sKQwLo\" }\nassert my_solution.sortVowels(**test_input) == \"sKQwLo\"\n\ntest_input = { \"s\": \"PoqU\" }\nassert my_solution.sortVowels(**test_input) == \"PUqo\"\n\ntest_input = { \"s\": \"QgUxRvJTfH\" }\nassert my_solution.sortVowels(**test_input) == \"QgUxRvJTfH\"\n\ntest_input = { \"s\": \"wUMnwnblpu\" }\nassert my_solution.sortVowels(**test_input) == \"wUMnwnblpu\"\n\ntest_input = { \"s\": \"JpqXrPuMd\" }\nassert my_solution.sortVowels(**test_input) == \"JpqXrPuMd\"\n\ntest_input = { \"s\": \"wdtDPSQdKl\" }\nassert my_solution.sortVowels(**test_input) == \"wdtDPSQdKl\"\n\ntest_input = { \"s\": \"Dl\" }\nassert my_solution.sortVowels(**test_input) == \"Dl\"\n\ntest_input = { \"s\": \"v\" }\nassert my_solution.sortVowels(**test_input) == \"v\"\n\ntest_input = { \"s\": \"axRukCyOHm\" }\nassert my_solution.sortVowels(**test_input) == \"OxRakCyuHm\"\n\ntest_input = { \"s\": \"sQyytiAh\" }\nassert my_solution.sortVowels(**test_input) == \"sQyytAih\"\n\ntest_input = { \"s\": \"ieTwHeOR\" }\nassert my_solution.sortVowels(**test_input) == \"OeTwHeiR\"\n\ntest_input = { \"s\": \"LLxyZ\" }\nassert my_solution.sortVowels(**test_input) == \"LLxyZ\"\n\ntest_input = { \"s\": \"s\" }\nassert my_solution.sortVowels(**test_input) == \"s\"\n\ntest_input = { \"s\": \"oefu\" }\nassert my_solution.sortVowels(**test_input) == \"eofu\"\n\ntest_input = { \"s\": \"XV\" }\nassert my_solution.sortVowels(**test_input) == \"XV\"\n\ntest_input = { \"s\": \"VkfjDpSH\" }\nassert my_solution.sortVowels(**test_input) == \"VkfjDpSH\"\n\ntest_input = { \"s\": \"rg\" }\nassert my_solution.sortVowels(**test_input) == \"rg\"\n\ntest_input = { \"s\": \"ecV\" }\nassert my_solution.sortVowels(**test_input) == \"ecV\"\n\ntest_input = { \"s\": \"RUnxytMua\" }\nassert my_solution.sortVowels(**test_input) == \"RUnxytMau\"\n\ntest_input = { \"s\": \"gUyMeyzOZo\" }\nassert my_solution.sortVowels(**test_input) == \"gOyMUyzeZo\"\n\ntest_input = { \"s\": \"WEir\" }\nassert my_solution.sortVowels(**test_input) == \"WEir\"\n\ntest_input = { \"s\": \"zZWs\" }\nassert my_solution.sortVowels(**test_input) == \"zZWs\"\n\ntest_input = { \"s\": \"WULsDqIhp\" }\nassert my_solution.sortVowels(**test_input) == \"WILsDqUhp\"\n\ntest_input = { \"s\": \"pw\" }\nassert my_solution.sortVowels(**test_input) == \"pw\"\n\ntest_input = { \"s\": \"nOWxdSzo\" }\nassert my_solution.sortVowels(**test_input) == \"nOWxdSzo\"\n\ntest_input = { \"s\": \"NfK\" }\nassert my_solution.sortVowels(**test_input) == \"NfK\"\n\ntest_input = { \"s\": \"wXRFu\" }\nassert my_solution.sortVowels(**test_input) == \"wXRFu\"\n\ntest_input = { \"s\": \"XXtjDoinAD\" }\nassert my_solution.sortVowels(**test_input) == \"XXtjDAinoD\"\n\ntest_input = { \"s\": \"SGUzEv\" }\nassert my_solution.sortVowels(**test_input) == \"SGEzUv\"\n\ntest_input = { \"s\": \"RFOvEt\" }\nassert my_solution.sortVowels(**test_input) == \"RFEvOt\"\n\ntest_input = { \"s\": \"umQePdr\" }\nassert my_solution.sortVowels(**test_input) == \"emQuPdr\"\n\ntest_input = { \"s\": \"wRqZ\" }\nassert my_solution.sortVowels(**test_input) == \"wRqZ\"\n\ntest_input = { \"s\": \"blu\" }\nassert my_solution.sortVowels(**test_input) == \"blu\"\n\ntest_input = { \"s\": \"QeOQEatFaW\" }\nassert my_solution.sortVowels(**test_input) == \"QEOQaatFeW\"\n\ntest_input = { \"s\": \"jzWiXrYa\" }\nassert my_solution.sortVowels(**test_input) == \"jzWaXrYi\"\n\ntest_input = { \"s\": \"xs\" }\nassert my_solution.sortVowels(**test_input) == \"xs\"\n\ntest_input = { \"s\": \"DwROc\" }\nassert my_solution.sortVowels(**test_input) == \"DwROc\"\n\ntest_input = { \"s\": \"XMhLlJd\" }\nassert my_solution.sortVowels(**test_input) == \"XMhLlJd\"\n\ntest_input = { \"s\": \"uAmir\" }\nassert my_solution.sortVowels(**test_input) == \"Aimur\"\n\ntest_input = { \"s\": \"PTlFpeAI\" }\nassert my_solution.sortVowels(**test_input) == \"PTlFpAIe\"\n\ntest_input = { \"s\": \"XLYy\" }\nassert my_solution.sortVowels(**test_input) == \"XLYy\"\n\ntest_input = { \"s\": \"vA\" }\nassert my_solution.sortVowels(**test_input) == \"vA\"\n\ntest_input = { \"s\": \"y\" }\nassert my_solution.sortVowels(**test_input) == \"y\"\n\ntest_input = { \"s\": \"C\" }\nassert my_solution.sortVowels(**test_input) == \"C\"\n\ntest_input = { \"s\": \"wrnMlek\" }\nassert my_solution.sortVowels(**test_input) == \"wrnMlek\"\n\ntest_input = { \"s\": \"JWbfCfGgf\" }\nassert my_solution.sortVowels(**test_input) == \"JWbfCfGgf\"\n\ntest_input = { \"s\": \"OPGlnq\" }\nassert my_solution.sortVowels(**test_input) == \"OPGlnq\"\n\ntest_input = { \"s\": \"DeOMW\" }\nassert my_solution.sortVowels(**test_input) == \"DOeMW\"\n\ntest_input = { \"s\": \"xG\" }\nassert my_solution.sortVowels(**test_input) == \"xG\"\n\ntest_input = { \"s\": \"ZcaBhfkWC\" }\nassert my_solution.sortVowels(**test_input) == \"ZcaBhfkWC\"\n\ntest_input = { \"s\": \"pKa\" }\nassert my_solution.sortVowels(**test_input) == \"pKa\"\n\ntest_input = { \"s\": \"DXSEKrfJCe\" }\nassert my_solution.sortVowels(**test_input) == \"DXSEKrfJCe\"\n\ntest_input = { \"s\": \"xA\" }\nassert my_solution.sortVowels(**test_input) == \"xA\"\n\ntest_input = { \"s\": \"Jb\" }\nassert my_solution.sortVowels(**test_input) == \"Jb\"\n\ntest_input = { \"s\": \"SBQT\" }\nassert my_solution.sortVowels(**test_input) == \"SBQT\"\n\ntest_input = { \"s\": \"LWRfYb\" }\nassert my_solution.sortVowels(**test_input) == \"LWRfYb\"\n\ntest_input = { \"s\": \"tvLWAeGDFK\" }\nassert my_solution.sortVowels(**test_input) == \"tvLWAeGDFK\"\n\ntest_input = { \"s\": \"jFkj\" }\nassert my_solution.sortVowels(**test_input) == \"jFkj\"\n\ntest_input = { \"s\": \"zC\" }\nassert my_solution.sortVowels(**test_input) == \"zC\"\n\ntest_input = { \"s\": \"ikYSsAveh\" }\nassert my_solution.sortVowels(**test_input) == \"AkYSsevih\"\n\ntest_input = { \"s\": \"YXkS\" }\nassert my_solution.sortVowels(**test_input) == \"YXkS\"\n\ntest_input = { \"s\": \"SOEo\" }\nassert my_solution.sortVowels(**test_input) == \"SEOo\"\n\ntest_input = { \"s\": \"qoJx\" }\nassert my_solution.sortVowels(**test_input) == \"qoJx\"\n\ntest_input = { \"s\": \"qGJbgTQ\" }\nassert my_solution.sortVowels(**test_input) == \"qGJbgTQ\"\n\ntest_input = { \"s\": \"yiYYO\" }\nassert my_solution.sortVowels(**test_input) == \"yOYYi\"", "start_time": 1690036200} +{"task_id": "biweekly-contest-109-visit-array-positions-to-maximize-score", "url": "https://leetcode.com/problems/visit-array-positions-to-maximize-score", "title": "visit-array-positions-to-maximize-score", "meta": {"questionId": "2893", "questionFrontendId": "2786", "title": "Visit Array Positions to Maximize Score", "titleSlug": "visit-array-positions-to-maximize-score", "isPaidOnly": false, "difficulty": "Medium", "likes": 438, "dislikes": 21, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0 开始的整数数组 nums 和一个正整数 x 。\n\n你 一开始 在数组的位置 0 处,你可以按照下述规则访问数组中的其他位置:\n\n * 如果你当前在位置 i ,那么你可以移动到满足 i < j 的 任意 位置 j 。\n * 对于你访问的位置 i ,你可以获得分数 nums[i] 。\n * 如果你从位置 i 移动到位置 j 且 nums[i] 和 nums[j] 的 奇偶性 不同,那么你将失去分数 x 。\n\n请你返回你能得到的 最大 得分之和。\n\n注意 ,你一开始的分数为 nums[0] 。\n\n示例 1:\n\n输入:nums = [2,3,6,1,9,2], x = 5\n输出:13\n解释:我们可以按顺序访问数组中的位置:0 -> 2 -> 3 -> 4 。\n对应位置的值为 2 ,6 ,1 和 9 。因为 6 和 1 的奇偶性不同,所以下标从 2 -> 3 让你失去 x = 5 分。\n总得分为:2 + 6 + 1 + 9 - 5 = 13 。\n\n示例 2:\n\n输入:nums = [2,4,6,8], x = 3\n输出:20\n解释:数组中的所有元素奇偶性都一样,所以我们可以将每个元素都访问一次,而且不会失去任何分数。\n总得分为:2 + 4 + 6 + 8 = 20 。\n\n\n提示:\n\n * 2 <= nums.length <= 105\n * 1 <= nums[i], x <= 106\n\"\"\"\nclass Solution:\n def maxScore(self, nums: List[int], x: int) -> int:\n ", "prompt_sft": "给你一个下标从 0 开始的整数数组 nums 和一个正整数 x 。\n\n你 一开始 在数组的位置 0 处,你可以按照下述规则访问数组中的其他位置:\n\n * 如果你当前在位置 i ,那么你可以移动到满足 i < j 的 任意 位置 j 。\n * 对于你访问的位置 i ,你可以获得分数 nums[i] 。\n * 如果你从位置 i 移动到位置 j 且 nums[i] 和 nums[j] 的 奇偶性 不同,那么你将失去分数 x 。\n\n请你返回你能得到的 最大 得分之和。\n\n注意 ,你一开始的分数为 nums[0] 。\n\n示例 1:\n\n输入:nums = [2,3,6,1,9,2], x = 5\n输出:13\n解释:我们可以按顺序访问数组中的位置:0 -> 2 -> 3 -> 4 。\n对应位置的值为 2 ,6 ,1 和 9 。因为 6 和 1 的奇偶性不同,所以下标从 2 -> 3 让你失去 x = 5 分。\n总得分为:2 + 6 + 1 + 9 - 5 = 13 。\n\n示例 2:\n\n输入:nums = [2,4,6,8], x = 3\n输出:20\n解释:数组中的所有元素奇偶性都一样,所以我们可以将每个元素都访问一次,而且不会失去任何分数。\n总得分为:2 + 4 + 6 + 8 = 20 。\n\n\n提示:\n\n * 2 <= nums.length <= 105\n * 1 <= nums[i], x <= 106\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def maxScore(self, nums: List[int], x: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [2,3,6,1,9,2], \"x\": 5 }\nassert my_solution.maxScore(**test_input) == 13\n\ntest_input = { \"nums\": [2,4,6,8], \"x\": 3 }\nassert my_solution.maxScore(**test_input) == 20\n\ntest_input = { \"nums\": [38,92,23,30,25,96,6,71,78,77,33,23,71,48,87,77,53,28,6,20,90,83,42,21,64,95,84,29,22,21,33,36,53,51,85,25,80,56,71,69,5,21,4,84,28,16,65,7], \"x\": 52 }\nassert my_solution.maxScore(**test_input) == 1545\n\ntest_input = { \"nums\": [18,13,60,61,57,21,10,98,51,3,13,36,72,70,68,62,52,83,63,63,53,42,59,98,95,48,22,64,94,80,14,14], \"x\": 2 }\nassert my_solution.maxScore(**test_input) == 1633\n\ntest_input = { \"nums\": [90,87,79,59,91,19,96], \"x\": 51 }\nassert my_solution.maxScore(**test_input) == 419\n\ntest_input = { \"nums\": [96,81,48,3,60,78,74,82,14,7,87,72,42,41,80,4,92,82,59,16,19,94,70,45,83,58,2,91,11,96,17,62,79,34,44,47,89,76,85,21,5,57,35,51], \"x\": 24 }\nassert my_solution.maxScore(**test_input) == 1952\n\ntest_input = { \"nums\": [99,88,98,15,34,40,29,81,2,6,12,9,82,93,5,81,84,71,83,31,12,22,9,65,56,9,68,79,39,84,50,7,25,3,49], \"x\": 19 }\nassert my_solution.maxScore(**test_input) == 1363\n\ntest_input = { \"nums\": [8,50,65,85,8,73,55,50,29,95,5,68,52,79], \"x\": 74 }\nassert my_solution.maxScore(**test_input) == 470\n\ntest_input = { \"nums\": [45,9,20,89,18,94,12,51,38,77,100,95,46,1,76,41,8,90,82,33,92,32,76,43,6,61,85,40,63,10,74,18,44,43,17,100,17,33,100,77,97,8,99,85,88,9,63,31,32], \"x\": 68 }\nassert my_solution.maxScore(**test_input) == 1694\n\ntest_input = { \"nums\": [87,23,53,57,21,60,68,84,66,49,48,61,32,95,71,11,15,61,10,86,50,53,38,20,63], \"x\": 92 }\nassert my_solution.maxScore(**test_input) == 814\n\ntest_input = { \"nums\": [39,47,76,64,90,17,30,57,19,40,9,76,68,33,36,61,19,93,8,1,31,2,55,70,24,85,97,40,35,93,56,67,64,67,52,2,75,13,89,97], \"x\": 77 }\nassert my_solution.maxScore(**test_input) == 1390\n\ntest_input = { \"nums\": [92,87,85,27,27,10,24,94,26,78,24,61,4,46,3,76,29,65,52,61,34,67,74,61,90,40,81,60,10,98,87,57,28,77,55,33,10,91,57,72,3,72,4,39,99], \"x\": 70 }\nassert my_solution.maxScore(**test_input) == 1551\n\ntest_input = { \"nums\": [20,90,68], \"x\": 39 }\nassert my_solution.maxScore(**test_input) == 178\n\ntest_input = { \"nums\": [43,100,72,33,45,9,51,10,22,42,7,74,41,68,100,24,20,20,79,30,99,82], \"x\": 1 }\nassert my_solution.maxScore(**test_input) == 1060\n\ntest_input = { \"nums\": [100,87,29,94,56,41,53,98,34,17,52,3,54,51,22,39,37,9,76], \"x\": 40 }\nassert my_solution.maxScore(**test_input) == 670\n\ntest_input = { \"nums\": [55,37,87,45,96,7,66,62,91,51,33,92,65,99], \"x\": 81 }\nassert my_solution.maxScore(**test_input) == 625\n\ntest_input = { \"nums\": [2,75,65,43], \"x\": 39 }\nassert my_solution.maxScore(**test_input) == 146\n\ntest_input = { \"nums\": [74,82,80,95,72,23,49,43,76,28,87,27,58,39,7,77,26,63,56,96,77,75,82,60,90,69,83,20,13,82,16,90,40,23,36,17,77,15,18,10], \"x\": 40 }\nassert my_solution.maxScore(**test_input) == 1571\n\ntest_input = { \"nums\": [75,99,45,34,63,19,71,48,73,66,2,14,76,41,92,23,6,31,49,6,70,40,69,25,97,58,20,84,21,37,100,75,73,10,59,87,30], \"x\": 96 }\nassert my_solution.maxScore(**test_input) == 1181\n\ntest_input = { \"nums\": [9,58,17,54,91,90,32,6,13,67,24,80,8,56,29,66,85,38,45,13,20,73,16,98,28,56,23,2,47,85,11,97,72,2,28,52,33], \"x\": 90 }\nassert my_solution.maxScore(**test_input) == 886\n\ntest_input = { \"nums\": [96,89,30,38,58,26,47,52,27,77,87,92,6], \"x\": 83 }\nassert my_solution.maxScore(**test_input) == 423\n\ntest_input = { \"nums\": [35,11,46,34,57,2,21,98,85,7,65,26,22,14,48,14,38,72,56,63,73,11,70,92,62,3,9,72,32,99,8,71,85,66,73,29,74,88,41,24,21,40,41,19,49,90], \"x\": 11 }\nassert my_solution.maxScore(**test_input) == 1948\n\ntest_input = { \"nums\": [31,17,68,37,56,25,43,71,46,59,6,30,98,69,91], \"x\": 78 }\nassert my_solution.maxScore(**test_input) == 443\n\ntest_input = { \"nums\": [53,49,57,84,69,39,97,78,19,42,10,16,16,62,79,74,49,59,21,29,76,6,14,64,76,29,8,27,26], \"x\": 80 }\nassert my_solution.maxScore(**test_input) == 855\n\ntest_input = { \"nums\": [42,60,23,29,66,46,82,83,97,56,71,39,19,31,23,60,34,63,14,73,4,92,37,65,50,49,100,72,63], \"x\": 88 }\nassert my_solution.maxScore(**test_input) == 943\n\ntest_input = { \"nums\": [79,60,100,62,25,2,86,9,66,67,20,14,92,27,93,52,12,67,9,8,69,21,31,77,71,52,60], \"x\": 84 }\nassert my_solution.maxScore(**test_input) == 906\n\ntest_input = { \"nums\": [40,54,14,66,95,97,3,10,34,100,68,35,54,35,48,3,79,69,71,2,44,82,85,67,47,5,37,61,68,64,61,49,36,87,77,57,69,31,40,45,50,17,2,50,71], \"x\": 69 }\nassert my_solution.maxScore(**test_input) == 1564\n\ntest_input = { \"nums\": [53,15,2,58,28,93,55,41,88,69,93,67,67,40,37,99,17,30,10,7,94,50,73,53,37,84,50,37,81,91,72,28,22,22,67], \"x\": 82 }\nassert my_solution.maxScore(**test_input) == 1165\n\ntest_input = { \"nums\": [41,35,43,93,79,62,66,16,92,29,74,67,93,100,56,73], \"x\": 69 }\nassert my_solution.maxScore(**test_input) == 714\n\ntest_input = { \"nums\": [67,9,2,39,28,92,99,62,37,75,3,53,26,32,76,14,88,16,68,56,60], \"x\": 91 }\nassert my_solution.maxScore(**test_input) == 727\n\ntest_input = { \"nums\": [95,29,91,86,23,30,46,95,6,84,62,23,71,6,13,19,25,65,29,6,65,92], \"x\": 28 }\nassert my_solution.maxScore(**test_input) == 886\n\ntest_input = { \"nums\": [74,47,86,24,44,91,88,64,37], \"x\": 24 }\nassert my_solution.maxScore(**test_input) == 436\n\ntest_input = { \"nums\": [36,62,82,46,40], \"x\": 54 }\nassert my_solution.maxScore(**test_input) == 266\n\ntest_input = { \"nums\": [66,28,100,33,15,47,80,43,61,16,10], \"x\": 3 }\nassert my_solution.maxScore(**test_input) == 487\n\ntest_input = { \"nums\": [62,1,66,47,85,69,35,42,42,7,20,91], \"x\": 41 }\nassert my_solution.maxScore(**test_input) == 436\n\ntest_input = { \"nums\": [8,23,19,37,12,78,25,62,99,88,86,27,1,78,40,57,5,62,12,93,10,42], \"x\": 60 }\nassert my_solution.maxScore(**test_input) == 578\n\ntest_input = { \"nums\": [35,49,85,37,74,50,77,21,68,49,86,92,36,31,70,66,10,75,6,70,55,72,40,99,24,74,55,46,4,46,22,36,58,36,68,68,54,9,36,76,57,83,86,92,6,47,44,31], \"x\": 55 }\nassert my_solution.maxScore(**test_input) == 1797\n\ntest_input = { \"nums\": [75,96,53,79,89,57,75,94,24,75,71,8,44,70,12,92,38,24,3,38,88,10], \"x\": 31 }\nassert my_solution.maxScore(**test_input) == 1057\n\ntest_input = { \"nums\": [93,68,62,23,56,95,7,38,43,87,76,60,34,32,40,4,49,15,41,18,76,50], \"x\": 46 }\nassert my_solution.maxScore(**test_input) == 776\n\ntest_input = { \"nums\": [53,78,79,81,75,36,35,37], \"x\": 61 }\nassert my_solution.maxScore(**test_input) == 360\n\ntest_input = { \"nums\": [60,55,100,61,23,45,43,31], \"x\": 62 }\nassert my_solution.maxScore(**test_input) == 301\n\ntest_input = { \"nums\": [98,48,29,44,96,57], \"x\": 40 }\nassert my_solution.maxScore(**test_input) == 303\n\ntest_input = { \"nums\": [96,18,77,100,88,19,41,32,15,41,14], \"x\": 30 }\nassert my_solution.maxScore(**test_input) == 405\n\ntest_input = { \"nums\": [46,69,20,84,52,23,13,52,68,49,99,23,14,60,56,71,68,43,44,66,96,58,94], \"x\": 6 }\nassert my_solution.maxScore(**test_input) == 1208\n\ntest_input = { \"nums\": [85,12], \"x\": 79 }\nassert my_solution.maxScore(**test_input) == 85\n\ntest_input = { \"nums\": [63,95,35,79,39,14,55,5,44,57,31,23,67,61,75,61,40,51,55,27,53,100,15,100,23,89,76,99,31,47,49,52,47], \"x\": 49 }\nassert my_solution.maxScore(**test_input) == 1419\n\ntest_input = { \"nums\": [60,94,97,97,57,16,45,84,10,44,16], \"x\": 10 }\nassert my_solution.maxScore(**test_input) == 584\n\ntest_input = { \"nums\": [24,28,63,5,13,83,2,15,81,34,9,10,54,88,12,36,81,87,81,42,56,82,85,85,31,47,29,59,21,55,73,31,80,75,61,70,82,90,23,44,71,94], \"x\": 57 }\nassert my_solution.maxScore(**test_input) == 1665\n\ntest_input = { \"nums\": [92,7,95,1,79,49,58,77,54,12,38,18,9,23,75,98,76,86,40,33,22,14,62,67,60,36,67,51,85,100,75,30,55,63,28,100,94,4], \"x\": 89 }\nassert my_solution.maxScore(**test_input) == 1282\n\ntest_input = { \"nums\": [76,24,85,30,37,86,3,50,94,19,48,95,31], \"x\": 93 }\nassert my_solution.maxScore(**test_input) == 441\n\ntest_input = { \"nums\": [50,19,12,63,20,33,21,77,25,24,46,22,46,57,86,65,13,99,36,23,85,99,10], \"x\": 7 }\nassert my_solution.maxScore(**test_input) == 949\n\ntest_input = { \"nums\": [68,26,50,20,54,30,12,66,30,75,31,89,78,30,17,38,97,15,43,39,82,25,3,78,66,6,68,86,29,20,99], \"x\": 97 }\nassert my_solution.maxScore(**test_input) == 985\n\ntest_input = { \"nums\": [62,1,18,37,87,73,16], \"x\": 44 }\nassert my_solution.maxScore(**test_input) == 233\n\ntest_input = { \"nums\": [35,60,95,31,19,87,19,37,78,82,81,96,23,58,93,96,92,41,48,67,90,70,6,97,6,2,77,47,34,17,51,15,13,93,12,46], \"x\": 1 }\nassert my_solution.maxScore(**test_input) == 1895\n\ntest_input = { \"nums\": [21,29], \"x\": 68 }\nassert my_solution.maxScore(**test_input) == 50\n\ntest_input = { \"nums\": [37,98,2,60,89,82,99,80,28,54,12,15,16,88,82,72,63,8,45,56,99,19,29,38,26,35], \"x\": 94 }\nassert my_solution.maxScore(**test_input) == 813\n\ntest_input = { \"nums\": [84,8,44,48,85,77,18,34,17,46,53,84,52,77,12,94,18,67,46,45], \"x\": 44 }\nassert my_solution.maxScore(**test_input) == 684\n\ntest_input = { \"nums\": [50,1,21,95,20,65,80,75,47,74,95,23,89,61,48,25,84,76,81,51,52,37,84,24,15,32,11,88], \"x\": 65 }\nassert my_solution.maxScore(**test_input) == 982\n\ntest_input = { \"nums\": [54,2,22,17,41,23,51,16,5,42,12,77,9,71,92,87,78,50,14,74,72,42,90], \"x\": 52 }\nassert my_solution.maxScore(**test_input) == 780\n\ntest_input = { \"nums\": [3,34,22,49,66,40,13,7,71,35,1,96,36,83,31,55,60,20,90,76,51,95,21,47,82,91,75,99,72,48,53,2,56,64], \"x\": 70 }\nassert my_solution.maxScore(**test_input) == 1105\n\ntest_input = { \"nums\": [75,34,33,97,3,25,4,71,8,73], \"x\": 27 }\nassert my_solution.maxScore(**test_input) == 377\n\ntest_input = { \"nums\": [27,91,78,7,48,79,23,34,17,42,94,85,48,36,26,57,53,10,38,32,45,89,74,5,35,39,9,59,71,39,1,60,39,50,47,47,48,74,71,91,85,86,22], \"x\": 74 }\nassert my_solution.maxScore(**test_input) == 1292\n\ntest_input = { \"nums\": [26,97,16,94,49,98,78,84,76,21,75,88,22,49,34,98,7,94,100,98,72,70,47,6,56,8,50,9,37,37,34,36,48,95,8,63,35,81,26,57,91,4,83,38,64,45,98,51], \"x\": 86 }\nassert my_solution.maxScore(**test_input) == 1919\n\ntest_input = { \"nums\": [14,64,4,14,94,58,67,15,79,26,66,34,47,42,20,67,5,21,63,73,44,96,29,72,26,20,84,84,62,39,93,53,13,35,32,82,22,58], \"x\": 87 }\nassert my_solution.maxScore(**test_input) == 1252\n\ntest_input = { \"nums\": [42,98,75,46,10,21,10,35,4,59,100,78,62,51,84,99,92,2,4,12,59,8,42,85,86,81,20,1,43,41,56,2,30,25,21,56,43,82,38,45,89,54,15,63,69,20,64], \"x\": 45 }\nassert my_solution.maxScore(**test_input) == 1442\n\ntest_input = { \"nums\": [99,80,22,56,93,18,65,63,8,16,80], \"x\": 39 }\nassert my_solution.maxScore(**test_input) == 465\n\ntest_input = { \"nums\": [2,17,64,100,23,2,8,93,31,6,16,28,32,98,18,33,22,54,73,35,47,16,76,74,17,5,6,1,7,19,100,17,70,98,94,5,78,38,10,80], \"x\": 59 }\nassert my_solution.maxScore(**test_input) == 1246\n\ntest_input = { \"nums\": [15,10,55,18,55,54,63,79,97,9,98,10,95,3,88,43,75,17,19,36,64,44,85,10,45,42,58,75,79,7,55,75,50,89,8,89,58,87,30,36,59,59,25], \"x\": 4 }\nassert my_solution.maxScore(**test_input) == 2072\n\ntest_input = { \"nums\": [97,60,79,8,79,39,37,66,78,58,32,59,83,23,36,82,34,70,17,17,33,91,1,55,54,45,30,11,30,19,8,8,98,36,39,30,87,34,99,83,6,90], \"x\": 91 }\nassert my_solution.maxScore(**test_input) == 1214\n\ntest_input = { \"nums\": [52,83,17,67,51,47,8,86,59,56,96,74,36,38,73,96,95,50,25,45,5,48,16,3,65,22,92,11,80,46,15], \"x\": 4 }\nassert my_solution.maxScore(**test_input) == 1497\n\ntest_input = { \"nums\": [38,97,36,48,88,68,66,39,40,36,39,53,96,21,3,28,86,94,31,53,76,24,54,45,10,99,92,21,52,25,15,42,12,17,89,51], \"x\": 14 }\nassert my_solution.maxScore(**test_input) == 1547\n\ntest_input = { \"nums\": [6,13,9], \"x\": 98 }\nassert my_solution.maxScore(**test_input) == 6\n\ntest_input = { \"nums\": [52,66,40,14,6,26,37,93,23,2,40,10,42,1,85,22,45,46,16,14,70,76,48,100,68,85,72,31,15,56,65,61,83,90,31,31,2,27,55,91,50,32], \"x\": 18 }\nassert my_solution.maxScore(**test_input) == 1679\n\ntest_input = { \"nums\": [8,60,58], \"x\": 18 }\nassert my_solution.maxScore(**test_input) == 126\n\ntest_input = { \"nums\": [74,24,7,80,13,46,52,19,20,6,70,95,20,82,97,32,28,16,4,21,19,56,9,56,30,99,64,94,61,5,28,51,58,49,49,92,68,66,17,84,54], \"x\": 51 }\nassert my_solution.maxScore(**test_input) == 1331\n\ntest_input = { \"nums\": [99,30,17,54,77,71,48,19,80,43,20,59,95,76,64,32,29,84,80,33,90,11,76,65,76,51,50,36,99], \"x\": 6 }\nassert my_solution.maxScore(**test_input) == 1533\n\ntest_input = { \"nums\": [21,99,29,76,1,25,62,67,82,90,99,12,51,53,62,78,41,14,55,66,90,73,30,76,97], \"x\": 60 }\nassert my_solution.maxScore(**test_input) == 935\n\ntest_input = { \"nums\": [59,78,89,17,43,89,21,43,73,76,68,94,69,76,26,3,86,65,45,29,68,53,41,87,79,37,11,55,82,97,9,48,64,13,56,56,60,22,22,50,23,51,14,36,2], \"x\": 81 }\nassert my_solution.maxScore(**test_input) == 1655\n\ntest_input = { \"nums\": [5,2,24,57,9,5,71,90,20,80,9,99,45,27,60,7,65,23,55,46,49,57,7,22,28,35], \"x\": 77 }\nassert my_solution.maxScore(**test_input) == 661\n\ntest_input = { \"nums\": [76,60,37,9,31,30,86,64,83,71,70,18,32,74,38,11,6,4,9,62,52,14,20,41,60,54,40,15,90,52,27,46,47,1,7,79,22,49,99,82], \"x\": 100 }\nassert my_solution.maxScore(**test_input) == 1230\n\ntest_input = { \"nums\": [20,89,67,20,1,84,36,92,41,79,35,85,58,76,42,12,96,38,44,93,54,80,44,49,55,6,34,84,3,74,13], \"x\": 23 }\nassert my_solution.maxScore(**test_input) == 1403\n\ntest_input = { \"nums\": [69,86,56,72,35,8,57,10,42,90,92,46,7,22,69,16,62,9,57,74,52,49,14,23,13,43,73,63,88,18,31,89,94,3,23,14,39,82,70,78], \"x\": 95 }\nassert my_solution.maxScore(**test_input) == 1234\n\ntest_input = { \"nums\": [28,66,78,21,47,6,18,60,8,82,34,19,62,26,34,56,59,56,7,75,35,42,19,23,92,88,83,65,74,24,69,83,12,63,4,71,78,40,64,98,15,17,81,19], \"x\": 84 }\nassert my_solution.maxScore(**test_input) == 1430\n\ntest_input = { \"nums\": [77,48,31,26], \"x\": 53 }\nassert my_solution.maxScore(**test_input) == 108\n\ntest_input = { \"nums\": [33,69,10,90,86,82,66,19,28,33,9,98,87,7,7,17,69,79,85,65,31,38,75], \"x\": 21 }\nassert my_solution.maxScore(**test_input) == 1042\n\ntest_input = { \"nums\": [16,99,70,71,62,42], \"x\": 83 }\nassert my_solution.maxScore(**test_input) == 190\n\ntest_input = { \"nums\": [55,64,59,68,50,32,56,75,84,53,97,7,40,62,56,80,36,52,43,77,82,47,7,96,94,43,77,71,36,92], \"x\": 48 }\nassert my_solution.maxScore(**test_input) == 1267\n\ntest_input = { \"nums\": [61,12,92,54,88,10,49,19,83,24,82,29,64,96,67,12,27,97,15,96,35,43,92,96,28,84,49,72,16,92,29,41], \"x\": 73 }\nassert my_solution.maxScore(**test_input) == 1151\n\ntest_input = { \"nums\": [90,84,13,56,24,54,29,20], \"x\": 31 }\nassert my_solution.maxScore(**test_input) == 328\n\ntest_input = { \"nums\": [94,12,26,83,92,8,64,21,80,32,47,71,30], \"x\": 66 }\nassert my_solution.maxScore(**test_input) == 460\n\ntest_input = { \"nums\": [42,11,1], \"x\": 16 }\nassert my_solution.maxScore(**test_input) == 42\n\ntest_input = { \"nums\": [22,56,65,84,34,80,56,63,22,52,94,29,99,45,20,66,50,62,44,10,3,70,13,23,99,99,71,61,11,28,48,66,41,4,5,18,22,44,36,92,10,90,20], \"x\": 36 }\nassert my_solution.maxScore(**test_input) == 1706\n\ntest_input = { \"nums\": [6,45,84,69,49,47,49,13,6,25,82,38,1,4,99,68,89,78,53,29,73,96,71,58,88,18,97,61,37,80,20,93,77,38,84], \"x\": 40 }\nassert my_solution.maxScore(**test_input) == 1336\n\ntest_input = { \"nums\": [85,71,5,91,31,75,36,4,42,81,92,42,40,14,57,72,33,66,4,1,26,81,45,56,64,76,43,39,53,9,37,38,53,26,2,55,6,70,9,45,35,60,73,38,62,58,3], \"x\": 86 }\nassert my_solution.maxScore(**test_input) == 1343\n\ntest_input = { \"nums\": [32,53,27,49,7,40,22,85,53,46,28,95,59,85,78,16,15,63,24,64,90,9,84,9,66,41,75,8,22,53,72,29,15,32,49,29,37,66,82,63,59,58], \"x\": 70 }\nassert my_solution.maxScore(**test_input) == 1221\n\ntest_input = { \"nums\": [76,100,47,98,31,46,73,18,40,46,4,70,33,43,58,21,72,24,97,17,18,61,86,9,8,96,54,55], \"x\": 43 }\nassert my_solution.maxScore(**test_input) == 997\n\ntest_input = { \"nums\": [78,66,10,19,59,87,27,40,49,80,25,3,33,54,29,97,9,36,73,80,59,68], \"x\": 97 }\nassert my_solution.maxScore(**test_input) == 626\n\ntest_input = { \"nums\": [13,26,3,19,21,43,33,62,32,61,40,22,56,69,15,21,10,87,84,66,26,35,54,64,7,53,32,14,7], \"x\": 76 }\nassert my_solution.maxScore(**test_input) == 649\n\ntest_input = { \"nums\": [73,93,27,67,11,40,18,88,78,77,79,80,15,100,83,33,36,63,90,44,89,23,25,79,56,41,8,62,32,98,58], \"x\": 10 }\nassert my_solution.maxScore(**test_input) == 1641\n\ntest_input = { \"nums\": [38,97,76,72,85,23,70,90,89,1,65,50,1,93,41,33,94,43,45,39,98,52,85,18,70,79,79,33,22,93,72,25,20,42,19,66,64,64,95,29,3,75,54,40,17,86,71,23,26,23], \"x\": 66 }\nassert my_solution.maxScore(**test_input) == 1683", "start_time": 1690036200} +{"task_id": "biweekly-contest-109-ways-to-express-an-integer-as-sum-of-powers", "url": "https://leetcode.com/problems/ways-to-express-an-integer-as-sum-of-powers", "title": "ways-to-express-an-integer-as-sum-of-powers", "meta": {"questionId": "2882", "questionFrontendId": "2787", "title": "Ways to Express an Integer as Sum of Powers", "titleSlug": "ways-to-express-an-integer-as-sum-of-powers", "isPaidOnly": false, "difficulty": "Medium", "likes": 346, "dislikes": 11, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你两个 正 整数 n 和 x 。\n\n请你返回将 n 表示成一些 互不相同 正整数的 x 次幂之和的方案数。换句话说,你需要返回互不相同整数 [n1, n2, ..., nk] 的集合数目,满足 n = n1x + n2x + ... + nkx 。\n\n由于答案可能非常大,请你将它对 109 + 7 取余后返回。\n\n比方说,n = 160 且 x = 3 ,一个表示 n 的方法是 n = 23 + 33 + 53 。\n\n示例 1:\n\n输入:n = 10, x = 2\n输出:1\n解释:我们可以将 n 表示为:n = 32 + 12 = 10 。\n这是唯一将 10 表达成不同整数 2 次方之和的方案。\n\n示例 2:\n\n输入:n = 4, x = 1\n输出:2\n解释:我们可以将 n 按以下方案表示:\n- n = 41 = 4 。\n- n = 31 + 11 = 4 。\n\n\n提示:\n\n * 1 <= n <= 300\n * 1 <= x <= 5\n\"\"\"\nclass Solution:\n def numberOfWays(self, n: int, x: int) -> int:\n ", "prompt_sft": "给你两个 正 整数 n 和 x 。\n\n请你返回将 n 表示成一些 互不相同 正整数的 x 次幂之和的方案数。换句话说,你需要返回互不相同整数 [n1, n2, ..., nk] 的集合数目,满足 n = n1x + n2x + ... + nkx 。\n\n由于答案可能非常大,请你将它对 109 + 7 取余后返回。\n\n比方说,n = 160 且 x = 3 ,一个表示 n 的方法是 n = 23 + 33 + 53 。\n\n示例 1:\n\n输入:n = 10, x = 2\n输出:1\n解释:我们可以将 n 表示为:n = 32 + 12 = 10 。\n这是唯一将 10 表达成不同整数 2 次方之和的方案。\n\n示例 2:\n\n输入:n = 4, x = 1\n输出:2\n解释:我们可以将 n 按以下方案表示:\n- n = 41 = 4 。\n- n = 31 + 11 = 4 。\n\n\n提示:\n\n * 1 <= n <= 300\n * 1 <= x <= 5\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def numberOfWays(self, n: int, x: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"n\": 10, \"x\": 2 }\nassert my_solution.numberOfWays(**test_input) == 1\n\ntest_input = { \"n\": 4, \"x\": 1 }\nassert my_solution.numberOfWays(**test_input) == 2\n\ntest_input = { \"n\": 1, \"x\": 1 }\nassert my_solution.numberOfWays(**test_input) == 1\n\ntest_input = { \"n\": 1, \"x\": 2 }\nassert my_solution.numberOfWays(**test_input) == 1\n\ntest_input = { \"n\": 1, \"x\": 3 }\nassert my_solution.numberOfWays(**test_input) == 1\n\ntest_input = { \"n\": 1, \"x\": 4 }\nassert my_solution.numberOfWays(**test_input) == 1\n\ntest_input = { \"n\": 1, \"x\": 5 }\nassert my_solution.numberOfWays(**test_input) == 1\n\ntest_input = { \"n\": 2, \"x\": 1 }\nassert my_solution.numberOfWays(**test_input) == 1\n\ntest_input = { \"n\": 2, \"x\": 2 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 2, \"x\": 3 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 2, \"x\": 4 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 2, \"x\": 5 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 3, \"x\": 1 }\nassert my_solution.numberOfWays(**test_input) == 2\n\ntest_input = { \"n\": 3, \"x\": 2 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 3, \"x\": 3 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 3, \"x\": 4 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 3, \"x\": 5 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 4, \"x\": 2 }\nassert my_solution.numberOfWays(**test_input) == 1\n\ntest_input = { \"n\": 4, \"x\": 3 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 4, \"x\": 4 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 4, \"x\": 5 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 5, \"x\": 1 }\nassert my_solution.numberOfWays(**test_input) == 3\n\ntest_input = { \"n\": 5, \"x\": 2 }\nassert my_solution.numberOfWays(**test_input) == 1\n\ntest_input = { \"n\": 5, \"x\": 3 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 5, \"x\": 4 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 5, \"x\": 5 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 6, \"x\": 1 }\nassert my_solution.numberOfWays(**test_input) == 4\n\ntest_input = { \"n\": 6, \"x\": 2 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 6, \"x\": 3 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 6, \"x\": 4 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 6, \"x\": 5 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 7, \"x\": 1 }\nassert my_solution.numberOfWays(**test_input) == 5\n\ntest_input = { \"n\": 7, \"x\": 2 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 7, \"x\": 3 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 7, \"x\": 4 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 7, \"x\": 5 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 8, \"x\": 1 }\nassert my_solution.numberOfWays(**test_input) == 6\n\ntest_input = { \"n\": 8, \"x\": 2 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 8, \"x\": 3 }\nassert my_solution.numberOfWays(**test_input) == 1\n\ntest_input = { \"n\": 8, \"x\": 4 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 8, \"x\": 5 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 9, \"x\": 1 }\nassert my_solution.numberOfWays(**test_input) == 8\n\ntest_input = { \"n\": 9, \"x\": 2 }\nassert my_solution.numberOfWays(**test_input) == 1\n\ntest_input = { \"n\": 9, \"x\": 3 }\nassert my_solution.numberOfWays(**test_input) == 1\n\ntest_input = { \"n\": 9, \"x\": 4 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 9, \"x\": 5 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 10, \"x\": 1 }\nassert my_solution.numberOfWays(**test_input) == 10\n\ntest_input = { \"n\": 10, \"x\": 3 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 10, \"x\": 4 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 10, \"x\": 5 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 11, \"x\": 1 }\nassert my_solution.numberOfWays(**test_input) == 12\n\ntest_input = { \"n\": 11, \"x\": 2 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 11, \"x\": 3 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 11, \"x\": 4 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 11, \"x\": 5 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 12, \"x\": 1 }\nassert my_solution.numberOfWays(**test_input) == 15\n\ntest_input = { \"n\": 12, \"x\": 2 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 12, \"x\": 3 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 12, \"x\": 4 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 12, \"x\": 5 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 13, \"x\": 1 }\nassert my_solution.numberOfWays(**test_input) == 18\n\ntest_input = { \"n\": 13, \"x\": 2 }\nassert my_solution.numberOfWays(**test_input) == 1\n\ntest_input = { \"n\": 13, \"x\": 3 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 13, \"x\": 4 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 13, \"x\": 5 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 14, \"x\": 1 }\nassert my_solution.numberOfWays(**test_input) == 22\n\ntest_input = { \"n\": 14, \"x\": 2 }\nassert my_solution.numberOfWays(**test_input) == 1\n\ntest_input = { \"n\": 14, \"x\": 3 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 14, \"x\": 4 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 14, \"x\": 5 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 15, \"x\": 1 }\nassert my_solution.numberOfWays(**test_input) == 27\n\ntest_input = { \"n\": 15, \"x\": 2 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 15, \"x\": 3 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 15, \"x\": 4 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 15, \"x\": 5 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 16, \"x\": 1 }\nassert my_solution.numberOfWays(**test_input) == 32\n\ntest_input = { \"n\": 16, \"x\": 2 }\nassert my_solution.numberOfWays(**test_input) == 1\n\ntest_input = { \"n\": 16, \"x\": 3 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 16, \"x\": 4 }\nassert my_solution.numberOfWays(**test_input) == 1\n\ntest_input = { \"n\": 16, \"x\": 5 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 17, \"x\": 1 }\nassert my_solution.numberOfWays(**test_input) == 38\n\ntest_input = { \"n\": 17, \"x\": 2 }\nassert my_solution.numberOfWays(**test_input) == 1\n\ntest_input = { \"n\": 17, \"x\": 3 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 17, \"x\": 4 }\nassert my_solution.numberOfWays(**test_input) == 1\n\ntest_input = { \"n\": 17, \"x\": 5 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 18, \"x\": 1 }\nassert my_solution.numberOfWays(**test_input) == 46\n\ntest_input = { \"n\": 18, \"x\": 2 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 18, \"x\": 3 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 18, \"x\": 4 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 18, \"x\": 5 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 19, \"x\": 1 }\nassert my_solution.numberOfWays(**test_input) == 54\n\ntest_input = { \"n\": 19, \"x\": 2 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 19, \"x\": 3 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 19, \"x\": 4 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 19, \"x\": 5 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 20, \"x\": 1 }\nassert my_solution.numberOfWays(**test_input) == 64\n\ntest_input = { \"n\": 20, \"x\": 2 }\nassert my_solution.numberOfWays(**test_input) == 1\n\ntest_input = { \"n\": 20, \"x\": 3 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 20, \"x\": 4 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 20, \"x\": 5 }\nassert my_solution.numberOfWays(**test_input) == 0", "start_time": 1690036200} +{"task_id": "weekly-contest-354-sum-of-squares-of-special-elements", "url": "https://leetcode.com/problems/sum-of-squares-of-special-elements", "title": "sum-of-squares-of-special-elements", "meta": {"questionId": "2844", "questionFrontendId": "2778", "title": "Sum of Squares of Special Elements ", "titleSlug": "sum-of-squares-of-special-elements", "isPaidOnly": false, "difficulty": "Easy", "likes": 218, "dislikes": 65, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 1 开始、长度为 n 的整数数组 nums 。\n\n对 nums 中的元素 nums[i] 而言,如果 n 能够被 i 整除,即 n % i == 0 ,则认为 num[i] 是一个 特殊元素 。\n\n返回 nums 中所有 特殊元素 的 平方和 。\n\n示例 1:\n\n输入:nums = [1,2,3,4]\n输出:21\n解释:nums 中共有 3 个特殊元素:nums[1],因为 4 被 1 整除;nums[2],因为 4 被 2 整除;以及 nums[4],因为 4 被 4 整除。\n因此,nums 中所有特殊元素的平方和等于 nums[1] * nums[1] + nums[2] * nums[2] + nums[4] * nums[4] = 1 * 1 + 2 * 2 + 4 * 4 = 21 。\n\n示例 2:\n\n输入:nums = [2,7,1,19,18,3]\n输出:63\n解释:nums 中共有 4 个特殊元素:nums[1],因为 6 被 1 整除;nums[2] ,因为 6 被 2 整除;nums[3],因为 6 被 3 整除;以及 nums[6],因为 6 被 6 整除。\n因此,nums 中所有特殊元素的平方和等于 nums[1] * nums[1] + nums[2] * nums[2] + nums[3] * nums[3] + nums[6] * nums[6] = 2 * 2 + 7 * 7 + 1 * 1 + 3 * 3 = 63 。\n\n提示:\n\n * 1 <= nums.length == n <= 50\n * 1 <= nums[i] <= 50\n\"\"\"\nclass Solution:\n def sumOfSquares(self, nums: List[int]) -> int:\n ", "prompt_sft": "给你一个下标从 1 开始、长度为 n 的整数数组 nums 。\n\n对 nums 中的元素 nums[i] 而言,如果 n 能够被 i 整除,即 n % i == 0 ,则认为 num[i] 是一个 特殊元素 。\n\n返回 nums 中所有 特殊元素 的 平方和 。\n\n示例 1:\n\n输入:nums = [1,2,3,4]\n输出:21\n解释:nums 中共有 3 个特殊元素:nums[1],因为 4 被 1 整除;nums[2],因为 4 被 2 整除;以及 nums[4],因为 4 被 4 整除。\n因此,nums 中所有特殊元素的平方和等于 nums[1] * nums[1] + nums[2] * nums[2] + nums[4] * nums[4] = 1 * 1 + 2 * 2 + 4 * 4 = 21 。\n\n示例 2:\n\n输入:nums = [2,7,1,19,18,3]\n输出:63\n解释:nums 中共有 4 个特殊元素:nums[1],因为 6 被 1 整除;nums[2] ,因为 6 被 2 整除;nums[3],因为 6 被 3 整除;以及 nums[6],因为 6 被 6 整除。\n因此,nums 中所有特殊元素的平方和等于 nums[1] * nums[1] + nums[2] * nums[2] + nums[3] * nums[3] + nums[6] * nums[6] = 2 * 2 + 7 * 7 + 1 * 1 + 3 * 3 = 63 。\n\n提示:\n\n * 1 <= nums.length == n <= 50\n * 1 <= nums[i] <= 50\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def sumOfSquares(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,2,3,4] }\nassert my_solution.sumOfSquares(**test_input) == 21\n\ntest_input = { \"nums\": [2,7,1,19,18,3] }\nassert my_solution.sumOfSquares(**test_input) == 63\n\ntest_input = { \"nums\": [1] }\nassert my_solution.sumOfSquares(**test_input) == 1\n\ntest_input = { \"nums\": [2] }\nassert my_solution.sumOfSquares(**test_input) == 4\n\ntest_input = { \"nums\": [3] }\nassert my_solution.sumOfSquares(**test_input) == 9\n\ntest_input = { \"nums\": [4] }\nassert my_solution.sumOfSquares(**test_input) == 16\n\ntest_input = { \"nums\": [5] }\nassert my_solution.sumOfSquares(**test_input) == 25\n\ntest_input = { \"nums\": [6] }\nassert my_solution.sumOfSquares(**test_input) == 36\n\ntest_input = { \"nums\": [7] }\nassert my_solution.sumOfSquares(**test_input) == 49\n\ntest_input = { \"nums\": [8] }\nassert my_solution.sumOfSquares(**test_input) == 64\n\ntest_input = { \"nums\": [9] }\nassert my_solution.sumOfSquares(**test_input) == 81\n\ntest_input = { \"nums\": [10] }\nassert my_solution.sumOfSquares(**test_input) == 100\n\ntest_input = { \"nums\": [11] }\nassert my_solution.sumOfSquares(**test_input) == 121\n\ntest_input = { \"nums\": [12] }\nassert my_solution.sumOfSquares(**test_input) == 144\n\ntest_input = { \"nums\": [13] }\nassert my_solution.sumOfSquares(**test_input) == 169\n\ntest_input = { \"nums\": [14] }\nassert my_solution.sumOfSquares(**test_input) == 196\n\ntest_input = { \"nums\": [15] }\nassert my_solution.sumOfSquares(**test_input) == 225\n\ntest_input = { \"nums\": [16] }\nassert my_solution.sumOfSquares(**test_input) == 256\n\ntest_input = { \"nums\": [17] }\nassert my_solution.sumOfSquares(**test_input) == 289\n\ntest_input = { \"nums\": [18] }\nassert my_solution.sumOfSquares(**test_input) == 324\n\ntest_input = { \"nums\": [19] }\nassert my_solution.sumOfSquares(**test_input) == 361\n\ntest_input = { \"nums\": [20] }\nassert my_solution.sumOfSquares(**test_input) == 400\n\ntest_input = { \"nums\": [21] }\nassert my_solution.sumOfSquares(**test_input) == 441\n\ntest_input = { \"nums\": [22] }\nassert my_solution.sumOfSquares(**test_input) == 484\n\ntest_input = { \"nums\": [23] }\nassert my_solution.sumOfSquares(**test_input) == 529\n\ntest_input = { \"nums\": [24] }\nassert my_solution.sumOfSquares(**test_input) == 576\n\ntest_input = { \"nums\": [25] }\nassert my_solution.sumOfSquares(**test_input) == 625\n\ntest_input = { \"nums\": [26] }\nassert my_solution.sumOfSquares(**test_input) == 676\n\ntest_input = { \"nums\": [27] }\nassert my_solution.sumOfSquares(**test_input) == 729\n\ntest_input = { \"nums\": [28] }\nassert my_solution.sumOfSquares(**test_input) == 784\n\ntest_input = { \"nums\": [29] }\nassert my_solution.sumOfSquares(**test_input) == 841\n\ntest_input = { \"nums\": [30] }\nassert my_solution.sumOfSquares(**test_input) == 900\n\ntest_input = { \"nums\": [31] }\nassert my_solution.sumOfSquares(**test_input) == 961\n\ntest_input = { \"nums\": [32] }\nassert my_solution.sumOfSquares(**test_input) == 1024\n\ntest_input = { \"nums\": [33] }\nassert my_solution.sumOfSquares(**test_input) == 1089\n\ntest_input = { \"nums\": [34] }\nassert my_solution.sumOfSquares(**test_input) == 1156\n\ntest_input = { \"nums\": [35] }\nassert my_solution.sumOfSquares(**test_input) == 1225\n\ntest_input = { \"nums\": [36] }\nassert my_solution.sumOfSquares(**test_input) == 1296\n\ntest_input = { \"nums\": [37] }\nassert my_solution.sumOfSquares(**test_input) == 1369\n\ntest_input = { \"nums\": [38] }\nassert my_solution.sumOfSquares(**test_input) == 1444\n\ntest_input = { \"nums\": [39] }\nassert my_solution.sumOfSquares(**test_input) == 1521\n\ntest_input = { \"nums\": [40] }\nassert my_solution.sumOfSquares(**test_input) == 1600\n\ntest_input = { \"nums\": [41] }\nassert my_solution.sumOfSquares(**test_input) == 1681\n\ntest_input = { \"nums\": [42] }\nassert my_solution.sumOfSquares(**test_input) == 1764\n\ntest_input = { \"nums\": [43] }\nassert my_solution.sumOfSquares(**test_input) == 1849\n\ntest_input = { \"nums\": [44] }\nassert my_solution.sumOfSquares(**test_input) == 1936\n\ntest_input = { \"nums\": [45] }\nassert my_solution.sumOfSquares(**test_input) == 2025\n\ntest_input = { \"nums\": [46] }\nassert my_solution.sumOfSquares(**test_input) == 2116\n\ntest_input = { \"nums\": [47] }\nassert my_solution.sumOfSquares(**test_input) == 2209\n\ntest_input = { \"nums\": [48] }\nassert my_solution.sumOfSquares(**test_input) == 2304\n\ntest_input = { \"nums\": [49] }\nassert my_solution.sumOfSquares(**test_input) == 2401\n\ntest_input = { \"nums\": [50] }\nassert my_solution.sumOfSquares(**test_input) == 2500\n\ntest_input = { \"nums\": [16,16] }\nassert my_solution.sumOfSquares(**test_input) == 512\n\ntest_input = { \"nums\": [13,36] }\nassert my_solution.sumOfSquares(**test_input) == 1465\n\ntest_input = { \"nums\": [40,37] }\nassert my_solution.sumOfSquares(**test_input) == 2969\n\ntest_input = { \"nums\": [33,42] }\nassert my_solution.sumOfSquares(**test_input) == 2853\n\ntest_input = { \"nums\": [46,9] }\nassert my_solution.sumOfSquares(**test_input) == 2197\n\ntest_input = { \"nums\": [30,14] }\nassert my_solution.sumOfSquares(**test_input) == 1096\n\ntest_input = { \"nums\": [5,41] }\nassert my_solution.sumOfSquares(**test_input) == 1706\n\ntest_input = { \"nums\": [17,9] }\nassert my_solution.sumOfSquares(**test_input) == 370\n\ntest_input = { \"nums\": [29,21] }\nassert my_solution.sumOfSquares(**test_input) == 1282\n\ntest_input = { \"nums\": [4,38] }\nassert my_solution.sumOfSquares(**test_input) == 1460\n\ntest_input = { \"nums\": [14,18] }\nassert my_solution.sumOfSquares(**test_input) == 520\n\ntest_input = { \"nums\": [11,7] }\nassert my_solution.sumOfSquares(**test_input) == 170\n\ntest_input = { \"nums\": [11,36] }\nassert my_solution.sumOfSquares(**test_input) == 1417\n\ntest_input = { \"nums\": [18,26] }\nassert my_solution.sumOfSquares(**test_input) == 1000\n\ntest_input = { \"nums\": [37,46] }\nassert my_solution.sumOfSquares(**test_input) == 3485\n\ntest_input = { \"nums\": [13,33] }\nassert my_solution.sumOfSquares(**test_input) == 1258\n\ntest_input = { \"nums\": [39,1] }\nassert my_solution.sumOfSquares(**test_input) == 1522\n\ntest_input = { \"nums\": [37,16] }\nassert my_solution.sumOfSquares(**test_input) == 1625\n\ntest_input = { \"nums\": [22,34] }\nassert my_solution.sumOfSquares(**test_input) == 1640\n\ntest_input = { \"nums\": [4,50] }\nassert my_solution.sumOfSquares(**test_input) == 2516\n\ntest_input = { \"nums\": [42,40] }\nassert my_solution.sumOfSquares(**test_input) == 3364\n\ntest_input = { \"nums\": [7,44] }\nassert my_solution.sumOfSquares(**test_input) == 1985\n\ntest_input = { \"nums\": [21,27] }\nassert my_solution.sumOfSquares(**test_input) == 1170\n\ntest_input = { \"nums\": [49,35] }\nassert my_solution.sumOfSquares(**test_input) == 3626\n\ntest_input = { \"nums\": [32,20] }\nassert my_solution.sumOfSquares(**test_input) == 1424\n\ntest_input = { \"nums\": [30,12] }\nassert my_solution.sumOfSquares(**test_input) == 1044\n\ntest_input = { \"nums\": [50,42] }\nassert my_solution.sumOfSquares(**test_input) == 4264\n\ntest_input = { \"nums\": [3,11] }\nassert my_solution.sumOfSquares(**test_input) == 130\n\ntest_input = { \"nums\": [38,17] }\nassert my_solution.sumOfSquares(**test_input) == 1733\n\ntest_input = { \"nums\": [50,32] }\nassert my_solution.sumOfSquares(**test_input) == 3524\n\ntest_input = { \"nums\": [12,35] }\nassert my_solution.sumOfSquares(**test_input) == 1369\n\ntest_input = { \"nums\": [9,32] }\nassert my_solution.sumOfSquares(**test_input) == 1105\n\ntest_input = { \"nums\": [6,11] }\nassert my_solution.sumOfSquares(**test_input) == 157\n\ntest_input = { \"nums\": [11,39] }\nassert my_solution.sumOfSquares(**test_input) == 1642\n\ntest_input = { \"nums\": [18,29] }\nassert my_solution.sumOfSquares(**test_input) == 1165\n\ntest_input = { \"nums\": [44,29] }\nassert my_solution.sumOfSquares(**test_input) == 2777\n\ntest_input = { \"nums\": [50,13] }\nassert my_solution.sumOfSquares(**test_input) == 2669\n\ntest_input = { \"nums\": [46,46] }\nassert my_solution.sumOfSquares(**test_input) == 4232\n\ntest_input = { \"nums\": [27,5] }\nassert my_solution.sumOfSquares(**test_input) == 754\n\ntest_input = { \"nums\": [12,13] }\nassert my_solution.sumOfSquares(**test_input) == 313\n\ntest_input = { \"nums\": [10,46] }\nassert my_solution.sumOfSquares(**test_input) == 2216\n\ntest_input = { \"nums\": [37,32] }\nassert my_solution.sumOfSquares(**test_input) == 2393\n\ntest_input = { \"nums\": [26,33] }\nassert my_solution.sumOfSquares(**test_input) == 1765\n\ntest_input = { \"nums\": [44,3] }\nassert my_solution.sumOfSquares(**test_input) == 1945\n\ntest_input = { \"nums\": [9,16] }\nassert my_solution.sumOfSquares(**test_input) == 337\n\ntest_input = { \"nums\": [7,21] }\nassert my_solution.sumOfSquares(**test_input) == 490\n\ntest_input = { \"nums\": [23,33] }\nassert my_solution.sumOfSquares(**test_input) == 1618\n\ntest_input = { \"nums\": [22,5] }\nassert my_solution.sumOfSquares(**test_input) == 509", "start_time": 1689474600} +{"task_id": "weekly-contest-354-maximum-beauty-of-an-array-after-applying-operation", "url": "https://leetcode.com/problems/maximum-beauty-of-an-array-after-applying-operation", "title": "maximum-beauty-of-an-array-after-applying-operation", "meta": {"questionId": "2891", "questionFrontendId": "2779", "title": "Maximum Beauty of an Array After Applying Operation", "titleSlug": "maximum-beauty-of-an-array-after-applying-operation", "isPaidOnly": false, "difficulty": "Medium", "likes": 559, "dislikes": 12, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0 开始的整数数组 nums 和一个 非负 整数 k 。\n\n在一步操作中,你可以执行下述指令:\n\n * 在范围 [0, nums.length - 1] 中选择一个 此前没有选过 的下标 i 。\n * 将 nums[i] 替换为范围 [nums[i] - k, nums[i] + k] 内的任一整数。\n\n数组的 美丽值 定义为数组中由相等元素组成的最长子序列的长度。\n\n对数组 nums 执行上述操作任意次后,返回数组可能取得的 最大 美丽值。\n\n注意:你 只 能对每个下标执行 一次 此操作。\n\n数组的 子序列 定义是:经由原数组删除一些元素(也可能不删除)得到的一个新数组,且在此过程中剩余元素的顺序不发生改变。\n\n示例 1:\n\n输入:nums = [4,6,1,2], k = 2\n输出:3\n解释:在这个示例中,我们执行下述操作:\n- 选择下标 1 ,将其替换为 4(从范围 [4,8] 中选出),此时 nums = [4,4,1,2] 。\n- 选择下标 3 ,将其替换为 4(从范围 [0,4] 中选出),此时 nums = [4,4,1,4] 。\n执行上述操作后,数组的美丽值是 3(子序列由下标 0 、1 、3 对应的元素组成)。\n可以证明 3 是我们可以得到的由相等元素组成的最长子序列长度。\n\n示例 2:\n\n输入:nums = [1,1,1,1], k = 10\n输出:4\n解释:在这个示例中,我们无需执行任何操作。\n数组 nums 的美丽值是 4(整个数组)。\n\n\n提示:\n\n * 1 <= nums.length <= 105\n * 0 <= nums[i], k <= 105\n\"\"\"\nclass Solution:\n def maximumBeauty(self, nums: List[int], k: int) -> int:\n ", "prompt_sft": "给你一个下标从 0 开始的整数数组 nums 和一个 非负 整数 k 。\n\n在一步操作中,你可以执行下述指令:\n\n * 在范围 [0, nums.length - 1] 中选择一个 此前没有选过 的下标 i 。\n * 将 nums[i] 替换为范围 [nums[i] - k, nums[i] + k] 内的任一整数。\n\n数组的 美丽值 定义为数组中由相等元素组成的最长子序列的长度。\n\n对数组 nums 执行上述操作任意次后,返回数组可能取得的 最大 美丽值。\n\n注意:你 只 能对每个下标执行 一次 此操作。\n\n数组的 子序列 定义是:经由原数组删除一些元素(也可能不删除)得到的一个新数组,且在此过程中剩余元素的顺序不发生改变。\n\n示例 1:\n\n输入:nums = [4,6,1,2], k = 2\n输出:3\n解释:在这个示例中,我们执行下述操作:\n- 选择下标 1 ,将其替换为 4(从范围 [4,8] 中选出),此时 nums = [4,4,1,2] 。\n- 选择下标 3 ,将其替换为 4(从范围 [0,4] 中选出),此时 nums = [4,4,1,4] 。\n执行上述操作后,数组的美丽值是 3(子序列由下标 0 、1 、3 对应的元素组成)。\n可以证明 3 是我们可以得到的由相等元素组成的最长子序列长度。\n\n示例 2:\n\n输入:nums = [1,1,1,1], k = 10\n输出:4\n解释:在这个示例中,我们无需执行任何操作。\n数组 nums 的美丽值是 4(整个数组)。\n\n\n提示:\n\n * 1 <= nums.length <= 105\n * 0 <= nums[i], k <= 105\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def maximumBeauty(self, nums: List[int], k: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [4,6,1,2], \"k\": 2 }\nassert my_solution.maximumBeauty(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,1,1], \"k\": 10 }\nassert my_solution.maximumBeauty(**test_input) == 4\n\ntest_input = { \"nums\": [12,71], \"k\": 10 }\nassert my_solution.maximumBeauty(**test_input) == 1\n\ntest_input = { \"nums\": [27,55], \"k\": 1 }\nassert my_solution.maximumBeauty(**test_input) == 1\n\ntest_input = { \"nums\": [52,34], \"k\": 21 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [76,0], \"k\": 16 }\nassert my_solution.maximumBeauty(**test_input) == 1\n\ntest_input = { \"nums\": [56,40], \"k\": 26 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [49,26], \"k\": 12 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [69,66], \"k\": 14 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [64,98], \"k\": 12 }\nassert my_solution.maximumBeauty(**test_input) == 1\n\ntest_input = { \"nums\": [83,81], \"k\": 7 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [44,93], \"k\": 15 }\nassert my_solution.maximumBeauty(**test_input) == 1\n\ntest_input = { \"nums\": [44,31], \"k\": 26 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [70,60], \"k\": 15 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [60,22], \"k\": 11 }\nassert my_solution.maximumBeauty(**test_input) == 1\n\ntest_input = { \"nums\": [33,20], \"k\": 1 }\nassert my_solution.maximumBeauty(**test_input) == 1\n\ntest_input = { \"nums\": [64,24], \"k\": 4 }\nassert my_solution.maximumBeauty(**test_input) == 1\n\ntest_input = { \"nums\": [59,20], \"k\": 28 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [10,98], \"k\": 27 }\nassert my_solution.maximumBeauty(**test_input) == 1\n\ntest_input = { \"nums\": [54,21], \"k\": 20 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [61,11], \"k\": 15 }\nassert my_solution.maximumBeauty(**test_input) == 1\n\ntest_input = { \"nums\": [99,40], \"k\": 27 }\nassert my_solution.maximumBeauty(**test_input) == 1\n\ntest_input = { \"nums\": [32,91], \"k\": 3 }\nassert my_solution.maximumBeauty(**test_input) == 1\n\ntest_input = { \"nums\": [91,57], \"k\": 21 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [60,92], \"k\": 26 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [4,45], \"k\": 6 }\nassert my_solution.maximumBeauty(**test_input) == 1\n\ntest_input = { \"nums\": [24,35], \"k\": 6 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [11,29], \"k\": 3 }\nassert my_solution.maximumBeauty(**test_input) == 1\n\ntest_input = { \"nums\": [51,29], \"k\": 3 }\nassert my_solution.maximumBeauty(**test_input) == 1\n\ntest_input = { \"nums\": [43,21], \"k\": 14 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [32,25], \"k\": 18 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [13,66], \"k\": 5 }\nassert my_solution.maximumBeauty(**test_input) == 1\n\ntest_input = { \"nums\": [89,71], \"k\": 28 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [36,29], \"k\": 20 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [11,43], \"k\": 21 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [15,36], \"k\": 4 }\nassert my_solution.maximumBeauty(**test_input) == 1\n\ntest_input = { \"nums\": [11,51], \"k\": 1 }\nassert my_solution.maximumBeauty(**test_input) == 1\n\ntest_input = { \"nums\": [2,57], \"k\": 20 }\nassert my_solution.maximumBeauty(**test_input) == 1\n\ntest_input = { \"nums\": [94,66], \"k\": 26 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [87,51], \"k\": 8 }\nassert my_solution.maximumBeauty(**test_input) == 1\n\ntest_input = { \"nums\": [5,57,46], \"k\": 15 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [81,46,85], \"k\": 23 }\nassert my_solution.maximumBeauty(**test_input) == 3\n\ntest_input = { \"nums\": [51,83,0], \"k\": 11 }\nassert my_solution.maximumBeauty(**test_input) == 1\n\ntest_input = { \"nums\": [75,15,9], \"k\": 28 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [10,59,86], \"k\": 23 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [41,11,59], \"k\": 17 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [62,77,100], \"k\": 5 }\nassert my_solution.maximumBeauty(**test_input) == 1\n\ntest_input = { \"nums\": [27,35,15], \"k\": 6 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [81,76,40], \"k\": 5 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [84,43,96], \"k\": 7 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [62,1,93], \"k\": 30 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [13,46,71], \"k\": 29 }\nassert my_solution.maximumBeauty(**test_input) == 3\n\ntest_input = { \"nums\": [92,99,44], \"k\": 28 }\nassert my_solution.maximumBeauty(**test_input) == 3\n\ntest_input = { \"nums\": [73,30,40], \"k\": 26 }\nassert my_solution.maximumBeauty(**test_input) == 3\n\ntest_input = { \"nums\": [83,89,17], \"k\": 5 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [38,20,11], \"k\": 9 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [63,56,23], \"k\": 14 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [32,16,98], \"k\": 0 }\nassert my_solution.maximumBeauty(**test_input) == 1\n\ntest_input = { \"nums\": [57,58,71], \"k\": 2 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [61,50,35], \"k\": 2 }\nassert my_solution.maximumBeauty(**test_input) == 1\n\ntest_input = { \"nums\": [22,97,13], \"k\": 22 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [89,52,33], \"k\": 14 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [89,4,77], \"k\": 20 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [50,26,72], \"k\": 30 }\nassert my_solution.maximumBeauty(**test_input) == 3\n\ntest_input = { \"nums\": [72,75,47], \"k\": 7 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [23,1,73], \"k\": 25 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [36,74,20], \"k\": 20 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [34,64,11], \"k\": 18 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [29,94,45], \"k\": 27 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [22,80,34], \"k\": 28 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [52,63,75], \"k\": 11 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [53,63,93,89], \"k\": 23 }\nassert my_solution.maximumBeauty(**test_input) == 4\n\ntest_input = { \"nums\": [47,76,100,51], \"k\": 27 }\nassert my_solution.maximumBeauty(**test_input) == 4\n\ntest_input = { \"nums\": [73,83,46,88], \"k\": 13 }\nassert my_solution.maximumBeauty(**test_input) == 3\n\ntest_input = { \"nums\": [50,28,30,51], \"k\": 2 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [88,87,9,17], \"k\": 10 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [27,56,27,40], \"k\": 6 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [88,19,2,30], \"k\": 6 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [58,50,0,97], \"k\": 18 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [83,10,99,99], \"k\": 18 }\nassert my_solution.maximumBeauty(**test_input) == 3\n\ntest_input = { \"nums\": [58,75,1,25], \"k\": 12 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [77,35,1,69], \"k\": 15 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [23,33,62,20], \"k\": 12 }\nassert my_solution.maximumBeauty(**test_input) == 3\n\ntest_input = { \"nums\": [42,34,18,0], \"k\": 5 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [10,58,37,46], \"k\": 0 }\nassert my_solution.maximumBeauty(**test_input) == 1\n\ntest_input = { \"nums\": [34,73,57,55], \"k\": 27 }\nassert my_solution.maximumBeauty(**test_input) == 4\n\ntest_input = { \"nums\": [53,100,74,5], \"k\": 4 }\nassert my_solution.maximumBeauty(**test_input) == 1\n\ntest_input = { \"nums\": [48,93,96,19], \"k\": 24 }\nassert my_solution.maximumBeauty(**test_input) == 3\n\ntest_input = { \"nums\": [91,12,29,31], \"k\": 22 }\nassert my_solution.maximumBeauty(**test_input) == 3\n\ntest_input = { \"nums\": [48,9,35,36], \"k\": 12 }\nassert my_solution.maximumBeauty(**test_input) == 3\n\ntest_input = { \"nums\": [24,64,40,30], \"k\": 3 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [19,58,41,42], \"k\": 14 }\nassert my_solution.maximumBeauty(**test_input) == 3\n\ntest_input = { \"nums\": [72,44,29,76], \"k\": 4 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [37,19,10,16], \"k\": 16 }\nassert my_solution.maximumBeauty(**test_input) == 4\n\ntest_input = { \"nums\": [54,84,73,31], \"k\": 30 }\nassert my_solution.maximumBeauty(**test_input) == 4\n\ntest_input = { \"nums\": [83,92,30,60], \"k\": 19 }\nassert my_solution.maximumBeauty(**test_input) == 3\n\ntest_input = { \"nums\": [14,51,99,64], \"k\": 15 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [7,60,16,2], \"k\": 17 }\nassert my_solution.maximumBeauty(**test_input) == 3\n\ntest_input = { \"nums\": [7,89,54,54], \"k\": 5 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [43,86,33,18], \"k\": 23 }\nassert my_solution.maximumBeauty(**test_input) == 3", "start_time": 1689474600} +{"task_id": "weekly-contest-354-minimum-index-of-a-valid-split", "url": "https://leetcode.com/problems/minimum-index-of-a-valid-split", "title": "minimum-index-of-a-valid-split", "meta": {"questionId": "2888", "questionFrontendId": "2780", "title": "Minimum Index of a Valid Split", "titleSlug": "minimum-index-of-a-valid-split", "isPaidOnly": false, "difficulty": "Medium", "likes": 282, "dislikes": 11, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n如果元素 x 在长度为 m 的整数数组 arr 中满足 freq(x) * 2 > m ,那么我们称 x 是 支配元素 。其中 freq(x) 是 x 在数组 arr 中出现的次数。注意,根据这个定义,数组 arr 最多 只会有 一个 支配元素。\n\n给你一个下标从 0 开始长度为 n 的整数数组 nums ,数据保证它含有一个支配元素。\n\n你需要在下标 i 处将 nums 分割成两个数组 nums[0, ..., i] 和 nums[i + 1, ..., n - 1] ,如果一个分割满足以下条件,我们称它是 合法 的:\n\n * 0 <= i < n - 1\n * nums[0, ..., i] 和 nums[i + 1, ..., n - 1] 的支配元素相同。\n\n这里, nums[i, ..., j] 表示 nums 的一个子数组,它开始于下标 i ,结束于下标 j ,两个端点都包含在子数组内。特别地,如果 j < i ,那么 nums[i, ..., j] 表示一个空数组。\n\n请你返回一个 合法分割 的 最小 下标。如果合法分割不存在,返回 -1 。\n\n示例 1:\n\n输入:nums = [1,2,2,2]\n输出:2\n解释:我们将数组在下标 2 处分割,得到 [1,2,2] 和 [2] 。\n数组 [1,2,2] 中,元素 2 是支配元素,因为它在数组中出现了 2 次,且 2 * 2 > 3 。\n数组 [2] 中,元素 2 是支配元素,因为它在数组中出现了 1 次,且 1 * 2 > 1 。\n两个数组 [1,2,2] 和 [2] 都有与 nums 一样的支配元素,所以这是一个合法分割。\n下标 2 是合法分割中的最小下标。\n\n示例 2:\n\n输入:nums = [2,1,3,1,1,1,7,1,2,1]\n输出:4\n解释:我们将数组在下标 4 处分割,得到 [2,1,3,1,1] 和 [1,7,1,2,1] 。\n数组 [2,1,3,1,1] 中,元素 1 是支配元素,因为它在数组中出现了 3 次,且 3 * 2 > 5 。\n数组 [1,7,1,2,1] 中,元素 1 是支配元素,因为它在数组中出现了 3 次,且 3 * 2 > 5 。\n两个数组 [2,1,3,1,1] 和 [1,7,1,2,1] 都有与 nums 一样的支配元素,所以这是一个合法分割。\n下标 4 是所有合法分割中的最小下标。\n\n示例 3:\n\n输入:nums = [3,3,3,3,7,2,2]\n输出:-1\n解释:没有合法分割。\n\n\n提示:\n\n * 1 <= nums.length <= 105\n * 1 <= nums[i] <= 109\n * nums 有且只有一个支配元素。\n\"\"\"\nclass Solution:\n def minimumIndex(self, nums: List[int]) -> int:\n ", "prompt_sft": "如果元素 x 在长度为 m 的整数数组 arr 中满足 freq(x) * 2 > m ,那么我们称 x 是 支配元素 。其中 freq(x) 是 x 在数组 arr 中出现的次数。注意,根据这个定义,数组 arr 最多 只会有 一个 支配元素。\n\n给你一个下标从 0 开始长度为 n 的整数数组 nums ,数据保证它含有一个支配元素。\n\n你需要在下标 i 处将 nums 分割成两个数组 nums[0, ..., i] 和 nums[i + 1, ..., n - 1] ,如果一个分割满足以下条件,我们称它是 合法 的:\n\n * 0 <= i < n - 1\n * nums[0, ..., i] 和 nums[i + 1, ..., n - 1] 的支配元素相同。\n\n这里, nums[i, ..., j] 表示 nums 的一个子数组,它开始于下标 i ,结束于下标 j ,两个端点都包含在子数组内。特别地,如果 j < i ,那么 nums[i, ..., j] 表示一个空数组。\n\n请你返回一个 合法分割 的 最小 下标。如果合法分割不存在,返回 -1 。\n\n示例 1:\n\n输入:nums = [1,2,2,2]\n输出:2\n解释:我们将数组在下标 2 处分割,得到 [1,2,2] 和 [2] 。\n数组 [1,2,2] 中,元素 2 是支配元素,因为它在数组中出现了 2 次,且 2 * 2 > 3 。\n数组 [2] 中,元素 2 是支配元素,因为它在数组中出现了 1 次,且 1 * 2 > 1 。\n两个数组 [1,2,2] 和 [2] 都有与 nums 一样的支配元素,所以这是一个合法分割。\n下标 2 是合法分割中的最小下标。\n\n示例 2:\n\n输入:nums = [2,1,3,1,1,1,7,1,2,1]\n输出:4\n解释:我们将数组在下标 4 处分割,得到 [2,1,3,1,1] 和 [1,7,1,2,1] 。\n数组 [2,1,3,1,1] 中,元素 1 是支配元素,因为它在数组中出现了 3 次,且 3 * 2 > 5 。\n数组 [1,7,1,2,1] 中,元素 1 是支配元素,因为它在数组中出现了 3 次,且 3 * 2 > 5 。\n两个数组 [2,1,3,1,1] 和 [1,7,1,2,1] 都有与 nums 一样的支配元素,所以这是一个合法分割。\n下标 4 是所有合法分割中的最小下标。\n\n示例 3:\n\n输入:nums = [3,3,3,3,7,2,2]\n输出:-1\n解释:没有合法分割。\n\n\n提示:\n\n * 1 <= nums.length <= 105\n * 1 <= nums[i] <= 109\n * nums 有且只有一个支配元素。\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def minimumIndex(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,2,2,2] }\nassert my_solution.minimumIndex(**test_input) == 2\n\ntest_input = { \"nums\": [2,1,3,1,1,1,7,1,2,1] }\nassert my_solution.minimumIndex(**test_input) == 4\n\ntest_input = { \"nums\": [3,3,3,3,7,2,2] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [1] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [1,1] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,1] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,1,1] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,1,2] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,1,3] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,1,4] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,2] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,2,1] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,3] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,3,1] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,4] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,4,1] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [1,2,1] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [1,2,1,1] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [1,2,2] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [1,3,1] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [1,3,1,1] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [1,3,3] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [1,3,3,3] }\nassert my_solution.minimumIndex(**test_input) == 2\n\ntest_input = { \"nums\": [1,4,1] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [1,4,1,1] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [1,4,4] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [1,4,4,4] }\nassert my_solution.minimumIndex(**test_input) == 2\n\ntest_input = { \"nums\": [2] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [2,1,1] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [2,1,1,1] }\nassert my_solution.minimumIndex(**test_input) == 2\n\ntest_input = { \"nums\": [2,1,2] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [2,1,2,2] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [2,2] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [2,2,1] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [2,2,1,2] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [2,2,2] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [2,2,2,1] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [2,2,2,2] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [2,2,2,3] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [2,2,2,4] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [2,2,3] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [2,2,3,2] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [2,2,4] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [2,2,4,2] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [2,3,2] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [2,3,2,2] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [2,3,3] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [2,3,3,3] }\nassert my_solution.minimumIndex(**test_input) == 2\n\ntest_input = { \"nums\": [2,4,2] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [2,4,2,2] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [2,4,4] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [2,4,4,4] }\nassert my_solution.minimumIndex(**test_input) == 2\n\ntest_input = { \"nums\": [3] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [3,1,1] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [3,1,1,1] }\nassert my_solution.minimumIndex(**test_input) == 2\n\ntest_input = { \"nums\": [3,1,3] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [3,1,3,3] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [3,2,2] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [3,2,2,2] }\nassert my_solution.minimumIndex(**test_input) == 2\n\ntest_input = { \"nums\": [3,2,3] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [3,2,3,3] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [3,3] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [3,3,1] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [3,3,1,3] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [3,3,2] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [3,3,2,3] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [3,3,3] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [3,3,3,1] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [3,3,3,2] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [3,3,3,3] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [3,3,3,4] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [3,3,4] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [3,3,4,3] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [3,4,3] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [3,4,3,3] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [3,4,4] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [3,4,4,4] }\nassert my_solution.minimumIndex(**test_input) == 2\n\ntest_input = { \"nums\": [4] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [4,1,1] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [4,1,1,1] }\nassert my_solution.minimumIndex(**test_input) == 2\n\ntest_input = { \"nums\": [4,1,4] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [4,1,4,4] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [4,2,2] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [4,2,2,2] }\nassert my_solution.minimumIndex(**test_input) == 2\n\ntest_input = { \"nums\": [4,2,4] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [4,2,4,4] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [4,3,3] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [4,3,3,3] }\nassert my_solution.minimumIndex(**test_input) == 2\n\ntest_input = { \"nums\": [4,3,4] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [4,3,4,4] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [4,4] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [4,4,1] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [4,4,1,4] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [4,4,2] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [4,4,2,4] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [4,4,3] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [4,4,3,4] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [4,4,4] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [4,4,4,1] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [4,4,4,2] }\nassert my_solution.minimumIndex(**test_input) == 0", "start_time": 1689474600} +{"task_id": "weekly-contest-354-length-of-the-longest-valid-substring", "url": "https://leetcode.com/problems/length-of-the-longest-valid-substring", "title": "length-of-the-longest-valid-substring", "meta": {"questionId": "2884", "questionFrontendId": "2781", "title": "Length of the Longest Valid Substring", "titleSlug": "length-of-the-longest-valid-substring", "isPaidOnly": false, "difficulty": "Hard", "likes": 447, "dislikes": 9, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个字符串 word 和一个字符串数组 forbidden 。\n\n如果一个字符串不包含 forbidden 中的任何字符串,我们称这个字符串是 合法 的。\n\n请你返回字符串 word 的一个 最长合法子字符串 的长度。\n\n子字符串 指的是一个字符串中一段连续的字符,它可以为空。\n\n示例 1:\n\n输入:word = \"cbaaaabc\", forbidden = [\"aaa\",\"cb\"]\n输出:4\n解释:总共有 11 个合法子字符串:\"c\", \"b\", \"a\", \"ba\", \"aa\", \"bc\", \"baa\", \"aab\", \"ab\", \"abc\" 和 \"aabc\"。最长合法子字符串的长度为 4 。\n其他子字符串都要么包含 \"aaa\" ,要么包含 \"cb\" 。\n\n示例 2:\n\n输入:word = \"leetcode\", forbidden = [\"de\",\"le\",\"e\"]\n输出:4\n解释:总共有 11 个合法子字符串:\"l\" ,\"t\" ,\"c\" ,\"o\" ,\"d\" ,\"tc\" ,\"co\" ,\"od\" ,\"tco\" ,\"cod\" 和 \"tcod\" 。最长合法子字符串的长度为 4 。\n所有其他子字符串都至少包含 \"de\" ,\"le\" 和 \"e\" 之一。\n\n\n提示:\n\n * 1 <= word.length <= 105\n * word 只包含小写英文字母。\n * 1 <= forbidden.length <= 105\n * 1 <= forbidden[i].length <= 10\n * forbidden[i] 只包含小写英文字母。\n\"\"\"\nclass Solution:\n def longestValidSubstring(self, word: str, forbidden: List[str]) -> int:\n ", "prompt_sft": "给你一个字符串 word 和一个字符串数组 forbidden 。\n\n如果一个字符串不包含 forbidden 中的任何字符串,我们称这个字符串是 合法 的。\n\n请你返回字符串 word 的一个 最长合法子字符串 的长度。\n\n子字符串 指的是一个字符串中一段连续的字符,它可以为空。\n\n示例 1:\n\n输入:word = \"cbaaaabc\", forbidden = [\"aaa\",\"cb\"]\n输出:4\n解释:总共有 11 个合法子字符串:\"c\", \"b\", \"a\", \"ba\", \"aa\", \"bc\", \"baa\", \"aab\", \"ab\", \"abc\" 和 \"aabc\"。最长合法子字符串的长度为 4 。\n其他子字符串都要么包含 \"aaa\" ,要么包含 \"cb\" 。\n\n示例 2:\n\n输入:word = \"leetcode\", forbidden = [\"de\",\"le\",\"e\"]\n输出:4\n解释:总共有 11 个合法子字符串:\"l\" ,\"t\" ,\"c\" ,\"o\" ,\"d\" ,\"tc\" ,\"co\" ,\"od\" ,\"tco\" ,\"cod\" 和 \"tcod\" 。最长合法子字符串的长度为 4 。\n所有其他子字符串都至少包含 \"de\" ,\"le\" 和 \"e\" 之一。\n\n\n提示:\n\n * 1 <= word.length <= 105\n * word 只包含小写英文字母。\n * 1 <= forbidden.length <= 105\n * 1 <= forbidden[i].length <= 10\n * forbidden[i] 只包含小写英文字母。\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def longestValidSubstring(self, word: str, forbidden: List[str]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"word\": \"cbaaaabc\", \"forbidden\": [\"aaa\",\"cb\"] }\nassert my_solution.longestValidSubstring(**test_input) == 4\n\ntest_input = { \"word\": \"leetcode\", \"forbidden\": [\"de\",\"le\",\"e\"] }\nassert my_solution.longestValidSubstring(**test_input) == 4\n\ntest_input = { \"word\": \"a\", \"forbidden\": [\"n\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"a\", \"forbidden\": [\"s\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"a\", \"forbidden\": [\"a\"] }\nassert my_solution.longestValidSubstring(**test_input) == 0\n\ntest_input = { \"word\": \"b\", \"forbidden\": [\"g\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"b\", \"forbidden\": [\"t\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"b\", \"forbidden\": [\"b\"] }\nassert my_solution.longestValidSubstring(**test_input) == 0\n\ntest_input = { \"word\": \"c\", \"forbidden\": [\"k\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"c\", \"forbidden\": [\"s\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"c\", \"forbidden\": [\"c\"] }\nassert my_solution.longestValidSubstring(**test_input) == 0\n\ntest_input = { \"word\": \"d\", \"forbidden\": [\"h\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"d\", \"forbidden\": [\"n\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"d\", \"forbidden\": [\"d\"] }\nassert my_solution.longestValidSubstring(**test_input) == 0\n\ntest_input = { \"word\": \"e\", \"forbidden\": [\"s\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"e\", \"forbidden\": [\"e\"] }\nassert my_solution.longestValidSubstring(**test_input) == 0\n\ntest_input = { \"word\": \"f\", \"forbidden\": [\"b\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"f\", \"forbidden\": [\"s\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"f\", \"forbidden\": [\"f\"] }\nassert my_solution.longestValidSubstring(**test_input) == 0\n\ntest_input = { \"word\": \"g\", \"forbidden\": [\"r\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"g\", \"forbidden\": [\"y\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"g\", \"forbidden\": [\"g\"] }\nassert my_solution.longestValidSubstring(**test_input) == 0\n\ntest_input = { \"word\": \"h\", \"forbidden\": [\"v\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"h\", \"forbidden\": [\"b\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"h\", \"forbidden\": [\"h\"] }\nassert my_solution.longestValidSubstring(**test_input) == 0\n\ntest_input = { \"word\": \"i\", \"forbidden\": [\"k\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"i\", \"forbidden\": [\"y\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"i\", \"forbidden\": [\"i\"] }\nassert my_solution.longestValidSubstring(**test_input) == 0\n\ntest_input = { \"word\": \"j\", \"forbidden\": [\"v\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"j\", \"forbidden\": [\"u\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"j\", \"forbidden\": [\"j\"] }\nassert my_solution.longestValidSubstring(**test_input) == 0\n\ntest_input = { \"word\": \"k\", \"forbidden\": [\"z\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"k\", \"forbidden\": [\"o\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"k\", \"forbidden\": [\"k\"] }\nassert my_solution.longestValidSubstring(**test_input) == 0\n\ntest_input = { \"word\": \"l\", \"forbidden\": [\"i\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"l\", \"forbidden\": [\"r\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"l\", \"forbidden\": [\"l\"] }\nassert my_solution.longestValidSubstring(**test_input) == 0\n\ntest_input = { \"word\": \"m\", \"forbidden\": [\"s\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"m\", \"forbidden\": [\"g\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"m\", \"forbidden\": [\"m\"] }\nassert my_solution.longestValidSubstring(**test_input) == 0\n\ntest_input = { \"word\": \"n\", \"forbidden\": [\"e\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"n\", \"forbidden\": [\"i\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"n\", \"forbidden\": [\"n\"] }\nassert my_solution.longestValidSubstring(**test_input) == 0\n\ntest_input = { \"word\": \"o\", \"forbidden\": [\"j\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"o\", \"forbidden\": [\"f\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"o\", \"forbidden\": [\"o\"] }\nassert my_solution.longestValidSubstring(**test_input) == 0\n\ntest_input = { \"word\": \"p\", \"forbidden\": [\"z\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"p\", \"forbidden\": [\"i\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"p\", \"forbidden\": [\"p\"] }\nassert my_solution.longestValidSubstring(**test_input) == 0\n\ntest_input = { \"word\": \"q\", \"forbidden\": [\"j\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"q\", \"forbidden\": [\"z\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"q\", \"forbidden\": [\"q\"] }\nassert my_solution.longestValidSubstring(**test_input) == 0\n\ntest_input = { \"word\": \"r\", \"forbidden\": [\"v\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"r\", \"forbidden\": [\"p\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"r\", \"forbidden\": [\"r\"] }\nassert my_solution.longestValidSubstring(**test_input) == 0\n\ntest_input = { \"word\": \"s\", \"forbidden\": [\"m\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"s\", \"forbidden\": [\"x\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"s\", \"forbidden\": [\"s\"] }\nassert my_solution.longestValidSubstring(**test_input) == 0\n\ntest_input = { \"word\": \"t\", \"forbidden\": [\"v\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"t\", \"forbidden\": [\"m\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"t\", \"forbidden\": [\"t\"] }\nassert my_solution.longestValidSubstring(**test_input) == 0\n\ntest_input = { \"word\": \"u\", \"forbidden\": [\"l\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"u\", \"forbidden\": [\"n\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"u\", \"forbidden\": [\"u\"] }\nassert my_solution.longestValidSubstring(**test_input) == 0\n\ntest_input = { \"word\": \"v\", \"forbidden\": [\"o\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"v\", \"forbidden\": [\"v\"] }\nassert my_solution.longestValidSubstring(**test_input) == 0\n\ntest_input = { \"word\": \"w\", \"forbidden\": [\"w\"] }\nassert my_solution.longestValidSubstring(**test_input) == 0\n\ntest_input = { \"word\": \"w\", \"forbidden\": [\"s\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"x\", \"forbidden\": [\"r\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"x\", \"forbidden\": [\"q\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"x\", \"forbidden\": [\"x\"] }\nassert my_solution.longestValidSubstring(**test_input) == 0\n\ntest_input = { \"word\": \"y\", \"forbidden\": [\"w\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"y\", \"forbidden\": [\"t\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"y\", \"forbidden\": [\"y\"] }\nassert my_solution.longestValidSubstring(**test_input) == 0\n\ntest_input = { \"word\": \"z\", \"forbidden\": [\"l\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"z\", \"forbidden\": [\"o\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"z\", \"forbidden\": [\"z\"] }\nassert my_solution.longestValidSubstring(**test_input) == 0\n\ntest_input = { \"word\": \"acbc\", \"forbidden\": [\"cbc\",\"acb\",\"acb\",\"acbc\"] }\nassert my_solution.longestValidSubstring(**test_input) == 2\n\ntest_input = { \"word\": \"cabba\", \"forbidden\": [\"aaba\",\"abba\",\"acabb\",\"cabb\"] }\nassert my_solution.longestValidSubstring(**test_input) == 3\n\ntest_input = { \"word\": \"bbc\", \"forbidden\": [\"baba\",\"babc\",\"bbc\",\"bbc\"] }\nassert my_solution.longestValidSubstring(**test_input) == 2\n\ntest_input = { \"word\": \"acb\", \"forbidden\": [\"acb\",\"caccc\",\"baaab\",\"baa\"] }\nassert my_solution.longestValidSubstring(**test_input) == 2\n\ntest_input = { \"word\": \"aaac\", \"forbidden\": [\"aaac\",\"aac\",\"aaa\",\"aaac\"] }\nassert my_solution.longestValidSubstring(**test_input) == 2\n\ntest_input = { \"word\": \"ca\", \"forbidden\": [\"ababa\",\"ca\",\"caac\",\"babb\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"babbb\", \"forbidden\": [\"bbb\",\"aacb\",\"babbb\",\"bcab\"] }\nassert my_solution.longestValidSubstring(**test_input) == 4\n\ntest_input = { \"word\": \"cbbba\", \"forbidden\": [\"bca\",\"cbbba\",\"acbcc\",\"aabb\"] }\nassert my_solution.longestValidSubstring(**test_input) == 4\n\ntest_input = { \"word\": \"abab\", \"forbidden\": [\"aab\",\"abab\",\"cacb\",\"bab\"] }\nassert my_solution.longestValidSubstring(**test_input) == 3\n\ntest_input = { \"word\": \"cbab\", \"forbidden\": [\"bbcc\",\"aaccc\",\"cbab\",\"babca\"] }\nassert my_solution.longestValidSubstring(**test_input) == 3\n\ntest_input = { \"word\": \"caaa\", \"forbidden\": [\"aaa\",\"cbb\",\"aaa\",\"caaa\"] }\nassert my_solution.longestValidSubstring(**test_input) == 3\n\ntest_input = { \"word\": \"baa\", \"forbidden\": [\"aaab\",\"bbaa\",\"babac\",\"baa\"] }\nassert my_solution.longestValidSubstring(**test_input) == 2\n\ntest_input = { \"word\": \"cbcc\", \"forbidden\": [\"cbcc\",\"baa\",\"bbba\",\"cac\"] }\nassert my_solution.longestValidSubstring(**test_input) == 3\n\ntest_input = { \"word\": \"cac\", \"forbidden\": [\"cccaa\",\"baaca\",\"cac\",\"cac\"] }\nassert my_solution.longestValidSubstring(**test_input) == 2\n\ntest_input = { \"word\": \"cabab\", \"forbidden\": [\"cabab\",\"abab\",\"cabab\",\"abab\"] }\nassert my_solution.longestValidSubstring(**test_input) == 4\n\ntest_input = { \"word\": \"caa\", \"forbidden\": [\"caa\",\"bba\",\"acc\",\"bcabb\"] }\nassert my_solution.longestValidSubstring(**test_input) == 2\n\ntest_input = { \"word\": \"ba\", \"forbidden\": [\"ba\",\"ba\",\"cab\",\"cbcac\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"bbc\", \"forbidden\": [\"baca\",\"bbc\",\"bbc\",\"caa\"] }\nassert my_solution.longestValidSubstring(**test_input) == 2\n\ntest_input = { \"word\": \"bbb\", \"forbidden\": [\"cbaab\",\"bbb\",\"bbb\",\"bab\"] }\nassert my_solution.longestValidSubstring(**test_input) == 2\n\ntest_input = { \"word\": \"bbccc\", \"forbidden\": [\"ccc\",\"bcba\",\"bcc\",\"bcc\"] }\nassert my_solution.longestValidSubstring(**test_input) == 3\n\ntest_input = { \"word\": \"bcac\", \"forbidden\": [\"bcac\",\"caca\",\"bcac\",\"bca\"] }\nassert my_solution.longestValidSubstring(**test_input) == 3\n\ntest_input = { \"word\": \"ab\", \"forbidden\": [\"aca\",\"cabcc\",\"caba\",\"ab\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"caa\", \"forbidden\": [\"bab\",\"babbb\",\"abbaa\",\"caa\"] }\nassert my_solution.longestValidSubstring(**test_input) == 2", "start_time": 1689474600} +{"task_id": "weekly-contest-353-find-the-maximum-achievable-number", "url": "https://leetcode.com/problems/find-the-maximum-achievable-number", "title": "find-the-maximum-achievable-number", "meta": {"questionId": "2812", "questionFrontendId": "2769", "title": "Find the Maximum Achievable Number", "titleSlug": "find-the-maximum-achievable-number", "isPaidOnly": false, "difficulty": "Easy", "likes": 230, "dislikes": 286, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你两个整数 num 和 t 。\n\n如果整数 x 可以在执行下述操作不超过 t 次的情况下变为与 num 相等,则称其为 可达成数字 :\n\n * 每次操作将 x 的值增加或减少 1 ,同时可以选择将 num 的值增加或减少 1 。\n\n返回所有可达成数字中的最大值。可以证明至少存在一个可达成数字。\n\n示例 1:\n\n输入:num = 4, t = 1\n输出:6\n解释:最大可达成数字是 x = 6 ,执行下述操作可以使其等于 num :\n- x 减少 1 ,同时 num 增加 1 。此时,x = 5 且 num = 5 。\n可以证明不存在大于 6 的可达成数字。\n\n示例 2:\n\n输入:num = 3, t = 2\n输出:7\n解释:最大的可达成数字是 x = 7 ,执行下述操作可以使其等于 num :\n- x 减少 1 ,同时 num 增加 1 。此时,x = 6 且 num = 4 。\n- x 减少 1 ,同时 num 增加 1 。此时,x = 5 且 num = 5 。\n可以证明不存在大于 7 的可达成数字。\n\n\n提示:\n\n * 1 <= num, t <= 50\n\"\"\"\nclass Solution:\n def theMaximumAchievableX(self, num: int, t: int) -> int:\n ", "prompt_sft": "给你两个整数 num 和 t 。\n\n如果整数 x 可以在执行下述操作不超过 t 次的情况下变为与 num 相等,则称其为 可达成数字 :\n\n * 每次操作将 x 的值增加或减少 1 ,同时可以选择将 num 的值增加或减少 1 。\n\n返回所有可达成数字中的最大值。可以证明至少存在一个可达成数字。\n\n示例 1:\n\n输入:num = 4, t = 1\n输出:6\n解释:最大可达成数字是 x = 6 ,执行下述操作可以使其等于 num :\n- x 减少 1 ,同时 num 增加 1 。此时,x = 5 且 num = 5 。\n可以证明不存在大于 6 的可达成数字。\n\n示例 2:\n\n输入:num = 3, t = 2\n输出:7\n解释:最大的可达成数字是 x = 7 ,执行下述操作可以使其等于 num :\n- x 减少 1 ,同时 num 增加 1 。此时,x = 6 且 num = 4 。\n- x 减少 1 ,同时 num 增加 1 。此时,x = 5 且 num = 5 。\n可以证明不存在大于 7 的可达成数字。\n\n\n提示:\n\n * 1 <= num, t <= 50\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def theMaximumAchievableX(self, num: int, t: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"num\": 4, \"t\": 1 }\nassert my_solution.theMaximumAchievableX(**test_input) == 6\n\ntest_input = { \"num\": 3, \"t\": 2 }\nassert my_solution.theMaximumAchievableX(**test_input) == 7\n\ntest_input = { \"num\": 1, \"t\": 1 }\nassert my_solution.theMaximumAchievableX(**test_input) == 3\n\ntest_input = { \"num\": 1, \"t\": 2 }\nassert my_solution.theMaximumAchievableX(**test_input) == 5\n\ntest_input = { \"num\": 1, \"t\": 3 }\nassert my_solution.theMaximumAchievableX(**test_input) == 7\n\ntest_input = { \"num\": 1, \"t\": 4 }\nassert my_solution.theMaximumAchievableX(**test_input) == 9\n\ntest_input = { \"num\": 1, \"t\": 5 }\nassert my_solution.theMaximumAchievableX(**test_input) == 11\n\ntest_input = { \"num\": 1, \"t\": 6 }\nassert my_solution.theMaximumAchievableX(**test_input) == 13\n\ntest_input = { \"num\": 1, \"t\": 7 }\nassert my_solution.theMaximumAchievableX(**test_input) == 15\n\ntest_input = { \"num\": 1, \"t\": 8 }\nassert my_solution.theMaximumAchievableX(**test_input) == 17\n\ntest_input = { \"num\": 1, \"t\": 9 }\nassert my_solution.theMaximumAchievableX(**test_input) == 19\n\ntest_input = { \"num\": 1, \"t\": 10 }\nassert my_solution.theMaximumAchievableX(**test_input) == 21\n\ntest_input = { \"num\": 1, \"t\": 11 }\nassert my_solution.theMaximumAchievableX(**test_input) == 23\n\ntest_input = { \"num\": 1, \"t\": 12 }\nassert my_solution.theMaximumAchievableX(**test_input) == 25\n\ntest_input = { \"num\": 1, \"t\": 13 }\nassert my_solution.theMaximumAchievableX(**test_input) == 27\n\ntest_input = { \"num\": 1, \"t\": 14 }\nassert my_solution.theMaximumAchievableX(**test_input) == 29\n\ntest_input = { \"num\": 1, \"t\": 15 }\nassert my_solution.theMaximumAchievableX(**test_input) == 31\n\ntest_input = { \"num\": 1, \"t\": 16 }\nassert my_solution.theMaximumAchievableX(**test_input) == 33\n\ntest_input = { \"num\": 1, \"t\": 17 }\nassert my_solution.theMaximumAchievableX(**test_input) == 35\n\ntest_input = { \"num\": 1, \"t\": 18 }\nassert my_solution.theMaximumAchievableX(**test_input) == 37\n\ntest_input = { \"num\": 1, \"t\": 19 }\nassert my_solution.theMaximumAchievableX(**test_input) == 39\n\ntest_input = { \"num\": 1, \"t\": 20 }\nassert my_solution.theMaximumAchievableX(**test_input) == 41\n\ntest_input = { \"num\": 1, \"t\": 21 }\nassert my_solution.theMaximumAchievableX(**test_input) == 43\n\ntest_input = { \"num\": 1, \"t\": 22 }\nassert my_solution.theMaximumAchievableX(**test_input) == 45\n\ntest_input = { \"num\": 1, \"t\": 23 }\nassert my_solution.theMaximumAchievableX(**test_input) == 47\n\ntest_input = { \"num\": 1, \"t\": 24 }\nassert my_solution.theMaximumAchievableX(**test_input) == 49\n\ntest_input = { \"num\": 1, \"t\": 25 }\nassert my_solution.theMaximumAchievableX(**test_input) == 51\n\ntest_input = { \"num\": 1, \"t\": 26 }\nassert my_solution.theMaximumAchievableX(**test_input) == 53\n\ntest_input = { \"num\": 1, \"t\": 27 }\nassert my_solution.theMaximumAchievableX(**test_input) == 55\n\ntest_input = { \"num\": 1, \"t\": 28 }\nassert my_solution.theMaximumAchievableX(**test_input) == 57\n\ntest_input = { \"num\": 1, \"t\": 29 }\nassert my_solution.theMaximumAchievableX(**test_input) == 59\n\ntest_input = { \"num\": 1, \"t\": 30 }\nassert my_solution.theMaximumAchievableX(**test_input) == 61\n\ntest_input = { \"num\": 1, \"t\": 31 }\nassert my_solution.theMaximumAchievableX(**test_input) == 63\n\ntest_input = { \"num\": 1, \"t\": 32 }\nassert my_solution.theMaximumAchievableX(**test_input) == 65\n\ntest_input = { \"num\": 1, \"t\": 33 }\nassert my_solution.theMaximumAchievableX(**test_input) == 67\n\ntest_input = { \"num\": 1, \"t\": 34 }\nassert my_solution.theMaximumAchievableX(**test_input) == 69\n\ntest_input = { \"num\": 1, \"t\": 35 }\nassert my_solution.theMaximumAchievableX(**test_input) == 71\n\ntest_input = { \"num\": 1, \"t\": 36 }\nassert my_solution.theMaximumAchievableX(**test_input) == 73\n\ntest_input = { \"num\": 1, \"t\": 37 }\nassert my_solution.theMaximumAchievableX(**test_input) == 75\n\ntest_input = { \"num\": 1, \"t\": 38 }\nassert my_solution.theMaximumAchievableX(**test_input) == 77\n\ntest_input = { \"num\": 1, \"t\": 39 }\nassert my_solution.theMaximumAchievableX(**test_input) == 79\n\ntest_input = { \"num\": 1, \"t\": 40 }\nassert my_solution.theMaximumAchievableX(**test_input) == 81\n\ntest_input = { \"num\": 1, \"t\": 41 }\nassert my_solution.theMaximumAchievableX(**test_input) == 83\n\ntest_input = { \"num\": 1, \"t\": 42 }\nassert my_solution.theMaximumAchievableX(**test_input) == 85\n\ntest_input = { \"num\": 1, \"t\": 43 }\nassert my_solution.theMaximumAchievableX(**test_input) == 87\n\ntest_input = { \"num\": 1, \"t\": 44 }\nassert my_solution.theMaximumAchievableX(**test_input) == 89\n\ntest_input = { \"num\": 1, \"t\": 45 }\nassert my_solution.theMaximumAchievableX(**test_input) == 91\n\ntest_input = { \"num\": 1, \"t\": 46 }\nassert my_solution.theMaximumAchievableX(**test_input) == 93\n\ntest_input = { \"num\": 1, \"t\": 47 }\nassert my_solution.theMaximumAchievableX(**test_input) == 95\n\ntest_input = { \"num\": 1, \"t\": 48 }\nassert my_solution.theMaximumAchievableX(**test_input) == 97\n\ntest_input = { \"num\": 1, \"t\": 49 }\nassert my_solution.theMaximumAchievableX(**test_input) == 99\n\ntest_input = { \"num\": 1, \"t\": 50 }\nassert my_solution.theMaximumAchievableX(**test_input) == 101\n\ntest_input = { \"num\": 2, \"t\": 1 }\nassert my_solution.theMaximumAchievableX(**test_input) == 4\n\ntest_input = { \"num\": 2, \"t\": 2 }\nassert my_solution.theMaximumAchievableX(**test_input) == 6\n\ntest_input = { \"num\": 2, \"t\": 3 }\nassert my_solution.theMaximumAchievableX(**test_input) == 8\n\ntest_input = { \"num\": 2, \"t\": 4 }\nassert my_solution.theMaximumAchievableX(**test_input) == 10\n\ntest_input = { \"num\": 2, \"t\": 5 }\nassert my_solution.theMaximumAchievableX(**test_input) == 12\n\ntest_input = { \"num\": 2, \"t\": 6 }\nassert my_solution.theMaximumAchievableX(**test_input) == 14\n\ntest_input = { \"num\": 2, \"t\": 7 }\nassert my_solution.theMaximumAchievableX(**test_input) == 16\n\ntest_input = { \"num\": 2, \"t\": 8 }\nassert my_solution.theMaximumAchievableX(**test_input) == 18\n\ntest_input = { \"num\": 2, \"t\": 9 }\nassert my_solution.theMaximumAchievableX(**test_input) == 20\n\ntest_input = { \"num\": 2, \"t\": 10 }\nassert my_solution.theMaximumAchievableX(**test_input) == 22\n\ntest_input = { \"num\": 2, \"t\": 11 }\nassert my_solution.theMaximumAchievableX(**test_input) == 24\n\ntest_input = { \"num\": 2, \"t\": 12 }\nassert my_solution.theMaximumAchievableX(**test_input) == 26\n\ntest_input = { \"num\": 2, \"t\": 13 }\nassert my_solution.theMaximumAchievableX(**test_input) == 28\n\ntest_input = { \"num\": 2, \"t\": 14 }\nassert my_solution.theMaximumAchievableX(**test_input) == 30\n\ntest_input = { \"num\": 2, \"t\": 15 }\nassert my_solution.theMaximumAchievableX(**test_input) == 32\n\ntest_input = { \"num\": 2, \"t\": 16 }\nassert my_solution.theMaximumAchievableX(**test_input) == 34\n\ntest_input = { \"num\": 2, \"t\": 17 }\nassert my_solution.theMaximumAchievableX(**test_input) == 36\n\ntest_input = { \"num\": 2, \"t\": 18 }\nassert my_solution.theMaximumAchievableX(**test_input) == 38\n\ntest_input = { \"num\": 2, \"t\": 19 }\nassert my_solution.theMaximumAchievableX(**test_input) == 40\n\ntest_input = { \"num\": 2, \"t\": 20 }\nassert my_solution.theMaximumAchievableX(**test_input) == 42\n\ntest_input = { \"num\": 2, \"t\": 21 }\nassert my_solution.theMaximumAchievableX(**test_input) == 44\n\ntest_input = { \"num\": 2, \"t\": 22 }\nassert my_solution.theMaximumAchievableX(**test_input) == 46\n\ntest_input = { \"num\": 2, \"t\": 23 }\nassert my_solution.theMaximumAchievableX(**test_input) == 48\n\ntest_input = { \"num\": 2, \"t\": 24 }\nassert my_solution.theMaximumAchievableX(**test_input) == 50\n\ntest_input = { \"num\": 2, \"t\": 25 }\nassert my_solution.theMaximumAchievableX(**test_input) == 52\n\ntest_input = { \"num\": 2, \"t\": 26 }\nassert my_solution.theMaximumAchievableX(**test_input) == 54\n\ntest_input = { \"num\": 2, \"t\": 27 }\nassert my_solution.theMaximumAchievableX(**test_input) == 56\n\ntest_input = { \"num\": 2, \"t\": 28 }\nassert my_solution.theMaximumAchievableX(**test_input) == 58\n\ntest_input = { \"num\": 2, \"t\": 29 }\nassert my_solution.theMaximumAchievableX(**test_input) == 60\n\ntest_input = { \"num\": 2, \"t\": 30 }\nassert my_solution.theMaximumAchievableX(**test_input) == 62\n\ntest_input = { \"num\": 2, \"t\": 31 }\nassert my_solution.theMaximumAchievableX(**test_input) == 64\n\ntest_input = { \"num\": 2, \"t\": 32 }\nassert my_solution.theMaximumAchievableX(**test_input) == 66\n\ntest_input = { \"num\": 2, \"t\": 33 }\nassert my_solution.theMaximumAchievableX(**test_input) == 68\n\ntest_input = { \"num\": 2, \"t\": 34 }\nassert my_solution.theMaximumAchievableX(**test_input) == 70\n\ntest_input = { \"num\": 2, \"t\": 35 }\nassert my_solution.theMaximumAchievableX(**test_input) == 72\n\ntest_input = { \"num\": 2, \"t\": 36 }\nassert my_solution.theMaximumAchievableX(**test_input) == 74\n\ntest_input = { \"num\": 2, \"t\": 37 }\nassert my_solution.theMaximumAchievableX(**test_input) == 76\n\ntest_input = { \"num\": 2, \"t\": 38 }\nassert my_solution.theMaximumAchievableX(**test_input) == 78\n\ntest_input = { \"num\": 2, \"t\": 39 }\nassert my_solution.theMaximumAchievableX(**test_input) == 80\n\ntest_input = { \"num\": 2, \"t\": 40 }\nassert my_solution.theMaximumAchievableX(**test_input) == 82\n\ntest_input = { \"num\": 2, \"t\": 41 }\nassert my_solution.theMaximumAchievableX(**test_input) == 84\n\ntest_input = { \"num\": 2, \"t\": 42 }\nassert my_solution.theMaximumAchievableX(**test_input) == 86\n\ntest_input = { \"num\": 2, \"t\": 43 }\nassert my_solution.theMaximumAchievableX(**test_input) == 88\n\ntest_input = { \"num\": 2, \"t\": 44 }\nassert my_solution.theMaximumAchievableX(**test_input) == 90\n\ntest_input = { \"num\": 2, \"t\": 45 }\nassert my_solution.theMaximumAchievableX(**test_input) == 92\n\ntest_input = { \"num\": 2, \"t\": 46 }\nassert my_solution.theMaximumAchievableX(**test_input) == 94\n\ntest_input = { \"num\": 2, \"t\": 47 }\nassert my_solution.theMaximumAchievableX(**test_input) == 96\n\ntest_input = { \"num\": 2, \"t\": 48 }\nassert my_solution.theMaximumAchievableX(**test_input) == 98", "start_time": 1688869800} +{"task_id": "weekly-contest-353-maximum-number-of-jumps-to-reach-the-last-index", "url": "https://leetcode.com/problems/maximum-number-of-jumps-to-reach-the-last-index", "title": "maximum-number-of-jumps-to-reach-the-last-index", "meta": {"questionId": "2855", "questionFrontendId": "2770", "title": "Maximum Number of Jumps to Reach the Last Index", "titleSlug": "maximum-number-of-jumps-to-reach-the-last-index", "isPaidOnly": false, "difficulty": "Medium", "likes": 356, "dislikes": 10, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0 开始、由 n 个整数组成的数组 nums 和一个整数 target 。\n\n你的初始位置在下标 0 。在一步操作中,你可以从下标 i 跳跃到任意满足下述条件的下标 j :\n\n * 0 <= i < j < n\n * -target <= nums[j] - nums[i] <= target\n\n返回到达下标 n - 1 处所需的 最大跳跃次数 。\n\n如果无法到达下标 n - 1 ,返回 -1 。\n\n示例 1:\n\n输入:nums = [1,3,6,4,1,2], target = 2\n输出:3\n解释:要想以最大跳跃次数从下标 0 到下标 n - 1 ,可以按下述跳跃序列执行操作:\n- 从下标 0 跳跃到下标 1 。\n- 从下标 1 跳跃到下标 3 。\n- 从下标 3 跳跃到下标 5 。\n可以证明,从 0 到 n - 1 的所有方案中,不存在比 3 步更长的跳跃序列。因此,答案是 3 。\n\n示例 2:\n\n输入:nums = [1,3,6,4,1,2], target = 3\n输出:5\n解释:要想以最大跳跃次数从下标 0 到下标 n - 1 ,可以按下述跳跃序列执行操作:\n- 从下标 0 跳跃到下标 1 。\n- 从下标 1 跳跃到下标 2 。\n- 从下标 2 跳跃到下标 3 。\n- 从下标 3 跳跃到下标 4 。\n- 从下标 4 跳跃到下标 5 。\n可以证明,从 0 到 n - 1 的所有方案中,不存在比 5 步更长的跳跃序列。因此,答案是 5 。\n\n示例 3:\n\n输入:nums = [1,3,6,4,1,2], target = 0\n输出:-1\n解释:可以证明不存在从 0 到 n - 1 的跳跃序列。因此,答案是 -1 。\n\n\n提示:\n\n * 2 <= nums.length == n <= 1000\n * -109 <= nums[i] <= 109\n * 0 <= target <= 2 * 109\n\"\"\"\nclass Solution:\n def maximumJumps(self, nums: List[int], target: int) -> int:\n ", "prompt_sft": "给你一个下标从 0 开始、由 n 个整数组成的数组 nums 和一个整数 target 。\n\n你的初始位置在下标 0 。在一步操作中,你可以从下标 i 跳跃到任意满足下述条件的下标 j :\n\n * 0 <= i < j < n\n * -target <= nums[j] - nums[i] <= target\n\n返回到达下标 n - 1 处所需的 最大跳跃次数 。\n\n如果无法到达下标 n - 1 ,返回 -1 。\n\n示例 1:\n\n输入:nums = [1,3,6,4,1,2], target = 2\n输出:3\n解释:要想以最大跳跃次数从下标 0 到下标 n - 1 ,可以按下述跳跃序列执行操作:\n- 从下标 0 跳跃到下标 1 。\n- 从下标 1 跳跃到下标 3 。\n- 从下标 3 跳跃到下标 5 。\n可以证明,从 0 到 n - 1 的所有方案中,不存在比 3 步更长的跳跃序列。因此,答案是 3 。\n\n示例 2:\n\n输入:nums = [1,3,6,4,1,2], target = 3\n输出:5\n解释:要想以最大跳跃次数从下标 0 到下标 n - 1 ,可以按下述跳跃序列执行操作:\n- 从下标 0 跳跃到下标 1 。\n- 从下标 1 跳跃到下标 2 。\n- 从下标 2 跳跃到下标 3 。\n- 从下标 3 跳跃到下标 4 。\n- 从下标 4 跳跃到下标 5 。\n可以证明,从 0 到 n - 1 的所有方案中,不存在比 5 步更长的跳跃序列。因此,答案是 5 。\n\n示例 3:\n\n输入:nums = [1,3,6,4,1,2], target = 0\n输出:-1\n解释:可以证明不存在从 0 到 n - 1 的跳跃序列。因此,答案是 -1 。\n\n\n提示:\n\n * 2 <= nums.length == n <= 1000\n * -109 <= nums[i] <= 109\n * 0 <= target <= 2 * 109\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def maximumJumps(self, nums: List[int], target: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,3,6,4,1,2], \"target\": 2 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [1,3,6,4,1,2], \"target\": 3 }\nassert my_solution.maximumJumps(**test_input) == 5\n\ntest_input = { \"nums\": [1,3,6,4,1,2], \"target\": 0 }\nassert my_solution.maximumJumps(**test_input) == -1\n\ntest_input = { \"nums\": [0,1], \"target\": 0 }\nassert my_solution.maximumJumps(**test_input) == -1\n\ntest_input = { \"nums\": [0,1], \"target\": 1 }\nassert my_solution.maximumJumps(**test_input) == 1\n\ntest_input = { \"nums\": [0,1], \"target\": 2 }\nassert my_solution.maximumJumps(**test_input) == 1\n\ntest_input = { \"nums\": [1,0], \"target\": 0 }\nassert my_solution.maximumJumps(**test_input) == -1\n\ntest_input = { \"nums\": [1,0], \"target\": 1 }\nassert my_solution.maximumJumps(**test_input) == 1\n\ntest_input = { \"nums\": [1,0], \"target\": 2 }\nassert my_solution.maximumJumps(**test_input) == 1\n\ntest_input = { \"nums\": [0,1,2], \"target\": 0 }\nassert my_solution.maximumJumps(**test_input) == -1\n\ntest_input = { \"nums\": [0,1,2], \"target\": 1 }\nassert my_solution.maximumJumps(**test_input) == 2\n\ntest_input = { \"nums\": [0,1,2], \"target\": 2 }\nassert my_solution.maximumJumps(**test_input) == 2\n\ntest_input = { \"nums\": [0,1,2], \"target\": 3 }\nassert my_solution.maximumJumps(**test_input) == 2\n\ntest_input = { \"nums\": [0,2,1], \"target\": 0 }\nassert my_solution.maximumJumps(**test_input) == -1\n\ntest_input = { \"nums\": [0,2,1], \"target\": 1 }\nassert my_solution.maximumJumps(**test_input) == 1\n\ntest_input = { \"nums\": [0,2,1], \"target\": 2 }\nassert my_solution.maximumJumps(**test_input) == 2\n\ntest_input = { \"nums\": [0,2,1], \"target\": 3 }\nassert my_solution.maximumJumps(**test_input) == 2\n\ntest_input = { \"nums\": [1,0,2], \"target\": 0 }\nassert my_solution.maximumJumps(**test_input) == -1\n\ntest_input = { \"nums\": [1,0,2], \"target\": 1 }\nassert my_solution.maximumJumps(**test_input) == 1\n\ntest_input = { \"nums\": [1,0,2], \"target\": 2 }\nassert my_solution.maximumJumps(**test_input) == 2\n\ntest_input = { \"nums\": [1,0,2], \"target\": 3 }\nassert my_solution.maximumJumps(**test_input) == 2\n\ntest_input = { \"nums\": [1,2,0], \"target\": 0 }\nassert my_solution.maximumJumps(**test_input) == -1\n\ntest_input = { \"nums\": [1,2,0], \"target\": 1 }\nassert my_solution.maximumJumps(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,0], \"target\": 2 }\nassert my_solution.maximumJumps(**test_input) == 2\n\ntest_input = { \"nums\": [1,2,0], \"target\": 3 }\nassert my_solution.maximumJumps(**test_input) == 2\n\ntest_input = { \"nums\": [2,0,1], \"target\": 0 }\nassert my_solution.maximumJumps(**test_input) == -1\n\ntest_input = { \"nums\": [2,0,1], \"target\": 1 }\nassert my_solution.maximumJumps(**test_input) == 1\n\ntest_input = { \"nums\": [2,0,1], \"target\": 2 }\nassert my_solution.maximumJumps(**test_input) == 2\n\ntest_input = { \"nums\": [2,0,1], \"target\": 3 }\nassert my_solution.maximumJumps(**test_input) == 2\n\ntest_input = { \"nums\": [2,1,0], \"target\": 0 }\nassert my_solution.maximumJumps(**test_input) == -1\n\ntest_input = { \"nums\": [2,1,0], \"target\": 1 }\nassert my_solution.maximumJumps(**test_input) == 2\n\ntest_input = { \"nums\": [2,1,0], \"target\": 2 }\nassert my_solution.maximumJumps(**test_input) == 2\n\ntest_input = { \"nums\": [2,1,0], \"target\": 3 }\nassert my_solution.maximumJumps(**test_input) == 2\n\ntest_input = { \"nums\": [0,1,2,3], \"target\": 0 }\nassert my_solution.maximumJumps(**test_input) == -1\n\ntest_input = { \"nums\": [0,1,2,3], \"target\": 1 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [0,1,2,3], \"target\": 2 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [0,1,2,3], \"target\": 3 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [0,1,2,3], \"target\": 4 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [0,1,3,2], \"target\": 0 }\nassert my_solution.maximumJumps(**test_input) == -1\n\ntest_input = { \"nums\": [0,1,3,2], \"target\": 1 }\nassert my_solution.maximumJumps(**test_input) == 2\n\ntest_input = { \"nums\": [0,1,3,2], \"target\": 2 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [0,1,3,2], \"target\": 3 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [0,1,3,2], \"target\": 4 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [0,2,1,3], \"target\": 0 }\nassert my_solution.maximumJumps(**test_input) == -1\n\ntest_input = { \"nums\": [0,2,1,3], \"target\": 1 }\nassert my_solution.maximumJumps(**test_input) == -1\n\ntest_input = { \"nums\": [0,2,1,3], \"target\": 2 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [0,2,1,3], \"target\": 3 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [0,2,1,3], \"target\": 4 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [0,2,3,1], \"target\": 0 }\nassert my_solution.maximumJumps(**test_input) == -1\n\ntest_input = { \"nums\": [0,2,3,1], \"target\": 1 }\nassert my_solution.maximumJumps(**test_input) == 1\n\ntest_input = { \"nums\": [0,2,3,1], \"target\": 2 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [0,2,3,1], \"target\": 3 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [0,2,3,1], \"target\": 4 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [0,3,1,2], \"target\": 0 }\nassert my_solution.maximumJumps(**test_input) == -1\n\ntest_input = { \"nums\": [0,3,1,2], \"target\": 1 }\nassert my_solution.maximumJumps(**test_input) == 2\n\ntest_input = { \"nums\": [0,3,1,2], \"target\": 2 }\nassert my_solution.maximumJumps(**test_input) == 2\n\ntest_input = { \"nums\": [0,3,1,2], \"target\": 3 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [0,3,1,2], \"target\": 4 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [0,3,2,1], \"target\": 0 }\nassert my_solution.maximumJumps(**test_input) == -1\n\ntest_input = { \"nums\": [0,3,2,1], \"target\": 1 }\nassert my_solution.maximumJumps(**test_input) == 1\n\ntest_input = { \"nums\": [0,3,2,1], \"target\": 2 }\nassert my_solution.maximumJumps(**test_input) == 2\n\ntest_input = { \"nums\": [0,3,2,1], \"target\": 3 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [0,3,2,1], \"target\": 4 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [1,0,2,3], \"target\": 0 }\nassert my_solution.maximumJumps(**test_input) == -1\n\ntest_input = { \"nums\": [1,0,2,3], \"target\": 1 }\nassert my_solution.maximumJumps(**test_input) == 2\n\ntest_input = { \"nums\": [1,0,2,3], \"target\": 2 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [1,0,2,3], \"target\": 3 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [1,0,2,3], \"target\": 4 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [1,0,3,2], \"target\": 0 }\nassert my_solution.maximumJumps(**test_input) == -1\n\ntest_input = { \"nums\": [1,0,3,2], \"target\": 1 }\nassert my_solution.maximumJumps(**test_input) == 1\n\ntest_input = { \"nums\": [1,0,3,2], \"target\": 2 }\nassert my_solution.maximumJumps(**test_input) == 2\n\ntest_input = { \"nums\": [1,0,3,2], \"target\": 3 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [1,0,3,2], \"target\": 4 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,0,3], \"target\": 0 }\nassert my_solution.maximumJumps(**test_input) == -1\n\ntest_input = { \"nums\": [1,2,0,3], \"target\": 1 }\nassert my_solution.maximumJumps(**test_input) == 2\n\ntest_input = { \"nums\": [1,2,0,3], \"target\": 2 }\nassert my_solution.maximumJumps(**test_input) == 2\n\ntest_input = { \"nums\": [1,2,0,3], \"target\": 3 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,0,3], \"target\": 4 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,3,0], \"target\": 0 }\nassert my_solution.maximumJumps(**test_input) == -1\n\ntest_input = { \"nums\": [1,2,3,0], \"target\": 1 }\nassert my_solution.maximumJumps(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,3,0], \"target\": 2 }\nassert my_solution.maximumJumps(**test_input) == 2\n\ntest_input = { \"nums\": [1,2,3,0], \"target\": 3 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,3,0], \"target\": 4 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [1,3,0,2], \"target\": 0 }\nassert my_solution.maximumJumps(**test_input) == -1\n\ntest_input = { \"nums\": [1,3,0,2], \"target\": 1 }\nassert my_solution.maximumJumps(**test_input) == 1\n\ntest_input = { \"nums\": [1,3,0,2], \"target\": 2 }\nassert my_solution.maximumJumps(**test_input) == 2\n\ntest_input = { \"nums\": [1,3,0,2], \"target\": 3 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [1,3,0,2], \"target\": 4 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [1,3,2,0], \"target\": 0 }\nassert my_solution.maximumJumps(**test_input) == -1\n\ntest_input = { \"nums\": [1,3,2,0], \"target\": 1 }\nassert my_solution.maximumJumps(**test_input) == 1\n\ntest_input = { \"nums\": [1,3,2,0], \"target\": 2 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [1,3,2,0], \"target\": 3 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [1,3,2,0], \"target\": 4 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [2,0,1,3], \"target\": 0 }\nassert my_solution.maximumJumps(**test_input) == -1\n\ntest_input = { \"nums\": [2,0,1,3], \"target\": 1 }\nassert my_solution.maximumJumps(**test_input) == 1\n\ntest_input = { \"nums\": [2,0,1,3], \"target\": 2 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [2,0,1,3], \"target\": 3 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [2,0,1,3], \"target\": 4 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [2,0,3,1], \"target\": 0 }\nassert my_solution.maximumJumps(**test_input) == -1\n\ntest_input = { \"nums\": [2,0,3,1], \"target\": 1 }\nassert my_solution.maximumJumps(**test_input) == 1", "start_time": 1688869800} +{"task_id": "weekly-contest-353-longest-non-decreasing-subarray-from-two-arrays", "url": "https://leetcode.com/problems/longest-non-decreasing-subarray-from-two-arrays", "title": "longest-non-decreasing-subarray-from-two-arrays", "meta": {"questionId": "2869", "questionFrontendId": "2771", "title": "Longest Non-decreasing Subarray From Two Arrays", "titleSlug": "longest-non-decreasing-subarray-from-two-arrays", "isPaidOnly": false, "difficulty": "Medium", "likes": 505, "dislikes": 10, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你两个下标从 0 开始的整数数组 nums1 和 nums2 ,长度均为 n 。\n\n让我们定义另一个下标从 0 开始、长度为 n 的整数数组,nums3 。对于范围 [0, n - 1] 的每个下标 i ,你可以将 nums1[i] 或 nums2[i] 的值赋给 nums3[i] 。\n\n你的任务是使用最优策略为 nums3 赋值,以最大化 nums3 中 最长非递减子数组 的长度。\n\n以整数形式表示并返回 nums3 中 最长非递减 子数组的长度。\n\n注意:子数组 是数组中的一个连续非空元素序列。\n\n示例 1:\n\n输入:nums1 = [2,3,1], nums2 = [1,2,1]\n输出:2\n解释:构造 nums3 的方法之一是:\nnums3 = [nums1[0], nums2[1], nums2[2]] => [2,2,1]\n从下标 0 开始到下标 1 结束,形成了一个长度为 2 的非递减子数组 [2,2] 。\n可以证明 2 是可达到的最大长度。\n\n示例 2:\n\n输入:nums1 = [1,3,2,1], nums2 = [2,2,3,4]\n输出:4\n解释:构造 nums3 的方法之一是:\nnums3 = [nums1[0], nums2[1], nums2[2], nums2[3]] => [1,2,3,4]\n整个数组形成了一个长度为 4 的非递减子数组,并且是可达到的最大长度。\n\n示例 3:\n\n输入:nums1 = [1,1], nums2 = [2,2]\n输出:2\n解释:构造 nums3 的方法之一是:\nnums3 = [nums1[0], nums1[1]] => [1,1]\n整个数组形成了一个长度为 2 的非递减子数组,并且是可达到的最大长度。\n\n\n提示:\n\n * 1 <= nums1.length == nums2.length == n <= 105\n * 1 <= nums1[i], nums2[i] <= 109\n\"\"\"\nclass Solution:\n def maxNonDecreasingLength(self, nums1: List[int], nums2: List[int]) -> int:\n ", "prompt_sft": "给你两个下标从 0 开始的整数数组 nums1 和 nums2 ,长度均为 n 。\n\n让我们定义另一个下标从 0 开始、长度为 n 的整数数组,nums3 。对于范围 [0, n - 1] 的每个下标 i ,你可以将 nums1[i] 或 nums2[i] 的值赋给 nums3[i] 。\n\n你的任务是使用最优策略为 nums3 赋值,以最大化 nums3 中 最长非递减子数组 的长度。\n\n以整数形式表示并返回 nums3 中 最长非递减 子数组的长度。\n\n注意:子数组 是数组中的一个连续非空元素序列。\n\n示例 1:\n\n输入:nums1 = [2,3,1], nums2 = [1,2,1]\n输出:2\n解释:构造 nums3 的方法之一是:\nnums3 = [nums1[0], nums2[1], nums2[2]] => [2,2,1]\n从下标 0 开始到下标 1 结束,形成了一个长度为 2 的非递减子数组 [2,2] 。\n可以证明 2 是可达到的最大长度。\n\n示例 2:\n\n输入:nums1 = [1,3,2,1], nums2 = [2,2,3,4]\n输出:4\n解释:构造 nums3 的方法之一是:\nnums3 = [nums1[0], nums2[1], nums2[2], nums2[3]] => [1,2,3,4]\n整个数组形成了一个长度为 4 的非递减子数组,并且是可达到的最大长度。\n\n示例 3:\n\n输入:nums1 = [1,1], nums2 = [2,2]\n输出:2\n解释:构造 nums3 的方法之一是:\nnums3 = [nums1[0], nums1[1]] => [1,1]\n整个数组形成了一个长度为 2 的非递减子数组,并且是可达到的最大长度。\n\n\n提示:\n\n * 1 <= nums1.length == nums2.length == n <= 105\n * 1 <= nums1[i], nums2[i] <= 109\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def maxNonDecreasingLength(self, nums1: List[int], nums2: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums1\": [2,3,1], \"nums2\": [1,2,1] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [1,3,2,1], \"nums2\": [2,2,3,4] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 4\n\ntest_input = { \"nums1\": [1,1], \"nums2\": [2,2] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [1], \"nums2\": [1] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 1\n\ntest_input = { \"nums1\": [1], \"nums2\": [2] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 1\n\ntest_input = { \"nums1\": [1,4], \"nums2\": [4,19] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [1,8], \"nums2\": [10,1] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [1,11], \"nums2\": [9,1] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [1,13], \"nums2\": [18,1] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [1,19], \"nums2\": [12,20] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [1,19], \"nums2\": [18,9] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [2,20], \"nums2\": [1,18] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [3,5], \"nums2\": [13,3] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [3,6], \"nums2\": [10,12] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [3,7], \"nums2\": [8,3] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [3,8], \"nums2\": [15,2] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [3,9], \"nums2\": [11,3] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [3,12], \"nums2\": [7,3] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [3,12], \"nums2\": [20,3] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [3,20], \"nums2\": [5,17] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [4,2], \"nums2\": [10,4] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [4,12], \"nums2\": [6,4] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [4,15], \"nums2\": [3,3] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [5,5], \"nums2\": [19,8] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [5,7], \"nums2\": [19,5] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [5,11], \"nums2\": [2,5] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [5,14], \"nums2\": [8,3] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [5,15], \"nums2\": [16,5] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [5,20], \"nums2\": [4,5] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [5,20], \"nums2\": [10,17] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [6,7], \"nums2\": [3,2] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [6,14], \"nums2\": [5,5] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [6,14], \"nums2\": [18,6] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [6,16], \"nums2\": [16,20] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [6,17], \"nums2\": [4,20] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [7,3], \"nums2\": [16,7] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [7,4], \"nums2\": [15,7] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [7,9], \"nums2\": [3,18] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [7,10], \"nums2\": [10,14] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [7,11], \"nums2\": [5,7] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [7,12], \"nums2\": [20,5] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [7,20], \"nums2\": [12,8] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [8,5], \"nums2\": [13,8] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [8,11], \"nums2\": [9,3] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [8,16], \"nums2\": [9,8] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [8,17], \"nums2\": [2,8] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [8,18], \"nums2\": [16,12] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [4,2], \"nums2\": [10,4] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [9,1], \"nums2\": [11,9] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [9,6], \"nums2\": [8,14] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [9,9], \"nums2\": [11,8] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [9,12], \"nums2\": [20,9] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [9,15], \"nums2\": [20,9] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [9,16], \"nums2\": [11,15] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [9,19], \"nums2\": [17,9] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [10,19], \"nums2\": [17,10] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [11,1], \"nums2\": [3,11] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [11,3], \"nums2\": [9,17] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [11,6], \"nums2\": [9,17] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [11,19], \"nums2\": [17,11] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [11,69], \"nums2\": [26,62] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [12,1], \"nums2\": [10,12] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [12,10], \"nums2\": [16,2] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 1\n\ntest_input = { \"nums1\": [13,6], \"nums2\": [20,13] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [13,16], \"nums2\": [5,13] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [14,2], \"nums2\": [2,14] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [14,4], \"nums2\": [2,13] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [15,10], \"nums2\": [17,15] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [15,11], \"nums2\": [19,2] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 1\n\ntest_input = { \"nums1\": [16,9], \"nums2\": [5,16] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [16,17], \"nums2\": [9,16] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [17,8], \"nums2\": [11,10] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 1\n\ntest_input = { \"nums1\": [17,10], \"nums2\": [9,17] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [17,10], \"nums2\": [18,7] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 1\n\ntest_input = { \"nums1\": [17,11], \"nums2\": [19,17] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [17,14], \"nums2\": [17,17] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [17,17], \"nums2\": [15,17] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [17,17], \"nums2\": [16,1] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [18,4], \"nums2\": [1,6] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [18,9], \"nums2\": [10,18] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [18,9], \"nums2\": [17,18] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [18,10], \"nums2\": [1,18] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [18,104], \"nums2\": [117,18] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [19,2], \"nums2\": [1,19] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [19,5], \"nums2\": [15,5] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 1\n\ntest_input = { \"nums1\": [19,5], \"nums2\": [52,10] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 1\n\ntest_input = { \"nums1\": [19,15], \"nums2\": [12,19] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [19,15], \"nums2\": [18,4] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 1\n\ntest_input = { \"nums1\": [20,1], \"nums2\": [1,20] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [20,5], \"nums2\": [2,3] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [20,5], \"nums2\": [14,8] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 1\n\ntest_input = { \"nums1\": [20,7], \"nums2\": [12,20] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [20,12], \"nums2\": [2,20] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [20,16], \"nums2\": [8,5] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [20,18], \"nums2\": [18,20] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [25,83], \"nums2\": [28,18] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [26,47], \"nums2\": [87,26] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [28,41], \"nums2\": [87,3] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [36,53], \"nums2\": [66,3] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [44,34], \"nums2\": [53,44] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2", "start_time": 1688869800} +{"task_id": "weekly-contest-353-apply-operations-to-make-all-array-elements-equal-to-zero", "url": "https://leetcode.com/problems/apply-operations-to-make-all-array-elements-equal-to-zero", "title": "apply-operations-to-make-all-array-elements-equal-to-zero", "meta": {"questionId": "2878", "questionFrontendId": "2772", "title": "Apply Operations to Make All Array Elements Equal to Zero", "titleSlug": "apply-operations-to-make-all-array-elements-equal-to-zero", "isPaidOnly": false, "difficulty": "Medium", "likes": 339, "dislikes": 19, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0 开始的整数数组 nums 和一个正整数 k 。\n\n你可以对数组执行下述操作 任意次 :\n\n * 从数组中选出长度为 k 的 任一 子数组,并将子数组中每个元素都 减去 1 。\n\n如果你可以使数组中的所有元素都等于 0 ,返回  true ;否则,返回 false 。\n\n子数组 是数组中的一个非空连续元素序列。\n\n示例 1:\n\n输入:nums = [2,2,3,1,1,0], k = 3\n输出:true\n解释:可以执行下述操作:\n- 选出子数组 [2,2,3] ,执行操作后,数组变为 nums = [1,1,2,1,1,0] 。\n- 选出子数组 [2,1,1] ,执行操作后,数组变为 nums = [1,1,1,0,0,0] 。\n- 选出子数组 [1,1,1] ,执行操作后,数组变为 nums = [0,0,0,0,0,0] 。\n\n示例 2:\n\n输入:nums = [1,3,1,1], k = 2\n输出:false\n解释:无法使数组中的所有元素等于 0 。\n\n\n提示:\n\n * 1 <= k <= nums.length <= 105\n * 0 <= nums[i] <= 106\n\"\"\"\nclass Solution:\n def checkArray(self, nums: List[int], k: int) -> bool:\n ", "prompt_sft": "给你一个下标从 0 开始的整数数组 nums 和一个正整数 k 。\n\n你可以对数组执行下述操作 任意次 :\n\n * 从数组中选出长度为 k 的 任一 子数组,并将子数组中每个元素都 减去 1 。\n\n如果你可以使数组中的所有元素都等于 0 ,返回  true ;否则,返回 false 。\n\n子数组 是数组中的一个非空连续元素序列。\n\n示例 1:\n\n输入:nums = [2,2,3,1,1,0], k = 3\n输出:true\n解释:可以执行下述操作:\n- 选出子数组 [2,2,3] ,执行操作后,数组变为 nums = [1,1,2,1,1,0] 。\n- 选出子数组 [2,1,1] ,执行操作后,数组变为 nums = [1,1,1,0,0,0] 。\n- 选出子数组 [1,1,1] ,执行操作后,数组变为 nums = [0,0,0,0,0,0] 。\n\n示例 2:\n\n输入:nums = [1,3,1,1], k = 2\n输出:false\n解释:无法使数组中的所有元素等于 0 。\n\n\n提示:\n\n * 1 <= k <= nums.length <= 105\n * 0 <= nums[i] <= 106\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def checkArray(self, nums: List[int], k: int) -> bool:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,3,1,1], \"k\": 2 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [2,2,3,1,1,0], \"k\": 3 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [24,24,14,37,31,88,94,38,94,0,100,100,4,46,5,50,0,33,22,25,0], \"k\": 10 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [60,72,87,89,63,52,64,62,31,37,57,83,98,94,92,77,94,91,87,100,91,91,50,26], \"k\": 4 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [22,4,1,25,68,30,97,99,100,22,20,39,85,68,3,1,1,74], \"k\": 4 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [63,40,30,0,72,53], \"k\": 1 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [27,99,7,1,94,63,84,46,76,35,97,77,19,72,3], \"k\": 2 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [60,78,96,97,97,97,49,7,97,97,97,99,97,97,97,97,85,97,97,97,37,5,1], \"k\": 20 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [34,34,99,93,93,26,99,100,94,94,82,86,100,100,87,100,100,100,100,100,63,100,100,66,17,10,8,7,3,1], \"k\": 23 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [67,98,97,99,98,97,97,96,99,99,99,42,68,18,99,44,95,79,1,16,49,1,2,2,0], \"k\": 16 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [59,60,99,99,99,99,99,99,99,40,39,0], \"k\": 9 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [12,87,91,18], \"k\": 3 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [0,0,51,67,80,98,88,75,89,83,100,70,77,82,57,100,80,69,19,17], \"k\": 3 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [22], \"k\": 1 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [52,92,51,24,23,79,100,94,78,96,38,14,72,27,99,94,32,67,43,31,88,8], \"k\": 4 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [8,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,43,0], \"k\": 25 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [0,0,39,84,86,94,55,10,8,0], \"k\": 4 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [12,79,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,83,16,0], \"k\": 24 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [15,11,99,86,58,23,82,100,100,80,58,58,84,57,0,25,6], \"k\": 3 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [99,0,82,66,3,25,92,41,3,0,46], \"k\": 7 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [18,52,56,96,98,82,76,87,2,61,88,100], \"k\": 2 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [0,6,100,74,4,50,100,92,18,70,15,88,0,24], \"k\": 9 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [0,0,33,72,86,53,14], \"k\": 3 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [67,0,68,97,94], \"k\": 3 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [0,0,8,64,89,89,89,89,89,89,89,89,89,89,89,89,89,89,89,89,89,89,89,89,89,89,89,81,25], \"k\": 25 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [84,0,68,95,95,0,25,0,7,71,4,68,23,97,80,0], \"k\": 1 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [95,92,99,99,2,100,100,100,100,100,100,100,8,57,65,69,69,100,100,100,100,100,100,100,100,0,79,72,32], \"k\": 12 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [7,33,97,98,100,100,74,98,95,13,39,31,82,51,28,68,37,59,21,5,66,77,89,6,0], \"k\": 6 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [48,48,48,48,48], \"k\": 5 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [42,60,56,99,72,2,100,51,65,14,13,51,1,55,56,61,99,49,96,2], \"k\": 3 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [8,82,98,99,66,39,71,100,81,85,100,19,96,0,2,85,40,0,19,0], \"k\": 11 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [92,96,96,96,97,99,99,99,99,99,99,99,99,22,18,18,18,17,15,15,15,15,15,15,15,15], \"k\": 13 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [89,8,8,8,8,8,8,8,8,8,8,8], \"k\": 12 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [4,19,0,74,0,26,94,25,99,35,0], \"k\": 10 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [79,4,27,35,16,27,85,92,75,99,7,98,86,92,33,8,96,44,21,52,34], \"k\": 4 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [75,18,0,81,18,16,51,0], \"k\": 1 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [74,74,74,74,74,74,74,74,74], \"k\": 9 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [5,5,5,9,37,81,95,95,95,98,98,99,100,100,97,99,100,96,68,24,10,10,10,7,7,6,5,5,3,1], \"k\": 14 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [81,100,99,99,68,66,56,100,74,63,2,84,23,67,93,92,56,90,18,57,100,33,88,26,100,72,93,57,28,17], \"k\": 4 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [62,76,96,12,0,20,63,29,96,97,8,18,56], \"k\": 1 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [31,60,97,71,53,46,63,50,91,82,40,79,96,100,55,55,57,39,50,98,72,37,27,55], \"k\": 3 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [100,65,78,59,17,17], \"k\": 1 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [57,10,53,20,40,42,64,94,82,67,100,3,22,67,95,28,61,74,67,99,100,46,67,67,76,31,99,26,85], \"k\": 24 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [34,76,66,48,13,89,22,24,70,17,17,42,100,2,96,8], \"k\": 3 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [92,94,2,6,6], \"k\": 2 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [100,17,95], \"k\": 3 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [20,27,75,96,97,84,90,77,65,64,57,44,9,0], \"k\": 5 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [41,39,98,99,100,100,100,100,100,100,100,100,100,100,100,37,5,2,1,0,0,92,0,0,0], \"k\": 15 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [45,90,90,99,99,99,99,99,54,9,9,0], \"k\": 8 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [41,18,59,3,52,59,59,55,1,34,67,1,2,13,60,40,5,0,4,47,73,96,33,59,98], \"k\": 24 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [53,88,96,97,97,97,97,97,97,97,44,9,1,0], \"k\": 10 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [90,74,13,81,34,10,29,18,61,94,43,99,86,0], \"k\": 11 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [44,47,72,0,0,68,97,67], \"k\": 1 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [77,78,19,97,79], \"k\": 2 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [36,61,86,61,0,61,61,61,61,61,61,61,61,65,62,61,95,61,61,61,80,66,61,61,25], \"k\": 24 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [0,44,92,94,94,50,95,98,98,99,6,1,54,58,94,94,41,36], \"k\": 4 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [60,71,76,93,98,98,98,98,38,27,22,5], \"k\": 8 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [94,94,99,94,86,100,32,96,59,69,99,95,75], \"k\": 3 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [6,55,95,95,95,96,95,95,90,5,0], \"k\": 8 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [62,90,90,90,99,57,61,96,96,97,99,78,84,0], \"k\": 5 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [57,77,91,66,46,32], \"k\": 3 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [86,87,92,20,42,99,100,97,17,18,48,11,60,98,96,28,59,5,18,56,62,35,100,87,51,54,77,98,61], \"k\": 7 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [21,26,20,2,38,22,0,96,79,93,9,67,34], \"k\": 12 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [92,14,95,100,53,99,100,100,50,99,99,99,93,99,100,15,71,100,7,5,48,65,6], \"k\": 18 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [64,14,64,8,0,83,17,68,5,98,36], \"k\": 7 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [50,50,50,50,93,92,84,96,96,96,96,96,96,96,96,46,46,46,46,33,4,1,0], \"k\": 15 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [79,90,100,96,22,2,100,10,100,100,78,85,54,7,35,97,98,98,98,98,33,38,4,14,63,23], \"k\": 10 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [49,74,96,93,93,99,100,95,73,100,41,95,99,22,13,52,19,13,11,80], \"k\": 7 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [6,100,100,100,100,100,98,4,74,89,89,89,85,85,15], \"k\": 6 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [69,48,8,3,82,10,88,76,32,95,68,30,97,64,32,62,86], \"k\": 1 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [87,87,87], \"k\": 3 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [88,98,99,99,100,100,58,82,85,87,86,86,40,6,2], \"k\": 6 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [26,26,46,46,70,70,95,97,98,98,98,72,72,52,52,28,28,3,1], \"k\": 11 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [25], \"k\": 1 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [71,87,87,96,99,36,61,87,98,97,93,96,71,59,75,71,27,26,18], \"k\": 5 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [39,90,15,100,52,27,100,67,99,79,4,78,95,84,2], \"k\": 4 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [39,39,39,39,39,39,39,39,39,39], \"k\": 10 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [58,72,93,99,99,64,50,29,23,23,0,0,0,0,0], \"k\": 5 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [30,86,23], \"k\": 3 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [65,69,74,79,90,95,98,99,99,99,100,100,100,100,100,100,35,31,26,21,10,5,2,1,1,1,0,0], \"k\": 16 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [69,2,71,4,97,97,100,26,100,100,100,100,100,77,13,8,13,3,3,72,0,0,0], \"k\": 13 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [77,90,94,94,98,98,28,29,36,91,91,94,87,73,80,81,77,74,74,74,56], \"k\": 6 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [93], \"k\": 1 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [70,91,100,17,80,94,35,83,33,0], \"k\": 4 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [79,87,87,99,50,77,97,85,92,91,71,71,34], \"k\": 4 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [75,9,96,100,100,77,7,99,100,99,94,71,5,78,3,8,8,7,59,8,6], \"k\": 10 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [36,37,69,88,88,96,96,96,96,96,96,96,96,96,96,96,96,96,96,96,96,60,59,27,8,8,0], \"k\": 21 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [94,94,96,97,98,11,64,85,84,87,98,45,65,83,79,63,74,79,61,61,59,48], \"k\": 5 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [80,80,98,98,98,18,18,0,0], \"k\": 5 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [14,100,17,100,13,85,100,100,14,100,100,1,83,0], \"k\": 11 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [98,74,91,70], \"k\": 2 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [0,29,29,93,93,93,93,93,93,93,93,93,64,64], \"k\": 11 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,0], \"k\": 15 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [34,89,92,96,96,98,99,98,79,4,100,100,12,99,100,44,100,66,25,8,4,98,2,1,97,70,1,15,0,88], \"k\": 17 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [95,95,98,99,99,99,100,100,100,100,100,100,100,5,5,2,1,1,1], \"k\": 13 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [15,58,78,10,68,49,100,94,30,14,72], \"k\": 5 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [9,44,70,75,28,23,11,37,69,34,61], \"k\": 10 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [70,51,47,100,59,66,17,98,60], \"k\": 4 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [92,33,58,88], \"k\": 2 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [99,15,91,32,7,98], \"k\": 3 }\nassert my_solution.checkArray(**test_input) == False", "start_time": 1688869800} +{"task_id": "biweekly-contest-108-longest-alternating-subarray", "url": "https://leetcode.com/problems/longest-alternating-subarray", "title": "longest-alternating-subarray", "meta": {"questionId": "2870", "questionFrontendId": "2765", "title": "Longest Alternating Subarray", "titleSlug": "longest-alternating-subarray", "isPaidOnly": false, "difficulty": "Easy", "likes": 181, "dislikes": 153, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0 开始的整数数组 nums 。如果 nums 中长度为 m 的子数组 s 满足以下条件,我们称它是一个 交替子序列 :\n\n * m 大于 1 。\n * s1 = s0 + 1 。\n * 下标从 0 开始的子数组 s 与数组 [s0, s1, s0, s1,...,s(m-1) % 2] 一样。也就是说,s1 - s0 = 1 ,s2 - s1 = -1 ,s3 - s2 = 1 ,s4 - s3 = -1 ,以此类推,直到 s[m - 1] - s[m - 2] = (-1)m 。\n\n请你返回 nums 中所有 交替 子数组中,最长的长度,如果不存在交替子数组,请你返回 -1 。\n\n子数组是一个数组中一段连续 非空 的元素序列。\n\n示例 1:\n\n输入:nums = [2,3,4,3,4]\n输出:4\n解释:交替子数组有 [3,4] ,[3,4,3] 和 [3,4,3,4] 。最长的子数组为 [3,4,3,4] ,长度为4 。\n\n示例 2:\n\n输入:nums = [4,5,6]\n输出:2\n解释:[4,5] 和 [5,6] 是仅有的两个交替子数组。它们长度都为 2 。\n\n\n提示:\n\n * 2 <= nums.length <= 100\n * 1 <= nums[i] <= 104\n\"\"\"\nclass Solution:\n def alternatingSubarray(self, nums: List[int]) -> int:\n ", "prompt_sft": "给你一个下标从 0 开始的整数数组 nums 。如果 nums 中长度为 m 的子数组 s 满足以下条件,我们称它是一个 交替子序列 :\n\n * m 大于 1 。\n * s1 = s0 + 1 。\n * 下标从 0 开始的子数组 s 与数组 [s0, s1, s0, s1,...,s(m-1) % 2] 一样。也就是说,s1 - s0 = 1 ,s2 - s1 = -1 ,s3 - s2 = 1 ,s4 - s3 = -1 ,以此类推,直到 s[m - 1] - s[m - 2] = (-1)m 。\n\n请你返回 nums 中所有 交替 子数组中,最长的长度,如果不存在交替子数组,请你返回 -1 。\n\n子数组是一个数组中一段连续 非空 的元素序列。\n\n示例 1:\n\n输入:nums = [2,3,4,3,4]\n输出:4\n解释:交替子数组有 [3,4] ,[3,4,3] 和 [3,4,3,4] 。最长的子数组为 [3,4,3,4] ,长度为4 。\n\n示例 2:\n\n输入:nums = [4,5,6]\n输出:2\n解释:[4,5] 和 [5,6] 是仅有的两个交替子数组。它们长度都为 2 。\n\n\n提示:\n\n * 2 <= nums.length <= 100\n * 1 <= nums[i] <= 104\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def alternatingSubarray(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [2,3,4,3,4] }\nassert my_solution.alternatingSubarray(**test_input) == 4\n\ntest_input = { \"nums\": [4,5,6] }\nassert my_solution.alternatingSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [31,32,31,32,33] }\nassert my_solution.alternatingSubarray(**test_input) == 4\n\ntest_input = { \"nums\": [21,9,5] }\nassert my_solution.alternatingSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [42,43,44,43,44,43,44,45,46] }\nassert my_solution.alternatingSubarray(**test_input) == 6\n\ntest_input = { \"nums\": [13,14,15,14] }\nassert my_solution.alternatingSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [74,75,74,75,74,75,74,75] }\nassert my_solution.alternatingSubarray(**test_input) == 8\n\ntest_input = { \"nums\": [77,78,79,78,79,78,79,78,79,80] }\nassert my_solution.alternatingSubarray(**test_input) == 8\n\ntest_input = { \"nums\": [88,42,53] }\nassert my_solution.alternatingSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [64,65,64,65,64,65,66,65,66,65] }\nassert my_solution.alternatingSubarray(**test_input) == 6\n\ntest_input = { \"nums\": [99,100,99,100] }\nassert my_solution.alternatingSubarray(**test_input) == 4\n\ntest_input = { \"nums\": [21,22] }\nassert my_solution.alternatingSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [23,24,23,24,25,24,25,24,25] }\nassert my_solution.alternatingSubarray(**test_input) == 6\n\ntest_input = { \"nums\": [20,9,15,15] }\nassert my_solution.alternatingSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [92,93,92,93,92] }\nassert my_solution.alternatingSubarray(**test_input) == 5\n\ntest_input = { \"nums\": [24,25,26] }\nassert my_solution.alternatingSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [51,52,53,52,53,52,53,54,53] }\nassert my_solution.alternatingSubarray(**test_input) == 6\n\ntest_input = { \"nums\": [65,66,65,66,67,68,69] }\nassert my_solution.alternatingSubarray(**test_input) == 4\n\ntest_input = { \"nums\": [29,2,5,24] }\nassert my_solution.alternatingSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [26,27,26,27,28,27,28,27,28] }\nassert my_solution.alternatingSubarray(**test_input) == 6\n\ntest_input = { \"nums\": [21,22,21,22,21,22] }\nassert my_solution.alternatingSubarray(**test_input) == 6\n\ntest_input = { \"nums\": [94,95,94,95,94] }\nassert my_solution.alternatingSubarray(**test_input) == 5\n\ntest_input = { \"nums\": [82,83,84,83,84,83,84,83] }\nassert my_solution.alternatingSubarray(**test_input) == 7\n\ntest_input = { \"nums\": [14,30,29,49,3,23,44,21,26,52] }\nassert my_solution.alternatingSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [4,5,4,5,6,5,6] }\nassert my_solution.alternatingSubarray(**test_input) == 4\n\ntest_input = { \"nums\": [62,63] }\nassert my_solution.alternatingSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [24,25,26,25,26,25,26,25,26] }\nassert my_solution.alternatingSubarray(**test_input) == 8\n\ntest_input = { \"nums\": [55,56,55,56,55,56,55,56,57,56] }\nassert my_solution.alternatingSubarray(**test_input) == 8\n\ntest_input = { \"nums\": [52,77,42,21] }\nassert my_solution.alternatingSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [80,81] }\nassert my_solution.alternatingSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [50,51,50,51,50,51,50,51,50] }\nassert my_solution.alternatingSubarray(**test_input) == 9\n\ntest_input = { \"nums\": [83,84,83] }\nassert my_solution.alternatingSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [17,18,17,18,19,18,19,20,19,20] }\nassert my_solution.alternatingSubarray(**test_input) == 4\n\ntest_input = { \"nums\": [5,14,8,12,5,4] }\nassert my_solution.alternatingSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [35,36,35,36,35,36,35,36,35,36] }\nassert my_solution.alternatingSubarray(**test_input) == 10\n\ntest_input = { \"nums\": [8,9,8,9,8,9] }\nassert my_solution.alternatingSubarray(**test_input) == 6\n\ntest_input = { \"nums\": [59,60] }\nassert my_solution.alternatingSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [55,56,55] }\nassert my_solution.alternatingSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [47,46,65,37,24,54,39,70] }\nassert my_solution.alternatingSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [45,46,45,46,45,46,45] }\nassert my_solution.alternatingSubarray(**test_input) == 7\n\ntest_input = { \"nums\": [78,79,78,79,78,79,78,79,80,79] }\nassert my_solution.alternatingSubarray(**test_input) == 8\n\ntest_input = { \"nums\": [65,66,65,66,65,66,67,68] }\nassert my_solution.alternatingSubarray(**test_input) == 6\n\ntest_input = { \"nums\": [62,63,62,63,62,63] }\nassert my_solution.alternatingSubarray(**test_input) == 6\n\ntest_input = { \"nums\": [7,10,5,2,11,3,9,12,9,11] }\nassert my_solution.alternatingSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [79,80,79,80,79,80] }\nassert my_solution.alternatingSubarray(**test_input) == 6\n\ntest_input = { \"nums\": [19,20,21,20,21,22] }\nassert my_solution.alternatingSubarray(**test_input) == 4\n\ntest_input = { \"nums\": [84,85,86,85,86,85,86,87,88,87] }\nassert my_solution.alternatingSubarray(**test_input) == 6\n\ntest_input = { \"nums\": [54,55] }\nassert my_solution.alternatingSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [71,14,24,13,21,14,18,84,37,2] }\nassert my_solution.alternatingSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [26,27,26] }\nassert my_solution.alternatingSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [53,54,53,54,53] }\nassert my_solution.alternatingSubarray(**test_input) == 5\n\ntest_input = { \"nums\": [67,68,67,68,67,68,69,70,69,70] }\nassert my_solution.alternatingSubarray(**test_input) == 6\n\ntest_input = { \"nums\": [85,86,85,86,85,86,85,86,85,86] }\nassert my_solution.alternatingSubarray(**test_input) == 10\n\ntest_input = { \"nums\": [22,16,27,22,44,10] }\nassert my_solution.alternatingSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [27,28,27,28,27,28,27,28,29,28] }\nassert my_solution.alternatingSubarray(**test_input) == 8\n\ntest_input = { \"nums\": [54,55,54,55,54,55,54,55,56,57] }\nassert my_solution.alternatingSubarray(**test_input) == 8\n\ntest_input = { \"nums\": [24,25,26,27,28] }\nassert my_solution.alternatingSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [55,56] }\nassert my_solution.alternatingSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [13,6,6,8,12,7,1] }\nassert my_solution.alternatingSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [40,41,40,41,40,41,40,41] }\nassert my_solution.alternatingSubarray(**test_input) == 8\n\ntest_input = { \"nums\": [10,11,10,11,10,11,12] }\nassert my_solution.alternatingSubarray(**test_input) == 6\n\ntest_input = { \"nums\": [58,59,58,59] }\nassert my_solution.alternatingSubarray(**test_input) == 4\n\ntest_input = { \"nums\": [1,15,44,74,56,41,48,71] }\nassert my_solution.alternatingSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [89,90,89,90,89,90] }\nassert my_solution.alternatingSubarray(**test_input) == 6\n\ntest_input = { \"nums\": [4,5,4,5,4,5,6] }\nassert my_solution.alternatingSubarray(**test_input) == 6\n\ntest_input = { \"nums\": [50,51,52,53,52,53] }\nassert my_solution.alternatingSubarray(**test_input) == 4\n\ntest_input = { \"nums\": [44,45,46,45,46,45,46,47,48] }\nassert my_solution.alternatingSubarray(**test_input) == 6\n\ntest_input = { \"nums\": [16,3,25,12,2,19,1,26] }\nassert my_solution.alternatingSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [17,18,19,20,19,20] }\nassert my_solution.alternatingSubarray(**test_input) == 4\n\ntest_input = { \"nums\": [91,92,93,92,93] }\nassert my_solution.alternatingSubarray(**test_input) == 4\n\ntest_input = { \"nums\": [28,29,28,29,28,29,30] }\nassert my_solution.alternatingSubarray(**test_input) == 6\n\ntest_input = { \"nums\": [88,89,88,89,88,89] }\nassert my_solution.alternatingSubarray(**test_input) == 6\n\ntest_input = { \"nums\": [1,1,1,1,1,1,1,1,1,1] }\nassert my_solution.alternatingSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [32,33,32,33,32,33,34] }\nassert my_solution.alternatingSubarray(**test_input) == 6\n\ntest_input = { \"nums\": [61,62,61,62,63,62,63,64,63] }\nassert my_solution.alternatingSubarray(**test_input) == 4\n\ntest_input = { \"nums\": [6,7,6,7] }\nassert my_solution.alternatingSubarray(**test_input) == 4\n\ntest_input = { \"nums\": [20,21,20,21,20] }\nassert my_solution.alternatingSubarray(**test_input) == 5\n\ntest_input = { \"nums\": [14,6,21] }\nassert my_solution.alternatingSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [12,13,12,13,12,13,12,13,12] }\nassert my_solution.alternatingSubarray(**test_input) == 9\n\ntest_input = { \"nums\": [33,34,33,34,33,34,33] }\nassert my_solution.alternatingSubarray(**test_input) == 7\n\ntest_input = { \"nums\": [92,93,92] }\nassert my_solution.alternatingSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [93,94,95,94,95,96,95,96,97] }\nassert my_solution.alternatingSubarray(**test_input) == 4\n\ntest_input = { \"nums\": [8,4,27] }\nassert my_solution.alternatingSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [30,31,32,31,32,33,34,33] }\nassert my_solution.alternatingSubarray(**test_input) == 4\n\ntest_input = { \"nums\": [26,27,26,27,26,27] }\nassert my_solution.alternatingSubarray(**test_input) == 6\n\ntest_input = { \"nums\": [67,68,69] }\nassert my_solution.alternatingSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [83,84,85,84,85] }\nassert my_solution.alternatingSubarray(**test_input) == 4\n\ntest_input = { \"nums\": [6,26,4,2] }\nassert my_solution.alternatingSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [81,82,81,82,81,82,81,82,83] }\nassert my_solution.alternatingSubarray(**test_input) == 8\n\ntest_input = { \"nums\": [58,59] }\nassert my_solution.alternatingSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [82,83,82,83,82,83,82,83,82] }\nassert my_solution.alternatingSubarray(**test_input) == 9\n\ntest_input = { \"nums\": [48,49] }\nassert my_solution.alternatingSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [8,6,2] }\nassert my_solution.alternatingSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [69,70,69,70,69,70,69,70,69] }\nassert my_solution.alternatingSubarray(**test_input) == 9\n\ntest_input = { \"nums\": [28,29,28,29] }\nassert my_solution.alternatingSubarray(**test_input) == 4\n\ntest_input = { \"nums\": [82,83,82,83,84] }\nassert my_solution.alternatingSubarray(**test_input) == 4\n\ntest_input = { \"nums\": [97,98,97,98,97,98,97] }\nassert my_solution.alternatingSubarray(**test_input) == 7\n\ntest_input = { \"nums\": [2,2,1] }\nassert my_solution.alternatingSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [84,85,84,85,84,85,84] }\nassert my_solution.alternatingSubarray(**test_input) == 7\n\ntest_input = { \"nums\": [21,22,21,22] }\nassert my_solution.alternatingSubarray(**test_input) == 4", "start_time": 1688826600} +{"task_id": "biweekly-contest-108-relocate-marbles", "url": "https://leetcode.com/problems/relocate-marbles", "title": "relocate-marbles", "meta": {"questionId": "2834", "questionFrontendId": "2766", "title": "Relocate Marbles", "titleSlug": "relocate-marbles", "isPaidOnly": false, "difficulty": "Medium", "likes": 170, "dislikes": 13, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0 开始的整数数组 nums ,表示一些石块的初始位置。再给你两个长度 相等 下标从 0 开始的整数数组 moveFrom 和 moveTo 。\n\n在 moveFrom.length 次操作内,你可以改变石块的位置。在第 i 次操作中,你将位置在 moveFrom[i] 的所有石块移到位置 moveTo[i] 。\n\n完成这些操作后,请你按升序返回所有 有 石块的位置。\n\n注意:\n\n * 如果一个位置至少有一个石块,我们称这个位置 有 石块。\n * 一个位置可能会有多个石块。\n\n示例 1:\n\n输入:nums = [1,6,7,8], moveFrom = [1,7,2], moveTo = [2,9,5]\n输出:[5,6,8,9]\n解释:一开始,石块在位置 1,6,7,8 。\n第 i = 0 步操作中,我们将位置 1 处的石块移到位置 2 处,位置 2,6,7,8 有石块。\n第 i = 1 步操作中,我们将位置 7 处的石块移到位置 9 处,位置 2,6,8,9 有石块。\n第 i = 2 步操作中,我们将位置 2 处的石块移到位置 5 处,位置 5,6,8,9 有石块。\n最后,至少有一个石块的位置为 [5,6,8,9] 。\n\n示例 2:\n\n输入:nums = [1,1,3,3], moveFrom = [1,3], moveTo = [2,2]\n输出:[2]\n解释:一开始,石块在位置 [1,1,3,3] 。\n第 i = 0 步操作中,我们将位置 1 处的石块移到位置 2 处,有石块的位置为 [2,2,3,3] 。\n第 i = 1 步操作中,我们将位置 3 处的石块移到位置 2 处,有石块的位置为 [2,2,2,2] 。\n由于 2 是唯一有石块的位置,我们返回 [2] 。\n\n\n提示:\n\n * 1 <= nums.length <= 105\n * 1 <= moveFrom.length <= 105\n * moveFrom.length == moveTo.length\n * 1 <= nums[i], moveFrom[i], moveTo[i] <= 109\n * 测试数据保证在进行第 i 步操作时,moveFrom[i] 处至少有一个石块。\n\"\"\"\nclass Solution:\n def relocateMarbles(self, nums: List[int], moveFrom: List[int], moveTo: List[int]) -> List[int]:\n ", "prompt_sft": "给你一个下标从 0 开始的整数数组 nums ,表示一些石块的初始位置。再给你两个长度 相等 下标从 0 开始的整数数组 moveFrom 和 moveTo 。\n\n在 moveFrom.length 次操作内,你可以改变石块的位置。在第 i 次操作中,你将位置在 moveFrom[i] 的所有石块移到位置 moveTo[i] 。\n\n完成这些操作后,请你按升序返回所有 有 石块的位置。\n\n注意:\n\n * 如果一个位置至少有一个石块,我们称这个位置 有 石块。\n * 一个位置可能会有多个石块。\n\n示例 1:\n\n输入:nums = [1,6,7,8], moveFrom = [1,7,2], moveTo = [2,9,5]\n输出:[5,6,8,9]\n解释:一开始,石块在位置 1,6,7,8 。\n第 i = 0 步操作中,我们将位置 1 处的石块移到位置 2 处,位置 2,6,7,8 有石块。\n第 i = 1 步操作中,我们将位置 7 处的石块移到位置 9 处,位置 2,6,8,9 有石块。\n第 i = 2 步操作中,我们将位置 2 处的石块移到位置 5 处,位置 5,6,8,9 有石块。\n最后,至少有一个石块的位置为 [5,6,8,9] 。\n\n示例 2:\n\n输入:nums = [1,1,3,3], moveFrom = [1,3], moveTo = [2,2]\n输出:[2]\n解释:一开始,石块在位置 [1,1,3,3] 。\n第 i = 0 步操作中,我们将位置 1 处的石块移到位置 2 处,有石块的位置为 [2,2,3,3] 。\n第 i = 1 步操作中,我们将位置 3 处的石块移到位置 2 处,有石块的位置为 [2,2,2,2] 。\n由于 2 是唯一有石块的位置,我们返回 [2] 。\n\n\n提示:\n\n * 1 <= nums.length <= 105\n * 1 <= moveFrom.length <= 105\n * moveFrom.length == moveTo.length\n * 1 <= nums[i], moveFrom[i], moveTo[i] <= 109\n * 测试数据保证在进行第 i 步操作时,moveFrom[i] 处至少有一个石块。\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def relocateMarbles(self, nums: List[int], moveFrom: List[int], moveTo: List[int]) -> List[int]:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,6,7,8], \"moveFrom\": [1,7,2], \"moveTo\": [2,9,5] }\nassert my_solution.relocateMarbles(**test_input) == [5,6,8,9]\n\ntest_input = { \"nums\": [1,1,3,3], \"moveFrom\": [1,3], \"moveTo\": [2,2] }\nassert my_solution.relocateMarbles(**test_input) == [2]\n\ntest_input = { \"nums\": [5,7,8,15], \"moveFrom\": [5,7,8,9], \"moveTo\": [9,15,2,7] }\nassert my_solution.relocateMarbles(**test_input) == [2,7,15]\n\ntest_input = { \"nums\": [4,6,6,9,18], \"moveFrom\": [18,6,17,4,9,19,2], \"moveTo\": [23,17,20,19,11,2,20] }\nassert my_solution.relocateMarbles(**test_input) == [11,20,23]\n\ntest_input = { \"nums\": [3,4], \"moveFrom\": [4,3,1,2,2,3,2,4,1], \"moveTo\": [3,1,2,2,3,2,4,1,1] }\nassert my_solution.relocateMarbles(**test_input) == [1]\n\ntest_input = { \"nums\": [5,13,22,23,23,33], \"moveFrom\": [13,5,12], \"moveTo\": [1,12,13] }\nassert my_solution.relocateMarbles(**test_input) == [1,13,22,23,33]\n\ntest_input = { \"nums\": [21,24,35,72,77,82,82,96,97,97], \"moveFrom\": [82,76,3,97], \"moveTo\": [76,3,52,27] }\nassert my_solution.relocateMarbles(**test_input) == [21,24,27,35,52,72,77,96]\n\ntest_input = { \"nums\": [4,6,17,41,46,46,52,57], \"moveFrom\": [4], \"moveTo\": [62] }\nassert my_solution.relocateMarbles(**test_input) == [6,17,41,46,52,57,62]\n\ntest_input = { \"nums\": [1,4,10,24,46,55,61,63,71], \"moveFrom\": [10,52,1,80,63,55,4,46,71,24], \"moveTo\": [52,42,80,55,50,62,60,17,46,38] }\nassert my_solution.relocateMarbles(**test_input) == [17,38,42,46,50,60,61,62]\n\ntest_input = { \"nums\": [8,9,16,17,23], \"moveFrom\": [8,5,16,2,9], \"moveTo\": [5,20,2,18,22] }\nassert my_solution.relocateMarbles(**test_input) == [17,18,20,22,23]\n\ntest_input = { \"nums\": [12,37,46,47,49,55,59,65,71,88], \"moveFrom\": [88,59,71], \"moveTo\": [81,39,73] }\nassert my_solution.relocateMarbles(**test_input) == [12,37,39,46,47,49,55,65,73,81]\n\ntest_input = { \"nums\": [2,45,45,48,51,57,67,73,78,78], \"moveFrom\": [78,67,45,34,51,62,48,95,2,67], \"moveTo\": [34,65,62,95,62,12,85,67,79,71] }\nassert my_solution.relocateMarbles(**test_input) == [12,57,65,71,73,79,85]\n\ntest_input = { \"nums\": [1,2], \"moveFrom\": [1,2,3], \"moveTo\": [2,3,2] }\nassert my_solution.relocateMarbles(**test_input) == [2]\n\ntest_input = { \"nums\": [7,19,28,34,36,36,47], \"moveFrom\": [36,33,34,28,41,19,14,47,28,40], \"moveTo\": [33,41,27,47,14,40,46,28,42,16] }\nassert my_solution.relocateMarbles(**test_input) == [7,16,27,42,46]\n\ntest_input = { \"nums\": [1,1,1], \"moveFrom\": [1], \"moveTo\": [7] }\nassert my_solution.relocateMarbles(**test_input) == [7]\n\ntest_input = { \"nums\": [1], \"moveFrom\": [1,1,1,1,1,1], \"moveTo\": [1,1,1,1,1,1] }\nassert my_solution.relocateMarbles(**test_input) == [1]\n\ntest_input = { \"nums\": [5,9,17,20,29,29], \"moveFrom\": [20,5,1,29,22,21,9,36,33,1], \"moveTo\": [1,22,21,36,36,15,33,1,3,15] }\nassert my_solution.relocateMarbles(**test_input) == [3,15,17]\n\ntest_input = { \"nums\": [1], \"moveFrom\": [1,1,1,1], \"moveTo\": [1,1,1,1] }\nassert my_solution.relocateMarbles(**test_input) == [1]\n\ntest_input = { \"nums\": [27,41,50,52,57,60,65,67,70], \"moveFrom\": [52,67,70,50,57,27,47], \"moveTo\": [45,45,61,47,21,65,60] }\nassert my_solution.relocateMarbles(**test_input) == [21,41,45,60,61,65]\n\ntest_input = { \"nums\": [2,3,7], \"moveFrom\": [2,7,8,8,3,5,1,4], \"moveTo\": [8,5,8,1,4,4,4,5] }\nassert my_solution.relocateMarbles(**test_input) == [5]\n\ntest_input = { \"nums\": [4,6,8,10], \"moveFrom\": [8,6], \"moveTo\": [4,3] }\nassert my_solution.relocateMarbles(**test_input) == [3,4,10]\n\ntest_input = { \"nums\": [2,4,29,34,41,44,48], \"moveFrom\": [29,3,44,48,2,43,4], \"moveTo\": [3,24,43,42,24,8,6] }\nassert my_solution.relocateMarbles(**test_input) == [6,8,24,34,41,42]\n\ntest_input = { \"nums\": [12,16,22,28,36,42,60,63], \"moveFrom\": [42,28,12,22], \"moveTo\": [22,63,14,45] }\nassert my_solution.relocateMarbles(**test_input) == [14,16,36,45,60,63]\n\ntest_input = { \"nums\": [12,18,21,21,31,38,39,41,84,90], \"moveFrom\": [41,31,12,84,9,39,21,62], \"moveTo\": [24,17,58,9,62,36,23,90] }\nassert my_solution.relocateMarbles(**test_input) == [17,18,23,24,36,38,58,90]\n\ntest_input = { \"nums\": [12,23,30,35,46,53,64,74,81], \"moveFrom\": [53,74,54,48,52,64,35,30,46,29], \"moveTo\": [54,48,52,47,53,29,52,10,44,28] }\nassert my_solution.relocateMarbles(**test_input) == [10,12,23,28,44,47,52,53,81]\n\ntest_input = { \"nums\": [2,10,13,14,16,30], \"moveFrom\": [2,6,14,16,25,13,30], \"moveTo\": [6,30,25,1,32,17,11] }\nassert my_solution.relocateMarbles(**test_input) == [1,10,11,17,32]\n\ntest_input = { \"nums\": [1,6,10,11,18,22,30], \"moveFrom\": [10,18,1,30,6], \"moveTo\": [1,37,28,38,15] }\nassert my_solution.relocateMarbles(**test_input) == [11,15,22,28,37,38]\n\ntest_input = { \"nums\": [3,9,10,13], \"moveFrom\": [9,3,13,10,5,11,8], \"moveTo\": [11,5,11,15,8,5,14] }\nassert my_solution.relocateMarbles(**test_input) == [5,14,15]\n\ntest_input = { \"nums\": [15,31,32,52,61,65,78,84,93,100], \"moveFrom\": [15,32,93,3,78,65,61,84], \"moveTo\": [61,3,8,55,23,87,95,44] }\nassert my_solution.relocateMarbles(**test_input) == [8,23,31,44,52,55,87,95,100]\n\ntest_input = { \"nums\": [1,2], \"moveFrom\": [1,2,1,1,1,3,4,4], \"moveTo\": [1,1,1,1,3,4,4,2] }\nassert my_solution.relocateMarbles(**test_input) == [2]\n\ntest_input = { \"nums\": [2,2,2], \"moveFrom\": [2,8,5,9], \"moveTo\": [8,5,9,2] }\nassert my_solution.relocateMarbles(**test_input) == [2]\n\ntest_input = { \"nums\": [3,10,11,27,58,59,61,66,68], \"moveFrom\": [59,61,3,15], \"moveTo\": [15,68,77,52] }\nassert my_solution.relocateMarbles(**test_input) == [10,11,27,52,58,66,68,77]\n\ntest_input = { \"nums\": [2,9,9], \"moveFrom\": [9,2,8,9,4,6,7,1,5,5], \"moveTo\": [4,8,9,4,6,7,1,5,5,5] }\nassert my_solution.relocateMarbles(**test_input) == [5]\n\ntest_input = { \"nums\": [1,18,24,25,29,31], \"moveFrom\": [18,25,29,18,23], \"moveTo\": [3,23,18,18,8] }\nassert my_solution.relocateMarbles(**test_input) == [1,3,8,18,24,31]\n\ntest_input = { \"nums\": [2,18,38,38,48,50,51,61,71], \"moveFrom\": [61,71,2,18,47,22,24,51], \"moveTo\": [58,38,22,47,68,24,47,60] }\nassert my_solution.relocateMarbles(**test_input) == [38,47,48,50,58,60,68]\n\ntest_input = { \"nums\": [11,11,35,35,38,43,45], \"moveFrom\": [35,11,2,27,38,45,47,17], \"moveTo\": [2,47,27,17,47,24,35,21] }\nassert my_solution.relocateMarbles(**test_input) == [21,24,35,43]\n\ntest_input = { \"nums\": [4,11,15,28,36,42,45,57], \"moveFrom\": [57,32,36,11,52,42,55,4], \"moveTo\": [32,55,39,52,11,54,31,56] }\nassert my_solution.relocateMarbles(**test_input) == [11,15,28,31,39,45,54,56]\n\ntest_input = { \"nums\": [2,4], \"moveFrom\": [4,2], \"moveTo\": [4,1] }\nassert my_solution.relocateMarbles(**test_input) == [1,4]\n\ntest_input = { \"nums\": [9,14,24,31,32,40,47,54,75,76], \"moveFrom\": [31,75,76,3,47,32,24,9,14,18], \"moveTo\": [76,76,3,8,18,66,32,2,62,82] }\nassert my_solution.relocateMarbles(**test_input) == [2,8,32,40,54,62,66,82]\n\ntest_input = { \"nums\": [1], \"moveFrom\": [1,1,1,1,1,1,1], \"moveTo\": [1,1,1,1,1,1,1] }\nassert my_solution.relocateMarbles(**test_input) == [1]\n\ntest_input = { \"nums\": [2,12,13,14,18], \"moveFrom\": [13,2,14], \"moveTo\": [17,20,19] }\nassert my_solution.relocateMarbles(**test_input) == [12,17,18,19,20]\n\ntest_input = { \"nums\": [12,21,24,28,41,60,62,70,76], \"moveFrom\": [21,76,41,3], \"moveTo\": [23,33,3,53] }\nassert my_solution.relocateMarbles(**test_input) == [12,23,24,28,33,53,60,62,70]\n\ntest_input = { \"nums\": [7,29,40,43,48,56,60,72,81], \"moveFrom\": [56,60,6,62], \"moveTo\": [62,6,34,17] }\nassert my_solution.relocateMarbles(**test_input) == [7,17,29,34,40,43,48,72,81]\n\ntest_input = { \"nums\": [2,4,5,8], \"moveFrom\": [2,4,3,7,5,8,14], \"moveTo\": [3,7,9,14,9,6,16] }\nassert my_solution.relocateMarbles(**test_input) == [6,9,16]\n\ntest_input = { \"nums\": [9,15,18,24,39,48,59,64], \"moveFrom\": [59,64,63,60,9], \"moveTo\": [60,63,61,45,57] }\nassert my_solution.relocateMarbles(**test_input) == [15,18,24,39,45,48,57,61]\n\ntest_input = { \"nums\": [2,8,8,9,11,21], \"moveFrom\": [8,11,30,21,14,27,9,22,2,7], \"moveTo\": [30,27,22,14,7,3,1,21,4,16] }\nassert my_solution.relocateMarbles(**test_input) == [1,3,4,16,21]\n\ntest_input = { \"nums\": [5,11,30,43,47,63,65,82,86,93], \"moveFrom\": [43,63,11,93,82,47,54,5,30], \"moveTo\": [36,53,54,49,18,3,29,66,22] }\nassert my_solution.relocateMarbles(**test_input) == [3,18,22,29,36,49,53,65,66,86]\n\ntest_input = { \"nums\": [9,14,14,16,26,51,53,64,76], \"moveFrom\": [64,45,9,14,26,53,51,67,80], \"moveTo\": [45,67,23,37,80,16,27,51,44] }\nassert my_solution.relocateMarbles(**test_input) == [16,23,27,37,44,51,76]\n\ntest_input = { \"nums\": [16,21,21,25,39,41,44], \"moveFrom\": [41,21,45,29,35,39,29,25,28], \"moveTo\": [21,45,29,35,33,29,20,28,45] }\nassert my_solution.relocateMarbles(**test_input) == [16,20,33,44,45]\n\ntest_input = { \"nums\": [1,1,3], \"moveFrom\": [3,1,9,5,5], \"moveTo\": [9,9,5,5,9] }\nassert my_solution.relocateMarbles(**test_input) == [9]\n\ntest_input = { \"nums\": [12,14,16,16,21,32], \"moveFrom\": [32,5,14,21,15,22,16], \"moveTo\": [5,22,15,16,15,27,22] }\nassert my_solution.relocateMarbles(**test_input) == [12,15,22,27]\n\ntest_input = { \"nums\": [1,5,9], \"moveFrom\": [1,5,9,3,8,5,9,1,5], \"moveTo\": [8,3,9,1,5,8,1,5,2] }\nassert my_solution.relocateMarbles(**test_input) == [2,8]\n\ntest_input = { \"nums\": [1,2,14,30,43,44,76,76,77], \"moveFrom\": [76,77,43,1], \"moveTo\": [56,44,11,45] }\nassert my_solution.relocateMarbles(**test_input) == [2,11,14,30,44,45,56]\n\ntest_input = { \"nums\": [4,25,27,33,33,35], \"moveFrom\": [25,27,27,34,7,36], \"moveTo\": [34,27,36,7,25,1] }\nassert my_solution.relocateMarbles(**test_input) == [1,4,25,33,35]\n\ntest_input = { \"nums\": [3,7,18,25,37,48,48,62], \"moveFrom\": [48,18,62,48,2,18,56,53,37], \"moveTo\": [15,48,56,2,18,55,53,40,22] }\nassert my_solution.relocateMarbles(**test_input) == [3,7,15,22,25,40,55]\n\ntest_input = { \"nums\": [19,35,46,55,59,59,68,72,93,100], \"moveFrom\": [46,100,35,19,68,87,21,93,27], \"moveTo\": [76,94,87,66,57,21,27,89,40] }\nassert my_solution.relocateMarbles(**test_input) == [40,55,57,59,66,72,76,89,94]\n\ntest_input = { \"nums\": [1,3], \"moveFrom\": [3,1,3,4,4], \"moveTo\": [1,3,4,4,4] }\nassert my_solution.relocateMarbles(**test_input) == [4]\n\ntest_input = { \"nums\": [22,30,36,40,44,48,50,59], \"moveFrom\": [30,44,64,59,4], \"moveTo\": [64,4,50,25,36] }\nassert my_solution.relocateMarbles(**test_input) == [22,25,36,40,48,50]\n\ntest_input = { \"nums\": [1], \"moveFrom\": [1,1,1,1,1,1,1,1,1,1], \"moveTo\": [1,1,1,1,1,1,1,1,1,1] }\nassert my_solution.relocateMarbles(**test_input) == [1]\n\ntest_input = { \"nums\": [8,18,23,37,37,39,48], \"moveFrom\": [8,39,23,7,37,36], \"moveTo\": [39,7,36,25,10,28] }\nassert my_solution.relocateMarbles(**test_input) == [10,18,25,28,48]\n\ntest_input = { \"nums\": [1,4], \"moveFrom\": [1,2,4], \"moveTo\": [2,3,1] }\nassert my_solution.relocateMarbles(**test_input) == [1,3]\n\ntest_input = { \"nums\": [3,7,9,13], \"moveFrom\": [3,16,9,7,6,15,16,7,13,7], \"moveTo\": [16,6,2,15,8,16,7,1,7,9] }\nassert my_solution.relocateMarbles(**test_input) == [1,2,8,9]\n\ntest_input = { \"nums\": [11,12,17,18,20], \"moveFrom\": [11,17], \"moveTo\": [18,13] }\nassert my_solution.relocateMarbles(**test_input) == [12,13,18,20]\n\ntest_input = { \"nums\": [5,11,17,21,25], \"moveFrom\": [17], \"moveTo\": [14] }\nassert my_solution.relocateMarbles(**test_input) == [5,11,14,21,25]\n\ntest_input = { \"nums\": [7,9,12,20,23], \"moveFrom\": [7,8], \"moveTo\": [8,12] }\nassert my_solution.relocateMarbles(**test_input) == [9,12,20,23]\n\ntest_input = { \"nums\": [1], \"moveFrom\": [1,1], \"moveTo\": [1,1] }\nassert my_solution.relocateMarbles(**test_input) == [1]\n\ntest_input = { \"nums\": [10,13,17,49,56,57,59,62,68], \"moveFrom\": [49,62,59,45], \"moveTo\": [58,64,45,77] }\nassert my_solution.relocateMarbles(**test_input) == [10,13,17,56,57,58,64,68,77]\n\ntest_input = { \"nums\": [1,8,15,23,24,29,47], \"moveFrom\": [8,23,24,47,10,1], \"moveTo\": [38,10,10,48,22,24] }\nassert my_solution.relocateMarbles(**test_input) == [15,22,24,29,38,48]\n\ntest_input = { \"nums\": [3,3], \"moveFrom\": [3,1,4,2,2,2,2,2,1], \"moveTo\": [1,4,2,2,2,2,2,1,3] }\nassert my_solution.relocateMarbles(**test_input) == [3]\n\ntest_input = { \"nums\": [4,8,8], \"moveFrom\": [8,7,7], \"moveTo\": [7,7,8] }\nassert my_solution.relocateMarbles(**test_input) == [4,8]\n\ntest_input = { \"nums\": [1,2], \"moveFrom\": [1,2,1,3,4,2,3,4,1,4], \"moveTo\": [3,1,3,4,2,3,4,1,4,4] }\nassert my_solution.relocateMarbles(**test_input) == [4]\n\ntest_input = { \"nums\": [12,13,16,31,48,52,56,72,79], \"moveFrom\": [13,79,12,72,14,48,56,52], \"moveTo\": [56,14,8,63,70,54,19,73] }\nassert my_solution.relocateMarbles(**test_input) == [8,16,19,31,54,63,70,73]\n\ntest_input = { \"nums\": [3,7,7,14], \"moveFrom\": [3,16,7,15,12,5,14,16,13], \"moveTo\": [16,15,5,12,16,14,9,13,5] }\nassert my_solution.relocateMarbles(**test_input) == [5,9]\n\ntest_input = { \"nums\": [9,13,14,15], \"moveFrom\": [15,14,13,5,8], \"moveTo\": [8,3,5,3,12] }\nassert my_solution.relocateMarbles(**test_input) == [3,9,12]\n\ntest_input = { \"nums\": [11,16,28,33,37,45,45,58,79], \"moveFrom\": [16,57,81,79,11], \"moveTo\": [57,81,29,45,31] }\nassert my_solution.relocateMarbles(**test_input) == [28,29,31,33,37,45,58]\n\ntest_input = { \"nums\": [1,6,7,7], \"moveFrom\": [6,8,8,12,15,8,9,15], \"moveTo\": [8,8,12,15,8,9,15,8] }\nassert my_solution.relocateMarbles(**test_input) == [1,7,8]\n\ntest_input = { \"nums\": [7,20,23,25,33,39,51,74,76], \"moveFrom\": [76,20,74,7,15], \"moveTo\": [74,64,15,40,71] }\nassert my_solution.relocateMarbles(**test_input) == [23,25,33,39,40,51,64,71]\n\ntest_input = { \"nums\": [4,6,6], \"moveFrom\": [6,4,7,6,4,7,8,1,2,4], \"moveTo\": [6,7,4,7,8,2,1,9,4,2] }\nassert my_solution.relocateMarbles(**test_input) == [2,9]\n\ntest_input = { \"nums\": [8,14,17,19,21], \"moveFrom\": [19,8,14,21,17,1,14,18], \"moveTo\": [14,18,14,1,18,23,10,12] }\nassert my_solution.relocateMarbles(**test_input) == [10,12,23]\n\ntest_input = { \"nums\": [13,18,39,44,45,49,72,81,95,100], \"moveFrom\": [49,81,18,39,44,22,100,66,45,5], \"moveTo\": [54,22,66,32,13,4,76,5,92,33] }\nassert my_solution.relocateMarbles(**test_input) == [4,13,32,33,54,72,76,92,95]\n\ntest_input = { \"nums\": [1,3], \"moveFrom\": [3,1,3,4,3,3,3,3,2], \"moveTo\": [1,3,4,3,3,3,3,2,3] }\nassert my_solution.relocateMarbles(**test_input) == [3]\n\ntest_input = { \"nums\": [2,4,5,13], \"moveFrom\": [13,5,2], \"moveTo\": [1,9,10] }\nassert my_solution.relocateMarbles(**test_input) == [1,4,9,10]\n\ntest_input = { \"nums\": [1], \"moveFrom\": [1], \"moveTo\": [1] }\nassert my_solution.relocateMarbles(**test_input) == [1]\n\ntest_input = { \"nums\": [3,4,13,14,19], \"moveFrom\": [13,3,19,3,3,14,13,4,15,11], \"moveTo\": [15,3,8,3,13,1,10,22,11,2] }\nassert my_solution.relocateMarbles(**test_input) == [1,2,8,10,22]\n\ntest_input = { \"nums\": [3,6,9,11], \"moveFrom\": [9,3,8], \"moveTo\": [7,8,9] }\nassert my_solution.relocateMarbles(**test_input) == [6,7,9,11]\n\ntest_input = { \"nums\": [9,15,16,18,20,26], \"moveFrom\": [20,18,13], \"moveTo\": [31,13,32] }\nassert my_solution.relocateMarbles(**test_input) == [9,15,16,26,31,32]\n\ntest_input = { \"nums\": [6,11,21,25,25], \"moveFrom\": [11,21,2,25,17,1], \"moveTo\": [17,2,19,8,1,9] }\nassert my_solution.relocateMarbles(**test_input) == [6,8,9,19]\n\ntest_input = { \"nums\": [2,6,8], \"moveFrom\": [2,6,8,2,9,2,7], \"moveTo\": [8,2,2,9,2,7,8] }\nassert my_solution.relocateMarbles(**test_input) == [8]\n\ntest_input = { \"nums\": [1,7,7], \"moveFrom\": [1,7,1,6,2,9,5,6], \"moveTo\": [2,1,6,9,5,6,5,6] }\nassert my_solution.relocateMarbles(**test_input) == [5,6]\n\ntest_input = { \"nums\": [4,6,7,12,12,25,37], \"moveFrom\": [37,41,37,6,4,7,25], \"moveTo\": [41,37,37,26,7,45,45] }\nassert my_solution.relocateMarbles(**test_input) == [12,26,37,45]\n\ntest_input = { \"nums\": [3,4], \"moveFrom\": [4,3], \"moveTo\": [2,1] }\nassert my_solution.relocateMarbles(**test_input) == [1,2]\n\ntest_input = { \"nums\": [1,2], \"moveFrom\": [1,2,3,3,2,1,2], \"moveTo\": [2,3,3,2,1,2,2] }\nassert my_solution.relocateMarbles(**test_input) == [2]\n\ntest_input = { \"nums\": [20,37,44,53,55,59,60,62], \"moveFrom\": [20,44,53,60,11,55,37,59], \"moveTo\": [53,28,62,11,16,63,9,6] }\nassert my_solution.relocateMarbles(**test_input) == [6,9,16,28,62,63]\n\ntest_input = { \"nums\": [2,4], \"moveFrom\": [4,2,2,1,4,2,2,3], \"moveTo\": [2,2,1,4,2,2,3,4] }\nassert my_solution.relocateMarbles(**test_input) == [4]\n\ntest_input = { \"nums\": [2,6,7], \"moveFrom\": [6,7,6,3,6,5,2], \"moveTo\": [6,6,3,6,5,4,8] }\nassert my_solution.relocateMarbles(**test_input) == [4,8]\n\ntest_input = { \"nums\": [3,7,13,13], \"moveFrom\": [13,7,4,6], \"moveTo\": [9,4,6,15] }\nassert my_solution.relocateMarbles(**test_input) == [3,9,15]\n\ntest_input = { \"nums\": [2,3], \"moveFrom\": [2,3], \"moveTo\": [1,1] }\nassert my_solution.relocateMarbles(**test_input) == [1]\n\ntest_input = { \"nums\": [12,13,25,27,34,34,38], \"moveFrom\": [12,13,11,33,2,25,34,27,38], \"moveTo\": [11,2,33,26,25,30,24,38,47] }\nassert my_solution.relocateMarbles(**test_input) == [24,26,30,47]\n\ntest_input = { \"nums\": [2,13,20,29,34,48,48], \"moveFrom\": [2,13], \"moveTo\": [5,42] }\nassert my_solution.relocateMarbles(**test_input) == [5,20,29,34,42,48]\n\ntest_input = { \"nums\": [19,30,31,41,47,54,57,62], \"moveFrom\": [41,31,62,30,54], \"moveTo\": [38,49,10,60,31] }\nassert my_solution.relocateMarbles(**test_input) == [10,19,31,38,47,49,57,60]", "start_time": 1688826600} +{"task_id": "biweekly-contest-108-partition-string-into-minimum-beautiful-substrings", "url": "https://leetcode.com/problems/partition-string-into-minimum-beautiful-substrings", "title": "partition-string-into-minimum-beautiful-substrings", "meta": {"questionId": "2883", "questionFrontendId": "2767", "title": "Partition String Into Minimum Beautiful Substrings", "titleSlug": "partition-string-into-minimum-beautiful-substrings", "isPaidOnly": false, "difficulty": "Medium", "likes": 289, "dislikes": 8, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个二进制字符串 s ,你需要将字符串分割成一个或者多个 子字符串  ,使每个子字符串都是 美丽 的。\n\n如果一个字符串满足以下条件,我们称它是 美丽 的:\n\n * 它不包含前导 0 。\n * 它是 5 的幂的 二进制 表示。\n\n请你返回分割后的子字符串的 最少 数目。如果无法将字符串 s 分割成美丽子字符串,请你返回 -1 。\n\n子字符串是一个字符串中一段连续的字符序列。\n\n示例 1:\n\n输入:s = \"1011\"\n输出:2\n解释:我们可以将输入字符串分成 [\"101\", \"1\"] 。\n- 字符串 \"101\" 不包含前导 0 ,且它是整数 51 = 5 的二进制表示。\n- 字符串 \"1\" 不包含前导 0 ,且它是整数 50 = 1 的二进制表示。\n最少可以将 s 分成 2 个美丽子字符串。\n\n示例 2:\n\n输入:s = \"111\"\n输出:3\n解释:我们可以将输入字符串分成 [\"1\", \"1\", \"1\"] 。\n- 字符串 \"1\" 不包含前导 0 ,且它是整数 50 = 1 的二进制表示。\n最少可以将 s 分成 3 个美丽子字符串。\n\n示例 3:\n\n输入:s = \"0\"\n输出:-1\n解释:无法将给定字符串分成任何美丽子字符串。\n\n\n提示:\n\n * 1 <= s.length <= 15\n * s[i] 要么是 '0' 要么是 '1' 。\n\"\"\"\nclass Solution:\n def minimumBeautifulSubstrings(self, s: str) -> int:\n ", "prompt_sft": "给你一个二进制字符串 s ,你需要将字符串分割成一个或者多个 子字符串  ,使每个子字符串都是 美丽 的。\n\n如果一个字符串满足以下条件,我们称它是 美丽 的:\n\n * 它不包含前导 0 。\n * 它是 5 的幂的 二进制 表示。\n\n请你返回分割后的子字符串的 最少 数目。如果无法将字符串 s 分割成美丽子字符串,请你返回 -1 。\n\n子字符串是一个字符串中一段连续的字符序列。\n\n示例 1:\n\n输入:s = \"1011\"\n输出:2\n解释:我们可以将输入字符串分成 [\"101\", \"1\"] 。\n- 字符串 \"101\" 不包含前导 0 ,且它是整数 51 = 5 的二进制表示。\n- 字符串 \"1\" 不包含前导 0 ,且它是整数 50 = 1 的二进制表示。\n最少可以将 s 分成 2 个美丽子字符串。\n\n示例 2:\n\n输入:s = \"111\"\n输出:3\n解释:我们可以将输入字符串分成 [\"1\", \"1\", \"1\"] 。\n- 字符串 \"1\" 不包含前导 0 ,且它是整数 50 = 1 的二进制表示。\n最少可以将 s 分成 3 个美丽子字符串。\n\n示例 3:\n\n输入:s = \"0\"\n输出:-1\n解释:无法将给定字符串分成任何美丽子字符串。\n\n\n提示:\n\n * 1 <= s.length <= 15\n * s[i] 要么是 '0' 要么是 '1' 。\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def minimumBeautifulSubstrings(self, s: str) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"s\": \"1011\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 2\n\ntest_input = { \"s\": \"111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 3\n\ntest_input = { \"s\": \"0\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == -1\n\ntest_input = { \"s\": \"100111000110111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 4\n\ntest_input = { \"s\": \"100111000111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 3\n\ntest_input = { \"s\": \"1001110001111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 4\n\ntest_input = { \"s\": \"100111000111101\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 4\n\ntest_input = { \"s\": \"10110011100011\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 3\n\ntest_input = { \"s\": \"101101\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 2\n\ntest_input = { \"s\": \"101101101\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 3\n\ntest_input = { \"s\": \"101101101101101\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 5\n\ntest_input = { \"s\": \"1011011011101\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 5\n\ntest_input = { \"s\": \"10110110111011\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 6\n\ntest_input = { \"s\": \"101101101111001\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 5\n\ntest_input = { \"s\": \"1011011011111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 7\n\ntest_input = { \"s\": \"101101110011101\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 5\n\ntest_input = { \"s\": \"10110111001111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 6\n\ntest_input = { \"s\": \"1011011101101\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 5\n\ntest_input = { \"s\": \"101101110110111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 7\n\ntest_input = { \"s\": \"101101110111011\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 7\n\ntest_input = { \"s\": \"1011011101111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 7\n\ntest_input = { \"s\": \"101101110111101\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 7\n\ntest_input = { \"s\": \"10110111011111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 8\n\ntest_input = { \"s\": \"101101111001101\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 5\n\ntest_input = { \"s\": \"10110111101\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 5\n\ntest_input = { \"s\": \"10110111101101\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 6\n\ntest_input = { \"s\": \"101101111011011\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 7\n\ntest_input = { \"s\": \"101101111011101\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 7\n\ntest_input = { \"s\": \"10110111101111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 8\n\ntest_input = { \"s\": \"101101111011111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 9\n\ntest_input = { \"s\": \"1011011111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 6\n\ntest_input = { \"s\": \"1011011111001\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 5\n\ntest_input = { \"s\": \"101101111101\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 6\n\ntest_input = { \"s\": \"1011011111011\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 7\n\ntest_input = { \"s\": \"10110111110111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 8\n\ntest_input = { \"s\": \"10110111111001\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 6\n\ntest_input = { \"s\": \"101101111110011\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 7\n\ntest_input = { \"s\": \"10110111111011\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 4\n\ntest_input = { \"s\": \"101101111110111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 5\n\ntest_input = { \"s\": \"101101111111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 8\n\ntest_input = { \"s\": \"101101111111101\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 5\n\ntest_input = { \"s\": \"101110011011\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 4\n\ntest_input = { \"s\": \"10111001101101\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 4\n\ntest_input = { \"s\": \"101110011011111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 7\n\ntest_input = { \"s\": \"1011100111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 4\n\ntest_input = { \"s\": \"10111001110001\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 3\n\ntest_input = { \"s\": \"10111001110011\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 4\n\ntest_input = { \"s\": \"1011100111011\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 5\n\ntest_input = { \"s\": \"10111001110111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 6\n\ntest_input = { \"s\": \"10111001111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 5\n\ntest_input = { \"s\": \"10111001111001\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 4\n\ntest_input = { \"s\": \"1011100111101\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 5\n\ntest_input = { \"s\": \"101110011110111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 7\n\ntest_input = { \"s\": \"101110011111001\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 5\n\ntest_input = { \"s\": \"10111001111101\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 6\n\ntest_input = { \"s\": \"101110011111011\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 7\n\ntest_input = { \"s\": \"1011100111111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 7\n\ntest_input = { \"s\": \"10111001111111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 8\n\ntest_input = { \"s\": \"1011101101\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 4\n\ntest_input = { \"s\": \"10111011011011\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 6\n\ntest_input = { \"s\": \"101110110111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 6\n\ntest_input = { \"s\": \"101110110111011\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 7\n\ntest_input = { \"s\": \"1011101101111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 7\n\ntest_input = { \"s\": \"101110111001101\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 5\n\ntest_input = { \"s\": \"101110111001111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 7\n\ntest_input = { \"s\": \"10111011101\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 5\n\ntest_input = { \"s\": \"10111011101111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 8\n\ntest_input = { \"s\": \"101110111011111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 9\n\ntest_input = { \"s\": \"1011101111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 6\n\ntest_input = { \"s\": \"1011101111001\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 5\n\ntest_input = { \"s\": \"10111011110011\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 6\n\ntest_input = { \"s\": \"101110111101\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 6\n\ntest_input = { \"s\": \"1011101111011\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 7\n\ntest_input = { \"s\": \"10111011111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 7\n\ntest_input = { \"s\": \"10111011111001\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 6\n\ntest_input = { \"s\": \"10111011111011\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 8\n\ntest_input = { \"s\": \"101110111110111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 9\n\ntest_input = { \"s\": \"101110111111001\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 7\n\ntest_input = { \"s\": \"101110111111011\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 5\n\ntest_input = { \"s\": \"101110111111101\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 5\n\ntest_input = { \"s\": \"10111011111111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 10\n\ntest_input = { \"s\": \"101110111111111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 11\n\ntest_input = { \"s\": \"101111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 4\n\ntest_input = { \"s\": \"101111001\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 3\n\ntest_input = { \"s\": \"1011110011\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 4\n\ntest_input = { \"s\": \"10111100110111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 6\n\ntest_input = { \"s\": \"101111001110001\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 4\n\ntest_input = { \"s\": \"101111001111101\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 7\n\ntest_input = { \"s\": \"10111100111111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 8\n\ntest_input = { \"s\": \"101111011\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 5\n\ntest_input = { \"s\": \"10111101101\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 5\n\ntest_input = { \"s\": \"101111011011\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 6\n\ntest_input = { \"s\": \"10111101101101\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 6\n\ntest_input = { \"s\": \"1011110110111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 7\n\ntest_input = { \"s\": \"1011110111101\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 7\n\ntest_input = { \"s\": \"101111011110111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 9\n\ntest_input = { \"s\": \"101111011111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 8\n\ntest_input = { \"s\": \"1011110111111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 9\n\ntest_input = { \"s\": \"101111011111101\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 5\n\ntest_input = { \"s\": \"10111101111111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 10", "start_time": 1688826600} +{"task_id": "biweekly-contest-108-number-of-black-blocks", "url": "https://leetcode.com/problems/number-of-black-blocks", "title": "number-of-black-blocks", "meta": {"questionId": "2889", "questionFrontendId": "2768", "title": "Number of Black Blocks", "titleSlug": "number-of-black-blocks", "isPaidOnly": false, "difficulty": "Medium", "likes": 204, "dislikes": 21, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你两个整数 m 和 n ,表示一个下标从 0 开始的 m x n 的网格图。\n\n给你一个下标从 0 开始的二维整数矩阵 coordinates ,其中 coordinates[i] = [x, y] 表示坐标为 [x, y] 的格子是 黑色的 ,所有没出现在 coordinates 中的格子都是 白色的。\n\n一个块定义为网格图中 2 x 2 的一个子矩阵。更正式的,对于左上角格子为 [x, y] 的块,其中 0 <= x < m - 1 且 0 <= y < n - 1 ,包含坐标为 [x, y] ,[x + 1, y] ,[x, y + 1] 和 [x + 1, y + 1] 的格子。\n\n请你返回一个下标从 0 开始长度为 5 的整数数组 arr ,arr[i] 表示恰好包含 i 个 黑色 格子的块的数目。\n\n示例 1:\n\n输入:m = 3, n = 3, coordinates = [[0,0]]\n输出:[3,1,0,0,0]\n解释:网格图如下:\n[https://assets.leetcode.com/uploads/2023/06/18/screen-shot-2023-06-18-at-44656-am.png]\n只有 1 个块有一个黑色格子,这个块是左上角为 [0,0] 的块。\n其他 3 个左上角分别为 [0,1] ,[1,0] 和 [1,1] 的块都有 0 个黑格子。\n所以我们返回 [3,1,0,0,0] 。\n\n示例 2:\n\n输入:m = 3, n = 3, coordinates = [[0,0],[1,1],[0,2]]\n输出:[0,2,2,0,0]\n解释:网格图如下:\n[https://assets.leetcode.com/uploads/2023/06/18/screen-shot-2023-06-18-at-45018-am.png]\n有 2 个块有 2 个黑色格子(左上角格子分别为 [0,0] 和 [0,1])。\n左上角为 [1,0] 和 [1,1] 的两个块,都有 1 个黑格子。\n所以我们返回 [0,2,2,0,0] 。\n\n\n提示:\n\n * 2 <= m <= 105\n * 2 <= n <= 105\n * 0 <= coordinates.length <= 104\n * coordinates[i].length == 2\n * 0 <= coordinates[i][0] < m\n * 0 <= coordinates[i][1] < n\n * coordinates 中的坐标对两两互不相同。\n\"\"\"\nclass Solution:\n def countBlackBlocks(self, m: int, n: int, coordinates: List[List[int]]) -> List[int]:\n ", "prompt_sft": "给你两个整数 m 和 n ,表示一个下标从 0 开始的 m x n 的网格图。\n\n给你一个下标从 0 开始的二维整数矩阵 coordinates ,其中 coordinates[i] = [x, y] 表示坐标为 [x, y] 的格子是 黑色的 ,所有没出现在 coordinates 中的格子都是 白色的。\n\n一个块定义为网格图中 2 x 2 的一个子矩阵。更正式的,对于左上角格子为 [x, y] 的块,其中 0 <= x < m - 1 且 0 <= y < n - 1 ,包含坐标为 [x, y] ,[x + 1, y] ,[x, y + 1] 和 [x + 1, y + 1] 的格子。\n\n请你返回一个下标从 0 开始长度为 5 的整数数组 arr ,arr[i] 表示恰好包含 i 个 黑色 格子的块的数目。\n\n示例 1:\n\n输入:m = 3, n = 3, coordinates = [[0,0]]\n输出:[3,1,0,0,0]\n解释:网格图如下:\n[https://assets.leetcode.com/uploads/2023/06/18/screen-shot-2023-06-18-at-44656-am.png]\n只有 1 个块有一个黑色格子,这个块是左上角为 [0,0] 的块。\n其他 3 个左上角分别为 [0,1] ,[1,0] 和 [1,1] 的块都有 0 个黑格子。\n所以我们返回 [3,1,0,0,0] 。\n\n示例 2:\n\n输入:m = 3, n = 3, coordinates = [[0,0],[1,1],[0,2]]\n输出:[0,2,2,0,0]\n解释:网格图如下:\n[https://assets.leetcode.com/uploads/2023/06/18/screen-shot-2023-06-18-at-45018-am.png]\n有 2 个块有 2 个黑色格子(左上角格子分别为 [0,0] 和 [0,1])。\n左上角为 [1,0] 和 [1,1] 的两个块,都有 1 个黑格子。\n所以我们返回 [0,2,2,0,0] 。\n\n\n提示:\n\n * 2 <= m <= 105\n * 2 <= n <= 105\n * 0 <= coordinates.length <= 104\n * coordinates[i].length == 2\n * 0 <= coordinates[i][0] < m\n * 0 <= coordinates[i][1] < n\n * coordinates 中的坐标对两两互不相同。\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def countBlackBlocks(self, m: int, n: int, coordinates: List[List[int]]) -> List[int]:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"m\": 3, \"n\": 3, \"coordinates\": [[0,0]] }\nassert my_solution.countBlackBlocks(**test_input) == [3,1,0,0,0]\n\ntest_input = { \"m\": 3, \"n\": 3, \"coordinates\": [[0,0],[1,1],[0,2]] }\nassert my_solution.countBlackBlocks(**test_input) == [0,2,2,0,0]\n\ntest_input = { \"m\": 32, \"n\": 32, \"coordinates\": [[17,29],[29,16],[19,20],[18,9],[16,7],[20,25],[22,19],[4,9],[14,17],[6,23],[2,2],[20,1],[8,7],[4,7],[14,14],[10,10],[1,27],[18,23],[6,30],[8,18],[26,23],[25,8],[5,6],[3,4]] }\nassert my_solution.countBlackBlocks(**test_input) == [866,94,1,0,0]\n\ntest_input = { \"m\": 22, \"n\": 73, \"coordinates\": [[11,14],[16,11],[20,5],[5,33],[14,7],[16,60],[0,15],[15,72],[6,60],[9,16],[14,51],[1,52],[18,24],[17,30],[3,4],[19,13],[9,10],[11,40],[15,7],[13,62],[8,41],[12,71],[4,72],[18,7],[1,0],[4,35],[16,33],[7,30],[13,52],[5,1],[15,21],[3,59],[2,41],[4,28]] }\nassert my_solution.countBlackBlocks(**test_input) == [1387,122,3,0,0]\n\ntest_input = { \"m\": 22, \"n\": 79, \"coordinates\": [[11,43],[17,56],[11,58],[19,68],[5,10],[18,35],[18,27],[10,53],[1,72],[4,64],[4,72],[3,76],[18,36],[14,47],[12,57],[10,11],[13,5],[17,39],[1,4],[3,32],[6,34],[2,62],[8,35],[9,18],[12,77],[8,43],[1,49],[15,14],[15,27],[4,68],[19,24],[9,19],[17,3],[3,51],[5,61]] }\nassert my_solution.countBlackBlocks(**test_input) == [1503,130,5,0,0]\n\ntest_input = { \"m\": 3, \"n\": 89, \"coordinates\": [[0,46],[1,29],[0,50],[1,61]] }\nassert my_solution.countBlackBlocks(**test_input) == [164,12,0,0,0]\n\ntest_input = { \"m\": 25, \"n\": 97, \"coordinates\": [[23,65],[11,33],[6,76],[9,65],[18,13],[16,59],[0,86],[17,14],[23,61],[8,78],[19,40],[18,57],[1,66],[15,1],[13,44],[17,6],[14,90],[1,22],[5,34],[0,53],[1,65],[20,32],[22,54],[3,11],[20,53],[7,70],[0,30],[23,17],[18,2],[14,93],[1,28],[19,82],[6,61],[13,64],[6,73],[0,52],[17,93],[20,63],[16,24],[14,6],[20,28],[4,57],[19,76],[21,50],[5,44],[5,29],[11,36],[14,87],[2,10],[4,78],[12,35],[11,27],[20,7],[11,20],[9,51],[22,37],[11,30],[2,77],[5,87],[13,5],[2,56],[23,25],[0,44],[19,23],[23,1],[3,70],[3,86],[17,92],[19,24],[23,39],[16,2],[15,45],[14,82],[21,30],[11,90],[7,82],[17,50],[12,66],[22,84],[15,71],[14,54]] }\nassert my_solution.countBlackBlocks(**test_input) == [2002,290,12,0,0]\n\ntest_input = { \"m\": 58, \"n\": 74, \"coordinates\": [[38,21],[1,34],[29,15],[46,33],[56,7],[55,63],[7,32],[53,38],[30,73],[17,68],[32,26],[13,39],[10,22],[42,38],[29,9],[7,53],[17,2],[56,13],[34,26],[31,30],[16,21],[13,56],[16,72],[21,8],[47,28],[2,24],[32,23],[13,4],[37,29],[1,11],[45,70],[49,40],[11,61],[20,49],[11,4],[17,61],[11,68],[14,64],[31,10],[1,14],[10,47],[21,48],[46,51],[25,59],[45,12],[47,43],[32,39],[11,28],[55,46],[50,7]] }\nassert my_solution.countBlackBlocks(**test_input) == [3964,196,1,0,0]\n\ntest_input = { \"m\": 40, \"n\": 82, \"coordinates\": [[11,63],[20,43],[16,53],[33,52],[7,30],[36,2],[25,65],[10,31],[4,29],[31,17],[14,52],[36,32],[35,68],[26,8],[20,68],[21,45],[7,46],[32,15],[33,13],[30,4],[32,9],[32,78],[32,66],[27,58],[20,14],[12,29],[8,80],[2,1],[1,0],[34,41],[1,3],[1,74],[0,69],[21,7],[36,16],[0,21],[4,80],[33,78],[18,11],[18,50],[17,63],[24,29]] }\nassert my_solution.countBlackBlocks(**test_input) == [3000,156,3,0,0]\n\ntest_input = { \"m\": 57, \"n\": 92, \"coordinates\": [[38,14],[27,72]] }\nassert my_solution.countBlackBlocks(**test_input) == [5088,8,0,0,0]\n\ntest_input = { \"m\": 94, \"n\": 98, \"coordinates\": [[39,62],[40,20],[47,78],[75,10],[52,82],[11,77],[52,21],[22,12],[75,42],[75,68],[42,39],[68,75],[1,29],[18,79],[56,82],[72,41],[52,28],[61,83],[44,55],[73,81],[43,71],[55,23],[4,13],[89,68],[36,57],[48,22],[64,49],[10,72],[84,80],[1,77],[50,7],[54,0],[76,9],[57,6],[7,81],[66,80]] }\nassert my_solution.countBlackBlocks(**test_input) == [8880,140,1,0,0]\n\ntest_input = { \"m\": 30, \"n\": 97, \"coordinates\": [] }\nassert my_solution.countBlackBlocks(**test_input) == [2784,0,0,0,0]\n\ntest_input = { \"m\": 11, \"n\": 28, \"coordinates\": [[7,24],[8,22],[1,5],[6,21],[0,22],[0,15],[4,16],[2,11],[0,11],[1,3],[3,26],[1,20],[5,27],[9,8],[7,25],[0,19],[3,21],[2,13],[6,7],[5,13],[0,1],[4,18],[4,1],[2,24],[7,17],[3,15],[9,18],[1,25],[3,18],[4,27],[4,20],[4,7],[9,12],[7,1],[3,12],[5,26],[5,23],[2,4],[3,5],[6,18],[4,10],[8,8],[2,7],[7,15],[5,0],[4,9],[8,1],[8,0],[1,17],[3,9],[2,10],[1,13],[0,10],[8,14],[1,21],[1,10],[7,8],[4,6],[7,23],[0,20],[8,13],[3,24],[1,15],[5,24],[4,11],[9,14],[4,12],[7,2],[2,25],[2,9],[6,14],[0,25],[7,4],[4,2],[6,1],[4,8],[6,17]] }\nassert my_solution.countBlackBlocks(**test_input) == [83,107,63,17,0]\n\ntest_input = { \"m\": 6, \"n\": 47, \"coordinates\": [[1,1],[1,23],[1,5],[0,22],[1,12],[0,24],[4,24],[2,8],[1,11],[0,31],[1,39],[0,43],[2,18],[1,17],[1,3],[3,10],[0,26],[2,38],[1,0],[3,37],[3,2],[1,26],[4,34],[3,24],[0,23]] }\nassert my_solution.countBlackBlocks(**test_input) == [159,58,11,2,0]\n\ntest_input = { \"m\": 45, \"n\": 88, \"coordinates\": [[13,14],[6,48],[4,20],[18,57],[2,48],[0,70],[42,71],[20,70],[29,11],[34,24],[24,28],[38,45],[31,73],[41,85],[18,69]] }\nassert my_solution.countBlackBlocks(**test_input) == [3770,58,0,0,0]\n\ntest_input = { \"m\": 7, \"n\": 36, \"coordinates\": [[2,21],[3,14],[4,18],[5,30],[4,26],[5,7],[2,31],[4,22],[0,0],[2,22],[4,6],[0,30],[0,19],[0,21],[3,11],[4,28],[5,25],[2,11],[0,23],[5,16],[3,29],[3,17],[4,11],[1,7],[1,19],[1,34],[5,19],[5,6],[5,28],[4,8],[2,9],[1,6],[4,24],[2,14],[1,24],[3,16],[0,2],[0,26],[5,27],[3,35],[2,16],[4,2],[4,32],[5,0],[0,34],[1,5],[2,4],[1,4],[0,22],[2,2],[3,19],[3,4],[1,10],[3,5],[1,29],[0,33],[0,3]] }\nassert my_solution.countBlackBlocks(**test_input) == [63,99,42,6,0]\n\ntest_input = { \"m\": 59, \"n\": 60, \"coordinates\": [[4,37],[56,0],[32,53],[27,8],[18,42],[5,25],[11,46],[51,55],[55,16],[7,17],[47,1],[47,38],[28,7],[17,39],[29,59],[47,39],[56,42],[2,31],[41,16],[44,32],[27,1],[14,8],[38,52],[38,48],[40,12],[25,32],[15,55],[12,22],[0,38],[38,58],[54,52],[19,28],[39,45],[10,43],[44,26],[18,14],[34,30],[6,23],[39,22],[15,29],[50,31],[24,11],[12,5],[42,45],[18,38],[27,56],[33,58],[54,24],[40,24],[24,2],[28,44],[33,53],[49,57],[47,56],[50,18],[25,14],[56,54],[40,55],[53,44],[27,42],[39,23],[44,38],[25,2],[47,14],[27,50],[26,46],[15,1],[16,15],[55,56],[27,21],[6,7]] }\nassert my_solution.countBlackBlocks(**test_input) == [3155,256,11,0,0]\n\ntest_input = { \"m\": 89, \"n\": 90, \"coordinates\": [[12,15],[31,16],[75,79],[86,48],[19,77],[39,82],[77,62],[75,35],[19,35]] }\nassert my_solution.countBlackBlocks(**test_input) == [7796,36,0,0,0]\n\ntest_input = { \"m\": 26, \"n\": 42, \"coordinates\": [[7,13],[1,3],[11,32],[5,8],[11,4],[9,24],[0,0],[18,20],[13,35],[19,31],[15,35],[1,41],[18,40],[18,41],[14,11],[20,0],[11,6],[14,16],[0,11],[4,36],[9,12],[20,36],[14,33],[6,34],[0,12],[22,6],[22,34],[13,6],[12,1],[4,23],[6,18],[11,38],[19,17],[22,27],[21,6],[3,35],[9,11],[23,6],[22,29],[8,5],[6,26],[3,18],[0,2],[3,41],[24,6],[24,1],[7,9],[8,35],[0,6],[6,23],[13,40],[10,38],[10,20],[21,7],[20,11],[10,11],[19,3],[14,9],[1,5],[3,30],[9,9],[17,34],[18,16],[3,26],[18,19],[17,16],[2,17],[5,22],[5,41],[16,32],[9,7],[1,36],[6,30],[6,38],[9,20],[4,28],[12,8],[7,26],[5,30],[2,27],[3,32],[11,7],[7,41],[8,4],[10,34],[19,19],[13,32],[23,25]] }\nassert my_solution.countBlackBlocks(**test_input) == [739,246,37,3,0]\n\ntest_input = { \"m\": 31, \"n\": 46, \"coordinates\": [[5,31],[13,5],[6,32],[3,24],[5,41],[22,22],[18,38],[29,11],[25,28],[10,43],[29,5],[10,28],[21,2],[27,1],[4,42],[18,2],[22,26],[22,4],[2,26],[21,4],[5,32],[0,43],[24,32],[2,30],[18,44],[18,43],[7,36],[15,13],[11,29],[6,17],[10,7],[15,8],[4,11],[9,7],[28,1],[0,15],[21,19],[6,0],[24,19],[1,0],[15,30],[1,18],[4,24],[1,9],[24,16],[22,28],[4,35],[14,15],[27,23],[13,1],[2,8],[4,20],[19,30],[15,11],[0,34],[27,21],[10,1],[10,33],[11,26],[13,40],[11,45],[25,4],[28,28],[4,7],[7,29],[3,45],[20,17],[25,38],[27,41],[23,35],[19,10],[2,7],[0,25],[4,18],[23,37],[6,38]] }\nassert my_solution.countBlackBlocks(**test_input) == [1081,251,17,1,0]\n\ntest_input = { \"m\": 11, \"n\": 21, \"coordinates\": [[0,19],[2,8],[6,9],[5,15],[6,15],[2,5],[3,14],[2,10],[8,13],[4,2],[0,0],[7,19],[9,10],[8,19]] }\nassert my_solution.countBlackBlocks(**test_input) == [153,43,4,0,0]\n\ntest_input = { \"m\": 76, \"n\": 95, \"coordinates\": [[16,61],[1,23],[51,8],[36,87],[60,92],[23,44],[28,93],[15,35],[8,68],[58,57],[58,80],[53,7],[47,25],[55,4],[6,61],[43,56],[6,40],[39,44],[67,76],[44,16],[40,93],[7,6],[59,44],[74,6],[1,72],[38,93],[58,51],[17,79],[73,79],[58,65],[45,28],[17,36],[69,94],[66,73],[56,1],[31,62],[62,68],[54,64],[72,46],[67,59],[9,47],[33,86],[45,49],[3,6],[63,59],[51,47],[31,74],[52,42],[34,80],[61,30],[62,4],[11,9],[44,21],[73,69],[7,77],[43,17],[53,22],[37,10],[49,5],[64,82],[51,77],[74,2],[60,2],[17,53],[16,51],[52,80],[22,23],[17,80],[52,26],[15,1],[19,59],[7,39]] }\nassert my_solution.countBlackBlocks(**test_input) == [6768,278,4,0,0]\n\ntest_input = { \"m\": 65, \"n\": 71, \"coordinates\": [[62,8],[18,63],[23,43],[30,3],[40,48],[60,62],[58,9],[13,20],[47,46],[34,0],[11,6],[17,28],[20,34],[24,48],[24,18],[43,18],[31,59],[25,60],[15,68],[24,35],[33,47],[32,4],[26,42],[35,63],[31,22],[16,0],[45,45],[52,19],[46,49],[36,37],[11,10],[23,5],[4,13],[17,20],[14,41],[26,4],[21,7],[52,40],[31,18],[55,26],[17,57],[41,31],[1,47],[56,61],[46,38],[7,16],[53,13],[45,4],[1,69],[29,15],[46,12],[29,65],[61,10],[35,54],[33,26],[41,34],[55,48],[42,48],[0,8],[44,44],[52,10],[30,37],[14,54],[4,29],[50,58],[41,10],[30,19],[31,1],[31,62],[31,44],[53,7],[12,56],[57,69],[34,2],[34,16],[42,68],[45,15],[44,61],[15,60],[54,69],[1,39],[50,59],[51,47],[52,15],[33,69],[5,51],[19,38],[10,61],[42,17],[60,30]] }\nassert my_solution.countBlackBlocks(**test_input) == [4131,344,5,0,0]\n\ntest_input = { \"m\": 25, \"n\": 95, \"coordinates\": [[8,74],[20,10],[18,56],[23,20],[7,16],[7,5],[23,52],[19,31],[11,93],[0,68],[4,3],[21,52],[17,61],[7,65],[11,20],[1,61],[20,63],[9,71],[11,63],[11,61],[0,74],[17,60],[16,12],[3,54],[23,66],[23,37],[14,0],[19,64],[18,82],[4,87],[14,82],[23,3],[11,86],[3,64],[9,32],[14,8],[1,24],[21,20],[21,38],[22,27],[21,82],[10,58],[19,5],[22,57],[18,44],[10,83]] }\nassert my_solution.countBlackBlocks(**test_input) == [2081,172,3,0,0]\n\ntest_input = { \"m\": 40, \"n\": 84, \"coordinates\": [[19,36],[35,7],[3,78],[17,4],[28,8],[20,38],[12,38],[30,6],[37,45],[26,53],[11,46]] }\nassert my_solution.countBlackBlocks(**test_input) == [3193,44,0,0,0]\n\ntest_input = { \"m\": 8, \"n\": 57, \"coordinates\": [[3,38],[1,41],[6,23],[0,54],[3,11],[3,44],[1,24],[0,38],[5,28]] }\nassert my_solution.countBlackBlocks(**test_input) == [360,32,0,0,0]\n\ntest_input = { \"m\": 32, \"n\": 41, \"coordinates\": [[12,13],[20,33],[3,12],[28,40],[9,10],[18,10],[5,18],[9,24],[29,24],[9,33],[25,38],[29,17],[28,25],[0,35],[2,30],[18,37],[7,0],[14,21],[25,27],[17,33],[9,38],[19,22],[17,5],[18,4],[9,18],[15,6],[4,21],[12,4],[5,35],[19,26],[6,6],[0,2],[0,28],[1,13],[19,10],[5,16],[2,31],[24,2],[3,22],[23,12],[0,17],[6,30],[20,31],[10,32],[17,15],[1,34],[28,6],[21,15],[14,11],[27,23],[4,16],[2,11],[21,26],[23,19],[27,15],[3,5],[28,10],[1,2],[27,18],[19,36],[2,2],[17,13],[7,19],[25,0],[5,37],[30,6],[3,39],[28,30],[26,0],[9,5],[23,5],[27,6],[4,26],[15,39],[10,26]] }\nassert my_solution.countBlackBlocks(**test_input) == [976,244,20,0,0]\n\ntest_input = { \"m\": 63, \"n\": 99, \"coordinates\": [[17,28],[7,39],[14,81],[44,4],[21,7],[21,95],[1,89],[57,74],[34,2],[55,56],[43,50],[52,28],[38,61],[35,62],[57,46],[30,72],[25,46],[4,32],[18,25],[53,98]] }\nassert my_solution.countBlackBlocks(**test_input) == [5998,78,0,0,0]\n\ntest_input = { \"m\": 44, \"n\": 97, \"coordinates\": [[17,3],[29,4],[40,71],[32,45],[3,59],[22,34],[11,17],[17,43],[4,32],[8,8],[19,43],[12,19],[32,57],[9,15],[7,46],[4,39],[11,26],[17,87],[21,70],[12,58],[35,88],[12,72],[23,61],[23,43],[3,86],[31,30],[17,26],[14,22],[16,77],[41,73],[39,91],[41,74],[15,78],[31,36],[11,45],[9,57],[25,68],[42,28],[5,60],[38,72],[26,14],[33,48],[39,50],[38,33],[41,21],[39,86],[29,64],[4,69],[37,25],[28,85],[9,32],[9,76],[13,25],[26,43],[10,79],[2,2],[23,85],[39,29],[34,47],[13,17],[34,59],[27,84],[29,93],[17,89],[23,27],[9,16],[39,64],[3,37],[41,75],[32,26],[27,11]] }\nassert my_solution.countBlackBlocks(**test_input) == [3853,266,9,0,0]\n\ntest_input = { \"m\": 45, \"n\": 53, \"coordinates\": [[15,41],[0,27],[24,15],[34,31],[36,27],[32,46],[1,39],[4,8],[18,8],[39,3],[2,50],[6,33],[25,46],[17,41],[27,46],[37,30],[41,23],[16,14],[21,17],[26,47],[31,47],[9,23],[32,21],[29,28],[37,41],[10,37],[21,31],[1,25],[31,19],[16,49],[2,22],[1,43],[39,33],[6,12],[12,39],[40,15],[31,50],[8,7],[5,21],[8,4],[30,10],[15,20],[9,21],[38,28],[42,14],[36,8],[27,5],[2,2],[13,32],[13,50],[22,8],[23,25],[33,23],[9,22],[28,12],[15,37],[40,10],[42,45],[1,11],[26,2],[30,18],[0,19],[15,38],[32,2],[26,19],[29,29],[24,21],[24,10],[19,8],[24,31],[37,34],[5,20],[11,30],[41,19],[34,43],[41,7],[38,36],[13,10],[39,14],[22,4],[34,27],[23,21],[9,24],[13,29],[14,30],[32,48],[9,47],[13,37],[3,4],[1,6],[19,48],[41,47],[40,33],[26,23],[1,4],[40,28],[31,37]] }\nassert my_solution.countBlackBlocks(**test_input) == [1929,334,25,0,0]\n\ntest_input = { \"m\": 36, \"n\": 62, \"coordinates\": [[5,42],[14,2],[32,11],[28,38],[18,49],[23,52],[32,52],[15,39],[11,38],[15,54],[21,27],[14,0],[26,38],[4,43],[22,26],[5,17]] }\nassert my_solution.countBlackBlocks(**test_input) == [2075,58,2,0,0]\n\ntest_input = { \"m\": 30, \"n\": 98, \"coordinates\": [[10,13],[23,8],[9,69],[20,70],[17,12],[12,39],[7,72],[14,0],[5,45],[21,24],[10,88],[2,8],[22,86],[2,28],[20,62],[6,82],[27,10],[7,28],[12,79],[21,38],[24,92],[0,47],[8,8],[26,3],[20,57],[12,36],[21,47],[19,12],[20,35],[28,26],[4,61],[5,90],[0,48],[14,50],[3,63],[17,93],[12,5],[12,94],[7,25]] }\nassert my_solution.countBlackBlocks(**test_input) == [2664,148,1,0,0]\n\ntest_input = { \"m\": 20, \"n\": 41, \"coordinates\": [[11,3],[1,36],[17,23],[13,1],[14,33],[2,23],[0,5],[5,32],[14,36],[8,16],[0,9],[14,26],[8,9],[6,5],[10,12],[17,20],[10,33],[16,23],[12,40],[8,17],[12,35],[11,23],[6,34],[2,4],[7,0],[7,7],[8,27],[7,39],[13,19],[14,2],[9,23],[12,33],[14,20],[12,27],[15,22],[1,19],[10,17],[7,36],[4,29],[12,37],[7,18],[10,20]] }\nassert my_solution.countBlackBlocks(**test_input) == [608,144,8,0,0]\n\ntest_input = { \"m\": 60, \"n\": 73, \"coordinates\": [[45,35],[12,1],[43,11],[58,9],[0,3],[51,34],[1,65],[15,55],[32,29],[41,36],[41,61],[5,39],[54,2],[21,35],[41,69],[12,71],[17,5],[56,59],[41,40],[49,17],[48,56],[18,71],[39,57],[1,46],[53,44],[40,46],[52,14],[57,68],[14,66],[20,26],[48,8],[46,22],[34,41],[15,47],[18,45],[16,29],[40,6],[51,51],[47,70],[29,64],[51,32],[18,40],[10,62],[5,28],[57,3],[43,69],[49,58],[8,7],[18,9],[24,0],[56,0],[23,39],[31,19],[56,12],[34,17],[13,42],[8,23],[28,20],[42,38],[5,16],[29,36],[56,47],[45,23],[51,58],[2,69],[2,44],[5,6],[53,6],[50,48],[51,64],[43,15],[37,70],[18,44],[41,23],[51,31],[31,10],[25,53],[28,46],[56,42],[7,49],[55,50],[31,26],[3,26],[43,52],[54,68],[21,37]] }\nassert my_solution.countBlackBlocks(**test_input) == [3915,328,5,0,0]\n\ntest_input = { \"m\": 37, \"n\": 80, \"coordinates\": [[5,3],[29,79],[35,32],[29,8],[10,57]] }\nassert my_solution.countBlackBlocks(**test_input) == [2826,18,0,0,0]\n\ntest_input = { \"m\": 31, \"n\": 97, \"coordinates\": [[29,40],[29,6],[11,73],[10,81],[12,92],[23,62],[16,86],[26,0],[9,95],[17,17],[22,60],[27,15],[15,70],[7,18],[1,27],[18,51],[14,38],[2,42],[26,43],[0,52],[1,69],[23,50],[26,68],[24,53],[23,31],[7,78],[18,23],[14,96],[25,49],[23,74],[11,35],[5,14],[24,35]] }\nassert my_solution.countBlackBlocks(**test_input) == [2754,126,0,0,0]\n\ntest_input = { \"m\": 17, \"n\": 43, \"coordinates\": [[8,38],[2,23],[15,18],[1,3],[7,40],[3,30],[13,1],[12,40],[9,4],[0,10],[5,36],[3,15],[3,5],[7,23],[5,13],[11,26],[3,28],[14,23],[10,16],[2,11],[14,5],[11,32],[1,20],[4,0],[15,13],[3,12],[12,9],[3,31],[8,35],[8,17],[3,42],[1,36],[5,2],[13,14],[9,2],[6,28],[5,4],[2,1],[13,36],[2,24],[12,29],[15,3],[11,20],[2,25],[13,8],[4,17],[8,29],[0,33],[11,3],[0,29],[12,30],[6,16],[7,33],[13,7],[5,26],[14,24],[3,16],[0,11],[11,28],[11,34],[6,8],[4,25],[14,20],[8,0],[7,32],[7,27],[8,23],[5,14],[4,30],[14,3],[6,21],[6,41],[12,18],[14,25],[8,3],[8,14]] }\nassert my_solution.countBlackBlocks(**test_input) == [418,219,34,1,0]\n\ntest_input = { \"m\": 12, \"n\": 73, \"coordinates\": [[7,64],[5,14],[5,46]] }\nassert my_solution.countBlackBlocks(**test_input) == [780,12,0,0,0]\n\ntest_input = { \"m\": 36, \"n\": 91, \"coordinates\": [[14,10],[28,69],[34,15],[6,62],[2,44],[12,81],[19,47],[32,89],[13,59],[12,25],[8,62],[26,87],[31,29],[16,49],[4,46],[3,46],[10,47],[31,87],[15,44],[1,75],[0,61],[3,35],[3,58],[25,88],[15,56],[30,30],[13,26],[9,49],[24,56],[17,17],[19,85],[23,80],[5,68],[30,79],[34,34],[32,69],[19,58],[20,43],[4,40],[33,44],[21,71],[3,37],[34,54],[10,28],[9,62],[20,19],[21,84],[22,32],[9,90],[10,82],[19,38],[15,51],[32,11],[26,72],[34,46],[17,89],[16,28],[15,81],[0,39],[5,28],[10,5],[20,0],[32,40],[14,76],[8,72]] }\nassert my_solution.countBlackBlocks(**test_input) == [2905,238,7,0,0]\n\ntest_input = { \"m\": 11, \"n\": 76, \"coordinates\": [[2,6],[1,36],[2,60],[3,57],[1,72],[5,15],[1,30],[1,28],[8,15],[4,39],[1,2],[0,56],[5,2],[4,27],[9,2],[3,67],[7,19],[6,54],[7,73],[9,51],[8,63],[0,27],[8,44],[5,31],[0,11]] }\nassert my_solution.countBlackBlocks(**test_input) == [657,92,1,0,0]\n\ntest_input = { \"m\": 24, \"n\": 70, \"coordinates\": [[9,49],[13,17],[14,52],[17,13],[20,40],[6,62],[18,62],[14,9],[13,0],[15,34],[5,33],[18,1],[17,33],[6,63],[4,26],[3,28],[18,68],[2,15],[5,10],[21,13],[10,53],[5,35],[21,60],[9,59],[1,0],[15,53],[5,45],[0,42],[6,24],[9,9],[2,44],[8,12],[1,16],[13,29],[21,38],[20,39],[4,13],[17,56],[10,45],[3,65],[14,15],[5,62],[13,18],[4,35],[18,11],[12,31],[18,18],[7,50],[12,52],[11,47],[7,14],[11,61],[13,1],[2,1],[4,19],[15,8],[0,7],[18,15],[20,31],[1,17],[15,31],[7,39],[5,52],[8,9],[1,50],[16,34],[21,15],[8,66],[5,53],[18,43],[5,19],[9,61],[11,52],[18,36],[4,9],[21,28],[10,30],[17,68],[4,52],[16,38],[15,57],[13,35],[9,32],[2,65],[17,34],[14,1],[16,3]] }\nassert my_solution.countBlackBlocks(**test_input) == [1290,258,35,4,0]\n\ntest_input = { \"m\": 55, \"n\": 74, \"coordinates\": [[33,73],[38,37],[4,69],[23,58],[47,17],[48,36],[46,42],[6,63],[22,23],[36,57],[20,38],[42,66],[31,6],[13,3],[5,40],[25,28],[50,7],[6,7],[23,66],[29,17],[5,67],[41,63],[2,53],[3,24],[25,49],[43,18],[27,11],[37,72],[30,14],[16,70],[22,71],[0,48],[21,4],[8,9],[38,57],[14,12],[13,54],[11,40],[10,28],[9,49],[31,24],[11,28],[11,51],[10,62],[46,39],[3,35],[23,15],[52,25],[37,55],[28,63],[1,2],[26,12],[29,30],[44,62],[35,34],[25,31],[8,63],[8,6],[38,14],[19,14],[8,28],[26,14],[27,36],[20,61],[23,12],[15,20]] }\nassert my_solution.countBlackBlocks(**test_input) == [3685,254,3,0,0]\n\ntest_input = { \"m\": 6, \"n\": 79, \"coordinates\": [[2,64],[4,74],[2,3],[1,63],[2,34],[3,57],[1,1],[3,52],[1,56],[3,1],[1,61],[2,49],[1,66],[2,25],[1,20],[4,51],[0,78],[1,30]] }\nassert my_solution.countBlackBlocks(**test_input) == [323,65,2,0,0]\n\ntest_input = { \"m\": 36, \"n\": 75, \"coordinates\": [[23,28],[21,10],[16,48],[26,45],[13,45],[24,66],[34,15],[20,13],[4,42],[17,14],[7,19],[8,5],[4,27],[16,32],[19,0],[27,69],[18,62],[18,63],[4,24],[15,51],[24,53],[6,46],[33,51],[13,65],[11,39],[14,37],[33,1],[5,16],[24,15],[30,63],[34,23],[12,22],[29,44],[19,8],[3,4],[12,67],[0,44],[4,65],[5,44],[16,13],[16,71],[16,10],[27,71],[28,56],[1,23],[11,42],[1,1],[10,19],[10,18],[8,55],[23,68],[12,23],[12,61],[31,3],[13,14],[20,30],[25,1],[4,37],[25,32]] }\nassert my_solution.countBlackBlocks(**test_input) == [2365,218,7,0,0]\n\ntest_input = { \"m\": 31, \"n\": 87, \"coordinates\": [[12,40],[28,11],[20,65],[24,38],[21,65],[29,11],[11,8],[26,16],[8,25],[18,63],[11,69],[9,16],[14,25],[2,34],[7,14],[26,74],[27,51],[13,53],[25,2],[27,17],[3,45],[23,22],[28,38],[5,26],[23,33],[2,16],[14,41],[22,79],[25,75],[7,79],[9,6],[14,73],[15,61],[27,16],[29,21],[27,72],[16,17],[1,37]] }\nassert my_solution.countBlackBlocks(**test_input) == [2437,135,7,1,0]\n\ntest_input = { \"m\": 55, \"n\": 67, \"coordinates\": [[44,3],[12,10],[20,17],[41,24],[25,40],[21,46],[5,9],[34,64],[29,40],[49,32],[19,37],[42,61],[35,46],[49,52],[16,65],[4,32],[20,48],[5,59],[28,26],[2,3],[40,28],[20,35],[4,29],[47,20],[3,8],[26,39],[7,54],[8,10],[37,5],[33,13],[3,44],[14,63],[21,24],[26,17],[11,60],[19,44],[46,23],[37,6],[9,64],[15,36],[1,36],[44,31],[3,24],[13,3],[49,39],[28,11],[21,32],[27,34],[44,52],[51,51],[17,50],[49,47],[0,5],[11,51],[37,23],[45,45],[50,19],[33,51],[14,36],[7,44],[3,36],[7,27],[18,54],[31,4],[15,12],[38,38],[52,33],[36,16],[25,42],[28,37],[24,50],[26,24],[48,26],[2,24],[33,10],[10,9],[25,26],[15,64],[52,58],[0,44],[7,48],[32,43],[10,6],[43,11],[50,53],[43,26],[13,45],[50,28],[40,0],[31,50],[42,51],[4,59],[18,62],[26,45],[22,44],[37,58],[38,43],[5,53],[23,1],[21,21]] }\nassert my_solution.countBlackBlocks(**test_input) == [3182,370,12,0,0]\n\ntest_input = { \"m\": 19, \"n\": 40, \"coordinates\": [[8,25],[14,19],[9,0],[10,26],[11,8],[4,8],[2,0],[13,6],[4,24],[6,11],[5,19],[2,21],[4,11],[4,29],[1,25],[6,14],[0,28],[5,39],[7,33],[15,7],[13,25],[15,5],[9,34],[0,33],[6,10],[3,20],[6,13],[14,12],[6,17],[3,1],[2,30],[13,16],[14,1],[9,9],[14,10],[17,4],[13,39],[8,7],[16,19],[2,5],[10,19],[1,6],[15,4],[7,0],[3,18],[16,3],[14,21],[10,31],[11,31],[1,33],[2,23],[17,20],[8,9],[0,16],[4,32],[9,4],[9,8],[0,8],[1,0],[13,1],[1,34],[7,9],[8,34],[4,39],[10,7],[4,5],[9,12],[5,36],[15,0],[15,36],[6,22]] }\nassert my_solution.countBlackBlocks(**test_input) == [478,190,32,2,0]\n\ntest_input = { \"m\": 16, \"n\": 27, \"coordinates\": [[7,4],[11,26],[2,21],[3,3],[13,11],[7,14],[0,8]] }\nassert my_solution.countBlackBlocks(**test_input) == [366,24,0,0,0]\n\ntest_input = { \"m\": 34, \"n\": 39, \"coordinates\": [[4,12],[29,24],[15,28],[3,1],[7,0],[0,27],[15,5],[2,0],[16,7],[19,33],[3,11],[5,26],[29,32],[21,32],[31,10],[17,4],[23,32],[5,10],[3,12],[27,11],[12,26],[2,5],[1,0],[20,2],[11,26],[0,11],[12,4],[14,7],[13,18],[9,7],[16,9],[10,3],[3,33],[13,27],[27,18],[11,19],[18,13],[16,21],[2,15],[11,27],[13,33],[8,21],[16,19],[26,27],[3,36],[9,3],[13,38],[10,22],[1,38],[12,31],[13,13],[17,19],[30,1],[15,37],[21,5],[14,15],[6,37],[8,23],[26,22],[24,38],[21,23]] }\nassert my_solution.countBlackBlocks(**test_input) == [1041,200,11,2,0]\n\ntest_input = { \"m\": 26, \"n\": 41, \"coordinates\": [[12,9],[1,18],[7,10],[22,0],[15,10],[12,3],[20,15],[0,27],[16,35],[20,40],[7,38],[13,27],[9,32],[4,26],[9,40],[4,1],[21,33],[16,12],[6,38],[22,40],[10,24],[20,21],[17,31],[12,6],[8,27],[9,15],[5,13],[14,31],[11,17],[20,31],[22,35],[23,19],[23,16],[3,15],[16,11],[23,27],[9,33],[16,3],[5,12],[21,20],[12,1],[13,30],[13,17],[13,22],[9,28],[7,8],[8,5],[19,15],[16,1],[23,36],[4,6],[18,40],[8,19],[5,2],[21,2],[23,7]] }\nassert my_solution.countBlackBlocks(**test_input) == [804,180,16,0,0]\n\ntest_input = { \"m\": 39, \"n\": 68, \"coordinates\": [[35,51],[9,25],[13,28],[14,62],[24,6]] }\nassert my_solution.countBlackBlocks(**test_input) == [2526,20,0,0,0]\n\ntest_input = { \"m\": 33, \"n\": 94, \"coordinates\": [[15,21],[0,63],[25,30],[11,77],[6,65],[14,5],[3,18],[30,61],[21,52],[17,8],[10,69],[24,84],[19,18],[10,75],[4,47],[8,9],[17,22],[3,70],[30,90],[22,58],[15,84],[4,78],[8,15],[20,18],[23,60],[26,83],[27,14],[5,31],[2,48],[18,48],[16,33],[6,31],[1,82],[5,46],[19,13],[0,86],[3,44],[9,49],[13,47],[0,4],[31,52],[6,68],[15,79],[29,47],[6,4],[5,33],[10,9],[30,50],[9,77],[13,79],[20,87],[11,27],[23,86]] }\nassert my_solution.countBlackBlocks(**test_input) == [2775,196,5,0,0]\n\ntest_input = { \"m\": 65, \"n\": 78, \"coordinates\": [[43,38],[0,36],[40,68],[52,19],[16,59],[10,35],[23,1],[1,58],[29,38],[19,49],[34,40],[57,37],[32,66],[35,37],[16,10],[53,51],[9,53],[23,40],[42,74],[31,51],[17,51],[21,32],[33,72]] }\nassert my_solution.countBlackBlocks(**test_input) == [4838,90,0,0,0]\n\ntest_input = { \"m\": 47, \"n\": 80, \"coordinates\": [[26,59],[14,64],[4,67],[17,51],[10,66],[18,78],[17,69],[33,57],[18,44],[16,78],[27,39],[22,18],[16,69],[21,5],[19,52],[39,40],[13,17],[15,10],[30,33],[9,67],[34,10],[3,39],[32,52],[33,71],[24,65],[15,57],[43,53]] }\nassert my_solution.countBlackBlocks(**test_input) == [3529,102,3,0,0]\n\ntest_input = { \"m\": 42, \"n\": 99, \"coordinates\": [[27,29],[39,18],[40,17],[36,14],[17,76],[15,67],[2,41],[37,70],[34,67],[36,15],[23,57],[7,46],[7,42],[3,91],[3,32],[17,30],[35,37],[25,91],[32,83],[20,81],[20,19],[23,51],[17,10],[23,61],[18,24],[3,13],[16,48],[0,88],[31,81],[4,20],[34,95],[30,22],[28,58],[4,50],[1,77],[4,13],[7,37],[13,1],[28,75],[28,77],[4,4],[31,20],[40,6],[18,65]] }\nassert my_solution.countBlackBlocks(**test_input) == [3849,164,5,0,0]\n\ntest_input = { \"m\": 77, \"n\": 80, \"coordinates\": [[34,8],[7,40],[67,29],[64,70],[32,71],[17,29],[19,15],[6,77],[68,39],[11,9],[9,59],[19,63],[44,11],[24,54],[13,15],[10,23],[27,35],[14,68],[9,61],[17,74],[44,56],[37,78],[20,68],[7,58],[9,38],[72,22],[72,33],[41,33],[64,63],[22,69],[2,12],[51,73],[43,32],[16,57],[11,16],[3,38],[14,45],[73,28],[8,51],[72,42],[18,65],[45,42],[42,18],[34,38],[47,50],[47,0],[29,32],[15,66],[43,61],[49,36],[69,71],[47,45],[55,64],[1,62],[42,0],[18,49],[57,48],[22,16],[14,7],[56,10],[49,42],[19,46],[40,68],[65,49],[8,20],[12,0],[31,17],[50,6],[8,14],[6,38],[32,67],[4,3],[10,13],[44,8],[21,43],[70,34],[49,22],[72,47],[59,59],[56,72],[33,30],[18,20],[2,76],[22,33]] }\nassert my_solution.countBlackBlocks(**test_input) == [5674,330,0,0,0]\n\ntest_input = { \"m\": 53, \"n\": 93, \"coordinates\": [] }\nassert my_solution.countBlackBlocks(**test_input) == [4784,0,0,0,0]\n\ntest_input = { \"m\": 48, \"n\": 91, \"coordinates\": [[19,79],[30,11],[6,54],[35,3],[41,20],[8,3],[8,46],[37,67],[21,61],[27,70],[15,32],[44,61],[1,70],[9,68],[28,16],[19,43],[12,68],[21,12],[7,77],[18,32],[1,25],[31,11],[1,82],[10,18],[31,86],[21,24],[11,43],[15,4],[8,12],[39,68],[11,65],[37,53],[10,39],[30,61],[34,46],[33,9],[30,64],[27,59],[31,60],[14,64],[11,70],[16,83],[28,15],[26,21],[33,71],[31,53],[39,36],[27,77],[41,82],[21,45],[3,59],[42,14],[19,59],[5,57]] }\nassert my_solution.countBlackBlocks(**test_input) == [4019,206,5,0,0]\n\ntest_input = { \"m\": 53, \"n\": 77, \"coordinates\": [[29,74],[44,76],[10,11],[11,14],[45,0],[41,19],[32,49],[21,50],[14,41],[7,74],[42,47],[50,19],[6,34],[47,0],[19,64],[39,25],[49,46],[45,1],[9,67],[51,19],[6,59],[24,52],[40,61],[48,23],[23,49],[4,64],[40,27],[49,42],[17,30],[13,14],[3,49],[41,14],[36,0],[5,32],[6,1],[4,27],[11,22],[26,37],[5,61],[22,15],[42,1],[9,33],[20,25],[44,38],[46,16],[10,20],[45,13],[31,27],[27,70],[22,11],[28,17]] }\nassert my_solution.countBlackBlocks(**test_input) == [3760,188,4,0,0]\n\ntest_input = { \"m\": 12, \"n\": 69, \"coordinates\": [[8,6],[1,19],[0,23],[7,8],[7,31],[10,16],[9,2],[6,1],[8,63],[7,45],[5,40],[1,27],[2,14],[6,54],[0,4],[1,62],[4,45],[5,31],[7,33],[2,38]] }\nassert my_solution.countBlackBlocks(**test_input) == [672,76,0,0,0]\n\ntest_input = { \"m\": 49, \"n\": 78, \"coordinates\": [[4,26],[9,25],[9,77],[42,45],[47,12],[30,68],[15,63],[23,11],[24,24],[23,49],[26,77]] }\nassert my_solution.countBlackBlocks(**test_input) == [3656,40,0,0,0]\n\ntest_input = { \"m\": 63, \"n\": 95, \"coordinates\": [[36,71],[2,38],[25,72],[16,54],[38,59],[44,82],[7,57],[8,65],[5,90],[8,82],[56,26],[39,15],[36,30],[31,53],[59,80],[38,25],[50,47],[12,72],[27,26],[41,23],[20,25],[19,74],[22,18],[19,75],[53,61],[25,17],[12,22],[32,40],[40,1],[6,7],[6,24],[46,43],[39,84],[17,92],[12,91],[32,25],[20,68],[11,12],[23,20],[7,36],[42,22],[21,69],[19,9],[25,8],[57,82],[52,83],[43,81],[60,19],[26,83],[18,73],[44,12],[30,45],[25,84],[55,77],[35,41],[53,8],[0,44],[29,36],[36,69],[9,53],[37,15],[24,0],[13,60],[31,62],[56,84],[45,59],[45,82],[58,35],[12,15],[34,60],[28,51],[18,40],[53,73],[10,48],[28,6],[8,16],[41,34],[50,15],[23,30],[33,21],[2,34]] }\nassert my_solution.countBlackBlocks(**test_input) == [5517,302,9,0,0]\n\ntest_input = { \"m\": 42, \"n\": 58, \"coordinates\": [[35,34],[26,21],[17,14],[34,44],[12,51],[1,33],[23,17],[30,54],[25,46],[39,12],[21,13],[26,37],[13,38],[37,10],[27,57],[3,14],[19,31]] }\nassert my_solution.countBlackBlocks(**test_input) == [2271,66,0,0,0]\n\ntest_input = { \"m\": 6, \"n\": 12, \"coordinates\": [[4,7],[2,11],[0,7],[0,10],[1,4],[2,0],[2,10],[0,8],[3,8],[3,2],[0,5],[1,10],[0,9],[3,4],[2,9],[1,1],[3,7],[2,3],[0,0]] }\nassert my_solution.countBlackBlocks(**test_input) == [18,19,14,4,0]\n\ntest_input = { \"m\": 51, \"n\": 77, \"coordinates\": [[41,39],[28,5],[6,8],[36,7],[2,46],[18,75],[12,63],[42,26],[16,42],[6,9],[9,55],[37,61],[8,69],[35,10],[34,51],[33,2],[37,64],[5,32],[17,53],[38,51],[42,18],[24,35],[8,25],[17,58],[41,53],[2,9],[48,37],[13,7],[47,20],[28,59],[17,8],[32,27],[39,16],[43,74],[38,61],[40,14],[35,28],[9,46],[30,44],[46,12],[7,45],[26,76],[34,10],[28,51],[47,1],[46,65],[29,71],[2,24],[11,43],[16,28],[33,40],[18,29],[8,73],[30,55],[0,47],[45,34],[3,45],[16,5],[33,9],[4,68],[36,47],[11,39],[8,37],[6,63],[42,51],[4,16],[37,5],[32,60],[40,17],[9,14],[5,29],[22,34],[47,21],[44,37],[2,75],[21,76],[30,46],[20,60]] }\nassert my_solution.countBlackBlocks(**test_input) == [3505,284,11,0,0]\n\ntest_input = { \"m\": 58, \"n\": 65, \"coordinates\": [[20,24],[4,13],[38,14],[41,21],[6,36],[12,3],[51,52],[10,7],[14,50],[47,60],[30,59],[46,58],[55,49],[35,25],[15,53],[24,39],[55,40],[4,43],[36,28],[21,38],[36,1],[44,42],[12,26],[50,30],[36,14],[53,0],[11,48],[0,55],[42,17],[34,48],[15,43],[13,6],[33,29],[32,20],[12,13],[7,1],[22,41],[26,64],[16,16],[3,5],[14,0],[39,19],[32,47],[47,14],[51,64],[51,12],[7,45],[43,46],[47,28],[50,60],[45,8],[6,30],[9,35],[21,47],[17,39]] }\nassert my_solution.countBlackBlocks(**test_input) == [3438,210,0,0,0]\n\ntest_input = { \"m\": 6, \"n\": 10, \"coordinates\": [[2,7],[0,4],[3,3],[0,2],[3,0],[4,2],[2,1]] }\nassert my_solution.countBlackBlocks(**test_input) == [25,18,2,0,0]\n\ntest_input = { \"m\": 37, \"n\": 75, \"coordinates\": [[34,9],[30,27],[20,54],[35,35],[24,8],[0,68],[22,23],[10,20],[4,32],[8,20],[33,6],[7,63],[17,72],[8,37],[28,48],[25,24],[25,74],[20,38],[9,51],[10,74],[3,37],[20,17],[11,31],[14,67],[19,26],[34,7],[31,51],[5,47],[24,28]] }\nassert my_solution.countBlackBlocks(**test_input) == [2555,108,1,0,0]\n\ntest_input = { \"m\": 32, \"n\": 90, \"coordinates\": [[14,54],[13,33],[27,23],[28,68],[23,46],[12,22],[4,85],[4,41],[26,32],[0,42],[16,24],[17,83],[28,75],[4,39],[5,46],[10,51],[27,88],[6,69],[22,11],[7,9],[19,37],[0,74],[24,85],[28,74],[28,3],[13,80],[9,30],[16,86],[3,22],[2,3],[21,68],[11,32],[19,68],[25,83],[25,31],[12,10],[26,3],[16,57],[24,47],[12,73],[21,87],[9,28],[21,16],[23,29],[25,13],[23,82],[19,7],[29,11],[21,78],[24,23],[7,66],[9,57],[6,78],[13,22],[0,39],[20,48],[18,66],[17,77],[25,66],[11,25],[19,26],[20,75],[29,63],[3,52],[28,15],[13,84],[12,21],[0,4],[7,60],[16,74],[1,3],[7,5],[14,27],[22,4],[12,6],[16,0],[16,14],[12,17],[27,75],[20,16],[0,16],[9,26],[4,43],[19,0],[22,81],[12,71],[15,54],[3,61],[13,72],[7,71],[2,30],[2,18],[16,15],[28,5],[2,7],[25,89]] }\nassert my_solution.countBlackBlocks(**test_input) == [2413,326,18,2,0]\n\ntest_input = { \"m\": 21, \"n\": 81, \"coordinates\": [[5,71],[9,65],[12,36],[19,38],[7,66],[7,2],[14,13],[4,71],[19,32],[14,30],[13,21],[16,79],[0,2],[3,27],[13,72],[18,49],[0,72],[0,52],[18,24],[18,41],[13,7],[1,29],[15,24],[16,2],[8,25],[5,51],[19,15],[12,18],[16,61],[9,6],[7,61],[18,37],[10,79],[6,35],[17,12],[2,36],[13,64],[9,59],[5,42],[19,30],[7,51],[15,53],[10,75],[2,34],[8,0],[2,70],[3,36],[12,38],[4,35],[9,25],[13,68],[13,13],[14,25],[6,48],[15,33],[15,29]] }\nassert my_solution.countBlackBlocks(**test_input) == [1396,192,12,0,0]\n\ntest_input = { \"m\": 44, \"n\": 54, \"coordinates\": [[37,23],[27,31],[19,28],[30,2],[15,29],[4,40],[7,47],[36,18],[17,49],[18,51],[29,42],[8,34],[28,51],[17,27],[18,49],[26,16],[34,39],[11,19],[20,43],[23,47],[25,0],[20,32],[16,5],[29,30],[22,3],[4,12],[13,8],[5,6],[35,40],[15,49],[27,14],[37,8],[41,15],[0,16],[37,37],[38,31],[36,52],[18,22],[30,3],[31,18]] }\nassert my_solution.countBlackBlocks(**test_input) == [2128,146,5,0,0]\n\ntest_input = { \"m\": 2, \"n\": 52, \"coordinates\": [[0,24],[0,29],[0,14],[0,23],[0,33],[0,51],[0,27],[0,50],[0,7],[0,32],[0,9],[0,26],[0,17],[0,31],[0,19],[0,11],[0,3],[0,15],[0,20],[0,12],[0,18],[0,45],[0,48],[0,41],[0,8],[0,42],[0,47],[0,43],[0,2],[0,34],[0,0],[0,5],[0,49],[0,4],[0,36],[0,40],[0,44],[0,6],[0,38],[0,22],[0,13]] }\nassert my_solution.countBlackBlocks(**test_input) == [0,22,29,0,0]\n\ntest_input = { \"m\": 3, \"n\": 75, \"coordinates\": [[0,49],[1,17],[1,18],[0,20],[1,65],[0,35],[1,70],[1,20],[0,43],[1,58],[1,36],[0,28],[0,74],[0,30],[1,51],[1,63],[1,66]] }\nassert my_solution.countBlackBlocks(**test_input) == [102,39,7,0,0]\n\ntest_input = { \"m\": 33, \"n\": 93, \"coordinates\": [[18,53],[29,30],[29,23],[10,74],[5,25],[17,26],[5,87],[27,11],[29,16],[22,34],[19,86],[24,80],[11,46],[13,41],[7,24],[24,86],[30,89],[17,92],[11,21],[8,71],[7,8],[24,21],[22,32],[27,21],[29,17],[4,25],[22,91],[23,81],[10,59],[19,87],[20,16],[30,56],[13,70],[18,78],[13,27],[3,48],[8,3],[1,27],[16,62],[3,46],[6,23],[22,12],[0,26],[18,91],[0,1],[8,36],[8,16],[27,17],[12,1],[9,88]] }\nassert my_solution.countBlackBlocks(**test_input) == [2760,174,10,0,0]\n\ntest_input = { \"m\": 70, \"n\": 88, \"coordinates\": [[40,71],[29,33],[59,67],[55,61],[17,41]] }\nassert my_solution.countBlackBlocks(**test_input) == [5983,20,0,0,0]\n\ntest_input = { \"m\": 76, \"n\": 88, \"coordinates\": [[39,76],[42,86],[4,51],[60,0],[5,28],[1,46],[28,25],[21,12],[5,39],[19,20],[71,58],[70,25],[38,32],[42,51],[49,62],[39,20],[48,24],[10,14],[17,85],[27,2],[5,40],[56,23],[21,67],[15,28],[15,84],[73,34],[50,81],[20,68],[0,30],[30,53],[33,82],[58,65],[4,7],[73,50],[55,25],[45,59],[69,78],[63,47],[19,83],[46,41],[23,66],[0,76],[63,18],[1,3],[18,71],[27,79],[51,21],[9,46],[48,30],[11,30],[67,74],[74,9],[8,8],[29,9],[66,4],[52,42],[21,56],[40,74],[16,57],[54,64],[41,4],[20,64],[28,9],[55,85],[13,35],[15,33],[43,43],[24,61],[11,52],[34,70],[19,66],[23,57],[68,86],[58,53],[23,19],[46,10],[59,49],[66,9],[24,64],[23,36],[20,10],[1,68],[12,20],[8,73],[59,41]] }\nassert my_solution.countBlackBlocks(**test_input) == [6196,324,5,0,0]\n\ntest_input = { \"m\": 77, \"n\": 92, \"coordinates\": [[57,46],[24,2],[13,78],[50,91],[50,3],[17,80],[62,17],[5,88],[17,53],[73,42],[10,62],[21,60],[36,45],[36,53],[57,29],[68,43],[4,80],[74,26],[18,23],[44,69],[9,16],[52,20],[25,13],[0,60],[23,80],[26,23],[49,34],[58,71],[24,53],[56,82],[30,63],[53,19],[34,14],[47,5],[2,49],[20,2],[38,87],[30,46],[56,48],[34,1],[24,14],[70,40],[33,74],[65,86],[17,39],[48,80],[24,19],[30,90],[17,61],[31,83],[66,79],[25,30],[57,51],[25,43],[54,47],[60,12],[17,67],[2,57],[40,32],[58,90],[19,62],[9,47],[45,26],[0,37],[10,65],[64,1],[64,38],[2,34],[53,4],[16,37],[2,22],[69,91],[27,64],[50,4],[27,88],[17,47],[9,28],[19,57],[35,88],[4,55],[7,21],[37,68],[8,83],[70,37],[38,0],[40,89],[5,36],[74,37],[59,64],[28,89],[34,75],[42,21],[51,26],[21,57],[66,63]] }\nassert my_solution.countBlackBlocks(**test_input) == [6552,358,6,0,0]\n\ntest_input = { \"m\": 25, \"n\": 52, \"coordinates\": [[7,8],[3,21],[10,39],[12,35],[20,21],[5,37],[4,28],[15,49],[14,26],[12,47],[10,28]] }\nassert my_solution.countBlackBlocks(**test_input) == [1180,44,0,0,0]\n\ntest_input = { \"m\": 78, \"n\": 84, \"coordinates\": [[70,29],[22,36],[60,16],[39,28],[67,15],[50,11],[69,28],[24,32],[48,52]] }\nassert my_solution.countBlackBlocks(**test_input) == [6356,34,1,0,0]\n\ntest_input = { \"m\": 46, \"n\": 76, \"coordinates\": [[18,2],[41,13],[38,28],[9,54],[35,67],[31,72],[29,47],[44,16],[35,5],[36,14],[16,69],[34,74],[15,32],[37,29],[41,37],[5,9],[26,68],[40,38],[30,38],[42,57],[2,2],[42,54],[4,23],[40,15],[22,18],[0,28],[34,33],[37,17],[24,49],[25,73],[35,63],[20,60],[20,16],[10,50],[24,46],[26,8],[43,56],[9,37],[24,56],[42,73],[2,9],[14,72],[35,0],[40,20],[30,8],[12,30],[15,37],[42,75],[31,2],[43,34],[24,18],[19,27],[42,23],[6,70],[22,21],[15,63],[13,39],[36,12],[13,46],[23,71],[21,44],[21,26],[3,15],[41,41],[17,43],[34,47],[4,65],[36,18],[19,1],[31,55],[44,21],[15,9],[18,46],[29,32],[32,19],[1,48],[41,55],[40,66],[43,3],[32,25],[36,49],[7,5],[26,4],[27,21],[27,44]] }\nassert my_solution.countBlackBlocks(**test_input) == [3047,322,6,0,0]\n\ntest_input = { \"m\": 6, \"n\": 35, \"coordinates\": [[1,26],[4,24],[2,2],[4,17],[2,5],[3,32],[3,21],[1,0],[2,8],[4,20],[1,4],[2,9],[1,17],[3,1],[0,2],[4,6],[0,18],[4,23],[2,24],[0,16],[1,15],[3,22],[2,12],[1,18],[4,21],[0,26],[4,19],[4,2],[3,34],[0,24],[3,31],[2,34],[3,2],[1,24],[0,33],[0,31]] }\nassert my_solution.countBlackBlocks(**test_input) == [81,59,25,5,0]\n\ntest_input = { \"m\": 95, \"n\": 99, \"coordinates\": [[40,34],[77,26],[5,19],[84,36],[6,42],[92,59],[67,70],[62,38],[87,44],[79,79],[92,44],[75,85],[43,2],[91,34],[78,69],[19,1],[10,15],[82,79],[28,14],[79,72],[57,84],[75,93],[29,93],[91,66],[84,38],[76,81],[5,11],[32,7],[48,25],[10,70],[67,37],[31,91],[45,19],[59,19],[29,98],[37,57],[83,18],[44,80],[91,27],[74,69],[13,62],[5,23],[91,70],[89,71],[11,32],[82,30],[45,61],[10,50],[25,65],[22,32],[77,13],[9,79],[69,37],[77,63],[6,48],[7,77],[35,8],[27,94],[45,37],[30,78],[81,21],[89,84],[75,73],[74,18],[4,28],[10,66],[43,54],[28,7],[26,41],[2,74],[6,70],[8,30],[18,98],[63,10],[22,98]] }\nassert my_solution.countBlackBlocks(**test_input) == [8918,294,0,0,0]\n\ntest_input = { \"m\": 57, \"n\": 91, \"coordinates\": [[42,12],[38,56],[28,82],[54,52],[24,5]] }\nassert my_solution.countBlackBlocks(**test_input) == [5020,20,0,0,0]\n\ntest_input = { \"m\": 60, \"n\": 73, \"coordinates\": [[22,24],[22,4],[45,1],[38,57],[54,41],[6,58],[8,44],[40,42],[19,47],[31,47],[48,33],[43,37],[22,54],[36,23],[23,9],[51,15],[24,39],[32,0],[17,7],[41,27],[39,12],[11,10],[22,58],[13,69],[37,37],[17,48],[18,19],[52,40],[52,32],[11,2],[32,21],[39,33],[32,1],[54,17],[0,71],[7,21],[18,24],[0,13],[22,29],[49,62],[44,63],[53,53],[31,44],[28,5],[46,65],[37,27],[39,55],[16,56],[33,10],[40,19],[43,58],[6,65],[24,41],[48,61],[28,46],[0,15],[0,55],[29,49],[5,72],[34,21],[33,40],[14,34],[9,70],[3,48],[16,15],[56,68],[18,68],[2,13],[47,38],[55,55],[22,13],[19,59],[48,60],[53,2],[46,67],[58,9],[56,67],[23,50]] }\nassert my_solution.countBlackBlocks(**test_input) == [3955,286,7,0,0]\n\ntest_input = { \"m\": 14, \"n\": 76, \"coordinates\": [[1,20],[9,9],[6,57],[3,8],[6,71],[2,67],[12,53],[6,44],[6,16],[3,26],[10,39],[7,4]] }\nassert my_solution.countBlackBlocks(**test_input) == [927,48,0,0,0]\n\ntest_input = { \"m\": 69, \"n\": 72, \"coordinates\": [[45,12],[54,37],[43,47],[4,45],[28,24],[56,5],[10,67],[30,0],[34,48],[40,45],[27,47],[47,58],[63,59],[53,53],[24,31],[16,51],[55,40],[42,27],[7,38],[3,0],[9,43],[17,15],[63,52],[27,24],[6,32],[13,50],[55,68],[11,34],[42,18],[20,42],[48,20],[36,8],[29,50],[4,55],[33,24],[43,32],[20,67],[29,37],[36,7],[66,60],[61,6],[8,28],[55,31],[61,17],[55,49],[64,33],[32,9],[54,67],[34,40],[52,39],[45,64],[4,38],[44,8],[48,34],[35,14],[25,43],[35,31],[10,21],[63,13],[7,0],[13,54],[54,68],[13,44],[51,62],[17,28],[33,31],[8,70],[25,32],[44,49],[25,16],[35,44],[23,37],[23,48],[8,49],[23,42]] }\nassert my_solution.countBlackBlocks(**test_input) == [4543,277,7,1,0]\n\ntest_input = { \"m\": 29, \"n\": 79, \"coordinates\": [[26,78],[24,55],[3,8],[3,55],[12,76],[11,23],[4,52],[5,73],[27,21],[8,19],[14,54],[10,4],[8,23],[13,16],[4,1],[21,47],[11,15],[2,26],[24,59],[12,22],[2,69],[20,1],[10,74],[25,53],[0,13],[9,28],[7,4],[10,76],[13,75],[24,25],[14,19],[12,7],[5,53],[5,59],[7,41],[8,25],[7,65],[23,48],[18,37],[7,67],[2,76],[8,64],[22,46],[2,16],[20,31],[7,38],[13,66],[22,30],[17,23],[22,60],[4,10],[6,37],[5,33],[19,58],[22,53],[9,53],[4,22],[12,4],[2,51],[3,63],[4,18],[22,43]] }\nassert my_solution.countBlackBlocks(**test_input) == [1946,232,6,0,0]\n\ntest_input = { \"m\": 6, \"n\": 58, \"coordinates\": [[0,33],[3,43],[4,25],[0,42],[4,2],[0,31],[2,10],[0,18],[1,46],[2,55],[0,13],[1,8],[2,24],[1,54],[3,54],[0,6],[0,37],[3,34],[3,53],[1,33],[2,1],[2,26],[3,11],[2,37],[1,24],[0,2],[0,14],[2,33],[0,41],[4,7],[4,28],[3,48],[3,0],[4,38],[1,34],[0,26],[4,43],[3,35],[2,7],[4,37],[4,26],[4,51],[4,21],[3,1],[4,53],[0,34],[4,3],[3,50],[3,24],[2,5],[3,40],[2,14],[4,39],[2,43],[2,50],[0,21],[2,8],[0,51],[0,47],[1,22],[3,17],[4,13],[2,2],[3,55],[4,29],[0,16],[1,55],[2,49],[0,24],[1,16],[2,17],[1,19],[1,42],[4,40],[0,5],[0,9],[2,32],[2,25],[0,40],[2,18],[3,31],[3,26],[1,57],[0,45],[0,17],[2,22],[3,3],[1,27],[1,20],[0,44],[2,0],[3,30],[2,40],[3,39],[4,50]] }\nassert my_solution.countBlackBlocks(**test_input) == [80,107,76,19,3]\n\ntest_input = { \"m\": 28, \"n\": 64, \"coordinates\": [[3,3],[13,53],[17,60],[1,30],[21,59],[1,51],[2,49],[1,16],[14,22],[23,17],[13,55],[8,38],[13,31],[8,34],[17,6]] }\nassert my_solution.countBlackBlocks(**test_input) == [1641,60,0,0,0]\n\ntest_input = { \"m\": 15, \"n\": 45, \"coordinates\": [[4,29],[0,10],[10,21],[6,5],[4,27],[3,11],[8,36],[1,38],[5,19],[9,1],[5,14],[8,18],[2,8],[13,5],[5,11],[6,37],[2,17],[5,39],[7,3],[2,3],[9,20],[9,41],[0,40],[10,20],[12,30],[2,4],[12,0],[5,16],[11,35],[4,38],[9,11],[3,34],[4,39],[5,8],[10,27],[5,13],[2,36],[9,44],[5,42],[7,43],[13,16],[0,30],[6,35],[8,12],[7,33],[11,12],[13,0],[10,0],[4,17],[0,34],[10,4],[0,22],[2,25],[8,39],[9,40],[4,35],[9,10],[7,18],[7,28],[13,12],[7,8],[10,37],[11,27],[12,40],[8,0],[7,4]] }\nassert my_solution.countBlackBlocks(**test_input) == [402,186,26,2,0]\n\ntest_input = { \"m\": 50, \"n\": 60, \"coordinates\": [[37,49],[8,45],[11,21],[38,10],[47,35],[15,33],[18,8],[15,22],[16,24],[14,50],[38,24],[8,23],[24,58],[11,35],[37,39],[29,18],[1,8],[40,47],[40,59],[47,48],[15,54],[16,33],[22,29],[39,16],[35,43],[40,54],[11,8],[16,14],[8,7],[38,1],[17,3],[8,3],[0,38],[43,22],[14,10],[31,15],[11,46],[21,45],[13,6],[0,34],[2,42],[47,57],[30,2],[6,38],[8,31],[11,44],[44,36],[10,45],[41,29],[31,30],[47,54],[3,51],[26,5],[3,43],[22,42],[27,28],[48,4],[0,49],[45,22],[7,58],[26,27],[35,31],[40,15],[45,44],[42,34],[17,54]] }\nassert my_solution.countBlackBlocks(**test_input) == [2642,242,7,0,0]\n\ntest_input = { \"m\": 36, \"n\": 54, \"coordinates\": [[7,0],[22,50],[2,41],[33,48],[1,26]] }\nassert my_solution.countBlackBlocks(**test_input) == [1837,18,0,0,0]\n\ntest_input = { \"m\": 26, \"n\": 68, \"coordinates\": [[8,51],[18,5],[18,64]] }\nassert my_solution.countBlackBlocks(**test_input) == [1663,12,0,0,0]\n\ntest_input = { \"m\": 21, \"n\": 46, \"coordinates\": [[12,7],[12,35],[13,14],[11,22],[2,1],[11,28],[1,7],[6,36],[2,15],[15,18],[1,39],[12,38],[11,35],[9,9],[17,6],[12,10]] }\nassert my_solution.countBlackBlocks(**test_input) == [838,60,2,0,0]\n\ntest_input = { \"m\": 35, \"n\": 74, \"coordinates\": [[9,54],[9,23],[8,48],[14,29],[17,37],[6,4],[17,39],[18,41],[18,50],[24,20],[29,65],[30,3],[5,19],[11,58],[6,67],[21,44],[8,3],[7,11],[18,29],[22,46],[19,51],[4,49],[13,15],[19,48],[12,33],[8,6],[25,48],[17,70],[2,68],[21,53],[9,37],[27,8],[14,69],[2,16],[20,54],[8,67],[31,44],[10,38],[19,21],[16,43],[25,65],[33,20],[17,5],[23,6],[14,23],[14,26],[1,61],[28,21],[1,68],[24,59],[19,17],[23,4],[25,52],[2,43],[30,13],[31,34],[32,43],[14,20],[11,4],[30,20],[0,67],[27,20],[32,64],[20,17],[24,61],[5,35],[31,18],[28,40],[13,11],[29,59],[17,50],[13,54],[20,67],[32,2],[4,18]] }\nassert my_solution.countBlackBlocks(**test_input) == [2197,272,13,0,0]\n\ntest_input = { \"m\": 28, \"n\": 52, \"coordinates\": [[3,23],[24,28],[7,19],[11,12],[4,27],[3,17],[8,41],[20,30],[23,24],[1,41],[12,30],[2,50],[18,36],[5,7],[1,42],[7,0],[10,51],[20,46],[20,24],[19,7],[23,28],[26,8],[17,31],[22,7],[22,26],[15,8],[19,27],[16,33],[15,39],[13,51],[20,47],[3,39],[25,36],[25,37],[10,0],[19,26],[8,9],[12,31],[19,44],[8,1],[3,12],[8,5],[23,46],[22,15],[18,2],[22,10],[24,43],[16,9],[18,22],[22,8],[20,6],[3,1],[8,17],[25,1],[9,32],[11,34],[7,44],[2,38],[13,37],[26,1],[2,26],[14,38],[6,36],[22,24],[6,27],[18,38],[25,41],[22,39],[18,51],[2,18],[12,24],[4,14],[21,38],[6,44],[18,25],[12,1],[12,4],[1,22],[12,40],[18,11]] }\nassert my_solution.countBlackBlocks(**test_input) == [1096,252,29,0,0]\n\ntest_input = { \"m\": 5, \"n\": 56, \"coordinates\": [[1,2],[3,7],[2,24],[0,5],[2,3],[2,25],[3,20],[1,8],[2,26],[0,53],[2,44],[0,49],[3,30],[0,11],[1,6],[0,14],[1,9],[2,34],[2,54],[0,31],[1,10],[0,39],[0,26],[0,12],[0,37],[0,42],[0,28],[2,29],[2,46],[1,44],[0,47],[0,35],[1,53],[1,38],[0,24],[0,2],[3,23],[3,36],[3,24],[2,17],[2,35],[3,37],[2,0],[3,45],[0,16],[1,34],[0,29],[1,5],[2,38]] }\nassert my_solution.countBlackBlocks(**test_input) == [105,76,35,4,0]\n\ntest_input = { \"m\": 36, \"n\": 38, \"coordinates\": [[7,13],[24,30],[23,29],[31,14],[28,33],[16,37],[3,27],[21,36],[9,30],[22,12],[22,21],[6,37],[18,31],[19,4],[18,20],[11,8],[16,14],[7,1],[11,30],[23,16],[15,15],[23,26],[13,12],[11,19]] }\nassert my_solution.countBlackBlocks(**test_input) == [1205,88,2,0,0]\n\ntest_input = { \"m\": 70, \"n\": 75, \"coordinates\": [[17,67],[60,71],[53,71],[14,36],[19,57],[35,22],[8,11],[27,36],[47,71],[58,54],[35,63],[54,18],[17,22],[34,60],[26,35],[61,39],[65,20],[38,37],[58,34],[34,23],[63,32],[55,32],[35,53],[29,52],[6,4],[5,66],[5,6],[6,60],[61,50],[16,24],[24,51],[65,45],[11,14],[7,27],[67,24],[34,53],[61,16],[60,50],[19,41],[56,19],[10,15],[17,0],[8,59],[32,24],[35,27],[41,34],[59,6],[17,30]] }\nassert my_solution.countBlackBlocks(**test_input) == [4923,176,7,0,0]\n\ntest_input = { \"m\": 8, \"n\": 68, \"coordinates\": [[5,36],[4,65],[1,9],[5,49],[5,34],[6,59],[5,27],[4,2],[6,53],[6,22],[4,60],[3,65],[6,16],[2,56],[0,27],[6,25],[3,32],[5,2],[3,63],[0,58],[0,37],[6,44],[0,61],[6,37],[1,36],[2,1],[1,4],[6,24],[5,12],[5,23],[0,57],[4,59],[1,44],[2,51],[5,1],[0,8],[5,22],[4,3],[5,0],[5,45],[2,8],[1,12],[1,8],[2,10],[0,48],[1,55],[1,14],[3,12],[5,39],[1,31],[1,27],[0,31],[4,61],[0,54],[2,46],[4,66],[6,32],[5,53],[3,11],[5,4],[2,21],[1,49]] }\nassert my_solution.countBlackBlocks(**test_input) == [288,140,35,6,0]", "start_time": 1688826600} +{"task_id": "weekly-contest-352-longest-even-odd-subarray-with-threshold", "url": "https://leetcode.com/problems/longest-even-odd-subarray-with-threshold", "title": "longest-even-odd-subarray-with-threshold", "meta": {"questionId": "2866", "questionFrontendId": "2760", "title": "Longest Even Odd Subarray With Threshold", "titleSlug": "longest-even-odd-subarray-with-threshold", "isPaidOnly": false, "difficulty": "Easy", "likes": 248, "dislikes": 243, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0 开始的整数数组 nums 和一个整数 threshold 。\n\n请你从 nums 的子数组中找出以下标 l 开头、下标 r 结尾 (0 <= l <= r < nums.length) 且满足以下条件的 最长子数组 :\n\n * nums[l] % 2 == 0\n * 对于范围 [l, r - 1] 内的所有下标 i ,nums[i] % 2 != nums[i + 1] % 2\n * 对于范围 [l, r] 内的所有下标 i ,nums[i] <= threshold\n\n以整数形式返回满足题目要求的最长子数组的长度。\n\n注意:子数组 是数组中的一个连续非空元素序列。\n\n示例 1:\n\n输入:nums = [3,2,5,4], threshold = 5\n输出:3\n解释:在这个示例中,我们选择从 l = 1 开始、到 r = 3 结束的子数组 => [2,5,4] ,满足上述条件。\n因此,答案就是这个子数组的长度 3 。可以证明 3 是满足题目要求的最大长度。\n\n示例 2:\n\n输入:nums = [1,2], threshold = 2\n输出:1\n解释:\n在这个示例中,我们选择从 l = 1 开始、到 r = 1 结束的子数组 => [2] 。\n该子数组满足上述全部条件。可以证明 1 是满足题目要求的最大长度。\n\n示例 3:\n\n输入:nums = [2,3,4,5], threshold = 4\n输出:3\n解释:\n在这个示例中,我们选择从 l = 0 开始、到 r = 2 结束的子数组 => [2,3,4] 。\n该子数组满足上述全部条件。\n因此,答案就是这个子数组的长度 3 。可以证明 3 是满足题目要求的最大长度。\n\n提示:\n\n * 1 <= nums.length <= 100\n * 1 <= nums[i] <= 100\n * 1 <= threshold <= 100\n\"\"\"\nclass Solution:\n def longestAlternatingSubarray(self, nums: List[int], threshold: int) -> int:\n ", "prompt_sft": "给你一个下标从 0 开始的整数数组 nums 和一个整数 threshold 。\n\n请你从 nums 的子数组中找出以下标 l 开头、下标 r 结尾 (0 <= l <= r < nums.length) 且满足以下条件的 最长子数组 :\n\n * nums[l] % 2 == 0\n * 对于范围 [l, r - 1] 内的所有下标 i ,nums[i] % 2 != nums[i + 1] % 2\n * 对于范围 [l, r] 内的所有下标 i ,nums[i] <= threshold\n\n以整数形式返回满足题目要求的最长子数组的长度。\n\n注意:子数组 是数组中的一个连续非空元素序列。\n\n示例 1:\n\n输入:nums = [3,2,5,4], threshold = 5\n输出:3\n解释:在这个示例中,我们选择从 l = 1 开始、到 r = 3 结束的子数组 => [2,5,4] ,满足上述条件。\n因此,答案就是这个子数组的长度 3 。可以证明 3 是满足题目要求的最大长度。\n\n示例 2:\n\n输入:nums = [1,2], threshold = 2\n输出:1\n解释:\n在这个示例中,我们选择从 l = 1 开始、到 r = 1 结束的子数组 => [2] 。\n该子数组满足上述全部条件。可以证明 1 是满足题目要求的最大长度。\n\n示例 3:\n\n输入:nums = [2,3,4,5], threshold = 4\n输出:3\n解释:\n在这个示例中,我们选择从 l = 0 开始、到 r = 2 结束的子数组 => [2,3,4] 。\n该子数组满足上述全部条件。\n因此,答案就是这个子数组的长度 3 。可以证明 3 是满足题目要求的最大长度。\n\n提示:\n\n * 1 <= nums.length <= 100\n * 1 <= nums[i] <= 100\n * 1 <= threshold <= 100\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def longestAlternatingSubarray(self, nums: List[int], threshold: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [3,2,5,4], \"threshold\": 5 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [1,2], \"threshold\": 2 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [2,3,4,5], \"threshold\": 4 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [1], \"threshold\": 1 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [2], \"threshold\": 2 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [3], \"threshold\": 3 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [4], \"threshold\": 1 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [5], \"threshold\": 3 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [6], \"threshold\": 5 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [7], \"threshold\": 2 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [8], \"threshold\": 1 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [9], \"threshold\": 7 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [10], \"threshold\": 7 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [1,3], \"threshold\": 16 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [1,6], \"threshold\": 2 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [1,10], \"threshold\": 6 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [1,10], \"threshold\": 7 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [2,2], \"threshold\": 18 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [2,4], \"threshold\": 7 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [2,5], \"threshold\": 2 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [2,6], \"threshold\": 15 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [2,7], \"threshold\": 9 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [2,8], \"threshold\": 4 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [2,8], \"threshold\": 8 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [2,8], \"threshold\": 16 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [2,9], \"threshold\": 14 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [3,1], \"threshold\": 9 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [3,4], \"threshold\": 10 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [3,10], \"threshold\": 3 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [4,2], \"threshold\": 11 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [4,2], \"threshold\": 15 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [4,4], \"threshold\": 9 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [4,7], \"threshold\": 8 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [4,9], \"threshold\": 17 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [5,8], \"threshold\": 5 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [5,8], \"threshold\": 15 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [6,2], \"threshold\": 10 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [6,4], \"threshold\": 14 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [6,4], \"threshold\": 16 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [6,5], \"threshold\": 10 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [7,3], \"threshold\": 8 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [7,4], \"threshold\": 7 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [7,5], \"threshold\": 1 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [7,10], \"threshold\": 52 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [7,17], \"threshold\": 31 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [8,4], \"threshold\": 6 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [8,8], \"threshold\": 20 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [9,2], \"threshold\": 11 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [9,4], \"threshold\": 15 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [10,3], \"threshold\": 11 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [10,4], \"threshold\": 7 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [10,5], \"threshold\": 20 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [10,7], \"threshold\": 11 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [10,8], \"threshold\": 4 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [10,18], \"threshold\": 43 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [12,34], \"threshold\": 7 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [12,35], \"threshold\": 8 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [13,9], \"threshold\": 53 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [15,13], \"threshold\": 23 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [15,15], \"threshold\": 18 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [17,2], \"threshold\": 17 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [23,37], \"threshold\": 35 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [24,11], \"threshold\": 54 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [27,9], \"threshold\": 55 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [27,17], \"threshold\": 40 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [33,4], \"threshold\": 43 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [41,16], \"threshold\": 9 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [47,44], \"threshold\": 20 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [49,39], \"threshold\": 52 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [50,8], \"threshold\": 19 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [76,46], \"threshold\": 91 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,7], \"threshold\": 4 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [1,3,1], \"threshold\": 18 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [1,4,3], \"threshold\": 1 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [1,5,3], \"threshold\": 8 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [1,10,5], \"threshold\": 9 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [2,1,8], \"threshold\": 6 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [2,10,5], \"threshold\": 7 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [3,2,8], \"threshold\": 18 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [3,3,10], \"threshold\": 20 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [3,4,2], \"threshold\": 19 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [3,6,10], \"threshold\": 6 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [3,8,9], \"threshold\": 19 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [4,3,1], \"threshold\": 4 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [4,4,4], \"threshold\": 8 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [4,5,10], \"threshold\": 3 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [4,10,2], \"threshold\": 4 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [4,10,3], \"threshold\": 8 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [4,10,3], \"threshold\": 10 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [4,40,8], \"threshold\": 45 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [5,3,9], \"threshold\": 7 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [5,5,6], \"threshold\": 7 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [6,2,2], \"threshold\": 16 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [6,2,4], \"threshold\": 17 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [6,3,4], \"threshold\": 6 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [6,5,2], \"threshold\": 17 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [6,5,3], \"threshold\": 17 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [6,7,2], \"threshold\": 14 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [7,1,10], \"threshold\": 9 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [7,5,6], \"threshold\": 8 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1", "start_time": 1688265000} +{"task_id": "weekly-contest-352-prime-pairs-with-target-sum", "url": "https://leetcode.com/problems/prime-pairs-with-target-sum", "title": "prime-pairs-with-target-sum", "meta": {"questionId": "2873", "questionFrontendId": "2761", "title": "Prime Pairs With Target Sum", "titleSlug": "prime-pairs-with-target-sum", "isPaidOnly": false, "difficulty": "Medium", "likes": 311, "dislikes": 30, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个整数 n 。如果两个整数 x 和 y 满足下述条件,则认为二者形成一个质数对:\n\n * 1 <= x <= y <= n\n * x + y == n\n * x 和 y 都是质数\n\n请你以二维有序列表的形式返回符合题目要求的所有 [xi, yi] ,列表需要按 xi 的 非递减顺序 排序。如果不存在符合要求的质数对,则返回一个空数组。\n\n注意:质数是大于 1 的自然数,并且只有两个因子,即它本身和 1 。\n\n示例 1:\n\n输入:n = 10\n输出:[[3,7],[5,5]]\n解释:在这个例子中,存在满足条件的两个质数对。\n这两个质数对分别是 [3,7] 和 [5,5],按照题面描述中的方式排序后返回。\n\n示例 2:\n\n输入:n = 2\n输出:[]\n解释:可以证明不存在和为 2 的质数对,所以返回一个空数组。\n\n\n提示:\n\n * 1 <= n <= 106\n\"\"\"\nclass Solution:\n def findPrimePairs(self, n: int) -> List[List[int]]:\n ", "prompt_sft": "给你一个整数 n 。如果两个整数 x 和 y 满足下述条件,则认为二者形成一个质数对:\n\n * 1 <= x <= y <= n\n * x + y == n\n * x 和 y 都是质数\n\n请你以二维有序列表的形式返回符合题目要求的所有 [xi, yi] ,列表需要按 xi 的 非递减顺序 排序。如果不存在符合要求的质数对,则返回一个空数组。\n\n注意:质数是大于 1 的自然数,并且只有两个因子,即它本身和 1 。\n\n示例 1:\n\n输入:n = 10\n输出:[[3,7],[5,5]]\n解释:在这个例子中,存在满足条件的两个质数对。\n这两个质数对分别是 [3,7] 和 [5,5],按照题面描述中的方式排序后返回。\n\n示例 2:\n\n输入:n = 2\n输出:[]\n解释:可以证明不存在和为 2 的质数对,所以返回一个空数组。\n\n\n提示:\n\n * 1 <= n <= 106\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def findPrimePairs(self, n: int) -> List[List[int]]:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"n\": 10 }\nassert my_solution.findPrimePairs(**test_input) == [[3,7],[5,5]]\n\ntest_input = { \"n\": 2 }\nassert my_solution.findPrimePairs(**test_input) == []\n\ntest_input = { \"n\": 1 }\nassert my_solution.findPrimePairs(**test_input) == []\n\ntest_input = { \"n\": 3 }\nassert my_solution.findPrimePairs(**test_input) == []\n\ntest_input = { \"n\": 4 }\nassert my_solution.findPrimePairs(**test_input) == [[2,2]]\n\ntest_input = { \"n\": 5 }\nassert my_solution.findPrimePairs(**test_input) == [[2,3]]\n\ntest_input = { \"n\": 6 }\nassert my_solution.findPrimePairs(**test_input) == [[3,3]]\n\ntest_input = { \"n\": 7 }\nassert my_solution.findPrimePairs(**test_input) == [[2,5]]\n\ntest_input = { \"n\": 8 }\nassert my_solution.findPrimePairs(**test_input) == [[3,5]]\n\ntest_input = { \"n\": 9 }\nassert my_solution.findPrimePairs(**test_input) == [[2,7]]\n\ntest_input = { \"n\": 11 }\nassert my_solution.findPrimePairs(**test_input) == []\n\ntest_input = { \"n\": 12 }\nassert my_solution.findPrimePairs(**test_input) == [[5,7]]\n\ntest_input = { \"n\": 13 }\nassert my_solution.findPrimePairs(**test_input) == [[2,11]]\n\ntest_input = { \"n\": 14 }\nassert my_solution.findPrimePairs(**test_input) == [[3,11],[7,7]]\n\ntest_input = { \"n\": 15 }\nassert my_solution.findPrimePairs(**test_input) == [[2,13]]\n\ntest_input = { \"n\": 16 }\nassert my_solution.findPrimePairs(**test_input) == [[3,13],[5,11]]\n\ntest_input = { \"n\": 17 }\nassert my_solution.findPrimePairs(**test_input) == []\n\ntest_input = { \"n\": 18 }\nassert my_solution.findPrimePairs(**test_input) == [[5,13],[7,11]]\n\ntest_input = { \"n\": 19 }\nassert my_solution.findPrimePairs(**test_input) == [[2,17]]\n\ntest_input = { \"n\": 20 }\nassert my_solution.findPrimePairs(**test_input) == [[3,17],[7,13]]\n\ntest_input = { \"n\": 21 }\nassert my_solution.findPrimePairs(**test_input) == [[2,19]]\n\ntest_input = { \"n\": 22 }\nassert my_solution.findPrimePairs(**test_input) == [[3,19],[5,17],[11,11]]\n\ntest_input = { \"n\": 23 }\nassert my_solution.findPrimePairs(**test_input) == []\n\ntest_input = { \"n\": 24 }\nassert my_solution.findPrimePairs(**test_input) == [[5,19],[7,17],[11,13]]\n\ntest_input = { \"n\": 25 }\nassert my_solution.findPrimePairs(**test_input) == [[2,23]]\n\ntest_input = { \"n\": 26 }\nassert my_solution.findPrimePairs(**test_input) == [[3,23],[7,19],[13,13]]\n\ntest_input = { \"n\": 27 }\nassert my_solution.findPrimePairs(**test_input) == []\n\ntest_input = { \"n\": 28 }\nassert my_solution.findPrimePairs(**test_input) == [[5,23],[11,17]]\n\ntest_input = { \"n\": 29 }\nassert my_solution.findPrimePairs(**test_input) == []\n\ntest_input = { \"n\": 30 }\nassert my_solution.findPrimePairs(**test_input) == [[7,23],[11,19],[13,17]]\n\ntest_input = { \"n\": 31 }\nassert my_solution.findPrimePairs(**test_input) == [[2,29]]\n\ntest_input = { \"n\": 32 }\nassert my_solution.findPrimePairs(**test_input) == [[3,29],[13,19]]\n\ntest_input = { \"n\": 33 }\nassert my_solution.findPrimePairs(**test_input) == [[2,31]]\n\ntest_input = { \"n\": 34 }\nassert my_solution.findPrimePairs(**test_input) == [[3,31],[5,29],[11,23],[17,17]]\n\ntest_input = { \"n\": 35 }\nassert my_solution.findPrimePairs(**test_input) == []\n\ntest_input = { \"n\": 36 }\nassert my_solution.findPrimePairs(**test_input) == [[5,31],[7,29],[13,23],[17,19]]\n\ntest_input = { \"n\": 37 }\nassert my_solution.findPrimePairs(**test_input) == []\n\ntest_input = { \"n\": 38 }\nassert my_solution.findPrimePairs(**test_input) == [[7,31],[19,19]]\n\ntest_input = { \"n\": 39 }\nassert my_solution.findPrimePairs(**test_input) == [[2,37]]\n\ntest_input = { \"n\": 40 }\nassert my_solution.findPrimePairs(**test_input) == [[3,37],[11,29],[17,23]]\n\ntest_input = { \"n\": 41 }\nassert my_solution.findPrimePairs(**test_input) == []\n\ntest_input = { \"n\": 42 }\nassert my_solution.findPrimePairs(**test_input) == [[5,37],[11,31],[13,29],[19,23]]\n\ntest_input = { \"n\": 43 }\nassert my_solution.findPrimePairs(**test_input) == [[2,41]]\n\ntest_input = { \"n\": 44 }\nassert my_solution.findPrimePairs(**test_input) == [[3,41],[7,37],[13,31]]\n\ntest_input = { \"n\": 45 }\nassert my_solution.findPrimePairs(**test_input) == [[2,43]]\n\ntest_input = { \"n\": 46 }\nassert my_solution.findPrimePairs(**test_input) == [[3,43],[5,41],[17,29],[23,23]]\n\ntest_input = { \"n\": 47 }\nassert my_solution.findPrimePairs(**test_input) == []\n\ntest_input = { \"n\": 48 }\nassert my_solution.findPrimePairs(**test_input) == [[5,43],[7,41],[11,37],[17,31],[19,29]]\n\ntest_input = { \"n\": 49 }\nassert my_solution.findPrimePairs(**test_input) == [[2,47]]\n\ntest_input = { \"n\": 50 }\nassert my_solution.findPrimePairs(**test_input) == [[3,47],[7,43],[13,37],[19,31]]\n\ntest_input = { \"n\": 51 }\nassert my_solution.findPrimePairs(**test_input) == []\n\ntest_input = { \"n\": 52 }\nassert my_solution.findPrimePairs(**test_input) == [[5,47],[11,41],[23,29]]\n\ntest_input = { \"n\": 53 }\nassert my_solution.findPrimePairs(**test_input) == []\n\ntest_input = { \"n\": 54 }\nassert my_solution.findPrimePairs(**test_input) == [[7,47],[11,43],[13,41],[17,37],[23,31]]\n\ntest_input = { \"n\": 55 }\nassert my_solution.findPrimePairs(**test_input) == [[2,53]]\n\ntest_input = { \"n\": 56 }\nassert my_solution.findPrimePairs(**test_input) == [[3,53],[13,43],[19,37]]\n\ntest_input = { \"n\": 57 }\nassert my_solution.findPrimePairs(**test_input) == []\n\ntest_input = { \"n\": 58 }\nassert my_solution.findPrimePairs(**test_input) == [[5,53],[11,47],[17,41],[29,29]]\n\ntest_input = { \"n\": 59 }\nassert my_solution.findPrimePairs(**test_input) == []\n\ntest_input = { \"n\": 60 }\nassert my_solution.findPrimePairs(**test_input) == [[7,53],[13,47],[17,43],[19,41],[23,37],[29,31]]\n\ntest_input = { \"n\": 61 }\nassert my_solution.findPrimePairs(**test_input) == [[2,59]]\n\ntest_input = { \"n\": 62 }\nassert my_solution.findPrimePairs(**test_input) == [[3,59],[19,43],[31,31]]\n\ntest_input = { \"n\": 63 }\nassert my_solution.findPrimePairs(**test_input) == [[2,61]]\n\ntest_input = { \"n\": 64 }\nassert my_solution.findPrimePairs(**test_input) == [[3,61],[5,59],[11,53],[17,47],[23,41]]\n\ntest_input = { \"n\": 65 }\nassert my_solution.findPrimePairs(**test_input) == []\n\ntest_input = { \"n\": 66 }\nassert my_solution.findPrimePairs(**test_input) == [[5,61],[7,59],[13,53],[19,47],[23,43],[29,37]]\n\ntest_input = { \"n\": 67 }\nassert my_solution.findPrimePairs(**test_input) == []\n\ntest_input = { \"n\": 68 }\nassert my_solution.findPrimePairs(**test_input) == [[7,61],[31,37]]\n\ntest_input = { \"n\": 69 }\nassert my_solution.findPrimePairs(**test_input) == [[2,67]]\n\ntest_input = { \"n\": 70 }\nassert my_solution.findPrimePairs(**test_input) == [[3,67],[11,59],[17,53],[23,47],[29,41]]\n\ntest_input = { \"n\": 71 }\nassert my_solution.findPrimePairs(**test_input) == []\n\ntest_input = { \"n\": 72 }\nassert my_solution.findPrimePairs(**test_input) == [[5,67],[11,61],[13,59],[19,53],[29,43],[31,41]]\n\ntest_input = { \"n\": 73 }\nassert my_solution.findPrimePairs(**test_input) == [[2,71]]\n\ntest_input = { \"n\": 74 }\nassert my_solution.findPrimePairs(**test_input) == [[3,71],[7,67],[13,61],[31,43],[37,37]]\n\ntest_input = { \"n\": 75 }\nassert my_solution.findPrimePairs(**test_input) == [[2,73]]\n\ntest_input = { \"n\": 76 }\nassert my_solution.findPrimePairs(**test_input) == [[3,73],[5,71],[17,59],[23,53],[29,47]]\n\ntest_input = { \"n\": 77 }\nassert my_solution.findPrimePairs(**test_input) == []\n\ntest_input = { \"n\": 78 }\nassert my_solution.findPrimePairs(**test_input) == [[5,73],[7,71],[11,67],[17,61],[19,59],[31,47],[37,41]]\n\ntest_input = { \"n\": 79 }\nassert my_solution.findPrimePairs(**test_input) == []\n\ntest_input = { \"n\": 80 }\nassert my_solution.findPrimePairs(**test_input) == [[7,73],[13,67],[19,61],[37,43]]\n\ntest_input = { \"n\": 81 }\nassert my_solution.findPrimePairs(**test_input) == [[2,79]]\n\ntest_input = { \"n\": 82 }\nassert my_solution.findPrimePairs(**test_input) == [[3,79],[11,71],[23,59],[29,53],[41,41]]\n\ntest_input = { \"n\": 83 }\nassert my_solution.findPrimePairs(**test_input) == []\n\ntest_input = { \"n\": 84 }\nassert my_solution.findPrimePairs(**test_input) == [[5,79],[11,73],[13,71],[17,67],[23,61],[31,53],[37,47],[41,43]]\n\ntest_input = { \"n\": 85 }\nassert my_solution.findPrimePairs(**test_input) == [[2,83]]\n\ntest_input = { \"n\": 86 }\nassert my_solution.findPrimePairs(**test_input) == [[3,83],[7,79],[13,73],[19,67],[43,43]]\n\ntest_input = { \"n\": 87 }\nassert my_solution.findPrimePairs(**test_input) == []\n\ntest_input = { \"n\": 88 }\nassert my_solution.findPrimePairs(**test_input) == [[5,83],[17,71],[29,59],[41,47]]\n\ntest_input = { \"n\": 89 }\nassert my_solution.findPrimePairs(**test_input) == []\n\ntest_input = { \"n\": 90 }\nassert my_solution.findPrimePairs(**test_input) == [[7,83],[11,79],[17,73],[19,71],[23,67],[29,61],[31,59],[37,53],[43,47]]\n\ntest_input = { \"n\": 91 }\nassert my_solution.findPrimePairs(**test_input) == [[2,89]]\n\ntest_input = { \"n\": 92 }\nassert my_solution.findPrimePairs(**test_input) == [[3,89],[13,79],[19,73],[31,61]]\n\ntest_input = { \"n\": 93 }\nassert my_solution.findPrimePairs(**test_input) == []\n\ntest_input = { \"n\": 94 }\nassert my_solution.findPrimePairs(**test_input) == [[5,89],[11,83],[23,71],[41,53],[47,47]]\n\ntest_input = { \"n\": 95 }\nassert my_solution.findPrimePairs(**test_input) == []\n\ntest_input = { \"n\": 96 }\nassert my_solution.findPrimePairs(**test_input) == [[7,89],[13,83],[17,79],[23,73],[29,67],[37,59],[43,53]]\n\ntest_input = { \"n\": 97 }\nassert my_solution.findPrimePairs(**test_input) == []\n\ntest_input = { \"n\": 98 }\nassert my_solution.findPrimePairs(**test_input) == [[19,79],[31,67],[37,61]]\n\ntest_input = { \"n\": 99 }\nassert my_solution.findPrimePairs(**test_input) == [[2,97]]\n\ntest_input = { \"n\": 100 }\nassert my_solution.findPrimePairs(**test_input) == [[3,97],[11,89],[17,83],[29,71],[41,59],[47,53]]", "start_time": 1688265000} +{"task_id": "weekly-contest-352-continuous-subarrays", "url": "https://leetcode.com/problems/continuous-subarrays", "title": "continuous-subarrays", "meta": {"questionId": "2868", "questionFrontendId": "2762", "title": "Continuous Subarrays", "titleSlug": "continuous-subarrays", "isPaidOnly": false, "difficulty": "Medium", "likes": 604, "dislikes": 17, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n给你一个下标从 0 开始的整数数组 nums 。nums 的一个子数组如果满足以下条件,那么它是 不间断 的:\n\n * i,i + 1 ,...,j  表示子数组中的下标。对于所有满足 i <= i1, i2 <= j 的下标对,都有 0 <= |nums[i1] - nums[i2]| <= 2 。\n\n请你返回 不间断 子数组的总数目。\n\n子数组是一个数组中一段连续 非空 的元素序列。\n\n示例 1:\n\n输入:nums = [5,4,2,4]\n输出:8\n解释:\n大小为 1 的不间断子数组:[5], [4], [2], [4] 。\n大小为 2 的不间断子数组:[5,4], [4,2], [2,4] 。\n大小为 3 的不间断子数组:[4,2,4] 。\n没有大小为 4 的不间断子数组。\n不间断子数组的总数目为 4 + 3 + 1 = 8 。\n除了这些以外,没有别的不间断子数组。\n\n示例 2:\n\n输入:nums = [1,2,3]\n输出:6\n解释:\n大小为 1 的不间断子数组:[1], [2], [3] 。\n大小为 2 的不间断子数组:[1,2], [2,3] 。\n大小为 3 的不间断子数组:[1,2,3] 。\n不间断子数组的总数目为 3 + 2 + 1 = 6 。\n\n\n提示:\n\n * 1 <= nums.length <= 105\n * 1 <= nums[i] <= 109\n\"\"\"\nclass Solution:\n def continuousSubarrays(self, nums: List[int]) -> int:\n ", "prompt_sft": "给你一个下标从 0 开始的整数数组 nums 。nums 的一个子数组如果满足以下条件,那么它是 不间断 的:\n\n * i,i + 1 ,...,j  表示子数组中的下标。对于所有满足 i <= i1, i2 <= j 的下标对,都有 0 <= |nums[i1] - nums[i2]| <= 2 。\n\n请你返回 不间断 子数组的总数目。\n\n子数组是一个数组中一段连续 非空 的元素序列。\n\n示例 1:\n\n输入:nums = [5,4,2,4]\n输出:8\n解释:\n大小为 1 的不间断子数组:[5], [4], [2], [4] 。\n大小为 2 的不间断子数组:[5,4], [4,2], [2,4] 。\n大小为 3 的不间断子数组:[4,2,4] 。\n没有大小为 4 的不间断子数组。\n不间断子数组的总数目为 4 + 3 + 1 = 8 。\n除了这些以外,没有别的不间断子数组。\n\n示例 2:\n\n输入:nums = [1,2,3]\n输出:6\n解释:\n大小为 1 的不间断子数组:[1], [2], [3] 。\n大小为 2 的不间断子数组:[1,2], [2,3] 。\n大小为 3 的不间断子数组:[1,2,3] 。\n不间断子数组的总数目为 3 + 2 + 1 = 6 。\n\n\n提示:\n\n * 1 <= nums.length <= 105\n * 1 <= nums[i] <= 109\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def continuousSubarrays(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [5,4,2,4] }\nassert my_solution.continuousSubarrays(**test_input) == 8\n\ntest_input = { \"nums\": [1,2,3] }\nassert my_solution.continuousSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [31,30,31,32] }\nassert my_solution.continuousSubarrays(**test_input) == 10\n\ntest_input = { \"nums\": [65,66,67,66,66,65,64,65,65,64] }\nassert my_solution.continuousSubarrays(**test_input) == 43\n\ntest_input = { \"nums\": [42,41,42,41,41,40,39,38] }\nassert my_solution.continuousSubarrays(**test_input) == 28\n\ntest_input = { \"nums\": [35,35,36,37,36,37,38,37,38] }\nassert my_solution.continuousSubarrays(**test_input) == 39\n\ntest_input = { \"nums\": [43,44,43,44] }\nassert my_solution.continuousSubarrays(**test_input) == 10\n\ntest_input = { \"nums\": [14,15,15,15,16,16,16,16,15,16] }\nassert my_solution.continuousSubarrays(**test_input) == 55\n\ntest_input = { \"nums\": [21] }\nassert my_solution.continuousSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [34,34,33,34,33,33,32,31,30,31] }\nassert my_solution.continuousSubarrays(**test_input) == 39\n\ntest_input = { \"nums\": [58,59,59,58,59] }\nassert my_solution.continuousSubarrays(**test_input) == 15\n\ntest_input = { \"nums\": [10,9,8,7,8,9,9] }\nassert my_solution.continuousSubarrays(**test_input) == 24\n\ntest_input = { \"nums\": [65,66,65,64,63,62,62] }\nassert my_solution.continuousSubarrays(**test_input) == 20\n\ntest_input = { \"nums\": [65,65,64,65,66,65] }\nassert my_solution.continuousSubarrays(**test_input) == 21\n\ntest_input = { \"nums\": [85,84,83,84,83,82] }\nassert my_solution.continuousSubarrays(**test_input) == 20\n\ntest_input = { \"nums\": [60,59,60] }\nassert my_solution.continuousSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [96,97,98] }\nassert my_solution.continuousSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [21,22,23,22,23] }\nassert my_solution.continuousSubarrays(**test_input) == 15\n\ntest_input = { \"nums\": [76,77,77,78,77,78,78] }\nassert my_solution.continuousSubarrays(**test_input) == 28\n\ntest_input = { \"nums\": [27,27,27,26,26,27,27,27,27] }\nassert my_solution.continuousSubarrays(**test_input) == 45\n\ntest_input = { \"nums\": [17] }\nassert my_solution.continuousSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [95] }\nassert my_solution.continuousSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [62] }\nassert my_solution.continuousSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [10,10,9,8,9,9,9,8,8] }\nassert my_solution.continuousSubarrays(**test_input) == 45\n\ntest_input = { \"nums\": [21,22,22,23,24,24,23,24,23,24] }\nassert my_solution.continuousSubarrays(**test_input) == 49\n\ntest_input = { \"nums\": [94,94,94,94,94,93,94] }\nassert my_solution.continuousSubarrays(**test_input) == 28\n\ntest_input = { \"nums\": [66,65,64,64,64,65,64,63] }\nassert my_solution.continuousSubarrays(**test_input) == 35\n\ntest_input = { \"nums\": [35,35,36,36,35] }\nassert my_solution.continuousSubarrays(**test_input) == 15\n\ntest_input = { \"nums\": [35,34,33,34,35,35,34,35,34] }\nassert my_solution.continuousSubarrays(**test_input) == 45\n\ntest_input = { \"nums\": [70,69,70,71,70,70,71,71] }\nassert my_solution.continuousSubarrays(**test_input) == 36\n\ntest_input = { \"nums\": [49,49,49,50,50,49,50,51,51] }\nassert my_solution.continuousSubarrays(**test_input) == 45\n\ntest_input = { \"nums\": [70,71,72,72,72] }\nassert my_solution.continuousSubarrays(**test_input) == 15\n\ntest_input = { \"nums\": [73,73,74,75,76,76,75,76] }\nassert my_solution.continuousSubarrays(**test_input) == 28\n\ntest_input = { \"nums\": [74,74,74,75,76,75,75,76,77,77] }\nassert my_solution.continuousSubarrays(**test_input) == 49\n\ntest_input = { \"nums\": [21,21,20,19,20,20,21,21] }\nassert my_solution.continuousSubarrays(**test_input) == 36\n\ntest_input = { \"nums\": [86,85] }\nassert my_solution.continuousSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [94,95,96,96,97,98,99,100,100] }\nassert my_solution.continuousSubarrays(**test_input) == 28\n\ntest_input = { \"nums\": [16,17,16] }\nassert my_solution.continuousSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [25,26,26,27,28,27,28,28,27,27] }\nassert my_solution.continuousSubarrays(**test_input) == 49\n\ntest_input = { \"nums\": [54] }\nassert my_solution.continuousSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [94,95,96,95,94,93,92,91] }\nassert my_solution.continuousSubarrays(**test_input) == 24\n\ntest_input = { \"nums\": [84,84,83] }\nassert my_solution.continuousSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [26,26] }\nassert my_solution.continuousSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [53,54,54,55] }\nassert my_solution.continuousSubarrays(**test_input) == 10\n\ntest_input = { \"nums\": [67,67,66,67,68,69,70,71,71] }\nassert my_solution.continuousSubarrays(**test_input) == 28\n\ntest_input = { \"nums\": [43,42,42,42,43] }\nassert my_solution.continuousSubarrays(**test_input) == 15\n\ntest_input = { \"nums\": [93,94,93] }\nassert my_solution.continuousSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [80,80] }\nassert my_solution.continuousSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [54,54,53,54,55,56,57,58,59] }\nassert my_solution.continuousSubarrays(**test_input) == 27\n\ntest_input = { \"nums\": [52,51,50,49,48,49,48,47,46] }\nassert my_solution.continuousSubarrays(**test_input) == 29\n\ntest_input = { \"nums\": [93,92,91,92,92,92,92] }\nassert my_solution.continuousSubarrays(**test_input) == 28\n\ntest_input = { \"nums\": [91,91,90,90,90,91,91,90] }\nassert my_solution.continuousSubarrays(**test_input) == 36\n\ntest_input = { \"nums\": [37,37,37,36] }\nassert my_solution.continuousSubarrays(**test_input) == 10\n\ntest_input = { \"nums\": [40,39,39,39,39,40,40,41,40,39] }\nassert my_solution.continuousSubarrays(**test_input) == 55\n\ntest_input = { \"nums\": [82,83,83,83,83,84] }\nassert my_solution.continuousSubarrays(**test_input) == 21\n\ntest_input = { \"nums\": [35,36,36,37,37,37,36,37,36] }\nassert my_solution.continuousSubarrays(**test_input) == 45\n\ntest_input = { \"nums\": [50,49,50,51,50] }\nassert my_solution.continuousSubarrays(**test_input) == 15\n\ntest_input = { \"nums\": [86,86,86,86,87] }\nassert my_solution.continuousSubarrays(**test_input) == 15\n\ntest_input = { \"nums\": [52] }\nassert my_solution.continuousSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [96,95,94,93] }\nassert my_solution.continuousSubarrays(**test_input) == 9\n\ntest_input = { \"nums\": [56,56,55,55,54,55,54,54,53,52] }\nassert my_solution.continuousSubarrays(**test_input) == 47\n\ntest_input = { \"nums\": [91] }\nassert my_solution.continuousSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [91,90,91,91] }\nassert my_solution.continuousSubarrays(**test_input) == 10\n\ntest_input = { \"nums\": [56,55,55,55] }\nassert my_solution.continuousSubarrays(**test_input) == 10\n\ntest_input = { \"nums\": [1,2,2,2,1,2,3,4,4,5] }\nassert my_solution.continuousSubarrays(**test_input) == 39\n\ntest_input = { \"nums\": [84,85,84,84,85,85,85] }\nassert my_solution.continuousSubarrays(**test_input) == 28\n\ntest_input = { \"nums\": [71,71,71,71] }\nassert my_solution.continuousSubarrays(**test_input) == 10\n\ntest_input = { \"nums\": [47,47,46] }\nassert my_solution.continuousSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [65] }\nassert my_solution.continuousSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [20,20,19,18] }\nassert my_solution.continuousSubarrays(**test_input) == 10\n\ntest_input = { \"nums\": [22,23,23,22,22,22,22] }\nassert my_solution.continuousSubarrays(**test_input) == 28\n\ntest_input = { \"nums\": [92,92] }\nassert my_solution.continuousSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [93,92,92,91,90,90,89,88] }\nassert my_solution.continuousSubarrays(**test_input) == 27\n\ntest_input = { \"nums\": [13,13,12,11] }\nassert my_solution.continuousSubarrays(**test_input) == 10\n\ntest_input = { \"nums\": [22,22,22,21,22,21] }\nassert my_solution.continuousSubarrays(**test_input) == 21\n\ntest_input = { \"nums\": [24,25,26,26,25,26,25,25,26] }\nassert my_solution.continuousSubarrays(**test_input) == 45\n\ntest_input = { \"nums\": [37,36] }\nassert my_solution.continuousSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [52,51] }\nassert my_solution.continuousSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [58] }\nassert my_solution.continuousSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [88,88,88,87,87,87,87,88,88] }\nassert my_solution.continuousSubarrays(**test_input) == 45\n\ntest_input = { \"nums\": [84,83,83,84,83,82,81] }\nassert my_solution.continuousSubarrays(**test_input) == 24\n\ntest_input = { \"nums\": [87,88,88,87,87,88,88,89] }\nassert my_solution.continuousSubarrays(**test_input) == 36\n\ntest_input = { \"nums\": [28,28,27] }\nassert my_solution.continuousSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [82,83,83,82] }\nassert my_solution.continuousSubarrays(**test_input) == 10\n\ntest_input = { \"nums\": [97,96,96,95,96,95] }\nassert my_solution.continuousSubarrays(**test_input) == 21\n\ntest_input = { \"nums\": [72,73,73,74,73,73] }\nassert my_solution.continuousSubarrays(**test_input) == 21\n\ntest_input = { \"nums\": [21,21,20] }\nassert my_solution.continuousSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [38,38] }\nassert my_solution.continuousSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [24,24,24,23,22,22,22,23] }\nassert my_solution.continuousSubarrays(**test_input) == 36\n\ntest_input = { \"nums\": [62,62] }\nassert my_solution.continuousSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [11,10,9,10,11] }\nassert my_solution.continuousSubarrays(**test_input) == 15\n\ntest_input = { \"nums\": [34,34,35,34,35,36,36] }\nassert my_solution.continuousSubarrays(**test_input) == 28\n\ntest_input = { \"nums\": [73,74,75,75] }\nassert my_solution.continuousSubarrays(**test_input) == 10\n\ntest_input = { \"nums\": [24,23,24,24] }\nassert my_solution.continuousSubarrays(**test_input) == 10\n\ntest_input = { \"nums\": [21,22,22,23,22,23,22,23,23,22] }\nassert my_solution.continuousSubarrays(**test_input) == 55\n\ntest_input = { \"nums\": [53,53,54,54,54] }\nassert my_solution.continuousSubarrays(**test_input) == 15\n\ntest_input = { \"nums\": [94,95,96,96,97,97,98,99] }\nassert my_solution.continuousSubarrays(**test_input) == 28\n\ntest_input = { \"nums\": [89,89,89,88,87,87] }\nassert my_solution.continuousSubarrays(**test_input) == 21\n\ntest_input = { \"nums\": [89,90] }\nassert my_solution.continuousSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [18,18] }\nassert my_solution.continuousSubarrays(**test_input) == 3", "start_time": 1688265000} +{"task_id": "weekly-contest-352-sum-of-imbalance-numbers-of-all-subarrays", "url": "https://leetcode.com/problems/sum-of-imbalance-numbers-of-all-subarrays", "title": "sum-of-imbalance-numbers-of-all-subarrays", "meta": {"questionId": "2849", "questionFrontendId": "2763", "title": "Sum of Imbalance Numbers of All Subarrays", "titleSlug": "sum-of-imbalance-numbers-of-all-subarrays", "isPaidOnly": false, "difficulty": "Hard", "likes": 278, "dislikes": 7, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\n一个长度为 n 下标从 0 开始的整数数组 arr 的 不平衡数字 定义为,在 sarr = sorted(arr) 数组中,满足以下条件的下标数目:\n\n * 0 <= i < n - 1 ,和\n * sarr[i+1] - sarr[i] > 1\n\n这里,sorted(arr) 表示将数组 arr 排序后得到的数组。\n\n给你一个下标从 0 开始的整数数组 nums ,请你返回它所有 子数组 的 不平衡数字 之和。\n\n子数组指的是一个数组中连续一段 非空 的元素序列。\n\n示例 1:\n\n输入:nums = [2,3,1,4]\n输出:3\n解释:总共有 3 个子数组有非 0 不平衡数字:\n- 子数组 [3, 1] ,不平衡数字为 1 。\n- 子数组 [3, 1, 4] ,不平衡数字为 1 。\n- 子数组 [1, 4] ,不平衡数字为 1 。\n其他所有子数组的不平衡数字都是 0 ,所以所有子数组的不平衡数字之和为 3 。\n\n示例 2:\n\n输入:nums = [1,3,3,3,5]\n输出:8\n解释:总共有 7 个子数组有非 0 不平衡数字:\n- 子数组 [1, 3] ,不平衡数字为 1 。\n- 子数组 [1, 3, 3] ,不平衡数字为 1 。\n- 子数组 [1, 3, 3, 3] ,不平衡数字为 1 。\n- 子数组 [1, 3, 3, 3, 5] ,不平衡数字为 2 。\n- 子数组 [3, 3, 3, 5] ,不平衡数字为 1 。\n- 子数组 [3, 3, 5] ,不平衡数字为 1 。\n- 子数组 [3, 5] ,不平衡数字为 1 。\n其他所有子数组的不平衡数字都是 0 ,所以所有子数组的不平衡数字之和为 8 。\n\n提示:\n\n * 1 <= nums.length <= 1000\n * 1 <= nums[i] <= nums.length\n\"\"\"\nclass Solution:\n def sumImbalanceNumbers(self, nums: List[int]) -> int:\n ", "prompt_sft": "一个长度为 n 下标从 0 开始的整数数组 arr 的 不平衡数字 定义为,在 sarr = sorted(arr) 数组中,满足以下条件的下标数目:\n\n * 0 <= i < n - 1 ,和\n * sarr[i+1] - sarr[i] > 1\n\n这里,sorted(arr) 表示将数组 arr 排序后得到的数组。\n\n给你一个下标从 0 开始的整数数组 nums ,请你返回它所有 子数组 的 不平衡数字 之和。\n\n子数组指的是一个数组中连续一段 非空 的元素序列。\n\n示例 1:\n\n输入:nums = [2,3,1,4]\n输出:3\n解释:总共有 3 个子数组有非 0 不平衡数字:\n- 子数组 [3, 1] ,不平衡数字为 1 。\n- 子数组 [3, 1, 4] ,不平衡数字为 1 。\n- 子数组 [1, 4] ,不平衡数字为 1 。\n其他所有子数组的不平衡数字都是 0 ,所以所有子数组的不平衡数字之和为 3 。\n\n示例 2:\n\n输入:nums = [1,3,3,3,5]\n输出:8\n解释:总共有 7 个子数组有非 0 不平衡数字:\n- 子数组 [1, 3] ,不平衡数字为 1 。\n- 子数组 [1, 3, 3] ,不平衡数字为 1 。\n- 子数组 [1, 3, 3, 3] ,不平衡数字为 1 。\n- 子数组 [1, 3, 3, 3, 5] ,不平衡数字为 2 。\n- 子数组 [3, 3, 3, 5] ,不平衡数字为 1 。\n- 子数组 [3, 3, 5] ,不平衡数字为 1 。\n- 子数组 [3, 5] ,不平衡数字为 1 。\n其他所有子数组的不平衡数字都是 0 ,所以所有子数组的不平衡数字之和为 8 。\n\n提示:\n\n * 1 <= nums.length <= 1000\n * 1 <= nums[i] <= nums.length\n\n\n请完成下面的代码来解决上述问题:\n```python\nclass Solution:\n def sumImbalanceNumbers(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [2,3,1,4] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 3\n\ntest_input = { \"nums\": [1,3,3,3,5] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 8\n\ntest_input = { \"nums\": [1] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [1,1] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [1,2] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [2,1] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [2,2] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,1] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,2] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,3] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 2\n\ntest_input = { \"nums\": [1,2,1] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [1,2,2] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [1,2,3] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [1,3,1] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 3\n\ntest_input = { \"nums\": [1,3,2] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 1\n\ntest_input = { \"nums\": [1,3,3] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 2\n\ntest_input = { \"nums\": [2,1,1] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [2,1,2] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [2,1,3] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 1\n\ntest_input = { \"nums\": [2,2,1] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [2,2,2] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [2,2,3] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [2,3,1] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 1\n\ntest_input = { \"nums\": [2,3,2] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [2,3,3] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [3,1,1] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 2\n\ntest_input = { \"nums\": [3,1,2] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 1\n\ntest_input = { \"nums\": [3,1,3] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 3\n\ntest_input = { \"nums\": [3,2,1] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [3,2,2] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [3,2,3] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [3,3,1] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 2\n\ntest_input = { \"nums\": [3,3,2] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [3,3,3] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,1,1] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,1,2] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,1,3] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,1,4] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,2,1] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,2,2] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,2,3] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,2,4] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,3,1] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 5\n\ntest_input = { \"nums\": [1,1,3,2] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,3,3] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 4\n\ntest_input = { \"nums\": [1,1,3,4] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 4\n\ntest_input = { \"nums\": [1,1,4,1] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 5\n\ntest_input = { \"nums\": [1,1,4,2] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 5\n\ntest_input = { \"nums\": [1,1,4,3] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 4\n\ntest_input = { \"nums\": [1,1,4,4] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,1,1] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [1,2,1,2] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [1,2,1,3] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,1,4] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,2,1] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [1,2,2,2] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [1,2,2,3] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [1,2,2,4] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,3,1] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,3,2] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [1,2,3,3] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [1,2,3,4] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [1,2,4,1] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 5\n\ntest_input = { \"nums\": [1,2,4,2] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 5\n\ntest_input = { \"nums\": [1,2,4,3] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 2\n\ntest_input = { \"nums\": [1,2,4,4] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 4\n\ntest_input = { \"nums\": [1,3,1,1] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 5\n\ntest_input = { \"nums\": [1,3,1,2] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 3\n\ntest_input = { \"nums\": [1,3,1,3] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 6\n\ntest_input = { \"nums\": [1,3,1,4] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 6\n\ntest_input = { \"nums\": [1,3,2,1] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 1\n\ntest_input = { \"nums\": [1,3,2,2] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 1\n\ntest_input = { \"nums\": [1,3,2,3] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 1\n\ntest_input = { \"nums\": [1,3,2,4] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 2\n\ntest_input = { \"nums\": [1,3,3,1] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 5\n\ntest_input = { \"nums\": [1,3,3,2] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 2\n\ntest_input = { \"nums\": [1,3,3,3] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 3\n\ntest_input = { \"nums\": [1,3,3,4] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 3\n\ntest_input = { \"nums\": [1,3,4,1] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 5\n\ntest_input = { \"nums\": [1,3,4,2] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 3\n\ntest_input = { \"nums\": [1,3,4,3] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 3\n\ntest_input = { \"nums\": [1,3,4,4] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 3\n\ntest_input = { \"nums\": [1,4,1,1] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 5\n\ntest_input = { \"nums\": [1,4,1,2] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 5\n\ntest_input = { \"nums\": [1,4,1,3] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 6\n\ntest_input = { \"nums\": [1,4,1,4] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 6\n\ntest_input = { \"nums\": [1,4,2,1] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 5\n\ntest_input = { \"nums\": [1,4,2,2] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 5\n\ntest_input = { \"nums\": [1,4,2,3] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 3\n\ntest_input = { \"nums\": [1,4,2,4] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 6\n\ntest_input = { \"nums\": [1,4,3,1] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 5\n\ntest_input = { \"nums\": [1,4,3,2] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 2\n\ntest_input = { \"nums\": [1,4,3,3] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 3\n\ntest_input = { \"nums\": [1,4,3,4] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 3\n\ntest_input = { \"nums\": [1,4,4,1] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 5\n\ntest_input = { \"nums\": [1,4,4,2] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 5\n\ntest_input = { \"nums\": [1,4,4,3] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 3\n\ntest_input = { \"nums\": [1,4,4,4] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 3\n\ntest_input = { \"nums\": [2,1,1,1] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [2,1,1,2] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0", "start_time": 1688265000} diff --git a/Evaluation/LeetCode/data/20240121-Jul.jsonl b/Evaluation/LeetCode/data/20240121-Jul.jsonl new file mode 100644 index 0000000..b96d757 --- /dev/null +++ b/Evaluation/LeetCode/data/20240121-Jul.jsonl @@ -0,0 +1,180 @@ +{"task_id": "weekly-contest-381-minimum-number-of-pushes-to-type-word-i", "url": "https://leetcode.com/problems/minimum-number-of-pushes-to-type-word-i", "title": "minimum-number-of-pushes-to-type-word-i", "meta": {"questionId": "3275", "questionFrontendId": "3014", "title": "Minimum Number of Pushes to Type Word I", "titleSlug": "minimum-number-of-pushes-to-type-word-i", "isPaidOnly": false, "difficulty": "Easy", "likes": 39, "dislikes": 7, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a string word containing distinct lowercase English letters.\nTelephone keypads have keys mapped with distinct collections of lowercase English letters, which can be used to form words by pushing them. For example, the key 2 is mapped with [\"a\",\"b\",\"c\"], we need to push the key one time to type \"a\", two times to type \"b\", and three times to type \"c\" .\nIt is allowed to remap the keys numbered 2 to 9 to distinct collections of letters. The keys can be remapped to any amount of letters, but each letter must be mapped to exactly one key. You need to find the minimum number of times the keys will be pushed to type the string word.\nReturn the minimum number of pushes needed to type word after remapping the keys.\nAn example mapping of letters to keys on a telephone keypad is given below. Note that 1, *, #, and 0 do not map to any letters.\n\n\nExample 1:\n\n\nInput: word = \"abcde\"\nOutput: 5\nExplanation: The remapped keypad given in the image provides the minimum cost.\n\"a\" -> one push on key 2\n\"b\" -> one push on key 3\n\"c\" -> one push on key 4\n\"d\" -> one push on key 5\n\"e\" -> one push on key 6\nTotal cost is 1 + 1 + 1 + 1 + 1 = 5.\nIt can be shown that no other mapping can provide a lower cost.\n\nExample 2:\n\n\nInput: word = \"xycdefghij\"\nOutput: 12\nExplanation: The remapped keypad given in the image provides the minimum cost.\n\"x\" -> one push on key 2\n\"y\" -> two pushes on key 2\n\"c\" -> one push on key 3\n\"d\" -> two pushes on key 3\n\"e\" -> one push on key 4\n\"f\" -> one push on key 5\n\"g\" -> one push on key 6\n\"h\" -> one push on key 7\n\"i\" -> one push on key 8\n\"j\" -> one push on key 9\nTotal cost is 1 + 2 + 1 + 2 + 1 + 1 + 1 + 1 + 1 + 1 = 12.\nIt can be shown that no other mapping can provide a lower cost.\n\n\nConstraints:\n\n1 <= word.length <= 26\nword consists of lowercase English letters.\nAll letters in word are distinct.\n\"\"\"\nclass Solution:\n def minimumPushes(self, word: str) -> int:\n ", "prompt_sft": "You are given a string word containing distinct lowercase English letters.\nTelephone keypads have keys mapped with distinct collections of lowercase English letters, which can be used to form words by pushing them. For example, the key 2 is mapped with [\"a\",\"b\",\"c\"], we need to push the key one time to type \"a\", two times to type \"b\", and three times to type \"c\" .\nIt is allowed to remap the keys numbered 2 to 9 to distinct collections of letters. The keys can be remapped to any amount of letters, but each letter must be mapped to exactly one key. You need to find the minimum number of times the keys will be pushed to type the string word.\nReturn the minimum number of pushes needed to type word after remapping the keys.\nAn example mapping of letters to keys on a telephone keypad is given below. Note that 1, *, #, and 0 do not map to any letters.\n\n\nExample 1:\n\n\nInput: word = \"abcde\"\nOutput: 5\nExplanation: The remapped keypad given in the image provides the minimum cost.\n\"a\" -> one push on key 2\n\"b\" -> one push on key 3\n\"c\" -> one push on key 4\n\"d\" -> one push on key 5\n\"e\" -> one push on key 6\nTotal cost is 1 + 1 + 1 + 1 + 1 = 5.\nIt can be shown that no other mapping can provide a lower cost.\n\nExample 2:\n\n\nInput: word = \"xycdefghij\"\nOutput: 12\nExplanation: The remapped keypad given in the image provides the minimum cost.\n\"x\" -> one push on key 2\n\"y\" -> two pushes on key 2\n\"c\" -> one push on key 3\n\"d\" -> two pushes on key 3\n\"e\" -> one push on key 4\n\"f\" -> one push on key 5\n\"g\" -> one push on key 6\n\"h\" -> one push on key 7\n\"i\" -> one push on key 8\n\"j\" -> one push on key 9\nTotal cost is 1 + 2 + 1 + 2 + 1 + 1 + 1 + 1 + 1 + 1 = 12.\nIt can be shown that no other mapping can provide a lower cost.\n\n\nConstraints:\n\n1 <= word.length <= 26\nword consists of lowercase English letters.\nAll letters in word are distinct.\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def minimumPushes(self, word: str) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"word\": \"abcde\" }\nassert my_solution.minimumPushes(**test_input) == 5\n\ntest_input = { \"word\": \"xycdefghij\" }\nassert my_solution.minimumPushes(**test_input) == 12\n\ntest_input = { \"word\": \"b\" }\nassert my_solution.minimumPushes(**test_input) == 1\n\ntest_input = { \"word\": \"d\" }\nassert my_solution.minimumPushes(**test_input) == 1\n\ntest_input = { \"word\": \"e\" }\nassert my_solution.minimumPushes(**test_input) == 1\n\ntest_input = { \"word\": \"f\" }\nassert my_solution.minimumPushes(**test_input) == 1\n\ntest_input = { \"word\": \"g\" }\nassert my_solution.minimumPushes(**test_input) == 1\n\ntest_input = { \"word\": \"h\" }\nassert my_solution.minimumPushes(**test_input) == 1\n\ntest_input = { \"word\": \"i\" }\nassert my_solution.minimumPushes(**test_input) == 1\n\ntest_input = { \"word\": \"k\" }\nassert my_solution.minimumPushes(**test_input) == 1\n\ntest_input = { \"word\": \"n\" }\nassert my_solution.minimumPushes(**test_input) == 1\n\ntest_input = { \"word\": \"o\" }\nassert my_solution.minimumPushes(**test_input) == 1\n\ntest_input = { \"word\": \"q\" }\nassert my_solution.minimumPushes(**test_input) == 1\n\ntest_input = { \"word\": \"u\" }\nassert my_solution.minimumPushes(**test_input) == 1\n\ntest_input = { \"word\": \"v\" }\nassert my_solution.minimumPushes(**test_input) == 1\n\ntest_input = { \"word\": \"w\" }\nassert my_solution.minimumPushes(**test_input) == 1\n\ntest_input = { \"word\": \"x\" }\nassert my_solution.minimumPushes(**test_input) == 1\n\ntest_input = { \"word\": \"bc\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"cu\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"dl\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"dn\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"ev\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"gn\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"gq\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"hu\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"jr\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"ln\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"lz\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"mv\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"mw\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"sw\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"wz\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"amw\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"bco\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"btx\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"cgp\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"cjq\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"clu\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"clx\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"crs\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"csz\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"dfp\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"htv\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"iwz\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"kux\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"nsv\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"svz\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"cfos\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"demr\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"dimo\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"dnpt\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"dorz\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"fgkn\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"fimn\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"hior\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"jkpy\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"jluv\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"knpv\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"kopu\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"lmpt\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"ltuw\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"qwxz\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"abhoz\" }\nassert my_solution.minimumPushes(**test_input) == 5\n\ntest_input = { \"word\": \"aejwx\" }\nassert my_solution.minimumPushes(**test_input) == 5\n\ntest_input = { \"word\": \"agjnr\" }\nassert my_solution.minimumPushes(**test_input) == 5\n\ntest_input = { \"word\": \"aikmu\" }\nassert my_solution.minimumPushes(**test_input) == 5\n\ntest_input = { \"word\": \"ajkmv\" }\nassert my_solution.minimumPushes(**test_input) == 5\n\ntest_input = { \"word\": \"cflvx\" }\nassert my_solution.minimumPushes(**test_input) == 5\n\ntest_input = { \"word\": \"dhstu\" }\nassert my_solution.minimumPushes(**test_input) == 5\n\ntest_input = { \"word\": \"djmnx\" }\nassert my_solution.minimumPushes(**test_input) == 5\n\ntest_input = { \"word\": \"dlovx\" }\nassert my_solution.minimumPushes(**test_input) == 5\n\ntest_input = { \"word\": \"eglqy\" }\nassert my_solution.minimumPushes(**test_input) == 5\n\ntest_input = { \"word\": \"ejntw\" }\nassert my_solution.minimumPushes(**test_input) == 5\n\ntest_input = { \"word\": \"ekrsz\" }\nassert my_solution.minimumPushes(**test_input) == 5\n\ntest_input = { \"word\": \"fopuz\" }\nassert my_solution.minimumPushes(**test_input) == 5\n\ntest_input = { \"word\": \"jlnvz\" }\nassert my_solution.minimumPushes(**test_input) == 5\n\ntest_input = { \"word\": \"jnstu\" }\nassert my_solution.minimumPushes(**test_input) == 5\n\ntest_input = { \"word\": \"afikno\" }\nassert my_solution.minimumPushes(**test_input) == 6\n\ntest_input = { \"word\": \"almsyz\" }\nassert my_solution.minimumPushes(**test_input) == 6\n\ntest_input = { \"word\": \"bcehov\" }\nassert my_solution.minimumPushes(**test_input) == 6\n\ntest_input = { \"word\": \"bdmprt\" }\nassert my_solution.minimumPushes(**test_input) == 6\n\ntest_input = { \"word\": \"bfhmnu\" }\nassert my_solution.minimumPushes(**test_input) == 6\n\ntest_input = { \"word\": \"bfhpty\" }\nassert my_solution.minimumPushes(**test_input) == 6\n\ntest_input = { \"word\": \"bfjstu\" }\nassert my_solution.minimumPushes(**test_input) == 6\n\ntest_input = { \"word\": \"cdfjmw\" }\nassert my_solution.minimumPushes(**test_input) == 6\n\ntest_input = { \"word\": \"dfilps\" }\nassert my_solution.minimumPushes(**test_input) == 6\n\ntest_input = { \"word\": \"dmswyz\" }\nassert my_solution.minimumPushes(**test_input) == 6\n\ntest_input = { \"word\": \"dpqruw\" }\nassert my_solution.minimumPushes(**test_input) == 6\n\ntest_input = { \"word\": \"fhmprz\" }\nassert my_solution.minimumPushes(**test_input) == 6\n\ntest_input = { \"word\": \"gjqrvy\" }\nassert my_solution.minimumPushes(**test_input) == 6\n\ntest_input = { \"word\": \"ijopsv\" }\nassert my_solution.minimumPushes(**test_input) == 6\n\ntest_input = { \"word\": \"lmqrtz\" }\nassert my_solution.minimumPushes(**test_input) == 6\n\ntest_input = { \"word\": \"bxnqpha\" }\nassert my_solution.minimumPushes(**test_input) == 7\n\ntest_input = { \"word\": \"ekbfqat\" }\nassert my_solution.minimumPushes(**test_input) == 7\n\ntest_input = { \"word\": \"esoizcx\" }\nassert my_solution.minimumPushes(**test_input) == 7\n\ntest_input = { \"word\": \"fmteczo\" }\nassert my_solution.minimumPushes(**test_input) == 7\n\ntest_input = { \"word\": \"lrywetm\" }\nassert my_solution.minimumPushes(**test_input) == 7\n\ntest_input = { \"word\": \"lvbornx\" }\nassert my_solution.minimumPushes(**test_input) == 7\n\ntest_input = { \"word\": \"pesmonc\" }\nassert my_solution.minimumPushes(**test_input) == 7\n\ntest_input = { \"word\": \"pudymjw\" }\nassert my_solution.minimumPushes(**test_input) == 7", "start_time": 1705804200} +{"task_id": "weekly-contest-381-count-the-number-of-houses-at-a-certain-distance-i", "url": "https://leetcode.com/problems/count-the-number-of-houses-at-a-certain-distance-i", "title": "count-the-number-of-houses-at-a-certain-distance-i", "meta": {"questionId": "3271", "questionFrontendId": "3015", "title": "Count the Number of Houses at a Certain Distance I", "titleSlug": "count-the-number-of-houses-at-a-certain-distance-i", "isPaidOnly": false, "difficulty": "Medium", "likes": 62, "dislikes": 7, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given three positive integers n, x, and y.\nIn a city, there exist houses numbered 1 to n connected by n streets. There is a street connecting the house numbered i with the house numbered i + 1 for all 1 <= i <= n - 1 . An additional street connects the house numbered x with the house numbered y.\nFor each k, such that 1 <= k <= n, you need to find the number of pairs of houses (house1, house2) such that the minimum number of streets that need to be traveled to reach house2 from house1 is k.\nReturn a 1-indexed array result of length n where result[k] represents the total number of pairs of houses such that the minimum streets required to reach one house from the other is k.\nNote that x and y can be equal.\n\nExample 1:\n\n\nInput: n = 3, x = 1, y = 3\nOutput: [6,0,0]\nExplanation: Let's look at each pair of houses:\n- For the pair (1, 2), we can go from house 1 to house 2 directly.\n- For the pair (2, 1), we can go from house 2 to house 1 directly.\n- For the pair (1, 3), we can go from house 1 to house 3 directly.\n- For the pair (3, 1), we can go from house 3 to house 1 directly.\n- For the pair (2, 3), we can go from house 2 to house 3 directly.\n- For the pair (3, 2), we can go from house 3 to house 2 directly.\n\nExample 2:\n\n\nInput: n = 5, x = 2, y = 4\nOutput: [10,8,2,0,0]\nExplanation: For each distance k the pairs are:\n- For k == 1, the pairs are (1, 2), (2, 1), (2, 3), (3, 2), (2, 4), (4, 2), (3, 4), (4, 3), (4, 5), and (5, 4).\n- For k == 2, the pairs are (1, 3), (3, 1), (1, 4), (4, 1), (2, 5), (5, 2), (3, 5), and (5, 3).\n- For k == 3, the pairs are (1, 5), and (5, 1).\n- For k == 4 and k == 5, there are no pairs.\n\nExample 3:\n\n\nInput: n = 4, x = 1, y = 1\nOutput: [6,4,2,0]\nExplanation: For each distance k the pairs are:\n- For k == 1, the pairs are (1, 2), (2, 1), (2, 3), (3, 2), (3, 4), and (4, 3).\n- For k == 2, the pairs are (1, 3), (3, 1), (2, 4), and (4, 2).\n- For k == 3, the pairs are (1, 4), and (4, 1).\n- For k == 4, there are no pairs.\n\n\nConstraints:\n\n2 <= n <= 100\n1 <= x, y <= n\n\"\"\"\nclass Solution:\n def countOfPairs(self, n: int, x: int, y: int) -> List[int]:\n ", "prompt_sft": "You are given three positive integers n, x, and y.\nIn a city, there exist houses numbered 1 to n connected by n streets. There is a street connecting the house numbered i with the house numbered i + 1 for all 1 <= i <= n - 1 . An additional street connects the house numbered x with the house numbered y.\nFor each k, such that 1 <= k <= n, you need to find the number of pairs of houses (house1, house2) such that the minimum number of streets that need to be traveled to reach house2 from house1 is k.\nReturn a 1-indexed array result of length n where result[k] represents the total number of pairs of houses such that the minimum streets required to reach one house from the other is k.\nNote that x and y can be equal.\n\nExample 1:\n\n\nInput: n = 3, x = 1, y = 3\nOutput: [6,0,0]\nExplanation: Let's look at each pair of houses:\n- For the pair (1, 2), we can go from house 1 to house 2 directly.\n- For the pair (2, 1), we can go from house 2 to house 1 directly.\n- For the pair (1, 3), we can go from house 1 to house 3 directly.\n- For the pair (3, 1), we can go from house 3 to house 1 directly.\n- For the pair (2, 3), we can go from house 2 to house 3 directly.\n- For the pair (3, 2), we can go from house 3 to house 2 directly.\n\nExample 2:\n\n\nInput: n = 5, x = 2, y = 4\nOutput: [10,8,2,0,0]\nExplanation: For each distance k the pairs are:\n- For k == 1, the pairs are (1, 2), (2, 1), (2, 3), (3, 2), (2, 4), (4, 2), (3, 4), (4, 3), (4, 5), and (5, 4).\n- For k == 2, the pairs are (1, 3), (3, 1), (1, 4), (4, 1), (2, 5), (5, 2), (3, 5), and (5, 3).\n- For k == 3, the pairs are (1, 5), and (5, 1).\n- For k == 4 and k == 5, there are no pairs.\n\nExample 3:\n\n\nInput: n = 4, x = 1, y = 1\nOutput: [6,4,2,0]\nExplanation: For each distance k the pairs are:\n- For k == 1, the pairs are (1, 2), (2, 1), (2, 3), (3, 2), (3, 4), and (4, 3).\n- For k == 2, the pairs are (1, 3), (3, 1), (2, 4), and (4, 2).\n- For k == 3, the pairs are (1, 4), and (4, 1).\n- For k == 4, there are no pairs.\n\n\nConstraints:\n\n2 <= n <= 100\n1 <= x, y <= n\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def countOfPairs(self, n: int, x: int, y: int) -> List[int]:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"n\": 3, \"x\": 1, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [6,0,0]\n\ntest_input = { \"n\": 5, \"x\": 2, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [10,8,2,0,0]\n\ntest_input = { \"n\": 4, \"x\": 1, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [6,4,2,0]\n\ntest_input = { \"n\": 2, \"x\": 1, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [2,0]\n\ntest_input = { \"n\": 2, \"x\": 1, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [2,0]\n\ntest_input = { \"n\": 2, \"x\": 2, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [2,0]\n\ntest_input = { \"n\": 2, \"x\": 2, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [2,0]\n\ntest_input = { \"n\": 3, \"x\": 1, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [4,2,0]\n\ntest_input = { \"n\": 3, \"x\": 1, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [4,2,0]\n\ntest_input = { \"n\": 3, \"x\": 2, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [4,2,0]\n\ntest_input = { \"n\": 3, \"x\": 2, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [4,2,0]\n\ntest_input = { \"n\": 3, \"x\": 2, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [4,2,0]\n\ntest_input = { \"n\": 3, \"x\": 3, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [6,0,0]\n\ntest_input = { \"n\": 3, \"x\": 3, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [4,2,0]\n\ntest_input = { \"n\": 3, \"x\": 3, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [4,2,0]\n\ntest_input = { \"n\": 4, \"x\": 1, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [6,4,2,0]\n\ntest_input = { \"n\": 4, \"x\": 1, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [8,4,0,0]\n\ntest_input = { \"n\": 4, \"x\": 1, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [8,4,0,0]\n\ntest_input = { \"n\": 4, \"x\": 2, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [6,4,2,0]\n\ntest_input = { \"n\": 4, \"x\": 2, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [6,4,2,0]\n\ntest_input = { \"n\": 4, \"x\": 2, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [6,4,2,0]\n\ntest_input = { \"n\": 4, \"x\": 2, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [8,4,0,0]\n\ntest_input = { \"n\": 4, \"x\": 3, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [8,4,0,0]\n\ntest_input = { \"n\": 4, \"x\": 3, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [6,4,2,0]\n\ntest_input = { \"n\": 4, \"x\": 3, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [6,4,2,0]\n\ntest_input = { \"n\": 4, \"x\": 3, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [6,4,2,0]\n\ntest_input = { \"n\": 4, \"x\": 4, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [8,4,0,0]\n\ntest_input = { \"n\": 4, \"x\": 4, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [8,4,0,0]\n\ntest_input = { \"n\": 4, \"x\": 4, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [6,4,2,0]\n\ntest_input = { \"n\": 4, \"x\": 4, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [6,4,2,0]\n\ntest_input = { \"n\": 5, \"x\": 1, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [8,6,4,2,0]\n\ntest_input = { \"n\": 5, \"x\": 1, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [8,6,4,2,0]\n\ntest_input = { \"n\": 5, \"x\": 1, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [10,6,4,0,0]\n\ntest_input = { \"n\": 5, \"x\": 1, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [10,8,2,0,0]\n\ntest_input = { \"n\": 5, \"x\": 1, \"y\": 5 }\nassert my_solution.countOfPairs(**test_input) == [10,10,0,0,0]\n\ntest_input = { \"n\": 5, \"x\": 2, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [8,6,4,2,0]\n\ntest_input = { \"n\": 5, \"x\": 2, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [8,6,4,2,0]\n\ntest_input = { \"n\": 5, \"x\": 2, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [8,6,4,2,0]\n\ntest_input = { \"n\": 5, \"x\": 2, \"y\": 5 }\nassert my_solution.countOfPairs(**test_input) == [10,8,2,0,0]\n\ntest_input = { \"n\": 5, \"x\": 3, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [10,6,4,0,0]\n\ntest_input = { \"n\": 5, \"x\": 3, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [8,6,4,2,0]\n\ntest_input = { \"n\": 5, \"x\": 3, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [8,6,4,2,0]\n\ntest_input = { \"n\": 5, \"x\": 3, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [8,6,4,2,0]\n\ntest_input = { \"n\": 5, \"x\": 3, \"y\": 5 }\nassert my_solution.countOfPairs(**test_input) == [10,6,4,0,0]\n\ntest_input = { \"n\": 5, \"x\": 4, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [10,8,2,0,0]\n\ntest_input = { \"n\": 5, \"x\": 4, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [10,8,2,0,0]\n\ntest_input = { \"n\": 5, \"x\": 4, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [8,6,4,2,0]\n\ntest_input = { \"n\": 5, \"x\": 4, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [8,6,4,2,0]\n\ntest_input = { \"n\": 5, \"x\": 4, \"y\": 5 }\nassert my_solution.countOfPairs(**test_input) == [8,6,4,2,0]\n\ntest_input = { \"n\": 5, \"x\": 5, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [10,10,0,0,0]\n\ntest_input = { \"n\": 5, \"x\": 5, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [10,8,2,0,0]\n\ntest_input = { \"n\": 5, \"x\": 5, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [10,6,4,0,0]\n\ntest_input = { \"n\": 5, \"x\": 5, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [8,6,4,2,0]\n\ntest_input = { \"n\": 5, \"x\": 5, \"y\": 5 }\nassert my_solution.countOfPairs(**test_input) == [8,6,4,2,0]\n\ntest_input = { \"n\": 6, \"x\": 1, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [10,8,6,4,2,0]\n\ntest_input = { \"n\": 6, \"x\": 1, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [10,8,6,4,2,0]\n\ntest_input = { \"n\": 6, \"x\": 1, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [12,8,6,4,0,0]\n\ntest_input = { \"n\": 6, \"x\": 1, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [12,10,6,2,0,0]\n\ntest_input = { \"n\": 6, \"x\": 1, \"y\": 5 }\nassert my_solution.countOfPairs(**test_input) == [12,14,4,0,0,0]\n\ntest_input = { \"n\": 6, \"x\": 1, \"y\": 6 }\nassert my_solution.countOfPairs(**test_input) == [12,12,6,0,0,0]\n\ntest_input = { \"n\": 6, \"x\": 2, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [10,8,6,4,2,0]\n\ntest_input = { \"n\": 6, \"x\": 2, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [10,8,6,4,2,0]\n\ntest_input = { \"n\": 6, \"x\": 2, \"y\": 5 }\nassert my_solution.countOfPairs(**test_input) == [12,12,6,0,0,0]\n\ntest_input = { \"n\": 6, \"x\": 2, \"y\": 6 }\nassert my_solution.countOfPairs(**test_input) == [12,14,4,0,0,0]\n\ntest_input = { \"n\": 6, \"x\": 3, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [12,8,6,4,0,0]\n\ntest_input = { \"n\": 6, \"x\": 3, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [10,8,6,4,2,0]\n\ntest_input = { \"n\": 6, \"x\": 3, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [10,8,6,4,2,0]\n\ntest_input = { \"n\": 6, \"x\": 3, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [10,8,6,4,2,0]\n\ntest_input = { \"n\": 6, \"x\": 3, \"y\": 5 }\nassert my_solution.countOfPairs(**test_input) == [12,10,6,2,0,0]\n\ntest_input = { \"n\": 6, \"x\": 3, \"y\": 6 }\nassert my_solution.countOfPairs(**test_input) == [12,10,6,2,0,0]\n\ntest_input = { \"n\": 6, \"x\": 4, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [12,10,6,2,0,0]\n\ntest_input = { \"n\": 6, \"x\": 4, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [12,10,6,2,0,0]\n\ntest_input = { \"n\": 6, \"x\": 4, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [10,8,6,4,2,0]\n\ntest_input = { \"n\": 6, \"x\": 4, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [10,8,6,4,2,0]\n\ntest_input = { \"n\": 6, \"x\": 4, \"y\": 6 }\nassert my_solution.countOfPairs(**test_input) == [12,8,6,4,0,0]\n\ntest_input = { \"n\": 6, \"x\": 5, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [12,14,4,0,0,0]\n\ntest_input = { \"n\": 6, \"x\": 5, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [12,12,6,0,0,0]\n\ntest_input = { \"n\": 6, \"x\": 5, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [12,10,6,2,0,0]\n\ntest_input = { \"n\": 6, \"x\": 5, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [10,8,6,4,2,0]\n\ntest_input = { \"n\": 6, \"x\": 5, \"y\": 5 }\nassert my_solution.countOfPairs(**test_input) == [10,8,6,4,2,0]\n\ntest_input = { \"n\": 6, \"x\": 5, \"y\": 6 }\nassert my_solution.countOfPairs(**test_input) == [10,8,6,4,2,0]\n\ntest_input = { \"n\": 6, \"x\": 6, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [12,12,6,0,0,0]\n\ntest_input = { \"n\": 6, \"x\": 6, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [12,14,4,0,0,0]\n\ntest_input = { \"n\": 6, \"x\": 6, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [12,10,6,2,0,0]\n\ntest_input = { \"n\": 6, \"x\": 6, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [12,8,6,4,0,0]\n\ntest_input = { \"n\": 6, \"x\": 6, \"y\": 5 }\nassert my_solution.countOfPairs(**test_input) == [10,8,6,4,2,0]\n\ntest_input = { \"n\": 6, \"x\": 6, \"y\": 6 }\nassert my_solution.countOfPairs(**test_input) == [10,8,6,4,2,0]\n\ntest_input = { \"n\": 7, \"x\": 1, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [12,10,8,6,4,2,0]\n\ntest_input = { \"n\": 7, \"x\": 1, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [14,10,8,6,4,0,0]\n\ntest_input = { \"n\": 7, \"x\": 1, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [14,12,8,6,2,0,0]\n\ntest_input = { \"n\": 7, \"x\": 1, \"y\": 5 }\nassert my_solution.countOfPairs(**test_input) == [14,16,8,4,0,0,0]\n\ntest_input = { \"n\": 7, \"x\": 1, \"y\": 6 }\nassert my_solution.countOfPairs(**test_input) == [14,16,10,2,0,0,0]\n\ntest_input = { \"n\": 7, \"x\": 1, \"y\": 7 }\nassert my_solution.countOfPairs(**test_input) == [14,14,14,0,0,0,0]\n\ntest_input = { \"n\": 7, \"x\": 2, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [12,10,8,6,4,2,0]\n\ntest_input = { \"n\": 7, \"x\": 2, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [12,10,8,6,4,2,0]\n\ntest_input = { \"n\": 7, \"x\": 2, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [12,10,8,6,4,2,0]\n\ntest_input = { \"n\": 7, \"x\": 2, \"y\": 7 }\nassert my_solution.countOfPairs(**test_input) == [14,16,10,2,0,0,0]\n\ntest_input = { \"n\": 7, \"x\": 3, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [14,10,8,6,4,0,0]\n\ntest_input = { \"n\": 7, \"x\": 3, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [12,10,8,6,4,2,0]\n\ntest_input = { \"n\": 7, \"x\": 3, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [12,10,8,6,4,2,0]", "start_time": 1705804200} +{"task_id": "weekly-contest-381-minimum-number-of-pushes-to-type-word-ii", "url": "https://leetcode.com/problems/minimum-number-of-pushes-to-type-word-ii", "title": "minimum-number-of-pushes-to-type-word-ii", "meta": {"questionId": "3276", "questionFrontendId": "3016", "title": "Minimum Number of Pushes to Type Word II", "titleSlug": "minimum-number-of-pushes-to-type-word-ii", "isPaidOnly": false, "difficulty": "Medium", "likes": 59, "dislikes": 2, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a string word containing lowercase English letters.\nTelephone keypads have keys mapped with distinct collections of lowercase English letters, which can be used to form words by pushing them. For example, the key 2 is mapped with [\"a\",\"b\",\"c\"], we need to push the key one time to type \"a\", two times to type \"b\", and three times to type \"c\" .\nIt is allowed to remap the keys numbered 2 to 9 to distinct collections of letters. The keys can be remapped to any amount of letters, but each letter must be mapped to exactly one key. You need to find the minimum number of times the keys will be pushed to type the string word.\nReturn the minimum number of pushes needed to type word after remapping the keys.\nAn example mapping of letters to keys on a telephone keypad is given below. Note that 1, *, #, and 0 do not map to any letters.\n\n\nExample 1:\n\n\nInput: word = \"abcde\"\nOutput: 5\nExplanation: The remapped keypad given in the image provides the minimum cost.\n\"a\" -> one push on key 2\n\"b\" -> one push on key 3\n\"c\" -> one push on key 4\n\"d\" -> one push on key 5\n\"e\" -> one push on key 6\nTotal cost is 1 + 1 + 1 + 1 + 1 = 5.\nIt can be shown that no other mapping can provide a lower cost.\n\nExample 2:\n\n\nInput: word = \"xyzxyzxyzxyz\"\nOutput: 12\nExplanation: The remapped keypad given in the image provides the minimum cost.\n\"x\" -> one push on key 2\n\"y\" -> one push on key 3\n\"z\" -> one push on key 4\nTotal cost is 1 * 4 + 1 * 4 + 1 * 4 = 12\nIt can be shown that no other mapping can provide a lower cost.\nNote that the key 9 is not mapped to any letter: it is not necessary to map letters to every key, but to map all the letters.\n\nExample 3:\n\n\nInput: word = \"aabbccddeeffgghhiiiiii\"\nOutput: 24\nExplanation: The remapped keypad given in the image provides the minimum cost.\n\"a\" -> one push on key 2\n\"b\" -> one push on key 3\n\"c\" -> one push on key 4\n\"d\" -> one push on key 5\n\"e\" -> one push on key 6\n\"f\" -> one push on key 7\n\"g\" -> one push on key 8\n\"h\" -> two pushes on key 9\n\"i\" -> one push on key 9\nTotal cost is 1 * 2 + 1 * 2 + 1 * 2 + 1 * 2 + 1 * 2 + 1 * 2 + 1 * 2 + 2 * 2 + 6 * 1 = 24.\nIt can be shown that no other mapping can provide a lower cost.\n\n\nConstraints:\n\n1 <= word.length <= 105\nword consists of lowercase English letters.\n\"\"\"\nclass Solution:\n def minimumPushes(self, word: str) -> int:\n ", "prompt_sft": "You are given a string word containing lowercase English letters.\nTelephone keypads have keys mapped with distinct collections of lowercase English letters, which can be used to form words by pushing them. For example, the key 2 is mapped with [\"a\",\"b\",\"c\"], we need to push the key one time to type \"a\", two times to type \"b\", and three times to type \"c\" .\nIt is allowed to remap the keys numbered 2 to 9 to distinct collections of letters. The keys can be remapped to any amount of letters, but each letter must be mapped to exactly one key. You need to find the minimum number of times the keys will be pushed to type the string word.\nReturn the minimum number of pushes needed to type word after remapping the keys.\nAn example mapping of letters to keys on a telephone keypad is given below. Note that 1, *, #, and 0 do not map to any letters.\n\n\nExample 1:\n\n\nInput: word = \"abcde\"\nOutput: 5\nExplanation: The remapped keypad given in the image provides the minimum cost.\n\"a\" -> one push on key 2\n\"b\" -> one push on key 3\n\"c\" -> one push on key 4\n\"d\" -> one push on key 5\n\"e\" -> one push on key 6\nTotal cost is 1 + 1 + 1 + 1 + 1 = 5.\nIt can be shown that no other mapping can provide a lower cost.\n\nExample 2:\n\n\nInput: word = \"xyzxyzxyzxyz\"\nOutput: 12\nExplanation: The remapped keypad given in the image provides the minimum cost.\n\"x\" -> one push on key 2\n\"y\" -> one push on key 3\n\"z\" -> one push on key 4\nTotal cost is 1 * 4 + 1 * 4 + 1 * 4 = 12\nIt can be shown that no other mapping can provide a lower cost.\nNote that the key 9 is not mapped to any letter: it is not necessary to map letters to every key, but to map all the letters.\n\nExample 3:\n\n\nInput: word = \"aabbccddeeffgghhiiiiii\"\nOutput: 24\nExplanation: The remapped keypad given in the image provides the minimum cost.\n\"a\" -> one push on key 2\n\"b\" -> one push on key 3\n\"c\" -> one push on key 4\n\"d\" -> one push on key 5\n\"e\" -> one push on key 6\n\"f\" -> one push on key 7\n\"g\" -> one push on key 8\n\"h\" -> two pushes on key 9\n\"i\" -> one push on key 9\nTotal cost is 1 * 2 + 1 * 2 + 1 * 2 + 1 * 2 + 1 * 2 + 1 * 2 + 1 * 2 + 2 * 2 + 6 * 1 = 24.\nIt can be shown that no other mapping can provide a lower cost.\n\n\nConstraints:\n\n1 <= word.length <= 105\nword consists of lowercase English letters.\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def minimumPushes(self, word: str) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"word\": \"abcde\" }\nassert my_solution.minimumPushes(**test_input) == 5\n\ntest_input = { \"word\": \"xyzxyzxyzxyz\" }\nassert my_solution.minimumPushes(**test_input) == 12\n\ntest_input = { \"word\": \"aabbccddeeffgghhiiiiii\" }\nassert my_solution.minimumPushes(**test_input) == 24\n\ntest_input = { \"word\": \"a\" }\nassert my_solution.minimumPushes(**test_input) == 1\n\ntest_input = { \"word\": \"f\" }\nassert my_solution.minimumPushes(**test_input) == 1\n\ntest_input = { \"word\": \"h\" }\nassert my_solution.minimumPushes(**test_input) == 1\n\ntest_input = { \"word\": \"i\" }\nassert my_solution.minimumPushes(**test_input) == 1\n\ntest_input = { \"word\": \"l\" }\nassert my_solution.minimumPushes(**test_input) == 1\n\ntest_input = { \"word\": \"o\" }\nassert my_solution.minimumPushes(**test_input) == 1\n\ntest_input = { \"word\": \"q\" }\nassert my_solution.minimumPushes(**test_input) == 1\n\ntest_input = { \"word\": \"s\" }\nassert my_solution.minimumPushes(**test_input) == 1\n\ntest_input = { \"word\": \"t\" }\nassert my_solution.minimumPushes(**test_input) == 1\n\ntest_input = { \"word\": \"u\" }\nassert my_solution.minimumPushes(**test_input) == 1\n\ntest_input = { \"word\": \"x\" }\nassert my_solution.minimumPushes(**test_input) == 1\n\ntest_input = { \"word\": \"y\" }\nassert my_solution.minimumPushes(**test_input) == 1\n\ntest_input = { \"word\": \"z\" }\nassert my_solution.minimumPushes(**test_input) == 1\n\ntest_input = { \"word\": \"at\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"aw\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"bd\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"bs\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"ck\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"de\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"ex\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"fy\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"fz\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"hu\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"ir\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"iz\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"km\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"lr\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"lu\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"mz\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"ng\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"nu\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"oo\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"qc\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"rv\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"se\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"up\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"wb\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"xg\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"yg\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"zv\" }\nassert my_solution.minimumPushes(**test_input) == 2\n\ntest_input = { \"word\": \"abx\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"amw\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"bem\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"bhs\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"blg\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"bwq\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"cku\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"cmo\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"cnr\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"dgh\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"dmh\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"dqf\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"eys\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"fff\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"foz\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"fqw\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"fsh\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"gjz\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"gpx\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"gqu\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"jcc\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"nmu\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"pzm\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"rdz\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"rvy\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"rya\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"sbn\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"szd\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"tbd\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"uqk\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"vbh\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"vgr\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"vxy\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"xbp\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"yex\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"ynx\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"yuv\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"zih\" }\nassert my_solution.minimumPushes(**test_input) == 3\n\ntest_input = { \"word\": \"acpy\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"ainw\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"aluw\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"ayfb\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"bbmr\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"bgta\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"bitn\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"bwif\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"bwrz\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"cdcl\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"dglo\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"dxng\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"earx\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"feig\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"fgjk\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"flmd\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"fnfp\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"glms\" }\nassert my_solution.minimumPushes(**test_input) == 4\n\ntest_input = { \"word\": \"glou\" }\nassert my_solution.minimumPushes(**test_input) == 4", "start_time": 1705804200} +{"task_id": "weekly-contest-381-count-the-number-of-houses-at-a-certain-distance-ii", "url": "https://leetcode.com/problems/count-the-number-of-houses-at-a-certain-distance-ii", "title": "count-the-number-of-houses-at-a-certain-distance-ii", "meta": {"questionId": "3310", "questionFrontendId": "3017", "title": "Count the Number of Houses at a Certain Distance II", "titleSlug": "count-the-number-of-houses-at-a-certain-distance-ii", "isPaidOnly": false, "difficulty": "Hard", "likes": 27, "dislikes": 12, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given three positive integers n, x, and y.\nIn a city, there exist houses numbered 1 to n connected by n streets. There is a street connecting the house numbered i with the house numbered i + 1 for all 1 <= i <= n - 1 . An additional street connects the house numbered x with the house numbered y.\nFor each k, such that 1 <= k <= n, you need to find the number of pairs of houses (house1, house2) such that the minimum number of streets that need to be traveled to reach house2 from house1 is k.\nReturn a 1-indexed array result of length n where result[k] represents the total number of pairs of houses such that the minimum streets required to reach one house from the other is k.\nNote that x and y can be equal.\n\nExample 1:\n\n\nInput: n = 3, x = 1, y = 3\nOutput: [6,0,0]\nExplanation: Let's look at each pair of houses:\n- For the pair (1, 2), we can go from house 1 to house 2 directly.\n- For the pair (2, 1), we can go from house 2 to house 1 directly.\n- For the pair (1, 3), we can go from house 1 to house 3 directly.\n- For the pair (3, 1), we can go from house 3 to house 1 directly.\n- For the pair (2, 3), we can go from house 2 to house 3 directly.\n- For the pair (3, 2), we can go from house 3 to house 2 directly.\n\nExample 2:\n\n\nInput: n = 5, x = 2, y = 4\nOutput: [10,8,2,0,0]\nExplanation: For each distance k the pairs are:\n- For k == 1, the pairs are (1, 2), (2, 1), (2, 3), (3, 2), (2, 4), (4, 2), (3, 4), (4, 3), (4, 5), and (5, 4).\n- For k == 2, the pairs are (1, 3), (3, 1), (1, 4), (4, 1), (2, 5), (5, 2), (3, 5), and (5, 3).\n- For k == 3, the pairs are (1, 5), and (5, 1).\n- For k == 4 and k == 5, there are no pairs.\n\nExample 3:\n\n\nInput: n = 4, x = 1, y = 1\nOutput: [6,4,2,0]\nExplanation: For each distance k the pairs are:\n- For k == 1, the pairs are (1, 2), (2, 1), (2, 3), (3, 2), (3, 4), and (4, 3).\n- For k == 2, the pairs are (1, 3), (3, 1), (2, 4), and (4, 2).\n- For k == 3, the pairs are (1, 4), and (4, 1).\n- For k == 4, there are no pairs.\n\n\nConstraints:\n\n2 <= n <= 105\n1 <= x, y <= n\n\"\"\"\nclass Solution:\n def countOfPairs(self, n: int, x: int, y: int) -> List[int]:\n ", "prompt_sft": "You are given three positive integers n, x, and y.\nIn a city, there exist houses numbered 1 to n connected by n streets. There is a street connecting the house numbered i with the house numbered i + 1 for all 1 <= i <= n - 1 . An additional street connects the house numbered x with the house numbered y.\nFor each k, such that 1 <= k <= n, you need to find the number of pairs of houses (house1, house2) such that the minimum number of streets that need to be traveled to reach house2 from house1 is k.\nReturn a 1-indexed array result of length n where result[k] represents the total number of pairs of houses such that the minimum streets required to reach one house from the other is k.\nNote that x and y can be equal.\n\nExample 1:\n\n\nInput: n = 3, x = 1, y = 3\nOutput: [6,0,0]\nExplanation: Let's look at each pair of houses:\n- For the pair (1, 2), we can go from house 1 to house 2 directly.\n- For the pair (2, 1), we can go from house 2 to house 1 directly.\n- For the pair (1, 3), we can go from house 1 to house 3 directly.\n- For the pair (3, 1), we can go from house 3 to house 1 directly.\n- For the pair (2, 3), we can go from house 2 to house 3 directly.\n- For the pair (3, 2), we can go from house 3 to house 2 directly.\n\nExample 2:\n\n\nInput: n = 5, x = 2, y = 4\nOutput: [10,8,2,0,0]\nExplanation: For each distance k the pairs are:\n- For k == 1, the pairs are (1, 2), (2, 1), (2, 3), (3, 2), (2, 4), (4, 2), (3, 4), (4, 3), (4, 5), and (5, 4).\n- For k == 2, the pairs are (1, 3), (3, 1), (1, 4), (4, 1), (2, 5), (5, 2), (3, 5), and (5, 3).\n- For k == 3, the pairs are (1, 5), and (5, 1).\n- For k == 4 and k == 5, there are no pairs.\n\nExample 3:\n\n\nInput: n = 4, x = 1, y = 1\nOutput: [6,4,2,0]\nExplanation: For each distance k the pairs are:\n- For k == 1, the pairs are (1, 2), (2, 1), (2, 3), (3, 2), (3, 4), and (4, 3).\n- For k == 2, the pairs are (1, 3), (3, 1), (2, 4), and (4, 2).\n- For k == 3, the pairs are (1, 4), and (4, 1).\n- For k == 4, there are no pairs.\n\n\nConstraints:\n\n2 <= n <= 105\n1 <= x, y <= n\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def countOfPairs(self, n: int, x: int, y: int) -> List[int]:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"n\": 3, \"x\": 1, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [6,0,0]\n\ntest_input = { \"n\": 5, \"x\": 2, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [10,8,2,0,0]\n\ntest_input = { \"n\": 4, \"x\": 1, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [6,4,2,0]\n\ntest_input = { \"n\": 2, \"x\": 1, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [2,0]\n\ntest_input = { \"n\": 2, \"x\": 1, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [2,0]\n\ntest_input = { \"n\": 2, \"x\": 2, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [2,0]\n\ntest_input = { \"n\": 2, \"x\": 2, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [2,0]\n\ntest_input = { \"n\": 3, \"x\": 1, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [4,2,0]\n\ntest_input = { \"n\": 3, \"x\": 1, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [4,2,0]\n\ntest_input = { \"n\": 3, \"x\": 2, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [4,2,0]\n\ntest_input = { \"n\": 3, \"x\": 2, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [4,2,0]\n\ntest_input = { \"n\": 3, \"x\": 2, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [4,2,0]\n\ntest_input = { \"n\": 3, \"x\": 3, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [6,0,0]\n\ntest_input = { \"n\": 3, \"x\": 3, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [4,2,0]\n\ntest_input = { \"n\": 3, \"x\": 3, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [4,2,0]\n\ntest_input = { \"n\": 4, \"x\": 1, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [6,4,2,0]\n\ntest_input = { \"n\": 4, \"x\": 1, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [8,4,0,0]\n\ntest_input = { \"n\": 4, \"x\": 1, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [8,4,0,0]\n\ntest_input = { \"n\": 4, \"x\": 2, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [6,4,2,0]\n\ntest_input = { \"n\": 4, \"x\": 2, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [6,4,2,0]\n\ntest_input = { \"n\": 4, \"x\": 2, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [6,4,2,0]\n\ntest_input = { \"n\": 4, \"x\": 2, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [8,4,0,0]\n\ntest_input = { \"n\": 4, \"x\": 3, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [8,4,0,0]\n\ntest_input = { \"n\": 4, \"x\": 3, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [6,4,2,0]\n\ntest_input = { \"n\": 4, \"x\": 3, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [6,4,2,0]\n\ntest_input = { \"n\": 4, \"x\": 3, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [6,4,2,0]\n\ntest_input = { \"n\": 4, \"x\": 4, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [8,4,0,0]\n\ntest_input = { \"n\": 4, \"x\": 4, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [8,4,0,0]\n\ntest_input = { \"n\": 4, \"x\": 4, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [6,4,2,0]\n\ntest_input = { \"n\": 4, \"x\": 4, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [6,4,2,0]\n\ntest_input = { \"n\": 5, \"x\": 1, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [8,6,4,2,0]\n\ntest_input = { \"n\": 5, \"x\": 1, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [10,6,4,0,0]\n\ntest_input = { \"n\": 5, \"x\": 2, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [8,6,4,2,0]\n\ntest_input = { \"n\": 5, \"x\": 2, \"y\": 5 }\nassert my_solution.countOfPairs(**test_input) == [10,8,2,0,0]\n\ntest_input = { \"n\": 5, \"x\": 3, \"y\": 5 }\nassert my_solution.countOfPairs(**test_input) == [10,6,4,0,0]\n\ntest_input = { \"n\": 5, \"x\": 4, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [10,8,2,0,0]\n\ntest_input = { \"n\": 5, \"x\": 4, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [8,6,4,2,0]\n\ntest_input = { \"n\": 5, \"x\": 5, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [10,6,4,0,0]\n\ntest_input = { \"n\": 5, \"x\": 5, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [8,6,4,2,0]\n\ntest_input = { \"n\": 5, \"x\": 5, \"y\": 5 }\nassert my_solution.countOfPairs(**test_input) == [8,6,4,2,0]\n\ntest_input = { \"n\": 6, \"x\": 1, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [12,10,6,2,0,0]\n\ntest_input = { \"n\": 6, \"x\": 1, \"y\": 5 }\nassert my_solution.countOfPairs(**test_input) == [12,14,4,0,0,0]\n\ntest_input = { \"n\": 6, \"x\": 1, \"y\": 6 }\nassert my_solution.countOfPairs(**test_input) == [12,12,6,0,0,0]\n\ntest_input = { \"n\": 6, \"x\": 3, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [10,8,6,4,2,0]\n\ntest_input = { \"n\": 6, \"x\": 3, \"y\": 5 }\nassert my_solution.countOfPairs(**test_input) == [12,10,6,2,0,0]\n\ntest_input = { \"n\": 6, \"x\": 4, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [10,8,6,4,2,0]\n\ntest_input = { \"n\": 6, \"x\": 4, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [10,8,6,4,2,0]\n\ntest_input = { \"n\": 6, \"x\": 4, \"y\": 5 }\nassert my_solution.countOfPairs(**test_input) == [10,8,6,4,2,0]\n\ntest_input = { \"n\": 6, \"x\": 4, \"y\": 6 }\nassert my_solution.countOfPairs(**test_input) == [12,8,6,4,0,0]\n\ntest_input = { \"n\": 6, \"x\": 5, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [12,12,6,0,0,0]\n\ntest_input = { \"n\": 6, \"x\": 5, \"y\": 5 }\nassert my_solution.countOfPairs(**test_input) == [10,8,6,4,2,0]\n\ntest_input = { \"n\": 6, \"x\": 6, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [12,14,4,0,0,0]\n\ntest_input = { \"n\": 6, \"x\": 6, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [12,8,6,4,0,0]\n\ntest_input = { \"n\": 6, \"x\": 6, \"y\": 5 }\nassert my_solution.countOfPairs(**test_input) == [10,8,6,4,2,0]\n\ntest_input = { \"n\": 6, \"x\": 6, \"y\": 6 }\nassert my_solution.countOfPairs(**test_input) == [10,8,6,4,2,0]\n\ntest_input = { \"n\": 7, \"x\": 1, \"y\": 7 }\nassert my_solution.countOfPairs(**test_input) == [14,14,14,0,0,0,0]\n\ntest_input = { \"n\": 7, \"x\": 2, \"y\": 6 }\nassert my_solution.countOfPairs(**test_input) == [14,18,10,0,0,0,0]\n\ntest_input = { \"n\": 7, \"x\": 3, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [12,10,8,6,4,2,0]\n\ntest_input = { \"n\": 7, \"x\": 3, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [12,10,8,6,4,2,0]\n\ntest_input = { \"n\": 7, \"x\": 3, \"y\": 6 }\nassert my_solution.countOfPairs(**test_input) == [14,14,10,4,0,0,0]\n\ntest_input = { \"n\": 7, \"x\": 4, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [12,10,8,6,4,2,0]\n\ntest_input = { \"n\": 7, \"x\": 4, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [12,10,8,6,4,2,0]\n\ntest_input = { \"n\": 7, \"x\": 4, \"y\": 7 }\nassert my_solution.countOfPairs(**test_input) == [14,12,8,6,2,0,0]\n\ntest_input = { \"n\": 7, \"x\": 5, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [14,12,10,4,2,0,0]\n\ntest_input = { \"n\": 7, \"x\": 5, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [12,10,8,6,4,2,0]\n\ntest_input = { \"n\": 7, \"x\": 5, \"y\": 7 }\nassert my_solution.countOfPairs(**test_input) == [14,10,8,6,4,0,0]\n\ntest_input = { \"n\": 7, \"x\": 6, \"y\": 6 }\nassert my_solution.countOfPairs(**test_input) == [12,10,8,6,4,2,0]\n\ntest_input = { \"n\": 7, \"x\": 6, \"y\": 7 }\nassert my_solution.countOfPairs(**test_input) == [12,10,8,6,4,2,0]\n\ntest_input = { \"n\": 7, \"x\": 7, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [14,12,8,6,2,0,0]\n\ntest_input = { \"n\": 8, \"x\": 1, \"y\": 2 }\nassert my_solution.countOfPairs(**test_input) == [14,12,10,8,6,4,2,0]\n\ntest_input = { \"n\": 8, \"x\": 2, \"y\": 7 }\nassert my_solution.countOfPairs(**test_input) == [16,20,16,4,0,0,0,0]\n\ntest_input = { \"n\": 8, \"x\": 3, \"y\": 5 }\nassert my_solution.countOfPairs(**test_input) == [16,14,12,8,4,2,0,0]\n\ntest_input = { \"n\": 8, \"x\": 3, \"y\": 6 }\nassert my_solution.countOfPairs(**test_input) == [16,16,14,8,2,0,0,0]\n\ntest_input = { \"n\": 8, \"x\": 4, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [14,12,10,8,6,4,2,0]\n\ntest_input = { \"n\": 8, \"x\": 4, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [14,12,10,8,6,4,2,0]\n\ntest_input = { \"n\": 8, \"x\": 4, \"y\": 8 }\nassert my_solution.countOfPairs(**test_input) == [16,18,10,8,4,0,0,0]\n\ntest_input = { \"n\": 8, \"x\": 5, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [16,14,12,8,4,2,0,0]\n\ntest_input = { \"n\": 8, \"x\": 5, \"y\": 7 }\nassert my_solution.countOfPairs(**test_input) == [16,14,10,8,6,2,0,0]\n\ntest_input = { \"n\": 8, \"x\": 6, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [16,16,14,8,2,0,0,0]\n\ntest_input = { \"n\": 8, \"x\": 6, \"y\": 7 }\nassert my_solution.countOfPairs(**test_input) == [14,12,10,8,6,4,2,0]\n\ntest_input = { \"n\": 8, \"x\": 6, \"y\": 8 }\nassert my_solution.countOfPairs(**test_input) == [16,12,10,8,6,4,0,0]\n\ntest_input = { \"n\": 8, \"x\": 7, \"y\": 8 }\nassert my_solution.countOfPairs(**test_input) == [14,12,10,8,6,4,2,0]\n\ntest_input = { \"n\": 8, \"x\": 8, \"y\": 1 }\nassert my_solution.countOfPairs(**test_input) == [16,16,16,8,0,0,0,0]\n\ntest_input = { \"n\": 8, \"x\": 8, \"y\": 7 }\nassert my_solution.countOfPairs(**test_input) == [14,12,10,8,6,4,2,0]\n\ntest_input = { \"n\": 8, \"x\": 8, \"y\": 8 }\nassert my_solution.countOfPairs(**test_input) == [14,12,10,8,6,4,2,0]\n\ntest_input = { \"n\": 9, \"x\": 1, \"y\": 3 }\nassert my_solution.countOfPairs(**test_input) == [18,14,12,10,8,6,4,0,0]\n\ntest_input = { \"n\": 9, \"x\": 4, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [16,14,12,10,8,6,4,2,0]\n\ntest_input = { \"n\": 9, \"x\": 4, \"y\": 6 }\nassert my_solution.countOfPairs(**test_input) == [18,16,14,12,6,4,2,0,0]\n\ntest_input = { \"n\": 9, \"x\": 4, \"y\": 9 }\nassert my_solution.countOfPairs(**test_input) == [18,20,16,10,6,2,0,0,0]\n\ntest_input = { \"n\": 9, \"x\": 5, \"y\": 5 }\nassert my_solution.countOfPairs(**test_input) == [16,14,12,10,8,6,4,2,0]\n\ntest_input = { \"n\": 9, \"x\": 5, \"y\": 9 }\nassert my_solution.countOfPairs(**test_input) == [18,20,12,10,8,4,0,0,0]\n\ntest_input = { \"n\": 9, \"x\": 6, \"y\": 7 }\nassert my_solution.countOfPairs(**test_input) == [16,14,12,10,8,6,4,2,0]\n\ntest_input = { \"n\": 9, \"x\": 7, \"y\": 7 }\nassert my_solution.countOfPairs(**test_input) == [16,14,12,10,8,6,4,2,0]\n\ntest_input = { \"n\": 9, \"x\": 8, \"y\": 4 }\nassert my_solution.countOfPairs(**test_input) == [18,22,16,10,6,0,0,0,0]\n\ntest_input = { \"n\": 9, \"x\": 8, \"y\": 6 }\nassert my_solution.countOfPairs(**test_input) == [18,16,12,10,8,6,2,0,0]\n\ntest_input = { \"n\": 9, \"x\": 8, \"y\": 7 }\nassert my_solution.countOfPairs(**test_input) == [16,14,12,10,8,6,4,2,0]\n\ntest_input = { \"n\": 9, \"x\": 8, \"y\": 9 }\nassert my_solution.countOfPairs(**test_input) == [16,14,12,10,8,6,4,2,0]\n\ntest_input = { \"n\": 9, \"x\": 9, \"y\": 5 }\nassert my_solution.countOfPairs(**test_input) == [18,20,12,10,8,4,0,0,0]\n\ntest_input = { \"n\": 9, \"x\": 9, \"y\": 7 }\nassert my_solution.countOfPairs(**test_input) == [18,14,12,10,8,6,4,0,0]\n\ntest_input = { \"n\": 9, \"x\": 9, \"y\": 8 }\nassert my_solution.countOfPairs(**test_input) == [16,14,12,10,8,6,4,2,0]", "start_time": 1705804200} +{"task_id": "biweekly-contest-122-divide-an-array-into-subarrays-with-minimum-cost-i", "url": "https://leetcode.com/problems/divide-an-array-into-subarrays-with-minimum-cost-i", "title": "divide-an-array-into-subarrays-with-minimum-cost-i", "meta": {"questionId": "3263", "questionFrontendId": "3010", "title": "Divide an Array Into Subarrays With Minimum Cost I", "titleSlug": "divide-an-array-into-subarrays-with-minimum-cost-i", "isPaidOnly": false, "difficulty": "Easy", "likes": 40, "dislikes": 2, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given an array of integers nums of length n.\nThe cost of an array is the value of its first element. For example, the cost of [1,2,3] is 1 while the cost of [3,4,1] is 3.\nYou need to divide nums into 3 disjoint contiguous subarrays.\nReturn the minimum possible sum of the cost of these subarrays.\n\nExample 1:\n\nInput: nums = [1,2,3,12]\nOutput: 6\nExplanation: The best possible way to form 3 subarrays is: [1], [2], and [3,12] at a total cost of 1 + 2 + 3 = 6.\nThe other possible ways to form 3 subarrays are:\n- [1], [2,3], and [12] at a total cost of 1 + 2 + 12 = 15.\n- [1,2], [3], and [12] at a total cost of 1 + 3 + 12 = 16.\n\nExample 2:\n\nInput: nums = [5,4,3]\nOutput: 12\nExplanation: The best possible way to form 3 subarrays is: [5], [4], and [3] at a total cost of 5 + 4 + 3 = 12.\nIt can be shown that 12 is the minimum cost achievable.\n\nExample 3:\n\nInput: nums = [10,3,1,1]\nOutput: 12\nExplanation: The best possible way to form 3 subarrays is: [10,3], [1], and [1] at a total cost of 10 + 1 + 1 = 12.\nIt can be shown that 12 is the minimum cost achievable.\n\n\nConstraints:\n\n3 <= n <= 50\n1 <= nums[i] <= 50\n\"\"\"\nclass Solution:\n def minimumCost(self, nums: List[int]) -> int:\n ", "prompt_sft": "You are given an array of integers nums of length n.\nThe cost of an array is the value of its first element. For example, the cost of [1,2,3] is 1 while the cost of [3,4,1] is 3.\nYou need to divide nums into 3 disjoint contiguous subarrays.\nReturn the minimum possible sum of the cost of these subarrays.\n\nExample 1:\n\nInput: nums = [1,2,3,12]\nOutput: 6\nExplanation: The best possible way to form 3 subarrays is: [1], [2], and [3,12] at a total cost of 1 + 2 + 3 = 6.\nThe other possible ways to form 3 subarrays are:\n- [1], [2,3], and [12] at a total cost of 1 + 2 + 12 = 15.\n- [1,2], [3], and [12] at a total cost of 1 + 3 + 12 = 16.\n\nExample 2:\n\nInput: nums = [5,4,3]\nOutput: 12\nExplanation: The best possible way to form 3 subarrays is: [5], [4], and [3] at a total cost of 5 + 4 + 3 = 12.\nIt can be shown that 12 is the minimum cost achievable.\n\nExample 3:\n\nInput: nums = [10,3,1,1]\nOutput: 12\nExplanation: The best possible way to form 3 subarrays is: [10,3], [1], and [1] at a total cost of 10 + 1 + 1 = 12.\nIt can be shown that 12 is the minimum cost achievable.\n\n\nConstraints:\n\n3 <= n <= 50\n1 <= nums[i] <= 50\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def minimumCost(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,2,3,12] }\nassert my_solution.minimumCost(**test_input) == 6\n\ntest_input = { \"nums\": [5,4,3] }\nassert my_solution.minimumCost(**test_input) == 12\n\ntest_input = { \"nums\": [10,3,1,1] }\nassert my_solution.minimumCost(**test_input) == 12\n\ntest_input = { \"nums\": [1,1,1] }\nassert my_solution.minimumCost(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,2] }\nassert my_solution.minimumCost(**test_input) == 4\n\ntest_input = { \"nums\": [1,1,3] }\nassert my_solution.minimumCost(**test_input) == 5\n\ntest_input = { \"nums\": [1,1,4] }\nassert my_solution.minimumCost(**test_input) == 6\n\ntest_input = { \"nums\": [1,1,5] }\nassert my_solution.minimumCost(**test_input) == 7\n\ntest_input = { \"nums\": [1,2,1] }\nassert my_solution.minimumCost(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,2] }\nassert my_solution.minimumCost(**test_input) == 5\n\ntest_input = { \"nums\": [1,2,3] }\nassert my_solution.minimumCost(**test_input) == 6\n\ntest_input = { \"nums\": [1,2,4] }\nassert my_solution.minimumCost(**test_input) == 7\n\ntest_input = { \"nums\": [1,2,5] }\nassert my_solution.minimumCost(**test_input) == 8\n\ntest_input = { \"nums\": [1,3,1] }\nassert my_solution.minimumCost(**test_input) == 5\n\ntest_input = { \"nums\": [1,3,2] }\nassert my_solution.minimumCost(**test_input) == 6\n\ntest_input = { \"nums\": [1,3,3] }\nassert my_solution.minimumCost(**test_input) == 7\n\ntest_input = { \"nums\": [1,3,4] }\nassert my_solution.minimumCost(**test_input) == 8\n\ntest_input = { \"nums\": [1,3,5] }\nassert my_solution.minimumCost(**test_input) == 9\n\ntest_input = { \"nums\": [1,4,1] }\nassert my_solution.minimumCost(**test_input) == 6\n\ntest_input = { \"nums\": [1,4,2] }\nassert my_solution.minimumCost(**test_input) == 7\n\ntest_input = { \"nums\": [1,4,3] }\nassert my_solution.minimumCost(**test_input) == 8\n\ntest_input = { \"nums\": [1,4,4] }\nassert my_solution.minimumCost(**test_input) == 9\n\ntest_input = { \"nums\": [1,4,5] }\nassert my_solution.minimumCost(**test_input) == 10\n\ntest_input = { \"nums\": [1,5,1] }\nassert my_solution.minimumCost(**test_input) == 7\n\ntest_input = { \"nums\": [1,5,2] }\nassert my_solution.minimumCost(**test_input) == 8\n\ntest_input = { \"nums\": [1,5,3] }\nassert my_solution.minimumCost(**test_input) == 9\n\ntest_input = { \"nums\": [1,5,4] }\nassert my_solution.minimumCost(**test_input) == 10\n\ntest_input = { \"nums\": [1,5,5] }\nassert my_solution.minimumCost(**test_input) == 11\n\ntest_input = { \"nums\": [2,1,1] }\nassert my_solution.minimumCost(**test_input) == 4\n\ntest_input = { \"nums\": [2,1,2] }\nassert my_solution.minimumCost(**test_input) == 5\n\ntest_input = { \"nums\": [2,1,3] }\nassert my_solution.minimumCost(**test_input) == 6\n\ntest_input = { \"nums\": [2,1,4] }\nassert my_solution.minimumCost(**test_input) == 7\n\ntest_input = { \"nums\": [2,1,5] }\nassert my_solution.minimumCost(**test_input) == 8\n\ntest_input = { \"nums\": [2,2,1] }\nassert my_solution.minimumCost(**test_input) == 5\n\ntest_input = { \"nums\": [2,2,2] }\nassert my_solution.minimumCost(**test_input) == 6\n\ntest_input = { \"nums\": [2,2,3] }\nassert my_solution.minimumCost(**test_input) == 7\n\ntest_input = { \"nums\": [2,2,4] }\nassert my_solution.minimumCost(**test_input) == 8\n\ntest_input = { \"nums\": [2,2,5] }\nassert my_solution.minimumCost(**test_input) == 9\n\ntest_input = { \"nums\": [2,3,1] }\nassert my_solution.minimumCost(**test_input) == 6\n\ntest_input = { \"nums\": [2,3,2] }\nassert my_solution.minimumCost(**test_input) == 7\n\ntest_input = { \"nums\": [2,3,3] }\nassert my_solution.minimumCost(**test_input) == 8\n\ntest_input = { \"nums\": [2,3,4] }\nassert my_solution.minimumCost(**test_input) == 9\n\ntest_input = { \"nums\": [2,3,5] }\nassert my_solution.minimumCost(**test_input) == 10\n\ntest_input = { \"nums\": [2,4,1] }\nassert my_solution.minimumCost(**test_input) == 7\n\ntest_input = { \"nums\": [2,4,2] }\nassert my_solution.minimumCost(**test_input) == 8\n\ntest_input = { \"nums\": [2,4,3] }\nassert my_solution.minimumCost(**test_input) == 9\n\ntest_input = { \"nums\": [2,4,4] }\nassert my_solution.minimumCost(**test_input) == 10\n\ntest_input = { \"nums\": [2,4,5] }\nassert my_solution.minimumCost(**test_input) == 11\n\ntest_input = { \"nums\": [2,5,1] }\nassert my_solution.minimumCost(**test_input) == 8\n\ntest_input = { \"nums\": [2,5,2] }\nassert my_solution.minimumCost(**test_input) == 9\n\ntest_input = { \"nums\": [2,5,3] }\nassert my_solution.minimumCost(**test_input) == 10\n\ntest_input = { \"nums\": [2,5,4] }\nassert my_solution.minimumCost(**test_input) == 11\n\ntest_input = { \"nums\": [2,5,5] }\nassert my_solution.minimumCost(**test_input) == 12\n\ntest_input = { \"nums\": [3,1,1] }\nassert my_solution.minimumCost(**test_input) == 5\n\ntest_input = { \"nums\": [3,1,2] }\nassert my_solution.minimumCost(**test_input) == 6\n\ntest_input = { \"nums\": [3,1,3] }\nassert my_solution.minimumCost(**test_input) == 7\n\ntest_input = { \"nums\": [3,1,4] }\nassert my_solution.minimumCost(**test_input) == 8\n\ntest_input = { \"nums\": [3,1,5] }\nassert my_solution.minimumCost(**test_input) == 9\n\ntest_input = { \"nums\": [3,2,1] }\nassert my_solution.minimumCost(**test_input) == 6\n\ntest_input = { \"nums\": [3,2,2] }\nassert my_solution.minimumCost(**test_input) == 7\n\ntest_input = { \"nums\": [3,2,3] }\nassert my_solution.minimumCost(**test_input) == 8\n\ntest_input = { \"nums\": [3,2,4] }\nassert my_solution.minimumCost(**test_input) == 9\n\ntest_input = { \"nums\": [3,2,5] }\nassert my_solution.minimumCost(**test_input) == 10\n\ntest_input = { \"nums\": [3,3,1] }\nassert my_solution.minimumCost(**test_input) == 7\n\ntest_input = { \"nums\": [3,3,2] }\nassert my_solution.minimumCost(**test_input) == 8\n\ntest_input = { \"nums\": [3,3,3] }\nassert my_solution.minimumCost(**test_input) == 9\n\ntest_input = { \"nums\": [3,3,4] }\nassert my_solution.minimumCost(**test_input) == 10\n\ntest_input = { \"nums\": [3,3,5] }\nassert my_solution.minimumCost(**test_input) == 11\n\ntest_input = { \"nums\": [3,4,1] }\nassert my_solution.minimumCost(**test_input) == 8\n\ntest_input = { \"nums\": [3,4,2] }\nassert my_solution.minimumCost(**test_input) == 9\n\ntest_input = { \"nums\": [3,4,3] }\nassert my_solution.minimumCost(**test_input) == 10\n\ntest_input = { \"nums\": [3,4,4] }\nassert my_solution.minimumCost(**test_input) == 11\n\ntest_input = { \"nums\": [3,4,5] }\nassert my_solution.minimumCost(**test_input) == 12\n\ntest_input = { \"nums\": [3,5,1] }\nassert my_solution.minimumCost(**test_input) == 9\n\ntest_input = { \"nums\": [3,5,2] }\nassert my_solution.minimumCost(**test_input) == 10\n\ntest_input = { \"nums\": [3,5,3] }\nassert my_solution.minimumCost(**test_input) == 11\n\ntest_input = { \"nums\": [3,5,4] }\nassert my_solution.minimumCost(**test_input) == 12\n\ntest_input = { \"nums\": [3,5,5] }\nassert my_solution.minimumCost(**test_input) == 13\n\ntest_input = { \"nums\": [4,1,1] }\nassert my_solution.minimumCost(**test_input) == 6\n\ntest_input = { \"nums\": [4,1,2] }\nassert my_solution.minimumCost(**test_input) == 7\n\ntest_input = { \"nums\": [4,1,3] }\nassert my_solution.minimumCost(**test_input) == 8\n\ntest_input = { \"nums\": [4,1,4] }\nassert my_solution.minimumCost(**test_input) == 9\n\ntest_input = { \"nums\": [4,1,5] }\nassert my_solution.minimumCost(**test_input) == 10\n\ntest_input = { \"nums\": [4,2,1] }\nassert my_solution.minimumCost(**test_input) == 7\n\ntest_input = { \"nums\": [4,2,2] }\nassert my_solution.minimumCost(**test_input) == 8\n\ntest_input = { \"nums\": [4,2,3] }\nassert my_solution.minimumCost(**test_input) == 9\n\ntest_input = { \"nums\": [4,2,4] }\nassert my_solution.minimumCost(**test_input) == 10\n\ntest_input = { \"nums\": [4,2,5] }\nassert my_solution.minimumCost(**test_input) == 11\n\ntest_input = { \"nums\": [4,3,1] }\nassert my_solution.minimumCost(**test_input) == 8\n\ntest_input = { \"nums\": [4,3,2] }\nassert my_solution.minimumCost(**test_input) == 9\n\ntest_input = { \"nums\": [4,3,3] }\nassert my_solution.minimumCost(**test_input) == 10\n\ntest_input = { \"nums\": [4,3,4] }\nassert my_solution.minimumCost(**test_input) == 11\n\ntest_input = { \"nums\": [4,3,5] }\nassert my_solution.minimumCost(**test_input) == 12\n\ntest_input = { \"nums\": [4,4,1] }\nassert my_solution.minimumCost(**test_input) == 9\n\ntest_input = { \"nums\": [4,4,2] }\nassert my_solution.minimumCost(**test_input) == 10\n\ntest_input = { \"nums\": [4,4,3] }\nassert my_solution.minimumCost(**test_input) == 11\n\ntest_input = { \"nums\": [4,4,4] }\nassert my_solution.minimumCost(**test_input) == 12\n\ntest_input = { \"nums\": [4,4,5] }\nassert my_solution.minimumCost(**test_input) == 13\n\ntest_input = { \"nums\": [4,5,1] }\nassert my_solution.minimumCost(**test_input) == 10\n\ntest_input = { \"nums\": [4,5,2] }\nassert my_solution.minimumCost(**test_input) == 11", "start_time": 1705761000} +{"task_id": "biweekly-contest-122-find-if-array-can-be-sorted", "url": "https://leetcode.com/problems/find-if-array-can-be-sorted", "title": "find-if-array-can-be-sorted", "meta": {"questionId": "3291", "questionFrontendId": "3011", "title": "Find if Array Can Be Sorted", "titleSlug": "find-if-array-can-be-sorted", "isPaidOnly": false, "difficulty": "Medium", "likes": 52, "dislikes": 7, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed array of positive integers nums.\nIn one operation, you can swap any two adjacent elements if they have the same number of set bits. You are allowed to do this operation any number of times (including zero).\nReturn true if you can sort the array, else return false.\n\nExample 1:\n\nInput: nums = [8,4,2,30,15]\nOutput: true\nExplanation: Let's look at the binary representation of every element. The numbers 2, 4, and 8 have one set bit each with binary representation \"10\", \"100\", and \"1000\" respectively. The numbers 15 and 30 have four set bits each with binary representation \"1111\" and \"11110\".\nWe can sort the array using 4 operations:\n- Swap nums[0] with nums[1]. This operation is valid because 8 and 4 have one set bit each. The array becomes [4,8,2,30,15].\n- Swap nums[1] with nums[2]. This operation is valid because 8 and 2 have one set bit each. The array becomes [4,2,8,30,15].\n- Swap nums[0] with nums[1]. This operation is valid because 4 and 2 have one set bit each. The array becomes [2,4,8,30,15].\n- Swap nums[3] with nums[4]. This operation is valid because 30 and 15 have four set bits each. The array becomes [2,4,8,15,30].\nThe array has become sorted, hence we return true.\nNote that there may be other sequences of operations which also sort the array.\n\nExample 2:\n\nInput: nums = [1,2,3,4,5]\nOutput: true\nExplanation: The array is already sorted, hence we return true.\n\nExample 3:\n\nInput: nums = [3,16,8,4,2]\nOutput: false\nExplanation: It can be shown that it is not possible to sort the input array using any number of operations.\n\n\nConstraints:\n\n1 <= nums.length <= 100\n1 <= nums[i] <= 28\n\"\"\"\nclass Solution:\n def canSortArray(self, nums: List[int]) -> bool:\n ", "prompt_sft": "You are given a 0-indexed array of positive integers nums.\nIn one operation, you can swap any two adjacent elements if they have the same number of set bits. You are allowed to do this operation any number of times (including zero).\nReturn true if you can sort the array, else return false.\n\nExample 1:\n\nInput: nums = [8,4,2,30,15]\nOutput: true\nExplanation: Let's look at the binary representation of every element. The numbers 2, 4, and 8 have one set bit each with binary representation \"10\", \"100\", and \"1000\" respectively. The numbers 15 and 30 have four set bits each with binary representation \"1111\" and \"11110\".\nWe can sort the array using 4 operations:\n- Swap nums[0] with nums[1]. This operation is valid because 8 and 4 have one set bit each. The array becomes [4,8,2,30,15].\n- Swap nums[1] with nums[2]. This operation is valid because 8 and 2 have one set bit each. The array becomes [4,2,8,30,15].\n- Swap nums[0] with nums[1]. This operation is valid because 4 and 2 have one set bit each. The array becomes [2,4,8,30,15].\n- Swap nums[3] with nums[4]. This operation is valid because 30 and 15 have four set bits each. The array becomes [2,4,8,15,30].\nThe array has become sorted, hence we return true.\nNote that there may be other sequences of operations which also sort the array.\n\nExample 2:\n\nInput: nums = [1,2,3,4,5]\nOutput: true\nExplanation: The array is already sorted, hence we return true.\n\nExample 3:\n\nInput: nums = [3,16,8,4,2]\nOutput: false\nExplanation: It can be shown that it is not possible to sort the input array using any number of operations.\n\n\nConstraints:\n\n1 <= nums.length <= 100\n1 <= nums[i] <= 28\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def canSortArray(self, nums: List[int]) -> bool:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [8,4,2,30,15] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [1,2,3,4,5] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [1] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [4] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [3,16,8,4,2] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [7] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [10] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [20,16] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [18] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [21,17] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [30] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [26,10] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [1,2] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [2,28,9] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [2,17] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [18,3,8] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [31,18,23] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [75,34,30] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [107,76,52] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [125,92,159] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [136,256,10] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [160,247,127] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [187,4,32] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [197,171,144] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [214,200,176] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [222,191,39] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [24,12] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [225,163,64] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [128,128] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [229,253,127] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [1,2,3] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [1,256,64] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [6,6,192] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [239,83,71] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [6,96,20] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [247,153,90] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [256,255,255] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [1,201,251,191] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [4,157,191,127] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [8,8,2] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [10,34,130] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [12,19,1,11] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [10,91,127] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [15,8,21,25] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [17,25,4,27] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [10,130,206] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [14,183,251] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [29,20,17,4] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [15,147,174] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [16,245,125] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [32,12,25,19] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [22,21,26] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [23,30,32] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [24,72,160] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [33,223,239] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [35,143,127,254] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [55,147,16,8] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [34,52,104] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [100,104,96,144] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [129,70,126,253] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [129,162,158,253] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [145,127,55,43] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [36,177,244] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [159,111,124,233] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [36,213,236] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [175,231,27,92] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [205,234,127,223] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [215,10,8,256] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [223,127,172,210] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [38,221,224] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [41,14,50] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [41,79,239] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [44,124,247] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [225,201,121,103] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [232,45,175,231] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [250,131,50,46] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [254,249,173,163] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [255,255,214,229] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [256,151,141,15] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [47,205,182] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [48,64,251] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [51,253,254] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [53,172,195] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [57,127,251] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [4,98,210,79,254] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [59,31,236] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [8,5,103,247,235] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [8,74,170,254,132] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [8,148,182,62,255] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [62,153,210] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [64,93,253] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [9,28,18,26,11] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [12,208,240,216,139] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [13,21,23,13,32] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [16,24,13,46,156] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [16,192,71,31,239] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [64,195,203] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [65,254,239] }\nassert my_solution.canSortArray(**test_input) == True\n\ntest_input = { \"nums\": [17,11,5,20,8] }\nassert my_solution.canSortArray(**test_input) == False\n\ntest_input = { \"nums\": [23,12,22,29,20] }\nassert my_solution.canSortArray(**test_input) == False", "start_time": 1705761000} +{"task_id": "biweekly-contest-122-minimize-length-of-array-using-operations", "url": "https://leetcode.com/problems/minimize-length-of-array-using-operations", "title": "minimize-length-of-array-using-operations", "meta": {"questionId": "3244", "questionFrontendId": "3012", "title": "Minimize Length of Array Using Operations", "titleSlug": "minimize-length-of-array-using-operations", "isPaidOnly": false, "difficulty": "Medium", "likes": 79, "dislikes": 30, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed integer array nums containing positive integers.\nYour task is to minimize the length of nums by performing the following operations any number of times (including zero):\n\nSelect two distinct indices i and j from nums, such that nums[i] > 0 and nums[j] > 0.\nInsert the result of nums[i] % nums[j] at the end of nums.\nDelete the elements at indices i and j from nums.\n\nReturn an integer denoting the minimum length of nums after performing the operation any number of times.\n\nExample 1:\n\nInput: nums = [1,4,3,1]\nOutput: 1\nExplanation: One way to minimize the length of the array is as follows:\nOperation 1: Select indices 2 and 1, insert nums[2] % nums[1] at the end and it becomes [1,4,3,1,3], then delete elements at indices 2 and 1.\nnums becomes [1,1,3].\nOperation 2: Select indices 1 and 2, insert nums[1] % nums[2] at the end and it becomes [1,1,3,1], then delete elements at indices 1 and 2.\nnums becomes [1,1].\nOperation 3: Select indices 1 and 0, insert nums[1] % nums[0] at the end and it becomes [1,1,0], then delete elements at indices 1 and 0.\nnums becomes [0].\nThe length of nums cannot be reduced further. Hence, the answer is 1.\nIt can be shown that 1 is the minimum achievable length. \nExample 2:\n\nInput: nums = [5,5,5,10,5]\nOutput: 2\nExplanation: One way to minimize the length of the array is as follows:\nOperation 1: Select indices 0 and 3, insert nums[0] % nums[3] at the end and it becomes [5,5,5,10,5,5], then delete elements at indices 0 and 3.\nnums becomes [5,5,5,5]. \nOperation 2: Select indices 2 and 3, insert nums[2] % nums[3] at the end and it becomes [5,5,5,5,0], then delete elements at indices 2 and 3. \nnums becomes [5,5,0]. \nOperation 3: Select indices 0 and 1, insert nums[0] % nums[1] at the end and it becomes [5,5,0,0], then delete elements at indices 0 and 1.\nnums becomes [0,0].\nThe length of nums cannot be reduced further. Hence, the answer is 2.\nIt can be shown that 2 is the minimum achievable length. \nExample 3:\n\nInput: nums = [2,3,4]\nOutput: 1\nExplanation: One way to minimize the length of the array is as follows: \nOperation 1: Select indices 1 and 2, insert nums[1] % nums[2] at the end and it becomes [2,3,4,3], then delete elements at indices 1 and 2.\nnums becomes [2,3].\nOperation 2: Select indices 1 and 0, insert nums[1] % nums[0] at the end and it becomes [2,3,1], then delete elements at indices 1 and 0.\nnums becomes [1].\nThe length of nums cannot be reduced further. Hence, the answer is 1.\nIt can be shown that 1 is the minimum achievable length.\n\nConstraints:\n\n1 <= nums.length <= 105\n1 <= nums[i] <= 109\n\"\"\"\nclass Solution:\n def minimumArrayLength(self, nums: List[int]) -> int:\n ", "prompt_sft": "You are given a 0-indexed integer array nums containing positive integers.\nYour task is to minimize the length of nums by performing the following operations any number of times (including zero):\n\nSelect two distinct indices i and j from nums, such that nums[i] > 0 and nums[j] > 0.\nInsert the result of nums[i] % nums[j] at the end of nums.\nDelete the elements at indices i and j from nums.\n\nReturn an integer denoting the minimum length of nums after performing the operation any number of times.\n\nExample 1:\n\nInput: nums = [1,4,3,1]\nOutput: 1\nExplanation: One way to minimize the length of the array is as follows:\nOperation 1: Select indices 2 and 1, insert nums[2] % nums[1] at the end and it becomes [1,4,3,1,3], then delete elements at indices 2 and 1.\nnums becomes [1,1,3].\nOperation 2: Select indices 1 and 2, insert nums[1] % nums[2] at the end and it becomes [1,1,3,1], then delete elements at indices 1 and 2.\nnums becomes [1,1].\nOperation 3: Select indices 1 and 0, insert nums[1] % nums[0] at the end and it becomes [1,1,0], then delete elements at indices 1 and 0.\nnums becomes [0].\nThe length of nums cannot be reduced further. Hence, the answer is 1.\nIt can be shown that 1 is the minimum achievable length. \nExample 2:\n\nInput: nums = [5,5,5,10,5]\nOutput: 2\nExplanation: One way to minimize the length of the array is as follows:\nOperation 1: Select indices 0 and 3, insert nums[0] % nums[3] at the end and it becomes [5,5,5,10,5,5], then delete elements at indices 0 and 3.\nnums becomes [5,5,5,5]. \nOperation 2: Select indices 2 and 3, insert nums[2] % nums[3] at the end and it becomes [5,5,5,5,0], then delete elements at indices 2 and 3. \nnums becomes [5,5,0]. \nOperation 3: Select indices 0 and 1, insert nums[0] % nums[1] at the end and it becomes [5,5,0,0], then delete elements at indices 0 and 1.\nnums becomes [0,0].\nThe length of nums cannot be reduced further. Hence, the answer is 2.\nIt can be shown that 2 is the minimum achievable length. \nExample 3:\n\nInput: nums = [2,3,4]\nOutput: 1\nExplanation: One way to minimize the length of the array is as follows: \nOperation 1: Select indices 1 and 2, insert nums[1] % nums[2] at the end and it becomes [2,3,4,3], then delete elements at indices 1 and 2.\nnums becomes [2,3].\nOperation 2: Select indices 1 and 0, insert nums[1] % nums[0] at the end and it becomes [2,3,1], then delete elements at indices 1 and 0.\nnums becomes [1].\nThe length of nums cannot be reduced further. Hence, the answer is 1.\nIt can be shown that 1 is the minimum achievable length.\n\nConstraints:\n\n1 <= nums.length <= 105\n1 <= nums[i] <= 109\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def minimumArrayLength(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,4,3,1] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [5,5,5,10,5] }\nassert my_solution.minimumArrayLength(**test_input) == 2\n\ntest_input = { \"nums\": [2,3,4] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [1] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [3] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [6] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [1,4] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [1,5] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [2,4] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [3,4] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [5,3] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [6,9] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [8,2] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [9,9] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [9,10] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,5] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [2,1,1] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [2,7,10] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [2,9,5] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [3,2,1] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [3,2,7] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [3,3,1] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [4,1,3] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [4,4,4] }\nassert my_solution.minimumArrayLength(**test_input) == 2\n\ntest_input = { \"nums\": [5,1,5] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [5,5,5] }\nassert my_solution.minimumArrayLength(**test_input) == 2\n\ntest_input = { \"nums\": [6,5,1] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [8,4,5] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [9,2,2] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,3,2] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [1,3,1,7] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [1,5,5,4] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [1,8,7,2] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [2,2,1,1] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [2,7,10,1] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [2,10,1,7] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [4,2,3,5] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [4,4,1,1] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [5,3,10,10] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [6,3,4,4] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [6,5,2,10] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [7,2,5,9] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [1,3,4,4,3] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [4,1,7,10,1] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [4,3,1,4,3] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [4,6,2,6,4] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [6,10,6,3,3] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [1,4,5,4,5,1] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [1,6,6,9,5,7] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [2,1,2,5,3,1] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [2,2,4,4,2,1] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [3,5,2,5,5,2] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [4,1,4,4,5,1] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [4,3,1,2,5,2] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [4,8,8,7,6,8] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [5,2,2,2,9,10] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [7,3,2,4,3,10] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [7,5,6,6,7,3] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [8,3,9,4,5,8] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [2,5,4,3,5,5,4] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [4,5,5,1,2,5,2] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [4,8,7,4,9,3,9] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [5,3,5,7,9,10,10] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [7,1,9,3,9,2,6] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [7,10,1,8,6,1,2] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [9,1,10,7,3,9,7] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [10,10,3,9,8,3,5] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [10,10,4,8,5,2,6] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [1,5,2,10,4,5,10,1] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [2,1,3,3,3,3,1,4] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [2,2,7,4,5,5,1,2] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [2,4,5,5,3,5,2,4] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [2,10,6,7,7,2,3,4] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [3,3,2,2,4,2,3,3] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [3,4,3,4,1,1,1,2] }\nassert my_solution.minimumArrayLength(**test_input) == 2\n\ntest_input = { \"nums\": [3,4,4,3,5,4,5,5] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [3,6,7,7,6,9,1,6] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [5,1,1,1,1,5,5,5] }\nassert my_solution.minimumArrayLength(**test_input) == 2\n\ntest_input = { \"nums\": [6,7,5,5,3,6,1,8] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [8,5,4,5,4,7,6,10] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [8,10,4,6,7,9,2,1] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [2,6,3,8,9,10,9,3,10] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [4,2,2,1,3,1,5,3,3] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [4,4,5,1,2,1,1,1,2] }\nassert my_solution.minimumArrayLength(**test_input) == 2\n\ntest_input = { \"nums\": [4,5,3,5,5,4,4,2,1] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [5,1,5,1,1,5,4,3,3] }\nassert my_solution.minimumArrayLength(**test_input) == 2\n\ntest_input = { \"nums\": [5,1,5,3,3,2,2,4,4] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [6,4,5,7,9,10,10,6,9] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [6,5,6,4,9,8,8,3,7] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [9,7,6,10,1,8,5,4,2] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [9,10,1,6,4,10,1,3,4] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [10,5,4,8,4,3,7,10,3] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,1,2,2,2,5,5,1,3] }\nassert my_solution.minimumArrayLength(**test_input) == 2\n\ntest_input = { \"nums\": [4,5,1,8,2,7,2,7,7,6] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [7,1,3,10,1,4,5,2,9,7] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [7,2,2,9,5,6,6,10,2,3] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [7,7,3,6,8,10,3,7,6,9] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [1,4,5,8,9,3,1,4,7,4,5] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [4,10,3,8,9,5,7,6,9,10,10] }\nassert my_solution.minimumArrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [5,9,3,9,3,10,1,1,6,3,10] }\nassert my_solution.minimumArrayLength(**test_input) == 1", "start_time": 1705761000} +{"task_id": "biweekly-contest-122-divide-an-array-into-subarrays-with-minimum-cost-ii", "url": "https://leetcode.com/problems/divide-an-array-into-subarrays-with-minimum-cost-ii", "title": "divide-an-array-into-subarrays-with-minimum-cost-ii", "meta": {"questionId": "3260", "questionFrontendId": "3013", "title": "Divide an Array Into Subarrays With Minimum Cost II", "titleSlug": "divide-an-array-into-subarrays-with-minimum-cost-ii", "isPaidOnly": false, "difficulty": "Hard", "likes": 54, "dislikes": 2, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed array of integers nums of length n, and two positive integers k and dist.\nThe cost of an array is the value of its first element. For example, the cost of [1,2,3] is 1 while the cost of [3,4,1] is 3.\nYou need to divide nums into k disjoint contiguous subarrays, such that the difference between the starting index of the second subarray and the starting index of the kth subarray should be less than or equal to dist. In other words, if you divide nums into the subarrays nums[0..(i1 - 1)], nums[i1..(i2 - 1)], ..., nums[ik-1..(n - 1)], then ik-1 - i1 <= dist.\nReturn the minimum possible sum of the cost of these subarrays.\n\nExample 1:\n\nInput: nums = [1,3,2,6,4,2], k = 3, dist = 3\nOutput: 5\nExplanation: The best possible way to divide nums into 3 subarrays is: [1,3], [2,6,4], and [2]. This choice is valid because ik-1 - i1 is 5 - 2 = 3 which is equal to dist. The total cost is nums[0] + nums[2] + nums[5] which is 1 + 2 + 2 = 5.\nIt can be shown that there is no possible way to divide nums into 3 subarrays at a cost lower than 5.\n\nExample 2:\n\nInput: nums = [10,1,2,2,2,1], k = 4, dist = 3\nOutput: 15\nExplanation: The best possible way to divide nums into 4 subarrays is: [10], [1], [2], and [2,2,1]. This choice is valid because ik-1 - i1 is 3 - 1 = 2 which is less than dist. The total cost is nums[0] + nums[1] + nums[2] + nums[3] which is 10 + 1 + 2 + 2 = 15.\nThe division [10], [1], [2,2,2], and [1] is not valid, because the difference between ik-1 and i1 is 5 - 1 = 4, which is greater than dist.\nIt can be shown that there is no possible way to divide nums into 4 subarrays at a cost lower than 15.\n\nExample 3:\n\nInput: nums = [10,8,18,9], k = 3, dist = 1\nOutput: 36\nExplanation: The best possible way to divide nums into 4 subarrays is: [10], [8], and [18,9]. This choice is valid because ik-1 - i1 is 2 - 1 = 1 which is equal to dist.The total cost is nums[0] + nums[1] + nums[2] which is 10 + 8 + 18 = 36.\nThe division [10], [8,18], and [9] is not valid, because the difference between ik-1 and i1 is 3 - 1 = 2, which is greater than dist.\nIt can be shown that there is no possible way to divide nums into 3 subarrays at a cost lower than 36.\n\n\nConstraints:\n\n3 <= n <= 105\n1 <= nums[i] <= 109\n3 <= k <= n\nk - 2 <= dist <= n - 2\n\"\"\"\nclass Solution:\n def minimumCost(self, nums: List[int], k: int, dist: int) -> int:\n ", "prompt_sft": "You are given a 0-indexed array of integers nums of length n, and two positive integers k and dist.\nThe cost of an array is the value of its first element. For example, the cost of [1,2,3] is 1 while the cost of [3,4,1] is 3.\nYou need to divide nums into k disjoint contiguous subarrays, such that the difference between the starting index of the second subarray and the starting index of the kth subarray should be less than or equal to dist. In other words, if you divide nums into the subarrays nums[0..(i1 - 1)], nums[i1..(i2 - 1)], ..., nums[ik-1..(n - 1)], then ik-1 - i1 <= dist.\nReturn the minimum possible sum of the cost of these subarrays.\n\nExample 1:\n\nInput: nums = [1,3,2,6,4,2], k = 3, dist = 3\nOutput: 5\nExplanation: The best possible way to divide nums into 3 subarrays is: [1,3], [2,6,4], and [2]. This choice is valid because ik-1 - i1 is 5 - 2 = 3 which is equal to dist. The total cost is nums[0] + nums[2] + nums[5] which is 1 + 2 + 2 = 5.\nIt can be shown that there is no possible way to divide nums into 3 subarrays at a cost lower than 5.\n\nExample 2:\n\nInput: nums = [10,1,2,2,2,1], k = 4, dist = 3\nOutput: 15\nExplanation: The best possible way to divide nums into 4 subarrays is: [10], [1], [2], and [2,2,1]. This choice is valid because ik-1 - i1 is 3 - 1 = 2 which is less than dist. The total cost is nums[0] + nums[1] + nums[2] + nums[3] which is 10 + 1 + 2 + 2 = 15.\nThe division [10], [1], [2,2,2], and [1] is not valid, because the difference between ik-1 and i1 is 5 - 1 = 4, which is greater than dist.\nIt can be shown that there is no possible way to divide nums into 4 subarrays at a cost lower than 15.\n\nExample 3:\n\nInput: nums = [10,8,18,9], k = 3, dist = 1\nOutput: 36\nExplanation: The best possible way to divide nums into 4 subarrays is: [10], [8], and [18,9]. This choice is valid because ik-1 - i1 is 2 - 1 = 1 which is equal to dist.The total cost is nums[0] + nums[1] + nums[2] which is 10 + 8 + 18 = 36.\nThe division [10], [8,18], and [9] is not valid, because the difference between ik-1 and i1 is 3 - 1 = 2, which is greater than dist.\nIt can be shown that there is no possible way to divide nums into 3 subarrays at a cost lower than 36.\n\n\nConstraints:\n\n3 <= n <= 105\n1 <= nums[i] <= 109\n3 <= k <= n\nk - 2 <= dist <= n - 2\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def minimumCost(self, nums: List[int], k: int, dist: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,3,2,6,4,2], \"k\": 3, \"dist\": 3 }\nassert my_solution.minimumCost(**test_input) == 5\n\ntest_input = { \"nums\": [10,1,2,2,2,1], \"k\": 4, \"dist\": 3 }\nassert my_solution.minimumCost(**test_input) == 15\n\ntest_input = { \"nums\": [10,8,18,9], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 36\n\ntest_input = { \"nums\": [1,1,1], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,3], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 5\n\ntest_input = { \"nums\": [1,2,2], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 5\n\ntest_input = { \"nums\": [1,2,5], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 8\n\ntest_input = { \"nums\": [1,4,4], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 9\n\ntest_input = { \"nums\": [2,2,1], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 5\n\ntest_input = { \"nums\": [2,3,2], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 7\n\ntest_input = { \"nums\": [2,5,4], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 11\n\ntest_input = { \"nums\": [3,1,2], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 6\n\ntest_input = { \"nums\": [3,1,3], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 7\n\ntest_input = { \"nums\": [3,2,2], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 7\n\ntest_input = { \"nums\": [3,3,2], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 8\n\ntest_input = { \"nums\": [3,4,1], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 8\n\ntest_input = { \"nums\": [3,5,3], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 11\n\ntest_input = { \"nums\": [4,1,4], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 9\n\ntest_input = { \"nums\": [4,1,5], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 10\n\ntest_input = { \"nums\": [4,2,1], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 7\n\ntest_input = { \"nums\": [4,2,2], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 8\n\ntest_input = { \"nums\": [4,2,4], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 10\n\ntest_input = { \"nums\": [4,2,5], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 11\n\ntest_input = { \"nums\": [4,3,1], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 8\n\ntest_input = { \"nums\": [4,3,2], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 9\n\ntest_input = { \"nums\": [4,5,3], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 12\n\ntest_input = { \"nums\": [5,2,1], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 8\n\ntest_input = { \"nums\": [5,3,5], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 13\n\ntest_input = { \"nums\": [50,50,50], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 150\n\ntest_input = { \"nums\": [1,5,3,6], \"k\": 3, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 9\n\ntest_input = { \"nums\": [1,5,3,7], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 9\n\ntest_input = { \"nums\": [1,5,3,7], \"k\": 3, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 9\n\ntest_input = { \"nums\": [1,5,3,8], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 9\n\ntest_input = { \"nums\": [1,5,3,8], \"k\": 3, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 9\n\ntest_input = { \"nums\": [1,5,4,6], \"k\": 4, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 16\n\ntest_input = { \"nums\": [1,6,3,5], \"k\": 3, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 9\n\ntest_input = { \"nums\": [1,6,3,8], \"k\": 3, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 10\n\ntest_input = { \"nums\": [1,6,4,5], \"k\": 4, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 16\n\ntest_input = { \"nums\": [1,7,4,6], \"k\": 4, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 18\n\ntest_input = { \"nums\": [1,7,4,8], \"k\": 4, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 20\n\ntest_input = { \"nums\": [1,8,3,8], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 12\n\ntest_input = { \"nums\": [1,8,4,7], \"k\": 4, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 20\n\ntest_input = { \"nums\": [2,5,3,8], \"k\": 3, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 10\n\ntest_input = { \"nums\": [2,5,4,7], \"k\": 4, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 18\n\ntest_input = { \"nums\": [2,5,4,8], \"k\": 4, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 19\n\ntest_input = { \"nums\": [2,6,3,5], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 10\n\ntest_input = { \"nums\": [2,6,3,6], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 11\n\ntest_input = { \"nums\": [2,6,4,5], \"k\": 4, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 17\n\ntest_input = { \"nums\": [2,6,4,7], \"k\": 4, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 19\n\ntest_input = { \"nums\": [2,6,4,8], \"k\": 4, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 20\n\ntest_input = { \"nums\": [2,7,3,5], \"k\": 3, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 10\n\ntest_input = { \"nums\": [2,7,3,8], \"k\": 3, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 12\n\ntest_input = { \"nums\": [2,7,4,6], \"k\": 4, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 19\n\ntest_input = { \"nums\": [2,8,3,5], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 10\n\ntest_input = { \"nums\": [2,8,4,5], \"k\": 4, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 19\n\ntest_input = { \"nums\": [3,5,3,5], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 11\n\ntest_input = { \"nums\": [3,5,3,5], \"k\": 3, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 11\n\ntest_input = { \"nums\": [3,5,3,8], \"k\": 3, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 11\n\ntest_input = { \"nums\": [3,5,4,7], \"k\": 4, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 19\n\ntest_input = { \"nums\": [3,6,3,5], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 11\n\ntest_input = { \"nums\": [3,6,3,7], \"k\": 3, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 12\n\ntest_input = { \"nums\": [3,6,3,8], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 12\n\ntest_input = { \"nums\": [3,6,4,5], \"k\": 4, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 18\n\ntest_input = { \"nums\": [3,7,3,5], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 11\n\ntest_input = { \"nums\": [3,7,3,5], \"k\": 3, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 11\n\ntest_input = { \"nums\": [3,7,3,6], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 12\n\ntest_input = { \"nums\": [3,7,3,8], \"k\": 3, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 13\n\ntest_input = { \"nums\": [3,7,4,7], \"k\": 4, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 21\n\ntest_input = { \"nums\": [3,8,3,5], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 11\n\ntest_input = { \"nums\": [3,8,4,6], \"k\": 4, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 21\n\ntest_input = { \"nums\": [4,5,3,5], \"k\": 3, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 12\n\ntest_input = { \"nums\": [4,5,3,6], \"k\": 3, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 12\n\ntest_input = { \"nums\": [4,5,3,8], \"k\": 3, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 12\n\ntest_input = { \"nums\": [4,5,4,5], \"k\": 4, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 18\n\ntest_input = { \"nums\": [4,6,3,6], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 13\n\ntest_input = { \"nums\": [4,6,3,7], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 13\n\ntest_input = { \"nums\": [4,6,4,5], \"k\": 4, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 19\n\ntest_input = { \"nums\": [4,6,4,8], \"k\": 4, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 22\n\ntest_input = { \"nums\": [4,7,3,6], \"k\": 3, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 13\n\ntest_input = { \"nums\": [4,7,4,5], \"k\": 4, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 20\n\ntest_input = { \"nums\": [4,7,4,7], \"k\": 4, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 22\n\ntest_input = { \"nums\": [4,8,3,5], \"k\": 3, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 12\n\ntest_input = { \"nums\": [4,8,3,6], \"k\": 3, \"dist\": 1 }\nassert my_solution.minimumCost(**test_input) == 13\n\ntest_input = { \"nums\": [4,8,3,7], \"k\": 3, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 14\n\ntest_input = { \"nums\": [4,8,4,6], \"k\": 4, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 22\n\ntest_input = { \"nums\": [4,8,4,8], \"k\": 4, \"dist\": 2 }\nassert my_solution.minimumCost(**test_input) == 24\n\ntest_input = { \"nums\": [1,5,6,6,3,7,2], \"k\": 6, \"dist\": 5 }\nassert my_solution.minimumCost(**test_input) == 23\n\ntest_input = { \"nums\": [1,6,4,6,2,9,11], \"k\": 4, \"dist\": 3 }\nassert my_solution.minimumCost(**test_input) == 13\n\ntest_input = { \"nums\": [1,6,4,7,9,6,1], \"k\": 4, \"dist\": 4 }\nassert my_solution.minimumCost(**test_input) == 12\n\ntest_input = { \"nums\": [1,6,5,6,4,9,11], \"k\": 5, \"dist\": 5 }\nassert my_solution.minimumCost(**test_input) == 22\n\ntest_input = { \"nums\": [1,6,5,7,8,7,5], \"k\": 5, \"dist\": 4 }\nassert my_solution.minimumCost(**test_input) == 25\n\ntest_input = { \"nums\": [1,6,5,8,11,10,6], \"k\": 5, \"dist\": 3 }\nassert my_solution.minimumCost(**test_input) == 31\n\ntest_input = { \"nums\": [1,6,6,8,4,8,7], \"k\": 6, \"dist\": 4 }\nassert my_solution.minimumCost(**test_input) == 33\n\ntest_input = { \"nums\": [1,7,6,8,5,10,10], \"k\": 6, \"dist\": 5 }\nassert my_solution.minimumCost(**test_input) == 37\n\ntest_input = { \"nums\": [1,8,3,8,11,11,10], \"k\": 3, \"dist\": 5 }\nassert my_solution.minimumCost(**test_input) == 12\n\ntest_input = { \"nums\": [1,8,4,7,11,1,8], \"k\": 4, \"dist\": 4 }\nassert my_solution.minimumCost(**test_input) == 13\n\ntest_input = { \"nums\": [1,8,6,5,6,12,12], \"k\": 6, \"dist\": 5 }\nassert my_solution.minimumCost(**test_input) == 38\n\ntest_input = { \"nums\": [1,8,6,6,12,5,2], \"k\": 6, \"dist\": 5 }\nassert my_solution.minimumCost(**test_input) == 28\n\ntest_input = { \"nums\": [2,5,3,5,7,4,3], \"k\": 3, \"dist\": 3 }\nassert my_solution.minimumCost(**test_input) == 9\n\ntest_input = { \"nums\": [2,5,4,6,6,1,3], \"k\": 4, \"dist\": 5 }\nassert my_solution.minimumCost(**test_input) == 10", "start_time": 1705761000} +{"task_id": "weekly-contest-380-count-elements-with-maximum-frequency", "url": "https://leetcode.com/problems/count-elements-with-maximum-frequency", "title": "count-elements-with-maximum-frequency", "meta": {"questionId": "3242", "questionFrontendId": "3005", "title": "Count Elements With Maximum Frequency", "titleSlug": "count-elements-with-maximum-frequency", "isPaidOnly": false, "difficulty": "Easy", "likes": 47, "dislikes": 2, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given an array nums consisting of positive integers.\nReturn the total frequencies of elements in numssuch that those elements all have the maximum frequency.\nThe frequency of an element is the number of occurrences of that element in the array.\n\nExample 1:\n\nInput: nums = [1,2,2,3,1,4]\nOutput: 4\nExplanation: The elements 1 and 2 have a frequency of 2 which is the maximum frequency in the array.\nSo the number of elements in the array with maximum frequency is 4.\n\nExample 2:\n\nInput: nums = [1,2,3,4,5]\nOutput: 5\nExplanation: All elements of the array have a frequency of 1 which is the maximum.\nSo the number of elements in the array with maximum frequency is 5.\n\n\nConstraints:\n\n1 <= nums.length <= 100\n1 <= nums[i] <= 100\n\"\"\"\nclass Solution:\n def maxFrequencyElements(self, nums: List[int]) -> int:\n ", "prompt_sft": "You are given an array nums consisting of positive integers.\nReturn the total frequencies of elements in numssuch that those elements all have the maximum frequency.\nThe frequency of an element is the number of occurrences of that element in the array.\n\nExample 1:\n\nInput: nums = [1,2,2,3,1,4]\nOutput: 4\nExplanation: The elements 1 and 2 have a frequency of 2 which is the maximum frequency in the array.\nSo the number of elements in the array with maximum frequency is 4.\n\nExample 2:\n\nInput: nums = [1,2,3,4,5]\nOutput: 5\nExplanation: All elements of the array have a frequency of 1 which is the maximum.\nSo the number of elements in the array with maximum frequency is 5.\n\n\nConstraints:\n\n1 <= nums.length <= 100\n1 <= nums[i] <= 100\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def maxFrequencyElements(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,2,2,3,1,4] }\nassert my_solution.maxFrequencyElements(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,3,4,5] }\nassert my_solution.maxFrequencyElements(**test_input) == 5\n\ntest_input = { \"nums\": [15] }\nassert my_solution.maxFrequencyElements(**test_input) == 1\n\ntest_input = { \"nums\": [10,12,11,9,6,19,11] }\nassert my_solution.maxFrequencyElements(**test_input) == 2\n\ntest_input = { \"nums\": [2,12,17,18,11] }\nassert my_solution.maxFrequencyElements(**test_input) == 5\n\ntest_input = { \"nums\": [19,19,19,20,19,8,19] }\nassert my_solution.maxFrequencyElements(**test_input) == 5\n\ntest_input = { \"nums\": [1,1,1,1] }\nassert my_solution.maxFrequencyElements(**test_input) == 4\n\ntest_input = { \"nums\": [10,1,12,10,10,19,10] }\nassert my_solution.maxFrequencyElements(**test_input) == 4\n\ntest_input = { \"nums\": [1,1,1,20,6,1] }\nassert my_solution.maxFrequencyElements(**test_input) == 4\n\ntest_input = { \"nums\": [17,17] }\nassert my_solution.maxFrequencyElements(**test_input) == 2\n\ntest_input = { \"nums\": [6,13,15,15,11,6,7,12,4,11] }\nassert my_solution.maxFrequencyElements(**test_input) == 6\n\ntest_input = { \"nums\": [1,2] }\nassert my_solution.maxFrequencyElements(**test_input) == 2\n\ntest_input = { \"nums\": [14,14,17] }\nassert my_solution.maxFrequencyElements(**test_input) == 2\n\ntest_input = { \"nums\": [17,17,2,12,20,17,12] }\nassert my_solution.maxFrequencyElements(**test_input) == 3\n\ntest_input = { \"nums\": [3,9,11,11,20] }\nassert my_solution.maxFrequencyElements(**test_input) == 2\n\ntest_input = { \"nums\": [8,15,8,11,8,13,12,11,8] }\nassert my_solution.maxFrequencyElements(**test_input) == 4\n\ntest_input = { \"nums\": [17,8,17,19,17,13,17,17,17,5] }\nassert my_solution.maxFrequencyElements(**test_input) == 6\n\ntest_input = { \"nums\": [11] }\nassert my_solution.maxFrequencyElements(**test_input) == 1\n\ntest_input = { \"nums\": [5] }\nassert my_solution.maxFrequencyElements(**test_input) == 1\n\ntest_input = { \"nums\": [4,4,10] }\nassert my_solution.maxFrequencyElements(**test_input) == 2\n\ntest_input = { \"nums\": [15,13,2,16,2,5,1,18,8,16] }\nassert my_solution.maxFrequencyElements(**test_input) == 4\n\ntest_input = { \"nums\": [1,17,12,7,17,3] }\nassert my_solution.maxFrequencyElements(**test_input) == 2\n\ntest_input = { \"nums\": [8,2,8,6,1,1] }\nassert my_solution.maxFrequencyElements(**test_input) == 4\n\ntest_input = { \"nums\": [3,9,7,9] }\nassert my_solution.maxFrequencyElements(**test_input) == 2\n\ntest_input = { \"nums\": [20,20,20,5,12,20,9,16] }\nassert my_solution.maxFrequencyElements(**test_input) == 4\n\ntest_input = { \"nums\": [2,14,3,8,16,4,4,3] }\nassert my_solution.maxFrequencyElements(**test_input) == 4\n\ntest_input = { \"nums\": [6,12,3,3,11,2] }\nassert my_solution.maxFrequencyElements(**test_input) == 2\n\ntest_input = { \"nums\": [5,2,13,19,15,20] }\nassert my_solution.maxFrequencyElements(**test_input) == 6\n\ntest_input = { \"nums\": [2,13,13] }\nassert my_solution.maxFrequencyElements(**test_input) == 2\n\ntest_input = { \"nums\": [4,5] }\nassert my_solution.maxFrequencyElements(**test_input) == 2\n\ntest_input = { \"nums\": [20,20,15,20,20,20] }\nassert my_solution.maxFrequencyElements(**test_input) == 5\n\ntest_input = { \"nums\": [16,16,16,16,1,10,16,9] }\nassert my_solution.maxFrequencyElements(**test_input) == 5\n\ntest_input = { \"nums\": [5,3,5,8,5,3,5,15] }\nassert my_solution.maxFrequencyElements(**test_input) == 4\n\ntest_input = { \"nums\": [17] }\nassert my_solution.maxFrequencyElements(**test_input) == 1\n\ntest_input = { \"nums\": [2,2,3,3,9] }\nassert my_solution.maxFrequencyElements(**test_input) == 4\n\ntest_input = { \"nums\": [5,11,4,2] }\nassert my_solution.maxFrequencyElements(**test_input) == 4\n\ntest_input = { \"nums\": [13,13,7] }\nassert my_solution.maxFrequencyElements(**test_input) == 2\n\ntest_input = { \"nums\": [2,15,10,10,10,4,13] }\nassert my_solution.maxFrequencyElements(**test_input) == 3\n\ntest_input = { \"nums\": [3,7,1] }\nassert my_solution.maxFrequencyElements(**test_input) == 3\n\ntest_input = { \"nums\": [19,6,19,19,19,19,19] }\nassert my_solution.maxFrequencyElements(**test_input) == 6\n\ntest_input = { \"nums\": [15,3,12,4,9,14,10] }\nassert my_solution.maxFrequencyElements(**test_input) == 7\n\ntest_input = { \"nums\": [1,19,12,1,12,12,1,6] }\nassert my_solution.maxFrequencyElements(**test_input) == 6\n\ntest_input = { \"nums\": [17,7,3,3,6,5,6,2] }\nassert my_solution.maxFrequencyElements(**test_input) == 4\n\ntest_input = { \"nums\": [12,4,2,9,17,14,1,12,6] }\nassert my_solution.maxFrequencyElements(**test_input) == 2\n\ntest_input = { \"nums\": [16,11] }\nassert my_solution.maxFrequencyElements(**test_input) == 2\n\ntest_input = { \"nums\": [11,11,11,11,10,11,3,11,11] }\nassert my_solution.maxFrequencyElements(**test_input) == 7\n\ntest_input = { \"nums\": [16,4,20,10,12] }\nassert my_solution.maxFrequencyElements(**test_input) == 5\n\ntest_input = { \"nums\": [3,11,3,11] }\nassert my_solution.maxFrequencyElements(**test_input) == 4\n\ntest_input = { \"nums\": [13,9,13,13,13,13,2,13] }\nassert my_solution.maxFrequencyElements(**test_input) == 6\n\ntest_input = { \"nums\": [2,8,9,4,3] }\nassert my_solution.maxFrequencyElements(**test_input) == 5\n\ntest_input = { \"nums\": [19,6,9,12,12] }\nassert my_solution.maxFrequencyElements(**test_input) == 2\n\ntest_input = { \"nums\": [20] }\nassert my_solution.maxFrequencyElements(**test_input) == 1\n\ntest_input = { \"nums\": [1,11] }\nassert my_solution.maxFrequencyElements(**test_input) == 2\n\ntest_input = { \"nums\": [6,4,7,19,20,10,13,14] }\nassert my_solution.maxFrequencyElements(**test_input) == 8\n\ntest_input = { \"nums\": [16,8,5] }\nassert my_solution.maxFrequencyElements(**test_input) == 3\n\ntest_input = { \"nums\": [15,15,4,7,15,15,15,15,15,7] }\nassert my_solution.maxFrequencyElements(**test_input) == 7\n\ntest_input = { \"nums\": [5,20] }\nassert my_solution.maxFrequencyElements(**test_input) == 2\n\ntest_input = { \"nums\": [13] }\nassert my_solution.maxFrequencyElements(**test_input) == 1\n\ntest_input = { \"nums\": [7,15,13,18,3,11,13,7,1,13] }\nassert my_solution.maxFrequencyElements(**test_input) == 3\n\ntest_input = { \"nums\": [17,5,17,5,5] }\nassert my_solution.maxFrequencyElements(**test_input) == 3\n\ntest_input = { \"nums\": [4,5,3,5] }\nassert my_solution.maxFrequencyElements(**test_input) == 2\n\ntest_input = { \"nums\": [11,2] }\nassert my_solution.maxFrequencyElements(**test_input) == 2\n\ntest_input = { \"nums\": [1,17,17,20,2,2] }\nassert my_solution.maxFrequencyElements(**test_input) == 4\n\ntest_input = { \"nums\": [2,5,2,2] }\nassert my_solution.maxFrequencyElements(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,1,3,8,1] }\nassert my_solution.maxFrequencyElements(**test_input) == 4\n\ntest_input = { \"nums\": [1,19,19,5,14,13,1,20,6] }\nassert my_solution.maxFrequencyElements(**test_input) == 4\n\ntest_input = { \"nums\": [19,12,8,20,3,1,12,17] }\nassert my_solution.maxFrequencyElements(**test_input) == 2\n\ntest_input = { \"nums\": [7,15,1,1,6,3] }\nassert my_solution.maxFrequencyElements(**test_input) == 2\n\ntest_input = { \"nums\": [8,8,8,3,8,8,3] }\nassert my_solution.maxFrequencyElements(**test_input) == 5\n\ntest_input = { \"nums\": [5,1,2,2,2,1,1] }\nassert my_solution.maxFrequencyElements(**test_input) == 6\n\ntest_input = { \"nums\": [12,13,6] }\nassert my_solution.maxFrequencyElements(**test_input) == 3\n\ntest_input = { \"nums\": [18,12,8,2,16,19] }\nassert my_solution.maxFrequencyElements(**test_input) == 6\n\ntest_input = { \"nums\": [15,10,2,18,11,14,9] }\nassert my_solution.maxFrequencyElements(**test_input) == 7\n\ntest_input = { \"nums\": [19,17,9,13,1,13] }\nassert my_solution.maxFrequencyElements(**test_input) == 2\n\ntest_input = { \"nums\": [4,12,15,1,4,4,2] }\nassert my_solution.maxFrequencyElements(**test_input) == 3\n\ntest_input = { \"nums\": [16,16,16,8] }\nassert my_solution.maxFrequencyElements(**test_input) == 3\n\ntest_input = { \"nums\": [2] }\nassert my_solution.maxFrequencyElements(**test_input) == 1\n\ntest_input = { \"nums\": [13,15,1] }\nassert my_solution.maxFrequencyElements(**test_input) == 3\n\ntest_input = { \"nums\": [10,10,5,16,17,6,18] }\nassert my_solution.maxFrequencyElements(**test_input) == 2\n\ntest_input = { \"nums\": [3,2,14,2,18,7] }\nassert my_solution.maxFrequencyElements(**test_input) == 2\n\ntest_input = { \"nums\": [16,16,3] }\nassert my_solution.maxFrequencyElements(**test_input) == 2\n\ntest_input = { \"nums\": [1,8,10,11,8,15] }\nassert my_solution.maxFrequencyElements(**test_input) == 2\n\ntest_input = { \"nums\": [8,19,2,7,5,6,3,4] }\nassert my_solution.maxFrequencyElements(**test_input) == 8\n\ntest_input = { \"nums\": [9] }\nassert my_solution.maxFrequencyElements(**test_input) == 1\n\ntest_input = { \"nums\": [13,6,13,10] }\nassert my_solution.maxFrequencyElements(**test_input) == 2\n\ntest_input = { \"nums\": [14,13,14,4,4,14] }\nassert my_solution.maxFrequencyElements(**test_input) == 3\n\ntest_input = { \"nums\": [9,9,1,9,9,1] }\nassert my_solution.maxFrequencyElements(**test_input) == 4\n\ntest_input = { \"nums\": [14,4,11,14,14,4,4] }\nassert my_solution.maxFrequencyElements(**test_input) == 6\n\ntest_input = { \"nums\": [4,20,20,4,1] }\nassert my_solution.maxFrequencyElements(**test_input) == 4\n\ntest_input = { \"nums\": [5,11,8,3,11,11,11] }\nassert my_solution.maxFrequencyElements(**test_input) == 4\n\ntest_input = { \"nums\": [3,2,18,5] }\nassert my_solution.maxFrequencyElements(**test_input) == 4\n\ntest_input = { \"nums\": [3,8,20,7,16,20,18,13] }\nassert my_solution.maxFrequencyElements(**test_input) == 2\n\ntest_input = { \"nums\": [19,9,16,4,10,3,18] }\nassert my_solution.maxFrequencyElements(**test_input) == 7\n\ntest_input = { \"nums\": [11,2,2,3,19,3,11,2,14,1] }\nassert my_solution.maxFrequencyElements(**test_input) == 3\n\ntest_input = { \"nums\": [19,14,11,7,19,1,11,2,16] }\nassert my_solution.maxFrequencyElements(**test_input) == 4\n\ntest_input = { \"nums\": [18,15,3,2,8,12,19,14,12] }\nassert my_solution.maxFrequencyElements(**test_input) == 2\n\ntest_input = { \"nums\": [5,6,11,9,5,5,5] }\nassert my_solution.maxFrequencyElements(**test_input) == 4\n\ntest_input = { \"nums\": [8,4,4,12,8,1] }\nassert my_solution.maxFrequencyElements(**test_input) == 4\n\ntest_input = { \"nums\": [9,1,9,9,3] }\nassert my_solution.maxFrequencyElements(**test_input) == 3\n\ntest_input = { \"nums\": [18] }\nassert my_solution.maxFrequencyElements(**test_input) == 1", "start_time": 1705199400} +{"task_id": "weekly-contest-380-find-beautiful-indices-in-the-given-array-i", "url": "https://leetcode.com/problems/find-beautiful-indices-in-the-given-array-i", "title": "find-beautiful-indices-in-the-given-array-i", "meta": {"questionId": "3245", "questionFrontendId": "3006", "title": "Find Beautiful Indices in the Given Array I", "titleSlug": "find-beautiful-indices-in-the-given-array-i", "isPaidOnly": false, "difficulty": "Medium", "likes": 91, "dislikes": 21, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed string s, a string a, a string b, and an integer k.\nAn index i is beautiful if:\n\n0 <= i <= s.length - a.length\ns[i..(i + a.length - 1)] == a\nThere exists an index j such that:\n\t\n0 <= j <= s.length - b.length\ns[j..(j + b.length - 1)] == b\n|j - i| <= k\n\n\n\nReturn the array that contains beautiful indices in sorted order from smallest to largest.\n\nExample 1:\n\nInput: s = \"isawsquirrelnearmysquirrelhouseohmy\", a = \"my\", b = \"squirrel\", k = 15\nOutput: [16,33]\nExplanation: There are 2 beautiful indices: [16,33].\n- The index 16 is beautiful as s[16..17] == \"my\" and there exists an index 4 with s[4..11] == \"squirrel\" and |16 - 4| <= 15.\n- The index 33 is beautiful as s[33..34] == \"my\" and there exists an index 18 with s[18..25] == \"squirrel\" and |33 - 18| <= 15.\nThus we return [16,33] as the result.\n\nExample 2:\n\nInput: s = \"abcd\", a = \"a\", b = \"a\", k = 4\nOutput: [0]\nExplanation: There is 1 beautiful index: [0].\n- The index 0 is beautiful as s[0..0] == \"a\" and there exists an index 0 with s[0..0] == \"a\" and |0 - 0| <= 4.\nThus we return [0] as the result.\n\n\nConstraints:\n\n1 <= k <= s.length <= 105\n1 <= a.length, b.length <= 10\ns, a, and b contain only lowercase English letters.\n\"\"\"\nclass Solution:\n def beautifulIndices(self, s: str, a: str, b: str, k: int) -> List[int]:\n ", "prompt_sft": "You are given a 0-indexed string s, a string a, a string b, and an integer k.\nAn index i is beautiful if:\n\n0 <= i <= s.length - a.length\ns[i..(i + a.length - 1)] == a\nThere exists an index j such that:\n\t\n0 <= j <= s.length - b.length\ns[j..(j + b.length - 1)] == b\n|j - i| <= k\n\n\n\nReturn the array that contains beautiful indices in sorted order from smallest to largest.\n\nExample 1:\n\nInput: s = \"isawsquirrelnearmysquirrelhouseohmy\", a = \"my\", b = \"squirrel\", k = 15\nOutput: [16,33]\nExplanation: There are 2 beautiful indices: [16,33].\n- The index 16 is beautiful as s[16..17] == \"my\" and there exists an index 4 with s[4..11] == \"squirrel\" and |16 - 4| <= 15.\n- The index 33 is beautiful as s[33..34] == \"my\" and there exists an index 18 with s[18..25] == \"squirrel\" and |33 - 18| <= 15.\nThus we return [16,33] as the result.\n\nExample 2:\n\nInput: s = \"abcd\", a = \"a\", b = \"a\", k = 4\nOutput: [0]\nExplanation: There is 1 beautiful index: [0].\n- The index 0 is beautiful as s[0..0] == \"a\" and there exists an index 0 with s[0..0] == \"a\" and |0 - 0| <= 4.\nThus we return [0] as the result.\n\n\nConstraints:\n\n1 <= k <= s.length <= 105\n1 <= a.length, b.length <= 10\ns, a, and b contain only lowercase English letters.\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def beautifulIndices(self, s: str, a: str, b: str, k: int) -> List[int]:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"s\": \"isawsquirrelnearmysquirrelhouseohmy\", \"a\": \"my\", \"b\": \"squirrel\", \"k\": 15 }\nassert my_solution.beautifulIndices(**test_input) == [16,33]\n\ntest_input = { \"s\": \"abcd\", \"a\": \"a\", \"b\": \"a\", \"k\": 4 }\nassert my_solution.beautifulIndices(**test_input) == [0]\n\ntest_input = { \"s\": \"sqgrt\", \"a\": \"rt\", \"b\": \"sq\", \"k\": 3 }\nassert my_solution.beautifulIndices(**test_input) == [3]\n\ntest_input = { \"s\": \"mquz\", \"a\": \"tklr\", \"b\": \"caz\", \"k\": 4 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"wl\", \"a\": \"xjigt\", \"b\": \"wl\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"bavgoc\", \"a\": \"ba\", \"b\": \"c\", \"k\": 6 }\nassert my_solution.beautifulIndices(**test_input) == [0]\n\ntest_input = { \"s\": \"xpcp\", \"a\": \"yxnod\", \"b\": \"xpc\", \"k\": 4 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"lahhnlwx\", \"a\": \"hhnlw\", \"b\": \"ty\", \"k\": 6 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"dexgscgecd\", \"a\": \"gscge\", \"b\": \"d\", \"k\": 6 }\nassert my_solution.beautifulIndices(**test_input) == [3]\n\ntest_input = { \"s\": \"vjrao\", \"a\": \"vjr\", \"b\": \"yxpsw\", \"k\": 5 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"oo\", \"a\": \"swhup\", \"b\": \"o\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"bxlzgxc\", \"a\": \"ducf\", \"b\": \"xlzgx\", \"k\": 3 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"wetlgztzm\", \"a\": \"box\", \"b\": \"wetl\", \"k\": 4 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"ocmm\", \"a\": \"m\", \"b\": \"oc\", \"k\": 3 }\nassert my_solution.beautifulIndices(**test_input) == [2,3]\n\ntest_input = { \"s\": \"goxmox\", \"a\": \"gibs\", \"b\": \"ox\", \"k\": 6 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"kzlrqzldvy\", \"a\": \"zl\", \"b\": \"tfsr\", \"k\": 9 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"qhd\", \"a\": \"hd\", \"b\": \"od\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"bozpeh\", \"a\": \"bozp\", \"b\": \"vrjn\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"ggfsg\", \"a\": \"gfsg\", \"b\": \"g\", \"k\": 4 }\nassert my_solution.beautifulIndices(**test_input) == [1]\n\ntest_input = { \"s\": \"fape\", \"a\": \"vq\", \"b\": \"ap\", \"k\": 4 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"isitbenom\", \"a\": \"pmng\", \"b\": \"itben\", \"k\": 5 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"gw\", \"a\": \"ln\", \"b\": \"gw\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"jhu\", \"a\": \"sio\", \"b\": \"xnx\", \"k\": 3 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"elcklvcvdg\", \"a\": \"lck\", \"b\": \"e\", \"k\": 5 }\nassert my_solution.beautifulIndices(**test_input) == [1]\n\ntest_input = { \"s\": \"subsu\", \"a\": \"tdo\", \"b\": \"su\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"jqcdc\", \"a\": \"c\", \"b\": \"d\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == [2,4]\n\ntest_input = { \"s\": \"hhvc\", \"a\": \"gfwo\", \"b\": \"hh\", \"k\": 4 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"tyoq\", \"a\": \"vhjit\", \"b\": \"yoq\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"rtbp\", \"a\": \"migjb\", \"b\": \"es\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"gkkstqvl\", \"a\": \"gkkst\", \"b\": \"xszl\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"bc\", \"a\": \"spzk\", \"b\": \"wsick\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"gyalx\", \"a\": \"neet\", \"b\": \"rbhl\", \"k\": 3 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"qo\", \"a\": \"agt\", \"b\": \"xrh\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"rinzbrrr\", \"a\": \"nzb\", \"b\": \"r\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == [2]\n\ntest_input = { \"s\": \"tjly\", \"a\": \"j\", \"b\": \"n\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"frkxslnnn\", \"a\": \"rkxsl\", \"b\": \"n\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"cffczbccc\", \"a\": \"ff\", \"b\": \"c\", \"k\": 9 }\nassert my_solution.beautifulIndices(**test_input) == [1]\n\ntest_input = { \"s\": \"uiddqbeoaw\", \"a\": \"iddq\", \"b\": \"rlr\", \"k\": 6 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"fh\", \"a\": \"ywab\", \"b\": \"qcjyl\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"gdbm\", \"a\": \"gdbm\", \"b\": \"uefwm\", \"k\": 3 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"bpcwswu\", \"a\": \"zi\", \"b\": \"pcwsw\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"dh\", \"a\": \"jmcds\", \"b\": \"nytk\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"qjgckhiif\", \"a\": \"hiif\", \"b\": \"jgc\", \"k\": 4 }\nassert my_solution.beautifulIndices(**test_input) == [5]\n\ntest_input = { \"s\": \"qyixufgyk\", \"a\": \"y\", \"b\": \"ixuf\", \"k\": 5 }\nassert my_solution.beautifulIndices(**test_input) == [1,7]\n\ntest_input = { \"s\": \"wiwiwinwio\", \"a\": \"hm\", \"b\": \"wi\", \"k\": 8 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"ffnlge\", \"a\": \"bjt\", \"b\": \"pavkr\", \"k\": 6 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"rj\", \"a\": \"m\", \"b\": \"umg\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"bkgqxl\", \"a\": \"yufy\", \"b\": \"kgq\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"hhcwp\", \"a\": \"sixek\", \"b\": \"cwp\", \"k\": 4 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"czr\", \"a\": \"cz\", \"b\": \"wxxql\", \"k\": 3 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"tdbnme\", \"a\": \"t\", \"b\": \"dbnme\", \"k\": 4 }\nassert my_solution.beautifulIndices(**test_input) == [0]\n\ntest_input = { \"s\": \"px\", \"a\": \"acgz\", \"b\": \"jaxel\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"wfa\", \"a\": \"fyntx\", \"b\": \"a\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"ixfkxfld\", \"a\": \"ixfk\", \"b\": \"urkke\", \"k\": 6 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"kmjvlkjy\", \"a\": \"gll\", \"b\": \"vlk\", \"k\": 6 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"bsbsvnmvnm\", \"a\": \"vnm\", \"b\": \"bs\", \"k\": 7 }\nassert my_solution.beautifulIndices(**test_input) == [4,7]\n\ntest_input = { \"s\": \"uzqauzqw\", \"a\": \"uzq\", \"b\": \"psnso\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"fsvkche\", \"a\": \"yot\", \"b\": \"svkc\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"cwwzmfzz\", \"a\": \"fnlgc\", \"b\": \"cwwzm\", \"k\": 6 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"profguo\", \"a\": \"o\", \"b\": \"oyzje\", \"k\": 6 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"ckbdnw\", \"a\": \"djpc\", \"b\": \"ckbdn\", \"k\": 5 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"ankfahcorr\", \"a\": \"r\", \"b\": \"kfah\", \"k\": 7 }\nassert my_solution.beautifulIndices(**test_input) == [8,9]\n\ntest_input = { \"s\": \"ahjzfg\", \"a\": \"hjzf\", \"b\": \"zs\", \"k\": 6 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"eueuau\", \"a\": \"u\", \"b\": \"e\", \"k\": 3 }\nassert my_solution.beautifulIndices(**test_input) == [1,3,5]\n\ntest_input = { \"s\": \"etuwwhwljf\", \"a\": \"uwwh\", \"b\": \"efcuq\", \"k\": 3 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"vvjhgg\", \"a\": \"g\", \"b\": \"kj\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"igytmsmsgx\", \"a\": \"msmsg\", \"b\": \"gyt\", \"k\": 3 }\nassert my_solution.beautifulIndices(**test_input) == [4]\n\ntest_input = { \"s\": \"cheoeo\", \"a\": \"eo\", \"b\": \"y\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"gqzf\", \"a\": \"cgpdn\", \"b\": \"zf\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"zapqwtmx\", \"a\": \"apqwt\", \"b\": \"m\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"klxtee\", \"a\": \"e\", \"b\": \"klx\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"xa\", \"a\": \"gzsj\", \"b\": \"oooq\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"gxoxqgxoxq\", \"a\": \"gxoxq\", \"b\": \"x\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == [0,5]\n\ntest_input = { \"s\": \"lsuo\", \"a\": \"d\", \"b\": \"uo\", \"k\": 3 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"yhi\", \"a\": \"ph\", \"b\": \"yhi\", \"k\": 3 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"cj\", \"a\": \"j\", \"b\": \"em\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"clxzclxz\", \"a\": \"ge\", \"b\": \"clxz\", \"k\": 5 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"gjtcpyiniv\", \"a\": \"cpyi\", \"b\": \"hjvtq\", \"k\": 9 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"kyrvedszzo\", \"a\": \"rve\", \"b\": \"y\", \"k\": 3 }\nassert my_solution.beautifulIndices(**test_input) == [2]\n\ntest_input = { \"s\": \"makolbcrme\", \"a\": \"qlhpf\", \"b\": \"akol\", \"k\": 9 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"vgxshd\", \"a\": \"vgx\", \"b\": \"en\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"wfvxfzut\", \"a\": \"wfv\", \"b\": \"ut\", \"k\": 6 }\nassert my_solution.beautifulIndices(**test_input) == [0]\n\ntest_input = { \"s\": \"xxtxxuftxt\", \"a\": \"tx\", \"b\": \"x\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == [2,7]\n\ntest_input = { \"s\": \"cwtybs\", \"a\": \"wgfez\", \"b\": \"cwty\", \"k\": 4 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"opnkctux\", \"a\": \"op\", \"b\": \"nkctu\", \"k\": 5 }\nassert my_solution.beautifulIndices(**test_input) == [0]\n\ntest_input = { \"s\": \"swswmcsksw\", \"a\": \"mcsk\", \"b\": \"sw\", \"k\": 4 }\nassert my_solution.beautifulIndices(**test_input) == [4]\n\ntest_input = { \"s\": \"qqnb\", \"a\": \"q\", \"b\": \"q\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == [0,1]\n\ntest_input = { \"s\": \"tt\", \"a\": \"t\", \"b\": \"q\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"lllclbii\", \"a\": \"l\", \"b\": \"i\", \"k\": 7 }\nassert my_solution.beautifulIndices(**test_input) == [0,1,2,4]\n\ntest_input = { \"s\": \"oanyzue\", \"a\": \"yzu\", \"b\": \"oan\", \"k\": 5 }\nassert my_solution.beautifulIndices(**test_input) == [3]\n\ntest_input = { \"s\": \"opmfgzthj\", \"a\": \"opmf\", \"b\": \"g\", \"k\": 9 }\nassert my_solution.beautifulIndices(**test_input) == [0]\n\ntest_input = { \"s\": \"uiddidde\", \"a\": \"idd\", \"b\": \"sal\", \"k\": 7 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"gzzau\", \"a\": \"za\", \"b\": \"rwu\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"srpxqurxx\", \"a\": \"nsr\", \"b\": \"x\", \"k\": 3 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"sxaono\", \"a\": \"jy\", \"b\": \"xaon\", \"k\": 6 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"acxtjiova\", \"a\": \"acx\", \"b\": \"tjiov\", \"k\": 3 }\nassert my_solution.beautifulIndices(**test_input) == [0]\n\ntest_input = { \"s\": \"iltazkww\", \"a\": \"k\", \"b\": \"z\", \"k\": 6 }\nassert my_solution.beautifulIndices(**test_input) == [5]\n\ntest_input = { \"s\": \"ltxbhpi\", \"a\": \"cjfbb\", \"b\": \"ltxb\", \"k\": 5 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"gysgysh\", \"a\": \"gys\", \"b\": \"qzvae\", \"k\": 5 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"zypvgt\", \"a\": \"zypv\", \"b\": \"ljxni\", \"k\": 4 }\nassert my_solution.beautifulIndices(**test_input) == []", "start_time": 1705199400} +{"task_id": "weekly-contest-380-maximum-number-that-sum-of-the-prices-is-less-than-or-equal-to-k", "url": "https://leetcode.com/problems/maximum-number-that-sum-of-the-prices-is-less-than-or-equal-to-k", "title": "maximum-number-that-sum-of-the-prices-is-less-than-or-equal-to-k", "meta": {"questionId": "3240", "questionFrontendId": "3007", "title": "Maximum Number That Sum of the Prices Is Less Than or Equal to K", "titleSlug": "maximum-number-that-sum-of-the-prices-is-less-than-or-equal-to-k", "isPaidOnly": false, "difficulty": "Medium", "likes": 125, "dislikes": 74, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given an integer k and an integer x.\nConsider s is the 1-indexed binary representation of an integer num. The price of a number num is the number of i's such that i % x == 0 and s[i] is a set bit.\nReturn the greatest integer num such that the sum of prices of all numbers from 1 to num is less than or equal to k.\nNote:\n\nIn the binary representation of a number set bit is a bit of value 1.\nThe binary representation of a number will be indexed from right to left. For example, if s == 11100, s[4] == 1 and s[2] == 0.\n\n\nExample 1:\n\nInput: k = 9, x = 1\nOutput: 6\nExplanation: The numbers 1, 2, 3, 4, 5, and 6 can be written in binary representation as \"1\", \"10\", \"11\", \"100\", \"101\", and \"110\" respectively.\nSince x is equal to 1, the price of each number is the number of its set bits.\nThe number of set bits in these numbers is 9. So the sum of the prices of the first 6 numbers is 9.\nSo the answer is 6.\nExample 2:\n\nInput: k = 7, x = 2\nOutput: 9\nExplanation: Since x is equal to 2, we should just check eventh bits.\nThe second bit of binary representation of numbers 2 and 3 is a set bit. So the sum of their prices is 2.\nThe second bit of binary representation of numbers 6 and 7 is a set bit. So the sum of their prices is 2.\nThe fourth bit of binary representation of numbers 8 and 9 is a set bit but their second bit is not. So the sum of their prices is 2.\nNumbers 1, 4, and 5 don't have set bits in their eventh bits in their binary representation. So the sum of their prices is 0.\nThe second and the fourth bit of the binary representation of the number 10 are a set bit. So its price is 2.\nThe sum of the prices of the first 9 numbers is 6.\nBecause the sum of the prices of the first 10 numbers is 8, the answer is 9.\n\nConstraints:\n\n1 <= k <= 1015\n1 <= x <= 8\n\"\"\"\nclass Solution:\n def findMaximumNumber(self, k: int, x: int) -> int:\n ", "prompt_sft": "You are given an integer k and an integer x.\nConsider s is the 1-indexed binary representation of an integer num. The price of a number num is the number of i's such that i % x == 0 and s[i] is a set bit.\nReturn the greatest integer num such that the sum of prices of all numbers from 1 to num is less than or equal to k.\nNote:\n\nIn the binary representation of a number set bit is a bit of value 1.\nThe binary representation of a number will be indexed from right to left. For example, if s == 11100, s[4] == 1 and s[2] == 0.\n\n\nExample 1:\n\nInput: k = 9, x = 1\nOutput: 6\nExplanation: The numbers 1, 2, 3, 4, 5, and 6 can be written in binary representation as \"1\", \"10\", \"11\", \"100\", \"101\", and \"110\" respectively.\nSince x is equal to 1, the price of each number is the number of its set bits.\nThe number of set bits in these numbers is 9. So the sum of the prices of the first 6 numbers is 9.\nSo the answer is 6.\nExample 2:\n\nInput: k = 7, x = 2\nOutput: 9\nExplanation: Since x is equal to 2, we should just check eventh bits.\nThe second bit of binary representation of numbers 2 and 3 is a set bit. So the sum of their prices is 2.\nThe second bit of binary representation of numbers 6 and 7 is a set bit. So the sum of their prices is 2.\nThe fourth bit of binary representation of numbers 8 and 9 is a set bit but their second bit is not. So the sum of their prices is 2.\nNumbers 1, 4, and 5 don't have set bits in their eventh bits in their binary representation. So the sum of their prices is 0.\nThe second and the fourth bit of the binary representation of the number 10 are a set bit. So its price is 2.\nThe sum of the prices of the first 9 numbers is 6.\nBecause the sum of the prices of the first 10 numbers is 8, the answer is 9.\n\nConstraints:\n\n1 <= k <= 1015\n1 <= x <= 8\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def findMaximumNumber(self, k: int, x: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"k\": 9, \"x\": 1 }\nassert my_solution.findMaximumNumber(**test_input) == 6\n\ntest_input = { \"k\": 7, \"x\": 2 }\nassert my_solution.findMaximumNumber(**test_input) == 9\n\ntest_input = { \"k\": 19, \"x\": 6 }\nassert my_solution.findMaximumNumber(**test_input) == 50\n\ntest_input = { \"k\": 57, \"x\": 4 }\nassert my_solution.findMaximumNumber(**test_input) == 120\n\ntest_input = { \"k\": 58, \"x\": 5 }\nassert my_solution.findMaximumNumber(**test_input) == 121\n\ntest_input = { \"k\": 60, \"x\": 8 }\nassert my_solution.findMaximumNumber(**test_input) == 187\n\ntest_input = { \"k\": 72, \"x\": 5 }\nassert my_solution.findMaximumNumber(**test_input) == 151\n\ntest_input = { \"k\": 81, \"x\": 6 }\nassert my_solution.findMaximumNumber(**test_input) == 176\n\ntest_input = { \"k\": 83, \"x\": 1 }\nassert my_solution.findMaximumNumber(**test_input) == 33\n\ntest_input = { \"k\": 83, \"x\": 7 }\nassert my_solution.findMaximumNumber(**test_input) == 210\n\ntest_input = { \"k\": 116, \"x\": 5 }\nassert my_solution.findMaximumNumber(**test_input) == 243\n\ntest_input = { \"k\": 157, \"x\": 6 }\nassert my_solution.findMaximumNumber(**test_input) == 316\n\ntest_input = { \"k\": 201, \"x\": 3 }\nassert my_solution.findMaximumNumber(**test_input) == 212\n\ntest_input = { \"k\": 268, \"x\": 6 }\nassert my_solution.findMaximumNumber(**test_input) == 555\n\ntest_input = { \"k\": 281, \"x\": 5 }\nassert my_solution.findMaximumNumber(**test_input) == 531\n\ntest_input = { \"k\": 283, \"x\": 3 }\nassert my_solution.findMaximumNumber(**test_input) == 274\n\ntest_input = { \"k\": 309, \"x\": 4 }\nassert my_solution.findMaximumNumber(**test_input) == 364\n\ntest_input = { \"k\": 363, \"x\": 7 }\nassert my_solution.findMaximumNumber(**test_input) == 746\n\ntest_input = { \"k\": 409, \"x\": 2 }\nassert my_solution.findMaximumNumber(**test_input) == 220\n\ntest_input = { \"k\": 456, \"x\": 7 }\nassert my_solution.findMaximumNumber(**test_input) == 967\n\ntest_input = { \"k\": 466, \"x\": 3 }\nassert my_solution.findMaximumNumber(**test_input) == 365\n\ntest_input = { \"k\": 500, \"x\": 3 }\nassert my_solution.findMaximumNumber(**test_input) == 379\n\ntest_input = { \"k\": 513, \"x\": 1 }\nassert my_solution.findMaximumNumber(**test_input) == 148\n\ntest_input = { \"k\": 521, \"x\": 8 }\nassert my_solution.findMaximumNumber(**test_input) == 1160\n\ntest_input = { \"k\": 540, \"x\": 4 }\nassert my_solution.findMaximumNumber(**test_input) == 571\n\ntest_input = { \"k\": 545, \"x\": 1 }\nassert my_solution.findMaximumNumber(**test_input) == 156\n\ntest_input = { \"k\": 579, \"x\": 1 }\nassert my_solution.findMaximumNumber(**test_input) == 165\n\ntest_input = { \"k\": 584, \"x\": 1 }\nassert my_solution.findMaximumNumber(**test_input) == 166\n\ntest_input = { \"k\": 589, \"x\": 3 }\nassert my_solution.findMaximumNumber(**test_input) == 427\n\ntest_input = { \"k\": 599, \"x\": 6 }\nassert my_solution.findMaximumNumber(**test_input) == 1206\n\ntest_input = { \"k\": 632, \"x\": 2 }\nassert my_solution.findMaximumNumber(**test_input) == 346\n\ntest_input = { \"k\": 692, \"x\": 3 }\nassert my_solution.findMaximumNumber(**test_input) == 481\n\ntest_input = { \"k\": 701, \"x\": 7 }\nassert my_solution.findMaximumNumber(**test_input) == 1404\n\ntest_input = { \"k\": 704, \"x\": 4 }\nassert my_solution.findMaximumNumber(**test_input) == 727\n\ntest_input = { \"k\": 731, \"x\": 7 }\nassert my_solution.findMaximumNumber(**test_input) == 1498\n\ntest_input = { \"k\": 781, \"x\": 1 }\nassert my_solution.findMaximumNumber(**test_input) == 210\n\ntest_input = { \"k\": 782, \"x\": 7 }\nassert my_solution.findMaximumNumber(**test_input) == 1613\n\ntest_input = { \"k\": 808, \"x\": 6 }\nassert my_solution.findMaximumNumber(**test_input) == 1639\n\ntest_input = { \"k\": 814, \"x\": 7 }\nassert my_solution.findMaximumNumber(**test_input) == 1645\n\ntest_input = { \"k\": 818, \"x\": 1 }\nassert my_solution.findMaximumNumber(**test_input) == 218\n\ntest_input = { \"k\": 821, \"x\": 2 }\nassert my_solution.findMaximumNumber(**test_input) == 433\n\ntest_input = { \"k\": 829, \"x\": 6 }\nassert my_solution.findMaximumNumber(**test_input) == 1660\n\ntest_input = { \"k\": 865, \"x\": 7 }\nassert my_solution.findMaximumNumber(**test_input) == 1760\n\ntest_input = { \"k\": 874, \"x\": 6 }\nassert my_solution.findMaximumNumber(**test_input) == 1769\n\ntest_input = { \"k\": 879, \"x\": 1 }\nassert my_solution.findMaximumNumber(**test_input) == 230\n\ntest_input = { \"k\": 879, \"x\": 3 }\nassert my_solution.findMaximumNumber(**test_input) == 628\n\ntest_input = { \"k\": 898, \"x\": 8 }\nassert my_solution.findMaximumNumber(**test_input) == 1921\n\ntest_input = { \"k\": 902, \"x\": 3 }\nassert my_solution.findMaximumNumber(**test_input) == 653\n\ntest_input = { \"k\": 905, \"x\": 8 }\nassert my_solution.findMaximumNumber(**test_input) == 1928\n\ntest_input = { \"k\": 937, \"x\": 8 }\nassert my_solution.findMaximumNumber(**test_input) == 1960\n\ntest_input = { \"k\": 957, \"x\": 3 }\nassert my_solution.findMaximumNumber(**test_input) == 701\n\ntest_input = { \"k\": 973, \"x\": 1 }\nassert my_solution.findMaximumNumber(**test_input) == 247\n\ntest_input = { \"k\": 978, \"x\": 3 }\nassert my_solution.findMaximumNumber(**test_input) == 737\n\ntest_input = { \"k\": 991, \"x\": 5 }\nassert my_solution.findMaximumNumber(**test_input) == 1006\n\ntest_input = { \"k\": 1029, \"x\": 3 }\nassert my_solution.findMaximumNumber(**test_input) == 771\n\ntest_input = { \"k\": 1065, \"x\": 6 }\nassert my_solution.findMaximumNumber(**test_input) == 2083\n\ntest_input = { \"k\": 1086, \"x\": 3 }\nassert my_solution.findMaximumNumber(**test_input) == 805\n\ntest_input = { \"k\": 1105, \"x\": 1 }\nassert my_solution.findMaximumNumber(**test_input) == 280\n\ntest_input = { \"k\": 1113, \"x\": 3 }\nassert my_solution.findMaximumNumber(**test_input) == 815\n\ntest_input = { \"k\": 1143, \"x\": 4 }\nassert my_solution.findMaximumNumber(**test_input) == 1190\n\ntest_input = { \"k\": 1148, \"x\": 2 }\nassert my_solution.findMaximumNumber(**test_input) == 564\n\ntest_input = { \"k\": 1150, \"x\": 7 }\nassert my_solution.findMaximumNumber(**test_input) == 2301\n\ntest_input = { \"k\": 1156, \"x\": 3 }\nassert my_solution.findMaximumNumber(**test_input) == 835\n\ntest_input = { \"k\": 1171, \"x\": 7 }\nassert my_solution.findMaximumNumber(**test_input) == 2386\n\ntest_input = { \"k\": 1172, \"x\": 1 }\nassert my_solution.findMaximumNumber(**test_input) == 297\n\ntest_input = { \"k\": 1227, \"x\": 7 }\nassert my_solution.findMaximumNumber(**test_input) == 2506\n\ntest_input = { \"k\": 1236, \"x\": 8 }\nassert my_solution.findMaximumNumber(**test_input) == 2515\n\ntest_input = { \"k\": 1270, \"x\": 5 }\nassert my_solution.findMaximumNumber(**test_input) == 1525\n\ntest_input = { \"k\": 1274, \"x\": 6 }\nassert my_solution.findMaximumNumber(**test_input) == 2220\n\ntest_input = { \"k\": 1281, \"x\": 6 }\nassert my_solution.findMaximumNumber(**test_input) == 2223\n\ntest_input = { \"k\": 1282, \"x\": 6 }\nassert my_solution.findMaximumNumber(**test_input) == 2224\n\ntest_input = { \"k\": 1288, \"x\": 5 }\nassert my_solution.findMaximumNumber(**test_input) == 1543\n\ntest_input = { \"k\": 1376, \"x\": 6 }\nassert my_solution.findMaximumNumber(**test_input) == 2287\n\ntest_input = { \"k\": 1393, \"x\": 7 }\nassert my_solution.findMaximumNumber(**test_input) == 2800\n\ntest_input = { \"k\": 1415, \"x\": 4 }\nassert my_solution.findMaximumNumber(**test_input) == 1454\n\ntest_input = { \"k\": 1446, \"x\": 7 }\nassert my_solution.findMaximumNumber(**test_input) == 2917\n\ntest_input = { \"k\": 1459, \"x\": 1 }\nassert my_solution.findMaximumNumber(**test_input) == 358\n\ntest_input = { \"k\": 1520, \"x\": 3 }\nassert my_solution.findMaximumNumber(**test_input) == 1017\n\ntest_input = { \"k\": 1539, \"x\": 6 }\nassert my_solution.findMaximumNumber(**test_input) == 2400\n\ntest_input = { \"k\": 1545, \"x\": 7 }\nassert my_solution.findMaximumNumber(**test_input) == 3144\n\ntest_input = { \"k\": 1573, \"x\": 5 }\nassert my_solution.findMaximumNumber(**test_input) == 1732\n\ntest_input = { \"k\": 1588, \"x\": 8 }\nassert my_solution.findMaximumNumber(**test_input) == 3251\n\ntest_input = { \"k\": 1590, \"x\": 7 }\nassert my_solution.findMaximumNumber(**test_input) == 3189\n\ntest_input = { \"k\": 1617, \"x\": 7 }\nassert my_solution.findMaximumNumber(**test_input) == 3280\n\ntest_input = { \"k\": 1633, \"x\": 6 }\nassert my_solution.findMaximumNumber(**test_input) == 2463\n\ntest_input = { \"k\": 1634, \"x\": 7 }\nassert my_solution.findMaximumNumber(**test_input) == 3297\n\ntest_input = { \"k\": 1687, \"x\": 2 }\nassert my_solution.findMaximumNumber(**test_input) == 741\n\ntest_input = { \"k\": 1731, \"x\": 6 }\nassert my_solution.findMaximumNumber(**test_input) == 2528\n\ntest_input = { \"k\": 1750, \"x\": 5 }\nassert my_solution.findMaximumNumber(**test_input) == 1850\n\ntest_input = { \"k\": 1751, \"x\": 7 }\nassert my_solution.findMaximumNumber(**test_input) == 3542\n\ntest_input = { \"k\": 1760, \"x\": 8 }\nassert my_solution.findMaximumNumber(**test_input) == 3551\n\ntest_input = { \"k\": 1782, \"x\": 8 }\nassert my_solution.findMaximumNumber(**test_input) == 3573\n\ntest_input = { \"k\": 1787, \"x\": 2 }\nassert my_solution.findMaximumNumber(**test_input) == 766\n\ntest_input = { \"k\": 1851, \"x\": 2 }\nassert my_solution.findMaximumNumber(**test_input) == 797\n\ntest_input = { \"k\": 1856, \"x\": 2 }\nassert my_solution.findMaximumNumber(**test_input) == 799\n\ntest_input = { \"k\": 1874, \"x\": 8 }\nassert my_solution.findMaximumNumber(**test_input) == 3793\n\ntest_input = { \"k\": 1893, \"x\": 7 }\nassert my_solution.findMaximumNumber(**test_input) == 3812\n\ntest_input = { \"k\": 1900, \"x\": 1 }\nassert my_solution.findMaximumNumber(**test_input) == 444\n\ntest_input = { \"k\": 1900, \"x\": 7 }\nassert my_solution.findMaximumNumber(**test_input) == 3819\n\ntest_input = { \"k\": 1902, \"x\": 3 }\nassert my_solution.findMaximumNumber(**test_input) == 1336", "start_time": 1705199400} +{"task_id": "weekly-contest-380-find-beautiful-indices-in-the-given-array-ii", "url": "https://leetcode.com/problems/find-beautiful-indices-in-the-given-array-ii", "title": "find-beautiful-indices-in-the-given-array-ii", "meta": {"questionId": "3303", "questionFrontendId": "3008", "title": "Find Beautiful Indices in the Given Array II", "titleSlug": "find-beautiful-indices-in-the-given-array-ii", "isPaidOnly": false, "difficulty": "Hard", "likes": 101, "dislikes": 9, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed string s, a string a, a string b, and an integer k.\nAn index i is beautiful if:\n\n0 <= i <= s.length - a.length\ns[i..(i + a.length - 1)] == a\nThere exists an index j such that:\n\t\n0 <= j <= s.length - b.length\ns[j..(j + b.length - 1)] == b\n|j - i| <= k\n\n\n\nReturn the array that contains beautiful indices in sorted order from smallest to largest.\n\nExample 1:\n\nInput: s = \"isawsquirrelnearmysquirrelhouseohmy\", a = \"my\", b = \"squirrel\", k = 15\nOutput: [16,33]\nExplanation: There are 2 beautiful indices: [16,33].\n- The index 16 is beautiful as s[16..17] == \"my\" and there exists an index 4 with s[4..11] == \"squirrel\" and |16 - 4| <= 15.\n- The index 33 is beautiful as s[33..34] == \"my\" and there exists an index 18 with s[18..25] == \"squirrel\" and |33 - 18| <= 15.\nThus we return [16,33] as the result.\n\nExample 2:\n\nInput: s = \"abcd\", a = \"a\", b = \"a\", k = 4\nOutput: [0]\nExplanation: There is 1 beautiful index: [0].\n- The index 0 is beautiful as s[0..0] == \"a\" and there exists an index 0 with s[0..0] == \"a\" and |0 - 0| <= 4.\nThus we return [0] as the result.\n\n\nConstraints:\n\n1 <= k <= s.length <= 5 * 105\n1 <= a.length, b.length <= 5 * 105\ns, a, and b contain only lowercase English letters.\n\"\"\"\nclass Solution:\n def beautifulIndices(self, s: str, a: str, b: str, k: int) -> List[int]:\n ", "prompt_sft": "You are given a 0-indexed string s, a string a, a string b, and an integer k.\nAn index i is beautiful if:\n\n0 <= i <= s.length - a.length\ns[i..(i + a.length - 1)] == a\nThere exists an index j such that:\n\t\n0 <= j <= s.length - b.length\ns[j..(j + b.length - 1)] == b\n|j - i| <= k\n\n\n\nReturn the array that contains beautiful indices in sorted order from smallest to largest.\n\nExample 1:\n\nInput: s = \"isawsquirrelnearmysquirrelhouseohmy\", a = \"my\", b = \"squirrel\", k = 15\nOutput: [16,33]\nExplanation: There are 2 beautiful indices: [16,33].\n- The index 16 is beautiful as s[16..17] == \"my\" and there exists an index 4 with s[4..11] == \"squirrel\" and |16 - 4| <= 15.\n- The index 33 is beautiful as s[33..34] == \"my\" and there exists an index 18 with s[18..25] == \"squirrel\" and |33 - 18| <= 15.\nThus we return [16,33] as the result.\n\nExample 2:\n\nInput: s = \"abcd\", a = \"a\", b = \"a\", k = 4\nOutput: [0]\nExplanation: There is 1 beautiful index: [0].\n- The index 0 is beautiful as s[0..0] == \"a\" and there exists an index 0 with s[0..0] == \"a\" and |0 - 0| <= 4.\nThus we return [0] as the result.\n\n\nConstraints:\n\n1 <= k <= s.length <= 5 * 105\n1 <= a.length, b.length <= 5 * 105\ns, a, and b contain only lowercase English letters.\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def beautifulIndices(self, s: str, a: str, b: str, k: int) -> List[int]:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"s\": \"isawsquirrelnearmysquirrelhouseohmy\", \"a\": \"my\", \"b\": \"squirrel\", \"k\": 15 }\nassert my_solution.beautifulIndices(**test_input) == [16,33]\n\ntest_input = { \"s\": \"abcd\", \"a\": \"a\", \"b\": \"a\", \"k\": 4 }\nassert my_solution.beautifulIndices(**test_input) == [0]\n\ntest_input = { \"s\": \"a\", \"a\": \"a\", \"b\": \"a\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == [0]\n\ntest_input = { \"s\": \"aba\", \"a\": \"a\", \"b\": \"a\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == [0,2]\n\ntest_input = { \"s\": \"nvnvt\", \"a\": \"eq\", \"b\": \"nv\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"npearbvede\", \"a\": \"myqpb\", \"b\": \"pearb\", \"k\": 9 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"vatevavakz\", \"a\": \"va\", \"b\": \"lbda\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"ithhi\", \"a\": \"t\", \"b\": \"hhi\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == [1]\n\ntest_input = { \"s\": \"osuv\", \"a\": \"osuv\", \"b\": \"wrn\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"dc\", \"a\": \"dreec\", \"b\": \"dc\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"jajrfw\", \"a\": \"rf\", \"b\": \"j\", \"k\": 3 }\nassert my_solution.beautifulIndices(**test_input) == [3]\n\ntest_input = { \"s\": \"zcvx\", \"a\": \"kfdvv\", \"b\": \"tru\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"wltmqbxt\", \"a\": \"mqbxt\", \"b\": \"lt\", \"k\": 7 }\nassert my_solution.beautifulIndices(**test_input) == [3]\n\ntest_input = { \"s\": \"gggsytwgzg\", \"a\": \"sytwg\", \"b\": \"g\", \"k\": 4 }\nassert my_solution.beautifulIndices(**test_input) == [3]\n\ntest_input = { \"s\": \"diive\", \"a\": \"viw\", \"b\": \"lqqdn\", \"k\": 4 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"ss\", \"a\": \"omkdt\", \"b\": \"s\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"hfzoxcm\", \"a\": \"hfzo\", \"b\": \"ipelr\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"xllimtmil\", \"a\": \"imt\", \"b\": \"iwqx\", \"k\": 5 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"vdyl\", \"a\": \"i\", \"b\": \"ir\", \"k\": 4 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"ouwpaz\", \"a\": \"mxre\", \"b\": \"pa\", \"k\": 5 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"vlxgolxgoi\", \"a\": \"xf\", \"b\": \"lxgo\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"pnb\", \"a\": \"cx\", \"b\": \"pn\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"owhixi\", \"a\": \"hixi\", \"b\": \"anlc\", \"k\": 6 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"lrtsi\", \"a\": \"lrts\", \"b\": \"i\", \"k\": 3 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"tpyq\", \"a\": \"sa\", \"b\": \"py\", \"k\": 4 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"imxclscgz\", \"a\": \"iujc\", \"b\": \"mxcls\", \"k\": 7 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"sc\", \"a\": \"fc\", \"b\": \"th\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"tgs\", \"a\": \"ldy\", \"b\": \"tgs\", \"k\": 3 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"ssaeqzzvvg\", \"a\": \"ssa\", \"b\": \"z\", \"k\": 5 }\nassert my_solution.beautifulIndices(**test_input) == [0]\n\ntest_input = { \"s\": \"zchdy\", \"a\": \"zch\", \"b\": \"dm\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"youob\", \"a\": \"y\", \"b\": \"o\", \"k\": 5 }\nassert my_solution.beautifulIndices(**test_input) == [0]\n\ntest_input = { \"s\": \"snwj\", \"a\": \"snwj\", \"b\": \"ry\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"rneq\", \"a\": \"ynprc\", \"b\": \"yts\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"vxqf\", \"a\": \"tcnzs\", \"b\": \"qf\", \"k\": 4 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"avnzbrpb\", \"a\": \"yzfgy\", \"b\": \"cfri\", \"k\": 5 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"de\", \"a\": \"segs\", \"b\": \"bvdhs\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"ulgzs\", \"a\": \"eiib\", \"b\": \"ulgz\", \"k\": 4 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"tw\", \"a\": \"ypf\", \"b\": \"svl\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"sotqbvds\", \"a\": \"uoj\", \"b\": \"s\", \"k\": 6 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"oexy\", \"a\": \"e\", \"b\": \"a\", \"k\": 3 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"sywgismky\", \"a\": \"sywgi\", \"b\": \"t\", \"k\": 4 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"onwawarwa\", \"a\": \"wa\", \"b\": \"r\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == [4,7]\n\ntest_input = { \"s\": \"xpuldtpxpu\", \"a\": \"vkhl\", \"b\": \"xpu\", \"k\": 5 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"dg\", \"a\": \"amhb\", \"b\": \"aqwcf\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"spro\", \"a\": \"spro\", \"b\": \"lytwu\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"gfjuakm\", \"a\": \"fj\", \"b\": \"jytnd\", \"k\": 5 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"so\", \"a\": \"kkhvu\", \"b\": \"rukp\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"zwedfgnra\", \"a\": \"dfgn\", \"b\": \"zwe\", \"k\": 9 }\nassert my_solution.beautifulIndices(**test_input) == [3]\n\ntest_input = { \"s\": \"nipetnupg\", \"a\": \"n\", \"b\": \"ipet\", \"k\": 7 }\nassert my_solution.beautifulIndices(**test_input) == [0,5]\n\ntest_input = { \"s\": \"xckrhkrnfe\", \"a\": \"xc\", \"b\": \"kr\", \"k\": 9 }\nassert my_solution.beautifulIndices(**test_input) == [0]\n\ntest_input = { \"s\": \"xibrjp\", \"a\": \"ibr\", \"b\": \"bpfuf\", \"k\": 6 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"cj\", \"a\": \"x\", \"b\": \"dea\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"xfejay\", \"a\": \"xfej\", \"b\": \"koc\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"ijkqk\", \"a\": \"nzxwn\", \"b\": \"vqk\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"dqa\", \"a\": \"qj\", \"b\": \"norvy\", \"k\": 3 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"vbgvuo\", \"a\": \"u\", \"b\": \"rewjx\", \"k\": 4 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"uw\", \"a\": \"flap\", \"b\": \"lowqe\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"xoi\", \"a\": \"vefut\", \"b\": \"x\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"qzfsogwd\", \"a\": \"qzfs\", \"b\": \"txsdv\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"yalimlim\", \"a\": \"lim\", \"b\": \"bwi\", \"k\": 8 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"mjvosrhrip\", \"a\": \"jzz\", \"b\": \"vo\", \"k\": 4 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"dyswswiz\", \"a\": \"tib\", \"b\": \"dysws\", \"k\": 7 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"ftyhkld\", \"a\": \"tyh\", \"b\": \"znru\", \"k\": 5 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"adubkehe\", \"a\": \"kdtxl\", \"b\": \"dubke\", \"k\": 7 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"svpbvld\", \"a\": \"d\", \"b\": \"svpbv\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"rmiwdb\", \"a\": \"rmiw\", \"b\": \"xgwcv\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"arikarikox\", \"a\": \"o\", \"b\": \"arik\", \"k\": 8 }\nassert my_solution.beautifulIndices(**test_input) == [8]\n\ntest_input = { \"s\": \"cigzky\", \"a\": \"cigz\", \"b\": \"tu\", \"k\": 5 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"hjlllm\", \"a\": \"l\", \"b\": \"h\", \"k\": 6 }\nassert my_solution.beautifulIndices(**test_input) == [2,3,4]\n\ntest_input = { \"s\": \"xiyebjzdbv\", \"a\": \"iqku\", \"b\": \"yebjz\", \"k\": 5 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"qrmogc\", \"a\": \"g\", \"b\": \"rm\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"lagopphhnl\", \"a\": \"gopph\", \"b\": \"hnl\", \"k\": 8 }\nassert my_solution.beautifulIndices(**test_input) == [2]\n\ntest_input = { \"s\": \"xkggxk\", \"a\": \"xk\", \"b\": \"g\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == [0,4]\n\ntest_input = { \"s\": \"cdvr\", \"a\": \"iemxd\", \"b\": \"dt\", \"k\": 4 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"swuaumom\", \"a\": \"swuau\", \"b\": \"m\", \"k\": 8 }\nassert my_solution.beautifulIndices(**test_input) == [0]\n\ntest_input = { \"s\": \"qftqft\", \"a\": \"o\", \"b\": \"qft\", \"k\": 1 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"bc\", \"a\": \"ucfx\", \"b\": \"lzgx\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"egzttzmtot\", \"a\": \"boxwe\", \"b\": \"t\", \"k\": 9 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"agbx\", \"a\": \"a\", \"b\": \"tw\", \"k\": 3 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"fkm\", \"a\": \"gu\", \"b\": \"fkm\", \"k\": 3 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"lt\", \"a\": \"z\", \"b\": \"lt\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"qkddvykd\", \"a\": \"kd\", \"b\": \"tprs\", \"k\": 8 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"vndnqdehvr\", \"a\": \"dnqd\", \"b\": \"ybboz\", \"k\": 8 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"lpnltfewly\", \"a\": \"few\", \"b\": \"l\", \"k\": 6 }\nassert my_solution.beautifulIndices(**test_input) == [5]\n\ntest_input = { \"s\": \"lgioimioim\", \"a\": \"imsfs\", \"b\": \"ioim\", \"k\": 10 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"jhucel\", \"a\": \"iox\", \"b\": \"nx\", \"k\": 5 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"vdgtlvls\", \"a\": \"lvl\", \"b\": \"cu\", \"k\": 4 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"buyryryrjq\", \"a\": \"yr\", \"b\": \"u\", \"k\": 9 }\nassert my_solution.beautifulIndices(**test_input) == [2,4,6]\n\ntest_input = { \"s\": \"fwohvc\", \"a\": \"agagg\", \"b\": \"fwoh\", \"k\": 4 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"tjityoib\", \"a\": \"vh\", \"b\": \"jityo\", \"k\": 3 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"tssjrbpsck\", \"a\": \"ssjr\", \"b\": \"sc\", \"k\": 10 }\nassert my_solution.beautifulIndices(**test_input) == [1]\n\ntest_input = { \"s\": \"aqxv\", \"a\": \"t\", \"b\": \"x\", \"k\": 4 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"zw\", \"a\": \"l\", \"b\": \"c\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"cbccekck\", \"a\": \"c\", \"b\": \"k\", \"k\": 6 }\nassert my_solution.beautifulIndices(**test_input) == [0,2,3,6]\n\ntest_input = { \"s\": \"angkytf\", \"a\": \"ngk\", \"b\": \"ytf\", \"k\": 7 }\nassert my_solution.beautifulIndices(**test_input) == [1]\n\ntest_input = { \"s\": \"oloxjjjqj\", \"a\": \"olox\", \"b\": \"j\", \"k\": 7 }\nassert my_solution.beautifulIndices(**test_input) == [0]\n\ntest_input = { \"s\": \"zbriomnn\", \"a\": \"omn\", \"b\": \"zbr\", \"k\": 6 }\nassert my_solution.beautifulIndices(**test_input) == [4]\n\ntest_input = { \"s\": \"ydmlx\", \"a\": \"tu\", \"b\": \"dml\", \"k\": 5 }\nassert my_solution.beautifulIndices(**test_input) == []\n\ntest_input = { \"s\": \"lnoffflno\", \"a\": \"lno\", \"b\": \"f\", \"k\": 3 }\nassert my_solution.beautifulIndices(**test_input) == [0,6]\n\ntest_input = { \"s\": \"hwayzb\", \"a\": \"fc\", \"b\": \"hway\", \"k\": 2 }\nassert my_solution.beautifulIndices(**test_input) == []", "start_time": 1705199400} +{"task_id": "weekly-contest-379-maximum-area-of-longest-diagonal-rectangle", "url": "https://leetcode.com/problems/maximum-area-of-longest-diagonal-rectangle", "title": "maximum-area-of-longest-diagonal-rectangle", "meta": {"questionId": "3251", "questionFrontendId": "10035", "title": "Maximum Area of Longest Diagonal Rectangle", "titleSlug": "maximum-area-of-longest-diagonal-rectangle", "isPaidOnly": false, "difficulty": "Easy", "likes": 38, "dislikes": 7, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 2D 0-indexed integer array dimensions.\nFor all indices i, 0 <= i < dimensions.length, dimensions[i][0] represents the length and dimensions[i][1] represents the width of the rectangle i.\nReturn the area of the rectangle having the longest diagonal. If there are multiple rectangles with the longest diagonal, return the area of the rectangle having the maximum area.\n\nExample 1:\n\nInput: dimensions = [[9,3],[8,6]]\nOutput: 48\nExplanation: \nFor index = 0, length = 9 and width = 3. Diagonal length = sqrt(9 * 9 + 3 * 3) = sqrt(90) ≈ 9.487.\nFor index = 1, length = 8 and width = 6. Diagonal length = sqrt(8 * 8 + 6 * 6) = sqrt(100) = 10.\nSo, the rectangle at index 1 has a greater diagonal length therefore we return area = 8 * 6 = 48.\n\nExample 2:\n\nInput: dimensions = [[3,4],[4,3]]\nOutput: 12\nExplanation: Length of diagonal is the same for both which is 5, so maximum area = 12.\n\n\nConstraints:\n\n1 <= dimensions.length <= 100\ndimensions[i].length == 2\n1 <= dimensions[i][0], dimensions[i][1] <= 100\n\"\"\"\nclass Solution:\n def areaOfMaxDiagonal(self, dimensions: List[List[int]]) -> int:\n ", "prompt_sft": "You are given a 2D 0-indexed integer array dimensions.\nFor all indices i, 0 <= i < dimensions.length, dimensions[i][0] represents the length and dimensions[i][1] represents the width of the rectangle i.\nReturn the area of the rectangle having the longest diagonal. If there are multiple rectangles with the longest diagonal, return the area of the rectangle having the maximum area.\n\nExample 1:\n\nInput: dimensions = [[9,3],[8,6]]\nOutput: 48\nExplanation: \nFor index = 0, length = 9 and width = 3. Diagonal length = sqrt(9 * 9 + 3 * 3) = sqrt(90) ≈ 9.487.\nFor index = 1, length = 8 and width = 6. Diagonal length = sqrt(8 * 8 + 6 * 6) = sqrt(100) = 10.\nSo, the rectangle at index 1 has a greater diagonal length therefore we return area = 8 * 6 = 48.\n\nExample 2:\n\nInput: dimensions = [[3,4],[4,3]]\nOutput: 12\nExplanation: Length of diagonal is the same for both which is 5, so maximum area = 12.\n\n\nConstraints:\n\n1 <= dimensions.length <= 100\ndimensions[i].length == 2\n1 <= dimensions[i][0], dimensions[i][1] <= 100\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def areaOfMaxDiagonal(self, dimensions: List[List[int]]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"dimensions\": [[9,3],[8,6]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 48\n\ntest_input = { \"dimensions\": [[3,4],[4,3]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 12\n\ntest_input = { \"dimensions\": [[4,10],[4,9],[9,3],[10,8]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 80\n\ntest_input = { \"dimensions\": [[2,6],[5,1],[3,10],[8,4]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 30\n\ntest_input = { \"dimensions\": [[3,7],[2,10],[3,4],[9,9],[5,10]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 81\n\ntest_input = { \"dimensions\": [[10,4]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 40\n\ntest_input = { \"dimensions\": [[9,9],[1,8],[10,5],[2,8],[6,3],[7,1]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 81\n\ntest_input = { \"dimensions\": [[10,3],[5,9],[8,3]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 30\n\ntest_input = { \"dimensions\": [[2,7],[3,2],[3,3],[10,4],[5,3],[8,10],[8,8],[4,7]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 80\n\ntest_input = { \"dimensions\": [[1,10],[3,10],[4,4],[2,6],[6,3],[6,4],[9,1],[6,1],[2,3]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 30\n\ntest_input = { \"dimensions\": [[4,7],[10,10],[3,7],[9,1],[5,7],[3,9],[10,4],[4,8]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 100\n\ntest_input = { \"dimensions\": [[1,1],[6,8],[6,9],[7,2],[6,8],[1,3],[3,1],[1,9]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 54\n\ntest_input = { \"dimensions\": [[6,6],[1,3],[8,10],[10,1],[3,10],[7,7],[10,8]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 80\n\ntest_input = { \"dimensions\": [[6,5],[8,6],[2,10],[8,1],[9,2],[3,5],[3,5]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 20\n\ntest_input = { \"dimensions\": [[5,1],[4,9],[9,1],[5,8],[2,9],[3,2],[10,10],[5,2]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 100\n\ntest_input = { \"dimensions\": [[8,3],[9,10],[7,7],[6,5],[6,9],[9,10],[5,10]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 90\n\ntest_input = { \"dimensions\": [[6,10],[8,6],[10,1],[7,10],[10,10],[9,5]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 100\n\ntest_input = { \"dimensions\": [[9,5],[9,2],[2,2],[8,9],[5,7],[8,10],[3,5]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 80\n\ntest_input = { \"dimensions\": [[3,9],[9,5]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 45\n\ntest_input = { \"dimensions\": [[10,10],[5,5],[3,2],[2,6],[3,1],[10,7],[4,8],[7,9],[9,9],[1,2]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 100\n\ntest_input = { \"dimensions\": [[2,3],[3,5],[2,1]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 15\n\ntest_input = { \"dimensions\": [[4,4],[7,7]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 49\n\ntest_input = { \"dimensions\": [[7,5],[9,6],[9,4],[5,7],[2,6],[10,3],[9,9],[9,4],[8,2]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 81\n\ntest_input = { \"dimensions\": [[5,1],[9,1],[7,1],[7,1],[3,1],[10,7],[9,1],[7,2],[4,6],[3,6]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 70\n\ntest_input = { \"dimensions\": [[8,4],[7,4],[1,5],[7,8],[5,6],[5,2]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 56\n\ntest_input = { \"dimensions\": [[5,10],[3,7],[8,6],[8,6],[5,9],[10,5],[7,8],[1,9],[2,5],[6,6]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 50\n\ntest_input = { \"dimensions\": [[9,4]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 36\n\ntest_input = { \"dimensions\": [[7,6],[2,8],[9,6],[1,10],[5,1]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 54\n\ntest_input = { \"dimensions\": [[4,2],[1,6],[2,1],[4,10],[10,1],[7,5],[8,3]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 40\n\ntest_input = { \"dimensions\": [[1,4]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 4\n\ntest_input = { \"dimensions\": [[9,4],[6,7]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 36\n\ntest_input = { \"dimensions\": [[7,5]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 35\n\ntest_input = { \"dimensions\": [[1,9],[9,7],[8,4],[6,6],[7,8],[4,6],[7,4],[9,9],[9,8],[8,8]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 81\n\ntest_input = { \"dimensions\": [[3,8],[6,3],[5,2],[3,7],[1,3],[9,8],[4,2],[3,8]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 72\n\ntest_input = { \"dimensions\": [[5,4],[2,4],[8,5],[8,4],[1,2],[6,4]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 40\n\ntest_input = { \"dimensions\": [[7,2],[4,6]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 14\n\ntest_input = { \"dimensions\": [[8,10],[5,2],[4,9]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 80\n\ntest_input = { \"dimensions\": [[9,2],[5,6],[4,2]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 18\n\ntest_input = { \"dimensions\": [[3,8],[2,9],[7,7],[1,5],[1,1]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 49\n\ntest_input = { \"dimensions\": [[6,2],[8,2],[6,8],[7,6],[1,2],[6,8],[10,9],[2,8]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 90\n\ntest_input = { \"dimensions\": [[3,8],[4,1],[5,2],[2,6],[4,9],[10,6],[6,10],[3,4],[6,6],[4,3]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 60\n\ntest_input = { \"dimensions\": [[5,5],[3,8],[2,8]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 24\n\ntest_input = { \"dimensions\": [[8,1],[5,8],[3,8]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 40\n\ntest_input = { \"dimensions\": [[2,8],[8,1],[7,10],[5,7],[2,4],[3,10],[2,10],[7,10],[5,6]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 70\n\ntest_input = { \"dimensions\": [[3,10],[1,3],[10,5],[5,9]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 50\n\ntest_input = { \"dimensions\": [[10,6],[4,3]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 60\n\ntest_input = { \"dimensions\": [[7,8],[8,6],[10,10],[6,7],[7,10]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 100\n\ntest_input = { \"dimensions\": [[7,2],[7,3],[4,6],[4,4],[7,8],[2,4]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 56\n\ntest_input = { \"dimensions\": [[4,7],[3,1],[1,10],[4,2],[4,10],[8,8]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 64\n\ntest_input = { \"dimensions\": [[1,8],[4,3],[7,7],[10,6],[5,5],[1,3],[9,1],[8,3],[3,2],[5,8]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 60\n\ntest_input = { \"dimensions\": [[6,7],[1,7],[5,10],[10,1],[8,3]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 50\n\ntest_input = { \"dimensions\": [[3,5],[2,7],[4,4],[4,9],[7,6],[2,4],[5,2]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 36\n\ntest_input = { \"dimensions\": [[8,8],[6,10],[6,6]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 60\n\ntest_input = { \"dimensions\": [[10,2],[3,3],[5,9],[3,7]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 45\n\ntest_input = { \"dimensions\": [[4,3],[4,1],[8,9],[10,1],[2,7],[7,7],[9,3],[8,6],[1,5],[8,3]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 72\n\ntest_input = { \"dimensions\": [[6,8],[2,3],[4,9],[1,1]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 48\n\ntest_input = { \"dimensions\": [[1,6],[2,10],[1,5],[9,3],[9,1],[2,2]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 20\n\ntest_input = { \"dimensions\": [[6,5],[7,10],[1,2],[10,3],[4,2],[4,8],[5,10],[5,9]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 70\n\ntest_input = { \"dimensions\": [[1,2],[1,2],[2,4],[9,9],[3,8],[3,9],[2,3]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 81\n\ntest_input = { \"dimensions\": [[4,4],[6,1],[1,10],[10,7],[10,5]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 70\n\ntest_input = { \"dimensions\": [[3,2],[2,8],[10,9],[9,8],[2,2],[9,1]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 90\n\ntest_input = { \"dimensions\": [[4,10],[9,6],[4,10],[6,7],[2,3],[7,9],[9,2],[1,9]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 63\n\ntest_input = { \"dimensions\": [[7,4],[10,2],[10,8],[4,9],[4,9],[10,3],[5,4],[4,5],[10,6],[3,9]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 80\n\ntest_input = { \"dimensions\": [[2,5],[7,4],[5,3],[2,4],[3,10],[3,5],[4,5],[4,4],[6,5]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 30\n\ntest_input = { \"dimensions\": [[3,2],[7,10],[8,10],[7,4],[6,1]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 80\n\ntest_input = { \"dimensions\": [[3,8],[4,5],[3,8]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 24\n\ntest_input = { \"dimensions\": [[6,8],[9,9],[1,7]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 81\n\ntest_input = { \"dimensions\": [[8,1],[7,5]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 35\n\ntest_input = { \"dimensions\": [[10,6],[5,1],[9,5],[5,7],[5,8],[6,5],[8,3]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 60\n\ntest_input = { \"dimensions\": [[8,6]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 48\n\ntest_input = { \"dimensions\": [[5,2],[5,9],[9,5],[5,5],[8,6]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 45\n\ntest_input = { \"dimensions\": [[7,8],[9,9],[3,5],[8,1],[1,3],[8,2],[8,6]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 81\n\ntest_input = { \"dimensions\": [[3,10],[6,8],[4,5],[8,1],[7,2],[9,8],[3,7],[3,3],[9,10]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 90\n\ntest_input = { \"dimensions\": [[1,1],[8,7],[4,6],[5,2],[5,9]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 56\n\ntest_input = { \"dimensions\": [[6,2],[8,4],[8,6],[2,10],[6,1],[9,8],[10,8],[10,10],[5,9]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 100\n\ntest_input = { \"dimensions\": [[10,2],[9,7],[4,2],[8,6],[9,10],[10,7],[7,5],[5,10],[5,9]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 90\n\ntest_input = { \"dimensions\": [[1,4],[7,2],[2,6],[7,7]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 49\n\ntest_input = { \"dimensions\": [[2,5],[10,10],[4,4]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 100\n\ntest_input = { \"dimensions\": [[2,10],[10,4],[3,9],[6,10],[2,10],[10,1],[4,1]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 60\n\ntest_input = { \"dimensions\": [[3,6],[5,4],[9,5],[6,2],[4,4],[7,2],[6,7]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 45\n\ntest_input = { \"dimensions\": [[1,1],[1,7]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 7\n\ntest_input = { \"dimensions\": [[1,2],[8,8]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 64\n\ntest_input = { \"dimensions\": [[3,7]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 21\n\ntest_input = { \"dimensions\": [[6,7],[1,5],[10,9],[10,2]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 90\n\ntest_input = { \"dimensions\": [[7,8]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 56\n\ntest_input = { \"dimensions\": [[2,6],[10,3],[10,5],[1,9],[5,2],[9,10],[7,2],[7,7],[1,10]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 90\n\ntest_input = { \"dimensions\": [[3,4],[8,2],[9,3],[2,9],[6,5],[10,5],[4,1],[8,7],[3,9]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 50\n\ntest_input = { \"dimensions\": [[7,6],[6,8],[5,7],[1,1],[4,5],[6,10],[9,3],[4,4]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 60\n\ntest_input = { \"dimensions\": [[1,3],[2,4],[4,9],[10,9],[3,9],[7,5],[2,3],[10,7],[2,3],[1,5]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 90\n\ntest_input = { \"dimensions\": [[1,8],[6,10],[4,8],[3,8],[4,3]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 60\n\ntest_input = { \"dimensions\": [[6,5],[3,10],[8,7],[10,10],[2,8],[5,8],[10,8],[9,10],[2,8],[8,9]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 100\n\ntest_input = { \"dimensions\": [[1,6],[8,3],[6,1],[2,10],[2,5],[3,8]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 20\n\ntest_input = { \"dimensions\": [[7,2],[3,8],[10,10],[7,1],[6,8],[6,7],[10,6],[4,6],[5,7],[10,4]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 100\n\ntest_input = { \"dimensions\": [[9,6]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 54\n\ntest_input = { \"dimensions\": [[8,2],[7,6],[1,4],[1,6],[4,8],[10,9],[9,4],[1,5]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 90\n\ntest_input = { \"dimensions\": [[7,3],[2,5],[7,1],[10,7],[7,4],[8,1]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 70\n\ntest_input = { \"dimensions\": [[9,2]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 18\n\ntest_input = { \"dimensions\": [[9,2],[7,2],[2,7]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 18\n\ntest_input = { \"dimensions\": [[2,8],[10,6],[8,10],[9,9]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 80\n\ntest_input = { \"dimensions\": [[3,3]] }\nassert my_solution.areaOfMaxDiagonal(**test_input) == 9", "start_time": 1704594600} +{"task_id": "weekly-contest-379-minimum-moves-to-capture-the-queen", "url": "https://leetcode.com/problems/minimum-moves-to-capture-the-queen", "title": "minimum-moves-to-capture-the-queen", "meta": {"questionId": "3270", "questionFrontendId": "10036", "title": "Minimum Moves to Capture The Queen", "titleSlug": "minimum-moves-to-capture-the-queen", "isPaidOnly": false, "difficulty": "Medium", "likes": 71, "dislikes": 115, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nThere is a 1-indexed 8 x 8 chessboard containing 3 pieces.\nYou are given 6 integers a, b, c, d, e, and f where:\n\n(a, b) denotes the position of the white rook.\n(c, d) denotes the position of the white bishop.\n(e, f) denotes the position of the black queen.\n\nGiven that you can only move the white pieces, return the minimum number of moves required to capture the black queen.\nNote that:\n\nRooks can move any number of squares either vertically or horizontally, but cannot jump over other pieces.\nBishops can move any number of squares diagonally, but cannot jump over other pieces.\nA rook or a bishop can capture the queen if it is located in a square that they can move to.\nThe queen does not move.\n\n\nExample 1:\n\n\nInput: a = 1, b = 1, c = 8, d = 8, e = 2, f = 3\nOutput: 2\nExplanation: We can capture the black queen in two moves by moving the white rook to (1, 3) then to (2, 3).\nIt is impossible to capture the black queen in less than two moves since it is not being attacked by any of the pieces at the beginning.\n\nExample 2:\n\n\nInput: a = 5, b = 3, c = 3, d = 4, e = 5, f = 2\nOutput: 1\nExplanation: We can capture the black queen in a single move by doing one of the following: \n- Move the white rook to (5, 2).\n- Move the white bishop to (5, 2).\n\n\nConstraints:\n\n1 <= a, b, c, d, e, f <= 8\nNo two pieces are on the same square.\n\"\"\"\nclass Solution:\n def minMovesToCaptureTheQueen(self, a: int, b: int, c: int, d: int, e: int, f: int) -> int:\n ", "prompt_sft": "There is a 1-indexed 8 x 8 chessboard containing 3 pieces.\nYou are given 6 integers a, b, c, d, e, and f where:\n\n(a, b) denotes the position of the white rook.\n(c, d) denotes the position of the white bishop.\n(e, f) denotes the position of the black queen.\n\nGiven that you can only move the white pieces, return the minimum number of moves required to capture the black queen.\nNote that:\n\nRooks can move any number of squares either vertically or horizontally, but cannot jump over other pieces.\nBishops can move any number of squares diagonally, but cannot jump over other pieces.\nA rook or a bishop can capture the queen if it is located in a square that they can move to.\nThe queen does not move.\n\n\nExample 1:\n\n\nInput: a = 1, b = 1, c = 8, d = 8, e = 2, f = 3\nOutput: 2\nExplanation: We can capture the black queen in two moves by moving the white rook to (1, 3) then to (2, 3).\nIt is impossible to capture the black queen in less than two moves since it is not being attacked by any of the pieces at the beginning.\n\nExample 2:\n\n\nInput: a = 5, b = 3, c = 3, d = 4, e = 5, f = 2\nOutput: 1\nExplanation: We can capture the black queen in a single move by doing one of the following: \n- Move the white rook to (5, 2).\n- Move the white bishop to (5, 2).\n\n\nConstraints:\n\n1 <= a, b, c, d, e, f <= 8\nNo two pieces are on the same square.\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def minMovesToCaptureTheQueen(self, a: int, b: int, c: int, d: int, e: int, f: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"a\": 1, \"b\": 1, \"c\": 8, \"d\": 8, \"e\": 2, \"f\": 3 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 5, \"b\": 3, \"c\": 3, \"d\": 4, \"e\": 5, \"f\": 2 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 4, \"b\": 3, \"c\": 3, \"d\": 4, \"e\": 5, \"f\": 2 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 1, \"b\": 1, \"c\": 1, \"d\": 4, \"e\": 1, \"f\": 8 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 4, \"b\": 3, \"c\": 3, \"d\": 4, \"e\": 2, \"f\": 5 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 8, \"b\": 4, \"c\": 7, \"d\": 5, \"e\": 5, \"f\": 5 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 1, \"b\": 8, \"c\": 4, \"d\": 3, \"e\": 2, \"f\": 7 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 1, \"b\": 6, \"c\": 3, \"d\": 3, \"e\": 5, \"f\": 6 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 5, \"b\": 3, \"c\": 6, \"d\": 6, \"e\": 6, \"f\": 4 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 5, \"b\": 1, \"c\": 6, \"d\": 6, \"e\": 2, \"f\": 7 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 8, \"b\": 4, \"c\": 8, \"d\": 8, \"e\": 7, \"f\": 7 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 5, \"b\": 1, \"c\": 6, \"d\": 5, \"e\": 3, \"f\": 7 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 5, \"b\": 2, \"c\": 8, \"d\": 6, \"e\": 7, \"f\": 4 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 1, \"b\": 1, \"c\": 8, \"d\": 2, \"e\": 4, \"f\": 1 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 3, \"b\": 1, \"c\": 1, \"d\": 1, \"e\": 2, \"f\": 5 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 8, \"b\": 5, \"c\": 2, \"d\": 4, \"e\": 5, \"f\": 7 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 8, \"b\": 1, \"c\": 5, \"d\": 8, \"e\": 1, \"f\": 7 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 4, \"b\": 6, \"c\": 6, \"d\": 2, \"e\": 1, \"f\": 4 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 7, \"b\": 5, \"c\": 7, \"d\": 6, \"e\": 2, \"f\": 8 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 8, \"b\": 6, \"c\": 3, \"d\": 2, \"e\": 6, \"f\": 8 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 3, \"b\": 3, \"c\": 8, \"d\": 1, \"e\": 2, \"f\": 5 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 4, \"b\": 5, \"c\": 6, \"d\": 1, \"e\": 4, \"f\": 7 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 7, \"b\": 2, \"c\": 2, \"d\": 8, \"e\": 7, \"f\": 3 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 3, \"b\": 8, \"c\": 2, \"d\": 7, \"e\": 1, \"f\": 4 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 3, \"b\": 5, \"c\": 5, \"d\": 3, \"e\": 1, \"f\": 8 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 2, \"b\": 2, \"c\": 7, \"d\": 4, \"e\": 3, \"f\": 1 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 4, \"b\": 3, \"c\": 1, \"d\": 5, \"e\": 5, \"f\": 3 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 7, \"b\": 5, \"c\": 2, \"d\": 5, \"e\": 6, \"f\": 3 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 1, \"b\": 7, \"c\": 8, \"d\": 1, \"e\": 3, \"f\": 4 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 8, \"b\": 6, \"c\": 6, \"d\": 4, \"e\": 1, \"f\": 2 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 7, \"b\": 8, \"c\": 4, \"d\": 4, \"e\": 3, \"f\": 6 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 8, \"b\": 4, \"c\": 7, \"d\": 7, \"e\": 4, \"f\": 4 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 5, \"b\": 7, \"c\": 4, \"d\": 2, \"e\": 3, \"f\": 8 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 6, \"b\": 1, \"c\": 7, \"d\": 8, \"e\": 8, \"f\": 7 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 3, \"b\": 7, \"c\": 7, \"d\": 6, \"e\": 7, \"f\": 4 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 7, \"b\": 3, \"c\": 6, \"d\": 4, \"e\": 6, \"f\": 7 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 5, \"b\": 7, \"c\": 1, \"d\": 1, \"e\": 5, \"f\": 6 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 6, \"b\": 8, \"c\": 5, \"d\": 8, \"e\": 5, \"f\": 3 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 4, \"b\": 2, \"c\": 3, \"d\": 7, \"e\": 6, \"f\": 1 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 3, \"b\": 2, \"c\": 6, \"d\": 1, \"e\": 6, \"f\": 2 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 5, \"b\": 4, \"c\": 6, \"d\": 7, \"e\": 1, \"f\": 8 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 7, \"b\": 6, \"c\": 2, \"d\": 3, \"e\": 3, \"f\": 4 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 7, \"b\": 6, \"c\": 2, \"d\": 1, \"e\": 2, \"f\": 6 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 5, \"b\": 8, \"c\": 6, \"d\": 5, \"e\": 6, \"f\": 1 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 6, \"b\": 2, \"c\": 6, \"d\": 7, \"e\": 5, \"f\": 4 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 7, \"b\": 5, \"c\": 4, \"d\": 4, \"e\": 7, \"f\": 4 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 6, \"b\": 1, \"c\": 4, \"d\": 4, \"e\": 2, \"f\": 2 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 3, \"b\": 4, \"c\": 1, \"d\": 8, \"e\": 3, \"f\": 7 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 7, \"b\": 7, \"c\": 1, \"d\": 6, \"e\": 3, \"f\": 1 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 6, \"b\": 8, \"c\": 2, \"d\": 2, \"e\": 3, \"f\": 5 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 5, \"b\": 5, \"c\": 3, \"d\": 7, \"e\": 5, \"f\": 3 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 7, \"b\": 3, \"c\": 5, \"d\": 3, \"e\": 8, \"f\": 5 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 7, \"b\": 4, \"c\": 1, \"d\": 4, \"e\": 7, \"f\": 8 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 6, \"b\": 3, \"c\": 7, \"d\": 3, \"e\": 4, \"f\": 4 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 1, \"b\": 4, \"c\": 6, \"d\": 7, \"e\": 4, \"f\": 4 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 4, \"b\": 5, \"c\": 6, \"d\": 8, \"e\": 2, \"f\": 1 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 5, \"b\": 6, \"c\": 5, \"d\": 7, \"e\": 8, \"f\": 3 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 5, \"b\": 1, \"c\": 8, \"d\": 2, \"e\": 1, \"f\": 3 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 1, \"b\": 2, \"c\": 8, \"d\": 3, \"e\": 2, \"f\": 2 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 1, \"b\": 7, \"c\": 5, \"d\": 5, \"e\": 4, \"f\": 3 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 4, \"b\": 3, \"c\": 7, \"d\": 8, \"e\": 1, \"f\": 5 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 8, \"b\": 7, \"c\": 6, \"d\": 8, \"e\": 6, \"f\": 1 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 4, \"b\": 3, \"c\": 4, \"d\": 7, \"e\": 7, \"f\": 6 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 8, \"b\": 4, \"c\": 6, \"d\": 6, \"e\": 2, \"f\": 1 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 8, \"b\": 2, \"c\": 6, \"d\": 4, \"e\": 1, \"f\": 4 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 3, \"b\": 5, \"c\": 3, \"d\": 2, \"e\": 1, \"f\": 4 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 3, \"b\": 6, \"c\": 1, \"d\": 3, \"e\": 3, \"f\": 7 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 1, \"b\": 1, \"c\": 7, \"d\": 6, \"e\": 4, \"f\": 3 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 1, \"b\": 8, \"c\": 7, \"d\": 2, \"e\": 6, \"f\": 1 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 5, \"b\": 8, \"c\": 4, \"d\": 5, \"e\": 7, \"f\": 4 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 8, \"b\": 3, \"c\": 8, \"d\": 8, \"e\": 5, \"f\": 3 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 7, \"b\": 2, \"c\": 8, \"d\": 1, \"e\": 4, \"f\": 3 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 3, \"b\": 5, \"c\": 8, \"d\": 7, \"e\": 6, \"f\": 1 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 5, \"b\": 5, \"c\": 2, \"d\": 2, \"e\": 1, \"f\": 1 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 1, \"b\": 8, \"c\": 8, \"d\": 4, \"e\": 4, \"f\": 7 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 3, \"b\": 6, \"c\": 7, \"d\": 6, \"e\": 8, \"f\": 8 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 5, \"b\": 6, \"c\": 3, \"d\": 7, \"e\": 3, \"f\": 6 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 1, \"b\": 5, \"c\": 3, \"d\": 4, \"e\": 7, \"f\": 4 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 5, \"b\": 6, \"c\": 2, \"d\": 2, \"e\": 5, \"f\": 8 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 7, \"b\": 3, \"c\": 2, \"d\": 6, \"e\": 3, \"f\": 4 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 5, \"b\": 4, \"c\": 6, \"d\": 5, \"e\": 5, \"f\": 8 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 1, \"b\": 1, \"c\": 2, \"d\": 4, \"e\": 5, \"f\": 4 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 4, \"b\": 5, \"c\": 5, \"d\": 4, \"e\": 2, \"f\": 4 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 6, \"b\": 5, \"c\": 6, \"d\": 2, \"e\": 2, \"f\": 2 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 1, \"b\": 5, \"c\": 4, \"d\": 2, \"e\": 8, \"f\": 1 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 1, \"b\": 1, \"c\": 2, \"d\": 5, \"e\": 8, \"f\": 1 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 4, \"b\": 8, \"c\": 3, \"d\": 8, \"e\": 8, \"f\": 5 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 1, \"b\": 8, \"c\": 4, \"d\": 7, \"e\": 5, \"f\": 6 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 5, \"b\": 5, \"c\": 3, \"d\": 6, \"e\": 8, \"f\": 8 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 1, \"b\": 2, \"c\": 3, \"d\": 1, \"e\": 2, \"f\": 4 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 1, \"b\": 8, \"c\": 6, \"d\": 3, \"e\": 2, \"f\": 8 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 6, \"b\": 1, \"c\": 8, \"d\": 8, \"e\": 7, \"f\": 3 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 7, \"b\": 8, \"c\": 6, \"d\": 1, \"e\": 4, \"f\": 2 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 1, \"b\": 6, \"c\": 4, \"d\": 2, \"e\": 8, \"f\": 5 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 1, \"b\": 4, \"c\": 2, \"d\": 5, \"e\": 5, \"f\": 4 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 1\n\ntest_input = { \"a\": 4, \"b\": 4, \"c\": 3, \"d\": 2, \"e\": 6, \"f\": 7 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 8, \"b\": 3, \"c\": 6, \"d\": 7, \"e\": 4, \"f\": 6 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 2, \"b\": 5, \"c\": 1, \"d\": 1, \"e\": 8, \"f\": 4 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 7, \"b\": 8, \"c\": 1, \"d\": 4, \"e\": 5, \"f\": 1 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2\n\ntest_input = { \"a\": 5, \"b\": 5, \"c\": 2, \"d\": 1, \"e\": 1, \"f\": 1 }\nassert my_solution.minMovesToCaptureTheQueen(**test_input) == 2", "start_time": 1704594600} +{"task_id": "weekly-contest-379-maximum-size-of-a-set-after-removals", "url": "https://leetcode.com/problems/maximum-size-of-a-set-after-removals", "title": "maximum-size-of-a-set-after-removals", "meta": {"questionId": "3228", "questionFrontendId": "10037", "title": "Maximum Size of a Set After Removals", "titleSlug": "maximum-size-of-a-set-after-removals", "isPaidOnly": false, "difficulty": "Medium", "likes": 116, "dislikes": 11, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given two 0-indexed integer arrays nums1 and nums2 of even length n.\nYou must remove n / 2 elements from nums1 and n / 2 elements from nums2. After the removals, you insert the remaining elements of nums1 and nums2 into a set s.\nReturn the maximum possible size of the set s.\n\nExample 1:\n\nInput: nums1 = [1,2,1,2], nums2 = [1,1,1,1]\nOutput: 2\nExplanation: We remove two occurences of 1 from nums1 and nums2. After the removals, the arrays become equal to nums1 = [2,2] and nums2 = [1,1]. Therefore, s = {1,2}.\nIt can be shown that 2 is the maximum possible size of the set s after the removals.\n\nExample 2:\n\nInput: nums1 = [1,2,3,4,5,6], nums2 = [2,3,2,3,2,3]\nOutput: 5\nExplanation: We remove 2, 3, and 6 from nums1, as well as 2 and two occurrences of 3 from nums2. After the removals, the arrays become equal to nums1 = [1,4,5] and nums2 = [2,3,2]. Therefore, s = {1,2,3,4,5}.\nIt can be shown that 5 is the maximum possible size of the set s after the removals.\n\nExample 3:\n\nInput: nums1 = [1,1,2,2,3,3], nums2 = [4,4,5,5,6,6]\nOutput: 6\nExplanation: We remove 1, 2, and 3 from nums1, as well as 4, 5, and 6 from nums2. After the removals, the arrays become equal to nums1 = [1,2,3] and nums2 = [4,5,6]. Therefore, s = {1,2,3,4,5,6}.\nIt can be shown that 6 is the maximum possible size of the set s after the removals.\n\n\nConstraints:\n\nn == nums1.length == nums2.length\n1 <= n <= 2 * 104\nn is even.\n1 <= nums1[i], nums2[i] <= 109\n\"\"\"\nclass Solution:\n def maximumSetSize(self, nums1: List[int], nums2: List[int]) -> int:\n ", "prompt_sft": "You are given two 0-indexed integer arrays nums1 and nums2 of even length n.\nYou must remove n / 2 elements from nums1 and n / 2 elements from nums2. After the removals, you insert the remaining elements of nums1 and nums2 into a set s.\nReturn the maximum possible size of the set s.\n\nExample 1:\n\nInput: nums1 = [1,2,1,2], nums2 = [1,1,1,1]\nOutput: 2\nExplanation: We remove two occurences of 1 from nums1 and nums2. After the removals, the arrays become equal to nums1 = [2,2] and nums2 = [1,1]. Therefore, s = {1,2}.\nIt can be shown that 2 is the maximum possible size of the set s after the removals.\n\nExample 2:\n\nInput: nums1 = [1,2,3,4,5,6], nums2 = [2,3,2,3,2,3]\nOutput: 5\nExplanation: We remove 2, 3, and 6 from nums1, as well as 2 and two occurrences of 3 from nums2. After the removals, the arrays become equal to nums1 = [1,4,5] and nums2 = [2,3,2]. Therefore, s = {1,2,3,4,5}.\nIt can be shown that 5 is the maximum possible size of the set s after the removals.\n\nExample 3:\n\nInput: nums1 = [1,1,2,2,3,3], nums2 = [4,4,5,5,6,6]\nOutput: 6\nExplanation: We remove 1, 2, and 3 from nums1, as well as 4, 5, and 6 from nums2. After the removals, the arrays become equal to nums1 = [1,2,3] and nums2 = [4,5,6]. Therefore, s = {1,2,3,4,5,6}.\nIt can be shown that 6 is the maximum possible size of the set s after the removals.\n\n\nConstraints:\n\nn == nums1.length == nums2.length\n1 <= n <= 2 * 104\nn is even.\n1 <= nums1[i], nums2[i] <= 109\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def maximumSetSize(self, nums1: List[int], nums2: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums1\": [1,2,1,2], \"nums2\": [1,1,1,1] }\nassert my_solution.maximumSetSize(**test_input) == 2\n\ntest_input = { \"nums1\": [1,2,3,4,5,6], \"nums2\": [2,3,2,3,2,3] }\nassert my_solution.maximumSetSize(**test_input) == 5\n\ntest_input = { \"nums1\": [1,1,2,2,3,3], \"nums2\": [4,4,5,5,6,6] }\nassert my_solution.maximumSetSize(**test_input) == 6\n\ntest_input = { \"nums1\": [1,2,1,1], \"nums2\": [1,2,3,4] }\nassert my_solution.maximumSetSize(**test_input) == 4\n\ntest_input = { \"nums1\": [1,1,1,1], \"nums2\": [12,23,41,9] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [12,23,41,9], \"nums2\": [1,1,1,1] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [9,8,4,7], \"nums2\": [5,5,9,5] }\nassert my_solution.maximumSetSize(**test_input) == 4\n\ntest_input = { \"nums1\": [8,9], \"nums2\": [4,3] }\nassert my_solution.maximumSetSize(**test_input) == 2\n\ntest_input = { \"nums1\": [7,1], \"nums2\": [6,10] }\nassert my_solution.maximumSetSize(**test_input) == 2\n\ntest_input = { \"nums1\": [10,3], \"nums2\": [5,6] }\nassert my_solution.maximumSetSize(**test_input) == 2\n\ntest_input = { \"nums1\": [3,6], \"nums2\": [6,6] }\nassert my_solution.maximumSetSize(**test_input) == 2\n\ntest_input = { \"nums1\": [5,1], \"nums2\": [6,6] }\nassert my_solution.maximumSetSize(**test_input) == 2\n\ntest_input = { \"nums1\": [10,7], \"nums2\": [8,4] }\nassert my_solution.maximumSetSize(**test_input) == 2\n\ntest_input = { \"nums1\": [10,8,7,9], \"nums2\": [7,9,9,5] }\nassert my_solution.maximumSetSize(**test_input) == 4\n\ntest_input = { \"nums1\": [1,10,6,5], \"nums2\": [3,7,10,10] }\nassert my_solution.maximumSetSize(**test_input) == 4\n\ntest_input = { \"nums1\": [5,2,8,6], \"nums2\": [7,4,1,1] }\nassert my_solution.maximumSetSize(**test_input) == 4\n\ntest_input = { \"nums1\": [2,4,1,4], \"nums2\": [10,2,4,10] }\nassert my_solution.maximumSetSize(**test_input) == 4\n\ntest_input = { \"nums1\": [5,7], \"nums2\": [3,1] }\nassert my_solution.maximumSetSize(**test_input) == 2\n\ntest_input = { \"nums1\": [1,10,1,2], \"nums2\": [9,5,8,5] }\nassert my_solution.maximumSetSize(**test_input) == 4\n\ntest_input = { \"nums1\": [9,4], \"nums2\": [5,7] }\nassert my_solution.maximumSetSize(**test_input) == 2\n\ntest_input = { \"nums1\": [1,5,10,8], \"nums2\": [1,7,4,10] }\nassert my_solution.maximumSetSize(**test_input) == 4\n\ntest_input = { \"nums1\": [6,6,2,9], \"nums2\": [1,4,10,7] }\nassert my_solution.maximumSetSize(**test_input) == 4\n\ntest_input = { \"nums1\": [7,10], \"nums2\": [6,10] }\nassert my_solution.maximumSetSize(**test_input) == 2\n\ntest_input = { \"nums1\": [8,8], \"nums2\": [6,3] }\nassert my_solution.maximumSetSize(**test_input) == 2\n\ntest_input = { \"nums1\": [6,8], \"nums2\": [9,3] }\nassert my_solution.maximumSetSize(**test_input) == 2\n\ntest_input = { \"nums1\": [3,8,1,9], \"nums2\": [2,5,4,5] }\nassert my_solution.maximumSetSize(**test_input) == 4\n\ntest_input = { \"nums1\": [6,1,4,7], \"nums2\": [10,7,2,2] }\nassert my_solution.maximumSetSize(**test_input) == 4\n\ntest_input = { \"nums1\": [8,7,9,3], \"nums2\": [10,3,8,2] }\nassert my_solution.maximumSetSize(**test_input) == 4\n\ntest_input = { \"nums1\": [1,4,5,9], \"nums2\": [2,5,2,7] }\nassert my_solution.maximumSetSize(**test_input) == 4\n\ntest_input = { \"nums1\": [3,5], \"nums2\": [5,3] }\nassert my_solution.maximumSetSize(**test_input) == 2\n\ntest_input = { \"nums1\": [1,10,8,2], \"nums2\": [2,9,10,7] }\nassert my_solution.maximumSetSize(**test_input) == 4\n\ntest_input = { \"nums1\": [3,9], \"nums2\": [1,4] }\nassert my_solution.maximumSetSize(**test_input) == 2\n\ntest_input = { \"nums1\": [1,5], \"nums2\": [10,5] }\nassert my_solution.maximumSetSize(**test_input) == 2\n\ntest_input = { \"nums1\": [7,5], \"nums2\": [2,10] }\nassert my_solution.maximumSetSize(**test_input) == 2\n\ntest_input = { \"nums1\": [6,10], \"nums2\": [3,1] }\nassert my_solution.maximumSetSize(**test_input) == 2\n\ntest_input = { \"nums1\": [9,8,1,3], \"nums2\": [4,9,8,6] }\nassert my_solution.maximumSetSize(**test_input) == 4\n\ntest_input = { \"nums1\": [4,1], \"nums2\": [9,9] }\nassert my_solution.maximumSetSize(**test_input) == 2\n\ntest_input = { \"nums1\": [10,7], \"nums2\": [10,8] }\nassert my_solution.maximumSetSize(**test_input) == 2\n\ntest_input = { \"nums1\": [4,4,3,9], \"nums2\": [6,8,4,7] }\nassert my_solution.maximumSetSize(**test_input) == 4\n\ntest_input = { \"nums1\": [4,10,4,9], \"nums2\": [5,7,4,2] }\nassert my_solution.maximumSetSize(**test_input) == 4\n\ntest_input = { \"nums1\": [8,6], \"nums2\": [1,7] }\nassert my_solution.maximumSetSize(**test_input) == 2\n\ntest_input = { \"nums1\": [9,8,10,7], \"nums2\": [3,7,7,6] }\nassert my_solution.maximumSetSize(**test_input) == 4\n\ntest_input = { \"nums1\": [4,10,9,10], \"nums2\": [9,7,3,6] }\nassert my_solution.maximumSetSize(**test_input) == 4\n\ntest_input = { \"nums1\": [6,7], \"nums2\": [5,7] }\nassert my_solution.maximumSetSize(**test_input) == 2\n\ntest_input = { \"nums1\": [1,1,10,5], \"nums2\": [6,6,8,5] }\nassert my_solution.maximumSetSize(**test_input) == 4\n\ntest_input = { \"nums1\": [5,3,4,2], \"nums2\": [10,3,7,10] }\nassert my_solution.maximumSetSize(**test_input) == 4\n\ntest_input = { \"nums1\": [1,3], \"nums2\": [9,2] }\nassert my_solution.maximumSetSize(**test_input) == 2\n\ntest_input = { \"nums1\": [6,1,6,2], \"nums2\": [5,4,6,7] }\nassert my_solution.maximumSetSize(**test_input) == 4\n\ntest_input = { \"nums1\": [9,9], \"nums2\": [8,7] }\nassert my_solution.maximumSetSize(**test_input) == 2\n\ntest_input = { \"nums1\": [6,2,9,3], \"nums2\": [10,3,4,7] }\nassert my_solution.maximumSetSize(**test_input) == 4\n\ntest_input = { \"nums1\": [6,2,10,1], \"nums2\": [9,2,6,5] }\nassert my_solution.maximumSetSize(**test_input) == 4\n\ntest_input = { \"nums1\": [6,5,6,1], \"nums2\": [6,2,6,9] }\nassert my_solution.maximumSetSize(**test_input) == 4\n\ntest_input = { \"nums1\": [10,5,4,7], \"nums2\": [5,4,4,9] }\nassert my_solution.maximumSetSize(**test_input) == 4\n\ntest_input = { \"nums1\": [7,10,4,6], \"nums2\": [1,4,4,2] }\nassert my_solution.maximumSetSize(**test_input) == 4\n\ntest_input = { \"nums1\": [3,4], \"nums2\": [1,8] }\nassert my_solution.maximumSetSize(**test_input) == 2\n\ntest_input = { \"nums1\": [7,7], \"nums2\": [7,1] }\nassert my_solution.maximumSetSize(**test_input) == 2\n\ntest_input = { \"nums1\": [1,1,2,2,1,1], \"nums2\": [1,3,2,2,2,1] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [3,3,3,2,1,2,1,2], \"nums2\": [1,2,3,2,2,3,3,1] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [1,3,3,2], \"nums2\": [2,2,1,3] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [1,1,1,3,3,3,1,1], \"nums2\": [3,2,3,2,3,3,3,3] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [3,3,1,1,3,2], \"nums2\": [2,2,1,1,2,2] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [2,3,2,3,3,1], \"nums2\": [2,3,1,2,1,1] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [1,1,3,3,1,3,3,3], \"nums2\": [2,3,1,3,1,1,1,3] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [2,3,2,2,1,3,1,1], \"nums2\": [3,1,2,2,3,1,2,2] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [2,2,2,3,1,1,3,3], \"nums2\": [3,1,3,1,2,3,2,2] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [3,3,1,3,2,2,3,1], \"nums2\": [3,1,2,3,1,3,2,1] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [1,1,1,2,1,1,1,1,1,2], \"nums2\": [3,1,3,3,1,1,3,2,1,3] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [3,2,2,3], \"nums2\": [1,1,1,3] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [2,3,3,1,2,1,2,2], \"nums2\": [1,2,2,1,2,1,2,2] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [1,2,1,3,2,3], \"nums2\": [3,3,1,1,3,3] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [1,3,1,3,3,3,3,2,2,2], \"nums2\": [2,1,3,2,2,3,3,1,1,3] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [1,3,1,1,2,2,1,1], \"nums2\": [2,3,3,1,3,2,3,2] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [2,3,2,2,2,2,1,2], \"nums2\": [3,1,2,3,3,1,2,1] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [3,3,2,1,2,3], \"nums2\": [2,1,1,3,2,2] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [1,3,1,2,1,1,2,3], \"nums2\": [1,2,2,3,2,3,3,3] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [1,1,1,3,1,2,1,1], \"nums2\": [2,3,3,2,3,3,1,1] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [3,1,3,3,2,2,2,3,1,1], \"nums2\": [1,1,2,1,3,3,1,3,2,1] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [1,1,1,2,3,2,1,1], \"nums2\": [2,1,2,2,2,1,3,3] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [2,1,3,2,2,2,2,2], \"nums2\": [1,3,3,2,2,2,3,1] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [1,3,1,1], \"nums2\": [1,3,1,2] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [1,3,3,1,3,2], \"nums2\": [2,1,3,2,2,2] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [3,2,3,3,2,2], \"nums2\": [1,3,1,3,1,1] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [1,3,1,3,2,3], \"nums2\": [2,1,1,1,2,3] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [1,1,3,1,3,1], \"nums2\": [3,3,1,2,2,1] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [2,2,2,2,2,3,1,3], \"nums2\": [2,3,3,2,1,2,3,1] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [1,3,1,2,3,1], \"nums2\": [3,3,2,2,1,3] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [2,1,2,2,1,3], \"nums2\": [1,1,1,3,2,3] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [2,2,1,2,1,3,3,1], \"nums2\": [3,1,3,1,1,3,3,1] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [3,1,3,3,2,3], \"nums2\": [1,3,3,2,2,1] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [3,2,1,3,3,2], \"nums2\": [1,1,3,3,1,2] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [2,1,3,2,3,3], \"nums2\": [2,2,2,3,2,1] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [3,3,3,1,2,2,3,1], \"nums2\": [3,1,2,3,2,3,2,1] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [3,1,3,1,2,1,2,2,2,2], \"nums2\": [2,1,3,1,1,1,2,2,1,3] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [1,2,2,1,3,3], \"nums2\": [1,1,1,3,2,2] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [2,1,2,3], \"nums2\": [3,2,3,2] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [3,1,2,2], \"nums2\": [2,1,1,1] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [2,2,3,2], \"nums2\": [2,1,3,3] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [3,3,2,1,3,3,2,3], \"nums2\": [3,1,2,3,2,2,1,3] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [3,3,3,1,2,2], \"nums2\": [1,3,1,2,2,3] }\nassert my_solution.maximumSetSize(**test_input) == 3\n\ntest_input = { \"nums1\": [3,1,1,3,1,1,3,2], \"nums2\": [3,2,3,3,3,1,2,3] }\nassert my_solution.maximumSetSize(**test_input) == 3", "start_time": 1704594600} +{"task_id": "weekly-contest-379-maximize-the-number-of-partitions-after-operations", "url": "https://leetcode.com/problems/maximize-the-number-of-partitions-after-operations", "title": "maximize-the-number-of-partitions-after-operations", "meta": {"questionId": "3233", "questionFrontendId": "10038", "title": "Maximize the Number of Partitions After Operations", "titleSlug": "maximize-the-number-of-partitions-after-operations", "isPaidOnly": false, "difficulty": "Hard", "likes": 41, "dislikes": 11, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed string s and an integer k.\nYou are to perform the following partitioning operations until s is empty:\n\nChoose the longest prefix of s containing at most k distinct characters.\nDelete the prefix from s and increase the number of partitions by one. The remaining characters (if any) in s maintain their initial order.\n\nBefore the operations, you are allowed to change at most one index in s to another lowercase English letter.\nReturn an integer denoting the maximum number of resulting partitions after the operations by optimally choosing at most one index to change.\n\nExample 1:\n\nInput: s = \"accca\", k = 2\nOutput: 3\nExplanation: In this example, to maximize the number of resulting partitions, s[2] can be changed to 'b'.\ns becomes \"acbca\".\nThe operations can now be performed as follows until s becomes empty:\n- Choose the longest prefix containing at most 2 distinct characters, \"acbca\".\n- Delete the prefix, and s becomes \"bca\". The number of partitions is now 1.\n- Choose the longest prefix containing at most 2 distinct characters, \"bca\".\n- Delete the prefix, and s becomes \"a\". The number of partitions is now 2.\n- Choose the longest prefix containing at most 2 distinct characters, \"a\".\n- Delete the prefix, and s becomes empty. The number of partitions is now 3.\nHence, the answer is 3.\nIt can be shown that it is not possible to obtain more than 3 partitions.\nExample 2:\n\nInput: s = \"aabaab\", k = 3\nOutput: 1\nExplanation: In this example, to maximize the number of resulting partitions we can leave s as it is.\nThe operations can now be performed as follows until s becomes empty: \n- Choose the longest prefix containing at most 3 distinct characters, \"aabaab\".\n- Delete the prefix, and s becomes empty. The number of partitions becomes 1. \nHence, the answer is 1. \nIt can be shown that it is not possible to obtain more than 1 partition.\n\nExample 3:\n\nInput: s = \"xxyz\", k = 1\nOutput: 4\nExplanation: In this example, to maximize the number of resulting partitions, s[1] can be changed to 'a'.\ns becomes \"xayz\".\nThe operations can now be performed as follows until s becomes empty:\n- Choose the longest prefix containing at most 1 distinct character, \"xayz\".\n- Delete the prefix, and s becomes \"ayz\". The number of partitions is now 1.\n- Choose the longest prefix containing at most 1 distinct character, \"ayz\".\n- Delete the prefix, and s becomes \"yz\". The number of partitions is now 2.\n- Choose the longest prefix containing at most 1 distinct character, \"yz\".\n- Delete the prefix, and s becomes \"z\". The number of partitions is now 3.\n- Choose the longest prefix containing at most 1 distinct character, \"z\".\n- Delete the prefix, and s becomes empty. The number of partitions is now 4.\nHence, the answer is 4.\nIt can be shown that it is not possible to obtain more than 4 partitions.\n\n\nConstraints:\n\n1 <= s.length <= 104\ns consists only of lowercase English letters.\n1 <= k <= 26\n\"\"\"\nclass Solution:\n def maxPartitionsAfterOperations(self, s: str, k: int) -> int:\n ", "prompt_sft": "You are given a 0-indexed string s and an integer k.\nYou are to perform the following partitioning operations until s is empty:\n\nChoose the longest prefix of s containing at most k distinct characters.\nDelete the prefix from s and increase the number of partitions by one. The remaining characters (if any) in s maintain their initial order.\n\nBefore the operations, you are allowed to change at most one index in s to another lowercase English letter.\nReturn an integer denoting the maximum number of resulting partitions after the operations by optimally choosing at most one index to change.\n\nExample 1:\n\nInput: s = \"accca\", k = 2\nOutput: 3\nExplanation: In this example, to maximize the number of resulting partitions, s[2] can be changed to 'b'.\ns becomes \"acbca\".\nThe operations can now be performed as follows until s becomes empty:\n- Choose the longest prefix containing at most 2 distinct characters, \"acbca\".\n- Delete the prefix, and s becomes \"bca\". The number of partitions is now 1.\n- Choose the longest prefix containing at most 2 distinct characters, \"bca\".\n- Delete the prefix, and s becomes \"a\". The number of partitions is now 2.\n- Choose the longest prefix containing at most 2 distinct characters, \"a\".\n- Delete the prefix, and s becomes empty. The number of partitions is now 3.\nHence, the answer is 3.\nIt can be shown that it is not possible to obtain more than 3 partitions.\nExample 2:\n\nInput: s = \"aabaab\", k = 3\nOutput: 1\nExplanation: In this example, to maximize the number of resulting partitions we can leave s as it is.\nThe operations can now be performed as follows until s becomes empty: \n- Choose the longest prefix containing at most 3 distinct characters, \"aabaab\".\n- Delete the prefix, and s becomes empty. The number of partitions becomes 1. \nHence, the answer is 1. \nIt can be shown that it is not possible to obtain more than 1 partition.\n\nExample 3:\n\nInput: s = \"xxyz\", k = 1\nOutput: 4\nExplanation: In this example, to maximize the number of resulting partitions, s[1] can be changed to 'a'.\ns becomes \"xayz\".\nThe operations can now be performed as follows until s becomes empty:\n- Choose the longest prefix containing at most 1 distinct character, \"xayz\".\n- Delete the prefix, and s becomes \"ayz\". The number of partitions is now 1.\n- Choose the longest prefix containing at most 1 distinct character, \"ayz\".\n- Delete the prefix, and s becomes \"yz\". The number of partitions is now 2.\n- Choose the longest prefix containing at most 1 distinct character, \"yz\".\n- Delete the prefix, and s becomes \"z\". The number of partitions is now 3.\n- Choose the longest prefix containing at most 1 distinct character, \"z\".\n- Delete the prefix, and s becomes empty. The number of partitions is now 4.\nHence, the answer is 4.\nIt can be shown that it is not possible to obtain more than 4 partitions.\n\n\nConstraints:\n\n1 <= s.length <= 104\ns consists only of lowercase English letters.\n1 <= k <= 26\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def maxPartitionsAfterOperations(self, s: str, k: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"s\": \"accca\", \"k\": 2 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 3\n\ntest_input = { \"s\": \"aabaab\", \"k\": 3 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"xxyz\", \"k\": 1 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 4\n\ntest_input = { \"s\": \"c\", \"k\": 3 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"c\", \"k\": 5 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"h\", \"k\": 17 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"p\", \"k\": 13 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"ab\", \"k\": 5 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"ba\", \"k\": 1 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 2\n\ntest_input = { \"s\": \"ba\", \"k\": 3 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"ca\", \"k\": 1 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 2\n\ntest_input = { \"s\": \"fh\", \"k\": 8 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"abb\", \"k\": 1 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 3\n\ntest_input = { \"s\": \"aca\", \"k\": 2 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 2\n\ntest_input = { \"s\": \"acb\", \"k\": 2 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 2\n\ntest_input = { \"s\": \"acb\", \"k\": 4 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"bab\", \"k\": 3 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"cba\", \"k\": 1 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 3\n\ntest_input = { \"s\": \"cbb\", \"k\": 5 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"cca\", \"k\": 5 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"fjz\", \"k\": 11 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"jxg\", \"k\": 23 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"xfj\", \"k\": 5 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"abcc\", \"k\": 4 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"acab\", \"k\": 1 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 4\n\ntest_input = { \"s\": \"altj\", \"k\": 5 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"baac\", \"k\": 3 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 2\n\ntest_input = { \"s\": \"baca\", \"k\": 2 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 2\n\ntest_input = { \"s\": \"bbkk\", \"k\": 3 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"cbcc\", \"k\": 4 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"toqm\", \"k\": 14 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"yhbo\", \"k\": 9 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"aaabc\", \"k\": 1 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 5\n\ntest_input = { \"s\": \"accba\", \"k\": 3 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 2\n\ntest_input = { \"s\": \"bcbab\", \"k\": 1 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 5\n\ntest_input = { \"s\": \"bccaa\", \"k\": 5 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"caaaa\", \"k\": 3 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"cacaa\", \"k\": 4 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"cacac\", \"k\": 1 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 5\n\ntest_input = { \"s\": \"cbbab\", \"k\": 5 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"ccacb\", \"k\": 5 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"ccbba\", \"k\": 5 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"yhqlp\", \"k\": 4 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 2\n\ntest_input = { \"s\": \"aabaaa\", \"k\": 5 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"acbabb\", \"k\": 1 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 6\n\ntest_input = { \"s\": \"bbaaab\", \"k\": 4 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"bbbcca\", \"k\": 4 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"bbcaab\", \"k\": 4 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"cacbaa\", \"k\": 1 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 6\n\ntest_input = { \"s\": \"hnhdfs\", \"k\": 5 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 2\n\ntest_input = { \"s\": \"nihnrq\", \"k\": 1 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 6\n\ntest_input = { \"s\": \"odxttm\", \"k\": 19 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"uxqozq\", \"k\": 11 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"aabcaac\", \"k\": 5 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"aabcacc\", \"k\": 2 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 3\n\ntest_input = { \"s\": \"abbaaca\", \"k\": 2 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 3\n\ntest_input = { \"s\": \"baacaac\", \"k\": 3 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 2\n\ntest_input = { \"s\": \"baacbaa\", \"k\": 5 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"baacccb\", \"k\": 1 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 6\n\ntest_input = { \"s\": \"baccacb\", \"k\": 3 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 3\n\ntest_input = { \"s\": \"baccccb\", \"k\": 2 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 3\n\ntest_input = { \"s\": \"bcbbccb\", \"k\": 2 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 3\n\ntest_input = { \"s\": \"cbbcaab\", \"k\": 4 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"ccabbaa\", \"k\": 2 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 3\n\ntest_input = { \"s\": \"cccabcc\", \"k\": 3 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 2\n\ntest_input = { \"s\": \"tmdhzhy\", \"k\": 26 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"abhujxlb\", \"k\": 13 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"acabcbcb\", \"k\": 5 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"acbcbcac\", \"k\": 2 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 4\n\ntest_input = { \"s\": \"adklnsqm\", \"k\": 13 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"bababaca\", \"k\": 4 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"bcacbaaa\", \"k\": 2 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 4\n\ntest_input = { \"s\": \"bcccbacc\", \"k\": 5 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"aaaabcccb\", \"k\": 1 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 6\n\ntest_input = { \"s\": \"acabcaacc\", \"k\": 2 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 4\n\ntest_input = { \"s\": \"bcbbabcaa\", \"k\": 4 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"bccaabcaa\", \"k\": 2 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 4\n\ntest_input = { \"s\": \"cbcabbcca\", \"k\": 4 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"ccbaabbba\", \"k\": 2 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 4\n\ntest_input = { \"s\": \"aaaaabbcab\", \"k\": 5 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"aababbbbca\", \"k\": 4 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"aabbbbccab\", \"k\": 1 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 7\n\ntest_input = { \"s\": \"abbcbbcbba\", \"k\": 1 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 8\n\ntest_input = { \"s\": \"abcbbaccbb\", \"k\": 5 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"acabacccac\", \"k\": 5 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"acbbcacbab\", \"k\": 5 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"bbaccabbac\", \"k\": 4 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"bbbbcbcbbc\", \"k\": 2 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 3\n\ntest_input = { \"s\": \"bsoefqekpl\", \"k\": 6 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 2\n\ntest_input = { \"s\": \"caacccbcac\", \"k\": 3 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 2\n\ntest_input = { \"s\": \"cccacccbcb\", \"k\": 2 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 3\n\ntest_input = { \"s\": \"vwfyagymtp\", \"k\": 20 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"abaaccbaaaa\", \"k\": 2 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 4\n\ntest_input = { \"s\": \"abcccaccccc\", \"k\": 2 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 3\n\ntest_input = { \"s\": \"cbbbccaacaa\", \"k\": 3 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 2\n\ntest_input = { \"s\": \"ccaaabaaaaa\", \"k\": 2 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 3\n\ntest_input = { \"s\": \"wcmgarcruky\", \"k\": 10 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"yyogqjsswyn\", \"k\": 17 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1\n\ntest_input = { \"s\": \"aaaccccbbbca\", \"k\": 1 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 7\n\ntest_input = { \"s\": \"baaccaabaccc\", \"k\": 5 }\nassert my_solution.maxPartitionsAfterOperations(**test_input) == 1", "start_time": 1704594600} +{"task_id": "biweekly-contest-121-smallest-missing-integer-greater-than-sequential-prefix-sum", "url": "https://leetcode.com/problems/smallest-missing-integer-greater-than-sequential-prefix-sum", "title": "smallest-missing-integer-greater-than-sequential-prefix-sum", "meta": {"questionId": "3236", "questionFrontendId": "10031", "title": "Smallest Missing Integer Greater Than Sequential Prefix Sum", "titleSlug": "smallest-missing-integer-greater-than-sequential-prefix-sum", "isPaidOnly": false, "difficulty": "Easy", "likes": 41, "dislikes": 122, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed array of integers nums.\nA prefix nums[0..i] is sequential if, for all 1 <= j <= i, nums[j] = nums[j - 1] + 1. In particular, the prefix consisting only of nums[0] is sequential.\nReturn the smallest integer x missing from nums such that x is greater than or equal to the sum of the longest sequential prefix.\n\nExample 1:\n\nInput: nums = [1,2,3,2,5]\nOutput: 6\nExplanation: The longest sequential prefix of nums is [1,2,3] with a sum of 6. 6 is not in the array, therefore 6 is the smallest missing integer greater than or equal to the sum of the longest sequential prefix.\n\nExample 2:\n\nInput: nums = [3,4,5,1,12,14,13]\nOutput: 15\nExplanation: The longest sequential prefix of nums is [3,4,5] with a sum of 12. 12, 13, and 14 belong to the array while 15 does not. Therefore 15 is the smallest missing integer greater than or equal to the sum of the longest sequential prefix.\n\n\nConstraints:\n\n1 <= nums.length <= 50\n1 <= nums[i] <= 50\n\"\"\"\nclass Solution:\n def missingInteger(self, nums: List[int]) -> int:\n ", "prompt_sft": "You are given a 0-indexed array of integers nums.\nA prefix nums[0..i] is sequential if, for all 1 <= j <= i, nums[j] = nums[j - 1] + 1. In particular, the prefix consisting only of nums[0] is sequential.\nReturn the smallest integer x missing from nums such that x is greater than or equal to the sum of the longest sequential prefix.\n\nExample 1:\n\nInput: nums = [1,2,3,2,5]\nOutput: 6\nExplanation: The longest sequential prefix of nums is [1,2,3] with a sum of 6. 6 is not in the array, therefore 6 is the smallest missing integer greater than or equal to the sum of the longest sequential prefix.\n\nExample 2:\n\nInput: nums = [3,4,5,1,12,14,13]\nOutput: 15\nExplanation: The longest sequential prefix of nums is [3,4,5] with a sum of 12. 12, 13, and 14 belong to the array while 15 does not. Therefore 15 is the smallest missing integer greater than or equal to the sum of the longest sequential prefix.\n\n\nConstraints:\n\n1 <= nums.length <= 50\n1 <= nums[i] <= 50\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def missingInteger(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,2,3,2,5] }\nassert my_solution.missingInteger(**test_input) == 6\n\ntest_input = { \"nums\": [3,4,5,1,12,14,13] }\nassert my_solution.missingInteger(**test_input) == 15\n\ntest_input = { \"nums\": [29,30,31,32,33,34,35,36,37] }\nassert my_solution.missingInteger(**test_input) == 297\n\ntest_input = { \"nums\": [19,20,21,22] }\nassert my_solution.missingInteger(**test_input) == 82\n\ntest_input = { \"nums\": [18,19,20,21,22,23,24,25,26,27,28,9] }\nassert my_solution.missingInteger(**test_input) == 253\n\ntest_input = { \"nums\": [4,5,6,7,8,8,9,4,3,2,7] }\nassert my_solution.missingInteger(**test_input) == 30\n\ntest_input = { \"nums\": [38] }\nassert my_solution.missingInteger(**test_input) == 39\n\ntest_input = { \"nums\": [1] }\nassert my_solution.missingInteger(**test_input) == 2\n\ntest_input = { \"nums\": [11,12,13] }\nassert my_solution.missingInteger(**test_input) == 36\n\ntest_input = { \"nums\": [47,48,49,5,3] }\nassert my_solution.missingInteger(**test_input) == 144\n\ntest_input = { \"nums\": [23,24,25,4,5,1] }\nassert my_solution.missingInteger(**test_input) == 72\n\ntest_input = { \"nums\": [8,9,10,10,7,8] }\nassert my_solution.missingInteger(**test_input) == 27\n\ntest_input = { \"nums\": [31,32,33,34,10,8,7,9,7,9,9,5,10,1] }\nassert my_solution.missingInteger(**test_input) == 130\n\ntest_input = { \"nums\": [17,18,19,20,21,22,3,7,10,10] }\nassert my_solution.missingInteger(**test_input) == 117\n\ntest_input = { \"nums\": [6,7,8,9,10,8,6,7,4,1] }\nassert my_solution.missingInteger(**test_input) == 40\n\ntest_input = { \"nums\": [46,8,2,4,1,4,10,2,4,10,2,5,7,3,1] }\nassert my_solution.missingInteger(**test_input) == 47\n\ntest_input = { \"nums\": [37,1,2,9,5,8,5,2,9,4] }\nassert my_solution.missingInteger(**test_input) == 38\n\ntest_input = { \"nums\": [31,32,33,34,1] }\nassert my_solution.missingInteger(**test_input) == 130\n\ntest_input = { \"nums\": [45,46,47,48,49,10,8,1,7,4,10,10,6,6,2] }\nassert my_solution.missingInteger(**test_input) == 235\n\ntest_input = { \"nums\": [13,10,7,5,7,10,6,10,2] }\nassert my_solution.missingInteger(**test_input) == 14\n\ntest_input = { \"nums\": [32,33,34,35,36,37,38,39,40,41,42,43,44,8,6] }\nassert my_solution.missingInteger(**test_input) == 494\n\ntest_input = { \"nums\": [24,8,9] }\nassert my_solution.missingInteger(**test_input) == 25\n\ntest_input = { \"nums\": [47,48,49,9,3,8,1,9,2,5,4,5,9] }\nassert my_solution.missingInteger(**test_input) == 144\n\ntest_input = { \"nums\": [4,5,6,7,8,9,4,7,10,7,2] }\nassert my_solution.missingInteger(**test_input) == 39\n\ntest_input = { \"nums\": [28,29] }\nassert my_solution.missingInteger(**test_input) == 57\n\ntest_input = { \"nums\": [40,41,42,3,8,2,7,1,4] }\nassert my_solution.missingInteger(**test_input) == 123\n\ntest_input = { \"nums\": [17,18,19,20,21,22,23,24,25,26,27,9,2,5] }\nassert my_solution.missingInteger(**test_input) == 242\n\ntest_input = { \"nums\": [43,44] }\nassert my_solution.missingInteger(**test_input) == 87\n\ntest_input = { \"nums\": [19,20,5,3,10] }\nassert my_solution.missingInteger(**test_input) == 39\n\ntest_input = { \"nums\": [5] }\nassert my_solution.missingInteger(**test_input) == 6\n\ntest_input = { \"nums\": [14,15] }\nassert my_solution.missingInteger(**test_input) == 29\n\ntest_input = { \"nums\": [47,48,49] }\nassert my_solution.missingInteger(**test_input) == 144\n\ntest_input = { \"nums\": [10] }\nassert my_solution.missingInteger(**test_input) == 11\n\ntest_input = { \"nums\": [39] }\nassert my_solution.missingInteger(**test_input) == 40\n\ntest_input = { \"nums\": [11,12,13,14,15,7,5,2,10,5,6] }\nassert my_solution.missingInteger(**test_input) == 65\n\ntest_input = { \"nums\": [3,4,5,7,9,8,1,3,4,9] }\nassert my_solution.missingInteger(**test_input) == 12\n\ntest_input = { \"nums\": [29,30,31,32,33,34,35,36,37,38,39,40,41] }\nassert my_solution.missingInteger(**test_input) == 455\n\ntest_input = { \"nums\": [24,25,26,27,28,29,30,31,32,33,34,35,6,4,1] }\nassert my_solution.missingInteger(**test_input) == 354\n\ntest_input = { \"nums\": [7,8,9,10,11,12,13,14,15] }\nassert my_solution.missingInteger(**test_input) == 99\n\ntest_input = { \"nums\": [39,40,41,42,43,44,45,8,10,4] }\nassert my_solution.missingInteger(**test_input) == 294\n\ntest_input = { \"nums\": [36,37,6,8] }\nassert my_solution.missingInteger(**test_input) == 73\n\ntest_input = { \"nums\": [27,28,29,30] }\nassert my_solution.missingInteger(**test_input) == 114\n\ntest_input = { \"nums\": [34,35,5,7] }\nassert my_solution.missingInteger(**test_input) == 69\n\ntest_input = { \"nums\": [9,8,6,1] }\nassert my_solution.missingInteger(**test_input) == 10\n\ntest_input = { \"nums\": [36,37,38,39,8,10,7] }\nassert my_solution.missingInteger(**test_input) == 150\n\ntest_input = { \"nums\": [28,29,6] }\nassert my_solution.missingInteger(**test_input) == 57\n\ntest_input = { \"nums\": [14,15,16,17,18,19,20,10,9,10,9,7,3,6] }\nassert my_solution.missingInteger(**test_input) == 119\n\ntest_input = { \"nums\": [27,28,29,5] }\nassert my_solution.missingInteger(**test_input) == 84\n\ntest_input = { \"nums\": [42,43,44,45,46,47,48] }\nassert my_solution.missingInteger(**test_input) == 315\n\ntest_input = { \"nums\": [2,3,4,5,6,7,8,9,10,11,1,10,5,6] }\nassert my_solution.missingInteger(**test_input) == 65\n\ntest_input = { \"nums\": [32,33,34,35,36,37,5,8,5,3,4,2,10,3,7] }\nassert my_solution.missingInteger(**test_input) == 207\n\ntest_input = { \"nums\": [24,25,26,27,28,29,30,31,32,33,1,3,9] }\nassert my_solution.missingInteger(**test_input) == 285\n\ntest_input = { \"nums\": [48,49] }\nassert my_solution.missingInteger(**test_input) == 97\n\ntest_input = { \"nums\": [46,47,6,7,1] }\nassert my_solution.missingInteger(**test_input) == 93\n\ntest_input = { \"nums\": [32,33,34,35,36,37,38,39,40] }\nassert my_solution.missingInteger(**test_input) == 324\n\ntest_input = { \"nums\": [40,41,42,43,44,45,6] }\nassert my_solution.missingInteger(**test_input) == 255\n\ntest_input = { \"nums\": [5,6,7,8,9,10,11,12,13,14,15,16,17,18,9] }\nassert my_solution.missingInteger(**test_input) == 161\n\ntest_input = { \"nums\": [39,40,41,3,4,7,10,6,2,10,1,9] }\nassert my_solution.missingInteger(**test_input) == 120\n\ntest_input = { \"nums\": [17,18] }\nassert my_solution.missingInteger(**test_input) == 35\n\ntest_input = { \"nums\": [41,42,43,44,45,46,5,6] }\nassert my_solution.missingInteger(**test_input) == 261\n\ntest_input = { \"nums\": [6] }\nassert my_solution.missingInteger(**test_input) == 7\n\ntest_input = { \"nums\": [46,47,48,49,50,7] }\nassert my_solution.missingInteger(**test_input) == 240\n\ntest_input = { \"nums\": [17,18,19,20,21,22,23,24,25,26,4,7,5,4,4] }\nassert my_solution.missingInteger(**test_input) == 215\n\ntest_input = { \"nums\": [40,41,42,43,44,45,46,4,6] }\nassert my_solution.missingInteger(**test_input) == 301\n\ntest_input = { \"nums\": [13,4,2,2,3,4,1,8,3,7,7,7,1,6,3] }\nassert my_solution.missingInteger(**test_input) == 14\n\ntest_input = { \"nums\": [4,5,6,7,8,9,10,11,12,13,14,15,16,6,8] }\nassert my_solution.missingInteger(**test_input) == 130\n\ntest_input = { \"nums\": [12,10] }\nassert my_solution.missingInteger(**test_input) == 13\n\ntest_input = { \"nums\": [17,18,19,20,21,5,3,7,10,5,3,7,3,5,3] }\nassert my_solution.missingInteger(**test_input) == 95\n\ntest_input = { \"nums\": [38,39,40,41,42,43,44,45,5,7,9,9,4,1] }\nassert my_solution.missingInteger(**test_input) == 332\n\ntest_input = { \"nums\": [32,33,34,35] }\nassert my_solution.missingInteger(**test_input) == 134\n\ntest_input = { \"nums\": [33,34,7,3,4,4] }\nassert my_solution.missingInteger(**test_input) == 67\n\ntest_input = { \"nums\": [33,34,35,36,37,38,39,40,41,42,43,44,45,46,47] }\nassert my_solution.missingInteger(**test_input) == 600\n\ntest_input = { \"nums\": [14,9,6,9,7,9,10,4,9,9,4,4] }\nassert my_solution.missingInteger(**test_input) == 15\n\ntest_input = { \"nums\": [18,19,20,21,22,23,24,25,26,6,8,2,1] }\nassert my_solution.missingInteger(**test_input) == 198\n\ntest_input = { \"nums\": [19,20,21,7,9] }\nassert my_solution.missingInteger(**test_input) == 60\n\ntest_input = { \"nums\": [19,20,21,10,1,8,2,1] }\nassert my_solution.missingInteger(**test_input) == 60\n\ntest_input = { \"nums\": [1,2,3,9,2,10,8,3,10,2] }\nassert my_solution.missingInteger(**test_input) == 6\n\ntest_input = { \"nums\": [48,10] }\nassert my_solution.missingInteger(**test_input) == 49\n\ntest_input = { \"nums\": [20,21,22,23,24,25,5] }\nassert my_solution.missingInteger(**test_input) == 135\n\ntest_input = { \"nums\": [40,41,42,43,3,4,10,3,7,8,9,1,5] }\nassert my_solution.missingInteger(**test_input) == 166\n\ntest_input = { \"nums\": [21,22,23,24,25,26,27,8] }\nassert my_solution.missingInteger(**test_input) == 168\n\ntest_input = { \"nums\": [2,3,4,5,6,4] }\nassert my_solution.missingInteger(**test_input) == 20\n\ntest_input = { \"nums\": [9,10,11,12,13,14,15,16,17,4] }\nassert my_solution.missingInteger(**test_input) == 117\n\ntest_input = { \"nums\": [25,26,27,28,29,6,8] }\nassert my_solution.missingInteger(**test_input) == 135\n\ntest_input = { \"nums\": [16,17,18,19,20,21,22,23,24,25,6] }\nassert my_solution.missingInteger(**test_input) == 205\n\ntest_input = { \"nums\": [7,8,9,10,11,12] }\nassert my_solution.missingInteger(**test_input) == 57\n\ntest_input = { \"nums\": [32,9,2,6,4,1,4,3,5] }\nassert my_solution.missingInteger(**test_input) == 33\n\ntest_input = { \"nums\": [1,4,3] }\nassert my_solution.missingInteger(**test_input) == 2\n\ntest_input = { \"nums\": [34,35,36,37,38,39,1,9,3,3,10,7,1] }\nassert my_solution.missingInteger(**test_input) == 219\n\ntest_input = { \"nums\": [37,7,6,4,3,1,10,8,7,2,6] }\nassert my_solution.missingInteger(**test_input) == 38\n\ntest_input = { \"nums\": [32] }\nassert my_solution.missingInteger(**test_input) == 33\n\ntest_input = { \"nums\": [25,26,27,4] }\nassert my_solution.missingInteger(**test_input) == 78\n\ntest_input = { \"nums\": [31,32,33,8,5,3,7,2] }\nassert my_solution.missingInteger(**test_input) == 96\n\ntest_input = { \"nums\": [38,39,40,41,42,43,44,45,1] }\nassert my_solution.missingInteger(**test_input) == 332\n\ntest_input = { \"nums\": [35,36,3,10] }\nassert my_solution.missingInteger(**test_input) == 71\n\ntest_input = { \"nums\": [31,32,33,34,35,7,6,1,9] }\nassert my_solution.missingInteger(**test_input) == 165\n\ntest_input = { \"nums\": [47,48,49,2,2] }\nassert my_solution.missingInteger(**test_input) == 144\n\ntest_input = { \"nums\": [3,4,5,6,7,8,9,10,11,10,1] }\nassert my_solution.missingInteger(**test_input) == 63\n\ntest_input = { \"nums\": [50] }\nassert my_solution.missingInteger(**test_input) == 51\n\ntest_input = { \"nums\": [14,15,16,17,7,10,3,10] }\nassert my_solution.missingInteger(**test_input) == 62", "start_time": 1704551400} +{"task_id": "biweekly-contest-121-minimum-number-of-operations-to-make-array-xor-equal-to-k", "url": "https://leetcode.com/problems/minimum-number-of-operations-to-make-array-xor-equal-to-k", "title": "minimum-number-of-operations-to-make-array-xor-equal-to-k", "meta": {"questionId": "3249", "questionFrontendId": "10032", "title": "Minimum Number of Operations to Make Array XOR Equal to K", "titleSlug": "minimum-number-of-operations-to-make-array-xor-equal-to-k", "isPaidOnly": false, "difficulty": "Medium", "likes": 56, "dislikes": 4, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed integer array nums and a positive integer k.\nYou can apply the following operation on the array any number of times:\n\nChoose any element of the array and flip a bit in its binary representation. Flipping a bit means changing a 0 to 1 or vice versa.\n\nReturn the minimum number of operations required to make the bitwise XOR of all elements of the final array equal to k.\nNote that you can flip leading zero bits in the binary representation of elements. For example, for the number (101)2 you can flip the fourth bit and obtain (1101)2.\n\nExample 1:\n\nInput: nums = [2,1,3,4], k = 1\nOutput: 2\nExplanation: We can do the following operations:\n- Choose element 2 which is 3 == (011)2, we flip the first bit and we obtain (010)2 == 2. nums becomes [2,1,2,4].\n- Choose element 0 which is 2 == (010)2, we flip the third bit and we obtain (110)2 = 6. nums becomes [6,1,2,4].\nThe XOR of elements of the final array is (6 XOR 1 XOR 2 XOR 4) == 1 == k.\nIt can be shown that we cannot make the XOR equal to k in less than 2 operations.\n\nExample 2:\n\nInput: nums = [2,0,2,0], k = 0\nOutput: 0\nExplanation: The XOR of elements of the array is (2 XOR 0 XOR 2 XOR 0) == 0 == k. So no operation is needed.\n\n\nConstraints:\n\n1 <= nums.length <= 105\n0 <= nums[i] <= 106\n0 <= k <= 106\n\"\"\"\nclass Solution:\n def minOperations(self, nums: List[int], k: int) -> int:\n ", "prompt_sft": "You are given a 0-indexed integer array nums and a positive integer k.\nYou can apply the following operation on the array any number of times:\n\nChoose any element of the array and flip a bit in its binary representation. Flipping a bit means changing a 0 to 1 or vice versa.\n\nReturn the minimum number of operations required to make the bitwise XOR of all elements of the final array equal to k.\nNote that you can flip leading zero bits in the binary representation of elements. For example, for the number (101)2 you can flip the fourth bit and obtain (1101)2.\n\nExample 1:\n\nInput: nums = [2,1,3,4], k = 1\nOutput: 2\nExplanation: We can do the following operations:\n- Choose element 2 which is 3 == (011)2, we flip the first bit and we obtain (010)2 == 2. nums becomes [2,1,2,4].\n- Choose element 0 which is 2 == (010)2, we flip the third bit and we obtain (110)2 = 6. nums becomes [6,1,2,4].\nThe XOR of elements of the final array is (6 XOR 1 XOR 2 XOR 4) == 1 == k.\nIt can be shown that we cannot make the XOR equal to k in less than 2 operations.\n\nExample 2:\n\nInput: nums = [2,0,2,0], k = 0\nOutput: 0\nExplanation: The XOR of elements of the array is (2 XOR 0 XOR 2 XOR 0) == 0 == k. So no operation is needed.\n\n\nConstraints:\n\n1 <= nums.length <= 105\n0 <= nums[i] <= 106\n0 <= k <= 106\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def minOperations(self, nums: List[int], k: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [2,1,3,4], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [2,0,2,0], \"k\": 0 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [4], \"k\": 7 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [3,13,9,8,5,18,11,10], \"k\": 13 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [9,7,9,14,8,6], \"k\": 12 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [13,9,10,16,11,8,1], \"k\": 17 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [12,14], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [18,18], \"k\": 20 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [3,5,1,1], \"k\": 19 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [7,0,0,0], \"k\": 8 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [13,15,19,18,2,9,18,11,0,7], \"k\": 6 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [9,15,19,15,10,15,14,0,2,5], \"k\": 20 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [19,4,19,6,3,19,14,4,16,12], \"k\": 4 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [2,10,5,5,12,3,14,6,11,14], \"k\": 3 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [11,20], \"k\": 10 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [10,12,5,3,16,0], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [0,4,4,7,14,13], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [16,2,20,13,15,20,13], \"k\": 16 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [19,11,11,0,16,2,2,0,9], \"k\": 4 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [10,17,19,8,15], \"k\": 19 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [8,17,7,18], \"k\": 6 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [10,20], \"k\": 7 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [11,14,5,9,19,3,1], \"k\": 10 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [19,13,16], \"k\": 4 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [12,18,13,2,1,5,8,5,8,6], \"k\": 7 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [15], \"k\": 9 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [8,5,4,5,13,18], \"k\": 0 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [9,18], \"k\": 3 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [6,9,15,17,16], \"k\": 19 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [14,0,17], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [12,1,14,13], \"k\": 4 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [4,10,6,10,10,16], \"k\": 18 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [2,11,6,12,2,15,4,8,11], \"k\": 3 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [7,3,12,5,1,12,8], \"k\": 11 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [11,14,18,14,6,18,4,16,20,5], \"k\": 16 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [20,2,6,0,7], \"k\": 20 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [9,18,19,16,8,11,15], \"k\": 14 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [0,3,20,0,15,7,17,4], \"k\": 3 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [15,6], \"k\": 8 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [2,7,13,16,2,2], \"k\": 15 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [2,12,11,11,2,12], \"k\": 17 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [10,8,10], \"k\": 11 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,10,2,13], \"k\": 0 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,20,4,19,12,18,5,3,11,8], \"k\": 14 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [16,12,12], \"k\": 20 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [2,1,7,3,4,9], \"k\": 6 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [20,0,19,14,7,0], \"k\": 18 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [0,15,9,1,15], \"k\": 11 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [9,11,8,20,10], \"k\": 0 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [2,10,2,14,7,13,4,9,2], \"k\": 20 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [7,12,8], \"k\": 14 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [20,11,5,8,1,8,4,16], \"k\": 7 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [8,2,19,9,8], \"k\": 9 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [17], \"k\": 8 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [19,6], \"k\": 13 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [12,3,20,19], \"k\": 4 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [4,10,18,17,20,6,4], \"k\": 10 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [8,6,12,6,6], \"k\": 4 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [18,12,9,18,12,12,1], \"k\": 12 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [14,4,0,18,18,8,4,9], \"k\": 17 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [7,16,16,6], \"k\": 19 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [7,16,2,13,0,17,16], \"k\": 18 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [3,17,4,2,3,9], \"k\": 12 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [13,14,9,19,5,13], \"k\": 8 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [4,15,10,15,11,1,3,5,18,13], \"k\": 16 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [9,7,8], \"k\": 11 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [7,4,6,20,9,9,6,6], \"k\": 10 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [1,9,13,19,19,0,16,20,4], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [20,3,9,6,5,8], \"k\": 20 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [11,20,5,16,15,11,8], \"k\": 11 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [12,10,16,18,17,4,2,19,17,2], \"k\": 19 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [15,2], \"k\": 10 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [13,3,10,2,9,13,5,11,5], \"k\": 20 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [20,12,9,3,2,11], \"k\": 13 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [3,19,0,18,6], \"k\": 15 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [12,6], \"k\": 18 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [10,11,12,6,10,1,15], \"k\": 8 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [12,8,1,16,6,12], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [11,5,9], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [2,7], \"k\": 6 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [20,1], \"k\": 8 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [9], \"k\": 16 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [9,5,7,11,8,18,5,1,4], \"k\": 8 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,8,7,19,3,20,13,9,10], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [19,18,6], \"k\": 8 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [19,12,3,18,12,19,5,20], \"k\": 0 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [6,18,12,9,20], \"k\": 13 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [19,5,5,7,4,7,15], \"k\": 7 }\nassert my_solution.minOperations(**test_input) == 5\n\ntest_input = { \"nums\": [17,7,19], \"k\": 18 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [14,13,3,15,18,20,2,9,3], \"k\": 14 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [16,10,3,2,3,19], \"k\": 4 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [2,0,8], \"k\": 18 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [19,5,5,12,20,2,10,17], \"k\": 12 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [6,0,0,1,15,9,19,12], \"k\": 6 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [8,16,13,8,18,9,16,16,19,11], \"k\": 12 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [3,7,6,7,4,3,2], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [0,2,9], \"k\": 10 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [14,10,16,9,6,13,11,13,11,16], \"k\": 20 }\nassert my_solution.minOperations(**test_input) == 5\n\ntest_input = { \"nums\": [13,19,0,12,11,10,11,2,6], \"k\": 7 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [6,1,4,9,1,7,11,15,15,0], \"k\": 8 }\nassert my_solution.minOperations(**test_input) == 4", "start_time": 1704551400} +{"task_id": "biweekly-contest-121-minimum-number-of-operations-to-make-x-and-y-equal", "url": "https://leetcode.com/problems/minimum-number-of-operations-to-make-x-and-y-equal", "title": "minimum-number-of-operations-to-make-x-and-y-equal", "meta": {"questionId": "3239", "questionFrontendId": "10033", "title": "Minimum Number of Operations to Make X and Y Equal", "titleSlug": "minimum-number-of-operations-to-make-x-and-y-equal", "isPaidOnly": false, "difficulty": "Medium", "likes": 103, "dislikes": 19, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given two positive integers x and y.\nIn one operation, you can do one of the four following operations:\n\nDivide x by 11 if x is a multiple of 11.\nDivide x by 5 if x is a multiple of 5.\nDecrement x by 1.\nIncrement x by 1.\n\nReturn the minimum number of operations required to make x and y equal.\n\nExample 1:\n\nInput: x = 26, y = 1\nOutput: 3\nExplanation: We can make 26 equal to 1 by applying the following operations: \n1. Decrement x by 1\n2. Divide x by 5\n3. Divide x by 5\nIt can be shown that 3 is the minimum number of operations required to make 26 equal to 1.\n\nExample 2:\n\nInput: x = 54, y = 2\nOutput: 4\nExplanation: We can make 54 equal to 2 by applying the following operations: \n1. Increment x by 1\n2. Divide x by 11 \n3. Divide x by 5\n4. Increment x by 1\nIt can be shown that 4 is the minimum number of operations required to make 54 equal to 2.\n\nExample 3:\n\nInput: x = 25, y = 30\nOutput: 5\nExplanation: We can make 25 equal to 30 by applying the following operations: \n1. Increment x by 1\n2. Increment x by 1\n3. Increment x by 1\n4. Increment x by 1\n5. Increment x by 1\nIt can be shown that 5 is the minimum number of operations required to make 25 equal to 30.\n\n\nConstraints:\n\n1 <= x, y <= 104\n\"\"\"\nclass Solution:\n def minimumOperationsToMakeEqual(self, x: int, y: int) -> int:\n ", "prompt_sft": "You are given two positive integers x and y.\nIn one operation, you can do one of the four following operations:\n\nDivide x by 11 if x is a multiple of 11.\nDivide x by 5 if x is a multiple of 5.\nDecrement x by 1.\nIncrement x by 1.\n\nReturn the minimum number of operations required to make x and y equal.\n\nExample 1:\n\nInput: x = 26, y = 1\nOutput: 3\nExplanation: We can make 26 equal to 1 by applying the following operations: \n1. Decrement x by 1\n2. Divide x by 5\n3. Divide x by 5\nIt can be shown that 3 is the minimum number of operations required to make 26 equal to 1.\n\nExample 2:\n\nInput: x = 54, y = 2\nOutput: 4\nExplanation: We can make 54 equal to 2 by applying the following operations: \n1. Increment x by 1\n2. Divide x by 11 \n3. Divide x by 5\n4. Increment x by 1\nIt can be shown that 4 is the minimum number of operations required to make 54 equal to 2.\n\nExample 3:\n\nInput: x = 25, y = 30\nOutput: 5\nExplanation: We can make 25 equal to 30 by applying the following operations: \n1. Increment x by 1\n2. Increment x by 1\n3. Increment x by 1\n4. Increment x by 1\n5. Increment x by 1\nIt can be shown that 5 is the minimum number of operations required to make 25 equal to 30.\n\n\nConstraints:\n\n1 <= x, y <= 104\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def minimumOperationsToMakeEqual(self, x: int, y: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"x\": 26, \"y\": 1 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 3\n\ntest_input = { \"x\": 54, \"y\": 2 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 4\n\ntest_input = { \"x\": 25, \"y\": 30 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 5\n\ntest_input = { \"x\": 1, \"y\": 1 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 0\n\ntest_input = { \"x\": 1, \"y\": 2 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 1\n\ntest_input = { \"x\": 1, \"y\": 3 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 2\n\ntest_input = { \"x\": 1, \"y\": 4 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 3\n\ntest_input = { \"x\": 1, \"y\": 5 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 4\n\ntest_input = { \"x\": 1, \"y\": 6 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 5\n\ntest_input = { \"x\": 1, \"y\": 7 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 6\n\ntest_input = { \"x\": 1, \"y\": 8 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 7\n\ntest_input = { \"x\": 1, \"y\": 9 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 8\n\ntest_input = { \"x\": 1, \"y\": 10 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 9\n\ntest_input = { \"x\": 1, \"y\": 11 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 10\n\ntest_input = { \"x\": 1, \"y\": 12 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 11\n\ntest_input = { \"x\": 1, \"y\": 13 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 12\n\ntest_input = { \"x\": 1, \"y\": 14 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 13\n\ntest_input = { \"x\": 1, \"y\": 15 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 14\n\ntest_input = { \"x\": 1, \"y\": 16 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 15\n\ntest_input = { \"x\": 1, \"y\": 17 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 16\n\ntest_input = { \"x\": 1, \"y\": 18 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 17\n\ntest_input = { \"x\": 1, \"y\": 19 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 18\n\ntest_input = { \"x\": 1, \"y\": 20 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 19\n\ntest_input = { \"x\": 1, \"y\": 21 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 20\n\ntest_input = { \"x\": 1, \"y\": 22 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 21\n\ntest_input = { \"x\": 1, \"y\": 23 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 22\n\ntest_input = { \"x\": 1, \"y\": 24 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 23\n\ntest_input = { \"x\": 1, \"y\": 25 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 24\n\ntest_input = { \"x\": 2, \"y\": 1 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 1\n\ntest_input = { \"x\": 2, \"y\": 2 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 0\n\ntest_input = { \"x\": 2, \"y\": 3 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 1\n\ntest_input = { \"x\": 2, \"y\": 4 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 2\n\ntest_input = { \"x\": 2, \"y\": 5 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 3\n\ntest_input = { \"x\": 2, \"y\": 6 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 4\n\ntest_input = { \"x\": 2, \"y\": 7 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 5\n\ntest_input = { \"x\": 2, \"y\": 8 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 6\n\ntest_input = { \"x\": 2, \"y\": 9 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 7\n\ntest_input = { \"x\": 2, \"y\": 10 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 8\n\ntest_input = { \"x\": 2, \"y\": 11 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 9\n\ntest_input = { \"x\": 2, \"y\": 12 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 10\n\ntest_input = { \"x\": 2, \"y\": 13 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 11\n\ntest_input = { \"x\": 2, \"y\": 14 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 12\n\ntest_input = { \"x\": 2, \"y\": 15 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 13\n\ntest_input = { \"x\": 2, \"y\": 16 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 14\n\ntest_input = { \"x\": 2, \"y\": 17 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 15\n\ntest_input = { \"x\": 2, \"y\": 18 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 16\n\ntest_input = { \"x\": 2, \"y\": 19 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 17\n\ntest_input = { \"x\": 2, \"y\": 20 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 18\n\ntest_input = { \"x\": 2, \"y\": 21 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 19\n\ntest_input = { \"x\": 2, \"y\": 22 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 20\n\ntest_input = { \"x\": 2, \"y\": 23 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 21\n\ntest_input = { \"x\": 2, \"y\": 24 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 22\n\ntest_input = { \"x\": 2, \"y\": 25 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 23\n\ntest_input = { \"x\": 3, \"y\": 1 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 2\n\ntest_input = { \"x\": 3, \"y\": 2 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 1\n\ntest_input = { \"x\": 3, \"y\": 3 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 0\n\ntest_input = { \"x\": 3, \"y\": 4 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 1\n\ntest_input = { \"x\": 3, \"y\": 5 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 2\n\ntest_input = { \"x\": 3, \"y\": 6 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 3\n\ntest_input = { \"x\": 3, \"y\": 7 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 4\n\ntest_input = { \"x\": 3, \"y\": 8 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 5\n\ntest_input = { \"x\": 3, \"y\": 9 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 6\n\ntest_input = { \"x\": 3, \"y\": 10 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 7\n\ntest_input = { \"x\": 3, \"y\": 11 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 8\n\ntest_input = { \"x\": 3, \"y\": 12 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 9\n\ntest_input = { \"x\": 3, \"y\": 13 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 10\n\ntest_input = { \"x\": 3, \"y\": 14 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 11\n\ntest_input = { \"x\": 3, \"y\": 15 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 12\n\ntest_input = { \"x\": 3, \"y\": 16 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 13\n\ntest_input = { \"x\": 3, \"y\": 17 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 14\n\ntest_input = { \"x\": 3, \"y\": 18 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 15\n\ntest_input = { \"x\": 3, \"y\": 19 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 16\n\ntest_input = { \"x\": 3, \"y\": 20 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 17\n\ntest_input = { \"x\": 3, \"y\": 21 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 18\n\ntest_input = { \"x\": 3, \"y\": 22 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 19\n\ntest_input = { \"x\": 3, \"y\": 23 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 20\n\ntest_input = { \"x\": 3, \"y\": 24 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 21\n\ntest_input = { \"x\": 3, \"y\": 25 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 22\n\ntest_input = { \"x\": 4, \"y\": 1 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 2\n\ntest_input = { \"x\": 4, \"y\": 2 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 2\n\ntest_input = { \"x\": 4, \"y\": 3 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 1\n\ntest_input = { \"x\": 4, \"y\": 4 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 0\n\ntest_input = { \"x\": 4, \"y\": 5 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 1\n\ntest_input = { \"x\": 4, \"y\": 6 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 2\n\ntest_input = { \"x\": 4, \"y\": 7 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 3\n\ntest_input = { \"x\": 4, \"y\": 8 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 4\n\ntest_input = { \"x\": 4, \"y\": 9 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 5\n\ntest_input = { \"x\": 4, \"y\": 10 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 6\n\ntest_input = { \"x\": 4, \"y\": 11 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 7\n\ntest_input = { \"x\": 4, \"y\": 12 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 8\n\ntest_input = { \"x\": 4, \"y\": 13 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 9\n\ntest_input = { \"x\": 4, \"y\": 14 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 10\n\ntest_input = { \"x\": 4, \"y\": 15 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 11\n\ntest_input = { \"x\": 4, \"y\": 16 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 12\n\ntest_input = { \"x\": 4, \"y\": 17 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 13\n\ntest_input = { \"x\": 4, \"y\": 18 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 14\n\ntest_input = { \"x\": 4, \"y\": 19 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 15\n\ntest_input = { \"x\": 4, \"y\": 20 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 16\n\ntest_input = { \"x\": 4, \"y\": 21 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 17\n\ntest_input = { \"x\": 4, \"y\": 22 }\nassert my_solution.minimumOperationsToMakeEqual(**test_input) == 18", "start_time": 1704551400} +{"task_id": "biweekly-contest-121-count-the-number-of-powerful-integers", "url": "https://leetcode.com/problems/count-the-number-of-powerful-integers", "title": "count-the-number-of-powerful-integers", "meta": {"questionId": "3243", "questionFrontendId": "10034", "title": "Count the Number of Powerful Integers", "titleSlug": "count-the-number-of-powerful-integers", "isPaidOnly": false, "difficulty": "Hard", "likes": 53, "dislikes": 1, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given three integers start, finish, and limit. You are also given a 0-indexed string s representing a positive integer.\nA positive integer x is called powerful if it ends with s (in other words, s is a suffix of x) and each digit in x is at most limit.\nReturn the total number of powerful integers in the range [start..finish].\nA string x is a suffix of a string y if and only if x is a substring of y that starts from some index (including 0) in y and extends to the index y.length - 1. For example, 25 is a suffix of 5125 whereas 512 is not.\n\nExample 1:\n\nInput: start = 1, finish = 6000, limit = 4, s = \"124\"\nOutput: 5\nExplanation: The powerful integers in the range [1..6000] are 124, 1124, 2124, 3124, and, 4124. All these integers have each digit <= 4, and \"124\" as a suffix. Note that 5124 is not a powerful integer because the first digit is 5 which is greater than 4.\nIt can be shown that there are only 5 powerful integers in this range.\n\nExample 2:\n\nInput: start = 15, finish = 215, limit = 6, s = \"10\"\nOutput: 2\nExplanation: The powerful integers in the range [15..215] are 110 and 210. All these integers have each digit <= 6, and \"10\" as a suffix.\nIt can be shown that there are only 2 powerful integers in this range.\n\nExample 3:\n\nInput: start = 1000, finish = 2000, limit = 4, s = \"3000\"\nOutput: 0\nExplanation: All integers in the range [1000..2000] are smaller than 3000, hence \"3000\" cannot be a suffix of any integer in this range.\n\n\nConstraints:\n\n1 <= start <= finish <= 1015\n1 <= limit <= 9\n1 <= s.length <= floor(log10(finish)) + 1\ns only consists of numeric digits which are at most limit.\ns does not have leading zeros.\n\"\"\"\nclass Solution:\n def numberOfPowerfulInt(self, start: int, finish: int, limit: int, s: str) -> int:\n ", "prompt_sft": "You are given three integers start, finish, and limit. You are also given a 0-indexed string s representing a positive integer.\nA positive integer x is called powerful if it ends with s (in other words, s is a suffix of x) and each digit in x is at most limit.\nReturn the total number of powerful integers in the range [start..finish].\nA string x is a suffix of a string y if and only if x is a substring of y that starts from some index (including 0) in y and extends to the index y.length - 1. For example, 25 is a suffix of 5125 whereas 512 is not.\n\nExample 1:\n\nInput: start = 1, finish = 6000, limit = 4, s = \"124\"\nOutput: 5\nExplanation: The powerful integers in the range [1..6000] are 124, 1124, 2124, 3124, and, 4124. All these integers have each digit <= 4, and \"124\" as a suffix. Note that 5124 is not a powerful integer because the first digit is 5 which is greater than 4.\nIt can be shown that there are only 5 powerful integers in this range.\n\nExample 2:\n\nInput: start = 15, finish = 215, limit = 6, s = \"10\"\nOutput: 2\nExplanation: The powerful integers in the range [15..215] are 110 and 210. All these integers have each digit <= 6, and \"10\" as a suffix.\nIt can be shown that there are only 2 powerful integers in this range.\n\nExample 3:\n\nInput: start = 1000, finish = 2000, limit = 4, s = \"3000\"\nOutput: 0\nExplanation: All integers in the range [1000..2000] are smaller than 3000, hence \"3000\" cannot be a suffix of any integer in this range.\n\n\nConstraints:\n\n1 <= start <= finish <= 1015\n1 <= limit <= 9\n1 <= s.length <= floor(log10(finish)) + 1\ns only consists of numeric digits which are at most limit.\ns does not have leading zeros.\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def numberOfPowerfulInt(self, start: int, finish: int, limit: int, s: str) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"start\": 1, \"finish\": 6000, \"limit\": 4, \"s\": \"124\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 5\n\ntest_input = { \"start\": 15, \"finish\": 215, \"limit\": 6, \"s\": \"10\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 2\n\ntest_input = { \"start\": 1000, \"finish\": 2000, \"limit\": 4, \"s\": \"3000\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 0\n\ntest_input = { \"start\": 141, \"finish\": 148, \"limit\": 9, \"s\": \"9\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 0\n\ntest_input = { \"start\": 1, \"finish\": 971, \"limit\": 9, \"s\": \"17\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 10\n\ntest_input = { \"start\": 1, \"finish\": 971, \"limit\": 9, \"s\": \"27\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 10\n\ntest_input = { \"start\": 1, \"finish\": 971, \"limit\": 9, \"s\": \"41\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 10\n\ntest_input = { \"start\": 1, \"finish\": 971, \"limit\": 9, \"s\": \"47\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 10\n\ntest_input = { \"start\": 1, \"finish\": 971, \"limit\": 9, \"s\": \"61\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 10\n\ntest_input = { \"start\": 1, \"finish\": 971, \"limit\": 9, \"s\": \"66\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 10\n\ntest_input = { \"start\": 1, \"finish\": 971, \"limit\": 9, \"s\": \"71\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 10\n\ntest_input = { \"start\": 1, \"finish\": 971, \"limit\": 9, \"s\": \"72\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 9\n\ntest_input = { \"start\": 20, \"finish\": 1159, \"limit\": 5, \"s\": \"20\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 8\n\ntest_input = { \"start\": 20, \"finish\": 1159, \"limit\": 5, \"s\": \"24\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 8\n\ntest_input = { \"start\": 20, \"finish\": 1159, \"limit\": 5, \"s\": \"32\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 8\n\ntest_input = { \"start\": 20, \"finish\": 1159, \"limit\": 5, \"s\": \"33\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 8\n\ntest_input = { \"start\": 20, \"finish\": 1159, \"limit\": 5, \"s\": \"40\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 8\n\ntest_input = { \"start\": 20, \"finish\": 1159, \"limit\": 5, \"s\": \"41\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 8\n\ntest_input = { \"start\": 20, \"finish\": 1159, \"limit\": 5, \"s\": \"42\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 8\n\ntest_input = { \"start\": 20, \"finish\": 1159, \"limit\": 5, \"s\": \"43\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 8\n\ntest_input = { \"start\": 20, \"finish\": 1159, \"limit\": 5, \"s\": \"44\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 8\n\ntest_input = { \"start\": 1300, \"finish\": 1400, \"limit\": 5, \"s\": \"245\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 0\n\ntest_input = { \"start\": 3, \"finish\": 1429, \"limit\": 5, \"s\": \"11\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 11\n\ntest_input = { \"start\": 3, \"finish\": 1429, \"limit\": 5, \"s\": \"12\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 11\n\ntest_input = { \"start\": 3, \"finish\": 1429, \"limit\": 5, \"s\": \"13\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 11\n\ntest_input = { \"start\": 3, \"finish\": 1429, \"limit\": 5, \"s\": \"14\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 11\n\ntest_input = { \"start\": 3, \"finish\": 1429, \"limit\": 5, \"s\": \"20\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 11\n\ntest_input = { \"start\": 3, \"finish\": 1429, \"limit\": 5, \"s\": \"21\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 11\n\ntest_input = { \"start\": 3, \"finish\": 1429, \"limit\": 5, \"s\": \"34\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 10\n\ntest_input = { \"start\": 3, \"finish\": 1429, \"limit\": 5, \"s\": \"40\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 10\n\ntest_input = { \"start\": 3, \"finish\": 1429, \"limit\": 5, \"s\": \"43\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 10\n\ntest_input = { \"start\": 15, \"finish\": 1440, \"limit\": 5, \"s\": \"11\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 10\n\ntest_input = { \"start\": 15, \"finish\": 1440, \"limit\": 5, \"s\": \"12\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 10\n\ntest_input = { \"start\": 15, \"finish\": 1440, \"limit\": 5, \"s\": \"14\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 10\n\ntest_input = { \"start\": 15, \"finish\": 1440, \"limit\": 5, \"s\": \"21\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 11\n\ntest_input = { \"start\": 15, \"finish\": 1440, \"limit\": 5, \"s\": \"23\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 11\n\ntest_input = { \"start\": 15, \"finish\": 1440, \"limit\": 5, \"s\": \"31\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 11\n\ntest_input = { \"start\": 15, \"finish\": 1440, \"limit\": 5, \"s\": \"34\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 11\n\ntest_input = { \"start\": 15, \"finish\": 1440, \"limit\": 5, \"s\": \"42\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 10\n\ntest_input = { \"start\": 10, \"finish\": 1844, \"limit\": 5, \"s\": \"12\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 12\n\ntest_input = { \"start\": 10, \"finish\": 1844, \"limit\": 5, \"s\": \"20\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 12\n\ntest_input = { \"start\": 10, \"finish\": 1844, \"limit\": 5, \"s\": \"24\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 12\n\ntest_input = { \"start\": 10, \"finish\": 1844, \"limit\": 5, \"s\": \"30\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 12\n\ntest_input = { \"start\": 10, \"finish\": 1844, \"limit\": 5, \"s\": \"33\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 12\n\ntest_input = { \"start\": 10, \"finish\": 1844, \"limit\": 5, \"s\": \"40\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 12\n\ntest_input = { \"start\": 10, \"finish\": 1844, \"limit\": 5, \"s\": \"42\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 12\n\ntest_input = { \"start\": 10, \"finish\": 1844, \"limit\": 5, \"s\": \"44\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 12\n\ntest_input = { \"start\": 16, \"finish\": 1848, \"limit\": 5, \"s\": \"11\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 11\n\ntest_input = { \"start\": 16, \"finish\": 1848, \"limit\": 5, \"s\": \"13\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 11\n\ntest_input = { \"start\": 16, \"finish\": 1848, \"limit\": 5, \"s\": \"14\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 11\n\ntest_input = { \"start\": 16, \"finish\": 1848, \"limit\": 5, \"s\": \"22\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 12\n\ntest_input = { \"start\": 16, \"finish\": 1848, \"limit\": 5, \"s\": \"30\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 12\n\ntest_input = { \"start\": 16, \"finish\": 1848, \"limit\": 5, \"s\": \"33\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 12\n\ntest_input = { \"start\": 16, \"finish\": 1848, \"limit\": 5, \"s\": \"43\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 12\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"1\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 162\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"10\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"100\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 2\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"11\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"12\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"13\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"14\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"15\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"16\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"17\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"18\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"2\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 162\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"20\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"21\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"22\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"23\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"24\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"25\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"26\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"27\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"28\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"3\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 162\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"30\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"31\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"32\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"33\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"34\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"35\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"36\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"37\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"38\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"4\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 162\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"40\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"41\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"42\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"43\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"44\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"45\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"46\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"47\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"48\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"5\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 162\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"50\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"51\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"52\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18\n\ntest_input = { \"start\": 1, \"finish\": 2000, \"limit\": 8, \"s\": \"53\" }\nassert my_solution.numberOfPowerfulInt(**test_input) == 18", "start_time": 1704551400} +{"task_id": "weekly-contest-378-check-if-bitwise-or-has-trailing-zeros", "url": "https://leetcode.com/problems/check-if-bitwise-or-has-trailing-zeros", "title": "check-if-bitwise-or-has-trailing-zeros", "meta": {"questionId": "3246", "questionFrontendId": "2980", "title": "Check if Bitwise OR Has Trailing Zeros", "titleSlug": "check-if-bitwise-or-has-trailing-zeros", "isPaidOnly": false, "difficulty": "Easy", "likes": 68, "dislikes": 5, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given an array of positive integers nums.\nYou have to check if it is possible to select two or more elements in the array such that the bitwise OR of the selected elements has at least one trailing zero in its binary representation.\nFor example, the binary representation of 5, which is \"101\", does not have any trailing zeros, whereas the binary representation of 4, which is \"100\", has two trailing zeros.\nReturn true if it is possible to select two or more elements whose bitwise OR has trailing zeros, return false otherwise.\n\nExample 1:\n\nInput: nums = [1,2,3,4,5]\nOutput: true\nExplanation: If we select the elements 2 and 4, their bitwise OR is 6, which has the binary representation \"110\" with one trailing zero.\n\nExample 2:\n\nInput: nums = [2,4,8,16]\nOutput: true\nExplanation: If we select the elements 2 and 4, their bitwise OR is 6, which has the binary representation \"110\" with one trailing zero.\nOther possible ways to select elements to have trailing zeroes in the binary representation of their bitwise OR are: (2, 8), (2, 16), (4, 8), (4, 16), (8, 16), (2, 4, 8), (2, 4, 16), (2, 8, 16), (4, 8, 16), and (2, 4, 8, 16).\n\nExample 3:\n\nInput: nums = [1,3,5,7,9]\nOutput: false\nExplanation: There is no possible way to select two or more elements to have trailing zeros in the binary representation of their bitwise OR.\n\n\nConstraints:\n\n2 <= nums.length <= 100\n1 <= nums[i] <= 100\n\"\"\"\nclass Solution:\n def hasTrailingZeros(self, nums: List[int]) -> bool:\n ", "prompt_sft": "You are given an array of positive integers nums.\nYou have to check if it is possible to select two or more elements in the array such that the bitwise OR of the selected elements has at least one trailing zero in its binary representation.\nFor example, the binary representation of 5, which is \"101\", does not have any trailing zeros, whereas the binary representation of 4, which is \"100\", has two trailing zeros.\nReturn true if it is possible to select two or more elements whose bitwise OR has trailing zeros, return false otherwise.\n\nExample 1:\n\nInput: nums = [1,2,3,4,5]\nOutput: true\nExplanation: If we select the elements 2 and 4, their bitwise OR is 6, which has the binary representation \"110\" with one trailing zero.\n\nExample 2:\n\nInput: nums = [2,4,8,16]\nOutput: true\nExplanation: If we select the elements 2 and 4, their bitwise OR is 6, which has the binary representation \"110\" with one trailing zero.\nOther possible ways to select elements to have trailing zeroes in the binary representation of their bitwise OR are: (2, 8), (2, 16), (4, 8), (4, 16), (8, 16), (2, 4, 8), (2, 4, 16), (2, 8, 16), (4, 8, 16), and (2, 4, 8, 16).\n\nExample 3:\n\nInput: nums = [1,3,5,7,9]\nOutput: false\nExplanation: There is no possible way to select two or more elements to have trailing zeros in the binary representation of their bitwise OR.\n\n\nConstraints:\n\n2 <= nums.length <= 100\n1 <= nums[i] <= 100\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def hasTrailingZeros(self, nums: List[int]) -> bool:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,2,3,4,5] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [1,3,5,7,9] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [1,2] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [2,4,8,16] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [1,3] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [1,7] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [3,3] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [3,4] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [2,2] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [4,8] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [4,32] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [6,2] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [6,8] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [3,9] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [4,3] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [5,6] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [7,9] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [8,2] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [8,4] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [7,10] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [9,73] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [8,8] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [10,5] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [11,17] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [19,11] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [19,35] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [19,51] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [21,61] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [23,21] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [25,25] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [10,2] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [12,8] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [27,77] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [16,4] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [16,8] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [16,16] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [16,32] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [29,13] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [37,69] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [39,53] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [24,32] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [32,32] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [42,9] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [45,24] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [64,16] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [49,23] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [4,6,4] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [8,16,4] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [57,27] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [8,16,16] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [10,4,6] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [12,8,8] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [63,47] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [67,69] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [69,87] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [16,8,4] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [77,49] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [89,31] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [1,3,4] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [1,5,3] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [1,7,9] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [3,69,59] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [16,16,16] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [6,5,5] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [7,77,9] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [9,77,51] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [16,32,8] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [16,32,16] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [10,1,9] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [10,7,5] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [11,23,27] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [15,13,63] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [21,27,79] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [23,23,47] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [35,91,15] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [32,4,16] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [32,8,48] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [33,40,84] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [41,83,53] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [64,48,6] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [75,34,58] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [3,8,2,3] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [43,15,41] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [43,65,79] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [47,7,19] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [4,6,1,1] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [4,10,1,7] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [49,73,81] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [6,3,10,6] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [6,4,2,8] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [6,12,12,24] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [7,2,4,4] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [8,6,4,32] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [8,12,16,2] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [12,64,16,8] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [16,4,8,16] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [51,33,25] }\nassert my_solution.hasTrailingZeros(**test_input) == False\n\ntest_input = { \"nums\": [16,8,64,4] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [16,16,12,8] }\nassert my_solution.hasTrailingZeros(**test_input) == True\n\ntest_input = { \"nums\": [51,43,9] }\nassert my_solution.hasTrailingZeros(**test_input) == False", "start_time": 1703989800} +{"task_id": "weekly-contest-378-find-longest-special-substring-that-occurs-thrice-i", "url": "https://leetcode.com/problems/find-longest-special-substring-that-occurs-thrice-i", "title": "find-longest-special-substring-that-occurs-thrice-i", "meta": {"questionId": "3267", "questionFrontendId": "2981", "title": "Find Longest Special Substring That Occurs Thrice I", "titleSlug": "find-longest-special-substring-that-occurs-thrice-i", "isPaidOnly": false, "difficulty": "Medium", "likes": 112, "dislikes": 6, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a string s that consists of lowercase English letters.\nA string is called special if it is made up of only a single character. For example, the string \"abc\" is not special, whereas the strings \"ddd\", \"zz\", and \"f\" are special.\nReturn the length of the longest special substring of s which occurs at least thrice, or -1 if no special substring occurs at least thrice.\nA substring is a contiguous non-empty sequence of characters within a string.\n\nExample 1:\n\nInput: s = \"aaaa\"\nOutput: 2\nExplanation: The longest special substring which occurs thrice is \"aa\": substrings \"aaaa\", \"aaaa\", and \"aaaa\".\nIt can be shown that the maximum length achievable is 2.\n\nExample 2:\n\nInput: s = \"abcdef\"\nOutput: -1\nExplanation: There exists no special substring which occurs at least thrice. Hence return -1.\n\nExample 3:\n\nInput: s = \"abcaba\"\nOutput: 1\nExplanation: The longest special substring which occurs thrice is \"a\": substrings \"abcaba\", \"abcaba\", and \"abcaba\".\nIt can be shown that the maximum length achievable is 1.\n\n\nConstraints:\n\n3 <= s.length <= 50\ns consists of only lowercase English letters.\n\"\"\"\nclass Solution:\n def maximumLength(self, s: str) -> int:\n ", "prompt_sft": "You are given a string s that consists of lowercase English letters.\nA string is called special if it is made up of only a single character. For example, the string \"abc\" is not special, whereas the strings \"ddd\", \"zz\", and \"f\" are special.\nReturn the length of the longest special substring of s which occurs at least thrice, or -1 if no special substring occurs at least thrice.\nA substring is a contiguous non-empty sequence of characters within a string.\n\nExample 1:\n\nInput: s = \"aaaa\"\nOutput: 2\nExplanation: The longest special substring which occurs thrice is \"aa\": substrings \"aaaa\", \"aaaa\", and \"aaaa\".\nIt can be shown that the maximum length achievable is 2.\n\nExample 2:\n\nInput: s = \"abcdef\"\nOutput: -1\nExplanation: There exists no special substring which occurs at least thrice. Hence return -1.\n\nExample 3:\n\nInput: s = \"abcaba\"\nOutput: 1\nExplanation: The longest special substring which occurs thrice is \"a\": substrings \"abcaba\", \"abcaba\", and \"abcaba\".\nIt can be shown that the maximum length achievable is 1.\n\n\nConstraints:\n\n3 <= s.length <= 50\ns consists of only lowercase English letters.\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def maximumLength(self, s: str) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"s\": \"aaaa\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"abcdef\" }\nassert my_solution.maximumLength(**test_input) == -1\n\ntest_input = { \"s\": \"abcaba\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"abcccccdddd\" }\nassert my_solution.maximumLength(**test_input) == 3\n\ntest_input = { \"s\": \"aaa\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"acc\" }\nassert my_solution.maximumLength(**test_input) == -1\n\ntest_input = { \"s\": \"cab\" }\nassert my_solution.maximumLength(**test_input) == -1\n\ntest_input = { \"s\": \"cad\" }\nassert my_solution.maximumLength(**test_input) == -1\n\ntest_input = { \"s\": \"cbc\" }\nassert my_solution.maximumLength(**test_input) == -1\n\ntest_input = { \"s\": \"ccc\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"dca\" }\nassert my_solution.maximumLength(**test_input) == -1\n\ntest_input = { \"s\": \"ddd\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"fff\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"ggg\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"hhh\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"kkk\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"lll\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"ooo\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"ppp\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"qqq\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"rrr\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"xxx\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"yyy\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"aaau\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"affe\" }\nassert my_solution.maximumLength(**test_input) == -1\n\ntest_input = { \"s\": \"agae\" }\nassert my_solution.maximumLength(**test_input) == -1\n\ntest_input = { \"s\": \"aiii\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"bbbb\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"bbbz\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"bddd\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"beee\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"bnnn\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"bsss\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"bxxx\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"cafc\" }\nassert my_solution.maximumLength(**test_input) == -1\n\ntest_input = { \"s\": \"ccag\" }\nassert my_solution.maximumLength(**test_input) == -1\n\ntest_input = { \"s\": \"cfff\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"dddd\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"dsss\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"eccc\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"eeew\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"gfdc\" }\nassert my_solution.maximumLength(**test_input) == -1\n\ntest_input = { \"s\": \"giii\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"hhhn\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"hyyy\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"iiii\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"jiii\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"jjjj\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"kbbb\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"kddd\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"looo\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"nnnn\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"oaaa\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"osss\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"pppp\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"pppw\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"qqqc\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"qqqo\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"qqqq\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"reee\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"rzzz\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"thhh\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"tttt\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"unnn\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"uuuu\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"uyyy\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"vddd\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"vfff\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"vvvv\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"wbbb\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"wqqq\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"wwwg\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"xxxk\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"xxxx\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"zfff\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"ammmm\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"aqqqu\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"axxxx\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"bahhh\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"bbbbz\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"bbccc\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"biaei\" }\nassert my_solution.maximumLength(**test_input) == -1\n\ntest_input = { \"s\": \"bjjjj\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"cccll\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"ceaaa\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"cjlll\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"crqqq\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"cyyyy\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"ddddj\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"ddddt\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"dkkkk\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"eefff\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"efage\" }\nassert my_solution.maximumLength(**test_input) == -1\n\ntest_input = { \"s\": \"epppp\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"fafff\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"ffbbb\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"ffffr\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"gcgbf\" }\nassert my_solution.maximumLength(**test_input) == -1\n\ntest_input = { \"s\": \"gcooo\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"gfgec\" }\nassert my_solution.maximumLength(**test_input) == -1", "start_time": 1703989800} +{"task_id": "weekly-contest-378-find-longest-special-substring-that-occurs-thrice-ii", "url": "https://leetcode.com/problems/find-longest-special-substring-that-occurs-thrice-ii", "title": "find-longest-special-substring-that-occurs-thrice-ii", "meta": {"questionId": "3266", "questionFrontendId": "2982", "title": "Find Longest Special Substring That Occurs Thrice II", "titleSlug": "find-longest-special-substring-that-occurs-thrice-ii", "isPaidOnly": false, "difficulty": "Medium", "likes": 172, "dislikes": 17, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a string s that consists of lowercase English letters.\nA string is called special if it is made up of only a single character. For example, the string \"abc\" is not special, whereas the strings \"ddd\", \"zz\", and \"f\" are special.\nReturn the length of the longest special substring of s which occurs at least thrice, or -1 if no special substring occurs at least thrice.\nA substring is a contiguous non-empty sequence of characters within a string.\n\nExample 1:\n\nInput: s = \"aaaa\"\nOutput: 2\nExplanation: The longest special substring which occurs thrice is \"aa\": substrings \"aaaa\", \"aaaa\", and \"aaaa\".\nIt can be shown that the maximum length achievable is 2.\n\nExample 2:\n\nInput: s = \"abcdef\"\nOutput: -1\nExplanation: There exists no special substring which occurs at least thrice. Hence return -1.\n\nExample 3:\n\nInput: s = \"abcaba\"\nOutput: 1\nExplanation: The longest special substring which occurs thrice is \"a\": substrings \"abcaba\", \"abcaba\", and \"abcaba\".\nIt can be shown that the maximum length achievable is 1.\n\n\nConstraints:\n\n3 <= s.length <= 5 * 105\ns consists of only lowercase English letters.\n\"\"\"\nclass Solution:\n def maximumLength(self, s: str) -> int:\n ", "prompt_sft": "You are given a string s that consists of lowercase English letters.\nA string is called special if it is made up of only a single character. For example, the string \"abc\" is not special, whereas the strings \"ddd\", \"zz\", and \"f\" are special.\nReturn the length of the longest special substring of s which occurs at least thrice, or -1 if no special substring occurs at least thrice.\nA substring is a contiguous non-empty sequence of characters within a string.\n\nExample 1:\n\nInput: s = \"aaaa\"\nOutput: 2\nExplanation: The longest special substring which occurs thrice is \"aa\": substrings \"aaaa\", \"aaaa\", and \"aaaa\".\nIt can be shown that the maximum length achievable is 2.\n\nExample 2:\n\nInput: s = \"abcdef\"\nOutput: -1\nExplanation: There exists no special substring which occurs at least thrice. Hence return -1.\n\nExample 3:\n\nInput: s = \"abcaba\"\nOutput: 1\nExplanation: The longest special substring which occurs thrice is \"a\": substrings \"abcaba\", \"abcaba\", and \"abcaba\".\nIt can be shown that the maximum length achievable is 1.\n\n\nConstraints:\n\n3 <= s.length <= 5 * 105\ns consists of only lowercase English letters.\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def maximumLength(self, s: str) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"s\": \"aaaa\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"abcdef\" }\nassert my_solution.maximumLength(**test_input) == -1\n\ntest_input = { \"s\": \"abcaba\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"abcccccdddd\" }\nassert my_solution.maximumLength(**test_input) == 3\n\ntest_input = { \"s\": \"acd\" }\nassert my_solution.maximumLength(**test_input) == -1\n\ntest_input = { \"s\": \"bad\" }\nassert my_solution.maximumLength(**test_input) == -1\n\ntest_input = { \"s\": \"bbc\" }\nassert my_solution.maximumLength(**test_input) == -1\n\ntest_input = { \"s\": \"ccc\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"cda\" }\nassert my_solution.maximumLength(**test_input) == -1\n\ntest_input = { \"s\": \"dab\" }\nassert my_solution.maximumLength(**test_input) == -1\n\ntest_input = { \"s\": \"ddd\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"eee\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"fff\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"hhh\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"jjj\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"kkk\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"lll\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"mmm\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"nnn\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"ooo\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"ppp\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"qqq\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"rrr\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"sss\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"vvv\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"yyy\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"aaaj\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"aada\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"accc\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"auuu\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"azzz\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"bbbb\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"bbbr\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"bccc\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"brrr\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"cccc\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"clll\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"dbac\" }\nassert my_solution.maximumLength(**test_input) == -1\n\ntest_input = { \"s\": \"dddd\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"dddr\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"dddu\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"dzzz\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"eeee\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"efda\" }\nassert my_solution.maximumLength(**test_input) == -1\n\ntest_input = { \"s\": \"efdc\" }\nassert my_solution.maximumLength(**test_input) == -1\n\ntest_input = { \"s\": \"ekkk\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"ggge\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"gggp\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"gggr\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"gggy\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"guuu\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"hwww\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"hxxx\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"jjjj\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"jjjk\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"kkkk\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"lllm\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"lttt\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"mwww\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"nnnd\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"nnni\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"oooe\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"oooh\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"oooo\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"oooq\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"paaa\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"pggg\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"qooo\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"rrrr\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"smmm\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"thhh\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"tttt\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"uuuu\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"vppp\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"xqqq\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"xxxj\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"ysss\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"zzzz\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"aaaak\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"bbbjj\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"bbvvv\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"bfooo\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"buooo\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"cffff\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"cirrr\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"cwwwv\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"ddhhh\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"deeee\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"deiii\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"dtttk\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"eeeeq\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"eeekk\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"eesss\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"euuuu\" }\nassert my_solution.maximumLength(**test_input) == 2\n\ntest_input = { \"s\": \"euylz\" }\nassert my_solution.maximumLength(**test_input) == -1\n\ntest_input = { \"s\": \"fffhh\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"fpddd\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"gcccn\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"gtwww\" }\nassert my_solution.maximumLength(**test_input) == 1\n\ntest_input = { \"s\": \"hcfff\" }\nassert my_solution.maximumLength(**test_input) == 1", "start_time": 1703989800} +{"task_id": "weekly-contest-378-palindrome-rearrangement-queries", "url": "https://leetcode.com/problems/palindrome-rearrangement-queries", "title": "palindrome-rearrangement-queries", "meta": {"questionId": "3203", "questionFrontendId": "2983", "title": "Palindrome Rearrangement Queries", "titleSlug": "palindrome-rearrangement-queries", "isPaidOnly": false, "difficulty": "Hard", "likes": 73, "dislikes": 23, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed string s having an even length n.\nYou are also given a 0-indexed 2D integer array, queries, where queries[i] = [ai, bi, ci, di].\nFor each query i, you are allowed to perform the following operations:\n\nRearrange the characters within the substring s[ai:bi], where 0 <= ai <= bi < n / 2.\nRearrange the characters within the substring s[ci:di], where n / 2 <= ci <= di < n.\n\nFor each query, your task is to determine whether it is possible to make s a palindrome by performing the operations.\nEach query is answered independently of the others.\nReturn a 0-indexed array answer, where answer[i] == true if it is possible to make s a palindrome by performing operations specified by the ith query, and false otherwise.\n\nA substring is a contiguous sequence of characters within a string.\ns[x:y] represents the substring consisting of characters from the index x to index y in s, both inclusive.\n\n\nExample 1:\n\nInput: s = \"abcabc\", queries = [[1,1,3,5],[0,2,5,5]]\nOutput: [true,true]\nExplanation: In this example, there are two queries:\nIn the first query:\n- a0 = 1, b0 = 1, c0 = 3, d0 = 5.\n- So, you are allowed to rearrange s[1:1] => abcabc and s[3:5] => abcabc.\n- To make s a palindrome, s[3:5] can be rearranged to become => abccba.\n- Now, s is a palindrome. So, answer[0] = true.\nIn the second query:\n- a1 = 0, b1 = 2, c1 = 5, d1 = 5.\n- So, you are allowed to rearrange s[0:2] => abcabc and s[5:5] => abcabc.\n- To make s a palindrome, s[0:2] can be rearranged to become => cbaabc.\n- Now, s is a palindrome. So, answer[1] = true.\n\nExample 2:\n\nInput: s = \"abbcdecbba\", queries = [[0,2,7,9]]\nOutput: [false]\nExplanation: In this example, there is only one query.\na0 = 0, b0 = 2, c0 = 7, d0 = 9.\nSo, you are allowed to rearrange s[0:2] => abbcdecbba and s[7:9] => abbcdecbba.\nIt is not possible to make s a palindrome by rearranging these substrings because s[3:6] is not a palindrome.\nSo, answer[0] = false.\nExample 3:\n\nInput: s = \"acbcab\", queries = [[1,2,4,5]]\nOutput: [true]\nExplanation: In this example, there is only one query.\na0 = 1, b0 = 2, c0 = 4, d0 = 5.\nSo, you are allowed to rearrange s[1:2] => acbcab and s[4:5] => acbcab.\nTo make s a palindrome s[1:2] can be rearranged to become abccab.\nThen, s[4:5] can be rearranged to become abccba.\nNow, s is a palindrome. So, answer[0] = true.\n\nConstraints:\n\n2 <= n == s.length <= 105\n1 <= queries.length <= 105\nqueries[i].length == 4\nai == queries[i][0], bi == queries[i][1]\nci == queries[i][2], di == queries[i][3]\n0 <= ai <= bi < n / 2\nn / 2 <= ci <= di < n \nn is even.\ns consists of only lowercase English letters.\n\"\"\"\nclass Solution:\n def canMakePalindromeQueries(self, s: str, queries: List[List[int]]) -> List[bool]:\n ", "prompt_sft": "You are given a 0-indexed string s having an even length n.\nYou are also given a 0-indexed 2D integer array, queries, where queries[i] = [ai, bi, ci, di].\nFor each query i, you are allowed to perform the following operations:\n\nRearrange the characters within the substring s[ai:bi], where 0 <= ai <= bi < n / 2.\nRearrange the characters within the substring s[ci:di], where n / 2 <= ci <= di < n.\n\nFor each query, your task is to determine whether it is possible to make s a palindrome by performing the operations.\nEach query is answered independently of the others.\nReturn a 0-indexed array answer, where answer[i] == true if it is possible to make s a palindrome by performing operations specified by the ith query, and false otherwise.\n\nA substring is a contiguous sequence of characters within a string.\ns[x:y] represents the substring consisting of characters from the index x to index y in s, both inclusive.\n\n\nExample 1:\n\nInput: s = \"abcabc\", queries = [[1,1,3,5],[0,2,5,5]]\nOutput: [true,true]\nExplanation: In this example, there are two queries:\nIn the first query:\n- a0 = 1, b0 = 1, c0 = 3, d0 = 5.\n- So, you are allowed to rearrange s[1:1] => abcabc and s[3:5] => abcabc.\n- To make s a palindrome, s[3:5] can be rearranged to become => abccba.\n- Now, s is a palindrome. So, answer[0] = true.\nIn the second query:\n- a1 = 0, b1 = 2, c1 = 5, d1 = 5.\n- So, you are allowed to rearrange s[0:2] => abcabc and s[5:5] => abcabc.\n- To make s a palindrome, s[0:2] can be rearranged to become => cbaabc.\n- Now, s is a palindrome. So, answer[1] = true.\n\nExample 2:\n\nInput: s = \"abbcdecbba\", queries = [[0,2,7,9]]\nOutput: [false]\nExplanation: In this example, there is only one query.\na0 = 0, b0 = 2, c0 = 7, d0 = 9.\nSo, you are allowed to rearrange s[0:2] => abbcdecbba and s[7:9] => abbcdecbba.\nIt is not possible to make s a palindrome by rearranging these substrings because s[3:6] is not a palindrome.\nSo, answer[0] = false.\nExample 3:\n\nInput: s = \"acbcab\", queries = [[1,2,4,5]]\nOutput: [true]\nExplanation: In this example, there is only one query.\na0 = 1, b0 = 2, c0 = 4, d0 = 5.\nSo, you are allowed to rearrange s[1:2] => acbcab and s[4:5] => acbcab.\nTo make s a palindrome s[1:2] can be rearranged to become abccab.\nThen, s[4:5] can be rearranged to become abccba.\nNow, s is a palindrome. So, answer[0] = true.\n\nConstraints:\n\n2 <= n == s.length <= 105\n1 <= queries.length <= 105\nqueries[i].length == 4\nai == queries[i][0], bi == queries[i][1]\nci == queries[i][2], di == queries[i][3]\n0 <= ai <= bi < n / 2\nn / 2 <= ci <= di < n \nn is even.\ns consists of only lowercase English letters.\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def canMakePalindromeQueries(self, s: str, queries: List[List[int]]) -> List[bool]:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"s\": \"abcabc\", \"queries\": [[1,1,3,5],[0,2,5,5]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True,True]\n\ntest_input = { \"s\": \"abbcdecbba\", \"queries\": [[0,2,7,9]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False]\n\ntest_input = { \"s\": \"acbcab\", \"queries\": [[1,2,4,5]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True]\n\ntest_input = { \"s\": \"bcdbdc\", \"queries\": [[1,2,3,3]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False]\n\ntest_input = { \"s\": \"bb\", \"queries\": [[0,0,1,1]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True]\n\ntest_input = { \"s\": \"eoquueqo\", \"queries\": [[3,3,6,6]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False]\n\ntest_input = { \"s\": \"dd\", \"queries\": [[0,0,1,1]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True]\n\ntest_input = { \"s\": \"ceddceddcc\", \"queries\": [[0,1,6,8]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False]\n\ntest_input = { \"s\": \"bdbd\", \"queries\": [[0,0,2,3]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True]\n\ntest_input = { \"s\": \"eeee\", \"queries\": [[0,1,2,3]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True]\n\ntest_input = { \"s\": \"deebdeeddb\", \"queries\": [[1,2,5,7]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False]\n\ntest_input = { \"s\": \"xwaswsxwaw\", \"queries\": [[1,3,5,6]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False]\n\ntest_input = { \"s\": \"askloakosala\", \"queries\": [[2,4,7,10]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False]\n\ntest_input = { \"s\": \"bbccbb\", \"queries\": [[0,1,4,5]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True]\n\ntest_input = { \"s\": \"djaypzjpyzad\", \"queries\": [[0,3,7,8]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False]\n\ntest_input = { \"s\": \"ajvnbnznjnzbva\", \"queries\": [[5,6,10,11]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False]\n\ntest_input = { \"s\": \"vbeptwzvtwpzbe\", \"queries\": [[3,6,10,11]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False]\n\ntest_input = { \"s\": \"cababc\", \"queries\": [[1,2,3,4]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True]\n\ntest_input = { \"s\": \"cbbbbc\", \"queries\": [[1,1,5,5]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True]\n\ntest_input = { \"s\": \"qupzexxhqxpzhxeu\", \"queries\": [[2,4,8,12]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False]\n\ntest_input = { \"s\": \"cdbdbc\", \"queries\": [[1,2,3,3]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True]\n\ntest_input = { \"s\": \"odaxusaweuasuoeudxwa\", \"queries\": [[0,5,10,14]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False]\n\ntest_input = { \"s\": \"ujfscqolkwjucoswlkfq\", \"queries\": [[1,9,17,18]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False]\n\ntest_input = { \"s\": \"ceacea\", \"queries\": [[0,2,3,5]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True]\n\ntest_input = { \"s\": \"bnjzcgmnecxxbmnjngxzecxc\", \"queries\": [[8,9,19,22]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False]\n\ntest_input = { \"s\": \"daeaed\", \"queries\": [[0,2,3,3]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True]\n\ntest_input = { \"s\": \"ddaadd\", \"queries\": [[0,2,3,4]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True]\n\ntest_input = { \"s\": \"ddedde\", \"queries\": [[0,2,4,5]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True]\n\ntest_input = { \"s\": \"pmzwetzhzursuhmeswpzrztz\", \"queries\": [[4,6,16,17]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False]\n\ntest_input = { \"s\": \"qcryjkdzmqyoojzrckymdqyq\", \"queries\": [[2,8,21,22]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False]\n\ntest_input = { \"s\": \"qdltkndnclarncadtqnlldkr\", \"queries\": [[3,4,15,16]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False]\n\ntest_input = { \"s\": \"ecbbce\", \"queries\": [[0,1,3,5]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True]\n\ntest_input = { \"s\": \"eczecz\", \"queries\": [[0,0,3,5]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True]\n\ntest_input = { \"s\": \"etuouqokbalafokfbuqaaoetlu\", \"queries\": [[3,11,21,23]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False]\n\ntest_input = { \"s\": \"mpepem\", \"queries\": [[0,2,3,4]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True]\n\ntest_input = { \"s\": \"nbpechkpmudbsenphdmsbbupck\", \"queries\": [[6,7,18,19]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False]\n\ntest_input = { \"s\": \"bccacacb\", \"queries\": [[3,3,4,7]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True]\n\ntest_input = { \"s\": \"stgjtzqwgkuadjgqugkwdtzast\", \"queries\": [[5,10,13,23]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False]\n\ntest_input = { \"s\": \"qiyikbayvhkcgxyaqckgxkhivbyi\", \"queries\": [[5,12,17,24]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False]\n\ntest_input = { \"s\": \"ceedceed\", \"queries\": [[0,1,4,7]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True]\n\ntest_input = { \"s\": \"rcguwczbjhjhgqrggqcbwjzhjuch\", \"queries\": [[5,7,16,20]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False]\n\ntest_input = { \"s\": \"ckwbnmqmtzbixrrkixbtbqzmnwmc\", \"queries\": [[1,9,15,24]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True]\n\ntest_input = { \"s\": \"riirxzxuqpspoiixpirsoxrzpiuq\", \"queries\": [[1,6,14,21]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False]\n\ntest_input = { \"s\": \"geettndnusqufidtqdfgtsieenundu\", \"queries\": [[6,8,19,23]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False]\n\ntest_input = { \"s\": \"bb\", \"queries\": [[0,0,1,1],[0,0,1,1]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True,True]\n\ntest_input = { \"s\": \"cc\", \"queries\": [[0,0,1,1],[0,0,1,1]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True,True]\n\ntest_input = { \"s\": \"dd\", \"queries\": [[0,0,1,1],[0,0,1,1]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True,True]\n\ntest_input = { \"s\": \"ee\", \"queries\": [[0,0,1,1],[0,0,1,1]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True,True]\n\ntest_input = { \"s\": \"aeae\", \"queries\": [[1,1,2,3],[1,1,3,3]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True,False]\n\ntest_input = { \"s\": \"eaae\", \"queries\": [[0,1,3,3],[0,0,2,3]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True,True]\n\ntest_input = { \"s\": \"eded\", \"queries\": [[0,1,2,3],[1,1,2,3]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True,True]\n\ntest_input = { \"s\": \"lrlr\", \"queries\": [[0,1,2,3],[0,0,2,2]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True,False]\n\ntest_input = { \"s\": \"dbaabd\", \"queries\": [[0,1,5,5],[1,2,4,5]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True,True]\n\ntest_input = { \"s\": \"dcbcbd\", \"queries\": [[0,1,4,4],[0,2,3,4]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,True]\n\ntest_input = { \"s\": \"hykkyh\", \"queries\": [[0,0,3,4],[1,2,3,4]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True,True]\n\ntest_input = { \"s\": \"lvrvrl\", \"queries\": [[2,2,4,5],[0,2,3,4]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,True]\n\ntest_input = { \"s\": \"adceaecd\", \"queries\": [[3,3,5,5],[0,1,4,6]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,True]\n\ntest_input = { \"s\": \"baadadba\", \"queries\": [[1,2,4,5],[0,2,4,5]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,True]\n\ntest_input = { \"s\": \"bceaabec\", \"queries\": [[1,3,4,7],[0,2,6,6]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True,True]\n\ntest_input = { \"s\": \"ifchcifh\", \"queries\": [[1,2,5,6],[1,1,4,6]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,False]\n\ntest_input = { \"s\": \"adeeeeeaed\", \"queries\": [[2,4,7,9],[3,4,8,8]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True,False]\n\ntest_input = { \"s\": \"aedbdbddea\", \"queries\": [[4,4,7,8],[2,2,8,9]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,False]\n\ntest_input = { \"s\": \"caeaaaaaec\", \"queries\": [[0,2,5,8],[0,0,5,9]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True,True]\n\ntest_input = { \"s\": \"dbaccccdba\", \"queries\": [[4,4,6,7],[2,3,8,9]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,False]\n\ntest_input = { \"s\": \"deabadabea\", \"queries\": [[0,3,7,9],[0,2,5,7]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,True]\n\ntest_input = { \"s\": \"eddeededee\", \"queries\": [[0,3,6,9],[0,0,6,9]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,False]\n\ntest_input = { \"s\": \"eedbbedebb\", \"queries\": [[2,2,6,7],[2,2,5,6]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,False]\n\ntest_input = { \"s\": \"gvtkakgvat\", \"queries\": [[1,2,7,7],[2,3,7,9]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,False]\n\ntest_input = { \"s\": \"bzvvicviczbv\", \"queries\": [[1,2,7,8],[1,4,7,8]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,False]\n\ntest_input = { \"s\": \"ljccjajcljac\", \"queries\": [[2,4,6,10],[3,5,7,9]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,False]\n\ntest_input = { \"s\": \"rxvzvezvrvxe\", \"queries\": [[1,4,8,10],[3,3,10,11]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,False]\n\ntest_input = { \"s\": \"amgpelwpmlaewg\", \"queries\": [[3,4,7,9],[0,6,7,10]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,True]\n\ntest_input = { \"s\": \"leubdglmbglleudm\", \"queries\": [[1,3,9,14],[2,6,13,14]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,False]\n\ntest_input = { \"s\": \"ooxuznriuzrooixn\", \"queries\": [[1,3,10,12],[1,4,9,13]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,False]\n\ntest_input = { \"s\": \"nlaonaphinpnalohai\", \"queries\": [[2,5,13,13],[2,7,9,14]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,False]\n\ntest_input = { \"s\": \"rujokutobuttlysjusrtltuobkoytu\", \"queries\": [[5,6,18,23],[10,13,15,26]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,False]\n\ntest_input = { \"s\": \"bb\", \"queries\": [[0,0,1,1],[0,0,1,1],[0,0,1,1]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True,True,True]\n\ntest_input = { \"s\": \"cc\", \"queries\": [[0,0,1,1],[0,0,1,1],[0,0,1,1]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True,True,True]\n\ntest_input = { \"s\": \"dbdb\", \"queries\": [[0,0,2,2],[1,1,3,3],[0,1,2,3]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,False,True]\n\ntest_input = { \"s\": \"ebbe\", \"queries\": [[0,1,3,3],[1,1,2,2],[0,0,2,3]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True,True,True]\n\ntest_input = { \"s\": \"acacaa\", \"queries\": [[0,1,5,5],[1,1,4,4],[1,2,3,4]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,False,True]\n\ntest_input = { \"s\": \"bbaabb\", \"queries\": [[0,1,4,5],[0,2,3,5],[2,2,5,5]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True,True,True]\n\ntest_input = { \"s\": \"bbebbe\", \"queries\": [[0,1,3,5],[2,2,4,5],[0,1,5,5]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True,False,False]\n\ntest_input = { \"s\": \"ddaadd\", \"queries\": [[1,1,4,4],[0,0,4,4],[0,2,3,5]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True,True,True]\n\ntest_input = { \"s\": \"nlhhln\", \"queries\": [[2,2,4,5],[1,2,5,5],[2,2,3,3]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True,True,True]\n\ntest_input = { \"s\": \"zbebez\", \"queries\": [[0,2,5,5],[1,1,3,5],[0,2,4,5]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True,True,True]\n\ntest_input = { \"s\": \"cbcbbcbc\", \"queries\": [[0,2,7,7],[1,2,4,7],[0,2,4,5]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True,True,True]\n\ntest_input = { \"s\": \"deceecde\", \"queries\": [[3,3,6,7],[1,2,4,5],[2,3,7,7]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True,False,False]\n\ntest_input = { \"s\": \"fydyfyyd\", \"queries\": [[0,2,4,6],[1,3,4,7],[2,3,6,7]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [True,True,False]\n\ntest_input = { \"s\": \"dccabcdbca\", \"queries\": [[1,3,5,8],[2,4,7,7],[0,2,6,9]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,False,False]\n\ntest_input = { \"s\": \"eacbdeacbd\", \"queries\": [[4,4,8,9],[3,4,7,9],[0,0,6,8]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,False,False]\n\ntest_input = { \"s\": \"eddaaedada\", \"queries\": [[0,1,7,8],[0,1,7,8],[0,3,7,9]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,False,False]\n\ntest_input = { \"s\": \"vvsbgsvgbv\", \"queries\": [[0,1,6,9],[2,3,8,9],[0,0,6,7]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,False,False]\n\ntest_input = { \"s\": \"sukesivksseuiv\", \"queries\": [[2,3,11,13],[5,5,7,13],[2,5,8,13]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,True,False]\n\ntest_input = { \"s\": \"pbcjpsfxwtbcfjwpsptx\", \"queries\": [[0,4,13,13],[5,5,15,18],[2,3,13,18]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,False,False]\n\ntest_input = { \"s\": \"natvhtruvwyutyvvnarhwt\", \"queries\": [[5,7,14,21],[0,8,11,19],[2,8,11,14]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,False,False]\n\ntest_input = { \"s\": \"yjsjywxbriejyxieysrwbj\", \"queries\": [[4,5,15,19],[1,9,12,17],[3,6,12,18]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,False,False]\n\ntest_input = { \"s\": \"ellaghdbmazdallhmegabddz\", \"queries\": [[4,6,13,19],[4,11,17,17],[7,10,13,16]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,False,False]\n\ntest_input = { \"s\": \"wcfnhuaulqxbuuxafcwhnbql\", \"queries\": [[5,11,13,18],[7,8,18,21],[3,6,21,23]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,False,False]\n\ntest_input = { \"s\": \"qyioinjmvpgpropimvqiygrnjp\", \"queries\": [[1,4,15,25],[1,8,19,22],[4,9,18,23]] }\nassert my_solution.canMakePalindromeQueries(**test_input) == [False,False,False]", "start_time": 1703989800} +{"task_id": "weekly-contest-377-minimum-number-game", "url": "https://leetcode.com/problems/minimum-number-game", "title": "minimum-number-game", "meta": {"questionId": "3226", "questionFrontendId": "2974", "title": "Minimum Number Game", "titleSlug": "minimum-number-game", "isPaidOnly": false, "difficulty": "Easy", "likes": 38, "dislikes": 2, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed integer array nums of even length and there is also an empty array arr. Alice and Bob decided to play a game where in every round Alice and Bob will do one move. The rules of the game are as follows:\n\nEvery round, first Alice will remove the minimum element from nums, and then Bob does the same.\nNow, first Bob will append the removed element in the array arr, and then Alice does the same.\nThe game continues until nums becomes empty.\n\nReturn the resulting array arr.\n\nExample 1:\n\nInput: nums = [5,4,2,3]\nOutput: [3,2,5,4]\nExplanation: In round one, first Alice removes 2 and then Bob removes 3. Then in arr firstly Bob appends 3 and then Alice appends 2. So arr = [3,2].\nAt the begining of round two, nums = [5,4]. Now, first Alice removes 4 and then Bob removes 5. Then both append in arr which becomes [3,2,5,4].\n\nExample 2:\n\nInput: nums = [2,5]\nOutput: [5,2]\nExplanation: In round one, first Alice removes 2 and then Bob removes 5. Then in arr firstly Bob appends and then Alice appends. So arr = [5,2].\n\n\nConstraints:\n\n1 <= nums.length <= 100\n1 <= nums[i] <= 100\nnums.length % 2 == 0\n\"\"\"\nclass Solution:\n def numberGame(self, nums: List[int]) -> List[int]:\n ", "prompt_sft": "You are given a 0-indexed integer array nums of even length and there is also an empty array arr. Alice and Bob decided to play a game where in every round Alice and Bob will do one move. The rules of the game are as follows:\n\nEvery round, first Alice will remove the minimum element from nums, and then Bob does the same.\nNow, first Bob will append the removed element in the array arr, and then Alice does the same.\nThe game continues until nums becomes empty.\n\nReturn the resulting array arr.\n\nExample 1:\n\nInput: nums = [5,4,2,3]\nOutput: [3,2,5,4]\nExplanation: In round one, first Alice removes 2 and then Bob removes 3. Then in arr firstly Bob appends 3 and then Alice appends 2. So arr = [3,2].\nAt the begining of round two, nums = [5,4]. Now, first Alice removes 4 and then Bob removes 5. Then both append in arr which becomes [3,2,5,4].\n\nExample 2:\n\nInput: nums = [2,5]\nOutput: [5,2]\nExplanation: In round one, first Alice removes 2 and then Bob removes 5. Then in arr firstly Bob appends and then Alice appends. So arr = [5,2].\n\n\nConstraints:\n\n1 <= nums.length <= 100\n1 <= nums[i] <= 100\nnums.length % 2 == 0\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def numberGame(self, nums: List[int]) -> List[int]:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [5,4,2,3] }\nassert my_solution.numberGame(**test_input) == [3,2,5,4]\n\ntest_input = { \"nums\": [2,5] }\nassert my_solution.numberGame(**test_input) == [5,2]\n\ntest_input = { \"nums\": [4,4,3,8] }\nassert my_solution.numberGame(**test_input) == [4,3,8,4]\n\ntest_input = { \"nums\": [2,5,3,8] }\nassert my_solution.numberGame(**test_input) == [3,2,8,5]\n\ntest_input = { \"nums\": [2,7,9,6,4,6] }\nassert my_solution.numberGame(**test_input) == [4,2,6,6,9,7]\n\ntest_input = { \"nums\": [18,26,37,46,13,33,39,1,37,16] }\nassert my_solution.numberGame(**test_input) == [13,1,18,16,33,26,37,37,46,39]\n\ntest_input = { \"nums\": [17,2,4,11,14,18] }\nassert my_solution.numberGame(**test_input) == [4,2,14,11,18,17]\n\ntest_input = { \"nums\": [20,30,12,3,11,17,32,12] }\nassert my_solution.numberGame(**test_input) == [11,3,12,12,20,17,32,30]\n\ntest_input = { \"nums\": [9,32,6,11,11,39,18,29,44,29] }\nassert my_solution.numberGame(**test_input) == [9,6,11,11,29,18,32,29,44,39]\n\ntest_input = { \"nums\": [7,2,3,4] }\nassert my_solution.numberGame(**test_input) == [3,2,7,4]\n\ntest_input = { \"nums\": [8,7,1,3] }\nassert my_solution.numberGame(**test_input) == [3,1,8,7]\n\ntest_input = { \"nums\": [2,6,6,6] }\nassert my_solution.numberGame(**test_input) == [6,2,6,6]\n\ntest_input = { \"nums\": [1,2] }\nassert my_solution.numberGame(**test_input) == [2,1]\n\ntest_input = { \"nums\": [4,1,1,3] }\nassert my_solution.numberGame(**test_input) == [1,1,4,3]\n\ntest_input = { \"nums\": [13,12,18,11,15,28,26,2] }\nassert my_solution.numberGame(**test_input) == [11,2,13,12,18,15,28,26]\n\ntest_input = { \"nums\": [14,30,29,3,23,21,26,23] }\nassert my_solution.numberGame(**test_input) == [14,3,23,21,26,23,30,29]\n\ntest_input = { \"nums\": [1,1] }\nassert my_solution.numberGame(**test_input) == [1,1]\n\ntest_input = { \"nums\": [2,1] }\nassert my_solution.numberGame(**test_input) == [2,1]\n\ntest_input = { \"nums\": [12,1,28,23,2,31,11,26] }\nassert my_solution.numberGame(**test_input) == [2,1,12,11,26,23,31,28]\n\ntest_input = { \"nums\": [21,11,37,1,40,50,49,45,28,47] }\nassert my_solution.numberGame(**test_input) == [11,1,28,21,40,37,47,45,50,49]\n\ntest_input = { \"nums\": [25,22,31,7,30,9,9,18] }\nassert my_solution.numberGame(**test_input) == [9,7,18,9,25,22,31,30]\n\ntest_input = { \"nums\": [2,4,10,9,16,9] }\nassert my_solution.numberGame(**test_input) == [4,2,9,9,16,10]\n\ntest_input = { \"nums\": [5,2,3,5] }\nassert my_solution.numberGame(**test_input) == [3,2,5,5]\n\ntest_input = { \"nums\": [6,44,37,6,28,44,30,36,25,24] }\nassert my_solution.numberGame(**test_input) == [6,6,25,24,30,28,37,36,44,44]\n\ntest_input = { \"nums\": [17,10,6,14,10,18] }\nassert my_solution.numberGame(**test_input) == [10,6,14,10,18,17]\n\ntest_input = { \"nums\": [40,24,23,29,37,26,39,34,39,23] }\nassert my_solution.numberGame(**test_input) == [23,23,26,24,34,29,39,37,40,39]\n\ntest_input = { \"nums\": [2,2] }\nassert my_solution.numberGame(**test_input) == [2,2]\n\ntest_input = { \"nums\": [33,5,31,43,48,18,31,11,19,8] }\nassert my_solution.numberGame(**test_input) == [8,5,18,11,31,19,33,31,48,43]\n\ntest_input = { \"nums\": [37,46,42,19,10,8,43,10,40,13] }\nassert my_solution.numberGame(**test_input) == [10,8,13,10,37,19,42,40,46,43]\n\ntest_input = { \"nums\": [2,19,8,22,1,27,29,7] }\nassert my_solution.numberGame(**test_input) == [2,1,8,7,22,19,29,27]\n\ntest_input = { \"nums\": [2,3,2,3] }\nassert my_solution.numberGame(**test_input) == [2,2,3,3]\n\ntest_input = { \"nums\": [1,4,7,14,8,14] }\nassert my_solution.numberGame(**test_input) == [4,1,8,7,14,14]\n\ntest_input = { \"nums\": [28,47,36,34,19,7,40,46,33,43] }\nassert my_solution.numberGame(**test_input) == [19,7,33,28,36,34,43,40,47,46]\n\ntest_input = { \"nums\": [29,41,20,22,16,27,22,44,10,47] }\nassert my_solution.numberGame(**test_input) == [16,10,22,20,27,22,41,29,47,44]\n\ntest_input = { \"nums\": [14,6,40,19,47,46,34,27,28,10] }\nassert my_solution.numberGame(**test_input) == [10,6,19,14,28,27,40,34,47,46]\n\ntest_input = { \"nums\": [42,43,50,43,36,26,16,12,3,2] }\nassert my_solution.numberGame(**test_input) == [3,2,16,12,36,26,43,42,50,43]\n\ntest_input = { \"nums\": [1,7,24,24,23,32,28,2] }\nassert my_solution.numberGame(**test_input) == [2,1,23,7,24,24,32,28]\n\ntest_input = { \"nums\": [20,19,16,16,19,29,21,5] }\nassert my_solution.numberGame(**test_input) == [16,5,19,16,20,19,29,21]\n\ntest_input = { \"nums\": [20,9,29,29,17,39,27,44,1,8] }\nassert my_solution.numberGame(**test_input) == [8,1,17,9,27,20,29,29,44,39]\n\ntest_input = { \"nums\": [14,11,12,18,9,15] }\nassert my_solution.numberGame(**test_input) == [11,9,14,12,18,15]\n\ntest_input = { \"nums\": [17,22,2,35,15,19,25,5,33,44] }\nassert my_solution.numberGame(**test_input) == [5,2,17,15,22,19,33,25,44,35]\n\ntest_input = { \"nums\": [22,3,26,15,1,5,14,28] }\nassert my_solution.numberGame(**test_input) == [3,1,14,5,22,15,28,26]\n\ntest_input = { \"nums\": [5,24,3,2,17,9,2,4] }\nassert my_solution.numberGame(**test_input) == [2,2,4,3,9,5,24,17]\n\ntest_input = { \"nums\": [2,6,4,7] }\nassert my_solution.numberGame(**test_input) == [4,2,7,6]\n\ntest_input = { \"nums\": [1,33,29,21,25,14,26,35,34,30] }\nassert my_solution.numberGame(**test_input) == [14,1,25,21,29,26,33,30,35,34]\n\ntest_input = { \"nums\": [50,25,42,41,16,23,47,31,23,16] }\nassert my_solution.numberGame(**test_input) == [16,16,23,23,31,25,42,41,50,47]\n\ntest_input = { \"nums\": [31,31,31,12,24,17,11,3,33,13] }\nassert my_solution.numberGame(**test_input) == [11,3,13,12,24,17,31,31,33,31]\n\ntest_input = { \"nums\": [8,3,2,7] }\nassert my_solution.numberGame(**test_input) == [3,2,8,7]\n\ntest_input = { \"nums\": [8,2,8,6] }\nassert my_solution.numberGame(**test_input) == [6,2,8,8]\n\ntest_input = { \"nums\": [4,15,16,2,12,7] }\nassert my_solution.numberGame(**test_input) == [4,2,12,7,16,15]\n\ntest_input = { \"nums\": [5,4,2,4] }\nassert my_solution.numberGame(**test_input) == [4,2,5,4]\n\ntest_input = { \"nums\": [17,13,7,12,19,15,6,22] }\nassert my_solution.numberGame(**test_input) == [7,6,13,12,17,15,22,19]\n\ntest_input = { \"nums\": [2,15,12,16,12,13] }\nassert my_solution.numberGame(**test_input) == [12,2,13,12,16,15]\n\ntest_input = { \"nums\": [3,15,18,16,6,7] }\nassert my_solution.numberGame(**test_input) == [6,3,15,7,18,16]\n\ntest_input = { \"nums\": [4,7,11,6,11,8] }\nassert my_solution.numberGame(**test_input) == [6,4,8,7,11,11]\n\ntest_input = { \"nums\": [1,7,24,23,16,21,9,11] }\nassert my_solution.numberGame(**test_input) == [7,1,11,9,21,16,24,23]\n\ntest_input = { \"nums\": [6,3,10,16,15,6] }\nassert my_solution.numberGame(**test_input) == [6,3,10,6,16,15]\n\ntest_input = { \"nums\": [17,9,1,29,30,5,31,26] }\nassert my_solution.numberGame(**test_input) == [5,1,17,9,29,26,31,30]\n\ntest_input = { \"nums\": [3,6,4,14,9,15] }\nassert my_solution.numberGame(**test_input) == [4,3,9,6,15,14]\n\ntest_input = { \"nums\": [37,38,24,15,12,1,37,19,38,11] }\nassert my_solution.numberGame(**test_input) == [11,1,15,12,24,19,37,37,38,38]\n\ntest_input = { \"nums\": [17,3,8,12,6,9] }\nassert my_solution.numberGame(**test_input) == [6,3,9,8,17,12]\n\ntest_input = { \"nums\": [32,23,27,32,24,26,24,27] }\nassert my_solution.numberGame(**test_input) == [24,23,26,24,27,27,32,32]\n\ntest_input = { \"nums\": [15,16,26,6,5,9,22,14] }\nassert my_solution.numberGame(**test_input) == [6,5,14,9,16,15,26,22]\n\ntest_input = { \"nums\": [14,21,13,10,2,16,14,30] }\nassert my_solution.numberGame(**test_input) == [10,2,14,13,16,14,30,21]\n\ntest_input = { \"nums\": [1,6,30,1,13,25,18,1] }\nassert my_solution.numberGame(**test_input) == [1,1,6,1,18,13,30,25]\n\ntest_input = { \"nums\": [32,12,17,32,11,25,22,18,10,1] }\nassert my_solution.numberGame(**test_input) == [10,1,12,11,18,17,25,22,32,32]\n\ntest_input = { \"nums\": [2,8,5,6] }\nassert my_solution.numberGame(**test_input) == [5,2,8,6]\n\ntest_input = { \"nums\": [27,3,10,25,10,7,15,16] }\nassert my_solution.numberGame(**test_input) == [7,3,10,10,16,15,27,25]\n\ntest_input = { \"nums\": [5,18,19,25,13,21,16,7] }\nassert my_solution.numberGame(**test_input) == [7,5,16,13,19,18,25,21]\n\ntest_input = { \"nums\": [8,6,6,8] }\nassert my_solution.numberGame(**test_input) == [6,6,8,8]\n\ntest_input = { \"nums\": [23,15,39,9,19,10,6,9,33,28] }\nassert my_solution.numberGame(**test_input) == [9,6,10,9,19,15,28,23,39,33]\n\ntest_input = { \"nums\": [16,42,47,16,31,39,8,26,50,33] }\nassert my_solution.numberGame(**test_input) == [16,8,26,16,33,31,42,39,50,47]\n\ntest_input = { \"nums\": [4,31,9,2,4,28,28,12] }\nassert my_solution.numberGame(**test_input) == [4,2,9,4,28,12,31,28]\n\ntest_input = { \"nums\": [9,5,8,11,4,7] }\nassert my_solution.numberGame(**test_input) == [5,4,8,7,11,9]\n\ntest_input = { \"nums\": [44,2,23,3,7,2,36,33,7,21] }\nassert my_solution.numberGame(**test_input) == [2,2,7,3,21,7,33,23,44,36]\n\ntest_input = { \"nums\": [19,9,4,7,29,22,50,28,2,40] }\nassert my_solution.numberGame(**test_input) == [4,2,9,7,22,19,29,28,50,40]\n\ntest_input = { \"nums\": [4,5,5,5] }\nassert my_solution.numberGame(**test_input) == [5,4,5,5]\n\ntest_input = { \"nums\": [42,6,44,47,11,6,30,38,41,43] }\nassert my_solution.numberGame(**test_input) == [6,6,30,11,41,38,43,42,47,44]\n\ntest_input = { \"nums\": [28,4,47,1,7,35,10,10,5,8] }\nassert my_solution.numberGame(**test_input) == [4,1,7,5,10,8,28,10,47,35]\n\ntest_input = { \"nums\": [12,20,14,46,22,1,42,50,47,47] }\nassert my_solution.numberGame(**test_input) == [12,1,20,14,42,22,47,46,50,47]\n\ntest_input = { \"nums\": [37,13,1,38,28,46,18,22,12,7] }\nassert my_solution.numberGame(**test_input) == [7,1,13,12,22,18,37,28,46,38]\n\ntest_input = { \"nums\": [36,41,5,33,5,30,33,31,6,45] }\nassert my_solution.numberGame(**test_input) == [5,5,30,6,33,31,36,33,45,41]\n\ntest_input = { \"nums\": [13,50,42,24,47,41,8,26,34,3] }\nassert my_solution.numberGame(**test_input) == [8,3,24,13,34,26,42,41,50,47]\n\ntest_input = { \"nums\": [24,39,26,46,47,9,33,6,33,40] }\nassert my_solution.numberGame(**test_input) == [9,6,26,24,33,33,40,39,47,46]\n\ntest_input = { \"nums\": [14,13,17,14,12,15,6,32] }\nassert my_solution.numberGame(**test_input) == [12,6,14,13,15,14,32,17]\n\ntest_input = { \"nums\": [46,50,35,11,14,44,17,45,23,34] }\nassert my_solution.numberGame(**test_input) == [14,11,23,17,35,34,45,44,50,46]\n\ntest_input = { \"nums\": [8,27,19,7,10,12,14,50,45,14] }\nassert my_solution.numberGame(**test_input) == [8,7,12,10,14,14,27,19,50,45]\n\ntest_input = { \"nums\": [9,8,5,7,10,9] }\nassert my_solution.numberGame(**test_input) == [7,5,9,8,10,9]\n\ntest_input = { \"nums\": [5,5,3,7] }\nassert my_solution.numberGame(**test_input) == [5,3,7,5]\n\ntest_input = { \"nums\": [26,21,7,13,3,10,9,15] }\nassert my_solution.numberGame(**test_input) == [7,3,10,9,15,13,26,21]\n\ntest_input = { \"nums\": [8,5,8,3] }\nassert my_solution.numberGame(**test_input) == [5,3,8,8]\n\ntest_input = { \"nums\": [18,1,16,18,13,3] }\nassert my_solution.numberGame(**test_input) == [3,1,16,13,18,18]\n\ntest_input = { \"nums\": [25,2,17,26,17,20,19,24] }\nassert my_solution.numberGame(**test_input) == [17,2,19,17,24,20,26,25]\n\ntest_input = { \"nums\": [24,1,18,25,29,17,9,3] }\nassert my_solution.numberGame(**test_input) == [3,1,17,9,24,18,29,25]\n\ntest_input = { \"nums\": [23,17,18,18,18,30,8,19] }\nassert my_solution.numberGame(**test_input) == [17,8,18,18,19,18,30,23]\n\ntest_input = { \"nums\": [12,13,13,18,5,16] }\nassert my_solution.numberGame(**test_input) == [12,5,13,13,18,16]\n\ntest_input = { \"nums\": [19,4,11,7,24,12,24,14] }\nassert my_solution.numberGame(**test_input) == [7,4,12,11,19,14,24,24]\n\ntest_input = { \"nums\": [28,11,11,29,18,2,6,32] }\nassert my_solution.numberGame(**test_input) == [6,2,11,11,28,18,32,29]\n\ntest_input = { \"nums\": [12,17,3,31,15,18,18,2] }\nassert my_solution.numberGame(**test_input) == [3,2,15,12,18,17,31,18]\n\ntest_input = { \"nums\": [24,6,21,30,29,8,23,18] }\nassert my_solution.numberGame(**test_input) == [8,6,21,18,24,23,30,29]", "start_time": 1703385000} +{"task_id": "weekly-contest-377-maximum-square-area-by-removing-fences-from-a-field", "url": "https://leetcode.com/problems/maximum-square-area-by-removing-fences-from-a-field", "title": "maximum-square-area-by-removing-fences-from-a-field", "meta": {"questionId": "3250", "questionFrontendId": "2975", "title": "Maximum Square Area by Removing Fences From a Field", "titleSlug": "maximum-square-area-by-removing-fences-from-a-field", "isPaidOnly": false, "difficulty": "Medium", "likes": 67, "dislikes": 68, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nThere is a large (m - 1) x (n - 1) rectangular field with corners at (1, 1) and (m, n) containing some horizontal and vertical fences given in arrays hFences and vFences respectively.\nHorizontal fences are from the coordinates (hFences[i], 1) to (hFences[i], n) and vertical fences are from the coordinates (1, vFences[i]) to (m, vFences[i]).\nReturn the maximum area of a square field that can be formed by removing some fences (possibly none) or -1 if it is impossible to make a square field.\nSince the answer may be large, return it modulo 109 + 7.\nNote: The field is surrounded by two horizontal fences from the coordinates (1, 1) to (1, n) and (m, 1) to (m, n) and two vertical fences from the coordinates (1, 1) to (m, 1) and (1, n) to (m, n). These fences cannot be removed.\n\nExample 1:\n\n\nInput: m = 4, n = 3, hFences = [2,3], vFences = [2]\nOutput: 4\nExplanation: Removing the horizontal fence at 2 and the vertical fence at 2 will give a square field of area 4.\n\nExample 2:\n\n\nInput: m = 6, n = 7, hFences = [2], vFences = [4]\nOutput: -1\nExplanation: It can be proved that there is no way to create a square field by removing fences.\n\n\nConstraints:\n\n3 <= m, n <= 109\n1 <= hFences.length, vFences.length <= 600\n1 < hFences[i] < m\n1 < vFences[i] < n\nhFences and vFences are unique.\n\"\"\"\nclass Solution:\n def maximizeSquareArea(self, m: int, n: int, hFences: List[int], vFences: List[int]) -> int:\n ", "prompt_sft": "There is a large (m - 1) x (n - 1) rectangular field with corners at (1, 1) and (m, n) containing some horizontal and vertical fences given in arrays hFences and vFences respectively.\nHorizontal fences are from the coordinates (hFences[i], 1) to (hFences[i], n) and vertical fences are from the coordinates (1, vFences[i]) to (m, vFences[i]).\nReturn the maximum area of a square field that can be formed by removing some fences (possibly none) or -1 if it is impossible to make a square field.\nSince the answer may be large, return it modulo 109 + 7.\nNote: The field is surrounded by two horizontal fences from the coordinates (1, 1) to (1, n) and (m, 1) to (m, n) and two vertical fences from the coordinates (1, 1) to (m, 1) and (1, n) to (m, n). These fences cannot be removed.\n\nExample 1:\n\n\nInput: m = 4, n = 3, hFences = [2,3], vFences = [2]\nOutput: 4\nExplanation: Removing the horizontal fence at 2 and the vertical fence at 2 will give a square field of area 4.\n\nExample 2:\n\n\nInput: m = 6, n = 7, hFences = [2], vFences = [4]\nOutput: -1\nExplanation: It can be proved that there is no way to create a square field by removing fences.\n\n\nConstraints:\n\n3 <= m, n <= 109\n1 <= hFences.length, vFences.length <= 600\n1 < hFences[i] < m\n1 < vFences[i] < n\nhFences and vFences are unique.\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def maximizeSquareArea(self, m: int, n: int, hFences: List[int], vFences: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"m\": 4, \"n\": 3, \"hFences\": [2,3], \"vFences\": [2] }\nassert my_solution.maximizeSquareArea(**test_input) == 4\n\ntest_input = { \"m\": 6, \"n\": 7, \"hFences\": [2], \"vFences\": [4] }\nassert my_solution.maximizeSquareArea(**test_input) == -1\n\ntest_input = { \"m\": 4, \"n\": 4, \"hFences\": [2], \"vFences\": [2,3] }\nassert my_solution.maximizeSquareArea(**test_input) == 9\n\ntest_input = { \"m\": 8, \"n\": 5, \"hFences\": [5,4], \"vFences\": [4] }\nassert my_solution.maximizeSquareArea(**test_input) == 16\n\ntest_input = { \"m\": 4, \"n\": 5, \"hFences\": [2], \"vFences\": [4] }\nassert my_solution.maximizeSquareArea(**test_input) == 9\n\ntest_input = { \"m\": 5, \"n\": 6, \"hFences\": [4,2,3], \"vFences\": [4,5] }\nassert my_solution.maximizeSquareArea(**test_input) == 16\n\ntest_input = { \"m\": 3, \"n\": 9, \"hFences\": [2], \"vFences\": [8,6,5,4] }\nassert my_solution.maximizeSquareArea(**test_input) == 4\n\ntest_input = { \"m\": 6, \"n\": 4, \"hFences\": [3], \"vFences\": [3,2] }\nassert my_solution.maximizeSquareArea(**test_input) == 9\n\ntest_input = { \"m\": 7, \"n\": 4, \"hFences\": [2,3,6,5], \"vFences\": [3,2] }\nassert my_solution.maximizeSquareArea(**test_input) == 9\n\ntest_input = { \"m\": 8, \"n\": 8, \"hFences\": [2,3,6,7], \"vFences\": [6,5,7,4,2,3] }\nassert my_solution.maximizeSquareArea(**test_input) == 49\n\ntest_input = { \"m\": 9, \"n\": 9, \"hFences\": [2,4], \"vFences\": [6,4,2] }\nassert my_solution.maximizeSquareArea(**test_input) == 64\n\ntest_input = { \"m\": 7, \"n\": 7, \"hFences\": [4,3], \"vFences\": [2,6] }\nassert my_solution.maximizeSquareArea(**test_input) == 36\n\ntest_input = { \"m\": 4, \"n\": 6, \"hFences\": [2], \"vFences\": [3,4,2] }\nassert my_solution.maximizeSquareArea(**test_input) == 9\n\ntest_input = { \"m\": 8, \"n\": 6, \"hFences\": [7,5,2,4,3], \"vFences\": [5,3] }\nassert my_solution.maximizeSquareArea(**test_input) == 25\n\ntest_input = { \"m\": 9, \"n\": 3, \"hFences\": [7,4,5], \"vFences\": [2] }\nassert my_solution.maximizeSquareArea(**test_input) == 4\n\ntest_input = { \"m\": 4, \"n\": 3, \"hFences\": [3], \"vFences\": [2] }\nassert my_solution.maximizeSquareArea(**test_input) == 4\n\ntest_input = { \"m\": 4, \"n\": 3, \"hFences\": [3,2], \"vFences\": [2] }\nassert my_solution.maximizeSquareArea(**test_input) == 4\n\ntest_input = { \"m\": 8, \"n\": 6, \"hFences\": [6,4,3,7,2,5], \"vFences\": [5,3,4,2] }\nassert my_solution.maximizeSquareArea(**test_input) == 25\n\ntest_input = { \"m\": 8, \"n\": 8, \"hFences\": [6,3,7,5], \"vFences\": [6,2,7] }\nassert my_solution.maximizeSquareArea(**test_input) == 49\n\ntest_input = { \"m\": 5, \"n\": 5, \"hFences\": [4,3], \"vFences\": [4] }\nassert my_solution.maximizeSquareArea(**test_input) == 16\n\ntest_input = { \"m\": 5, \"n\": 3, \"hFences\": [4], \"vFences\": [2] }\nassert my_solution.maximizeSquareArea(**test_input) == 1\n\ntest_input = { \"m\": 7, \"n\": 9, \"hFences\": [5], \"vFences\": [2,7,6,8,3] }\nassert my_solution.maximizeSquareArea(**test_input) == 36\n\ntest_input = { \"m\": 8, \"n\": 6, \"hFences\": [5,4,6,7,3], \"vFences\": [5,3] }\nassert my_solution.maximizeSquareArea(**test_input) == 25\n\ntest_input = { \"m\": 9, \"n\": 7, \"hFences\": [6,4,7,5,8], \"vFences\": [6,4,2,3] }\nassert my_solution.maximizeSquareArea(**test_input) == 36\n\ntest_input = { \"m\": 6, \"n\": 7, \"hFences\": [5], \"vFences\": [5,3,6] }\nassert my_solution.maximizeSquareArea(**test_input) == 25\n\ntest_input = { \"m\": 3, \"n\": 3, \"hFences\": [2], \"vFences\": [2] }\nassert my_solution.maximizeSquareArea(**test_input) == 4\n\ntest_input = { \"m\": 7, \"n\": 8, \"hFences\": [4,6,2,5,3], \"vFences\": [3,5,2,4,7] }\nassert my_solution.maximizeSquareArea(**test_input) == 36\n\ntest_input = { \"m\": 3, \"n\": 5, \"hFences\": [2], \"vFences\": [4,2] }\nassert my_solution.maximizeSquareArea(**test_input) == 4\n\ntest_input = { \"m\": 4, \"n\": 3, \"hFences\": [2], \"vFences\": [2] }\nassert my_solution.maximizeSquareArea(**test_input) == 4\n\ntest_input = { \"m\": 9, \"n\": 3, \"hFences\": [3], \"vFences\": [2] }\nassert my_solution.maximizeSquareArea(**test_input) == 4\n\ntest_input = { \"m\": 6, \"n\": 7, \"hFences\": [4,2,3,5], \"vFences\": [3,5,6] }\nassert my_solution.maximizeSquareArea(**test_input) == 25\n\ntest_input = { \"m\": 8, \"n\": 4, \"hFences\": [6,3,2,4,7,5], \"vFences\": [2,3] }\nassert my_solution.maximizeSquareArea(**test_input) == 9\n\ntest_input = { \"m\": 4, \"n\": 4, \"hFences\": [2], \"vFences\": [2] }\nassert my_solution.maximizeSquareArea(**test_input) == 9\n\ntest_input = { \"m\": 3, \"n\": 6, \"hFences\": [2], \"vFences\": [4,3,5] }\nassert my_solution.maximizeSquareArea(**test_input) == 4\n\ntest_input = { \"m\": 8, \"n\": 6, \"hFences\": [5], \"vFences\": [4,2,5] }\nassert my_solution.maximizeSquareArea(**test_input) == 16\n\ntest_input = { \"m\": 9, \"n\": 9, \"hFences\": [5,4,2], \"vFences\": [8,4,3,5,6] }\nassert my_solution.maximizeSquareArea(**test_input) == 64\n\ntest_input = { \"m\": 5, \"n\": 9, \"hFences\": [3,2,4], \"vFences\": [7,6,5] }\nassert my_solution.maximizeSquareArea(**test_input) == 16\n\ntest_input = { \"m\": 5, \"n\": 5, \"hFences\": [4,3,2], \"vFences\": [3,4,2] }\nassert my_solution.maximizeSquareArea(**test_input) == 16\n\ntest_input = { \"m\": 7, \"n\": 4, \"hFences\": [5,2,4], \"vFences\": [3] }\nassert my_solution.maximizeSquareArea(**test_input) == 9\n\ntest_input = { \"m\": 8, \"n\": 5, \"hFences\": [4,6,2,3], \"vFences\": [4] }\nassert my_solution.maximizeSquareArea(**test_input) == 16\n\ntest_input = { \"m\": 9, \"n\": 5, \"hFences\": [6], \"vFences\": [3] }\nassert my_solution.maximizeSquareArea(**test_input) == -1\n\ntest_input = { \"m\": 9, \"n\": 4, \"hFences\": [2,8,3,7,4,6,5], \"vFences\": [2,3] }\nassert my_solution.maximizeSquareArea(**test_input) == 9\n\ntest_input = { \"m\": 5, \"n\": 8, \"hFences\": [2,3,4], \"vFences\": [3,5,6,4] }\nassert my_solution.maximizeSquareArea(**test_input) == 16\n\ntest_input = { \"m\": 9, \"n\": 6, \"hFences\": [7,3,4,5,8,2], \"vFences\": [5,3,2,4] }\nassert my_solution.maximizeSquareArea(**test_input) == 25\n\ntest_input = { \"m\": 5, \"n\": 4, \"hFences\": [4], \"vFences\": [2] }\nassert my_solution.maximizeSquareArea(**test_input) == 9\n\ntest_input = { \"m\": 9, \"n\": 6, \"hFences\": [2,5], \"vFences\": [5,2] }\nassert my_solution.maximizeSquareArea(**test_input) == 16\n\ntest_input = { \"m\": 6, \"n\": 9, \"hFences\": [4,5,2], \"vFences\": [5,7,8,2,3,6] }\nassert my_solution.maximizeSquareArea(**test_input) == 25\n\ntest_input = { \"m\": 4, \"n\": 5, \"hFences\": [2], \"vFences\": [2] }\nassert my_solution.maximizeSquareArea(**test_input) == 9\n\ntest_input = { \"m\": 9, \"n\": 6, \"hFences\": [2,4], \"vFences\": [5,3] }\nassert my_solution.maximizeSquareArea(**test_input) == 25\n\ntest_input = { \"m\": 4, \"n\": 7, \"hFences\": [2], \"vFences\": [4,3,6,2,5] }\nassert my_solution.maximizeSquareArea(**test_input) == 9\n\ntest_input = { \"m\": 8, \"n\": 3, \"hFences\": [3,2,5], \"vFences\": [2] }\nassert my_solution.maximizeSquareArea(**test_input) == 4\n\ntest_input = { \"m\": 6, \"n\": 8, \"hFences\": [4,2,3,5], \"vFences\": [7,4,5,6] }\nassert my_solution.maximizeSquareArea(**test_input) == 25\n\ntest_input = { \"m\": 3, \"n\": 5, \"hFences\": [2], \"vFences\": [3] }\nassert my_solution.maximizeSquareArea(**test_input) == 4\n\ntest_input = { \"m\": 8, \"n\": 8, \"hFences\": [2,5,6], \"vFences\": [3,7,4,2,5] }\nassert my_solution.maximizeSquareArea(**test_input) == 49\n\ntest_input = { \"m\": 8, \"n\": 7, \"hFences\": [3,4,7], \"vFences\": [2,6,3,4] }\nassert my_solution.maximizeSquareArea(**test_input) == 36\n\ntest_input = { \"m\": 7, \"n\": 4, \"hFences\": [3,6,5], \"vFences\": [2] }\nassert my_solution.maximizeSquareArea(**test_input) == 9\n\ntest_input = { \"m\": 5, \"n\": 6, \"hFences\": [2,3], \"vFences\": [3,2,5] }\nassert my_solution.maximizeSquareArea(**test_input) == 16\n\ntest_input = { \"m\": 6, \"n\": 7, \"hFences\": [5], \"vFences\": [4,2,5,6] }\nassert my_solution.maximizeSquareArea(**test_input) == 25\n\ntest_input = { \"m\": 8, \"n\": 8, \"hFences\": [4,5,2,7], \"vFences\": [5,3,4,2,7,6] }\nassert my_solution.maximizeSquareArea(**test_input) == 49\n\ntest_input = { \"m\": 7, \"n\": 9, \"hFences\": [6,3,4], \"vFences\": [8,6,2] }\nassert my_solution.maximizeSquareArea(**test_input) == 36\n\ntest_input = { \"m\": 7, \"n\": 4, \"hFences\": [3,4,6], \"vFences\": [3,2] }\nassert my_solution.maximizeSquareArea(**test_input) == 9\n\ntest_input = { \"m\": 6, \"n\": 8, \"hFences\": [5,4,3], \"vFences\": [5,7,3,2,6,4] }\nassert my_solution.maximizeSquareArea(**test_input) == 25\n\ntest_input = { \"m\": 8, \"n\": 9, \"hFences\": [2,3,4,7,6,5], \"vFences\": [3,7,8] }\nassert my_solution.maximizeSquareArea(**test_input) == 49\n\ntest_input = { \"m\": 3, \"n\": 4, \"hFences\": [2], \"vFences\": [2,3] }\nassert my_solution.maximizeSquareArea(**test_input) == 4\n\ntest_input = { \"m\": 9, \"n\": 9, \"hFences\": [8,5,6,2,7], \"vFences\": [8,6,4,2] }\nassert my_solution.maximizeSquareArea(**test_input) == 64\n\ntest_input = { \"m\": 7, \"n\": 6, \"hFences\": [4,5], \"vFences\": [5,3] }\nassert my_solution.maximizeSquareArea(**test_input) == 16\n\ntest_input = { \"m\": 5, \"n\": 4, \"hFences\": [2], \"vFences\": [3] }\nassert my_solution.maximizeSquareArea(**test_input) == 9\n\ntest_input = { \"m\": 5, \"n\": 5, \"hFences\": [3], \"vFences\": [3,4,2] }\nassert my_solution.maximizeSquareArea(**test_input) == 16\n\ntest_input = { \"m\": 9, \"n\": 7, \"hFences\": [3], \"vFences\": [3,2,5,4] }\nassert my_solution.maximizeSquareArea(**test_input) == 36\n\ntest_input = { \"m\": 8, \"n\": 6, \"hFences\": [4], \"vFences\": [5,2,3] }\nassert my_solution.maximizeSquareArea(**test_input) == 16\n\ntest_input = { \"m\": 6, \"n\": 9, \"hFences\": [3,4,2], \"vFences\": [3,2,8] }\nassert my_solution.maximizeSquareArea(**test_input) == 25\n\ntest_input = { \"m\": 7, \"n\": 6, \"hFences\": [3,6,5,2,4], \"vFences\": [2,3,5,4] }\nassert my_solution.maximizeSquareArea(**test_input) == 25\n\ntest_input = { \"m\": 7, \"n\": 3, \"hFences\": [5,3,6,4], \"vFences\": [2] }\nassert my_solution.maximizeSquareArea(**test_input) == 4\n\ntest_input = { \"m\": 4, \"n\": 7, \"hFences\": [3], \"vFences\": [2] }\nassert my_solution.maximizeSquareArea(**test_input) == 1\n\ntest_input = { \"m\": 3, \"n\": 7, \"hFences\": [2], \"vFences\": [4,3,2,6,5] }\nassert my_solution.maximizeSquareArea(**test_input) == 4\n\ntest_input = { \"m\": 5, \"n\": 9, \"hFences\": [2,4], \"vFences\": [4,7] }\nassert my_solution.maximizeSquareArea(**test_input) == 9\n\ntest_input = { \"m\": 5, \"n\": 9, \"hFences\": [4,2], \"vFences\": [8,7,3,2,6,4] }\nassert my_solution.maximizeSquareArea(**test_input) == 16\n\ntest_input = { \"m\": 3, \"n\": 8, \"hFences\": [2], \"vFences\": [3,7,2,5,4] }\nassert my_solution.maximizeSquareArea(**test_input) == 4\n\ntest_input = { \"m\": 4, \"n\": 7, \"hFences\": [2,3], \"vFences\": [4,2] }\nassert my_solution.maximizeSquareArea(**test_input) == 9\n\ntest_input = { \"m\": 8, \"n\": 9, \"hFences\": [7,6,3,2,5,4], \"vFences\": [3,2,6] }\nassert my_solution.maximizeSquareArea(**test_input) == 49\n\ntest_input = { \"m\": 7, \"n\": 8, \"hFences\": [6], \"vFences\": [5] }\nassert my_solution.maximizeSquareArea(**test_input) == -1\n\ntest_input = { \"m\": 9, \"n\": 7, \"hFences\": [2,7,8,5], \"vFences\": [6,3] }\nassert my_solution.maximizeSquareArea(**test_input) == 36\n\ntest_input = { \"m\": 9, \"n\": 9, \"hFences\": [4,7,2,5,8,6], \"vFences\": [7,6,4,5,8,2,3] }\nassert my_solution.maximizeSquareArea(**test_input) == 64\n\ntest_input = { \"m\": 7, \"n\": 7, \"hFences\": [6,3,2,5], \"vFences\": [6,3] }\nassert my_solution.maximizeSquareArea(**test_input) == 36\n\ntest_input = { \"m\": 7, \"n\": 7, \"hFences\": [5], \"vFences\": [2,3,6] }\nassert my_solution.maximizeSquareArea(**test_input) == 36\n\ntest_input = { \"m\": 4, \"n\": 9, \"hFences\": [3], \"vFences\": [4,3,7,6,8,5,2] }\nassert my_solution.maximizeSquareArea(**test_input) == 9\n\ntest_input = { \"m\": 4, \"n\": 5, \"hFences\": [2,3], \"vFences\": [3,4] }\nassert my_solution.maximizeSquareArea(**test_input) == 9\n\ntest_input = { \"m\": 3, \"n\": 7, \"hFences\": [2], \"vFences\": [3,6] }\nassert my_solution.maximizeSquareArea(**test_input) == 4\n\ntest_input = { \"m\": 4, \"n\": 9, \"hFences\": [3,2], \"vFences\": [4,6] }\nassert my_solution.maximizeSquareArea(**test_input) == 9\n\ntest_input = { \"m\": 9, \"n\": 9, \"hFences\": [5], \"vFences\": [6,5,2,7,3,8] }\nassert my_solution.maximizeSquareArea(**test_input) == 64\n\ntest_input = { \"m\": 5, \"n\": 6, \"hFences\": [3,4,2], \"vFences\": [5,3,2] }\nassert my_solution.maximizeSquareArea(**test_input) == 16\n\ntest_input = { \"m\": 5, \"n\": 6, \"hFences\": [3,2], \"vFences\": [5] }\nassert my_solution.maximizeSquareArea(**test_input) == 16\n\ntest_input = { \"m\": 5, \"n\": 5, \"hFences\": [3,4], \"vFences\": [3,2,4] }\nassert my_solution.maximizeSquareArea(**test_input) == 16\n\ntest_input = { \"m\": 9, \"n\": 5, \"hFences\": [7,5,8], \"vFences\": [4,2,3] }\nassert my_solution.maximizeSquareArea(**test_input) == 16\n\ntest_input = { \"m\": 3, \"n\": 6, \"hFences\": [2], \"vFences\": [2,5,4] }\nassert my_solution.maximizeSquareArea(**test_input) == 4\n\ntest_input = { \"m\": 5, \"n\": 9, \"hFences\": [4,2,3], \"vFences\": [8,3,5,6,4,2] }\nassert my_solution.maximizeSquareArea(**test_input) == 16\n\ntest_input = { \"m\": 4, \"n\": 7, \"hFences\": [3,2], \"vFences\": [5] }\nassert my_solution.maximizeSquareArea(**test_input) == 4\n\ntest_input = { \"m\": 6, \"n\": 9, \"hFences\": [4,2], \"vFences\": [3,4,7,2] }\nassert my_solution.maximizeSquareArea(**test_input) == 25\n\ntest_input = { \"m\": 6, \"n\": 5, \"hFences\": [4], \"vFences\": [3,2] }\nassert my_solution.maximizeSquareArea(**test_input) == 9\n\ntest_input = { \"m\": 8, \"n\": 5, \"hFences\": [6,7,4,5,2], \"vFences\": [4] }\nassert my_solution.maximizeSquareArea(**test_input) == 16", "start_time": 1703385000} +{"task_id": "weekly-contest-377-minimum-cost-to-convert-string-i", "url": "https://leetcode.com/problems/minimum-cost-to-convert-string-i", "title": "minimum-cost-to-convert-string-i", "meta": {"questionId": "3235", "questionFrontendId": "2976", "title": "Minimum Cost to Convert String I", "titleSlug": "minimum-cost-to-convert-string-i", "isPaidOnly": false, "difficulty": "Medium", "likes": 93, "dislikes": 4, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given two 0-indexed strings source and target, both of length n and consisting of lowercase English letters. You are also given two 0-indexed character arrays original and changed, and an integer array cost, where cost[i] represents the cost of changing the character original[i] to the character changed[i].\nYou start with the string source. In one operation, you can pick a character x from the string and change it to the character y at a cost of z if there exists any index j such that cost[j] == z, original[j] == x, and changed[j] == y.\nReturn the minimum cost to convert the string source to the string target using any number of operations. If it is impossible to convert source to target, return -1.\nNote that there may exist indices i, j such that original[j] == original[i] and changed[j] == changed[i].\n\nExample 1:\n\nInput: source = \"abcd\", target = \"acbe\", original = [\"a\",\"b\",\"c\",\"c\",\"e\",\"d\"], changed = [\"b\",\"c\",\"b\",\"e\",\"b\",\"e\"], cost = [2,5,5,1,2,20]\nOutput: 28\nExplanation: To convert the string \"abcd\" to string \"acbe\":\n- Change value at index 1 from 'b' to 'c' at a cost of 5.\n- Change value at index 2 from 'c' to 'e' at a cost of 1.\n- Change value at index 2 from 'e' to 'b' at a cost of 2.\n- Change value at index 3 from 'd' to 'e' at a cost of 20.\nThe total cost incurred is 5 + 1 + 2 + 20 = 28.\nIt can be shown that this is the minimum possible cost.\n\nExample 2:\n\nInput: source = \"aaaa\", target = \"bbbb\", original = [\"a\",\"c\"], changed = [\"c\",\"b\"], cost = [1,2]\nOutput: 12\nExplanation: To change the character 'a' to 'b' change the character 'a' to 'c' at a cost of 1, followed by changing the character 'c' to 'b' at a cost of 2, for a total cost of 1 + 2 = 3. To change all occurrences of 'a' to 'b', a total cost of 3 * 4 = 12 is incurred.\n\nExample 3:\n\nInput: source = \"abcd\", target = \"abce\", original = [\"a\"], changed = [\"e\"], cost = [10000]\nOutput: -1\nExplanation: It is impossible to convert source to target because the value at index 3 cannot be changed from 'd' to 'e'.\n\n\nConstraints:\n\n1 <= source.length == target.length <= 105\nsource, target consist of lowercase English letters.\n1 <= cost.length == original.length == changed.length <= 2000\noriginal[i], changed[i] are lowercase English letters.\n1 <= cost[i] <= 106\noriginal[i] != changed[i]\n\"\"\"\nclass Solution:\n def minimumCost(self, source: str, target: str, original: List[str], changed: List[str], cost: List[int]) -> int:\n ", "prompt_sft": "You are given two 0-indexed strings source and target, both of length n and consisting of lowercase English letters. You are also given two 0-indexed character arrays original and changed, and an integer array cost, where cost[i] represents the cost of changing the character original[i] to the character changed[i].\nYou start with the string source. In one operation, you can pick a character x from the string and change it to the character y at a cost of z if there exists any index j such that cost[j] == z, original[j] == x, and changed[j] == y.\nReturn the minimum cost to convert the string source to the string target using any number of operations. If it is impossible to convert source to target, return -1.\nNote that there may exist indices i, j such that original[j] == original[i] and changed[j] == changed[i].\n\nExample 1:\n\nInput: source = \"abcd\", target = \"acbe\", original = [\"a\",\"b\",\"c\",\"c\",\"e\",\"d\"], changed = [\"b\",\"c\",\"b\",\"e\",\"b\",\"e\"], cost = [2,5,5,1,2,20]\nOutput: 28\nExplanation: To convert the string \"abcd\" to string \"acbe\":\n- Change value at index 1 from 'b' to 'c' at a cost of 5.\n- Change value at index 2 from 'c' to 'e' at a cost of 1.\n- Change value at index 2 from 'e' to 'b' at a cost of 2.\n- Change value at index 3 from 'd' to 'e' at a cost of 20.\nThe total cost incurred is 5 + 1 + 2 + 20 = 28.\nIt can be shown that this is the minimum possible cost.\n\nExample 2:\n\nInput: source = \"aaaa\", target = \"bbbb\", original = [\"a\",\"c\"], changed = [\"c\",\"b\"], cost = [1,2]\nOutput: 12\nExplanation: To change the character 'a' to 'b' change the character 'a' to 'c' at a cost of 1, followed by changing the character 'c' to 'b' at a cost of 2, for a total cost of 1 + 2 = 3. To change all occurrences of 'a' to 'b', a total cost of 3 * 4 = 12 is incurred.\n\nExample 3:\n\nInput: source = \"abcd\", target = \"abce\", original = [\"a\"], changed = [\"e\"], cost = [10000]\nOutput: -1\nExplanation: It is impossible to convert source to target because the value at index 3 cannot be changed from 'd' to 'e'.\n\n\nConstraints:\n\n1 <= source.length == target.length <= 105\nsource, target consist of lowercase English letters.\n1 <= cost.length == original.length == changed.length <= 2000\noriginal[i], changed[i] are lowercase English letters.\n1 <= cost[i] <= 106\noriginal[i] != changed[i]\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def minimumCost(self, source: str, target: str, original: List[str], changed: List[str], cost: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"source\": \"abcd\", \"target\": \"acbe\", \"original\": [\"a\",\"b\",\"c\",\"c\",\"e\",\"d\"], \"changed\": [\"b\",\"c\",\"b\",\"e\",\"b\",\"e\"], \"cost\": [2,5,5,1,2,20] }\nassert my_solution.minimumCost(**test_input) == 28\n\ntest_input = { \"source\": \"aaaa\", \"target\": \"bbbb\", \"original\": [\"a\",\"c\"], \"changed\": [\"c\",\"b\"], \"cost\": [1,2] }\nassert my_solution.minimumCost(**test_input) == 12\n\ntest_input = { \"source\": \"abcd\", \"target\": \"abce\", \"original\": [\"a\"], \"changed\": [\"e\"], \"cost\": [10000] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"aaaabadaaa\", \"target\": \"dbdadddbad\", \"original\": [\"c\",\"a\",\"c\",\"a\",\"a\",\"b\",\"b\",\"b\",\"d\",\"d\",\"c\"], \"changed\": [\"a\",\"c\",\"b\",\"d\",\"b\",\"c\",\"a\",\"d\",\"c\",\"b\",\"d\"], \"cost\": [7,8,11,9,7,6,4,6,9,5,9] }\nassert my_solution.minimumCost(**test_input) == 56\n\ntest_input = { \"source\": \"aaadbdcdac\", \"target\": \"cdbabaddba\", \"original\": [\"a\",\"c\",\"b\",\"d\",\"b\",\"a\",\"c\"], \"changed\": [\"c\",\"a\",\"d\",\"b\",\"c\",\"b\",\"d\"], \"cost\": [7,2,1,3,6,1,7] }\nassert my_solution.minimumCost(**test_input) == 39\n\ntest_input = { \"source\": \"aababdaacb\", \"target\": \"bcdcdcbdcb\", \"original\": [\"a\",\"d\",\"d\",\"a\",\"c\",\"b\",\"c\",\"a\",\"c\",\"d\",\"b\",\"b\"], \"changed\": [\"b\",\"c\",\"b\",\"d\",\"a\",\"a\",\"b\",\"c\",\"d\",\"a\",\"c\",\"d\"], \"cost\": [11,4,3,2,7,11,7,6,9,2,1,7] }\nassert my_solution.minimumCost(**test_input) == 42\n\ntest_input = { \"source\": \"aababdbddc\", \"target\": \"adcbbbcdba\", \"original\": [\"a\",\"d\",\"b\",\"a\",\"d\",\"c\",\"d\",\"b\"], \"changed\": [\"b\",\"a\",\"d\",\"c\",\"c\",\"a\",\"b\",\"a\"], \"cost\": [10,6,8,3,6,10,8,6] }\nassert my_solution.minimumCost(**test_input) == 72\n\ntest_input = { \"source\": \"aabbcabbdb\", \"target\": \"acddbabbdd\", \"original\": [\"c\",\"d\",\"c\",\"a\",\"d\",\"c\",\"a\",\"d\",\"b\",\"a\",\"b\"], \"changed\": [\"d\",\"b\",\"a\",\"c\",\"c\",\"b\",\"b\",\"a\",\"d\",\"d\",\"c\"], \"cost\": [5,3,8,10,9,7,8,7,5,1,10] }\nassert my_solution.minimumCost(**test_input) == 32\n\ntest_input = { \"source\": \"aabbddccbc\", \"target\": \"abbbaabaca\", \"original\": [\"a\",\"b\",\"c\",\"b\",\"a\",\"d\"], \"changed\": [\"d\",\"c\",\"b\",\"d\",\"b\",\"b\"], \"cost\": [3,8,7,6,7,10] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"aabdbaabaa\", \"target\": \"bdaacabcab\", \"original\": [\"b\",\"d\",\"d\",\"a\",\"c\",\"c\",\"a\",\"d\",\"a\",\"b\"], \"changed\": [\"c\",\"c\",\"b\",\"d\",\"b\",\"d\",\"b\",\"a\",\"c\",\"a\"], \"cost\": [9,1,7,9,2,1,3,8,8,2] }\nassert my_solution.minimumCost(**test_input) == 43\n\ntest_input = { \"source\": \"aacacaaccd\", \"target\": \"dadaacaabd\", \"original\": [\"c\",\"c\",\"a\",\"a\",\"d\",\"b\",\"d\",\"d\"], \"changed\": [\"b\",\"d\",\"d\",\"b\",\"b\",\"c\",\"c\",\"a\"], \"cost\": [7,8,9,11,4,6,9,10] }\nassert my_solution.minimumCost(**test_input) == 77\n\ntest_input = { \"source\": \"aacbabbacc\", \"target\": \"adbdbcbdaa\", \"original\": [\"c\",\"b\",\"a\",\"b\",\"a\",\"c\",\"d\",\"c\",\"d\"], \"changed\": [\"b\",\"c\",\"b\",\"d\",\"d\",\"a\",\"b\",\"d\",\"c\"], \"cost\": [2,6,7,4,7,4,3,5,6] }\nassert my_solution.minimumCost(**test_input) == 41\n\ntest_input = { \"source\": \"aacbbabdad\", \"target\": \"ddadcababd\", \"original\": [\"d\",\"b\",\"c\",\"a\",\"b\",\"c\",\"d\",\"c\",\"b\",\"a\",\"a\"], \"changed\": [\"c\",\"d\",\"d\",\"b\",\"c\",\"b\",\"b\",\"a\",\"a\",\"c\",\"d\"], \"cost\": [7,10,4,2,7,4,4,4,6,2,8] }\nassert my_solution.minimumCost(**test_input) == 45\n\ntest_input = { \"source\": \"aacbbbbcab\", \"target\": \"cdacdcddac\", \"original\": [\"b\",\"d\",\"c\",\"c\",\"b\",\"a\"], \"changed\": [\"c\",\"c\",\"b\",\"a\",\"a\",\"d\"], \"cost\": [4,7,9,11,3,4] }\nassert my_solution.minimumCost(**test_input) == 67\n\ntest_input = { \"source\": \"aacbcabcad\", \"target\": \"bbcadddcdd\", \"original\": [\"b\",\"a\",\"d\",\"a\",\"b\",\"c\",\"a\",\"d\",\"d\",\"b\"], \"changed\": [\"d\",\"b\",\"b\",\"d\",\"c\",\"a\",\"c\",\"c\",\"a\",\"a\"], \"cost\": [7,7,9,8,6,3,8,2,1,5] }\nassert my_solution.minimumCost(**test_input) == 53\n\ntest_input = { \"source\": \"aacbdbcdca\", \"target\": \"bbbdbcaacd\", \"original\": [\"a\",\"c\",\"b\",\"d\",\"d\",\"a\",\"c\",\"d\"], \"changed\": [\"c\",\"b\",\"c\",\"c\",\"b\",\"d\",\"d\",\"a\"], \"cost\": [9,5,4,1,2,4,7,1] }\nassert my_solution.minimumCost(**test_input) == 47\n\ntest_input = { \"source\": \"aadbbcdbbd\", \"target\": \"badddbdbac\", \"original\": [\"c\",\"d\",\"c\",\"d\",\"b\",\"a\"], \"changed\": [\"b\",\"b\",\"a\",\"a\",\"a\",\"d\"], \"cost\": [11,4,7,8,5,2] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"aadbccbddd\", \"target\": \"cacdbabadc\", \"original\": [\"d\",\"b\",\"c\",\"d\",\"a\",\"a\",\"c\",\"b\"], \"changed\": [\"c\",\"c\",\"b\",\"b\",\"b\",\"d\",\"a\",\"a\"], \"cost\": [5,8,7,2,4,7,1,5] }\nassert my_solution.minimumCost(**test_input) == 46\n\ntest_input = { \"source\": \"aadbddcabd\", \"target\": \"bdcdccbada\", \"original\": [\"d\",\"a\",\"a\",\"b\",\"d\",\"b\"], \"changed\": [\"b\",\"c\",\"d\",\"c\",\"a\",\"d\"], \"cost\": [6,10,5,8,11,4] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"aaddadccad\", \"target\": \"cbaaadbcba\", \"original\": [\"c\",\"a\",\"a\",\"d\",\"c\",\"c\",\"b\",\"b\",\"a\",\"d\"], \"changed\": [\"a\",\"c\",\"d\",\"c\",\"d\",\"b\",\"d\",\"c\",\"b\",\"b\"], \"cost\": [1,10,2,8,9,1,9,10,5,1] }\nassert my_solution.minimumCost(**test_input) == 44\n\ntest_input = { \"source\": \"aaddadcdba\", \"target\": \"caaaccbbca\", \"original\": [\"b\",\"b\",\"c\",\"d\",\"b\",\"c\",\"a\",\"a\"], \"changed\": [\"a\",\"d\",\"d\",\"a\",\"c\",\"b\",\"c\",\"b\"], \"cost\": [11,7,10,8,7,5,10,10] }\nassert my_solution.minimumCost(**test_input) == 84\n\ntest_input = { \"source\": \"abaacbbcaa\", \"target\": \"bdbdbcbdcd\", \"original\": [\"d\",\"a\",\"d\",\"a\",\"b\",\"b\"], \"changed\": [\"a\",\"d\",\"b\",\"b\",\"a\",\"c\"], \"cost\": [10,9,8,11,4,11] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"abacaadcba\", \"target\": \"cadbadcdbd\", \"original\": [\"b\",\"d\",\"c\",\"a\",\"b\",\"d\",\"b\"], \"changed\": [\"a\",\"b\",\"b\",\"b\",\"c\",\"a\",\"d\"], \"cost\": [9,10,6,2,7,10,9] }\nassert my_solution.minimumCost(**test_input) == 89\n\ntest_input = { \"source\": \"abacbadadc\", \"target\": \"aabbdaaccb\", \"original\": [\"d\",\"a\",\"b\",\"d\",\"a\",\"a\",\"c\",\"b\",\"c\",\"c\",\"d\",\"b\"], \"changed\": [\"c\",\"b\",\"a\",\"a\",\"d\",\"c\",\"b\",\"c\",\"d\",\"a\",\"b\",\"d\"], \"cost\": [2,10,3,6,4,1,5,5,11,4,2,1] }\nassert my_solution.minimumCost(**test_input) == 28\n\ntest_input = { \"source\": \"abadbbabcd\", \"target\": \"cdcbdddcbb\", \"original\": [\"d\",\"d\",\"b\",\"a\",\"c\",\"c\",\"c\",\"a\"], \"changed\": [\"c\",\"a\",\"a\",\"c\",\"b\",\"d\",\"a\",\"d\"], \"cost\": [2,10,11,7,6,11,7,1] }\nassert my_solution.minimumCost(**test_input) == 79\n\ntest_input = { \"source\": \"abadcadacc\", \"target\": \"cbabaddcba\", \"original\": [\"a\",\"d\",\"a\",\"b\",\"c\",\"a\",\"d\",\"b\",\"b\",\"d\",\"c\",\"c\"], \"changed\": [\"b\",\"b\",\"d\",\"d\",\"a\",\"c\",\"a\",\"c\",\"a\",\"c\",\"d\",\"b\"], \"cost\": [7,6,11,11,8,10,4,11,2,3,11,7] }\nassert my_solution.minimumCost(**test_input) == 60\n\ntest_input = { \"source\": \"abadcdadac\", \"target\": \"baddbccdac\", \"original\": [\"d\",\"c\",\"d\",\"c\",\"b\",\"a\"], \"changed\": [\"b\",\"b\",\"c\",\"a\",\"d\",\"d\"], \"cost\": [8,5,9,1,10,2] }\nassert my_solution.minimumCost(**test_input) == 57\n\ntest_input = { \"source\": \"abbaadacba\", \"target\": \"cdbbcadddd\", \"original\": [\"d\",\"a\",\"d\",\"c\",\"b\",\"b\",\"c\",\"d\",\"c\",\"a\",\"a\"], \"changed\": [\"a\",\"c\",\"c\",\"d\",\"a\",\"d\",\"a\",\"b\",\"b\",\"d\",\"b\"], \"cost\": [8,3,5,8,3,9,3,4,11,4,9] }\nassert my_solution.minimumCost(**test_input) == 50\n\ntest_input = { \"source\": \"abbaddaacd\", \"target\": \"ccbbaccacc\", \"original\": [\"d\",\"d\",\"a\",\"b\",\"c\",\"b\"], \"changed\": [\"a\",\"c\",\"c\",\"d\",\"b\",\"c\"], \"cost\": [9,8,2,8,3,1] }\nassert my_solution.minimumCost(**test_input) == 35\n\ntest_input = { \"source\": \"abbbcabddb\", \"target\": \"bbccdbbadc\", \"original\": [\"c\",\"d\",\"c\",\"a\",\"b\",\"d\",\"d\",\"a\",\"b\",\"b\"], \"changed\": [\"d\",\"a\",\"b\",\"c\",\"c\",\"b\",\"c\",\"d\",\"a\",\"d\"], \"cost\": [3,6,9,4,9,6,9,6,10,7] }\nassert my_solution.minimumCost(**test_input) == 60\n\ntest_input = { \"source\": \"abbbcbabab\", \"target\": \"abcacbaddd\", \"original\": [\"b\",\"c\",\"a\",\"c\",\"a\",\"d\",\"d\",\"c\"], \"changed\": [\"a\",\"b\",\"d\",\"a\",\"b\",\"b\",\"c\",\"d\"], \"cost\": [11,5,8,1,7,7,1,2] }\nassert my_solution.minimumCost(**test_input) == 77\n\ntest_input = { \"source\": \"abbcaccabb\", \"target\": \"ddddddcacc\", \"original\": [\"a\",\"b\",\"c\",\"b\",\"a\",\"c\",\"c\"], \"changed\": [\"c\",\"c\",\"d\",\"a\",\"d\",\"a\",\"b\"], \"cost\": [2,6,10,11,9,7,3] }\nassert my_solution.minimumCost(**test_input) == 82\n\ntest_input = { \"source\": \"abbcaccdba\", \"target\": \"accadababc\", \"original\": [\"d\",\"a\",\"a\",\"c\",\"b\",\"d\"], \"changed\": [\"c\",\"d\",\"b\",\"a\",\"a\",\"b\"], \"cost\": [7,4,10,11,5,5] }\nassert my_solution.minimumCost(**test_input) == 99\n\ntest_input = { \"source\": \"abbdaccada\", \"target\": \"acddaccddc\", \"original\": [\"b\",\"b\",\"c\",\"a\",\"d\",\"a\",\"d\"], \"changed\": [\"a\",\"c\",\"b\",\"b\",\"b\",\"c\",\"c\"], \"cost\": [4,9,3,1,11,3,3] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"abcabdaddb\", \"target\": \"dcbadaaacc\", \"original\": [\"d\",\"b\",\"a\",\"a\",\"c\",\"c\"], \"changed\": [\"c\",\"c\",\"d\",\"b\",\"b\",\"a\"], \"cost\": [3,3,9,3,7,6] }\nassert my_solution.minimumCost(**test_input) == 61\n\ntest_input = { \"source\": \"abcadcabaa\", \"target\": \"bbbdddcaba\", \"original\": [\"b\",\"d\",\"c\",\"d\",\"a\",\"c\",\"b\",\"b\"], \"changed\": [\"c\",\"b\",\"a\",\"a\",\"c\",\"b\",\"d\",\"a\"], \"cost\": [1,8,4,3,8,3,11,5] }\nassert my_solution.minimumCost(**test_input) == 74\n\ntest_input = { \"source\": \"abccabacaa\", \"target\": \"aaabacbcbb\", \"original\": [\"c\",\"c\",\"d\",\"a\",\"d\",\"b\",\"c\",\"b\",\"d\",\"a\"], \"changed\": [\"b\",\"a\",\"a\",\"b\",\"b\",\"d\",\"d\",\"a\",\"c\",\"c\"], \"cost\": [9,10,8,6,9,10,2,6,6,8] }\nassert my_solution.minimumCost(**test_input) == 57\n\ntest_input = { \"source\": \"abdaababbb\", \"target\": \"dbdadabadc\", \"original\": [\"a\",\"c\",\"c\",\"b\",\"d\",\"a\",\"b\"], \"changed\": [\"c\",\"a\",\"b\",\"c\",\"b\",\"b\",\"d\"], \"cost\": [3,4,6,1,8,11,6] }\nassert my_solution.minimumCost(**test_input) == 56\n\ntest_input = { \"source\": \"abdbaaacaa\", \"target\": \"abbbccccad\", \"original\": [\"a\",\"a\",\"c\",\"b\",\"d\",\"d\",\"b\"], \"changed\": [\"d\",\"b\",\"b\",\"a\",\"a\",\"b\",\"c\"], \"cost\": [3,10,7,2,5,7,3] }\nassert my_solution.minimumCost(**test_input) == 49\n\ntest_input = { \"source\": \"abdcbdbccc\", \"target\": \"dbbcdcabba\", \"original\": [\"c\",\"c\",\"d\",\"b\",\"a\",\"c\",\"a\",\"d\",\"b\",\"d\",\"a\",\"b\"], \"changed\": [\"d\",\"a\",\"b\",\"d\",\"c\",\"b\",\"b\",\"a\",\"c\",\"c\",\"d\",\"a\"], \"cost\": [9,5,9,6,5,5,5,10,7,7,3,6] }\nassert my_solution.minimumCost(**test_input) == 46\n\ntest_input = { \"source\": \"acabbbdbdb\", \"target\": \"accbccbbab\", \"original\": [\"b\",\"d\",\"c\",\"d\",\"b\",\"c\"], \"changed\": [\"a\",\"a\",\"a\",\"c\",\"d\",\"d\"], \"cost\": [7,7,10,9,7,1] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"acadadccbb\", \"target\": \"dcaaabbbdd\", \"original\": [\"a\",\"c\",\"c\",\"a\",\"d\",\"b\",\"b\",\"d\",\"b\",\"a\"], \"changed\": [\"d\",\"d\",\"b\",\"b\",\"c\",\"d\",\"a\",\"a\",\"c\",\"c\"], \"cost\": [1,2,1,4,9,4,8,5,11,7] }\nassert my_solution.minimumCost(**test_input) == 25\n\ntest_input = { \"source\": \"acadbbcdcb\", \"target\": \"bcacabdcdd\", \"original\": [\"a\",\"b\",\"d\",\"b\",\"b\",\"c\",\"a\"], \"changed\": [\"d\",\"c\",\"c\",\"a\",\"d\",\"b\",\"b\"], \"cost\": [3,6,3,10,11,3,6] }\nassert my_solution.minimumCost(**test_input) == 61\n\ntest_input = { \"source\": \"acaddccaad\", \"target\": \"daacadcdda\", \"original\": [\"c\",\"c\",\"a\",\"b\",\"b\",\"a\",\"b\",\"d\",\"c\",\"a\",\"d\"], \"changed\": [\"a\",\"b\",\"b\",\"d\",\"a\",\"d\",\"c\",\"b\",\"d\",\"c\",\"c\"], \"cost\": [10,8,4,8,3,1,2,8,11,8,6] }\nassert my_solution.minimumCost(**test_input) == 52\n\ntest_input = { \"source\": \"acbbabcaac\", \"target\": \"bdcbaadcab\", \"original\": [\"d\",\"c\",\"a\",\"c\",\"b\",\"a\",\"a\",\"b\",\"c\",\"d\"], \"changed\": [\"a\",\"a\",\"d\",\"d\",\"c\",\"c\",\"b\",\"a\",\"b\",\"c\"], \"cost\": [9,11,8,6,11,11,1,1,9,9] }\nassert my_solution.minimumCost(**test_input) == 45\n\ntest_input = { \"source\": \"accabbadbc\", \"target\": \"adbbccbcbd\", \"original\": [\"a\",\"c\",\"a\",\"d\",\"b\",\"a\",\"c\",\"c\",\"b\",\"b\"], \"changed\": [\"c\",\"d\",\"b\",\"c\",\"d\",\"d\",\"b\",\"a\",\"c\",\"a\"], \"cost\": [7,10,9,3,2,5,1,8,11,2] }\nassert my_solution.minimumCost(**test_input) == 36\n\ntest_input = { \"source\": \"accabbdddd\", \"target\": \"cacdccbcad\", \"original\": [\"c\",\"a\",\"d\",\"b\",\"d\",\"c\",\"a\",\"b\",\"b\",\"c\",\"d\"], \"changed\": [\"d\",\"b\",\"a\",\"d\",\"c\",\"a\",\"d\",\"a\",\"c\",\"b\",\"b\"], \"cost\": [11,6,6,4,7,11,2,7,7,7,2] }\nassert my_solution.minimumCost(**test_input) == 51\n\ntest_input = { \"source\": \"accbaadbdb\", \"target\": \"baccbaacbb\", \"original\": [\"b\",\"b\",\"a\",\"d\",\"d\",\"a\",\"c\"], \"changed\": [\"a\",\"d\",\"d\",\"b\",\"a\",\"c\",\"a\"], \"cost\": [9,11,6,7,4,2,2] }\nassert my_solution.minimumCost(**test_input) == 61\n\ntest_input = { \"source\": \"accbddaaab\", \"target\": \"baddbaabbd\", \"original\": [\"a\",\"b\",\"c\",\"d\",\"d\",\"b\",\"d\",\"b\"], \"changed\": [\"b\",\"a\",\"a\",\"b\",\"a\",\"c\",\"c\",\"d\"], \"cost\": [6,3,4,6,1,6,10,6] }\nassert my_solution.minimumCost(**test_input) == 57\n\ntest_input = { \"source\": \"acccbcdccb\", \"target\": \"bdadccdbad\", \"original\": [\"a\",\"b\",\"c\",\"c\",\"a\",\"d\",\"d\"], \"changed\": [\"b\",\"c\",\"a\",\"d\",\"c\",\"a\",\"c\"], \"cost\": [8,1,1,9,3,10,4] }\nassert my_solution.minimumCost(**test_input) == 48\n\ntest_input = { \"source\": \"accccbccda\", \"target\": \"daadbbcaac\", \"original\": [\"a\",\"c\",\"a\",\"a\",\"d\",\"d\"], \"changed\": [\"c\",\"d\",\"d\",\"b\",\"b\",\"c\"], \"cost\": [3,6,6,10,9,8] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"acdacbdadb\", \"target\": \"aacccbbacd\", \"original\": [\"b\",\"b\",\"a\",\"a\",\"d\",\"c\"], \"changed\": [\"d\",\"a\",\"b\",\"d\",\"a\",\"a\"], \"cost\": [6,1,9,6,8,11] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"acdbcdadbd\", \"target\": \"daaadaaadd\", \"original\": [\"c\",\"a\",\"b\",\"b\",\"b\",\"d\",\"a\"], \"changed\": [\"d\",\"c\",\"d\",\"c\",\"a\",\"b\",\"d\"], \"cost\": [3,9,4,6,1,9,3] }\nassert my_solution.minimumCost(**test_input) == 54\n\ntest_input = { \"source\": \"acddadcbca\", \"target\": \"ddaabaaaac\", \"original\": [\"b\",\"d\",\"c\",\"a\",\"b\",\"d\",\"c\",\"b\",\"d\",\"c\",\"a\"], \"changed\": [\"c\",\"a\",\"b\",\"c\",\"d\",\"c\",\"a\",\"a\",\"b\",\"d\",\"d\"], \"cost\": [7,8,2,10,1,7,8,1,1,11,4] }\nassert my_solution.minimumCost(**test_input) == 35\n\ntest_input = { \"source\": \"adaadcaddd\", \"target\": \"cdddbdccad\", \"original\": [\"c\",\"c\",\"c\",\"d\",\"b\",\"a\",\"d\"], \"changed\": [\"d\",\"a\",\"b\",\"b\",\"d\",\"b\",\"c\"], \"cost\": [10,9,2,2,7,1,10] }\nassert my_solution.minimumCost(**test_input) == 92\n\ntest_input = { \"source\": \"adaaddacba\", \"target\": \"aabbddbbdd\", \"original\": [\"c\",\"b\",\"a\",\"b\",\"c\",\"b\"], \"changed\": [\"b\",\"c\",\"b\",\"a\",\"d\",\"d\"], \"cost\": [10,7,7,6,8,5] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"adacdcdacd\", \"target\": \"ccbabbbbdc\", \"original\": [\"a\",\"b\",\"c\",\"a\",\"d\",\"b\",\"a\",\"c\"], \"changed\": [\"c\",\"d\",\"d\",\"d\",\"a\",\"c\",\"b\",\"a\"], \"cost\": [4,3,1,1,6,4,10,6] }\nassert my_solution.minimumCost(**test_input) == 99\n\ntest_input = { \"source\": \"adadbabcdd\", \"target\": \"abbcdcbdba\", \"original\": [\"c\",\"d\",\"b\",\"a\",\"c\",\"b\",\"a\"], \"changed\": [\"d\",\"b\",\"d\",\"b\",\"b\",\"a\",\"c\"], \"cost\": [11,10,6,1,5,3,8] }\nassert my_solution.minimumCost(**test_input) == 80\n\ntest_input = { \"source\": \"adadcabbda\", \"target\": \"cabadddccc\", \"original\": [\"c\",\"a\",\"b\",\"b\",\"a\",\"d\",\"d\"], \"changed\": [\"b\",\"d\",\"d\",\"c\",\"b\",\"c\",\"b\"], \"cost\": [7,2,8,4,4,4,7] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"adbaabacdc\", \"target\": \"bccbbadcdc\", \"original\": [\"c\",\"b\",\"b\",\"d\",\"c\",\"a\",\"b\"], \"changed\": [\"b\",\"a\",\"c\",\"a\",\"a\",\"d\",\"d\"], \"cost\": [5,2,6,1,7,7,1] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"adbadbaacb\", \"target\": \"bccdbdccab\", \"original\": [\"d\",\"a\",\"c\",\"b\",\"c\",\"d\",\"a\",\"b\",\"c\",\"b\",\"a\",\"d\"], \"changed\": [\"a\",\"c\",\"b\",\"c\",\"a\",\"b\",\"b\",\"d\",\"d\",\"a\",\"d\",\"c\"], \"cost\": [3,7,7,9,2,9,10,2,9,5,11,8] }\nassert my_solution.minimumCost(**test_input) == 65\n\ntest_input = { \"source\": \"adbcdaddda\", \"target\": \"cbdccabcbc\", \"original\": [\"c\",\"a\",\"d\",\"d\",\"b\",\"b\",\"b\"], \"changed\": [\"a\",\"c\",\"c\",\"a\",\"d\",\"c\",\"a\"], \"cost\": [8,5,5,10,10,3,9] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"adcacaaabb\", \"target\": \"daaadadcbb\", \"original\": [\"d\",\"b\",\"a\",\"a\",\"d\",\"c\",\"b\",\"b\",\"d\",\"c\",\"c\",\"a\"], \"changed\": [\"b\",\"c\",\"d\",\"c\",\"c\",\"a\",\"a\",\"d\",\"a\",\"b\",\"d\",\"b\"], \"cost\": [2,3,2,4,5,9,11,3,10,1,9,2] }\nassert my_solution.minimumCost(**test_input) == 31\n\ntest_input = { \"source\": \"adcbbbdada\", \"target\": \"cdaabadcdc\", \"original\": [\"a\",\"a\",\"b\",\"c\",\"d\",\"b\",\"d\"], \"changed\": [\"c\",\"d\",\"c\",\"d\",\"a\",\"a\",\"c\"], \"cost\": [11,11,2,8,5,7,5] }\nassert my_solution.minimumCost(**test_input) == 60\n\ntest_input = { \"source\": \"adccbabbca\", \"target\": \"dcdbbdabba\", \"original\": [\"a\",\"d\",\"d\",\"b\",\"c\",\"b\",\"a\"], \"changed\": [\"c\",\"b\",\"c\",\"c\",\"a\",\"d\",\"d\"], \"cost\": [5,10,10,1,6,7,7] }\nassert my_solution.minimumCost(**test_input) == 90\n\ntest_input = { \"source\": \"adcdcbacab\", \"target\": \"acddaddadc\", \"original\": [\"b\",\"d\",\"c\",\"d\",\"c\",\"d\",\"b\",\"c\",\"a\",\"a\",\"a\",\"b\"], \"changed\": [\"a\",\"b\",\"b\",\"c\",\"a\",\"a\",\"d\",\"d\",\"c\",\"b\",\"d\",\"c\"], \"cost\": [2,11,11,9,1,3,6,9,6,4,8,5] }\nassert my_solution.minimumCost(**test_input) == 47\n\ntest_input = { \"source\": \"addbaccbbd\", \"target\": \"cabdcdadcc\", \"original\": [\"b\",\"d\",\"d\",\"d\",\"c\",\"b\",\"a\",\"c\",\"c\"], \"changed\": [\"a\",\"c\",\"a\",\"b\",\"b\",\"d\",\"d\",\"a\",\"d\"], \"cost\": [10,11,5,6,10,1,4,8,8] }\nassert my_solution.minimumCost(**test_input) == 82\n\ntest_input = { \"source\": \"addbacdaac\", \"target\": \"abddcadbcb\", \"original\": [\"d\",\"a\",\"c\",\"b\",\"a\",\"c\",\"a\",\"d\",\"c\",\"d\",\"b\"], \"changed\": [\"c\",\"c\",\"b\",\"d\",\"d\",\"d\",\"b\",\"b\",\"a\",\"a\",\"c\"], \"cost\": [9,2,9,4,11,6,10,3,7,2,5] }\nassert my_solution.minimumCost(**test_input) == 37\n\ntest_input = { \"source\": \"addbcccdcb\", \"target\": \"cbbdbddacb\", \"original\": [\"d\",\"c\",\"a\",\"a\",\"b\",\"b\",\"c\"], \"changed\": [\"c\",\"d\",\"b\",\"d\",\"d\",\"c\",\"b\"], \"cost\": [2,6,4,3,7,7,8] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"addcadccaa\", \"target\": \"dbbcaccabc\", \"original\": [\"a\",\"b\",\"d\",\"b\",\"d\",\"a\",\"c\",\"b\",\"a\",\"c\"], \"changed\": [\"c\",\"d\",\"a\",\"c\",\"b\",\"b\",\"d\",\"a\",\"d\",\"a\"], \"cost\": [8,11,5,1,11,4,3,8,11,4] }\nassert my_solution.minimumCost(**test_input) == 49\n\ntest_input = { \"source\": \"addcdbdadb\", \"target\": \"bcabdcccbd\", \"original\": [\"b\",\"b\",\"a\",\"c\",\"d\",\"a\",\"b\",\"c\",\"a\"], \"changed\": [\"a\",\"c\",\"c\",\"a\",\"a\",\"b\",\"d\",\"b\",\"d\"], \"cost\": [2,4,8,8,3,5,2,7,2] }\nassert my_solution.minimumCost(**test_input) == 59\n\ntest_input = { \"source\": \"adddbbdbdb\", \"target\": \"cdbadcaccc\", \"original\": [\"b\",\"c\",\"c\",\"b\",\"a\",\"c\",\"b\",\"a\",\"a\",\"d\",\"d\"], \"changed\": [\"d\",\"a\",\"b\",\"a\",\"b\",\"d\",\"c\",\"c\",\"d\",\"a\",\"c\"], \"cost\": [1,1,1,8,6,9,3,6,5,3,10] }\nassert my_solution.minimumCost(**test_input) == 40\n\ntest_input = { \"source\": \"adddccacca\", \"target\": \"cdcdcccdac\", \"original\": [\"d\",\"c\",\"a\",\"d\",\"b\",\"b\",\"b\",\"a\",\"d\",\"a\",\"c\",\"c\"], \"changed\": [\"c\",\"a\",\"c\",\"a\",\"d\",\"a\",\"c\",\"b\",\"b\",\"d\",\"d\",\"b\"], \"cost\": [7,7,6,10,1,1,11,5,3,2,10,3] }\nassert my_solution.minimumCost(**test_input) == 33\n\ntest_input = { \"source\": \"baacbbcdaa\", \"target\": \"abdbdbbabd\", \"original\": [\"c\",\"d\",\"c\",\"b\",\"a\",\"c\",\"b\",\"d\",\"b\"], \"changed\": [\"d\",\"c\",\"b\",\"a\",\"d\",\"a\",\"d\",\"a\",\"c\"], \"cost\": [9,5,5,2,9,4,5,3,6] }\nassert my_solution.minimumCost(**test_input) == 76\n\ntest_input = { \"source\": \"baadcdabbc\", \"target\": \"acbccadccd\", \"original\": [\"b\",\"b\",\"a\",\"a\",\"a\",\"d\",\"d\",\"d\",\"c\",\"c\",\"b\"], \"changed\": [\"c\",\"a\",\"c\",\"b\",\"d\",\"c\",\"a\",\"b\",\"b\",\"d\",\"d\"], \"cost\": [8,6,5,10,11,1,1,6,3,1,4] }\nassert my_solution.minimumCost(**test_input) == 37\n\ntest_input = { \"source\": \"baadcdabda\", \"target\": \"abdbcdaaca\", \"original\": [\"b\",\"b\",\"c\",\"d\",\"d\",\"a\",\"c\"], \"changed\": [\"d\",\"a\",\"a\",\"b\",\"c\",\"b\",\"d\"], \"cost\": [11,8,7,3,10,4,1] }\nassert my_solution.minimumCost(**test_input) == 48\n\ntest_input = { \"source\": \"babababdba\", \"target\": \"ccdaaabbac\", \"original\": [\"c\",\"d\",\"b\",\"a\",\"d\",\"a\",\"b\"], \"changed\": [\"b\",\"a\",\"d\",\"c\",\"c\",\"d\",\"c\"], \"cost\": [8,5,6,2,8,6,8] }\nassert my_solution.minimumCost(**test_input) == 55\n\ntest_input = { \"source\": \"babbacabba\", \"target\": \"adacccdcba\", \"original\": [\"c\",\"d\",\"d\",\"d\",\"c\",\"b\",\"b\",\"b\",\"a\"], \"changed\": [\"a\",\"b\",\"c\",\"a\",\"d\",\"a\",\"c\",\"d\",\"c\"], \"cost\": [1,1,8,3,2,2,11,8,3] }\nassert my_solution.minimumCost(**test_input) == 27\n\ntest_input = { \"source\": \"babbadbabc\", \"target\": \"ccdabbcbba\", \"original\": [\"a\",\"c\",\"d\",\"a\",\"b\",\"d\",\"b\",\"b\"], \"changed\": [\"b\",\"d\",\"c\",\"d\",\"a\",\"a\",\"c\",\"d\"], \"cost\": [3,3,1,4,4,8,2,9] }\nassert my_solution.minimumCost(**test_input) == 46\n\ntest_input = { \"source\": \"bacbddaacb\", \"target\": \"dcdaaadcda\", \"original\": [\"a\",\"d\",\"a\",\"a\",\"d\",\"c\",\"b\",\"c\",\"c\",\"b\"], \"changed\": [\"d\",\"c\",\"c\",\"b\",\"b\",\"b\",\"a\",\"a\",\"d\",\"c\"], \"cost\": [8,5,1,10,8,6,2,1,6,8] }\nassert my_solution.minimumCost(**test_input) == 46\n\ntest_input = { \"source\": \"baccbbcdcb\", \"target\": \"cabadbbacc\", \"original\": [\"c\",\"a\",\"c\",\"b\",\"c\",\"d\",\"a\",\"b\",\"d\",\"b\"], \"changed\": [\"a\",\"b\",\"b\",\"a\",\"d\",\"b\",\"c\",\"d\",\"c\",\"c\"], \"cost\": [4,4,2,11,9,9,1,4,6,1] }\nassert my_solution.minimumCost(**test_input) == 24\n\ntest_input = { \"source\": \"bacdbbcdba\", \"target\": \"cdcdddbbcd\", \"original\": [\"d\",\"a\",\"c\",\"b\",\"d\",\"a\",\"b\",\"c\",\"b\",\"c\",\"d\"], \"changed\": [\"c\",\"c\",\"a\",\"d\",\"b\",\"b\",\"a\",\"d\",\"c\",\"b\",\"a\"], \"cost\": [3,8,4,6,5,8,6,2,1,6,2] }\nassert my_solution.minimumCost(**test_input) == 39\n\ntest_input = { \"source\": \"bacdbccabb\", \"target\": \"caaccdbaac\", \"original\": [\"c\",\"d\",\"d\",\"a\",\"d\",\"c\"], \"changed\": [\"d\",\"b\",\"a\",\"b\",\"c\",\"a\"], \"cost\": [8,4,4,4,3,6] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"bacddacdba\", \"target\": \"bcbbaacdda\", \"original\": [\"b\",\"c\",\"c\",\"d\",\"d\",\"b\",\"b\",\"d\",\"a\",\"a\",\"c\",\"a\"], \"changed\": [\"a\",\"b\",\"d\",\"b\",\"a\",\"c\",\"d\",\"c\",\"c\",\"d\",\"a\",\"b\"], \"cost\": [5,6,7,4,4,8,8,6,8,3,6,11] }\nassert my_solution.minimumCost(**test_input) == 30\n\ntest_input = { \"source\": \"badaabbaba\", \"target\": \"caadbcadcd\", \"original\": [\"b\",\"c\",\"a\",\"c\",\"d\",\"a\",\"b\",\"d\",\"d\",\"b\",\"c\"], \"changed\": [\"c\",\"a\",\"d\",\"b\",\"a\",\"c\",\"d\",\"c\",\"b\",\"a\",\"d\"], \"cost\": [4,8,6,3,1,8,3,8,3,6,9] }\nassert my_solution.minimumCost(**test_input) == 44\n\ntest_input = { \"source\": \"badabbbbac\", \"target\": \"dacaabbcaa\", \"original\": [\"d\",\"b\",\"a\",\"d\",\"c\",\"b\",\"d\",\"c\",\"a\",\"c\",\"a\"], \"changed\": [\"b\",\"c\",\"d\",\"c\",\"a\",\"d\",\"a\",\"d\",\"c\",\"b\",\"b\"], \"cost\": [11,5,9,7,11,11,7,9,6,11,5] }\nassert my_solution.minimumCost(**test_input) == 50\n\ntest_input = { \"source\": \"badaccbdbd\", \"target\": \"dbbdacaaab\", \"original\": [\"b\",\"d\",\"b\",\"c\",\"b\",\"d\",\"a\",\"d\",\"a\",\"a\",\"c\",\"c\"], \"changed\": [\"d\",\"a\",\"a\",\"a\",\"c\",\"b\",\"d\",\"c\",\"b\",\"c\",\"d\",\"b\"], \"cost\": [3,9,3,11,11,6,2,11,11,2,11,1] }\nassert my_solution.minimumCost(**test_input) == 39\n\ntest_input = { \"source\": \"badadcccba\", \"target\": \"bbdbababcc\", \"original\": [\"c\",\"c\",\"a\",\"d\",\"d\",\"d\"], \"changed\": [\"a\",\"d\",\"b\",\"a\",\"b\",\"c\"], \"cost\": [1,3,2,2,4,4] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"badbbbccdb\", \"target\": \"bbbabbccbd\", \"original\": [\"a\",\"c\",\"a\",\"c\",\"d\",\"c\",\"d\",\"b\",\"d\",\"b\",\"a\"], \"changed\": [\"c\",\"b\",\"d\",\"d\",\"c\",\"a\",\"b\",\"d\",\"a\",\"c\",\"b\"], \"cost\": [5,4,5,3,4,4,6,3,8,11,4] }\nassert my_solution.minimumCost(**test_input) == 30\n\ntest_input = { \"source\": \"badcbccabc\", \"target\": \"bdcaacbcad\", \"original\": [\"d\",\"d\",\"c\",\"d\",\"a\",\"b\",\"c\",\"a\"], \"changed\": [\"a\",\"c\",\"d\",\"b\",\"b\",\"a\",\"b\",\"d\"], \"cost\": [1,5,4,5,11,10,8,11] }\nassert my_solution.minimumCost(**test_input) == 69\n\ntest_input = { \"source\": \"badcbdddcd\", \"target\": \"cdcbaddadc\", \"original\": [\"c\",\"b\",\"c\",\"d\",\"a\",\"b\",\"b\",\"d\",\"a\",\"c\",\"a\",\"d\"], \"changed\": [\"a\",\"c\",\"b\",\"a\",\"c\",\"d\",\"a\",\"b\",\"d\",\"d\",\"b\",\"c\"], \"cost\": [3,2,8,9,11,5,11,11,9,2,8,1] }\nassert my_solution.minimumCost(**test_input) == 32\n\ntest_input = { \"source\": \"baddbcbdbd\", \"target\": \"acdbcadabd\", \"original\": [\"a\",\"b\",\"b\",\"c\",\"a\",\"a\",\"b\",\"d\",\"c\",\"d\",\"d\"], \"changed\": [\"c\",\"a\",\"d\",\"d\",\"b\",\"d\",\"c\",\"c\",\"b\",\"b\",\"a\"], \"cost\": [9,10,5,4,1,5,7,8,11,9,8] }\nassert my_solution.minimumCost(**test_input) == 59\n\ntest_input = { \"source\": \"baddbdacad\", \"target\": \"cadaccbbab\", \"original\": [\"b\",\"a\",\"d\",\"a\",\"c\",\"b\",\"d\",\"c\",\"a\",\"d\"], \"changed\": [\"d\",\"b\",\"b\",\"d\",\"a\",\"c\",\"a\",\"b\",\"c\",\"c\"], \"cost\": [3,5,6,7,2,4,4,2,3,9] }\nassert my_solution.minimumCost(**test_input) == 32\n\ntest_input = { \"source\": \"bbacdcdcda\", \"target\": \"cbadabbdcb\", \"original\": [\"a\",\"d\",\"b\",\"c\",\"b\",\"c\",\"d\",\"a\",\"d\"], \"changed\": [\"b\",\"c\",\"d\",\"a\",\"a\",\"b\",\"b\",\"d\",\"a\"], \"cost\": [11,6,2,8,5,7,5,8,9] }\nassert my_solution.minimumCost(**test_input) == 64\n\ntest_input = { \"source\": \"bbadbbabbb\", \"target\": \"cbaaddaddc\", \"original\": [\"d\",\"a\",\"b\",\"c\",\"d\",\"c\",\"b\"], \"changed\": [\"b\",\"d\",\"c\",\"b\",\"c\",\"d\",\"d\"], \"cost\": [4,10,1,11,7,1,11] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"bbadcbcbbc\", \"target\": \"aaaccbccbb\", \"original\": [\"b\",\"d\",\"b\",\"d\",\"a\",\"c\",\"c\",\"a\",\"b\"], \"changed\": [\"c\",\"a\",\"a\",\"b\",\"b\",\"a\",\"b\",\"c\",\"d\"], \"cost\": [8,5,9,4,1,10,1,11,4] }\nassert my_solution.minimumCost(**test_input) == 39\n\ntest_input = { \"source\": \"bbbadaccbb\", \"target\": \"dadcaccadb\", \"original\": [\"a\",\"d\",\"d\",\"d\",\"c\",\"b\",\"c\",\"b\",\"c\",\"b\"], \"changed\": [\"d\",\"b\",\"c\",\"a\",\"b\",\"d\",\"d\",\"c\",\"a\",\"a\"], \"cost\": [10,1,4,6,4,1,10,3,1,6] }\nassert my_solution.minimumCost(**test_input) == 41\n\ntest_input = { \"source\": \"bbbadcbadb\", \"target\": \"aacbdcddcd\", \"original\": [\"a\",\"d\",\"d\",\"c\",\"a\",\"b\",\"c\",\"b\"], \"changed\": [\"d\",\"b\",\"a\",\"a\",\"c\",\"c\",\"b\",\"d\"], \"cost\": [3,1,1,9,1,2,1,2] }\nassert my_solution.minimumCost(**test_input) == 19\n\ntest_input = { \"source\": \"bbbbabbcbc\", \"target\": \"adacababac\", \"original\": [\"a\",\"c\",\"a\",\"b\",\"b\",\"d\",\"d\",\"a\",\"d\",\"b\",\"c\"], \"changed\": [\"d\",\"b\",\"c\",\"c\",\"d\",\"a\",\"b\",\"b\",\"c\",\"a\",\"d\"], \"cost\": [7,9,9,7,3,2,6,8,11,5,8] }\nassert my_solution.minimumCost(**test_input) == 39\n\ntest_input = { \"source\": \"bbbbdacbcd\", \"target\": \"cbadccdaaa\", \"original\": [\"d\",\"a\",\"c\",\"b\",\"d\",\"c\",\"a\",\"d\",\"b\",\"a\"], \"changed\": [\"c\",\"c\",\"b\",\"c\",\"a\",\"d\",\"d\",\"b\",\"d\",\"b\"], \"cost\": [2,9,11,3,6,11,6,4,5,5] }\nassert my_solution.minimumCost(**test_input) == 74", "start_time": 1703385000} +{"task_id": "weekly-contest-377-minimum-cost-to-convert-string-ii", "url": "https://leetcode.com/problems/minimum-cost-to-convert-string-ii", "title": "minimum-cost-to-convert-string-ii", "meta": {"questionId": "3238", "questionFrontendId": "2977", "title": "Minimum Cost to Convert String II", "titleSlug": "minimum-cost-to-convert-string-ii", "isPaidOnly": false, "difficulty": "Hard", "likes": 40, "dislikes": 36, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given two 0-indexed strings source and target, both of length n and consisting of lowercase English characters. You are also given two 0-indexed string arrays original and changed, and an integer array cost, where cost[i] represents the cost of converting the string original[i] to the string changed[i].\nYou start with the string source. In one operation, you can pick a substring x from the string, and change it to y at a cost of z if there exists any index j such that cost[j] == z, original[j] == x, and changed[j] == y. You are allowed to do any number of operations, but any pair of operations must satisfy either of these two conditions:\n\nThe substrings picked in the operations are source[a..b] and source[c..d] with either b < c or d < a. In other words, the indices picked in both operations are disjoint.\nThe substrings picked in the operations are source[a..b] and source[c..d] with a == c and b == d. In other words, the indices picked in both operations are identical.\n\nReturn the minimum cost to convert the string source to the string target using any number of operations. If it is impossible to convert source to target, return -1.\nNote that there may exist indices i, j such that original[j] == original[i] and changed[j] == changed[i].\n\nExample 1:\n\nInput: source = \"abcd\", target = \"acbe\", original = [\"a\",\"b\",\"c\",\"c\",\"e\",\"d\"], changed = [\"b\",\"c\",\"b\",\"e\",\"b\",\"e\"], cost = [2,5,5,1,2,20]\nOutput: 28\nExplanation: To convert \"abcd\" to \"acbe\", do the following operations:\n- Change substring source[1..1] from \"b\" to \"c\" at a cost of 5.\n- Change substring source[2..2] from \"c\" to \"e\" at a cost of 1.\n- Change substring source[2..2] from \"e\" to \"b\" at a cost of 2.\n- Change substring source[3..3] from \"d\" to \"e\" at a cost of 20.\nThe total cost incurred is 5 + 1 + 2 + 20 = 28. \nIt can be shown that this is the minimum possible cost.\n\nExample 2:\n\nInput: source = \"abcdefgh\", target = \"acdeeghh\", original = [\"bcd\",\"fgh\",\"thh\"], changed = [\"cde\",\"thh\",\"ghh\"], cost = [1,3,5]\nOutput: 9\nExplanation: To convert \"abcdefgh\" to \"acdeeghh\", do the following operations:\n- Change substring source[1..3] from \"bcd\" to \"cde\" at a cost of 1.\n- Change substring source[5..7] from \"fgh\" to \"thh\" at a cost of 3. We can do this operation because indices [5,7] are disjoint with indices picked in the first operation.\n- Change substring source[5..7] from \"thh\" to \"ghh\" at a cost of 5. We can do this operation because indices [5,7] are disjoint with indices picked in the first operation, and identical with indices picked in the second operation.\nThe total cost incurred is 1 + 3 + 5 = 9.\nIt can be shown that this is the minimum possible cost.\n\nExample 3:\n\nInput: source = \"abcdefgh\", target = \"addddddd\", original = [\"bcd\",\"defgh\"], changed = [\"ddd\",\"ddddd\"], cost = [100,1578]\nOutput: -1\nExplanation: It is impossible to convert \"abcdefgh\" to \"addddddd\".\nIf you select substring source[1..3] as the first operation to change \"abcdefgh\" to \"adddefgh\", you cannot select substring source[3..7] as the second operation because it has a common index, 3, with the first operation.\nIf you select substring source[3..7] as the first operation to change \"abcdefgh\" to \"abcddddd\", you cannot select substring source[1..3] as the second operation because it has a common index, 3, with the first operation.\n\n\nConstraints:\n\n1 <= source.length == target.length <= 1000\nsource, target consist only of lowercase English characters.\n1 <= cost.length == original.length == changed.length <= 100\n1 <= original[i].length == changed[i].length <= source.length\noriginal[i], changed[i] consist only of lowercase English characters.\noriginal[i] != changed[i]\n1 <= cost[i] <= 106\n\"\"\"\nclass Solution:\n def minimumCost(self, source: str, target: str, original: List[str], changed: List[str], cost: List[int]) -> int:\n ", "prompt_sft": "You are given two 0-indexed strings source and target, both of length n and consisting of lowercase English characters. You are also given two 0-indexed string arrays original and changed, and an integer array cost, where cost[i] represents the cost of converting the string original[i] to the string changed[i].\nYou start with the string source. In one operation, you can pick a substring x from the string, and change it to y at a cost of z if there exists any index j such that cost[j] == z, original[j] == x, and changed[j] == y. You are allowed to do any number of operations, but any pair of operations must satisfy either of these two conditions:\n\nThe substrings picked in the operations are source[a..b] and source[c..d] with either b < c or d < a. In other words, the indices picked in both operations are disjoint.\nThe substrings picked in the operations are source[a..b] and source[c..d] with a == c and b == d. In other words, the indices picked in both operations are identical.\n\nReturn the minimum cost to convert the string source to the string target using any number of operations. If it is impossible to convert source to target, return -1.\nNote that there may exist indices i, j such that original[j] == original[i] and changed[j] == changed[i].\n\nExample 1:\n\nInput: source = \"abcd\", target = \"acbe\", original = [\"a\",\"b\",\"c\",\"c\",\"e\",\"d\"], changed = [\"b\",\"c\",\"b\",\"e\",\"b\",\"e\"], cost = [2,5,5,1,2,20]\nOutput: 28\nExplanation: To convert \"abcd\" to \"acbe\", do the following operations:\n- Change substring source[1..1] from \"b\" to \"c\" at a cost of 5.\n- Change substring source[2..2] from \"c\" to \"e\" at a cost of 1.\n- Change substring source[2..2] from \"e\" to \"b\" at a cost of 2.\n- Change substring source[3..3] from \"d\" to \"e\" at a cost of 20.\nThe total cost incurred is 5 + 1 + 2 + 20 = 28. \nIt can be shown that this is the minimum possible cost.\n\nExample 2:\n\nInput: source = \"abcdefgh\", target = \"acdeeghh\", original = [\"bcd\",\"fgh\",\"thh\"], changed = [\"cde\",\"thh\",\"ghh\"], cost = [1,3,5]\nOutput: 9\nExplanation: To convert \"abcdefgh\" to \"acdeeghh\", do the following operations:\n- Change substring source[1..3] from \"bcd\" to \"cde\" at a cost of 1.\n- Change substring source[5..7] from \"fgh\" to \"thh\" at a cost of 3. We can do this operation because indices [5,7] are disjoint with indices picked in the first operation.\n- Change substring source[5..7] from \"thh\" to \"ghh\" at a cost of 5. We can do this operation because indices [5,7] are disjoint with indices picked in the first operation, and identical with indices picked in the second operation.\nThe total cost incurred is 1 + 3 + 5 = 9.\nIt can be shown that this is the minimum possible cost.\n\nExample 3:\n\nInput: source = \"abcdefgh\", target = \"addddddd\", original = [\"bcd\",\"defgh\"], changed = [\"ddd\",\"ddddd\"], cost = [100,1578]\nOutput: -1\nExplanation: It is impossible to convert \"abcdefgh\" to \"addddddd\".\nIf you select substring source[1..3] as the first operation to change \"abcdefgh\" to \"adddefgh\", you cannot select substring source[3..7] as the second operation because it has a common index, 3, with the first operation.\nIf you select substring source[3..7] as the first operation to change \"abcdefgh\" to \"abcddddd\", you cannot select substring source[1..3] as the second operation because it has a common index, 3, with the first operation.\n\n\nConstraints:\n\n1 <= source.length == target.length <= 1000\nsource, target consist only of lowercase English characters.\n1 <= cost.length == original.length == changed.length <= 100\n1 <= original[i].length == changed[i].length <= source.length\noriginal[i], changed[i] consist only of lowercase English characters.\noriginal[i] != changed[i]\n1 <= cost[i] <= 106\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def minimumCost(self, source: str, target: str, original: List[str], changed: List[str], cost: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"source\": \"abcd\", \"target\": \"acbe\", \"original\": [\"a\",\"b\",\"c\",\"c\",\"e\",\"d\"], \"changed\": [\"b\",\"c\",\"b\",\"e\",\"b\",\"e\"], \"cost\": [2,5,5,1,2,20] }\nassert my_solution.minimumCost(**test_input) == 28\n\ntest_input = { \"source\": \"abcdefgh\", \"target\": \"acdeeghh\", \"original\": [\"bcd\",\"fgh\",\"thh\"], \"changed\": [\"cde\",\"thh\",\"ghh\"], \"cost\": [1,3,5] }\nassert my_solution.minimumCost(**test_input) == 9\n\ntest_input = { \"source\": \"abcdefgh\", \"target\": \"addddddd\", \"original\": [\"bcd\",\"defgh\"], \"changed\": [\"ddd\",\"ddddd\"], \"cost\": [100,1578] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"a\", \"target\": \"b\", \"original\": [\"a\"], \"changed\": [\"b\"], \"cost\": [1] }\nassert my_solution.minimumCost(**test_input) == 1\n\ntest_input = { \"source\": \"a\", \"target\": \"c\", \"original\": [\"a\",\"b\",\"a\",\"a\"], \"changed\": [\"b\",\"c\",\"c\",\"c\"], \"cost\": [1,2,10,1] }\nassert my_solution.minimumCost(**test_input) == 1\n\ntest_input = { \"source\": \"a\", \"target\": \"d\", \"original\": [\"a\"], \"changed\": [\"b\"], \"cost\": [1] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"ajhpd\", \"target\": \"djjdc\", \"original\": [\"hpd\",\"iyk\",\"qzd\",\"hpi\",\"aic\",\"znh\",\"cea\",\"fug\",\"wir\",\"kwu\",\"yjo\",\"rzi\",\"a\",\"n\",\"f\",\"q\",\"u\",\"w\",\"x\",\"i\",\"x\",\"s\",\"o\",\"u\"], \"changed\": [\"iyk\",\"qzd\",\"hpi\",\"aic\",\"znh\",\"cea\",\"fug\",\"wir\",\"kwu\",\"yjo\",\"rzi\",\"jdc\",\"n\",\"f\",\"q\",\"u\",\"w\",\"x\",\"i\",\"x\",\"s\",\"o\",\"u\",\"d\"], \"cost\": [80257,95140,96349,89449,81714,5859,96734,96109,41211,99975,57611,32644,82896,22164,99889,98061,95403,90922,64031,94558,58418,99717,96588,88286] }\nassert my_solution.minimumCost(**test_input) == 1264348\n\ntest_input = { \"source\": \"bzshh\", \"target\": \"mlosr\", \"original\": [\"shh\",\"wbs\",\"hup\",\"sab\",\"csp\",\"tel\",\"mhq\",\"ezp\",\"eap\",\"fqb\",\"iea\",\"cej\",\"b\",\"v\",\"g\",\"e\",\"d\",\"x\",\"q\",\"v\",\"g\",\"x\",\"u\",\"m\",\"u\",\"q\",\"z\",\"q\",\"n\",\"p\"], \"changed\": [\"wbs\",\"hup\",\"sab\",\"csp\",\"tel\",\"mhq\",\"ezp\",\"eap\",\"fqb\",\"iea\",\"cej\",\"osr\",\"v\",\"g\",\"e\",\"d\",\"x\",\"q\",\"v\",\"g\",\"x\",\"u\",\"m\",\"u\",\"q\",\"m\",\"q\",\"n\",\"p\",\"l\"], \"cost\": [69565,82190,75322,85502,89675,98424,86521,85852,32285,99465,82356,97775,30173,88276,82158,40971,75361,65284,89814,68219,44777,95082,99781,99072,74513,49667,99719,93132,99203,54171] }\nassert my_solution.minimumCost(**test_input) == 1589277\n\ntest_input = { \"source\": \"fjybg\", \"target\": \"apyyt\", \"original\": [\"bg\",\"xr\",\"cc\",\"ip\",\"vq\",\"po\",\"ym\",\"rh\",\"vw\",\"lf\",\"lo\",\"ee\",\"qv\",\"yr\",\"f\",\"w\",\"i\",\"u\",\"g\",\"a\",\"e\",\"f\",\"s\",\"r\",\"p\",\"j\",\"o\",\"g\",\"i\",\"u\"], \"changed\": [\"xr\",\"cc\",\"ip\",\"vq\",\"po\",\"ym\",\"rh\",\"vw\",\"lf\",\"lo\",\"ee\",\"qv\",\"yr\",\"yt\",\"w\",\"i\",\"u\",\"g\",\"a\",\"e\",\"f\",\"s\",\"r\",\"p\",\"a\",\"o\",\"g\",\"i\",\"u\",\"p\"], \"cost\": [97733,90086,87125,85361,75644,46301,21616,79538,52507,95884,79353,61127,58665,96031,95035,12116,41158,91096,47819,88522,25493,80186,66981,87597,56691,86820,89031,99954,41271,39699] }\nassert my_solution.minimumCost(**test_input) == 1628332\n\ntest_input = { \"source\": \"htkdz\", \"target\": \"oaqaw\", \"original\": [\"kdz\",\"yyv\",\"cde\",\"oks\",\"fzu\",\"hkm\",\"dmb\",\"arh\",\"lix\",\"eij\",\"ksv\",\"t\",\"u\",\"f\",\"w\",\"b\",\"u\",\"v\",\"h\",\"o\",\"b\",\"o\",\"p\",\"z\",\"h\",\"w\",\"t\",\"p\",\"x\",\"y\"], \"changed\": [\"yyv\",\"cde\",\"oks\",\"fzu\",\"hkm\",\"dmb\",\"arh\",\"lix\",\"eij\",\"ksv\",\"qaw\",\"u\",\"f\",\"w\",\"b\",\"u\",\"v\",\"h\",\"o\",\"b\",\"o\",\"p\",\"z\",\"a\",\"w\",\"t\",\"p\",\"x\",\"y\",\"o\"], \"cost\": [90243,86765,84893,80924,85915,42672,99995,99429,88069,84925,71184,54929,83245,72750,87238,30151,58657,94445,98330,90683,83980,96513,75536,95212,79301,74556,94836,94781,76273,86147] }\nassert my_solution.minimumCost(**test_input) == 1278928\n\ntest_input = { \"source\": \"iktgh\", \"target\": \"srwcg\", \"original\": [\"h\",\"e\",\"y\",\"g\",\"q\",\"y\",\"t\",\"n\",\"r\",\"e\",\"i\",\"x\",\"iktg\",\"xwgv\",\"ddrp\",\"saxt\",\"rvdq\",\"moiy\",\"loln\",\"bkgj\",\"jjgi\",\"vatf\"], \"changed\": [\"e\",\"y\",\"g\",\"q\",\"y\",\"t\",\"n\",\"r\",\"e\",\"i\",\"x\",\"g\",\"xwgv\",\"ddrp\",\"saxt\",\"rvdq\",\"moiy\",\"loln\",\"bkgj\",\"jjgi\",\"vatf\",\"srwc\"], \"cost\": [70839,75691,55903,82637,97906,86576,92197,74464,86638,61531,80041,52732,96361,39766,74988,59857,69068,89990,74293,82838,37650,26885] }\nassert my_solution.minimumCost(**test_input) == 854129\n\ntest_input = { \"source\": \"imbin\", \"target\": \"dmhjv\", \"original\": [\"bin\",\"pwo\",\"fwt\",\"xwi\",\"xal\",\"uqt\",\"lmp\",\"erq\",\"kac\",\"dgv\",\"qgh\",\"rei\",\"nbx\",\"i\",\"u\",\"b\",\"v\",\"c\",\"q\",\"p\",\"f\",\"q\",\"v\",\"t\",\"n\",\"b\"], \"changed\": [\"pwo\",\"fwt\",\"xwi\",\"xal\",\"uqt\",\"lmp\",\"erq\",\"kac\",\"dgv\",\"qgh\",\"rei\",\"nbx\",\"hjv\",\"u\",\"b\",\"v\",\"c\",\"q\",\"p\",\"f\",\"q\",\"v\",\"t\",\"n\",\"b\",\"d\"], \"cost\": [47307,30907,64949,35735,84284,83424,69858,92113,51405,69242,97014,91471,78165,92733,79709,99573,78055,20529,85549,90496,60896,75354,50630,49094,41380,46980] }\nassert my_solution.minimumCost(**test_input) == 1115296\n\ntest_input = { \"source\": \"jegbx\", \"target\": \"ezhfc\", \"original\": [\"egbx\",\"hrbf\",\"twne\",\"snjd\",\"ysrf\",\"qzqg\",\"rcll\",\"ekvz\",\"inpr\",\"frxs\",\"xcww\",\"unsw\",\"vdug\",\"ycvs\",\"j\",\"v\",\"j\",\"y\",\"n\",\"q\",\"w\",\"a\",\"z\",\"g\",\"b\",\"d\"], \"changed\": [\"hrbf\",\"twne\",\"snjd\",\"ysrf\",\"qzqg\",\"rcll\",\"ekvz\",\"inpr\",\"frxs\",\"xcww\",\"unsw\",\"vdug\",\"ycvs\",\"zhfc\",\"v\",\"j\",\"y\",\"n\",\"q\",\"w\",\"a\",\"z\",\"g\",\"b\",\"d\",\"e\"], \"cost\": [50682,89150,91153,85032,97960,96862,81138,86570,77628,45200,44955,70845,99254,80325,91331,95349,84374,94177,53994,94284,79531,92353,60384,100000,93152,19787] }\nassert my_solution.minimumCost(**test_input) == 1868790\n\ntest_input = { \"source\": \"jpyjj\", \"target\": \"jqnfp\", \"original\": [\"j\",\"i\",\"q\",\"u\",\"y\",\"w\",\"d\",\"a\",\"h\",\"s\",\"i\",\"y\",\"w\",\"pyj\",\"qng\",\"lrn\",\"nrm\",\"tvn\",\"fei\",\"fpj\",\"qlw\",\"lrb\",\"ufu\",\"kll\",\"nqp\"], \"changed\": [\"i\",\"q\",\"u\",\"y\",\"w\",\"d\",\"a\",\"h\",\"s\",\"i\",\"y\",\"w\",\"p\",\"qng\",\"lrn\",\"nrm\",\"tvn\",\"fei\",\"fpj\",\"qlw\",\"lrb\",\"ufu\",\"kll\",\"nqp\",\"qnf\"], \"cost\": [62657,90954,55348,88767,87756,55487,49700,51801,94877,81661,99027,91814,62872,25235,62153,96875,12009,85321,68993,75866,72888,96411,78568,83975,60456] }\nassert my_solution.minimumCost(**test_input) == 1131062\n\ntest_input = { \"source\": \"nialx\", \"target\": \"qvqfl\", \"original\": [\"x\",\"r\",\"a\",\"x\",\"c\",\"w\",\"s\",\"a\",\"n\",\"e\",\"q\",\"p\",\"v\",\"k\",\"o\",\"ial\",\"qzu\",\"owr\",\"kyq\",\"ukk\",\"gpq\",\"jdp\",\"dus\",\"eng\",\"btu\",\"cbp\"], \"changed\": [\"r\",\"a\",\"x\",\"c\",\"w\",\"s\",\"a\",\"l\",\"e\",\"q\",\"p\",\"v\",\"k\",\"o\",\"q\",\"qzu\",\"owr\",\"kyq\",\"ukk\",\"gpq\",\"jdp\",\"dus\",\"eng\",\"btu\",\"cbp\",\"vqf\"], \"cost\": [64196,95812,96987,40860,41507,99365,99208,53062,44440,65136,95625,86166,61798,84228,92555,97678,97576,19742,92989,98167,68457,82411,39923,81778,87792,7523] }\nassert my_solution.minimumCost(**test_input) == 1096682\n\ntest_input = { \"source\": \"pagpe\", \"target\": \"xacng\", \"original\": [\"gpe\",\"owt\",\"wyv\",\"eba\",\"xgp\",\"uny\",\"ibc\",\"usb\",\"mzj\",\"wdo\",\"lyc\",\"eof\",\"oci\",\"p\",\"e\",\"p\",\"u\",\"h\",\"w\",\"i\",\"l\"], \"changed\": [\"owt\",\"wyv\",\"eba\",\"xgp\",\"uny\",\"ibc\",\"usb\",\"mzj\",\"wdo\",\"lyc\",\"eof\",\"oci\",\"cng\",\"e\",\"p\",\"u\",\"h\",\"w\",\"i\",\"l\",\"x\"], \"cost\": [56193,92982,90717,67407,91949,77752,88841,43278,51149,43646,99585,41038,84989,57688,64474,96532,77511,37031,90895,62831,87342] }\nassert my_solution.minimumCost(**test_input) == 1381668\n\ntest_input = { \"source\": \"aaabbebbbhbbbbebaaeh\", \"target\": \"hhbebebbahhhehhbbhee\", \"original\": [\"a\",\"b\",\"b\",\"b\",\"e\",\"a\",\"h\"], \"changed\": [\"b\",\"e\",\"a\",\"h\",\"h\",\"h\",\"e\"], \"cost\": [9,8,5,9,3,7,9] }\nassert my_solution.minimumCost(**test_input) == 99\n\ntest_input = { \"source\": \"abbbeebebehbbhhhbeab\", \"target\": \"aehebehebaeaebbaahhb\", \"original\": [\"b\",\"b\",\"e\",\"e\",\"h\",\"h\",\"h\",\"b\",\"e\",\"a\"], \"changed\": [\"e\",\"h\",\"b\",\"a\",\"e\",\"b\",\"a\",\"a\",\"h\",\"h\"], \"cost\": [10,2,9,10,7,8,10,10,6,9] }\nassert my_solution.minimumCost(**test_input) == 118\n\ntest_input = { \"source\": \"abebbeeeahhbahaehaab\", \"target\": \"eebhheeahaahbaebaaea\", \"original\": [\"a\",\"b\",\"e\",\"a\",\"h\",\"a\",\"e\",\"b\"], \"changed\": [\"e\",\"h\",\"a\",\"h\",\"a\",\"b\",\"b\",\"a\"], \"cost\": [6,8,5,10,10,10,10,8] }\nassert my_solution.minimumCost(**test_input) == 149\n\ntest_input = { \"source\": \"aeaaebhbhehbeehbehea\", \"target\": \"babehheaaeebeebahhba\", \"original\": [\"a\",\"e\",\"a\",\"e\",\"b\",\"h\",\"b\",\"h\",\"h\",\"e\"], \"changed\": [\"b\",\"a\",\"e\",\"h\",\"h\",\"e\",\"a\",\"a\",\"b\",\"b\"], \"cost\": [8,6,3,8,7,9,9,10,10,5] }\nassert my_solution.minimumCost(**test_input) == 109\n\ntest_input = { \"source\": \"aeehhhaeebhhbeabeeha\", \"target\": \"haaeaabeeeheehbaehha\", \"original\": [\"a\",\"e\",\"h\",\"a\",\"h\",\"b\",\"e\",\"b\"], \"changed\": [\"h\",\"a\",\"a\",\"b\",\"e\",\"e\",\"h\",\"a\"], \"cost\": [7,9,10,7,8,9,8,8] }\nassert my_solution.minimumCost(**test_input) == 117\n\ntest_input = { \"source\": \"ahhebhhbbhbebaeehbbh\", \"target\": \"hbebaeebebhabeehahhb\", \"original\": [\"a\",\"h\",\"h\",\"b\",\"b\",\"e\",\"a\",\"e\",\"h\",\"b\"], \"changed\": [\"h\",\"b\",\"e\",\"a\",\"e\",\"a\",\"e\",\"h\",\"a\",\"h\"], \"cost\": [4,8,2,8,9,9,9,8,9,6] }\nassert my_solution.minimumCost(**test_input) == 116\n\ntest_input = { \"source\": \"babhbaaabbabehhhaaea\", \"target\": \"aabhhaebehbaehahbahb\", \"original\": [\"b\",\"b\",\"a\",\"a\",\"e\"], \"changed\": [\"a\",\"h\",\"e\",\"b\",\"h\"], \"cost\": [2,10,8,4,6] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"bbaaaebhhbehaaaabbab\", \"target\": \"aebahaaabheebbaehbbb\", \"original\": [\"b\",\"b\",\"a\",\"e\",\"h\",\"h\",\"a\",\"a\",\"b\"], \"changed\": [\"a\",\"e\",\"h\",\"a\",\"a\",\"b\",\"b\",\"e\",\"h\"], \"cost\": [6,8,3,10,10,7,7,9,10] }\nassert my_solution.minimumCost(**test_input) == 120\n\ntest_input = { \"source\": \"bbabeehehhbhbhbbaabb\", \"target\": \"heaabheabehhahhabhhe\", \"original\": [\"b\",\"b\",\"b\",\"e\",\"h\",\"e\",\"h\",\"a\",\"a\"], \"changed\": [\"h\",\"e\",\"a\",\"b\",\"e\",\"a\",\"b\",\"b\",\"h\"], \"cost\": [7,6,5,9,7,3,10,10,6] }\nassert my_solution.minimumCost(**test_input) == 116\n\ntest_input = { \"source\": \"bbhbahbbbabhbbbbbhaa\", \"target\": \"aheebebehaeheehhbahh\", \"original\": [\"b\",\"b\",\"h\",\"b\",\"a\",\"a\"], \"changed\": [\"a\",\"h\",\"e\",\"e\",\"b\",\"h\"], \"cost\": [3,5,9,9,5,10] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"beeeaehhbbbaeaeebabh\", \"target\": \"ahehaahaaehhabaehbah\", \"original\": [\"b\",\"e\",\"e\",\"h\",\"b\",\"a\",\"a\"], \"changed\": [\"a\",\"h\",\"a\",\"a\",\"h\",\"h\",\"b\"], \"cost\": [3,5,5,10,1,7,2] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"bhabahbhabaahbhahabb\", \"target\": \"ehbbhehbbhebaeeheebe\", \"original\": [\"a\",\"a\",\"h\",\"b\",\"h\",\"a\"], \"changed\": [\"b\",\"h\",\"e\",\"h\",\"b\",\"e\"], \"cost\": [9,10,5,10,10,8] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"bhhbaaahheaebehhabeh\", \"target\": \"bbhebbeeahahhbeabeba\", \"original\": [\"h\",\"b\",\"h\",\"h\",\"e\",\"b\",\"e\",\"a\"], \"changed\": [\"b\",\"e\",\"e\",\"a\",\"h\",\"h\",\"b\",\"b\"], \"cost\": [2,8,8,8,10,7,5,7] }\nassert my_solution.minimumCost(**test_input) == 131\n\ntest_input = { \"source\": \"eaabhhahhhehbabaabae\", \"target\": \"bebaehabeehehbehhahh\", \"original\": [\"a\",\"a\",\"b\",\"h\",\"h\",\"b\",\"a\",\"e\"], \"changed\": [\"e\",\"b\",\"a\",\"e\",\"b\",\"e\",\"h\",\"h\"], \"cost\": [9,9,9,8,6,4,7,10] }\nassert my_solution.minimumCost(**test_input) == 158\n\ntest_input = { \"source\": \"ebbaebeheabhheeeaeaa\", \"target\": \"eehbhebhheeabehbebea\", \"original\": [\"b\",\"a\",\"e\",\"e\",\"h\",\"h\",\"a\"], \"changed\": [\"e\",\"b\",\"h\",\"b\",\"a\",\"b\",\"e\"], \"cost\": [6,9,10,7,7,7,9] }\nassert my_solution.minimumCost(**test_input) == 135\n\ntest_input = { \"source\": \"ebbhbheeaeaeeahehahh\", \"target\": \"ehhebhahhhhheaaaaahb\", \"original\": [\"b\",\"h\",\"e\",\"a\",\"h\",\"e\",\"h\"], \"changed\": [\"h\",\"e\",\"h\",\"h\",\"a\",\"a\",\"b\"], \"cost\": [10,7,10,8,10,3,9] }\nassert my_solution.minimumCost(**test_input) == 108\n\ntest_input = { \"source\": \"eebhehaabeaaaaheheha\", \"target\": \"abbbaeaebbhabehbabbb\", \"original\": [\"e\",\"h\",\"e\",\"h\",\"a\",\"a\",\"a\",\"h\"], \"changed\": [\"b\",\"b\",\"a\",\"e\",\"h\",\"b\",\"e\",\"a\"], \"cost\": [10,10,10,8,9,6,10,10] }\nassert my_solution.minimumCost(**test_input) == 139\n\ntest_input = { \"source\": \"eeeaehbabbebhhaehaha\", \"target\": \"hehbbahabhhababeeeeh\", \"original\": [\"e\",\"a\",\"e\",\"h\",\"b\",\"h\",\"h\",\"a\",\"a\"], \"changed\": [\"h\",\"b\",\"b\",\"a\",\"h\",\"b\",\"e\",\"e\",\"h\"], \"cost\": [3,9,4,8,9,10,6,10,6] }\nassert my_solution.minimumCost(**test_input) == 120\n\ntest_input = { \"source\": \"eeehababeeeheebeehah\", \"target\": \"hhhabbbbahhehhhbhbab\", \"original\": [\"e\",\"h\",\"a\",\"e\",\"h\",\"b\",\"e\"], \"changed\": [\"h\",\"a\",\"b\",\"a\",\"e\",\"h\",\"b\"], \"cost\": [7,8,6,10,10,10,9] }\nassert my_solution.minimumCost(**test_input) == 143\n\ntest_input = { \"source\": \"eehhhbbhebeeehahaaae\", \"target\": \"bahaeebhbhhebbbahbhh\", \"original\": [\"e\",\"h\",\"b\",\"b\",\"e\",\"e\",\"h\",\"a\",\"h\",\"a\"], \"changed\": [\"a\",\"e\",\"e\",\"h\",\"h\",\"b\",\"b\",\"b\",\"a\",\"h\"], \"cost\": [9,9,9,5,3,8,10,2,2,1] }\nassert my_solution.minimumCost(**test_input) == 69\n\ntest_input = { \"source\": \"ehaaeabaebaehbbhbhbe\", \"target\": \"baheeebehhebhbeebbbe\", \"original\": [\"e\",\"h\",\"a\",\"a\",\"e\",\"b\",\"b\",\"h\"], \"changed\": [\"b\",\"a\",\"h\",\"e\",\"h\",\"h\",\"e\",\"e\"], \"cost\": [8,8,4,10,7,10,10,10] }\nassert my_solution.minimumCost(**test_input) == 123\n\ntest_input = { \"source\": \"ehaehehbeebaebaeebeb\", \"target\": \"eehhebaheaheahhhbeaa\", \"original\": [\"h\",\"e\",\"b\",\"e\",\"a\",\"a\",\"e\",\"b\",\"b\"], \"changed\": [\"e\",\"h\",\"h\",\"a\",\"e\",\"h\",\"b\",\"e\",\"a\"], \"cost\": [9,8,8,10,10,10,3,10,9] }\nassert my_solution.minimumCost(**test_input) == 162\n\ntest_input = { \"source\": \"ehbahbbaabhbabahbbhh\", \"target\": \"ahbhbehbahaehhaaehhh\", \"original\": [\"a\",\"b\",\"h\"], \"changed\": [\"h\",\"h\",\"a\"], \"cost\": [9,9,2] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"ehbeabbhhebhbahbhbab\", \"target\": \"hhbaaebbaaabhhbehhae\", \"original\": [\"e\",\"e\",\"b\",\"h\",\"b\",\"a\",\"b\"], \"changed\": [\"h\",\"a\",\"a\",\"b\",\"h\",\"h\",\"e\"], \"cost\": [3,8,10,7,5,10,10] }\nassert my_solution.minimumCost(**test_input) == 117\n\ntest_input = { \"source\": \"hbhheeehehbbhbbehaae\", \"target\": \"aebhbheehbbbhabbhebh\", \"original\": [\"h\",\"b\",\"h\",\"e\",\"h\",\"e\",\"a\",\"a\"], \"changed\": [\"a\",\"e\",\"b\",\"h\",\"e\",\"b\",\"e\",\"b\"], \"cost\": [3,9,8,10,7,8,4,9] }\nassert my_solution.minimumCost(**test_input) == 116\n\ntest_input = { \"source\": \"hebeebhhhhabaaheabbh\", \"target\": \"aeheabaeaaeababeheae\", \"original\": [\"h\",\"b\",\"h\",\"a\",\"b\",\"a\",\"h\",\"a\",\"b\"], \"changed\": [\"a\",\"h\",\"e\",\"e\",\"a\",\"b\",\"b\",\"h\",\"e\"], \"cost\": [10,6,8,10,10,5,10,10,2] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"hebhhaaaahbehahebaba\", \"target\": \"ahhabehbahehhahaehhh\", \"original\": [\"h\",\"b\",\"h\",\"a\",\"a\",\"b\",\"e\",\"e\"], \"changed\": [\"a\",\"h\",\"b\",\"e\",\"h\",\"e\",\"h\",\"a\"], \"cost\": [6,6,10,9,7,10,10,7] }\nassert my_solution.minimumCost(**test_input) == 128\n\ntest_input = { \"source\": \"hheahabebabhehahaahe\", \"target\": \"eaahbbbaehhhahhhebhe\", \"original\": [\"h\",\"h\",\"e\",\"a\",\"a\",\"b\",\"a\"], \"changed\": [\"e\",\"a\",\"a\",\"b\",\"h\",\"h\",\"e\"], \"cost\": [3,10,10,8,10,10,10] }\nassert my_solution.minimumCost(**test_input) == 140\n\ntest_input = { \"source\": \"hhebabehhhhbehaahbhh\", \"target\": \"ehhabeahaheaabbehhbe\", \"original\": [\"h\",\"e\",\"b\",\"a\",\"b\",\"e\",\"h\",\"h\",\"b\"], \"changed\": [\"e\",\"h\",\"a\",\"b\",\"e\",\"a\",\"a\",\"b\",\"h\"], \"cost\": [5,3,9,10,10,6,9,5,10] }\nassert my_solution.minimumCost(**test_input) == 127\n\ntest_input = { \"source\": \"hhhbbbhhaeabhheaehea\", \"target\": \"bebhhaeheahhebbeeahb\", \"original\": [\"h\",\"h\",\"b\",\"a\",\"e\",\"a\",\"e\",\"h\",\"e\",\"a\"], \"changed\": [\"b\",\"e\",\"h\",\"e\",\"a\",\"h\",\"b\",\"a\",\"h\",\"b\"], \"cost\": [10,6,8,9,6,8,10,5,8,9] }\nassert my_solution.minimumCost(**test_input) == 149\n\ntest_input = { \"source\": \"anrlqxdnlqcxqdlsceokwgrzkakyqw\", \"target\": \"fxynzghpiexaarjuaepxxpaudqipxx\", \"original\": [\"a\",\"n\",\"r\",\"l\",\"q\",\"x\",\"d\",\"n\",\"l\",\"q\",\"d\",\"s\",\"k\",\"w\",\"g\",\"z\",\"k\",\"a\",\"k\",\"q\"], \"changed\": [\"f\",\"x\",\"y\",\"n\",\"z\",\"g\",\"h\",\"p\",\"i\",\"a\",\"r\",\"u\",\"x\",\"x\",\"p\",\"u\",\"d\",\"q\",\"i\",\"x\"], \"cost\": [78,19,91,27,96,16,95,100,38,99,99,94,82,75,71,100,96,88,78,89] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"ayvhtgqvcputvzdksluictwibnvlxx\", \"target\": \"pssmcmkjyqniiyiiubwghwldxptuix\", \"original\": [\"a\",\"h\",\"t\",\"g\",\"v\",\"c\",\"t\",\"v\",\"z\",\"d\",\"k\",\"s\",\"l\",\"u\",\"i\",\"c\",\"w\",\"b\",\"v\",\"l\",\"x\"], \"changed\": [\"p\",\"m\",\"c\",\"m\",\"j\",\"y\",\"i\",\"i\",\"y\",\"i\",\"i\",\"u\",\"b\",\"w\",\"g\",\"h\",\"l\",\"x\",\"t\",\"u\",\"i\"], \"cost\": [82,77,100,95,86,34,77,38,90,31,97,96,77,32,79,87,72,65,100,98,56] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"bdkgumfyqsosetnboawzhflcfkhryb\", \"target\": \"rqwqiefmafkzmataueoobbfkkxsung\", \"original\": [\"b\",\"d\",\"k\",\"g\",\"u\",\"m\",\"y\",\"q\",\"s\",\"o\",\"s\",\"e\",\"t\",\"o\",\"z\",\"h\",\"l\",\"c\",\"f\",\"k\",\"h\",\"r\",\"y\",\"b\"], \"changed\": [\"r\",\"q\",\"w\",\"q\",\"i\",\"e\",\"m\",\"a\",\"f\",\"k\",\"z\",\"m\",\"a\",\"u\",\"o\",\"b\",\"f\",\"k\",\"k\",\"x\",\"s\",\"u\",\"n\",\"g\"], \"cost\": [97,97,72,71,84,96,81,53,85,81,85,48,82,47,54,79,63,94,86,66,96,39,80,82] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"dmhqhwozzfespijaadiwceabbxlfgd\", \"target\": \"owmyowokqacnhwmaellbhcnoodviac\", \"original\": [\"d\",\"m\",\"h\",\"h\",\"z\",\"z\",\"f\",\"s\",\"p\",\"a\",\"d\",\"i\",\"w\",\"c\",\"a\",\"b\",\"x\",\"l\",\"g\",\"d\"], \"changed\": [\"o\",\"w\",\"m\",\"o\",\"k\",\"q\",\"a\",\"n\",\"h\",\"e\",\"l\",\"l\",\"b\",\"h\",\"n\",\"o\",\"d\",\"v\",\"a\",\"c\"], \"cost\": [100,55,84,66,97,92,86,86,98,78,71,100,89,74,77,15,59,59,87,86] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"erjbgdadefwtaydgneprfphalkagce\", \"target\": \"uzslvcynelwivxyzvhlpoxeulnguvi\", \"original\": [\"e\",\"r\",\"j\",\"b\",\"g\",\"d\",\"a\",\"d\",\"f\",\"t\",\"a\",\"y\",\"d\",\"g\",\"e\",\"p\",\"r\",\"f\",\"h\",\"a\",\"k\",\"g\",\"c\",\"e\"], \"changed\": [\"u\",\"z\",\"s\",\"l\",\"v\",\"c\",\"y\",\"n\",\"l\",\"i\",\"v\",\"x\",\"y\",\"z\",\"h\",\"l\",\"p\",\"o\",\"e\",\"u\",\"n\",\"u\",\"v\",\"i\"], \"cost\": [36,100,100,98,99,90,98,93,29,80,37,98,82,84,94,97,86,97,73,96,73,92,94,57] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"gsolujonrufkcbigtjvpsgwtcaafjk\", \"target\": \"niymoyhbyicgjgcjkqkonhcgyqvhwr\", \"original\": [\"g\",\"s\",\"o\",\"j\",\"o\",\"n\",\"u\",\"b\",\"i\",\"g\",\"t\",\"j\",\"v\",\"p\",\"s\",\"g\",\"t\",\"c\",\"a\",\"a\",\"j\"], \"changed\": [\"n\",\"i\",\"y\",\"y\",\"h\",\"b\",\"i\",\"g\",\"c\",\"j\",\"k\",\"q\",\"k\",\"o\",\"n\",\"h\",\"g\",\"y\",\"q\",\"v\",\"w\"], \"cost\": [90,91,99,100,97,95,72,56,85,55,96,77,65,21,38,18,54,91,90,99,87] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"haqgciljqjmplyboytkbvzvncembca\", \"target\": \"vxjxtxjkvyfvnkfbcfxzwjgmvflduz\", \"original\": [\"a\",\"q\",\"g\",\"c\",\"i\",\"l\",\"j\",\"q\",\"j\",\"p\",\"l\",\"b\",\"y\",\"t\",\"b\",\"z\",\"n\",\"c\",\"e\",\"m\",\"c\",\"a\"], \"changed\": [\"x\",\"j\",\"x\",\"t\",\"x\",\"j\",\"k\",\"v\",\"y\",\"v\",\"n\",\"f\",\"c\",\"f\",\"z\",\"j\",\"m\",\"v\",\"f\",\"l\",\"u\",\"z\"], \"cost\": [92,99,90,100,86,49,32,98,72,80,87,87,54,56,93,19,94,81,94,98,76,94] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"jdsusoktswdtjkwuawzxxxruaybamd\", \"target\": \"ycnwpqplsmumuzggvekrmgtjxxdqwd\", \"original\": [\"j\",\"s\",\"u\",\"s\",\"k\",\"t\",\"d\",\"t\",\"j\",\"w\",\"u\",\"a\",\"w\",\"z\",\"x\",\"x\",\"r\",\"u\",\"y\",\"b\",\"m\"], \"changed\": [\"y\",\"n\",\"w\",\"p\",\"p\",\"l\",\"u\",\"m\",\"u\",\"g\",\"g\",\"v\",\"e\",\"k\",\"r\",\"g\",\"t\",\"j\",\"x\",\"d\",\"w\"], \"cost\": [40,97,100,79,39,99,59,49,84,95,90,82,87,22,95,90,76,70,66,96,92] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"nwukaumgrqigiynrvteerkcwheiiim\", \"target\": \"nkimfbwdsbbbpccfepohlvxapvgxlg\", \"original\": [\"w\",\"k\",\"u\",\"m\",\"r\",\"q\",\"g\",\"i\",\"y\",\"n\",\"r\",\"v\",\"t\",\"e\",\"e\",\"r\",\"k\",\"h\",\"e\",\"i\",\"i\",\"i\",\"m\"], \"changed\": [\"k\",\"m\",\"b\",\"w\",\"s\",\"b\",\"b\",\"p\",\"c\",\"c\",\"f\",\"e\",\"p\",\"o\",\"h\",\"l\",\"v\",\"p\",\"v\",\"g\",\"x\",\"l\",\"g\"], \"cost\": [63,94,50,93,100,95,99,92,100,28,98,73,80,99,73,77,84,98,64,87,98,60,85] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"ovtbwsxlxgefyzlwgslddghfjyvyif\", \"target\": \"iobyykxbenmagxgftwubmkrxuvhaxq\", \"original\": [\"v\",\"t\",\"s\",\"l\",\"x\",\"g\",\"e\",\"f\",\"y\",\"z\",\"l\",\"g\",\"s\",\"l\",\"d\",\"d\",\"g\",\"h\",\"f\",\"j\",\"y\",\"v\",\"i\",\"f\"], \"changed\": [\"o\",\"b\",\"k\",\"b\",\"e\",\"n\",\"m\",\"a\",\"g\",\"x\",\"g\",\"t\",\"w\",\"u\",\"b\",\"m\",\"k\",\"r\",\"x\",\"u\",\"v\",\"h\",\"x\",\"q\"], \"cost\": [95,63,97,83,95,93,81,95,100,83,63,99,97,94,45,100,38,99,18,81,39,73,92,24] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"pkluljeraiornkwyxkowpqlpeemdha\", \"target\": \"ckwzwedmdxrkbtgrhrpozwvzwijlri\", \"original\": [\"p\",\"l\",\"u\",\"e\",\"a\",\"i\",\"r\",\"n\",\"k\",\"w\",\"y\",\"x\",\"k\",\"o\",\"w\",\"p\",\"q\",\"l\",\"e\",\"e\",\"m\"], \"changed\": [\"c\",\"w\",\"z\",\"d\",\"d\",\"x\",\"k\",\"b\",\"t\",\"g\",\"r\",\"h\",\"r\",\"p\",\"o\",\"z\",\"w\",\"v\",\"w\",\"i\",\"j\"], \"cost\": [95,88,96,84,49,86,39,68,64,84,99,96,83,46,95,84,74,64,95,83,67] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"qxzlstqdqpfgswlrztsnnclfnsaajc\", \"target\": \"hgjeamofjdcawvbdmwczbctphfupgl\", \"original\": [\"q\",\"x\",\"z\",\"l\",\"s\",\"t\",\"q\",\"q\",\"p\",\"g\",\"l\",\"r\",\"z\",\"t\",\"n\",\"n\",\"f\",\"n\",\"s\",\"a\",\"a\",\"j\",\"c\"], \"changed\": [\"h\",\"g\",\"j\",\"e\",\"a\",\"m\",\"o\",\"j\",\"d\",\"a\",\"b\",\"d\",\"m\",\"w\",\"z\",\"b\",\"p\",\"h\",\"f\",\"u\",\"p\",\"g\",\"l\"], \"cost\": [91,10,86,97,98,76,100,96,97,59,95,97,67,93,84,64,55,81,97,69,99,81,81] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"sozjzrckkcytmscpjjhbkzsfgofzml\", \"target\": \"xjwgnxzbukkqwtocdtjeglsxkjhfsg\", \"original\": [\"s\",\"o\",\"z\",\"j\",\"z\",\"r\",\"k\",\"k\",\"s\",\"j\",\"j\",\"h\",\"b\",\"k\",\"z\",\"f\",\"g\",\"f\",\"z\",\"m\",\"l\"], \"changed\": [\"x\",\"j\",\"w\",\"g\",\"n\",\"x\",\"b\",\"u\",\"t\",\"d\",\"t\",\"j\",\"e\",\"g\",\"l\",\"x\",\"k\",\"h\",\"f\",\"s\",\"g\"], \"cost\": [92,100,97,100,21,93,47,100,50,44,84,84,50,90,64,83,55,75,73,42,89] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"tahngidhiduqtsaimwqhjfkoyvubhx\", \"target\": \"xsglbaliykddukogzcfpchirxnzdlp\", \"original\": [\"t\",\"a\",\"h\",\"n\",\"g\",\"i\",\"d\",\"h\",\"i\",\"d\",\"u\",\"q\",\"t\",\"s\",\"a\",\"i\",\"m\",\"w\",\"q\",\"h\",\"f\",\"k\",\"o\",\"v\",\"b\",\"h\",\"x\"], \"changed\": [\"x\",\"s\",\"g\",\"l\",\"b\",\"a\",\"l\",\"i\",\"y\",\"k\",\"d\",\"d\",\"u\",\"k\",\"o\",\"g\",\"z\",\"c\",\"f\",\"p\",\"h\",\"i\",\"r\",\"n\",\"d\",\"l\",\"p\"], \"cost\": [26,97,84,85,78,59,98,50,91,100,98,7,96,96,73,82,23,96,59,75,87,79,69,95,41,87,100] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"tqamxbehkpaapskhicnkuyyzkvjxfl\", \"target\": \"jlykiobovnobxxwnevqcluhcfmutqu\", \"original\": [\"t\",\"q\",\"a\",\"m\",\"x\",\"b\",\"e\",\"h\",\"k\",\"p\",\"p\",\"s\",\"h\",\"i\",\"n\",\"k\",\"u\",\"y\",\"y\",\"z\",\"v\",\"x\",\"l\"], \"changed\": [\"j\",\"l\",\"y\",\"k\",\"i\",\"o\",\"b\",\"o\",\"v\",\"n\",\"x\",\"x\",\"n\",\"e\",\"q\",\"c\",\"l\",\"u\",\"h\",\"c\",\"m\",\"t\",\"u\"], \"cost\": [68,73,57,37,99,81,75,93,100,88,50,93,89,96,88,85,70,36,71,77,54,65,94] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"ujdbivstmdpnnpnnpggqiwankpoyfw\", \"target\": \"grttiosznxkzeapbsjcisymwaetxcl\", \"original\": [\"u\",\"d\",\"b\",\"v\",\"t\",\"m\",\"p\",\"n\",\"n\",\"p\",\"n\",\"n\",\"p\",\"g\",\"q\",\"i\",\"w\",\"a\",\"n\",\"p\",\"o\",\"f\"], \"changed\": [\"g\",\"t\",\"t\",\"o\",\"z\",\"n\",\"k\",\"z\",\"e\",\"a\",\"p\",\"b\",\"s\",\"c\",\"i\",\"s\",\"y\",\"m\",\"w\",\"e\",\"t\",\"c\"], \"cost\": [100,99,62,99,77,64,56,90,46,94,75,99,87,90,75,83,78,49,100,87,75,20] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"wqomlunjedgsdmdmcwohbxmkeqayxa\", \"target\": \"pojjjjzfsrvrhezcdbinplekiwhllb\", \"original\": [\"w\",\"o\",\"m\",\"l\",\"u\",\"n\",\"e\",\"d\",\"d\",\"m\",\"d\",\"m\",\"c\",\"o\",\"h\",\"b\",\"x\",\"e\",\"a\",\"y\"], \"changed\": [\"p\",\"j\",\"j\",\"j\",\"j\",\"z\",\"s\",\"r\",\"h\",\"e\",\"z\",\"c\",\"d\",\"i\",\"n\",\"p\",\"l\",\"i\",\"h\",\"l\"], \"cost\": [91,91,51,66,89,97,95,89,72,58,98,65,99,63,58,42,89,79,52,42] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"yzflltfyomcnxhwfxcijnsxotwgcuy\", \"target\": \"pwdaiitmmlwdyhwpcrhcnncughvchb\", \"original\": [\"y\",\"l\",\"l\",\"f\",\"y\",\"o\",\"c\",\"n\",\"x\",\"f\",\"i\",\"j\",\"s\",\"x\",\"o\",\"t\",\"w\",\"g\",\"u\",\"y\"], \"changed\": [\"p\",\"a\",\"i\",\"t\",\"m\",\"m\",\"w\",\"d\",\"y\",\"p\",\"h\",\"c\",\"n\",\"c\",\"u\",\"g\",\"h\",\"v\",\"h\",\"b\"], \"cost\": [84,87,90,88,64,80,95,59,96,76,100,93,72,50,97,79,60,90,72,67] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"zchjedhjmkrzqkqnywdgxakcdmsdwg\", \"target\": \"cbftcpgezcgjguefrieolevyaadkgb\", \"original\": [\"z\",\"c\",\"h\",\"j\",\"e\",\"m\",\"k\",\"r\",\"z\",\"q\",\"k\",\"q\",\"n\",\"y\",\"w\",\"d\",\"x\",\"k\",\"c\",\"m\",\"s\",\"d\",\"w\",\"g\"], \"changed\": [\"c\",\"b\",\"f\",\"t\",\"c\",\"z\",\"c\",\"g\",\"j\",\"g\",\"u\",\"e\",\"f\",\"r\",\"i\",\"e\",\"l\",\"v\",\"y\",\"a\",\"d\",\"k\",\"g\",\"b\"], \"cost\": [57,94,71,85,53,96,97,43,93,65,76,93,94,100,81,85,62,100,34,99,95,85,77,68] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"zpxcysgujcbbcgbqqofookukkotwij\", \"target\": \"dfxsvtmexhdnfhbdrcdgqlajddteph\", \"original\": [\"z\",\"s\",\"g\",\"u\",\"j\",\"c\",\"g\",\"q\",\"o\",\"f\",\"k\",\"u\",\"k\",\"o\",\"w\",\"j\"], \"changed\": [\"d\",\"t\",\"m\",\"e\",\"x\",\"f\",\"h\",\"r\",\"c\",\"d\",\"l\",\"a\",\"j\",\"d\",\"e\",\"h\"], \"cost\": [75,28,71,70,92,88,82,82,80,91,97,93,77,14,68,75] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"bavusatavvvuubavsauavubtusubsvtsvsbttbvs\", \"target\": \"ssauttbvssatusutusbattuttsutabubutuasvuu\", \"original\": [\"b\",\"a\",\"v\",\"s\",\"t\",\"a\",\"v\",\"a\",\"v\",\"s\",\"u\",\"u\",\"b\",\"s\",\"v\",\"t\",\"s\",\"b\",\"t\",\"b\"], \"changed\": [\"s\",\"s\",\"a\",\"t\",\"b\",\"v\",\"s\",\"u\",\"t\",\"u\",\"b\",\"t\",\"t\",\"a\",\"b\",\"u\",\"b\",\"u\",\"a\",\"v\"], \"cost\": [948,467,690,969,300,877,924,924,791,724,809,652,388,592,772,829,912,679,751,529] }\nassert my_solution.minimumCost(**test_input) == 27579\n\ntest_input = { \"source\": \"bbvstvuatvbasbbsvsuvvuvvauutttvtsuavsvua\", \"target\": \"buvbtutbsbuttbtvabbuvubvbvabsbattutvbvvu\", \"original\": [\"b\",\"s\",\"v\",\"u\",\"a\",\"t\",\"v\",\"a\",\"s\",\"u\",\"u\",\"u\",\"t\",\"v\",\"a\"], \"changed\": [\"u\",\"b\",\"u\",\"t\",\"b\",\"s\",\"b\",\"t\",\"v\",\"b\",\"v\",\"a\",\"b\",\"a\",\"u\"], \"cost\": [795,956,694,238,665,894,519,867,887,715,845,16,942,429,282] }\nassert my_solution.minimumCost(**test_input) == 22249\n\ntest_input = { \"source\": \"busbsusauusbbasssutaauttavbbabtbustvubtv\", \"target\": \"vuabutaustubbbsbabbusavsttbtubavsabuvvbt\", \"original\": [\"b\",\"s\",\"u\",\"s\",\"a\",\"u\",\"s\",\"t\",\"a\",\"u\",\"t\",\"t\",\"v\",\"b\",\"v\"], \"changed\": [\"v\",\"u\",\"t\",\"a\",\"u\",\"s\",\"b\",\"b\",\"s\",\"a\",\"v\",\"s\",\"t\",\"t\",\"u\"], \"cost\": [927,992,291,999,989,996,318,196,155,948,375,845,960,949,250] }\nassert my_solution.minimumCost(**test_input) == 24291\n\ntest_input = { \"source\": \"buuasstsvvvvtsaavstbvubtbstbussbavsvvvbt\", \"target\": \"utsabasvssauvuvavvbstbbaauvvvtvtbastatua\", \"original\": [\"b\",\"u\",\"u\",\"s\",\"s\",\"v\",\"v\",\"t\",\"b\",\"u\",\"b\",\"s\",\"t\",\"b\",\"u\",\"b\",\"a\",\"v\"], \"changed\": [\"u\",\"t\",\"s\",\"b\",\"v\",\"s\",\"a\",\"b\",\"s\",\"b\",\"a\",\"u\",\"v\",\"v\",\"v\",\"t\",\"b\",\"t\"], \"cost\": [935,827,806,951,298,554,896,852,759,853,530,891,942,944,464,952,882,887] }\nassert my_solution.minimumCost(**test_input) == 31617\n\ntest_input = { \"source\": \"bvbsstasaabvubbaabvbsbsttuvvuutsabbaubau\", \"target\": \"sbuutvuttaubsbbsaatbvsbtsvutuutvtabaubat\", \"original\": [\"b\",\"b\",\"s\",\"t\",\"a\",\"u\",\"a\",\"v\",\"s\",\"s\",\"v\"], \"changed\": [\"s\",\"u\",\"t\",\"v\",\"u\",\"s\",\"s\",\"t\",\"v\",\"b\",\"u\"], \"cost\": [985,604,940,913,910,765,729,905,848,793,468] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"satuaabaavaauussvsvssavtuuvbttassbtususv\", \"target\": \"ababsttvsabvuvaatuvtsvtsasbaatavuauvvstv\", \"original\": [\"s\",\"u\",\"a\",\"a\",\"a\",\"v\",\"a\",\"u\",\"s\",\"s\",\"v\",\"t\",\"u\",\"u\",\"v\",\"b\",\"t\",\"s\",\"t\"], \"changed\": [\"a\",\"b\",\"s\",\"t\",\"v\",\"a\",\"b\",\"v\",\"u\",\"t\",\"t\",\"s\",\"a\",\"s\",\"b\",\"a\",\"a\",\"v\",\"u\"], \"cost\": [848,908,555,510,759,404,799,963,855,901,609,854,878,915,879,594,748,937,942] }\nassert my_solution.minimumCost(**test_input) == 27052\n\ntest_input = { \"source\": \"sauaavvasvsatabbvuusvatsabssavvtsbvuusva\", \"target\": \"abtuuvutubsbbtuttbtubbasuaustsbssatubsvb\", \"original\": [\"s\",\"a\",\"a\",\"a\",\"v\",\"t\",\"b\",\"b\",\"v\",\"u\",\"u\",\"s\",\"t\",\"b\",\"v\",\"t\"], \"changed\": [\"a\",\"b\",\"u\",\"t\",\"b\",\"b\",\"u\",\"t\",\"t\",\"b\",\"t\",\"u\",\"a\",\"a\",\"s\",\"s\"], \"cost\": [689,325,535,931,528,722,965,786,645,499,791,717,557,988,229,834] }\nassert my_solution.minimumCost(**test_input) == 21007\n\ntest_input = { \"source\": \"ssautbbbuattvtutbavabtbvbusbsbaavutvbutu\", \"target\": \"svbvuttvtbtvuavbvtstutuvutvbasbauvabsvvv\", \"original\": [\"s\",\"a\",\"b\",\"u\",\"t\",\"v\",\"t\",\"u\",\"b\",\"a\",\"b\",\"v\",\"b\"], \"changed\": [\"v\",\"b\",\"t\",\"t\",\"v\",\"u\",\"a\",\"v\",\"v\",\"t\",\"u\",\"b\",\"s\"], \"cost\": [943,915,778,641,540,872,999,856,979,848,856,935,677] }\nassert my_solution.minimumCost(**test_input) == 33036\n\ntest_input = { \"source\": \"sstsvvvvvabubtvsvaatsavssbatstbbabbtbvvt\", \"target\": \"tattabsubsatbtbbbussususassautbabsbvabvu\", \"original\": [\"s\",\"s\",\"v\",\"v\",\"v\",\"v\",\"a\",\"b\",\"s\",\"a\",\"t\",\"s\",\"t\",\"a\",\"b\",\"t\",\"t\"], \"changed\": [\"t\",\"a\",\"a\",\"b\",\"s\",\"u\",\"s\",\"a\",\"b\",\"u\",\"s\",\"u\",\"a\",\"b\",\"s\",\"v\",\"u\"], \"cost\": [723,861,682,949,830,969,880,892,750,461,870,592,233,718,967,621,472] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"ssuuavtuuutubutvtssbasssvttuvuubbabubvsu\", \"target\": \"ustbvvsutaasabtasabuaasuatuaabatubsbtvbt\", \"original\": [\"s\",\"u\",\"u\",\"a\",\"t\",\"u\",\"b\",\"s\",\"b\",\"t\",\"u\",\"v\",\"b\",\"a\",\"b\",\"s\"], \"changed\": [\"u\",\"t\",\"b\",\"v\",\"a\",\"s\",\"a\",\"a\",\"u\",\"u\",\"a\",\"a\",\"t\",\"b\",\"s\",\"b\"], \"cost\": [709,599,774,993,858,730,987,700,596,200,984,567,656,971,777,790] }\nassert my_solution.minimumCost(**test_input) == 23824\n\ntest_input = { \"source\": \"suvsavbasssavasvvbttubvbvatbstbabsutvuua\", \"target\": \"aaavasusvsatsuvuatbsstbvstuatttuuvubavau\", \"original\": [\"s\",\"v\",\"b\",\"a\",\"s\",\"a\",\"t\",\"t\",\"u\",\"b\",\"v\",\"b\",\"b\",\"s\",\"a\",\"u\",\"u\"], \"changed\": [\"v\",\"s\",\"u\",\"s\",\"a\",\"t\",\"b\",\"s\",\"s\",\"t\",\"b\",\"v\",\"a\",\"t\",\"u\",\"v\",\"a\"], \"cost\": [944,923,845,911,686,687,403,705,378,929,315,296,484,666,354,375,649] }\nassert my_solution.minimumCost(**test_input) == 25662\n\ntest_input = { \"source\": \"tavauavbtsuuubtbuaatsbutvastasaavbtbsubs\", \"target\": \"stsautbvvtbuvvtstaaubavvuaabubavsvbasvvb\", \"original\": [\"t\",\"a\",\"v\",\"v\",\"s\",\"u\",\"b\",\"b\",\"u\",\"t\",\"s\",\"b\",\"u\",\"t\",\"v\",\"s\",\"t\",\"a\"], \"changed\": [\"s\",\"t\",\"s\",\"b\",\"t\",\"b\",\"v\",\"s\",\"t\",\"u\",\"b\",\"a\",\"v\",\"v\",\"u\",\"a\",\"b\",\"u\"], \"cost\": [936,867,711,886,565,650,500,694,394,662,948,878,864,993,925,508,714,815] }\nassert my_solution.minimumCost(**test_input) == 24476\n\ntest_input = { \"source\": \"tbsttbstvtvusvbaavuuuvvuavuuusbusabsubta\", \"target\": \"uvvbttvbvtbtausvtavsuavusvusuabuvtutttas\", \"original\": [\"t\",\"b\",\"s\",\"u\",\"v\",\"a\",\"a\",\"v\",\"u\",\"u\",\"a\",\"s\",\"b\",\"s\",\"b\",\"t\"], \"changed\": [\"u\",\"v\",\"v\",\"t\",\"u\",\"v\",\"t\",\"a\",\"v\",\"s\",\"s\",\"a\",\"u\",\"t\",\"t\",\"a\"], \"cost\": [409,241,815,861,536,968,983,726,882,674,981,516,918,653,368,845] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"tsauvattvvavaasbutvuavvvttuvasavbvavtsaa\", \"target\": \"vbtsubbbbbavvvbsvstavasaaaatsattvbtubsvs\", \"original\": [\"t\",\"s\",\"u\",\"a\",\"t\",\"v\",\"a\",\"b\",\"u\",\"v\",\"u\",\"v\",\"v\",\"t\",\"a\",\"a\",\"b\"], \"changed\": [\"v\",\"b\",\"s\",\"b\",\"b\",\"b\",\"v\",\"s\",\"v\",\"t\",\"a\",\"a\",\"s\",\"a\",\"s\",\"t\",\"v\"], \"cost\": [731,965,614,651,952,991,940,606,664,261,468,295,202,675,921,628,690] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"tsvsstututatsbvatauatsausaubsuuassssbuts\", \"target\": \"assutuavuvusbubbtavsavbvusvbvtbubvvuvtvb\", \"original\": [\"t\",\"v\",\"s\",\"s\",\"t\",\"u\",\"t\",\"a\",\"s\",\"b\",\"v\",\"a\",\"s\",\"u\",\"a\",\"u\",\"u\",\"b\"], \"changed\": [\"a\",\"s\",\"u\",\"t\",\"u\",\"a\",\"v\",\"u\",\"b\",\"u\",\"b\",\"b\",\"v\",\"v\",\"s\",\"t\",\"b\",\"v\"], \"cost\": [924,489,946,903,425,474,965,605,168,870,992,903,367,995,425,580,918,991] }\nassert my_solution.minimumCost(**test_input) == 23945\n\ntest_input = { \"source\": \"ttuvauavausttvusavuvsuababtubbbvvsttbasv\", \"target\": \"butttussvtvbbtbtasuusstattuvvvuavbtsbttu\", \"original\": [\"t\",\"t\",\"u\",\"a\",\"a\",\"u\",\"s\",\"v\",\"v\",\"u\",\"a\",\"b\",\"b\",\"u\",\"b\",\"b\",\"v\",\"s\",\"t\"], \"changed\": [\"b\",\"u\",\"t\",\"s\",\"v\",\"b\",\"t\",\"s\",\"u\",\"s\",\"t\",\"a\",\"t\",\"v\",\"v\",\"u\",\"a\",\"b\",\"s\"], \"cost\": [790,396,583,83,931,950,760,364,698,503,957,984,611,688,1000,986,679,913,906] }\nassert my_solution.minimumCost(**test_input) == 25663\n\ntest_input = { \"source\": \"tuasbutsuubbvauvautsbtabsaaauubbvaavtuua\", \"target\": \"tvauvutvbbavuatsbaatvtbavatavtsvttttuvta\", \"original\": [\"u\",\"s\",\"b\",\"u\",\"v\",\"u\",\"v\",\"a\",\"u\",\"t\",\"b\",\"s\",\"a\",\"b\",\"v\",\"t\"], \"changed\": [\"v\",\"u\",\"v\",\"b\",\"u\",\"t\",\"s\",\"b\",\"a\",\"a\",\"a\",\"v\",\"t\",\"s\",\"t\",\"u\"], \"cost\": [958,880,986,571,311,294,673,433,733,984,444,576,666,847,516,866] }\nassert my_solution.minimumCost(**test_input) == 21164\n\ntest_input = { \"source\": \"tvsbbttvsvubbtasvbusataaatautauavvstsbub\", \"target\": \"tbttvaavutvbstvutavavtbuvtuabsubsuvbtusa\", \"original\": [\"v\",\"b\",\"s\",\"u\",\"b\",\"v\",\"s\",\"a\",\"a\",\"a\",\"u\",\"t\",\"v\",\"v\",\"s\",\"s\",\"u\",\"b\"], \"changed\": [\"b\",\"v\",\"u\",\"v\",\"s\",\"t\",\"a\",\"v\",\"b\",\"u\",\"a\",\"b\",\"s\",\"u\",\"v\",\"t\",\"s\",\"a\"], \"cost\": [977,323,878,825,625,908,794,831,973,881,946,981,437,904,564,826,720,583] }\nassert my_solution.minimumCost(**test_input) == 29347\n\ntest_input = { \"source\": \"uatavuaavatstabvtvabbbuvatvabbauvsvtauuu\", \"target\": \"ustbbuvbtusutuutvsuttbuubuuubasvubuubusb\", \"original\": [\"a\",\"a\",\"v\",\"a\",\"v\",\"a\",\"t\",\"b\",\"t\",\"b\",\"v\",\"t\",\"s\",\"u\",\"u\"], \"changed\": [\"s\",\"b\",\"b\",\"v\",\"t\",\"u\",\"s\",\"u\",\"v\",\"t\",\"u\",\"u\",\"b\",\"s\",\"b\"], \"cost\": [681,801,894,221,732,732,984,989,750,705,181,993,888,957,912] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"ubvtusbavavtbssuutvsvasttbauvtvttsvtttss\", \"target\": \"usasbvasuttsbvvuuvvtubssuuuuvuvubtsbsstu\", \"original\": [\"b\",\"t\",\"a\",\"v\",\"a\",\"s\",\"s\",\"t\",\"b\",\"a\",\"t\",\"v\",\"s\"], \"changed\": [\"s\",\"s\",\"s\",\"u\",\"t\",\"v\",\"t\",\"u\",\"u\",\"u\",\"b\",\"s\",\"u\"], \"cost\": [933,864,772,686,918,885,923,892,538,120,913,892,441] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"ubvuasvuvuavasvvasausabbtausaaubbvbtuubv\", \"target\": \"sbbutubbvtvauatbavstvbttavbubvsvsutuavta\", \"original\": [\"u\",\"v\",\"a\",\"s\",\"u\",\"a\",\"v\",\"a\",\"s\",\"s\",\"a\",\"a\",\"b\",\"b\",\"u\",\"u\"], \"changed\": [\"s\",\"b\",\"t\",\"u\",\"b\",\"v\",\"a\",\"u\",\"a\",\"v\",\"s\",\"b\",\"t\",\"s\",\"a\",\"v\"], \"cost\": [951,655,564,597,402,910,850,664,352,937,698,281,997,798,368,963] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"utauutasstbuubsussstaauatvaavuuabvvbvaba\", \"target\": \"vttavbbbvbbbvuaavauubbsavaststtatsbssaab\", \"original\": [\"a\",\"u\",\"t\",\"a\",\"s\",\"s\",\"s\",\"t\",\"v\",\"a\",\"u\",\"b\",\"v\",\"b\",\"v\",\"b\"], \"changed\": [\"t\",\"a\",\"b\",\"b\",\"b\",\"a\",\"v\",\"v\",\"a\",\"s\",\"t\",\"t\",\"b\",\"s\",\"s\",\"a\"], \"cost\": [862,888,579,525,903,443,828,892,953,879,855,705,961,438,478,998] }\nassert my_solution.minimumCost(**test_input) == -1\n\ntest_input = { \"source\": \"uttbbsvttssubvbbaabsavaabvsvbbbbbatvbtsu\", \"target\": \"tatsstaubbtbvsabvasbubvvbutasssvttuvvtvs\", \"original\": [\"u\",\"t\",\"b\",\"s\",\"v\",\"t\",\"t\",\"u\",\"b\",\"v\",\"b\",\"a\",\"s\",\"v\",\"v\",\"b\",\"a\",\"s\",\"u\"], \"changed\": [\"t\",\"a\",\"s\",\"t\",\"a\",\"u\",\"b\",\"b\",\"v\",\"s\",\"a\",\"v\",\"b\",\"b\",\"u\",\"t\",\"t\",\"v\",\"s\"], \"cost\": [880,822,798,549,420,189,730,621,865,189,950,921,887,816,772,69,907,868,715] }\nassert my_solution.minimumCost(**test_input) == 23971\n\ntest_input = { \"source\": \"utvsausubbtuasvtuttatbtasuvbtuuubsatabau\", \"target\": \"tstsatsbsttaatasbvvsabbabbtabtvbvuaavaau\", \"original\": [\"u\",\"b\",\"b\",\"u\",\"s\",\"v\",\"u\",\"t\",\"a\",\"t\",\"s\",\"b\",\"u\",\"b\",\"s\",\"a\"], \"changed\": [\"t\",\"s\",\"t\",\"a\",\"t\",\"a\",\"b\",\"v\",\"s\",\"a\",\"b\",\"a\",\"v\",\"v\",\"u\",\"v\"], \"cost\": [425,837,948,892,923,403,619,690,775,951,577,1000,816,999,602,800] }\nassert my_solution.minimumCost(**test_input) == 29865\n\ntest_input = { \"source\": \"uvtavsbvvvvavsstavustttuuvvavatattbavttv\", \"target\": \"vvbuuutbtvbtutatuttvsssvtvsbbvbbvuausavu\", \"original\": [\"t\",\"a\",\"v\",\"s\",\"b\",\"v\",\"v\",\"a\",\"s\",\"s\",\"u\",\"s\",\"t\",\"u\",\"v\",\"a\",\"t\",\"t\",\"b\"], \"changed\": [\"b\",\"u\",\"u\",\"u\",\"t\",\"b\",\"t\",\"t\",\"t\",\"a\",\"t\",\"v\",\"s\",\"v\",\"s\",\"b\",\"v\",\"u\",\"a\"], \"cost\": [984,969,379,449,842,818,399,954,718,823,932,935,405,591,643,965,1000,700,189] }\nassert my_solution.minimumCost(**test_input) == 27084\n\ntest_input = { \"source\": \"vabsuaavabatbastaauaaaututtutsvuusatavas\", \"target\": \"svubbsaavaubbbvasatssvvubtsssabsabsbstau\", \"original\": [\"a\",\"s\",\"u\",\"a\",\"v\",\"b\",\"a\",\"s\",\"t\",\"u\",\"u\",\"t\",\"u\",\"t\",\"s\",\"v\",\"u\",\"t\",\"v\",\"s\"], \"changed\": [\"v\",\"b\",\"b\",\"s\",\"a\",\"a\",\"u\",\"v\",\"a\",\"t\",\"v\",\"u\",\"s\",\"s\",\"a\",\"b\",\"a\",\"b\",\"t\",\"u\"], \"cost\": [948,531,696,662,908,460,829,859,857,374,1000,996,356,810,804,751,988,815,933,924] }\nassert my_solution.minimumCost(**test_input) == 27967\n\ntest_input = { \"source\": \"vsvstbbutastuuaubuausuuavvttvabvsaavbtvs\", \"target\": \"vbbtbuatasbauavbbabbbvbutaavsvtubvbuttst\", \"original\": [\"s\",\"v\",\"s\",\"t\",\"b\",\"b\",\"u\",\"a\",\"t\",\"u\",\"a\",\"u\",\"a\",\"u\",\"a\",\"v\",\"v\",\"b\",\"v\"], \"changed\": [\"b\",\"b\",\"t\",\"b\",\"u\",\"a\",\"t\",\"s\",\"a\",\"a\",\"v\",\"b\",\"b\",\"v\",\"u\",\"t\",\"s\",\"t\",\"u\"], \"cost\": [510,990,975,894,921,775,819,665,76,509,943,691,757,617,773,404,777,932,837] }\nassert my_solution.minimumCost(**test_input) == 25040\n\ntest_input = { \"source\": \"vusbbaubbusbbtusttbtavsavbbbausavbausbub\", \"target\": \"uvvbsututvavautuatuussbbttbaaaasbbuvavaa\", \"original\": [\"u\",\"b\",\"a\",\"u\",\"b\",\"b\",\"s\",\"b\",\"b\",\"t\",\"t\",\"s\",\"a\",\"v\",\"u\",\"a\",\"v\"], \"changed\": [\"v\",\"s\",\"u\",\"t\",\"u\",\"t\",\"a\",\"v\",\"a\",\"u\",\"a\",\"b\",\"b\",\"t\",\"a\",\"s\",\"b\"], \"cost\": [555,920,950,949,936,35,455,910,746,791,661,864,926,11,833,870,854] }\nassert my_solution.minimumCost(**test_input) == 26439\n\ntest_input = { \"source\": \"vvabsutautvsutvavtsvstabvbvtutbvuautaatb\", \"target\": \"taasvsstbstasbtuauvtbtusbssbbssbuusuvbbu\", \"original\": [\"v\",\"b\",\"s\",\"u\",\"t\",\"u\",\"v\",\"t\",\"a\",\"t\",\"s\",\"v\",\"v\",\"a\"], \"changed\": [\"a\",\"s\",\"v\",\"s\",\"s\",\"b\",\"t\",\"b\",\"u\",\"u\",\"b\",\"s\",\"b\",\"b\"], \"cost\": [813,860,971,768,419,950,866,741,989,756,325,806,507,571] }\nassert my_solution.minimumCost(**test_input) == 36258\n\ntest_input = { \"source\": \"vvvsaavtavaabtssasstbvuusbubbbsastvttbba\", \"target\": \"utssutvbabttvstsbbusttuuutvvbtasvuvbvvav\", \"original\": [\"v\",\"a\",\"a\",\"v\",\"b\",\"t\",\"s\",\"a\",\"s\",\"b\",\"s\",\"u\",\"s\",\"a\",\"s\",\"t\",\"t\",\"b\",\"a\"], \"changed\": [\"t\",\"u\",\"t\",\"b\",\"v\",\"s\",\"t\",\"b\",\"b\",\"t\",\"u\",\"v\",\"a\",\"s\",\"v\",\"b\",\"v\",\"a\",\"v\"], \"cost\": [722,823,981,465,482,999,572,191,410,968,377,549,658,692,898,263,928,197,831] }\nassert my_solution.minimumCost(**test_input) == 22953\n\ntest_input = { \"source\": \"asmlmoumomvummakmlbabvmvvavlavtsvbvssuumsllttsusts\", \"target\": \"asmlmoumomvummakmlbabvmvvaolklllvbsltuomkslvmmusts\", \"original\": [\"vlavtsvbvssuumslltts\",\"mtmubkasuvumkobbmsmo\",\"vsbbvauauvuvsauaastl\",\"uovumoluksslvkvlkmam\",\"smsvsuubusskmublvvst\",\"momuatbkubosmmavvssk\",\"mommltotttbtvlvalsbt\",\"vbbbuvslutblvvkvtmmo\",\"boaosasttvtvtabtubab\",\"mbtkumblvbasoobaauvm\",\"vbotklaoltambktlulot\",\"vluamsokkbaalsmmalav\",\"mttmbuosbmlttabmbabl\",\"sskvkbmlabaulluomovt\",\"lstbuomkaoatmavsmvml\"], \"changed\": [\"mtmubkasuvumkobbmsmo\",\"vsbbvauauvuvsauaastl\",\"uovumoluksslvkvlkmam\",\"smsvsuubusskmublvvst\",\"momuatbkubosmmavvssk\",\"mommltotttbtvlvalsbt\",\"vbbbuvslutblvvkvtmmo\",\"boaosasttvtvtabtubab\",\"mbtkumblvbasoobaauvm\",\"vbotklaoltambktlulot\",\"vluamsokkbaalsmmalav\",\"mttmbuosbmlttabmbabl\",\"sskvkbmlabaulluomovt\",\"lstbuomkaoatmavsmvml\",\"olklllvbsltuomkslvmm\"], \"cost\": [9758,7133,9355,8885,6055,7360,9168,9288,7422,6995,8167,6154,6939,6343,9733] }\nassert my_solution.minimumCost(**test_input) == 118755\n\ntest_input = { \"source\": \"bkmltoaakmatkvllubamuvbmkolamvolsaottsokbmutktsvlo\", \"target\": \"skmltoaakmatkvllubamuvbmkolamvolsosuataatovmktsvlo\", \"original\": [\"aottsokbmut\",\"ktuumtblakk\",\"mkumbambakt\",\"tubtvmuuoat\",\"kkkksosllks\",\"sastauoammb\",\"sbomolbklsk\",\"kaabakosmsb\",\"ltaltkmukoa\",\"lmlaovmluta\",\"kusalltssaa\",\"mattouslbou\",\"obaavmovsal\",\"bk\",\"ko\"], \"changed\": [\"ktuumtblakk\",\"mkumbambakt\",\"tubtvmuuoat\",\"kkkksosllks\",\"sastauoammb\",\"sbomolbklsk\",\"kaabakosmsb\",\"ltaltkmukoa\",\"lmlaovmluta\",\"kusalltssaa\",\"mattouslbou\",\"obaavmovsal\",\"osuataatovm\",\"ko\",\"sk\"], \"cost\": [5819,9018,7484,6655,5163,5728,3077,7032,4630,8093,6974,5623,9179,7307,9974] }\nassert my_solution.minimumCost(**test_input) == 101756\n\ntest_input = { \"source\": \"blvalvmkosattusaubkbuvusmoolmkloavaskmkbovkkbvtaas\", \"target\": \"blvalvmkosattlooutkvsmabuvaumkloavaskmkbovkkbvtaas\", \"original\": [\"usaubkbuvusmoolm\",\"stvkuuablkvlvbuv\",\"laosbokmbsusulta\",\"tosusvtstuousmtv\",\"tkbbalmtoubtmlvk\",\"vauvllvbootbvtsv\",\"malabvmoaavulomv\",\"ootsoksuosvlakov\",\"alaobmvbttmtobvl\",\"oauamtksvbuovmbt\",\"ubtlssmbbaloatsa\",\"sstskkmtkoobaavt\",\"avsskubbbtossbsu\",\"aumbsbautvkmsauu\",\"btsuvmosbtomvmma\"], \"changed\": [\"stvkuuablkvlvbuv\",\"laosbokmbsusulta\",\"tosusvtstuousmtv\",\"tkbbalmtoubtmlvk\",\"vauvllvbootbvtsv\",\"malabvmoaavulomv\",\"ootsoksuosvlakov\",\"alaobmvbttmtobvl\",\"oauamtksvbuovmbt\",\"ubtlssmbbaloatsa\",\"sstskkmtkoobaavt\",\"avsskubbbtossbsu\",\"aumbsbautvkmsauu\",\"btsuvmosbtomvmma\",\"looutkvsmabuvaum\"], \"cost\": [8903,5338,8835,8645,8789,7933,8044,3865,7564,5782,9245,9165,8886,7691,8039] }\nassert my_solution.minimumCost(**test_input) == 116724\n\ntest_input = { \"source\": \"mobbmmmsabbomsbukkotbttvsuoubtvuabaktsuoltvamlltbv\", \"target\": \"mobbmmmsauotksusvmvtbmaovtsvtaklabaktsuoltbamtumtl\", \"original\": [\"bbomsbukkotbttvsuoubtvua\",\"sbuastublskotvtotmokuota\",\"kssvtltakbtmlbmtoskaousb\",\"vuososkmtvsobkbvuvbklvbv\",\"vtsvllsklslkbulusbuastlm\",\"bttokabvovvktkavatskoamt\",\"lbmobulvomkovaalbtkoukso\",\"tmmlusaokamvstsmuksmbulu\",\"lkktooukbstvkumvbbsllaas\",\"mbvtkltbvuumuvobstooammv\",\"skovmvassobkbutolttvkokb\",\"olastbtotmlusbmlukmokubl\",\"kvbomsvuaskvkvvmssavubtt\",\"buusuklobuoukatusulotmks\",\"vamlltbv\"], \"changed\": [\"sbuastublskotvtotmokuota\",\"kssvtltakbtmlbmtoskaousb\",\"vuososkmtvsobkbvuvbklvbv\",\"vtsvllsklslkbulusbuastlm\",\"bttokabvovvktkavatskoamt\",\"lbmobulvomkovaalbtkoukso\",\"tmmlusaokamvstsmuksmbulu\",\"lkktooukbstvkumvbbsllaas\",\"mbvtkltbvuumuvobstooammv\",\"skovmvassobkbutolttvkokb\",\"olastbtotmlusbmlukmokubl\",\"kvbomsvuaskvkvvmssavubtt\",\"buusuklobuoukatusulotmks\",\"uotksusvmvtbmaovtsvtakla\",\"bamtumtl\"], \"cost\": [8432,9912,7958,9938,8402,7223,5772,9501,8749,8597,6195,7504,7103,9582,8898] }\nassert my_solution.minimumCost(**test_input) == 123766", "start_time": 1703385000} +{"task_id": "biweekly-contest-120-count-the-number-of-incremovable-subarrays-i", "url": "https://leetcode.com/problems/count-the-number-of-incremovable-subarrays-i", "title": "count-the-number-of-incremovable-subarrays-i", "meta": {"questionId": "3252", "questionFrontendId": "2970", "title": "Count the Number of Incremovable Subarrays I", "titleSlug": "count-the-number-of-incremovable-subarrays-i", "isPaidOnly": false, "difficulty": "Easy", "likes": 38, "dislikes": 49, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed array of positive integers nums.\nA subarray of nums is called incremovable if nums becomes strictly increasing on removing the subarray. For example, the subarray [3, 4] is an incremovable subarray of [5, 3, 4, 6, 7] because removing this subarray changes the array [5, 3, 4, 6, 7] to [5, 6, 7] which is strictly increasing.\nReturn the total number of incremovable subarrays of nums.\nNote that an empty array is considered strictly increasing.\nA subarray is a contiguous non-empty sequence of elements within an array.\n\nExample 1:\n\nInput: nums = [1,2,3,4]\nOutput: 10\nExplanation: The 10 incremovable subarrays are: [1], [2], [3], [4], [1,2], [2,3], [3,4], [1,2,3], [2,3,4], and [1,2,3,4], because on removing any one of these subarrays nums becomes strictly increasing. Note that you cannot select an empty subarray.\n\nExample 2:\n\nInput: nums = [6,5,7,8]\nOutput: 7\nExplanation: The 7 incremovable subarrays are: [5], [6], [5,7], [6,5], [5,7,8], [6,5,7] and [6,5,7,8].\nIt can be shown that there are only 7 incremovable subarrays in nums.\n\nExample 3:\n\nInput: nums = [8,7,6,6]\nOutput: 3\nExplanation: The 3 incremovable subarrays are: [8,7,6], [7,6,6], and [8,7,6,6]. Note that [8,7] is not an incremovable subarray because after removing [8,7] nums becomes [6,6], which is sorted in ascending order but not strictly increasing.\n\n\nConstraints:\n\n1 <= nums.length <= 50\n1 <= nums[i] <= 50\n\"\"\"\nclass Solution:\n def incremovableSubarrayCount(self, nums: List[int]) -> int:\n ", "prompt_sft": "You are given a 0-indexed array of positive integers nums.\nA subarray of nums is called incremovable if nums becomes strictly increasing on removing the subarray. For example, the subarray [3, 4] is an incremovable subarray of [5, 3, 4, 6, 7] because removing this subarray changes the array [5, 3, 4, 6, 7] to [5, 6, 7] which is strictly increasing.\nReturn the total number of incremovable subarrays of nums.\nNote that an empty array is considered strictly increasing.\nA subarray is a contiguous non-empty sequence of elements within an array.\n\nExample 1:\n\nInput: nums = [1,2,3,4]\nOutput: 10\nExplanation: The 10 incremovable subarrays are: [1], [2], [3], [4], [1,2], [2,3], [3,4], [1,2,3], [2,3,4], and [1,2,3,4], because on removing any one of these subarrays nums becomes strictly increasing. Note that you cannot select an empty subarray.\n\nExample 2:\n\nInput: nums = [6,5,7,8]\nOutput: 7\nExplanation: The 7 incremovable subarrays are: [5], [6], [5,7], [6,5], [5,7,8], [6,5,7] and [6,5,7,8].\nIt can be shown that there are only 7 incremovable subarrays in nums.\n\nExample 3:\n\nInput: nums = [8,7,6,6]\nOutput: 3\nExplanation: The 3 incremovable subarrays are: [8,7,6], [7,6,6], and [8,7,6,6]. Note that [8,7] is not an incremovable subarray because after removing [8,7] nums becomes [6,6], which is sorted in ascending order but not strictly increasing.\n\n\nConstraints:\n\n1 <= nums.length <= 50\n1 <= nums[i] <= 50\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def incremovableSubarrayCount(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,2,3,4] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 10\n\ntest_input = { \"nums\": [6,5,7,8] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 7\n\ntest_input = { \"nums\": [8,7,6,6] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [1] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 1\n\ntest_input = { \"nums\": [2] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 1\n\ntest_input = { \"nums\": [3] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 1\n\ntest_input = { \"nums\": [4] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 1\n\ntest_input = { \"nums\": [5] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 1\n\ntest_input = { \"nums\": [6] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 1\n\ntest_input = { \"nums\": [7] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 1\n\ntest_input = { \"nums\": [8] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 1\n\ntest_input = { \"nums\": [9] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 1\n\ntest_input = { \"nums\": [10] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 1\n\ntest_input = { \"nums\": [1,2] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [1,4] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [1,8] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [2,10] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [3,4] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [3,8] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [3,10] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [4,2] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [4,3] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [4,5] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [5,1] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [5,4] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [5,6] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [5,7] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [5,9] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [6,4] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [6,5] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [6,9] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [9,3] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [9,4] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [9,7] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [9,8] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [10,5] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [10,10] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,3] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 6\n\ntest_input = { \"nums\": [1,2,6] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 6\n\ntest_input = { \"nums\": [2,1,6] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 5\n\ntest_input = { \"nums\": [2,4,5] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 6\n\ntest_input = { \"nums\": [2,6,8] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 6\n\ntest_input = { \"nums\": [2,6,9] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 6\n\ntest_input = { \"nums\": [2,10,9] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 5\n\ntest_input = { \"nums\": [3,1,9] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 5\n\ntest_input = { \"nums\": [3,5,9] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 6\n\ntest_input = { \"nums\": [3,7,2] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [3,8,8] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 5\n\ntest_input = { \"nums\": [3,10,10] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 5\n\ntest_input = { \"nums\": [4,5,2] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [5,8,4] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [5,9,3] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [5,9,7] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 5\n\ntest_input = { \"nums\": [6,7,4] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [8,7,4] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [8,7,5] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [8,9,5] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [9,2,5] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [9,5,2] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [9,6,9] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [9,9,4] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [10,7,4] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [10,10,6] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [2,1,1,4] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 5\n\ntest_input = { \"nums\": [2,5,7,9] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 10\n\ntest_input = { \"nums\": [3,5,3,5] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 6\n\ntest_input = { \"nums\": [3,7,10,6] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 6\n\ntest_input = { \"nums\": [3,8,3,8] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 6\n\ntest_input = { \"nums\": [4,1,3,7] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 6\n\ntest_input = { \"nums\": [4,3,5,1] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [4,3,7,5] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [4,8,7,6] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 5\n\ntest_input = { \"nums\": [4,9,10,6] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 6\n\ntest_input = { \"nums\": [5,4,3,8] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 5\n\ntest_input = { \"nums\": [5,5,9,5] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [5,10,10,9] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 5\n\ntest_input = { \"nums\": [6,4,4,9] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 5\n\ntest_input = { \"nums\": [6,5,2,10] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 5\n\ntest_input = { \"nums\": [7,3,2,3] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [7,5,1,10] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 5\n\ntest_input = { \"nums\": [7,9,7,2] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [7,9,8,8] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 5\n\ntest_input = { \"nums\": [7,10,4,3] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [8,8,1,7] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [9,2,8,7] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [10,5,9,5] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [10,7,2,8] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [10,9,1,3] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [1,1,4,4,7] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 6\n\ntest_input = { \"nums\": [1,2,3,4,5] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 15\n\ntest_input = { \"nums\": [1,2,8,9,2] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 7\n\ntest_input = { \"nums\": [1,7,4,9,2] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 5\n\ntest_input = { \"nums\": [2,2,4,6,3] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [2,7,1,3,9] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 9\n\ntest_input = { \"nums\": [3,1,9,6,5] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [3,3,3,6,1] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [3,7,1,8,1] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [4,1,6,10,2] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [5,4,8,4,2] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [6,1,1,8,10] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 7", "start_time": 1703341800} +{"task_id": "biweekly-contest-120-find-polygon-with-the-largest-perimeter", "url": "https://leetcode.com/problems/find-polygon-with-the-largest-perimeter", "title": "find-polygon-with-the-largest-perimeter", "meta": {"questionId": "3262", "questionFrontendId": "2971", "title": "Find Polygon With the Largest Perimeter", "titleSlug": "find-polygon-with-the-largest-perimeter", "isPaidOnly": false, "difficulty": "Medium", "likes": 53, "dislikes": 6, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given an array of positive integers nums of length n.\nA polygon is a closed plane figure that has at least 3 sides. The longest side of a polygon is smaller than the sum of its other sides.\nConversely, if you have k (k >= 3) positive real numbers a1, a2, a3, ..., ak where a1 <= a2 <= a3 <= ... <= ak and a1 + a2 + a3 + ... + ak-1 > ak, then there always exists a polygon with k sides whose lengths are a1, a2, a3, ..., ak.\nThe perimeter of a polygon is the sum of lengths of its sides.\nReturn the largest possible perimeter of a polygon whose sides can be formed from nums, or -1 if it is not possible to create a polygon.\n\nExample 1:\n\nInput: nums = [5,5,5]\nOutput: 15\nExplanation: The only possible polygon that can be made from nums has 3 sides: 5, 5, and 5. The perimeter is 5 + 5 + 5 = 15.\n\nExample 2:\n\nInput: nums = [1,12,1,2,5,50,3]\nOutput: 12\nExplanation: The polygon with the largest perimeter which can be made from nums has 5 sides: 1, 1, 2, 3, and 5. The perimeter is 1 + 1 + 2 + 3 + 5 = 12.\nWe cannot have a polygon with either 12 or 50 as the longest side because it is not possible to include 2 or more smaller sides that have a greater sum than either of them.\nIt can be shown that the largest possible perimeter is 12.\n\nExample 3:\n\nInput: nums = [5,5,50]\nOutput: -1\nExplanation: There is no possible way to form a polygon from nums, as a polygon has at least 3 sides and 50 > 5 + 5.\n\n\nConstraints:\n\n3 <= n <= 105\n1 <= nums[i] <= 109\n\"\"\"\nclass Solution:\n def largestPerimeter(self, nums: List[int]) -> int:\n ", "prompt_sft": "You are given an array of positive integers nums of length n.\nA polygon is a closed plane figure that has at least 3 sides. The longest side of a polygon is smaller than the sum of its other sides.\nConversely, if you have k (k >= 3) positive real numbers a1, a2, a3, ..., ak where a1 <= a2 <= a3 <= ... <= ak and a1 + a2 + a3 + ... + ak-1 > ak, then there always exists a polygon with k sides whose lengths are a1, a2, a3, ..., ak.\nThe perimeter of a polygon is the sum of lengths of its sides.\nReturn the largest possible perimeter of a polygon whose sides can be formed from nums, or -1 if it is not possible to create a polygon.\n\nExample 1:\n\nInput: nums = [5,5,5]\nOutput: 15\nExplanation: The only possible polygon that can be made from nums has 3 sides: 5, 5, and 5. The perimeter is 5 + 5 + 5 = 15.\n\nExample 2:\n\nInput: nums = [1,12,1,2,5,50,3]\nOutput: 12\nExplanation: The polygon with the largest perimeter which can be made from nums has 5 sides: 1, 1, 2, 3, and 5. The perimeter is 1 + 1 + 2 + 3 + 5 = 12.\nWe cannot have a polygon with either 12 or 50 as the longest side because it is not possible to include 2 or more smaller sides that have a greater sum than either of them.\nIt can be shown that the largest possible perimeter is 12.\n\nExample 3:\n\nInput: nums = [5,5,50]\nOutput: -1\nExplanation: There is no possible way to form a polygon from nums, as a polygon has at least 3 sides and 50 > 5 + 5.\n\n\nConstraints:\n\n3 <= n <= 105\n1 <= nums[i] <= 109\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def largestPerimeter(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [5,5,5] }\nassert my_solution.largestPerimeter(**test_input) == 15\n\ntest_input = { \"nums\": [1,12,1,2,5,50,3] }\nassert my_solution.largestPerimeter(**test_input) == 12\n\ntest_input = { \"nums\": [5,5,50] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,1] }\nassert my_solution.largestPerimeter(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,2] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,3] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,4] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,5] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [1,2,1] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [1,2,2] }\nassert my_solution.largestPerimeter(**test_input) == 5\n\ntest_input = { \"nums\": [1,2,3] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [1,2,4] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [1,2,5] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [1,3,1] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [1,3,2] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [1,3,3] }\nassert my_solution.largestPerimeter(**test_input) == 7\n\ntest_input = { \"nums\": [1,3,4] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [1,3,5] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [1,4,1] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [1,4,2] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [1,4,3] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [1,4,4] }\nassert my_solution.largestPerimeter(**test_input) == 9\n\ntest_input = { \"nums\": [1,4,5] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [1,5,1] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [1,5,2] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [1,5,3] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [1,5,4] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [1,5,5] }\nassert my_solution.largestPerimeter(**test_input) == 11\n\ntest_input = { \"nums\": [2,1,1] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [2,1,2] }\nassert my_solution.largestPerimeter(**test_input) == 5\n\ntest_input = { \"nums\": [2,1,3] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [2,1,4] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [2,1,5] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [2,2,1] }\nassert my_solution.largestPerimeter(**test_input) == 5\n\ntest_input = { \"nums\": [2,2,2] }\nassert my_solution.largestPerimeter(**test_input) == 6\n\ntest_input = { \"nums\": [2,2,3] }\nassert my_solution.largestPerimeter(**test_input) == 7\n\ntest_input = { \"nums\": [2,2,4] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [2,2,5] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [2,3,1] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [2,3,2] }\nassert my_solution.largestPerimeter(**test_input) == 7\n\ntest_input = { \"nums\": [2,3,3] }\nassert my_solution.largestPerimeter(**test_input) == 8\n\ntest_input = { \"nums\": [2,3,4] }\nassert my_solution.largestPerimeter(**test_input) == 9\n\ntest_input = { \"nums\": [2,3,5] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [2,4,1] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [2,4,2] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [2,4,3] }\nassert my_solution.largestPerimeter(**test_input) == 9\n\ntest_input = { \"nums\": [2,4,4] }\nassert my_solution.largestPerimeter(**test_input) == 10\n\ntest_input = { \"nums\": [2,4,5] }\nassert my_solution.largestPerimeter(**test_input) == 11\n\ntest_input = { \"nums\": [2,5,1] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [2,5,2] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [2,5,3] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [2,5,4] }\nassert my_solution.largestPerimeter(**test_input) == 11\n\ntest_input = { \"nums\": [2,5,5] }\nassert my_solution.largestPerimeter(**test_input) == 12\n\ntest_input = { \"nums\": [3,1,1] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [3,1,2] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [3,1,3] }\nassert my_solution.largestPerimeter(**test_input) == 7\n\ntest_input = { \"nums\": [3,1,4] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [3,1,5] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [3,2,1] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [3,2,2] }\nassert my_solution.largestPerimeter(**test_input) == 7\n\ntest_input = { \"nums\": [3,2,3] }\nassert my_solution.largestPerimeter(**test_input) == 8\n\ntest_input = { \"nums\": [3,2,4] }\nassert my_solution.largestPerimeter(**test_input) == 9\n\ntest_input = { \"nums\": [3,2,5] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [3,3,1] }\nassert my_solution.largestPerimeter(**test_input) == 7\n\ntest_input = { \"nums\": [3,3,2] }\nassert my_solution.largestPerimeter(**test_input) == 8\n\ntest_input = { \"nums\": [3,3,3] }\nassert my_solution.largestPerimeter(**test_input) == 9\n\ntest_input = { \"nums\": [3,3,4] }\nassert my_solution.largestPerimeter(**test_input) == 10\n\ntest_input = { \"nums\": [3,3,5] }\nassert my_solution.largestPerimeter(**test_input) == 11\n\ntest_input = { \"nums\": [3,4,1] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [3,4,2] }\nassert my_solution.largestPerimeter(**test_input) == 9\n\ntest_input = { \"nums\": [3,4,3] }\nassert my_solution.largestPerimeter(**test_input) == 10\n\ntest_input = { \"nums\": [3,4,4] }\nassert my_solution.largestPerimeter(**test_input) == 11\n\ntest_input = { \"nums\": [3,4,5] }\nassert my_solution.largestPerimeter(**test_input) == 12\n\ntest_input = { \"nums\": [3,5,1] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [3,5,2] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [3,5,3] }\nassert my_solution.largestPerimeter(**test_input) == 11\n\ntest_input = { \"nums\": [3,5,4] }\nassert my_solution.largestPerimeter(**test_input) == 12\n\ntest_input = { \"nums\": [3,5,5] }\nassert my_solution.largestPerimeter(**test_input) == 13\n\ntest_input = { \"nums\": [4,1,1] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [4,1,2] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [4,1,3] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [4,1,4] }\nassert my_solution.largestPerimeter(**test_input) == 9\n\ntest_input = { \"nums\": [4,1,5] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [4,2,1] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [4,2,2] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [4,2,3] }\nassert my_solution.largestPerimeter(**test_input) == 9\n\ntest_input = { \"nums\": [4,2,4] }\nassert my_solution.largestPerimeter(**test_input) == 10\n\ntest_input = { \"nums\": [4,2,5] }\nassert my_solution.largestPerimeter(**test_input) == 11\n\ntest_input = { \"nums\": [4,3,1] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [4,3,2] }\nassert my_solution.largestPerimeter(**test_input) == 9\n\ntest_input = { \"nums\": [4,3,3] }\nassert my_solution.largestPerimeter(**test_input) == 10\n\ntest_input = { \"nums\": [4,3,4] }\nassert my_solution.largestPerimeter(**test_input) == 11\n\ntest_input = { \"nums\": [4,3,5] }\nassert my_solution.largestPerimeter(**test_input) == 12\n\ntest_input = { \"nums\": [4,4,1] }\nassert my_solution.largestPerimeter(**test_input) == 9\n\ntest_input = { \"nums\": [4,4,2] }\nassert my_solution.largestPerimeter(**test_input) == 10\n\ntest_input = { \"nums\": [4,4,3] }\nassert my_solution.largestPerimeter(**test_input) == 11\n\ntest_input = { \"nums\": [4,4,4] }\nassert my_solution.largestPerimeter(**test_input) == 12\n\ntest_input = { \"nums\": [4,4,5] }\nassert my_solution.largestPerimeter(**test_input) == 13\n\ntest_input = { \"nums\": [4,5,1] }\nassert my_solution.largestPerimeter(**test_input) == -1\n\ntest_input = { \"nums\": [4,5,2] }\nassert my_solution.largestPerimeter(**test_input) == 11", "start_time": 1703341800} +{"task_id": "biweekly-contest-120-count-the-number-of-incremovable-subarrays-ii", "url": "https://leetcode.com/problems/count-the-number-of-incremovable-subarrays-ii", "title": "count-the-number-of-incremovable-subarrays-ii", "meta": {"questionId": "3248", "questionFrontendId": "2972", "title": "Count the Number of Incremovable Subarrays II", "titleSlug": "count-the-number-of-incremovable-subarrays-ii", "isPaidOnly": false, "difficulty": "Hard", "likes": 97, "dislikes": 15, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed array of positive integers nums.\nA subarray of nums is called incremovable if nums becomes strictly increasing on removing the subarray. For example, the subarray [3, 4] is an incremovable subarray of [5, 3, 4, 6, 7] because removing this subarray changes the array [5, 3, 4, 6, 7] to [5, 6, 7] which is strictly increasing.\nReturn the total number of incremovable subarrays of nums.\nNote that an empty array is considered strictly increasing.\nA subarray is a contiguous non-empty sequence of elements within an array.\n\nExample 1:\n\nInput: nums = [1,2,3,4]\nOutput: 10\nExplanation: The 10 incremovable subarrays are: [1], [2], [3], [4], [1,2], [2,3], [3,4], [1,2,3], [2,3,4], and [1,2,3,4], because on removing any one of these subarrays nums becomes strictly increasing. Note that you cannot select an empty subarray.\n\nExample 2:\n\nInput: nums = [6,5,7,8]\nOutput: 7\nExplanation: The 7 incremovable subarrays are: [5], [6], [5,7], [6,5], [5,7,8], [6,5,7] and [6,5,7,8].\nIt can be shown that there are only 7 incremovable subarrays in nums.\n\nExample 3:\n\nInput: nums = [8,7,6,6]\nOutput: 3\nExplanation: The 3 incremovable subarrays are: [8,7,6], [7,6,6], and [8,7,6,6]. Note that [8,7] is not an incremovable subarray because after removing [8,7] nums becomes [6,6], which is sorted in ascending order but not strictly increasing.\n\n\nConstraints:\n\n1 <= nums.length <= 105\n1 <= nums[i] <= 109\n\"\"\"\nclass Solution:\n def incremovableSubarrayCount(self, nums: List[int]) -> int:\n ", "prompt_sft": "You are given a 0-indexed array of positive integers nums.\nA subarray of nums is called incremovable if nums becomes strictly increasing on removing the subarray. For example, the subarray [3, 4] is an incremovable subarray of [5, 3, 4, 6, 7] because removing this subarray changes the array [5, 3, 4, 6, 7] to [5, 6, 7] which is strictly increasing.\nReturn the total number of incremovable subarrays of nums.\nNote that an empty array is considered strictly increasing.\nA subarray is a contiguous non-empty sequence of elements within an array.\n\nExample 1:\n\nInput: nums = [1,2,3,4]\nOutput: 10\nExplanation: The 10 incremovable subarrays are: [1], [2], [3], [4], [1,2], [2,3], [3,4], [1,2,3], [2,3,4], and [1,2,3,4], because on removing any one of these subarrays nums becomes strictly increasing. Note that you cannot select an empty subarray.\n\nExample 2:\n\nInput: nums = [6,5,7,8]\nOutput: 7\nExplanation: The 7 incremovable subarrays are: [5], [6], [5,7], [6,5], [5,7,8], [6,5,7] and [6,5,7,8].\nIt can be shown that there are only 7 incremovable subarrays in nums.\n\nExample 3:\n\nInput: nums = [8,7,6,6]\nOutput: 3\nExplanation: The 3 incremovable subarrays are: [8,7,6], [7,6,6], and [8,7,6,6]. Note that [8,7] is not an incremovable subarray because after removing [8,7] nums becomes [6,6], which is sorted in ascending order but not strictly increasing.\n\n\nConstraints:\n\n1 <= nums.length <= 105\n1 <= nums[i] <= 109\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def incremovableSubarrayCount(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,2,3,4] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 10\n\ntest_input = { \"nums\": [6,5,7,8] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 7\n\ntest_input = { \"nums\": [8,7,6,6] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [1] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 1\n\ntest_input = { \"nums\": [2] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 1\n\ntest_input = { \"nums\": [3] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 1\n\ntest_input = { \"nums\": [4] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 1\n\ntest_input = { \"nums\": [5] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 1\n\ntest_input = { \"nums\": [6] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 1\n\ntest_input = { \"nums\": [7] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 1\n\ntest_input = { \"nums\": [8] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 1\n\ntest_input = { \"nums\": [9] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 1\n\ntest_input = { \"nums\": [10] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 1\n\ntest_input = { \"nums\": [4,10] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [7,3] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [8,5] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [8,10] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [9,9] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [5,5,6] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 5\n\ntest_input = { \"nums\": [6,7,5] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [8,1,2] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [9,2,8] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [9,3,8] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,10,6] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 7\n\ntest_input = { \"nums\": [1,9,6,9] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 7\n\ntest_input = { \"nums\": [4,8,5,9] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 8\n\ntest_input = { \"nums\": [6,2,6,4] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [10,2,5,7] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 5\n\ntest_input = { \"nums\": [1,2,4,7,10] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 15\n\ntest_input = { \"nums\": [1,5,9,5,7] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 9\n\ntest_input = { \"nums\": [6,6,5,3,5] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [8,5,5,3,10] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 5\n\ntest_input = { \"nums\": [9,10,1,8,2] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [11,50,14,33,45,38,33,19,28,34] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 9\n\ntest_input = { \"nums\": [25,9,28,31,38,15,31,44,46,49] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 11\n\ntest_input = { \"nums\": [25,26,49,31,40,47,30,29,32,34] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 13\n\ntest_input = { \"nums\": [25,39,29,30,40,28,30,39,30,42] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 8\n\ntest_input = { \"nums\": [25,41,31,38,30,38,37,41,36,32] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 5\n\ntest_input = { \"nums\": [25,45,49,28,47,44,42,34,28,25] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 5\n\ntest_input = { \"nums\": [25,46,48,41,29,47,32,34,41,34] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 6\n\ntest_input = { \"nums\": [25,47,25,35,48,49,27,37,36,43] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 7\n\ntest_input = { \"nums\": [26,26,50,38,30,38,31,26,39,45] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 7\n\ntest_input = { \"nums\": [26,32,41,38,45,32,31,27,48,41] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 7\n\ntest_input = { \"nums\": [26,45,44,26,33,35,34,36,44,38] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 5\n\ntest_input = { \"nums\": [26,49,42,26,37,41,31,36,45,41] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 5\n\ntest_input = { \"nums\": [27,39,32,30,38,41,28,26,49,49] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 6\n\ntest_input = { \"nums\": [27,43,36,37,33,46,48,35,49,49] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 6\n\ntest_input = { \"nums\": [28,17,12,21,21,49,31,30,40,13] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [28,30,39,31,33,41,47,36,43,46] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 15\n\ntest_input = { \"nums\": [29,27,32,38,26,38,39,30,41,45] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 8\n\ntest_input = { \"nums\": [29,31,48,28,27,38,32,28,30,44] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 10\n\ntest_input = { \"nums\": [29,34,44,27,45,31,37,32,50,26] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 5\n\ntest_input = { \"nums\": [29,38,36,42,31,38,27,48,42,28] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [29,46,34,47,46,41,29,29,38,39] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 8\n\ntest_input = { \"nums\": [29,49,32,35,38,37,27,25,50,46] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 5\n\ntest_input = { \"nums\": [30,27,38,33,28,48,41,30,25,50] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 5\n\ntest_input = { \"nums\": [30,29,31,44,31,25,50,35,35,47] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 6\n\ntest_input = { \"nums\": [30,30,46,35,31,41,30,37,37,33] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [30,41,28,45,35,41,47,32,29,33] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 6\n\ntest_input = { \"nums\": [30,45,44,27,43,40,28,34,39,40] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 10\n\ntest_input = { \"nums\": [30,49,34,26,50,50,48,49,39,26] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [31,34,25,43,38,34,29,50,27,34] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 6\n\ntest_input = { \"nums\": [31,35,39,38,41,47,26,43,47,46] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 8\n\ntest_input = { \"nums\": [31,37,29,41,32,46,25,28,30,29] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [31,38,31,47,25,25,36,29,43,28] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [31,41,25,37,43,29,30,26,30,46] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 8\n\ntest_input = { \"nums\": [31,42,40,36,39,28,43,29,35,50] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 9\n\ntest_input = { \"nums\": [32,29,13,39,34,47,38,15,10,5] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [32,35,32,50,32,26,29,49,40,41] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 9\n\ntest_input = { \"nums\": [32,37,35,26,45,44,47,29,31,28] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [32,43,44,44,36,41,31,33,41,43] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 11\n\ntest_input = { \"nums\": [32,50,50,46,32,30,32,32,31,39] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 6\n\ntest_input = { \"nums\": [33,27,34,46,42,35,36,49,25,40] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 5\n\ntest_input = { \"nums\": [33,28,35,32,36,38,33,47,36,35] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [33,31,36,38,39,46,42,41,27,33] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [33,45,25,48,45,42,35,38,47,43] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 5\n\ntest_input = { \"nums\": [33,46,38,37,42,48,31,43,38,29] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [33,48,50,48,46,33,34,26,32,33] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 7\n\ntest_input = { \"nums\": [34,25,38,41,31,46,40,46,39,30] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [34,38,35,28,30,37,35,25,48,28] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [34,47,26,48,30,25,26,43,44,41] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 5\n\ntest_input = { \"nums\": [35,22,35,6,20,47,3,29,45,30] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [35,25,29,40,32,29,35,39,39,32] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [35,26,39,41,26,44,36,26,46,50] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 7\n\ntest_input = { \"nums\": [35,27,29,45,29,30,48,42,37,50] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 6\n\ntest_input = { \"nums\": [35,31,27,45,39,46,47,49,26,27] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [35,39,36,30,32,48,34,25,37,45] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 9\n\ntest_input = { \"nums\": [36,26,44,32,36,29,44,28,48,30] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [36,28,28,45,40,40,32,48,34,48] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 5\n\ntest_input = { \"nums\": [36,28,34,49,48,36,50,25,43,40] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [36,30,47,32,32,35,41,49,41,45] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 6\n\ntest_input = { \"nums\": [36,31,45,34,47,48,49,31,34,34] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 3\n\ntest_input = { \"nums\": [37,33,50,48,25,37,29,49,46,45] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [37,35,29,27,39,38,49,48,27,37] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4\n\ntest_input = { \"nums\": [37,40,42,41,30,40,46,44,47,27] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 5\n\ntest_input = { \"nums\": [37,43,49,40,30,46,31,44,47,25] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 5\n\ntest_input = { \"nums\": [37,45,49,26,32,45,33,40,35,43] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 7\n\ntest_input = { \"nums\": [37,50,42,50,40,26,34,25,28,44] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 7\n\ntest_input = { \"nums\": [38,28,25,31,28,44,35,26,33,41] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 6\n\ntest_input = { \"nums\": [38,30,36,50,36,40,41,25,43,43] }\nassert my_solution.incremovableSubarrayCount(**test_input) == 4", "start_time": 1703341800} +{"task_id": "biweekly-contest-120-find-number-of-coins-to-place-in-tree-nodes", "url": "https://leetcode.com/problems/find-number-of-coins-to-place-in-tree-nodes", "title": "find-number-of-coins-to-place-in-tree-nodes", "meta": {"questionId": "3218", "questionFrontendId": "2973", "title": "Find Number of Coins to Place in Tree Nodes", "titleSlug": "find-number-of-coins-to-place-in-tree-nodes", "isPaidOnly": false, "difficulty": "Hard", "likes": 67, "dislikes": 2, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given an undirected tree with n nodes labeled from 0 to n - 1, and rooted at node 0. You are given a 2D integer array edges of length n - 1, where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree.\nYou are also given a 0-indexed integer array cost of length n, where cost[i] is the cost assigned to the ith node.\nYou need to place some coins on every node of the tree. The number of coins to be placed at node i can be calculated as:\n\nIf size of the subtree of node i is less than 3, place 1 coin.\nOtherwise, place an amount of coins equal to the maximum product of cost values assigned to 3 distinct nodes in the subtree of node i. If this product is negative, place 0 coins.\n\nReturn an array coin of size n such that coin[i] is the number of coins placed at node i.\n\nExample 1:\n\n\nInput: edges = [[0,1],[0,2],[0,3],[0,4],[0,5]], cost = [1,2,3,4,5,6]\nOutput: [120,1,1,1,1,1]\nExplanation: For node 0 place 6 * 5 * 4 = 120 coins. All other nodes are leaves with subtree of size 1, place 1 coin on each of them.\n\nExample 2:\n\n\nInput: edges = [[0,1],[0,2],[1,3],[1,4],[1,5],[2,6],[2,7],[2,8]], cost = [1,4,2,3,5,7,8,-4,2]\nOutput: [280,140,32,1,1,1,1,1,1]\nExplanation: The coins placed on each node are:\n- Place 8 * 7 * 5 = 280 coins on node 0.\n- Place 7 * 5 * 4 = 140 coins on node 1.\n- Place 8 * 2 * 2 = 32 coins on node 2.\n- All other nodes are leaves with subtree of size 1, place 1 coin on each of them.\n\nExample 3:\n\n\nInput: edges = [[0,1],[0,2]], cost = [1,2,-2]\nOutput: [0,1,1]\nExplanation: Node 1 and 2 are leaves with subtree of size 1, place 1 coin on each of them. For node 0 the only possible product of cost is 2 * 1 * -2 = -4. Hence place 0 coins on node 0.\n\n\nConstraints:\n\n2 <= n <= 2 * 104\nedges.length == n - 1\nedges[i].length == 2\n0 <= ai, bi < n\ncost.length == n\n1 <= |cost[i]| <= 104\nThe input is generated such that edges represents a valid tree.\n\"\"\"\nclass Solution:\n def placedCoins(self, edges: List[List[int]], cost: List[int]) -> List[int]:\n ", "prompt_sft": "You are given an undirected tree with n nodes labeled from 0 to n - 1, and rooted at node 0. You are given a 2D integer array edges of length n - 1, where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree.\nYou are also given a 0-indexed integer array cost of length n, where cost[i] is the cost assigned to the ith node.\nYou need to place some coins on every node of the tree. The number of coins to be placed at node i can be calculated as:\n\nIf size of the subtree of node i is less than 3, place 1 coin.\nOtherwise, place an amount of coins equal to the maximum product of cost values assigned to 3 distinct nodes in the subtree of node i. If this product is negative, place 0 coins.\n\nReturn an array coin of size n such that coin[i] is the number of coins placed at node i.\n\nExample 1:\n\n\nInput: edges = [[0,1],[0,2],[0,3],[0,4],[0,5]], cost = [1,2,3,4,5,6]\nOutput: [120,1,1,1,1,1]\nExplanation: For node 0 place 6 * 5 * 4 = 120 coins. All other nodes are leaves with subtree of size 1, place 1 coin on each of them.\n\nExample 2:\n\n\nInput: edges = [[0,1],[0,2],[1,3],[1,4],[1,5],[2,6],[2,7],[2,8]], cost = [1,4,2,3,5,7,8,-4,2]\nOutput: [280,140,32,1,1,1,1,1,1]\nExplanation: The coins placed on each node are:\n- Place 8 * 7 * 5 = 280 coins on node 0.\n- Place 7 * 5 * 4 = 140 coins on node 1.\n- Place 8 * 2 * 2 = 32 coins on node 2.\n- All other nodes are leaves with subtree of size 1, place 1 coin on each of them.\n\nExample 3:\n\n\nInput: edges = [[0,1],[0,2]], cost = [1,2,-2]\nOutput: [0,1,1]\nExplanation: Node 1 and 2 are leaves with subtree of size 1, place 1 coin on each of them. For node 0 the only possible product of cost is 2 * 1 * -2 = -4. Hence place 0 coins on node 0.\n\n\nConstraints:\n\n2 <= n <= 2 * 104\nedges.length == n - 1\nedges[i].length == 2\n0 <= ai, bi < n\ncost.length == n\n1 <= |cost[i]| <= 104\nThe input is generated such that edges represents a valid tree.\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def placedCoins(self, edges: List[List[int]], cost: List[int]) -> List[int]:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"edges\": [[0,1],[0,2],[0,3],[0,4],[0,5]], \"cost\": [1,2,3,4,5,6] }\nassert my_solution.placedCoins(**test_input) == [120,1,1,1,1,1]\n\ntest_input = { \"edges\": [[0,1],[0,2],[1,3],[1,4],[1,5],[2,6],[2,7],[2,8]], \"cost\": [1,4,2,3,5,7,8,-4,2] }\nassert my_solution.placedCoins(**test_input) == [280,140,32,1,1,1,1,1,1]\n\ntest_input = { \"edges\": [[0,1],[0,2]], \"cost\": [1,2,-2] }\nassert my_solution.placedCoins(**test_input) == [0,1,1]\n\ntest_input = { \"edges\": [[0,1]], \"cost\": [1,2] }\nassert my_solution.placedCoins(**test_input) == [1,1]\n\ntest_input = { \"edges\": [[0,1]], \"cost\": [2,1] }\nassert my_solution.placedCoins(**test_input) == [1,1]\n\ntest_input = { \"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],[0,20],[0,21],[0,22],[0,23],[0,24],[0,25],[0,26],[0,27],[0,28],[0,29],[0,30],[0,31],[0,32],[0,33],[0,34],[0,35],[0,36],[0,37],[0,38],[0,39],[0,40],[0,41],[0,42],[0,43],[0,44],[0,45],[0,46],[0,47],[0,48],[0,49],[0,50],[0,51],[0,52],[0,53],[0,54],[0,55],[0,56],[0,57],[0,58],[0,59],[0,60],[0,61],[0,62],[0,63],[0,64],[0,65],[0,66],[0,67],[0,68],[0,69],[0,70],[0,71],[0,72],[0,73],[0,74],[0,75],[0,76],[0,77],[0,78],[0,79],[0,80],[0,81],[0,82],[0,83],[0,84],[0,85],[0,86],[0,87],[0,88],[0,89],[0,90],[0,91],[0,92],[0,93],[0,94],[0,95],[0,96],[0,97],[0,98],[0,99]], \"cost\": [-5959,602,-6457,7055,-1462,6347,7226,-8422,-6088,2997,-7909,6433,5217,3294,-3792,7463,8538,-3811,5009,151,5659,4458,-1702,-1877,2799,9861,-9668,-1765,2181,-8128,7046,9529,6202,-8026,6464,1345,121,1922,7274,-1227,-9914,3025,1046,-9368,-7368,6205,-6342,8091,-6732,-7620,3276,5136,6871,4823,-1885,-4005,-3974,-2725,-3845,-8508,7201,-9566,-7236,-3386,4021,6793,-8759,5066,5879,-5171,1011,1242,8536,-8405,-9646,-214,2251,-9934,-8820,6206,1006,1318,-9712,7230,5608,-4601,9185,346,3056,8913,-2454,-3445,-4295,4802,-8852,-6121,-4538,-5580,-9246,-6462] }\nassert my_solution.placedCoins(**test_input) == [971167251036,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]\n\ntest_input = { \"edges\": [[0,1],[0,2],[2,3]], \"cost\": [10000,-10000,10000,-10000] }\nassert my_solution.placedCoins(**test_input) == [1000000000000,1,1,1]\n\ntest_input = { \"edges\": [[0,2],[0,6],[1,4],[3,5],[7,6],[3,6],[1,8],[3,1],[9,3]], \"cost\": [63,13,-6,20,56,-14,61,25,-99,54] }\nassert my_solution.placedCoins(**test_input) == [215208,0,1,77616,1,1,184464,1,1,1]\n\ntest_input = { \"edges\": [[7,0],[4,3],[4,8],[1,5],[6,2],[2,7],[7,9],[1,8],[1,9]], \"cost\": [37,-48,30,-67,-84,36,-96,24,29,38] }\nassert my_solution.placedCoins(**test_input) == [306432,202608,1,1,1,1,1,306432,163212,213864]\n\ntest_input = { \"edges\": [[0,2],[2,7],[3,4],[5,4],[5,8],[7,6],[7,1],[8,1],[1,9]], \"cost\": [-18,15,-82,-85,63,-89,60,63,20,18] }\nassert my_solution.placedCoins(**test_input) == [476595,476595,476595,1,1,476595,1,476595,476595,1]\n\ntest_input = { \"edges\": [[2,0],[1,4],[3,8],[4,9],[6,8],[7,2],[2,8],[5,2],[5,9]], \"cost\": [-9,46,17,34,43,92,41,-50,4,76] }\nassert my_solution.placedCoins(**test_input) == [321632,1,321632,1,1,321632,1,1,5576,150328]\n\ntest_input = { \"edges\": [[0,6],[3,2],[3,1],[6,1],[8,7],[7,1],[5,1],[5,4],[9,4]], \"cost\": [86,50,10,-54,-85,-65,54,-19,39,37] }\nassert my_solution.placedCoins(**test_input) == [475150,276250,1,1,1,204425,298350,1,1,1]\n\ntest_input = { \"edges\": [[0,8],[8,1],[9,2],[4,6],[7,4],[3,7],[3,8],[5,8],[5,9]], \"cost\": [-4,83,-97,40,86,-85,-6,-84,-16,-53] }\nassert my_solution.placedCoins(**test_input) == [709070,1,1,43344,1,0,1,43344,709070,1]\n\ntest_input = { \"edges\": [[4,2],[1,3],[4,5],[7,5],[5,0],[8,1],[0,1],[0,6],[9,6]], \"cost\": [-72,-18,-27,38,13,-53,43,-95,-100,-77] }\nassert my_solution.placedCoins(**test_input) == [408500,68400,1,1,1,65455,1,1,1,1]\n\ntest_input = { \"edges\": [[0,2],[5,2],[1,5],[7,4],[4,8],[1,8],[1,6],[6,3],[9,3]], \"cost\": [6,93,59,-14,1,-71,-87,95,16,-12] }\nassert my_solution.placedCoins(**test_input) == [586815,141360,586815,1,1,586815,0,1,1520,1]\n\ntest_input = { \"edges\": [[0,1],[5,4],[4,2],[7,2],[7,3],[8,6],[3,6],[3,1],[9,1]], \"cost\": [66,-54,74,18,-77,-57,49,-82,-71,80] }\nassert my_solution.placedCoins(**test_input) == [505120,505120,324786,467236,1,1,1,467236,1,1]\n\ntest_input = { \"edges\": [[3,8],[2,4],[5,6],[6,7],[0,8],[2,0],[2,6],[1,6],[9,1]], \"cost\": [92,-71,-10,-70,-56,-47,69,51,100,65] }\nassert my_solution.placedCoins(**test_input) == [634800,1,274344,1,1,1,230253,1,1,1]\n\ntest_input = { \"edges\": [[0,3],[2,8],[5,6],[9,5],[7,9],[8,1],[1,4],[4,3],[9,3]], \"cost\": [-71,66,86,99,50,-29,-30,27,16,-65] }\nassert my_solution.placedCoins(**test_input) == [561924,90816,1,561924,283800,1,1,1,1,52650]\n\ntest_input = { \"edges\": [[1,0],[2,7],[6,3],[0,4],[6,5],[5,8],[0,7],[9,0],[9,8]], \"cost\": [40,8,43,31,-27,-21,-21,55,-36,75] }\nassert my_solution.placedCoins(**test_input) == [177375,1,1,1,1,13671,1,1,23436,56700]\n\ntest_input = { \"edges\": [[9,0],[9,3],[4,5],[1,6],[1,5],[8,5],[9,7],[8,2],[2,9]], \"cost\": [64,35,-1,-28,-50,38,-77,-13,-72,35] }\nassert my_solution.placedCoins(**test_input) == [354816,1,210672,1,1,146300,1,1,210672,210672]\n\ntest_input = { \"edges\": [[5,3],[4,2],[5,2],[6,5],[5,1],[0,1],[0,8],[9,7],[9,8]], \"cost\": [-100,44,-76,55,8,-8,38,26,-41,-83] }\nassert my_solution.placedCoins(**test_input) == [456500,91960,1,1,1,33440,1,1,88478,1]\n\ntest_input = { \"edges\": [[0,8],[9,3],[4,5],[8,5],[2,6],[7,8],[2,8],[1,2],[9,1]], \"cost\": [36,33,52,-24,7,-82,63,85,21,-64] }\nassert my_solution.placedCoins(**test_input) == [446080,50688,108108,1,1,1,1,1,446080,1]\n\ntest_input = { \"edges\": [[9,2],[1,3],[8,4],[1,5],[1,9],[8,6],[7,9],[8,0],[0,9]], \"cost\": [-67,-82,-2,32,-97,6,-85,14,8,1] }\nassert my_solution.placedCoins(**test_input) == [263840,0,1,1,1,1,1,1,65960,5248]\n\ntest_input = { \"edges\": [[7,0],[3,1],[7,3],[4,8],[8,5],[7,6],[2,6],[2,9],[8,9]], \"cost\": [-48,-69,-25,-65,65,51,85,34,17,-28] }\nassert my_solution.placedCoins(**test_input) == [381225,1,56355,1,1,1,281775,381225,56355,56355]\n\ntest_input = { \"edges\": [[4,2],[7,2],[3,5],[6,3],[3,0],[7,0],[1,8],[1,0],[9,0]], \"cost\": [-14,39,40,-76,-69,66,43,82,-66,-45] }\nassert my_solution.placedCoins(**test_input) == [430008,1,1,0,1,1,1,0,1,1]\n\ntest_input = { \"edges\": [[1,9],[3,7],[0,6],[7,0],[8,5],[2,5],[4,2],[4,0],[0,9]], \"cost\": [34,-87,-34,87,58,76,5,43,14,-45] }\nassert my_solution.placedCoins(**test_input) == [383496,1,0,1,61712,1,1,1,1,1]\n\ntest_input = { \"edges\": [[7,1],[2,7],[4,3],[9,5],[6,7],[3,6],[8,3],[0,3],[0,9]], \"cost\": [-9,67,10,-67,91,29,-4,-35,60,-84] }\nassert my_solution.placedCoins(**test_input) == [512148,1,1,365820,1,1,9380,0,1,1]\n\ntest_input = { \"edges\": [[2,3],[3,6],[3,7],[8,5],[1,5],[4,1],[4,0],[0,3],[9,3]], \"cost\": [88,-73,8,-82,64,-14,56,-82,-2,-89] }\nassert my_solution.placedCoins(**test_input) == [642224,0,1,408688,65408,1,1,1,1,1]\n\ntest_input = { \"edges\": [[8,4],[7,3],[3,0],[0,6],[6,8],[8,2],[5,2],[1,5],[1,9]], \"cost\": [-50,34,51,-69,-28,72,61,-76,-30,76] }\nassert my_solution.placedCoins(**test_input) == [398544,1,279072,1,1,186048,333792,1,279072,1]\n\ntest_input = { \"edges\": [[5,0],[1,6],[7,2],[4,9],[3,5],[3,7],[8,7],[6,7],[6,9]], \"cost\": [-75,-39,-30,-69,84,-7,98,92,-42,-51] }\nassert my_solution.placedCoins(**test_input) == [757344,1,1,757344,1,757344,194922,757344,1,1]\n\ntest_input = { \"edges\": [[0,8],[2,5],[3,5],[1,6],[4,1],[8,4],[7,8],[8,5],[9,5]], \"cost\": [81,-76,-61,1,39,-3,-21,-33,42,-78] }\nassert my_solution.placedCoins(**test_input) == [480168,1,1,1,62244,4758,1,1,248976,1]\n\ntest_input = { \"edges\": [[7,1],[0,2],[0,3],[6,5],[6,0],[0,7],[7,4],[9,4],[8,9]], \"cost\": [-37,-11,71,-57,-2,-78,87,55,-21,-66] }\nassert my_solution.placedCoins(**test_input) == [447876,1,1,1,0,1,1,76230,1,1]\n\ntest_input = { \"edges\": [[0,9],[8,2],[3,7],[6,4],[1,5],[8,1],[6,8],[6,7],[7,9]], \"cost\": [61,-53,-97,-86,-91,-32,-8,79,100,75] }\nassert my_solution.placedCoins(**test_input) == [882700,1,1,1,1,1,882700,882700,514100,882700]\n\ntest_input = { \"edges\": [[8,3],[4,6],[2,5],[2,1],[6,8],[8,0],[0,7],[1,7],[1,9]], \"cost\": [-40,-4,60,-47,35,39,-8,-12,-29,-43] }\nassert my_solution.placedCoins(**test_input) == [121260,10320,1,1,1,1,1,30960,47705,1]\n\ntest_input = { \"edges\": [[3,0],[1,7],[6,3],[7,5],[4,5],[4,6],[6,9],[2,8],[9,2]], \"cost\": [36,84,5,32,-36,86,-35,58,36,-100] }\nassert my_solution.placedCoins(**test_input) == [418992,1,1,418992,418992,418992,418992,1,1,0]\n\ntest_input = { \"edges\": [[1,0],[3,0],[2,5],[3,5],[6,4],[4,9],[7,3],[8,3],[3,9]], \"cost\": [39,22,-9,-65,9,-53,83,-94,-34,12] }\nassert my_solution.placedCoins(**test_input) == [507130,1,1,507130,1,1,1,1,1,8964]\n\ntest_input = { \"edges\": [[2,0],[7,0],[4,3],[5,8],[7,9],[8,1],[3,1],[3,6],[9,6]], \"cost\": [-68,1,-68,65,-45,-26,36,-3,-85,40] }\nassert my_solution.placedCoins(**test_input) == [375700,2210,1,248625,1,1,248625,248625,1,248625]\n\ntest_input = { \"edges\": [[4,0],[7,2],[2,6],[8,6],[5,6],[4,5],[4,3],[1,3],[1,9]], \"cost\": [-45,26,-26,-34,-33,81,-33,55,-87,52] }\nassert my_solution.placedCoins(**test_input) == [317115,1,1,0,239598,232551,157905,1,1,1]\n\ntest_input = { \"edges\": [[2,1],[0,1],[6,3],[5,4],[6,5],[0,6],[9,0],[8,7],[9,7]], \"cost\": [94,76,-92,61,27,78,-94,39,-12,77] }\nassert my_solution.placedCoins(**test_input) == [812912,1,1,1,1,1,128466,1,1,0]\n\ntest_input = { \"edges\": [[8,0],[3,2],[6,2],[1,2],[1,5],[4,7],[9,4],[8,5],[9,5]], \"cost\": [-6,-89,62,-82,-78,97,-71,58,-43,12] }\nassert my_solution.placedCoins(**test_input) == [707906,452476,360964,1,1,707906,1,1,707906,0]\n\ntest_input = { \"edges\": [[1,0],[2,0],[4,0],[4,3],[4,6],[6,5],[7,5],[7,8],[9,8]], \"cost\": [-35,4,-1,-44,-27,-93,10,55,-14,93] }\nassert my_solution.placedCoins(**test_input) == [380556,1,1,1,380556,121086,121086,0,1,1]\n\ntest_input = { \"edges\": [[0,6],[1,5],[8,2],[8,3],[9,6],[4,7],[5,8],[5,4],[4,9]], \"cost\": [26,22,32,-27,54,44,-58,-88,79,-77] }\nassert my_solution.placedCoins(**test_input) == [535304,1,1,1,187704,111232,535304,1,0,535304]\n\ntest_input = { \"edges\": [[7,2],[3,1],[5,1],[8,5],[6,9],[7,0],[0,4],[4,8],[9,4]], \"cost\": [-70,-80,17,23,19,-71,84,-52,-21,-44] }\nassert my_solution.placedCoins(**test_input) == [477120,1,1,1,477120,130640,1,1,130640,1]\n\ntest_input = { \"edges\": [[2,1],[3,6],[0,6],[7,2],[5,2],[5,4],[4,0],[0,8],[9,0]], \"cost\": [-27,11,-5,22,-81,48,-28,-85,85,-44] }\nassert my_solution.placedCoins(**test_input) == [585225,1,4675,1,330480,20400,1,1,1,1]\n\ntest_input = { \"edges\": [[8,1],[2,5],[4,3],[8,5],[5,6],[6,3],[0,3],[7,0],[9,7]], \"cost\": [79,-73,75,-96,61,87,-74,69,84,41] }\nassert my_solution.placedCoins(**test_input) == [618048,1,1,618048,1,548100,548100,1,1,1]\n\ntest_input = { \"edges\": [[1,0],[2,0],[3,0],[4,0],[0,7],[8,0],[8,6],[5,6],[5,9]], \"cost\": [-97,-61,-67,60,-75,-85,-21,75,-89,59] }\nassert my_solution.placedCoins(**test_input) == [647475,1,1,1,1,1,105315,1,446335,1]\n\ntest_input = { \"edges\": [[0,1],[0,4],[9,3],[9,4],[5,2],[2,7],[6,8],[8,7],[8,9]], \"cost\": [-88,-7,-16,-49,-53,46,-19,38,-2,-12] }\nassert my_solution.placedCoins(**test_input) == [214544,1,1,1,119462,1,1,0,13984,42826]\n\ntest_input = { \"edges\": [[2,0],[4,6],[4,5],[1,5],[3,1],[3,2],[2,7],[8,7],[7,9]], \"cost\": [-71,-13,56,3,95,74,79,81,-50,-24] }\nassert my_solution.placedCoins(**test_input) == [607905,555370,607905,555370,1,555370,1,97200,1,1]\n\ntest_input = { \"edges\": [[3,2],[7,3],[4,8],[1,5],[6,7],[0,7],[8,1],[0,1],[9,0]], \"cost\": [25,-2,22,-40,-53,-17,-97,-49,29,36] }\nassert my_solution.placedCoins(**test_input) == [185076,26129,1,1,1,1,1,104566,1,1]\n\ntest_input = { \"edges\": [[1,8],[2,6],[7,2],[7,3],[8,3],[8,4],[5,4],[5,0],[9,0]], \"cost\": [-54,-16,51,-79,73,-83,-54,5,45,14] }\nassert my_solution.placedCoins(**test_input) == [478661,1,1,217566,311418,478661,1,0,217566,1]\n\ntest_input = { \"edges\": [[3,1],[4,0],[1,5],[6,1],[6,0],[9,7],[0,8],[0,2],[2,9]], \"cost\": [23,-50,-5,-36,-49,49,39,-82,-8,81] }\nassert my_solution.placedCoins(**test_input) == [332100,88200,33210,1,1,1,88200,1,1,1]\n\ntest_input = { \"edges\": [[0,7],[8,1],[5,7],[8,2],[2,3],[3,7],[4,7],[4,6],[6,9]], \"cost\": [-12,-83,-3,-43,12,48,-46,19,-92,69] }\nassert my_solution.placedCoins(**test_input) == [526884,1,0,0,0,1,1,526884,1,1]\n\ntest_input = { \"edges\": [[0,1],[2,5],[7,2],[7,6],[1,8],[1,3],[3,7],[4,7],[9,4]], \"cost\": [56,61,-17,-3,-100,-28,81,42,1,-86] }\nassert my_solution.placedCoins(**test_input) == [696600,696600,1,696600,1,1,1,696600,1,1]\n\ntest_input = { \"edges\": [[0,3],[8,1],[3,6],[5,3],[2,8],[4,2],[4,7],[7,5],[5,9]], \"cost\": [-42,72,54,-46,57,95,94,21,-19,-92] }\nassert my_solution.placedCoins(**test_input) == [642960,1,0,642960,221616,389880,1,221616,1,1]\n\ntest_input = { \"edges\": [[2,0],[2,4],[6,5],[8,6],[3,7],[3,1],[1,8],[2,1],[2,9]], \"cost\": [-58,-82,-70,33,20,-40,21,-93,18,-6] }\nassert my_solution.placedCoins(**test_input) == [251658,251658,251658,1,1,1,1,1,0,1]\n\ntest_input = { \"edges\": [[1,5],[3,0],[0,2],[2,4],[5,2],[7,2],[6,7],[8,7],[7,9]], \"cost\": [-96,-98,41,59,-69,-51,-78,43,-40,-8] }\nassert my_solution.placedCoins(**test_input) == [555072,1,328692,1,1,1,1,134160,1,1]\n\ntest_input = { \"edges\": [[0,4],[1,4],[3,6],[5,7],[4,6],[7,2],[4,2],[4,9],[9,8]], \"cost\": [-98,-100,-37,62,38,-54,56,56,1,-72] }\nassert my_solution.placedCoins(**test_input) == [607600,1,111888,1,446400,1,1,1,1,1]\n\ntest_input = { \"edges\": [[8,0],[4,3],[6,3],[5,7],[6,8],[8,2],[1,2],[7,1],[9,7]], \"cost\": [-70,-59,-87,-64,56,-15,-62,-48,-58,-85] }\nassert my_solution.placedCoins(**test_input) == [414120,0,0,1,1,1,222208,0,414120,1]\n\ntest_input = { \"edges\": [[3,0],[1,8],[6,2],[5,3],[4,5],[8,4],[7,8],[8,6],[6,9]], \"cost\": [-56,-14,-44,-2,31,34,-61,53,-39,-21] }\nassert my_solution.placedCoins(**test_input) == [181048,1,1,142252,142252,142252,0,1,142252,1]\n\ntest_input = { \"edges\": [[2,1],[1,3],[5,8],[9,6],[8,1],[1,4],[4,0],[7,0],[7,9]], \"cost\": [-18,-10,25,-60,-48,4,14,38,26,16] }\nassert my_solution.placedCoins(**test_input) == [109440,15600,1,1,74880,1,1,8512,1,1]\n\ntest_input = { \"edges\": [[0,2],[2,5],[3,4],[5,3],[6,8],[7,1],[5,1],[5,9],[8,9]], \"cost\": [46,96,34,76,19,29,-36,48,-71,-45] }\nassert my_solution.placedCoins(**test_input) == [350208,1,350208,1,1,350208,1,1,1,0]\n\ntest_input = { \"edges\": [[0,2],[7,2],[3,4],[4,7],[5,1],[6,1],[7,6],[9,6],[8,9]], \"cost\": [4,70,65,-34,-59,-70,-83,-21,66,-10] }\nassert my_solution.placedCoins(**test_input) == [406700,1,406700,1,1,1,406700,406700,1,1]\n\ntest_input = { \"edges\": [[0,1],[2,3],[5,2],[9,2],[6,9],[9,7],[1,8],[4,1],[9,4]], \"cost\": [54,72,-52,45,-62,96,-54,28,-76,86] }\nassert my_solution.placedCoins(**test_input) == [594432,594432,0,1,371520,1,1,1,1,371520]\n\ntest_input = { \"edges\": [[1,0],[0,4],[3,5],[6,7],[6,3],[3,8],[8,0],[0,2],[9,2]], \"cost\": [-98,-85,82,-30,64,-76,36,-54,84,85] }\nassert my_solution.placedCoins(**test_input) == [708050,1,1,147744,1,1,1,1,344736,1]\n\ntest_input = { \"edges\": [[0,8],[2,6],[4,7],[5,1],[1,9],[3,7],[3,8],[6,8],[9,6]], \"cost\": [60,-76,-76,38,-5,-33,-80,-36,28,63] }\nassert my_solution.placedCoins(**test_input) == [383040,1,1,6840,1,1,383040,1,383040,158004]\n\ntest_input = { \"edges\": [[5,3],[6,5],[7,6],[6,2],[2,1],[0,1],[0,9],[4,8],[4,9]], \"cost\": [-56,-92,-10,-70,52,22,43,37,88,48] }\nassert my_solution.placedCoins(**test_input) == [566720,276920,35002,1,1,1,35002,1,1,219648]\n\ntest_input = { \"edges\": [[8,2],[9,4],[1,7],[3,1],[3,5],[5,8],[5,0],[0,6],[9,6]], \"cost\": [-70,17,-31,41,-93,17,-19,21,-66,-29] }\nassert my_solution.placedCoins(**test_input) == [266910,1,1,14637,1,83886,0,1,1,1]\n\ntest_input = { \"edges\": [[8,1],[2,4],[7,3],[2,3],[2,6],[6,5],[0,5],[0,8],[9,8]], \"cost\": [88,86,55,-61,3,-70,12,44,-92,-72] }\nassert my_solution.placedCoins(**test_input) == [582912,1,7260,1,1,234850,29040,1,569664,1]\n\ntest_input = { \"edges\": [[0,7],[1,3],[1,6],[4,2],[6,2],[5,6],[5,9],[7,8],[9,8]], \"cost\": [15,78,-48,58,-27,28,60,-9,-64,-71] }\nassert my_solution.placedCoins(**test_input) == [354432,1,1,1,1,271440,271440,354432,354432,271440]\n\ntest_input = { \"edges\": [[4,0],[8,0],[5,6],[8,6],[6,1],[7,1],[3,7],[2,3],[9,2]], \"cost\": [14,10,10,-73,-43,19,92,62,16,-27] }\nassert my_solution.placedCoins(**test_input) == [288788,122202,1,19710,1,1,181332,122202,181332,1]\n\ntest_input = { \"edges\": [[8,0],[3,1],[1,2],[8,5],[6,7],[4,7],[9,4],[2,8],[2,9]], \"cost\": [97,35,-74,5,65,5,86,61,-55,53] }\nassert my_solution.placedCoins(**test_input) == [542230,1,340990,1,340990,1,1,1,350020,340990]\n\ntest_input = { \"edges\": [[0,1],[7,0],[8,2],[3,4],[4,7],[4,8],[4,6],[5,6],[9,5]], \"cost\": [-74,40,73,-97,-62,9,-96,-98,-38,63] }\nassert my_solution.placedCoins(**test_input) == [693938,1,1,1,679776,1,0,693938,1,1]\n\ntest_input = { \"edges\": [[2,3],[0,3],[0,6],[6,5],[7,1],[1,5],[8,5],[4,5],[9,4]], \"cost\": [4,-30,59,61,78,-22,-24,85,-19,-89] }\nassert my_solution.placedCoins(**test_input) == [404430,1,1,1,1,226950,226950,1,1,1]\n\ntest_input = { \"edges\": [[1,2],[5,4],[5,6],[7,1],[3,1],[3,5],[5,8],[0,5],[0,9]], \"cost\": [11,-80,95,64,-76,56,61,22,13,-58] }\nassert my_solution.placedCoins(**test_input) == [577600,0,1,133760,1,577600,1,1,1,1]\n\ntest_input = { \"edges\": [[1,9],[2,7],[3,5],[4,3],[0,4],[0,6],[8,0],[7,0],[9,7]], \"cost\": [-69,18,-39,-59,-48,-65,97,1,74,-63] }\nassert my_solution.placedCoins(**test_input) == [435045,1,1,1,0,1,1,44226,1,1]\n\ntest_input = { \"edges\": [[0,6],[1,4],[5,4],[6,8],[3,8],[5,3],[5,2],[7,2],[9,7]], \"cost\": [-84,27,16,75,49,4,72,46,-17,48] }\nassert my_solution.placedCoins(**test_input) == [264600,1,35328,176400,1,108192,264600,1,176400,1]\n\ntest_input = { \"edges\": [[0,9],[1,7],[6,3],[8,7],[7,3],[5,3],[2,5],[2,4],[4,9]], \"cost\": [1,-53,88,-67,-55,-31,-89,-39,21,-96] }\nassert my_solution.placedCoins(**test_input) == [751872,1,524744,125223,524744,125223,1,43407,1,751872]\n\ntest_input = { \"edges\": [[3,6],[0,6],[8,0],[7,4],[4,1],[2,1],[2,9],[8,5],[9,5]], \"cost\": [78,-10,-51,-50,-55,-72,-7,31,-94,4] }\nassert my_solution.placedCoins(**test_input) == [527904,17050,86955,1,1,122760,1,1,209808,86955]\n\ntest_input = { \"edges\": [[2,5],[4,7],[4,5],[5,3],[3,6],[6,0],[1,0],[8,1],[9,8]], \"cost\": [-19,93,-23,-86,54,-70,-70,9,69,13] }\nassert my_solution.placedCoins(**test_input) == [559860,83421,1,325080,1,86940,325080,1,1,1]\n\ntest_input = { \"edges\": [[2,7],[3,9],[7,5],[4,5],[4,1],[6,1],[6,0],[8,0],[0,9]], \"cost\": [45,-53,-16,-26,99,50,33,-57,-97,74] }\nassert my_solution.placedCoins(**test_input) == [547371,299079,1,1,90288,45600,299079,1,1,1]\n\ntest_input = { \"edges\": [[5,0],[9,1],[3,6],[2,4],[2,6],[6,9],[8,7],[7,5],[5,9]], \"cost\": [-14,-4,-49,52,-45,77,-17,-79,21,-33] }\nassert my_solution.placedCoins(**test_input) == [298067,1,1,1,1,298067,114660,1,1,114660]\n\ntest_input = { \"edges\": [[6,3],[7,0],[2,0],[2,4],[9,4],[1,8],[1,6],[5,6],[9,5]], \"cost\": [-58,-55,17,68,37,-32,91,-63,79,69] }\nassert my_solution.placedCoins(**test_input) == [496041,1,496041,1,496041,488852,488852,1,1,496041]\n\ntest_input = { \"edges\": [[1,8],[0,3],[2,4],[0,2],[8,5],[0,5],[7,0],[7,6],[9,6]], \"cost\": [-8,-99,36,31,94,5,-35,54,33,19] }\nassert my_solution.placedCoins(**test_input) == [325710,1,1,1,1,0,1,0,1,1]\n\ntest_input = { \"edges\": [[1,0],[1,7],[3,4],[4,5],[5,6],[7,5],[5,2],[8,2],[2,9]], \"cost\": [70,-75,-13,30,-87,20,-67,76,20,-30] }\nassert my_solution.placedCoins(**test_input) == [495900,495900,7800,1,1,174870,1,443004,1,1]\n\ntest_input = { \"edges\": [[5,1],[2,1],[0,2],[6,0],[0,3],[3,7],[9,7],[4,8],[9,4]], \"cost\": [-10,-31,-7,-77,64,-80,-53,37,1,10] }\nassert my_solution.placedCoins(**test_input) == [394240,1,0,23680,1,1,1,23680,1,640]\n\ntest_input = { \"edges\": [[2,0],[1,2],[2,8],[4,3],[4,7],[5,9],[6,9],[8,7],[7,9]], \"cost\": [-80,77,-18,-72,11,66,82,80,32,61] }\nassert my_solution.placedCoins(**test_input) == [505120,1,505120,1,1,1,1,432960,432960,330132]\n\ntest_input = { \"edges\": [[0,3],[1,0],[1,8],[5,4],[9,6],[7,4],[9,4],[8,2],[9,2]], \"cost\": [70,-14,-91,98,-12,30,-24,79,-62,11] }\nassert my_solution.placedCoins(**test_input) == [552916,445718,172536,1,0,1,1,1,445718,26070]\n\ntest_input = { \"edges\": [[5,8],[2,6],[2,0],[0,3],[7,8],[8,4],[3,4],[1,3],[1,9]], \"cost\": [55,69,29,87,27,-35,-83,71,-82,-8] }\nassert my_solution.placedCoins(**test_input) == [592122,1,1,426213,203770,1,1,1,203770,1]\n\ntest_input = { \"edges\": [[1,9],[5,4],[5,3],[6,3],[6,2],[2,8],[0,7],[0,9],[8,9]], \"cost\": [-25,28,47,-75,-78,-39,23,93,-20,61] }\nassert my_solution.placedCoins(**test_input) == [544050,1,274950,0,1,1,134550,1,274950,356850]\n\ntest_input = { \"edges\": [[5,0],[1,8],[6,4],[4,9],[7,3],[8,5],[3,5],[3,2],[9,2]], \"cost\": [-11,-91,-54,53,58,16,-60,85,20,51] }\nassert my_solution.placedCoins(**test_input) == [464100,1,187920,275400,1,464100,1,1,1,0]\n\ntest_input = { \"edges\": [[1,3],[1,4],[2,4],[6,5],[7,5],[0,5],[9,0],[8,2],[9,2]], \"cost\": [-74,26,99,58,42,-55,-1,-56,29,-35] }\nassert my_solution.placedCoins(**test_input) == [410256,1,241164,1,63336,0,1,1,1,241164]\n\ntest_input = { \"edges\": [[2,5],[5,3],[0,4],[5,9],[6,1],[7,1],[7,0],[0,9],[8,9]], \"cost\": [72,68,-18,95,87,-58,-55,20,40,2] }\nassert my_solution.placedCoins(**test_input) == [595080,1,1,1,1,99180,1,0,1,99180]\n\ntest_input = { \"edges\": [[1,6],[3,2],[9,3],[6,5],[5,9],[7,0],[4,8],[0,4],[0,9]], \"cost\": [85,19,-56,-71,41,-72,59,30,55,67] }\nassert my_solution.placedCoins(**test_input) == [434520,1,1,1,1,0,1,1,1,342504]\n\ntest_input = { \"edges\": [[2,1],[7,1],[0,3],[8,4],[0,5],[7,6],[0,6],[8,0],[9,8]], \"cost\": [13,4,84,36,29,-97,-59,-40,77,41] }\nassert my_solution.placedCoins(**test_input) == [480732,1,1,1,1,1,198240,0,91553,1]\n\ntest_input = { \"edges\": [[2,1],[4,5],[6,3],[1,3],[1,0],[7,0],[8,7],[5,8],[9,5]], \"cost\": [85,64,-67,-60,5,-14,31,-84,47,-36] }\nassert my_solution.placedCoins(**test_input) == [478380,257280,1,1,1,2520,1,142128,23688,1]\n\ntest_input = { \"edges\": [[6,1],[4,2],[7,4],[5,7],[0,8],[6,0],[3,6],[7,3],[7,9]], \"cost\": [-51,-55,82,25,-53,13,-15,98,39,29] }\nassert my_solution.placedCoins(**test_input) == [313404,1,1,233044,1,1,285670,233044,1,1]\n\ntest_input = { \"edges\": [[0,2],[5,1],[6,2],[7,3],[5,4],[5,9],[6,9],[7,9],[8,9]], \"cost\": [-96,-75,-58,26,-73,-25,-9,87,57,3] }\nassert my_solution.placedCoins(**test_input) == [626400,1,476325,1,1,0,476325,1,1,476325]\n\ntest_input = { \"edges\": [[0,4],[0,9],[5,1],[2,6],[3,7],[3,8],[1,8],[1,2],[2,9]], \"cost\": [-58,20,21,77,-96,53,-77,-66,-32,42] }\nassert my_solution.placedCoins(**test_input) == [569184,162624,391314,1,1,1,1,1,162624,391314]\n\ntest_input = { \"edges\": [[2,4],[5,2],[6,3],[3,0],[7,5],[8,5],[1,8],[1,0],[0,9]], \"cost\": [-59,-25,-25,-78,22,29,9,-12,-11,-5] }\nassert my_solution.placedCoins(**test_input) == [133458,18125,1,1,1,8700,1,1,8700,1]\n\ntest_input = { \"edges\": [[8,1],[3,2],[5,4],[6,3],[0,3],[8,5],[5,7],[7,0],[9,0]], \"cost\": [86,-87,-96,-74,51,75,-76,74,-2,-60] }\nassert my_solution.placedCoins(**test_input) == [718272,1,1,0,1,13050,1,283050,1,1]", "start_time": 1703341800} +{"task_id": "weekly-contest-376-find-missing-and-repeated-values", "url": "https://leetcode.com/problems/find-missing-and-repeated-values", "title": "find-missing-and-repeated-values", "meta": {"questionId": "3227", "questionFrontendId": "2965", "title": "Find Missing and Repeated Values", "titleSlug": "find-missing-and-repeated-values", "isPaidOnly": false, "difficulty": "Easy", "likes": 90, "dislikes": 3, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed 2D integer matrix grid of size n * n with values in the range [1, n2]. Each integer appears exactly once except a which appears twice and b which is missing. The task is to find the repeating and missing numbers a and b.\nReturn a 0-indexed integer array ans of size 2 where ans[0] equals to a and ans[1] equals to b.\n\nExample 1:\n\nInput: grid = [[1,3],[2,2]]\nOutput: [2,4]\nExplanation: Number 2 is repeated and number 4 is missing so the answer is [2,4].\n\nExample 2:\n\nInput: grid = [[9,1,7],[8,9,2],[3,4,6]]\nOutput: [9,5]\nExplanation: Number 9 is repeated and number 5 is missing so the answer is [9,5].\n\n\nConstraints:\n\n2 <= n == grid.length == grid[i].length <= 50\n1 <= grid[i][j] <= n * n\nFor all x that 1 <= x <= n * n there is exactly one x that is not equal to any of the grid members.\nFor all x that 1 <= x <= n * n there is exactly one x that is equal to exactly two of the grid members.\nFor all x that 1 <= x <= n * n except two of them there is exatly one pair of i, j that 0 <= i, j <= n - 1 and grid[i][j] == x.\n\"\"\"\nclass Solution:\n def findMissingAndRepeatedValues(self, grid: List[List[int]]) -> List[int]:\n ", "prompt_sft": "You are given a 0-indexed 2D integer matrix grid of size n * n with values in the range [1, n2]. Each integer appears exactly once except a which appears twice and b which is missing. The task is to find the repeating and missing numbers a and b.\nReturn a 0-indexed integer array ans of size 2 where ans[0] equals to a and ans[1] equals to b.\n\nExample 1:\n\nInput: grid = [[1,3],[2,2]]\nOutput: [2,4]\nExplanation: Number 2 is repeated and number 4 is missing so the answer is [2,4].\n\nExample 2:\n\nInput: grid = [[9,1,7],[8,9,2],[3,4,6]]\nOutput: [9,5]\nExplanation: Number 9 is repeated and number 5 is missing so the answer is [9,5].\n\n\nConstraints:\n\n2 <= n == grid.length == grid[i].length <= 50\n1 <= grid[i][j] <= n * n\nFor all x that 1 <= x <= n * n there is exactly one x that is not equal to any of the grid members.\nFor all x that 1 <= x <= n * n there is exactly one x that is equal to exactly two of the grid members.\nFor all x that 1 <= x <= n * n except two of them there is exatly one pair of i, j that 0 <= i, j <= n - 1 and grid[i][j] == x.\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def findMissingAndRepeatedValues(self, grid: List[List[int]]) -> List[int]:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"grid\": [[1,3],[2,2]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [2,4]\n\ntest_input = { \"grid\": [[9,1,7],[8,9,2],[3,4,6]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [9,5]\n\ntest_input = { \"grid\": [[1,1],[3,2]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [1,4]\n\ntest_input = { \"grid\": [[1,1],[3,4]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [1,2]\n\ntest_input = { \"grid\": [[1,2],[1,3]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [1,4]\n\ntest_input = { \"grid\": [[1,2],[1,4]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [1,3]\n\ntest_input = { \"grid\": [[1,2],[3,3]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [3,4]\n\ntest_input = { \"grid\": [[1,2],[4,1]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [1,3]\n\ntest_input = { \"grid\": [[1,2],[4,2]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [2,3]\n\ntest_input = { \"grid\": [[1,2],[4,4]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [4,3]\n\ntest_input = { \"grid\": [[1,4],[1,3]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [1,2]\n\ntest_input = { \"grid\": [[1,4],[2,1]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [1,3]\n\ntest_input = { \"grid\": [[1,4],[3,1]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [1,2]\n\ntest_input = { \"grid\": [[1,4],[3,4]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [4,2]\n\ntest_input = { \"grid\": [[1,4],[4,2]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [4,3]\n\ntest_input = { \"grid\": [[2,1],[4,2]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [2,3]\n\ntest_input = { \"grid\": [[2,1],[4,4]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [4,3]\n\ntest_input = { \"grid\": [[2,2],[3,4]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [2,1]\n\ntest_input = { \"grid\": [[2,2],[4,1]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [2,3]\n\ntest_input = { \"grid\": [[2,3],[2,1]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [2,4]\n\ntest_input = { \"grid\": [[2,3],[4,3]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [3,1]\n\ntest_input = { \"grid\": [[2,4],[3,2]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [2,1]\n\ntest_input = { \"grid\": [[2,4],[3,4]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [4,1]\n\ntest_input = { \"grid\": [[2,4],[4,1]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [4,3]\n\ntest_input = { \"grid\": [[3,1],[3,2]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [3,4]\n\ntest_input = { \"grid\": [[3,1],[3,4]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [3,2]\n\ntest_input = { \"grid\": [[3,1],[4,4]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [4,2]\n\ntest_input = { \"grid\": [[3,3],[1,4]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [3,2]\n\ntest_input = { \"grid\": [[3,4],[2,2]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [2,1]\n\ntest_input = { \"grid\": [[3,4],[2,4]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [4,1]\n\ntest_input = { \"grid\": [[3,4],[3,1]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [3,2]\n\ntest_input = { \"grid\": [[3,4],[4,1]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [4,2]\n\ntest_input = { \"grid\": [[4,1],[1,2]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [1,3]\n\ntest_input = { \"grid\": [[4,1],[2,2]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [2,3]\n\ntest_input = { \"grid\": [[4,1],[2,4]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [4,3]\n\ntest_input = { \"grid\": [[4,1],[3,1]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [1,2]\n\ntest_input = { \"grid\": [[4,1],[3,3]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [3,2]\n\ntest_input = { \"grid\": [[4,1],[4,2]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [4,3]\n\ntest_input = { \"grid\": [[4,2],[2,3]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [2,1]\n\ntest_input = { \"grid\": [[4,2],[4,1]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [4,3]\n\ntest_input = { \"grid\": [[4,3],[1,1]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [1,2]\n\ntest_input = { \"grid\": [[4,3],[2,2]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [2,1]\n\ntest_input = { \"grid\": [[4,3],[2,4]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [4,1]\n\ntest_input = { \"grid\": [[4,3],[3,1]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [3,2]\n\ntest_input = { \"grid\": [[4,4],[2,3]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [4,1]\n\ntest_input = { \"grid\": [[1,3,4],[9,7,5],[8,2,3]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [3,6]\n\ntest_input = { \"grid\": [[1,5,2],[8,4,3],[7,8,6]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [8,9]\n\ntest_input = { \"grid\": [[1,5,8],[2,7,3],[6,1,4]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [1,9]\n\ntest_input = { \"grid\": [[1,6,1],[4,3,7],[5,2,8]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [1,9]\n\ntest_input = { \"grid\": [[1,6,4],[9,7,5],[7,8,2]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [7,3]\n\ntest_input = { \"grid\": [[1,6,7],[3,6,8],[9,5,4]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [6,2]\n\ntest_input = { \"grid\": [[1,7,4],[8,6,2],[8,3,5]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [8,9]\n\ntest_input = { \"grid\": [[1,7,8],[4,5,6],[3,9,9]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [9,2]\n\ntest_input = { \"grid\": [[1,8,4],[9,2,7],[6,3,8]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [8,5]\n\ntest_input = { \"grid\": [[1,8,5],[4,3,2],[7,9,4]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [4,6]\n\ntest_input = { \"grid\": [[1,9,3],[2,7,8],[2,4,5]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [2,6]\n\ntest_input = { \"grid\": [[1,9,7],[8,4,2],[6,3,9]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [9,5]\n\ntest_input = { \"grid\": [[2,1,3],[2,9,4],[6,8,5]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [2,7]\n\ntest_input = { \"grid\": [[2,2,4],[7,5,3],[1,6,8]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [2,9]\n\ntest_input = { \"grid\": [[2,3,9],[5,6,4],[2,8,7]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [2,1]\n\ntest_input = { \"grid\": [[2,4,6],[4,8,9],[7,3,5]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [4,1]\n\ntest_input = { \"grid\": [[2,5,5],[4,8,7],[9,3,6]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [5,1]\n\ntest_input = { \"grid\": [[2,6,4],[6,9,5],[3,7,8]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [6,1]\n\ntest_input = { \"grid\": [[2,6,9],[1,7,9],[4,8,5]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [9,3]\n\ntest_input = { \"grid\": [[2,7,1],[8,6,2],[9,3,4]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [2,5]\n\ntest_input = { \"grid\": [[2,7,5],[7,6,4],[1,3,9]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [7,8]\n\ntest_input = { \"grid\": [[2,7,9],[6,8,1],[4,1,5]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [1,3]\n\ntest_input = { \"grid\": [[2,9,7],[8,5,1],[6,7,4]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [7,3]\n\ntest_input = { \"grid\": [[3,4,5],[8,2,4],[6,1,7]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [4,9]\n\ntest_input = { \"grid\": [[3,5,7],[8,6,9],[1,5,2]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [5,4]\n\ntest_input = { \"grid\": [[3,6,1],[5,9,2],[1,7,8]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [1,4]\n\ntest_input = { \"grid\": [[3,9,4],[3,6,1],[5,7,2]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [3,8]\n\ntest_input = { \"grid\": [[4,2,6],[3,5,8],[3,1,9]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [3,7]\n\ntest_input = { \"grid\": [[4,3,2],[6,9,9],[8,7,5]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [9,1]\n\ntest_input = { \"grid\": [[4,6,5],[3,5,7],[2,8,9]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [5,1]\n\ntest_input = { \"grid\": [[4,8,7],[4,6,9],[3,2,1]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [4,5]\n\ntest_input = { \"grid\": [[4,9,6],[2,5,8],[3,7,7]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [7,1]\n\ntest_input = { \"grid\": [[5,3,6],[1,4,2],[9,8,2]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [2,7]\n\ntest_input = { \"grid\": [[5,6,9],[3,7,8],[2,2,4]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [2,1]\n\ntest_input = { \"grid\": [[5,7,8],[1,3,2],[7,6,9]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [7,4]\n\ntest_input = { \"grid\": [[6,1,3],[2,4,2],[8,9,7]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [2,5]\n\ntest_input = { \"grid\": [[6,4,2],[3,7,8],[5,6,9]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [6,1]\n\ntest_input = { \"grid\": [[6,4,5],[7,9,3],[1,2,9]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [9,8]\n\ntest_input = { \"grid\": [[6,4,8],[8,1,2],[9,3,7]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [8,5]\n\ntest_input = { \"grid\": [[6,9,3],[8,9,7],[5,4,2]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [9,1]\n\ntest_input = { \"grid\": [[7,2,1],[6,5,3],[2,9,4]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [2,8]\n\ntest_input = { \"grid\": [[7,2,4],[5,8,7],[9,3,1]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [7,6]\n\ntest_input = { \"grid\": [[7,3,1],[8,9,2],[4,5,2]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [2,6]\n\ntest_input = { \"grid\": [[7,4,2],[9,1,9],[8,3,5]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [9,6]\n\ntest_input = { \"grid\": [[7,4,8],[1,1,3],[2,6,9]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [1,5]\n\ntest_input = { \"grid\": [[7,5,3],[4,6,3],[9,2,8]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [3,1]\n\ntest_input = { \"grid\": [[7,5,7],[3,1,6],[8,9,4]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [7,2]\n\ntest_input = { \"grid\": [[8,2,6],[1,8,9],[4,5,3]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [8,7]\n\ntest_input = { \"grid\": [[8,2,7],[3,5,1],[9,6,3]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [3,4]\n\ntest_input = { \"grid\": [[8,6,3],[1,9,5],[5,4,7]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [5,2]\n\ntest_input = { \"grid\": [[8,6,5],[3,9,1],[8,7,4]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [8,2]\n\ntest_input = { \"grid\": [[8,9,6],[6,1,3],[2,7,5]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [6,4]\n\ntest_input = { \"grid\": [[8,9,6],[7,4,2],[7,1,5]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [7,3]\n\ntest_input = { \"grid\": [[9,2,3],[7,6,4],[5,8,8]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [8,1]\n\ntest_input = { \"grid\": [[9,2,7],[3,8,7],[1,5,4]] }\nassert my_solution.findMissingAndRepeatedValues(**test_input) == [7,6]", "start_time": 1702780200} +{"task_id": "weekly-contest-376-divide-array-into-arrays-with-max-difference", "url": "https://leetcode.com/problems/divide-array-into-arrays-with-max-difference", "title": "divide-array-into-arrays-with-max-difference", "meta": {"questionId": "3241", "questionFrontendId": "2966", "title": "Divide Array Into Arrays With Max Difference", "titleSlug": "divide-array-into-arrays-with-max-difference", "isPaidOnly": false, "difficulty": "Medium", "likes": 95, "dislikes": 20, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given an integer array nums of size n and a positive integer k.\nDivide the array into one or more arrays of size 3 satisfying the following conditions:\n\nEach element of nums should be in exactly one array.\nThe difference between any two elements in one array is less than or equal to k.\n\nReturn a 2D array containing all the arrays. If it is impossible to satisfy the conditions, return an empty array. And if there are multiple answers, return any of them.\n\nExample 1:\n\nInput: nums = [1,3,4,8,7,9,3,5,1], k = 2\nOutput: [[1,1,3],[3,4,5],[7,8,9]]\nExplanation: We can divide the array into the following arrays: [1,1,3], [3,4,5] and [7,8,9].\nThe difference between any two elements in each array is less than or equal to 2.\nNote that the order of elements is not important.\n\nExample 2:\n\nInput: nums = [1,3,3,2,7,3], k = 3\nOutput: []\nExplanation: It is not possible to divide the array satisfying all the conditions.\n\n\nConstraints:\n\nn == nums.length\n1 <= n <= 105\nn is a multiple of 3.\n1 <= nums[i] <= 105\n1 <= k <= 105\n\"\"\"\nclass Solution:\n def divideArray(self, nums: List[int], k: int) -> List[List[int]]:\n ", "prompt_sft": "You are given an integer array nums of size n and a positive integer k.\nDivide the array into one or more arrays of size 3 satisfying the following conditions:\n\nEach element of nums should be in exactly one array.\nThe difference between any two elements in one array is less than or equal to k.\n\nReturn a 2D array containing all the arrays. If it is impossible to satisfy the conditions, return an empty array. And if there are multiple answers, return any of them.\n\nExample 1:\n\nInput: nums = [1,3,4,8,7,9,3,5,1], k = 2\nOutput: [[1,1,3],[3,4,5],[7,8,9]]\nExplanation: We can divide the array into the following arrays: [1,1,3], [3,4,5] and [7,8,9].\nThe difference between any two elements in each array is less than or equal to 2.\nNote that the order of elements is not important.\n\nExample 2:\n\nInput: nums = [1,3,3,2,7,3], k = 3\nOutput: []\nExplanation: It is not possible to divide the array satisfying all the conditions.\n\n\nConstraints:\n\nn == nums.length\n1 <= n <= 105\nn is a multiple of 3.\n1 <= nums[i] <= 105\n1 <= k <= 105\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def divideArray(self, nums: List[int], k: int) -> List[List[int]]:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,3,4,8,7,9,3,5,1], \"k\": 2 }\nassert my_solution.divideArray(**test_input) == [[1,1,3],[3,4,5],[7,8,9]]\n\ntest_input = { \"nums\": [1,3,3,2,7,3], \"k\": 3 }\nassert my_solution.divideArray(**test_input) == []\n\ntest_input = { \"nums\": [4,2,9,8,2,12,7,12,10,5,8,5,5,7,9,2,5,11], \"k\": 14 }\nassert my_solution.divideArray(**test_input) == [[2,2,2],[4,5,5],[5,5,7],[7,8,8],[9,9,10],[11,12,12]]\n\ntest_input = { \"nums\": [33,26,4,18,16,24,24,15,8,18,34,20,24,16,3], \"k\": 16 }\nassert my_solution.divideArray(**test_input) == [[3,4,8],[15,16,16],[18,18,20],[24,24,24],[26,33,34]]\n\ntest_input = { \"nums\": [6,1,8,8,5,8,5,9,8,9,5,8,3,4,6], \"k\": 7 }\nassert my_solution.divideArray(**test_input) == [[1,3,4],[5,5,5],[6,6,8],[8,8,8],[8,9,9]]\n\ntest_input = { \"nums\": [20,21,34,3,19,2,23,32,20,17,14,13,19,20,6], \"k\": 15 }\nassert my_solution.divideArray(**test_input) == [[2,3,6],[13,14,17],[19,19,20],[20,20,21],[23,32,34]]\n\ntest_input = { \"nums\": [6,10,5,12,7,11,6,6,12,12,11,7], \"k\": 2 }\nassert my_solution.divideArray(**test_input) == [[5,6,6],[6,7,7],[10,11,11],[12,12,12]]\n\ntest_input = { \"nums\": [12,15,26,7,10,13,15,5,27,16,14,15], \"k\": 18 }\nassert my_solution.divideArray(**test_input) == [[5,7,10],[12,13,14],[15,15,15],[16,26,27]]\n\ntest_input = { \"nums\": [12,7,13,10,7,19,11,23,3,3,7,9], \"k\": 16 }\nassert my_solution.divideArray(**test_input) == [[3,3,7],[7,7,9],[10,11,12],[13,19,23]]\n\ntest_input = { \"nums\": [19,3,23,4,8,1,1,3,26], \"k\": 7 }\nassert my_solution.divideArray(**test_input) == [[1,1,3],[3,4,8],[19,23,26]]\n\ntest_input = { \"nums\": [11,13,24,11,9,23,16,19,13], \"k\": 8 }\nassert my_solution.divideArray(**test_input) == [[9,11,11],[13,13,16],[19,23,24]]\n\ntest_input = { \"nums\": [6,12,21,12,6,12,25,20,15,22,11,19,8,4,18,26,17,18,12,5,8], \"k\": 11 }\nassert my_solution.divideArray(**test_input) == [[4,5,6],[6,8,8],[11,12,12],[12,12,15],[17,18,18],[19,20,21],[22,25,26]]\n\ntest_input = { \"nums\": [15,17,14,3,25,15,11,25,15,16,12,18], \"k\": 10 }\nassert my_solution.divideArray(**test_input) == [[3,11,12],[14,15,15],[15,16,17],[18,25,25]]\n\ntest_input = { \"nums\": [16,20,16,19,20,13,14,20,14], \"k\": 10 }\nassert my_solution.divideArray(**test_input) == [[13,14,14],[16,16,19],[20,20,20]]\n\ntest_input = { \"nums\": [2,13,15,14,18,15,3,13,2], \"k\": 1 }\nassert my_solution.divideArray(**test_input) == []\n\ntest_input = { \"nums\": [1,14,20,7,17,2,14,1,8], \"k\": 11 }\nassert my_solution.divideArray(**test_input) == [[1,1,2],[7,8,14],[14,17,20]]\n\ntest_input = { \"nums\": [8,12,19,8,9,19,9,19,9,8,6,9,6,6,12], \"k\": 3 }\nassert my_solution.divideArray(**test_input) == [[6,6,6],[8,8,8],[9,9,9],[9,12,12],[19,19,19]]\n\ntest_input = { \"nums\": [18,16,17,19,12,25,11,27,11,32,32,17], \"k\": 20 }\nassert my_solution.divideArray(**test_input) == [[11,11,12],[16,17,17],[18,19,25],[27,32,32]]\n\ntest_input = { \"nums\": [21,11,24,20,17,13,7,20,20,16,24,20,12,17,16,15,7,7,18,15,20], \"k\": 6 }\nassert my_solution.divideArray(**test_input) == [[7,7,7],[11,12,13],[15,15,16],[16,17,17],[18,20,20],[20,20,20],[21,24,24]]\n\ntest_input = { \"nums\": [6,7,7,6,7,6], \"k\": 13 }\nassert my_solution.divideArray(**test_input) == [[6,6,6],[7,7,7]]\n\ntest_input = { \"nums\": [11,12,12,5,6,5], \"k\": 9 }\nassert my_solution.divideArray(**test_input) == [[5,5,6],[11,12,12]]\n\ntest_input = { \"nums\": [5,5,12,5,5,22,2,2,5,2,5,5,16,2,22,2,12,16,15,13,19], \"k\": 3 }\nassert my_solution.divideArray(**test_input) == [[2,2,2],[2,2,5],[5,5,5],[5,5,5],[12,12,13],[15,16,16],[19,22,22]]\n\ntest_input = { \"nums\": [11,28,12,5,19,15,16,9,21,13,12,9,19,19,18], \"k\": 9 }\nassert my_solution.divideArray(**test_input) == [[5,9,9],[11,12,12],[13,15,16],[18,19,19],[19,21,28]]\n\ntest_input = { \"nums\": [10,14,17], \"k\": 15 }\nassert my_solution.divideArray(**test_input) == [[10,14,17]]\n\ntest_input = { \"nums\": [16,15,9,20,17,19,11,18,16], \"k\": 9 }\nassert my_solution.divideArray(**test_input) == [[9,11,15],[16,16,17],[18,19,20]]\n\ntest_input = { \"nums\": [16,28,16,7,18,13,5,27,27,16,20,22,13,6,17], \"k\": 11 }\nassert my_solution.divideArray(**test_input) == [[5,6,7],[13,13,16],[16,16,17],[18,20,22],[27,27,28]]\n\ntest_input = { \"nums\": [14,7,13,2,3,7,17,13,13,2,14,7], \"k\": 3 }\nassert my_solution.divideArray(**test_input) == [[2,2,3],[7,7,7],[13,13,13],[14,14,17]]\n\ntest_input = { \"nums\": [20,8,6,5,10,5,10,2,20,6,12,13,13,20,4], \"k\": 6 }\nassert my_solution.divideArray(**test_input) == [[2,4,5],[5,6,6],[8,10,10],[12,13,13],[20,20,20]]\n\ntest_input = { \"nums\": [12,14,16,9,20,18,16,4,24,14,16,30,1,17,30,16,30,6], \"k\": 13 }\nassert my_solution.divideArray(**test_input) == [[1,4,6],[9,12,14],[14,16,16],[16,16,17],[18,20,24],[30,30,30]]\n\ntest_input = { \"nums\": [13,6,19,21,16,11,1,14,7], \"k\": 20 }\nassert my_solution.divideArray(**test_input) == [[1,6,7],[11,13,14],[16,19,21]]\n\ntest_input = { \"nums\": [13,2,12,22,18,15,3,20,2,18,3,14,2,10,14,9,14,3,14,17,5], \"k\": 9 }\nassert my_solution.divideArray(**test_input) == [[2,2,2],[3,3,3],[5,9,10],[12,13,14],[14,14,14],[15,17,18],[18,20,22]]\n\ntest_input = { \"nums\": [12,13,12,14,14,6,5,7,23,21,21,16,15,20,22,14,20,7], \"k\": 10 }\nassert my_solution.divideArray(**test_input) == [[5,6,7],[7,12,12],[13,14,14],[14,15,16],[20,20,21],[21,22,23]]\n\ntest_input = { \"nums\": [15,14,3,19,17,18,19,23,2,16,19,3], \"k\": 5 }\nassert my_solution.divideArray(**test_input) == [[2,3,3],[14,15,16],[17,18,19],[19,19,23]]\n\ntest_input = { \"nums\": [12,8,18,6,12,6,8,33,20,6,17,17,27,8,12], \"k\": 16 }\nassert my_solution.divideArray(**test_input) == [[6,6,6],[8,8,8],[12,12,12],[17,17,18],[20,27,33]]\n\ntest_input = { \"nums\": [1,1,23,17,18,1], \"k\": 12 }\nassert my_solution.divideArray(**test_input) == [[1,1,1],[17,18,23]]\n\ntest_input = { \"nums\": [13,13,3,7,6,13,6,4,3], \"k\": 1 }\nassert my_solution.divideArray(**test_input) == [[3,3,4],[6,6,7],[13,13,13]]\n\ntest_input = { \"nums\": [19,10,9,20,29,28,29,9,18,27,23,4,16,8,11,19,10,12,10,10,21], \"k\": 20 }\nassert my_solution.divideArray(**test_input) == [[4,8,9],[9,10,10],[10,10,11],[12,16,18],[19,19,20],[21,23,27],[28,29,29]]\n\ntest_input = { \"nums\": [13,12,12,11,22,10], \"k\": 15 }\nassert my_solution.divideArray(**test_input) == [[10,11,12],[12,13,22]]\n\ntest_input = { \"nums\": [15,16,12,34,16,16,24,21,3,24,29,10], \"k\": 20 }\nassert my_solution.divideArray(**test_input) == [[3,10,12],[15,16,16],[16,21,24],[24,29,34]]\n\ntest_input = { \"nums\": [17,16,17,11,13,6], \"k\": 19 }\nassert my_solution.divideArray(**test_input) == [[6,11,13],[16,17,17]]\n\ntest_input = { \"nums\": [11,16,16,6,8,20,21,3,20,11,16,6,6,11,6], \"k\": 3 }\nassert my_solution.divideArray(**test_input) == [[3,6,6],[6,6,8],[11,11,11],[16,16,16],[20,20,21]]\n\ntest_input = { \"nums\": [2,16,8,7,15,16], \"k\": 9 }\nassert my_solution.divideArray(**test_input) == [[2,7,8],[15,16,16]]\n\ntest_input = { \"nums\": [15,17,22], \"k\": 14 }\nassert my_solution.divideArray(**test_input) == [[15,17,22]]\n\ntest_input = { \"nums\": [8,4,9,18,18,5,10,11,19,18,19,23,4,15,25,20,20,6], \"k\": 7 }\nassert my_solution.divideArray(**test_input) == [[4,4,5],[6,8,9],[10,11,15],[18,18,18],[19,19,20],[20,23,25]]\n\ntest_input = { \"nums\": [12,20,16,12,15,16,15,20,14,16,19,13], \"k\": 1 }\nassert my_solution.divideArray(**test_input) == [[12,12,13],[14,15,15],[16,16,16],[19,20,20]]\n\ntest_input = { \"nums\": [20,19,8,21,13,18,21,12,12,18,9,9], \"k\": 1 }\nassert my_solution.divideArray(**test_input) == [[8,9,9],[12,12,13],[18,18,19],[20,21,21]]\n\ntest_input = { \"nums\": [6,14,19,17,13,4,17,10,17], \"k\": 19 }\nassert my_solution.divideArray(**test_input) == [[4,6,10],[13,14,17],[17,17,19]]\n\ntest_input = { \"nums\": [8,8,12], \"k\": 4 }\nassert my_solution.divideArray(**test_input) == [[8,8,12]]\n\ntest_input = { \"nums\": [3,16,17,18,10,8,20,16,20,10,10,21], \"k\": 16 }\nassert my_solution.divideArray(**test_input) == [[3,8,10],[10,10,16],[16,17,18],[20,20,21]]\n\ntest_input = { \"nums\": [19,14,17,20,16,16,7,10,18,8,16,15,15,13,12,14,17,11], \"k\": 8 }\nassert my_solution.divideArray(**test_input) == [[7,8,10],[11,12,13],[14,14,15],[15,16,16],[16,17,17],[18,19,20]]\n\ntest_input = { \"nums\": [18,7,11,13,13,9,22,20,21,13,7,18,8,8,16], \"k\": 4 }\nassert my_solution.divideArray(**test_input) == [[7,7,8],[8,9,11],[13,13,13],[16,18,18],[20,21,22]]\n\ntest_input = { \"nums\": [10,15,9,15,15,10], \"k\": 1 }\nassert my_solution.divideArray(**test_input) == [[9,10,10],[15,15,15]]\n\ntest_input = { \"nums\": [16,17,16], \"k\": 16 }\nassert my_solution.divideArray(**test_input) == [[16,16,17]]\n\ntest_input = { \"nums\": [15,1,15,14,18,17,1,18,12,16,6,6,7,1,12], \"k\": 4 }\nassert my_solution.divideArray(**test_input) == [[1,1,1],[6,6,7],[12,12,14],[15,15,16],[17,18,18]]\n\ntest_input = { \"nums\": [6,11,6,18,11,13,13,8,11,4,4,11,12,17,11], \"k\": 12 }\nassert my_solution.divideArray(**test_input) == [[4,4,6],[6,8,11],[11,11,11],[11,12,13],[13,17,18]]\n\ntest_input = { \"nums\": [5,13,4,14,11,18,9,10,20,5,17,11,5,8,20,5,14,4,18,17,17], \"k\": 8 }\nassert my_solution.divideArray(**test_input) == [[4,4,5],[5,5,5],[8,9,10],[11,11,13],[14,14,17],[17,17,18],[18,20,20]]\n\ntest_input = { \"nums\": [13,6,20,13,12,8,7,12,22,16,13,7,12,17,5], \"k\": 6 }\nassert my_solution.divideArray(**test_input) == [[5,6,7],[7,8,12],[12,12,13],[13,13,16],[17,20,22]]\n\ntest_input = { \"nums\": [23,2,15,20,18,14,20,7,2,22,4,14,7,9,15,14,2,7], \"k\": 8 }\nassert my_solution.divideArray(**test_input) == [[2,2,2],[4,7,7],[7,9,14],[14,14,15],[15,18,20],[20,22,23]]\n\ntest_input = { \"nums\": [19,9,2,4,17,2,27,18,17], \"k\": 18 }\nassert my_solution.divideArray(**test_input) == [[2,2,4],[9,17,17],[18,19,27]]\n\ntest_input = { \"nums\": [5,20,29,4,12,14,31,6,11,2,15,17,15,19,4], \"k\": 20 }\nassert my_solution.divideArray(**test_input) == [[2,4,4],[5,6,11],[12,14,15],[15,17,19],[20,29,31]]\n\ntest_input = { \"nums\": [15,20,5,24,18,16,25,21,28,12,19,28,25,20,14,18,24,28], \"k\": 17 }\nassert my_solution.divideArray(**test_input) == [[5,12,14],[15,16,18],[18,19,20],[20,21,24],[24,25,25],[28,28,28]]\n\ntest_input = { \"nums\": [9,6,23,17,7,17], \"k\": 20 }\nassert my_solution.divideArray(**test_input) == [[6,7,9],[17,17,23]]\n\ntest_input = { \"nums\": [24,23,19], \"k\": 6 }\nassert my_solution.divideArray(**test_input) == [[19,23,24]]\n\ntest_input = { \"nums\": [6,19,22,7,17,7,15,17,7,18,4,14,9,10,16], \"k\": 9 }\nassert my_solution.divideArray(**test_input) == [[4,6,7],[7,7,9],[10,14,15],[16,17,17],[18,19,22]]\n\ntest_input = { \"nums\": [4,3,15,1,15,15], \"k\": 4 }\nassert my_solution.divideArray(**test_input) == [[1,3,4],[15,15,15]]\n\ntest_input = { \"nums\": [10,22,18,15,7,21,6,7,11,9,7,6,7,10,18], \"k\": 8 }\nassert my_solution.divideArray(**test_input) == [[6,6,7],[7,7,7],[9,10,10],[11,15,18],[18,21,22]]\n\ntest_input = { \"nums\": [16,17,2,17,9,7,22,17,12,4,14,17,4,19,12,18,19,8,17,5,6], \"k\": 7 }\nassert my_solution.divideArray(**test_input) == [[2,4,4],[5,6,7],[8,9,12],[12,14,16],[17,17,17],[17,17,18],[19,19,22]]\n\ntest_input = { \"nums\": [20,18,18,22,7,9,9,10,16,4,18,18,11,9,18,11,11,21], \"k\": 7 }\nassert my_solution.divideArray(**test_input) == [[4,7,9],[9,9,10],[11,11,11],[16,18,18],[18,18,18],[20,21,22]]\n\ntest_input = { \"nums\": [5,11,15,9,17,6,16,14,4,9,5,13,10,12,13,15,13,12,16,12,13], \"k\": 5 }\nassert my_solution.divideArray(**test_input) == [[4,5,5],[6,9,9],[10,11,12],[12,12,13],[13,13,13],[14,15,15],[16,16,17]]\n\ntest_input = { \"nums\": [4,16,17], \"k\": 20 }\nassert my_solution.divideArray(**test_input) == [[4,16,17]]\n\ntest_input = { \"nums\": [10,9,22,13,17,11,6,9,11], \"k\": 10 }\nassert my_solution.divideArray(**test_input) == [[6,9,9],[10,11,11],[13,17,22]]\n\ntest_input = { \"nums\": [3,11,19,8,22,23,15,18,37,7,25,20,12,19,7], \"k\": 18 }\nassert my_solution.divideArray(**test_input) == [[3,7,7],[8,11,12],[15,18,19],[19,20,22],[23,25,37]]\n\ntest_input = { \"nums\": [4,6,6,3,11,11], \"k\": 16 }\nassert my_solution.divideArray(**test_input) == [[3,4,6],[6,11,11]]\n\ntest_input = { \"nums\": [10,17,10,15,16,8], \"k\": 7 }\nassert my_solution.divideArray(**test_input) == [[8,10,10],[15,16,17]]\n\ntest_input = { \"nums\": [4,20,4,19,8,7,4,20,7], \"k\": 3 }\nassert my_solution.divideArray(**test_input) == [[4,4,4],[7,7,8],[19,20,20]]\n\ntest_input = { \"nums\": [4,4,4], \"k\": 17 }\nassert my_solution.divideArray(**test_input) == [[4,4,4]]\n\ntest_input = { \"nums\": [18,6,15,20,5,27,23,15,26,11,11,4,17,23,11], \"k\": 15 }\nassert my_solution.divideArray(**test_input) == [[4,5,6],[11,11,11],[15,15,17],[18,20,23],[23,26,27]]\n\ntest_input = { \"nums\": [8,9,5], \"k\": 15 }\nassert my_solution.divideArray(**test_input) == [[5,8,9]]\n\ntest_input = { \"nums\": [20,15,8,11,11,10,19,7,20], \"k\": 7 }\nassert my_solution.divideArray(**test_input) == [[7,8,10],[11,11,15],[19,20,20]]\n\ntest_input = { \"nums\": [12,11,18,13,13,21], \"k\": 11 }\nassert my_solution.divideArray(**test_input) == [[11,12,13],[13,18,21]]\n\ntest_input = { \"nums\": [19,29,11,18,19,17,29,19,7], \"k\": 14 }\nassert my_solution.divideArray(**test_input) == [[7,11,17],[18,19,19],[19,29,29]]\n\ntest_input = { \"nums\": [14,1,25,1,14,19,2,2,4,16,17,11,26,29,12], \"k\": 17 }\nassert my_solution.divideArray(**test_input) == [[1,1,2],[2,4,11],[12,14,14],[16,17,19],[25,26,29]]\n\ntest_input = { \"nums\": [14,25,16,11,7,13,12,16,24,19,5,17], \"k\": 13 }\nassert my_solution.divideArray(**test_input) == [[5,7,11],[12,13,14],[16,16,17],[19,24,25]]\n\ntest_input = { \"nums\": [11,26,19,10,16,10,11,18,9], \"k\": 11 }\nassert my_solution.divideArray(**test_input) == [[9,10,10],[11,11,16],[18,19,26]]\n\ntest_input = { \"nums\": [16,8,15], \"k\": 16 }\nassert my_solution.divideArray(**test_input) == [[8,15,16]]\n\ntest_input = { \"nums\": [12,8,18,8,18,13,12,18,18,13,12,23,21,8,13], \"k\": 5 }\nassert my_solution.divideArray(**test_input) == [[8,8,8],[12,12,12],[13,13,13],[18,18,18],[18,21,23]]\n\ntest_input = { \"nums\": [12,16,9,8,22,16], \"k\": 16 }\nassert my_solution.divideArray(**test_input) == [[8,9,12],[16,16,22]]\n\ntest_input = { \"nums\": [15,16,18,8,12,7,5,17,23,17,18,13,5,4,13,18,7,20], \"k\": 6 }\nassert my_solution.divideArray(**test_input) == [[4,5,5],[7,7,8],[12,13,13],[15,16,17],[17,18,18],[18,20,23]]\n\ntest_input = { \"nums\": [12,11,14,13,9,16,31,19,21,22,7,1,22,23,9,2,21,21], \"k\": 15 }\nassert my_solution.divideArray(**test_input) == [[1,2,7],[9,9,11],[12,13,14],[16,19,21],[21,21,22],[22,23,31]]\n\ntest_input = { \"nums\": [7,15,18,20,6,21,18,17,11,1,14,15,18,8,17,13,11,8,5,12,11], \"k\": 10 }\nassert my_solution.divideArray(**test_input) == [[1,5,6],[7,8,8],[11,11,11],[12,13,14],[15,15,17],[17,18,18],[18,20,21]]\n\ntest_input = { \"nums\": [13,16,17,16,6,12], \"k\": 11 }\nassert my_solution.divideArray(**test_input) == [[6,12,13],[16,16,17]]\n\ntest_input = { \"nums\": [17,17,17,16,17,17], \"k\": 1 }\nassert my_solution.divideArray(**test_input) == [[16,17,17],[17,17,17]]\n\ntest_input = { \"nums\": [6,14,6,15,14,6], \"k\": 17 }\nassert my_solution.divideArray(**test_input) == [[6,6,6],[14,14,15]]\n\ntest_input = { \"nums\": [23,19,21,10,10,13,15,19,19,3,15,3], \"k\": 12 }\nassert my_solution.divideArray(**test_input) == [[3,3,10],[10,13,15],[15,19,19],[19,21,23]]\n\ntest_input = { \"nums\": [11,4,3,11,3,27,19,10,6,12,11,24,27,1,31], \"k\": 17 }\nassert my_solution.divideArray(**test_input) == [[1,3,3],[4,6,10],[11,11,11],[12,19,24],[27,27,31]]\n\ntest_input = { \"nums\": [8,18,18,20,20,19,20,31,7], \"k\": 17 }\nassert my_solution.divideArray(**test_input) == [[7,8,18],[18,19,20],[20,20,31]]\n\ntest_input = { \"nums\": [4,22,8,12,1,4,4,17,22,4,10,1], \"k\": 12 }\nassert my_solution.divideArray(**test_input) == [[1,1,4],[4,4,4],[8,10,12],[17,22,22]]\n\ntest_input = { \"nums\": [16,15,16,6,9,22,14,16,10,26,18,16,11,18,7], \"k\": 10 }\nassert my_solution.divideArray(**test_input) == [[6,7,9],[10,11,14],[15,16,16],[16,16,18],[18,22,26]]\n\ntest_input = { \"nums\": [5,16,12,26,16,18,1,6,23,2,1,21,8,11,9], \"k\": 14 }\nassert my_solution.divideArray(**test_input) == [[1,1,2],[5,6,8],[9,11,12],[16,16,18],[21,23,26]]\n\ntest_input = { \"nums\": [6,3,24,13,19,24,13,12,15,3,6,3], \"k\": 17 }\nassert my_solution.divideArray(**test_input) == [[3,3,3],[6,6,12],[13,13,15],[19,24,24]]", "start_time": 1702780200} +{"task_id": "weekly-contest-376-minimum-cost-to-make-array-equalindromic", "url": "https://leetcode.com/problems/minimum-cost-to-make-array-equalindromic", "title": "minimum-cost-to-make-array-equalindromic", "meta": {"questionId": "3229", "questionFrontendId": "2967", "title": "Minimum Cost to Make Array Equalindromic", "titleSlug": "minimum-cost-to-make-array-equalindromic", "isPaidOnly": false, "difficulty": "Medium", "likes": 164, "dislikes": 70, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed integer array nums having length n.\nYou are allowed to perform a special move any number of times (including zero) on nums. In one special move you perform the following steps in order:\n\nChoose an index i in the range [0, n - 1], and a positive integer x.\nAdd |nums[i] - x| to the total cost.\nChange the value of nums[i] to x.\n\nA palindromic number is a positive integer that remains the same when its digits are reversed. For example, 121, 2552 and 65756 are palindromic numbers whereas 24, 46, 235 are not palindromic numbers.\nAn array is considered equalindromic if all the elements in the array are equal to an integer y, where y is a palindromic number less than 109.\nReturn an integer denoting the minimum possible total cost to make nums equalindromic by performing any number of special moves.\n\nExample 1:\n\nInput: nums = [1,2,3,4,5]\nOutput: 6\nExplanation: We can make the array equalindromic by changing all elements to 3 which is a palindromic number. The cost of changing the array to [3,3,3,3,3] using 4 special moves is given by |1 - 3| + |2 - 3| + |4 - 3| + |5 - 3| = 6.\nIt can be shown that changing all elements to any palindromic number other than 3 cannot be achieved at a lower cost.\n\nExample 2:\n\nInput: nums = [10,12,13,14,15]\nOutput: 11\nExplanation: We can make the array equalindromic by changing all elements to 11 which is a palindromic number. The cost of changing the array to [11,11,11,11,11] using 5 special moves is given by |10 - 11| + |12 - 11| + |13 - 11| + |14 - 11| + |15 - 11| = 11.\nIt can be shown that changing all elements to any palindromic number other than 11 cannot be achieved at a lower cost.\n\nExample 3:\n\nInput: nums = [22,33,22,33,22]\nOutput: 22\nExplanation: We can make the array equalindromic by changing all elements to 22 which is a palindromic number. The cost of changing the array to [22,22,22,22,22] using 2 special moves is given by |33 - 22| + |33 - 22| = 22.\nIt can be shown that changing all elements to any palindromic number other than 22 cannot be achieved at a lower cost.\n\n\nConstraints:\n\n1 <= n <= 105\n1 <= nums[i] <= 109\n\"\"\"\nclass Solution:\n def minimumCost(self, nums: List[int]) -> int:\n ", "prompt_sft": "You are given a 0-indexed integer array nums having length n.\nYou are allowed to perform a special move any number of times (including zero) on nums. In one special move you perform the following steps in order:\n\nChoose an index i in the range [0, n - 1], and a positive integer x.\nAdd |nums[i] - x| to the total cost.\nChange the value of nums[i] to x.\n\nA palindromic number is a positive integer that remains the same when its digits are reversed. For example, 121, 2552 and 65756 are palindromic numbers whereas 24, 46, 235 are not palindromic numbers.\nAn array is considered equalindromic if all the elements in the array are equal to an integer y, where y is a palindromic number less than 109.\nReturn an integer denoting the minimum possible total cost to make nums equalindromic by performing any number of special moves.\n\nExample 1:\n\nInput: nums = [1,2,3,4,5]\nOutput: 6\nExplanation: We can make the array equalindromic by changing all elements to 3 which is a palindromic number. The cost of changing the array to [3,3,3,3,3] using 4 special moves is given by |1 - 3| + |2 - 3| + |4 - 3| + |5 - 3| = 6.\nIt can be shown that changing all elements to any palindromic number other than 3 cannot be achieved at a lower cost.\n\nExample 2:\n\nInput: nums = [10,12,13,14,15]\nOutput: 11\nExplanation: We can make the array equalindromic by changing all elements to 11 which is a palindromic number. The cost of changing the array to [11,11,11,11,11] using 5 special moves is given by |10 - 11| + |12 - 11| + |13 - 11| + |14 - 11| + |15 - 11| = 11.\nIt can be shown that changing all elements to any palindromic number other than 11 cannot be achieved at a lower cost.\n\nExample 3:\n\nInput: nums = [22,33,22,33,22]\nOutput: 22\nExplanation: We can make the array equalindromic by changing all elements to 22 which is a palindromic number. The cost of changing the array to [22,22,22,22,22] using 2 special moves is given by |33 - 22| + |33 - 22| = 22.\nIt can be shown that changing all elements to any palindromic number other than 22 cannot be achieved at a lower cost.\n\n\nConstraints:\n\n1 <= n <= 105\n1 <= nums[i] <= 109\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def minimumCost(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,2,3,4,5] }\nassert my_solution.minimumCost(**test_input) == 6\n\ntest_input = { \"nums\": [10,12,13,14,15] }\nassert my_solution.minimumCost(**test_input) == 11\n\ntest_input = { \"nums\": [22,33,22,33,22] }\nassert my_solution.minimumCost(**test_input) == 22\n\ntest_input = { \"nums\": [1] }\nassert my_solution.minimumCost(**test_input) == 0\n\ntest_input = { \"nums\": [2] }\nassert my_solution.minimumCost(**test_input) == 0\n\ntest_input = { \"nums\": [3] }\nassert my_solution.minimumCost(**test_input) == 0\n\ntest_input = { \"nums\": [4] }\nassert my_solution.minimumCost(**test_input) == 0\n\ntest_input = { \"nums\": [5] }\nassert my_solution.minimumCost(**test_input) == 0\n\ntest_input = { \"nums\": [2,1] }\nassert my_solution.minimumCost(**test_input) == 1\n\ntest_input = { \"nums\": [3,1] }\nassert my_solution.minimumCost(**test_input) == 2\n\ntest_input = { \"nums\": [3,2] }\nassert my_solution.minimumCost(**test_input) == 1\n\ntest_input = { \"nums\": [4,1] }\nassert my_solution.minimumCost(**test_input) == 3\n\ntest_input = { \"nums\": [4,2] }\nassert my_solution.minimumCost(**test_input) == 2\n\ntest_input = { \"nums\": [4,3] }\nassert my_solution.minimumCost(**test_input) == 1\n\ntest_input = { \"nums\": [5,1] }\nassert my_solution.minimumCost(**test_input) == 4\n\ntest_input = { \"nums\": [5,2] }\nassert my_solution.minimumCost(**test_input) == 3\n\ntest_input = { \"nums\": [5,3] }\nassert my_solution.minimumCost(**test_input) == 2\n\ntest_input = { \"nums\": [5,4] }\nassert my_solution.minimumCost(**test_input) == 1\n\ntest_input = { \"nums\": [3,2,1] }\nassert my_solution.minimumCost(**test_input) == 2\n\ntest_input = { \"nums\": [4,2,1] }\nassert my_solution.minimumCost(**test_input) == 3\n\ntest_input = { \"nums\": [4,3,1] }\nassert my_solution.minimumCost(**test_input) == 3\n\ntest_input = { \"nums\": [4,3,2] }\nassert my_solution.minimumCost(**test_input) == 2\n\ntest_input = { \"nums\": [5,2,1] }\nassert my_solution.minimumCost(**test_input) == 4\n\ntest_input = { \"nums\": [5,3,1] }\nassert my_solution.minimumCost(**test_input) == 4\n\ntest_input = { \"nums\": [5,3,2] }\nassert my_solution.minimumCost(**test_input) == 3\n\ntest_input = { \"nums\": [5,4,1] }\nassert my_solution.minimumCost(**test_input) == 4\n\ntest_input = { \"nums\": [5,4,2] }\nassert my_solution.minimumCost(**test_input) == 3\n\ntest_input = { \"nums\": [5,4,3] }\nassert my_solution.minimumCost(**test_input) == 2\n\ntest_input = { \"nums\": [4,3,2,1] }\nassert my_solution.minimumCost(**test_input) == 4\n\ntest_input = { \"nums\": [5,3,2,1] }\nassert my_solution.minimumCost(**test_input) == 5\n\ntest_input = { \"nums\": [5,4,2,1] }\nassert my_solution.minimumCost(**test_input) == 6\n\ntest_input = { \"nums\": [5,4,3,1] }\nassert my_solution.minimumCost(**test_input) == 5\n\ntest_input = { \"nums\": [5,4,3,2] }\nassert my_solution.minimumCost(**test_input) == 4\n\ntest_input = { \"nums\": [301,309,312,322] }\nassert my_solution.minimumCost(**test_input) == 26\n\ntest_input = { \"nums\": [302,306,316,329] }\nassert my_solution.minimumCost(**test_input) == 37\n\ntest_input = { \"nums\": [302,315,317,320] }\nassert my_solution.minimumCost(**test_input) == 24\n\ntest_input = { \"nums\": [304,310,324,328] }\nassert my_solution.minimumCost(**test_input) == 38\n\ntest_input = { \"nums\": [307,321,322,327] }\nassert my_solution.minimumCost(**test_input) == 23\n\ntest_input = { \"nums\": [307,323,325,330] }\nassert my_solution.minimumCost(**test_input) == 25\n\ntest_input = { \"nums\": [308,313,319,322] }\nassert my_solution.minimumCost(**test_input) == 20\n\ntest_input = { \"nums\": [311,313,320,324] }\nassert my_solution.minimumCost(**test_input) == 20\n\ntest_input = { \"nums\": [313,318,323,328] }\nassert my_solution.minimumCost(**test_input) == 20\n\ntest_input = { \"nums\": [101,102,105,108,124] }\nassert my_solution.minimumCost(**test_input) == 35\n\ntest_input = { \"nums\": [101,102,105,120,124] }\nassert my_solution.minimumCost(**test_input) == 47\n\ntest_input = { \"nums\": [101,102,111,125,126] }\nassert my_solution.minimumCost(**test_input) == 48\n\ntest_input = { \"nums\": [101,104,107,126,130] }\nassert my_solution.minimumCost(**test_input) == 55\n\ntest_input = { \"nums\": [101,106,113,120,124] }\nassert my_solution.minimumCost(**test_input) == 39\n\ntest_input = { \"nums\": [101,115,116,120,122] }\nassert my_solution.minimumCost(**test_input) == 33\n\ntest_input = { \"nums\": [102,103,105,106,109] }\nassert my_solution.minimumCost(**test_input) == 20\n\ntest_input = { \"nums\": [102,103,107,125,128] }\nassert my_solution.minimumCost(**test_input) == 52\n\ntest_input = { \"nums\": [102,103,111,119,125] }\nassert my_solution.minimumCost(**test_input) == 39\n\ntest_input = { \"nums\": [102,105,120,128,129] }\nassert my_solution.minimumCost(**test_input) == 51\n\ntest_input = { \"nums\": [103,104,113,116,119] }\nassert my_solution.minimumCost(**test_input) == 30\n\ntest_input = { \"nums\": [103,105,107,113,125] }\nassert my_solution.minimumCost(**test_input) == 34\n\ntest_input = { \"nums\": [103,106,113,120,130] }\nassert my_solution.minimumCost(**test_input) == 43\n\ntest_input = { \"nums\": [103,109,110,118,123] }\nassert my_solution.minimumCost(**test_input) == 30\n\ntest_input = { \"nums\": [103,110,121,127,129] }\nassert my_solution.minimumCost(**test_input) == 43\n\ntest_input = { \"nums\": [103,114,120,123,125] }\nassert my_solution.minimumCost(**test_input) == 32\n\ntest_input = { \"nums\": [103,115,120,122,128] }\nassert my_solution.minimumCost(**test_input) == 33\n\ntest_input = { \"nums\": [104,107,120,122,124] }\nassert my_solution.minimumCost(**test_input) == 36\n\ntest_input = { \"nums\": [104,111,121,128,129] }\nassert my_solution.minimumCost(**test_input) == 42\n\ntest_input = { \"nums\": [104,119,123,125,126] }\nassert my_solution.minimumCost(**test_input) == 30\n\ntest_input = { \"nums\": [105,108,112,119,130] }\nassert my_solution.minimumCost(**test_input) == 37\n\ntest_input = { \"nums\": [105,108,122,126,130] }\nassert my_solution.minimumCost(**test_input) == 44\n\ntest_input = { \"nums\": [105,110,118,123,125] }\nassert my_solution.minimumCost(**test_input) == 36\n\ntest_input = { \"nums\": [105,116,118,123,129] }\nassert my_solution.minimumCost(**test_input) == 34\n\ntest_input = { \"nums\": [106,107,114,117,127] }\nassert my_solution.minimumCost(**test_input) == 34\n\ntest_input = { \"nums\": [106,109,118,124,125] }\nassert my_solution.minimumCost(**test_input) == 37\n\ntest_input = { \"nums\": [106,111,113,123,129] }\nassert my_solution.minimumCost(**test_input) == 37\n\ntest_input = { \"nums\": [106,113,116,120,122] }\nassert my_solution.minimumCost(**test_input) == 30\n\ntest_input = { \"nums\": [107,108,113,114,122] }\nassert my_solution.minimumCost(**test_input) == 23\n\ntest_input = { \"nums\": [107,109,112,118,128] }\nassert my_solution.minimumCost(**test_input) == 31\n\ntest_input = { \"nums\": [107,109,115,116,129] }\nassert my_solution.minimumCost(**test_input) == 33\n\ntest_input = { \"nums\": [107,110,119,125,130] }\nassert my_solution.minimumCost(**test_input) == 40\n\ntest_input = { \"nums\": [107,112,116,121,124] }\nassert my_solution.minimumCost(**test_input) == 31\n\ntest_input = { \"nums\": [107,115,116,120,127] }\nassert my_solution.minimumCost(**test_input) == 32\n\ntest_input = { \"nums\": [107,116,123,125,128] }\nassert my_solution.minimumCost(**test_input) == 32\n\ntest_input = { \"nums\": [108,110,116,121,130] }\nassert my_solution.minimumCost(**test_input) == 38\n\ntest_input = { \"nums\": [108,113,114,115,119] }\nassert my_solution.minimumCost(**test_input) == 20\n\ntest_input = { \"nums\": [108,113,116,124,129] }\nassert my_solution.minimumCost(**test_input) == 37\n\ntest_input = { \"nums\": [108,115,124,127,129] }\nassert my_solution.minimumCost(**test_input) == 36\n\ntest_input = { \"nums\": [109,113,115,122,128] }\nassert my_solution.minimumCost(**test_input) == 34\n\ntest_input = { \"nums\": [110,111,112,126,129] }\nassert my_solution.minimumCost(**test_input) == 35\n\ntest_input = { \"nums\": [110,113,119,124,125] }\nassert my_solution.minimumCost(**test_input) == 28\n\ntest_input = { \"nums\": [111,114,117,118,125] }\nassert my_solution.minimumCost(**test_input) == 28\n\ntest_input = { \"nums\": [112,113,114,120,130] }\nassert my_solution.minimumCost(**test_input) == 34\n\ntest_input = { \"nums\": [112,115,120,123,129] }\nassert my_solution.minimumCost(**test_input) == 26\n\ntest_input = { \"nums\": [117,118,119,124,128] }\nassert my_solution.minimumCost(**test_input) == 19\n\ntest_input = { \"nums\": [201,202,203,205,215,228] }\nassert my_solution.minimumCost(**test_input) == 44\n\ntest_input = { \"nums\": [201,202,204,205,215,225] }\nassert my_solution.minimumCost(**test_input) == 42\n\ntest_input = { \"nums\": [201,202,204,207,220,224] }\nassert my_solution.minimumCost(**test_input) == 48\n\ntest_input = { \"nums\": [201,202,204,208,216,225] }\nassert my_solution.minimumCost(**test_input) == 46\n\ntest_input = { \"nums\": [201,202,204,218,223,224] }\nassert my_solution.minimumCost(**test_input) == 58\n\ntest_input = { \"nums\": [201,202,205,210,227,228] }\nassert my_solution.minimumCost(**test_input) == 61\n\ntest_input = { \"nums\": [201,202,205,211,214,225] }\nassert my_solution.minimumCost(**test_input) == 44\n\ntest_input = { \"nums\": [201,202,207,210,223,226] }\nassert my_solution.minimumCost(**test_input) == 53\n\ntest_input = { \"nums\": [201,202,207,212,215,222] }\nassert my_solution.minimumCost(**test_input) == 39\n\ntest_input = { \"nums\": [201,202,207,216,220,223] }\nassert my_solution.minimumCost(**test_input) == 49\n\ntest_input = { \"nums\": [201,202,211,213,221,223] }\nassert my_solution.minimumCost(**test_input) == 43\n\ntest_input = { \"nums\": [201,202,212,213,219,229] }\nassert my_solution.minimumCost(**test_input) == 46", "start_time": 1702780200} +{"task_id": "weekly-contest-376-apply-operations-to-maximize-frequency-score", "url": "https://leetcode.com/problems/apply-operations-to-maximize-frequency-score", "title": "apply-operations-to-maximize-frequency-score", "meta": {"questionId": "3196", "questionFrontendId": "2968", "title": "Apply Operations to Maximize Frequency Score", "titleSlug": "apply-operations-to-maximize-frequency-score", "isPaidOnly": false, "difficulty": "Hard", "likes": 175, "dislikes": 4, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed integer array nums and an integer k.\nYou can perform the following operation on the array at most k times:\n\nChoose any index i from the array and increase or decrease nums[i] by 1.\n\nThe score of the final array is the frequency of the most frequent element in the array.\nReturn the maximum score you can achieve.\nThe frequency of an element is the number of occurences of that element in the array.\n\nExample 1:\n\nInput: nums = [1,2,6,4], k = 3\nOutput: 3\nExplanation: We can do the following operations on the array:\n- Choose i = 0, and increase the value of nums[0] by 1. The resulting array is [2,2,6,4].\n- Choose i = 3, and decrease the value of nums[3] by 1. The resulting array is [2,2,6,3].\n- Choose i = 3, and decrease the value of nums[3] by 1. The resulting array is [2,2,6,2].\nThe element 2 is the most frequent in the final array so our score is 3.\nIt can be shown that we cannot achieve a better score.\n\nExample 2:\n\nInput: nums = [1,4,4,2,4], k = 0\nOutput: 3\nExplanation: We cannot apply any operations so our score will be the frequency of the most frequent element in the original array, which is 3.\n\n\nConstraints:\n\n1 <= nums.length <= 105\n1 <= nums[i] <= 109\n0 <= k <= 1014\n\"\"\"\nclass Solution:\n def maxFrequencyScore(self, nums: List[int], k: int) -> int:\n ", "prompt_sft": "You are given a 0-indexed integer array nums and an integer k.\nYou can perform the following operation on the array at most k times:\n\nChoose any index i from the array and increase or decrease nums[i] by 1.\n\nThe score of the final array is the frequency of the most frequent element in the array.\nReturn the maximum score you can achieve.\nThe frequency of an element is the number of occurences of that element in the array.\n\nExample 1:\n\nInput: nums = [1,2,6,4], k = 3\nOutput: 3\nExplanation: We can do the following operations on the array:\n- Choose i = 0, and increase the value of nums[0] by 1. The resulting array is [2,2,6,4].\n- Choose i = 3, and decrease the value of nums[3] by 1. The resulting array is [2,2,6,3].\n- Choose i = 3, and decrease the value of nums[3] by 1. The resulting array is [2,2,6,2].\nThe element 2 is the most frequent in the final array so our score is 3.\nIt can be shown that we cannot achieve a better score.\n\nExample 2:\n\nInput: nums = [1,4,4,2,4], k = 0\nOutput: 3\nExplanation: We cannot apply any operations so our score will be the frequency of the most frequent element in the original array, which is 3.\n\n\nConstraints:\n\n1 <= nums.length <= 105\n1 <= nums[i] <= 109\n0 <= k <= 1014\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def maxFrequencyScore(self, nums: List[int], k: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,2,6,4], \"k\": 3 }\nassert my_solution.maxFrequencyScore(**test_input) == 3\n\ntest_input = { \"nums\": [1,4,4,2,4], \"k\": 0 }\nassert my_solution.maxFrequencyScore(**test_input) == 3\n\ntest_input = { \"nums\": [3,20,13,2,3,15,24,19,8,13,19,20,21], \"k\": 45 }\nassert my_solution.maxFrequencyScore(**test_input) == 10\n\ntest_input = { \"nums\": [13,22,29,21,13,17,5,2,27,6,10,4,23,29,27], \"k\": 117 }\nassert my_solution.maxFrequencyScore(**test_input) == 14\n\ntest_input = { \"nums\": [27,8,30,3,13,28,7,14,21,19,24,28,29,1,14,22,6], \"k\": 23 }\nassert my_solution.maxFrequencyScore(**test_input) == 8\n\ntest_input = { \"nums\": [10,11,3], \"k\": 1 }\nassert my_solution.maxFrequencyScore(**test_input) == 2\n\ntest_input = { \"nums\": [10,19,26,18,27,18], \"k\": 9 }\nassert my_solution.maxFrequencyScore(**test_input) == 4\n\ntest_input = { \"nums\": [17,24,10,23,22,15,25,2,13,24,22,25,25,21], \"k\": 52 }\nassert my_solution.maxFrequencyScore(**test_input) == 13\n\ntest_input = { \"nums\": [28,6,22,10], \"k\": 12 }\nassert my_solution.maxFrequencyScore(**test_input) == 2\n\ntest_input = { \"nums\": [17,17,25,14,29,28,20,14,16,22,4,28,2,5,3,11,6,20,17], \"k\": 76 }\nassert my_solution.maxFrequencyScore(**test_input) == 14\n\ntest_input = { \"nums\": [23,10,18,21,16,23,14], \"k\": 2 }\nassert my_solution.maxFrequencyScore(**test_input) == 3\n\ntest_input = { \"nums\": [5,13,7], \"k\": 8 }\nassert my_solution.maxFrequencyScore(**test_input) == 3\n\ntest_input = { \"nums\": [6,29,3,19,10,6,20,26,1,30,11,25,29,12,29,14,15,16,5], \"k\": 64 }\nassert my_solution.maxFrequencyScore(**test_input) == 12\n\ntest_input = { \"nums\": [10,26,21,18,30,25,1], \"k\": 8 }\nassert my_solution.maxFrequencyScore(**test_input) == 3\n\ntest_input = { \"nums\": [29,10,26,1,2,2,17,7,5,16,24,27,7,7,26,26,24], \"k\": 3 }\nassert my_solution.maxFrequencyScore(**test_input) == 5\n\ntest_input = { \"nums\": [11,16,6,12,3,8,5,29,9,15,7,9,14,6,11,14,12,23,22,14], \"k\": 79 }\nassert my_solution.maxFrequencyScore(**test_input) == 19\n\ntest_input = { \"nums\": [5,17,15,14,27,11,22,6,4], \"k\": 26 }\nassert my_solution.maxFrequencyScore(**test_input) == 6\n\ntest_input = { \"nums\": [13,22,17], \"k\": 4 }\nassert my_solution.maxFrequencyScore(**test_input) == 2\n\ntest_input = { \"nums\": [24,6,14,6,30,9,6,11,21,10,12,27,1], \"k\": 90 }\nassert my_solution.maxFrequencyScore(**test_input) == 13\n\ntest_input = { \"nums\": [19,5,2,23,16,22,3,2,5,20,17,3,22,1], \"k\": 15 }\nassert my_solution.maxFrequencyScore(**test_input) == 7\n\ntest_input = { \"nums\": [15,20], \"k\": 5 }\nassert my_solution.maxFrequencyScore(**test_input) == 2\n\ntest_input = { \"nums\": [9,2,5,14,19,5,10,10,2,25,1,1,1,14,9,13,5,6,10,1], \"k\": 80 }\nassert my_solution.maxFrequencyScore(**test_input) == 18\n\ntest_input = { \"nums\": [2,29,24,19,5], \"k\": 24 }\nassert my_solution.maxFrequencyScore(**test_input) == 3\n\ntest_input = { \"nums\": [4,10,5], \"k\": 6 }\nassert my_solution.maxFrequencyScore(**test_input) == 3\n\ntest_input = { \"nums\": [5,2,22,7,18,26,15,4,24,26,24], \"k\": 19 }\nassert my_solution.maxFrequencyScore(**test_input) == 6\n\ntest_input = { \"nums\": [23,21,10], \"k\": 13 }\nassert my_solution.maxFrequencyScore(**test_input) == 3\n\ntest_input = { \"nums\": [5,23,7,2,1,5,12,2,20,24,5,4], \"k\": 71 }\nassert my_solution.maxFrequencyScore(**test_input) == 11\n\ntest_input = { \"nums\": [22,13,30], \"k\": 17 }\nassert my_solution.maxFrequencyScore(**test_input) == 3\n\ntest_input = { \"nums\": [7,23,29,8,9,3,4,16,24,6,18,20,19,14,5], \"k\": 55 }\nassert my_solution.maxFrequencyScore(**test_input) == 11\n\ntest_input = { \"nums\": [3,11,24,27,10], \"k\": 24 }\nassert my_solution.maxFrequencyScore(**test_input) == 4\n\ntest_input = { \"nums\": [12,11,21,6,13,27,11,2,27,26,24,13], \"k\": 0 }\nassert my_solution.maxFrequencyScore(**test_input) == 2\n\ntest_input = { \"nums\": [4,10,26,16,21,26,11,26,30,24,18,30,23,26,24], \"k\": 50 }\nassert my_solution.maxFrequencyScore(**test_input) == 12\n\ntest_input = { \"nums\": [4,2,18,14,9,29], \"k\": 4 }\nassert my_solution.maxFrequencyScore(**test_input) == 2\n\ntest_input = { \"nums\": [9,27,19,18], \"k\": 9 }\nassert my_solution.maxFrequencyScore(**test_input) == 3\n\ntest_input = { \"nums\": [11,17,29,9,22,7,13,14,12,24,9], \"k\": 47 }\nassert my_solution.maxFrequencyScore(**test_input) == 10\n\ntest_input = { \"nums\": [20,10,15,16], \"k\": 10 }\nassert my_solution.maxFrequencyScore(**test_input) == 3\n\ntest_input = { \"nums\": [16,2,6,20,2,18,16,8,15,19,22,29,24,2,26,19], \"k\": 40 }\nassert my_solution.maxFrequencyScore(**test_input) == 11\n\ntest_input = { \"nums\": [17,13,19,28,6,8,5,25,2,3,9,4,21,6,13,10,5,3], \"k\": 113 }\nassert my_solution.maxFrequencyScore(**test_input) == 18\n\ntest_input = { \"nums\": [16,5,10,15], \"k\": 5 }\nassert my_solution.maxFrequencyScore(**test_input) == 2\n\ntest_input = { \"nums\": [23,2,23,27,21], \"k\": 2 }\nassert my_solution.maxFrequencyScore(**test_input) == 3\n\ntest_input = { \"nums\": [15,26,3,14,3,18,16,19,11,9,2,18,14,8,20,9], \"k\": 75 }\nassert my_solution.maxFrequencyScore(**test_input) == 15\n\ntest_input = { \"nums\": [13,23,4,5,2], \"k\": 3 }\nassert my_solution.maxFrequencyScore(**test_input) == 3\n\ntest_input = { \"nums\": [3,1,9,12], \"k\": 8 }\nassert my_solution.maxFrequencyScore(**test_input) == 3\n\ntest_input = { \"nums\": [4,27,21,16,11,5,5,1,5,10], \"k\": 18 }\nassert my_solution.maxFrequencyScore(**test_input) == 7\n\ntest_input = { \"nums\": [14,4,23,27,8,25,7,12,12,21,21,11,20,23,30,11,12,29,22], \"k\": 77 }\nassert my_solution.maxFrequencyScore(**test_input) == 15\n\ntest_input = { \"nums\": [10,30,25], \"k\": 20 }\nassert my_solution.maxFrequencyScore(**test_input) == 3\n\ntest_input = { \"nums\": [4,8,22,25,27,26,18,14,18], \"k\": 56 }\nassert my_solution.maxFrequencyScore(**test_input) == 9\n\ntest_input = { \"nums\": [2,19,27,25,23,17,8,16,28,10,6,24,6], \"k\": 28 }\nassert my_solution.maxFrequencyScore(**test_input) == 7\n\ntest_input = { \"nums\": [27,25,27,10,23,14,24,17,12,22,14,11,19,16,7,15], \"k\": 21 }\nassert my_solution.maxFrequencyScore(**test_input) == 9\n\ntest_input = { \"nums\": [23,11], \"k\": 12 }\nassert my_solution.maxFrequencyScore(**test_input) == 2\n\ntest_input = { \"nums\": [20,28,15,11,22,26,29,2,16,9], \"k\": 61 }\nassert my_solution.maxFrequencyScore(**test_input) == 9\n\ntest_input = { \"nums\": [21,11,1,17,20,19,24,10,1,4,10,30,11,29,20,12,18,5,4,27], \"k\": 110 }\nassert my_solution.maxFrequencyScore(**test_input) == 17\n\ntest_input = { \"nums\": [22,29,7,1,26,22,27,1,16,25,25], \"k\": 26 }\nassert my_solution.maxFrequencyScore(**test_input) == 8\n\ntest_input = { \"nums\": [26,6,24], \"k\": 20 }\nassert my_solution.maxFrequencyScore(**test_input) == 3\n\ntest_input = { \"nums\": [29,24,9,4,2,9,28,1,25,25,13,22,27,26,15,18], \"k\": 2 }\nassert my_solution.maxFrequencyScore(**test_input) == 4\n\ntest_input = { \"nums\": [9,19,1,24,15,19,22,13,10,8,4,10,26,23,11,8], \"k\": 89 }\nassert my_solution.maxFrequencyScore(**test_input) == 15\n\ntest_input = { \"nums\": [18,6,20,22,25,21,19,19,15,5,7,29,28,7,17,4], \"k\": 104 }\nassert my_solution.maxFrequencyScore(**test_input) == 16\n\ntest_input = { \"nums\": [9,11,28,24,30,6,1,30,22,16,20,19,21,17], \"k\": 62 }\nassert my_solution.maxFrequencyScore(**test_input) == 11\n\ntest_input = { \"nums\": [15,13,29,28], \"k\": 15 }\nassert my_solution.maxFrequencyScore(**test_input) == 3\n\ntest_input = { \"nums\": [28,26,8], \"k\": 18 }\nassert my_solution.maxFrequencyScore(**test_input) == 2\n\ntest_input = { \"nums\": [6,12,24,4,25,23,5,13,7,5], \"k\": 12 }\nassert my_solution.maxFrequencyScore(**test_input) == 6\n\ntest_input = { \"nums\": [8,23,15,15,3,19,6,20,12,18,7,8,18,19,11,20,4,18], \"k\": 54 }\nassert my_solution.maxFrequencyScore(**test_input) == 14\n\ntest_input = { \"nums\": [30,2,4,7,19,3,3,14,24,4,26,17,1,12,4,11], \"k\": 36 }\nassert my_solution.maxFrequencyScore(**test_input) == 11\n\ntest_input = { \"nums\": [12,15,21,17,7,20,16,30,8,6,28,28,23,6,12,14,19,26,27,5], \"k\": 87 }\nassert my_solution.maxFrequencyScore(**test_input) == 16\n\ntest_input = { \"nums\": [15,1,27,4,5,20,5,26,28], \"k\": 38 }\nassert my_solution.maxFrequencyScore(**test_input) == 6\n\ntest_input = { \"nums\": [27,14,30,6,14,29,5,8], \"k\": 51 }\nassert my_solution.maxFrequencyScore(**test_input) == 7\n\ntest_input = { \"nums\": [18,22], \"k\": 4 }\nassert my_solution.maxFrequencyScore(**test_input) == 2\n\ntest_input = { \"nums\": [17,28,16,24,29], \"k\": 5 }\nassert my_solution.maxFrequencyScore(**test_input) == 3\n\ntest_input = { \"nums\": [2,22,27,12,30,9,27,3,26,23,25,30,20,19,9,1,23,14,18,26], \"k\": 30 }\nassert my_solution.maxFrequencyScore(**test_input) == 11\n\ntest_input = { \"nums\": [26,16,9,7,10,16,26,22,24,1,30,8,15,5,28,16,13,12], \"k\": 84 }\nassert my_solution.maxFrequencyScore(**test_input) == 15\n\ntest_input = { \"nums\": [26,8,27,27,22,28,8,26,24,15,6,13,20,12], \"k\": 55 }\nassert my_solution.maxFrequencyScore(**test_input) == 11\n\ntest_input = { \"nums\": [19,19,20,14,19,20,5,4,14,26,12,17,14,29,3,9], \"k\": 94 }\nassert my_solution.maxFrequencyScore(**test_input) == 16\n\ntest_input = { \"nums\": [9,19,14,17,14,20,27,9,22,29,15,20,6,25,8,17,18,24,23], \"k\": 44 }\nassert my_solution.maxFrequencyScore(**test_input) == 13\n\ntest_input = { \"nums\": [2,10], \"k\": 8 }\nassert my_solution.maxFrequencyScore(**test_input) == 2\n\ntest_input = { \"nums\": [20,2,27,27,19,20,8,21,15,20,14,18,25], \"k\": 17 }\nassert my_solution.maxFrequencyScore(**test_input) == 8\n\ntest_input = { \"nums\": [6,27,6,30,2,1,7,24,18,4,2,18,17], \"k\": 56 }\nassert my_solution.maxFrequencyScore(**test_input) == 10\n\ntest_input = { \"nums\": [23,18,30,24,5,21], \"k\": 33 }\nassert my_solution.maxFrequencyScore(**test_input) == 6\n\ntest_input = { \"nums\": [12,16,24,18,12,20,26,15,11,23,4,25], \"k\": 35 }\nassert my_solution.maxFrequencyScore(**test_input) == 9\n\ntest_input = { \"nums\": [9,9,11,18], \"k\": 11 }\nassert my_solution.maxFrequencyScore(**test_input) == 4\n\ntest_input = { \"nums\": [19,21,7,15,21,10,5,27,2,27,14], \"k\": 63 }\nassert my_solution.maxFrequencyScore(**test_input) == 9\n\ntest_input = { \"nums\": [25,17,13,6,3,19,21,12,29,1,16,14,24,27,25,13,1,5,17], \"k\": 136 }\nassert my_solution.maxFrequencyScore(**test_input) == 19\n\ntest_input = { \"nums\": [4,4,8,9,14,7,27,8,2,29,1,28,23,13], \"k\": 109 }\nassert my_solution.maxFrequencyScore(**test_input) == 14\n\ntest_input = { \"nums\": [14,2,18,30,28,17,25,10,7,10,19,3,26,22,12,17,8,4], \"k\": 24 }\nassert my_solution.maxFrequencyScore(**test_input) == 8\n\ntest_input = { \"nums\": [27,17,12,19,25,1,9,4,9,20,2,5], \"k\": 70 }\nassert my_solution.maxFrequencyScore(**test_input) == 10\n\ntest_input = { \"nums\": [18,25,12,20,19,26,2,15,3,6,29,29,2,24,4,9], \"k\": 106 }\nassert my_solution.maxFrequencyScore(**test_input) == 14\n\ntest_input = { \"nums\": [17,18,14,1,28,15,14,13,9,16,28,9,21,23,2,11], \"k\": 65 }\nassert my_solution.maxFrequencyScore(**test_input) == 14\n\ntest_input = { \"nums\": [17,15,29,30,12,13,10], \"k\": 37 }\nassert my_solution.maxFrequencyScore(**test_input) == 6\n\ntest_input = { \"nums\": [15,4,11,1,18,29,9,23,14,25,15,12,15,6,30,28], \"k\": 60 }\nassert my_solution.maxFrequencyScore(**test_input) == 12\n\ntest_input = { \"nums\": [20,6,8,15,12,8,26,7,27,8,5,25,17,12,7,1,23,24,8], \"k\": 62 }\nassert my_solution.maxFrequencyScore(**test_input) == 14\n\ntest_input = { \"nums\": [22,21,30,16,23,24,2,2,24], \"k\": 39 }\nassert my_solution.maxFrequencyScore(**test_input) == 7\n\ntest_input = { \"nums\": [8,9,6,30,28,2,1,3,14,8,21,26,13,29,23,3,14,9,6,25], \"k\": 91 }\nassert my_solution.maxFrequencyScore(**test_input) == 16\n\ntest_input = { \"nums\": [7,10,16,23,17,22,28,7,4,21,25,21,19,30,13,19,15,21,23], \"k\": 53 }\nassert my_solution.maxFrequencyScore(**test_input) == 15\n\ntest_input = { \"nums\": [25,17,1,24,3,6,8,29,19,4,16,12,9,28,1,21,13,29], \"k\": 151 }\nassert my_solution.maxFrequencyScore(**test_input) == 18\n\ntest_input = { \"nums\": [1,6,14,9], \"k\": 8 }\nassert my_solution.maxFrequencyScore(**test_input) == 3\n\ntest_input = { \"nums\": [5,7,17,2,23,6,3,13,2,11,10,8,18,16,3,11,26], \"k\": 30 }\nassert my_solution.maxFrequencyScore(**test_input) == 10\n\ntest_input = { \"nums\": [27,27,16,18,24,7,26,30,21,25,28,28,29,27,28,6], \"k\": 0 }\nassert my_solution.maxFrequencyScore(**test_input) == 3\n\ntest_input = { \"nums\": [29,16,9,21,2,16,4,17,22,11,20,23,5,22,7,27,20], \"k\": 85 }\nassert my_solution.maxFrequencyScore(**test_input) == 15\n\ntest_input = { \"nums\": [25,5,24,2,30,15,17,27,15,15,27], \"k\": 69 }\nassert my_solution.maxFrequencyScore(**test_input) == 10\n\ntest_input = { \"nums\": [6,29,24,14,9,14,1,1,28,20,19,21,13,25,17,24,30,14], \"k\": 107 }\nassert my_solution.maxFrequencyScore(**test_input) == 16\n\ntest_input = { \"nums\": [17,20,2,11,5,7,28], \"k\": 36 }\nassert my_solution.maxFrequencyScore(**test_input) == 6", "start_time": 1702780200} +{"task_id": "weekly-contest-375-count-tested-devices-after-test-operations", "url": "https://leetcode.com/problems/count-tested-devices-after-test-operations", "title": "count-tested-devices-after-test-operations", "meta": {"questionId": "3220", "questionFrontendId": "2960", "title": "Count Tested Devices After Test Operations", "titleSlug": "count-tested-devices-after-test-operations", "isPaidOnly": false, "difficulty": "Easy", "likes": 90, "dislikes": 5, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed integer array batteryPercentages having length n, denoting the battery percentages of n 0-indexed devices.\nYour task is to test each device i in order from 0 to n - 1, by performing the following test operations:\n\nIf batteryPercentages[i] is greater than 0:\n\n\t\nIncrement the count of tested devices.\nDecrease the battery percentage of all devices with indices j in the range [i + 1, n - 1] by 1, ensuring their battery percentage never goes below 0, i.e, batteryPercentages[j] = max(0, batteryPercentages[j] - 1).\nMove to the next device.\n\n\nOtherwise, move to the next device without performing any test.\n\nReturn an integer denoting the number of devices that will be tested after performing the test operations in order.\n\nExample 1:\n\nInput: batteryPercentages = [1,1,2,1,3]\nOutput: 3\nExplanation: Performing the test operations in order starting from device 0:\nAt device 0, batteryPercentages[0] > 0, so there is now 1 tested device, and batteryPercentages becomes [1,0,1,0,2].\nAt device 1, batteryPercentages[1] == 0, so we move to the next device without testing.\nAt device 2, batteryPercentages[2] > 0, so there are now 2 tested devices, and batteryPercentages becomes [1,0,1,0,1].\nAt device 3, batteryPercentages[3] == 0, so we move to the next device without testing.\nAt device 4, batteryPercentages[4] > 0, so there are now 3 tested devices, and batteryPercentages stays the same.\nSo, the answer is 3.\n\nExample 2:\n\nInput: batteryPercentages = [0,1,2]\nOutput: 2\nExplanation: Performing the test operations in order starting from device 0:\nAt device 0, batteryPercentages[0] == 0, so we move to the next device without testing.\nAt device 1, batteryPercentages[1] > 0, so there is now 1 tested device, and batteryPercentages becomes [0,1,1].\nAt device 2, batteryPercentages[2] > 0, so there are now 2 tested devices, and batteryPercentages stays the same.\nSo, the answer is 2.\n\n\nConstraints:\n\n1 <= n == batteryPercentages.length <= 100 \n0 <= batteryPercentages[i] <= 100\n\"\"\"\nclass Solution:\n def countTestedDevices(self, batteryPercentages: List[int]) -> int:\n ", "prompt_sft": "You are given a 0-indexed integer array batteryPercentages having length n, denoting the battery percentages of n 0-indexed devices.\nYour task is to test each device i in order from 0 to n - 1, by performing the following test operations:\n\nIf batteryPercentages[i] is greater than 0:\n\n\t\nIncrement the count of tested devices.\nDecrease the battery percentage of all devices with indices j in the range [i + 1, n - 1] by 1, ensuring their battery percentage never goes below 0, i.e, batteryPercentages[j] = max(0, batteryPercentages[j] - 1).\nMove to the next device.\n\n\nOtherwise, move to the next device without performing any test.\n\nReturn an integer denoting the number of devices that will be tested after performing the test operations in order.\n\nExample 1:\n\nInput: batteryPercentages = [1,1,2,1,3]\nOutput: 3\nExplanation: Performing the test operations in order starting from device 0:\nAt device 0, batteryPercentages[0] > 0, so there is now 1 tested device, and batteryPercentages becomes [1,0,1,0,2].\nAt device 1, batteryPercentages[1] == 0, so we move to the next device without testing.\nAt device 2, batteryPercentages[2] > 0, so there are now 2 tested devices, and batteryPercentages becomes [1,0,1,0,1].\nAt device 3, batteryPercentages[3] == 0, so we move to the next device without testing.\nAt device 4, batteryPercentages[4] > 0, so there are now 3 tested devices, and batteryPercentages stays the same.\nSo, the answer is 3.\n\nExample 2:\n\nInput: batteryPercentages = [0,1,2]\nOutput: 2\nExplanation: Performing the test operations in order starting from device 0:\nAt device 0, batteryPercentages[0] == 0, so we move to the next device without testing.\nAt device 1, batteryPercentages[1] > 0, so there is now 1 tested device, and batteryPercentages becomes [0,1,1].\nAt device 2, batteryPercentages[2] > 0, so there are now 2 tested devices, and batteryPercentages stays the same.\nSo, the answer is 2.\n\n\nConstraints:\n\n1 <= n == batteryPercentages.length <= 100 \n0 <= batteryPercentages[i] <= 100\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def countTestedDevices(self, batteryPercentages: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"batteryPercentages\": [1,1,2,1,3] }\nassert my_solution.countTestedDevices(**test_input) == 3\n\ntest_input = { \"batteryPercentages\": [0,1,2] }\nassert my_solution.countTestedDevices(**test_input) == 2\n\ntest_input = { \"batteryPercentages\": [0] }\nassert my_solution.countTestedDevices(**test_input) == 0\n\ntest_input = { \"batteryPercentages\": [1] }\nassert my_solution.countTestedDevices(**test_input) == 1\n\ntest_input = { \"batteryPercentages\": [0,0] }\nassert my_solution.countTestedDevices(**test_input) == 0\n\ntest_input = { \"batteryPercentages\": [0,1] }\nassert my_solution.countTestedDevices(**test_input) == 1\n\ntest_input = { \"batteryPercentages\": [0,2] }\nassert my_solution.countTestedDevices(**test_input) == 1\n\ntest_input = { \"batteryPercentages\": [1,0] }\nassert my_solution.countTestedDevices(**test_input) == 1\n\ntest_input = { \"batteryPercentages\": [1,2] }\nassert my_solution.countTestedDevices(**test_input) == 2\n\ntest_input = { \"batteryPercentages\": [2,1] }\nassert my_solution.countTestedDevices(**test_input) == 1\n\ntest_input = { \"batteryPercentages\": [2,2] }\nassert my_solution.countTestedDevices(**test_input) == 2\n\ntest_input = { \"batteryPercentages\": [0,0,1] }\nassert my_solution.countTestedDevices(**test_input) == 1\n\ntest_input = { \"batteryPercentages\": [0,0,2] }\nassert my_solution.countTestedDevices(**test_input) == 1\n\ntest_input = { \"batteryPercentages\": [1,1,0] }\nassert my_solution.countTestedDevices(**test_input) == 1\n\ntest_input = { \"batteryPercentages\": [1,2,0] }\nassert my_solution.countTestedDevices(**test_input) == 2\n\ntest_input = { \"batteryPercentages\": [1,3,1] }\nassert my_solution.countTestedDevices(**test_input) == 2\n\ntest_input = { \"batteryPercentages\": [2,0,1] }\nassert my_solution.countTestedDevices(**test_input) == 1\n\ntest_input = { \"batteryPercentages\": [2,2,0] }\nassert my_solution.countTestedDevices(**test_input) == 2\n\ntest_input = { \"batteryPercentages\": [2,2,2] }\nassert my_solution.countTestedDevices(**test_input) == 2\n\ntest_input = { \"batteryPercentages\": [3,0,3] }\nassert my_solution.countTestedDevices(**test_input) == 2\n\ntest_input = { \"batteryPercentages\": [3,3,1] }\nassert my_solution.countTestedDevices(**test_input) == 2\n\ntest_input = { \"batteryPercentages\": [3,3,3] }\nassert my_solution.countTestedDevices(**test_input) == 3\n\ntest_input = { \"batteryPercentages\": [0,2,1,4] }\nassert my_solution.countTestedDevices(**test_input) == 2\n\ntest_input = { \"batteryPercentages\": [1,4,4,1] }\nassert my_solution.countTestedDevices(**test_input) == 3\n\ntest_input = { \"batteryPercentages\": [3,1,2,0] }\nassert my_solution.countTestedDevices(**test_input) == 2\n\ntest_input = { \"batteryPercentages\": [3,2,1,1] }\nassert my_solution.countTestedDevices(**test_input) == 2\n\ntest_input = { \"batteryPercentages\": [3,2,1,3] }\nassert my_solution.countTestedDevices(**test_input) == 3\n\ntest_input = { \"batteryPercentages\": [4,1,4,4] }\nassert my_solution.countTestedDevices(**test_input) == 3\n\ntest_input = { \"batteryPercentages\": [4,2,0,1] }\nassert my_solution.countTestedDevices(**test_input) == 2\n\ntest_input = { \"batteryPercentages\": [4,2,1,3] }\nassert my_solution.countTestedDevices(**test_input) == 3\n\ntest_input = { \"batteryPercentages\": [4,4,4,2] }\nassert my_solution.countTestedDevices(**test_input) == 3\n\ntest_input = { \"batteryPercentages\": [0,3,1,3,5] }\nassert my_solution.countTestedDevices(**test_input) == 3\n\ntest_input = { \"batteryPercentages\": [0,4,2,5,3] }\nassert my_solution.countTestedDevices(**test_input) == 3\n\ntest_input = { \"batteryPercentages\": [0,5,4,2,0] }\nassert my_solution.countTestedDevices(**test_input) == 2\n\ntest_input = { \"batteryPercentages\": [2,2,3,0,2] }\nassert my_solution.countTestedDevices(**test_input) == 3\n\ntest_input = { \"batteryPercentages\": [2,3,5,0,1] }\nassert my_solution.countTestedDevices(**test_input) == 3\n\ntest_input = { \"batteryPercentages\": [2,4,5,2,0] }\nassert my_solution.countTestedDevices(**test_input) == 3\n\ntest_input = { \"batteryPercentages\": [4,3,3,5,4] }\nassert my_solution.countTestedDevices(**test_input) == 4\n\ntest_input = { \"batteryPercentages\": [5,4,1,0,3] }\nassert my_solution.countTestedDevices(**test_input) == 3\n\ntest_input = { \"batteryPercentages\": [5,5,5,2,0] }\nassert my_solution.countTestedDevices(**test_input) == 3\n\ntest_input = { \"batteryPercentages\": [0,2,4,3,0,2] }\nassert my_solution.countTestedDevices(**test_input) == 3\n\ntest_input = { \"batteryPercentages\": [0,4,5,3,3,2] }\nassert my_solution.countTestedDevices(**test_input) == 3\n\ntest_input = { \"batteryPercentages\": [1,3,1,5,4,5] }\nassert my_solution.countTestedDevices(**test_input) == 5\n\ntest_input = { \"batteryPercentages\": [1,6,0,3,3,6] }\nassert my_solution.countTestedDevices(**test_input) == 4\n\ntest_input = { \"batteryPercentages\": [3,1,3,5,2,0] }\nassert my_solution.countTestedDevices(**test_input) == 3\n\ntest_input = { \"batteryPercentages\": [3,2,6,2,6,0] }\nassert my_solution.countTestedDevices(**test_input) == 4\n\ntest_input = { \"batteryPercentages\": [4,1,5,3,5,2] }\nassert my_solution.countTestedDevices(**test_input) == 4\n\ntest_input = { \"batteryPercentages\": [4,3,3,2,4,3] }\nassert my_solution.countTestedDevices(**test_input) == 4\n\ntest_input = { \"batteryPercentages\": [4,5,2,3,6,2] }\nassert my_solution.countTestedDevices(**test_input) == 4\n\ntest_input = { \"batteryPercentages\": [5,1,1,2,1,4] }\nassert my_solution.countTestedDevices(**test_input) == 3\n\ntest_input = { \"batteryPercentages\": [5,1,6,6,3,6] }\nassert my_solution.countTestedDevices(**test_input) == 4\n\ntest_input = { \"batteryPercentages\": [6,1,5,1,4,5] }\nassert my_solution.countTestedDevices(**test_input) == 4\n\ntest_input = { \"batteryPercentages\": [6,2,2,3,4,6] }\nassert my_solution.countTestedDevices(**test_input) == 5\n\ntest_input = { \"batteryPercentages\": [6,2,3,0,2,0] }\nassert my_solution.countTestedDevices(**test_input) == 3\n\ntest_input = { \"batteryPercentages\": [1,0,6,3,6,3,1] }\nassert my_solution.countTestedDevices(**test_input) == 4\n\ntest_input = { \"batteryPercentages\": [2,1,7,3,0,3,3] }\nassert my_solution.countTestedDevices(**test_input) == 3\n\ntest_input = { \"batteryPercentages\": [2,3,7,0,6,4,4] }\nassert my_solution.countTestedDevices(**test_input) == 4\n\ntest_input = { \"batteryPercentages\": [2,5,2,4,2,1,3] }\nassert my_solution.countTestedDevices(**test_input) == 3\n\ntest_input = { \"batteryPercentages\": [2,5,2,7,6,5,5] }\nassert my_solution.countTestedDevices(**test_input) == 5\n\ntest_input = { \"batteryPercentages\": [4,2,6,4,7,6,7] }\nassert my_solution.countTestedDevices(**test_input) == 7\n\ntest_input = { \"batteryPercentages\": [4,2,6,6,3,3,7] }\nassert my_solution.countTestedDevices(**test_input) == 5\n\ntest_input = { \"batteryPercentages\": [4,4,3,0,2,6,6] }\nassert my_solution.countTestedDevices(**test_input) == 5\n\ntest_input = { \"batteryPercentages\": [5,2,2,3,4,6,6] }\nassert my_solution.countTestedDevices(**test_input) == 6\n\ntest_input = { \"batteryPercentages\": [5,4,6,0,7,2,2] }\nassert my_solution.countTestedDevices(**test_input) == 4\n\ntest_input = { \"batteryPercentages\": [6,6,7,0,1,7,2] }\nassert my_solution.countTestedDevices(**test_input) == 4\n\ntest_input = { \"batteryPercentages\": [0,5,1,4,5,0,4,8] }\nassert my_solution.countTestedDevices(**test_input) == 5\n\ntest_input = { \"batteryPercentages\": [1,0,7,0,7,4,5,7] }\nassert my_solution.countTestedDevices(**test_input) == 6\n\ntest_input = { \"batteryPercentages\": [2,5,3,4,4,8,6,5] }\nassert my_solution.countTestedDevices(**test_input) == 6\n\ntest_input = { \"batteryPercentages\": [2,6,3,4,5,6,2,6] }\nassert my_solution.countTestedDevices(**test_input) == 6\n\ntest_input = { \"batteryPercentages\": [4,5,2,1,3,7,3,5] }\nassert my_solution.countTestedDevices(**test_input) == 5\n\ntest_input = { \"batteryPercentages\": [6,5,4,8,6,8,3,6] }\nassert my_solution.countTestedDevices(**test_input) == 6\n\ntest_input = { \"batteryPercentages\": [7,4,0,8,5,5,2,0] }\nassert my_solution.countTestedDevices(**test_input) == 5\n\ntest_input = { \"batteryPercentages\": [7,5,3,2,3,5,8,6] }\nassert my_solution.countTestedDevices(**test_input) == 6\n\ntest_input = { \"batteryPercentages\": [8,0,4,3,2,6,6,1] }\nassert my_solution.countTestedDevices(**test_input) == 5\n\ntest_input = { \"batteryPercentages\": [8,3,0,1,0,8,6,8] }\nassert my_solution.countTestedDevices(**test_input) == 5\n\ntest_input = { \"batteryPercentages\": [8,6,7,1,0,1,3,7] }\nassert my_solution.countTestedDevices(**test_input) == 4\n\ntest_input = { \"batteryPercentages\": [0,6,8,8,0,1,2,3,4] }\nassert my_solution.countTestedDevices(**test_input) == 4\n\ntest_input = { \"batteryPercentages\": [2,7,9,7,2,9,0,3,9] }\nassert my_solution.countTestedDevices(**test_input) == 6\n\ntest_input = { \"batteryPercentages\": [8,1,9,8,5,3,4,4,1] }\nassert my_solution.countTestedDevices(**test_input) == 4\n\ntest_input = { \"batteryPercentages\": [8,4,0,1,1,6,5,3,5] }\nassert my_solution.countTestedDevices(**test_input) == 5\n\ntest_input = { \"batteryPercentages\": [8,4,1,5,8,5,8,7,9] }\nassert my_solution.countTestedDevices(**test_input) == 8\n\ntest_input = { \"batteryPercentages\": [8,4,9,8,9,0,0,4,9] }\nassert my_solution.countTestedDevices(**test_input) == 6\n\ntest_input = { \"batteryPercentages\": [8,9,4,4,1,9,8,9,1] }\nassert my_solution.countTestedDevices(**test_input) == 7\n\ntest_input = { \"batteryPercentages\": [2,5,8,9,1,5,10,9,6,3] }\nassert my_solution.countTestedDevices(**test_input) == 7\n\ntest_input = { \"batteryPercentages\": [2,6,5,4,1,5,3,3,3,9] }\nassert my_solution.countTestedDevices(**test_input) == 6\n\ntest_input = { \"batteryPercentages\": [7,7,7,3,6,6,4,3,5,10] }\nassert my_solution.countTestedDevices(**test_input) == 6\n\ntest_input = { \"batteryPercentages\": [9,3,10,1,8,2,4,3,3,0] }\nassert my_solution.countTestedDevices(**test_input) == 4\n\ntest_input = { \"batteryPercentages\": [10,10,2,0,2,7,6,7,10,4] }\nassert my_solution.countTestedDevices(**test_input) == 6\n\ntest_input = { \"batteryPercentages\": [0,8,7,9,4,10,4,3,7,11,7] }\nassert my_solution.countTestedDevices(**test_input) == 7\n\ntest_input = { \"batteryPercentages\": [1,2,3,5,6,11,3,2,11,0,8] }\nassert my_solution.countTestedDevices(**test_input) == 8\n\ntest_input = { \"batteryPercentages\": [5,10,4,10,10,6,8,1,8,10,3] }\nassert my_solution.countTestedDevices(**test_input) == 9\n\ntest_input = { \"batteryPercentages\": [7,10,2,7,11,8,11,4,1,4,5] }\nassert my_solution.countTestedDevices(**test_input) == 6\n\ntest_input = { \"batteryPercentages\": [7,11,0,4,1,10,5,3,2,0,2] }\nassert my_solution.countTestedDevices(**test_input) == 5\n\ntest_input = { \"batteryPercentages\": [8,8,1,8,6,2,5,2,8,5,6] }\nassert my_solution.countTestedDevices(**test_input) == 6\n\ntest_input = { \"batteryPercentages\": [8,9,10,10,1,5,4,6,7,2,4] }\nassert my_solution.countTestedDevices(**test_input) == 7\n\ntest_input = { \"batteryPercentages\": [9,9,2,3,2,2,9,6,11,1,10] }\nassert my_solution.countTestedDevices(**test_input) == 7\n\ntest_input = { \"batteryPercentages\": [10,0,6,2,6,6,11,1,8,10,5] }\nassert my_solution.countTestedDevices(**test_input) == 7\n\ntest_input = { \"batteryPercentages\": [1,4,7,2,12,8,1,11,5,10,2,3] }\nassert my_solution.countTestedDevices(**test_input) == 7\n\ntest_input = { \"batteryPercentages\": [2,5,4,4,9,6,10,0,11,8,2,10] }\nassert my_solution.countTestedDevices(**test_input) == 9\n\ntest_input = { \"batteryPercentages\": [4,11,9,8,9,11,11,5,11,6,12,11] }\nassert my_solution.countTestedDevices(**test_input) == 10", "start_time": 1702175400} +{"task_id": "weekly-contest-375-double-modular-exponentiation", "url": "https://leetcode.com/problems/double-modular-exponentiation", "title": "double-modular-exponentiation", "meta": {"questionId": "3234", "questionFrontendId": "2961", "title": "Double Modular Exponentiation", "titleSlug": "double-modular-exponentiation", "isPaidOnly": false, "difficulty": "Medium", "likes": 87, "dislikes": 12, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed 2D array variables where variables[i] = [ai, bi, ci, mi], and an integer target.\nAn index i is good if the following formula holds:\n\n0 <= i < variables.length\n((aibi % 10)ci) % mi == target\n\nReturn an array consisting of good indices in any order.\n\nExample 1:\n\nInput: variables = [[2,3,3,10],[3,3,3,1],[6,1,1,4]], target = 2\nOutput: [0,2]\nExplanation: For each index i in the variables array:\n1) For the index 0, variables[0] = [2,3,3,10], (23 % 10)3 % 10 = 2.\n2) For the index 1, variables[1] = [3,3,3,1], (33 % 10)3 % 1 = 0.\n3) For the index 2, variables[2] = [6,1,1,4], (61 % 10)1 % 4 = 2.\nTherefore we return [0,2] as the answer.\n\nExample 2:\n\nInput: variables = [[39,3,1000,1000]], target = 17\nOutput: []\nExplanation: For each index i in the variables array:\n1) For the index 0, variables[0] = [39,3,1000,1000], (393 % 10)1000 % 1000 = 1.\nTherefore we return [] as the answer.\n\n\nConstraints:\n\n1 <= variables.length <= 100\nvariables[i] == [ai, bi, ci, mi]\n1 <= ai, bi, ci, mi <= 103\n0 <= target <= 103\n\"\"\"\nclass Solution:\n def getGoodIndices(self, variables: List[List[int]], target: int) -> List[int]:\n ", "prompt_sft": "You are given a 0-indexed 2D array variables where variables[i] = [ai, bi, ci, mi], and an integer target.\nAn index i is good if the following formula holds:\n\n0 <= i < variables.length\n((aibi % 10)ci) % mi == target\n\nReturn an array consisting of good indices in any order.\n\nExample 1:\n\nInput: variables = [[2,3,3,10],[3,3,3,1],[6,1,1,4]], target = 2\nOutput: [0,2]\nExplanation: For each index i in the variables array:\n1) For the index 0, variables[0] = [2,3,3,10], (23 % 10)3 % 10 = 2.\n2) For the index 1, variables[1] = [3,3,3,1], (33 % 10)3 % 1 = 0.\n3) For the index 2, variables[2] = [6,1,1,4], (61 % 10)1 % 4 = 2.\nTherefore we return [0,2] as the answer.\n\nExample 2:\n\nInput: variables = [[39,3,1000,1000]], target = 17\nOutput: []\nExplanation: For each index i in the variables array:\n1) For the index 0, variables[0] = [39,3,1000,1000], (393 % 10)1000 % 1000 = 1.\nTherefore we return [] as the answer.\n\n\nConstraints:\n\n1 <= variables.length <= 100\nvariables[i] == [ai, bi, ci, mi]\n1 <= ai, bi, ci, mi <= 103\n0 <= target <= 103\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def getGoodIndices(self, variables: List[List[int]], target: int) -> List[int]:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"variables\": [[2,3,3,10],[3,3,3,1],[6,1,1,4]], \"target\": 2 }\nassert my_solution.getGoodIndices(**test_input) == [0,2]\n\ntest_input = { \"variables\": [[39,3,1000,1000]], \"target\": 17 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[3,2,4,2],[3,3,1,3],[2,2,2,4],[4,4,2,3],[2,4,1,3]], \"target\": 4 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[9,2,8,5],[7,8,8,8],[8,9,6,1],[8,6,2,2],[3,6,3,1]], \"target\": 9 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[2,2,3,2],[1,3,3,2],[3,2,2,3],[3,1,2,3],[1,2,3,1],[2,2,2,2],[2,1,3,1],[3,2,2,2],[2,1,3,1],[3,3,1,3]], \"target\": 0 }\nassert my_solution.getGoodIndices(**test_input) == [0,2,3,4,5,6,8]\n\ntest_input = { \"variables\": [[1,3,2,3],[4,2,3,3],[4,1,4,4],[4,2,3,1],[4,2,1,1],[1,2,4,1],[1,1,4,2],[1,4,4,3],[1,2,2,3]], \"target\": 2 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[5,4,1,3],[2,5,5,1],[5,3,4,1]], \"target\": 5 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[4,7,6,7],[7,6,6,4],[6,8,2,3],[8,3,5,8]], \"target\": 4 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[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]], \"target\": 0 }\nassert my_solution.getGoodIndices(**test_input) == [0,1,2,3,4,5,6]\n\ntest_input = { \"variables\": [[3,5,1,2],[3,2,5,2],[4,4,3,2],[3,2,5,3],[1,5,1,4]], \"target\": 1 }\nassert my_solution.getGoodIndices(**test_input) == [0,1,4]\n\ntest_input = { \"variables\": [[1,2,1,1],[2,2,2,2],[1,1,1,2],[1,2,2,2]], \"target\": 2 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[3,3,5,6],[8,2,9,2],[1,4,6,1],[6,4,7,7]], \"target\": 8 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[3,5,4,3],[1,3,3,1],[3,3,5,5],[4,5,5,5],[5,1,4,3],[2,5,3,4]], \"target\": 7 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[9,7,2,7],[9,1,8,1],[9,3,5,6],[6,1,8,4],[9,6,2,3]], \"target\": 8 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[10,6,8,7],[3,6,1,8]], \"target\": 5 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[4,6,5,2],[2,6,4,6],[4,6,3,6],[2,2,6,5],[6,5,5,2]], \"target\": 2 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[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]], \"target\": 1 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[5,6,5,1],[4,3,1,6],[5,4,4,2]], \"target\": 4 }\nassert my_solution.getGoodIndices(**test_input) == [1]\n\ntest_input = { \"variables\": [[5,1,2,4],[4,5,5,5],[5,9,7,4],[7,9,6,3],[1,8,6,1],[1,1,9,9],[3,7,6,5],[2,6,2,6]], \"target\": 1 }\nassert my_solution.getGoodIndices(**test_input) == [0,2,3,5]\n\ntest_input = { \"variables\": [[1,3,2,5],[5,4,1,2],[2,2,3,2],[4,2,5,4],[1,5,4,1],[2,2,5,2],[3,3,2,1],[2,5,4,3],[2,1,5,1]], \"target\": 4 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[3,2,1,3],[1,2,1,1],[2,1,3,2],[2,3,1,3],[3,3,1,1],[2,3,2,1],[2,1,3,3],[1,2,2,2],[3,2,1,3]], \"target\": 1 }\nassert my_solution.getGoodIndices(**test_input) == [7]\n\ntest_input = { \"variables\": [[3,3,2,2],[3,3,2,2]], \"target\": 0 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[1,6,7,5],[6,3,1,5],[7,5,5,4],[6,2,2,4],[6,1,1,2],[2,6,5,4]], \"target\": 8 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[7,8,9,3],[7,8,2,8],[2,4,4,8],[8,8,4,4]], \"target\": 6 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[6,7,6,6],[1,2,4,8],[6,4,2,4],[3,2,4,5]], \"target\": 2 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[2,3,1,1],[3,2,1,1],[2,1,2,3]], \"target\": 2 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[9,8,10,1],[7,1,3,9],[6,8,9,10],[4,8,8,9]], \"target\": 2 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[4,3,2,2],[3,6,4,6],[1,4,1,4],[5,2,5,1],[8,3,6,3],[8,4,8,3]], \"target\": 6 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[3,4,4,2],[4,4,1,2],[1,1,3,2],[3,1,4,3],[2,2,3,4],[2,3,2,4],[3,1,4,4],[1,4,1,4],[3,2,1,4]], \"target\": 0 }\nassert my_solution.getGoodIndices(**test_input) == [1,3,4,5]\n\ntest_input = { \"variables\": [[2,1,1,1],[2,2,2,2],[1,2,1,2],[1,1,1,1],[1,1,1,1],[2,1,2,2],[1,1,2,1],[2,2,2,2]], \"target\": 0 }\nassert my_solution.getGoodIndices(**test_input) == [0,1,3,4,5,6,7]\n\ntest_input = { \"variables\": [[3,1,2,4],[3,3,4,2],[3,4,3,4],[3,3,4,2]], \"target\": 1 }\nassert my_solution.getGoodIndices(**test_input) == [0,1,2,3]\n\ntest_input = { \"variables\": [[4,10,5,8],[7,7,5,8],[4,8,6,2],[6,3,3,2]], \"target\": 4 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[3,5,3,6],[3,1,6,3],[6,4,1,5],[3,2,3,5],[1,4,7,5],[6,6,6,2],[7,5,6,3],[1,2,7,1],[1,1,6,3]], \"target\": 4 }\nassert my_solution.getGoodIndices(**test_input) == [3]\n\ntest_input = { \"variables\": [[1,4,2,3],[4,3,1,4],[3,3,1,3],[1,4,1,3]], \"target\": 0 }\nassert my_solution.getGoodIndices(**test_input) == [1]\n\ntest_input = { \"variables\": [[1,4,2,2],[5,5,1,2],[3,4,2,3]], \"target\": 6 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[3,5,1,1],[4,8,6,8],[5,1,4,9],[4,3,1,2],[5,9,4,7],[8,7,7,1],[9,3,7,5]], \"target\": 0 }\nassert my_solution.getGoodIndices(**test_input) == [0,1,3,5]\n\ntest_input = { \"variables\": [[1,1,1,1],[2,2,2,1],[2,2,2,1],[2,2,2,2],[1,1,1,1],[1,1,1,1],[1,1,1,1]], \"target\": 1 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[5,5,6,5],[4,1,2,2],[6,2,5,3],[1,1,5,5],[3,5,6,5]], \"target\": 2 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[1,4,1,3],[2,4,4,1],[1,1,3,1],[2,3,3,1]], \"target\": 0 }\nassert my_solution.getGoodIndices(**test_input) == [1,2,3]\n\ntest_input = { \"variables\": [[1,1,1,1],[1,1,1,1]], \"target\": 1 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[4,2,1,7],[3,3,7,1],[5,5,8,2],[5,1,3,1]], \"target\": 4 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[1,5,7,2],[2,10,7,10],[6,8,2,2],[9,4,1,2],[1,7,4,1]], \"target\": 3 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[5,5,3,5],[4,2,5,9],[4,6,6,1],[4,5,3,6]], \"target\": 8 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[1,1,2,1],[1,1,3,2],[2,3,3,2],[1,2,3,2],[1,1,1,3],[2,2,1,2]], \"target\": 3 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[4,1,3,5],[4,7,1,6],[7,3,5,4],[2,4,2,7],[6,3,4,7]], \"target\": 7 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[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]], \"target\": 1 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[4,2,3,7],[2,9,6,2],[3,8,9,2],[1,7,7,3],[1,3,8,1],[2,4,5,1],[3,6,3,2],[4,4,6,8]], \"target\": 4 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[8,3,7,1],[7,8,3,2],[4,1,5,3],[6,6,6,3],[2,4,7,5]], \"target\": 2 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[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]], \"target\": 1 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[1,1,6,6],[1,1,1,2],[3,6,6,1],[4,5,5,6],[3,1,6,6],[3,2,2,1],[6,1,1,2]], \"target\": 6 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[4,2,2,1],[6,3,2,1],[2,4,3,2],[1,1,6,6],[4,6,2,1],[5,4,2,1],[1,2,6,1],[6,2,4,4]], \"target\": 6 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[2,2,2,2],[1,2,2,3]], \"target\": 3 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[1,1,1,1],[1,1,1,1]], \"target\": 0 }\nassert my_solution.getGoodIndices(**test_input) == [0,1]\n\ntest_input = { \"variables\": [[2,5,8,2],[2,6,1,2],[7,4,8,9],[6,3,1,4],[7,1,6,7],[4,6,2,7],[8,2,2,7],[4,5,3,8],[1,2,6,4]], \"target\": 2 }\nassert my_solution.getGoodIndices(**test_input) == [3,6]\n\ntest_input = { \"variables\": [[4,2,4,1],[6,1,2,6],[4,3,3,2]], \"target\": 8 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[1,1,1,1],[1,1,1,1],[1,1,1,1],[1,1,1,1]], \"target\": 1 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[6,4,3,5],[7,4,2,6],[1,4,2,1],[4,5,4,5],[7,2,2,7],[7,5,4,3],[2,7,1,3],[6,7,2,2],[4,7,4,1],[7,3,2,1]], \"target\": 1 }\nassert my_solution.getGoodIndices(**test_input) == [0,1,3,5]\n\ntest_input = { \"variables\": [[4,10,5,8],[8,8,9,8],[7,1,5,4],[8,9,2,2],[2,2,8,7],[6,8,10,3],[6,8,4,4],[5,4,10,5],[3,7,8,2]], \"target\": 1 }\nassert my_solution.getGoodIndices(**test_input) == [8]\n\ntest_input = { \"variables\": [[7,5,4,2],[2,1,3,6],[7,2,2,3],[1,4,7,3]], \"target\": 3 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[2,3,3,3],[3,2,1,3],[2,2,3,2],[3,1,2,2],[1,2,2,1],[2,3,3,3],[3,1,2,2]], \"target\": 1 }\nassert my_solution.getGoodIndices(**test_input) == [3,6]\n\ntest_input = { \"variables\": [[10,2,6,2],[8,10,5,7]], \"target\": 0 }\nassert my_solution.getGoodIndices(**test_input) == [0]\n\ntest_input = { \"variables\": [[6,8,3,6],[4,8,3,1],[6,8,6,5],[7,4,7,1],[5,2,1,5],[2,3,5,7],[3,2,6,3],[4,3,7,1]], \"target\": 6 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[5,5,5,1],[6,1,3,2],[3,1,2,6],[2,6,6,5],[6,1,3,6],[4,2,3,1],[2,5,3,5],[6,6,6,2]], \"target\": 4 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[1,1,1,2],[2,1,1,1],[2,1,1,1],[1,1,1,1],[2,1,2,2],[2,2,2,2],[1,1,1,1],[1,2,2,2],[1,2,1,1]], \"target\": 0 }\nassert my_solution.getGoodIndices(**test_input) == [1,2,3,4,5,6,8]\n\ntest_input = { \"variables\": [[9,4,4,9],[9,4,2,6],[7,5,1,4],[9,2,2,3],[6,5,1,2],[2,7,2,9],[1,8,1,6],[5,4,9,7],[8,1,7,4]], \"target\": 1 }\nassert my_solution.getGoodIndices(**test_input) == [0,1,3,5,6]\n\ntest_input = { \"variables\": [[1,3,1,3],[2,1,3,2],[2,2,1,1],[1,2,1,3]], \"target\": 2 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[3,5,5,1],[4,2,6,3],[3,5,6,6],[5,3,1,1],[5,1,3,4],[6,1,6,1]], \"target\": 1 }\nassert my_solution.getGoodIndices(**test_input) == [4]\n\ntest_input = { \"variables\": [[1,2,1,2],[1,2,1,2]], \"target\": 0 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[1,4,2,4],[5,5,3,5],[3,5,3,4],[2,4,5,5],[5,4,4,5],[2,2,2,3]], \"target\": 5 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[1,4,4,4],[5,2,4,4],[1,1,5,3],[3,4,1,2],[3,1,2,3],[4,3,3,3],[3,5,4,1],[2,1,4,5],[3,3,1,3]], \"target\": 1 }\nassert my_solution.getGoodIndices(**test_input) == [0,1,2,3,5,7,8]\n\ntest_input = { \"variables\": [[1,1,6,1],[3,8,4,7],[8,5,5,9],[4,9,1,3],[9,1,1,9]], \"target\": 0 }\nassert my_solution.getGoodIndices(**test_input) == [0,4]\n\ntest_input = { \"variables\": [[2,1,2,2],[2,2,2,1],[2,1,2,2],[1,2,1,1],[2,1,2,2],[2,2,2,2]], \"target\": 1 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[5,7,4,2],[2,8,10,10],[4,4,7,2],[7,4,4,6]], \"target\": 10 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[1,1,1,1],[1,1,1,1],[1,1,1,1],[1,1,1,1],[1,1,1,1],[1,1,1,1]], \"target\": 1 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[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]], \"target\": 0 }\nassert my_solution.getGoodIndices(**test_input) == [0,1,2,3,4,5,6,7,8,9]\n\ntest_input = { \"variables\": [[9,3,6,3],[9,7,2,5],[2,8,9,9],[4,7,7,4],[2,7,3,9],[8,5,5,3],[7,5,4,3],[9,9,2,9],[9,4,8,8]], \"target\": 4 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[7,5,2,3],[1,7,2,3],[9,1,7,1]], \"target\": 3 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[2,5,7,3],[2,6,5,1],[4,3,6,5]], \"target\": 3 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[7,8,1,1],[1,5,4,1],[4,7,8,9],[7,9,2,4],[5,1,4,3],[3,9,4,1],[6,6,1,8],[4,8,5,1],[1,4,5,9]], \"target\": 1 }\nassert my_solution.getGoodIndices(**test_input) == [3,4,8]\n\ntest_input = { \"variables\": [[5,1,6,1],[3,6,5,2],[4,2,5,4],[2,3,5,2],[2,4,3,1],[3,2,3,6],[6,2,4,6],[6,3,3,2]], \"target\": 0 }\nassert my_solution.getGoodIndices(**test_input) == [0,2,3,4,6,7]\n\ntest_input = { \"variables\": [[3,2,5,3],[9,4,2,4],[2,4,7,7],[1,4,9,2],[5,1,5,5],[9,5,6,7],[9,1,4,7]], \"target\": 5 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[3,2,2,2],[3,1,3,2],[2,1,2,2],[3,2,3,3],[1,1,2,3],[1,1,3,1]], \"target\": 0 }\nassert my_solution.getGoodIndices(**test_input) == [2,3,5]\n\ntest_input = { \"variables\": [[1,5,2,1],[3,5,3,2],[1,2,4,1],[1,4,1,4],[4,4,1,3],[4,2,4,5],[2,2,4,1],[2,1,3,3]], \"target\": 4 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[3,2,7,6],[10,6,5,10],[2,4,10,7],[9,5,8,6],[10,6,3,10],[9,6,5,2],[8,10,1,2],[7,1,8,8],[7,7,4,8],[8,3,8,1]], \"target\": 4 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[6,6,5,2],[3,5,4,3],[2,4,3,3],[6,3,4,4],[4,1,3,6],[1,6,3,5],[3,3,5,5]], \"target\": 0 }\nassert my_solution.getGoodIndices(**test_input) == [0,1,2,3]\n\ntest_input = { \"variables\": [[10,3,8,9],[9,1,5,5],[4,5,10,5],[9,8,3,5],[3,5,4,7],[1,10,2,3],[6,2,4,8],[6,4,3,2],[5,9,9,2]], \"target\": 8 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[7,7,4,3],[2,10,10,4],[8,1,9,1],[9,7,7,9],[8,9,8,5],[9,8,4,2],[1,9,3,8],[6,8,3,1]], \"target\": 8 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[9,8,1,4],[5,2,7,4],[5,6,3,4],[9,5,9,8],[2,1,10,10],[10,9,9,2],[8,5,2,3],[10,10,3,8],[1,7,8,1],[1,4,3,5]], \"target\": 2 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[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]], \"target\": 1 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[2,3,4,4],[2,3,7,2],[4,2,6,3],[2,3,3,6],[5,1,2,7],[7,6,7,1]], \"target\": 5 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[3,3,8,8],[2,5,6,5],[8,1,2,3],[1,4,8,7],[8,5,5,7],[6,6,3,9],[5,6,7,1],[4,7,5,1],[1,5,1,5],[5,3,2,1]], \"target\": 2 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[3,1,7,8],[4,3,7,8],[7,4,2,2]], \"target\": 1 }\nassert my_solution.getGoodIndices(**test_input) == [2]\n\ntest_input = { \"variables\": [[4,4,8,8],[4,7,8,7],[1,4,8,2],[5,5,6,4],[7,8,4,3],[8,6,2,1]], \"target\": 1 }\nassert my_solution.getGoodIndices(**test_input) == [2,3,4]\n\ntest_input = { \"variables\": [[2,5,2,5],[1,1,4,1],[3,2,4,3],[3,1,3,4]], \"target\": 1 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[2,2,1,2],[2,2,2,2],[2,2,1,2]], \"target\": 2 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[7,6,4,6],[3,7,2,3],[7,7,1,7],[7,7,6,5],[6,1,1,4],[1,4,2,3],[1,2,4,2],[3,2,2,1],[7,6,2,5],[2,4,5,7]], \"target\": 7 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[1,1,2,1],[1,1,1,2],[1,1,2,1],[2,1,1,2],[1,1,2,1],[2,1,1,1]], \"target\": 2 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[4,5,8,5],[4,2,9,9],[2,3,3,3],[8,6,3,1]], \"target\": 2 }\nassert my_solution.getGoodIndices(**test_input) == [2]\n\ntest_input = { \"variables\": [[4,1,4,2],[3,4,3,4],[5,5,1,5],[5,1,1,4],[4,2,1,5],[5,2,1,1],[1,4,1,4],[1,4,5,5],[5,1,4,5],[1,2,1,2]], \"target\": 2 }\nassert my_solution.getGoodIndices(**test_input) == []\n\ntest_input = { \"variables\": [[3,1,3,3],[1,2,1,2],[3,1,1,3],[2,2,1,1],[3,3,2,2],[2,3,1,1]], \"target\": 0 }\nassert my_solution.getGoodIndices(**test_input) == [0,2,3,5]", "start_time": 1702175400} +{"task_id": "weekly-contest-375-count-subarrays-where-max-element-appears-at-least-k-times", "url": "https://leetcode.com/problems/count-subarrays-where-max-element-appears-at-least-k-times", "title": "count-subarrays-where-max-element-appears-at-least-k-times", "meta": {"questionId": "3213", "questionFrontendId": "2962", "title": "Count Subarrays Where Max Element Appears at Least K Times", "titleSlug": "count-subarrays-where-max-element-appears-at-least-k-times", "isPaidOnly": false, "difficulty": "Medium", "likes": 215, "dislikes": 10, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given an integer array nums and a positive integer k.\nReturn the number of subarrays where the maximum element of nums appears at least k times in that subarray.\nA subarray is a contiguous sequence of elements within an array.\n\nExample 1:\n\nInput: nums = [1,3,2,3,3], k = 2\nOutput: 6\nExplanation: The subarrays that contain the element 3 at least 2 times are: [1,3,2,3], [1,3,2,3,3], [3,2,3], [3,2,3,3], [2,3,3] and [3,3].\n\nExample 2:\n\nInput: nums = [1,4,2,1], k = 3\nOutput: 0\nExplanation: No subarray contains the element 4 at least 3 times.\n\n\nConstraints:\n\n1 <= nums.length <= 105\n1 <= nums[i] <= 106\n1 <= k <= 105\n\"\"\"\nclass Solution:\n def countSubarrays(self, nums: List[int], k: int) -> int:\n ", "prompt_sft": "You are given an integer array nums and a positive integer k.\nReturn the number of subarrays where the maximum element of nums appears at least k times in that subarray.\nA subarray is a contiguous sequence of elements within an array.\n\nExample 1:\n\nInput: nums = [1,3,2,3,3], k = 2\nOutput: 6\nExplanation: The subarrays that contain the element 3 at least 2 times are: [1,3,2,3], [1,3,2,3,3], [3,2,3], [3,2,3,3], [2,3,3] and [3,3].\n\nExample 2:\n\nInput: nums = [1,4,2,1], k = 3\nOutput: 0\nExplanation: No subarray contains the element 4 at least 3 times.\n\n\nConstraints:\n\n1 <= nums.length <= 105\n1 <= nums[i] <= 106\n1 <= k <= 105\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def countSubarrays(self, nums: List[int], k: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,3,2,3,3], \"k\": 2 }\nassert my_solution.countSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [1,4,2,1], \"k\": 3 }\nassert my_solution.countSubarrays(**test_input) == 0\n\ntest_input = { \"nums\": [61,23,38,23,56,40,82,56,82,82,82,70,8,69,8,7,19,14,58,42,82,10,82,78,15,82], \"k\": 2 }\nassert my_solution.countSubarrays(**test_input) == 224\n\ntest_input = { \"nums\": [37,20,38,66,34,38,9,41,1,14,25,63,8,12,66,66,60,12,35,27,16,38,12,66,38,36,59,54,66,54,66,48,59,66,34,11,50,66,42,51,53,66,31,24,66,44,66,1,66,66,29,54], \"k\": 5 }\nassert my_solution.countSubarrays(**test_input) == 594\n\ntest_input = { \"nums\": [28,5,58,91,24,91,53,9,48,85,16,70,91,91,47,91,61,4,54,61,49], \"k\": 1 }\nassert my_solution.countSubarrays(**test_input) == 187\n\ntest_input = { \"nums\": [43,105,105,88,19,82,95,32,80,37,49,105,25,105,46,54,45,84,105,88,26,20,49,54,31,105,8,103,37,32,105,105,97,27,105,89,105,47,25,87,29,105,105,105,24,105,105,48,19,91,96,71], \"k\": 7 }\nassert my_solution.countSubarrays(**test_input) == 454\n\ntest_input = { \"nums\": [107,101,180,137,191,148,83,15,188,22,100,124,69,94,191,181,171,64,136,96,91,191,107,191,191,191,107,191,191,11,140,33,4,110,83,5,86,33,42,186,191,6,42,61,94,129,191,119,191,134,43,182,191,187,63,116,172,118,50,141,124,191,125,145,191,34,191,191], \"k\": 9 }\nassert my_solution.countSubarrays(**test_input) == 548\n\ntest_input = { \"nums\": [41,121,92,15,24,59,45,110,97,132,75,72,31,38,103,37,132,91,132,132,105,24], \"k\": 3 }\nassert my_solution.countSubarrays(**test_input) == 61\n\ntest_input = { \"nums\": [21,11,13,15,16,21,8,9,6,21], \"k\": 2 }\nassert my_solution.countSubarrays(**test_input) == 10\n\ntest_input = { \"nums\": [31,18,36,166,166,166,135,166,166,12,102], \"k\": 3 }\nassert my_solution.countSubarrays(**test_input) == 31\n\ntest_input = { \"nums\": [2,2,2,2,1,3,3,2,2,1,1,3,1,1,2,3,2,1,1,2,1,1,2,1,2,1,2,1,3,1,3,3], \"k\": 5 }\nassert my_solution.countSubarrays(**test_input) == 31\n\ntest_input = { \"nums\": [3,2,4,4,3,4,3,1,1,1,1,3,2,1,2,1,3,4,4,1,2,4,1,1,2,3,3,3,4,4,4,1,3,1,4,1,4,4,4,2,2,3,4,3,3,2,2,2,1,2,4,2,2,4,4,1,3,2,3,2,4,4,4,2,3,4,2,4,1,4,1,4,1,4,4,3,4,2,4,3,3,2,3,3,2,3,4,2,1,1,1,2,3], \"k\": 23 }\nassert my_solution.countSubarrays(**test_input) == 473\n\ntest_input = { \"nums\": [1,1,1,2,3,2,1,2,3,3,3,3,2,3,2,1,1,2,2,1,3,2,3,1,2,1,3,1,1,3,1,2,1,1,1,1,1,1,3], \"k\": 8 }\nassert my_solution.countSubarrays(**test_input) == 148\n\ntest_input = { \"nums\": [54,161,161,161,161,31,74,51,87,19,161,116,108,149,6,19,155,101,161,161,154,161,78,132,62,156,112,51,161,42,92,151,142,17,110,85], \"k\": 4 }\nassert my_solution.countSubarrays(**test_input) == 279\n\ntest_input = { \"nums\": [97,102,144,55,144,128,16,93,144,9,144,15,144,144,32,68,144,60,94,56,103,5,41,27,48,144,12,86,129,144,144,99,93,96,144,73,106,76,107,144,53,21,144,144,98,32,85,97,71,127,144,9,144,144,133,125,144,135,52,144,144,46,134,23,23,144,79], \"k\": 1 }\nassert my_solution.countSubarrays(**test_input) == 2163\n\ntest_input = { \"nums\": [17,17,15,9,14,11,15,1,6,2,1,17,3,17,11,12,9,11,2,4,15,17,3,17,8,6,7,12,3,16,2,9,14,17,17,17,3,7,8,9,8,17,17,17,4,2,12,17,7,17,17,16,17,17,8,12,11,3,10,4,10,17,14,7,5,17,12,10,17,13,5,17,8,14,9,17,17,17,7,16,10,13,17,15,1,14,6,8,11,3], \"k\": 15 }\nassert my_solution.countSubarrays(**test_input) == 1055\n\ntest_input = { \"nums\": [17,12,16,17,7,1,12,6,17,5,17,13,16,16,17,14,17,6,17,17,17,17,16,17,14,8,14,1,12,13,17,17,14,8,14,5,16,17,17], \"k\": 5 }\nassert my_solution.countSubarrays(**test_input) == 404\n\ntest_input = { \"nums\": [98,59,98,32,45,15,98,98,98,65,98,10,98,89,87,51,42,58,76,23,85,98,98,35,18,65,39,88,56,62,10,32,8,16,32,98,6,39,14,24,98,95,68,98,77,47,98,23,69,98,49,98,7,11,92,98,27,25,85,98,45,30,50,62,46,1,79,58,69,15,59,57,85,19,98,95,98,67,52,98,59,8,98,98,98,73,86,20,98,96,21,98,79,97,52,22,98,86], \"k\": 12 }\nassert my_solution.countSubarrays(**test_input) == 1168\n\ntest_input = { \"nums\": [6,50,118,27,133,133,3,121,133,72,117,133,91,57,107,93,66,122,133,6,133,122,81,20,133,133,121,133,46,25,133,133,133,17,8,49,133,116,40,133,67,9,133,133,133,133,109,41,127,13,39,133,133,133,122,58,8,125,33,62], \"k\": 12 }\nassert my_solution.countSubarrays(**test_input) == 538\n\ntest_input = { \"nums\": [94,34,112,106,112,13,12,112,112,21,48,71,112,104,112,29,99,58,23,11,49,112,20,86], \"k\": 4 }\nassert my_solution.countSubarrays(**test_input) == 105\n\ntest_input = { \"nums\": [21,27,9,85,1,7,28,11,44,39,85,52,51,30,67,83,75,10,57,59,53,85,75,33,35,85,76,85,65,85,85,85,35,4,60,85,85,72,57,42,34,85,53,85,85,36,85,56,13,16,69,55,81,24,85,27,54,66,10,85,30,58,71,43,85,66,42,27,85,70], \"k\": 13 }\nassert my_solution.countSubarrays(**test_input) == 508\n\ntest_input = { \"nums\": [8,14,7,1,11,10,1,13,7,14,14,6,13], \"k\": 2 }\nassert my_solution.countSubarrays(**test_input) == 32\n\ntest_input = { \"nums\": [165,135,165,46,126,165,73,165,165,155,150,165,40,38,165,145,137,106,10], \"k\": 7 }\nassert my_solution.countSubarrays(**test_input) == 5\n\ntest_input = { \"nums\": [9,3,12,6,24,23,24], \"k\": 2 }\nassert my_solution.countSubarrays(**test_input) == 5\n\ntest_input = { \"nums\": [42,85,78,92,46,63,21,14,22,37,96,50,74], \"k\": 1 }\nassert my_solution.countSubarrays(**test_input) == 33\n\ntest_input = { \"nums\": [73,54,15,4,23,70,53,65,73,73,2,72,36,71,73,69,35,18,62,73,62,73,73,50,30,73,20,71,60,9,12,57,48,73,40,20,8,73,73,73,34,59,31,49,73,5,51,36,47,38,36,58,34,42,23,28,52,73], \"k\": 1 }\nassert my_solution.countSubarrays(**test_input) == 1537\n\ntest_input = { \"nums\": [52,88,92,92,44,4,92,37,27,59,3,3,76,51,21,89,92,31,26,10,47,69,30,68,60,92,80,19,65,38,92,4,54,88,92,75,56,71,11,92,44,43,56,92,16,66,22,70], \"k\": 2 }\nassert my_solution.countSubarrays(**test_input) == 796\n\ntest_input = { \"nums\": [29,9,43,5,8,52,24,52,52,41,33,52,27,52,8,6,35,52,27,52,7,2,9,52,52,42,52,52], \"k\": 7 }\nassert my_solution.countSubarrays(**test_input) == 76\n\ntest_input = { \"nums\": [165,165,58,153,45,124,165,143,38,165,165,165,165,73,8,138,165,139,165,165,59,40,120,165,123,92,98,136,161], \"k\": 1 }\nassert my_solution.countSubarrays(**test_input) == 394\n\ntest_input = { \"nums\": [28,64,64,63,21,64,55,64,10,30,12,5,64,56,63,64,64,31,31,64,19,54,53,64,58,44,64,28,64,64,63,10,64,64,57,29,44,32,50,55,49,21,64,64,34,26,28,64,15,31,28,64,45,64,19,54,9,41,25,33,7,60,1,7,34,14,4,64,64,64,55,49,3,41,28,42,40,52,25,46,25,15], \"k\": 18 }\nassert my_solution.countSubarrays(**test_input) == 229\n\ntest_input = { \"nums\": [97,23,53,33,141,150,128,153,71,39,153,35,125,143], \"k\": 2 }\nassert my_solution.countSubarrays(**test_input) == 32\n\ntest_input = { \"nums\": [144,144,87,144,18,53,129,61,34,123,141,68,37,23,94,28,64,58,16,36,27,112,144,80,77,144,97,142,8,101,14,74,37,115,115,144,99,37,144,48,28,110,13,78,144,144,83,7,112,144,144,144,78,61,87,144,144,61,144,44,123,74,144,142], \"k\": 4 }\nassert my_solution.countSubarrays(**test_input) == 1083\n\ntest_input = { \"nums\": [63,129,134,61,134,134,134,43,74,4,111], \"k\": 2 }\nassert my_solution.countSubarrays(**test_input) == 38\n\ntest_input = { \"nums\": [46,105,44,36,106,35,91,8,52,106,95,86,75,7,19,30,25,27,18,72,106,106,33,106,6,63,67,45,15,106,106,6,42,106,27,14,18,106,4,106,95,64,23,93,106,37,106,106,16,81,91,79,106,97,106,66,31,59,58], \"k\": 1 }\nassert my_solution.countSubarrays(**test_input) == 1637\n\ntest_input = { \"nums\": [78,120,110,53,53,120,116,39,64,120,120,120,120,120,97,28,92,120,101,5,46,92], \"k\": 1 }\nassert my_solution.countSubarrays(**test_input) == 224\n\ntest_input = { \"nums\": [111,111,72,111,111,56,21,95,111,101,38,77,111,111,76,58,70,72,32,72,19,111,111,63,39,111], \"k\": 9 }\nassert my_solution.countSubarrays(**test_input) == 5\n\ntest_input = { \"nums\": [33,82,82,82,71,39,17,82,38,75,82,2,82,82,9,82,57,12,78,65,29,20,82,82,50,11,39,74,65,69,81,71,25,82,46,43,49,80], \"k\": 6 }\nassert my_solution.countSubarrays(**test_input) == 219\n\ntest_input = { \"nums\": [83,72,17,147,147,57,147,22,120,107,59,133,123,91,147,147,72,147,31,147,147,147,96,147,18,25,13,8,18,59,46,91,15,147,25,30,6,147,113,27,84,95,38,147,147,147,106,53,127,132,55,147,22,147,124,102,17,69,131,147,4,95,59,38,147,147,41,99,142,147,136,142,57,26,16,3,142], \"k\": 8 }\nassert my_solution.countSubarrays(**test_input) == 1336\n\ntest_input = { \"nums\": [52,95,173,26,173,16,4,144,173,77,22,103,162,120,77,173,173,89,173,104,62,151,173,124,173,117,113,164,3,70,15,144,161,118,139,16,157,173,154,151,37,69,60,173,173,168,148,97,173,125,161,128,85,64,70,102,100,168,56,57,157,112,119,135,42,72,135,173,173,124,143,121,75,37,162,161,102,50,173,173,107], \"k\": 4 }\nassert my_solution.countSubarrays(**test_input) == 1940\n\ntest_input = { \"nums\": [4,18,6,22,19,15,20,12,22,22,19,6,10,7,20,4,22,21,7,17,3,16,13,17,22,14,8,2,3,22,18,18,22,22,7,22,13,10,20,4,14,17,9,19,1,12,3,11,19,15,6,4,10], \"k\": 6 }\nassert my_solution.countSubarrays(**test_input) == 347\n\ntest_input = { \"nums\": [55,103,123,68,16,72,104,63,40,15,180,162,82,180,131,46,180,2,120,107,100,97,180,180,17,134,180,124,40,125,15,132,4,112,180,180,28,66,180,122,99,46,15,180,180,111,30,169,132,180,10,180,180,180,107,74,95,28,180,66,180,128,61,180,118,180,28,103,37,180,88,152], \"k\": 8 }\nassert my_solution.countSubarrays(**test_input) == 1181\n\ntest_input = { \"nums\": [20,6,49,60,16,54,13,2,35,6,27,62,67,56,27,6,33,51,67,42,9,59,67,14,59,7,67,34,51,5,67,48,53,20,35,67,65,34,67,67,62,7,27,18,40,10,67,67,9,8,60,12,2,67,64,67,60,28,60,26,37,2,67,33,49,23,2,36,67,6,67,7,67,44,18], \"k\": 8 }\nassert my_solution.countSubarrays(**test_input) == 1034\n\ntest_input = { \"nums\": [191,2,46,65,191,166,191,156,157,181,167,123,26,191,191,104,33,126,51,191,191,191,6,152,74,84,126,191,191,162,188,38,30,191,191,125,30,56,12,151,45,163,91,168,15,125,60,4,108,27,67,97,125,147,167,152,191,159,142,105], \"k\": 7 }\nassert my_solution.countSubarrays(**test_input) == 647\n\ntest_input = { \"nums\": [2,4,11,30,23,1,8,18,4,6,30,30,30,10,30,17,24,13,17,30,25,30,30,12,15,29,24,28,21,30,25,11,1,30,9,30,21,3,10,6,30,5,5,24,21,30,17,29,21,30,3,30,8,18,17], \"k\": 7 }\nassert my_solution.countSubarrays(**test_input) == 584\n\ntest_input = { \"nums\": [141,106,141,141,94,98,33,141,2,115,11,141,9,131,104,2,141,75,141,141,24,141,28,68,141,134,141,110,15,21,141,65,108,141,35,95,94,141,117,25], \"k\": 10 }\nassert my_solution.countSubarrays(**test_input) == 94\n\ntest_input = { \"nums\": [139,94,77,139,139,139,139,92,61,105,25,139,93,139,113,128,139,81,70,139,25,139,37,118,15,5,139,115,133,1], \"k\": 3 }\nassert my_solution.countSubarrays(**test_input) == 292\n\ntest_input = { \"nums\": [107,160,86,160,69,160,160,73,120,129,130,104,112,136,7,100,21,160,160,94,3,96,160,65,74,87,110,160,145,116,38,72,127,152,71,24,35,79,160,120,160,80,50,160,129,50,82,160,140,160,3,17,129,18,108,34,132,69,4,160,124,108,30,125,160,102,51,138,160,120,159,160,49,68,160,19,87,160,6,160,76,160,110], \"k\": 16 }\nassert my_solution.countSubarrays(**test_input) == 124\n\ntest_input = { \"nums\": [89,9,89,82,89,11,31,45,61,56,27,15,33,6,5,89,28,73,8,48,11,89,5,89,4,65,18,20,17,38,4,36,59,34,5,81,10,6,44,19,20,86,58,60,27,89,34,29,36,88,89,10,73], \"k\": 7 }\nassert my_solution.countSubarrays(**test_input) == 14\n\ntest_input = { \"nums\": [45,40,44,51,51,33,33,38,46,38,51,40,9,29,51,40,51,36,39,36,51,24,39,51,31,50,12,50,1,51,32,51,49,12,44,19,4,26,7,51,14,4,33,36,19,18,14,20,16,11,51,51,7,18,7,10,8,8,48,51,43,41,51], \"k\": 10 }\nassert my_solution.countSubarrays(**test_input) == 199\n\ntest_input = { \"nums\": [102,4,3,22,78,96,21,126,103,52,99,94,57,126,49,20,75,126,93,1,4,126,122,123,21,111,23,110,126,81,112,92,121,30,41,126,20,10,126,54,15,27,126,126,9,126,126,1,106,34,119,108,126,126,34,57,27,126,110,126,65,125,126,59,117,126,67,114,115,38,79,123,118,126,33,52,1,119,11,105,21,51,75,126,84], \"k\": 9 }\nassert my_solution.countSubarrays(**test_input) == 1500\n\ntest_input = { \"nums\": [71,122,36,39,48,158,83,20,131,41,126,1,33,19,138,133,80,106,92,2,68,158,158,111,158,50,158,81,158,138,108,36,149], \"k\": 4 }\nassert my_solution.countSubarrays(**test_input) == 171\n\ntest_input = { \"nums\": [39,136,153,85,134,19,34,22,5,124,116,91,122,160,112,160,22,111,160,160,113,34,40,16,160,117,61,160,31,34,145,160], \"k\": 6 }\nassert my_solution.countSubarrays(**test_input) == 72\n\ntest_input = { \"nums\": [14,14,1,8,2,11,14,14,5,1,8,1,6,3,14,14,14,2,9,10,14,2,3,14,2,5,5,11,10,11,14,5,3,10,5,3,1,3,14,5,13,9,2,9,3,5,14,14,2,3,10,4,14,14,10,14,2,10,9,2,7,9,11,14,9,5,1,5,13,6,10,1,7,4,13,13,9,10,2,10,3,8,14,3,14,13,1,14,8,12,1,6,12,14,14], \"k\": 14 }\nassert my_solution.countSubarrays(**test_input) == 438\n\ntest_input = { \"nums\": [1,7,4,10,12,10,10,1,12,1,6,6,9,7,10,6,12,10,7,9,6,10,12,8,11,9,8,3,8,3,12,12,12,3,2,2,3,1,10,2,12,12,12,9,10,1,8,10,12,4,8,8,6,2,11,7,3,3,12,12,2,7,8,11,4,3,12,5,8,12,10,2,9,6,5,10,8], \"k\": 7 }\nassert my_solution.countSubarrays(**test_input) == 1236\n\ntest_input = { \"nums\": [1,7,11,13,10,13,8,6,4,11,13,6,1,6,8,10,5,13,4,2,3,7,12,5,1,1,11,13,8,9,1,8], \"k\": 2 }\nassert my_solution.countSubarrays(**test_input) == 262\n\ntest_input = { \"nums\": [73,24,67,11,66,73,73,40,4,47,25,26,48,40,27,69,73,28,23,9,16,8,63,65,73,57,73,21,43,73,19], \"k\": 1 }\nassert my_solution.countSubarrays(**test_input) == 408\n\ntest_input = { \"nums\": [7,47,50,16,35,24,61,44,53,49], \"k\": 1 }\nassert my_solution.countSubarrays(**test_input) == 28\n\ntest_input = { \"nums\": [14,89,43,1,12,64,23,89,55,23,56,69,62,89,89,86,89,89,89,76,84,57,18,54,29,50,67,69,65,3,22,26,8,77,51,74,74,40,89,89,18,74,89,26,16,27,1,66,72,22,78,20,15,14,63,77,73,23,65,89,79,32,18,89,59,16,24,39,87,78,29,84,89,49,80,69,89,44,89,89,58,6,55,38,89,53,89,3,81,28,65,39,30,14,16,89,22,4,23,84], \"k\": 7 }\nassert my_solution.countSubarrays(**test_input) == 2045\n\ntest_input = { \"nums\": [16,11,12,16,5,17,11,13,12,17,16,2,3,13,1,4,10,2,17,17,8,7,4,17,11,17,8,2,15,17,4,16,9,8,17,2,17,16,17,4,6,8,12,17,16,13,4,11,9,11,16,10,17,17,10,13,17,13,1,13,3,7,4,2,15,6,11,12,17,17,7,15,9,16,7,2,17,7,17,16,5,8], \"k\": 8 }\nassert my_solution.countSubarrays(**test_input) == 1317\n\ntest_input = { \"nums\": [52,46,47,52,52,4,2,21,2,26,47,26,52,7,12,35,52,33,47,3,31,37,36,52,38,19,12,40,52,7,40,16,51,41,52,23,20,52,18,52,21,2,52,49,5,48,23,52,52], \"k\": 8 }\nassert my_solution.countSubarrays(**test_input) == 132\n\ntest_input = { \"nums\": [99,155,73,80,32,69,113,37,126,155,95,155,155,48,155,43,37,68,131,68,150,155,153,155,45,59,155,155,155,77,155,155,100,4,127,155,107,151,101,104,155,155,71,147,153,37,155,18,155,100,155,153,155,155,138,4,114,153,111,83,74,144,18,64,94,155,50,45,51,122,146,50,43], \"k\": 8 }\nassert my_solution.countSubarrays(**test_input) == 1346\n\ntest_input = { \"nums\": [64,156,156,119,156,35,108,82,86,18,107,156,68,83,130,86,80,8,129,95,23,7,71,131,19,156,17,21,43,156,25,156,124,51,91,156,77,88,156,156,62,105,135,142,156,156,78,156,113,156,47,156,156,22,71,49,156,57,71,156,36,84,139,156,17,49,156,121,46,7,155,156,156,156,93,150,102,81,90,52,52,91,2,63,156,49,118,77,156,156,156,79], \"k\": 19 }\nassert my_solution.countSubarrays(**test_input) == 590\n\ntest_input = { \"nums\": [24,9,28,46,14,41], \"k\": 1 }\nassert my_solution.countSubarrays(**test_input) == 12\n\ntest_input = { \"nums\": [169,19], \"k\": 1 }\nassert my_solution.countSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [95,109,79,198,195,198,198,97,34,43,165,198,198,195,98,198,198,170,39,78,21,198,140,187,29,107,198,132,198,174,109,187,173,198,58,38,62,179,198,68,114,198,10,198,81,198,40,10,71,82,196,128,50,153,146,101,195], \"k\": 12 }\nassert my_solution.countSubarrays(**test_input) == 182\n\ntest_input = { \"nums\": [9,15,39,33,43,47,15,29,14,12,48,37,9,37,15,48,48,3,1,48,37,39,43,29,43,15,35,2,33,48,28,37,48,45,9,36,3,48,29,14,48,11,24,30,38,18,24,12,47,31,22,10,29,46,14,48,15,29,43,48,37,48,46,14,32,33,15,42,9,12,48,20,35,44,48,4], \"k\": 10 }\nassert my_solution.countSubarrays(**test_input) == 274\n\ntest_input = { \"nums\": [37,12,14,46,29,98,149,149,149,67,97,56,81,71,11,149,32,149,119,149,44,149,43,149,149,32,75,54,24,148,41], \"k\": 2 }\nassert my_solution.countSubarrays(**test_input) == 379\n\ntest_input = { \"nums\": [59,101,127,118,19,55,18,127,127,26,127,103,4,127,26,43,26,125,80,127,127,112,2,107,127,127,110,122,77,127,11,86,127,127,91,27,85,86,71,36,41,127,86,37,11], \"k\": 6 }\nassert my_solution.countSubarrays(**test_input) == 418\n\ntest_input = { \"nums\": [82,82,42,51,82,64,13,16,36,49,22,52,82,10,72,9,6,42,80,74,37,80,73,10,82,31,78,22,14,11,82,60,76,67,82,2,61,52,79,72,77,12,23,33,44,11,82,4,14,65,19,66,56,11,75,82,42,82,56,77,82,81,51,48,19,70,33,51,9,78,62,31,41,46,13,82,82,77,55,24,49,82,82,8,3,44,34], \"k\": 9 }\nassert my_solution.countSubarrays(**test_input) == 427\n\ntest_input = { \"nums\": [30,83,42,83,83,60,61,60,62,83,74,32,83,83,46,82,25,81,31,83,48,15,49,43,41,83,29,36,45,53,83,74,55,63,1,19,74,2,15,83,61,82,46,48,83,83,8,45,83,80,30,33,83,83,83,22,65,79,57,15,24,25,83,83,60,60,83,44,9,29,60,69,2,83,35,7,40,74,55,83,7,21,11,59,5,80], \"k\": 17 }\nassert my_solution.countSubarrays(**test_input) == 200\n\ntest_input = { \"nums\": [11,25,22,14,14,29,6,28,12,14,2,15,29,2,6,27,22,29,26,29,11,1,7,27,24,29,7,29,6], \"k\": 1 }\nassert my_solution.countSubarrays(**test_input) == 371\n\ntest_input = { \"nums\": [173,97,53,181,161,119,152,97,69,181,123,84,83,9,169,135,86,27,119,181,64,147,7,181,154,43,83,181,14,181,45,77,181,83,181,53,181,117,181,27,181,174,181,47], \"k\": 6 }\nassert my_solution.countSubarrays(**test_input) == 302\n\ntest_input = { \"nums\": [124,52,111,24,191,117,128,153,69,190,51,1,112,52,28,191,188,191,1,124,128,111,191,94,34,167,191,191,9,191,164,60,113,69,151,130,15,86,150,191,175,36,113,23,119,68,191,87,90,159,178,50,104,191,187,48,97,100,136,155,140,132,1,180,182,191,130,110,191,191,191,191,191,177,73,118,191,27,129,124,43,140,191,132,191,41,44,191,169,49,191,191,191,191,113,4], \"k\": 7 }\nassert my_solution.countSubarrays(**test_input) == 2434\n\ntest_input = { \"nums\": [86,89,92,23,92,72,41,92,92,92,47,30,46,76,20,80,92,60,20,9,92,92,92,36,4,38,92,74,15,20,92,2,73,58,68,2,29,13,92,91,92,44,46,8,57,10,47,92,6,90,92,92,76,92,86,26,22,67,92,92,17,92,18,23,22,40,7], \"k\": 9 }\nassert my_solution.countSubarrays(**test_input) == 738\n\ntest_input = { \"nums\": [75,65,37,83,80,17,69,83,83,76,64,58,13,83,18,66,25,55,25,60,83,83,83,50,70,39,82,83,47,39,74,83,75,83,34,8,81,46,52,72,45,65,46,2,9,4,23,47,83,83,59,32,54,43,53,56,83], \"k\": 9 }\nassert my_solution.countSubarrays(**test_input) == 256\n\ntest_input = { \"nums\": [23,70,2,70,49,65,6,69,5,26,29,70,70,15,17,22,70,63,51,25,18,68,31,3,43,60,70,6,61,23,46,21,66,67,63,3,7,70,66,47,15,65,52,70,70,38,8,18,29,33,50,9,70,9], \"k\": 1 }\nassert my_solution.countSubarrays(**test_input) == 1305\n\ntest_input = { \"nums\": [23,12,6,3,4,7,23,23,6,23,23,9,23,2,14,11,21,23,8,9,19,10,17,23,11,3,13,23,18,3,6,7,6,19,17,14,17,7,23,21,10,22,6,23,23,3,1,20,14,7,19,20,23,19,23,15,4,23,2,6,20,23,8,6,17,14,23,6,10,23,17,6,11,8,3,6,23,16,19,16,2,19,2,23,1,16,20,4,20,12,1], \"k\": 11 }\nassert my_solution.countSubarrays(**test_input) == 942\n\ntest_input = { \"nums\": [199,146,138,199,97,169,199,198,199,199,11,62,68,122,193,199,22,41,199,181,199,157,199,44,199,199,199,142,132,112,199,199,155,199,97,101,26,52,199,45,164,112,188,97,180,103,199,3,130,64,131,199,194,135,36,199,80,67,41,67,158,183,188,12,126], \"k\": 13 }\nassert my_solution.countSubarrays(**test_input) == 420\n\ntest_input = { \"nums\": [25,32,40,47,35,9,39,58,67,42,77,57,77,77,34,28,13,77,15,33,77,10,64,67,35,21,61,60,74,57,77,71,28,77,48,67,17,48,77,77,77,60,26,30,77,49,77,3,77,33,75,77,20,77,77], \"k\": 9 }\nassert my_solution.countSubarrays(**test_input) == 325\n\ntest_input = { \"nums\": [50,108,19,118,46,45,126,118,89,126,46,63,30,126,120,10,126,126,108,95,126,94], \"k\": 3 }\nassert my_solution.countSubarrays(**test_input) == 107\n\ntest_input = { \"nums\": [28,94,94,5,1,74,33,3,88,76,78,30], \"k\": 1 }\nassert my_solution.countSubarrays(**test_input) == 32\n\ntest_input = { \"nums\": [44,4,4,31,33,51,51,40,51,2,27,48,51,6,51,27,45,1,25,2,20,43,51,12,11,44,40,28,29,51,51,45,30,24,51,51,30,51,13,18,29,51,15,11,39], \"k\": 11 }\nassert my_solution.countSubarrays(**test_input) == 52\n\ntest_input = { \"nums\": [6,30,19,32,24,8,28,2,18,32,5,31,3,31,28,30,30,22,32,22,31,1,9,2,7,32,14,24,24,6,23,6,25,32,32,22,10,11,4,2,32,18,15,1,22,20,6,26,11,13,26,22,32,30,18], \"k\": 4 }\nassert my_solution.countSubarrays(**test_input) == 570\n\ntest_input = { \"nums\": [17,41,71,95,56,88,25,95,73,95,91,95,8,43,2,52,95,88,5,49,20,48,95,84,95,44,27,95,87,32,45,95,95,95,51,56,6,5,65,21,52,56,84,95,75,33,95,62,47,95], \"k\": 13 }\nassert my_solution.countSubarrays(**test_input) == 20\n\ntest_input = { \"nums\": [5,12,6,13,11,13,9,13,10,13,13,12,7,11,2,11,4,7,6,6,13,9,1,12,13,11,7,11,11,13,2,13,7,4,9,5,13,8,4,1,2,5,13,7,7,12,2,2,8,11,12,1,8,5,3,6,4,2,9,10,6,6,13,12,13,6,13,13,13,13,13,3,4,4,10,1,2,12,12,13,13,6,13,4,13,1,12,11,9,12,2,5], \"k\": 3 }\nassert my_solution.countSubarrays(**test_input) == 3240\n\ntest_input = { \"nums\": [13,16,2,27,10,2,44,44,44,28,44,44,23], \"k\": 4 }\nassert my_solution.countSubarrays(**test_input) == 23\n\ntest_input = { \"nums\": [69,46,80,10,80,48,76,15,67,1,80,80,34,4,14,15,2,38,62,31,17,56,58,17,38,29,67], \"k\": 4 }\nassert my_solution.countSubarrays(**test_input) == 48\n\ntest_input = { \"nums\": [39,38,136,136,97,122,54,102,112,125,135,57,136], \"k\": 1 }\nassert my_solution.countSubarrays(**test_input) == 52\n\ntest_input = { \"nums\": [39,67,17,52,89,63,52,8,14,90,76,2,90,65,90,80,90,33,61,76,90,32,43,55,62,24,29,90,35,36,90,8,40,1,72,54,64,90,58,88,77,89,35,79,90,81,90], \"k\": 2 }\nassert my_solution.countSubarrays(**test_input) == 822\n\ntest_input = { \"nums\": [16,22,10,22,4,16,16,15,3,22,22,15,7,7,21,17,16,1,10,13,16,17,2,18,2,5,11], \"k\": 3 }\nassert my_solution.countSubarrays(**test_input) == 70\n\ntest_input = { \"nums\": [120,58,118,34,32,110,94,10,119,133,70,154,151,107,124,148,154,154,24,154,6,83,20,6,3,72,154,28,148,107,154,73,126,154,41], \"k\": 5 }\nassert my_solution.countSubarrays(**test_input) == 135\n\ntest_input = { \"nums\": [15,2,1,21,20,33,16,19], \"k\": 1 }\nassert my_solution.countSubarrays(**test_input) == 18\n\ntest_input = { \"nums\": [45,25], \"k\": 1 }\nassert my_solution.countSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [179,127,54,149,90,119,179,127,115,82,159,128,6,55,33,43,2,172,105,159,83,179,30,179,175,125,179,179,105,179,74,77,179,153,145,124,70,179,129,31,62,172,179,29,130,179,82,64,98,179,91,179,89,166,60,159,54,179,179,137,54,158,64,177,56,165,97,142,90,170,179,127,111,179,145,179,8], \"k\": 16 }\nassert my_solution.countSubarrays(**test_input) == 61\n\ntest_input = { \"nums\": [25,41,11,41,26,30,41,34,31,41,40,23,14,41,10,34,8,15,41,10,14,41,37,20,37,35,37,8,21,30,11,7,33,3,25,1,3,38,27,26,27,20,29,41,30,7,23,15,41,41,41,25,18,41,19,41,34,35,33,41,4,41,15], \"k\": 3 }\nassert my_solution.countSubarrays(**test_input) == 1227\n\ntest_input = { \"nums\": [7,6,3,9,6,3,4,4,9,7,3,3,8,9,2,4,8,8,8,6,3,2,9,9,9,4,2,6,9,3], \"k\": 1 }\nassert my_solution.countSubarrays(**test_input) == 396\n\ntest_input = { \"nums\": [158,2,138,177,96,104,175,81,46,19,85,1,174,177,115,145,32,177,174,95,96,101,177,114,115,137,77,98,15,177,125,162,177,177,111,106,112,177,174,40,177,177,176,40,177,145,177,99,177,177,163,177,143,147,177,11,142,177,44,171,52,98,177,163,140,139,61,147,71,20,177,45,172], \"k\": 5 }\nassert my_solution.countSubarrays(**test_input) == 1642\n\ntest_input = { \"nums\": [3,1], \"k\": 1 }\nassert my_solution.countSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [99,166,166,5,166,44,83,73,40,64,166,135,166,24,166,41,70,93,166,166,166,49,157,3,135,137,1,133,18,166,15,82,4,166,13,55,95,166,166,151,102,166,166,34,32,31,48,166,166,13,166,166,94,28,166,166,119,103,157,12,103,19,126,13,117,71,85,166,166,81,132,105,128,166,166,125,73,161,166,139,6,32,5,31,137], \"k\": 24 }\nassert my_solution.countSubarrays(**test_input) == 49\n\ntest_input = { \"nums\": [121,135,135,135,57,18,7,22,135,57,96,72,23,68,32,39,135,135,135,135,51,25,100,49,72,135,99,38,126,110,52,63,48,135,135,132,111,114,135,135,24,125,135,135,120,93,55,40,135,44,135,22,135,48,35,12,116,79,80,22,135,135,111,135], \"k\": 20 }\nassert my_solution.countSubarrays(**test_input) == 7", "start_time": 1702175400} +{"task_id": "weekly-contest-375-count-the-number-of-good-partitions", "url": "https://leetcode.com/problems/count-the-number-of-good-partitions", "title": "count-the-number-of-good-partitions", "meta": {"questionId": "3212", "questionFrontendId": "2963", "title": "Count the Number of Good Partitions", "titleSlug": "count-the-number-of-good-partitions", "isPaidOnly": false, "difficulty": "Hard", "likes": 163, "dislikes": 1, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed array nums consisting of positive integers.\nA partition of an array into one or more contiguous subarrays is called good if no two subarrays contain the same number.\nReturn the total number of good partitions of nums.\nSince the answer may be large, return it modulo 109 + 7.\n\nExample 1:\n\nInput: nums = [1,2,3,4]\nOutput: 8\nExplanation: The 8 possible good partitions are: ([1], [2], [3], [4]), ([1], [2], [3,4]), ([1], [2,3], [4]), ([1], [2,3,4]), ([1,2], [3], [4]), ([1,2], [3,4]), ([1,2,3], [4]), and ([1,2,3,4]).\n\nExample 2:\n\nInput: nums = [1,1,1,1]\nOutput: 1\nExplanation: The only possible good partition is: ([1,1,1,1]).\n\nExample 3:\n\nInput: nums = [1,2,1,3]\nOutput: 2\nExplanation: The 2 possible good partitions are: ([1,2,1], [3]) and ([1,2,1,3]).\n\n\nConstraints:\n\n1 <= nums.length <= 105\n1 <= nums[i] <= 109\n\"\"\"\nclass Solution:\n def numberOfGoodPartitions(self, nums: List[int]) -> int:\n ", "prompt_sft": "You are given a 0-indexed array nums consisting of positive integers.\nA partition of an array into one or more contiguous subarrays is called good if no two subarrays contain the same number.\nReturn the total number of good partitions of nums.\nSince the answer may be large, return it modulo 109 + 7.\n\nExample 1:\n\nInput: nums = [1,2,3,4]\nOutput: 8\nExplanation: The 8 possible good partitions are: ([1], [2], [3], [4]), ([1], [2], [3,4]), ([1], [2,3], [4]), ([1], [2,3,4]), ([1,2], [3], [4]), ([1,2], [3,4]), ([1,2,3], [4]), and ([1,2,3,4]).\n\nExample 2:\n\nInput: nums = [1,1,1,1]\nOutput: 1\nExplanation: The only possible good partition is: ([1,1,1,1]).\n\nExample 3:\n\nInput: nums = [1,2,1,3]\nOutput: 2\nExplanation: The 2 possible good partitions are: ([1,2,1], [3]) and ([1,2,1,3]).\n\n\nConstraints:\n\n1 <= nums.length <= 105\n1 <= nums[i] <= 109\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def numberOfGoodPartitions(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,2,3,4] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 8\n\ntest_input = { \"nums\": [1,1,1,1] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,1,3] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 2\n\ntest_input = { \"nums\": [1] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 1\n\ntest_input = { \"nums\": [100000] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 1\n\ntest_input = { \"nums\": [1000000000] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,1,3,2] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 4\n\ntest_input = { \"nums\": [1,1,1,9,7] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 4\n\ntest_input = { \"nums\": [1,1,5,9,2] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 8\n\ntest_input = { \"nums\": [1,4,1,7,5] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 4\n\ntest_input = { \"nums\": [1,5,1,5,6] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 2\n\ntest_input = { \"nums\": [1,5,1,10,8] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 4\n\ntest_input = { \"nums\": [1,6,8,1,5] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 2\n\ntest_input = { \"nums\": [1,6,9,4,10] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 16\n\ntest_input = { \"nums\": [1,7,1,6,8] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 4\n\ntest_input = { \"nums\": [1,9,1,1,7] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 2\n\ntest_input = { \"nums\": [2,1,6,7,5] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 16\n\ntest_input = { \"nums\": [2,3,2,6,9] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 4\n\ntest_input = { \"nums\": [2,3,2,8,8] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 2\n\ntest_input = { \"nums\": [2,3,9,2,6] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 2\n\ntest_input = { \"nums\": [2,4,2,7,4] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 1\n\ntest_input = { \"nums\": [2,4,7,1,2] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 1\n\ntest_input = { \"nums\": [2,5,1,2,2] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 1\n\ntest_input = { \"nums\": [2,5,1,4,9] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 16\n\ntest_input = { \"nums\": [2,5,6,4,2] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 1\n\ntest_input = { \"nums\": [2,6,1,9,5] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 16\n\ntest_input = { \"nums\": [2,7,8,9,3] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 16\n\ntest_input = { \"nums\": [2,9,1,2,4] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 2\n\ntest_input = { \"nums\": [2,10,4,2,3] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 2\n\ntest_input = { \"nums\": [3,3,3,9,9] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 2\n\ntest_input = { \"nums\": [3,3,8,1,6] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 8\n\ntest_input = { \"nums\": [3,3,10,4,2] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 8\n\ntest_input = { \"nums\": [3,4,5,1,7] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 16\n\ntest_input = { \"nums\": [3,7,6,4,9] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 16\n\ntest_input = { \"nums\": [3,8,10,7,6] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 16\n\ntest_input = { \"nums\": [3,10,10,10,4] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 4\n\ntest_input = { \"nums\": [4,1,2,3,10] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 16\n\ntest_input = { \"nums\": [4,1,7,9,4] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 1\n\ntest_input = { \"nums\": [4,8,4,8,6] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 2\n\ntest_input = { \"nums\": [5,1,1,9,3] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 8\n\ntest_input = { \"nums\": [5,2,8,10,4] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 16\n\ntest_input = { \"nums\": [5,3,6,6,6] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 4\n\ntest_input = { \"nums\": [5,3,8,8,2] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 8\n\ntest_input = { \"nums\": [5,4,5,9,9] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 2\n\ntest_input = { \"nums\": [5,4,10,2,4] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 2\n\ntest_input = { \"nums\": [5,5,7,3,1] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 8\n\ntest_input = { \"nums\": [5,5,8,4,1] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 8\n\ntest_input = { \"nums\": [5,9,1,9,2] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 4\n\ntest_input = { \"nums\": [5,10,1,1,6] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 8\n\ntest_input = { \"nums\": [6,1,7,9,10] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 16\n\ntest_input = { \"nums\": [6,3,5,1,10] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 16\n\ntest_input = { \"nums\": [6,3,9,9,3] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 2\n\ntest_input = { \"nums\": [6,6,5,5,8] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 4\n\ntest_input = { \"nums\": [6,7,3,3,8] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 8\n\ntest_input = { \"nums\": [6,8,6,5,7] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 4\n\ntest_input = { \"nums\": [6,9,10,5,8] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 16\n\ntest_input = { \"nums\": [6,10,2,6,10] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 1\n\ntest_input = { \"nums\": [6,10,5,4,3] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 16\n\ntest_input = { \"nums\": [7,1,2,3,5] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 16\n\ntest_input = { \"nums\": [7,1,9,2,1] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 2\n\ntest_input = { \"nums\": [7,2,1,2,6] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 4\n\ntest_input = { \"nums\": [7,5,1,10,10] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 8\n\ntest_input = { \"nums\": [7,5,7,4,6] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 4\n\ntest_input = { \"nums\": [7,5,8,4,6] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 16\n\ntest_input = { \"nums\": [7,9,4,8,7] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 1\n\ntest_input = { \"nums\": [7,9,8,8,4] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 8\n\ntest_input = { \"nums\": [8,2,2,5,6] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 8\n\ntest_input = { \"nums\": [8,3,2,1,9] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 16\n\ntest_input = { \"nums\": [8,3,4,9,7] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 16\n\ntest_input = { \"nums\": [8,3,6,5,1] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 16\n\ntest_input = { \"nums\": [8,3,8,3,4] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 2\n\ntest_input = { \"nums\": [8,3,8,3,10] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 2\n\ntest_input = { \"nums\": [8,4,4,5,8] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 1\n\ntest_input = { \"nums\": [8,4,8,10,9] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 4\n\ntest_input = { \"nums\": [8,5,5,3,9] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 8\n\ntest_input = { \"nums\": [8,7,4,2,1] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 16\n\ntest_input = { \"nums\": [8,7,6,10,1] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 16\n\ntest_input = { \"nums\": [8,9,7,3,6] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 16\n\ntest_input = { \"nums\": [8,10,5,9,9] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 8\n\ntest_input = { \"nums\": [9,1,2,2,3] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 8\n\ntest_input = { \"nums\": [9,1,4,3,7] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 16\n\ntest_input = { \"nums\": [9,1,7,8,9] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 1\n\ntest_input = { \"nums\": [9,2,7,5,10] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 16\n\ntest_input = { \"nums\": [9,3,6,5,5] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 8\n\ntest_input = { \"nums\": [9,4,7,1,1] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 8\n\ntest_input = { \"nums\": [9,5,5,8,3] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 8\n\ntest_input = { \"nums\": [9,7,2,7,10] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 4\n\ntest_input = { \"nums\": [9,7,8,3,2] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 16\n\ntest_input = { \"nums\": [9,8,2,5,5] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 8\n\ntest_input = { \"nums\": [9,8,2,10,7] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 16\n\ntest_input = { \"nums\": [9,8,3,7,6] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 16\n\ntest_input = { \"nums\": [9,8,6,6,8] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 2\n\ntest_input = { \"nums\": [9,8,8,2,1] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 8\n\ntest_input = { \"nums\": [9,8,9,5,7] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 4\n\ntest_input = { \"nums\": [10,1,3,2,3] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 4\n\ntest_input = { \"nums\": [10,1,10,3,5] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 4\n\ntest_input = { \"nums\": [10,2,1,4,1] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 4\n\ntest_input = { \"nums\": [10,3,1,3,4] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 4\n\ntest_input = { \"nums\": [10,5,6,2,8] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 16\n\ntest_input = { \"nums\": [10,6,5,10,2] }\nassert my_solution.numberOfGoodPartitions(**test_input) == 2", "start_time": 1702175400} +{"task_id": "biweekly-contest-119-find-common-elements-between-two-arrays", "url": "https://leetcode.com/problems/find-common-elements-between-two-arrays", "title": "find-common-elements-between-two-arrays", "meta": {"questionId": "3206", "questionFrontendId": "2956", "title": "Find Common Elements Between Two Arrays", "titleSlug": "find-common-elements-between-two-arrays", "isPaidOnly": false, "difficulty": "Easy", "likes": 66, "dislikes": 25, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given two 0-indexed integer arrays nums1 and nums2 of sizes n and m, respectively.\nConsider calculating the following values:\n\nThe number of indices i such that 0 <= i < n and nums1[i] occurs at least once in nums2.\nThe number of indices i such that 0 <= i < m and nums2[i] occurs at least once in nums1.\n\nReturn an integer array answer of size 2 containing the two values in the above order.\n\nExample 1:\n\nInput: nums1 = [4,3,2,3,1], nums2 = [2,2,5,2,3,6]\nOutput: [3,4]\nExplanation: We calculate the values as follows:\n- The elements at indices 1, 2, and 3 in nums1 occur at least once in nums2. So the first value is 3.\n- The elements at indices 0, 1, 3, and 4 in nums2 occur at least once in nums1. So the second value is 4.\n\nExample 2:\n\nInput: nums1 = [3,4,2,3], nums2 = [1,5]\nOutput: [0,0]\nExplanation: There are no common elements between the two arrays, so the two values will be 0.\n\n\nConstraints:\n\nn == nums1.length\nm == nums2.length\n1 <= n, m <= 100\n1 <= nums1[i], nums2[i] <= 100\n\"\"\"\nclass Solution:\n def findIntersectionValues(self, nums1: List[int], nums2: List[int]) -> List[int]:\n ", "prompt_sft": "You are given two 0-indexed integer arrays nums1 and nums2 of sizes n and m, respectively.\nConsider calculating the following values:\n\nThe number of indices i such that 0 <= i < n and nums1[i] occurs at least once in nums2.\nThe number of indices i such that 0 <= i < m and nums2[i] occurs at least once in nums1.\n\nReturn an integer array answer of size 2 containing the two values in the above order.\n\nExample 1:\n\nInput: nums1 = [4,3,2,3,1], nums2 = [2,2,5,2,3,6]\nOutput: [3,4]\nExplanation: We calculate the values as follows:\n- The elements at indices 1, 2, and 3 in nums1 occur at least once in nums2. So the first value is 3.\n- The elements at indices 0, 1, 3, and 4 in nums2 occur at least once in nums1. So the second value is 4.\n\nExample 2:\n\nInput: nums1 = [3,4,2,3], nums2 = [1,5]\nOutput: [0,0]\nExplanation: There are no common elements between the two arrays, so the two values will be 0.\n\n\nConstraints:\n\nn == nums1.length\nm == nums2.length\n1 <= n, m <= 100\n1 <= nums1[i], nums2[i] <= 100\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def findIntersectionValues(self, nums1: List[int], nums2: List[int]) -> List[int]:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums1\": [4,3,2,3,1], \"nums2\": [2,2,5,2,3,6] }\nassert my_solution.findIntersectionValues(**test_input) == [3,4]\n\ntest_input = { \"nums1\": [3,4,2,3], \"nums2\": [1,5] }\nassert my_solution.findIntersectionValues(**test_input) == [0,0]\n\ntest_input = { \"nums1\": [24,28,7,27,7,27,9,24,9,10], \"nums2\": [12,29,9,7,5] }\nassert my_solution.findIntersectionValues(**test_input) == [4,2]\n\ntest_input = { \"nums1\": [10,30,16,18], \"nums2\": [23,30,30,6,10,26,9,27,6,16,18,10,27,2,20,7,16] }\nassert my_solution.findIntersectionValues(**test_input) == [4,7]\n\ntest_input = { \"nums1\": [7,23,27,20,21,29,7,27,27,18,7,6,20,10], \"nums2\": [27,27,28,24,20,4,6,17,9,29,20,14,20] }\nassert my_solution.findIntersectionValues(**test_input) == [7,7]\n\ntest_input = { \"nums1\": [15,30,6,6], \"nums2\": [15,4,16,10,7,23,24,3,4,6,14,8,18,1,29,27,2,17] }\nassert my_solution.findIntersectionValues(**test_input) == [3,2]\n\ntest_input = { \"nums1\": [24,7,8,6,22,28,22,28,7,19], \"nums2\": [3,7,28,7,3,3] }\nassert my_solution.findIntersectionValues(**test_input) == [4,3]\n\ntest_input = { \"nums1\": [23,4,26,17,23,13], \"nums2\": [24,17,20,16,1,13,17,28,17] }\nassert my_solution.findIntersectionValues(**test_input) == [2,4]\n\ntest_input = { \"nums1\": [5,8,18,27,16,29,27,12,1,29,16,27,22,19,14,12,11,25], \"nums2\": [24,8,16] }\nassert my_solution.findIntersectionValues(**test_input) == [3,2]\n\ntest_input = { \"nums1\": [29,17,30,17,15,30,11,2,24,28,28,30,30,27,30,2,30,9,1,7], \"nums2\": [12,12,11,21,2,28,5,24,12,17,24,29,22,19,11,17,1,23] }\nassert my_solution.findIntersectionValues(**test_input) == [10,10]\n\ntest_input = { \"nums1\": [4,27,12,16,16,21,26,7,19,21,24,26,12,24,22,12,16], \"nums2\": [1,25,8,27,23,27,27,24] }\nassert my_solution.findIntersectionValues(**test_input) == [3,4]\n\ntest_input = { \"nums1\": [27,19,20,16,24,27,27,24], \"nums2\": [30,21,21,6,17,16] }\nassert my_solution.findIntersectionValues(**test_input) == [1,1]\n\ntest_input = { \"nums1\": [3,19,21,5,24,26,22,22,5], \"nums2\": [23,26,20,14,30,9,10,24,19,22,19,6,3,20,22,22,5,24,24] }\nassert my_solution.findIntersectionValues(**test_input) == [8,11]\n\ntest_input = { \"nums1\": [13,13,29,12], \"nums2\": [29,29,13,7,30,22] }\nassert my_solution.findIntersectionValues(**test_input) == [3,3]\n\ntest_input = { \"nums1\": [30,4,16,14,14,14,20,15,20,30,6,10,14], \"nums2\": [30,16,20,2,18,10,5,6,30,20,22,18,14,23,15] }\nassert my_solution.findIntersectionValues(**test_input) == [12,9]\n\ntest_input = { \"nums1\": [22,1,22,4,11,22,4,20,11,29,11,11,4,26,20,12,20,8,26,17], \"nums2\": [4,17,7,15] }\nassert my_solution.findIntersectionValues(**test_input) == [4,2]\n\ntest_input = { \"nums1\": [30,15,16,15,11,16,26,15,21], \"nums2\": [22,25,27,2,26,20,18,15,26,20,16] }\nassert my_solution.findIntersectionValues(**test_input) == [6,4]\n\ntest_input = { \"nums1\": [5,6], \"nums2\": [13,12,8,5,19,13,27] }\nassert my_solution.findIntersectionValues(**test_input) == [1,1]\n\ntest_input = { \"nums1\": [27,28,15,20,5,13,28,29,24,29,20,15,5,20,20,25,9,20,24,20], \"nums2\": [16,20,13,24,11] }\nassert my_solution.findIntersectionValues(**test_input) == [9,3]\n\ntest_input = { \"nums1\": [25,7,18], \"nums2\": [28,1,14,22,24,8,25,17] }\nassert my_solution.findIntersectionValues(**test_input) == [1,1]\n\ntest_input = { \"nums1\": [10,15], \"nums2\": [4,10,15,28] }\nassert my_solution.findIntersectionValues(**test_input) == [2,2]\n\ntest_input = { \"nums1\": [11,11,25], \"nums2\": [11,28,25,13,23,11] }\nassert my_solution.findIntersectionValues(**test_input) == [3,3]\n\ntest_input = { \"nums1\": [10,30,27,8,8,5,11,12,17,13,14,27,17,19,13,20,27], \"nums2\": [10,14,25,2,17,29,10,9,5,30,15,27] }\nassert my_solution.findIntersectionValues(**test_input) == [9,7]\n\ntest_input = { \"nums1\": [19,22,22,22,22,29,22,28,29], \"nums2\": [7,28,29,22,16,22,22,4,17,11,22,22,22,25,25] }\nassert my_solution.findIntersectionValues(**test_input) == [8,8]\n\ntest_input = { \"nums1\": [18,1,23,1,1], \"nums2\": [16,9,1,4,15,11] }\nassert my_solution.findIntersectionValues(**test_input) == [3,1]\n\ntest_input = { \"nums1\": [30,11,15,1,15,6,5,26,15,15], \"nums2\": [1,20,19,30,17,10,6,15] }\nassert my_solution.findIntersectionValues(**test_input) == [7,4]\n\ntest_input = { \"nums1\": [17,6,30,30,15,30,22,2,18,22,21,21,17,19,25,30,18,30,1], \"nums2\": [2,16,25,5,25,1,14,11] }\nassert my_solution.findIntersectionValues(**test_input) == [3,4]\n\ntest_input = { \"nums1\": [3,21,21,23,14], \"nums2\": [1,28,1,3,27,15,28,29,22,14,8,24] }\nassert my_solution.findIntersectionValues(**test_input) == [2,2]\n\ntest_input = { \"nums1\": [8,20,29,23,29,2,2,2,20], \"nums2\": [2,24,20,28,11,8,6,25] }\nassert my_solution.findIntersectionValues(**test_input) == [6,3]\n\ntest_input = { \"nums1\": [22,27,4,27,30,22,25,8,8,30,1,16,1], \"nums2\": [9,21,8,12] }\nassert my_solution.findIntersectionValues(**test_input) == [2,1]\n\ntest_input = { \"nums1\": [19,11,13,1,26,25,19,24,3,10,1,11,1,15,20,20,26,13,13], \"nums2\": [13,23] }\nassert my_solution.findIntersectionValues(**test_input) == [3,1]\n\ntest_input = { \"nums1\": [21,16,11,21], \"nums2\": [21,11,21,2,2,8,16,29,16,16,18,14,18,16,29,10,2] }\nassert my_solution.findIntersectionValues(**test_input) == [4,7]\n\ntest_input = { \"nums1\": [15,7,23,12,23,16,18,1,16,28,28,19,7,30,19], \"nums2\": [9,1,10,15,23,8,8,24,30] }\nassert my_solution.findIntersectionValues(**test_input) == [5,4]\n\ntest_input = { \"nums1\": [2,2,22,24,20,22,1,27,27,10,8,26,22,22,22,10,13,29], \"nums2\": [8,11,1,11] }\nassert my_solution.findIntersectionValues(**test_input) == [2,2]\n\ntest_input = { \"nums1\": [25,29,15,15,21,14,10,23,10,18,11,30,28,16,29], \"nums2\": [1,16,10,2,25,1,15] }\nassert my_solution.findIntersectionValues(**test_input) == [6,4]\n\ntest_input = { \"nums1\": [18,18,11,27,18,20,20], \"nums2\": [16,28,25,28,20,15,8,21,4,6,19,20,20,20,29] }\nassert my_solution.findIntersectionValues(**test_input) == [2,4]\n\ntest_input = { \"nums1\": [1,25,15,20,25,11,4,1,1,21,17,1,19], \"nums2\": [19,19,9,23,1,5,28,28,17,28,3,9,8] }\nassert my_solution.findIntersectionValues(**test_input) == [6,4]\n\ntest_input = { \"nums1\": [7,30,7,7,30,2,7,7], \"nums2\": [19,7,1,7,17,17,20,7,21,30,8,21,10,30,14] }\nassert my_solution.findIntersectionValues(**test_input) == [7,5]\n\ntest_input = { \"nums1\": [7,18,13,27,13,9,22,30], \"nums2\": [27,29,21,30,16,13,29,5,9,16,29,27] }\nassert my_solution.findIntersectionValues(**test_input) == [5,5]\n\ntest_input = { \"nums1\": [19,19,25,24,24,3,19,24,3], \"nums2\": [16,19,19,17,19,24,5,19] }\nassert my_solution.findIntersectionValues(**test_input) == [6,5]\n\ntest_input = { \"nums1\": [19,11,3,11,22,12,23,12,29,19,25,15,23,23], \"nums2\": [4,29,19,23,23,10,2,10,10,15,19,20,19,12,2,19,15,29] }\nassert my_solution.findIntersectionValues(**test_input) == [9,11]\n\ntest_input = { \"nums1\": [25,21], \"nums2\": [20,12,5,13,21,25,9,30,21,7,21,12,20,7] }\nassert my_solution.findIntersectionValues(**test_input) == [2,4]\n\ntest_input = { \"nums1\": [16,17,16,20,29,16,30,24], \"nums2\": [1,30,24] }\nassert my_solution.findIntersectionValues(**test_input) == [2,2]\n\ntest_input = { \"nums1\": [10,6,7,24,17,24,3,24], \"nums2\": [24,27,26,8,7,3,19,24,6,7,30,6] }\nassert my_solution.findIntersectionValues(**test_input) == [6,7]\n\ntest_input = { \"nums1\": [3,26,7,6,23,22,26,8,11,23,17,26,7,2], \"nums2\": [13,11,10,8,4,23] }\nassert my_solution.findIntersectionValues(**test_input) == [4,3]\n\ntest_input = { \"nums1\": [29,10,9,26,30,21,11,26,30], \"nums2\": [2,9,12,9,30,9,30,21,8,3,17,15,25,26,9,15] }\nassert my_solution.findIntersectionValues(**test_input) == [6,8]\n\ntest_input = { \"nums1\": [14,29,15,12,20,27,24,29,4,29,12,6,12,4,7], \"nums2\": [2,19,6,29,10,20,26,11,11,19,4,12,30,22,13,4,24] }\nassert my_solution.findIntersectionValues(**test_input) == [11,7]\n\ntest_input = { \"nums1\": [11,5,3,4,15,30,25,25,30,6,3,28,25,6,30,17,15], \"nums2\": [4,25,17,2,24,28,25,15,4,25,8,6,15] }\nassert my_solution.findIntersectionValues(**test_input) == [10,10]\n\ntest_input = { \"nums1\": [5,23,17,6,5,15,29,2,7,27,5], \"nums2\": [28,14,1,1,27,26,23,20,6,17,11] }\nassert my_solution.findIntersectionValues(**test_input) == [4,4]\n\ntest_input = { \"nums1\": [26,20,12,2,11,23,8,28,28,2,28,20,2,13,13,28,22], \"nums2\": [8,7,12,15,20] }\nassert my_solution.findIntersectionValues(**test_input) == [4,3]\n\ntest_input = { \"nums1\": [15,6,14,24,6,22,6,24,6,6,6,16,24,3,7,6], \"nums2\": [11,6,18,20,12,14,17,3,11,6,2,3,17,19,3] }\nassert my_solution.findIntersectionValues(**test_input) == [9,6]\n\ntest_input = { \"nums1\": [21,10,13,2,3,29,2,29,12,21,16,7,21,26], \"nums2\": [26,16,18,29,16,15,2,16,23,24,26,21,26,13,4,29,13,17,10] }\nassert my_solution.findIntersectionValues(**test_input) == [11,13]\n\ntest_input = { \"nums1\": [5,18,7,30,16,1,24,5,1,15,28,24,25], \"nums2\": [20,29,16,14] }\nassert my_solution.findIntersectionValues(**test_input) == [1,1]\n\ntest_input = { \"nums1\": [1,11,11,28,28,10,15,28,6], \"nums2\": [27,21,28,18,7,7,20,26,4,28,11,22,16,30,11,9,9] }\nassert my_solution.findIntersectionValues(**test_input) == [5,4]\n\ntest_input = { \"nums1\": [27,3], \"nums2\": [29,29,27,1,26,21,27,1,8,3,7,24,19] }\nassert my_solution.findIntersectionValues(**test_input) == [2,3]\n\ntest_input = { \"nums1\": [19,20,25,16,22,23,25,16,23,16,23,14], \"nums2\": [16,5] }\nassert my_solution.findIntersectionValues(**test_input) == [3,1]\n\ntest_input = { \"nums1\": [9,9,5,28,22,15,11,28,5,3,15,6,16,13,29,30], \"nums2\": [18,12,3,5,24,15] }\nassert my_solution.findIntersectionValues(**test_input) == [5,3]\n\ntest_input = { \"nums1\": [21,19,11,24,7,5,10], \"nums2\": [19,19,14,3,4,14,27,18,14,10] }\nassert my_solution.findIntersectionValues(**test_input) == [2,3]\n\ntest_input = { \"nums1\": [6,18,18,20,5,18,1,15,18,26,28,26], \"nums2\": [13,12,2,24,20,28,27,20,11] }\nassert my_solution.findIntersectionValues(**test_input) == [2,3]\n\ntest_input = { \"nums1\": [18,14,14,15,10,14,7,1,28,15], \"nums2\": [11,18,15,18,27,12] }\nassert my_solution.findIntersectionValues(**test_input) == [3,3]\n\ntest_input = { \"nums1\": [29,18,29,18,27,11,11,8,4,18,11,14,5,21,21,29,11], \"nums2\": [25,29,15,17,27,20,9,23,11,13,26,8,11,6] }\nassert my_solution.findIntersectionValues(**test_input) == [9,5]\n\ntest_input = { \"nums1\": [14,5,8,21,24,5,21,19,29], \"nums2\": [15,10,9,13,24,4,9,10,3,6,5,20,24,26,14,27,14,10,22] }\nassert my_solution.findIntersectionValues(**test_input) == [4,5]\n\ntest_input = { \"nums1\": [2,11,11,9,25,11,27,16,28,10,18,3,22,15,16,11], \"nums2\": [11,3,21,9,3,13,23,9,28,25,8,28,29,2,23,12,13,14,14] }\nassert my_solution.findIntersectionValues(**test_input) == [9,9]\n\ntest_input = { \"nums1\": [12,11,23,17,23,3,17], \"nums2\": [18,20,8,29,28,27,14,28,13,25,24,2,11,23] }\nassert my_solution.findIntersectionValues(**test_input) == [3,2]\n\ntest_input = { \"nums1\": [8,18,7,7,7,24,16,8,23,23,16,16,3,16,22,18,8], \"nums2\": [29,3,14,22,17,22,25,25,1,23,6,23,7,12,16] }\nassert my_solution.findIntersectionValues(**test_input) == [11,7]\n\ntest_input = { \"nums1\": [25,9,11,13,21,3,7,24,29,14,2,7,18,30,18], \"nums2\": [2,3,28,3,25,25,21,10,4,19,23,11,27] }\nassert my_solution.findIntersectionValues(**test_input) == [5,7]\n\ntest_input = { \"nums1\": [5,8,12,18,5,8], \"nums2\": [12,19,30,16,13] }\nassert my_solution.findIntersectionValues(**test_input) == [1,1]\n\ntest_input = { \"nums1\": [14,22,29,29,3,22,4,29,28,27], \"nums2\": [14,29] }\nassert my_solution.findIntersectionValues(**test_input) == [4,2]\n\ntest_input = { \"nums1\": [28,28,11,5,18,5,18,17,21,4,9,4], \"nums2\": [19,6,12,17,13] }\nassert my_solution.findIntersectionValues(**test_input) == [1,1]\n\ntest_input = { \"nums1\": [24,29,19,25,7,26,7,25,7,25,2], \"nums2\": [9,4,2,20,29,1,27] }\nassert my_solution.findIntersectionValues(**test_input) == [2,2]\n\ntest_input = { \"nums1\": [19,14,14,21,14,11,21,18,11,14,18,28,4], \"nums2\": [25,30,1] }\nassert my_solution.findIntersectionValues(**test_input) == [0,0]\n\ntest_input = { \"nums1\": [9,17,21,21,18,9,9,16,9,3,17,9,3], \"nums2\": [9,10,20,7,3,13,13,22,15] }\nassert my_solution.findIntersectionValues(**test_input) == [7,2]\n\ntest_input = { \"nums1\": [21,14,14,14,5,11,8,7,9,3,7,3], \"nums2\": [2,24,28,8,15,5,3,6,14,3,19,25,5] }\nassert my_solution.findIntersectionValues(**test_input) == [7,6]\n\ntest_input = { \"nums1\": [3,17,13,18,18,12,5,12,27,6,3,13,7,3,12,27,6], \"nums2\": [17,28,13,26,12,27,20,12,27,7,10,24] }\nassert my_solution.findIntersectionValues(**test_input) == [9,7]\n\ntest_input = { \"nums1\": [18,9,30,9,3,13,25,5,30,25,13,19,25,3,28,29,9,9,9,12], \"nums2\": [17,20,28,30,27,1,22] }\nassert my_solution.findIntersectionValues(**test_input) == [3,2]\n\ntest_input = { \"nums1\": [18,19,13,20,26,26,13,13,26,25,22,20,17], \"nums2\": [3,21,12,12,18,20,26,17,30,6,22,13] }\nassert my_solution.findIntersectionValues(**test_input) == [11,6]\n\ntest_input = { \"nums1\": [19,10,2,18,15,24,4,11,12,24,10,10,9,12,6,10,17,22,11,12], \"nums2\": [10,16,7,2,27,22,19,17,11,15,27,24] }\nassert my_solution.findIntersectionValues(**test_input) == [13,8]\n\ntest_input = { \"nums1\": [8,8], \"nums2\": [8,24,8,8,19,27,7,21,8,8] }\nassert my_solution.findIntersectionValues(**test_input) == [2,5]\n\ntest_input = { \"nums1\": [22,23,22], \"nums2\": [22,21,3,22,17,27] }\nassert my_solution.findIntersectionValues(**test_input) == [2,2]\n\ntest_input = { \"nums1\": [20,10], \"nums2\": [10,20,12] }\nassert my_solution.findIntersectionValues(**test_input) == [2,2]\n\ntest_input = { \"nums1\": [15,28,15,17,3,6], \"nums2\": [3,15,17,30,18,22,4] }\nassert my_solution.findIntersectionValues(**test_input) == [4,3]\n\ntest_input = { \"nums1\": [30,15], \"nums2\": [15,25,23,26,14,30,8,19,15,8,10,14,26,15,28,30] }\nassert my_solution.findIntersectionValues(**test_input) == [2,5]\n\ntest_input = { \"nums1\": [16,11,16,24,7,9,9,24], \"nums2\": [19,2,9,18,25,11,1,16,24,18,20,9,24,7,9,29,16,22,15] }\nassert my_solution.findIntersectionValues(**test_input) == [8,9]\n\ntest_input = { \"nums1\": [13,25,8,8,1,14,8,4,8,8,25,8,22], \"nums2\": [17,8,13,8,8,20,26,20,8,22,17,14,8,16,26,2,23,18,18,4] }\nassert my_solution.findIntersectionValues(**test_input) == [10,9]\n\ntest_input = { \"nums1\": [9,9,9,29,11,9,18,23,9,9,26,9,23,9,9,2,28,7], \"nums2\": [17,6,2,11,10,23,11,30,11,24,1,11,13,9,23,25] }\nassert my_solution.findIntersectionValues(**test_input) == [13,8]\n\ntest_input = { \"nums1\": [27,16,16,15], \"nums2\": [3,16,7,16,23,16,3,26,27,30,4,28,26,24,7] }\nassert my_solution.findIntersectionValues(**test_input) == [3,4]\n\ntest_input = { \"nums1\": [19,1,26,15,15], \"nums2\": [6,25] }\nassert my_solution.findIntersectionValues(**test_input) == [0,0]\n\ntest_input = { \"nums1\": [13,29,29,12,25,22,2,25,11,3,22,13,23,19,24,24,8,30], \"nums2\": [20,25,12,5,2,28,14,27,24,3,21,15,25,2,12,28,19,7,5] }\nassert my_solution.findIntersectionValues(**test_input) == [8,9]\n\ntest_input = { \"nums1\": [14,14,26,25,28,26], \"nums2\": [4,23,9,3,1,2,27,8,22,6,24] }\nassert my_solution.findIntersectionValues(**test_input) == [0,0]\n\ntest_input = { \"nums1\": [14,29,2,26,14,10,1,23,28,5,17,1,21,5,28,14,6,4,18], \"nums2\": [1,20,7,15,18,26,5,10,8,6,27] }\nassert my_solution.findIntersectionValues(**test_input) == [8,6]\n\ntest_input = { \"nums1\": [29,3,15,7,2,20,30,15,7,29,2,21], \"nums2\": [15,23,22,19,21,5,7,29,23,2,17,27,21,15,6,7] }\nassert my_solution.findIntersectionValues(**test_input) == [9,8]\n\ntest_input = { \"nums1\": [7,23,23,15,23,10,30,23,30,10,30,17,30,10,3,7,10], \"nums2\": [21,21] }\nassert my_solution.findIntersectionValues(**test_input) == [0,0]\n\ntest_input = { \"nums1\": [8,13,1,13,13,12,27,21,4,4,17], \"nums2\": [12,13,1,27,4,9,12,8,25,29,4,8,4,29,21,28,1,8,6,6] }\nassert my_solution.findIntersectionValues(**test_input) == [10,13]\n\ntest_input = { \"nums1\": [6,15,7,1,7,14,21,3,30,23,22,29], \"nums2\": [30,1,7,29,3,4] }\nassert my_solution.findIntersectionValues(**test_input) == [6,5]\n\ntest_input = { \"nums1\": [15,10,22,22,6,8,15,8,10], \"nums2\": [10,4,8,15,29,6,9,22,3,3,23,3,13,8,5,8,3] }\nassert my_solution.findIntersectionValues(**test_input) == [9,7]\n\ntest_input = { \"nums1\": [14,4,1,27,22,14,7,22,15,3,22,8], \"nums2\": [30,4,4,27,6,4,16,11,23,14,4,7,21,22,9,14,4,27,17,27] }\nassert my_solution.findIntersectionValues(**test_input) == [8,12]\n\ntest_input = { \"nums1\": [23,15,15,15], \"nums2\": [23,17,12,15,21] }\nassert my_solution.findIntersectionValues(**test_input) == [4,2]\n\ntest_input = { \"nums1\": [28,29,15,19,1,23,25,9,29,25,19,11,9,19], \"nums2\": [9,4,11,23,13,8,24,9,23] }\nassert my_solution.findIntersectionValues(**test_input) == [4,5]\n\ntest_input = { \"nums1\": [19,24,7,2,3,10,27,10,4,4,9,29,10,7], \"nums2\": [23,4,7,4,27,13,2,9,23] }\nassert my_solution.findIntersectionValues(**test_input) == [7,6]\n\ntest_input = { \"nums1\": [24,22,17,24,22,16,1,5], \"nums2\": [1,27,7,22,27,13,4,5,12,8,22,18,5] }\nassert my_solution.findIntersectionValues(**test_input) == [4,5]", "start_time": 1702132200} +{"task_id": "biweekly-contest-119-remove-adjacent-almost-equal-characters", "url": "https://leetcode.com/problems/remove-adjacent-almost-equal-characters", "title": "remove-adjacent-almost-equal-characters", "meta": {"questionId": "3230", "questionFrontendId": "2957", "title": "Remove Adjacent Almost-Equal Characters", "titleSlug": "remove-adjacent-almost-equal-characters", "isPaidOnly": false, "difficulty": "Medium", "likes": 115, "dislikes": 16, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed string word.\nIn one operation, you can pick any index i of word and change word[i] to any lowercase English letter.\nReturn the minimum number of operations needed to remove all adjacent almost-equal characters from word.\nTwo characters a and b are almost-equal if a == b or a and b are adjacent in the alphabet.\n\nExample 1:\n\nInput: word = \"aaaaa\"\nOutput: 2\nExplanation: We can change word into \"acaca\" which does not have any adjacent almost-equal characters.\nIt can be shown that the minimum number of operations needed to remove all adjacent almost-equal characters from word is 2.\n\nExample 2:\n\nInput: word = \"abddez\"\nOutput: 2\nExplanation: We can change word into \"ybdoez\" which does not have any adjacent almost-equal characters.\nIt can be shown that the minimum number of operations needed to remove all adjacent almost-equal characters from word is 2.\nExample 3:\n\nInput: word = \"zyxyxyz\"\nOutput: 3\nExplanation: We can change word into \"zaxaxaz\" which does not have any adjacent almost-equal characters. \nIt can be shown that the minimum number of operations needed to remove all adjacent almost-equal characters from word is 3.\n\n\nConstraints:\n\n1 <= word.length <= 100\nword consists only of lowercase English letters.\n\"\"\"\nclass Solution:\n def removeAlmostEqualCharacters(self, word: str) -> int:\n ", "prompt_sft": "You are given a 0-indexed string word.\nIn one operation, you can pick any index i of word and change word[i] to any lowercase English letter.\nReturn the minimum number of operations needed to remove all adjacent almost-equal characters from word.\nTwo characters a and b are almost-equal if a == b or a and b are adjacent in the alphabet.\n\nExample 1:\n\nInput: word = \"aaaaa\"\nOutput: 2\nExplanation: We can change word into \"acaca\" which does not have any adjacent almost-equal characters.\nIt can be shown that the minimum number of operations needed to remove all adjacent almost-equal characters from word is 2.\n\nExample 2:\n\nInput: word = \"abddez\"\nOutput: 2\nExplanation: We can change word into \"ybdoez\" which does not have any adjacent almost-equal characters.\nIt can be shown that the minimum number of operations needed to remove all adjacent almost-equal characters from word is 2.\nExample 3:\n\nInput: word = \"zyxyxyz\"\nOutput: 3\nExplanation: We can change word into \"zaxaxaz\" which does not have any adjacent almost-equal characters. \nIt can be shown that the minimum number of operations needed to remove all adjacent almost-equal characters from word is 3.\n\n\nConstraints:\n\n1 <= word.length <= 100\nword consists only of lowercase English letters.\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def removeAlmostEqualCharacters(self, word: str) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"word\": \"aaaaa\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"abddez\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"zyxyxyz\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 3\n\ntest_input = { \"word\": \"a\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 0\n\ntest_input = { \"word\": \"b\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 0\n\ntest_input = { \"word\": \"c\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 0\n\ntest_input = { \"word\": \"aa\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"ab\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"ac\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 0\n\ntest_input = { \"word\": \"ba\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"bb\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"bc\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"ca\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 0\n\ntest_input = { \"word\": \"cb\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"cc\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"aaa\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"aab\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"aac\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"aba\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"abb\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"abc\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"aca\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 0\n\ntest_input = { \"word\": \"acb\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"acc\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"baa\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"bab\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"bac\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"bba\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"bbb\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"bbc\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"bca\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"bcb\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"bcc\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"caa\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"cab\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"cac\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 0\n\ntest_input = { \"word\": \"cba\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"cbb\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"cbc\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"cca\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"ccb\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"ccc\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"aaaa\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"aaab\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"aaac\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"aaba\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"aabb\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"aabc\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"aaca\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"aacb\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"aacc\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"abaa\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"abab\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"abac\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"abba\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"abbb\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"abbc\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"abca\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"abcb\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"abcc\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"acaa\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"acab\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"acac\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 0\n\ntest_input = { \"word\": \"acba\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"acbb\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"acbc\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"acca\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"accb\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"accc\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"baaa\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"baab\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"baac\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"baba\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"babb\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"babc\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"baca\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"bacb\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"bacc\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"bbaa\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"bbab\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"bbac\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"bbba\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"bbbb\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"bbbc\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"bbca\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"bbcb\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"bbcc\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"bcaa\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"bcab\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"bcac\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"bcba\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"bcbb\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"bcbc\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"bcca\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"bccb\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"bccc\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 2\n\ntest_input = { \"word\": \"caaa\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"caab\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"caac\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1\n\ntest_input = { \"word\": \"caba\" }\nassert my_solution.removeAlmostEqualCharacters(**test_input) == 1", "start_time": 1702132200} +{"task_id": "biweekly-contest-119-length-of-longest-subarray-with-at-most-k-frequency", "url": "https://leetcode.com/problems/length-of-longest-subarray-with-at-most-k-frequency", "title": "length-of-longest-subarray-with-at-most-k-frequency", "meta": {"questionId": "3225", "questionFrontendId": "2958", "title": "Length of Longest Subarray With at Most K Frequency", "titleSlug": "length-of-longest-subarray-with-at-most-k-frequency", "isPaidOnly": false, "difficulty": "Medium", "likes": 139, "dislikes": 5, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given an integer array nums and an integer k.\nThe frequency of an element x is the number of times it occurs in an array.\nAn array is called good if the frequency of each element in this array is less than or equal to k.\nReturn the length of the longest good subarray of nums.\nA subarray is a contiguous non-empty sequence of elements within an array.\n\nExample 1:\n\nInput: nums = [1,2,3,1,2,3,1,2], k = 2\nOutput: 6\nExplanation: The longest possible good subarray is [1,2,3,1,2,3] since the values 1, 2, and 3 occur at most twice in this subarray. Note that the subarrays [2,3,1,2,3,1] and [3,1,2,3,1,2] are also good.\nIt can be shown that there are no good subarrays with length more than 6.\n\nExample 2:\n\nInput: nums = [1,2,1,2,1,2,1,2], k = 1\nOutput: 2\nExplanation: The longest possible good subarray is [1,2] since the values 1 and 2 occur at most once in this subarray. Note that the subarray [2,1] is also good.\nIt can be shown that there are no good subarrays with length more than 2.\n\nExample 3:\n\nInput: nums = [5,5,5,5,5,5,5], k = 4\nOutput: 4\nExplanation: The longest possible good subarray is [5,5,5,5] since the value 5 occurs 4 times in this subarray.\nIt can be shown that there are no good subarrays with length more than 4.\n\n\nConstraints:\n\n1 <= nums.length <= 105\n1 <= nums[i] <= 109\n1 <= k <= nums.length\n\"\"\"\nclass Solution:\n def maxSubarrayLength(self, nums: List[int], k: int) -> int:\n ", "prompt_sft": "You are given an integer array nums and an integer k.\nThe frequency of an element x is the number of times it occurs in an array.\nAn array is called good if the frequency of each element in this array is less than or equal to k.\nReturn the length of the longest good subarray of nums.\nA subarray is a contiguous non-empty sequence of elements within an array.\n\nExample 1:\n\nInput: nums = [1,2,3,1,2,3,1,2], k = 2\nOutput: 6\nExplanation: The longest possible good subarray is [1,2,3,1,2,3] since the values 1, 2, and 3 occur at most twice in this subarray. Note that the subarrays [2,3,1,2,3,1] and [3,1,2,3,1,2] are also good.\nIt can be shown that there are no good subarrays with length more than 6.\n\nExample 2:\n\nInput: nums = [1,2,1,2,1,2,1,2], k = 1\nOutput: 2\nExplanation: The longest possible good subarray is [1,2] since the values 1 and 2 occur at most once in this subarray. Note that the subarray [2,1] is also good.\nIt can be shown that there are no good subarrays with length more than 2.\n\nExample 3:\n\nInput: nums = [5,5,5,5,5,5,5], k = 4\nOutput: 4\nExplanation: The longest possible good subarray is [5,5,5,5] since the value 5 occurs 4 times in this subarray.\nIt can be shown that there are no good subarrays with length more than 4.\n\n\nConstraints:\n\n1 <= nums.length <= 105\n1 <= nums[i] <= 109\n1 <= k <= nums.length\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def maxSubarrayLength(self, nums: List[int], k: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,2,3,1,2,3,1,2], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 6\n\ntest_input = { \"nums\": [1,2,1,2,1,2,1,2], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 2\n\ntest_input = { \"nums\": [5,5,5,5,5,5,5], \"k\": 4 }\nassert my_solution.maxSubarrayLength(**test_input) == 4\n\ntest_input = { \"nums\": [1], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [2], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [3], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [4], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [5], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [6], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [7], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [8], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [9], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [10], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [1,11], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 2\n\ntest_input = { \"nums\": [2,11], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 2\n\ntest_input = { \"nums\": [3,5], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 2\n\ntest_input = { \"nums\": [4,6], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 2\n\ntest_input = { \"nums\": [5,8], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 2\n\ntest_input = { \"nums\": [6,7], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 2\n\ntest_input = { \"nums\": [7,9], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 2\n\ntest_input = { \"nums\": [8,8], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 1\n\ntest_input = { \"nums\": [9,8], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 2\n\ntest_input = { \"nums\": [10,5], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,2], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,5], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,3], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,4], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [1,3,3], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [1,3,5], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [1,4,1], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 2\n\ntest_input = { \"nums\": [1,4,1], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [1,5,1], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [1,5,5], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [1,6,4], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [1,6,4], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [1,7,1], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 2\n\ntest_input = { \"nums\": [1,7,5], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [1,8,2], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [1,8,4], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [1,9,2], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [1,9,2], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [1,10,2], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [2,1,2], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [2,2,3], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 2\n\ntest_input = { \"nums\": [2,2,4], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [2,3,3], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [2,3,4], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [2,4,1], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [2,4,2], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [2,5,2], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 2\n\ntest_input = { \"nums\": [2,5,4], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [2,6,2], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 2\n\ntest_input = { \"nums\": [2,6,3], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [2,7,1], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [2,7,2], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [2,8,2], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [2,8,5], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [2,9,2], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 2\n\ntest_input = { \"nums\": [2,9,5], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [2,10,1], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [2,10,3], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [3,1,1], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 2\n\ntest_input = { \"nums\": [3,1,4], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [3,2,3], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 2\n\ntest_input = { \"nums\": [3,2,4], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [3,3,1], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [3,3,3], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 2\n\ntest_input = { \"nums\": [3,4,1], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [3,4,2], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [3,5,4], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [3,5,5], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 2\n\ntest_input = { \"nums\": [3,6,2], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [3,6,4], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [3,7,5], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [3,7,5], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [3,8,1], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [3,8,2], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [3,9,1], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [3,9,4], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [3,10,1], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [3,10,3], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [4,1,2], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [4,1,5], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [4,2,4], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [4,2,5], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [4,3,1], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [4,3,3], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 2\n\ntest_input = { \"nums\": [4,4,3], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [4,4,5], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [4,5,2], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [4,5,4], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [4,6,1], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [4,6,2], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [4,7,1], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [4,7,4], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [4,8,2], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [4,8,4], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [4,9,2], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [4,9,3], \"k\": 2 }\nassert my_solution.maxSubarrayLength(**test_input) == 3\n\ntest_input = { \"nums\": [4,10,2], \"k\": 1 }\nassert my_solution.maxSubarrayLength(**test_input) == 3", "start_time": 1702132200} +{"task_id": "biweekly-contest-119-number-of-possible-sets-of-closing-branches", "url": "https://leetcode.com/problems/number-of-possible-sets-of-closing-branches", "title": "number-of-possible-sets-of-closing-branches", "meta": {"questionId": "3217", "questionFrontendId": "2959", "title": "Number of Possible Sets of Closing Branches", "titleSlug": "number-of-possible-sets-of-closing-branches", "isPaidOnly": false, "difficulty": "Hard", "likes": 110, "dislikes": 9, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nThere is a company with n branches across the country, some of which are connected by roads. Initially, all branches are reachable from each other by traveling some roads.\nThe company has realized that they are spending an excessive amount of time traveling between their branches. As a result, they have decided to close down some of these branches (possibly none). However, they want to ensure that the remaining branches have a distance of at most maxDistance from each other.\nThe distance between two branches is the minimum total traveled length needed to reach one branch from another.\nYou are given integers n, maxDistance, and a 0-indexed 2D array roads, where roads[i] = [ui, vi, wi] represents the undirected road between branches ui and vi with length wi.\nReturn the number of possible sets of closing branches, so that any branch has a distance of at most maxDistance from any other.\nNote that, after closing a branch, the company will no longer have access to any roads connected to it.\nNote that, multiple roads are allowed.\n\nExample 1:\n\n\nInput: n = 3, maxDistance = 5, roads = [[0,1,2],[1,2,10],[0,2,10]]\nOutput: 5\nExplanation: The possible sets of closing branches are:\n- The set [2], after closing, active branches are [0,1] and they are reachable to each other within distance 2.\n- The set [0,1], after closing, the active branch is [2].\n- The set [1,2], after closing, the active branch is [0].\n- The set [0,2], after closing, the active branch is [1].\n- The set [0,1,2], after closing, there are no active branches.\nIt can be proven, that there are only 5 possible sets of closing branches.\n\nExample 2:\n\n\nInput: n = 3, maxDistance = 5, roads = [[0,1,20],[0,1,10],[1,2,2],[0,2,2]]\nOutput: 7\nExplanation: The possible sets of closing branches are:\n- The set [], after closing, active branches are [0,1,2] and they are reachable to each other within distance 4.\n- The set [0], after closing, active branches are [1,2] and they are reachable to each other within distance 2.\n- The set [1], after closing, active branches are [0,2] and they are reachable to each other within distance 2.\n- The set [0,1], after closing, the active branch is [2].\n- The set [1,2], after closing, the active branch is [0].\n- The set [0,2], after closing, the active branch is [1].\n- The set [0,1,2], after closing, there are no active branches.\nIt can be proven, that there are only 7 possible sets of closing branches.\n\nExample 3:\n\nInput: n = 1, maxDistance = 10, roads = []\nOutput: 2\nExplanation: The possible sets of closing branches are:\n- The set [], after closing, the active branch is [0].\n- The set [0], after closing, there are no active branches.\nIt can be proven, that there are only 2 possible sets of closing branches.\n\n\nConstraints:\n\n1 <= n <= 10\n1 <= maxDistance <= 105\n0 <= roads.length <= 1000\nroads[i].length == 3\n0 <= ui, vi <= n - 1\nui != vi\n1 <= wi <= 1000\nAll branches are reachable from each other by traveling some roads.\n\"\"\"\nclass Solution:\n def numberOfSets(self, n: int, maxDistance: int, roads: List[List[int]]) -> int:\n ", "prompt_sft": "There is a company with n branches across the country, some of which are connected by roads. Initially, all branches are reachable from each other by traveling some roads.\nThe company has realized that they are spending an excessive amount of time traveling between their branches. As a result, they have decided to close down some of these branches (possibly none). However, they want to ensure that the remaining branches have a distance of at most maxDistance from each other.\nThe distance between two branches is the minimum total traveled length needed to reach one branch from another.\nYou are given integers n, maxDistance, and a 0-indexed 2D array roads, where roads[i] = [ui, vi, wi] represents the undirected road between branches ui and vi with length wi.\nReturn the number of possible sets of closing branches, so that any branch has a distance of at most maxDistance from any other.\nNote that, after closing a branch, the company will no longer have access to any roads connected to it.\nNote that, multiple roads are allowed.\n\nExample 1:\n\n\nInput: n = 3, maxDistance = 5, roads = [[0,1,2],[1,2,10],[0,2,10]]\nOutput: 5\nExplanation: The possible sets of closing branches are:\n- The set [2], after closing, active branches are [0,1] and they are reachable to each other within distance 2.\n- The set [0,1], after closing, the active branch is [2].\n- The set [1,2], after closing, the active branch is [0].\n- The set [0,2], after closing, the active branch is [1].\n- The set [0,1,2], after closing, there are no active branches.\nIt can be proven, that there are only 5 possible sets of closing branches.\n\nExample 2:\n\n\nInput: n = 3, maxDistance = 5, roads = [[0,1,20],[0,1,10],[1,2,2],[0,2,2]]\nOutput: 7\nExplanation: The possible sets of closing branches are:\n- The set [], after closing, active branches are [0,1,2] and they are reachable to each other within distance 4.\n- The set [0], after closing, active branches are [1,2] and they are reachable to each other within distance 2.\n- The set [1], after closing, active branches are [0,2] and they are reachable to each other within distance 2.\n- The set [0,1], after closing, the active branch is [2].\n- The set [1,2], after closing, the active branch is [0].\n- The set [0,2], after closing, the active branch is [1].\n- The set [0,1,2], after closing, there are no active branches.\nIt can be proven, that there are only 7 possible sets of closing branches.\n\nExample 3:\n\nInput: n = 1, maxDistance = 10, roads = []\nOutput: 2\nExplanation: The possible sets of closing branches are:\n- The set [], after closing, the active branch is [0].\n- The set [0], after closing, there are no active branches.\nIt can be proven, that there are only 2 possible sets of closing branches.\n\n\nConstraints:\n\n1 <= n <= 10\n1 <= maxDistance <= 105\n0 <= roads.length <= 1000\nroads[i].length == 3\n0 <= ui, vi <= n - 1\nui != vi\n1 <= wi <= 1000\nAll branches are reachable from each other by traveling some roads.\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def numberOfSets(self, n: int, maxDistance: int, roads: List[List[int]]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"n\": 3, \"maxDistance\": 5, \"roads\": [[0,1,2],[1,2,10],[0,2,10]] }\nassert my_solution.numberOfSets(**test_input) == 5\n\ntest_input = { \"n\": 3, \"maxDistance\": 5, \"roads\": [[0,1,20],[0,1,10],[1,2,2],[0,2,2]] }\nassert my_solution.numberOfSets(**test_input) == 7\n\ntest_input = { \"n\": 1, \"maxDistance\": 10, \"roads\": [] }\nassert my_solution.numberOfSets(**test_input) == 2\n\ntest_input = { \"n\": 3, \"maxDistance\": 12, \"roads\": [[1,0,11],[1,0,16],[0,2,13]] }\nassert my_solution.numberOfSets(**test_input) == 5\n\ntest_input = { \"n\": 3, \"maxDistance\": 3, \"roads\": [[2,0,14],[1,0,15],[1,0,7]] }\nassert my_solution.numberOfSets(**test_input) == 4\n\ntest_input = { \"n\": 3, \"maxDistance\": 19, \"roads\": [[1,0,7],[0,2,18]] }\nassert my_solution.numberOfSets(**test_input) == 6\n\ntest_input = { \"n\": 3, \"maxDistance\": 5, \"roads\": [[2,0,4],[1,0,3],[1,0,2]] }\nassert my_solution.numberOfSets(**test_input) == 6\n\ntest_input = { \"n\": 4, \"maxDistance\": 3, \"roads\": [[2,1,8],[1,0,3],[0,3,8]] }\nassert my_solution.numberOfSets(**test_input) == 6\n\ntest_input = { \"n\": 5, \"maxDistance\": 20, \"roads\": [[3,2,20],[1,0,10],[0,2,19],[0,3,13],[0,4,19]] }\nassert my_solution.numberOfSets(**test_input) == 12\n\ntest_input = { \"n\": 2, \"maxDistance\": 30, \"roads\": [[1,0,33]] }\nassert my_solution.numberOfSets(**test_input) == 3\n\ntest_input = { \"n\": 3, \"maxDistance\": 12, \"roads\": [[2,1,4],[0,1,4],[0,2,6]] }\nassert my_solution.numberOfSets(**test_input) == 8\n\ntest_input = { \"n\": 3, \"maxDistance\": 3, \"roads\": [[1,0,4],[0,2,5]] }\nassert my_solution.numberOfSets(**test_input) == 4\n\ntest_input = { \"n\": 3, \"maxDistance\": 27, \"roads\": [[2,1,23],[0,1,14],[0,2,18]] }\nassert my_solution.numberOfSets(**test_input) == 8\n\ntest_input = { \"n\": 4, \"maxDistance\": 20, \"roads\": [[2,0,16],[0,1,13],[0,3,11]] }\nassert my_solution.numberOfSets(**test_input) == 8\n\ntest_input = { \"n\": 3, \"maxDistance\": 22, \"roads\": [[1,0,21],[2,1,28]] }\nassert my_solution.numberOfSets(**test_input) == 5\n\ntest_input = { \"n\": 2, \"maxDistance\": 2, \"roads\": [[1,0,6]] }\nassert my_solution.numberOfSets(**test_input) == 3\n\ntest_input = { \"n\": 3, \"maxDistance\": 22, \"roads\": [[1,0,16],[1,0,12],[0,2,14]] }\nassert my_solution.numberOfSets(**test_input) == 6\n\ntest_input = { \"n\": 2, \"maxDistance\": 8, \"roads\": [[1,0,9]] }\nassert my_solution.numberOfSets(**test_input) == 3\n\ntest_input = { \"n\": 2, \"maxDistance\": 18, \"roads\": [[1,0,3]] }\nassert my_solution.numberOfSets(**test_input) == 4\n\ntest_input = { \"n\": 4, \"maxDistance\": 27, \"roads\": [[3,2,3],[0,1,27],[0,2,6],[0,3,17]] }\nassert my_solution.numberOfSets(**test_input) == 10\n\ntest_input = { \"n\": 5, \"maxDistance\": 14, \"roads\": [[1,0,13],[2,0,19],[0,3,16],[0,4,18]] }\nassert my_solution.numberOfSets(**test_input) == 7\n\ntest_input = { \"n\": 5, \"maxDistance\": 8, \"roads\": [[1,0,3],[3,1,10],[4,0,6],[2,0,9],[3,2,11],[4,0,12]] }\nassert my_solution.numberOfSets(**test_input) == 8\n\ntest_input = { \"n\": 2, \"maxDistance\": 4, \"roads\": [[1,0,7]] }\nassert my_solution.numberOfSets(**test_input) == 3\n\ntest_input = { \"n\": 4, \"maxDistance\": 39, \"roads\": [[2,0,44],[3,2,42],[2,1,45]] }\nassert my_solution.numberOfSets(**test_input) == 5\n\ntest_input = { \"n\": 5, \"maxDistance\": 2, \"roads\": [[4,1,11],[3,1,5],[1,0,4],[0,2,7]] }\nassert my_solution.numberOfSets(**test_input) == 6\n\ntest_input = { \"n\": 3, \"maxDistance\": 9, \"roads\": [[1,0,17],[0,2,22]] }\nassert my_solution.numberOfSets(**test_input) == 4\n\ntest_input = { \"n\": 2, \"maxDistance\": 1, \"roads\": [[1,0,3]] }\nassert my_solution.numberOfSets(**test_input) == 3\n\ntest_input = { \"n\": 3, \"maxDistance\": 39, \"roads\": [[1,0,28],[0,2,35]] }\nassert my_solution.numberOfSets(**test_input) == 6\n\ntest_input = { \"n\": 4, \"maxDistance\": 17, \"roads\": [[2,1,28],[2,0,6],[1,0,28],[1,0,24],[1,0,18],[1,0,25],[0,3,10]] }\nassert my_solution.numberOfSets(**test_input) == 8\n\ntest_input = { \"n\": 5, \"maxDistance\": 16, \"roads\": [[2,1,27],[3,0,22],[2,1,4],[1,0,11],[2,1,48],[1,0,40],[4,2,33],[4,3,44],[1,0,1]] }\nassert my_solution.numberOfSets(**test_input) == 9\n\ntest_input = { \"n\": 3, \"maxDistance\": 23, \"roads\": [[2,1,20],[0,1,12],[0,2,10]] }\nassert my_solution.numberOfSets(**test_input) == 8\n\ntest_input = { \"n\": 5, \"maxDistance\": 3, \"roads\": [[4,0,5],[1,0,2],[3,0,5],[3,0,4],[4,2,5],[4,2,1]] }\nassert my_solution.numberOfSets(**test_input) == 8\n\ntest_input = { \"n\": 3, \"maxDistance\": 5, \"roads\": [[1,0,6],[2,0,7]] }\nassert my_solution.numberOfSets(**test_input) == 4\n\ntest_input = { \"n\": 3, \"maxDistance\": 21, \"roads\": [[2,1,30],[0,1,36],[0,2,44]] }\nassert my_solution.numberOfSets(**test_input) == 4\n\ntest_input = { \"n\": 5, \"maxDistance\": 25, \"roads\": [[1,0,17],[1,0,1],[2,1,24],[3,2,12],[1,0,7],[3,2,4],[2,1,15],[0,4,14]] }\nassert my_solution.numberOfSets(**test_input) == 14\n\ntest_input = { \"n\": 2, \"maxDistance\": 3, \"roads\": [[1,0,6]] }\nassert my_solution.numberOfSets(**test_input) == 3\n\ntest_input = { \"n\": 3, \"maxDistance\": 4, \"roads\": [[1,0,6],[2,1,6],[2,0,2]] }\nassert my_solution.numberOfSets(**test_input) == 5\n\ntest_input = { \"n\": 4, \"maxDistance\": 21, \"roads\": [[3,2,18],[1,0,15],[2,1,15],[3,0,19],[3,2,19]] }\nassert my_solution.numberOfSets(**test_input) == 9\n\ntest_input = { \"n\": 4, \"maxDistance\": 1, \"roads\": [[1,0,4],[1,0,2],[3,1,2],[2,1,1],[1,0,3],[2,0,3]] }\nassert my_solution.numberOfSets(**test_input) == 6\n\ntest_input = { \"n\": 3, \"maxDistance\": 33, \"roads\": [[2,1,2],[1,0,40],[2,1,43]] }\nassert my_solution.numberOfSets(**test_input) == 5\n\ntest_input = { \"n\": 4, \"maxDistance\": 29, \"roads\": [[2,1,20],[1,0,38],[2,1,15],[2,0,32],[0,3,18]] }\nassert my_solution.numberOfSets(**test_input) == 7\n\ntest_input = { \"n\": 3, \"maxDistance\": 1, \"roads\": [[2,1,4],[2,0,2],[1,0,12]] }\nassert my_solution.numberOfSets(**test_input) == 4\n\ntest_input = { \"n\": 2, \"maxDistance\": 2, \"roads\": [[1,0,3]] }\nassert my_solution.numberOfSets(**test_input) == 3\n\ntest_input = { \"n\": 3, \"maxDistance\": 13, \"roads\": [[1,0,18],[2,0,1],[2,1,2]] }\nassert my_solution.numberOfSets(**test_input) == 7\n\ntest_input = { \"n\": 3, \"maxDistance\": 1, \"roads\": [[1,0,23],[0,2,37]] }\nassert my_solution.numberOfSets(**test_input) == 4\n\ntest_input = { \"n\": 3, \"maxDistance\": 18, \"roads\": [[2,0,39],[0,1,47]] }\nassert my_solution.numberOfSets(**test_input) == 4\n\ntest_input = { \"n\": 4, \"maxDistance\": 6, \"roads\": [[3,0,6],[0,1,3],[0,2,9]] }\nassert my_solution.numberOfSets(**test_input) == 7\n\ntest_input = { \"n\": 3, \"maxDistance\": 35, \"roads\": [[1,0,10],[1,0,15],[0,2,32]] }\nassert my_solution.numberOfSets(**test_input) == 6\n\ntest_input = { \"n\": 5, \"maxDistance\": 10, \"roads\": [[4,0,38],[4,0,11],[2,0,24],[3,0,5],[2,1,18],[2,0,38],[1,0,7],[2,1,3],[2,1,2],[3,1,36]] }\nassert my_solution.numberOfSets(**test_input) == 10\n\ntest_input = { \"n\": 5, \"maxDistance\": 16, \"roads\": [[2,0,32],[4,0,17],[2,0,22],[3,1,38],[3,0,13],[3,1,34],[3,1,36],[1,0,36],[3,1,18],[3,2,10]] }\nassert my_solution.numberOfSets(**test_input) == 8\n\ntest_input = { \"n\": 2, \"maxDistance\": 4, \"roads\": [[1,0,18]] }\nassert my_solution.numberOfSets(**test_input) == 3\n\ntest_input = { \"n\": 5, \"maxDistance\": 13, \"roads\": [[3,0,5],[2,1,3],[1,0,6],[3,2,19],[2,1,29],[2,1,30],[1,0,5],[2,0,29],[4,3,15],[2,1,23]] }\nassert my_solution.numberOfSets(**test_input) == 12\n\ntest_input = { \"n\": 3, \"maxDistance\": 23, \"roads\": [[2,1,12],[1,0,8],[2,1,7]] }\nassert my_solution.numberOfSets(**test_input) == 7\n\ntest_input = { \"n\": 5, \"maxDistance\": 38, \"roads\": [[2,0,8],[2,1,10],[0,3,25],[0,4,48]] }\nassert my_solution.numberOfSets(**test_input) == 11\n\ntest_input = { \"n\": 2, \"maxDistance\": 4, \"roads\": [[1,0,2]] }\nassert my_solution.numberOfSets(**test_input) == 4\n\ntest_input = { \"n\": 4, \"maxDistance\": 12, \"roads\": [[2,1,18],[0,1,25],[0,2,24],[0,3,16]] }\nassert my_solution.numberOfSets(**test_input) == 5\n\ntest_input = { \"n\": 4, \"maxDistance\": 1, \"roads\": [[2,0,1],[3,2,2],[2,0,2],[2,0,1],[1,0,1],[1,0,1]] }\nassert my_solution.numberOfSets(**test_input) == 7\n\ntest_input = { \"n\": 3, \"maxDistance\": 1, \"roads\": [[1,0,1],[0,2,1]] }\nassert my_solution.numberOfSets(**test_input) == 6\n\ntest_input = { \"n\": 2, \"maxDistance\": 3, \"roads\": [[1,0,24]] }\nassert my_solution.numberOfSets(**test_input) == 3\n\ntest_input = { \"n\": 2, \"maxDistance\": 10, \"roads\": [[1,0,13]] }\nassert my_solution.numberOfSets(**test_input) == 3\n\ntest_input = { \"n\": 3, \"maxDistance\": 1, \"roads\": [[2,1,1],[0,1,1],[0,2,1]] }\nassert my_solution.numberOfSets(**test_input) == 8\n\ntest_input = { \"n\": 5, \"maxDistance\": 13, \"roads\": [[1,0,17],[1,0,21],[3,0,9],[1,0,10],[2,0,11],[4,1,12],[2,1,11],[1,0,18]] }\nassert my_solution.numberOfSets(**test_input) == 12\n\ntest_input = { \"n\": 2, \"maxDistance\": 19, \"roads\": [[1,0,28]] }\nassert my_solution.numberOfSets(**test_input) == 3\n\ntest_input = { \"n\": 3, \"maxDistance\": 8, \"roads\": [[2,0,7],[2,0,28],[0,1,34]] }\nassert my_solution.numberOfSets(**test_input) == 5\n\ntest_input = { \"n\": 5, \"maxDistance\": 7, \"roads\": [[1,0,32],[0,2,35],[0,3,20],[0,4,27]] }\nassert my_solution.numberOfSets(**test_input) == 6\n\ntest_input = { \"n\": 4, \"maxDistance\": 1, \"roads\": [[1,0,4],[1,0,3],[3,0,4],[1,0,7],[0,2,11]] }\nassert my_solution.numberOfSets(**test_input) == 5\n\ntest_input = { \"n\": 2, \"maxDistance\": 34, \"roads\": [[1,0,11]] }\nassert my_solution.numberOfSets(**test_input) == 4\n\ntest_input = { \"n\": 5, \"maxDistance\": 10, \"roads\": [[2,1,32],[4,3,14],[3,2,3],[2,1,21],[3,1,37],[2,1,30],[0,1,18],[0,2,26],[0,3,19],[0,4,23]] }\nassert my_solution.numberOfSets(**test_input) == 7\n\ntest_input = { \"n\": 5, \"maxDistance\": 14, \"roads\": [[2,0,19],[3,1,24],[4,3,10],[4,1,15],[0,1,21],[0,3,21],[0,4,12]] }\nassert my_solution.numberOfSets(**test_input) == 8\n\ntest_input = { \"n\": 4, \"maxDistance\": 30, \"roads\": [[2,0,5],[0,1,27],[0,3,24]] }\nassert my_solution.numberOfSets(**test_input) == 9\n\ntest_input = { \"n\": 2, \"maxDistance\": 6, \"roads\": [[1,0,23]] }\nassert my_solution.numberOfSets(**test_input) == 3\n\ntest_input = { \"n\": 5, \"maxDistance\": 6, \"roads\": [[4,0,17],[2,1,7],[4,1,23],[1,0,1],[1,0,19],[0,3,20]] }\nassert my_solution.numberOfSets(**test_input) == 7\n\ntest_input = { \"n\": 3, \"maxDistance\": 5, \"roads\": [[1,0,1],[1,0,3],[2,0,4]] }\nassert my_solution.numberOfSets(**test_input) == 7\n\ntest_input = { \"n\": 4, \"maxDistance\": 19, \"roads\": [[3,2,21],[2,1,3],[0,1,15],[0,2,22],[0,3,8]] }\nassert my_solution.numberOfSets(**test_input) == 9\n\ntest_input = { \"n\": 2, \"maxDistance\": 5, \"roads\": [[1,0,4]] }\nassert my_solution.numberOfSets(**test_input) == 4\n\ntest_input = { \"n\": 4, \"maxDistance\": 18, \"roads\": [[2,1,7],[2,0,5],[0,3,10]] }\nassert my_solution.numberOfSets(**test_input) == 10\n\ntest_input = { \"n\": 5, \"maxDistance\": 35, \"roads\": [[1,0,39],[1,0,3],[3,1,45],[2,0,21],[3,2,40],[3,0,27],[2,1,44],[4,2,6],[4,2,45],[3,0,22]] }\nassert my_solution.numberOfSets(**test_input) == 14\n\ntest_input = { \"n\": 4, \"maxDistance\": 2, \"roads\": [[1,0,2],[1,0,3],[1,0,15],[1,0,7],[0,2,4],[0,3,6]] }\nassert my_solution.numberOfSets(**test_input) == 6\n\ntest_input = { \"n\": 4, \"maxDistance\": 5, \"roads\": [[2,0,1],[1,0,3],[0,3,4]] }\nassert my_solution.numberOfSets(**test_input) == 10\n\ntest_input = { \"n\": 3, \"maxDistance\": 19, \"roads\": [[1,0,9],[0,2,4]] }\nassert my_solution.numberOfSets(**test_input) == 7\n\ntest_input = { \"n\": 4, \"maxDistance\": 1, \"roads\": [[3,0,4],[2,1,4],[1,0,4]] }\nassert my_solution.numberOfSets(**test_input) == 5\n\ntest_input = { \"n\": 2, \"maxDistance\": 29, \"roads\": [[1,0,18]] }\nassert my_solution.numberOfSets(**test_input) == 4\n\ntest_input = { \"n\": 2, \"maxDistance\": 11, \"roads\": [[1,0,28]] }\nassert my_solution.numberOfSets(**test_input) == 3\n\ntest_input = { \"n\": 2, \"maxDistance\": 12, \"roads\": [[1,0,10]] }\nassert my_solution.numberOfSets(**test_input) == 4\n\ntest_input = { \"n\": 5, \"maxDistance\": 9, \"roads\": [[3,2,23],[4,3,11],[1,0,16],[2,0,11],[2,0,16],[1,0,20],[4,0,16],[2,0,36],[3,0,7]] }\nassert my_solution.numberOfSets(**test_input) == 7\n\ntest_input = { \"n\": 5, \"maxDistance\": 17, \"roads\": [[3,2,22],[3,2,3],[4,0,19],[3,0,21],[4,3,4],[1,0,24],[3,0,7],[3,2,12],[1,0,17]] }\nassert my_solution.numberOfSets(**test_input) == 14\n\ntest_input = { \"n\": 4, \"maxDistance\": 5, \"roads\": [[2,0,26],[1,0,15],[3,2,17]] }\nassert my_solution.numberOfSets(**test_input) == 5\n\ntest_input = { \"n\": 4, \"maxDistance\": 4, \"roads\": [[1,0,11],[0,2,3],[0,3,3]] }\nassert my_solution.numberOfSets(**test_input) == 7\n\ntest_input = { \"n\": 5, \"maxDistance\": 13, \"roads\": [[3,1,16],[0,1,3],[0,2,19],[0,3,10],[0,4,2]] }\nassert my_solution.numberOfSets(**test_input) == 13\n\ntest_input = { \"n\": 4, \"maxDistance\": 5, \"roads\": [[1,0,21],[1,0,13],[1,0,19],[2,1,15],[1,0,17],[1,0,3],[0,3,1]] }\nassert my_solution.numberOfSets(**test_input) == 8\n\ntest_input = { \"n\": 5, \"maxDistance\": 25, \"roads\": [[1,0,18],[3,0,20],[2,0,17],[2,1,21],[0,4,3]] }\nassert my_solution.numberOfSets(**test_input) == 16\n\ntest_input = { \"n\": 5, \"maxDistance\": 15, \"roads\": [[2,1,33],[1,0,18],[2,0,16],[3,1,37],[3,0,26],[0,4,18]] }\nassert my_solution.numberOfSets(**test_input) == 6\n\ntest_input = { \"n\": 4, \"maxDistance\": 1, \"roads\": [[1,0,1],[1,0,1],[0,2,1],[0,3,1]] }\nassert my_solution.numberOfSets(**test_input) == 8\n\ntest_input = { \"n\": 4, \"maxDistance\": 10, \"roads\": [[2,0,22],[2,1,6],[2,0,21],[2,1,27],[3,1,12]] }\nassert my_solution.numberOfSets(**test_input) == 6\n\ntest_input = { \"n\": 2, \"maxDistance\": 13, \"roads\": [[1,0,21]] }\nassert my_solution.numberOfSets(**test_input) == 3\n\ntest_input = { \"n\": 4, \"maxDistance\": 31, \"roads\": [[3,1,7],[2,1,10],[2,0,25],[2,0,27]] }\nassert my_solution.numberOfSets(**test_input) == 9\n\ntest_input = { \"n\": 3, \"maxDistance\": 17, \"roads\": [[1,0,8],[1,0,8],[0,2,14]] }\nassert my_solution.numberOfSets(**test_input) == 6\n\ntest_input = { \"n\": 2, \"maxDistance\": 3, \"roads\": [[1,0,3]] }\nassert my_solution.numberOfSets(**test_input) == 4\n\ntest_input = { \"n\": 5, \"maxDistance\": 5, \"roads\": [[4,1,37],[4,1,7],[2,1,6],[3,2,8],[2,1,35],[1,0,28],[4,1,3],[2,1,2]] }\nassert my_solution.numberOfSets(**test_input) == 9\n\ntest_input = { \"n\": 4, \"maxDistance\": 1, \"roads\": [[2,0,2],[2,0,1],[0,1,2],[0,3,2]] }\nassert my_solution.numberOfSets(**test_input) == 6", "start_time": 1702132200} +{"task_id": "weekly-contest-374-find-the-peaks", "url": "https://leetcode.com/problems/find-the-peaks", "title": "find-the-peaks", "meta": {"questionId": "3221", "questionFrontendId": "2951", "title": "Find the Peaks", "titleSlug": "find-the-peaks", "isPaidOnly": false, "difficulty": "Easy", "likes": 91, "dislikes": 9, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed array mountain. Your task is to find all the peaks in the mountain array.\nReturn an array that consists of indices of peaks in the given array in any order.\nNotes:\n\nA peak is defined as an element that is strictly greater than its neighboring elements.\nThe first and last elements of the array are not a peak.\n\n\nExample 1:\n\nInput: mountain = [2,4,4]\nOutput: []\nExplanation: mountain[0] and mountain[2] can not be a peak because they are first and last elements of the array.\nmountain[1] also can not be a peak because it is not strictly greater than mountain[2].\nSo the answer is [].\n\nExample 2:\n\nInput: mountain = [1,4,3,8,5]\nOutput: [1,3]\nExplanation: mountain[0] and mountain[4] can not be a peak because they are first and last elements of the array.\nmountain[2] also can not be a peak because it is not strictly greater than mountain[3] and mountain[1].\nBut mountain [1] and mountain[3] are strictly greater than their neighboring elements.\nSo the answer is [1,3].\n\n\nConstraints:\n\n3 <= mountain.length <= 100\n1 <= mountain[i] <= 100\n\"\"\"\nclass Solution:\n def findPeaks(self, mountain: List[int]) -> List[int]:\n ", "prompt_sft": "You are given a 0-indexed array mountain. Your task is to find all the peaks in the mountain array.\nReturn an array that consists of indices of peaks in the given array in any order.\nNotes:\n\nA peak is defined as an element that is strictly greater than its neighboring elements.\nThe first and last elements of the array are not a peak.\n\n\nExample 1:\n\nInput: mountain = [2,4,4]\nOutput: []\nExplanation: mountain[0] and mountain[2] can not be a peak because they are first and last elements of the array.\nmountain[1] also can not be a peak because it is not strictly greater than mountain[2].\nSo the answer is [].\n\nExample 2:\n\nInput: mountain = [1,4,3,8,5]\nOutput: [1,3]\nExplanation: mountain[0] and mountain[4] can not be a peak because they are first and last elements of the array.\nmountain[2] also can not be a peak because it is not strictly greater than mountain[3] and mountain[1].\nBut mountain [1] and mountain[3] are strictly greater than their neighboring elements.\nSo the answer is [1,3].\n\n\nConstraints:\n\n3 <= mountain.length <= 100\n1 <= mountain[i] <= 100\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def findPeaks(self, mountain: List[int]) -> List[int]:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"mountain\": [2,4,4] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [1,4,3,8,5] }\nassert my_solution.findPeaks(**test_input) == [1,3]\n\ntest_input = { \"mountain\": [1,1,1] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [1,1,3] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [1,1,5] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [1,2,5] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [1,4,1] }\nassert my_solution.findPeaks(**test_input) == [1]\n\ntest_input = { \"mountain\": [1,4,3] }\nassert my_solution.findPeaks(**test_input) == [1]\n\ntest_input = { \"mountain\": [1,5,5] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [1,6,4] }\nassert my_solution.findPeaks(**test_input) == [1]\n\ntest_input = { \"mountain\": [2,1,1] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [2,1,2] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [2,2,3] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [2,2,5] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [2,3,2] }\nassert my_solution.findPeaks(**test_input) == [1]\n\ntest_input = { \"mountain\": [2,3,6] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [2,4,3] }\nassert my_solution.findPeaks(**test_input) == [1]\n\ntest_input = { \"mountain\": [2,4,5] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [2,6,4] }\nassert my_solution.findPeaks(**test_input) == [1]\n\ntest_input = { \"mountain\": [3,3,3] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [3,3,5] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [3,4,6] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [3,5,1] }\nassert my_solution.findPeaks(**test_input) == [1]\n\ntest_input = { \"mountain\": [3,5,3] }\nassert my_solution.findPeaks(**test_input) == [1]\n\ntest_input = { \"mountain\": [3,5,4] }\nassert my_solution.findPeaks(**test_input) == [1]\n\ntest_input = { \"mountain\": [3,5,6] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [4,2,1] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [4,2,2] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [4,2,4] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [4,2,6] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [4,4,1] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [4,4,2] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [4,4,5] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [4,5,4] }\nassert my_solution.findPeaks(**test_input) == [1]\n\ntest_input = { \"mountain\": [4,6,1] }\nassert my_solution.findPeaks(**test_input) == [1]\n\ntest_input = { \"mountain\": [4,6,6] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [5,1,2] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [5,2,1] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [5,2,2] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [5,2,4] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [5,3,1] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [5,5,1] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [5,5,2] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [5,5,6] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [5,6,1] }\nassert my_solution.findPeaks(**test_input) == [1]\n\ntest_input = { \"mountain\": [5,6,4] }\nassert my_solution.findPeaks(**test_input) == [1]\n\ntest_input = { \"mountain\": [6,1,1] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [6,1,2] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [6,1,5] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [6,2,2] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [6,2,5] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [6,3,2] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [6,3,3] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [6,3,6] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [6,4,3] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [6,5,2] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [6,5,4] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [6,6,4] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [1,1,1,4] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [1,1,7,7] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [1,3,6,5] }\nassert my_solution.findPeaks(**test_input) == [2]\n\ntest_input = { \"mountain\": [1,4,7,8] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [1,6,6,6] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [1,8,1,8] }\nassert my_solution.findPeaks(**test_input) == [1]\n\ntest_input = { \"mountain\": [2,2,1,2] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [2,3,7,6] }\nassert my_solution.findPeaks(**test_input) == [2]\n\ntest_input = { \"mountain\": [2,5,4,5] }\nassert my_solution.findPeaks(**test_input) == [1]\n\ntest_input = { \"mountain\": [2,7,1,2] }\nassert my_solution.findPeaks(**test_input) == [1]\n\ntest_input = { \"mountain\": [2,7,2,6] }\nassert my_solution.findPeaks(**test_input) == [1]\n\ntest_input = { \"mountain\": [2,7,5,3] }\nassert my_solution.findPeaks(**test_input) == [1]\n\ntest_input = { \"mountain\": [2,7,7,6] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [3,1,2,5] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [3,3,4,2] }\nassert my_solution.findPeaks(**test_input) == [2]\n\ntest_input = { \"mountain\": [3,3,7,8] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [3,4,2,4] }\nassert my_solution.findPeaks(**test_input) == [1]\n\ntest_input = { \"mountain\": [3,4,5,4] }\nassert my_solution.findPeaks(**test_input) == [2]\n\ntest_input = { \"mountain\": [3,4,7,6] }\nassert my_solution.findPeaks(**test_input) == [2]\n\ntest_input = { \"mountain\": [3,5,5,3] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [3,6,4,7] }\nassert my_solution.findPeaks(**test_input) == [1]\n\ntest_input = { \"mountain\": [3,8,5,5] }\nassert my_solution.findPeaks(**test_input) == [1]\n\ntest_input = { \"mountain\": [4,2,4,3] }\nassert my_solution.findPeaks(**test_input) == [2]\n\ntest_input = { \"mountain\": [4,2,6,8] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [4,3,3,8] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [4,4,8,7] }\nassert my_solution.findPeaks(**test_input) == [2]\n\ntest_input = { \"mountain\": [4,5,1,1] }\nassert my_solution.findPeaks(**test_input) == [1]\n\ntest_input = { \"mountain\": [4,6,1,7] }\nassert my_solution.findPeaks(**test_input) == [1]\n\ntest_input = { \"mountain\": [4,6,2,1] }\nassert my_solution.findPeaks(**test_input) == [1]\n\ntest_input = { \"mountain\": [4,6,2,2] }\nassert my_solution.findPeaks(**test_input) == [1]\n\ntest_input = { \"mountain\": [5,1,7,6] }\nassert my_solution.findPeaks(**test_input) == [2]\n\ntest_input = { \"mountain\": [5,3,2,2] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [5,3,6,3] }\nassert my_solution.findPeaks(**test_input) == [2]\n\ntest_input = { \"mountain\": [5,3,8,3] }\nassert my_solution.findPeaks(**test_input) == [2]\n\ntest_input = { \"mountain\": [5,4,4,6] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [5,4,4,8] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [5,5,1,7] }\nassert my_solution.findPeaks(**test_input) == []\n\ntest_input = { \"mountain\": [5,5,8,2] }\nassert my_solution.findPeaks(**test_input) == [2]\n\ntest_input = { \"mountain\": [5,6,7,4] }\nassert my_solution.findPeaks(**test_input) == [2]\n\ntest_input = { \"mountain\": [5,7,4,3] }\nassert my_solution.findPeaks(**test_input) == [1]\n\ntest_input = { \"mountain\": [5,8,7,8] }\nassert my_solution.findPeaks(**test_input) == [1]\n\ntest_input = { \"mountain\": [6,2,8,6] }\nassert my_solution.findPeaks(**test_input) == [2]", "start_time": 1701570600} +{"task_id": "weekly-contest-374-minimum-number-of-coins-to-be-added", "url": "https://leetcode.com/problems/minimum-number-of-coins-to-be-added", "title": "minimum-number-of-coins-to-be-added", "meta": {"questionId": "3231", "questionFrontendId": "2952", "title": "Minimum Number of Coins to be Added", "titleSlug": "minimum-number-of-coins-to-be-added", "isPaidOnly": false, "difficulty": "Medium", "likes": 227, "dislikes": 40, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed integer array coins, representing the values of the coins available, and an integer target.\nAn integer x is obtainable if there exists a subsequence of coins that sums to x.\nReturn the minimum number of coins of any value that need to be added to the array so that every integer in the range [1, target] is obtainable.\nA subsequence of an array is a new non-empty array that is formed from the original array by deleting some (possibly none) of the elements without disturbing the relative positions of the remaining elements.\n\nExample 1:\n\nInput: coins = [1,4,10], target = 19\nOutput: 2\nExplanation: We need to add coins 2 and 8. The resulting array will be [1,2,4,8,10].\nIt can be shown that all integers from 1 to 19 are obtainable from the resulting array, and that 2 is the minimum number of coins that need to be added to the array. \n\nExample 2:\n\nInput: coins = [1,4,10,5,7,19], target = 19\nOutput: 1\nExplanation: We only need to add the coin 2. The resulting array will be [1,2,4,5,7,10,19].\nIt can be shown that all integers from 1 to 19 are obtainable from the resulting array, and that 1 is the minimum number of coins that need to be added to the array. \n\nExample 3:\n\nInput: coins = [1,1,1], target = 20\nOutput: 3\nExplanation: We need to add coins 4, 8, and 16. The resulting array will be [1,1,1,4,8,16].\nIt can be shown that all integers from 1 to 20 are obtainable from the resulting array, and that 3 is the minimum number of coins that need to be added to the array.\n\n\nConstraints:\n\n1 <= target <= 105\n1 <= coins.length <= 105\n1 <= coins[i] <= target\n\"\"\"\nclass Solution:\n def minimumAddedCoins(self, coins: List[int], target: int) -> int:\n ", "prompt_sft": "You are given a 0-indexed integer array coins, representing the values of the coins available, and an integer target.\nAn integer x is obtainable if there exists a subsequence of coins that sums to x.\nReturn the minimum number of coins of any value that need to be added to the array so that every integer in the range [1, target] is obtainable.\nA subsequence of an array is a new non-empty array that is formed from the original array by deleting some (possibly none) of the elements without disturbing the relative positions of the remaining elements.\n\nExample 1:\n\nInput: coins = [1,4,10], target = 19\nOutput: 2\nExplanation: We need to add coins 2 and 8. The resulting array will be [1,2,4,8,10].\nIt can be shown that all integers from 1 to 19 are obtainable from the resulting array, and that 2 is the minimum number of coins that need to be added to the array. \n\nExample 2:\n\nInput: coins = [1,4,10,5,7,19], target = 19\nOutput: 1\nExplanation: We only need to add the coin 2. The resulting array will be [1,2,4,5,7,10,19].\nIt can be shown that all integers from 1 to 19 are obtainable from the resulting array, and that 1 is the minimum number of coins that need to be added to the array. \n\nExample 3:\n\nInput: coins = [1,1,1], target = 20\nOutput: 3\nExplanation: We need to add coins 4, 8, and 16. The resulting array will be [1,1,1,4,8,16].\nIt can be shown that all integers from 1 to 20 are obtainable from the resulting array, and that 3 is the minimum number of coins that need to be added to the array.\n\n\nConstraints:\n\n1 <= target <= 105\n1 <= coins.length <= 105\n1 <= coins[i] <= target\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def minimumAddedCoins(self, coins: List[int], target: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"coins\": [1,4,10], \"target\": 19 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [1,4,10,5,7,19], \"target\": 19 }\nassert my_solution.minimumAddedCoins(**test_input) == 1\n\ntest_input = { \"coins\": [1,1,1], \"target\": 20 }\nassert my_solution.minimumAddedCoins(**test_input) == 3\n\ntest_input = { \"coins\": [1], \"target\": 100000 }\nassert my_solution.minimumAddedCoins(**test_input) == 16\n\ntest_input = { \"coins\": [100000], \"target\": 100000 }\nassert my_solution.minimumAddedCoins(**test_input) == 17\n\ntest_input = { \"coins\": [2], \"target\": 5 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [5,6,7], \"target\": 10 }\nassert my_solution.minimumAddedCoins(**test_input) == 3\n\ntest_input = { \"coins\": [5,6,7], \"target\": 15 }\nassert my_solution.minimumAddedCoins(**test_input) == 3\n\ntest_input = { \"coins\": [4,11,13,15,7,5,12,11,5,9], \"target\": 34 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [8,12,9], \"target\": 27 }\nassert my_solution.minimumAddedCoins(**test_input) == 3\n\ntest_input = { \"coins\": [2,13,7,1,11], \"target\": 35 }\nassert my_solution.minimumAddedCoins(**test_input) == 1\n\ntest_input = { \"coins\": [10,3,5,11,6], \"target\": 27 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [6,6,6,15,4], \"target\": 31 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [6,15,6], \"target\": 22 }\nassert my_solution.minimumAddedCoins(**test_input) == 3\n\ntest_input = { \"coins\": [8,14,15,4,14,15,8,10,8], \"target\": 42 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [9,14,14,9,14,5,12,10,11], \"target\": 17 }\nassert my_solution.minimumAddedCoins(**test_input) == 3\n\ntest_input = { \"coins\": [14,5,13,3,7,10,10,10], \"target\": 32 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [8,6,7,12], \"target\": 26 }\nassert my_solution.minimumAddedCoins(**test_input) == 3\n\ntest_input = { \"coins\": [15,1,12], \"target\": 43 }\nassert my_solution.minimumAddedCoins(**test_input) == 4\n\ntest_input = { \"coins\": [4,1,4,10], \"target\": 16 }\nassert my_solution.minimumAddedCoins(**test_input) == 1\n\ntest_input = { \"coins\": [10,2,13,5,7,15], \"target\": 26 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [10,1,10], \"target\": 10 }\nassert my_solution.minimumAddedCoins(**test_input) == 3\n\ntest_input = { \"coins\": [9,5,13,8], \"target\": 30 }\nassert my_solution.minimumAddedCoins(**test_input) == 3\n\ntest_input = { \"coins\": [13,9,4,5], \"target\": 37 }\nassert my_solution.minimumAddedCoins(**test_input) == 3\n\ntest_input = { \"coins\": [1,15,5,12,13,10,14,8,1,7], \"target\": 29 }\nassert my_solution.minimumAddedCoins(**test_input) == 1\n\ntest_input = { \"coins\": [14,14,6,2,9,1,4,10], \"target\": 38 }\nassert my_solution.minimumAddedCoins(**test_input) == 0\n\ntest_input = { \"coins\": [7,10,6,14,10,11,2], \"target\": 45 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [6,3,2,6,8,9,13,3,12,13], \"target\": 47 }\nassert my_solution.minimumAddedCoins(**test_input) == 1\n\ntest_input = { \"coins\": [8,1,9,2,15], \"target\": 34 }\nassert my_solution.minimumAddedCoins(**test_input) == 1\n\ntest_input = { \"coins\": [5,13,9,11,6,1], \"target\": 27 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [10,15,7,14,2,2,12,14,13], \"target\": 45 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [9,3,10,3,8,2,7,11,1], \"target\": 26 }\nassert my_solution.minimumAddedCoins(**test_input) == 0\n\ntest_input = { \"coins\": [9,11,2,5,2,7,11], \"target\": 28 }\nassert my_solution.minimumAddedCoins(**test_input) == 1\n\ntest_input = { \"coins\": [5,5,15,3,13], \"target\": 17 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [2,2,9,10,7,15,4,3,9,15], \"target\": 16 }\nassert my_solution.minimumAddedCoins(**test_input) == 1\n\ntest_input = { \"coins\": [3,1,12,15,5,10], \"target\": 34 }\nassert my_solution.minimumAddedCoins(**test_input) == 1\n\ntest_input = { \"coins\": [12,7,5,2,12], \"target\": 50 }\nassert my_solution.minimumAddedCoins(**test_input) == 3\n\ntest_input = { \"coins\": [11,6,10,3,1,7,11], \"target\": 44 }\nassert my_solution.minimumAddedCoins(**test_input) == 1\n\ntest_input = { \"coins\": [13,12,1,11,3,4,11,9,13,13], \"target\": 41 }\nassert my_solution.minimumAddedCoins(**test_input) == 1\n\ntest_input = { \"coins\": [6,4,1,9,9,2,10,7], \"target\": 48 }\nassert my_solution.minimumAddedCoins(**test_input) == 0\n\ntest_input = { \"coins\": [10,4,4,3,9,6,8,4,7,7], \"target\": 22 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [15,9,5,7,4,13], \"target\": 19 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [13,11,8,6,11], \"target\": 16 }\nassert my_solution.minimumAddedCoins(**test_input) == 3\n\ntest_input = { \"coins\": [8,14,15,9,8,10,13,7,3], \"target\": 42 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [6,14,7,4,10,9,10,9,7], \"target\": 22 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [4,6,7,15,13,14,5,7], \"target\": 16 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [10,12,5], \"target\": 32 }\nassert my_solution.minimumAddedCoins(**test_input) == 3\n\ntest_input = { \"coins\": [8,5,14,13,13,11,14,13], \"target\": 43 }\nassert my_solution.minimumAddedCoins(**test_input) == 3\n\ntest_input = { \"coins\": [3,14,4,2,10,3,7], \"target\": 50 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [1,3,11,9,2,10,6,12], \"target\": 12 }\nassert my_solution.minimumAddedCoins(**test_input) == 0\n\ntest_input = { \"coins\": [2,5,4,12,6,7,11,15], \"target\": 17 }\nassert my_solution.minimumAddedCoins(**test_input) == 1\n\ntest_input = { \"coins\": [7,12,10,15,6,15,14,2,9,12], \"target\": 24 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [4,7,15,10,14], \"target\": 38 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [10,1,12,9], \"target\": 16 }\nassert my_solution.minimumAddedCoins(**test_input) == 3\n\ntest_input = { \"coins\": [5,8,12,6,15,13,11,5], \"target\": 35 }\nassert my_solution.minimumAddedCoins(**test_input) == 3\n\ntest_input = { \"coins\": [6,2,6], \"target\": 39 }\nassert my_solution.minimumAddedCoins(**test_input) == 3\n\ntest_input = { \"coins\": [15,10,5,4,7,12,12,5,11], \"target\": 30 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [9,10,7,12,10,4], \"target\": 35 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [4,4,2], \"target\": 8 }\nassert my_solution.minimumAddedCoins(**test_input) == 1\n\ntest_input = { \"coins\": [13,4,15,1,8], \"target\": 25 }\nassert my_solution.minimumAddedCoins(**test_input) == 1\n\ntest_input = { \"coins\": [14,7,7,1,6,14,3,15,13], \"target\": 18 }\nassert my_solution.minimumAddedCoins(**test_input) == 1\n\ntest_input = { \"coins\": [8,2,14,2,3,10,15,5], \"target\": 31 }\nassert my_solution.minimumAddedCoins(**test_input) == 1\n\ntest_input = { \"coins\": [3,7,12,10,11,5,3], \"target\": 36 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [5,3,14,8,10], \"target\": 33 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [9,14,9,14,4,1,4,12,12], \"target\": 41 }\nassert my_solution.minimumAddedCoins(**test_input) == 1\n\ntest_input = { \"coins\": [6,3,9,7,3,4,4,15,15,10], \"target\": 47 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [4,9,6], \"target\": 43 }\nassert my_solution.minimumAddedCoins(**test_input) == 3\n\ntest_input = { \"coins\": [12,9,13,12,10,4,9,9,4], \"target\": 28 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [6,8,2,13,1,5,6], \"target\": 31 }\nassert my_solution.minimumAddedCoins(**test_input) == 1\n\ntest_input = { \"coins\": [9,8,9,9,3,5,10,15,1], \"target\": 45 }\nassert my_solution.minimumAddedCoins(**test_input) == 1\n\ntest_input = { \"coins\": [1,10,15,15], \"target\": 24 }\nassert my_solution.minimumAddedCoins(**test_input) == 3\n\ntest_input = { \"coins\": [9,12,2], \"target\": 43 }\nassert my_solution.minimumAddedCoins(**test_input) == 4\n\ntest_input = { \"coins\": [14,13,10,2,2], \"target\": 16 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [11,5,5,13,4,13,10,3,4], \"target\": 21 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [8,9,1,5,8,7,6,8,6], \"target\": 47 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [4,10,9], \"target\": 18 }\nassert my_solution.minimumAddedCoins(**test_input) == 3\n\ntest_input = { \"coins\": [7,9,7,6,8,11], \"target\": 50 }\nassert my_solution.minimumAddedCoins(**test_input) == 3\n\ntest_input = { \"coins\": [11,6,6,14,12,2], \"target\": 46 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [8,9,2], \"target\": 31 }\nassert my_solution.minimumAddedCoins(**test_input) == 3\n\ntest_input = { \"coins\": [12,1,4,3,5,3], \"target\": 18 }\nassert my_solution.minimumAddedCoins(**test_input) == 1\n\ntest_input = { \"coins\": [4,3,13], \"target\": 34 }\nassert my_solution.minimumAddedCoins(**test_input) == 3\n\ntest_input = { \"coins\": [9,11,3], \"target\": 22 }\nassert my_solution.minimumAddedCoins(**test_input) == 3\n\ntest_input = { \"coins\": [1,11,15,1,10,13,7,6,12], \"target\": 28 }\nassert my_solution.minimumAddedCoins(**test_input) == 1\n\ntest_input = { \"coins\": [1,10,8,7,12], \"target\": 19 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [1,5,15,13,8,4,5,7], \"target\": 29 }\nassert my_solution.minimumAddedCoins(**test_input) == 1\n\ntest_input = { \"coins\": [3,8,13,8,5,3,7,2,9,8], \"target\": 50 }\nassert my_solution.minimumAddedCoins(**test_input) == 1\n\ntest_input = { \"coins\": [4,13,12], \"target\": 47 }\nassert my_solution.minimumAddedCoins(**test_input) == 4\n\ntest_input = { \"coins\": [9,3,10,9,11], \"target\": 48 }\nassert my_solution.minimumAddedCoins(**test_input) == 3\n\ntest_input = { \"coins\": [8,7,6,1,9,5,5], \"target\": 13 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [11,9,1,15], \"target\": 16 }\nassert my_solution.minimumAddedCoins(**test_input) == 3\n\ntest_input = { \"coins\": [8,13,8], \"target\": 27 }\nassert my_solution.minimumAddedCoins(**test_input) == 3\n\ntest_input = { \"coins\": [7,10,11,3,10,14], \"target\": 36 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [14,9,6,11,13,8,8,5,6], \"target\": 22 }\nassert my_solution.minimumAddedCoins(**test_input) == 3\n\ntest_input = { \"coins\": [9,3,6,10,11,1,5,14,3], \"target\": 27 }\nassert my_solution.minimumAddedCoins(**test_input) == 1\n\ntest_input = { \"coins\": [4,5,9,6,2,2,10,5,13], \"target\": 43 }\nassert my_solution.minimumAddedCoins(**test_input) == 1\n\ntest_input = { \"coins\": [3,10,2,13,6,13,14,14,3], \"target\": 28 }\nassert my_solution.minimumAddedCoins(**test_input) == 1\n\ntest_input = { \"coins\": [14,15,15,12,13,4,15], \"target\": 38 }\nassert my_solution.minimumAddedCoins(**test_input) == 3\n\ntest_input = { \"coins\": [10,5,12,11,9,8,1], \"target\": 12 }\nassert my_solution.minimumAddedCoins(**test_input) == 2\n\ntest_input = { \"coins\": [15,13,12,4], \"target\": 31 }\nassert my_solution.minimumAddedCoins(**test_input) == 3\n\ntest_input = { \"coins\": [4,5,14,13,10,12], \"target\": 31 }\nassert my_solution.minimumAddedCoins(**test_input) == 2", "start_time": 1701570600} +{"task_id": "weekly-contest-374-count-complete-substrings", "url": "https://leetcode.com/problems/count-complete-substrings", "title": "count-complete-substrings", "meta": {"questionId": "3223", "questionFrontendId": "2953", "title": "Count Complete Substrings", "titleSlug": "count-complete-substrings", "isPaidOnly": false, "difficulty": "Hard", "likes": 154, "dislikes": 30, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a string word and an integer k.\nA substring s of word is complete if:\n\nEach character in s occurs exactly k times.\nThe difference between two adjacent characters is at most 2. That is, for any two adjacent characters c1 and c2 in s, the absolute difference in their positions in the alphabet is at most 2.\n\nReturn the number of complete substrings of word.\nA substring is a non-empty contiguous sequence of characters in a string.\n\nExample 1:\n\nInput: word = \"igigee\", k = 2\nOutput: 3\nExplanation: The complete substrings where each character appears exactly twice and the difference between adjacent characters is at most 2 are: igigee, igigee, igigee.\n\nExample 2:\n\nInput: word = \"aaabbbccc\", k = 3\nOutput: 6\nExplanation: The complete substrings where each character appears exactly three times and the difference between adjacent characters is at most 2 are: aaabbbccc, aaabbbccc, aaabbbccc, aaabbbccc, aaabbbccc, aaabbbccc.\n\n\nConstraints:\n\n1 <= word.length <= 105\nword consists only of lowercase English letters.\n1 <= k <= word.length\n\"\"\"\nclass Solution:\n def countCompleteSubstrings(self, word: str, k: int) -> int:\n ", "prompt_sft": "You are given a string word and an integer k.\nA substring s of word is complete if:\n\nEach character in s occurs exactly k times.\nThe difference between two adjacent characters is at most 2. That is, for any two adjacent characters c1 and c2 in s, the absolute difference in their positions in the alphabet is at most 2.\n\nReturn the number of complete substrings of word.\nA substring is a non-empty contiguous sequence of characters in a string.\n\nExample 1:\n\nInput: word = \"igigee\", k = 2\nOutput: 3\nExplanation: The complete substrings where each character appears exactly twice and the difference between adjacent characters is at most 2 are: igigee, igigee, igigee.\n\nExample 2:\n\nInput: word = \"aaabbbccc\", k = 3\nOutput: 6\nExplanation: The complete substrings where each character appears exactly three times and the difference between adjacent characters is at most 2 are: aaabbbccc, aaabbbccc, aaabbbccc, aaabbbccc, aaabbbccc, aaabbbccc.\n\n\nConstraints:\n\n1 <= word.length <= 105\nword consists only of lowercase English letters.\n1 <= k <= word.length\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def countCompleteSubstrings(self, word: str, k: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"word\": \"igigee\", \"k\": 2 }\nassert my_solution.countCompleteSubstrings(**test_input) == 3\n\ntest_input = { \"word\": \"aaabbbccc\", \"k\": 3 }\nassert my_solution.countCompleteSubstrings(**test_input) == 6\n\ntest_input = { \"word\": \"a\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 1\n\ntest_input = { \"word\": \"b\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 1\n\ntest_input = { \"word\": \"c\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 1\n\ntest_input = { \"word\": \"aa\", \"k\": 2 }\nassert my_solution.countCompleteSubstrings(**test_input) == 1\n\ntest_input = { \"word\": \"ab\", \"k\": 2 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"ac\", \"k\": 2 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"ba\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 3\n\ntest_input = { \"word\": \"bb\", \"k\": 2 }\nassert my_solution.countCompleteSubstrings(**test_input) == 1\n\ntest_input = { \"word\": \"bc\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 3\n\ntest_input = { \"word\": \"ca\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 3\n\ntest_input = { \"word\": \"cb\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 3\n\ntest_input = { \"word\": \"cc\", \"k\": 2 }\nassert my_solution.countCompleteSubstrings(**test_input) == 1\n\ntest_input = { \"word\": \"aaa\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 3\n\ntest_input = { \"word\": \"aab\", \"k\": 3 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"aac\", \"k\": 2 }\nassert my_solution.countCompleteSubstrings(**test_input) == 1\n\ntest_input = { \"word\": \"aba\", \"k\": 3 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"abb\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 4\n\ntest_input = { \"word\": \"abc\", \"k\": 3 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"aca\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 5\n\ntest_input = { \"word\": \"acb\", \"k\": 2 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"acc\", \"k\": 3 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"baa\", \"k\": 2 }\nassert my_solution.countCompleteSubstrings(**test_input) == 1\n\ntest_input = { \"word\": \"bab\", \"k\": 3 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"bac\", \"k\": 2 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"bba\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 4\n\ntest_input = { \"word\": \"bbb\", \"k\": 2 }\nassert my_solution.countCompleteSubstrings(**test_input) == 2\n\ntest_input = { \"word\": \"bbc\", \"k\": 2 }\nassert my_solution.countCompleteSubstrings(**test_input) == 1\n\ntest_input = { \"word\": \"bca\", \"k\": 2 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"bcb\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 5\n\ntest_input = { \"word\": \"bcc\", \"k\": 2 }\nassert my_solution.countCompleteSubstrings(**test_input) == 1\n\ntest_input = { \"word\": \"caa\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 4\n\ntest_input = { \"word\": \"cab\", \"k\": 2 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"cac\", \"k\": 2 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"cba\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 6\n\ntest_input = { \"word\": \"cbb\", \"k\": 3 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"cbc\", \"k\": 2 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"cca\", \"k\": 2 }\nassert my_solution.countCompleteSubstrings(**test_input) == 1\n\ntest_input = { \"word\": \"ccb\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 4\n\ntest_input = { \"word\": \"ccc\", \"k\": 2 }\nassert my_solution.countCompleteSubstrings(**test_input) == 2\n\ntest_input = { \"word\": \"aaaa\", \"k\": 4 }\nassert my_solution.countCompleteSubstrings(**test_input) == 1\n\ntest_input = { \"word\": \"aaab\", \"k\": 4 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"aaac\", \"k\": 4 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"aaba\", \"k\": 3 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"aabb\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 5\n\ntest_input = { \"word\": \"aabc\", \"k\": 3 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"aaca\", \"k\": 3 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"aacb\", \"k\": 2 }\nassert my_solution.countCompleteSubstrings(**test_input) == 1\n\ntest_input = { \"word\": \"aacc\", \"k\": 4 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"abaa\", \"k\": 3 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"abab\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 7\n\ntest_input = { \"word\": \"abac\", \"k\": 4 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"abba\", \"k\": 3 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"abbb\", \"k\": 4 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"abbc\", \"k\": 2 }\nassert my_solution.countCompleteSubstrings(**test_input) == 1\n\ntest_input = { \"word\": \"abca\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 9\n\ntest_input = { \"word\": \"abcb\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 8\n\ntest_input = { \"word\": \"abcc\", \"k\": 4 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"acaa\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 6\n\ntest_input = { \"word\": \"acab\", \"k\": 2 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"acac\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 7\n\ntest_input = { \"word\": \"acba\", \"k\": 2 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"acbb\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 7\n\ntest_input = { \"word\": \"acbc\", \"k\": 2 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"acca\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 6\n\ntest_input = { \"word\": \"accb\", \"k\": 3 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"accc\", \"k\": 4 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"baaa\", \"k\": 2 }\nassert my_solution.countCompleteSubstrings(**test_input) == 2\n\ntest_input = { \"word\": \"baab\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 6\n\ntest_input = { \"word\": \"baac\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 6\n\ntest_input = { \"word\": \"baba\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 7\n\ntest_input = { \"word\": \"babb\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 6\n\ntest_input = { \"word\": \"babc\", \"k\": 3 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"baca\", \"k\": 4 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"bacb\", \"k\": 3 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"bacc\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 7\n\ntest_input = { \"word\": \"bbaa\", \"k\": 2 }\nassert my_solution.countCompleteSubstrings(**test_input) == 3\n\ntest_input = { \"word\": \"bbab\", \"k\": 3 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"bbac\", \"k\": 4 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"bbba\", \"k\": 4 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"bbbb\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 4\n\ntest_input = { \"word\": \"bbbc\", \"k\": 3 }\nassert my_solution.countCompleteSubstrings(**test_input) == 1\n\ntest_input = { \"word\": \"bbca\", \"k\": 4 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"bbcb\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 6\n\ntest_input = { \"word\": \"bbcc\", \"k\": 4 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"bcaa\", \"k\": 2 }\nassert my_solution.countCompleteSubstrings(**test_input) == 1\n\ntest_input = { \"word\": \"bcab\", \"k\": 3 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"bcac\", \"k\": 3 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"bcba\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 8\n\ntest_input = { \"word\": \"bcbb\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 6\n\ntest_input = { \"word\": \"bcbc\", \"k\": 2 }\nassert my_solution.countCompleteSubstrings(**test_input) == 1\n\ntest_input = { \"word\": \"bcca\", \"k\": 4 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"bccb\", \"k\": 3 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"bccc\", \"k\": 4 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"caaa\", \"k\": 3 }\nassert my_solution.countCompleteSubstrings(**test_input) == 1\n\ntest_input = { \"word\": \"caab\", \"k\": 1 }\nassert my_solution.countCompleteSubstrings(**test_input) == 6\n\ntest_input = { \"word\": \"caac\", \"k\": 4 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"caba\", \"k\": 4 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0\n\ntest_input = { \"word\": \"cabb\", \"k\": 3 }\nassert my_solution.countCompleteSubstrings(**test_input) == 0", "start_time": 1701570600} +{"task_id": "weekly-contest-374-count-the-number-of-infection-sequences", "url": "https://leetcode.com/problems/count-the-number-of-infection-sequences", "title": "count-the-number-of-infection-sequences", "meta": {"questionId": "3224", "questionFrontendId": "2954", "title": "Count the Number of Infection Sequences", "titleSlug": "count-the-number-of-infection-sequences", "isPaidOnly": false, "difficulty": "Hard", "likes": 50, "dislikes": 12, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given an integer n and a 0-indexed integer array sick which is sorted in increasing order.\nThere are n children standing in a queue with positions 0 to n - 1 assigned to them. The array sick contains the positions of the children who are infected with an infectious disease. An infected child at position i can spread the disease to either of its immediate neighboring children at positions i - 1 and i + 1 if they exist and are currently not infected. At most one child who was previously not infected can get infected with the disease in one second.\nIt can be shown that after a finite number of seconds, all the children in the queue will get infected with the disease. An infection sequence is the sequential order of positions in which all of the non-infected children get infected with the disease. Return the total number of possible infection sequences.\nSince the answer may be large, return it modulo 109 + 7.\nNote that an infection sequence does not contain positions of children who were already infected with the disease in the beginning.\n\nExample 1:\n\nInput: n = 5, sick = [0,4]\nOutput: 4\nExplanation: Children at positions 1, 2, and 3 are not infected in the beginning. There are 4 possible infection sequences:\n- The children at positions 1 and 3 can get infected since their positions are adjacent to the infected children 0 and 4. The child at position 1 gets infected first.\nNow, the child at position 2 is adjacent to the child at position 1 who is infected and the child at position 3 is adjacent to the child at position 4 who is infected, hence either of them can get infected. The child at position 2 gets infected.\nFinally, the child at position 3 gets infected because it is adjacent to children at positions 2 and 4 who are infected. The infection sequence is [1,2,3].\n- The children at positions 1 and 3 can get infected because their positions are adjacent to the infected children 0 and 4. The child at position 1 gets infected first.\nNow, the child at position 2 is adjacent to the child at position 1 who is infected and the child at position 3 is adjacent to the child at position 4 who is infected, hence either of them can get infected. The child at position 3 gets infected.\nFinally, the child at position 2 gets infected because it is adjacent to children at positions 1 and 3 who are infected. The infection sequence is [1,3,2].\n- The infection sequence is [3,1,2]. The order of infection of disease in the children can be seen as: [0,1,2,3,4] => [0,1,2,3,4] => [0,1,2,3,4] => [0,1,2,3,4].\n- The infection sequence is [3,2,1]. The order of infection of disease in the children can be seen as: [0,1,2,3,4] => [0,1,2,3,4] => [0,1,2,3,4] => [0,1,2,3,4].\n\nExample 2:\n\nInput: n = 4, sick = [1]\nOutput: 3\nExplanation: Children at positions 0, 2, and 3 are not infected in the beginning. There are 3 possible infection sequences:\n- The infection sequence is [0,2,3]. The order of infection of disease in the children can be seen as: [0,1,2,3] => [0,1,2,3] => [0,1,2,3] => [0,1,2,3].\n- The infection sequence is [2,0,3]. The order of infection of disease in the children can be seen as: [0,1,2,3] => [0,1,2,3] => [0,1,2,3] => [0,1,2,3].\n- The infection sequence is [2,3,0]. The order of infection of disease in the children can be seen as: [0,1,2,3] => [0,1,2,3] => [0,1,2,3] => [0,1,2,3].\n\n\nConstraints:\n\n2 <= n <= 105\n1 <= sick.length <= n - 1\n0 <= sick[i] <= n - 1\nsick is sorted in increasing order.\n\"\"\"\nclass Solution:\n def numberOfSequence(self, n: int, sick: List[int]) -> int:\n ", "prompt_sft": "You are given an integer n and a 0-indexed integer array sick which is sorted in increasing order.\nThere are n children standing in a queue with positions 0 to n - 1 assigned to them. The array sick contains the positions of the children who are infected with an infectious disease. An infected child at position i can spread the disease to either of its immediate neighboring children at positions i - 1 and i + 1 if they exist and are currently not infected. At most one child who was previously not infected can get infected with the disease in one second.\nIt can be shown that after a finite number of seconds, all the children in the queue will get infected with the disease. An infection sequence is the sequential order of positions in which all of the non-infected children get infected with the disease. Return the total number of possible infection sequences.\nSince the answer may be large, return it modulo 109 + 7.\nNote that an infection sequence does not contain positions of children who were already infected with the disease in the beginning.\n\nExample 1:\n\nInput: n = 5, sick = [0,4]\nOutput: 4\nExplanation: Children at positions 1, 2, and 3 are not infected in the beginning. There are 4 possible infection sequences:\n- The children at positions 1 and 3 can get infected since their positions are adjacent to the infected children 0 and 4. The child at position 1 gets infected first.\nNow, the child at position 2 is adjacent to the child at position 1 who is infected and the child at position 3 is adjacent to the child at position 4 who is infected, hence either of them can get infected. The child at position 2 gets infected.\nFinally, the child at position 3 gets infected because it is adjacent to children at positions 2 and 4 who are infected. The infection sequence is [1,2,3].\n- The children at positions 1 and 3 can get infected because their positions are adjacent to the infected children 0 and 4. The child at position 1 gets infected first.\nNow, the child at position 2 is adjacent to the child at position 1 who is infected and the child at position 3 is adjacent to the child at position 4 who is infected, hence either of them can get infected. The child at position 3 gets infected.\nFinally, the child at position 2 gets infected because it is adjacent to children at positions 1 and 3 who are infected. The infection sequence is [1,3,2].\n- The infection sequence is [3,1,2]. The order of infection of disease in the children can be seen as: [0,1,2,3,4] => [0,1,2,3,4] => [0,1,2,3,4] => [0,1,2,3,4].\n- The infection sequence is [3,2,1]. The order of infection of disease in the children can be seen as: [0,1,2,3,4] => [0,1,2,3,4] => [0,1,2,3,4] => [0,1,2,3,4].\n\nExample 2:\n\nInput: n = 4, sick = [1]\nOutput: 3\nExplanation: Children at positions 0, 2, and 3 are not infected in the beginning. There are 3 possible infection sequences:\n- The infection sequence is [0,2,3]. The order of infection of disease in the children can be seen as: [0,1,2,3] => [0,1,2,3] => [0,1,2,3] => [0,1,2,3].\n- The infection sequence is [2,0,3]. The order of infection of disease in the children can be seen as: [0,1,2,3] => [0,1,2,3] => [0,1,2,3] => [0,1,2,3].\n- The infection sequence is [2,3,0]. The order of infection of disease in the children can be seen as: [0,1,2,3] => [0,1,2,3] => [0,1,2,3] => [0,1,2,3].\n\n\nConstraints:\n\n2 <= n <= 105\n1 <= sick.length <= n - 1\n0 <= sick[i] <= n - 1\nsick is sorted in increasing order.\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def numberOfSequence(self, n: int, sick: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"n\": 5, \"sick\": [0,4] }\nassert my_solution.numberOfSequence(**test_input) == 4\n\ntest_input = { \"n\": 4, \"sick\": [1] }\nassert my_solution.numberOfSequence(**test_input) == 3\n\ntest_input = { \"n\": 2, \"sick\": [0] }\nassert my_solution.numberOfSequence(**test_input) == 1\n\ntest_input = { \"n\": 5, \"sick\": [0] }\nassert my_solution.numberOfSequence(**test_input) == 1\n\ntest_input = { \"n\": 100, \"sick\": [0] }\nassert my_solution.numberOfSequence(**test_input) == 1\n\ntest_input = { \"n\": 2, \"sick\": [1] }\nassert my_solution.numberOfSequence(**test_input) == 1\n\ntest_input = { \"n\": 5, \"sick\": [1] }\nassert my_solution.numberOfSequence(**test_input) == 4\n\ntest_input = { \"n\": 5, \"sick\": [2] }\nassert my_solution.numberOfSequence(**test_input) == 6\n\ntest_input = { \"n\": 5, \"sick\": [3] }\nassert my_solution.numberOfSequence(**test_input) == 4\n\ntest_input = { \"n\": 5, \"sick\": [4] }\nassert my_solution.numberOfSequence(**test_input) == 1\n\ntest_input = { \"n\": 5, \"sick\": [0,1] }\nassert my_solution.numberOfSequence(**test_input) == 1\n\ntest_input = { \"n\": 3, \"sick\": [0,2] }\nassert my_solution.numberOfSequence(**test_input) == 1\n\ntest_input = { \"n\": 5, \"sick\": [0,2] }\nassert my_solution.numberOfSequence(**test_input) == 3\n\ntest_input = { \"n\": 5, \"sick\": [0,3] }\nassert my_solution.numberOfSequence(**test_input) == 6\n\ntest_input = { \"n\": 5, \"sick\": [1,2] }\nassert my_solution.numberOfSequence(**test_input) == 3\n\ntest_input = { \"n\": 5, \"sick\": [1,3] }\nassert my_solution.numberOfSequence(**test_input) == 6\n\ntest_input = { \"n\": 5, \"sick\": [1,4] }\nassert my_solution.numberOfSequence(**test_input) == 6\n\ntest_input = { \"n\": 5, \"sick\": [2,3] }\nassert my_solution.numberOfSequence(**test_input) == 3\n\ntest_input = { \"n\": 5, \"sick\": [2,4] }\nassert my_solution.numberOfSequence(**test_input) == 3\n\ntest_input = { \"n\": 5, \"sick\": [3,4] }\nassert my_solution.numberOfSequence(**test_input) == 1\n\ntest_input = { \"n\": 5, \"sick\": [0,1,2] }\nassert my_solution.numberOfSequence(**test_input) == 1\n\ntest_input = { \"n\": 5, \"sick\": [0,1,3] }\nassert my_solution.numberOfSequence(**test_input) == 2\n\ntest_input = { \"n\": 5, \"sick\": [0,1,4] }\nassert my_solution.numberOfSequence(**test_input) == 2\n\ntest_input = { \"n\": 5, \"sick\": [0,2,3] }\nassert my_solution.numberOfSequence(**test_input) == 2\n\ntest_input = { \"n\": 5, \"sick\": [0,2,4] }\nassert my_solution.numberOfSequence(**test_input) == 2\n\ntest_input = { \"n\": 5, \"sick\": [0,3,4] }\nassert my_solution.numberOfSequence(**test_input) == 2\n\ntest_input = { \"n\": 5, \"sick\": [1,2,3] }\nassert my_solution.numberOfSequence(**test_input) == 2\n\ntest_input = { \"n\": 5, \"sick\": [1,2,4] }\nassert my_solution.numberOfSequence(**test_input) == 2\n\ntest_input = { \"n\": 5, \"sick\": [1,3,4] }\nassert my_solution.numberOfSequence(**test_input) == 2\n\ntest_input = { \"n\": 5, \"sick\": [2,3,4] }\nassert my_solution.numberOfSequence(**test_input) == 1\n\ntest_input = { \"n\": 5, \"sick\": [0,1,2,3] }\nassert my_solution.numberOfSequence(**test_input) == 1\n\ntest_input = { \"n\": 10, \"sick\": [0,1,2,3] }\nassert my_solution.numberOfSequence(**test_input) == 1\n\ntest_input = { \"n\": 5, \"sick\": [0,1,2,4] }\nassert my_solution.numberOfSequence(**test_input) == 1\n\ntest_input = { \"n\": 10, \"sick\": [0,1,2,4] }\nassert my_solution.numberOfSequence(**test_input) == 6\n\ntest_input = { \"n\": 10, \"sick\": [0,1,2,5] }\nassert my_solution.numberOfSequence(**test_input) == 30\n\ntest_input = { \"n\": 10, \"sick\": [0,1,2,8] }\nassert my_solution.numberOfSequence(**test_input) == 96\n\ntest_input = { \"n\": 10, \"sick\": [0,1,2,9] }\nassert my_solution.numberOfSequence(**test_input) == 32\n\ntest_input = { \"n\": 5, \"sick\": [0,1,3,4] }\nassert my_solution.numberOfSequence(**test_input) == 1\n\ntest_input = { \"n\": 10, \"sick\": [0,1,3,5] }\nassert my_solution.numberOfSequence(**test_input) == 30\n\ntest_input = { \"n\": 10, \"sick\": [0,1,3,6] }\nassert my_solution.numberOfSequence(**test_input) == 120\n\ntest_input = { \"n\": 10, \"sick\": [0,1,3,7] }\nassert my_solution.numberOfSequence(**test_input) == 240\n\ntest_input = { \"n\": 10, \"sick\": [0,1,3,8] }\nassert my_solution.numberOfSequence(**test_input) == 240\n\ntest_input = { \"n\": 10, \"sick\": [0,1,4,5] }\nassert my_solution.numberOfSequence(**test_input) == 30\n\ntest_input = { \"n\": 10, \"sick\": [0,1,4,6] }\nassert my_solution.numberOfSequence(**test_input) == 120\n\ntest_input = { \"n\": 10, \"sick\": [0,1,4,7] }\nassert my_solution.numberOfSequence(**test_input) == 360\n\ntest_input = { \"n\": 10, \"sick\": [0,1,4,8] }\nassert my_solution.numberOfSequence(**test_input) == 480\n\ntest_input = { \"n\": 10, \"sick\": [0,1,4,9] }\nassert my_solution.numberOfSequence(**test_input) == 240\n\ntest_input = { \"n\": 10, \"sick\": [0,1,5,6] }\nassert my_solution.numberOfSequence(**test_input) == 80\n\ntest_input = { \"n\": 10, \"sick\": [0,1,5,7] }\nassert my_solution.numberOfSequence(**test_input) == 240\n\ntest_input = { \"n\": 10, \"sick\": [0,1,5,8] }\nassert my_solution.numberOfSequence(**test_input) == 480\n\ntest_input = { \"n\": 10, \"sick\": [0,1,5,9] }\nassert my_solution.numberOfSequence(**test_input) == 320\n\ntest_input = { \"n\": 10, \"sick\": [0,1,6,7] }\nassert my_solution.numberOfSequence(**test_input) == 120\n\ntest_input = { \"n\": 10, \"sick\": [0,1,6,8] }\nassert my_solution.numberOfSequence(**test_input) == 240\n\ntest_input = { \"n\": 10, \"sick\": [0,1,6,9] }\nassert my_solution.numberOfSequence(**test_input) == 240\n\ntest_input = { \"n\": 10, \"sick\": [0,1,7,8] }\nassert my_solution.numberOfSequence(**test_input) == 96\n\ntest_input = { \"n\": 10, \"sick\": [0,1,7,9] }\nassert my_solution.numberOfSequence(**test_input) == 96\n\ntest_input = { \"n\": 10, \"sick\": [0,1,8,9] }\nassert my_solution.numberOfSequence(**test_input) == 32\n\ntest_input = { \"n\": 5, \"sick\": [0,2,3,4] }\nassert my_solution.numberOfSequence(**test_input) == 1\n\ntest_input = { \"n\": 10, \"sick\": [0,2,3,4] }\nassert my_solution.numberOfSequence(**test_input) == 6\n\ntest_input = { \"n\": 10, \"sick\": [0,2,3,5] }\nassert my_solution.numberOfSequence(**test_input) == 30\n\ntest_input = { \"n\": 10, \"sick\": [0,2,3,6] }\nassert my_solution.numberOfSequence(**test_input) == 120\n\ntest_input = { \"n\": 10, \"sick\": [0,2,3,7] }\nassert my_solution.numberOfSequence(**test_input) == 240\n\ntest_input = { \"n\": 10, \"sick\": [0,2,3,8] }\nassert my_solution.numberOfSequence(**test_input) == 240\n\ntest_input = { \"n\": 10, \"sick\": [0,2,3,9] }\nassert my_solution.numberOfSequence(**test_input) == 96\n\ntest_input = { \"n\": 10, \"sick\": [0,2,4,5] }\nassert my_solution.numberOfSequence(**test_input) == 30\n\ntest_input = { \"n\": 10, \"sick\": [0,2,4,6] }\nassert my_solution.numberOfSequence(**test_input) == 120\n\ntest_input = { \"n\": 10, \"sick\": [0,2,4,7] }\nassert my_solution.numberOfSequence(**test_input) == 360\n\ntest_input = { \"n\": 10, \"sick\": [0,2,4,8] }\nassert my_solution.numberOfSequence(**test_input) == 480\n\ntest_input = { \"n\": 10, \"sick\": [0,2,4,9] }\nassert my_solution.numberOfSequence(**test_input) == 240\n\ntest_input = { \"n\": 10, \"sick\": [0,2,5,6] }\nassert my_solution.numberOfSequence(**test_input) == 120\n\ntest_input = { \"n\": 10, \"sick\": [0,2,5,7] }\nassert my_solution.numberOfSequence(**test_input) == 360\n\ntest_input = { \"n\": 10, \"sick\": [0,2,5,8] }\nassert my_solution.numberOfSequence(**test_input) == 720\n\ntest_input = { \"n\": 10, \"sick\": [0,2,5,9] }\nassert my_solution.numberOfSequence(**test_input) == 480\n\ntest_input = { \"n\": 10, \"sick\": [0,2,6,7] }\nassert my_solution.numberOfSequence(**test_input) == 240\n\ntest_input = { \"n\": 10, \"sick\": [0,2,6,8] }\nassert my_solution.numberOfSequence(**test_input) == 480\n\ntest_input = { \"n\": 10, \"sick\": [0,2,7,8] }\nassert my_solution.numberOfSequence(**test_input) == 240\n\ntest_input = { \"n\": 10, \"sick\": [0,2,7,9] }\nassert my_solution.numberOfSequence(**test_input) == 240\n\ntest_input = { \"n\": 10, \"sick\": [0,2,8,9] }\nassert my_solution.numberOfSequence(**test_input) == 96\n\ntest_input = { \"n\": 10, \"sick\": [0,3,4,5] }\nassert my_solution.numberOfSequence(**test_input) == 30\n\ntest_input = { \"n\": 10, \"sick\": [0,3,4,7] }\nassert my_solution.numberOfSequence(**test_input) == 360\n\ntest_input = { \"n\": 10, \"sick\": [0,3,4,8] }\nassert my_solution.numberOfSequence(**test_input) == 480\n\ntest_input = { \"n\": 10, \"sick\": [0,3,4,9] }\nassert my_solution.numberOfSequence(**test_input) == 240\n\ntest_input = { \"n\": 10, \"sick\": [0,3,5,6] }\nassert my_solution.numberOfSequence(**test_input) == 120\n\ntest_input = { \"n\": 10, \"sick\": [0,3,5,7] }\nassert my_solution.numberOfSequence(**test_input) == 360\n\ntest_input = { \"n\": 10, \"sick\": [0,3,6,7] }\nassert my_solution.numberOfSequence(**test_input) == 360\n\ntest_input = { \"n\": 10, \"sick\": [0,3,6,8] }\nassert my_solution.numberOfSequence(**test_input) == 720\n\ntest_input = { \"n\": 10, \"sick\": [0,3,6,9] }\nassert my_solution.numberOfSequence(**test_input) == 720\n\ntest_input = { \"n\": 10, \"sick\": [0,3,7,8] }\nassert my_solution.numberOfSequence(**test_input) == 480\n\ntest_input = { \"n\": 10, \"sick\": [0,3,7,9] }\nassert my_solution.numberOfSequence(**test_input) == 480\n\ntest_input = { \"n\": 10, \"sick\": [0,3,8,9] }\nassert my_solution.numberOfSequence(**test_input) == 240\n\ntest_input = { \"n\": 10, \"sick\": [0,4,5,6] }\nassert my_solution.numberOfSequence(**test_input) == 80\n\ntest_input = { \"n\": 10, \"sick\": [0,4,5,7] }\nassert my_solution.numberOfSequence(**test_input) == 240\n\ntest_input = { \"n\": 10, \"sick\": [0,4,5,9] }\nassert my_solution.numberOfSequence(**test_input) == 320\n\ntest_input = { \"n\": 10, \"sick\": [0,4,6,7] }\nassert my_solution.numberOfSequence(**test_input) == 240\n\ntest_input = { \"n\": 10, \"sick\": [0,4,6,8] }\nassert my_solution.numberOfSequence(**test_input) == 480\n\ntest_input = { \"n\": 10, \"sick\": [0,4,8,9] }\nassert my_solution.numberOfSequence(**test_input) == 320\n\ntest_input = { \"n\": 10, \"sick\": [0,5,6,7] }\nassert my_solution.numberOfSequence(**test_input) == 120\n\ntest_input = { \"n\": 10, \"sick\": [0,5,6,9] }\nassert my_solution.numberOfSequence(**test_input) == 240\n\ntest_input = { \"n\": 10, \"sick\": [0,5,7,8] }\nassert my_solution.numberOfSequence(**test_input) == 240\n\ntest_input = { \"n\": 10, \"sick\": [0,5,7,9] }\nassert my_solution.numberOfSequence(**test_input) == 240", "start_time": 1701570600} +{"task_id": "weekly-contest-373-matrix-similarity-after-cyclic-shifts", "url": "https://leetcode.com/problems/matrix-similarity-after-cyclic-shifts", "title": "matrix-similarity-after-cyclic-shifts", "meta": {"questionId": "3215", "questionFrontendId": "2946", "title": "Matrix Similarity After Cyclic Shifts", "titleSlug": "matrix-similarity-after-cyclic-shifts", "isPaidOnly": false, "difficulty": "Easy", "likes": 72, "dislikes": 48, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed m x n integer matrix mat and an integer k. You have to cyclically right shift odd indexed rows k times and cyclically left shift even indexed rows k times.\nReturn true if the initial and final matrix are exactly the same and false otherwise.\n\nExample 1:\n\nInput: mat = [[1,2,1,2],[5,5,5,5],[6,3,6,3]], k = 2\nOutput: true\nExplanation:\n\n\nInitially, the matrix looks like the first figure. \nSecond figure represents the state of the matrix after one right and left cyclic shifts to even and odd indexed rows.\nThird figure is the final state of the matrix after two cyclic shifts which is similar to the initial matrix.\nTherefore, return true.\n\nExample 2:\n\nInput: mat = [[2,2],[2,2]], k = 3\nOutput: true\nExplanation: As all the values are equal in the matrix, even after performing cyclic shifts the matrix will remain the same. Therefeore, we return true.\n\nExample 3:\n\nInput: mat = [[1,2]], k = 1\nOutput: false\nExplanation: After one cyclic shift, mat = [[2,1]] which is not equal to the initial matrix. Therefore we return false.\n\n\nConstraints:\n\n1 <= mat.length <= 25\n1 <= mat[i].length <= 25\n1 <= mat[i][j] <= 25\n1 <= k <= 50\n\"\"\"\nclass Solution:\n def areSimilar(self, mat: List[List[int]], k: int) -> bool:\n ", "prompt_sft": "You are given a 0-indexed m x n integer matrix mat and an integer k. You have to cyclically right shift odd indexed rows k times and cyclically left shift even indexed rows k times.\nReturn true if the initial and final matrix are exactly the same and false otherwise.\n\nExample 1:\n\nInput: mat = [[1,2,1,2],[5,5,5,5],[6,3,6,3]], k = 2\nOutput: true\nExplanation:\n\n\nInitially, the matrix looks like the first figure. \nSecond figure represents the state of the matrix after one right and left cyclic shifts to even and odd indexed rows.\nThird figure is the final state of the matrix after two cyclic shifts which is similar to the initial matrix.\nTherefore, return true.\n\nExample 2:\n\nInput: mat = [[2,2],[2,2]], k = 3\nOutput: true\nExplanation: As all the values are equal in the matrix, even after performing cyclic shifts the matrix will remain the same. Therefeore, we return true.\n\nExample 3:\n\nInput: mat = [[1,2]], k = 1\nOutput: false\nExplanation: After one cyclic shift, mat = [[2,1]] which is not equal to the initial matrix. Therefore we return false.\n\n\nConstraints:\n\n1 <= mat.length <= 25\n1 <= mat[i].length <= 25\n1 <= mat[i][j] <= 25\n1 <= k <= 50\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def areSimilar(self, mat: List[List[int]], k: int) -> bool:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"mat\": [[1,2]], \"k\": 1 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[1,2,1,2],[5,5,5,5],[6,3,6,3]], \"k\": 2 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[4,9,10,10],[9,3,8,4],[2,5,3,8],[6,1,10,4]], \"k\": 5 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[5,8,8,4,7,2,3,4,3,10],[8,7,9,1,3,4,2,6,6,9],[6,2,10,10,4,6,3,4,1,1]], \"k\": 3 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[4,7,9,1,10,5,2,6,1,7],[8,9,9,2,3,2,3,2,3,5],[1,2,4,7,4,7,9,7,9,9]], \"k\": 5 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[10,6,3,6],[4,8,1,2]], \"k\": 6 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[7,10,6,7,7,4,4,7,2,2],[3,6,4,8,4,6,4,3,1,4],[4,8,7,1,10,2,10,8,10,1],[4,7,10,5,1,9,8,3,5,8],[3,7,6,5,3,1,3,2,8,5],[6,1,5,10,8,7,7,10,1,3]], \"k\": 7 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[6,5,3],[4,6,2],[4,1,8],[3,9,1],[6,1,2],[1,9,9],[2,6,10]], \"k\": 5 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[2,4],[9,8]], \"k\": 9 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[2,2],[2,2]], \"k\": 3 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[9,1,10,6,10,7,3],[9,2,9,10,7,10,10]], \"k\": 4 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[7,7],[10,10],[4,4]], \"k\": 2 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[6,6,6,6,6,6,6,6,6,6],[9,9,9,9,9,9,9,9,9,9],[1,1,1,1,1,1,1,1,1,1],[10,10,10,10,10,10,10,10,10,10],[2,2,2,2,2,2,2,2,2,2],[6,6,6,6,6,6,6,6,6,6],[7,7,7,7,7,7,7,7,7,7],[9,9,9,9,9,9,9,9,9,9],[8,8,8,8,8,8,8,8,8,8]], \"k\": 1 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[6,9,1],[8,9,7],[2,8,7],[1,5,7],[10,5,9],[5,5,6],[8,6,1],[5,7,8]], \"k\": 5 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[3,10,3,10,3,10,3,10],[5,8,5,8,5,8,5,8],[3,9,3,9,3,9,3,9],[3,8,3,8,3,8,3,8],[2,3,2,3,2,3,2,3]], \"k\": 2 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[9,5,3,10],[4,7,10,7],[1,7,9,4],[8,8,1,6],[6,7,6,1],[3,1,1,8],[9,2,8,3],[1,9,7,6]], \"k\": 4 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[4,6],[10,1],[8,8],[10,9],[9,10]], \"k\": 9 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[1,9,6,7,1,4,7,6,7],[7,10,6,6,4,9,6,8,2],[3,9,8,10,9,9,3,9,5],[8,5,2,3,4,7,3,3,1],[1,5,9,9,6,1,9,7,5],[8,3,10,2,4,8,7,9,9],[5,9,6,8,4,3,4,6,4],[7,2,6,9,2,4,5,4,9],[4,8,7,5,3,6,3,9,5]], \"k\": 1 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[9,3,3,7,7,5,3,3],[10,9,9,3,6,8,7,5],[8,9,3,10,10,10,2,1],[9,7,8,2,3,4,8,4],[5,9,5,2,2,6,5,7],[1,5,9,7,8,1,1,1]], \"k\": 10 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[10,6,10,6,10,6,10,6]], \"k\": 4 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[2,4],[6,1],[1,2],[2,10],[6,5],[4,9]], \"k\": 7 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[8,8,8,8,8,8,8,8,8,8],[7,7,7,7,7,7,7,7,7,7],[6,6,6,6,6,6,6,6,6,6]], \"k\": 2 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[8,10,1,7,1,3,9,6,8],[9,10,4,8,8,9,3,10,10],[4,3,2,2,3,6,4,6,1],[9,4,1,4,5,2,5,1,8],[3,10,6,3,8,4,8,3,10]], \"k\": 7 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[8,9],[3,3],[5,6],[10,1],[2,5],[5,8],[5,4],[9,5]], \"k\": 2 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[9,1,8,9,2,9,1,8,9,2],[10,2,7,8,9,10,2,7,8,9],[7,6,6,9,5,7,6,6,9,5]], \"k\": 5 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[4,4,4,2,7,9,1,8,9,8],[3,3,6,3,8,8,7,7,4,5],[10,1,3,7,6,5,7,10,3,10]], \"k\": 5 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[9,10,10,6,6,8,10,7,10,9],[10,6,1,10,10,5,7,9,9,2],[8,5,8,3,5,2,2,9,7,10]], \"k\": 20 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[4,5,1,3,10],[10,5,9,10,2],[8,10,2,8,1],[5,8,9,3,4],[6,6,10,10,10],[6,1,7,9,4],[6,7,6,2,10]], \"k\": 8 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[2,7,1,10,5,3],[10,7,8,2,2,2],[9,6,1,4,10,6],[6,1,1,9,2,5],[6,4,7,3,6,4],[10,10,5,4,2,1],[7,3,3,7,1,5],[5,8,2,10,5,1],[3,1,5,1,5,7]], \"k\": 2 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[7,7,4],[8,9,9],[9,7,5],[6,3,6],[4,9,5],[1,10,3],[4,4,7],[4,7,6]], \"k\": 1 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[10,10],[10,10],[5,5],[3,3],[2,2]], \"k\": 2 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[6,4,7,6,3,9,4,2,10,5],[9,7,7,3,10,9,7,4,3,1]], \"k\": 20 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[7]], \"k\": 1 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[6,3,2]], \"k\": 4 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[6,8]], \"k\": 4 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[6,6,7,7,1],[10,3,3,2,2],[7,9,8,10,7],[10,8,2,7,1],[2,2,1,2,3],[6,2,8,10,10],[6,2,6,3,3],[2,2,2,4,7]], \"k\": 4 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[8,8,5,3,7,8],[8,9,1,7,3,10],[4,3,9,8,4,7],[2,2,5,8,2,2],[6,1,2,7,4,8],[10,9,6,3,1,4],[7,1,6,7,4,6]], \"k\": 2 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[7],[5],[5],[4],[4],[5],[8]], \"k\": 6 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[8,8,5,10,7,8,8,5,10,7],[1,2,6,10,7,1,2,6,10,7]], \"k\": 5 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[10,2,6,7,6,6,5],[6,3,3,4,6,5,7],[6,8,5,10,8,4,1]], \"k\": 8 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[4,10,9,7,9,9,2],[3,9,2,1,8,9,10],[7,10,9,7,2,3,8]], \"k\": 1 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[1,7,10,10,9,2,1],[6,4,5,2,3,3,10],[2,6,8,3,6,1,4]], \"k\": 9 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[2,9,2,2,6,10,4,8,3],[10,8,4,5,10,3,3,8,5],[2,6,4,5,4,8,5,5,4],[1,3,2,10,5,3,10,9,4],[2,4,2,4,7,7,1,4,9]], \"k\": 2 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[9,5,6,9,5,6],[1,9,4,1,9,4],[5,7,2,5,7,2],[9,1,5,9,1,5],[6,8,6,6,8,6],[10,1,7,10,1,7]], \"k\": 6 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[2,7,6],[10,6,5],[10,2,4],[10,7,9],[5,8,6],[10,6,3],[10,9,6],[5,2,8],[10,1,2]], \"k\": 7 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[5,4,5,10,5]], \"k\": 9 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[10,10,9],[5,6,7],[1,4,7],[5,1,1],[5,1,5],[5,10,3]], \"k\": 2 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[9,4,5],[8,5,4],[2,9,9]], \"k\": 10 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[4,2,2,7,9,1,1,2],[1,8,7,5,7,5,9,6],[2,9,4,10,1,8,5,4]], \"k\": 3 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[10],[7],[8],[2]], \"k\": 1 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[10],[1],[5],[3],[1],[1]], \"k\": 4 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[7,1,7,7,1,7,7,1,7],[5,10,1,5,10,1,5,10,1]], \"k\": 3 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[4,7,9,9,4,7,9,9],[8,9,7,4,8,9,7,4],[6,8,6,4,6,8,6,4],[9,8,8,8,9,8,8,8],[3,6,5,3,3,6,5,3],[1,9,4,3,1,9,4,3],[8,3,2,7,8,3,2,7],[3,8,2,8,3,8,2,8],[6,5,2,8,6,5,2,8]], \"k\": 8 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[4],[5],[4],[2],[4],[2],[7],[4]], \"k\": 1 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[3,8,5,4,10,2],[9,3,9,5,4,2]], \"k\": 6 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[8,9,10,6,5,7],[8,9,9,3,3,9],[4,5,4,4,4,10],[2,6,3,9,7,1],[10,10,4,4,6,10]], \"k\": 9 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[7,7,7,7,7],[1,1,1,1,1]], \"k\": 1 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[5,7,5,5,1,9,1,8,6,7],[8,1,9,10,10,5,4,9,1,8],[10,6,8,10,2,10,9,4,9,6],[4,7,10,2,7,4,2,10,3,5],[2,2,4,9,10,1,6,2,8,3],[1,3,5,9,9,8,10,8,9,10],[7,8,7,7,6,9,2,5,8,4],[6,9,4,2,4,10,10,8,10,7]], \"k\": 8 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[2,9,10],[7,3,3],[7,6,2]], \"k\": 1 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[2,5,8,9,6,8],[3,6,4,10,10,6],[9,6,10,9,6,5]], \"k\": 1 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[2,2],[4,5],[3,2],[4,6],[1,9],[5,3],[3,5],[2,4],[3,9]], \"k\": 7 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[1,8,6,8,6,7,1,6]], \"k\": 16 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[7,9,9,2,7],[8,5,8,6,7],[2,9,8,5,2],[9,9,2,6,8],[7,4,10,10,8]], \"k\": 6 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[8,8],[6,6],[2,2],[8,8],[9,9],[8,8],[10,10],[3,3],[4,4],[5,5]], \"k\": 1 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[3,3,3,3,3,3],[5,3,5,3,5,3],[2,5,2,5,2,5],[8,8,8,8,8,8],[3,8,3,8,3,8],[5,3,5,3,5,3],[1,8,1,8,1,8],[8,9,8,9,8,9],[2,8,2,8,2,8]], \"k\": 4 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[2,2,2,2,2],[7,7,7,7,7],[5,5,5,5,5],[8,8,8,8,8],[1,1,1,1,1],[10,10,10,10,10],[7,7,7,7,7]], \"k\": 1 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[3,1,10,5,10,3,1,10,5,10],[3,5,9,2,10,3,5,9,2,10],[4,6,3,5,7,4,6,3,5,7],[8,10,6,7,8,8,10,6,7,8]], \"k\": 5 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[10,7,1,7],[3,5,9,5],[2,8,3,10],[8,7,1,9],[3,8,6,3],[6,5,8,9],[8,7,5,1],[10,4,9,9],[4,6,1,9],[6,10,1,7]], \"k\": 3 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[1,10,3,9,6],[7,1,3,4,10]], \"k\": 3 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[7,7],[2,2],[5,5]], \"k\": 1 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[4,4,4,4,4,4,4],[2,2,2,2,2,2,2],[3,3,3,3,3,3,3],[8,8,8,8,8,8,8],[6,6,6,6,6,6,6]], \"k\": 2 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[10,3,5,3,10,3,5,3],[2,3,9,7,2,3,9,7],[10,4,4,8,10,4,4,8],[10,2,7,9,10,2,7,9],[8,1,8,3,8,1,8,3],[1,9,1,7,1,9,1,7]], \"k\": 4 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[6],[7],[1]], \"k\": 2 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[7,6,4,5]], \"k\": 5 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[5,5,5,5],[5,5,5,5],[10,10,10,10],[2,2,2,2],[3,3,3,3],[2,2,2,2],[8,8,8,8],[10,10,10,10],[9,9,9,9],[7,7,7,7]], \"k\": 2 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[5,1,1,9,4,1,7,6],[8,7,7,6,2,2,1,5],[10,2,5,3,10,7,7,5],[10,6,1,6,8,4,6,3],[10,10,9,8,2,10,8,7],[7,4,2,10,2,3,8,7],[4,7,5,9,10,4,3,2],[10,9,7,7,6,3,9,7],[1,4,8,4,6,5,5,1]], \"k\": 1 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[3]], \"k\": 1 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[1,1,1,1,1],[10,10,10,10,10],[10,10,10,10,10]], \"k\": 2 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[6],[3],[2],[10]], \"k\": 2 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[9,7,5,6],[5,2,1,8],[9,4,3,6],[5,7,4,1],[8,1,8,9],[4,3,6,5],[6,2,7,3],[1,3,6,4],[4,9,5,5]], \"k\": 7 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[10,7,2,10,5,2,7],[10,10,3,8,3,3,8],[4,3,10,10,10,4,10]], \"k\": 4 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[8,5],[8,10],[8,10],[1,1],[2,1]], \"k\": 7 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[9,9],[8,8],[2,2],[1,1],[8,8],[4,4],[9,9],[4,4],[6,6]], \"k\": 2 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[10,1,1],[7,10,6],[9,6,6],[9,8,10],[8,2,1],[6,8,3],[8,6,6]], \"k\": 5 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[2,10,5,6,5,5],[6,3,1,5,4,7],[5,6,3,2,4,10],[9,2,6,8,6,2],[3,6,8,4,9,1]], \"k\": 8 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[10,3,4,2,8,10,3,4,2,8],[9,9,3,4,5,9,9,3,4,5],[6,9,9,2,7,6,9,9,2,7],[5,2,3,3,4,5,2,3,3,4]], \"k\": 5 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[3,4,10,3,4,10],[5,5,4,5,5,4],[5,5,3,5,5,3],[7,8,7,7,8,7]], \"k\": 3 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[7,1,9,3,6],[5,6,5,5,6],[2,3,5,10,8],[5,10,2,5,4],[7,9,1,7,10],[8,2,3,4,2],[1,6,9,2,1]], \"k\": 7 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[3,3],[3,3],[4,4],[3,3],[8,8],[5,5]], \"k\": 1 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[2,10,2,6,3,6],[4,5,10,7,7,9],[1,7,4,1,9,4],[3,7,6,3,1,4],[4,10,4,6,3,5],[1,5,5,9,5,1],[10,2,5,4,7,10],[2,9,7,4,5,3],[5,5,1,2,8,3]], \"k\": 2 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[5],[5],[5]], \"k\": 2 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[9,5,5,6,7],[7,9,3,8,1],[8,8,8,9,5],[1,3,2,6,9],[3,6,4,8,7],[9,3,3,9,10],[8,5,1,2,8],[7,3,10,5,1],[8,4,5,5,1]], \"k\": 5 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[5,8,5,2,8,5,9],[7,8,2,2,8,2,2],[4,5,6,7,3,9,9],[5,7,4,8,2,9,2],[9,5,3,3,5,7,3],[3,8,9,6,3,10,7],[6,7,3,7,3,6,6]], \"k\": 8 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[8,8,8,8,8,8],[8,8,8,8,8,8],[2,2,2,2,2,2],[6,6,6,6,6,6],[9,9,9,9,9,9],[10,10,10,10,10,10],[10,10,10,10,10,10]], \"k\": 2 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[7,7,10,2],[3,5,7,6],[2,10,1,8],[8,3,1,10],[5,1,3,3],[6,3,4,9],[8,9,1,1]], \"k\": 7 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[5,2,7,2,6,10,7,5],[10,9,4,1,7,2,7,4],[2,6,7,3,2,10,4,5],[10,4,7,2,10,3,6,2]], \"k\": 16 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[9,10,10,1],[1,7,3,5],[9,6,4,7],[6,6,4,5],[2,4,2,7],[2,1,1,1],[7,2,1,8],[2,8,1,3],[7,4,6,1],[10,10,7,5]], \"k\": 4 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[7,3,10,2,3,1,10],[7,6,10,1,3,2,1],[9,1,5,7,1,8,3],[4,10,10,7,7,9,7],[7,9,1,5,3,8,4],[4,9,5,10,2,8,10],[2,5,10,3,6,2,9],[6,7,2,3,4,2,2]], \"k\": 1 }\nassert my_solution.areSimilar(**test_input) == False\n\ntest_input = { \"mat\": [[8,8],[9,9],[2,2],[10,10],[10,10],[1,1],[5,5],[9,9],[7,7]], \"k\": 2 }\nassert my_solution.areSimilar(**test_input) == True\n\ntest_input = { \"mat\": [[2,1,7,3,7,6,7,9,9,3],[3,9,10,4,4,6,8,10,5,6],[9,8,6,2,3,4,9,1,9,10],[7,10,8,8,3,9,9,5,8,9],[9,5,6,9,9,6,4,3,2,3],[3,10,6,2,7,6,10,6,2,6],[7,9,7,4,5,7,2,4,9,5],[4,7,9,6,7,4,6,4,10,4]], \"k\": 6 }\nassert my_solution.areSimilar(**test_input) == False", "start_time": 1700965800} +{"task_id": "weekly-contest-373-count-beautiful-substrings-i", "url": "https://leetcode.com/problems/count-beautiful-substrings-i", "title": "count-beautiful-substrings-i", "meta": {"questionId": "3210", "questionFrontendId": "2947", "title": "Count Beautiful Substrings I", "titleSlug": "count-beautiful-substrings-i", "isPaidOnly": false, "difficulty": "Medium", "likes": 102, "dislikes": 8, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a string s and a positive integer k.\nLet vowels and consonants be the number of vowels and consonants in a string.\nA string is beautiful if:\n\nvowels == consonants.\n(vowels * consonants) % k == 0, in other terms the multiplication of vowels and consonants is divisible by k.\n\nReturn the number of non-empty beautiful substrings in the given string s.\nA substring is a contiguous sequence of characters in a string.\nVowel letters in English are 'a', 'e', 'i', 'o', and 'u'.\nConsonant letters in English are every letter except vowels.\n\nExample 1:\n\nInput: s = \"baeyh\", k = 2\nOutput: 2\nExplanation: There are 2 beautiful substrings in the given string.\n- Substring \"baeyh\", vowels = 2 ([\"a\",e\"]), consonants = 2 ([\"y\",\"h\"]).\nYou can see that string \"aeyh\" is beautiful as vowels == consonants and vowels * consonants % k == 0.\n- Substring \"baeyh\", vowels = 2 ([\"a\",e\"]), consonants = 2 ([\"b\",\"y\"]). \nYou can see that string \"baey\" is beautiful as vowels == consonants and vowels * consonants % k == 0.\nIt can be shown that there are only 2 beautiful substrings in the given string.\n\nExample 2:\n\nInput: s = \"abba\", k = 1\nOutput: 3\nExplanation: There are 3 beautiful substrings in the given string.\n- Substring \"abba\", vowels = 1 ([\"a\"]), consonants = 1 ([\"b\"]). \n- Substring \"abba\", vowels = 1 ([\"a\"]), consonants = 1 ([\"b\"]).\n- Substring \"abba\", vowels = 2 ([\"a\",\"a\"]), consonants = 2 ([\"b\",\"b\"]).\nIt can be shown that there are only 3 beautiful substrings in the given string.\n\nExample 3:\n\nInput: s = \"bcdf\", k = 1\nOutput: 0\nExplanation: There are no beautiful substrings in the given string.\n\n\nConstraints:\n\n1 <= s.length <= 1000\n1 <= k <= 1000\ns consists of only English lowercase letters.\n\"\"\"\nclass Solution:\n def beautifulSubstrings(self, s: str, k: int) -> int:\n ", "prompt_sft": "You are given a string s and a positive integer k.\nLet vowels and consonants be the number of vowels and consonants in a string.\nA string is beautiful if:\n\nvowels == consonants.\n(vowels * consonants) % k == 0, in other terms the multiplication of vowels and consonants is divisible by k.\n\nReturn the number of non-empty beautiful substrings in the given string s.\nA substring is a contiguous sequence of characters in a string.\nVowel letters in English are 'a', 'e', 'i', 'o', and 'u'.\nConsonant letters in English are every letter except vowels.\n\nExample 1:\n\nInput: s = \"baeyh\", k = 2\nOutput: 2\nExplanation: There are 2 beautiful substrings in the given string.\n- Substring \"baeyh\", vowels = 2 ([\"a\",e\"]), consonants = 2 ([\"y\",\"h\"]).\nYou can see that string \"aeyh\" is beautiful as vowels == consonants and vowels * consonants % k == 0.\n- Substring \"baeyh\", vowels = 2 ([\"a\",e\"]), consonants = 2 ([\"b\",\"y\"]). \nYou can see that string \"baey\" is beautiful as vowels == consonants and vowels * consonants % k == 0.\nIt can be shown that there are only 2 beautiful substrings in the given string.\n\nExample 2:\n\nInput: s = \"abba\", k = 1\nOutput: 3\nExplanation: There are 3 beautiful substrings in the given string.\n- Substring \"abba\", vowels = 1 ([\"a\"]), consonants = 1 ([\"b\"]). \n- Substring \"abba\", vowels = 1 ([\"a\"]), consonants = 1 ([\"b\"]).\n- Substring \"abba\", vowels = 2 ([\"a\",\"a\"]), consonants = 2 ([\"b\",\"b\"]).\nIt can be shown that there are only 3 beautiful substrings in the given string.\n\nExample 3:\n\nInput: s = \"bcdf\", k = 1\nOutput: 0\nExplanation: There are no beautiful substrings in the given string.\n\n\nConstraints:\n\n1 <= s.length <= 1000\n1 <= k <= 1000\ns consists of only English lowercase letters.\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def beautifulSubstrings(self, s: str, k: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"s\": \"baeyh\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 2\n\ntest_input = { \"s\": \"abba\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 3\n\ntest_input = { \"s\": \"bcdf\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"ihroyeeb\", \"k\": 5 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"uzuxpzou\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 1\n\ntest_input = { \"s\": \"ouuoeqd\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 1\n\ntest_input = { \"s\": \"eeebjoxxujuaeoqibd\", \"k\": 8 }\nassert my_solution.beautifulSubstrings(**test_input) == 4\n\ntest_input = { \"s\": \"ilougekqlovegioemdvu\", \"k\": 4 }\nassert my_solution.beautifulSubstrings(**test_input) == 21\n\ntest_input = { \"s\": \"tqaewreikaztwpfwnef\", \"k\": 8 }\nassert my_solution.beautifulSubstrings(**test_input) == 3\n\ntest_input = { \"s\": \"oykiuhsafgfjumnzb\", \"k\": 7 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"ifvsa\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"svzauyuevujektj\", \"k\": 5 }\nassert my_solution.beautifulSubstrings(**test_input) == 3\n\ntest_input = { \"s\": \"urahjig\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 2\n\ntest_input = { \"s\": \"ime\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"oacghieut\", \"k\": 5 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"aoluu\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"ioaoiciiuoziout\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 5\n\ntest_input = { \"s\": \"ouafupsuhid\", \"k\": 6 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"ox\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"tlaiwoauazutusiaaui\", \"k\": 10 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"caepeym\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 2\n\ntest_input = { \"s\": \"apyxvceue\", \"k\": 4 }\nassert my_solution.beautifulSubstrings(**test_input) == 1\n\ntest_input = { \"s\": \"imkqbb\", \"k\": 4 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"caaz\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 1\n\ntest_input = { \"s\": \"pyicoy\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 6\n\ntest_input = { \"s\": \"uopmyrsntjhiroikup\", \"k\": 8 }\nassert my_solution.beautifulSubstrings(**test_input) == 2\n\ntest_input = { \"s\": \"aujfxqxcj\", \"k\": 5 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"eeizejuoxeumz\", \"k\": 4 }\nassert my_solution.beautifulSubstrings(**test_input) == 6\n\ntest_input = { \"s\": \"uuouuaifnboeiulttio\", \"k\": 4 }\nassert my_solution.beautifulSubstrings(**test_input) == 10\n\ntest_input = { \"s\": \"woozzxd\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"pulorolqcvhafexui\", \"k\": 9 }\nassert my_solution.beautifulSubstrings(**test_input) == 3\n\ntest_input = { \"s\": \"hmuaewojioizoguvoaje\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 4\n\ntest_input = { \"s\": \"b\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"aiejouohnqnketinvat\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 6\n\ntest_input = { \"s\": \"mjiogpri\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 3\n\ntest_input = { \"s\": \"movbyaeouil\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 2\n\ntest_input = { \"s\": \"puureouausxmitvav\", \"k\": 6 }\nassert my_solution.beautifulSubstrings(**test_input) == 2\n\ntest_input = { \"s\": \"op\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 1\n\ntest_input = { \"s\": \"iuhoezpooxcohtlapolo\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 39\n\ntest_input = { \"s\": \"cioi\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"pueutaoyaxk\", \"k\": 6 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"iiuresacruaaan\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 3\n\ntest_input = { \"s\": \"agntyaazvpejidwaph\", \"k\": 8 }\nassert my_solution.beautifulSubstrings(**test_input) == 1\n\ntest_input = { \"s\": \"wiybolyniexiibou\", \"k\": 6 }\nassert my_solution.beautifulSubstrings(**test_input) == 2\n\ntest_input = { \"s\": \"coiyakadxi\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 8\n\ntest_input = { \"s\": \"oraajoeruiakixj\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 1\n\ntest_input = { \"s\": \"jeayap\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 7\n\ntest_input = { \"s\": \"iu\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"awozoy\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 3\n\ntest_input = { \"s\": \"fheabmlsyeeeuoeogyz\", \"k\": 9 }\nassert my_solution.beautifulSubstrings(**test_input) == 5\n\ntest_input = { \"s\": \"eaizneuxi\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 10\n\ntest_input = { \"s\": \"uurqufaucsuoqljh\", \"k\": 4 }\nassert my_solution.beautifulSubstrings(**test_input) == 14\n\ntest_input = { \"s\": \"jrtept\", \"k\": 4 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"olgioxooiejooosaed\", \"k\": 5 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"uizoy\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 1\n\ntest_input = { \"s\": \"lswabfiujjhexzos\", \"k\": 4 }\nassert my_solution.beautifulSubstrings(**test_input) == 5\n\ntest_input = { \"s\": \"iuu\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"qeaxut\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 7\n\ntest_input = { \"s\": \"aojiau\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"oaiaaaargkonlcsoaygf\", \"k\": 5 }\nassert my_solution.beautifulSubstrings(**test_input) == 2\n\ntest_input = { \"s\": \"zoowrawkm\", \"k\": 4 }\nassert my_solution.beautifulSubstrings(**test_input) == 3\n\ntest_input = { \"s\": \"uqiwuoevkfhkkua\", \"k\": 4 }\nassert my_solution.beautifulSubstrings(**test_input) == 6\n\ntest_input = { \"s\": \"kavuaaeodvaxicm\", \"k\": 6 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"qpxeceq\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 6\n\ntest_input = { \"s\": \"iaabaofuodcbek\", \"k\": 5 }\nassert my_solution.beautifulSubstrings(**test_input) == 3\n\ntest_input = { \"s\": \"eel\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 1\n\ntest_input = { \"s\": \"ikeuhe\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 5\n\ntest_input = { \"s\": \"lueikvo\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 2\n\ntest_input = { \"s\": \"oauau\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"qzoieeotieeakqraeao\", \"k\": 4 }\nassert my_solution.beautifulSubstrings(**test_input) == 4\n\ntest_input = { \"s\": \"ehaascocsdmgekni\", \"k\": 9 }\nassert my_solution.beautifulSubstrings(**test_input) == 3\n\ntest_input = { \"s\": \"euqeklniykiji\", \"k\": 5 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"vaeiiioidiioxhduu\", \"k\": 7 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"aa\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"chaua\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"edfrglfr\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"dqbe\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 1\n\ntest_input = { \"s\": \"ghooirorxge\", \"k\": 4 }\nassert my_solution.beautifulSubstrings(**test_input) == 6\n\ntest_input = { \"s\": \"fodartekaonq\", \"k\": 4 }\nassert my_solution.beautifulSubstrings(**test_input) == 9\n\ntest_input = { \"s\": \"feeanzkjpfehzeuni\", \"k\": 6 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"ignoouesduu\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 6\n\ntest_input = { \"s\": \"yif\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"gondfjaeeuhbuuasgip\", \"k\": 10 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"djooomsffoonelyeode\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 14\n\ntest_input = { \"s\": \"pgaimei\", \"k\": 4 }\nassert my_solution.beautifulSubstrings(**test_input) == 2\n\ntest_input = { \"s\": \"naipqentonee\", \"k\": 4 }\nassert my_solution.beautifulSubstrings(**test_input) == 8\n\ntest_input = { \"s\": \"bouov\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"lcuhoypz\", \"k\": 5 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"g\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"qc\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"mhznea\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 1\n\ntest_input = { \"s\": \"uxvjixdujgyfauo\", \"k\": 8 }\nassert my_solution.beautifulSubstrings(**test_input) == 1\n\ntest_input = { \"s\": \"iyjkuox\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 1\n\ntest_input = { \"s\": \"xbjfoayfpafatnuyord\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 3\n\ntest_input = { \"s\": \"nvoede\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 1\n\ntest_input = { \"s\": \"usnuaxpaktrweatruu\", \"k\": 5 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"euojmsora\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 10\n\ntest_input = { \"s\": \"iapgoi\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"uafuimcpxyeoixgbyeio\", \"k\": 5 }\nassert my_solution.beautifulSubstrings(**test_input) == 3\n\ntest_input = { \"s\": \"weuaatpu\", \"k\": 5 }\nassert my_solution.beautifulSubstrings(**test_input) == 0", "start_time": 1700965800} +{"task_id": "weekly-contest-373-make-lexicographically-smallest-array-by-swapping-elements", "url": "https://leetcode.com/problems/make-lexicographically-smallest-array-by-swapping-elements", "title": "make-lexicographically-smallest-array-by-swapping-elements", "meta": {"questionId": "3219", "questionFrontendId": "2948", "title": "Make Lexicographically Smallest Array by Swapping Elements", "titleSlug": "make-lexicographically-smallest-array-by-swapping-elements", "isPaidOnly": false, "difficulty": "Medium", "likes": 197, "dislikes": 10, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed array of positive integers nums and a positive integer limit.\nIn one operation, you can choose any two indices i and j and swap nums[i] and nums[j] if |nums[i] - nums[j]| <= limit.\nReturn the lexicographically smallest array that can be obtained by performing the operation any number of times.\nAn array a is lexicographically smaller than an array b if in the first position where a and b differ, array a has an element that is less than the corresponding element in b. For example, the array [2,10,3] is lexicographically smaller than the array [10,2,3] because they differ at index 0 and 2 < 10.\n\nExample 1:\n\nInput: nums = [1,5,3,9,8], limit = 2\nOutput: [1,3,5,8,9]\nExplanation: Apply the operation 2 times:\n- Swap nums[1] with nums[2]. The array becomes [1,3,5,9,8]\n- Swap nums[3] with nums[4]. The array becomes [1,3,5,8,9]\nWe cannot obtain a lexicographically smaller array by applying any more operations.\nNote that it may be possible to get the same result by doing different operations.\n\nExample 2:\n\nInput: nums = [1,7,6,18,2,1], limit = 3\nOutput: [1,6,7,18,1,2]\nExplanation: Apply the operation 3 times:\n- Swap nums[1] with nums[2]. The array becomes [1,6,7,18,2,1]\n- Swap nums[0] with nums[4]. The array becomes [2,6,7,18,1,1]\n- Swap nums[0] with nums[5]. The array becomes [1,6,7,18,1,2]\nWe cannot obtain a lexicographically smaller array by applying any more operations.\n\nExample 3:\n\nInput: nums = [1,7,28,19,10], limit = 3\nOutput: [1,7,28,19,10]\nExplanation: [1,7,28,19,10] is the lexicographically smallest array we can obtain because we cannot apply the operation on any two indices.\n\n\nConstraints:\n\n1 <= nums.length <= 105\n1 <= nums[i] <= 109\n1 <= limit <= 109\n\"\"\"\nclass Solution:\n def lexicographicallySmallestArray(self, nums: List[int], limit: int) -> List[int]:\n ", "prompt_sft": "You are given a 0-indexed array of positive integers nums and a positive integer limit.\nIn one operation, you can choose any two indices i and j and swap nums[i] and nums[j] if |nums[i] - nums[j]| <= limit.\nReturn the lexicographically smallest array that can be obtained by performing the operation any number of times.\nAn array a is lexicographically smaller than an array b if in the first position where a and b differ, array a has an element that is less than the corresponding element in b. For example, the array [2,10,3] is lexicographically smaller than the array [10,2,3] because they differ at index 0 and 2 < 10.\n\nExample 1:\n\nInput: nums = [1,5,3,9,8], limit = 2\nOutput: [1,3,5,8,9]\nExplanation: Apply the operation 2 times:\n- Swap nums[1] with nums[2]. The array becomes [1,3,5,9,8]\n- Swap nums[3] with nums[4]. The array becomes [1,3,5,8,9]\nWe cannot obtain a lexicographically smaller array by applying any more operations.\nNote that it may be possible to get the same result by doing different operations.\n\nExample 2:\n\nInput: nums = [1,7,6,18,2,1], limit = 3\nOutput: [1,6,7,18,1,2]\nExplanation: Apply the operation 3 times:\n- Swap nums[1] with nums[2]. The array becomes [1,6,7,18,2,1]\n- Swap nums[0] with nums[4]. The array becomes [2,6,7,18,1,1]\n- Swap nums[0] with nums[5]. The array becomes [1,6,7,18,1,2]\nWe cannot obtain a lexicographically smaller array by applying any more operations.\n\nExample 3:\n\nInput: nums = [1,7,28,19,10], limit = 3\nOutput: [1,7,28,19,10]\nExplanation: [1,7,28,19,10] is the lexicographically smallest array we can obtain because we cannot apply the operation on any two indices.\n\n\nConstraints:\n\n1 <= nums.length <= 105\n1 <= nums[i] <= 109\n1 <= limit <= 109\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def lexicographicallySmallestArray(self, nums: List[int], limit: int) -> List[int]:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,5,3,9,8], \"limit\": 2 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [1,3,5,8,9]\n\ntest_input = { \"nums\": [1,7,6,18,2,1], \"limit\": 3 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [1,6,7,18,1,2]\n\ntest_input = { \"nums\": [1,7,28,19,10], \"limit\": 3 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [1,7,28,19,10]\n\ntest_input = { \"nums\": [1000000000], \"limit\": 1 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [1000000000]\n\ntest_input = { \"nums\": [1,60,34,84,62,56,39,76,49,38], \"limit\": 4 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [1,56,34,84,60,62,38,76,49,39]\n\ntest_input = { \"nums\": [1,81,10,79,36,2,87,12,20,77], \"limit\": 7 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [1,77,10,79,36,2,81,12,20,87]\n\ntest_input = { \"nums\": [2,71,5,87,11,15,70,70,14,38], \"limit\": 14 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [2,70,5,87,11,14,70,71,15,38]\n\ntest_input = { \"nums\": [4,3,23,84,34,88,44,44,18,15], \"limit\": 3 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [3,4,23,84,34,88,44,44,15,18]\n\ntest_input = { \"nums\": [4,34,29,73,51,11,8,53,98,47], \"limit\": 10 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [4,29,34,73,47,8,11,51,98,53]\n\ntest_input = { \"nums\": [4,52,38,59,71,27,31,83,88,10], \"limit\": 14 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [4,27,31,38,52,59,71,83,88,10]\n\ntest_input = { \"nums\": [4,68,8,10,70,62,27,5,42,61], \"limit\": 11 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [4,61,5,8,62,68,27,10,42,70]\n\ntest_input = { \"nums\": [5,9,35,60,73,91,61,57,87,76], \"limit\": 11 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [5,9,35,57,73,76,60,61,87,91]\n\ntest_input = { \"nums\": [5,15,68,47,49,67,9,6,35,14], \"limit\": 4 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [5,14,67,47,49,68,6,9,35,15]\n\ntest_input = { \"nums\": [5,16,43,15,66,21,58,74,55,66], \"limit\": 9 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [5,15,43,16,55,21,58,66,66,74]\n\ntest_input = { \"nums\": [5,30,92,4,31,2,17,39,15,7], \"limit\": 3 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [2,30,92,4,31,5,15,39,17,7]\n\ntest_input = { \"nums\": [5,38,68,80,64,79,50,5,8,95], \"limit\": 7 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [5,38,64,79,68,80,50,5,8,95]\n\ntest_input = { \"nums\": [5,100,44,45,16,30,14,65,83,64], \"limit\": 15 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [5,100,14,16,30,44,45,64,83,65]\n\ntest_input = { \"nums\": [6,57,100,67,4,63,47,59,21,66], \"limit\": 8 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [4,57,100,59,6,63,47,66,21,67]\n\ntest_input = { \"nums\": [6,70,90,1,33,81,60,80,68,44], \"limit\": 7 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [1,68,90,6,33,80,60,81,70,44]\n\ntest_input = { \"nums\": [6,74,74,74,30,70,91,74,76,41], \"limit\": 1 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [6,74,74,74,30,70,91,74,76,41]\n\ntest_input = { \"nums\": [6,77,68,15,3,98,56,22,81,72], \"limit\": 2 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [6,77,68,15,3,98,56,22,81,72]\n\ntest_input = { \"nums\": [7,17,79,29,29,83,21,12,5,1], \"limit\": 10 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [1,5,79,7,12,83,17,21,29,29]\n\ntest_input = { \"nums\": [7,66,85,9,29,1,25,69,57,95], \"limit\": 13 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [1,57,85,7,25,9,29,66,69,95]\n\ntest_input = { \"nums\": [7,73,1,97,13,55,74,29,76,19], \"limit\": 14 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [1,73,7,97,13,55,74,19,76,29]\n\ntest_input = { \"nums\": [8,4,47,23,73,79,63,62,35,51], \"limit\": 11 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [4,8,47,23,51,62,63,73,35,79]\n\ntest_input = { \"nums\": [8,17,20,100,59,98,64,78,64,53], \"limit\": 1 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [8,17,20,100,59,98,64,78,64,53]\n\ntest_input = { \"nums\": [8,70,99,5,49,27,79,2,57,49], \"limit\": 14 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [2,49,99,5,49,27,57,8,70,79]\n\ntest_input = { \"nums\": [9,67,94,37,5,90,43,13,27,21], \"limit\": 11 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [5,67,90,9,13,94,21,27,37,43]\n\ntest_input = { \"nums\": [10,22,17,76,6,64,51,60,65,37], \"limit\": 9 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [6,10,17,76,22,51,60,64,65,37]\n\ntest_input = { \"nums\": [10,34,63,88,76,30,70,80,52,13], \"limit\": 7 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [10,30,63,88,70,34,76,80,52,13]\n\ntest_input = { \"nums\": [10,69,4,28,15,30,23,53,41,93], \"limit\": 9 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [4,69,10,15,23,28,30,53,41,93]\n\ntest_input = { \"nums\": [12,86,98,73,64,77,30,76,46,69], \"limit\": 4 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [12,86,98,69,64,73,30,76,46,77]\n\ntest_input = { \"nums\": [13,43,32,15,45,69,58,89,64,76], \"limit\": 12 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [13,32,43,15,45,58,64,89,69,76]\n\ntest_input = { \"nums\": [13,70,11,74,73,21,4,45,95,38], \"limit\": 9 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [4,70,11,73,74,13,21,38,95,45]\n\ntest_input = { \"nums\": [14,15,53,11,38,18,27,69,55,2], \"limit\": 13 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [2,11,53,14,15,18,27,69,55,38]\n\ntest_input = { \"nums\": [14,28,61,49,10,25,80,83,42,100], \"limit\": 3 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [14,25,61,49,10,28,80,83,42,100]\n\ntest_input = { \"nums\": [14,71,7,77,99,90,20,81,100,65], \"limit\": 7 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [7,65,14,71,99,90,20,77,100,81]\n\ntest_input = { \"nums\": [14,95,75,100,33,98,88,2,74,26], \"limit\": 1 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [14,95,74,100,33,98,88,2,75,26]\n\ntest_input = { \"nums\": [15,29,16,37,10,70,58,5,33,76], \"limit\": 8 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [5,29,10,33,15,70,58,16,37,76]\n\ntest_input = { \"nums\": [15,33,1,74,47,6,60,95,78,72], \"limit\": 7 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [15,33,1,72,47,6,60,95,74,78]\n\ntest_input = { \"nums\": [16,20,79,92,17,7,70,41,54,18], \"limit\": 6 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [16,17,79,92,18,7,70,41,54,20]\n\ntest_input = { \"nums\": [16,43,19,36,99,15,70,89,45,71], \"limit\": 4 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [15,43,16,36,99,19,70,89,45,71]\n\ntest_input = { \"nums\": [17,99,88,73,13,1,3,5,55,4], \"limit\": 15 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [1,73,88,99,3,4,5,13,55,17]\n\ntest_input = { \"nums\": [18,97,57,1,23,36,77,80,47,91], \"limit\": 10 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [18,91,47,1,23,36,77,80,57,97]\n\ntest_input = { \"nums\": [19,25,49,96,35,69,81,81,51,50], \"limit\": 12 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [19,25,49,96,35,69,81,81,50,51]\n\ntest_input = { \"nums\": [19,37,12,11,70,99,88,36,64,9], \"limit\": 3 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [19,36,9,11,70,99,88,37,64,12]\n\ntest_input = { \"nums\": [19,64,26,5,70,10,17,66,51,36], \"limit\": 13 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [5,51,10,17,64,19,26,66,70,36]\n\ntest_input = { \"nums\": [21,14,21,34,4,88,39,62,30,20], \"limit\": 12 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [4,14,20,21,21,88,30,62,34,39]\n\ntest_input = { \"nums\": [22,94,100,54,97,14,100,48,41,35], \"limit\": 6 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [22,94,97,48,100,14,100,54,35,41]\n\ntest_input = { \"nums\": [23,50,8,48,62,26,92,5,96,9], \"limit\": 13 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [23,48,5,50,62,26,92,8,96,9]\n\ntest_input = { \"nums\": [25,47,34,69,36,91,14,44,37,2], \"limit\": 1 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [25,47,34,69,36,91,14,44,37,2]\n\ntest_input = { \"nums\": [25,58,36,16,42,57,17,96,10,2], \"limit\": 13 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [2,57,10,16,17,58,25,96,36,42]\n\ntest_input = { \"nums\": [26,21,9,15,94,47,52,86,89,7], \"limit\": 9 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [7,9,15,21,86,47,52,89,94,26]\n\ntest_input = { \"nums\": [27,26,24,2,95,90,41,14,20,35], \"limit\": 2 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [24,26,27,2,95,90,41,14,20,35]\n\ntest_input = { \"nums\": [27,56,68,41,39,80,60,36,24,5], \"limit\": 13 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [24,56,60,27,36,68,80,39,41,5]\n\ntest_input = { \"nums\": [27,71,52,71,68,2,49,37,34,97], \"limit\": 8 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [27,68,49,71,71,2,52,34,37,97]\n\ntest_input = { \"nums\": [29,82,25,91,17,9,38,25,29,68], \"limit\": 7 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [25,82,25,91,17,9,38,29,29,68]\n\ntest_input = { \"nums\": [30,48,76,86,21,1,55,49,90,9], \"limit\": 2 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [30,48,76,86,21,1,55,49,90,9]\n\ntest_input = { \"nums\": [31,10,64,15,60,32,88,79,79,33], \"limit\": 2 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [31,10,64,15,60,32,88,79,79,33]\n\ntest_input = { \"nums\": [32,70,43,51,40,73,56,39,75,45], \"limit\": 8 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [32,70,39,40,43,73,45,51,75,56]\n\ntest_input = { \"nums\": [32,95,51,87,29,43,21,55,45,84], \"limit\": 2 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [32,95,51,87,29,43,21,55,45,84]\n\ntest_input = { \"nums\": [33,25,25,65,82,71,56,82,13,46], \"limit\": 14 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [13,25,25,33,46,56,65,71,82,82]\n\ntest_input = { \"nums\": [33,37,77,41,83,75,96,97,4,60], \"limit\": 15 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [33,37,60,41,75,77,83,96,4,97]\n\ntest_input = { \"nums\": [35,81,18,79,47,53,20,2,98,22], \"limit\": 2 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [35,79,18,81,47,53,20,2,98,22]\n\ntest_input = { \"nums\": [36,39,100,4,44,33,65,11,15,35], \"limit\": 10 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [33,35,100,4,36,39,65,11,15,44]\n\ntest_input = { \"nums\": [38,56,60,98,21,15,70,37,24,61], \"limit\": 15 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [15,56,60,98,21,24,61,37,38,70]\n\ntest_input = { \"nums\": [39,36,18,39,99,51,68,92,5,38], \"limit\": 4 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [36,38,18,39,99,51,68,92,5,39]\n\ntest_input = { \"nums\": [39,89,81,37,67,37,98,89,49,47], \"limit\": 12 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [37,81,89,37,67,39,89,98,47,49]\n\ntest_input = { \"nums\": [40,67,99,53,95,47,59,99,64,44], \"limit\": 7 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [40,44,95,47,99,53,59,99,64,67]\n\ntest_input = { \"nums\": [40,97,72,48,55,91,83,82,91,63], \"limit\": 11 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [40,48,55,63,72,82,83,91,91,97]\n\ntest_input = { \"nums\": [41,10,22,43,17,38,67,7,68,70], \"limit\": 7 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [38,7,10,41,17,43,67,22,68,70]\n\ntest_input = { \"nums\": [41,25,83,44,39,37,67,33,58,5], \"limit\": 1 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [41,25,83,44,39,37,67,33,58,5]\n\ntest_input = { \"nums\": [41,87,34,74,77,62,18,28,5,8], \"limit\": 1 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [41,87,34,74,77,62,18,28,5,8]\n\ntest_input = { \"nums\": [45,1,66,44,45,74,75,96,31,47], \"limit\": 2 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [44,1,66,45,45,74,75,96,31,47]\n\ntest_input = { \"nums\": [45,64,77,71,73,6,24,55,82,25], \"limit\": 3 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [45,64,77,71,73,6,24,55,82,25]\n\ntest_input = { \"nums\": [46,72,1,33,1,51,78,96,44,20], \"limit\": 1 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [46,72,1,33,1,51,78,96,44,20]\n\ntest_input = { \"nums\": [47,32,72,79,16,69,85,70,87,73], \"limit\": 2 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [47,32,69,79,16,70,85,72,87,73]\n\ntest_input = { \"nums\": [47,94,72,49,50,62,17,22,85,86], \"limit\": 7 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [47,94,72,49,50,62,17,22,85,86]\n\ntest_input = { \"nums\": [48,39,45,58,26,57,38,63,82,80], \"limit\": 2 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [48,38,45,57,26,58,39,63,80,82]\n\ntest_input = { \"nums\": [48,51,51,39,54,56,57,6,1,40], \"limit\": 2 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [48,51,51,39,54,56,57,6,1,40]\n\ntest_input = { \"nums\": [49,4,95,24,20,12,70,60,82,62], \"limit\": 11 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [49,4,95,12,20,24,60,62,82,70]\n\ntest_input = { \"nums\": [49,7,92,79,43,88,31,89,36,97], \"limit\": 8 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [31,7,88,79,36,89,43,92,49,97]\n\ntest_input = { \"nums\": [49,16,32,11,7,57,69,41,52,23], \"limit\": 15 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [7,11,16,23,32,41,49,52,57,69]\n\ntest_input = { \"nums\": [49,26,82,77,52,76,90,23,64,42], \"limit\": 12 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [42,23,49,52,64,76,77,26,82,90]\n\ntest_input = { \"nums\": [49,62,63,32,57,22,74,87,42,19], \"limit\": 13 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [19,22,32,42,49,57,62,63,74,87]\n\ntest_input = { \"nums\": [49,93,5,15,56,2,65,74,82,42], \"limit\": 13 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [42,49,2,5,56,15,65,74,82,93]\n\ntest_input = { \"nums\": [49,93,100,79,76,14,90,32,4,5], \"limit\": 10 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [49,90,93,76,79,4,100,32,5,14]\n\ntest_input = { \"nums\": [49,96,75,44,74,78,82,40,43,68], \"limit\": 4 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [49,96,74,40,75,78,82,43,44,68]\n\ntest_input = { \"nums\": [51,61,49,11,69,78,40,98,68,36], \"limit\": 10 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [36,40,49,11,51,61,68,98,69,78]\n\ntest_input = { \"nums\": [51,99,52,80,83,69,18,49,71,13], \"limit\": 14 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [49,99,51,69,71,80,13,52,83,18]\n\ntest_input = { \"nums\": [52,28,93,16,33,37,37,21,47,64], \"limit\": 12 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [16,21,93,28,33,37,37,47,52,64]\n\ntest_input = { \"nums\": [53,7,99,22,3,50,62,70,56,40], \"limit\": 2 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [53,7,99,22,3,50,62,70,56,40]\n\ntest_input = { \"nums\": [53,17,39,72,5,78,40,3,84,20], \"limit\": 5 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [53,17,39,72,3,78,40,5,84,20]\n\ntest_input = { \"nums\": [53,71,55,38,26,89,20,98,55,21], \"limit\": 4 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [53,71,55,38,26,89,20,98,55,21]\n\ntest_input = { \"nums\": [53,71,74,7,99,64,95,99,90,22], \"limit\": 9 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [53,64,71,7,90,74,95,99,99,22]\n\ntest_input = { \"nums\": [55,19,82,86,12,64,44,76,88,31], \"limit\": 4 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [55,19,82,86,12,64,44,76,88,31]\n\ntest_input = { \"nums\": [56,13,55,1,18,36,45,25,20,52], \"limit\": 14 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [1,13,18,20,25,36,45,52,55,56]\n\ntest_input = { \"nums\": [56,28,50,100,56,99,80,71,6,5], \"limit\": 7 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [50,28,56,99,56,100,80,71,5,6]\n\ntest_input = { \"nums\": [56,35,19,2,83,20,96,42,33,68], \"limit\": 3 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [56,33,19,2,83,20,96,42,35,68]\n\ntest_input = { \"nums\": [56,69,94,21,65,46,64,91,75,25], \"limit\": 5 }\nassert my_solution.lexicographicallySmallestArray(**test_input) == [56,64,91,21,65,46,69,94,75,25]", "start_time": 1700965800} +{"task_id": "weekly-contest-373-count-beautiful-substrings-ii", "url": "https://leetcode.com/problems/count-beautiful-substrings-ii", "title": "count-beautiful-substrings-ii", "meta": {"questionId": "3208", "questionFrontendId": "2949", "title": "Count Beautiful Substrings II", "titleSlug": "count-beautiful-substrings-ii", "isPaidOnly": false, "difficulty": "Hard", "likes": 137, "dislikes": 3, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a string s and a positive integer k.\nLet vowels and consonants be the number of vowels and consonants in a string.\nA string is beautiful if:\n\nvowels == consonants.\n(vowels * consonants) % k == 0, in other terms the multiplication of vowels and consonants is divisible by k.\n\nReturn the number of non-empty beautiful substrings in the given string s.\nA substring is a contiguous sequence of characters in a string.\nVowel letters in English are 'a', 'e', 'i', 'o', and 'u'.\nConsonant letters in English are every letter except vowels.\n\nExample 1:\n\nInput: s = \"baeyh\", k = 2\nOutput: 2\nExplanation: There are 2 beautiful substrings in the given string.\n- Substring \"baeyh\", vowels = 2 ([\"a\",e\"]), consonants = 2 ([\"y\",\"h\"]).\nYou can see that string \"aeyh\" is beautiful as vowels == consonants and vowels * consonants % k == 0.\n- Substring \"baeyh\", vowels = 2 ([\"a\",e\"]), consonants = 2 ([\"b\",\"y\"]).\nYou can see that string \"baey\" is beautiful as vowels == consonants and vowels * consonants % k == 0.\nIt can be shown that there are only 2 beautiful substrings in the given string.\n\nExample 2:\n\nInput: s = \"abba\", k = 1\nOutput: 3\nExplanation: There are 3 beautiful substrings in the given string.\n- Substring \"abba\", vowels = 1 ([\"a\"]), consonants = 1 ([\"b\"]).\n- Substring \"abba\", vowels = 1 ([\"a\"]), consonants = 1 ([\"b\"]).\n- Substring \"abba\", vowels = 2 ([\"a\",\"a\"]), consonants = 2 ([\"b\",\"b\"]).\nIt can be shown that there are only 3 beautiful substrings in the given string.\n\nExample 3:\n\nInput: s = \"bcdf\", k = 1\nOutput: 0\nExplanation: There are no beautiful substrings in the given string.\n\n\nConstraints:\n\n1 <= s.length <= 5 * 104\n1 <= k <= 1000\ns consists of only English lowercase letters.\n\"\"\"\nclass Solution:\n def beautifulSubstrings(self, s: str, k: int) -> int:\n ", "prompt_sft": "You are given a string s and a positive integer k.\nLet vowels and consonants be the number of vowels and consonants in a string.\nA string is beautiful if:\n\nvowels == consonants.\n(vowels * consonants) % k == 0, in other terms the multiplication of vowels and consonants is divisible by k.\n\nReturn the number of non-empty beautiful substrings in the given string s.\nA substring is a contiguous sequence of characters in a string.\nVowel letters in English are 'a', 'e', 'i', 'o', and 'u'.\nConsonant letters in English are every letter except vowels.\n\nExample 1:\n\nInput: s = \"baeyh\", k = 2\nOutput: 2\nExplanation: There are 2 beautiful substrings in the given string.\n- Substring \"baeyh\", vowels = 2 ([\"a\",e\"]), consonants = 2 ([\"y\",\"h\"]).\nYou can see that string \"aeyh\" is beautiful as vowels == consonants and vowels * consonants % k == 0.\n- Substring \"baeyh\", vowels = 2 ([\"a\",e\"]), consonants = 2 ([\"b\",\"y\"]).\nYou can see that string \"baey\" is beautiful as vowels == consonants and vowels * consonants % k == 0.\nIt can be shown that there are only 2 beautiful substrings in the given string.\n\nExample 2:\n\nInput: s = \"abba\", k = 1\nOutput: 3\nExplanation: There are 3 beautiful substrings in the given string.\n- Substring \"abba\", vowels = 1 ([\"a\"]), consonants = 1 ([\"b\"]).\n- Substring \"abba\", vowels = 1 ([\"a\"]), consonants = 1 ([\"b\"]).\n- Substring \"abba\", vowels = 2 ([\"a\",\"a\"]), consonants = 2 ([\"b\",\"b\"]).\nIt can be shown that there are only 3 beautiful substrings in the given string.\n\nExample 3:\n\nInput: s = \"bcdf\", k = 1\nOutput: 0\nExplanation: There are no beautiful substrings in the given string.\n\n\nConstraints:\n\n1 <= s.length <= 5 * 104\n1 <= k <= 1000\ns consists of only English lowercase letters.\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def beautifulSubstrings(self, s: str, k: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"s\": \"baeyh\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 2\n\ntest_input = { \"s\": \"abba\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 3\n\ntest_input = { \"s\": \"bcdf\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"ihroyeeb\", \"k\": 5 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"uzuxpzou\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 1\n\ntest_input = { \"s\": \"ouuoeqd\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 1\n\ntest_input = { \"s\": \"eeebjoxxujuaeoqibd\", \"k\": 8 }\nassert my_solution.beautifulSubstrings(**test_input) == 4\n\ntest_input = { \"s\": \"ilougekqlovegioemdvu\", \"k\": 4 }\nassert my_solution.beautifulSubstrings(**test_input) == 21\n\ntest_input = { \"s\": \"tqaewreikaztwpfwnef\", \"k\": 8 }\nassert my_solution.beautifulSubstrings(**test_input) == 3\n\ntest_input = { \"s\": \"oykiuhsafgfjumnzb\", \"k\": 7 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"ifvsa\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"svzauyuevujektj\", \"k\": 5 }\nassert my_solution.beautifulSubstrings(**test_input) == 3\n\ntest_input = { \"s\": \"urahjig\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 2\n\ntest_input = { \"s\": \"ime\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"oacghieut\", \"k\": 5 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"aoluu\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"ioaoiciiuoziout\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 5\n\ntest_input = { \"s\": \"ouafupsuhid\", \"k\": 6 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"ox\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"tlaiwoauazutusiaaui\", \"k\": 10 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"caepeym\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 2\n\ntest_input = { \"s\": \"apyxvceue\", \"k\": 4 }\nassert my_solution.beautifulSubstrings(**test_input) == 1\n\ntest_input = { \"s\": \"imkqbb\", \"k\": 4 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"caaz\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 1\n\ntest_input = { \"s\": \"pyicoy\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 6\n\ntest_input = { \"s\": \"uopmyrsntjhiroikup\", \"k\": 8 }\nassert my_solution.beautifulSubstrings(**test_input) == 2\n\ntest_input = { \"s\": \"aujfxqxcj\", \"k\": 5 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"eeizejuoxeumz\", \"k\": 4 }\nassert my_solution.beautifulSubstrings(**test_input) == 6\n\ntest_input = { \"s\": \"uuouuaifnboeiulttio\", \"k\": 4 }\nassert my_solution.beautifulSubstrings(**test_input) == 10\n\ntest_input = { \"s\": \"woozzxd\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"pulorolqcvhafexui\", \"k\": 9 }\nassert my_solution.beautifulSubstrings(**test_input) == 3\n\ntest_input = { \"s\": \"hmuaewojioizoguvoaje\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 4\n\ntest_input = { \"s\": \"b\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"aiejouohnqnketinvat\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 6\n\ntest_input = { \"s\": \"mjiogpri\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 3\n\ntest_input = { \"s\": \"movbyaeouil\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 2\n\ntest_input = { \"s\": \"puureouausxmitvav\", \"k\": 6 }\nassert my_solution.beautifulSubstrings(**test_input) == 2\n\ntest_input = { \"s\": \"op\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 1\n\ntest_input = { \"s\": \"iuhoezpooxcohtlapolo\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 39\n\ntest_input = { \"s\": \"cioi\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"pueutaoyaxk\", \"k\": 6 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"iiuresacruaaan\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 3\n\ntest_input = { \"s\": \"agntyaazvpejidwaph\", \"k\": 8 }\nassert my_solution.beautifulSubstrings(**test_input) == 1\n\ntest_input = { \"s\": \"wiybolyniexiibou\", \"k\": 6 }\nassert my_solution.beautifulSubstrings(**test_input) == 2\n\ntest_input = { \"s\": \"coiyakadxi\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 8\n\ntest_input = { \"s\": \"oraajoeruiakixj\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 1\n\ntest_input = { \"s\": \"jeayap\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 7\n\ntest_input = { \"s\": \"iu\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"awozoy\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 3\n\ntest_input = { \"s\": \"fheabmlsyeeeuoeogyz\", \"k\": 9 }\nassert my_solution.beautifulSubstrings(**test_input) == 5\n\ntest_input = { \"s\": \"eaizneuxi\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 10\n\ntest_input = { \"s\": \"uurqufaucsuoqljh\", \"k\": 4 }\nassert my_solution.beautifulSubstrings(**test_input) == 14\n\ntest_input = { \"s\": \"jrtept\", \"k\": 4 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"olgioxooiejooosaed\", \"k\": 5 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"uizoy\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 1\n\ntest_input = { \"s\": \"lswabfiujjhexzos\", \"k\": 4 }\nassert my_solution.beautifulSubstrings(**test_input) == 5\n\ntest_input = { \"s\": \"iuu\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"qeaxut\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 7\n\ntest_input = { \"s\": \"aojiau\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"oaiaaaargkonlcsoaygf\", \"k\": 5 }\nassert my_solution.beautifulSubstrings(**test_input) == 2\n\ntest_input = { \"s\": \"zoowrawkm\", \"k\": 4 }\nassert my_solution.beautifulSubstrings(**test_input) == 3\n\ntest_input = { \"s\": \"uqiwuoevkfhkkua\", \"k\": 4 }\nassert my_solution.beautifulSubstrings(**test_input) == 6\n\ntest_input = { \"s\": \"kavuaaeodvaxicm\", \"k\": 6 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"qpxeceq\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 6\n\ntest_input = { \"s\": \"iaabaofuodcbek\", \"k\": 5 }\nassert my_solution.beautifulSubstrings(**test_input) == 3\n\ntest_input = { \"s\": \"eel\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 1\n\ntest_input = { \"s\": \"ikeuhe\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 5\n\ntest_input = { \"s\": \"lueikvo\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 2\n\ntest_input = { \"s\": \"oauau\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"qzoieeotieeakqraeao\", \"k\": 4 }\nassert my_solution.beautifulSubstrings(**test_input) == 4\n\ntest_input = { \"s\": \"ehaascocsdmgekni\", \"k\": 9 }\nassert my_solution.beautifulSubstrings(**test_input) == 3\n\ntest_input = { \"s\": \"euqeklniykiji\", \"k\": 5 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"vaeiiioidiioxhduu\", \"k\": 7 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"aa\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"chaua\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"edfrglfr\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"dqbe\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 1\n\ntest_input = { \"s\": \"ghooirorxge\", \"k\": 4 }\nassert my_solution.beautifulSubstrings(**test_input) == 6\n\ntest_input = { \"s\": \"fodartekaonq\", \"k\": 4 }\nassert my_solution.beautifulSubstrings(**test_input) == 9\n\ntest_input = { \"s\": \"feeanzkjpfehzeuni\", \"k\": 6 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"ignoouesduu\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 6\n\ntest_input = { \"s\": \"yif\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"gondfjaeeuhbuuasgip\", \"k\": 10 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"djooomsffoonelyeode\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 14\n\ntest_input = { \"s\": \"pgaimei\", \"k\": 4 }\nassert my_solution.beautifulSubstrings(**test_input) == 2\n\ntest_input = { \"s\": \"naipqentonee\", \"k\": 4 }\nassert my_solution.beautifulSubstrings(**test_input) == 8\n\ntest_input = { \"s\": \"bouov\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"lcuhoypz\", \"k\": 5 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"g\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"qc\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"mhznea\", \"k\": 2 }\nassert my_solution.beautifulSubstrings(**test_input) == 1\n\ntest_input = { \"s\": \"uxvjixdujgyfauo\", \"k\": 8 }\nassert my_solution.beautifulSubstrings(**test_input) == 1\n\ntest_input = { \"s\": \"iyjkuox\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 1\n\ntest_input = { \"s\": \"xbjfoayfpafatnuyord\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 3\n\ntest_input = { \"s\": \"nvoede\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 1\n\ntest_input = { \"s\": \"usnuaxpaktrweatruu\", \"k\": 5 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"euojmsora\", \"k\": 1 }\nassert my_solution.beautifulSubstrings(**test_input) == 10\n\ntest_input = { \"s\": \"iapgoi\", \"k\": 3 }\nassert my_solution.beautifulSubstrings(**test_input) == 0\n\ntest_input = { \"s\": \"uafuimcpxyeoixgbyeio\", \"k\": 5 }\nassert my_solution.beautifulSubstrings(**test_input) == 3\n\ntest_input = { \"s\": \"weuaatpu\", \"k\": 5 }\nassert my_solution.beautifulSubstrings(**test_input) == 0", "start_time": 1700965800} +{"task_id": "biweekly-contest-118-find-words-containing-character", "url": "https://leetcode.com/problems/find-words-containing-character", "title": "find-words-containing-character", "meta": {"questionId": "3194", "questionFrontendId": "2942", "title": "Find Words Containing Character", "titleSlug": "find-words-containing-character", "isPaidOnly": false, "difficulty": "Easy", "likes": 134, "dislikes": 4, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed array of strings words and a character x.\nReturn an array of indices representing the words that contain the character x.\nNote that the returned array may be in any order.\n\nExample 1:\n\nInput: words = [\"leet\",\"code\"], x = \"e\"\nOutput: [0,1]\nExplanation: \"e\" occurs in both words: \"leet\", and \"code\". Hence, we return indices 0 and 1.\n\nExample 2:\n\nInput: words = [\"abc\",\"bcd\",\"aaaa\",\"cbc\"], x = \"a\"\nOutput: [0,2]\nExplanation: \"a\" occurs in \"abc\", and \"aaaa\". Hence, we return indices 0 and 2.\n\nExample 3:\n\nInput: words = [\"abc\",\"bcd\",\"aaaa\",\"cbc\"], x = \"z\"\nOutput: []\nExplanation: \"z\" does not occur in any of the words. Hence, we return an empty array.\n\n\nConstraints:\n\n1 <= words.length <= 50\n1 <= words[i].length <= 50\nx is a lowercase English letter.\nwords[i] consists only of lowercase English letters.\n\"\"\"\nclass Solution:\n def findWordsContaining(self, words: List[str], x: str) -> List[int]:\n ", "prompt_sft": "You are given a 0-indexed array of strings words and a character x.\nReturn an array of indices representing the words that contain the character x.\nNote that the returned array may be in any order.\n\nExample 1:\n\nInput: words = [\"leet\",\"code\"], x = \"e\"\nOutput: [0,1]\nExplanation: \"e\" occurs in both words: \"leet\", and \"code\". Hence, we return indices 0 and 1.\n\nExample 2:\n\nInput: words = [\"abc\",\"bcd\",\"aaaa\",\"cbc\"], x = \"a\"\nOutput: [0,2]\nExplanation: \"a\" occurs in \"abc\", and \"aaaa\". Hence, we return indices 0 and 2.\n\nExample 3:\n\nInput: words = [\"abc\",\"bcd\",\"aaaa\",\"cbc\"], x = \"z\"\nOutput: []\nExplanation: \"z\" does not occur in any of the words. Hence, we return an empty array.\n\n\nConstraints:\n\n1 <= words.length <= 50\n1 <= words[i].length <= 50\nx is a lowercase English letter.\nwords[i] consists only of lowercase English letters.\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def findWordsContaining(self, words: List[str], x: str) -> List[int]:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"words\": [\"leet\",\"code\"], \"x\": \"e\" }\nassert my_solution.findWordsContaining(**test_input) == [0,1]\n\ntest_input = { \"words\": [\"abc\",\"bcd\",\"aaaa\",\"cbc\"], \"x\": \"a\" }\nassert my_solution.findWordsContaining(**test_input) == [0,2]\n\ntest_input = { \"words\": [\"abc\",\"bcd\",\"aaaa\",\"cbc\"], \"x\": \"z\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"sgtkshnss\",\"m\",\"ryvbkyvuz\",\"ezittyjwgb\",\"wudlwg\"], \"x\": \"x\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"lkwnhpbj\",\"tlohm\",\"juazsb\",\"f\",\"rq\"], \"x\": \"v\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"aaa\",\"imvtfjmxr\",\"wbzfoovjnf\",\"hqwrwmi\"], \"x\": \"c\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"utyeachht\",\"bgpkcs\",\"skeecqvvvw\",\"nccrd\"], \"x\": \"i\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"alcpxexztg\",\"r\"], \"x\": \"h\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"ekcpg\",\"pdknua\",\"fot\",\"janppw\",\"ofomkfvx\"], \"x\": \"g\" }\nassert my_solution.findWordsContaining(**test_input) == [0]\n\ntest_input = { \"words\": [\"dq\",\"rlvopu\"], \"x\": \"d\" }\nassert my_solution.findWordsContaining(**test_input) == [0]\n\ntest_input = { \"words\": [\"wzppkd\",\"jxvk\",\"zaztizmwuv\",\"hvcdtobr\"], \"x\": \"b\" }\nassert my_solution.findWordsContaining(**test_input) == [3]\n\ntest_input = { \"words\": [\"y\",\"hs\",\"qznrkpi\"], \"x\": \"v\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"pze\",\"yojczsb\",\"mjvyr\",\"i\",\"xsygks\"], \"x\": \"q\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"qsgtjagcu\",\"m\"], \"x\": \"e\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"kidtwmw\",\"ogh\",\"trdedlh\",\"wwbtlindg\",\"naoylytpof\",\"ujcbzwzkm\",\"doamcoxdv\"], \"x\": \"o\" }\nassert my_solution.findWordsContaining(**test_input) == [1,4,6]\n\ntest_input = { \"words\": [\"tsmeupctki\"], \"x\": \"t\" }\nassert my_solution.findWordsContaining(**test_input) == [0]\n\ntest_input = { \"words\": [\"dqxlbljmpf\",\"uvdzfoiqg\",\"jsnbnx\",\"fbedae\",\"nodewb\",\"o\",\"ivepktj\"], \"x\": \"g\" }\nassert my_solution.findWordsContaining(**test_input) == [1]\n\ntest_input = { \"words\": [\"fjlmmecm\",\"sautsoorhl\",\"n\",\"hsyco\",\"amlukrpjpv\",\"rmhdnj\",\"g\"], \"x\": \"e\" }\nassert my_solution.findWordsContaining(**test_input) == [0]\n\ntest_input = { \"words\": [\"khjchmeciv\",\"vgx\",\"xghr\",\"bbufgegu\",\"qyfxu\"], \"x\": \"r\" }\nassert my_solution.findWordsContaining(**test_input) == [2]\n\ntest_input = { \"words\": [\"jhtcugtcpl\",\"bvhlgmmla\",\"ntfkwzite\",\"imbtzafaj\",\"sdl\",\"t\"], \"x\": \"m\" }\nassert my_solution.findWordsContaining(**test_input) == [1,3]\n\ntest_input = { \"words\": [\"kxoziqoafc\",\"vifcxifq\"], \"x\": \"q\" }\nassert my_solution.findWordsContaining(**test_input) == [0,1]\n\ntest_input = { \"words\": [\"ckfkjjsonl\",\"scaaug\",\"rmvqzyiwc\",\"a\",\"smymw\"], \"x\": \"p\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"t\",\"exo\",\"npr\",\"skd\",\"bxpmbu\"], \"x\": \"e\" }\nassert my_solution.findWordsContaining(**test_input) == [1]\n\ntest_input = { \"words\": [\"eulsl\",\"fwooyct\",\"ypytexil\"], \"x\": \"c\" }\nassert my_solution.findWordsContaining(**test_input) == [1]\n\ntest_input = { \"words\": [\"nhd\",\"zheyegi\",\"ogz\",\"fpybmcc\",\"ntbbwtde\"], \"x\": \"g\" }\nassert my_solution.findWordsContaining(**test_input) == [1,2]\n\ntest_input = { \"words\": [\"gwzvusl\",\"upcpvbfyxy\",\"hg\",\"yu\",\"wsfqgzhh\",\"zgphqacsyo\"], \"x\": \"o\" }\nassert my_solution.findWordsContaining(**test_input) == [5]\n\ntest_input = { \"words\": [\"uiovpph\",\"xxj\",\"uwzxzvkobk\"], \"x\": \"r\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"abtrpwo\",\"sgaegnavk\",\"pfmv\"], \"x\": \"z\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"m\",\"fxtphsdmgy\",\"otq\",\"vwuhhnebr\",\"yen\"], \"x\": \"y\" }\nassert my_solution.findWordsContaining(**test_input) == [1,4]\n\ntest_input = { \"words\": [\"irlzx\",\"lbrknhl\",\"roupfj\",\"fskaieszo\",\"nz\",\"ijfyejq\"], \"x\": \"e\" }\nassert my_solution.findWordsContaining(**test_input) == [3,5]\n\ntest_input = { \"words\": [\"raavc\",\"tx\"], \"x\": \"l\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"bkpuvcrexw\",\"hxtbcdprhr\",\"ovt\",\"xgurm\",\"pjcz\",\"sbhwpjmyz\"], \"x\": \"g\" }\nassert my_solution.findWordsContaining(**test_input) == [3]\n\ntest_input = { \"words\": [\"f\",\"xlmy\",\"akbiqa\",\"fobo\"], \"x\": \"s\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"mhan\"], \"x\": \"a\" }\nassert my_solution.findWordsContaining(**test_input) == [0]\n\ntest_input = { \"words\": [\"uisx\"], \"x\": \"o\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"znqdolksyn\",\"keewspe\",\"ffod\",\"lah\",\"gadhym\",\"awnyymd\",\"fvkl\"], \"x\": \"v\" }\nassert my_solution.findWordsContaining(**test_input) == [6]\n\ntest_input = { \"words\": [\"ftujx\",\"dnbwrurk\",\"t\",\"x\",\"zjzhdl\",\"jc\"], \"x\": \"t\" }\nassert my_solution.findWordsContaining(**test_input) == [0,2]\n\ntest_input = { \"words\": [\"zrwf\",\"thp\",\"qecwlnq\",\"w\",\"teetdaxx\"], \"x\": \"t\" }\nassert my_solution.findWordsContaining(**test_input) == [1,4]\n\ntest_input = { \"words\": [\"xyzgb\",\"qflfrfqgaf\"], \"x\": \"l\" }\nassert my_solution.findWordsContaining(**test_input) == [1]\n\ntest_input = { \"words\": [\"shnjr\",\"qfvop\"], \"x\": \"y\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"fmwclqh\",\"xbphhgreze\",\"yi\",\"gmtzrfdab\",\"uicqa\",\"n\"], \"x\": \"i\" }\nassert my_solution.findWordsContaining(**test_input) == [2,4]\n\ntest_input = { \"words\": [\"jgkv\",\"njhwihtv\",\"v\"], \"x\": \"z\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"tqkwoofh\",\"bcgngl\",\"frjpqgrr\",\"drvb\"], \"x\": \"x\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"npkvocbw\",\"tn\",\"dp\",\"c\",\"g\",\"fsxvzcnty\",\"ywnf\"], \"x\": \"k\" }\nassert my_solution.findWordsContaining(**test_input) == [0]\n\ntest_input = { \"words\": [\"leompil\",\"vta\",\"fzrsps\",\"yp\",\"bykmgwgk\"], \"x\": \"o\" }\nassert my_solution.findWordsContaining(**test_input) == [0]\n\ntest_input = { \"words\": [\"umq\",\"c\",\"ctuh\",\"eadzeuui\",\"tabum\",\"isuct\"], \"x\": \"p\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"rnmpdkmrnb\",\"icxxsvss\",\"h\",\"gd\"], \"x\": \"s\" }\nassert my_solution.findWordsContaining(**test_input) == [1]\n\ntest_input = { \"words\": [\"ft\",\"hsjf\",\"e\",\"xi\"], \"x\": \"w\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"ozf\",\"xkehlkgp\",\"vliewlbv\",\"okgaahah\"], \"x\": \"b\" }\nassert my_solution.findWordsContaining(**test_input) == [2]\n\ntest_input = { \"words\": [\"gbktzr\",\"kbamubluz\",\"dwoi\",\"crhldx\",\"idjronpded\",\"rqaz\"], \"x\": \"c\" }\nassert my_solution.findWordsContaining(**test_input) == [3]\n\ntest_input = { \"words\": [\"gvbzqcb\",\"rwtbra\",\"iuijl\",\"qbmpbi\"], \"x\": \"c\" }\nassert my_solution.findWordsContaining(**test_input) == [0]\n\ntest_input = { \"words\": [\"lsh\",\"szhxhcdc\",\"quem\",\"zupiydjeqp\",\"czxyvysrrb\",\"aqnlqtnfiv\"], \"x\": \"p\" }\nassert my_solution.findWordsContaining(**test_input) == [3]\n\ntest_input = { \"words\": [\"leuah\",\"liaoczeuch\",\"ol\",\"ify\",\"layh\",\"ifzudwuybw\",\"x\"], \"x\": \"p\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"ksdpwwho\",\"ktunsikyu\"], \"x\": \"a\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"vpypaumzlp\",\"kqrb\",\"pgw\"], \"x\": \"l\" }\nassert my_solution.findWordsContaining(**test_input) == [0]\n\ntest_input = { \"words\": [\"jkrpnx\",\"c\",\"kqi\",\"xrsaviyusg\",\"waoxq\",\"fld\",\"otxfgcp\"], \"x\": \"l\" }\nassert my_solution.findWordsContaining(**test_input) == [5]\n\ntest_input = { \"words\": [\"tetw\",\"zl\",\"wd\",\"hnkxoxlnz\",\"dexgufawjd\",\"oolpr\",\"yyfwizbsl\"], \"x\": \"p\" }\nassert my_solution.findWordsContaining(**test_input) == [5]\n\ntest_input = { \"words\": [\"hihprd\",\"kitgiflc\",\"nr\",\"idduuahfkm\"], \"x\": \"x\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"flfxeca\",\"g\"], \"x\": \"e\" }\nassert my_solution.findWordsContaining(**test_input) == [0]\n\ntest_input = { \"words\": [\"st\",\"betf\",\"ipacxza\",\"jpnw\"], \"x\": \"r\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"cvuxnzaib\",\"c\",\"tiytr\",\"yiav\",\"hp\",\"yg\"], \"x\": \"d\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"yz\",\"k\",\"midujexvn\",\"kwcgbht\"], \"x\": \"y\" }\nassert my_solution.findWordsContaining(**test_input) == [0]\n\ntest_input = { \"words\": [\"qcxobdaxv\"], \"x\": \"q\" }\nassert my_solution.findWordsContaining(**test_input) == [0]\n\ntest_input = { \"words\": [\"b\",\"shrexcf\",\"ve\",\"eqpbnuy\",\"qdhahodo\",\"aerdf\",\"bdjlaakagk\"], \"x\": \"p\" }\nassert my_solution.findWordsContaining(**test_input) == [3]\n\ntest_input = { \"words\": [\"ympv\"], \"x\": \"q\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"thfy\",\"lnfzoyafiy\",\"qmc\",\"boijcl\",\"pvbzmsa\",\"yjarwylcyc\"], \"x\": \"e\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"hqptwi\"], \"x\": \"o\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"bv\",\"xgrhtjnxh\",\"fdtljkxa\",\"po\",\"hejof\"], \"x\": \"k\" }\nassert my_solution.findWordsContaining(**test_input) == [2]\n\ntest_input = { \"words\": [\"mfdrclyx\",\"pith\"], \"x\": \"e\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"bxeblhrl\",\"o\",\"uvv\"], \"x\": \"b\" }\nassert my_solution.findWordsContaining(**test_input) == [0]\n\ntest_input = { \"words\": [\"giygz\"], \"x\": \"u\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"ffqw\",\"nykncbxrqi\",\"pgzy\",\"of\",\"oye\",\"f\"], \"x\": \"g\" }\nassert my_solution.findWordsContaining(**test_input) == [2]\n\ntest_input = { \"words\": [\"jjnh\",\"nrbh\",\"z\"], \"x\": \"l\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"gdzkdtvrm\",\"ps\",\"kp\",\"sbdlkac\",\"s\",\"bt\"], \"x\": \"n\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"hpsk\",\"stjltzz\",\"gvbjwzktgg\",\"hmeovbxvv\",\"gqaxqoshbh\",\"mqnwyabqq\",\"sq\"], \"x\": \"f\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"gwmg\",\"qdjeaxgc\",\"rlajltxpd\",\"d\"], \"x\": \"g\" }\nassert my_solution.findWordsContaining(**test_input) == [0,1]\n\ntest_input = { \"words\": [\"dupx\",\"r\",\"j\",\"wq\",\"macfcfoz\"], \"x\": \"r\" }\nassert my_solution.findWordsContaining(**test_input) == [1]\n\ntest_input = { \"words\": [\"rmypzoyto\",\"wvhtrbuz\",\"dgt\",\"tmhqswmkx\",\"trpjwzitp\",\"tbetdxic\"], \"x\": \"t\" }\nassert my_solution.findWordsContaining(**test_input) == [0,1,2,3,4,5]\n\ntest_input = { \"words\": [\"vpkjymgdb\",\"s\",\"gv\",\"geie\"], \"x\": \"g\" }\nassert my_solution.findWordsContaining(**test_input) == [0,2,3]\n\ntest_input = { \"words\": [\"epnmbry\",\"hhfhprvqba\"], \"x\": \"l\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"zst\",\"mjzbdxsks\",\"dza\",\"neqj\",\"oqeilr\"], \"x\": \"d\" }\nassert my_solution.findWordsContaining(**test_input) == [1,2]\n\ntest_input = { \"words\": [\"ffruqk\",\"sse\",\"cyj\",\"tntq\",\"mibbhhpce\"], \"x\": \"c\" }\nassert my_solution.findWordsContaining(**test_input) == [2,4]\n\ntest_input = { \"words\": [\"vumzrbe\",\"qudq\",\"qfrt\"], \"x\": \"u\" }\nassert my_solution.findWordsContaining(**test_input) == [0,1]\n\ntest_input = { \"words\": [\"wcrrprvu\",\"fizkw\",\"vzcjxhjy\",\"e\"], \"x\": \"r\" }\nassert my_solution.findWordsContaining(**test_input) == [0]\n\ntest_input = { \"words\": [\"gjk\",\"vri\"], \"x\": \"n\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"fds\",\"vbmg\",\"p\",\"iesyvc\",\"wgmyxhoo\",\"yfllvzr\"], \"x\": \"f\" }\nassert my_solution.findWordsContaining(**test_input) == [0,5]\n\ntest_input = { \"words\": [\"mifbjo\",\"kpjlwfbas\",\"skhueysodn\",\"zeewicisy\"], \"x\": \"g\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"pvkmoccv\",\"j\"], \"x\": \"y\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"s\",\"uhcfwsssbe\",\"iwofeukmx\",\"yfta\",\"ovrdcb\",\"psnje\"], \"x\": \"s\" }\nassert my_solution.findWordsContaining(**test_input) == [0,1,5]\n\ntest_input = { \"words\": [\"klpzrjw\",\"qmrhbpa\"], \"x\": \"v\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"fzegksjmw\",\"masiwhjue\",\"gngsht\",\"xwvmp\",\"aahn\",\"dwxr\"], \"x\": \"c\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"mveahpesx\",\"tsqds\",\"g\",\"mux\",\"bivffitjx\",\"zfsqdje\"], \"x\": \"f\" }\nassert my_solution.findWordsContaining(**test_input) == [4,5]\n\ntest_input = { \"words\": [\"c\"], \"x\": \"a\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"jzmhnhqkq\"], \"x\": \"a\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"cfdgbc\",\"ltpvko\",\"batjenrlq\",\"edwefhw\"], \"x\": \"t\" }\nassert my_solution.findWordsContaining(**test_input) == [1,2]\n\ntest_input = { \"words\": [\"smlcojfydr\",\"slb\"], \"x\": \"r\" }\nassert my_solution.findWordsContaining(**test_input) == [0]\n\ntest_input = { \"words\": [\"lnjimir\"], \"x\": \"x\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"do\"], \"x\": \"e\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"xyyvbxsb\",\"dc\",\"mmqpb\",\"mmbwv\",\"wdreyof\",\"kpk\",\"reeb\"], \"x\": \"l\" }\nassert my_solution.findWordsContaining(**test_input) == []\n\ntest_input = { \"words\": [\"ytvyknnmzv\",\"jsoe\",\"wctzk\"], \"x\": \"i\" }\nassert my_solution.findWordsContaining(**test_input) == []", "start_time": 1700922600} +{"task_id": "biweekly-contest-118-maximize-area-of-square-hole-in-grid", "url": "https://leetcode.com/problems/maximize-area-of-square-hole-in-grid", "title": "maximize-area-of-square-hole-in-grid", "meta": {"questionId": "3214", "questionFrontendId": "2943", "title": "Maximize Area of Square Hole in Grid", "titleSlug": "maximize-area-of-square-hole-in-grid", "isPaidOnly": false, "difficulty": "Medium", "likes": 73, "dislikes": 110, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nThere is a grid with n + 2 horizontal bars and m + 2 vertical bars, and initially containing 1 x 1 unit cells.\nThe bars are 1-indexed.\nYou are given the two integers, n and m.\nYou are also given two integer arrays: hBars and vBars.\n\nhBars contains distinct horizontal bars in the range [2, n + 1].\nvBars contains distinct vertical bars in the range [2, m + 1].\n\nYou are allowed to remove bars that satisfy any of the following conditions:\n\nIf it is a horizontal bar, it must correspond to a value in hBars.\nIf it is a vertical bar, it must correspond to a value in vBars.\n\nReturn an integer denoting the maximum area of a square-shaped hole in the grid after removing some bars (possibly none).\n\nExample 1:\n\n\nInput: n = 2, m = 1, hBars = [2,3], vBars = [2]\nOutput: 4\nExplanation: The left image shows the initial grid formed by the bars.\nThe horizontal bars are in the range [1,4], and the vertical bars are in the range [1,3].\nIt is allowed to remove horizontal bars [2,3] and the vertical bar [2].\nOne way to get the maximum square-shaped hole is by removing horizontal bar 2 and vertical bar 2.\nThe resulting grid is shown on the right.\nThe hole has an area of 4.\nIt can be shown that it is not possible to get a square hole with an area more than 4.\nHence, the answer is 4.\n\nExample 2:\n\n\nInput: n = 1, m = 1, hBars = [2], vBars = [2]\nOutput: 4\nExplanation: The left image shows the initial grid formed by the bars.\nThe horizontal bars are in the range [1,3], and the vertical bars are in the range [1,3].\nIt is allowed to remove the horizontal bar [2] and the vertical bar [2].\nTo get the maximum square-shaped hole, we remove horizontal bar 2 and vertical bar 2.\nThe resulting grid is shown on the right.\nThe hole has an area of 4.\nHence, the answer is 4, and it is the maximum possible.\n\nExample 3:\n\n\nInput: n = 2, m = 3, hBars = [2,3], vBars = [2,3,4]\nOutput: 9\nExplanation: The left image shows the initial grid formed by the bars.\nThe horizontal bars are in the range [1,4], and the vertical bars are in the range [1,5].\nIt is allowed to remove horizontal bars [2,3] and vertical bars [2,3,4].\nOne way to get the maximum square-shaped hole is by removing horizontal bars 2 and 3, and vertical bars 3 and 4.\nThe resulting grid is shown on the right.\nThe hole has an area of 9.\nIt can be shown that it is not possible to get a square hole with an area more than 9.\nHence, the answer is 9.\n\n\nConstraints:\n\n1 <= n <= 109\n1 <= m <= 109\n1 <= hBars.length <= 100\n2 <= hBars[i] <= n + 1\n1 <= vBars.length <= 100\n2 <= vBars[i] <= m + 1\nAll values in hBars are distinct.\nAll values in vBars are distinct.\n\"\"\"\nclass Solution:\n def maximizeSquareHoleArea(self, n: int, m: int, hBars: List[int], vBars: List[int]) -> int:\n ", "prompt_sft": "There is a grid with n + 2 horizontal bars and m + 2 vertical bars, and initially containing 1 x 1 unit cells.\nThe bars are 1-indexed.\nYou are given the two integers, n and m.\nYou are also given two integer arrays: hBars and vBars.\n\nhBars contains distinct horizontal bars in the range [2, n + 1].\nvBars contains distinct vertical bars in the range [2, m + 1].\n\nYou are allowed to remove bars that satisfy any of the following conditions:\n\nIf it is a horizontal bar, it must correspond to a value in hBars.\nIf it is a vertical bar, it must correspond to a value in vBars.\n\nReturn an integer denoting the maximum area of a square-shaped hole in the grid after removing some bars (possibly none).\n\nExample 1:\n\n\nInput: n = 2, m = 1, hBars = [2,3], vBars = [2]\nOutput: 4\nExplanation: The left image shows the initial grid formed by the bars.\nThe horizontal bars are in the range [1,4], and the vertical bars are in the range [1,3].\nIt is allowed to remove horizontal bars [2,3] and the vertical bar [2].\nOne way to get the maximum square-shaped hole is by removing horizontal bar 2 and vertical bar 2.\nThe resulting grid is shown on the right.\nThe hole has an area of 4.\nIt can be shown that it is not possible to get a square hole with an area more than 4.\nHence, the answer is 4.\n\nExample 2:\n\n\nInput: n = 1, m = 1, hBars = [2], vBars = [2]\nOutput: 4\nExplanation: The left image shows the initial grid formed by the bars.\nThe horizontal bars are in the range [1,3], and the vertical bars are in the range [1,3].\nIt is allowed to remove the horizontal bar [2] and the vertical bar [2].\nTo get the maximum square-shaped hole, we remove horizontal bar 2 and vertical bar 2.\nThe resulting grid is shown on the right.\nThe hole has an area of 4.\nHence, the answer is 4, and it is the maximum possible.\n\nExample 3:\n\n\nInput: n = 2, m = 3, hBars = [2,3], vBars = [2,3,4]\nOutput: 9\nExplanation: The left image shows the initial grid formed by the bars.\nThe horizontal bars are in the range [1,4], and the vertical bars are in the range [1,5].\nIt is allowed to remove horizontal bars [2,3] and vertical bars [2,3,4].\nOne way to get the maximum square-shaped hole is by removing horizontal bars 2 and 3, and vertical bars 3 and 4.\nThe resulting grid is shown on the right.\nThe hole has an area of 9.\nIt can be shown that it is not possible to get a square hole with an area more than 9.\nHence, the answer is 9.\n\n\nConstraints:\n\n1 <= n <= 109\n1 <= m <= 109\n1 <= hBars.length <= 100\n2 <= hBars[i] <= n + 1\n1 <= vBars.length <= 100\n2 <= vBars[i] <= m + 1\nAll values in hBars are distinct.\nAll values in vBars are distinct.\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def maximizeSquareHoleArea(self, n: int, m: int, hBars: List[int], vBars: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"n\": 2, \"m\": 1, \"hBars\": [2,3], \"vBars\": [2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 4\n\ntest_input = { \"n\": 1, \"m\": 1, \"hBars\": [2], \"vBars\": [2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 4\n\ntest_input = { \"n\": 2, \"m\": 3, \"hBars\": [2,3], \"vBars\": [2,3,4] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 9\n\ntest_input = { \"n\": 1, \"m\": 5, \"hBars\": [2], \"vBars\": [2,3] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 4\n\ntest_input = { \"n\": 2, \"m\": 4, \"hBars\": [3,2], \"vBars\": [4,2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 4\n\ntest_input = { \"n\": 1, \"m\": 4, \"hBars\": [2], \"vBars\": [2,3,5,4] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 4\n\ntest_input = { \"n\": 1, \"m\": 4, \"hBars\": [2], \"vBars\": [4,3,2,5] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 4\n\ntest_input = { \"n\": 3, \"m\": 2, \"hBars\": [3,2,4], \"vBars\": [3,2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 9\n\ntest_input = { \"n\": 3, \"m\": 2, \"hBars\": [4,2,3], \"vBars\": [3,2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 9\n\ntest_input = { \"n\": 14, \"m\": 4, \"hBars\": [13], \"vBars\": [3,4,5,2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 4\n\ntest_input = { \"n\": 19, \"m\": 7, \"hBars\": [6,12,4], \"vBars\": [6,3] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 4\n\ntest_input = { \"n\": 2, \"m\": 4, \"hBars\": [2,3], \"vBars\": [4,2,3,5] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 9\n\ntest_input = { \"n\": 4, \"m\": 2, \"hBars\": [2,5,4,3], \"vBars\": [3,2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 9\n\ntest_input = { \"n\": 5, \"m\": 1, \"hBars\": [2,4,3,6,5], \"vBars\": [2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 4\n\ntest_input = { \"n\": 1, \"m\": 6, \"hBars\": [2], \"vBars\": [3,2,7,4,6,5] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 4\n\ntest_input = { \"n\": 1, \"m\": 13, \"hBars\": [2], \"vBars\": [4,14,2,12,11,3] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 4\n\ntest_input = { \"n\": 2, \"m\": 5, \"hBars\": [2,3], \"vBars\": [6,2,5,4,3] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 9\n\ntest_input = { \"n\": 5, \"m\": 2, \"hBars\": [2,3,6,4,5], \"vBars\": [2,3] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 9\n\ntest_input = { \"n\": 6, \"m\": 1, \"hBars\": [7,4,3,2,5,6], \"vBars\": [2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 4\n\ntest_input = { \"n\": 4, \"m\": 4, \"hBars\": [2,3,4,5], \"vBars\": [5,4,3,2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 25\n\ntest_input = { \"n\": 4, \"m\": 4, \"hBars\": [3,4,2,5], \"vBars\": [2,5,3,4] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 25\n\ntest_input = { \"n\": 6, \"m\": 2, \"hBars\": [7,3,5,4,6,2], \"vBars\": [3,2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 9\n\ntest_input = { \"n\": 7, \"m\": 11, \"hBars\": [7,4,5,2,8,6,3], \"vBars\": [4] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 4\n\ntest_input = { \"n\": 1, \"m\": 8, \"hBars\": [2], \"vBars\": [9,7,8,2,5,6,4,3] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 4\n\ntest_input = { \"n\": 1, \"m\": 9, \"hBars\": [2], \"vBars\": [5,2,10,4,3,6,8,7] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 4\n\ntest_input = { \"n\": 2, \"m\": 7, \"hBars\": [2,3], \"vBars\": [2,5,6,8,7,3,4] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 9\n\ntest_input = { \"n\": 2, \"m\": 7, \"hBars\": [2,3], \"vBars\": [2,8,6,7,5,3,4] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 9\n\ntest_input = { \"n\": 4, \"m\": 5, \"hBars\": [3,2,4,5], \"vBars\": [4,3,6,5,2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 25\n\ntest_input = { \"n\": 4, \"m\": 5, \"hBars\": [5,3,4,2], \"vBars\": [5,3,6,4,2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 25\n\ntest_input = { \"n\": 4, \"m\": 40, \"hBars\": [5,3,2,4], \"vBars\": [36,41,6,34,33] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 9\n\ntest_input = { \"n\": 8, \"m\": 1, \"hBars\": [4,7,9,8,6,2,3,5], \"vBars\": [2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 4\n\ntest_input = { \"n\": 11, \"m\": 6, \"hBars\": [8,9,6], \"vBars\": [5,3,6,4,2,7] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 9\n\ntest_input = { \"n\": 22, \"m\": 50, \"hBars\": [6,19,8,17,23], \"vBars\": [51,3,32,44] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 4\n\ntest_input = { \"n\": 27, \"m\": 2, \"hBars\": [2,26,28,22,4,8,23], \"vBars\": [3,2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 9\n\ntest_input = { \"n\": 1, \"m\": 9, \"hBars\": [2], \"vBars\": [3,6,10,4,8,5,9,7,2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 4\n\ntest_input = { \"n\": 1, \"m\": 9, \"hBars\": [2], \"vBars\": [3,7,5,9,10,2,4,8,6] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 4\n\ntest_input = { \"n\": 3, \"m\": 7, \"hBars\": [2,4,3], \"vBars\": [5,4,2,3,7,6,8] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 16\n\ntest_input = { \"n\": 3, \"m\": 7, \"hBars\": [4,3,2], \"vBars\": [2,7,3,6,5,4,8] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 16\n\ntest_input = { \"n\": 3, \"m\": 7, \"hBars\": [4,3,2], \"vBars\": [3,7,5,2,6,4,8] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 16\n\ntest_input = { \"n\": 3, \"m\": 7, \"hBars\": [4,3,2], \"vBars\": [8,2,5,3,6,4,7] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 16\n\ntest_input = { \"n\": 3, \"m\": 13, \"hBars\": [2,4,3], \"vBars\": [4,6,7,12,10,13,2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 9\n\ntest_input = { \"n\": 4, \"m\": 6, \"hBars\": [2,3,4,5], \"vBars\": [7,2,4,6,3,5] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 25\n\ntest_input = { \"n\": 5, \"m\": 5, \"hBars\": [4,6,5,2,3], \"vBars\": [2,4,5,6,3] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 36\n\ntest_input = { \"n\": 7, \"m\": 3, \"hBars\": [8,6,4,5,7,2,3], \"vBars\": [4,3,2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 16\n\ntest_input = { \"n\": 8, \"m\": 2, \"hBars\": [4,2,6,8,7,5,3,9], \"vBars\": [3,2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 9\n\ntest_input = { \"n\": 9, \"m\": 1, \"hBars\": [2,9,3,10,4,6,7,8,5], \"vBars\": [2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 4\n\ntest_input = { \"n\": 9, \"m\": 1, \"hBars\": [9,5,4,8,7,10,3,2,6], \"vBars\": [2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 4\n\ntest_input = { \"n\": 12, \"m\": 5, \"hBars\": [10,9,13,6,3], \"vBars\": [3,4,2,5,6] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 9\n\ntest_input = { \"n\": 29, \"m\": 2, \"hBars\": [25,14,11,29,7,10,16,8], \"vBars\": [2,3] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 9\n\ntest_input = { \"n\": 1, \"m\": 10, \"hBars\": [2], \"vBars\": [3,4,6,8,5,7,9,10,11,2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 4\n\ntest_input = { \"n\": 1, \"m\": 10, \"hBars\": [2], \"vBars\": [10,6,5,7,4,3,11,8,9,2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 4\n\ntest_input = { \"n\": 2, \"m\": 9, \"hBars\": [2,3], \"vBars\": [6,7,9,3,10,2,5,4,8] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 9\n\ntest_input = { \"n\": 2, \"m\": 9, \"hBars\": [3,2], \"vBars\": [4,8,2,6,7,3,5,9,10] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 9\n\ntest_input = { \"n\": 4, \"m\": 7, \"hBars\": [5,4,3,2], \"vBars\": [8,7,5,2,4,3,6] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 25\n\ntest_input = { \"n\": 5, \"m\": 6, \"hBars\": [2,6,5,3,4], \"vBars\": [4,2,5,3,7,6] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 36\n\ntest_input = { \"n\": 5, \"m\": 6, \"hBars\": [5,3,6,2,4], \"vBars\": [5,7,2,4,3,6] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 36\n\ntest_input = { \"n\": 5, \"m\": 6, \"hBars\": [6,4,3,5,2], \"vBars\": [2,4,5,7,6,3] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 36\n\ntest_input = { \"n\": 5, \"m\": 11, \"hBars\": [4,2,6,3,5], \"vBars\": [8,11,10,12,6,2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 16\n\ntest_input = { \"n\": 6, \"m\": 5, \"hBars\": [4,5,3,2,7,6], \"vBars\": [6,3,5,4,2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 36\n\ntest_input = { \"n\": 6, \"m\": 5, \"hBars\": [5,2,3,7,4,6], \"vBars\": [6,2,4,3,5] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 36\n\ntest_input = { \"n\": 6, \"m\": 5, \"hBars\": [6,3,4,2,7,5], \"vBars\": [2,5,4,3,6] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 36\n\ntest_input = { \"n\": 6, \"m\": 5, \"hBars\": [7,2,3,4,5,6], \"vBars\": [6,5,4,2,3] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 36\n\ntest_input = { \"n\": 8, \"m\": 3, \"hBars\": [4,6,9,3,8,2,7,5], \"vBars\": [2,4,3] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 16\n\ntest_input = { \"n\": 8, \"m\": 3, \"hBars\": [5,6,9,3,2,4,8,7], \"vBars\": [2,4,3] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 16\n\ntest_input = { \"n\": 8, \"m\": 3, \"hBars\": [8,6,4,3,7,2,9,5], \"vBars\": [4,2,3] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 16\n\ntest_input = { \"n\": 8, \"m\": 3, \"hBars\": [9,2,7,6,8,3,4,5], \"vBars\": [4,2,3] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 16\n\ntest_input = { \"n\": 9, \"m\": 2, \"hBars\": [5,4,6,8,9,10,2,3,7], \"vBars\": [3,2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 9\n\ntest_input = { \"n\": 9, \"m\": 2, \"hBars\": [6,3,5,4,8,9,2,10,7], \"vBars\": [3,2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 9\n\ntest_input = { \"n\": 10, \"m\": 1, \"hBars\": [4,3,10,2,11,5,6,9,8,7], \"vBars\": [2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 4\n\ntest_input = { \"n\": 1, \"m\": 11, \"hBars\": [2], \"vBars\": [7,12,6,3,4,9,5,10,11,2,8] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 4\n\ntest_input = { \"n\": 2, \"m\": 10, \"hBars\": [2,3], \"vBars\": [11,10,2,8,7,5,6,9,3,4] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 9\n\ntest_input = { \"n\": 4, \"m\": 8, \"hBars\": [5,2,3,4], \"vBars\": [8,7,5,9,4,2,3,6] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 25\n\ntest_input = { \"n\": 5, \"m\": 7, \"hBars\": [2,3,6,4,5], \"vBars\": [6,8,4,5,3,7,2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 36\n\ntest_input = { \"n\": 6, \"m\": 10, \"hBars\": [2,4,3,6,5,7], \"vBars\": [11,3,9,6,10,4] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 16\n\ntest_input = { \"n\": 10, \"m\": 2, \"hBars\": [8,5,4,3,10,2,11,9,6,7], \"vBars\": [3,2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 9\n\ntest_input = { \"n\": 11, \"m\": 1, \"hBars\": [2,6,9,7,5,11,3,10,4,12,8], \"vBars\": [2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 4\n\ntest_input = { \"n\": 44, \"m\": 2, \"hBars\": [5,16,18,28,3,9,6,35,14,10], \"vBars\": [3,2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 9\n\ntest_input = { \"n\": 1, \"m\": 12, \"hBars\": [2], \"vBars\": [12,9,3,13,7,2,6,11,10,8,4,5] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 4\n\ntest_input = { \"n\": 2, \"m\": 11, \"hBars\": [2,3], \"vBars\": [3,7,2,5,12,9,10,4,8,11,6] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 9\n\ntest_input = { \"n\": 2, \"m\": 11, \"hBars\": [2,3], \"vBars\": [12,10,6,7,2,3,5,11,4,8,9] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 9\n\ntest_input = { \"n\": 5, \"m\": 8, \"hBars\": [2,4,6,3,5], \"vBars\": [8,7,9,4,2,5,6,3] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 36\n\ntest_input = { \"n\": 6, \"m\": 7, \"hBars\": [5,4,6,3,2,7], \"vBars\": [4,7,6,5,2,8,3] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 49\n\ntest_input = { \"n\": 6, \"m\": 7, \"hBars\": [6,3,2,7,4,5], \"vBars\": [6,7,5,2,3,4,8] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 49\n\ntest_input = { \"n\": 8, \"m\": 5, \"hBars\": [7,4,3,9,2,8,6,5], \"vBars\": [5,2,6,3,4] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 36\n\ntest_input = { \"n\": 9, \"m\": 4, \"hBars\": [4,5,6,10,7,2,3,9,8], \"vBars\": [5,3,2,4] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 25\n\ntest_input = { \"n\": 9, \"m\": 4, \"hBars\": [9,6,3,10,2,8,4,5,7], \"vBars\": [4,3,2,5] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 25\n\ntest_input = { \"n\": 10, \"m\": 3, \"hBars\": [5,4,9,8,3,6,11,2,10,7], \"vBars\": [4,3,2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 16\n\ntest_input = { \"n\": 10, \"m\": 6, \"hBars\": [6,2,8,3,11,9,10,7,4,5], \"vBars\": [6,2,5] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 9\n\ntest_input = { \"n\": 11, \"m\": 2, \"hBars\": [8,12,9,3,5,2,10,6,7,4,11], \"vBars\": [3,2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 9\n\ntest_input = { \"n\": 28, \"m\": 31, \"hBars\": [29,24,4], \"vBars\": [22,24,2,14,26,4,29,13,15,25] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 4\n\ntest_input = { \"n\": 1, \"m\": 13, \"hBars\": [2], \"vBars\": [9,5,2,6,8,11,7,10,3,13,14,4,12] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 4\n\ntest_input = { \"n\": 2, \"m\": 12, \"hBars\": [3,2], \"vBars\": [13,2,7,4,12,9,10,3,6,5,8,11] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 9\n\ntest_input = { \"n\": 2, \"m\": 12, \"hBars\": [3,2], \"vBars\": [13,4,7,8,3,2,11,12,5,9,6,10] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 9\n\ntest_input = { \"n\": 5, \"m\": 9, \"hBars\": [2,5,6,3,4], \"vBars\": [2,7,3,9,4,10,8,6,5] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 36\n\ntest_input = { \"n\": 6, \"m\": 9, \"hBars\": [4,2,5,7,6,3], \"vBars\": [4,2,6,8,10,3,7,5] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 49\n\ntest_input = { \"n\": 8, \"m\": 6, \"hBars\": [4,8,6,7,2,9,3,5], \"vBars\": [4,7,6,3,2,5] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 49\n\ntest_input = { \"n\": 9, \"m\": 5, \"hBars\": [2,5,4,8,3,7,6,10,9], \"vBars\": [6,3,5,2,4] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 36\n\ntest_input = { \"n\": 9, \"m\": 5, \"hBars\": [8,9,5,2,6,7,4,10,3], \"vBars\": [6,2,3,4,5] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 36\n\ntest_input = { \"n\": 10, \"m\": 4, \"hBars\": [4,8,6,3,10,2,7,9,5,11], \"vBars\": [5,4,3,2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 25\n\ntest_input = { \"n\": 11, \"m\": 3, \"hBars\": [2,8,5,3,12,10,4,11,6,7,9], \"vBars\": [3,4,2] }\nassert my_solution.maximizeSquareHoleArea(**test_input) == 16", "start_time": 1700922600} +{"task_id": "biweekly-contest-118-minimum-number-of-coins-for-fruits", "url": "https://leetcode.com/problems/minimum-number-of-coins-for-fruits", "title": "minimum-number-of-coins-for-fruits", "meta": {"questionId": "3209", "questionFrontendId": "2944", "title": "Minimum Number of Coins for Fruits", "titleSlug": "minimum-number-of-coins-for-fruits", "isPaidOnly": false, "difficulty": "Medium", "likes": 141, "dislikes": 27, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are at a fruit market with different types of exotic fruits on display.\nYou are given a 1-indexed array prices, where prices[i] denotes the number of coins needed to purchase the ith fruit.\nThe fruit market has the following offer:\n\nIf you purchase the ith fruit at prices[i] coins, you can get the next i fruits for free.\n\nNote that even if you can take fruit j for free, you can still purchase it for prices[j] coins to receive a new offer.\nReturn the minimum number of coins needed to acquire all the fruits.\n\nExample 1:\n\nInput: prices = [3,1,2]\nOutput: 4\nExplanation: You can acquire the fruits as follows:\n- Purchase the 1st fruit with 3 coins, you are allowed to take the 2nd fruit for free.\n- Purchase the 2nd fruit with 1 coin, you are allowed to take the 3rd fruit for free.\n- Take the 3rd fruit for free.\nNote that even though you were allowed to take the 2nd fruit for free, you purchased it because it is more optimal.\nIt can be proven that 4 is the minimum number of coins needed to acquire all the fruits.\n\nExample 2:\n\nInput: prices = [1,10,1,1]\nOutput: 2\nExplanation: You can acquire the fruits as follows:\n- Purchase the 1st fruit with 1 coin, you are allowed to take the 2nd fruit for free.\n- Take the 2nd fruit for free.\n- Purchase the 3rd fruit for 1 coin, you are allowed to take the 4th fruit for free.\n- Take the 4th fruit for free.\nIt can be proven that 2 is the minimum number of coins needed to acquire all the fruits.\n\n\nConstraints:\n\n1 <= prices.length <= 1000\n1 <= prices[i] <= 105\n\"\"\"\nclass Solution:\n def minimumCoins(self, prices: List[int]) -> int:\n ", "prompt_sft": "You are at a fruit market with different types of exotic fruits on display.\nYou are given a 1-indexed array prices, where prices[i] denotes the number of coins needed to purchase the ith fruit.\nThe fruit market has the following offer:\n\nIf you purchase the ith fruit at prices[i] coins, you can get the next i fruits for free.\n\nNote that even if you can take fruit j for free, you can still purchase it for prices[j] coins to receive a new offer.\nReturn the minimum number of coins needed to acquire all the fruits.\n\nExample 1:\n\nInput: prices = [3,1,2]\nOutput: 4\nExplanation: You can acquire the fruits as follows:\n- Purchase the 1st fruit with 3 coins, you are allowed to take the 2nd fruit for free.\n- Purchase the 2nd fruit with 1 coin, you are allowed to take the 3rd fruit for free.\n- Take the 3rd fruit for free.\nNote that even though you were allowed to take the 2nd fruit for free, you purchased it because it is more optimal.\nIt can be proven that 4 is the minimum number of coins needed to acquire all the fruits.\n\nExample 2:\n\nInput: prices = [1,10,1,1]\nOutput: 2\nExplanation: You can acquire the fruits as follows:\n- Purchase the 1st fruit with 1 coin, you are allowed to take the 2nd fruit for free.\n- Take the 2nd fruit for free.\n- Purchase the 3rd fruit for 1 coin, you are allowed to take the 4th fruit for free.\n- Take the 4th fruit for free.\nIt can be proven that 2 is the minimum number of coins needed to acquire all the fruits.\n\n\nConstraints:\n\n1 <= prices.length <= 1000\n1 <= prices[i] <= 105\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def minimumCoins(self, prices: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"prices\": [3,1,2] }\nassert my_solution.minimumCoins(**test_input) == 4\n\ntest_input = { \"prices\": [1,10,1,1] }\nassert my_solution.minimumCoins(**test_input) == 2\n\ntest_input = { \"prices\": [26,18,6,12,49,7,45,45] }\nassert my_solution.minimumCoins(**test_input) == 39\n\ntest_input = { \"prices\": [27,17,29,45,3,39,42,26] }\nassert my_solution.minimumCoins(**test_input) == 47\n\ntest_input = { \"prices\": [14,37,37,38,24,15,12] }\nassert my_solution.minimumCoins(**test_input) == 63\n\ntest_input = { \"prices\": [1,37,19,38,11,42,18,33,6,37,15,48,23,12,41,18,27,32] }\nassert my_solution.minimumCoins(**test_input) == 37\n\ntest_input = { \"prices\": [38,23,27,32,47,45,48,24,39,26,37,42,24,45,27,26,15,16,26,6] }\nassert my_solution.minimumCoins(**test_input) == 132\n\ntest_input = { \"prices\": [45,44,5,9,22,14,29,14,21,13,45,10,2,16,14,30,26,1,49] }\nassert my_solution.minimumCoins(**test_input) == 66\n\ntest_input = { \"prices\": [37,42,6,50,50,38,30,38,1,13,25,39,18,1,35,32,12] }\nassert my_solution.minimumCoins(**test_input) == 74\n\ntest_input = { \"prices\": [17,32,11,25,22] }\nassert my_solution.minimumCoins(**test_input) == 28\n\ntest_input = { \"prices\": [18,10,1,11,6,30,19,24,1,18,37,29,28,27,38] }\nassert my_solution.minimumCoins(**test_input) == 26\n\ntest_input = { \"prices\": [3,10,25,47,49,10,49] }\nassert my_solution.minimumCoins(**test_input) == 38\n\ntest_input = { \"prices\": [46,7,15] }\nassert my_solution.minimumCoins(**test_input) == 53\n\ntest_input = { \"prices\": [16,45,25,5,18,19,25,13,33] }\nassert my_solution.minimumCoins(**test_input) == 59\n\ntest_input = { \"prices\": [21,16,7,10,30] }\nassert my_solution.minimumCoins(**test_input) == 28\n\ntest_input = { \"prices\": [21,22,29,37,23,15,39,9,19,10,6,9,33,28,43] }\nassert my_solution.minimumCoins(**test_input) == 71\n\ntest_input = { \"prices\": [37,16,42,47,16,31,39,8,26,50,33] }\nassert my_solution.minimumCoins(**test_input) == 77\n\ntest_input = { \"prices\": [32,4] }\nassert my_solution.minimumCoins(**test_input) == 32\n\ntest_input = { \"prices\": [31,9,2,36,4,45,28,28,12,22,44,17,10,48,15,22,7,14,41] }\nassert my_solution.minimumCoins(**test_input) == 56\n\ntest_input = { \"prices\": [1,31,9,36,44,2,23] }\nassert my_solution.minimumCoins(**test_input) == 12\n\ntest_input = { \"prices\": [3,7,2,36,33,7,21,40,19] }\nassert my_solution.minimumCoins(**test_input) == 12\n\ntest_input = { \"prices\": [9,4,7,29,22,50] }\nassert my_solution.minimumCoins(**test_input) == 16\n\ntest_input = { \"prices\": [28,2,40,15] }\nassert my_solution.minimumCoins(**test_input) == 30\n\ntest_input = { \"prices\": [16,17,47,20,18,37] }\nassert my_solution.minimumCoins(**test_input) == 51\n\ntest_input = { \"prices\": [42,6,44,47,11,6,30,38,41,43,46,35,28,4,47,1,7,35] }\nassert my_solution.minimumCoins(**test_input) == 93\n\ntest_input = { \"prices\": [10,10,5,8,5,13,34,31,36] }\nassert my_solution.minimumCoins(**test_input) == 20\n\ntest_input = { \"prices\": [12,20,14,46,22,1,42,50,47,47,38,37,13] }\nassert my_solution.minimumCoins(**test_input) == 40\n\ntest_input = { \"prices\": [1,38,28,46,18,22,12,7,44,44,40,36,41,5,33,5,30,33,31] }\nassert my_solution.minimumCoins(**test_input) == 46\n\ntest_input = { \"prices\": [6,45,2,29,44,14,44] }\nassert my_solution.minimumCoins(**test_input) == 22\n\ntest_input = { \"prices\": [34,13,50,42,24,47,41,8,26,34,3,48,39,24,39,26,46] }\nassert my_solution.minimumCoins(**test_input) == 74\n\ntest_input = { \"prices\": [47,9,33,6,33,40,28,37,49,39,45,14,13,40,17,14,39,12,15,6] }\nassert my_solution.minimumCoins(**test_input) == 103\n\ntest_input = { \"prices\": [32] }\nassert my_solution.minimumCoins(**test_input) == 32\n\ntest_input = { \"prices\": [35,46,50,35,11,14,44,17,45,23,34,33,8,27,19,7,10,12,14] }\nassert my_solution.minimumCoins(**test_input) == 107\n\ntest_input = { \"prices\": [50,45,14,24,18,15,9,14] }\nassert my_solution.minimumCoins(**test_input) == 73\n\ntest_input = { \"prices\": [38,19,18,15,20,43,18,9,44,26,29] }\nassert my_solution.minimumCoins(**test_input) == 74\n\ntest_input = { \"prices\": [26,21,7,40,37,44,13,3,10,9,15,12,30,18,31,10,23] }\nassert my_solution.minimumCoins(**test_input) == 55\n\ntest_input = { \"prices\": [36,50] }\nassert my_solution.minimumCoins(**test_input) == 36\n\ntest_input = { \"prices\": [1,32,48,36,26,5,30,25,2,17,26,39,17,46,34,47,43,45,20,48] }\nassert my_solution.minimumCoins(**test_input) == 71\n\ntest_input = { \"prices\": [19,24,31,24] }\nassert my_solution.minimumCoins(**test_input) == 43\n\ntest_input = { \"prices\": [1,18,25,29,17,9,3,29,23,17,18] }\nassert my_solution.minimumCoins(**test_input) == 29\n\ntest_input = { \"prices\": [18,36,18,44,30,8,42,33,45,19,50,19,24,48] }\nassert my_solution.minimumCoins(**test_input) == 63\n\ntest_input = { \"prices\": [26,25,47,36,9,31,1,29,29,42,29,42,36,19,45,4,11,7] }\nassert my_solution.minimumCoins(**test_input) == 80\n\ntest_input = { \"prices\": [24,34,47,12,24,48,14,30,28,43,35,45,11,11,35,38] }\nassert my_solution.minimumCoins(**test_input) == 95\n\ntest_input = { \"prices\": [29,18,2,6,47,32,27,12,38,17] }\nassert my_solution.minimumCoins(**test_input) == 49\n\ntest_input = { \"prices\": [3,31,15,18,47,18,2,27,24,6,36,35,41,21,30] }\nassert my_solution.minimumCoins(**test_input) == 26\n\ntest_input = { \"prices\": [29,45,8,45,23,35] }\nassert my_solution.minimumCoins(**test_input) == 37\n\ntest_input = { \"prices\": [39,37] }\nassert my_solution.minimumCoins(**test_input) == 39\n\ntest_input = { \"prices\": [18,45,6,14,41,41] }\nassert my_solution.minimumCoins(**test_input) == 24\n\ntest_input = { \"prices\": [50,21,38,2,32,49,32,40,41,34,33,40,36,16,29,34,42,40,46] }\nassert my_solution.minimumCoins(**test_input) == 121\n\ntest_input = { \"prices\": [28,17,42,20,6,26,47,6,23] }\nassert my_solution.minimumCoins(**test_input) == 51\n\ntest_input = { \"prices\": [37,27,17,40,50,35,16,4,28,5,27,13,46,7,23,27] }\nassert my_solution.minimumCoins(**test_input) == 74\n\ntest_input = { \"prices\": [11,5,40,16,20,38] }\nassert my_solution.minimumCoins(**test_input) == 32\n\ntest_input = { \"prices\": [16,27,5,38,12,24,7,49,40,13,38,13,34,38,37,2,4,44] }\nassert my_solution.minimumCoins(**test_input) == 41\n\ntest_input = { \"prices\": [25,9,49,19,33] }\nassert my_solution.minimumCoins(**test_input) == 53\n\ntest_input = { \"prices\": [47,23,46,13,26,44,43,22,43,24,13,20,6,16,8,26] }\nassert my_solution.minimumCoins(**test_input) == 105\n\ntest_input = { \"prices\": [8,1,1] }\nassert my_solution.minimumCoins(**test_input) == 9\n\ntest_input = { \"prices\": [47,45,2,25,7,46] }\nassert my_solution.minimumCoins(**test_input) == 49\n\ntest_input = { \"prices\": [4,31,50,45,5,50] }\nassert my_solution.minimumCoins(**test_input) == 40\n\ntest_input = { \"prices\": [30,41,1,49,9,49,41,27,41,14,23,3,46,40,37,28,45,19,36,49] }\nassert my_solution.minimumCoins(**test_input) == 54\n\ntest_input = { \"prices\": [6,3,49,28,31,36,5,50,39] }\nassert my_solution.minimumCoins(**test_input) == 40\n\ntest_input = { \"prices\": [37,2,19,36,26,27,3,23,10,20,33,8,39,6,28] }\nassert my_solution.minimumCoins(**test_input) == 65\n\ntest_input = { \"prices\": [37,34,12,30,43,35,6,21,47,38,14,31,49,11,14] }\nassert my_solution.minimumCoins(**test_input) == 66\n\ntest_input = { \"prices\": [49,6,12,35,17,17,2] }\nassert my_solution.minimumCoins(**test_input) == 63\n\ntest_input = { \"prices\": [45,27,43,34,41,30,28,45,24,50,20,4,15,42] }\nassert my_solution.minimumCoins(**test_input) == 116\n\ntest_input = { \"prices\": [48,22,36] }\nassert my_solution.minimumCoins(**test_input) == 70\n\ntest_input = { \"prices\": [47,13,23,31,41,25] }\nassert my_solution.minimumCoins(**test_input) == 70\n\ntest_input = { \"prices\": [3,44,17,37,9,14,37] }\nassert my_solution.minimumCoins(**test_input) == 29\n\ntest_input = { \"prices\": [4,43,7,15,38] }\nassert my_solution.minimumCoins(**test_input) == 11\n\ntest_input = { \"prices\": [10,25,7,37,6,43,4,50,9,14,36,35,36,44,17,10,44,46,50] }\nassert my_solution.minimumCoins(**test_input) == 35\n\ntest_input = { \"prices\": [45,28,10,18,18,3,42,24,14,11,13,32,37,31,50,32] }\nassert my_solution.minimumCoins(**test_input) == 69\n\ntest_input = { \"prices\": [12,38,44,24,42,9,32,40,8,20,46,39,33] }\nassert my_solution.minimumCoins(**test_input) == 73\n\ntest_input = { \"prices\": [5,42,30,20,37,26,38,30,30,32,39,31,33,41,23,4,29] }\nassert my_solution.minimumCoins(**test_input) == 85\n\ntest_input = { \"prices\": [44,22] }\nassert my_solution.minimumCoins(**test_input) == 44\n\ntest_input = { \"prices\": [8,8,11,21,9] }\nassert my_solution.minimumCoins(**test_input) == 19\n\ntest_input = { \"prices\": [2,37,19,30,37,27,10,37] }\nassert my_solution.minimumCoins(**test_input) == 31\n\ntest_input = { \"prices\": [43,27,48,22] }\nassert my_solution.minimumCoins(**test_input) == 70\n\ntest_input = { \"prices\": [50,23,37,49,45,14,18,39,50,7,31] }\nassert my_solution.minimumCoins(**test_input) == 101\n\ntest_input = { \"prices\": [37,3,32,25,21,22,26,49,14,45,1,36] }\nassert my_solution.minimumCoins(**test_input) == 62\n\ntest_input = { \"prices\": [21,29,31,28,2,41,4,43,41,16,38,33,3,6,43,22,15] }\nassert my_solution.minimumCoins(**test_input) == 59\n\ntest_input = { \"prices\": [24,47,32,41,35,14,18,23,27,8,27] }\nassert my_solution.minimumCoins(**test_input) == 70\n\ntest_input = { \"prices\": [40,25,32] }\nassert my_solution.minimumCoins(**test_input) == 65\n\ntest_input = { \"prices\": [9,18,2,26,15,3,2,33,46,6,11,34,27,7,5,7,26,13,48] }\nassert my_solution.minimumCoins(**test_input) == 18\n\ntest_input = { \"prices\": [41,8,38,32,36,30,23,49,40,46,42,34,2,12,12,19,20,50,40] }\nassert my_solution.minimumCoins(**test_input) == 104\n\ntest_input = { \"prices\": [28,8,24,14,34,36,48] }\nassert my_solution.minimumCoins(**test_input) == 50\n\ntest_input = { \"prices\": [2,36,22,41,42,26,1,48,14,27,22,26] }\nassert my_solution.minimumCoins(**test_input) == 25\n\ntest_input = { \"prices\": [25,39,21,21,16] }\nassert my_solution.minimumCoins(**test_input) == 46\n\ntest_input = { \"prices\": [44,41,36,42,21,32,45,5] }\nassert my_solution.minimumCoins(**test_input) == 101\n\ntest_input = { \"prices\": [10] }\nassert my_solution.minimumCoins(**test_input) == 10\n\ntest_input = { \"prices\": [35,29] }\nassert my_solution.minimumCoins(**test_input) == 35\n\ntest_input = { \"prices\": [38,35,33,11,43,33] }\nassert my_solution.minimumCoins(**test_input) == 71\n\ntest_input = { \"prices\": [19,29,49,20,8,12,13,28,45,9,12,3,1,17,35] }\nassert my_solution.minimumCoins(**test_input) == 65\n\ntest_input = { \"prices\": [34,22,1,41,34,27,18] }\nassert my_solution.minimumCoins(**test_input) == 53\n\ntest_input = { \"prices\": [31,9,39,6,14,32,28,35,34,42,19,41,35,24,32,16,12,49,16] }\nassert my_solution.minimumCoins(**test_input) == 73\n\ntest_input = { \"prices\": [46,50,21,14,26,47] }\nassert my_solution.minimumCoins(**test_input) == 67\n\ntest_input = { \"prices\": [5,22,36,6,15,49,20,16,36,15,32,27,50,19,12,22,9,33] }\nassert my_solution.minimumCoins(**test_input) == 57\n\ntest_input = { \"prices\": [17,4,36,4,32,11,42,12,20] }\nassert my_solution.minimumCoins(**test_input) == 36\n\ntest_input = { \"prices\": [48,33,39,1,13,40] }\nassert my_solution.minimumCoins(**test_input) == 82\n\ntest_input = { \"prices\": [32,19,33,30,32,44,47,8,10,1,23,6,28,19,20,48,12,10,20,22] }\nassert my_solution.minimumCoins(**test_input) == 84\n\ntest_input = { \"prices\": [29,5,46,34,38,7,1,15] }\nassert my_solution.minimumCoins(**test_input) == 68\n\ntest_input = { \"prices\": [39,50,22,1,38,22,49,16,27,48,45,28,43,34] }\nassert my_solution.minimumCoins(**test_input) == 78", "start_time": 1700922600} +{"task_id": "biweekly-contest-118-find-maximum-non-decreasing-array-length", "url": "https://leetcode.com/problems/find-maximum-non-decreasing-array-length", "title": "find-maximum-non-decreasing-array-length", "meta": {"questionId": "3211", "questionFrontendId": "2945", "title": "Find Maximum Non-decreasing Array Length", "titleSlug": "find-maximum-non-decreasing-array-length", "isPaidOnly": false, "difficulty": "Hard", "likes": 90, "dislikes": 9, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed integer array nums.\nYou can perform any number of operations, where each operation involves selecting a subarray of the array and replacing it with the sum of its elements. For example, if the given array is [1,3,5,6] and you select subarray [3,5] the array will convert to [1,8,6].\nReturn the maximum length of a non-decreasing array that can be made after applying operations.\nA subarray is a contiguous non-empty sequence of elements within an array.\n\nExample 1:\n\nInput: nums = [5,2,2]\nOutput: 1\nExplanation: This array with length 3 is not non-decreasing.\nWe have two ways to make the array length two.\nFirst, choosing subarray [2,2] converts the array to [5,4].\nSecond, choosing subarray [5,2] converts the array to [7,2].\nIn these two ways the array is not non-decreasing.\nAnd if we choose subarray [5,2,2] and replace it with [9] it becomes non-decreasing. \nSo the answer is 1.\n\nExample 2:\n\nInput: nums = [1,2,3,4]\nOutput: 4\nExplanation: The array is non-decreasing. So the answer is 4.\n\nExample 3:\n\nInput: nums = [4,3,2,6]\nOutput: 3\nExplanation: Replacing [3,2] with [5] converts the given array to [4,5,6] that is non-decreasing.\nBecause the given array is not non-decreasing, the maximum possible answer is 3.\n\nConstraints:\n\n1 <= nums.length <= 105\n1 <= nums[i] <= 105\n\"\"\"\nclass Solution:\n def findMaximumLength(self, nums: List[int]) -> int:\n ", "prompt_sft": "You are given a 0-indexed integer array nums.\nYou can perform any number of operations, where each operation involves selecting a subarray of the array and replacing it with the sum of its elements. For example, if the given array is [1,3,5,6] and you select subarray [3,5] the array will convert to [1,8,6].\nReturn the maximum length of a non-decreasing array that can be made after applying operations.\nA subarray is a contiguous non-empty sequence of elements within an array.\n\nExample 1:\n\nInput: nums = [5,2,2]\nOutput: 1\nExplanation: This array with length 3 is not non-decreasing.\nWe have two ways to make the array length two.\nFirst, choosing subarray [2,2] converts the array to [5,4].\nSecond, choosing subarray [5,2] converts the array to [7,2].\nIn these two ways the array is not non-decreasing.\nAnd if we choose subarray [5,2,2] and replace it with [9] it becomes non-decreasing. \nSo the answer is 1.\n\nExample 2:\n\nInput: nums = [1,2,3,4]\nOutput: 4\nExplanation: The array is non-decreasing. So the answer is 4.\n\nExample 3:\n\nInput: nums = [4,3,2,6]\nOutput: 3\nExplanation: Replacing [3,2] with [5] converts the given array to [4,5,6] that is non-decreasing.\nBecause the given array is not non-decreasing, the maximum possible answer is 3.\n\nConstraints:\n\n1 <= nums.length <= 105\n1 <= nums[i] <= 105\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def findMaximumLength(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [5,2,2] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,3,4] }\nassert my_solution.findMaximumLength(**test_input) == 4\n\ntest_input = { \"nums\": [4,3,2,6] }\nassert my_solution.findMaximumLength(**test_input) == 3\n\ntest_input = { \"nums\": [32] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [38] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [60] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [79] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [85] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [170] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [198] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [220] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [318] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [350] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [381] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [413] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [426] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [429] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [431] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [445] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [488] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [492] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [497] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [515] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [582] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [589] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [620] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [632] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [703] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [748] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [776] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [977] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [986] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [990] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [29,859] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [48,612] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [76,837] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [103,341] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [171,323] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [248,719] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [253,61] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [274,467] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [351,665] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [372,382] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [404,409] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [455,40] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [472,843] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [504,838] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [549,747] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [570,810] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [621,809] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [643,802] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [689,192] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [709,481] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [742,67] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [745,725] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [773,877] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [776,962] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [791,434] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [824,783] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [840,388] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [876,264] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [940,694] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [959,372] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [981,998] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [41,340,784] }\nassert my_solution.findMaximumLength(**test_input) == 3\n\ntest_input = { \"nums\": [103,652,579] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [116,635,966] }\nassert my_solution.findMaximumLength(**test_input) == 3\n\ntest_input = { \"nums\": [137,32,745] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [247,173,316] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [276,315,947] }\nassert my_solution.findMaximumLength(**test_input) == 3\n\ntest_input = { \"nums\": [278,754,912] }\nassert my_solution.findMaximumLength(**test_input) == 3\n\ntest_input = { \"nums\": [314,882,708] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [371,101,367] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [402,305,990] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [403,553,697] }\nassert my_solution.findMaximumLength(**test_input) == 3\n\ntest_input = { \"nums\": [431,780,315] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [479,322,44] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [512,234,679] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [513,847,778] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [525,177,936] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [588,42,18] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [646,174,827] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [680,242,726] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [769,131,241] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [780,591,213] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [783,23,848] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [787,201,30] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [791,470,87] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [797,181,492] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [868,4,455] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [881,306,316] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [886,116,68] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [893,531,805] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [926,641,145] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [964,624,279] }\nassert my_solution.findMaximumLength(**test_input) == 1\n\ntest_input = { \"nums\": [987,694,396] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [38,986,134,156] }\nassert my_solution.findMaximumLength(**test_input) == 2\n\ntest_input = { \"nums\": [43,236,417,521] }\nassert my_solution.findMaximumLength(**test_input) == 4\n\ntest_input = { \"nums\": [58,890,892,52] }\nassert my_solution.findMaximumLength(**test_input) == 3\n\ntest_input = { \"nums\": [81,738,403,654] }\nassert my_solution.findMaximumLength(**test_input) == 3", "start_time": 1700922600} +{"task_id": "weekly-contest-372-make-three-strings-equal", "url": "https://leetcode.com/problems/make-three-strings-equal/", "title": "make-three-strings-equal", "meta": {"questionId": "3207", "questionFrontendId": "2937", "title": "Make Three Strings Equal", "titleSlug": "make-three-strings-equal", "isPaidOnly": false, "difficulty": "Easy", "likes": 114, "dislikes": 30, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given three strings s1, s2, and s3. You have to perform the following operation on these three strings as many times as you want.\nIn one operation you can choose one of these three strings such that its length is at least 2 and delete the rightmost character of it.\nReturn the minimum number of operations you need to perform to make the three strings equal if there is a way to make them equal, otherwise, return -1.\n\nExample 1:\n\nInput: s1 = \"abc\", s2 = \"abb\", s3 = \"ab\"\nOutput: 2\nExplanation: Performing operations on s1 and s2 once will lead to three equal strings.\nIt can be shown that there is no way to make them equal with less than two operations.\nExample 2:\n\nInput: s1 = \"dac\", s2 = \"bac\", s3 = \"cac\"\nOutput: -1\nExplanation: Because the leftmost letters of s1 and s2 are not equal, they could not be equal after any number of operations. So the answer is -1.\n\n\nConstraints:\n\n1 <= s1.length, s2.length, s3.length <= 100\ns1, s2 and s3 consist only of lowercase English letters.\n\"\"\"\nclass Solution:\n def findMinimumOperations(self, s1: str, s2: str, s3: str) -> int:\n ", "prompt_sft": "You are given three strings s1, s2, and s3. You have to perform the following operation on these three strings as many times as you want.\nIn one operation you can choose one of these three strings such that its length is at least 2 and delete the rightmost character of it.\nReturn the minimum number of operations you need to perform to make the three strings equal if there is a way to make them equal, otherwise, return -1.\n\nExample 1:\n\nInput: s1 = \"abc\", s2 = \"abb\", s3 = \"ab\"\nOutput: 2\nExplanation: Performing operations on s1 and s2 once will lead to three equal strings.\nIt can be shown that there is no way to make them equal with less than two operations.\nExample 2:\n\nInput: s1 = \"dac\", s2 = \"bac\", s3 = \"cac\"\nOutput: -1\nExplanation: Because the leftmost letters of s1 and s2 are not equal, they could not be equal after any number of operations. So the answer is -1.\n\n\nConstraints:\n\n1 <= s1.length, s2.length, s3.length <= 100\ns1, s2 and s3 consist only of lowercase English letters.\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def findMinimumOperations(self, s1: str, s2: str, s3: str) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"s1\": \"abc\", \"s2\": \"abb\", \"s3\": \"ab\" }\nassert my_solution.findMinimumOperations(**test_input) == 2\n\ntest_input = { \"s1\": \"dac\", \"s2\": \"bac\", \"s3\": \"cac\" }\nassert my_solution.findMinimumOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"a\", \"s2\": \"a\", \"s3\": \"a\" }\nassert my_solution.findMinimumOperations(**test_input) == 0\n\ntest_input = { \"s1\": \"kui\", \"s2\": \"m\", \"s3\": \"v\" }\nassert my_solution.findMinimumOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"a\", \"s2\": \"aabc\", \"s3\": \"a\" }\nassert my_solution.findMinimumOperations(**test_input) == 3\n\ntest_input = { \"s1\": \"cc\", \"s2\": \"cccb\", \"s3\": \"c\" }\nassert my_solution.findMinimumOperations(**test_input) == 4\n\ntest_input = { \"s1\": \"luso\", \"s2\": \"lu\", \"s3\": \"lu\" }\nassert my_solution.findMinimumOperations(**test_input) == 2\n\ntest_input = { \"s1\": \"xx\", \"s2\": \"phe\", \"s3\": \"xie\" }\nassert my_solution.findMinimumOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"gzd\", \"s2\": \"bcju\", \"s3\": \"db\" }\nassert my_solution.findMinimumOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"cbba\", \"s2\": \"cbaa\", \"s3\": \"c\" }\nassert my_solution.findMinimumOperations(**test_input) == 6\n\ntest_input = { \"s1\": \"k\", \"s2\": \"kfb\", \"s3\": \"krcnf\" }\nassert my_solution.findMinimumOperations(**test_input) == 6\n\ntest_input = { \"s1\": \"oby\", \"s2\": \"obz\", \"s3\": \"obf\" }\nassert my_solution.findMinimumOperations(**test_input) == 3\n\ntest_input = { \"s1\": \"b\", \"s2\": \"aba\", \"s3\": \"aaccaa\" }\nassert my_solution.findMinimumOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"a\", \"s2\": \"accabb\", \"s3\": \"aaa\" }\nassert my_solution.findMinimumOperations(**test_input) == 7\n\ntest_input = { \"s1\": \"b\", \"s2\": \"bccaaba\", \"s3\": \"ba\" }\nassert my_solution.findMinimumOperations(**test_input) == 7\n\ntest_input = { \"s1\": \"b\", \"s2\": \"bacccab\", \"s3\": \"cc\" }\nassert my_solution.findMinimumOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"ca\", \"s2\": \"cccabb\", \"s3\": \"cb\" }\nassert my_solution.findMinimumOperations(**test_input) == 7\n\ntest_input = { \"s1\": \"ccb\", \"s2\": \"ccba\", \"s3\": \"ccb\" }\nassert my_solution.findMinimumOperations(**test_input) == 1\n\ntest_input = { \"s1\": \"mbooi\", \"s2\": \"pdq\", \"s3\": \"br\" }\nassert my_solution.findMinimumOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"xxfzj\", \"s2\": \"faho\", \"s3\": \"c\" }\nassert my_solution.findMinimumOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"acbc\", \"s2\": \"acba\", \"s3\": \"acb\" }\nassert my_solution.findMinimumOperations(**test_input) == 2\n\ntest_input = { \"s1\": \"aduyyk\", \"s2\": \"v\", \"s3\": \"lpyt\" }\nassert my_solution.findMinimumOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"xd\", \"s2\": \"sl\", \"s3\": \"azoeaje\" }\nassert my_solution.findMinimumOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"bbbaa\", \"s2\": \"bacab\", \"s3\": \"b\" }\nassert my_solution.findMinimumOperations(**test_input) == 8\n\ntest_input = { \"s1\": \"cibn\", \"s2\": \"ioom\", \"s3\": \"bxa\" }\nassert my_solution.findMinimumOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"bcb\", \"s2\": \"bbac\", \"s3\": \"cbbc\" }\nassert my_solution.findMinimumOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"aabbb\", \"s2\": \"cc\", \"s3\": \"cccb\" }\nassert my_solution.findMinimumOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"i\", \"s2\": \"xqsfy\", \"s3\": \"diqae\" }\nassert my_solution.findMinimumOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"iq\", \"s2\": \"iimanmy\", \"s3\": \"id\" }\nassert my_solution.findMinimumOperations(**test_input) == 8\n\ntest_input = { \"s1\": \"pitggt\", \"s2\": \"pi\", \"s3\": \"pih\" }\nassert my_solution.findMinimumOperations(**test_input) == 5\n\ntest_input = { \"s1\": \"ten\", \"s2\": \"ten\", \"s3\": \"tenob\" }\nassert my_solution.findMinimumOperations(**test_input) == 2\n\ntest_input = { \"s1\": \"vejy\", \"s2\": \"fbqfo\", \"s3\": \"gl\" }\nassert my_solution.findMinimumOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"aca\", \"s2\": \"abcc\", \"s3\": \"accba\" }\nassert my_solution.findMinimumOperations(**test_input) == 9\n\ntest_input = { \"s1\": \"br\", \"s2\": \"br\", \"s3\": \"brvhgtou\" }\nassert my_solution.findMinimumOperations(**test_input) == 6\n\ntest_input = { \"s1\": \"c\", \"s2\": \"bcc\", \"s3\": \"aacbcaca\" }\nassert my_solution.findMinimumOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"cab\", \"s2\": \"caac\", \"s3\": \"cacbb\" }\nassert my_solution.findMinimumOperations(**test_input) == 6\n\ntest_input = { \"s1\": \"ccab\", \"s2\": \"cbbcbb\", \"s3\": \"ca\" }\nassert my_solution.findMinimumOperations(**test_input) == 9\n\ntest_input = { \"s1\": \"inuc\", \"s2\": \"iwpdfj\", \"s3\": \"ib\" }\nassert my_solution.findMinimumOperations(**test_input) == 9\n\ntest_input = { \"s1\": \"jrrpyyc\", \"s2\": \"jr\", \"s3\": \"jrt\" }\nassert my_solution.findMinimumOperations(**test_input) == 6\n\ntest_input = { \"s1\": \"l\", \"s2\": \"gebqrgnz\", \"s3\": \"jkr\" }\nassert my_solution.findMinimumOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"naynn\", \"s2\": \"ax\", \"s3\": \"bhdcz\" }\nassert my_solution.findMinimumOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"rexmx\", \"s2\": \"ujmbg\", \"s3\": \"gg\" }\nassert my_solution.findMinimumOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"aacbcb\", \"s2\": \"a\", \"s3\": \"acaaac\" }\nassert my_solution.findMinimumOperations(**test_input) == 10\n\ntest_input = { \"s1\": \"acbb\", \"s2\": \"acbacc\", \"s3\": \"acb\" }\nassert my_solution.findMinimumOperations(**test_input) == 4\n\ntest_input = { \"s1\": \"baacbab\", \"s2\": \"bcc\", \"s3\": \"bca\" }\nassert my_solution.findMinimumOperations(**test_input) == 10\n\ntest_input = { \"s1\": \"bcacbba\", \"s2\": \"bca\", \"s3\": \"bca\" }\nassert my_solution.findMinimumOperations(**test_input) == 4\n\ntest_input = { \"s1\": \"bcaca\", \"s2\": \"bcaba\", \"s3\": \"bca\" }\nassert my_solution.findMinimumOperations(**test_input) == 4\n\ntest_input = { \"s1\": \"ba\", \"s2\": \"bcbcab\", \"s3\": \"bbcbb\" }\nassert my_solution.findMinimumOperations(**test_input) == 10\n\ntest_input = { \"s1\": \"cabc\", \"s2\": \"cab\", \"s3\": \"cabbac\" }\nassert my_solution.findMinimumOperations(**test_input) == 4\n\ntest_input = { \"s1\": \"bbbbcaac\", \"s2\": \"a\", \"s3\": \"cbcc\" }\nassert my_solution.findMinimumOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"gjbtodtym\", \"s2\": \"gxp\", \"s3\": \"g\" }\nassert my_solution.findMinimumOperations(**test_input) == 10\n\ntest_input = { \"s1\": \"hfkq\", \"s2\": \"hfrbvno\", \"s3\": \"hf\" }\nassert my_solution.findMinimumOperations(**test_input) == 7\n\ntest_input = { \"s1\": \"hym\", \"s2\": \"hl\", \"s3\": \"hshxmbbj\" }\nassert my_solution.findMinimumOperations(**test_input) == 10\n\ntest_input = { \"s1\": \"mkdflu\", \"s2\": \"mmbn\", \"s3\": \"mge\" }\nassert my_solution.findMinimumOperations(**test_input) == 10\n\ntest_input = { \"s1\": \"nvlobl\", \"s2\": \"mekbzd\", \"s3\": \"s\" }\nassert my_solution.findMinimumOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"rpa\", \"s2\": \"rpaxpoh\", \"s3\": \"rpa\" }\nassert my_solution.findMinimumOperations(**test_input) == 4\n\ntest_input = { \"s1\": \"ac\", \"s2\": \"aacccccbc\", \"s3\": \"acc\" }\nassert my_solution.findMinimumOperations(**test_input) == 11\n\ntest_input = { \"s1\": \"abb\", \"s2\": \"abaac\", \"s3\": \"abcaca\" }\nassert my_solution.findMinimumOperations(**test_input) == 8\n\ntest_input = { \"s1\": \"caa\", \"s2\": \"caccaccacb\", \"s3\": \"c\" }\nassert my_solution.findMinimumOperations(**test_input) == 11\n\ntest_input = { \"s1\": \"baccaab\", \"s2\": \"cababc\", \"s3\": \"a\" }\nassert my_solution.findMinimumOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"cacbb\", \"s2\": \"ca\", \"s3\": \"cacbcac\" }\nassert my_solution.findMinimumOperations(**test_input) == 8\n\ntest_input = { \"s1\": \"cbba\", \"s2\": \"cabcabab\", \"s3\": \"ca\" }\nassert my_solution.findMinimumOperations(**test_input) == 11\n\ntest_input = { \"s1\": \"cb\", \"s2\": \"cbcbb\", \"s3\": \"cbaaabb\" }\nassert my_solution.findMinimumOperations(**test_input) == 8\n\ntest_input = { \"s1\": \"ccabaa\", \"s2\": \"ccabc\", \"s3\": \"cca\" }\nassert my_solution.findMinimumOperations(**test_input) == 5\n\ntest_input = { \"s1\": \"ccb\", \"s2\": \"ccac\", \"s3\": \"cccaaca\" }\nassert my_solution.findMinimumOperations(**test_input) == 8\n\ntest_input = { \"s1\": \"ccccbb\", \"s2\": \"cccc\", \"s3\": \"cccc\" }\nassert my_solution.findMinimumOperations(**test_input) == 2\n\ntest_input = { \"s1\": \"cxxq\", \"s2\": \"cxx\", \"s3\": \"cxxdeqh\" }\nassert my_solution.findMinimumOperations(**test_input) == 5\n\ntest_input = { \"s1\": \"d\", \"s2\": \"dffjiulzya\", \"s3\": \"dke\" }\nassert my_solution.findMinimumOperations(**test_input) == 11\n\ntest_input = { \"s1\": \"dogv\", \"s2\": \"dofjkhx\", \"s3\": \"dog\" }\nassert my_solution.findMinimumOperations(**test_input) == 8\n\ntest_input = { \"s1\": \"dwefrocz\", \"s2\": \"dzz\", \"s3\": \"dwn\" }\nassert my_solution.findMinimumOperations(**test_input) == 11\n\ntest_input = { \"s1\": \"etr\", \"s2\": \"ejb\", \"s3\": \"etpubpvr\" }\nassert my_solution.findMinimumOperations(**test_input) == 11\n\ntest_input = { \"s1\": \"f\", \"s2\": \"morycy\", \"s3\": \"vledqoo\" }\nassert my_solution.findMinimumOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"ful\", \"s2\": \"fular\", \"s3\": \"fulvkv\" }\nassert my_solution.findMinimumOperations(**test_input) == 5\n\ntest_input = { \"s1\": \"kzwat\", \"s2\": \"ku\", \"s3\": \"koftvbd\" }\nassert my_solution.findMinimumOperations(**test_input) == 11\n\ntest_input = { \"s1\": \"qey\", \"s2\": \"qevtkbss\", \"s3\": \"qeb\" }\nassert my_solution.findMinimumOperations(**test_input) == 8\n\ntest_input = { \"s1\": \"saqy\", \"s2\": \"hvufcpko\", \"s3\": \"xm\" }\nassert my_solution.findMinimumOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"tllwgcdi\", \"s2\": \"t\", \"s3\": \"tvham\" }\nassert my_solution.findMinimumOperations(**test_input) == 11\n\ntest_input = { \"s1\": \"vmwdmadn\", \"s2\": \"vmw\", \"s3\": \"vmw\" }\nassert my_solution.findMinimumOperations(**test_input) == 5\n\ntest_input = { \"s1\": \"xobwwhu\", \"s2\": \"xobb\", \"s3\": \"xob\" }\nassert my_solution.findMinimumOperations(**test_input) == 5\n\ntest_input = { \"s1\": \"yptajimiz\", \"s2\": \"yp\", \"s3\": \"ypr\" }\nassert my_solution.findMinimumOperations(**test_input) == 8\n\ntest_input = { \"s1\": \"z\", \"s2\": \"zcrouxlukb\", \"s3\": \"zbb\" }\nassert my_solution.findMinimumOperations(**test_input) == 11\n\ntest_input = { \"s1\": \"aaabc\", \"s2\": \"aaaa\", \"s3\": \"aaaabc\" }\nassert my_solution.findMinimumOperations(**test_input) == 6\n\ntest_input = { \"s1\": \"aaa\", \"s2\": \"aab\", \"s3\": \"aabaacaab\" }\nassert my_solution.findMinimumOperations(**test_input) == 9\n\ntest_input = { \"s1\": \"aac\", \"s2\": \"aac\", \"s3\": \"aacabbbca\" }\nassert my_solution.findMinimumOperations(**test_input) == 6\n\ntest_input = { \"s1\": \"abaab\", \"s2\": \"abaabb\", \"s3\": \"abaa\" }\nassert my_solution.findMinimumOperations(**test_input) == 3\n\ntest_input = { \"s1\": \"abcomon\", \"s2\": \"gkuneup\", \"s3\": \"q\" }\nassert my_solution.findMinimumOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"acc\", \"s2\": \"accacb\", \"s3\": \"acbabc\" }\nassert my_solution.findMinimumOperations(**test_input) == 9\n\ntest_input = { \"s1\": \"cca\", \"s2\": \"caaab\", \"s3\": \"babbacc\" }\nassert my_solution.findMinimumOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"bccbc\", \"s2\": \"bc\", \"s3\": \"bcccbcac\" }\nassert my_solution.findMinimumOperations(**test_input) == 9\n\ntest_input = { \"s1\": \"bpp\", \"s2\": \"bin\", \"s3\": \"bfkbyhubw\" }\nassert my_solution.findMinimumOperations(**test_input) == 12\n\ntest_input = { \"s1\": \"bbsyg\", \"s2\": \"blbp\", \"s3\": \"brghkr\" }\nassert my_solution.findMinimumOperations(**test_input) == 12\n\ntest_input = { \"s1\": \"bxpvamp\", \"s2\": \"bxpv\", \"s3\": \"bxpv\" }\nassert my_solution.findMinimumOperations(**test_input) == 3\n\ntest_input = { \"s1\": \"ccbabca\", \"s2\": \"cbcbaca\", \"s3\": \"c\" }\nassert my_solution.findMinimumOperations(**test_input) == 12\n\ntest_input = { \"s1\": \"accb\", \"s2\": \"bbc\", \"s3\": \"cbbaccba\" }\nassert my_solution.findMinimumOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"cbccc\", \"s2\": \"cbc\", \"s3\": \"cbcccba\" }\nassert my_solution.findMinimumOperations(**test_input) == 6\n\ntest_input = { \"s1\": \"cac\", \"s2\": \"ccacc\", \"s3\": \"cabacba\" }\nassert my_solution.findMinimumOperations(**test_input) == 12\n\ntest_input = { \"s1\": \"ccb\", \"s2\": \"ccbcb\", \"s3\": \"ccbccab\" }\nassert my_solution.findMinimumOperations(**test_input) == 6\n\ntest_input = { \"s1\": \"caacabcbc\", \"s2\": \"ccb\", \"s3\": \"ccc\" }\nassert my_solution.findMinimumOperations(**test_input) == 12\n\ntest_input = { \"s1\": \"cccabaacc\", \"s2\": \"ccc\", \"s3\": \"ccc\" }\nassert my_solution.findMinimumOperations(**test_input) == 6\n\ntest_input = { \"s1\": \"ajjdre\", \"s2\": \"gsrq\", \"s3\": \"eurcj\" }\nassert my_solution.findMinimumOperations(**test_input) == -1", "start_time": 1700361000} +{"task_id": "weekly-contest-372-separate-black-and-white-balls", "url": "https://leetcode.com/problems/separate-black-and-white-balls", "title": "separate-black-and-white-balls", "meta": {"questionId": "3195", "questionFrontendId": "2938", "title": "Separate Black and White Balls", "titleSlug": "separate-black-and-white-balls", "isPaidOnly": false, "difficulty": "Medium", "likes": 133, "dislikes": 3, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nThere are n balls on a table, each ball has a color black or white.\nYou are given a 0-indexed binary string s of length n, where 1 and 0 represent black and white balls, respectively.\nIn each step, you can choose two adjacent balls and swap them.\nReturn the minimum number of steps to group all the black balls to the right and all the white balls to the left.\n\nExample 1:\n\nInput: s = \"101\"\nOutput: 1\nExplanation: We can group all the black balls to the right in the following way:\n- Swap s[0] and s[1], s = \"011\".\nInitially, 1s are not grouped together, requiring at least 1 step to group them to the right.\nExample 2:\n\nInput: s = \"100\"\nOutput: 2\nExplanation: We can group all the black balls to the right in the following way:\n- Swap s[0] and s[1], s = \"010\".\n- Swap s[1] and s[2], s = \"001\".\nIt can be proven that the minimum number of steps needed is 2.\n\nExample 3:\n\nInput: s = \"0111\"\nOutput: 0\nExplanation: All the black balls are already grouped to the right.\n\n\nConstraints:\n\n1 <= n == s.length <= 105\ns[i] is either '0' or '1'.\n\"\"\"\nclass Solution:\n def minimumSteps(self, s: str) -> int:\n ", "prompt_sft": "There are n balls on a table, each ball has a color black or white.\nYou are given a 0-indexed binary string s of length n, where 1 and 0 represent black and white balls, respectively.\nIn each step, you can choose two adjacent balls and swap them.\nReturn the minimum number of steps to group all the black balls to the right and all the white balls to the left.\n\nExample 1:\n\nInput: s = \"101\"\nOutput: 1\nExplanation: We can group all the black balls to the right in the following way:\n- Swap s[0] and s[1], s = \"011\".\nInitially, 1s are not grouped together, requiring at least 1 step to group them to the right.\nExample 2:\n\nInput: s = \"100\"\nOutput: 2\nExplanation: We can group all the black balls to the right in the following way:\n- Swap s[0] and s[1], s = \"010\".\n- Swap s[1] and s[2], s = \"001\".\nIt can be proven that the minimum number of steps needed is 2.\n\nExample 3:\n\nInput: s = \"0111\"\nOutput: 0\nExplanation: All the black balls are already grouped to the right.\n\n\nConstraints:\n\n1 <= n == s.length <= 105\ns[i] is either '0' or '1'.\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def minimumSteps(self, s: str) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"s\": \"101\" }\nassert my_solution.minimumSteps(**test_input) == 1\n\ntest_input = { \"s\": \"100\" }\nassert my_solution.minimumSteps(**test_input) == 2\n\ntest_input = { \"s\": \"0111\" }\nassert my_solution.minimumSteps(**test_input) == 0\n\ntest_input = { \"s\": \"11000111\" }\nassert my_solution.minimumSteps(**test_input) == 6\n\ntest_input = { \"s\": \"01010001\" }\nassert my_solution.minimumSteps(**test_input) == 7\n\ntest_input = { \"s\": \"0100101\" }\nassert my_solution.minimumSteps(**test_input) == 4\n\ntest_input = { \"s\": \"111111111100100010\" }\nassert my_solution.minimumSteps(**test_input) == 65\n\ntest_input = { \"s\": \"10100000110010011010\" }\nassert my_solution.minimumSteps(**test_input) == 44\n\ntest_input = { \"s\": \"1101110000111011110\" }\nassert my_solution.minimumSteps(**test_input) == 42\n\ntest_input = { \"s\": \"01000010111010001\" }\nassert my_solution.minimumSteps(**test_input) == 29\n\ntest_input = { \"s\": \"11110\" }\nassert my_solution.minimumSteps(**test_input) == 4\n\ntest_input = { \"s\": \"010001001011010\" }\nassert my_solution.minimumSteps(**test_input) == 21\n\ntest_input = { \"s\": \"0011011\" }\nassert my_solution.minimumSteps(**test_input) == 2\n\ntest_input = { \"s\": \"001\" }\nassert my_solution.minimumSteps(**test_input) == 0\n\ntest_input = { \"s\": \"000100100\" }\nassert my_solution.minimumSteps(**test_input) == 6\n\ntest_input = { \"s\": \"00110\" }\nassert my_solution.minimumSteps(**test_input) == 2\n\ntest_input = { \"s\": \"001110001110001\" }\nassert my_solution.minimumSteps(**test_input) == 27\n\ntest_input = { \"s\": \"10000000001\" }\nassert my_solution.minimumSteps(**test_input) == 9\n\ntest_input = { \"s\": \"01\" }\nassert my_solution.minimumSteps(**test_input) == 0\n\ntest_input = { \"s\": \"0100011100001100100\" }\nassert my_solution.minimumSteps(**test_input) == 45\n\ntest_input = { \"s\": \"1010110\" }\nassert my_solution.minimumSteps(**test_input) == 7\n\ntest_input = { \"s\": \"010010000\" }\nassert my_solution.minimumSteps(**test_input) == 10\n\ntest_input = { \"s\": \"100110\" }\nassert my_solution.minimumSteps(**test_input) == 5\n\ntest_input = { \"s\": \"1100\" }\nassert my_solution.minimumSteps(**test_input) == 4\n\ntest_input = { \"s\": \"000110\" }\nassert my_solution.minimumSteps(**test_input) == 2\n\ntest_input = { \"s\": \"001101101111000000\" }\nassert my_solution.minimumSteps(**test_input) == 54\n\ntest_input = { \"s\": \"011101011\" }\nassert my_solution.minimumSteps(**test_input) == 7\n\ntest_input = { \"s\": \"0110111111110\" }\nassert my_solution.minimumSteps(**test_input) == 12\n\ntest_input = { \"s\": \"1111001111111011111\" }\nassert my_solution.minimumSteps(**test_input) == 19\n\ntest_input = { \"s\": \"0101111\" }\nassert my_solution.minimumSteps(**test_input) == 1\n\ntest_input = { \"s\": \"00010101100110011\" }\nassert my_solution.minimumSteps(**test_input) == 23\n\ntest_input = { \"s\": \"01010110110111011001\" }\nassert my_solution.minimumSteps(**test_input) == 44\n\ntest_input = { \"s\": \"0\" }\nassert my_solution.minimumSteps(**test_input) == 0\n\ntest_input = { \"s\": \"1101111010111001010\" }\nassert my_solution.minimumSteps(**test_input) == 58\n\ntest_input = { \"s\": \"01100010\" }\nassert my_solution.minimumSteps(**test_input) == 9\n\ntest_input = { \"s\": \"10010000010\" }\nassert my_solution.minimumSteps(**test_input) == 15\n\ntest_input = { \"s\": \"11011101000100001\" }\nassert my_solution.minimumSteps(**test_input) == 53\n\ntest_input = { \"s\": \"00\" }\nassert my_solution.minimumSteps(**test_input) == 0\n\ntest_input = { \"s\": \"10100101011001100111\" }\nassert my_solution.minimumSteps(**test_input) == 40\n\ntest_input = { \"s\": \"0101\" }\nassert my_solution.minimumSteps(**test_input) == 1\n\ntest_input = { \"s\": \"00101010100\" }\nassert my_solution.minimumSteps(**test_input) == 14\n\ntest_input = { \"s\": \"00110111110010\" }\nassert my_solution.minimumSteps(**test_input) == 24\n\ntest_input = { \"s\": \"111010000001000001\" }\nassert my_solution.minimumSteps(**test_input) == 52\n\ntest_input = { \"s\": \"0101101000111010\" }\nassert my_solution.minimumSteps(**test_input) == 31\n\ntest_input = { \"s\": \"1010111111\" }\nassert my_solution.minimumSteps(**test_input) == 3\n\ntest_input = { \"s\": \"110110001001110\" }\nassert my_solution.minimumSteps(**test_input) == 32\n\ntest_input = { \"s\": \"111010\" }\nassert my_solution.minimumSteps(**test_input) == 7\n\ntest_input = { \"s\": \"10\" }\nassert my_solution.minimumSteps(**test_input) == 1\n\ntest_input = { \"s\": \"111110\" }\nassert my_solution.minimumSteps(**test_input) == 5\n\ntest_input = { \"s\": \"0111100000101101110\" }\nassert my_solution.minimumSteps(**test_input) == 42\n\ntest_input = { \"s\": \"111010100\" }\nassert my_solution.minimumSteps(**test_input) == 17\n\ntest_input = { \"s\": \"0001000100111000\" }\nassert my_solution.minimumSteps(**test_input) == 22\n\ntest_input = { \"s\": \"011001111110110010\" }\nassert my_solution.minimumSteps(**test_input) == 43\n\ntest_input = { \"s\": \"11100\" }\nassert my_solution.minimumSteps(**test_input) == 6\n\ntest_input = { \"s\": \"0100001101110001\" }\nassert my_solution.minimumSteps(**test_input) == 25\n\ntest_input = { \"s\": \"111\" }\nassert my_solution.minimumSteps(**test_input) == 0\n\ntest_input = { \"s\": \"100010\" }\nassert my_solution.minimumSteps(**test_input) == 5\n\ntest_input = { \"s\": \"101001\" }\nassert my_solution.minimumSteps(**test_input) == 5\n\ntest_input = { \"s\": \"00111010100100100111\" }\nassert my_solution.minimumSteps(**test_input) == 43\n\ntest_input = { \"s\": \"100010111\" }\nassert my_solution.minimumSteps(**test_input) == 5\n\ntest_input = { \"s\": \"001110000101011\" }\nassert my_solution.minimumSteps(**test_input) == 21\n\ntest_input = { \"s\": \"111011011101101\" }\nassert my_solution.minimumSteps(**test_input) == 26\n\ntest_input = { \"s\": \"1110101\" }\nassert my_solution.minimumSteps(**test_input) == 7\n\ntest_input = { \"s\": \"00111010100111\" }\nassert my_solution.minimumSteps(**test_input) == 17\n\ntest_input = { \"s\": \"010\" }\nassert my_solution.minimumSteps(**test_input) == 1\n\ntest_input = { \"s\": \"111001\" }\nassert my_solution.minimumSteps(**test_input) == 6\n\ntest_input = { \"s\": \"1100011\" }\nassert my_solution.minimumSteps(**test_input) == 6\n\ntest_input = { \"s\": \"0110001011001110111\" }\nassert my_solution.minimumSteps(**test_input) == 27\n\ntest_input = { \"s\": \"0001111111011101\" }\nassert my_solution.minimumSteps(**test_input) == 17\n\ntest_input = { \"s\": \"0110110100001\" }\nassert my_solution.minimumSteps(**test_input) == 26\n\ntest_input = { \"s\": \"11110110011000011\" }\nassert my_solution.minimumSteps(**test_input) == 48\n\ntest_input = { \"s\": \"10100\" }\nassert my_solution.minimumSteps(**test_input) == 5\n\ntest_input = { \"s\": \"10100001\" }\nassert my_solution.minimumSteps(**test_input) == 9\n\ntest_input = { \"s\": \"01000011000\" }\nassert my_solution.minimumSteps(**test_input) == 13\n\ntest_input = { \"s\": \"110001001001\" }\nassert my_solution.minimumSteps(**test_input) == 20\n\ntest_input = { \"s\": \"01100011010011110\" }\nassert my_solution.minimumSteps(**test_input) == 29\n\ntest_input = { \"s\": \"01111001111\" }\nassert my_solution.minimumSteps(**test_input) == 8\n\ntest_input = { \"s\": \"1110100010000110110\" }\nassert my_solution.minimumSteps(**test_input) == 51\n\ntest_input = { \"s\": \"1101000111001111100\" }\nassert my_solution.minimumSteps(**test_input) == 45\n\ntest_input = { \"s\": \"0110000\" }\nassert my_solution.minimumSteps(**test_input) == 8\n\ntest_input = { \"s\": \"001010010010\" }\nassert my_solution.minimumSteps(**test_input) == 15\n\ntest_input = { \"s\": \"11101\" }\nassert my_solution.minimumSteps(**test_input) == 3\n\ntest_input = { \"s\": \"00110110\" }\nassert my_solution.minimumSteps(**test_input) == 6\n\ntest_input = { \"s\": \"001010\" }\nassert my_solution.minimumSteps(**test_input) == 3\n\ntest_input = { \"s\": \"000101010101010\" }\nassert my_solution.minimumSteps(**test_input) == 21\n\ntest_input = { \"s\": \"1111011\" }\nassert my_solution.minimumSteps(**test_input) == 4\n\ntest_input = { \"s\": \"0000101011001101011\" }\nassert my_solution.minimumSteps(**test_input) == 24\n\ntest_input = { \"s\": \"011010\" }\nassert my_solution.minimumSteps(**test_input) == 5\n\ntest_input = { \"s\": \"110010100011110101\" }\nassert my_solution.minimumSteps(**test_input) == 36\n\ntest_input = { \"s\": \"000000001\" }\nassert my_solution.minimumSteps(**test_input) == 0\n\ntest_input = { \"s\": \"011001\" }\nassert my_solution.minimumSteps(**test_input) == 4\n\ntest_input = { \"s\": \"01111010011110111111\" }\nassert my_solution.minimumSteps(**test_input) == 23\n\ntest_input = { \"s\": \"10001111\" }\nassert my_solution.minimumSteps(**test_input) == 3\n\ntest_input = { \"s\": \"11011010001111\" }\nassert my_solution.minimumSteps(**test_input) == 21\n\ntest_input = { \"s\": \"0110101010100000111\" }\nassert my_solution.minimumSteps(**test_input) == 44\n\ntest_input = { \"s\": \"0000001000110\" }\nassert my_solution.minimumSteps(**test_input) == 6\n\ntest_input = { \"s\": \"1\" }\nassert my_solution.minimumSteps(**test_input) == 0\n\ntest_input = { \"s\": \"0111100110100\" }\nassert my_solution.minimumSteps(**test_input) == 28\n\ntest_input = { \"s\": \"101010110011101011\" }\nassert my_solution.minimumSteps(**test_input) == 33\n\ntest_input = { \"s\": \"1011101\" }\nassert my_solution.minimumSteps(**test_input) == 5", "start_time": 1700361000} +{"task_id": "weekly-contest-372-maximum-xor-product", "url": "https://leetcode.com/problems/maximum-xor-product", "title": "maximum-xor-product", "meta": {"questionId": "3192", "questionFrontendId": "2939", "title": "Maximum Xor Product", "titleSlug": "maximum-xor-product", "isPaidOnly": false, "difficulty": "Medium", "likes": 140, "dislikes": 63, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nGiven three integers a, b, and n, return the maximum value of (a XOR x) * (b XOR x) where 0 <= x < 2n.\nSince the answer may be too large, return it modulo 109 + 7.\nNote that XOR is the bitwise XOR operation.\n\nExample 1:\n\nInput: a = 12, b = 5, n = 4\nOutput: 98\nExplanation: For x = 2, (a XOR x) = 14 and (b XOR x) = 7. Hence, (a XOR x) * (b XOR x) = 98. \nIt can be shown that 98 is the maximum value of (a XOR x) * (b XOR x) for all 0 <= x < 2n.\n\nExample 2:\n\nInput: a = 6, b = 7 , n = 5\nOutput: 930\nExplanation: For x = 25, (a XOR x) = 31 and (b XOR x) = 30. Hence, (a XOR x) * (b XOR x) = 930.\nIt can be shown that 930 is the maximum value of (a XOR x) * (b XOR x) for all 0 <= x < 2n.\nExample 3:\n\nInput: a = 1, b = 6, n = 3\nOutput: 12\nExplanation: For x = 5, (a XOR x) = 4 and (b XOR x) = 3. Hence, (a XOR x) * (b XOR x) = 12.\nIt can be shown that 12 is the maximum value of (a XOR x) * (b XOR x) for all 0 <= x < 2n.\n\n\nConstraints:\n\n0 <= a, b < 250\n0 <= n <= 50\n\"\"\"\nclass Solution:\n def maximumXorProduct(self, a: int, b: int, n: int) -> int:\n ", "prompt_sft": "Given three integers a, b, and n, return the maximum value of (a XOR x) * (b XOR x) where 0 <= x < 2n.\nSince the answer may be too large, return it modulo 109 + 7.\nNote that XOR is the bitwise XOR operation.\n\nExample 1:\n\nInput: a = 12, b = 5, n = 4\nOutput: 98\nExplanation: For x = 2, (a XOR x) = 14 and (b XOR x) = 7. Hence, (a XOR x) * (b XOR x) = 98. \nIt can be shown that 98 is the maximum value of (a XOR x) * (b XOR x) for all 0 <= x < 2n.\n\nExample 2:\n\nInput: a = 6, b = 7 , n = 5\nOutput: 930\nExplanation: For x = 25, (a XOR x) = 31 and (b XOR x) = 30. Hence, (a XOR x) * (b XOR x) = 930.\nIt can be shown that 930 is the maximum value of (a XOR x) * (b XOR x) for all 0 <= x < 2n.\nExample 3:\n\nInput: a = 1, b = 6, n = 3\nOutput: 12\nExplanation: For x = 5, (a XOR x) = 4 and (b XOR x) = 3. Hence, (a XOR x) * (b XOR x) = 12.\nIt can be shown that 12 is the maximum value of (a XOR x) * (b XOR x) for all 0 <= x < 2n.\n\n\nConstraints:\n\n0 <= a, b < 250\n0 <= n <= 50\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def maximumXorProduct(self, a: int, b: int, n: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"a\": 12, \"b\": 5, \"n\": 4 }\nassert my_solution.maximumXorProduct(**test_input) == 98\n\ntest_input = { \"a\": 6, \"b\": 7, \"n\": 5 }\nassert my_solution.maximumXorProduct(**test_input) == 930\n\ntest_input = { \"a\": 1, \"b\": 6, \"n\": 3 }\nassert my_solution.maximumXorProduct(**test_input) == 12\n\ntest_input = { \"a\": 0, \"b\": 0, \"n\": 1 }\nassert my_solution.maximumXorProduct(**test_input) == 1\n\ntest_input = { \"a\": 0, \"b\": 1, \"n\": 6 }\nassert my_solution.maximumXorProduct(**test_input) == 3906\n\ntest_input = { \"a\": 0, \"b\": 2, \"n\": 7 }\nassert my_solution.maximumXorProduct(**test_input) == 15875\n\ntest_input = { \"a\": 0, \"b\": 3, \"n\": 1 }\nassert my_solution.maximumXorProduct(**test_input) == 2\n\ntest_input = { \"a\": 0, \"b\": 4, \"n\": 0 }\nassert my_solution.maximumXorProduct(**test_input) == 0\n\ntest_input = { \"a\": 0, \"b\": 5, \"n\": 6 }\nassert my_solution.maximumXorProduct(**test_input) == 3658\n\ntest_input = { \"a\": 0, \"b\": 6, \"n\": 1 }\nassert my_solution.maximumXorProduct(**test_input) == 7\n\ntest_input = { \"a\": 0, \"b\": 7, \"n\": 2 }\nassert my_solution.maximumXorProduct(**test_input) == 12\n\ntest_input = { \"a\": 0, \"b\": 8, \"n\": 5 }\nassert my_solution.maximumXorProduct(**test_input) == 713\n\ntest_input = { \"a\": 0, \"b\": 9, \"n\": 2 }\nassert my_solution.maximumXorProduct(**test_input) == 30\n\ntest_input = { \"a\": 0, \"b\": 10, \"n\": 7 }\nassert my_solution.maximumXorProduct(**test_input) == 14875\n\ntest_input = { \"a\": 0, \"b\": 11, \"n\": 4 }\nassert my_solution.maximumXorProduct(**test_input) == 84\n\ntest_input = { \"a\": 0, \"b\": 12, \"n\": 2 }\nassert my_solution.maximumXorProduct(**test_input) == 45\n\ntest_input = { \"a\": 0, \"b\": 13, \"n\": 2 }\nassert my_solution.maximumXorProduct(**test_input) == 42\n\ntest_input = { \"a\": 0, \"b\": 14, \"n\": 0 }\nassert my_solution.maximumXorProduct(**test_input) == 0\n\ntest_input = { \"a\": 0, \"b\": 15, \"n\": 6 }\nassert my_solution.maximumXorProduct(**test_input) == 3080\n\ntest_input = { \"a\": 1, \"b\": 0, \"n\": 3 }\nassert my_solution.maximumXorProduct(**test_input) == 42\n\ntest_input = { \"a\": 1, \"b\": 1, \"n\": 4 }\nassert my_solution.maximumXorProduct(**test_input) == 225\n\ntest_input = { \"a\": 1, \"b\": 2, \"n\": 6 }\nassert my_solution.maximumXorProduct(**test_input) == 3782\n\ntest_input = { \"a\": 1, \"b\": 3, \"n\": 2 }\nassert my_solution.maximumXorProduct(**test_input) == 3\n\ntest_input = { \"a\": 1, \"b\": 4, \"n\": 5 }\nassert my_solution.maximumXorProduct(**test_input) == 810\n\ntest_input = { \"a\": 1, \"b\": 5, \"n\": 4 }\nassert my_solution.maximumXorProduct(**test_input) == 165\n\ntest_input = { \"a\": 1, \"b\": 6, \"n\": 4 }\nassert my_solution.maximumXorProduct(**test_input) == 132\n\ntest_input = { \"a\": 1, \"b\": 7, \"n\": 2 }\nassert my_solution.maximumXorProduct(**test_input) == 15\n\ntest_input = { \"a\": 1, \"b\": 8, \"n\": 0 }\nassert my_solution.maximumXorProduct(**test_input) == 8\n\ntest_input = { \"a\": 1, \"b\": 9, \"n\": 2 }\nassert my_solution.maximumXorProduct(**test_input) == 33\n\ntest_input = { \"a\": 1, \"b\": 10, \"n\": 7 }\nassert my_solution.maximumXorProduct(**test_input) == 14756\n\ntest_input = { \"a\": 1, \"b\": 11, \"n\": 7 }\nassert my_solution.maximumXorProduct(**test_input) == 14875\n\ntest_input = { \"a\": 1, \"b\": 12, \"n\": 7 }\nassert my_solution.maximumXorProduct(**test_input) == 14518\n\ntest_input = { \"a\": 1, \"b\": 13, \"n\": 0 }\nassert my_solution.maximumXorProduct(**test_input) == 13\n\ntest_input = { \"a\": 1, \"b\": 14, \"n\": 5 }\nassert my_solution.maximumXorProduct(**test_input) == 552\n\ntest_input = { \"a\": 1, \"b\": 15, \"n\": 4 }\nassert my_solution.maximumXorProduct(**test_input) == 63\n\ntest_input = { \"a\": 2, \"b\": 0, \"n\": 0 }\nassert my_solution.maximumXorProduct(**test_input) == 0\n\ntest_input = { \"a\": 2, \"b\": 1, \"n\": 0 }\nassert my_solution.maximumXorProduct(**test_input) == 2\n\ntest_input = { \"a\": 2, \"b\": 2, \"n\": 0 }\nassert my_solution.maximumXorProduct(**test_input) == 4\n\ntest_input = { \"a\": 2, \"b\": 3, \"n\": 5 }\nassert my_solution.maximumXorProduct(**test_input) == 930\n\ntest_input = { \"a\": 2, \"b\": 4, \"n\": 4 }\nassert my_solution.maximumXorProduct(**test_input) == 143\n\ntest_input = { \"a\": 2, \"b\": 5, \"n\": 5 }\nassert my_solution.maximumXorProduct(**test_input) == 756\n\ntest_input = { \"a\": 2, \"b\": 6, \"n\": 4 }\nassert my_solution.maximumXorProduct(**test_input) == 165\n\ntest_input = { \"a\": 2, \"b\": 7, \"n\": 3 }\nassert my_solution.maximumXorProduct(**test_input) == 18\n\ntest_input = { \"a\": 2, \"b\": 8, \"n\": 1 }\nassert my_solution.maximumXorProduct(**test_input) == 27\n\ntest_input = { \"a\": 2, \"b\": 9, \"n\": 2 }\nassert my_solution.maximumXorProduct(**test_input) == 24\n\ntest_input = { \"a\": 2, \"b\": 10, \"n\": 5 }\nassert my_solution.maximumXorProduct(**test_input) == 713\n\ntest_input = { \"a\": 2, \"b\": 11, \"n\": 0 }\nassert my_solution.maximumXorProduct(**test_input) == 22\n\ntest_input = { \"a\": 2, \"b\": 12, \"n\": 2 }\nassert my_solution.maximumXorProduct(**test_input) == 39\n\ntest_input = { \"a\": 2, \"b\": 13, \"n\": 1 }\nassert my_solution.maximumXorProduct(**test_input) == 36\n\ntest_input = { \"a\": 2, \"b\": 14, \"n\": 0 }\nassert my_solution.maximumXorProduct(**test_input) == 28\n\ntest_input = { \"a\": 2, \"b\": 15, \"n\": 2 }\nassert my_solution.maximumXorProduct(**test_input) == 42\n\ntest_input = { \"a\": 3, \"b\": 0, \"n\": 6 }\nassert my_solution.maximumXorProduct(**test_input) == 3782\n\ntest_input = { \"a\": 3, \"b\": 1, \"n\": 6 }\nassert my_solution.maximumXorProduct(**test_input) == 3843\n\ntest_input = { \"a\": 3, \"b\": 2, \"n\": 2 }\nassert my_solution.maximumXorProduct(**test_input) == 6\n\ntest_input = { \"a\": 3, \"b\": 3, \"n\": 7 }\nassert my_solution.maximumXorProduct(**test_input) == 16129\n\ntest_input = { \"a\": 3, \"b\": 4, \"n\": 5 }\nassert my_solution.maximumXorProduct(**test_input) == 756\n\ntest_input = { \"a\": 3, \"b\": 5, \"n\": 4 }\nassert my_solution.maximumXorProduct(**test_input) == 143\n\ntest_input = { \"a\": 3, \"b\": 6, \"n\": 2 }\nassert my_solution.maximumXorProduct(**test_input) == 18\n\ntest_input = { \"a\": 3, \"b\": 7, \"n\": 2 }\nassert my_solution.maximumXorProduct(**test_input) == 21\n\ntest_input = { \"a\": 3, \"b\": 8, \"n\": 6 }\nassert my_solution.maximumXorProduct(**test_input) == 3300\n\ntest_input = { \"a\": 3, \"b\": 9, \"n\": 1 }\nassert my_solution.maximumXorProduct(**test_input) == 27\n\ntest_input = { \"a\": 3, \"b\": 10, \"n\": 5 }\nassert my_solution.maximumXorProduct(**test_input) == 690\n\ntest_input = { \"a\": 3, \"b\": 11, \"n\": 1 }\nassert my_solution.maximumXorProduct(**test_input) == 33\n\ntest_input = { \"a\": 3, \"b\": 12, \"n\": 1 }\nassert my_solution.maximumXorProduct(**test_input) == 36\n\ntest_input = { \"a\": 3, \"b\": 13, \"n\": 2 }\nassert my_solution.maximumXorProduct(**test_input) == 39\n\ntest_input = { \"a\": 3, \"b\": 14, \"n\": 0 }\nassert my_solution.maximumXorProduct(**test_input) == 42\n\ntest_input = { \"a\": 3, \"b\": 15, \"n\": 6 }\nassert my_solution.maximumXorProduct(**test_input) == 3245\n\ntest_input = { \"a\": 4, \"b\": 0, \"n\": 4 }\nassert my_solution.maximumXorProduct(**test_input) == 165\n\ntest_input = { \"a\": 4, \"b\": 1, \"n\": 2 }\nassert my_solution.maximumXorProduct(**test_input) == 18\n\ntest_input = { \"a\": 4, \"b\": 2, \"n\": 2 }\nassert my_solution.maximumXorProduct(**test_input) == 15\n\ntest_input = { \"a\": 4, \"b\": 3, \"n\": 0 }\nassert my_solution.maximumXorProduct(**test_input) == 12\n\ntest_input = { \"a\": 4, \"b\": 4, \"n\": 3 }\nassert my_solution.maximumXorProduct(**test_input) == 49\n\ntest_input = { \"a\": 4, \"b\": 5, \"n\": 3 }\nassert my_solution.maximumXorProduct(**test_input) == 42\n\ntest_input = { \"a\": 4, \"b\": 6, \"n\": 2 }\nassert my_solution.maximumXorProduct(**test_input) == 35\n\ntest_input = { \"a\": 4, \"b\": 7, \"n\": 3 }\nassert my_solution.maximumXorProduct(**test_input) == 30\n\ntest_input = { \"a\": 4, \"b\": 8, \"n\": 4 }\nassert my_solution.maximumXorProduct(**test_input) == 77\n\ntest_input = { \"a\": 4, \"b\": 9, \"n\": 7 }\nassert my_solution.maximumXorProduct(**test_input) == 14518\n\ntest_input = { \"a\": 4, \"b\": 10, \"n\": 0 }\nassert my_solution.maximumXorProduct(**test_input) == 40\n\ntest_input = { \"a\": 4, \"b\": 11, \"n\": 5 }\nassert my_solution.maximumXorProduct(**test_input) == 552\n\ntest_input = { \"a\": 4, \"b\": 12, \"n\": 6 }\nassert my_solution.maximumXorProduct(**test_input) == 3465\n\ntest_input = { \"a\": 4, \"b\": 13, \"n\": 7 }\nassert my_solution.maximumXorProduct(**test_input) == 14994\n\ntest_input = { \"a\": 4, \"b\": 14, \"n\": 5 }\nassert my_solution.maximumXorProduct(**test_input) == 667\n\ntest_input = { \"a\": 4, \"b\": 15, \"n\": 6 }\nassert my_solution.maximumXorProduct(**test_input) == 3300\n\ntest_input = { \"a\": 5, \"b\": 0, \"n\": 1 }\nassert my_solution.maximumXorProduct(**test_input) == 4\n\ntest_input = { \"a\": 5, \"b\": 1, \"n\": 3 }\nassert my_solution.maximumXorProduct(**test_input) == 21\n\ntest_input = { \"a\": 5, \"b\": 2, \"n\": 2 }\nassert my_solution.maximumXorProduct(**test_input) == 12\n\ntest_input = { \"a\": 5, \"b\": 3, \"n\": 7 }\nassert my_solution.maximumXorProduct(**test_input) == 15375\n\ntest_input = { \"a\": 5, \"b\": 4, \"n\": 7 }\nassert my_solution.maximumXorProduct(**test_input) == 16002\n\ntest_input = { \"a\": 5, \"b\": 5, \"n\": 0 }\nassert my_solution.maximumXorProduct(**test_input) == 25\n\ntest_input = { \"a\": 5, \"b\": 6, \"n\": 1 }\nassert my_solution.maximumXorProduct(**test_input) == 30\n\ntest_input = { \"a\": 5, \"b\": 7, \"n\": 0 }\nassert my_solution.maximumXorProduct(**test_input) == 35\n\ntest_input = { \"a\": 5, \"b\": 8, \"n\": 2 }\nassert my_solution.maximumXorProduct(**test_input) == 70\n\ntest_input = { \"a\": 5, \"b\": 9, \"n\": 4 }\nassert my_solution.maximumXorProduct(**test_input) == 77\n\ntest_input = { \"a\": 5, \"b\": 10, \"n\": 5 }\nassert my_solution.maximumXorProduct(**test_input) == 552\n\ntest_input = { \"a\": 5, \"b\": 11, \"n\": 7 }\nassert my_solution.maximumXorProduct(**test_input) == 14399\n\ntest_input = { \"a\": 5, \"b\": 12, \"n\": 1 }\nassert my_solution.maximumXorProduct(**test_input) == 60\n\ntest_input = { \"a\": 5, \"b\": 13, \"n\": 5 }\nassert my_solution.maximumXorProduct(**test_input) == 713\n\ntest_input = { \"a\": 5, \"b\": 14, \"n\": 4 }\nassert my_solution.maximumXorProduct(**test_input) == 84\n\ntest_input = { \"a\": 5, \"b\": 15, \"n\": 0 }\nassert my_solution.maximumXorProduct(**test_input) == 75\n\ntest_input = { \"a\": 6, \"b\": 0, \"n\": 4 }\nassert my_solution.maximumXorProduct(**test_input) == 143", "start_time": 1700361000} +{"task_id": "weekly-contest-372-find-building-where-alice-and-bob-can-meet", "url": "https://leetcode.com/problems/find-building-where-alice-and-bob-can-meet", "title": "find-building-where-alice-and-bob-can-meet", "meta": {"questionId": "3181", "questionFrontendId": "2940", "title": "Find Building Where Alice and Bob Can Meet", "titleSlug": "find-building-where-alice-and-bob-can-meet", "isPaidOnly": false, "difficulty": "Hard", "likes": 171, "dislikes": 3, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed array heights of positive integers, where heights[i] represents the height of the ith building.\nIf a person is in building i, they can move to any other building j if and only if i < j and heights[i] < heights[j].\nYou are also given another array queries where queries[i] = [ai, bi]. On the ith query, Alice is in building ai while Bob is in building bi.\nReturn an array ans where ans[i] is the index of the leftmost building where Alice and Bob can meet on the ith query. If Alice and Bob cannot move to a common building on query i, set ans[i] to -1.\n\nExample 1:\n\nInput: heights = [6,4,8,5,2,7], queries = [[0,1],[0,3],[2,4],[3,4],[2,2]]\nOutput: [2,5,-1,5,2]\nExplanation: In the first query, Alice and Bob can move to building 2 since heights[0] < heights[2] and heights[1] < heights[2]. \nIn the second query, Alice and Bob can move to building 5 since heights[0] < heights[5] and heights[3] < heights[5]. \nIn the third query, Alice cannot meet Bob since Alice cannot move to any other building.\nIn the fourth query, Alice and Bob can move to building 5 since heights[3] < heights[5] and heights[4] < heights[5].\nIn the fifth query, Alice and Bob are already in the same building. \nFor ans[i] != -1, It can be shown that ans[i] is the leftmost building where Alice and Bob can meet.\nFor ans[i] == -1, It can be shown that there is no building where Alice and Bob can meet.\n\nExample 2:\n\nInput: heights = [5,3,8,2,6,1,4,6], queries = [[0,7],[3,5],[5,2],[3,0],[1,6]]\nOutput: [7,6,-1,4,6]\nExplanation: In the first query, Alice can directly move to Bob's building since heights[0] < heights[7].\nIn the second query, Alice and Bob can move to building 6 since heights[3] < heights[6] and heights[5] < heights[6].\nIn the third query, Alice cannot meet Bob since Bob cannot move to any other building.\nIn the fourth query, Alice and Bob can move to building 4 since heights[3] < heights[4] and heights[0] < heights[4].\nIn the fifth query, Alice can directly move to Bob's building since heights[1] < heights[6].\nFor ans[i] != -1, It can be shown that ans[i] is the leftmost building where Alice and Bob can meet.\nFor ans[i] == -1, It can be shown that there is no building where Alice and Bob can meet.\n\n\n\nConstraints:\n\n1 <= heights.length <= 5 * 104\n1 <= heights[i] <= 109\n1 <= queries.length <= 5 * 104\nqueries[i] = [ai, bi]\n0 <= ai, bi <= heights.length - 1\n\"\"\"\nclass Solution:\n def leftmostBuildingQueries(self, heights: List[int], queries: List[List[int]]) -> List[int]:\n ", "prompt_sft": "You are given a 0-indexed array heights of positive integers, where heights[i] represents the height of the ith building.\nIf a person is in building i, they can move to any other building j if and only if i < j and heights[i] < heights[j].\nYou are also given another array queries where queries[i] = [ai, bi]. On the ith query, Alice is in building ai while Bob is in building bi.\nReturn an array ans where ans[i] is the index of the leftmost building where Alice and Bob can meet on the ith query. If Alice and Bob cannot move to a common building on query i, set ans[i] to -1.\n\nExample 1:\n\nInput: heights = [6,4,8,5,2,7], queries = [[0,1],[0,3],[2,4],[3,4],[2,2]]\nOutput: [2,5,-1,5,2]\nExplanation: In the first query, Alice and Bob can move to building 2 since heights[0] < heights[2] and heights[1] < heights[2]. \nIn the second query, Alice and Bob can move to building 5 since heights[0] < heights[5] and heights[3] < heights[5]. \nIn the third query, Alice cannot meet Bob since Alice cannot move to any other building.\nIn the fourth query, Alice and Bob can move to building 5 since heights[3] < heights[5] and heights[4] < heights[5].\nIn the fifth query, Alice and Bob are already in the same building. \nFor ans[i] != -1, It can be shown that ans[i] is the leftmost building where Alice and Bob can meet.\nFor ans[i] == -1, It can be shown that there is no building where Alice and Bob can meet.\n\nExample 2:\n\nInput: heights = [5,3,8,2,6,1,4,6], queries = [[0,7],[3,5],[5,2],[3,0],[1,6]]\nOutput: [7,6,-1,4,6]\nExplanation: In the first query, Alice can directly move to Bob's building since heights[0] < heights[7].\nIn the second query, Alice and Bob can move to building 6 since heights[3] < heights[6] and heights[5] < heights[6].\nIn the third query, Alice cannot meet Bob since Bob cannot move to any other building.\nIn the fourth query, Alice and Bob can move to building 4 since heights[3] < heights[4] and heights[0] < heights[4].\nIn the fifth query, Alice can directly move to Bob's building since heights[1] < heights[6].\nFor ans[i] != -1, It can be shown that ans[i] is the leftmost building where Alice and Bob can meet.\nFor ans[i] == -1, It can be shown that there is no building where Alice and Bob can meet.\n\n\n\nConstraints:\n\n1 <= heights.length <= 5 * 104\n1 <= heights[i] <= 109\n1 <= queries.length <= 5 * 104\nqueries[i] = [ai, bi]\n0 <= ai, bi <= heights.length - 1\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def leftmostBuildingQueries(self, heights: List[int], queries: List[List[int]]) -> List[int]:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"heights\": [6,4,8,5,2,7], \"queries\": [[0,1],[0,3],[2,4],[3,4],[2,2]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [2,5,-1,5,2]\n\ntest_input = { \"heights\": [5,3,8,2,6,1,4,6], \"queries\": [[0,7],[3,5],[5,2],[3,0],[1,6]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [7,6,-1,4,6]\n\ntest_input = { \"heights\": [1], \"queries\": [[0,0]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0]\n\ntest_input = { \"heights\": [1000000000], \"queries\": [[0,0]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0]\n\ntest_input = { \"heights\": [1,2], \"queries\": [[0,0],[0,1],[1,0],[1,1]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,1,1]\n\ntest_input = { \"heights\": [2,1], \"queries\": [[0,0],[0,1],[1,0],[1,1]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,-1,-1,1]\n\ntest_input = { \"heights\": [1,2,3], \"queries\": [[0,0],[0,1],[0,2],[1,0],[1,1],[1,2],[2,0],[2,1],[2,2]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,1,1,2,2,2,2]\n\ntest_input = { \"heights\": [1,3,2], \"queries\": [[0,0],[0,1],[0,2],[1,0],[1,1],[1,2],[2,0],[2,1],[2,2]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,1,1,-1,2,-1,2]\n\ntest_input = { \"heights\": [2,1,3], \"queries\": [[0,0],[0,1],[0,2],[1,0],[1,1],[1,2],[2,0],[2,1],[2,2]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,2,2,2,1,2,2,2,2]\n\ntest_input = { \"heights\": [2,3,1], \"queries\": [[0,0],[0,1],[0,2],[1,0],[1,1],[1,2],[2,0],[2,1],[2,2]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,-1,1,1,-1,-1,-1,2]\n\ntest_input = { \"heights\": [3,1,2], \"queries\": [[0,0],[0,1],[0,2],[1,0],[1,1],[1,2],[2,0],[2,1],[2,2]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,-1,-1,-1,1,2,-1,2,2]\n\ntest_input = { \"heights\": [3,2,1], \"queries\": [[0,0],[0,1],[0,2],[1,0],[1,1],[1,2],[2,0],[2,1],[2,2]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,-1,-1,-1,1,-1,-1,-1,2]\n\ntest_input = { \"heights\": [1,2,3,4], \"queries\": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,1,1,2,3,2,2,2,3,3,3,3,3]\n\ntest_input = { \"heights\": [1,2,4,3], \"queries\": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,1,1,2,3,2,2,2,-1,3,3,-1,3]\n\ntest_input = { \"heights\": [1,3,2,4], \"queries\": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,1,1,3,3,2,3,2,3,3,3,3,3]\n\ntest_input = { \"heights\": [1,3,4,2], \"queries\": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,1,1,2,-1,2,2,2,-1,3,-1,-1,3]\n\ntest_input = { \"heights\": [1,4,2,3], \"queries\": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,1,1,-1,-1,2,-1,2,3,3,-1,3,3]\n\ntest_input = { \"heights\": [1,4,3,2], \"queries\": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,1,1,-1,-1,2,-1,2,-1,3,-1,-1,3]\n\ntest_input = { \"heights\": [2,1,3,4], \"queries\": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,2,2,3,2,1,2,3,2,2,2,3,3,3,3,3]\n\ntest_input = { \"heights\": [2,1,4,3], \"queries\": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,2,2,3,2,1,2,3,2,2,2,-1,3,3,-1,3]\n\ntest_input = { \"heights\": [2,3,1,4], \"queries\": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,3,3,1,1,3,3,3,3,2,3,3,3,3,3]\n\ntest_input = { \"heights\": [2,3,4,1], \"queries\": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,-1,1,1,2,-1,2,2,2,-1,-1,-1,-1,3]\n\ntest_input = { \"heights\": [2,4,1,3], \"queries\": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,3,3,1,1,-1,-1,3,-1,2,3,3,-1,3,3]\n\ntest_input = { \"heights\": [2,4,3,1], \"queries\": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,-1,1,1,-1,-1,2,-1,2,-1,-1,-1,-1,3]\n\ntest_input = { \"heights\": [3,1,2,4], \"queries\": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,3,3,3,3,1,2,3,3,2,2,3,3,3,3,3]\n\ntest_input = { \"heights\": [3,1,4,2], \"queries\": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,2,2,-1,2,1,2,3,2,2,2,-1,-1,3,-1,3]\n\ntest_input = { \"heights\": [3,2,1,4], \"queries\": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,3,3,3,3,1,3,3,3,3,2,3,3,3,3,3]\n\ntest_input = { \"heights\": [3,2,4,1], \"queries\": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,2,2,-1,2,1,2,-1,2,2,2,-1,-1,-1,-1,3]\n\ntest_input = { \"heights\": [3,4,1,2], \"queries\": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,-1,-1,1,1,-1,-1,-1,-1,2,3,-1,-1,3,3]\n\ntest_input = { \"heights\": [3,4,2,1], \"queries\": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,-1,-1,1,1,-1,-1,-1,-1,2,-1,-1,-1,-1,3]\n\ntest_input = { \"heights\": [4,1,2,3], \"queries\": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,-1,-1,-1,-1,1,2,3,-1,2,2,3,-1,3,3,3]\n\ntest_input = { \"heights\": [4,1,3,2], \"queries\": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,-1,-1,-1,-1,1,2,3,-1,2,2,-1,-1,3,-1,3]\n\ntest_input = { \"heights\": [4,2,1,3], \"queries\": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,-1,-1,-1,-1,1,3,3,-1,3,2,3,-1,3,3,3]\n\ntest_input = { \"heights\": [4,2,3,1], \"queries\": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,-1,-1,-1,-1,1,2,-1,-1,2,2,-1,-1,-1,-1,3]\n\ntest_input = { \"heights\": [4,3,1,2], \"queries\": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,-1,-1,-1,-1,1,-1,-1,-1,-1,2,3,-1,-1,3,3]\n\ntest_input = { \"heights\": [4,3,2,1], \"queries\": [[0,0],[0,1],[0,2],[0,3],[1,0],[1,1],[1,2],[1,3],[2,0],[2,1],[2,2],[2,3],[3,0],[3,1],[3,2],[3,3]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,-1,-1,-1,-1,1,-1,-1,-1,-1,2,-1,-1,-1,-1,3]\n\ntest_input = { \"heights\": [1,2,3,4,5], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,2,3,4,2,2,2,3,4,3,3,3,3,4,4,4,4,4,4]\n\ntest_input = { \"heights\": [1,2,3,5,4], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,2,3,4,2,2,2,3,4,3,3,3,3,-1,4,4,4,-1,4]\n\ntest_input = { \"heights\": [1,2,4,3,5], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,2,3,4,2,2,2,4,4,3,3,4,3,4,4,4,4,4,4]\n\ntest_input = { \"heights\": [1,2,4,5,3], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,2,3,4,2,2,2,3,-1,3,3,3,3,-1,4,4,-1,-1,4]\n\ntest_input = { \"heights\": [1,2,5,3,4], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,2,3,4,2,2,2,-1,-1,3,3,-1,3,4,4,4,-1,4,4]\n\ntest_input = { \"heights\": [1,2,5,4,3], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,2,3,4,2,2,2,-1,-1,3,3,-1,3,-1,4,4,-1,-1,4]\n\ntest_input = { \"heights\": [1,3,2,4,5], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,3,3,4,2,3,2,3,4,3,3,3,3,4,4,4,4,4,4]\n\ntest_input = { \"heights\": [1,3,2,5,4], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,3,3,4,2,3,2,3,4,3,3,3,3,-1,4,4,4,-1,4]\n\ntest_input = { \"heights\": [1,3,4,2,5], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,2,4,4,2,2,2,4,4,3,4,4,3,4,4,4,4,4,4]\n\ntest_input = { \"heights\": [1,3,4,5,2], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,2,3,-1,2,2,2,3,-1,3,3,3,3,-1,4,-1,-1,-1,4]\n\ntest_input = { \"heights\": [1,3,5,2,4], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,2,4,4,2,2,2,-1,-1,3,4,-1,3,4,4,4,-1,4,4]\n\ntest_input = { \"heights\": [1,3,5,4,2], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,2,3,-1,2,2,2,-1,-1,3,3,-1,3,-1,4,-1,-1,-1,4]\n\ntest_input = { \"heights\": [1,4,2,3,5], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,4,4,4,2,4,2,3,4,3,4,3,3,4,4,4,4,4,4]\n\ntest_input = { \"heights\": [1,4,2,5,3], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,3,3,-1,2,3,2,3,4,3,3,3,3,-1,4,-1,4,-1,4]\n\ntest_input = { \"heights\": [1,4,3,2,5], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,4,4,4,2,4,2,4,4,3,4,4,3,4,4,4,4,4,4]\n\ntest_input = { \"heights\": [1,4,3,5,2], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,3,3,-1,2,3,2,3,-1,3,3,3,3,-1,4,-1,-1,-1,4]\n\ntest_input = { \"heights\": [1,4,5,2,3], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,2,-1,-1,2,2,2,-1,-1,3,-1,-1,3,4,4,-1,-1,4,4]\n\ntest_input = { \"heights\": [1,4,5,3,2], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,2,-1,-1,2,2,2,-1,-1,3,-1,-1,3,-1,4,-1,-1,-1,4]\n\ntest_input = { \"heights\": [1,5,2,3,4], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,-1,-1,-1,2,-1,2,3,4,3,-1,3,3,4,4,-1,4,4,4]\n\ntest_input = { \"heights\": [1,5,2,4,3], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,-1,-1,-1,2,-1,2,3,4,3,-1,3,3,-1,4,-1,4,-1,4]\n\ntest_input = { \"heights\": [1,5,3,2,4], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,-1,-1,-1,2,-1,2,4,4,3,-1,4,3,4,4,-1,4,4,4]\n\ntest_input = { \"heights\": [1,5,3,4,2], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,-1,-1,-1,2,-1,2,3,-1,3,-1,3,3,-1,4,-1,-1,-1,4]\n\ntest_input = { \"heights\": [1,5,4,2,3], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,-1,-1,-1,2,-1,2,-1,-1,3,-1,-1,3,4,4,-1,-1,4,4]\n\ntest_input = { \"heights\": [1,5,4,3,2], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,4,1,1,-1,-1,-1,2,-1,2,-1,-1,3,-1,-1,3,-1,4,-1,-1,-1,4]\n\ntest_input = { \"heights\": [2,1,3,4,5], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,2,2,3,4,2,1,2,3,4,2,2,2,3,4,3,3,3,3,4,4,4,4,4,4]\n\ntest_input = { \"heights\": [2,1,3,5,4], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,2,2,3,4,2,1,2,3,4,2,2,2,3,4,3,3,3,3,-1,4,4,4,-1,4]\n\ntest_input = { \"heights\": [2,1,4,3,5], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,2,2,3,4,2,1,2,3,4,2,2,2,4,4,3,3,4,3,4,4,4,4,4,4]\n\ntest_input = { \"heights\": [2,1,4,5,3], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,2,2,3,4,2,1,2,3,4,2,2,2,3,-1,3,3,3,3,-1,4,4,-1,-1,4]\n\ntest_input = { \"heights\": [2,1,5,3,4], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,2,2,3,4,2,1,2,3,4,2,2,2,-1,-1,3,3,-1,3,4,4,4,-1,4,4]\n\ntest_input = { \"heights\": [2,1,5,4,3], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,2,2,3,4,2,1,2,3,4,2,2,2,-1,-1,3,3,-1,3,-1,4,4,-1,-1,4]\n\ntest_input = { \"heights\": [2,3,1,4,5], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,3,3,4,1,1,3,3,4,3,3,2,3,4,3,3,3,3,4,4,4,4,4,4]\n\ntest_input = { \"heights\": [2,3,1,5,4], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,3,3,4,1,1,3,3,4,3,3,2,3,4,3,3,3,3,-1,4,4,4,-1,4]\n\ntest_input = { \"heights\": [2,3,4,1,5], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,4,4,1,1,2,4,4,2,2,2,4,4,4,4,4,3,4,4,4,4,4,4]\n\ntest_input = { \"heights\": [2,3,4,5,1], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,-1,1,1,2,3,-1,2,2,2,3,-1,3,3,3,3,-1,-1,-1,-1,-1,4]\n\ntest_input = { \"heights\": [2,3,5,1,4], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,4,4,1,1,2,4,4,2,2,2,-1,-1,4,4,-1,3,4,4,4,-1,4,4]\n\ntest_input = { \"heights\": [2,3,5,4,1], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,-1,1,1,2,3,-1,2,2,2,-1,-1,3,3,-1,3,-1,-1,-1,-1,-1,4]\n\ntest_input = { \"heights\": [2,4,1,3,5], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,3,3,4,1,1,4,4,4,3,4,2,3,4,3,4,3,3,4,4,4,4,4,4]\n\ntest_input = { \"heights\": [2,4,1,5,3], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,3,3,4,1,1,3,3,-1,3,3,2,3,4,3,3,3,3,-1,4,-1,4,-1,4]\n\ntest_input = { \"heights\": [2,4,3,1,5], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,4,4,1,1,4,4,4,2,4,2,4,4,4,4,4,3,4,4,4,4,4,4]\n\ntest_input = { \"heights\": [2,4,3,5,1], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,-1,1,1,3,3,-1,2,3,2,3,-1,3,3,3,3,-1,-1,-1,-1,-1,4]\n\ntest_input = { \"heights\": [2,4,5,1,3], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,4,4,1,1,2,-1,-1,2,2,2,-1,-1,4,-1,-1,3,4,4,-1,-1,4,4]\n\ntest_input = { \"heights\": [2,4,5,3,1], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,-1,1,1,2,-1,-1,2,2,2,-1,-1,3,-1,-1,3,-1,-1,-1,-1,-1,4]\n\ntest_input = { \"heights\": [2,5,1,3,4], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,3,3,4,1,1,-1,-1,-1,3,-1,2,3,4,3,-1,3,3,4,4,-1,4,4,4]\n\ntest_input = { \"heights\": [2,5,1,4,3], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,3,3,4,1,1,-1,-1,-1,3,-1,2,3,4,3,-1,3,3,-1,4,-1,4,-1,4]\n\ntest_input = { \"heights\": [2,5,3,1,4], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,4,4,1,1,-1,-1,-1,2,-1,2,4,4,4,-1,4,3,4,4,-1,4,4,4]\n\ntest_input = { \"heights\": [2,5,3,4,1], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,-1,1,1,-1,-1,-1,2,-1,2,3,-1,3,-1,3,3,-1,-1,-1,-1,-1,4]\n\ntest_input = { \"heights\": [2,5,4,1,3], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,4,4,1,1,-1,-1,-1,2,-1,2,-1,-1,4,-1,-1,3,4,4,-1,-1,4,4]\n\ntest_input = { \"heights\": [2,5,4,3,1], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,2,3,-1,1,1,-1,-1,-1,2,-1,2,-1,-1,3,-1,-1,3,-1,-1,-1,-1,-1,4]\n\ntest_input = { \"heights\": [3,1,2,4,5], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,3,3,3,4,3,1,2,3,4,3,2,2,3,4,3,3,3,3,4,4,4,4,4,4]\n\ntest_input = { \"heights\": [3,1,2,5,4], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,3,3,3,4,3,1,2,3,4,3,2,2,3,4,3,3,3,3,-1,4,4,4,-1,4]\n\ntest_input = { \"heights\": [3,1,4,2,5], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,2,2,4,4,2,1,2,3,4,2,2,2,4,4,4,3,4,3,4,4,4,4,4,4]\n\ntest_input = { \"heights\": [3,1,4,5,2], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,2,2,3,-1,2,1,2,3,4,2,2,2,3,-1,3,3,3,3,-1,-1,4,-1,-1,4]\n\ntest_input = { \"heights\": [3,1,5,2,4], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,2,2,4,4,2,1,2,3,4,2,2,2,-1,-1,4,3,-1,3,4,4,4,-1,4,4]\n\ntest_input = { \"heights\": [3,1,5,4,2], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,2,2,3,-1,2,1,2,3,4,2,2,2,-1,-1,3,3,-1,3,-1,-1,4,-1,-1,4]\n\ntest_input = { \"heights\": [3,2,1,4,5], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,3,3,3,4,3,1,3,3,4,3,3,2,3,4,3,3,3,3,4,4,4,4,4,4]\n\ntest_input = { \"heights\": [3,2,1,5,4], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,3,3,3,4,3,1,3,3,4,3,3,2,3,4,3,3,3,3,-1,4,4,4,-1,4]\n\ntest_input = { \"heights\": [3,2,4,1,5], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,2,2,4,4,2,1,2,4,4,2,2,2,4,4,4,4,4,3,4,4,4,4,4,4]\n\ntest_input = { \"heights\": [3,2,4,5,1], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,2,2,3,-1,2,1,2,3,-1,2,2,2,3,-1,3,3,3,3,-1,-1,-1,-1,-1,4]\n\ntest_input = { \"heights\": [3,2,5,1,4], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,2,2,4,4,2,1,2,4,4,2,2,2,-1,-1,4,4,-1,3,4,4,4,-1,4,4]\n\ntest_input = { \"heights\": [3,2,5,4,1], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,2,2,3,-1,2,1,2,3,-1,2,2,2,-1,-1,3,3,-1,3,-1,-1,-1,-1,-1,4]\n\ntest_input = { \"heights\": [3,4,1,2,5], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,4,4,4,1,1,4,4,4,4,4,2,3,4,4,4,3,3,4,4,4,4,4,4]\n\ntest_input = { \"heights\": [3,4,1,5,2], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,3,3,-1,1,1,3,3,-1,3,3,2,3,4,3,3,3,3,-1,-1,-1,4,-1,4]\n\ntest_input = { \"heights\": [3,4,2,1,5], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,4,4,4,1,1,4,4,4,4,4,2,4,4,4,4,4,3,4,4,4,4,4,4]\n\ntest_input = { \"heights\": [3,4,2,5,1], \"queries\": [[0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4],[2,0],[2,1],[2,2],[2,3],[2,4],[3,0],[3,1],[3,2],[3,3],[3,4],[4,0],[4,1],[4,2],[4,3],[4,4]] }\nassert my_solution.leftmostBuildingQueries(**test_input) == [0,1,3,3,-1,1,1,3,3,-1,3,3,2,3,-1,3,3,3,3,-1,-1,-1,-1,-1,4]", "start_time": 1700361000} +{"task_id": "weekly-contest-371-maximum-strong-pair-xor-i", "url": "https://leetcode.com/problems/maximum-strong-pair-xor-i", "title": "maximum-strong-pair-xor-i", "meta": {"questionId": "3193", "questionFrontendId": "2932", "title": "Maximum Strong Pair XOR I", "titleSlug": "maximum-strong-pair-xor-i", "isPaidOnly": false, "difficulty": "Easy", "likes": 77, "dislikes": 4, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed integer array nums. A pair of integers x and y is called a strong pair if it satisfies the condition:\n\n|x - y| <= min(x, y)\n\nYou need to select two integers from nums such that they form a strong pair and their bitwise XOR is the maximum among all strong pairs in the array.\nReturn the maximum XOR value out of all possible strong pairs in the array nums.\nNote that you can pick the same integer twice to form a pair.\n\nExample 1:\n\nInput: nums = [1,2,3,4,5]\nOutput: 7\nExplanation: There are 11 strong pairs in the array nums: (1, 1), (1, 2), (2, 2), (2, 3), (2, 4), (3, 3), (3, 4), (3, 5), (4, 4), (4, 5) and (5, 5).\nThe maximum XOR possible from these pairs is 3 XOR 4 = 7.\n\nExample 2:\n\nInput: nums = [10,100]\nOutput: 0\nExplanation: There are 2 strong pairs in the array nums: (10, 10) and (100, 100).\nThe maximum XOR possible from these pairs is 10 XOR 10 = 0 since the pair (100, 100) also gives 100 XOR 100 = 0.\n\nExample 3:\n\nInput: nums = [5,6,25,30]\nOutput: 7\nExplanation: There are 6 strong pairs in the array nums: (5, 5), (5, 6), (6, 6), (25, 25), (25, 30) and (30, 30).\nThe maximum XOR possible from these pairs is 25 XOR 30 = 7 since the only other non-zero XOR value is 5 XOR 6 = 3.\n\n\nConstraints:\n\n1 <= nums.length <= 50\n1 <= nums[i] <= 100\n\"\"\"\nclass Solution:\n def maximumStrongPairXor(self, nums: List[int]) -> int:\n ", "prompt_sft": "You are given a 0-indexed integer array nums. A pair of integers x and y is called a strong pair if it satisfies the condition:\n\n|x - y| <= min(x, y)\n\nYou need to select two integers from nums such that they form a strong pair and their bitwise XOR is the maximum among all strong pairs in the array.\nReturn the maximum XOR value out of all possible strong pairs in the array nums.\nNote that you can pick the same integer twice to form a pair.\n\nExample 1:\n\nInput: nums = [1,2,3,4,5]\nOutput: 7\nExplanation: There are 11 strong pairs in the array nums: (1, 1), (1, 2), (2, 2), (2, 3), (2, 4), (3, 3), (3, 4), (3, 5), (4, 4), (4, 5) and (5, 5).\nThe maximum XOR possible from these pairs is 3 XOR 4 = 7.\n\nExample 2:\n\nInput: nums = [10,100]\nOutput: 0\nExplanation: There are 2 strong pairs in the array nums: (10, 10) and (100, 100).\nThe maximum XOR possible from these pairs is 10 XOR 10 = 0 since the pair (100, 100) also gives 100 XOR 100 = 0.\n\nExample 3:\n\nInput: nums = [5,6,25,30]\nOutput: 7\nExplanation: There are 6 strong pairs in the array nums: (5, 5), (5, 6), (6, 6), (25, 25), (25, 30) and (30, 30).\nThe maximum XOR possible from these pairs is 25 XOR 30 = 7 since the only other non-zero XOR value is 5 XOR 6 = 3.\n\n\nConstraints:\n\n1 <= nums.length <= 50\n1 <= nums[i] <= 100\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def maximumStrongPairXor(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,2,3,4,5] }\nassert my_solution.maximumStrongPairXor(**test_input) == 7\n\ntest_input = { \"nums\": [10,100] }\nassert my_solution.maximumStrongPairXor(**test_input) == 0\n\ntest_input = { \"nums\": [5,6,25,30] }\nassert my_solution.maximumStrongPairXor(**test_input) == 7\n\ntest_input = { \"nums\": [1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 0\n\ntest_input = { \"nums\": [100] }\nassert my_solution.maximumStrongPairXor(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,2,3,5] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [1,1,3,8,7] }\nassert my_solution.maximumStrongPairXor(**test_input) == 15\n\ntest_input = { \"nums\": [1,1,4,4,3] }\nassert my_solution.maximumStrongPairXor(**test_input) == 7\n\ntest_input = { \"nums\": [1,1,6,6,9] }\nassert my_solution.maximumStrongPairXor(**test_input) == 15\n\ntest_input = { \"nums\": [1,1,10,3,9] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,1,5,3] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [1,2,2,1,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,3,8,1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,5,5,10] }\nassert my_solution.maximumStrongPairXor(**test_input) == 15\n\ntest_input = { \"nums\": [1,2,8,3,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,9,2,8] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [1,3,3,2,1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [1,3,8,5,3] }\nassert my_solution.maximumStrongPairXor(**test_input) == 13\n\ntest_input = { \"nums\": [1,3,9,6,5] }\nassert my_solution.maximumStrongPairXor(**test_input) == 15\n\ntest_input = { \"nums\": [1,4,1,2,5] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [1,4,3,9,7] }\nassert my_solution.maximumStrongPairXor(**test_input) == 14\n\ntest_input = { \"nums\": [1,4,4,3,4] }\nassert my_solution.maximumStrongPairXor(**test_input) == 7\n\ntest_input = { \"nums\": [1,4,5,2,1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [1,4,8,6,6] }\nassert my_solution.maximumStrongPairXor(**test_input) == 14\n\ntest_input = { \"nums\": [1,5,1,9,1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 12\n\ntest_input = { \"nums\": [1,5,4,1,7] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [1,5,5,2,7] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [1,5,9,1,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 12\n\ntest_input = { \"nums\": [1,5,9,10,4] }\nassert my_solution.maximumStrongPairXor(**test_input) == 15\n\ntest_input = { \"nums\": [1,6,2,7,9] }\nassert my_solution.maximumStrongPairXor(**test_input) == 15\n\ntest_input = { \"nums\": [1,6,3,3,10] }\nassert my_solution.maximumStrongPairXor(**test_input) == 12\n\ntest_input = { \"nums\": [1,6,4,5,3] }\nassert my_solution.maximumStrongPairXor(**test_input) == 7\n\ntest_input = { \"nums\": [1,6,4,6,1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 2\n\ntest_input = { \"nums\": [1,6,5,5,8] }\nassert my_solution.maximumStrongPairXor(**test_input) == 14\n\ntest_input = { \"nums\": [1,6,6,1,9] }\nassert my_solution.maximumStrongPairXor(**test_input) == 15\n\ntest_input = { \"nums\": [1,6,8,5,3] }\nassert my_solution.maximumStrongPairXor(**test_input) == 14\n\ntest_input = { \"nums\": [1,6,8,10,3] }\nassert my_solution.maximumStrongPairXor(**test_input) == 14\n\ntest_input = { \"nums\": [1,6,9,8,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 15\n\ntest_input = { \"nums\": [1,6,10,1,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 12\n\ntest_input = { \"nums\": [1,7,1,4,3] }\nassert my_solution.maximumStrongPairXor(**test_input) == 7\n\ntest_input = { \"nums\": [1,7,2,1,10] }\nassert my_solution.maximumStrongPairXor(**test_input) == 13\n\ntest_input = { \"nums\": [1,7,2,10,10] }\nassert my_solution.maximumStrongPairXor(**test_input) == 13\n\ntest_input = { \"nums\": [1,7,6,1,4] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [1,7,8,6,8] }\nassert my_solution.maximumStrongPairXor(**test_input) == 15\n\ntest_input = { \"nums\": [1,8,1,1,8] }\nassert my_solution.maximumStrongPairXor(**test_input) == 0\n\ntest_input = { \"nums\": [1,8,4,2,1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 12\n\ntest_input = { \"nums\": [1,8,4,5,6] }\nassert my_solution.maximumStrongPairXor(**test_input) == 14\n\ntest_input = { \"nums\": [1,8,5,10,4] }\nassert my_solution.maximumStrongPairXor(**test_input) == 15\n\ntest_input = { \"nums\": [1,8,8,8,3] }\nassert my_solution.maximumStrongPairXor(**test_input) == 0\n\ntest_input = { \"nums\": [1,8,10,2,6] }\nassert my_solution.maximumStrongPairXor(**test_input) == 14\n\ntest_input = { \"nums\": [1,9,4,4,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [1,9,6,5,7] }\nassert my_solution.maximumStrongPairXor(**test_input) == 15\n\ntest_input = { \"nums\": [1,9,6,8,1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 15\n\ntest_input = { \"nums\": [1,9,8,2,8] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [1,9,8,9,6] }\nassert my_solution.maximumStrongPairXor(**test_input) == 15\n\ntest_input = { \"nums\": [1,9,9,7,6] }\nassert my_solution.maximumStrongPairXor(**test_input) == 15\n\ntest_input = { \"nums\": [1,10,1,1,1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 0\n\ntest_input = { \"nums\": [1,10,5,10,6] }\nassert my_solution.maximumStrongPairXor(**test_input) == 15\n\ntest_input = { \"nums\": [1,10,8,7,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 15\n\ntest_input = { \"nums\": [1,10,9,9,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [2,1,1,5,5] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [2,1,1,7,4] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [2,1,8,3,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [2,1,9,2,1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [2,2,4,1,4] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [2,2,5,5,1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [2,2,5,10,6] }\nassert my_solution.maximumStrongPairXor(**test_input) == 15\n\ntest_input = { \"nums\": [2,2,8,2,10] }\nassert my_solution.maximumStrongPairXor(**test_input) == 2\n\ntest_input = { \"nums\": [2,2,10,5,9] }\nassert my_solution.maximumStrongPairXor(**test_input) == 15\n\ntest_input = { \"nums\": [2,3,3,5,3] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [2,3,8,8,10] }\nassert my_solution.maximumStrongPairXor(**test_input) == 2\n\ntest_input = { \"nums\": [2,4,5,3,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 7\n\ntest_input = { \"nums\": [2,4,6,8,8] }\nassert my_solution.maximumStrongPairXor(**test_input) == 14\n\ntest_input = { \"nums\": [2,4,6,9,8] }\nassert my_solution.maximumStrongPairXor(**test_input) == 15\n\ntest_input = { \"nums\": [2,4,8,7,5] }\nassert my_solution.maximumStrongPairXor(**test_input) == 15\n\ntest_input = { \"nums\": [2,4,10,4,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [2,4,10,6,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 12\n\ntest_input = { \"nums\": [2,4,10,7,8] }\nassert my_solution.maximumStrongPairXor(**test_input) == 15\n\ntest_input = { \"nums\": [2,4,10,9,3] }\nassert my_solution.maximumStrongPairXor(**test_input) == 7\n\ntest_input = { \"nums\": [2,5,2,5,5] }\nassert my_solution.maximumStrongPairXor(**test_input) == 0\n\ntest_input = { \"nums\": [2,5,3,10,10] }\nassert my_solution.maximumStrongPairXor(**test_input) == 15\n\ntest_input = { \"nums\": [2,5,7,2,7] }\nassert my_solution.maximumStrongPairXor(**test_input) == 2\n\ntest_input = { \"nums\": [2,5,9,8,9] }\nassert my_solution.maximumStrongPairXor(**test_input) == 13\n\ntest_input = { \"nums\": [2,5,10,8,4] }\nassert my_solution.maximumStrongPairXor(**test_input) == 15\n\ntest_input = { \"nums\": [2,6,1,6,4] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [2,6,1,8,7] }\nassert my_solution.maximumStrongPairXor(**test_input) == 15\n\ntest_input = { \"nums\": [2,6,7,4,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [2,6,8,6,10] }\nassert my_solution.maximumStrongPairXor(**test_input) == 14\n\ntest_input = { \"nums\": [2,6,10,5,4] }\nassert my_solution.maximumStrongPairXor(**test_input) == 15\n\ntest_input = { \"nums\": [2,7,1,8,9] }\nassert my_solution.maximumStrongPairXor(**test_input) == 15\n\ntest_input = { \"nums\": [2,7,2,8,10] }\nassert my_solution.maximumStrongPairXor(**test_input) == 15\n\ntest_input = { \"nums\": [2,7,3,3,7] }\nassert my_solution.maximumStrongPairXor(**test_input) == 1\n\ntest_input = { \"nums\": [2,7,4,8,1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 15\n\ntest_input = { \"nums\": [2,7,9,2,6] }\nassert my_solution.maximumStrongPairXor(**test_input) == 15\n\ntest_input = { \"nums\": [2,7,10,7,1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 13\n\ntest_input = { \"nums\": [2,8,1,9,5] }\nassert my_solution.maximumStrongPairXor(**test_input) == 13\n\ntest_input = { \"nums\": [2,8,7,10,3] }\nassert my_solution.maximumStrongPairXor(**test_input) == 15\n\ntest_input = { \"nums\": [2,9,1,7,7] }\nassert my_solution.maximumStrongPairXor(**test_input) == 14\n\ntest_input = { \"nums\": [2,9,2,8,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 1\n\ntest_input = { \"nums\": [2,9,5,10,10] }\nassert my_solution.maximumStrongPairXor(**test_input) == 15", "start_time": 1699756200} +{"task_id": "weekly-contest-371-high-access-employees", "url": "https://leetcode.com/problems/high-access-employees", "title": "high-access-employees", "meta": {"questionId": "3202", "questionFrontendId": "2933", "title": "High-Access Employees", "titleSlug": "high-access-employees", "isPaidOnly": false, "difficulty": "Medium", "likes": 110, "dislikes": 14, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 2D 0-indexed array of strings, access_times, with size n. For each i where 0 <= i <= n - 1, access_times[i][0] represents the name of an employee, and access_times[i][1] represents the access time of that employee. All entries in access_times are within the same day.\nThe access time is represented as four digits using a 24-hour time format, for example, \"0800\" or \"2250\".\nAn employee is said to be high-access if he has accessed the system three or more times within a one-hour period.\nTimes with exactly one hour of difference are not considered part of the same one-hour period. For example, \"0815\" and \"0915\" are not part of the same one-hour period.\nAccess times at the start and end of the day are not counted within the same one-hour period. For example, \"0005\" and \"2350\" are not part of the same one-hour period.\nReturn a list that contains the names of high-access employees with any order you want.\n\nExample 1:\n\nInput: access_times = [[\"a\",\"0549\"],[\"b\",\"0457\"],[\"a\",\"0532\"],[\"a\",\"0621\"],[\"b\",\"0540\"]]\nOutput: [\"a\"]\nExplanation: \"a\" has three access times in the one-hour period of [05:32, 06:31] which are 05:32, 05:49, and 06:21.\nBut \"b\" does not have more than two access times at all.\nSo the answer is [\"a\"].\nExample 2:\n\nInput: access_times = [[\"d\",\"0002\"],[\"c\",\"0808\"],[\"c\",\"0829\"],[\"e\",\"0215\"],[\"d\",\"1508\"],[\"d\",\"1444\"],[\"d\",\"1410\"],[\"c\",\"0809\"]]\nOutput: [\"c\",\"d\"]\nExplanation: \"c\" has three access times in the one-hour period of [08:08, 09:07] which are 08:08, 08:09, and 08:29.\n\"d\" has also three access times in the one-hour period of [14:10, 15:09] which are 14:10, 14:44, and 15:08.\nHowever, \"e\" has just one access time, so it can not be in the answer and the final answer is [\"c\",\"d\"].\nExample 3:\n\nInput: access_times = [[\"cd\",\"1025\"],[\"ab\",\"1025\"],[\"cd\",\"1046\"],[\"cd\",\"1055\"],[\"ab\",\"1124\"],[\"ab\",\"1120\"]]\nOutput: [\"ab\",\"cd\"]\nExplanation: \"ab\" has three access times in the one-hour period of [10:25, 11:24] which are 10:25, 11:20, and 11:24.\n\"cd\" has also three access times in the one-hour period of [10:25, 11:24] which are 10:25, 10:46, and 10:55.\nSo the answer is [\"ab\",\"cd\"].\n\nConstraints:\n\n1 <= access_times.length <= 100\naccess_times[i].length == 2\n1 <= access_times[i][0].length <= 10\naccess_times[i][0] consists only of English small letters.\naccess_times[i][1].length == 4\naccess_times[i][1] is in 24-hour time format.\naccess_times[i][1] consists only of '0' to '9'.\n\"\"\"\nclass Solution:\n def findHighAccessEmployees(self, access_times: List[List[str]]) -> List[str]:\n ", "prompt_sft": "You are given a 2D 0-indexed array of strings, access_times, with size n. For each i where 0 <= i <= n - 1, access_times[i][0] represents the name of an employee, and access_times[i][1] represents the access time of that employee. All entries in access_times are within the same day.\nThe access time is represented as four digits using a 24-hour time format, for example, \"0800\" or \"2250\".\nAn employee is said to be high-access if he has accessed the system three or more times within a one-hour period.\nTimes with exactly one hour of difference are not considered part of the same one-hour period. For example, \"0815\" and \"0915\" are not part of the same one-hour period.\nAccess times at the start and end of the day are not counted within the same one-hour period. For example, \"0005\" and \"2350\" are not part of the same one-hour period.\nReturn a list that contains the names of high-access employees with any order you want.\n\nExample 1:\n\nInput: access_times = [[\"a\",\"0549\"],[\"b\",\"0457\"],[\"a\",\"0532\"],[\"a\",\"0621\"],[\"b\",\"0540\"]]\nOutput: [\"a\"]\nExplanation: \"a\" has three access times in the one-hour period of [05:32, 06:31] which are 05:32, 05:49, and 06:21.\nBut \"b\" does not have more than two access times at all.\nSo the answer is [\"a\"].\nExample 2:\n\nInput: access_times = [[\"d\",\"0002\"],[\"c\",\"0808\"],[\"c\",\"0829\"],[\"e\",\"0215\"],[\"d\",\"1508\"],[\"d\",\"1444\"],[\"d\",\"1410\"],[\"c\",\"0809\"]]\nOutput: [\"c\",\"d\"]\nExplanation: \"c\" has three access times in the one-hour period of [08:08, 09:07] which are 08:08, 08:09, and 08:29.\n\"d\" has also three access times in the one-hour period of [14:10, 15:09] which are 14:10, 14:44, and 15:08.\nHowever, \"e\" has just one access time, so it can not be in the answer and the final answer is [\"c\",\"d\"].\nExample 3:\n\nInput: access_times = [[\"cd\",\"1025\"],[\"ab\",\"1025\"],[\"cd\",\"1046\"],[\"cd\",\"1055\"],[\"ab\",\"1124\"],[\"ab\",\"1120\"]]\nOutput: [\"ab\",\"cd\"]\nExplanation: \"ab\" has three access times in the one-hour period of [10:25, 11:24] which are 10:25, 11:20, and 11:24.\n\"cd\" has also three access times in the one-hour period of [10:25, 11:24] which are 10:25, 10:46, and 10:55.\nSo the answer is [\"ab\",\"cd\"].\n\nConstraints:\n\n1 <= access_times.length <= 100\naccess_times[i].length == 2\n1 <= access_times[i][0].length <= 10\naccess_times[i][0] consists only of English small letters.\naccess_times[i][1].length == 4\naccess_times[i][1] is in 24-hour time format.\naccess_times[i][1] consists only of '0' to '9'.\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def findHighAccessEmployees(self, access_times: List[List[str]]) -> List[str]:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"access_times\": [[\"a\",\"0549\"],[\"b\",\"0457\"],[\"a\",\"0532\"],[\"a\",\"0621\"],[\"b\",\"0540\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == [\"a\"]\n\ntest_input = { \"access_times\": [[\"d\",\"0002\"],[\"c\",\"0808\"],[\"c\",\"0829\"],[\"e\",\"0215\"],[\"d\",\"1508\"],[\"d\",\"1444\"],[\"d\",\"1410\"],[\"c\",\"0809\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == [\"c\",\"d\"]\n\ntest_input = { \"access_times\": [[\"cd\",\"1025\"],[\"ab\",\"1025\"],[\"cd\",\"1046\"],[\"cd\",\"1055\"],[\"ab\",\"1124\"],[\"ab\",\"1120\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == [\"ab\",\"cd\"]\n\ntest_input = { \"access_times\": [[\"baipstt\",\"1456\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"bouo\",\"1126\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"cavfbqg\",\"2304\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"cenjcq\",\"1007\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"cqotrwqcaq\",\"0131\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"downbuk\",\"1951\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"dqsoiyz\",\"2204\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"duzeyrov\",\"0243\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"erfg\",\"1223\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"fwhefd\",\"2026\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"gbefbne\",\"0911\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"gp\",\"1540\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"ht\",\"1319\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"inahnsjdqz\",\"1750\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"jwxvijxo\",\"0851\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"kibwwvjuez\",\"0716\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"lvry\",\"0706\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"mbsyxxfzjf\",\"0114\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"mlehvzqb\",\"1620\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"mmgat\",\"0516\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"mxatapbs\",\"2240\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"mzxbgtfc\",\"1531\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"nnhh\",\"1445\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"o\",\"1414\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"qaxqifxxww\",\"1557\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"rjy\",\"0200\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"sgpgh\",\"0539\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"sxx\",\"0325\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"tkvgcf\",\"1645\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"ttk\",\"0304\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"un\",\"0833\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"vlifcdn\",\"0731\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"w\",\"2224\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"wkmehwsg\",\"2023\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"y\",\"1005\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"ynnale\",\"1331\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"yt\",\"0900\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"zbgzk\",\"0527\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"a\",\"0039\"],[\"a\",\"0042\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"ajhzcltqse\",\"0605\"],[\"ajhzcltqse\",\"0558\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"cbaqsymoi\",\"0001\"],[\"cbaqsymoi\",\"0004\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"df\",\"1958\"],[\"df\",\"2002\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"dhmnhvou\",\"0529\"],[\"dhmnhvou\",\"0531\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"epghzrog\",\"0333\"],[\"epghzrog\",\"0333\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"gda\",\"1529\"],[\"gda\",\"1534\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"gjhtgm\",\"2207\"],[\"gjhtgm\",\"2156\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"gsd\",\"2030\"],[\"gsd\",\"2046\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"gsstuktwm\",\"1403\"],[\"gsstuktwm\",\"1357\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"h\",\"2159\"],[\"h\",\"2203\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"hxrdffk\",\"1736\"],[\"hxrdffk\",\"1724\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"iaxsnenx\",\"2037\"],[\"iaxsnenx\",\"2050\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"ikwjvflxq\",\"0055\"],[\"ikwjvflxq\",\"0056\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"jkgjmku\",\"0743\"],[\"jkgjmku\",\"0754\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"jkw\",\"0241\"],[\"jkw\",\"0235\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"jykugiprxf\",\"1633\"],[\"jykugiprxf\",\"1641\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"kdxw\",\"1338\"],[\"kdxw\",\"1336\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"kenltmrg\",\"0932\"],[\"kenltmrg\",\"0941\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"kptjrr\",\"1356\"],[\"kptjrr\",\"1349\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"mcd\",\"1333\"],[\"mcd\",\"1325\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"mhkizga\",\"1552\"],[\"mhkizga\",\"1551\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"monxm\",\"1748\"],[\"monxm\",\"1742\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"msjydtinfy\",\"1301\"],[\"msjydtinfy\",\"1245\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"myhdmu\",\"1407\"],[\"myhdmu\",\"1419\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"nyoezc\",\"1050\"],[\"nyoezc\",\"1041\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"oksvrskxch\",\"0053\"],[\"oksvrskxch\",\"0111\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"pxc\",\"1915\"],[\"pxc\",\"1910\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"qedxyj\",\"0609\"],[\"qedxyj\",\"0614\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"qmslkyxnph\",\"0946\"],[\"qmslkyxnph\",\"0958\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"r\",\"0206\"],[\"r\",\"0202\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"r\",\"2041\"],[\"r\",\"2052\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"rf\",\"2205\"],[\"rf\",\"2203\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"rswegeuhqd\",\"0235\"],[\"rswegeuhqd\",\"0238\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"skfgl\",\"0718\"],[\"skfgl\",\"0712\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"smnnl\",\"2329\"],[\"smnnl\",\"2340\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"tpbbxpx\",\"0409\"],[\"tpbbxpx\",\"0408\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"uiqxqp\",\"0515\"],[\"uiqxqp\",\"0516\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"uyuz\",\"1530\"],[\"uyuz\",\"1543\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"vfeunkee\",\"1500\"],[\"vfeunkee\",\"1508\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"wbyd\",\"1848\"],[\"wbyd\",\"1839\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"x\",\"0522\"],[\"x\",\"0506\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"xhrhdy\",\"1455\"],[\"xhrhdy\",\"1454\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"xmsypay\",\"1605\"],[\"xmsypay\",\"1612\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"xy\",\"0015\"],[\"xy\",\"0021\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"ydtnnpzw\",\"0516\"],[\"ydtnnpzw\",\"0520\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"zh\",\"2348\"],[\"zh\",\"2334\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"zinywjn\",\"0017\"],[\"zinywjn\",\"0019\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == []\n\ntest_input = { \"access_times\": [[\"aczdfmsd\",\"0317\"],[\"aczdfmsd\",\"0314\"],[\"aczdfmsd\",\"0320\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == [\"aczdfmsd\"]\n\ntest_input = { \"access_times\": [[\"bsluadumi\",\"1518\"],[\"bsluadumi\",\"1516\"],[\"bsluadumi\",\"1510\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == [\"bsluadumi\"]\n\ntest_input = { \"access_times\": [[\"ckrdpxq\",\"1122\"],[\"ckrdpxq\",\"1125\"],[\"ckrdpxq\",\"1121\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == [\"ckrdpxq\"]\n\ntest_input = { \"access_times\": [[\"fe\",\"1320\"],[\"fe\",\"1326\"],[\"fe\",\"1331\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == [\"fe\"]\n\ntest_input = { \"access_times\": [[\"ff\",\"1508\"],[\"ff\",\"1508\"],[\"ff\",\"1516\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == [\"ff\"]\n\ntest_input = { \"access_times\": [[\"fnlmbcedu\",\"0052\"],[\"fnlmbcedu\",\"0103\"],[\"fnlmbcedu\",\"0055\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == [\"fnlmbcedu\"]\n\ntest_input = { \"access_times\": [[\"hffgwjjve\",\"0159\"],[\"hffgwjjve\",\"0152\"],[\"hffgwjjve\",\"0159\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == [\"hffgwjjve\"]\n\ntest_input = { \"access_times\": [[\"ivlvfgwsx\",\"0122\"],[\"ivlvfgwsx\",\"0135\"],[\"ivlvfgwsx\",\"0139\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == [\"ivlvfgwsx\"]\n\ntest_input = { \"access_times\": [[\"jlfnksqlt\",\"0304\"],[\"jlfnksqlt\",\"0252\"],[\"jlfnksqlt\",\"0304\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == [\"jlfnksqlt\"]\n\ntest_input = { \"access_times\": [[\"jy\",\"0647\"],[\"jy\",\"0652\"],[\"jy\",\"0704\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == [\"jy\"]\n\ntest_input = { \"access_times\": [[\"kchzzdso\",\"2329\"],[\"kchzzdso\",\"2326\"],[\"kchzzdso\",\"2329\"]] }\nassert my_solution.findHighAccessEmployees(**test_input) == [\"kchzzdso\"]", "start_time": 1699756200} +{"task_id": "weekly-contest-371-minimum-operations-to-maximize-last-elements-in-arrays", "url": "https://leetcode.com/problems/minimum-operations-to-maximize-last-elements-in-arrays", "title": "minimum-operations-to-maximize-last-elements-in-arrays", "meta": {"questionId": "3190", "questionFrontendId": "2934", "title": "Minimum Operations to Maximize Last Elements in Arrays", "titleSlug": "minimum-operations-to-maximize-last-elements-in-arrays", "isPaidOnly": false, "difficulty": "Medium", "likes": 152, "dislikes": 12, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given two 0-indexed integer arrays, nums1 and nums2, both having length n.\nYou are allowed to perform a series of operations (possibly none).\nIn an operation, you select an index i in the range [0, n - 1] and swap the values of nums1[i] and nums2[i].\nYour task is to find the minimum number of operations required to satisfy the following conditions:\n\nnums1[n - 1] is equal to the maximum value among all elements of nums1, i.e., nums1[n - 1] = max(nums1[0], nums1[1], ..., nums1[n - 1]).\nnums2[n - 1] is equal to the maximum value among all elements of nums2, i.e., nums2[n - 1] = max(nums2[0], nums2[1], ..., nums2[n - 1]).\n\nReturn an integer denoting the minimum number of operations needed to meet both conditions, or -1 if it is impossible to satisfy both conditions.\n\nExample 1:\n\nInput: nums1 = [1,2,7], nums2 = [4,5,3]\nOutput: 1\nExplanation: In this example, an operation can be performed using index i = 2.\nWhen nums1[2] and nums2[2] are swapped, nums1 becomes [1,2,3] and nums2 becomes [4,5,7].\nBoth conditions are now satisfied.\nIt can be shown that the minimum number of operations needed to be performed is 1.\nSo, the answer is 1.\n\nExample 2:\n\nInput: nums1 = [2,3,4,5,9], nums2 = [8,8,4,4,4]\nOutput: 2\nExplanation: In this example, the following operations can be performed:\nFirst operation using index i = 4.\nWhen nums1[4] and nums2[4] are swapped, nums1 becomes [2,3,4,5,4], and nums2 becomes [8,8,4,4,9].\nAnother operation using index i = 3.\nWhen nums1[3] and nums2[3] are swapped, nums1 becomes [2,3,4,4,4], and nums2 becomes [8,8,4,5,9].\nBoth conditions are now satisfied.\nIt can be shown that the minimum number of operations needed to be performed is 2.\nSo, the answer is 2. \n\nExample 3:\n\nInput: nums1 = [1,5,4], nums2 = [2,5,3]\nOutput: -1\nExplanation: In this example, it is not possible to satisfy both conditions. \nSo, the answer is -1.\n\n\nConstraints:\n\n1 <= n == nums1.length == nums2.length <= 1000\n1 <= nums1[i] <= 109\n1 <= nums2[i] <= 109\n\"\"\"\nclass Solution:\n def minOperations(self, nums1: List[int], nums2: List[int]) -> int:\n ", "prompt_sft": "You are given two 0-indexed integer arrays, nums1 and nums2, both having length n.\nYou are allowed to perform a series of operations (possibly none).\nIn an operation, you select an index i in the range [0, n - 1] and swap the values of nums1[i] and nums2[i].\nYour task is to find the minimum number of operations required to satisfy the following conditions:\n\nnums1[n - 1] is equal to the maximum value among all elements of nums1, i.e., nums1[n - 1] = max(nums1[0], nums1[1], ..., nums1[n - 1]).\nnums2[n - 1] is equal to the maximum value among all elements of nums2, i.e., nums2[n - 1] = max(nums2[0], nums2[1], ..., nums2[n - 1]).\n\nReturn an integer denoting the minimum number of operations needed to meet both conditions, or -1 if it is impossible to satisfy both conditions.\n\nExample 1:\n\nInput: nums1 = [1,2,7], nums2 = [4,5,3]\nOutput: 1\nExplanation: In this example, an operation can be performed using index i = 2.\nWhen nums1[2] and nums2[2] are swapped, nums1 becomes [1,2,3] and nums2 becomes [4,5,7].\nBoth conditions are now satisfied.\nIt can be shown that the minimum number of operations needed to be performed is 1.\nSo, the answer is 1.\n\nExample 2:\n\nInput: nums1 = [2,3,4,5,9], nums2 = [8,8,4,4,4]\nOutput: 2\nExplanation: In this example, the following operations can be performed:\nFirst operation using index i = 4.\nWhen nums1[4] and nums2[4] are swapped, nums1 becomes [2,3,4,5,4], and nums2 becomes [8,8,4,4,9].\nAnother operation using index i = 3.\nWhen nums1[3] and nums2[3] are swapped, nums1 becomes [2,3,4,4,4], and nums2 becomes [8,8,4,5,9].\nBoth conditions are now satisfied.\nIt can be shown that the minimum number of operations needed to be performed is 2.\nSo, the answer is 2. \n\nExample 3:\n\nInput: nums1 = [1,5,4], nums2 = [2,5,3]\nOutput: -1\nExplanation: In this example, it is not possible to satisfy both conditions. \nSo, the answer is -1.\n\n\nConstraints:\n\n1 <= n == nums1.length == nums2.length <= 1000\n1 <= nums1[i] <= 109\n1 <= nums2[i] <= 109\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def minOperations(self, nums1: List[int], nums2: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums1\": [1,2,7], \"nums2\": [4,5,3] }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums1\": [2,3,4,5,9], \"nums2\": [8,8,4,4,4] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums1\": [1,5,4], \"nums2\": [2,5,3] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums1\": [1], \"nums2\": [1] }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums1\": [1,2], \"nums2\": [2,1] }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums1\": [1,1,10], \"nums2\": [1,5,1] }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums1\": [1,4,16], \"nums2\": [16,16,16] }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums1\": [1,5,15], \"nums2\": [1,1,1] }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums1\": [2,5,7], \"nums2\": [2,2,2] }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums1\": [8,9,10], \"nums2\": [10,9,9] }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums1\": [9,14,14], \"nums2\": [14,11,14] }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums1\": [16,16,16], \"nums2\": [6,7,16] }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums1\": [19,7,19], \"nums2\": [5,19,19] }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums1\": [1,1,8,9], \"nums2\": [1,7,1,1] }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums1\": [1,5,9,9], \"nums2\": [9,9,8,9] }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums1\": [1,7,7,7], \"nums2\": [7,3,3,7] }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums1\": [10,18,12,12], \"nums2\": [19,6,5,12] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums1\": [12,9,11,12], \"nums2\": [3,9,9,9] }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums1\": [15,54,22,54], \"nums2\": [54,19,54,54] }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums1\": [20,20,20,20], \"nums2\": [5,8,19,20] }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums1\": [1,3,4,6,7], \"nums2\": [1,1,1,1,1] }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums1\": [1,11,17,1,18], \"nums2\": [1,1,1,18,1] }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums1\": [3,3,3,14,14], \"nums2\": [3,3,4,3,3] }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums1\": [4,4,8,4,17], \"nums2\": [4,8,4,14,4] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums1\": [4,12,11,11,12], \"nums2\": [12,6,12,12,12] }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums1\": [6,21,87,63,87], \"nums2\": [87,87,23,63,63] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums1\": [10,6,6,6,10], \"nums2\": [6,6,10,10,6] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums1\": [16,12,15,15,16], \"nums2\": [8,16,16,15,15] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums1\": [17,3,6,6,17], \"nums2\": [3,17,6,14,6] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums1\": [19,13,18,18,19], \"nums2\": [5,13,13,13,13] }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums1\": [20,20,53,20,68], \"nums2\": [20,28,20,61,20] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums1\": [6,6,2,4,4,6], \"nums2\": [1,1,6,4,4,4] }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums1\": [8,6,6,6,7,8], \"nums2\": [5,8,8,8,7,7] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums1\": [15,1,15,6,12,15], \"nums2\": [1,15,2,15,15,15] }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums1\": [17,13,19,9,6,14], \"nums2\": [17,14,15,1,19,19] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums1\": [20,8,10,12,17,20], \"nums2\": [7,20,20,20,20,20] }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums1\": [20,18,15,11,17,20], \"nums2\": [7,15,13,7,20,12] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums1\": [20,20,20,20,19,20], \"nums2\": [3,6,7,15,20,20] }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums1\": [28,43,79,32,40,3], \"nums2\": [95,25,74,16,82,56] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums1\": [29,81,58,99,41,36], \"nums2\": [15,34,47,57,31,95] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums1\": [1,1,4,1,7,1,15], \"nums2\": [1,1,1,4,1,9,1] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums1\": [1,4,4,4,7,4,9], \"nums2\": [9,9,4,6,4,9,4] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums1\": [2,88,17,88,68,68,88], \"nums2\": [88,16,88,68,68,68,68] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums1\": [3,3,5,3,3,3,18], \"nums2\": [3,4,3,11,13,14,3] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums1\": [3,41,98,71,71,71,98], \"nums2\": [98,98,49,71,85,94,71] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums1\": [5,5,27,53,5,59,65], \"nums2\": [5,16,5,5,58,5,5] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums1\": [5,6,11,11,13,11,14], \"nums2\": [14,14,11,11,11,14,11] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums1\": [6,5,1,10,8,4,5], \"nums2\": [3,8,8,3,6,1,4] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums1\": [14,3,4,4,4,4,14], \"nums2\": [2,14,4,4,5,12,4] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums1\": [14,28,68,68,65,67,68], \"nums2\": [68,68,49,64,68,67,67] }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums1\": [19,19,8,9,10,13,19], \"nums2\": [1,5,19,19,19,13,13] }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums1\": [20,6,20,20,20,20,20], \"nums2\": [3,20,7,9,13,14,20] }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums1\": [85,85,62,85,78,84,85], \"nums2\": [5,37,85,76,85,85,85] }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums1\": [1,2,2,2,2,2,2,10], \"nums2\": [10,2,2,2,7,8,9,2] }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums1\": [1,9,3,3,4,9,9,9], \"nums2\": [9,2,9,9,9,6,8,9] }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums1\": [3,3,4,3,3,3,3,8], \"nums2\": [3,3,3,5,7,7,8,3] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums1\": [4,8,11,19,16,16,19,19], \"nums2\": [19,19,19,13,16,16,16,16] }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums1\": [8,20,4,9,9,4,4,20], \"nums2\": [9,14,10,1,1,20,16,15] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums1\": [9,9,1,2,2,6,8,9], \"nums2\": [1,1,9,2,2,2,2,2] }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums1\": [10,4,10,9,10,10,10,10], \"nums2\": [4,10,9,9,9,9,9,9] }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums1\": [13,95,19,56,59,95,95,95], \"nums2\": [95,14,95,95,95,83,88,95] }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums1\": [19,7,19,8,9,15,9,19], \"nums2\": [7,19,7,19,9,9,18,9] }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums1\": [19,19,3,3,15,16,3,19], \"nums2\": [2,2,3,7,3,3,17,3] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums1\": [1,8,8,5,8,8,8,7,8], \"nums2\": [8,2,4,8,5,6,6,8,8] }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums1\": [1,10,10,5,10,8,10,10,10], \"nums2\": [10,2,4,10,7,8,8,8,8] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums1\": [2,7,7,7,7,7,7,17,18], \"nums2\": [18,7,10,11,13,15,17,7,7] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums1\": [3,13,22,24,13,13,13,81,91], \"nums2\": [91,13,13,13,45,59,71,13,13] }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums1\": [4,4,9,4,16,4,17,4,18], \"nums2\": [4,8,4,14,4,16,4,18,4] }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums1\": [6,9,65,13,65,65,28,28,65], \"nums2\": [65,65,13,65,24,27,28,34,28] }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums1\": [8,3,5,6,6,3,3,3,8], \"nums2\": [1,3,3,3,3,7,7,8,3] }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums1\": [10,1,10,10,10,9,9,9,10], \"nums2\": [1,10,5,6,8,9,9,10,9] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums1\": [15,15,3,5,15,15,9,13,15], \"nums2\": [1,2,15,15,6,8,9,9,9] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums1\": [16,3,3,7,3,11,3,3,16], \"nums2\": [2,3,6,3,10,3,15,16,3] }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums1\": [16,3,16,7,16,16,10,10,16], \"nums2\": [2,16,4,16,9,10,10,13,10] }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums1\": [80,80,18,39,39,62,39,39,80], \"nums2\": [2,10,80,39,42,39,66,66,39] }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums1\": [1,1,1,1,1,1,1,7,1,9], \"nums2\": [9,1,3,3,3,5,5,1,9,1] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums1\": [1,2,2,2,2,5,8,2,2,9], \"nums2\": [9,2,2,2,4,2,2,9,9,2] }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums1\": [1,2,18,18,10,18,18,17,18,18], \"nums2\": [18,18,5,5,18,13,14,18,18,18] }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums1\": [1,3,1,1,1,1,16,16,1,19], \"nums2\": [1,1,7,7,9,12,1,1,18,1] }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums1\": [1,9,3,9,4,5,7,8,8,9], \"nums2\": [9,1,9,3,9,9,7,7,7,7] }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums1\": [2,2,2,2,10,11,2,2,2,20], \"nums2\": [2,3,9,9,2,2,12,14,19,2] }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums1\": [3,15,6,7,7,10,7,7,15,15], \"nums2\": [15,6,15,7,9,7,12,13,7,7] }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums1\": [5,20,20,8,8,12,20,19,20,20], \"nums2\": [20,6,7,20,20,20,15,20,20,20] }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums1\": [8,8,8,8,8,8,8,8,6,8], \"nums2\": [1,2,3,4,4,5,5,5,8,8] }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums1\": [9,3,3,3,3,6,7,7,3,9], \"nums2\": [3,3,4,5,5,3,3,3,7,3] }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums1\": [9,8,6,2,1,10,9,7,9,4], \"nums2\": [6,2,8,2,5,3,6,5,6,10] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums1\": [10,2,2,2,3,2,2,2,2,10], \"nums2\": [1,10,2,2,2,6,6,8,10,2] }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums1\": [12,19,10,4,17,12,18,6,7,7], \"nums2\": [20,5,15,7,10,8,2,16,14,1] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums1\": [17,31,31,34,31,42,31,65,31,89], \"nums2\": [89,31,32,31,37,31,45,31,84,31] }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums1\": [19,7,7,19,9,19,19,19,17,19], \"nums2\": [6,19,19,8,19,10,10,16,19,19] }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums1\": [20,20,7,20,8,11,11,11,11,20], \"nums2\": [5,6,20,7,20,11,15,18,20,11] }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums1\": [90,7,90,13,90,33,33,83,33,90], \"nums2\": [6,90,13,90,22,33,62,33,86,33] }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums1\": [1,1,1,1,1,10,1,15,16,17,20], \"nums2\": [1,2,2,9,10,1,14,1,1,1,1] }\nassert my_solution.minOperations(**test_input) == 5\n\ntest_input = { \"nums1\": [1,1,1,1,3,1,1,6,1,1,8], \"nums2\": [1,1,1,3,1,3,5,1,6,7,1] }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums1\": [1,2,2,6,2,2,2,2,2,2,10], \"nums2\": [10,2,4,2,6,6,7,8,9,9,2] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums1\": [1,2,3,20,8,8,19,19,19,20,20], \"nums2\": [20,20,20,5,20,20,20,19,19,19,19] }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums1\": [1,2,4,9,5,9,9,6,7,6,9], \"nums2\": [9,9,9,4,9,5,5,6,6,7,6] }\nassert my_solution.minOperations(**test_input) == 5\n\ntest_input = { \"nums1\": [1,7,7,7,7,7,13,16,7,19,19], \"nums2\": [19,7,10,11,11,12,7,7,16,7,7] }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums1\": [1,10,4,10,10,10,6,10,7,9,10], \"nums2\": [10,3,10,5,5,6,10,7,10,9,9] }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums1\": [1,20,20,7,20,20,13,17,17,19,20], \"nums2\": [20,2,4,20,7,7,20,20,17,17,17] }\nassert my_solution.minOperations(**test_input) == 4", "start_time": 1699756200} +{"task_id": "weekly-contest-371-maximum-strong-pair-xor-ii", "url": "https://leetcode.com/problems/maximum-strong-pair-xor-ii", "title": "maximum-strong-pair-xor-ii", "meta": {"questionId": "3197", "questionFrontendId": "2935", "title": "Maximum Strong Pair XOR II", "titleSlug": "maximum-strong-pair-xor-ii", "isPaidOnly": false, "difficulty": "Hard", "likes": 140, "dislikes": 1, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed integer array nums. A pair of integers x and y is called a strong pair if it satisfies the condition:\n\n|x - y| <= min(x, y)\n\nYou need to select two integers from nums such that they form a strong pair and their bitwise XOR is the maximum among all strong pairs in the array.\nReturn the maximum XOR value out of all possible strong pairs in the array nums.\nNote that you can pick the same integer twice to form a pair.\n\nExample 1:\n\nInput: nums = [1,2,3,4,5]\nOutput: 7\nExplanation: There are 11 strong pairs in the array nums: (1, 1), (1, 2), (2, 2), (2, 3), (2, 4), (3, 3), (3, 4), (3, 5), (4, 4), (4, 5) and (5, 5).\nThe maximum XOR possible from these pairs is 3 XOR 4 = 7.\n\nExample 2:\n\nInput: nums = [10,100]\nOutput: 0\nExplanation: There are 2 strong pairs in the array nums: (10, 10) and (100, 100).\nThe maximum XOR possible from these pairs is 10 XOR 10 = 0 since the pair (100, 100) also gives 100 XOR 100 = 0.\n\nExample 3:\n\nInput: nums = [500,520,2500,3000]\nOutput: 1020\nExplanation: There are 6 strong pairs in the array nums: (500, 500), (500, 520), (520, 520), (2500, 2500), (2500, 3000) and (3000, 3000).\nThe maximum XOR possible from these pairs is 500 XOR 520 = 1020 since the only other non-zero XOR value is 2500 XOR 3000 = 636.\n\n\nConstraints:\n\n1 <= nums.length <= 5 * 104\n1 <= nums[i] <= 220 - 1\n\"\"\"\nclass Solution:\n def maximumStrongPairXor(self, nums: List[int]) -> int:\n ", "prompt_sft": "You are given a 0-indexed integer array nums. A pair of integers x and y is called a strong pair if it satisfies the condition:\n\n|x - y| <= min(x, y)\n\nYou need to select two integers from nums such that they form a strong pair and their bitwise XOR is the maximum among all strong pairs in the array.\nReturn the maximum XOR value out of all possible strong pairs in the array nums.\nNote that you can pick the same integer twice to form a pair.\n\nExample 1:\n\nInput: nums = [1,2,3,4,5]\nOutput: 7\nExplanation: There are 11 strong pairs in the array nums: (1, 1), (1, 2), (2, 2), (2, 3), (2, 4), (3, 3), (3, 4), (3, 5), (4, 4), (4, 5) and (5, 5).\nThe maximum XOR possible from these pairs is 3 XOR 4 = 7.\n\nExample 2:\n\nInput: nums = [10,100]\nOutput: 0\nExplanation: There are 2 strong pairs in the array nums: (10, 10) and (100, 100).\nThe maximum XOR possible from these pairs is 10 XOR 10 = 0 since the pair (100, 100) also gives 100 XOR 100 = 0.\n\nExample 3:\n\nInput: nums = [500,520,2500,3000]\nOutput: 1020\nExplanation: There are 6 strong pairs in the array nums: (500, 500), (500, 520), (520, 520), (2500, 2500), (2500, 3000) and (3000, 3000).\nThe maximum XOR possible from these pairs is 500 XOR 520 = 1020 since the only other non-zero XOR value is 2500 XOR 3000 = 636.\n\n\nConstraints:\n\n1 <= nums.length <= 5 * 104\n1 <= nums[i] <= 220 - 1\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def maximumStrongPairXor(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,2,3,4,5] }\nassert my_solution.maximumStrongPairXor(**test_input) == 7\n\ntest_input = { \"nums\": [10,100] }\nassert my_solution.maximumStrongPairXor(**test_input) == 0\n\ntest_input = { \"nums\": [500,520,2500,3000] }\nassert my_solution.maximumStrongPairXor(**test_input) == 1020\n\ntest_input = { \"nums\": [1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 0\n\ntest_input = { \"nums\": [2,3] }\nassert my_solution.maximumStrongPairXor(**test_input) == 1\n\ntest_input = { \"nums\": [3,4] }\nassert my_solution.maximumStrongPairXor(**test_input) == 7\n\ntest_input = { \"nums\": [4,5] }\nassert my_solution.maximumStrongPairXor(**test_input) == 1\n\ntest_input = { \"nums\": [5,6] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,3] }\nassert my_solution.maximumStrongPairXor(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,4] }\nassert my_solution.maximumStrongPairXor(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,5] }\nassert my_solution.maximumStrongPairXor(**test_input) == 0\n\ntest_input = { \"nums\": [1,2,1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,3] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,4] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [1,2,5] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [1,3,1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 0\n\ntest_input = { \"nums\": [1,3,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [1,3,3] }\nassert my_solution.maximumStrongPairXor(**test_input) == 0\n\ntest_input = { \"nums\": [1,3,4] }\nassert my_solution.maximumStrongPairXor(**test_input) == 7\n\ntest_input = { \"nums\": [1,3,5] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [1,4,1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 0\n\ntest_input = { \"nums\": [1,4,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [1,4,3] }\nassert my_solution.maximumStrongPairXor(**test_input) == 7\n\ntest_input = { \"nums\": [1,4,4] }\nassert my_solution.maximumStrongPairXor(**test_input) == 0\n\ntest_input = { \"nums\": [1,4,5] }\nassert my_solution.maximumStrongPairXor(**test_input) == 1\n\ntest_input = { \"nums\": [1,5,1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 0\n\ntest_input = { \"nums\": [1,5,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [1,5,3] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [1,5,4] }\nassert my_solution.maximumStrongPairXor(**test_input) == 1\n\ntest_input = { \"nums\": [1,5,5] }\nassert my_solution.maximumStrongPairXor(**test_input) == 0\n\ntest_input = { \"nums\": [2,1,1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [2,1,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [2,1,3] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [2,1,4] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [2,1,5] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [2,2,1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [2,2,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 0\n\ntest_input = { \"nums\": [2,2,3] }\nassert my_solution.maximumStrongPairXor(**test_input) == 1\n\ntest_input = { \"nums\": [2,2,4] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [2,2,5] }\nassert my_solution.maximumStrongPairXor(**test_input) == 0\n\ntest_input = { \"nums\": [2,3,1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [2,3,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 1\n\ntest_input = { \"nums\": [2,3,3] }\nassert my_solution.maximumStrongPairXor(**test_input) == 1\n\ntest_input = { \"nums\": [2,3,4] }\nassert my_solution.maximumStrongPairXor(**test_input) == 7\n\ntest_input = { \"nums\": [2,3,5] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [2,4,1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [2,4,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [2,4,3] }\nassert my_solution.maximumStrongPairXor(**test_input) == 7\n\ntest_input = { \"nums\": [2,4,4] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [2,4,5] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [2,5,1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [2,5,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 0\n\ntest_input = { \"nums\": [2,5,3] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [2,5,4] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [2,5,5] }\nassert my_solution.maximumStrongPairXor(**test_input) == 0\n\ntest_input = { \"nums\": [3,1,1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 0\n\ntest_input = { \"nums\": [3,1,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [3,1,3] }\nassert my_solution.maximumStrongPairXor(**test_input) == 0\n\ntest_input = { \"nums\": [3,1,4] }\nassert my_solution.maximumStrongPairXor(**test_input) == 7\n\ntest_input = { \"nums\": [3,1,5] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [3,2,1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 3\n\ntest_input = { \"nums\": [3,2,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 1\n\ntest_input = { \"nums\": [3,2,3] }\nassert my_solution.maximumStrongPairXor(**test_input) == 1\n\ntest_input = { \"nums\": [3,2,4] }\nassert my_solution.maximumStrongPairXor(**test_input) == 7\n\ntest_input = { \"nums\": [3,2,5] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [3,3,1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 0\n\ntest_input = { \"nums\": [3,3,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 1\n\ntest_input = { \"nums\": [3,3,3] }\nassert my_solution.maximumStrongPairXor(**test_input) == 0\n\ntest_input = { \"nums\": [3,3,4] }\nassert my_solution.maximumStrongPairXor(**test_input) == 7\n\ntest_input = { \"nums\": [3,3,5] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [3,4,1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 7\n\ntest_input = { \"nums\": [3,4,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 7\n\ntest_input = { \"nums\": [3,4,3] }\nassert my_solution.maximumStrongPairXor(**test_input) == 7\n\ntest_input = { \"nums\": [3,4,4] }\nassert my_solution.maximumStrongPairXor(**test_input) == 7\n\ntest_input = { \"nums\": [3,4,5] }\nassert my_solution.maximumStrongPairXor(**test_input) == 7\n\ntest_input = { \"nums\": [3,5,1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [3,5,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [3,5,3] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [3,5,4] }\nassert my_solution.maximumStrongPairXor(**test_input) == 7\n\ntest_input = { \"nums\": [3,5,5] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [4,1,1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 0\n\ntest_input = { \"nums\": [4,1,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [4,1,3] }\nassert my_solution.maximumStrongPairXor(**test_input) == 7\n\ntest_input = { \"nums\": [4,1,4] }\nassert my_solution.maximumStrongPairXor(**test_input) == 0\n\ntest_input = { \"nums\": [4,1,5] }\nassert my_solution.maximumStrongPairXor(**test_input) == 1\n\ntest_input = { \"nums\": [4,2,1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [4,2,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [4,2,3] }\nassert my_solution.maximumStrongPairXor(**test_input) == 7\n\ntest_input = { \"nums\": [4,2,4] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [4,2,5] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6\n\ntest_input = { \"nums\": [4,3,1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 7\n\ntest_input = { \"nums\": [4,3,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 7\n\ntest_input = { \"nums\": [4,3,3] }\nassert my_solution.maximumStrongPairXor(**test_input) == 7\n\ntest_input = { \"nums\": [4,3,4] }\nassert my_solution.maximumStrongPairXor(**test_input) == 7\n\ntest_input = { \"nums\": [4,3,5] }\nassert my_solution.maximumStrongPairXor(**test_input) == 7\n\ntest_input = { \"nums\": [4,4,1] }\nassert my_solution.maximumStrongPairXor(**test_input) == 0\n\ntest_input = { \"nums\": [4,4,2] }\nassert my_solution.maximumStrongPairXor(**test_input) == 6", "start_time": 1699756200} +{"task_id": "biweekly-contest-117-distribute-candies-among-children-i", "url": "https://leetcode.com/problems/distribute-candies-among-children-i", "title": "distribute-candies-among-children-i", "meta": {"questionId": "3199", "questionFrontendId": "2928", "title": "Distribute Candies Among Children I", "titleSlug": "distribute-candies-among-children-i", "isPaidOnly": false, "difficulty": "Easy", "likes": 50, "dislikes": 25, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given two positive integers n and limit.\n\nReturn the total number of ways to distribute n candies among 3 children such that no child gets more than limit candies.\n\nExample 1:\n\nInput: n = 5, limit = 2\nOutput: 3\nExplanation: There are 3 ways to distribute 5 candies such that no child gets more than 2 candies: (1, 2, 2), (2, 1, 2) and (2, 2, 1).\n\nExample 2:\n\nInput: n = 3, limit = 3\nOutput: 10\nExplanation: There are 10 ways to distribute 3 candies such that no child gets more than 3 candies: (0, 0, 3), (0, 1, 2), (0, 2, 1), (0, 3, 0), (1, 0, 2), (1, 1, 1), (1, 2, 0), (2, 0, 1), (2, 1, 0) and (3, 0, 0).\n\n\nConstraints:\n\n * 1 <= n <= 50\n * 1 <= limit <= 50\n\"\"\"\nclass Solution:\n def distributeCandies(self, n: int, limit: int) -> int:\n ", "prompt_sft": "You are given two positive integers n and limit.\n\nReturn the total number of ways to distribute n candies among 3 children such that no child gets more than limit candies.\n\nExample 1:\n\nInput: n = 5, limit = 2\nOutput: 3\nExplanation: There are 3 ways to distribute 5 candies such that no child gets more than 2 candies: (1, 2, 2), (2, 1, 2) and (2, 2, 1).\n\nExample 2:\n\nInput: n = 3, limit = 3\nOutput: 10\nExplanation: There are 10 ways to distribute 3 candies such that no child gets more than 3 candies: (0, 0, 3), (0, 1, 2), (0, 2, 1), (0, 3, 0), (1, 0, 2), (1, 1, 1), (1, 2, 0), (2, 0, 1), (2, 1, 0) and (3, 0, 0).\n\n\nConstraints:\n\n * 1 <= n <= 50\n * 1 <= limit <= 50\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def distributeCandies(self, n: int, limit: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"n\": 5, \"limit\": 2 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 3, \"limit\": 3 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 1, \"limit\": 1 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 2 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 3 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 4 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 5 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 6 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 7 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 8 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 9 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 10 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 11 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 12 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 13 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 14 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 15 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 16 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 17 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 18 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 19 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 20 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 21 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 22 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 23 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 24 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 25 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 2, \"limit\": 1 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 2, \"limit\": 2 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 3 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 4 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 5 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 6 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 7 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 8 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 9 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 10 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 11 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 12 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 13 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 14 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 15 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 16 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 17 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 18 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 19 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 20 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 21 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 22 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 23 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 24 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 25 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 3, \"limit\": 1 }\nassert my_solution.distributeCandies(**test_input) == 1\n\ntest_input = { \"n\": 3, \"limit\": 2 }\nassert my_solution.distributeCandies(**test_input) == 7\n\ntest_input = { \"n\": 3, \"limit\": 4 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 5 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 6 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 7 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 8 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 9 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 10 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 11 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 12 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 13 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 14 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 15 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 16 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 17 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 18 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 19 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 20 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 21 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 22 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 23 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 24 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 25 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 4, \"limit\": 1 }\nassert my_solution.distributeCandies(**test_input) == 0\n\ntest_input = { \"n\": 4, \"limit\": 2 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 4, \"limit\": 3 }\nassert my_solution.distributeCandies(**test_input) == 12\n\ntest_input = { \"n\": 4, \"limit\": 4 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 5 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 6 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 7 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 8 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 9 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 10 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 11 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 12 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 13 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 14 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 15 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 16 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 17 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 18 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 19 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 20 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 21 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 22 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 23 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 24 }\nassert my_solution.distributeCandies(**test_input) == 15", "start_time": 1699713000} +{"task_id": "biweekly-contest-117-distribute-candies-among-children-ii", "url": "https://leetcode.com/problems/distribute-candies-among-children-ii", "title": "distribute-candies-among-children-ii", "meta": {"questionId": "3201", "questionFrontendId": "2929", "title": "Distribute Candies Among Children II", "titleSlug": "distribute-candies-among-children-ii", "isPaidOnly": false, "difficulty": "Medium", "likes": 62, "dislikes": 95, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given two positive integers n and limit.\n\nReturn the total number of ways to distribute n candies among 3 children such that no child gets more than limit candies.\n\nExample 1:\n\nInput: n = 5, limit = 2\nOutput: 3\nExplanation: There are 3 ways to distribute 5 candies such that no child gets more than 2 candies: (1, 2, 2), (2, 1, 2) and (2, 2, 1).\n\nExample 2:\n\nInput: n = 3, limit = 3\nOutput: 10\nExplanation: There are 10 ways to distribute 3 candies such that no child gets more than 3 candies: (0, 0, 3), (0, 1, 2), (0, 2, 1), (0, 3, 0), (1, 0, 2), (1, 1, 1), (1, 2, 0), (2, 0, 1), (2, 1, 0) and (3, 0, 0).\n\n\nConstraints:\n\n * 1 <= n <= 106\n * 1 <= limit <= 106\n\"\"\"\nclass Solution:\n def distributeCandies(self, n: int, limit: int) -> int:\n ", "prompt_sft": "You are given two positive integers n and limit.\n\nReturn the total number of ways to distribute n candies among 3 children such that no child gets more than limit candies.\n\nExample 1:\n\nInput: n = 5, limit = 2\nOutput: 3\nExplanation: There are 3 ways to distribute 5 candies such that no child gets more than 2 candies: (1, 2, 2), (2, 1, 2) and (2, 2, 1).\n\nExample 2:\n\nInput: n = 3, limit = 3\nOutput: 10\nExplanation: There are 10 ways to distribute 3 candies such that no child gets more than 3 candies: (0, 0, 3), (0, 1, 2), (0, 2, 1), (0, 3, 0), (1, 0, 2), (1, 1, 1), (1, 2, 0), (2, 0, 1), (2, 1, 0) and (3, 0, 0).\n\n\nConstraints:\n\n * 1 <= n <= 106\n * 1 <= limit <= 106\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def distributeCandies(self, n: int, limit: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"n\": 5, \"limit\": 2 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 3, \"limit\": 3 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 1, \"limit\": 1 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 2 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 3 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 4 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 5 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 6 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 7 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 8 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 9 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 10 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 11 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 12 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 13 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 14 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 15 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 16 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 17 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 18 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 19 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 1, \"limit\": 20 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 2, \"limit\": 1 }\nassert my_solution.distributeCandies(**test_input) == 3\n\ntest_input = { \"n\": 2, \"limit\": 2 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 3 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 4 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 5 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 6 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 7 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 8 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 9 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 10 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 11 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 12 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 13 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 14 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 15 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 16 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 17 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 18 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 19 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 2, \"limit\": 20 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 3, \"limit\": 1 }\nassert my_solution.distributeCandies(**test_input) == 1\n\ntest_input = { \"n\": 3, \"limit\": 2 }\nassert my_solution.distributeCandies(**test_input) == 7\n\ntest_input = { \"n\": 3, \"limit\": 4 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 5 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 6 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 7 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 8 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 9 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 10 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 11 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 12 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 13 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 14 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 15 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 16 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 17 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 18 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 19 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 3, \"limit\": 20 }\nassert my_solution.distributeCandies(**test_input) == 10\n\ntest_input = { \"n\": 4, \"limit\": 1 }\nassert my_solution.distributeCandies(**test_input) == 0\n\ntest_input = { \"n\": 4, \"limit\": 2 }\nassert my_solution.distributeCandies(**test_input) == 6\n\ntest_input = { \"n\": 4, \"limit\": 3 }\nassert my_solution.distributeCandies(**test_input) == 12\n\ntest_input = { \"n\": 4, \"limit\": 4 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 5 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 6 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 7 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 8 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 9 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 10 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 11 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 12 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 13 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 14 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 15 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 16 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 17 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 18 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 19 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 4, \"limit\": 20 }\nassert my_solution.distributeCandies(**test_input) == 15\n\ntest_input = { \"n\": 5, \"limit\": 1 }\nassert my_solution.distributeCandies(**test_input) == 0\n\ntest_input = { \"n\": 5, \"limit\": 3 }\nassert my_solution.distributeCandies(**test_input) == 12\n\ntest_input = { \"n\": 5, \"limit\": 4 }\nassert my_solution.distributeCandies(**test_input) == 18\n\ntest_input = { \"n\": 5, \"limit\": 5 }\nassert my_solution.distributeCandies(**test_input) == 21\n\ntest_input = { \"n\": 5, \"limit\": 6 }\nassert my_solution.distributeCandies(**test_input) == 21\n\ntest_input = { \"n\": 5, \"limit\": 7 }\nassert my_solution.distributeCandies(**test_input) == 21\n\ntest_input = { \"n\": 5, \"limit\": 8 }\nassert my_solution.distributeCandies(**test_input) == 21\n\ntest_input = { \"n\": 5, \"limit\": 9 }\nassert my_solution.distributeCandies(**test_input) == 21\n\ntest_input = { \"n\": 5, \"limit\": 10 }\nassert my_solution.distributeCandies(**test_input) == 21\n\ntest_input = { \"n\": 5, \"limit\": 11 }\nassert my_solution.distributeCandies(**test_input) == 21\n\ntest_input = { \"n\": 5, \"limit\": 12 }\nassert my_solution.distributeCandies(**test_input) == 21\n\ntest_input = { \"n\": 5, \"limit\": 13 }\nassert my_solution.distributeCandies(**test_input) == 21\n\ntest_input = { \"n\": 5, \"limit\": 14 }\nassert my_solution.distributeCandies(**test_input) == 21\n\ntest_input = { \"n\": 5, \"limit\": 15 }\nassert my_solution.distributeCandies(**test_input) == 21\n\ntest_input = { \"n\": 5, \"limit\": 16 }\nassert my_solution.distributeCandies(**test_input) == 21\n\ntest_input = { \"n\": 5, \"limit\": 17 }\nassert my_solution.distributeCandies(**test_input) == 21\n\ntest_input = { \"n\": 5, \"limit\": 18 }\nassert my_solution.distributeCandies(**test_input) == 21\n\ntest_input = { \"n\": 5, \"limit\": 19 }\nassert my_solution.distributeCandies(**test_input) == 21\n\ntest_input = { \"n\": 5, \"limit\": 20 }\nassert my_solution.distributeCandies(**test_input) == 21", "start_time": 1699713000} +{"task_id": "biweekly-contest-117-number-of-strings-which-can-be-rearranged-to-contain-substring", "url": "https://leetcode.com/problems/number-of-strings-which-can-be-rearranged-to-contain-substring", "title": "number-of-strings-which-can-be-rearranged-to-contain-substring", "meta": {"questionId": "3200", "questionFrontendId": "2930", "title": "Number of Strings Which Can Be Rearranged to Contain Substring", "titleSlug": "number-of-strings-which-can-be-rearranged-to-contain-substring", "isPaidOnly": false, "difficulty": "Medium", "likes": 119, "dislikes": 54, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given an integer n.\n\nA string s is called good if it contains only lowercase English characters and it is possible to rearrange the characters of s such that the new string contains \"leet\" as a substring.\n\nFor example:\n\n * The string \"lteer\" is good because we can rearrange it to form \"leetr\" .\n * \"letl\" is not good because we cannot rearrange it to contain \"leet\" as a substring.\n\nReturn the total number of good strings of length n.\n\nSince the answer may be large, return it modulo 109 + 7.\n\nA substring is a contiguous sequence of characters within a string.\n\n\nExample 1:\n\nInput: n = 4\nOutput: 12\nExplanation: The 12 strings which can be rearranged to have \"leet\" as a substring are: \"eelt\", \"eetl\", \"elet\", \"elte\", \"etel\", \"etle\", \"leet\", \"lete\", \"ltee\", \"teel\", \"tele\", and \"tlee\".\n\nExample 2:\n\nInput: n = 10\nOutput: 83943898\nExplanation: The number of strings with length 10 which can be rearranged to have \"leet\" as a substring is 526083947580. Hence the answer is 526083947580 % (109 + 7) = 83943898.\n\n\nConstraints:\n\n * 1 <= n <= 105\n\"\"\"\nclass Solution:\n def stringCount(self, n: int) -> int:\n ", "prompt_sft": "You are given an integer n.\n\nA string s is called good if it contains only lowercase English characters and it is possible to rearrange the characters of s such that the new string contains \"leet\" as a substring.\n\nFor example:\n\n * The string \"lteer\" is good because we can rearrange it to form \"leetr\" .\n * \"letl\" is not good because we cannot rearrange it to contain \"leet\" as a substring.\n\nReturn the total number of good strings of length n.\n\nSince the answer may be large, return it modulo 109 + 7.\n\nA substring is a contiguous sequence of characters within a string.\n\n\nExample 1:\n\nInput: n = 4\nOutput: 12\nExplanation: The 12 strings which can be rearranged to have \"leet\" as a substring are: \"eelt\", \"eetl\", \"elet\", \"elte\", \"etel\", \"etle\", \"leet\", \"lete\", \"ltee\", \"teel\", \"tele\", and \"tlee\".\n\nExample 2:\n\nInput: n = 10\nOutput: 83943898\nExplanation: The number of strings with length 10 which can be rearranged to have \"leet\" as a substring is 526083947580. Hence the answer is 526083947580 % (109 + 7) = 83943898.\n\n\nConstraints:\n\n * 1 <= n <= 105\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def stringCount(self, n: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"n\": 4 }\nassert my_solution.stringCount(**test_input) == 12\n\ntest_input = { \"n\": 10 }\nassert my_solution.stringCount(**test_input) == 83943898\n\ntest_input = { \"n\": 1 }\nassert my_solution.stringCount(**test_input) == 0\n\ntest_input = { \"n\": 2 }\nassert my_solution.stringCount(**test_input) == 0\n\ntest_input = { \"n\": 3 }\nassert my_solution.stringCount(**test_input) == 0\n\ntest_input = { \"n\": 5 }\nassert my_solution.stringCount(**test_input) == 1460\n\ntest_input = { \"n\": 6 }\nassert my_solution.stringCount(**test_input) == 106620\n\ntest_input = { \"n\": 7 }\nassert my_solution.stringCount(**test_input) == 6058192\n\ntest_input = { \"n\": 8 }\nassert my_solution.stringCount(**test_input) == 295164156\n\ntest_input = { \"n\": 9 }\nassert my_solution.stringCount(**test_input) == 947613240\n\ntest_input = { \"n\": 11 }\nassert my_solution.stringCount(**test_input) == 795234177\n\ntest_input = { \"n\": 12 }\nassert my_solution.stringCount(**test_input) == 55396773\n\ntest_input = { \"n\": 13 }\nassert my_solution.stringCount(**test_input) == 968092561\n\ntest_input = { \"n\": 14 }\nassert my_solution.stringCount(**test_input) == 715599898\n\ntest_input = { \"n\": 15 }\nassert my_solution.stringCount(**test_input) == 430509685\n\ntest_input = { \"n\": 16 }\nassert my_solution.stringCount(**test_input) == 462719236\n\ntest_input = { \"n\": 17 }\nassert my_solution.stringCount(**test_input) == 155543310\n\ntest_input = { \"n\": 18 }\nassert my_solution.stringCount(**test_input) == 159683962\n\ntest_input = { \"n\": 19 }\nassert my_solution.stringCount(**test_input) == 808507313\n\ntest_input = { \"n\": 20 }\nassert my_solution.stringCount(**test_input) == 291395991\n\ntest_input = { \"n\": 21 }\nassert my_solution.stringCount(**test_input) == 461951930\n\ntest_input = { \"n\": 22 }\nassert my_solution.stringCount(**test_input) == 871561520\n\ntest_input = { \"n\": 23 }\nassert my_solution.stringCount(**test_input) == 993268925\n\ntest_input = { \"n\": 24 }\nassert my_solution.stringCount(**test_input) == 871982505\n\ntest_input = { \"n\": 25 }\nassert my_solution.stringCount(**test_input) == 935610434\n\ntest_input = { \"n\": 26 }\nassert my_solution.stringCount(**test_input) == 867518559\n\ntest_input = { \"n\": 27 }\nassert my_solution.stringCount(**test_input) == 3067523\n\ntest_input = { \"n\": 28 }\nassert my_solution.stringCount(**test_input) == 716801469\n\ntest_input = { \"n\": 29 }\nassert my_solution.stringCount(**test_input) == 452206104\n\ntest_input = { \"n\": 30 }\nassert my_solution.stringCount(**test_input) == 52805056\n\ntest_input = { \"n\": 31 }\nassert my_solution.stringCount(**test_input) == 61992724\n\ntest_input = { \"n\": 32 }\nassert my_solution.stringCount(**test_input) == 76928250\n\ntest_input = { \"n\": 33 }\nassert my_solution.stringCount(**test_input) == 257967635\n\ntest_input = { \"n\": 34 }\nassert my_solution.stringCount(**test_input) == 549347744\n\ntest_input = { \"n\": 35 }\nassert my_solution.stringCount(**test_input) == 290653839\n\ntest_input = { \"n\": 36 }\nassert my_solution.stringCount(**test_input) == 123906995\n\ntest_input = { \"n\": 37 }\nassert my_solution.stringCount(**test_input) == 41253530\n\ntest_input = { \"n\": 38 }\nassert my_solution.stringCount(**test_input) == 828924891\n\ntest_input = { \"n\": 39 }\nassert my_solution.stringCount(**test_input) == 60893212\n\ntest_input = { \"n\": 40 }\nassert my_solution.stringCount(**test_input) == 618599272\n\ntest_input = { \"n\": 41 }\nassert my_solution.stringCount(**test_input) == 840600409\n\ntest_input = { \"n\": 42 }\nassert my_solution.stringCount(**test_input) == 995406621\n\ntest_input = { \"n\": 43 }\nassert my_solution.stringCount(**test_input) == 991833054\n\ntest_input = { \"n\": 44 }\nassert my_solution.stringCount(**test_input) == 403185520\n\ntest_input = { \"n\": 45 }\nassert my_solution.stringCount(**test_input) == 904195428\n\ntest_input = { \"n\": 46 }\nassert my_solution.stringCount(**test_input) == 643609894\n\ntest_input = { \"n\": 47 }\nassert my_solution.stringCount(**test_input) == 177947842\n\ntest_input = { \"n\": 48 }\nassert my_solution.stringCount(**test_input) == 826753905\n\ntest_input = { \"n\": 49 }\nassert my_solution.stringCount(**test_input) == 855443295\n\ntest_input = { \"n\": 50 }\nassert my_solution.stringCount(**test_input) == 232825199\n\ntest_input = { \"n\": 51 }\nassert my_solution.stringCount(**test_input) == 227116084\n\ntest_input = { \"n\": 52 }\nassert my_solution.stringCount(**test_input) == 417264566\n\ntest_input = { \"n\": 53 }\nassert my_solution.stringCount(**test_input) == 468973861\n\ntest_input = { \"n\": 54 }\nassert my_solution.stringCount(**test_input) == 999145386\n\ntest_input = { \"n\": 55 }\nassert my_solution.stringCount(**test_input) == 721276317\n\ntest_input = { \"n\": 56 }\nassert my_solution.stringCount(**test_input) == 385673910\n\ntest_input = { \"n\": 57 }\nassert my_solution.stringCount(**test_input) == 7891114\n\ntest_input = { \"n\": 58 }\nassert my_solution.stringCount(**test_input) == 85081065\n\ntest_input = { \"n\": 59 }\nassert my_solution.stringCount(**test_input) == 194677227\n\ntest_input = { \"n\": 60 }\nassert my_solution.stringCount(**test_input) == 759126147\n\ntest_input = { \"n\": 61 }\nassert my_solution.stringCount(**test_input) == 273111337\n\ntest_input = { \"n\": 62 }\nassert my_solution.stringCount(**test_input) == 166598301\n\ntest_input = { \"n\": 63 }\nassert my_solution.stringCount(**test_input) == 955460796\n\ntest_input = { \"n\": 64 }\nassert my_solution.stringCount(**test_input) == 685704195\n\ntest_input = { \"n\": 65 }\nassert my_solution.stringCount(**test_input) == 821093882\n\ntest_input = { \"n\": 66 }\nassert my_solution.stringCount(**test_input) == 172674695\n\ntest_input = { \"n\": 67 }\nassert my_solution.stringCount(**test_input) == 464621746\n\ntest_input = { \"n\": 68 }\nassert my_solution.stringCount(**test_input) == 432202634\n\ntest_input = { \"n\": 69 }\nassert my_solution.stringCount(**test_input) == 465445347\n\ntest_input = { \"n\": 70 }\nassert my_solution.stringCount(**test_input) == 654273613\n\ntest_input = { \"n\": 71 }\nassert my_solution.stringCount(**test_input) == 366864502\n\ntest_input = { \"n\": 72 }\nassert my_solution.stringCount(**test_input) == 124689502\n\ntest_input = { \"n\": 73 }\nassert my_solution.stringCount(**test_input) == 419691288\n\ntest_input = { \"n\": 74 }\nassert my_solution.stringCount(**test_input) == 987033948\n\ntest_input = { \"n\": 75 }\nassert my_solution.stringCount(**test_input) == 842828500\n\ntest_input = { \"n\": 76 }\nassert my_solution.stringCount(**test_input) == 409614634\n\ntest_input = { \"n\": 77 }\nassert my_solution.stringCount(**test_input) == 73844796\n\ntest_input = { \"n\": 78 }\nassert my_solution.stringCount(**test_input) == 584672527\n\ntest_input = { \"n\": 79 }\nassert my_solution.stringCount(**test_input) == 113476429\n\ntest_input = { \"n\": 80 }\nassert my_solution.stringCount(**test_input) == 974106352\n\ntest_input = { \"n\": 81 }\nassert my_solution.stringCount(**test_input) == 646239862\n\ntest_input = { \"n\": 82 }\nassert my_solution.stringCount(**test_input) == 420253116\n\ntest_input = { \"n\": 83 }\nassert my_solution.stringCount(**test_input) == 817573615\n\ntest_input = { \"n\": 84 }\nassert my_solution.stringCount(**test_input) == 471199144\n\ntest_input = { \"n\": 85 }\nassert my_solution.stringCount(**test_input) == 567239979\n\ntest_input = { \"n\": 86 }\nassert my_solution.stringCount(**test_input) == 221534816\n\ntest_input = { \"n\": 87 }\nassert my_solution.stringCount(**test_input) == 707218848\n\ntest_input = { \"n\": 88 }\nassert my_solution.stringCount(**test_input) == 687360104\n\ntest_input = { \"n\": 89 }\nassert my_solution.stringCount(**test_input) == 551986596\n\ntest_input = { \"n\": 90 }\nassert my_solution.stringCount(**test_input) == 122933939\n\ntest_input = { \"n\": 91 }\nassert my_solution.stringCount(**test_input) == 427294641\n\ntest_input = { \"n\": 92 }\nassert my_solution.stringCount(**test_input) == 14022454\n\ntest_input = { \"n\": 93 }\nassert my_solution.stringCount(**test_input) == 568729284\n\ntest_input = { \"n\": 94 }\nassert my_solution.stringCount(**test_input) == 653568519\n\ntest_input = { \"n\": 95 }\nassert my_solution.stringCount(**test_input) == 15509440\n\ntest_input = { \"n\": 96 }\nassert my_solution.stringCount(**test_input) == 991824044\n\ntest_input = { \"n\": 97 }\nassert my_solution.stringCount(**test_input) == 690441338\n\ntest_input = { \"n\": 98 }\nassert my_solution.stringCount(**test_input) == 600462833\n\ntest_input = { \"n\": 99 }\nassert my_solution.stringCount(**test_input) == 880019356\n\ntest_input = { \"n\": 100 }\nassert my_solution.stringCount(**test_input) == 86731066", "start_time": 1699713000} +{"task_id": "biweekly-contest-117-maximum-spending-after-buying-items", "url": "https://leetcode.com/problems/maximum-spending-after-buying-items", "title": "maximum-spending-after-buying-items", "meta": {"questionId": "3107", "questionFrontendId": "2931", "title": "Maximum Spending After Buying Items", "titleSlug": "maximum-spending-after-buying-items", "isPaidOnly": false, "difficulty": "Hard", "likes": 66, "dislikes": 20, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed m * n integer matrix values, representing the values of m * n different items in m different shops. Each shop has n items where the jth item in the ith shop has a value of values[i][j]. Additionally, the items in the ith shop are sorted in non-increasing order of value. That is, values[i][j] >= values[i][j + 1] for all 0 <= j < n - 1.\n\nOn each day, you would like to buy a single item from one of the shops. Specifically, On the dth day you can:\n\n * Pick any shop i.\n * Buy the rightmost available item j for the price of values[i][j] * d. That is, find the greatest index j such that item j was never bought before, and buy it for the price of values[i][j] * d.\n\nNote that all items are pairwise different. For example, if you have bought item 0 from shop 1, you can still buy item 0 from any other shop.\n\nReturn the maximum amount of money that can be spent on buying all m * n products.\n\nExample 1:\n\nInput: values = [[8,5,2],[6,4,1],[9,7,3]]\nOutput: 285\nExplanation: On the first day, we buy product 2 from shop 1 for a price of values[1][2] * 1 = 1.\nOn the second day, we buy product 2 from shop 0 for a price of values[0][2] * 2 = 4.\nOn the third day, we buy product 2 from shop 2 for a price of values[2][2] * 3 = 9.\nOn the fourth day, we buy product 1 from shop 1 for a price of values[1][1] * 4 = 16.\nOn the fifth day, we buy product 1 from shop 0 for a price of values[0][1] * 5 = 25.\nOn the sixth day, we buy product 0 from shop 1 for a price of values[1][0] * 6 = 36.\nOn the seventh day, we buy product 1 from shop 2 for a price of values[2][1] * 7 = 49.\nOn the eighth day, we buy product 0 from shop 0 for a price of values[0][0] * 8 = 64.\nOn the ninth day, we buy product 0 from shop 2 for a price of values[2][0] * 9 = 81.\nHence, our total spending is equal to 285.\nIt can be shown that 285 is the maximum amount of money that can be spent buying all m * n products.\n\nExample 2:\n\nInput: values = [[10,8,6,4,2],[9,7,5,3,2]]\nOutput: 386\nExplanation: On the first day, we buy product 4 from shop 0 for a price of values[0][4] * 1 = 2.\nOn the second day, we buy product 4 from shop 1 for a price of values[1][4] * 2 = 4.\nOn the third day, we buy product 3 from shop 1 for a price of values[1][3] * 3 = 9.\nOn the fourth day, we buy product 3 from shop 0 for a price of values[0][3] * 4 = 16.\nOn the fifth day, we buy product 2 from shop 1 for a price of values[1][2] * 5 = 25.\nOn the sixth day, we buy product 2 from shop 0 for a price of values[0][2] * 6 = 36.\nOn the seventh day, we buy product 1 from shop 1 for a price of values[1][1] * 7 = 49.\nOn the eighth day, we buy product 1 from shop 0 for a price of values[0][1] * 8 = 64\nOn the ninth day, we buy product 0 from shop 1 for a price of values[1][0] * 9 = 81.\nOn the tenth day, we buy product 0 from shop 0 for a price of values[0][0] * 10 = 100.\nHence, our total spending is equal to 386.\nIt can be shown that 386 is the maximum amount of money that can be spent buying all m * n products.\n\n\nConstraints:\n\n * 1 <= m == values.length <= 10\n * 1 <= n == values[i].length <= 104\n * 1 <= values[i][j] <= 106\n * values[i] are sorted in non-increasing order.\n\"\"\"\nclass Solution:\n def maxSpending(self, values: List[List[int]]) -> int:\n ", "prompt_sft": "You are given a 0-indexed m * n integer matrix values, representing the values of m * n different items in m different shops. Each shop has n items where the jth item in the ith shop has a value of values[i][j]. Additionally, the items in the ith shop are sorted in non-increasing order of value. That is, values[i][j] >= values[i][j + 1] for all 0 <= j < n - 1.\n\nOn each day, you would like to buy a single item from one of the shops. Specifically, On the dth day you can:\n\n * Pick any shop i.\n * Buy the rightmost available item j for the price of values[i][j] * d. That is, find the greatest index j such that item j was never bought before, and buy it for the price of values[i][j] * d.\n\nNote that all items are pairwise different. For example, if you have bought item 0 from shop 1, you can still buy item 0 from any other shop.\n\nReturn the maximum amount of money that can be spent on buying all m * n products.\n\nExample 1:\n\nInput: values = [[8,5,2],[6,4,1],[9,7,3]]\nOutput: 285\nExplanation: On the first day, we buy product 2 from shop 1 for a price of values[1][2] * 1 = 1.\nOn the second day, we buy product 2 from shop 0 for a price of values[0][2] * 2 = 4.\nOn the third day, we buy product 2 from shop 2 for a price of values[2][2] * 3 = 9.\nOn the fourth day, we buy product 1 from shop 1 for a price of values[1][1] * 4 = 16.\nOn the fifth day, we buy product 1 from shop 0 for a price of values[0][1] * 5 = 25.\nOn the sixth day, we buy product 0 from shop 1 for a price of values[1][0] * 6 = 36.\nOn the seventh day, we buy product 1 from shop 2 for a price of values[2][1] * 7 = 49.\nOn the eighth day, we buy product 0 from shop 0 for a price of values[0][0] * 8 = 64.\nOn the ninth day, we buy product 0 from shop 2 for a price of values[2][0] * 9 = 81.\nHence, our total spending is equal to 285.\nIt can be shown that 285 is the maximum amount of money that can be spent buying all m * n products.\n\nExample 2:\n\nInput: values = [[10,8,6,4,2],[9,7,5,3,2]]\nOutput: 386\nExplanation: On the first day, we buy product 4 from shop 0 for a price of values[0][4] * 1 = 2.\nOn the second day, we buy product 4 from shop 1 for a price of values[1][4] * 2 = 4.\nOn the third day, we buy product 3 from shop 1 for a price of values[1][3] * 3 = 9.\nOn the fourth day, we buy product 3 from shop 0 for a price of values[0][3] * 4 = 16.\nOn the fifth day, we buy product 2 from shop 1 for a price of values[1][2] * 5 = 25.\nOn the sixth day, we buy product 2 from shop 0 for a price of values[0][2] * 6 = 36.\nOn the seventh day, we buy product 1 from shop 1 for a price of values[1][1] * 7 = 49.\nOn the eighth day, we buy product 1 from shop 0 for a price of values[0][1] * 8 = 64\nOn the ninth day, we buy product 0 from shop 1 for a price of values[1][0] * 9 = 81.\nOn the tenth day, we buy product 0 from shop 0 for a price of values[0][0] * 10 = 100.\nHence, our total spending is equal to 386.\nIt can be shown that 386 is the maximum amount of money that can be spent buying all m * n products.\n\n\nConstraints:\n\n * 1 <= m == values.length <= 10\n * 1 <= n == values[i].length <= 104\n * 1 <= values[i][j] <= 106\n * values[i] are sorted in non-increasing order.\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def maxSpending(self, values: List[List[int]]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"values\": [[8,5,2],[6,4,1],[9,7,3]] }\nassert my_solution.maxSpending(**test_input) == 285\n\ntest_input = { \"values\": [[10,8,6,4,2],[9,7,5,3,2]] }\nassert my_solution.maxSpending(**test_input) == 386\n\ntest_input = { \"values\": [[1000000]] }\nassert my_solution.maxSpending(**test_input) == 1000000\n\ntest_input = { \"values\": [[1]] }\nassert my_solution.maxSpending(**test_input) == 1\n\ntest_input = { \"values\": [[1],[2]] }\nassert my_solution.maxSpending(**test_input) == 5\n\ntest_input = { \"values\": [[2],[1]] }\nassert my_solution.maxSpending(**test_input) == 5\n\ntest_input = { \"values\": [[1],[1]] }\nassert my_solution.maxSpending(**test_input) == 3\n\ntest_input = { \"values\": [[5,2]] }\nassert my_solution.maxSpending(**test_input) == 12\n\ntest_input = { \"values\": [[5,5]] }\nassert my_solution.maxSpending(**test_input) == 15\n\ntest_input = { \"values\": [[7,5]] }\nassert my_solution.maxSpending(**test_input) == 19\n\ntest_input = { \"values\": [[3,2,1]] }\nassert my_solution.maxSpending(**test_input) == 14\n\ntest_input = { \"values\": [[2,2,1]] }\nassert my_solution.maxSpending(**test_input) == 11\n\ntest_input = { \"values\": [[3,3,2]] }\nassert my_solution.maxSpending(**test_input) == 17\n\ntest_input = { \"values\": [[3],[2],[1]] }\nassert my_solution.maxSpending(**test_input) == 14\n\ntest_input = { \"values\": [[2],[10],[1]] }\nassert my_solution.maxSpending(**test_input) == 35\n\ntest_input = { \"values\": [[1000000,1000000,1000000]] }\nassert my_solution.maxSpending(**test_input) == 6000000\n\ntest_input = { \"values\": [[1000000,1000000,1000000,1000000]] }\nassert my_solution.maxSpending(**test_input) == 10000000\n\ntest_input = { \"values\": [[1000000],[1000000],[1000000],[1000000]] }\nassert my_solution.maxSpending(**test_input) == 10000000\n\ntest_input = { \"values\": [[1000000,1000000],[1000000,1000000]] }\nassert my_solution.maxSpending(**test_input) == 10000000\n\ntest_input = { \"values\": [[2,1],[4,3]] }\nassert my_solution.maxSpending(**test_input) == 30\n\ntest_input = { \"values\": [[3,1],[4,2]] }\nassert my_solution.maxSpending(**test_input) == 30\n\ntest_input = { \"values\": [[4,1],[3,2]] }\nassert my_solution.maxSpending(**test_input) == 30\n\ntest_input = { \"values\": [[15,13,13,12,12,12,12,11,11,11,11,9,9,8,7,5,5,5,1]] }\nassert my_solution.maxSpending(**test_input) == 2162\n\ntest_input = { \"values\": [[13,13,11,7,2,1],[13,10,10,6,3,3]] }\nassert my_solution.maxSpending(**test_input) == 776\n\ntest_input = { \"values\": [[12,6],[13,5],[13,3],[6,6],[15,6],[5,4],[6,1]] }\nassert my_solution.maxSpending(**test_input) == 971\n\ntest_input = { \"values\": [[15,15,14,14,14,10,10,9,9,8,8,8,7,7,7,4]] }\nassert my_solution.maxSpending(**test_input) == 1585\n\ntest_input = { \"values\": [[11,10],[10,1],[14,6],[13,5],[7,3],[10,10],[10,5]] }\nassert my_solution.maxSpending(**test_input) == 1061\n\ntest_input = { \"values\": [[15,13,12,7,6,4,1]] }\nassert my_solution.maxSpending(**test_input) == 298\n\ntest_input = { \"values\": [[8,2],[4,1],[10,4]] }\nassert my_solution.maxSpending(**test_input) == 133\n\ntest_input = { \"values\": [[10,4],[13,2],[7,5],[15,11]] }\nassert my_solution.maxSpending(**test_input) == 380\n\ntest_input = { \"values\": [[13,10,10,9,8,5,5,2,1,1]] }\nassert my_solution.maxSpending(**test_input) == 465\n\ntest_input = { \"values\": [[15,14,8,7,5,5,1]] }\nassert my_solution.maxSpending(**test_input) == 283\n\ntest_input = { \"values\": [[15,15,14,14,14,14,13,11,10,10,10,9,7,7,6,6,4,4,2,1]] }\nassert my_solution.maxSpending(**test_input) == 2449\n\ntest_input = { \"values\": [[15,14,11,10,10,6,2],[13,8,8,6,6,3,2]] }\nassert my_solution.maxSpending(**test_input) == 1084\n\ntest_input = { \"values\": [[15,15,14,13,13,12,11,9,9,9,8,6,5,5,4,3,2,1,1]] }\nassert my_solution.maxSpending(**test_input) == 2030\n\ntest_input = { \"values\": [[15,10,7],[14,2,2],[14,13,12],[13,13,10]] }\nassert my_solution.maxSpending(**test_input) == 975\n\ntest_input = { \"values\": [[10,9,3,3],[11,8,7,2],[14,14,13,1],[14,14,11,4],[13,11,9,5]] }\nassert my_solution.maxSpending(**test_input) == 2338\n\ntest_input = { \"values\": [[11,7,5,2],[15,5,5,3]] }\nassert my_solution.maxSpending(**test_input) == 307\n\ntest_input = { \"values\": [[15,10,10,9,8,7,4,2,2]] }\nassert my_solution.maxSpending(**test_input) == 425\n\ntest_input = { \"values\": [[15,13,12,12,10,5,4,3,1]] }\nassert my_solution.maxSpending(**test_input) == 484\n\ntest_input = { \"values\": [[12,12,12,11,10,10,7,7,6,5,5,3,2,1]] }\nassert my_solution.maxSpending(**test_input) == 979\n\ntest_input = { \"values\": [[15,13,13,13,12,12,11,11,10,9,9,9,8,6,6,4,4,3,2,1]] }\nassert my_solution.maxSpending(**test_input) == 2253\n\ntest_input = { \"values\": [[14,11],[11,8],[10,4],[4,3],[9,6],[8,4],[7,7],[10,4],[14,4]] }\nassert my_solution.maxSpending(**test_input) == 1621\n\ntest_input = { \"values\": [[14,13,13,11,11,8,8,7,6,4,3,2,1]] }\nassert my_solution.maxSpending(**test_input) == 912\n\ntest_input = { \"values\": [[15,14,14,10,10,9,9,7,7,7,7,7,6,6,6,4,4,3,3]] }\nassert my_solution.maxSpending(**test_input) == 1823\n\ntest_input = { \"values\": [[14,13,11,10,10,1,1],[15,12,8,6,6,5,5]] }\nassert my_solution.maxSpending(**test_input) == 1120\n\ntest_input = { \"values\": [[15,14,13,12,11,10,10,10,9,7,6,6,4,3,3,3,2,2,1]] }\nassert my_solution.maxSpending(**test_input) == 1860\n\ntest_input = { \"values\": [[12,6,5,4,2]] }\nassert my_solution.maxSpending(**test_input) == 109\n\ntest_input = { \"values\": [[15,15,14,13,12,12,12,11,10,10,9,9,9,8,7,6,3,2]] }\nassert my_solution.maxSpending(**test_input) == 2006\n\ntest_input = { \"values\": [[15,14,12,11,10,10,7,6,2,1]] }\nassert my_solution.maxSpending(**test_input) == 610\n\ntest_input = { \"values\": [[15,13,12,11,8,6,5]] }\nassert my_solution.maxSpending(**test_input) == 328\n\ntest_input = { \"values\": [[15,15,12,10,9,7,7,6,6,5,4,2,1]] }\nassert my_solution.maxSpending(**test_input) == 896\n\ntest_input = { \"values\": [[15,15,12,12,10,10,9,7,6,4,4,4,1]] }\nassert my_solution.maxSpending(**test_input) == 969\n\ntest_input = { \"values\": [[15,14,14,13,8,7,7,4,3,3,2,1]] }\nassert my_solution.maxSpending(**test_input) == 792\n\ntest_input = { \"values\": [[15,15,14,14,14,13,10,8,6,6,5,5,3,3,2,2,1]] }\nassert my_solution.maxSpending(**test_input) == 1634\n\ntest_input = { \"values\": [[14,12,11,10,10,8,7,7,5,5,3,3,3]] }\nassert my_solution.maxSpending(**test_input) == 855\n\ntest_input = { \"values\": [[14,14,9,9,4,4,1],[12,12,9,8,7,6,3]] }\nassert my_solution.maxSpending(**test_input) == 1060\n\ntest_input = { \"values\": [[15,15,15,13,12,12,10,9,9,9,9,7,6,4,4,4,1]] }\nassert my_solution.maxSpending(**test_input) == 1727\n\ntest_input = { \"values\": [[9,4],[13,4],[13,9],[6,5],[8,2],[13,1]] }\nassert my_solution.maxSpending(**test_input) == 732\n\ntest_input = { \"values\": [[14,9,9,9,8,7,5],[15,14,10,8,5,3,1]] }\nassert my_solution.maxSpending(**test_input) == 1094\n\ntest_input = { \"values\": [[15,15,14,13,10,3,1]] }\nassert my_solution.maxSpending(**test_input) == 354\n\ntest_input = { \"values\": [[13,12],[13,12],[11,8],[14,3]] }\nassert my_solution.maxSpending(**test_input) == 441\n\ntest_input = { \"values\": [[13,12,11,10,7,5,5,1]] }\nassert my_solution.maxSpending(**test_input) == 358\n\ntest_input = { \"values\": [[15,10,9,8,8,7,7,5,4,3,1]] }\nassert my_solution.maxSpending(**test_input) == 582\n\ntest_input = { \"values\": [[10,10,6,4,1],[14,13,13,11,9],[14,11,7,4,3]] }\nassert my_solution.maxSpending(**test_input) == 1302\n\ntest_input = { \"values\": [[15,14,12,12,11,11,10,9,9,8,8,6,6,4,2,2,1]] }\nassert my_solution.maxSpending(**test_input) == 1596\n\ntest_input = { \"values\": [[12,5,4,3,3,2,1,1],[13,11,9,9,6,4,3,1]] }\nassert my_solution.maxSpending(**test_input) == 1019\n\ntest_input = { \"values\": [[15,15,13,11,10,10,7,1,1]] }\nassert my_solution.maxSpending(**test_input) == 526\n\ntest_input = { \"values\": [[14,12,10,4,3,1],[12,12,8,7,6,2],[15,13,8,5,4,1]] }\nassert my_solution.maxSpending(**test_input) == 1719\n\ntest_input = { \"values\": [[13,8,8,8,5,4,3],[15,13,9,8,7,3,2]] }\nassert my_solution.maxSpending(**test_input) == 1006\n\ntest_input = { \"values\": [[13,13,12,12,9]] }\nassert my_solution.maxSpending(**test_input) == 186\n\ntest_input = { \"values\": [[10,3],[11,9],[10,5],[8,7],[6,1]] }\nassert my_solution.maxSpending(**test_input) == 472\n\ntest_input = { \"values\": [[15,15,12,12,11,10,9,8,2,2,1,1,1]] }\nassert my_solution.maxSpending(**test_input) == 941\n\ntest_input = { \"values\": [[14,14,13,13,11,11,10,10,10,9,8,8,7,7,6,6,5,4,3]] }\nassert my_solution.maxSpending(**test_input) == 2023\n\ntest_input = { \"values\": [[11,10,9,7,6,5,3,1],[14,14,10,9,7,4,4,3]] }\nassert my_solution.maxSpending(**test_input) == 1270\n\ntest_input = { \"values\": [[6,2],[10,2],[13,5],[8,7],[10,3],[13,2],[13,6]] }\nassert my_solution.maxSpending(**test_input) == 972\n\ntest_input = { \"values\": [[15,15,15,14,13,12,6,5,5,4]] }\nassert my_solution.maxSpending(**test_input) == 694\n\ntest_input = { \"values\": [[11,9],[8,1],[2,1],[15,13],[12,4],[14,5],[13,4]] }\nassert my_solution.maxSpending(**test_input) == 1113\n\ntest_input = { \"values\": [[15,14,14,13,12,11,10,10,5,4,2]] }\nassert my_solution.maxSpending(**test_input) == 800\n\ntest_input = { \"values\": [[13,12,12,6,5,5,4,2,2,2,1]] }\nassert my_solution.maxSpending(**test_input) == 523\n\ntest_input = { \"values\": [[13,8],[15,1],[9,1],[13,1]] }\nassert my_solution.maxSpending(**test_input) == 372\n\ntest_input = { \"values\": [[12,8,4,1],[14,8,8,3]] }\nassert my_solution.maxSpending(**test_input) == 335\n\ntest_input = { \"values\": [[15,14,14,13,13,13,12,12,9,9,8,7,6,5,5,5,4,3,1]] }\nassert my_solution.maxSpending(**test_input) == 2113\n\ntest_input = { \"values\": [[13,9,8,2,1],[9,4,3,2,1],[10,8,6,3,1]] }\nassert my_solution.maxSpending(**test_input) == 877\n\ntest_input = { \"values\": [[8,6],[13,1],[12,8],[8,7]] }\nassert my_solution.maxSpending(**test_input) == 342\n\ntest_input = { \"values\": [[9,7],[15,15],[9,8],[6,1],[11,4]] }\nassert my_solution.maxSpending(**test_input) == 585\n\ntest_input = { \"values\": [[14,9,9,8,6,4,2]] }\nassert my_solution.maxSpending(**test_input) == 257\n\ntest_input = { \"values\": [[15,13,11,11,10,9,5,5,4,4,4,4,3,2]] }\nassert my_solution.maxSpending(**test_input) == 968\n\ntest_input = { \"values\": [[13,7,7,4],[8,8,6,6]] }\nassert my_solution.maxSpending(**test_input) == 305\n\ntest_input = { \"values\": [[15,13,12,10,10,10,9,9,9,8,7,6,6,5,4,4,2,1,1]] }\nassert my_solution.maxSpending(**test_input) == 1805\n\ntest_input = { \"values\": [[13,13,1],[11,5,4],[14,5,1],[15,5,2],[10,1,1],[15,12,1]] }\nassert my_solution.maxSpending(**test_input) == 1714\n\ntest_input = { \"values\": [[15,15,14,14,11,10,10,8,8,8,3,1,1]] }\nassert my_solution.maxSpending(**test_input) == 1050\n\ntest_input = { \"values\": [[3,3],[15,10],[14,9]] }\nassert my_solution.maxSpending(**test_input) == 236\n\ntest_input = { \"values\": [[14,13,11,10,9,7,2]] }\nassert my_solution.maxSpending(**test_input) == 314\n\ntest_input = { \"values\": [[11,7],[5,3],[11,6],[6,1],[15,13]] }\nassert my_solution.maxSpending(**test_input) == 550\n\ntest_input = { \"values\": [[14,13,13,12,12,12,11,11,9,8,8,6,5,5,5,5,3,3,2]] }\nassert my_solution.maxSpending(**test_input) == 1962\n\ntest_input = { \"values\": [[14,14,13,13,13,12,12,11,10,9,9,8,8,7,3,2,2]] }\nassert my_solution.maxSpending(**test_input) == 1750\n\ntest_input = { \"values\": [[15,8],[12,2],[15,10],[9,3],[5,4],[14,2],[7,6]] }\nassert my_solution.maxSpending(**test_input) == 1091\n\ntest_input = { \"values\": [[15,9,7,3,3],[7,6,4,3,2],[15,9,8,4,4],[15,10,9,7,4]] }\nassert my_solution.maxSpending(**test_input) == 1952\n\ntest_input = { \"values\": [[12,12,10,8,8,8,8,6,2,2,1]] }\nassert my_solution.maxSpending(**test_input) == 585", "start_time": 1699713000} +{"task_id": "weekly-contest-370-find-champion-i", "url": "https://leetcode.com/problems/find-champion-i", "title": "find-champion-i", "meta": {"questionId": "3188", "questionFrontendId": "2923", "title": "Find Champion I", "titleSlug": "find-champion-i", "isPaidOnly": false, "difficulty": "Easy", "likes": 84, "dislikes": 20, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nThere are n teams numbered from 0 to n - 1 in a tournament.\n\nGiven a 0-indexed 2D boolean matrix grid of size n * n. For all i, j that 0 <= i, j <= n - 1 and i != j team i is stronger than team j if grid[i][j] == 1, otherwise, team j is stronger than team i.\n\nTeam a will be the champion of the tournament if there is no team b that is stronger than team a.\n\nReturn the team that will be the champion of the tournament.\n\nExample 1:\n\nInput: grid = [[0,1],[0,0]]\nOutput: 0\nExplanation: There are two teams in this tournament.\ngrid[0][1] == 1 means that team 0 is stronger than team 1. So team 0 will be the champion.\n\nExample 2:\n\nInput: grid = [[0,0,1],[1,0,1],[0,0,0]]\nOutput: 1\nExplanation: There are three teams in this tournament.\ngrid[1][0] == 1 means that team 1 is stronger than team 0.\ngrid[1][2] == 1 means that team 1 is stronger than team 2.\nSo team 1 will be the champion.\n\n\nConstraints:\n\n * n == grid.length\n * n == grid[i].length\n * 2 <= n <= 100\n * grid[i][j] is either 0 or 1.\n * For all i grid[i][i] is 0.\n * For all i, j that i != j, grid[i][j] != grid[j][i].\n * The input is generated such that if team a is stronger than team b and team b is stronger than team c, then team a is stronger than team c.\n\"\"\"\nclass Solution:\n def findChampion(self, grid: List[List[int]]) -> int:\n ", "prompt_sft": "There are n teams numbered from 0 to n - 1 in a tournament.\n\nGiven a 0-indexed 2D boolean matrix grid of size n * n. For all i, j that 0 <= i, j <= n - 1 and i != j team i is stronger than team j if grid[i][j] == 1, otherwise, team j is stronger than team i.\n\nTeam a will be the champion of the tournament if there is no team b that is stronger than team a.\n\nReturn the team that will be the champion of the tournament.\n\nExample 1:\n\nInput: grid = [[0,1],[0,0]]\nOutput: 0\nExplanation: There are two teams in this tournament.\ngrid[0][1] == 1 means that team 0 is stronger than team 1. So team 0 will be the champion.\n\nExample 2:\n\nInput: grid = [[0,0,1],[1,0,1],[0,0,0]]\nOutput: 1\nExplanation: There are three teams in this tournament.\ngrid[1][0] == 1 means that team 1 is stronger than team 0.\ngrid[1][2] == 1 means that team 1 is stronger than team 2.\nSo team 1 will be the champion.\n\n\nConstraints:\n\n * n == grid.length\n * n == grid[i].length\n * 2 <= n <= 100\n * grid[i][j] is either 0 or 1.\n * For all i grid[i][i] is 0.\n * For all i, j that i != j, grid[i][j] != grid[j][i].\n * The input is generated such that if team a is stronger than team b and team b is stronger than team c, then team a is stronger than team c.\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def findChampion(self, grid: List[List[int]]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"grid\": [[0,1],[0,0]] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"grid\": [[0,0,1],[1,0,1],[0,0,0]] }\nassert my_solution.findChampion(**test_input) == 1\n\ntest_input = { \"grid\": [[0,0],[1,0]] }\nassert my_solution.findChampion(**test_input) == 1\n\ntest_input = { \"grid\": [[0,0,0],[1,0,0],[1,1,0]] }\nassert my_solution.findChampion(**test_input) == 2\n\ntest_input = { \"grid\": [[0,0,0],[1,0,1],[1,0,0]] }\nassert my_solution.findChampion(**test_input) == 1\n\ntest_input = { \"grid\": [[0,1,0],[0,0,0],[1,1,0]] }\nassert my_solution.findChampion(**test_input) == 2\n\ntest_input = { \"grid\": [[0,1,1],[0,0,0],[0,1,0]] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"grid\": [[0,1,1],[0,0,1],[0,0,0]] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"grid\": [[0,0,0,0],[1,0,0,0],[1,1,0,0],[1,1,1,0]] }\nassert my_solution.findChampion(**test_input) == 3\n\ntest_input = { \"grid\": [[0,0,0,0],[1,0,0,0],[1,1,0,1],[1,1,0,0]] }\nassert my_solution.findChampion(**test_input) == 2\n\ntest_input = { \"grid\": [[0,0,0,0],[1,0,0,1],[1,1,0,1],[1,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 2\n\ntest_input = { \"grid\": [[0,0,0,0],[1,0,1,0],[1,0,0,0],[1,1,1,0]] }\nassert my_solution.findChampion(**test_input) == 3\n\ntest_input = { \"grid\": [[0,0,0,0],[1,0,1,1],[1,0,0,0],[1,0,1,0]] }\nassert my_solution.findChampion(**test_input) == 1\n\ntest_input = { \"grid\": [[0,0,0,0],[1,0,1,1],[1,0,0,1],[1,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 1\n\ntest_input = { \"grid\": [[0,0,0,1],[1,0,0,1],[1,1,0,1],[0,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 2\n\ntest_input = { \"grid\": [[0,0,0,1],[1,0,1,1],[1,0,0,1],[0,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 1\n\ntest_input = { \"grid\": [[0,0,1,0],[1,0,1,0],[0,0,0,0],[1,1,1,0]] }\nassert my_solution.findChampion(**test_input) == 3\n\ntest_input = { \"grid\": [[0,0,1,0],[1,0,1,1],[0,0,0,0],[1,0,1,0]] }\nassert my_solution.findChampion(**test_input) == 1\n\ntest_input = { \"grid\": [[0,0,1,1],[1,0,1,1],[0,0,0,0],[0,0,1,0]] }\nassert my_solution.findChampion(**test_input) == 1\n\ntest_input = { \"grid\": [[0,0,1,1],[1,0,1,1],[0,0,0,1],[0,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 1\n\ntest_input = { \"grid\": [[0,1,0,0],[0,0,0,0],[1,1,0,0],[1,1,1,0]] }\nassert my_solution.findChampion(**test_input) == 3\n\ntest_input = { \"grid\": [[0,1,0,0],[0,0,0,0],[1,1,0,1],[1,1,0,0]] }\nassert my_solution.findChampion(**test_input) == 2\n\ntest_input = { \"grid\": [[0,1,0,1],[0,0,0,0],[1,1,0,1],[0,1,0,0]] }\nassert my_solution.findChampion(**test_input) == 2\n\ntest_input = { \"grid\": [[0,1,0,1],[0,0,0,1],[1,1,0,1],[0,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 2\n\ntest_input = { \"grid\": [[0,1,1,0],[0,0,0,0],[0,1,0,0],[1,1,1,0]] }\nassert my_solution.findChampion(**test_input) == 3\n\ntest_input = { \"grid\": [[0,1,1,0],[0,0,1,0],[0,0,0,0],[1,1,1,0]] }\nassert my_solution.findChampion(**test_input) == 3\n\ntest_input = { \"grid\": [[0,1,1,1],[0,0,0,0],[0,1,0,0],[0,1,1,0]] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"grid\": [[0,1,1,1],[0,0,0,0],[0,1,0,1],[0,1,0,0]] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"grid\": [[0,1,1,1],[0,0,0,1],[0,1,0,1],[0,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"grid\": [[0,1,1,1],[0,0,1,0],[0,0,0,0],[0,1,1,0]] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"grid\": [[0,1,1,1],[0,0,1,1],[0,0,0,0],[0,0,1,0]] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"grid\": [[0,1,1,1],[0,0,1,1],[0,0,0,1],[0,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"grid\": [[0,0,0,0,0],[1,0,0,0,0],[1,1,0,0,0],[1,1,1,0,1],[1,1,1,0,0]] }\nassert my_solution.findChampion(**test_input) == 3\n\ntest_input = { \"grid\": [[0,0,0,0,0],[1,0,0,0,0],[1,1,0,1,0],[1,1,0,0,0],[1,1,1,1,0]] }\nassert my_solution.findChampion(**test_input) == 4\n\ntest_input = { \"grid\": [[0,0,0,0,0],[1,0,0,0,0],[1,1,0,1,1],[1,1,0,0,0],[1,1,0,1,0]] }\nassert my_solution.findChampion(**test_input) == 2\n\ntest_input = { \"grid\": [[0,0,0,0,0],[1,0,0,0,0],[1,1,0,1,1],[1,1,0,0,1],[1,1,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 2\n\ntest_input = { \"grid\": [[0,0,0,0,0],[1,0,0,0,1],[1,1,0,0,1],[1,1,1,0,1],[1,0,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 3\n\ntest_input = { \"grid\": [[0,0,0,0,0],[1,0,0,0,1],[1,1,0,1,1],[1,1,0,0,1],[1,0,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 2\n\ntest_input = { \"grid\": [[0,0,0,0,0],[1,0,0,1,0],[1,1,0,1,0],[1,0,0,0,0],[1,1,1,1,0]] }\nassert my_solution.findChampion(**test_input) == 4\n\ntest_input = { \"grid\": [[0,0,0,0,0],[1,0,0,1,0],[1,1,0,1,1],[1,0,0,0,0],[1,1,0,1,0]] }\nassert my_solution.findChampion(**test_input) == 2\n\ntest_input = { \"grid\": [[0,0,0,0,0],[1,0,0,1,1],[1,1,0,1,1],[1,0,0,0,1],[1,0,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 2\n\ntest_input = { \"grid\": [[0,0,0,0,0],[1,0,1,0,1],[1,0,0,0,0],[1,1,1,0,1],[1,0,1,0,0]] }\nassert my_solution.findChampion(**test_input) == 3\n\ntest_input = { \"grid\": [[0,0,0,0,0],[1,0,1,1,0],[1,0,0,0,0],[1,0,1,0,0],[1,1,1,1,0]] }\nassert my_solution.findChampion(**test_input) == 4\n\ntest_input = { \"grid\": [[0,0,0,0,0],[1,0,1,1,0],[1,0,0,1,0],[1,0,0,0,0],[1,1,1,1,0]] }\nassert my_solution.findChampion(**test_input) == 4\n\ntest_input = { \"grid\": [[0,0,0,0,0],[1,0,1,1,1],[1,0,0,0,0],[1,0,1,0,1],[1,0,1,0,0]] }\nassert my_solution.findChampion(**test_input) == 1\n\ntest_input = { \"grid\": [[0,0,0,0,0],[1,0,1,1,1],[1,0,0,0,1],[1,0,1,0,1],[1,0,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 1\n\ntest_input = { \"grid\": [[0,0,0,0,0],[1,0,1,1,1],[1,0,0,1,1],[1,0,0,0,1],[1,0,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 1\n\ntest_input = { \"grid\": [[0,0,0,0,1],[1,0,0,0,1],[1,1,0,0,1],[1,1,1,0,1],[0,0,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 3\n\ntest_input = { \"grid\": [[0,0,0,0,1],[1,0,0,0,1],[1,1,0,1,1],[1,1,0,0,1],[0,0,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 2\n\ntest_input = { \"grid\": [[0,0,0,0,1],[1,0,0,1,1],[1,1,0,1,1],[1,0,0,0,1],[0,0,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 2\n\ntest_input = { \"grid\": [[0,0,0,0,1],[1,0,1,1,1],[1,0,0,0,1],[1,0,1,0,1],[0,0,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 1\n\ntest_input = { \"grid\": [[0,0,0,1,0],[1,0,0,1,0],[1,1,0,1,0],[0,0,0,0,0],[1,1,1,1,0]] }\nassert my_solution.findChampion(**test_input) == 4\n\ntest_input = { \"grid\": [[0,0,0,1,0],[1,0,0,1,0],[1,1,0,1,1],[0,0,0,0,0],[1,1,0,1,0]] }\nassert my_solution.findChampion(**test_input) == 2\n\ntest_input = { \"grid\": [[0,0,0,1,0],[1,0,0,1,1],[1,1,0,1,1],[0,0,0,0,0],[1,0,0,1,0]] }\nassert my_solution.findChampion(**test_input) == 2\n\ntest_input = { \"grid\": [[0,0,0,1,0],[1,0,1,1,0],[1,0,0,1,0],[0,0,0,0,0],[1,1,1,1,0]] }\nassert my_solution.findChampion(**test_input) == 4\n\ntest_input = { \"grid\": [[0,0,0,1,0],[1,0,1,1,1],[1,0,0,1,0],[0,0,0,0,0],[1,0,1,1,0]] }\nassert my_solution.findChampion(**test_input) == 1\n\ntest_input = { \"grid\": [[0,0,0,1,0],[1,0,1,1,1],[1,0,0,1,1],[0,0,0,0,0],[1,0,0,1,0]] }\nassert my_solution.findChampion(**test_input) == 1\n\ntest_input = { \"grid\": [[0,0,0,1,1],[1,0,0,1,1],[1,1,0,1,1],[0,0,0,0,0],[0,0,0,1,0]] }\nassert my_solution.findChampion(**test_input) == 2\n\ntest_input = { \"grid\": [[0,0,0,1,1],[1,0,0,1,1],[1,1,0,1,1],[0,0,0,0,1],[0,0,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 2\n\ntest_input = { \"grid\": [[0,0,0,1,1],[1,0,1,1,1],[1,0,0,1,1],[0,0,0,0,0],[0,0,0,1,0]] }\nassert my_solution.findChampion(**test_input) == 1\n\ntest_input = { \"grid\": [[0,0,0,1,1],[1,0,1,1,1],[1,0,0,1,1],[0,0,0,0,1],[0,0,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 1\n\ntest_input = { \"grid\": [[0,0,1,0,0],[1,0,1,0,0],[0,0,0,0,0],[1,1,1,0,0],[1,1,1,1,0]] }\nassert my_solution.findChampion(**test_input) == 4\n\ntest_input = { \"grid\": [[0,0,1,0,0],[1,0,1,1,0],[0,0,0,0,0],[1,0,1,0,0],[1,1,1,1,0]] }\nassert my_solution.findChampion(**test_input) == 4\n\ntest_input = { \"grid\": [[0,0,1,0,0],[1,0,1,1,1],[0,0,0,0,0],[1,0,1,0,1],[1,0,1,0,0]] }\nassert my_solution.findChampion(**test_input) == 1\n\ntest_input = { \"grid\": [[0,0,1,0,1],[1,0,1,0,1],[0,0,0,0,1],[1,1,1,0,1],[0,0,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 3\n\ntest_input = { \"grid\": [[0,0,1,1,0],[1,0,1,1,0],[0,0,0,1,0],[0,0,0,0,0],[1,1,1,1,0]] }\nassert my_solution.findChampion(**test_input) == 4\n\ntest_input = { \"grid\": [[0,0,1,1,0],[1,0,1,1,1],[0,0,0,0,0],[0,0,1,0,0],[1,0,1,1,0]] }\nassert my_solution.findChampion(**test_input) == 1\n\ntest_input = { \"grid\": [[0,0,1,1,1],[1,0,1,1,1],[0,0,0,1,0],[0,0,0,0,0],[0,0,1,1,0]] }\nassert my_solution.findChampion(**test_input) == 1\n\ntest_input = { \"grid\": [[0,0,1,1,1],[1,0,1,1,1],[0,0,0,1,1],[0,0,0,0,1],[0,0,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 1\n\ntest_input = { \"grid\": [[0,1,0,0,0],[0,0,0,0,0],[1,1,0,0,0],[1,1,1,0,1],[1,1,1,0,0]] }\nassert my_solution.findChampion(**test_input) == 3\n\ntest_input = { \"grid\": [[0,1,0,0,0],[0,0,0,0,0],[1,1,0,1,1],[1,1,0,0,0],[1,1,0,1,0]] }\nassert my_solution.findChampion(**test_input) == 2\n\ntest_input = { \"grid\": [[0,1,0,0,1],[0,0,0,0,0],[1,1,0,0,1],[1,1,1,0,1],[0,1,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 3\n\ntest_input = { \"grid\": [[0,1,0,0,1],[0,0,0,0,0],[1,1,0,1,1],[1,1,0,0,1],[0,1,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 2\n\ntest_input = { \"grid\": [[0,1,0,1,0],[0,0,0,0,0],[1,1,0,1,0],[0,1,0,0,0],[1,1,1,1,0]] }\nassert my_solution.findChampion(**test_input) == 4\n\ntest_input = { \"grid\": [[0,1,0,1,0],[0,0,0,0,0],[1,1,0,1,1],[0,1,0,0,0],[1,1,0,1,0]] }\nassert my_solution.findChampion(**test_input) == 2\n\ntest_input = { \"grid\": [[0,1,0,1,0],[0,0,0,1,0],[1,1,0,1,0],[0,0,0,0,0],[1,1,1,1,0]] }\nassert my_solution.findChampion(**test_input) == 4\n\ntest_input = { \"grid\": [[0,1,0,1,0],[0,0,0,1,0],[1,1,0,1,1],[0,0,0,0,0],[1,1,0,1,0]] }\nassert my_solution.findChampion(**test_input) == 2\n\ntest_input = { \"grid\": [[0,1,0,1,1],[0,0,0,0,0],[1,1,0,1,1],[0,1,0,0,1],[0,1,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 2\n\ntest_input = { \"grid\": [[0,1,0,1,1],[0,0,0,1,1],[1,1,0,1,1],[0,0,0,0,0],[0,0,0,1,0]] }\nassert my_solution.findChampion(**test_input) == 2\n\ntest_input = { \"grid\": [[0,1,1,0,0],[0,0,0,0,0],[0,1,0,0,0],[1,1,1,0,0],[1,1,1,1,0]] }\nassert my_solution.findChampion(**test_input) == 4\n\ntest_input = { \"grid\": [[0,1,1,0,0],[0,0,1,0,0],[0,0,0,0,0],[1,1,1,0,1],[1,1,1,0,0]] }\nassert my_solution.findChampion(**test_input) == 3\n\ntest_input = { \"grid\": [[0,1,1,0,1],[0,0,0,0,0],[0,1,0,0,1],[1,1,1,0,1],[0,1,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 3\n\ntest_input = { \"grid\": [[0,1,1,0,1],[0,0,0,0,1],[0,1,0,0,1],[1,1,1,0,1],[0,0,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 3\n\ntest_input = { \"grid\": [[0,1,1,0,1],[0,0,1,0,0],[0,0,0,0,0],[1,1,1,0,1],[0,1,1,0,0]] }\nassert my_solution.findChampion(**test_input) == 3\n\ntest_input = { \"grid\": [[0,1,1,0,1],[0,0,1,0,1],[0,0,0,0,0],[1,1,1,0,1],[0,0,1,0,0]] }\nassert my_solution.findChampion(**test_input) == 3\n\ntest_input = { \"grid\": [[0,1,1,0,1],[0,0,1,0,1],[0,0,0,0,1],[1,1,1,0,1],[0,0,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 3\n\ntest_input = { \"grid\": [[0,1,1,1,0],[0,0,0,1,0],[0,1,0,1,0],[0,0,0,0,0],[1,1,1,1,0]] }\nassert my_solution.findChampion(**test_input) == 4\n\ntest_input = { \"grid\": [[0,1,1,1,0],[0,0,1,0,0],[0,0,0,0,0],[0,1,1,0,0],[1,1,1,1,0]] }\nassert my_solution.findChampion(**test_input) == 4\n\ntest_input = { \"grid\": [[0,1,1,1,0],[0,0,1,1,0],[0,0,0,0,0],[0,0,1,0,0],[1,1,1,1,0]] }\nassert my_solution.findChampion(**test_input) == 4\n\ntest_input = { \"grid\": [[0,1,1,1,1],[0,0,0,0,0],[0,1,0,0,0],[0,1,1,0,0],[0,1,1,1,0]] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"grid\": [[0,1,1,1,1],[0,0,0,0,0],[0,1,0,0,0],[0,1,1,0,1],[0,1,1,0,0]] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"grid\": [[0,1,1,1,1],[0,0,0,0,0],[0,1,0,0,1],[0,1,1,0,1],[0,1,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"grid\": [[0,1,1,1,1],[0,0,0,0,0],[0,1,0,1,0],[0,1,0,0,0],[0,1,1,1,0]] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"grid\": [[0,1,1,1,1],[0,0,0,0,0],[0,1,0,1,1],[0,1,0,0,0],[0,1,0,1,0]] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"grid\": [[0,1,1,1,1],[0,0,0,0,0],[0,1,0,1,1],[0,1,0,0,1],[0,1,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"grid\": [[0,1,1,1,1],[0,0,0,0,1],[0,1,0,0,1],[0,1,1,0,1],[0,0,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"grid\": [[0,1,1,1,1],[0,0,1,0,0],[0,0,0,0,0],[0,1,1,0,0],[0,1,1,1,0]] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"grid\": [[0,1,1,1,1],[0,0,1,0,0],[0,0,0,0,0],[0,1,1,0,1],[0,1,1,0,0]] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"grid\": [[0,1,1,1,1],[0,0,1,0,1],[0,0,0,0,1],[0,1,1,0,1],[0,0,0,0,0]] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"grid\": [[0,1,1,1,1],[0,0,1,1,0],[0,0,0,0,0],[0,0,1,0,0],[0,1,1,1,0]] }\nassert my_solution.findChampion(**test_input) == 0", "start_time": 1699151400} +{"task_id": "weekly-contest-370-find-champion-ii", "url": "https://leetcode.com/problems/find-champion-ii", "title": "find-champion-ii", "meta": {"questionId": "3189", "questionFrontendId": "2924", "title": "Find Champion II", "titleSlug": "find-champion-ii", "isPaidOnly": false, "difficulty": "Medium", "likes": 92, "dislikes": 7, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nThere are n teams numbered from 0 to n - 1 in a tournament; each team is also a node in a DAG.\n\nYou are given the integer n and a 0-indexed 2D integer array edges of length m representing the DAG, where edges[i] = [ui, vi] indicates that there is a directed edge from team ui to team vi in the graph.\n\nA directed edge from a to b in the graph means that team a is stronger than team b and team b is weaker than team a.\n\nTeam a will be the champion of the tournament if there is no team b that is stronger than team a.\n\nReturn the team that will be the champion of the tournament if there is a unique champion, otherwise, return -1.\n\nNotes\n\n * A cycle is a series of nodes a1, a2, ..., an, an+1 such that node a1 is the same node as node an+1, the nodes a1, a2, ..., an are distinct, and there is a directed edge from the node ai to node ai+1 for every i in the range [1, n].\n * A DAG is a directed graph that does not have any cycle.\n\nExample 1:\n\n[https://assets.leetcode.com/uploads/2023/10/19/graph-3.png]\n\nInput: n = 3, edges = [[0,1],[1,2]]\nOutput: 0\nExplanation: Team 1 is weaker than team 0. Team 2 is weaker than team 1. So the champion is team 0.\n\nExample 2:\n\n[https://assets.leetcode.com/uploads/2023/10/19/graph-4.png]\n\nInput: n = 4, edges = [[0,2],[1,3],[1,2]]\nOutput: -1\nExplanation: Team 2 is weaker than team 0 and team 1. Team 3 is weaker than team 1. But team 1 and team 0 are not weaker than any other teams. So the answer is -1.\n\n\nConstraints:\n\n * 1 <= n <= 100\n * m == edges.length\n * 0 <= m <= n * (n - 1) / 2\n * edges[i].length == 2\n * 0 <= edge[i][j] <= n - 1\n * edges[i][0] != edges[i][1]\n * The input is generated such that if team a is stronger than team b, team b is not stronger than team a.\n * The input is generated such that if team a is stronger than team b and team b is stronger than team c, then team a is stronger than team c.\n\"\"\"\nclass Solution:\n def findChampion(self, n: int, edges: List[List[int]]) -> int:\n ", "prompt_sft": "There are n teams numbered from 0 to n - 1 in a tournament; each team is also a node in a DAG.\n\nYou are given the integer n and a 0-indexed 2D integer array edges of length m representing the DAG, where edges[i] = [ui, vi] indicates that there is a directed edge from team ui to team vi in the graph.\n\nA directed edge from a to b in the graph means that team a is stronger than team b and team b is weaker than team a.\n\nTeam a will be the champion of the tournament if there is no team b that is stronger than team a.\n\nReturn the team that will be the champion of the tournament if there is a unique champion, otherwise, return -1.\n\nNotes\n\n * A cycle is a series of nodes a1, a2, ..., an, an+1 such that node a1 is the same node as node an+1, the nodes a1, a2, ..., an are distinct, and there is a directed edge from the node ai to node ai+1 for every i in the range [1, n].\n * A DAG is a directed graph that does not have any cycle.\n\nExample 1:\n\n[https://assets.leetcode.com/uploads/2023/10/19/graph-3.png]\n\nInput: n = 3, edges = [[0,1],[1,2]]\nOutput: 0\nExplanation: Team 1 is weaker than team 0. Team 2 is weaker than team 1. So the champion is team 0.\n\nExample 2:\n\n[https://assets.leetcode.com/uploads/2023/10/19/graph-4.png]\n\nInput: n = 4, edges = [[0,2],[1,3],[1,2]]\nOutput: -1\nExplanation: Team 2 is weaker than team 0 and team 1. Team 3 is weaker than team 1. But team 1 and team 0 are not weaker than any other teams. So the answer is -1.\n\n\nConstraints:\n\n * 1 <= n <= 100\n * m == edges.length\n * 0 <= m <= n * (n - 1) / 2\n * edges[i].length == 2\n * 0 <= edge[i][j] <= n - 1\n * edges[i][0] != edges[i][1]\n * The input is generated such that if team a is stronger than team b, team b is not stronger than team a.\n * The input is generated such that if team a is stronger than team b and team b is stronger than team c, then team a is stronger than team c.\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def findChampion(self, n: int, edges: List[List[int]]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"n\": 3, \"edges\": [[0,1],[1,2]] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"n\": 4, \"edges\": [[0,2],[1,3],[1,2]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 1, \"edges\": [] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"n\": 2, \"edges\": [] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 2, \"edges\": [[0,1]] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"n\": 2, \"edges\": [[1,0]] }\nassert my_solution.findChampion(**test_input) == 1\n\ntest_input = { \"n\": 3, \"edges\": [] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 3, \"edges\": [[0,1]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 3, \"edges\": [[0,2]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 3, \"edges\": [[1,2]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 3, \"edges\": [[2,0]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 3, \"edges\": [[0,1],[2,1]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 3, \"edges\": [[0,2],[0,1]] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"n\": 3, \"edges\": [[0,2],[1,0]] }\nassert my_solution.findChampion(**test_input) == 1\n\ntest_input = { \"n\": 3, \"edges\": [[2,0],[1,0]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 3, \"edges\": [[2,0],[2,1]] }\nassert my_solution.findChampion(**test_input) == 2\n\ntest_input = { \"n\": 3, \"edges\": [[2,1],[2,0]] }\nassert my_solution.findChampion(**test_input) == 2\n\ntest_input = { \"n\": 3, \"edges\": [[0,1],[1,2],[0,2]] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"n\": 3, \"edges\": [[0,1],[2,1],[0,2]] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"n\": 3, \"edges\": [[0,2],[0,1],[1,2]] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"n\": 3, \"edges\": [[0,2],[0,1],[2,1]] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"n\": 3, \"edges\": [[0,2],[1,2],[1,0]] }\nassert my_solution.findChampion(**test_input) == 1\n\ntest_input = { \"n\": 3, \"edges\": [[1,0],[0,2],[1,2]] }\nassert my_solution.findChampion(**test_input) == 1\n\ntest_input = { \"n\": 3, \"edges\": [[2,1],[1,0],[2,0]] }\nassert my_solution.findChampion(**test_input) == 2\n\ntest_input = { \"n\": 4, \"edges\": [] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 4, \"edges\": [[0,2]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 4, \"edges\": [[1,0]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 4, \"edges\": [[1,3]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 4, \"edges\": [[3,2]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 4, \"edges\": [[0,1],[2,3]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 4, \"edges\": [[0,3],[2,3]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 4, \"edges\": [[1,3],[2,1]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 4, \"edges\": [[2,1],[1,3]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 4, \"edges\": [[3,0],[3,1]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 4, \"edges\": [[0,1],[2,0],[2,1]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 4, \"edges\": [[0,2],[3,2],[1,2]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 4, \"edges\": [[1,0],[2,3],[1,2]] }\nassert my_solution.findChampion(**test_input) == 1\n\ntest_input = { \"n\": 4, \"edges\": [[1,2],[0,3],[1,3]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 4, \"edges\": [[1,2],[1,0],[1,3]] }\nassert my_solution.findChampion(**test_input) == 1\n\ntest_input = { \"n\": 4, \"edges\": [[1,3],[1,2],[0,3]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 4, \"edges\": [[1,3],[3,0],[2,0]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 4, \"edges\": [[3,1],[2,0],[1,2]] }\nassert my_solution.findChampion(**test_input) == 3\n\ntest_input = { \"n\": 4, \"edges\": [[3,1],[2,1],[0,2]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 4, \"edges\": [[0,2],[0,3],[1,2],[1,0]] }\nassert my_solution.findChampion(**test_input) == 1\n\ntest_input = { \"n\": 4, \"edges\": [[2,0],[2,3],[3,1],[2,1]] }\nassert my_solution.findChampion(**test_input) == 2\n\ntest_input = { \"n\": 4, \"edges\": [[2,1],[1,0],[3,0],[2,0]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 4, \"edges\": [[3,0],[3,1],[2,1],[0,1]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 4, \"edges\": [[3,0],[1,0],[1,2],[3,2],[2,0]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 4, \"edges\": [[3,0],[2,0],[1,0],[2,3],[1,2]] }\nassert my_solution.findChampion(**test_input) == 1\n\ntest_input = { \"n\": 4, \"edges\": [[3,2],[0,1],[3,0],[3,1],[2,0]] }\nassert my_solution.findChampion(**test_input) == 3\n\ntest_input = { \"n\": 4, \"edges\": [[0,3],[2,3],[2,1],[1,0],[2,0],[1,3]] }\nassert my_solution.findChampion(**test_input) == 2\n\ntest_input = { \"n\": 4, \"edges\": [[1,2],[2,3],[0,2],[0,1],[0,3],[1,3]] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"n\": 4, \"edges\": [[2,1],[3,1],[3,0],[3,2],[2,0],[0,1]] }\nassert my_solution.findChampion(**test_input) == 3\n\ntest_input = { \"n\": 4, \"edges\": [[2,3],[2,1],[0,1],[0,3],[3,1],[0,2]] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"n\": 5, \"edges\": [] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 5, \"edges\": [[0,2]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 5, \"edges\": [[2,0]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 5, \"edges\": [[4,0]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 5, \"edges\": [[1,4],[2,0]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 5, \"edges\": [[2,0],[4,3]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 5, \"edges\": [[3,2],[0,2]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 5, \"edges\": [[3,4],[2,1]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 5, \"edges\": [[0,4],[1,4],[0,1]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 5, \"edges\": [[1,3],[4,2],[1,0]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 5, \"edges\": [[2,3],[4,1],[3,0]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 5, \"edges\": [[0,4],[2,0],[1,3],[2,4]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 5, \"edges\": [[0,1],[2,1],[4,1],[4,2],[4,0]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 5, \"edges\": [[0,2],[2,1],[3,2],[4,1],[0,4]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 5, \"edges\": [[2,3],[0,4],[1,4],[1,0],[4,3]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 5, \"edges\": [[3,1],[0,2],[4,2],[0,1],[1,2]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 5, \"edges\": [[3,2],[3,4],[3,0],[3,1],[0,2]] }\nassert my_solution.findChampion(**test_input) == 3\n\ntest_input = { \"n\": 5, \"edges\": [[4,0],[3,0],[2,4],[3,4],[4,1]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 5, \"edges\": [[4,3],[1,0],[1,2],[3,2],[4,1]] }\nassert my_solution.findChampion(**test_input) == 4\n\ntest_input = { \"n\": 5, \"edges\": [[2,1],[0,3],[0,1],[0,4],[0,2],[4,1]] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"n\": 5, \"edges\": [[2,1],[4,1],[3,0],[2,0],[3,4],[3,2]] }\nassert my_solution.findChampion(**test_input) == 3\n\ntest_input = { \"n\": 5, \"edges\": [[0,1],[0,4],[2,0],[3,4],[3,1],[2,1],[3,0]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 5, \"edges\": [[1,4],[3,1],[0,1],[3,0],[0,2],[2,4],[3,4]] }\nassert my_solution.findChampion(**test_input) == 3\n\ntest_input = { \"n\": 5, \"edges\": [[3,2],[1,2],[2,0],[2,4],[1,4],[3,1],[3,4]] }\nassert my_solution.findChampion(**test_input) == 3\n\ntest_input = { \"n\": 5, \"edges\": [[0,4],[0,3],[4,3],[4,2],[1,2],[4,1],[0,1],[3,2]] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"n\": 5, \"edges\": [[4,3],[4,2],[4,1],[2,3],[4,0],[3,1],[2,0],[0,3]] }\nassert my_solution.findChampion(**test_input) == 4\n\ntest_input = { \"n\": 5, \"edges\": [[1,2],[1,4],[2,3],[0,2],[1,0],[1,3],[0,3],[4,3],[0,4]] }\nassert my_solution.findChampion(**test_input) == 1\n\ntest_input = { \"n\": 5, \"edges\": [[1,3],[3,0],[3,4],[2,0],[3,2],[0,4],[2,4],[1,0],[1,2]] }\nassert my_solution.findChampion(**test_input) == 1\n\ntest_input = { \"n\": 5, \"edges\": [[3,0],[4,0],[3,2],[0,1],[0,2],[4,3],[1,2],[4,2],[3,1]] }\nassert my_solution.findChampion(**test_input) == 4\n\ntest_input = { \"n\": 5, \"edges\": [[4,0],[2,3],[4,3],[4,2],[2,0],[4,1],[1,3],[1,0],[3,0]] }\nassert my_solution.findChampion(**test_input) == 4\n\ntest_input = { \"n\": 5, \"edges\": [[0,2],[1,3],[4,1],[4,2],[2,1],[0,3],[0,1],[2,3],[0,4],[4,3]] }\nassert my_solution.findChampion(**test_input) == 0\n\ntest_input = { \"n\": 5, \"edges\": [[2,0],[4,0],[3,4],[4,2],[1,2],[1,0],[3,1],[3,0],[1,4],[3,2]] }\nassert my_solution.findChampion(**test_input) == 3\n\ntest_input = { \"n\": 6, \"edges\": [] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 6, \"edges\": [[2,1]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 6, \"edges\": [[2,3]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 6, \"edges\": [[3,5]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 6, \"edges\": [[5,4]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 6, \"edges\": [[1,2],[4,3]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 6, \"edges\": [[0,4],[4,5],[3,1]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 6, \"edges\": [[0,4],[5,2],[5,4],[3,0],[1,0]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 6, \"edges\": [[1,0],[1,4],[0,2],[3,5],[3,4]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 6, \"edges\": [[5,0],[2,4],[0,4],[3,2],[2,0]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 6, \"edges\": [[1,2],[3,2],[3,5],[4,0],[1,5],[0,5]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 6, \"edges\": [[3,2],[1,2],[3,0],[5,0],[5,1],[5,3]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 6, \"edges\": [[4,2],[0,4],[1,3],[3,4],[1,2],[1,0]] }\nassert my_solution.findChampion(**test_input) == -1\n\ntest_input = { \"n\": 6, \"edges\": [[0,5],[2,0],[1,5],[3,2],[2,1],[2,4],[4,5]] }\nassert my_solution.findChampion(**test_input) == 3", "start_time": 1699151400} +{"task_id": "weekly-contest-370-maximum-score-after-applying-operations-on-a-tree", "url": "https://leetcode.com/problems/maximum-score-after-applying-operations-on-a-tree", "title": "maximum-score-after-applying-operations-on-a-tree", "meta": {"questionId": "3191", "questionFrontendId": "2925", "title": "Maximum Score After Applying Operations on a Tree", "titleSlug": "maximum-score-after-applying-operations-on-a-tree", "isPaidOnly": false, "difficulty": "Medium", "likes": 243, "dislikes": 45, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nThere is an undirected tree with n nodes labeled from 0 to n - 1, and rooted at node 0. You are given a 2D integer array edges of length n - 1, where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree.\n\nYou are also given a 0-indexed integer array values of length n, where values[i] is the value associated with the ith node.\n\nYou start with a score of 0. In one operation, you can:\n\n * Pick any node i.\n * Add values[i] to your score.\n * Set values[i] to 0.\n\nA tree is healthy if the sum of values on the path from the root to any leaf node is different than zero.\n\nReturn the maximum score you can obtain after performing these operations on the tree any number of times so that it remains healthy.\n\nExample 1:\n\n[https://assets.leetcode.com/uploads/2023/10/11/graph-13-1.png]\n\nInput: edges = [[0,1],[0,2],[0,3],[2,4],[4,5]], values = [5,2,5,2,1,1]\nOutput: 11\nExplanation: We can choose nodes 1, 2, 3, 4, and 5. The value of the root is non-zero. Hence, the sum of values on the path from the root to any leaf is different than zero. Therefore, the tree is healthy and the score is values[1] + values[2] + values[3] + values[4] + values[5] = 11.\nIt can be shown that 11 is the maximum score obtainable after any number of operations on the tree.\n\nExample 2:\n\n[https://assets.leetcode.com/uploads/2023/10/11/graph-14-2.png]\n\nInput: edges = [[0,1],[0,2],[1,3],[1,4],[2,5],[2,6]], values = [20,10,9,7,4,3,5]\nOutput: 40\nExplanation: We can choose nodes 0, 2, 3, and 4.\n- The sum of values on the path from 0 to 4 is equal to 10.\n- The sum of values on the path from 0 to 3 is equal to 10.\n- The sum of values on the path from 0 to 5 is equal to 3.\n- The sum of values on the path from 0 to 6 is equal to 5.\nTherefore, the tree is healthy and the score is values[0] + values[2] + values[3] + values[4] = 40.\nIt can be shown that 40 is the maximum score obtainable after any number of operations on the tree.\n\n\nConstraints:\n\n * 2 <= n <= 2 * 104\n * edges.length == n - 1\n * edges[i].length == 2\n * 0 <= ai, bi < n\n * values.length == n\n * 1 <= values[i] <= 109\n * The input is generated such that edges represents a valid tree.\n\"\"\"\nclass Solution:\n def maximumScoreAfterOperations(self, edges: List[List[int]], values: List[int]) -> int:\n ", "prompt_sft": "There is an undirected tree with n nodes labeled from 0 to n - 1, and rooted at node 0. You are given a 2D integer array edges of length n - 1, where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree.\n\nYou are also given a 0-indexed integer array values of length n, where values[i] is the value associated with the ith node.\n\nYou start with a score of 0. In one operation, you can:\n\n * Pick any node i.\n * Add values[i] to your score.\n * Set values[i] to 0.\n\nA tree is healthy if the sum of values on the path from the root to any leaf node is different than zero.\n\nReturn the maximum score you can obtain after performing these operations on the tree any number of times so that it remains healthy.\n\nExample 1:\n\n[https://assets.leetcode.com/uploads/2023/10/11/graph-13-1.png]\n\nInput: edges = [[0,1],[0,2],[0,3],[2,4],[4,5]], values = [5,2,5,2,1,1]\nOutput: 11\nExplanation: We can choose nodes 1, 2, 3, 4, and 5. The value of the root is non-zero. Hence, the sum of values on the path from the root to any leaf is different than zero. Therefore, the tree is healthy and the score is values[1] + values[2] + values[3] + values[4] + values[5] = 11.\nIt can be shown that 11 is the maximum score obtainable after any number of operations on the tree.\n\nExample 2:\n\n[https://assets.leetcode.com/uploads/2023/10/11/graph-14-2.png]\n\nInput: edges = [[0,1],[0,2],[1,3],[1,4],[2,5],[2,6]], values = [20,10,9,7,4,3,5]\nOutput: 40\nExplanation: We can choose nodes 0, 2, 3, and 4.\n- The sum of values on the path from 0 to 4 is equal to 10.\n- The sum of values on the path from 0 to 3 is equal to 10.\n- The sum of values on the path from 0 to 5 is equal to 3.\n- The sum of values on the path from 0 to 6 is equal to 5.\nTherefore, the tree is healthy and the score is values[0] + values[2] + values[3] + values[4] = 40.\nIt can be shown that 40 is the maximum score obtainable after any number of operations on the tree.\n\n\nConstraints:\n\n * 2 <= n <= 2 * 104\n * edges.length == n - 1\n * edges[i].length == 2\n * 0 <= ai, bi < n\n * values.length == n\n * 1 <= values[i] <= 109\n * The input is generated such that edges represents a valid tree.\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def maximumScoreAfterOperations(self, edges: List[List[int]], values: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"edges\": [[0,1],[0,2],[0,3],[2,4],[4,5]], \"values\": [5,2,5,2,1,1] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 11\n\ntest_input = { \"edges\": [[0,1],[0,2],[1,3],[1,4],[2,5],[2,6]], \"values\": [20,10,9,7,4,3,5] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 40\n\ntest_input = { \"edges\": [[0,1]], \"values\": [1,2] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 2\n\ntest_input = { \"edges\": [[0,1]], \"values\": [2,1] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 2\n\ntest_input = { \"edges\": [[0,1],[0,2]], \"values\": [1000000000,1000000000,1000000000] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 2000000000\n\ntest_input = { \"edges\": [[0,1],[0,2],[0,3]], \"values\": [1000000000,1000000000,1000000000,1000000000] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 3000000000\n\ntest_input = { \"edges\": [[7,0],[3,1],[6,2],[4,3],[4,5],[4,6],[4,7]], \"values\": [2,16,23,17,22,21,8,6] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 113\n\ntest_input = { \"edges\": [[3,1],[0,2],[0,3]], \"values\": [21,12,19,5] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 36\n\ntest_input = { \"edges\": [[2,0],[4,1],[5,3],[4,6],[2,4],[5,2],[5,7]], \"values\": [12,12,7,9,2,11,12,25] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 83\n\ntest_input = { \"edges\": [[1,0],[9,1],[6,2],[7,4],[3,5],[7,3],[9,6],[7,8],[7,9]], \"values\": [14,17,13,18,17,10,23,19,22,2] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 153\n\ntest_input = { \"edges\": [[5,0],[4,3],[2,5],[6,2],[4,6],[1,4],[1,7]], \"values\": [15,12,13,23,8,1,2,23] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 96\n\ntest_input = { \"edges\": [[0,2],[1,3],[0,5],[1,0],[4,1],[4,6]], \"values\": [22,25,4,21,8,20,4] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 82\n\ntest_input = { \"edges\": [[4,1],[6,3],[2,4],[0,2],[9,5],[0,6],[9,7],[0,8],[0,9]], \"values\": [3,18,10,16,9,3,25,17,8,9] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 115\n\ntest_input = { \"edges\": [[6,1],[3,4],[0,3],[2,0],[5,2],[5,6]], \"values\": [25,20,16,2,13,8,19] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 93\n\ntest_input = { \"edges\": [[9,2],[5,4],[5,6],[1,5],[8,1],[0,7],[3,0],[9,3],[8,9]], \"values\": [21,13,10,14,20,11,19,22,3,16] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 128\n\ntest_input = { \"edges\": [[2,4],[1,5],[0,1],[2,0],[3,2],[3,6]], \"values\": [17,5,24,18,6,16,1] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 75\n\ntest_input = { \"edges\": [[1,2],[4,1],[3,6],[4,3],[5,4],[0,5],[0,7]], \"values\": [8,13,19,13,4,3,24,25] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 101\n\ntest_input = { \"edges\": [[9,0],[7,1],[6,3],[8,4],[2,5],[9,6],[2,8],[7,2],[7,9]], \"values\": [4,13,21,1,25,8,21,22,9,18] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 138\n\ntest_input = { \"edges\": [[1,0],[4,3],[1,5],[6,1],[4,6],[2,7],[4,2],[4,8]], \"values\": [10,5,25,19,2,20,15,3,3] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 97\n\ntest_input = { \"edges\": [[6,1],[3,4],[2,5],[0,6],[3,0],[2,3],[2,7]], \"values\": [2,23,10,20,22,10,6,24] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 115\n\ntest_input = { \"edges\": [[2,1],[0,2],[5,0],[4,3],[5,4],[5,6]], \"values\": [9,21,12,20,5,2,13] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 73\n\ntest_input = { \"edges\": [[8,1],[7,4],[0,5],[2,0],[3,2],[8,3],[7,6],[7,8]], \"values\": [23,24,25,12,12,7,1,17,17] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 119\n\ntest_input = { \"edges\": [[3,0],[3,1],[2,3]], \"values\": [19,8,8,5] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 35\n\ntest_input = { \"edges\": [[5,0],[7,1],[3,2],[6,4],[6,5],[3,6],[3,7]], \"values\": [19,7,17,9,13,7,25,3] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 93\n\ntest_input = { \"edges\": [[3,1],[2,3],[0,2],[0,4]], \"values\": [14,15,18,15,20] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 68\n\ntest_input = { \"edges\": [[6,0],[2,1],[6,2],[6,4],[5,7],[6,5],[3,6],[9,3],[8,9]], \"values\": [17,20,17,13,5,12,8,12,14,25] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 135\n\ntest_input = { \"edges\": [[4,1],[6,2],[9,3],[0,6],[0,7],[9,0],[4,8],[5,4],[5,9]], \"values\": [11,16,10,25,21,25,15,10,5,7] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 134\n\ntest_input = { \"edges\": [[1,0],[3,1],[2,3]], \"values\": [25,19,12,2] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 56\n\ntest_input = { \"edges\": [[4,1],[0,2],[4,0],[3,4]], \"values\": [12,24,1,11,3] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 47\n\ntest_input = { \"edges\": [[1,0],[5,1],[2,4],[3,2],[3,5]], \"values\": [21,2,17,18,22,16] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 94\n\ntest_input = { \"edges\": [[5,1],[4,3],[2,4],[6,2],[0,5],[0,6]], \"values\": [18,24,5,20,23,6,7] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 92\n\ntest_input = { \"edges\": [[4,1],[6,3],[2,4],[5,2],[0,5],[0,6]], \"values\": [19,2,23,18,3,12,9] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 75\n\ntest_input = { \"edges\": [[5,0],[2,1],[6,3],[5,4],[2,5],[2,6]], \"values\": [22,11,2,11,3,11,17] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 72\n\ntest_input = { \"edges\": [[6,0],[4,1],[3,2],[6,5],[4,6],[3,4],[3,7],[3,8]], \"values\": [18,20,14,23,20,8,24,12,1] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 122\n\ntest_input = { \"edges\": [[1,2],[0,1],[0,3],[0,4]], \"values\": [6,8,2,16,6] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 32\n\ntest_input = { \"edges\": [[6,1],[3,4],[3,5],[0,3],[2,0],[2,6]], \"values\": [5,25,2,12,15,3,3] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 60\n\ntest_input = { \"edges\": [[4,0],[2,1],[2,3],[2,4]], \"values\": [9,5,14,24,19] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 62\n\ntest_input = { \"edges\": [[4,0],[2,1],[6,3],[2,5],[4,6],[2,4],[7,2],[7,8]], \"values\": [19,10,14,18,17,8,2,8,24] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 104\n\ntest_input = { \"edges\": [[6,0],[7,1],[5,3],[2,4],[8,5],[6,7],[2,6],[2,8]], \"values\": [8,8,19,17,24,1,7,18,12] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 107\n\ntest_input = { \"edges\": [[6,0],[3,1],[3,2],[3,6],[4,3],[5,4],[5,7]], \"values\": [15,3,25,2,10,11,10,13] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 87\n\ntest_input = { \"edges\": [[7,3],[2,5],[4,2],[0,4],[7,0],[1,6],[1,7]], \"values\": [1,19,5,1,18,24,4,20] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 91\n\ntest_input = { \"edges\": [[7,3],[2,4],[9,2],[1,5],[1,7],[0,1],[9,0],[6,8],[6,9]], \"values\": [21,10,9,25,7,20,5,8,20,5] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 115\n\ntest_input = { \"edges\": [[3,1],[4,5],[0,4],[2,0],[3,2],[3,6]], \"values\": [13,11,16,12,20,1,7] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 67\n\ntest_input = { \"edges\": [[2,0],[3,1],[6,2],[6,3],[5,4],[7,5],[6,7]], \"values\": [21,20,8,21,11,12,23,4] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 112\n\ntest_input = { \"edges\": [[0,2],[7,4],[1,6],[5,1],[3,5],[0,3],[0,7]], \"values\": [8,6,9,5,4,1,8,6] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 39\n\ntest_input = { \"edges\": [[5,1],[8,3],[0,4],[8,0],[2,5],[2,7],[9,2],[6,8],[6,9]], \"values\": [2,22,2,19,25,14,11,24,7,6] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 130\n\ntest_input = { \"edges\": [[3,0],[3,1],[2,3]], \"values\": [24,24,4,12] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 52\n\ntest_input = { \"edges\": [[2,0],[3,1],[2,3]], \"values\": [7,10,13,8] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 31\n\ntest_input = { \"edges\": [[1,0],[3,1],[6,4],[3,5],[2,3],[2,6]], \"values\": [6,14,4,17,16,19,24] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 94\n\ntest_input = { \"edges\": [[0,1],[3,0],[8,3],[2,4],[8,5],[2,6],[8,2],[7,8]], \"values\": [22,19,10,16,14,11,2,17,9] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 98\n\ntest_input = { \"edges\": [[5,1],[5,2],[0,3],[0,4],[0,5]], \"values\": [21,18,2,20,1,1] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 42\n\ntest_input = { \"edges\": [[6,0],[3,2],[1,3],[6,4],[1,5],[1,6]], \"values\": [14,19,22,6,19,12,20] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 98\n\ntest_input = { \"edges\": [[6,0],[4,1],[2,3],[5,2],[6,4],[5,6]], \"values\": [16,16,9,12,5,14,17] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 75\n\ntest_input = { \"edges\": [[2,1],[4,2],[0,3],[0,4]], \"values\": [9,6,7,17,19] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 49\n\ntest_input = { \"edges\": [[1,3],[2,1],[4,5],[2,4],[0,2],[0,6]], \"values\": [4,19,10,25,16,13,6] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 89\n\ntest_input = { \"edges\": [[1,0],[5,1],[2,5],[3,2],[4,6],[3,4],[3,7]], \"values\": [12,9,19,10,24,22,18,16] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 121\n\ntest_input = { \"edges\": [[0,1],[0,2],[0,3]], \"values\": [25,23,7,9] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 39\n\ntest_input = { \"edges\": [[3,0],[3,2],[4,5],[9,6],[4,7],[9,4],[3,8],[1,3],[1,9]], \"values\": [23,22,7,22,19,12,10,11,24,3] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 131\n\ntest_input = { \"edges\": [[0,1],[0,2],[0,3]], \"values\": [9,8,24,21] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 53\n\ntest_input = { \"edges\": [[3,1],[0,2],[0,3]], \"values\": [17,2,2,4] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 21\n\ntest_input = { \"edges\": [[5,2],[3,4],[0,3],[1,0],[1,5]], \"values\": [16,6,15,15,10,1] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 52\n\ntest_input = { \"edges\": [[8,0],[8,1],[7,2],[3,7],[6,3],[4,6],[5,4],[5,8]], \"values\": [10,25,10,6,21,17,11,15,15] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 120\n\ntest_input = { \"edges\": [[0,4],[1,5],[2,6],[0,2],[1,0],[3,1],[3,7]], \"values\": [20,1,16,12,5,23,21,4] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 82\n\ntest_input = { \"edges\": [[7,1],[5,2],[0,3],[7,0],[7,4],[6,5],[6,7]], \"values\": [6,20,14,17,18,16,11,1] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 97\n\ntest_input = { \"edges\": [[3,2],[8,4],[1,6],[0,1],[5,0],[3,5],[8,3],[7,8]], \"values\": [3,18,16,22,10,2,7,3,10] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 88\n\ntest_input = { \"edges\": [[4,0],[3,4],[3,5],[3,6],[2,3],[1,2],[1,7]], \"values\": [12,14,7,25,13,16,12,15] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 102\n\ntest_input = { \"edges\": [[3,0],[5,2],[1,3],[4,1],[4,5]], \"values\": [11,18,19,14,8,11] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 73\n\ntest_input = { \"edges\": [[1,2],[4,1],[0,4],[8,5],[0,6],[7,0],[3,7],[3,8]], \"values\": [17,22,14,15,2,21,7,9,1] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 98\n\ntest_input = { \"edges\": [[2,1],[0,2],[4,3],[0,4],[0,5]], \"values\": [1,2,24,25,9,24] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 84\n\ntest_input = { \"edges\": [[3,1],[3,2],[0,4],[3,5],[0,3],[0,6]], \"values\": [21,19,5,20,2,25,20] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 91\n\ntest_input = { \"edges\": [[1,0],[4,1],[4,2],[3,4]], \"values\": [3,6,17,4,20] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 47\n\ntest_input = { \"edges\": [[6,1],[2,3],[6,7],[4,6],[2,4],[5,2],[5,8],[0,5],[0,9]], \"values\": [23,19,15,4,3,18,25,22,6,11] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 123\n\ntest_input = { \"edges\": [[2,0],[1,2],[5,1],[3,4],[3,5]], \"values\": [23,24,10,15,10,22] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 94\n\ntest_input = { \"edges\": [[1,0],[6,1],[6,2],[4,3],[5,4],[5,6]], \"values\": [18,21,3,13,25,15,20] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 99\n\ntest_input = { \"edges\": [[1,0],[3,1],[2,3]], \"values\": [23,10,24,15] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 62\n\ntest_input = { \"edges\": [[1,0],[1,2],[1,3]], \"values\": [10,4,12,14] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 36\n\ntest_input = { \"edges\": [[2,0],[3,2],[1,3],[4,5],[1,4],[1,6]], \"values\": [3,8,13,11,6,18,8] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 64\n\ntest_input = { \"edges\": [[3,0],[3,2],[1,3],[1,4]], \"values\": [18,19,7,7,2] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 46\n\ntest_input = { \"edges\": [[7,0],[5,2],[1,3],[7,4],[1,5],[7,1],[6,7]], \"values\": [24,24,16,17,25,9,3,23] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 118\n\ntest_input = { \"edges\": [[2,0],[2,1],[2,3]], \"values\": [25,12,5,7] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 44\n\ntest_input = { \"edges\": [[0,1],[2,0],[2,3],[2,4]], \"values\": [24,14,9,5,24] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 53\n\ntest_input = { \"edges\": [[6,2],[7,3],[0,5],[4,0],[1,6],[4,1],[4,7]], \"values\": [20,15,15,2,22,7,19,24] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 104\n\ntest_input = { \"edges\": [[1,0],[4,2],[7,5],[3,6],[1,3],[4,1],[4,7]], \"values\": [11,21,15,23,2,7,21,3] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 92\n\ntest_input = { \"edges\": [[4,0],[2,1],[2,3],[2,4]], \"values\": [22,20,20,8,14] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 70\n\ntest_input = { \"edges\": [[0,2],[4,3],[0,4],[1,0],[1,6],[5,1],[5,7]], \"values\": [18,10,19,9,11,14,11,18] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 92\n\ntest_input = { \"edges\": [[6,1],[4,2],[4,3],[0,5],[4,0],[4,6]], \"values\": [18,10,5,23,16,13,1] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 68\n\ntest_input = { \"edges\": [[4,0],[6,2],[6,3],[6,4],[1,5],[7,1],[6,7]], \"values\": [14,15,22,9,13,2,25,3] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 90\n\ntest_input = { \"edges\": [[6,2],[0,3],[5,0],[1,5],[4,1],[4,6]], \"values\": [22,10,19,14,18,24,8] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 93\n\ntest_input = { \"edges\": [[0,1],[0,2],[0,3]], \"values\": [6,22,9,5] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 36\n\ntest_input = { \"edges\": [[2,1],[0,2],[6,0],[6,4],[3,5],[3,6],[3,7]], \"values\": [9,16,13,9,19,1,16,19] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 93\n\ntest_input = { \"edges\": [[3,5],[7,3],[0,6],[4,0],[1,4],[2,1],[2,7]], \"values\": [16,9,8,14,6,18,23,25] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 103\n\ntest_input = { \"edges\": [[7,1],[4,5],[3,6],[4,3],[2,4],[0,2],[0,7]], \"values\": [7,22,12,22,5,3,6,7] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 77\n\ntest_input = { \"edges\": [[5,0],[4,1],[5,2],[3,5],[4,3],[7,4],[6,7]], \"values\": [19,16,8,13,15,13,3,5] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 79\n\ntest_input = { \"edges\": [[7,1],[6,2],[3,5],[8,3],[0,6],[4,0],[7,4],[7,8]], \"values\": [23,11,22,6,19,6,19,8,25] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 116\n\ntest_input = { \"edges\": [[4,0],[4,2],[1,3],[4,1],[4,5]], \"values\": [23,22,13,1,11,25] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 84\n\ntest_input = { \"edges\": [[4,0],[4,1],[2,3],[2,4]], \"values\": [3,17,5,24,14] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 60\n\ntest_input = { \"edges\": [[4,0],[2,4],[1,2],[3,1],[3,5]], \"values\": [6,12,21,6,8,8] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 55\n\ntest_input = { \"edges\": [[4,2],[5,4],[0,5],[0,6],[3,0],[1,3],[7,8],[1,7],[1,9]], \"values\": [25,16,16,14,22,19,2,22,13,11] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 135\n\ntest_input = { \"edges\": [[4,0],[1,3],[4,1],[7,5],[2,6],[4,2],[4,7]], \"values\": [23,16,24,25,3,21,3,25] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 137\n\ntest_input = { \"edges\": [[0,1],[2,0],[2,3]], \"values\": [22,17,9,9] }\nassert my_solution.maximumScoreAfterOperations(**test_input) == 35", "start_time": 1699151400} +{"task_id": "weekly-contest-370-maximum-balanced-subsequence-sum", "url": "https://leetcode.com/problems/maximum-balanced-subsequence-sum", "title": "maximum-balanced-subsequence-sum", "meta": {"questionId": "3184", "questionFrontendId": "2926", "title": "Maximum Balanced Subsequence Sum", "titleSlug": "maximum-balanced-subsequence-sum", "isPaidOnly": false, "difficulty": "Hard", "likes": 133, "dislikes": 6, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed integer array nums.\n\nA subsequence of nums having length k and consisting of indices i0 < i1 < ... < ik-1 is balanced if the following holds:\n\n * nums[ij] - nums[ij-1] >= ij - ij-1, for every j in the range [1, k - 1].\n\nA subsequence of nums having length 1 is considered balanced.\n\nReturn an integer denoting the maximum possible sum of elements in a balanced subsequence of nums.\n\nA subsequence of an array is a new non-empty array that is formed from the original array by deleting some (possibly none) of the elements without disturbing the relative positions of the remaining elements.\n\nExample 1:\n\nInput: nums = [3,3,5,6]\nOutput: 14\nExplanation: In this example, the subsequence [3,5,6] consisting of indices 0, 2, and 3 can be selected.\nnums[2] - nums[0] >= 2 - 0.\nnums[3] - nums[2] >= 3 - 2.\nHence, it is a balanced subsequence, and its sum is the maximum among the balanced subsequences of nums.\nThe subsequence consisting of indices 1, 2, and 3 is also valid.\nIt can be shown that it is not possible to get a balanced subsequence with a sum greater than 14.\n\nExample 2:\n\nInput: nums = [5,-1,-3,8]\nOutput: 13\nExplanation: In this example, the subsequence [5,8] consisting of indices 0 and 3 can be selected.\nnums[3] - nums[0] >= 3 - 0.\nHence, it is a balanced subsequence, and its sum is the maximum among the balanced subsequences of nums.\nIt can be shown that it is not possible to get a balanced subsequence with a sum greater than 13.\n\nExample 3:\n\nInput: nums = [-2,-1]\nOutput: -1\nExplanation: In this example, the subsequence [-1] can be selected.\nIt is a balanced subsequence, and its sum is the maximum among the balanced subsequences of nums.\n\n\nConstraints:\n\n * 1 <= nums.length <= 105\n * -109 <= nums[i] <= 109\n\"\"\"\nclass Solution:\n def maxBalancedSubsequenceSum(self, nums: List[int]) -> int:\n ", "prompt_sft": "You are given a 0-indexed integer array nums.\n\nA subsequence of nums having length k and consisting of indices i0 < i1 < ... < ik-1 is balanced if the following holds:\n\n * nums[ij] - nums[ij-1] >= ij - ij-1, for every j in the range [1, k - 1].\n\nA subsequence of nums having length 1 is considered balanced.\n\nReturn an integer denoting the maximum possible sum of elements in a balanced subsequence of nums.\n\nA subsequence of an array is a new non-empty array that is formed from the original array by deleting some (possibly none) of the elements without disturbing the relative positions of the remaining elements.\n\nExample 1:\n\nInput: nums = [3,3,5,6]\nOutput: 14\nExplanation: In this example, the subsequence [3,5,6] consisting of indices 0, 2, and 3 can be selected.\nnums[2] - nums[0] >= 2 - 0.\nnums[3] - nums[2] >= 3 - 2.\nHence, it is a balanced subsequence, and its sum is the maximum among the balanced subsequences of nums.\nThe subsequence consisting of indices 1, 2, and 3 is also valid.\nIt can be shown that it is not possible to get a balanced subsequence with a sum greater than 14.\n\nExample 2:\n\nInput: nums = [5,-1,-3,8]\nOutput: 13\nExplanation: In this example, the subsequence [5,8] consisting of indices 0 and 3 can be selected.\nnums[3] - nums[0] >= 3 - 0.\nHence, it is a balanced subsequence, and its sum is the maximum among the balanced subsequences of nums.\nIt can be shown that it is not possible to get a balanced subsequence with a sum greater than 13.\n\nExample 3:\n\nInput: nums = [-2,-1]\nOutput: -1\nExplanation: In this example, the subsequence [-1] can be selected.\nIt is a balanced subsequence, and its sum is the maximum among the balanced subsequences of nums.\n\n\nConstraints:\n\n * 1 <= nums.length <= 105\n * -109 <= nums[i] <= 109\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def maxBalancedSubsequenceSum(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [3,3,5,6] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 14\n\ntest_input = { \"nums\": [5,-1,-3,8] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 13\n\ntest_input = { \"nums\": [-2,-1] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == -1\n\ntest_input = { \"nums\": [0] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 0\n\ntest_input = { \"nums\": [-47] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == -47\n\ntest_input = { \"nums\": [-8] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == -8\n\ntest_input = { \"nums\": [-7] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == -7\n\ntest_input = { \"nums\": [-6] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == -6\n\ntest_input = { \"nums\": [-5] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == -5\n\ntest_input = { \"nums\": [-3] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == -3\n\ntest_input = { \"nums\": [-2] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == -2\n\ntest_input = { \"nums\": [-1] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == -1\n\ntest_input = { \"nums\": [1] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 1\n\ntest_input = { \"nums\": [3] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 3\n\ntest_input = { \"nums\": [4] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 4\n\ntest_input = { \"nums\": [5] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 5\n\ntest_input = { \"nums\": [7] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 7\n\ntest_input = { \"nums\": [8] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 8\n\ntest_input = { \"nums\": [9] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 9\n\ntest_input = { \"nums\": [45] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 45\n\ntest_input = { \"nums\": [-9,-5] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == -5\n\ntest_input = { \"nums\": [-6,8] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 8\n\ntest_input = { \"nums\": [-5,-1] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == -1\n\ntest_input = { \"nums\": [-5,0] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 0\n\ntest_input = { \"nums\": [-3,-1] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == -1\n\ntest_input = { \"nums\": [-2,3] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 3\n\ntest_input = { \"nums\": [-1,-5] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == -1\n\ntest_input = { \"nums\": [-1,0] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 0\n\ntest_input = { \"nums\": [-1,3] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 3\n\ntest_input = { \"nums\": [0,-3] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 0\n\ntest_input = { \"nums\": [0,5] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 5\n\ntest_input = { \"nums\": [2,7] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 9\n\ntest_input = { \"nums\": [5,-1] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 5\n\ntest_input = { \"nums\": [6,-8] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 6\n\ntest_input = { \"nums\": [7,-2] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 7\n\ntest_input = { \"nums\": [7,2] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 7\n\ntest_input = { \"nums\": [8,-9] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 8\n\ntest_input = { \"nums\": [9,-9] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 9\n\ntest_input = { \"nums\": [-43,23,-49] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 23\n\ntest_input = { \"nums\": [-9,-6,-5] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == -5\n\ntest_input = { \"nums\": [-9,-2,4] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 4\n\ntest_input = { \"nums\": [-9,5,-6] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 5\n\ntest_input = { \"nums\": [-8,9,-9] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 9\n\ntest_input = { \"nums\": [-5,-1,-9] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == -1\n\ntest_input = { \"nums\": [-4,-9,3] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 3\n\ntest_input = { \"nums\": [-4,-2,-7] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == -2\n\ntest_input = { \"nums\": [-3,-4,-2] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == -2\n\ntest_input = { \"nums\": [-2,-1,-2] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == -1\n\ntest_input = { \"nums\": [-1,-6,1] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 1\n\ntest_input = { \"nums\": [0,-6,-4] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 0\n\ntest_input = { \"nums\": [0,-5,4] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,-4,4] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 5\n\ntest_input = { \"nums\": [4,1,-8] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 4\n\ntest_input = { \"nums\": [5,-6,-8] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 5\n\ntest_input = { \"nums\": [5,-4,-5] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 5\n\ntest_input = { \"nums\": [6,-3,9] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 15\n\ntest_input = { \"nums\": [6,0,2] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 6\n\ntest_input = { \"nums\": [7,-6,0] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 7\n\ntest_input = { \"nums\": [8,-7,2] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 8\n\ntest_input = { \"nums\": [14,-21,-18] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 14\n\ntest_input = { \"nums\": [-9,7,-8,1] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 7\n\ntest_input = { \"nums\": [-8,2,-5,-7] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 2\n\ntest_input = { \"nums\": [-7,1,-2,-8] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 1\n\ntest_input = { \"nums\": [-6,-8,7,-3] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 7\n\ntest_input = { \"nums\": [-5,-1,0,6] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 6\n\ntest_input = { \"nums\": [-4,8,9,2] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 17\n\ntest_input = { \"nums\": [-4,9,7,-4] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 9\n\ntest_input = { \"nums\": [-2,-6,0,-5] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 0\n\ntest_input = { \"nums\": [-2,-3,9,3] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 9\n\ntest_input = { \"nums\": [0,-6,-3,5] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 5\n\ntest_input = { \"nums\": [0,1,0,-2] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 1\n\ntest_input = { \"nums\": [1,-7,-8,6] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 7\n\ntest_input = { \"nums\": [3,-7,9,-3] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 12\n\ntest_input = { \"nums\": [3,-7,9,2] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 12\n\ntest_input = { \"nums\": [4,-8,-1,8] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 12\n\ntest_input = { \"nums\": [5,4,1,0] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 5\n\ntest_input = { \"nums\": [7,7,-9,-4] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 7\n\ntest_input = { \"nums\": [8,0,4,-2] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 8\n\ntest_input = { \"nums\": [9,7,-2,1] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 9\n\ntest_input = { \"nums\": [34,34,32,33] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 65\n\ntest_input = { \"nums\": [-9,-6,-8,-2,4] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 4\n\ntest_input = { \"nums\": [-9,-5,2,2,7] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 9\n\ntest_input = { \"nums\": [-9,-2,-6,0,6] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 6\n\ntest_input = { \"nums\": [-7,0,-8,-9,-3] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 0\n\ntest_input = { \"nums\": [-7,0,9,-4,9] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 9\n\ntest_input = { \"nums\": [-6,-2,-8,-4,-8] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == -2\n\ntest_input = { \"nums\": [-6,2,-3,0,-5] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 2\n\ntest_input = { \"nums\": [-6,3,-6,-3,-2] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 3\n\ntest_input = { \"nums\": [-5,-9,1,3,-5] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 4\n\ntest_input = { \"nums\": [-5,1,5,-5,-1] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 6\n\ntest_input = { \"nums\": [-3,7,0,4,6] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 10\n\ntest_input = { \"nums\": [-2,-2,9,-2,-8] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 9\n\ntest_input = { \"nums\": [0,-6,-9,-8,-3] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 0\n\ntest_input = { \"nums\": [0,-2,-7,-1,-8] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 0\n\ntest_input = { \"nums\": [0,-1,-4,-6,-9] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 0\n\ntest_input = { \"nums\": [1,-3,-8,9,-9] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 10\n\ntest_input = { \"nums\": [2,-6,-2,0,-3] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 2\n\ntest_input = { \"nums\": [2,9,-4,4,2] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 11\n\ntest_input = { \"nums\": [4,-1,5,-1,-7] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 5\n\ntest_input = { \"nums\": [4,6,-8,-8,-5] }\nassert my_solution.maxBalancedSubsequenceSum(**test_input) == 10", "start_time": 1699151400} +{"task_id": "weekly-contest-369-find-the-k-or-of-an-array", "url": "https://leetcode.com/problems/find-the-k-or-of-an-array", "title": "find-the-k-or-of-an-array", "meta": {"questionId": "3183", "questionFrontendId": "2917", "title": "Find the K-or of an Array", "titleSlug": "find-the-k-or-of-an-array", "isPaidOnly": false, "difficulty": "Easy", "likes": 55, "dislikes": 201, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed integer array nums, and an integer k.\n\nThe K-or of nums is a non-negative integer that satisfies the following:\n\n * The ith bit is set in the K-or if and only if there are at least k elements of nums in which bit i is set.\n\nReturn the K-or of nums.\n\nNote that a bit i is set in x if (2i AND x) == 2i, where AND is the bitwise AND operator.\n\nExample 1:\n\nInput: nums = [7,12,9,8,9,15], k = 4\nOutput: 9\nExplanation: Bit 0 is set at nums[0], nums[2], nums[4], and nums[5].\nBit 1 is set at nums[0], and nums[5].\nBit 2 is set at nums[0], nums[1], and nums[5].\nBit 3 is set at nums[1], nums[2], nums[3], nums[4], and nums[5].\nOnly bits 0 and 3 are set in at least k elements of the array, and bits i >= 4 are not set in any of the array's elements. Hence, the answer is 2^0 + 2^3 = 9.\n\nExample 2:\n\nInput: nums = [2,12,1,11,4,5], k = 6\nOutput: 0\nExplanation: Since k == 6 == nums.length, the 6-or of the array is equal to the bitwise AND of all its elements. Hence, the answer is 2 AND 12 AND 1 AND 11 AND 4 AND 5 = 0.\n\nExample 3:\n\nInput: nums = [10,8,5,9,11,6,8], k = 1\nOutput: 15\nExplanation: Since k == 1, the 1-or of the array is equal to the bitwise OR of all its elements. Hence, the answer is 10 OR 8 OR 5 OR 9 OR 11 OR 6 OR 8 = 15.\n\n\nConstraints:\n\n * 1 <= nums.length <= 50\n * 0 <= nums[i] < 231\n * 1 <= k <= nums.length\n\"\"\"\nclass Solution:\n def findKOr(self, nums: List[int], k: int) -> int:\n ", "prompt_sft": "You are given a 0-indexed integer array nums, and an integer k.\n\nThe K-or of nums is a non-negative integer that satisfies the following:\n\n * The ith bit is set in the K-or if and only if there are at least k elements of nums in which bit i is set.\n\nReturn the K-or of nums.\n\nNote that a bit i is set in x if (2i AND x) == 2i, where AND is the bitwise AND operator.\n\nExample 1:\n\nInput: nums = [7,12,9,8,9,15], k = 4\nOutput: 9\nExplanation: Bit 0 is set at nums[0], nums[2], nums[4], and nums[5].\nBit 1 is set at nums[0], and nums[5].\nBit 2 is set at nums[0], nums[1], and nums[5].\nBit 3 is set at nums[1], nums[2], nums[3], nums[4], and nums[5].\nOnly bits 0 and 3 are set in at least k elements of the array, and bits i >= 4 are not set in any of the array's elements. Hence, the answer is 2^0 + 2^3 = 9.\n\nExample 2:\n\nInput: nums = [2,12,1,11,4,5], k = 6\nOutput: 0\nExplanation: Since k == 6 == nums.length, the 6-or of the array is equal to the bitwise AND of all its elements. Hence, the answer is 2 AND 12 AND 1 AND 11 AND 4 AND 5 = 0.\n\nExample 3:\n\nInput: nums = [10,8,5,9,11,6,8], k = 1\nOutput: 15\nExplanation: Since k == 1, the 1-or of the array is equal to the bitwise OR of all its elements. Hence, the answer is 10 OR 8 OR 5 OR 9 OR 11 OR 6 OR 8 = 15.\n\n\nConstraints:\n\n * 1 <= nums.length <= 50\n * 0 <= nums[i] < 231\n * 1 <= k <= nums.length\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def findKOr(self, nums: List[int], k: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [7,12,9,8,9,15], \"k\": 4 }\nassert my_solution.findKOr(**test_input) == 9\n\ntest_input = { \"nums\": [2,12,1,11,4,5], \"k\": 6 }\nassert my_solution.findKOr(**test_input) == 0\n\ntest_input = { \"nums\": [10,8,5,9,11,6,8], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 15\n\ntest_input = { \"nums\": [14,7,12,9,8,9,1,15], \"k\": 4 }\nassert my_solution.findKOr(**test_input) == 13\n\ntest_input = { \"nums\": [2,12,1,11,4,5], \"k\": 3 }\nassert my_solution.findKOr(**test_input) == 5\n\ntest_input = { \"nums\": [10,8,5,10,11,11,6,8], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 15\n\ntest_input = { \"nums\": [0], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 0\n\ntest_input = { \"nums\": [1], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 1\n\ntest_input = { \"nums\": [2], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 2\n\ntest_input = { \"nums\": [3], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 3\n\ntest_input = { \"nums\": [4], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 4\n\ntest_input = { \"nums\": [5], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 5\n\ntest_input = { \"nums\": [6], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 6\n\ntest_input = { \"nums\": [7], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 7\n\ntest_input = { \"nums\": [8], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 8\n\ntest_input = { \"nums\": [9], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 9\n\ntest_input = { \"nums\": [10], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 10\n\ntest_input = { \"nums\": [11], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 11\n\ntest_input = { \"nums\": [12], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 12\n\ntest_input = { \"nums\": [13], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 13\n\ntest_input = { \"nums\": [14], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 14\n\ntest_input = { \"nums\": [15], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 15\n\ntest_input = { \"nums\": [16], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 16\n\ntest_input = { \"nums\": [17], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 17\n\ntest_input = { \"nums\": [18], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 18\n\ntest_input = { \"nums\": [19], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 19\n\ntest_input = { \"nums\": [20], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 20\n\ntest_input = { \"nums\": [21], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 21\n\ntest_input = { \"nums\": [22], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 22\n\ntest_input = { \"nums\": [23], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 23\n\ntest_input = { \"nums\": [24], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 24\n\ntest_input = { \"nums\": [25], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 25\n\ntest_input = { \"nums\": [26], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 26\n\ntest_input = { \"nums\": [27], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 27\n\ntest_input = { \"nums\": [28], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 28\n\ntest_input = { \"nums\": [29], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 29\n\ntest_input = { \"nums\": [30], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 30\n\ntest_input = { \"nums\": [31], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 31\n\ntest_input = { \"nums\": [22,7,27,30,15,30,28], \"k\": 4 }\nassert my_solution.findKOr(**test_input) == 30\n\ntest_input = { \"nums\": [24,18,3,23,16,11,27,18,5,29], \"k\": 6 }\nassert my_solution.findKOr(**test_input) == 19\n\ntest_input = { \"nums\": [14,1,2,28,4,15,3,12], \"k\": 2 }\nassert my_solution.findKOr(**test_input) == 15\n\ntest_input = { \"nums\": [7,18,25,11,2], \"k\": 5 }\nassert my_solution.findKOr(**test_input) == 0\n\ntest_input = { \"nums\": [0,4], \"k\": 2 }\nassert my_solution.findKOr(**test_input) == 0\n\ntest_input = { \"nums\": [17,5,14,16,24,30,3,19,31], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 31\n\ntest_input = { \"nums\": [14,20,23,7,1,12,24,19], \"k\": 7 }\nassert my_solution.findKOr(**test_input) == 0\n\ntest_input = { \"nums\": [5,31,29,22,8,6,23], \"k\": 4 }\nassert my_solution.findKOr(**test_input) == 23\n\ntest_input = { \"nums\": [9,10,30,0,7,19,14,19,20,3], \"k\": 4 }\nassert my_solution.findKOr(**test_input) == 31\n\ntest_input = { \"nums\": [25,6,5,30,27,11,10,30], \"k\": 2 }\nassert my_solution.findKOr(**test_input) == 31\n\ntest_input = { \"nums\": [0,15,16,6,19,5,24,17], \"k\": 3 }\nassert my_solution.findKOr(**test_input) == 23\n\ntest_input = { \"nums\": [19,8,2,28,4,5], \"k\": 5 }\nassert my_solution.findKOr(**test_input) == 0\n\ntest_input = { \"nums\": [13,9,1,15,9,2,19,19], \"k\": 3 }\nassert my_solution.findKOr(**test_input) == 11\n\ntest_input = { \"nums\": [16,6,16,22,8,2,25,30], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 31\n\ntest_input = { \"nums\": [14,28,23,22], \"k\": 2 }\nassert my_solution.findKOr(**test_input) == 30\n\ntest_input = { \"nums\": [6,26], \"k\": 2 }\nassert my_solution.findKOr(**test_input) == 2\n\ntest_input = { \"nums\": [14,9,22,30,15], \"k\": 4 }\nassert my_solution.findKOr(**test_input) == 14\n\ntest_input = { \"nums\": [12,13,16,25,12,4,8,29], \"k\": 6 }\nassert my_solution.findKOr(**test_input) == 8\n\ntest_input = { \"nums\": [27,29], \"k\": 2 }\nassert my_solution.findKOr(**test_input) == 25\n\ntest_input = { \"nums\": [9,27,27,20,24,13,25,8], \"k\": 6 }\nassert my_solution.findKOr(**test_input) == 8\n\ntest_input = { \"nums\": [22,26,18,26,1], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 31\n\ntest_input = { \"nums\": [20,20,31,19,29,19], \"k\": 2 }\nassert my_solution.findKOr(**test_input) == 31\n\ntest_input = { \"nums\": [5,8,27,23,3], \"k\": 2 }\nassert my_solution.findKOr(**test_input) == 31\n\ntest_input = { \"nums\": [4,23,0,20,4,19,14,22,26,2], \"k\": 9 }\nassert my_solution.findKOr(**test_input) == 0\n\ntest_input = { \"nums\": [31,26,21,4,9,11,13,24,23,5], \"k\": 10 }\nassert my_solution.findKOr(**test_input) == 0\n\ntest_input = { \"nums\": [4,22], \"k\": 2 }\nassert my_solution.findKOr(**test_input) == 4\n\ntest_input = { \"nums\": [22,17,20,3,21,5,20,25,16], \"k\": 4 }\nassert my_solution.findKOr(**test_input) == 21\n\ntest_input = { \"nums\": [16,15,13,26,15,23,0,12], \"k\": 4 }\nassert my_solution.findKOr(**test_input) == 15\n\ntest_input = { \"nums\": [4,11,14], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 15\n\ntest_input = { \"nums\": [10,26,27,25,3,21,9,3,22], \"k\": 8 }\nassert my_solution.findKOr(**test_input) == 0\n\ntest_input = { \"nums\": [4,11,16], \"k\": 2 }\nassert my_solution.findKOr(**test_input) == 0\n\ntest_input = { \"nums\": [9,27,19,9,24,11], \"k\": 3 }\nassert my_solution.findKOr(**test_input) == 27\n\ntest_input = { \"nums\": [29,19,27,14], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 31\n\ntest_input = { \"nums\": [27,31,21,8,25], \"k\": 2 }\nassert my_solution.findKOr(**test_input) == 31\n\ntest_input = { \"nums\": [14,1,13,22,27], \"k\": 5 }\nassert my_solution.findKOr(**test_input) == 0\n\ntest_input = { \"nums\": [14,15,17,23,29], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 31\n\ntest_input = { \"nums\": [19,21], \"k\": 2 }\nassert my_solution.findKOr(**test_input) == 17\n\ntest_input = { \"nums\": [29,9,18,0,30,5,1,9], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 31\n\ntest_input = { \"nums\": [6,31,11,7,6,2,26,19,17,13], \"k\": 10 }\nassert my_solution.findKOr(**test_input) == 0\n\ntest_input = { \"nums\": [15,8,27,28], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 31\n\ntest_input = { \"nums\": [28,24,20,31,23,1], \"k\": 2 }\nassert my_solution.findKOr(**test_input) == 31\n\ntest_input = { \"nums\": [8,13,27,24,20,28,15,21,23,6], \"k\": 9 }\nassert my_solution.findKOr(**test_input) == 0\n\ntest_input = { \"nums\": [31,6], \"k\": 2 }\nassert my_solution.findKOr(**test_input) == 6\n\ntest_input = { \"nums\": [3,14,11,17,9], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 31\n\ntest_input = { \"nums\": [14,11], \"k\": 2 }\nassert my_solution.findKOr(**test_input) == 10\n\ntest_input = { \"nums\": [2,9,11,25,3,2,26,21,13,11], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 31\n\ntest_input = { \"nums\": [26,7,23,0,16,31,12,18,24], \"k\": 4 }\nassert my_solution.findKOr(**test_input) == 30\n\ntest_input = { \"nums\": [11,30,30,17,10,27,6,31,0], \"k\": 4 }\nassert my_solution.findKOr(**test_input) == 31\n\ntest_input = { \"nums\": [11,9,18,30,27,20,2,17,18,4], \"k\": 2 }\nassert my_solution.findKOr(**test_input) == 31\n\ntest_input = { \"nums\": [2,1,0,30,29,14,13,26,10,22], \"k\": 10 }\nassert my_solution.findKOr(**test_input) == 0\n\ntest_input = { \"nums\": [21,30,30,17,23,8,26,9], \"k\": 6 }\nassert my_solution.findKOr(**test_input) == 16\n\ntest_input = { \"nums\": [16,10], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 26\n\ntest_input = { \"nums\": [26,12,19,22,5,6,19,30,24,11], \"k\": 10 }\nassert my_solution.findKOr(**test_input) == 0\n\ntest_input = { \"nums\": [20,10,14], \"k\": 2 }\nassert my_solution.findKOr(**test_input) == 14\n\ntest_input = { \"nums\": [23,17,18,30,3], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 31\n\ntest_input = { \"nums\": [13,16,12], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 29\n\ntest_input = { \"nums\": [17,12,5,13,23,19], \"k\": 3 }\nassert my_solution.findKOr(**test_input) == 21\n\ntest_input = { \"nums\": [5,4,3], \"k\": 2 }\nassert my_solution.findKOr(**test_input) == 5\n\ntest_input = { \"nums\": [6,28,1,3,2], \"k\": 1 }\nassert my_solution.findKOr(**test_input) == 31\n\ntest_input = { \"nums\": [28,3,15,30,10,29], \"k\": 4 }\nassert my_solution.findKOr(**test_input) == 14\n\ntest_input = { \"nums\": [0,31,13,24,16,21], \"k\": 3 }\nassert my_solution.findKOr(**test_input) == 29\n\ntest_input = { \"nums\": [11,20,28,29,3,4], \"k\": 2 }\nassert my_solution.findKOr(**test_input) == 31", "start_time": 1698546600} +{"task_id": "weekly-contest-369-minimum-equal-sum-of-two-arrays-after-replacing-zeros", "url": "https://leetcode.com/problems/minimum-equal-sum-of-two-arrays-after-replacing-zeros", "title": "minimum-equal-sum-of-two-arrays-after-replacing-zeros", "meta": {"questionId": "3171", "questionFrontendId": "2918", "title": "Minimum Equal Sum of Two Arrays After Replacing Zeros", "titleSlug": "minimum-equal-sum-of-two-arrays-after-replacing-zeros", "isPaidOnly": false, "difficulty": "Medium", "likes": 131, "dislikes": 15, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given two arrays nums1 and nums2 consisting of positive integers.\n\nYou have to replace all the 0's in both arrays with strictly positive integers such that the sum of elements of both arrays becomes equal.\n\nReturn the minimum equal sum you can obtain, or -1 if it is impossible.\n\nExample 1:\n\nInput: nums1 = [3,2,0,1,0], nums2 = [6,5,0]\nOutput: 12\nExplanation: We can replace 0's in the following way:\n- Replace the two 0's in nums1 with the values 2 and 4. The resulting array is nums1 = [3,2,2,1,4].\n- Replace the 0 in nums2 with the value 1. The resulting array is nums2 = [6,5,1].\nBoth arrays have an equal sum of 12. It can be shown that it is the minimum sum we can obtain.\n\nExample 2:\n\nInput: nums1 = [2,0,2,0], nums2 = [1,4]\nOutput: -1\nExplanation: It is impossible to make the sum of both arrays equal.\n\n\nConstraints:\n\n * 1 <= nums1.length, nums2.length <= 105\n * 0 <= nums1[i], nums2[i] <= 106\n\"\"\"\nclass Solution:\n def minSum(self, nums1: List[int], nums2: List[int]) -> int:\n ", "prompt_sft": "You are given two arrays nums1 and nums2 consisting of positive integers.\n\nYou have to replace all the 0's in both arrays with strictly positive integers such that the sum of elements of both arrays becomes equal.\n\nReturn the minimum equal sum you can obtain, or -1 if it is impossible.\n\nExample 1:\n\nInput: nums1 = [3,2,0,1,0], nums2 = [6,5,0]\nOutput: 12\nExplanation: We can replace 0's in the following way:\n- Replace the two 0's in nums1 with the values 2 and 4. The resulting array is nums1 = [3,2,2,1,4].\n- Replace the 0 in nums2 with the value 1. The resulting array is nums2 = [6,5,1].\nBoth arrays have an equal sum of 12. It can be shown that it is the minimum sum we can obtain.\n\nExample 2:\n\nInput: nums1 = [2,0,2,0], nums2 = [1,4]\nOutput: -1\nExplanation: It is impossible to make the sum of both arrays equal.\n\n\nConstraints:\n\n * 1 <= nums1.length, nums2.length <= 105\n * 0 <= nums1[i], nums2[i] <= 106\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def minSum(self, nums1: List[int], nums2: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums1\": [3,2,0,1,0], \"nums2\": [6,5,0] }\nassert my_solution.minSum(**test_input) == 12\n\ntest_input = { \"nums1\": [2,0,2,0], \"nums2\": [1,4] }\nassert my_solution.minSum(**test_input) == -1\n\ntest_input = { \"nums1\": [0,7,28,17,18], \"nums2\": [1,2,6,26,1,0,27,3,0,30] }\nassert my_solution.minSum(**test_input) == 98\n\ntest_input = { \"nums1\": [8,13,15,18,0,18,0,0,5,20,12,27,3,14,22,0], \"nums2\": [29,1,6,0,10,24,27,17,14,13,2,19,2,11] }\nassert my_solution.minSum(**test_input) == 179\n\ntest_input = { \"nums1\": [9,5], \"nums2\": [15,12,5,21,4,26,27,9,6,29,0,18,16,0,0,0,20] }\nassert my_solution.minSum(**test_input) == -1\n\ntest_input = { \"nums1\": [0,29,5,22,5,9,30,11,20,0,18,16,26,11,3,0,24,24,14,24], \"nums2\": [30,12,16,3,24,6,13,0,16] }\nassert my_solution.minSum(**test_input) == 294\n\ntest_input = { \"nums1\": [9,13,0,0,12,10,0,8,0,0,5,13,0], \"nums2\": [8,14,11,2,27,0,0] }\nassert my_solution.minSum(**test_input) == 76\n\ntest_input = { \"nums1\": [3,0,20,9,20,0,20,25,26,9,0,12,6,11,0,6], \"nums2\": [0,3,8,13,27,0,0,0,29,27,0,11,23,0,19,19,0] }\nassert my_solution.minSum(**test_input) == 186\n\ntest_input = { \"nums1\": [25,28,13,0,14,23,14,0,3,3,12], \"nums2\": [24,30,0,15,20,19,18,0,23,23,0,16,26,0,29,19,16,25] }\nassert my_solution.minSum(**test_input) == 307\n\ntest_input = { \"nums1\": [0,29,30,18,5,24,16,5,17,0,18,16,26,0,15,19,14,20,3,26], \"nums2\": [0,8,14,11,13,6,8,0,13] }\nassert my_solution.minSum(**test_input) == 304\n\ntest_input = { \"nums1\": [0,17,20,17,5,0,14,19,7,8,16,18,6], \"nums2\": [21,1,27,19,2,2,24,21,16,1,13,27,8,5,3,11,13,7,29,7] }\nassert my_solution.minSum(**test_input) == 257\n\ntest_input = { \"nums1\": [26,1,25,10,14,14,4,0,10,0,23], \"nums2\": [23,8,30,18,8,15,6,9,0,2,0,0,19,8,19,4,10] }\nassert my_solution.minSum(**test_input) == 182\n\ntest_input = { \"nums1\": [15,10,7,16], \"nums2\": [8,16,2,6,4,12,6,16,24,0] }\nassert my_solution.minSum(**test_input) == -1\n\ntest_input = { \"nums1\": [0,0,0,17,0,6,2,22,12,0,25,18,1,12,19,0,0], \"nums2\": [0,0,0,30,4,3,13,25,9,25,3,0,1,12,2,10,4,7,30,16] }\nassert my_solution.minSum(**test_input) == 198\n\ntest_input = { \"nums1\": [23,17], \"nums2\": [7,3,22,0,12] }\nassert my_solution.minSum(**test_input) == -1\n\ntest_input = { \"nums1\": [15,0,8,30,6,3,24,6,0,11,13,30,6,25,23,3], \"nums2\": [12,20,0,6,0,0,14,0,0,8,5,19,16,0,0,15] }\nassert my_solution.minSum(**test_input) == 205\n\ntest_input = { \"nums1\": [3,25,1,13], \"nums2\": [19,13,10,27,10,20,27,0,3,12,16,26,0,27] }\nassert my_solution.minSum(**test_input) == -1\n\ntest_input = { \"nums1\": [0,0], \"nums2\": [29,28] }\nassert my_solution.minSum(**test_input) == 57\n\ntest_input = { \"nums1\": [17,4,11,8,0,17,0,0,12,27,20,28,0,30,21,18,12], \"nums2\": [0,2,30,0,5,17,0,0,0,15,11,2,25,18,18] }\nassert my_solution.minSum(**test_input) == 229\n\ntest_input = { \"nums1\": [0,17,0,7,29,10,22,27,13,8,19], \"nums2\": [26,23,8,14,0,17,20,4,26,15,0,9,14,0,12,10,23,16] }\nassert my_solution.minSum(**test_input) == 240\n\ntest_input = { \"nums1\": [0,25,8,0,22,0], \"nums2\": [6,12,22,3,0,28,19,0,20,21,2,3] }\nassert my_solution.minSum(**test_input) == 138\n\ntest_input = { \"nums1\": [2,17,23,16,2,0,6,12,10], \"nums2\": [19,11,7,16,0] }\nassert my_solution.minSum(**test_input) == 89\n\ntest_input = { \"nums1\": [4,7,14,15,18,7,0,6,8], \"nums2\": [27,2,13,18,20,23,9,0,0,25,5,0,17,0,0,14] }\nassert my_solution.minSum(**test_input) == 178\n\ntest_input = { \"nums1\": [16,0,7,19,0,0,7,26,12,0,4,0,7,0,22,12,0,26], \"nums2\": [7,25,0,25,18,0,6,14,0] }\nassert my_solution.minSum(**test_input) == 165\n\ntest_input = { \"nums1\": [7,0,3,6,5,24,0,0,0,30,20,13,0,5,19,4,25,17], \"nums2\": [11,19,28,25,27,6,0,18,0,19,18,16,0,16,9,0,2,23,23,10] }\nassert my_solution.minSum(**test_input) == 274\n\ntest_input = { \"nums1\": [23,19,24,0,8,19,30,0,14], \"nums2\": [25,17,18,6,30] }\nassert my_solution.minSum(**test_input) == -1\n\ntest_input = { \"nums1\": [0,15,8,0,4,0,21,20,0,0,18], \"nums2\": [16,0] }\nassert my_solution.minSum(**test_input) == 91\n\ntest_input = { \"nums1\": [0,0,24,21,16,4,22,21], \"nums2\": [18,7,28,0,0,11,2,0] }\nassert my_solution.minSum(**test_input) == 110\n\ntest_input = { \"nums1\": [4,11,17,30,11,21,21,10,2,10,7,29,21,1,0,9,15,5], \"nums2\": [0,0,1,7,8,0,27,20] }\nassert my_solution.minSum(**test_input) == 225\n\ntest_input = { \"nums1\": [12,16,1], \"nums2\": [1,0,19,24,21,0,0,24,24,18,26,19,13,14,30,9,0,4,20] }\nassert my_solution.minSum(**test_input) == -1\n\ntest_input = { \"nums1\": [0,0,8,0], \"nums2\": [23,0,15,29,25] }\nassert my_solution.minSum(**test_input) == 93\n\ntest_input = { \"nums1\": [28,25,14,10], \"nums2\": [0,6,16,2,0,13,0,0,4,2,16,6,18,0,8,14,10] }\nassert my_solution.minSum(**test_input) == -1\n\ntest_input = { \"nums1\": [0,0,8,30,1,0,22,0,0,1,0], \"nums2\": [22,6,0,13,0,23,14,27,20,4,0,11,11,25,9,22,11,17,17] }\nassert my_solution.minSum(**test_input) == 255\n\ntest_input = { \"nums1\": [0,0,27], \"nums2\": [18,0,0,7,26,11,28,20,1,19] }\nassert my_solution.minSum(**test_input) == 132\n\ntest_input = { \"nums1\": [30,6,0,8,14,0,15,0,11,13,0,8,28,8,8,0,28,0,25], \"nums2\": [21,8,0,10,28,2,6,3,0,20,1,2,24,12,29] }\nassert my_solution.minSum(**test_input) == 208\n\ntest_input = { \"nums1\": [18,27,20,10,28,12,29,5,24,0,27,9,22,0,14,0,5,11], \"nums2\": [24,0,14,26,1,9,24,0,12,30,13,21] }\nassert my_solution.minSum(**test_input) == 264\n\ntest_input = { \"nums1\": [0,5], \"nums2\": [17,12,5,6,0,13,19,7] }\nassert my_solution.minSum(**test_input) == 80\n\ntest_input = { \"nums1\": [30,2,20,30], \"nums2\": [8,14,0,2,0,18,9,24,0,0,28,0,1,14,27] }\nassert my_solution.minSum(**test_input) == -1\n\ntest_input = { \"nums1\": [0,17,0,1,19,0,0,7,23,0,0,0,5,0], \"nums2\": [7,1,28,8,1,0,0,5,5,18,17,23] }\nassert my_solution.minSum(**test_input) == 115\n\ntest_input = { \"nums1\": [17,4,26,28,0,0,1,0,24,5,4,6,10,8,8,16,27], \"nums2\": [0,18,12,0,0,22,15] }\nassert my_solution.minSum(**test_input) == 187\n\ntest_input = { \"nums1\": [17,1,13,12,3,13], \"nums2\": [2,25] }\nassert my_solution.minSum(**test_input) == -1\n\ntest_input = { \"nums1\": [19,19,21,6,0,0,28,3], \"nums2\": [5,0,16] }\nassert my_solution.minSum(**test_input) == 98\n\ntest_input = { \"nums1\": [27,17,9,23,21,18,8,27,19,3,0,0,0,0,19], \"nums2\": [4,7,27,21,27,0,28,0,28,19,20,14,0,12,24,3] }\nassert my_solution.minSum(**test_input) == 237\n\ntest_input = { \"nums1\": [25,25,0,5,15,13,26,5,25,23,19,20,1,15], \"nums2\": [23,6] }\nassert my_solution.minSum(**test_input) == -1\n\ntest_input = { \"nums1\": [9,0,15,10,18,30,7,0,1,27,24,2,8,0], \"nums2\": [0,0,1,13,0,9,21,3,0,20] }\nassert my_solution.minSum(**test_input) == 154\n\ntest_input = { \"nums1\": [23,7,0,4,21,20,18,3,17,18,4,0,0,13,29,17], \"nums2\": [0,0,18,9,0,11,21,0] }\nassert my_solution.minSum(**test_input) == 197\n\ntest_input = { \"nums1\": [7,0,5,7,19,12,0,11,7,24,22], \"nums2\": [8,3,0,23,19,24,2,10,4,20,0,14] }\nassert my_solution.minSum(**test_input) == 129\n\ntest_input = { \"nums1\": [15,23,12,0,0,1,29,24,0,5,21,9,7,6,27,11,0,19,20], \"nums2\": [14,25,7,18] }\nassert my_solution.minSum(**test_input) == -1\n\ntest_input = { \"nums1\": [26,14,0], \"nums2\": [0,16,0,8,14,7,0,2,0,0,10,10,7,14,0,18,11] }\nassert my_solution.minSum(**test_input) == 123\n\ntest_input = { \"nums1\": [16,15,27,20,29], \"nums2\": [27,19,0,11,2,19,28,16,0,16,24,11,0,4,2,24,8] }\nassert my_solution.minSum(**test_input) == -1\n\ntest_input = { \"nums1\": [26,0,28,0,28,24,15,30,9,17,0,1,21,26,21,8,0,28,0,11], \"nums2\": [0,20,9,12,10,16,2,21,12,0,26,11,0,21,0,0,0,29,23,22] }\nassert my_solution.minSum(**test_input) == 298\n\ntest_input = { \"nums1\": [0,0,9,22,3,14,13,26,21], \"nums2\": [21,9,21,28,17,6,15,11,5,14,17,22,0,24] }\nassert my_solution.minSum(**test_input) == 211\n\ntest_input = { \"nums1\": [0,0,18,27,7,20,9,10,29], \"nums2\": [29,26,19,0,0,0,0,8,24] }\nassert my_solution.minSum(**test_input) == 122\n\ntest_input = { \"nums1\": [5,0,0,0,27,22,0,0,1,9], \"nums2\": [20,22,5,0,0,24,22,27,15] }\nassert my_solution.minSum(**test_input) == 137\n\ntest_input = { \"nums1\": [2,3,0,0,0,1,18,14,25,1,0,0,3,1,13,29,0,11,0,0], \"nums2\": [0,12,5,14,2,0,0,14,1,10,5,17,17,8,0,0,9] }\nassert my_solution.minSum(**test_input) == 129\n\ntest_input = { \"nums1\": [22,0,16,16,27,21,13,9,15,28,0,7,21,8,28,27,26,4], \"nums2\": [0,16,23,0,26,4,0,13,19,0,0,0,14,18,5,14,20,0,27] }\nassert my_solution.minSum(**test_input) == 290\n\ntest_input = { \"nums1\": [26,0,26,18,25,20,20,3,0,14,13,5,13,0,20], \"nums2\": [16,17,0,12,2,26,14,0,27,17,14,10,0,0,28,29,8,25,3,7] }\nassert my_solution.minSum(**test_input) == 259\n\ntest_input = { \"nums1\": [0,25,27,23], \"nums2\": [28,0,12,0,24,4,14,5,16,30,26,15,6,9,28,0] }\nassert my_solution.minSum(**test_input) == 220\n\ntest_input = { \"nums1\": [3,23,15,19,0,7,24,27,25,0,0,16,28,15], \"nums2\": [26,3,21,0,26,0,9,12,0,0,21,28,23,0,0,4,16,9,7] }\nassert my_solution.minSum(**test_input) == 211\n\ntest_input = { \"nums1\": [0,2,0,11,22,0,26,0,1,0,6,0,24,2,24,19,15,12], \"nums2\": [9,14,0,25,24,29,17,16,24,26,1,28,27,4,11,5,14] }\nassert my_solution.minSum(**test_input) == 275\n\ntest_input = { \"nums1\": [1,1,1], \"nums2\": [18] }\nassert my_solution.minSum(**test_input) == -1\n\ntest_input = { \"nums1\": [29,15,0,0,0,0,1,0,9,0,0], \"nums2\": [16,0,30,28,23,0,0,0,0,24,14,27,0,0] }\nassert my_solution.minSum(**test_input) == 169\n\ntest_input = { \"nums1\": [27,10,0,13,25], \"nums2\": [24,10,18,27,3,0,23,6,6] }\nassert my_solution.minSum(**test_input) == 118\n\ntest_input = { \"nums1\": [5,0,10,0,4,0,13,0,27,20,12,10,15,29], \"nums2\": [13,25,4,0,11,0,30,0,29,17,7,28,23] }\nassert my_solution.minSum(**test_input) == 190\n\ntest_input = { \"nums1\": [29,6,30,0,25,8,12,0,25,7,2,15,12,1,5,0,0,12], \"nums2\": [12,14,13,0,0,24,25,22,0,5,8,28,23,6,20,3] }\nassert my_solution.minSum(**test_input) == 206\n\ntest_input = { \"nums1\": [9,11,20,0,0,0,21,25,0,0,0,3,11,5,18], \"nums2\": [0,27,27,21,28,25,3,0,25,0,21,0,3,0,30,20,17] }\nassert my_solution.minSum(**test_input) == 252\n\ntest_input = { \"nums1\": [0,0,10,4], \"nums2\": [9,0,22,9,22,3,16,3,9,19,0,29,3,1,0,1,8,12] }\nassert my_solution.minSum(**test_input) == 169\n\ntest_input = { \"nums1\": [20,10,0,16,18,0,16,21,22,4,0,15,0,8], \"nums2\": [0,1,2,0,20] }\nassert my_solution.minSum(**test_input) == 154\n\ntest_input = { \"nums1\": [23,24,0], \"nums2\": [0,0,26,27,12,18,0] }\nassert my_solution.minSum(**test_input) == 86\n\ntest_input = { \"nums1\": [0,17,27,12,0,22], \"nums2\": [20,0] }\nassert my_solution.minSum(**test_input) == 80\n\ntest_input = { \"nums1\": [1,29], \"nums2\": [20,0,8,11,13,17,0,18,0,2,5,3,27,11,7,17] }\nassert my_solution.minSum(**test_input) == -1\n\ntest_input = { \"nums1\": [19,29,0,0,1,0,0,0,0,24,18,0,24,0,11,14,16,18], \"nums2\": [2,0,26,8,17] }\nassert my_solution.minSum(**test_input) == 182\n\ntest_input = { \"nums1\": [2,0,0,19,6,29], \"nums2\": [25,4,0,11,0,13,28,0,28,7,4,2,16,0,22] }\nassert my_solution.minSum(**test_input) == 164\n\ntest_input = { \"nums1\": [0,0], \"nums2\": [26,5,7,0,1,3,0,7,0,0,5,25,26,20,0,3,20,23,18] }\nassert my_solution.minSum(**test_input) == 194\n\ntest_input = { \"nums1\": [21,2,0,0,12,2,0,4,6,29,15,0], \"nums2\": [12,20,3,10,16,25,17,8,27,0,0,23,2,0,2,4,10,27] }\nassert my_solution.minSum(**test_input) == 209\n\ntest_input = { \"nums1\": [25,29,10,12,25,26,19,6,19,10,18], \"nums2\": [0,0,22,2,17,0,7,23,22,18,20,0,13,22,0,0,0,13,6,8] }\nassert my_solution.minSum(**test_input) == -1\n\ntest_input = { \"nums1\": [0,0,16,23,28,20,0,22,4,1,0,0,19,0,0,3,2,28], \"nums2\": [20,28] }\nassert my_solution.minSum(**test_input) == -1\n\ntest_input = { \"nums1\": [16,14,0,11,9,7,18,2,24,0,0,11,0,0,23], \"nums2\": [0,0,0,7,0,24,24,6,0,0,12,18,1,0,0] }\nassert my_solution.minSum(**test_input) == 140\n\ntest_input = { \"nums1\": [4,15,7,10,8,11,2,0,0,22,11,0,4,14,0,16,29,0,0,27], \"nums2\": [13,23,8,16] }\nassert my_solution.minSum(**test_input) == -1\n\ntest_input = { \"nums1\": [7], \"nums2\": [6,26,25,0,14,19,0,29,16,29,5,26,29,6,0,25,12,0,19,19] }\nassert my_solution.minSum(**test_input) == -1\n\ntest_input = { \"nums1\": [0,10,5,16,13,20,20,0,15,4,0,4,3,0,0,15,0,24,0], \"nums2\": [16,14,27,0,20,0,23,0,5,10,28,21,9,28,21,8,28,0,27,0] }\nassert my_solution.minSum(**test_input) == 290\n\ntest_input = { \"nums1\": [12,14,25,12,3], \"nums2\": [3,26,0,21,22] }\nassert my_solution.minSum(**test_input) == -1\n\ntest_input = { \"nums1\": [0,1,6,20,13,9,28,30,0,14,6,0,25,25,24,16,2,21], \"nums2\": [5,3,0] }\nassert my_solution.minSum(**test_input) == 243\n\ntest_input = { \"nums1\": [0,12,18,0,2,12,29,0,20,29,26,14], \"nums2\": [1,0,29,14,24] }\nassert my_solution.minSum(**test_input) == 165\n\ntest_input = { \"nums1\": [0,21,18,13,9,0,10], \"nums2\": [0,22,27,1,0,0,23,23] }\nassert my_solution.minSum(**test_input) == 99\n\ntest_input = { \"nums1\": [28,16,0,0,0,0,0,26,3,0,3,7,5,0,19,27,1,7], \"nums2\": [28,9,0,16,14] }\nassert my_solution.minSum(**test_input) == 149\n\ntest_input = { \"nums1\": [9,17,6,0,24,18,14,10,14,10,0,0,12,0,3,28,25,5,0,30], \"nums2\": [13,11,30,30,17,27,0,24,15,0,0] }\nassert my_solution.minSum(**test_input) == 230\n\ntest_input = { \"nums1\": [26,2,0,0,13,14,18,17,0], \"nums2\": [27,30,26,14,10,24,17,2,10,25,27] }\nassert my_solution.minSum(**test_input) == 212\n\ntest_input = { \"nums1\": [9,0,26], \"nums2\": [0,16] }\nassert my_solution.minSum(**test_input) == 36\n\ntest_input = { \"nums1\": [4,17,6,0,1,8,19,30,21,11,26,0,0,19,0,12], \"nums2\": [29,17,7,4,29,5,0,25,11,6,0,0,13,22] }\nassert my_solution.minSum(**test_input) == 178\n\ntest_input = { \"nums1\": [1], \"nums2\": [10,29,23,4,0,6,23,23,0,8,29,16,7,20,15,23] }\nassert my_solution.minSum(**test_input) == -1\n\ntest_input = { \"nums1\": [0,20,12,15,0,1,5,4,16,13,8,8,0,28,2,9,0,12], \"nums2\": [13,21,9,0,11,26,0,16,0,29,7,0,0,7,4,0,28,0,2] }\nassert my_solution.minSum(**test_input) == 180\n\ntest_input = { \"nums1\": [0,20,0,0,8,29,17,25,4,0,0,0,0,7,13,14], \"nums2\": [6,21,24,14,20,19,0,0,7,21,0,11,0,0,0,0,17,16,0,6] }\nassert my_solution.minSum(**test_input) == 190\n\ntest_input = { \"nums1\": [28,25,9,0,10,19,23,21,25,8,24,25,18,5], \"nums2\": [0,3,0] }\nassert my_solution.minSum(**test_input) == 241\n\ntest_input = { \"nums1\": [23,7,15,16,25,9,30,14,8,0,0,2,25,1,7,0,16,0,19], \"nums2\": [3,1,24,0,25,0,7,24,0,0,17,27,0] }\nassert my_solution.minSum(**test_input) == 221\n\ntest_input = { \"nums1\": [0,14,10,29,0,5,13,0,0,1,18,0,0,0,11,3,28,0], \"nums2\": [30,2,24,0,0,0,14,12,23,3,17,12,14,13,0,28,29,0,21] }\nassert my_solution.minSum(**test_input) == 247\n\ntest_input = { \"nums1\": [5,29], \"nums2\": [23,24] }\nassert my_solution.minSum(**test_input) == -1\n\ntest_input = { \"nums1\": [23,2,12,27,0,5,14,0,1,6,30,0,0,2,6,0,11,0], \"nums2\": [1,26,27,5,0,14,28,24,2,2,15,25,7,13,9] }\nassert my_solution.minSum(**test_input) == 199\n\ntest_input = { \"nums1\": [0,10,29,11,11,22,0,0,12,10], \"nums2\": [14,0,1,3,13,29,21] }\nassert my_solution.minSum(**test_input) == 108\n\ntest_input = { \"nums1\": [0,9,22,25,28], \"nums2\": [0,0,0,14,19,6,0,7,19,15,0,30,19,18,11,1,0,15,10,18] }\nassert my_solution.minSum(**test_input) == 208", "start_time": 1698546600} +{"task_id": "weekly-contest-369-minimum-increment-operations-to-make-array-beautiful", "url": "https://leetcode.com/problems/minimum-increment-operations-to-make-array-beautiful", "title": "minimum-increment-operations-to-make-array-beautiful", "meta": {"questionId": "3178", "questionFrontendId": "2919", "title": "Minimum Increment Operations to Make Array Beautiful", "titleSlug": "minimum-increment-operations-to-make-array-beautiful", "isPaidOnly": false, "difficulty": "Medium", "likes": 254, "dislikes": 15, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed integer array nums having length n, and an integer k.\n\nYou can perform the following increment operation any number of times (including zero):\n\n * Choose an index i in the range [0, n - 1], and increase nums[i] by 1.\n\nAn array is considered beautiful if, for any subarray with a size of 3 or more, its maximum element is greater than or equal to k.\n\nReturn an integer denoting the minimum number of increment operations needed to make nums beautiful.\n\nA subarray is a contiguous non-empty sequence of elements within an array.\n\nExample 1:\n\nInput: nums = [2,3,0,0,2], k = 4\nOutput: 3\nExplanation: We can perform the following increment operations to make nums beautiful:\nChoose index i = 1 and increase nums[1] by 1 -> [2,4,0,0,2].\nChoose index i = 4 and increase nums[4] by 1 -> [2,4,0,0,3].\nChoose index i = 4 and increase nums[4] by 1 -> [2,4,0,0,4].\nThe subarrays with a size of 3 or more are: [2,4,0], [4,0,0], [0,0,4], [2,4,0,0], [4,0,0,4], [2,4,0,0,4].\nIn all the subarrays, the maximum element is equal to k = 4, so nums is now beautiful.\nIt can be shown that nums cannot be made beautiful with fewer than 3 increment operations.\nHence, the answer is 3.\n\nExample 2:\n\nInput: nums = [0,1,3,3], k = 5\nOutput: 2\nExplanation: We can perform the following increment operations to make nums beautiful:\nChoose index i = 2 and increase nums[2] by 1 -> [0,1,4,3].\nChoose index i = 2 and increase nums[2] by 1 -> [0,1,5,3].\nThe subarrays with a size of 3 or more are: [0,1,5], [1,5,3], [0,1,5,3].\nIn all the subarrays, the maximum element is equal to k = 5, so nums is now beautiful.\nIt can be shown that nums cannot be made beautiful with fewer than 2 increment operations.\nHence, the answer is 2.\n\nExample 3:\n\nInput: nums = [1,1,2], k = 1\nOutput: 0\nExplanation: The only subarray with a size of 3 or more in this example is [1,1,2].\nThe maximum element, 2, is already greater than k = 1, so we don't need any increment operation.\nHence, the answer is 0.\n\n\nConstraints:\n\n * 3 <= n == nums.length <= 105\n * 0 <= nums[i] <= 109\n * 0 <= k <= 109\n\"\"\"\nclass Solution:\n def minIncrementOperations(self, nums: List[int], k: int) -> int:\n ", "prompt_sft": "You are given a 0-indexed integer array nums having length n, and an integer k.\n\nYou can perform the following increment operation any number of times (including zero):\n\n * Choose an index i in the range [0, n - 1], and increase nums[i] by 1.\n\nAn array is considered beautiful if, for any subarray with a size of 3 or more, its maximum element is greater than or equal to k.\n\nReturn an integer denoting the minimum number of increment operations needed to make nums beautiful.\n\nA subarray is a contiguous non-empty sequence of elements within an array.\n\nExample 1:\n\nInput: nums = [2,3,0,0,2], k = 4\nOutput: 3\nExplanation: We can perform the following increment operations to make nums beautiful:\nChoose index i = 1 and increase nums[1] by 1 -> [2,4,0,0,2].\nChoose index i = 4 and increase nums[4] by 1 -> [2,4,0,0,3].\nChoose index i = 4 and increase nums[4] by 1 -> [2,4,0,0,4].\nThe subarrays with a size of 3 or more are: [2,4,0], [4,0,0], [0,0,4], [2,4,0,0], [4,0,0,4], [2,4,0,0,4].\nIn all the subarrays, the maximum element is equal to k = 4, so nums is now beautiful.\nIt can be shown that nums cannot be made beautiful with fewer than 3 increment operations.\nHence, the answer is 3.\n\nExample 2:\n\nInput: nums = [0,1,3,3], k = 5\nOutput: 2\nExplanation: We can perform the following increment operations to make nums beautiful:\nChoose index i = 2 and increase nums[2] by 1 -> [0,1,4,3].\nChoose index i = 2 and increase nums[2] by 1 -> [0,1,5,3].\nThe subarrays with a size of 3 or more are: [0,1,5], [1,5,3], [0,1,5,3].\nIn all the subarrays, the maximum element is equal to k = 5, so nums is now beautiful.\nIt can be shown that nums cannot be made beautiful with fewer than 2 increment operations.\nHence, the answer is 2.\n\nExample 3:\n\nInput: nums = [1,1,2], k = 1\nOutput: 0\nExplanation: The only subarray with a size of 3 or more in this example is [1,1,2].\nThe maximum element, 2, is already greater than k = 1, so we don't need any increment operation.\nHence, the answer is 0.\n\n\nConstraints:\n\n * 3 <= n == nums.length <= 105\n * 0 <= nums[i] <= 109\n * 0 <= k <= 109\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def minIncrementOperations(self, nums: List[int], k: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [2,3,0,0,2], \"k\": 4 }\nassert my_solution.minIncrementOperations(**test_input) == 3\n\ntest_input = { \"nums\": [0,1,3,3], \"k\": 5 }\nassert my_solution.minIncrementOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,2], \"k\": 1 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [0,5,5], \"k\": 8 }\nassert my_solution.minIncrementOperations(**test_input) == 3\n\ntest_input = { \"nums\": [0,18,28], \"k\": 93 }\nassert my_solution.minIncrementOperations(**test_input) == 65\n\ntest_input = { \"nums\": [0,24,14], \"k\": 7 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [2,3,4], \"k\": 3 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [3,5,9], \"k\": 6 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [4,3,0], \"k\": 2 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [5,6,5], \"k\": 9 }\nassert my_solution.minIncrementOperations(**test_input) == 3\n\ntest_input = { \"nums\": [6,9,6], \"k\": 3 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [7,9,0], \"k\": 6 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [7,47,16], \"k\": 39 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [9,6,1], \"k\": 6 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [41,44,37], \"k\": 55 }\nassert my_solution.minIncrementOperations(**test_input) == 11\n\ntest_input = { \"nums\": [48,3,13], \"k\": 1 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [1,2,6,9], \"k\": 8 }\nassert my_solution.minIncrementOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,3,1,6], \"k\": 6 }\nassert my_solution.minIncrementOperations(**test_input) == 3\n\ntest_input = { \"nums\": [2,35,41,20], \"k\": 4 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [3,9,9,7], \"k\": 6 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [7,7,2,7], \"k\": 9 }\nassert my_solution.minIncrementOperations(**test_input) == 2\n\ntest_input = { \"nums\": [10,2,0,2], \"k\": 6 }\nassert my_solution.minIncrementOperations(**test_input) == 4\n\ntest_input = { \"nums\": [20,2,22,30], \"k\": 67 }\nassert my_solution.minIncrementOperations(**test_input) == 45\n\ntest_input = { \"nums\": [22,49,0,20], \"k\": 52 }\nassert my_solution.minIncrementOperations(**test_input) == 3\n\ntest_input = { \"nums\": [25,2,1,41], \"k\": 9 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [31,86,1,2], \"k\": 354 }\nassert my_solution.minIncrementOperations(**test_input) == 268\n\ntest_input = { \"nums\": [43,31,14,4], \"k\": 73 }\nassert my_solution.minIncrementOperations(**test_input) == 42\n\ntest_input = { \"nums\": [44,24,28,47], \"k\": 16 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [1,9,5,2,0], \"k\": 2 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [3,7,9,6,0], \"k\": 7 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [5,9,0,10,3], \"k\": 3 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [6,2,8,10,6], \"k\": 9 }\nassert my_solution.minIncrementOperations(**test_input) == 1\n\ntest_input = { \"nums\": [6,14,17,4,7], \"k\": 22 }\nassert my_solution.minIncrementOperations(**test_input) == 5\n\ntest_input = { \"nums\": [10,9,5,2,4], \"k\": 1 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [20,38,29,34,6], \"k\": 95 }\nassert my_solution.minIncrementOperations(**test_input) == 66\n\ntest_input = { \"nums\": [21,45,33,14,22], \"k\": 58 }\nassert my_solution.minIncrementOperations(**test_input) == 25\n\ntest_input = { \"nums\": [32,14,31,43,29], \"k\": 46 }\nassert my_solution.minIncrementOperations(**test_input) == 15\n\ntest_input = { \"nums\": [39,21,10,46,40], \"k\": 81 }\nassert my_solution.minIncrementOperations(**test_input) == 71\n\ntest_input = { \"nums\": [42,7,32,19,4], \"k\": 66 }\nassert my_solution.minIncrementOperations(**test_input) == 34\n\ntest_input = { \"nums\": [74,91,93,96,12], \"k\": 964 }\nassert my_solution.minIncrementOperations(**test_input) == 871\n\ntest_input = { \"nums\": [84,17,58,61,72], \"k\": 432 }\nassert my_solution.minIncrementOperations(**test_input) == 374\n\ntest_input = { \"nums\": [4,0,10,2,10,6], \"k\": 8 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [4,0,22,41,29,28], \"k\": 30 }\nassert my_solution.minIncrementOperations(**test_input) == 8\n\ntest_input = { \"nums\": [4,1,8,0,3,9], \"k\": 2 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [4,7,6,9,2,6], \"k\": 1 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [5,1,3,9,8,8], \"k\": 4 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [6,5,8,6,0,9], \"k\": 9 }\nassert my_solution.minIncrementOperations(**test_input) == 1\n\ntest_input = { \"nums\": [7,4,10,2,0,8], \"k\": 7 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [8,10,7,1,9,6], \"k\": 1 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [9,5,0,10,9,0], \"k\": 8 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [13,34,0,13,9,19], \"k\": 82 }\nassert my_solution.minIncrementOperations(**test_input) == 117\n\ntest_input = { \"nums\": [16,50,23,35,38,13], \"k\": 34 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [20,1,40,48,32,24], \"k\": 38 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [28,5,10,26,38,6], \"k\": 17 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [30,42,46,45,23,31], \"k\": 13 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [3,8,0,6,46,24,31], \"k\": 30 }\nassert my_solution.minIncrementOperations(**test_input) == 22\n\ntest_input = { \"nums\": [4,7,2,10,4,10,5], \"k\": 10 }\nassert my_solution.minIncrementOperations(**test_input) == 3\n\ntest_input = { \"nums\": [8,10,1,5,8,9,7], \"k\": 4 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [10,7,2,5,9,6,3], \"k\": 2 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [10,24,21,42,6,10,43], \"k\": 55 }\nassert my_solution.minIncrementOperations(**test_input) == 56\n\ntest_input = { \"nums\": [18,48,1,19,43,25,49], \"k\": 21 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [37,82,95,82,77,87,93], \"k\": 239 }\nassert my_solution.minIncrementOperations(**test_input) == 296\n\ntest_input = { \"nums\": [40,17,28,38,41,32,9], \"k\": 97 }\nassert my_solution.minIncrementOperations(**test_input) == 125\n\ntest_input = { \"nums\": [41,22,4,41,4,47,36], \"k\": 25 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [42,19,52,36,8,5,9], \"k\": 656 }\nassert my_solution.minIncrementOperations(**test_input) == 1252\n\ntest_input = { \"nums\": [45,58,6,16,70,69,87], \"k\": 26 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [48,24,41,16,4,20,38], \"k\": 97 }\nassert my_solution.minIncrementOperations(**test_input) == 133\n\ntest_input = { \"nums\": [50,3,17,36,16,10,2], \"k\": 19 }\nassert my_solution.minIncrementOperations(**test_input) == 3\n\ntest_input = { \"nums\": [57,41,90,16,41,25,2], \"k\": 934 }\nassert my_solution.minIncrementOperations(**test_input) == 1737\n\ntest_input = { \"nums\": [74,33,13,74,75,95,11], \"k\": 426 }\nassert my_solution.minIncrementOperations(**test_input) == 744\n\ntest_input = { \"nums\": [83,54,75,22,32,59,30], \"k\": 298 }\nassert my_solution.minIncrementOperations(**test_input) == 462\n\ntest_input = { \"nums\": [1,9,3,6,3,1,10,4], \"k\": 2 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [1,29,18,3,38,4,7,47], \"k\": 67 }\nassert my_solution.minIncrementOperations(**test_input) == 87\n\ntest_input = { \"nums\": [2,1,1,7,2,3,5,6], \"k\": 9 }\nassert my_solution.minIncrementOperations(**test_input) == 13\n\ntest_input = { \"nums\": [2,3,6,3,0,0,7,4], \"k\": 8 }\nassert my_solution.minIncrementOperations(**test_input) == 8\n\ntest_input = { \"nums\": [2,9,6,9,1,9,4,0], \"k\": 6 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [5,1,6,9,5,4,9,2], \"k\": 10 }\nassert my_solution.minIncrementOperations(**test_input) == 6\n\ntest_input = { \"nums\": [5,10,8,7,6,7,1,10], \"k\": 3 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [6,7,9,5,0,2,7,7], \"k\": 1 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [7,2,2,6,7,5,0,2], \"k\": 3 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [7,12,36,8,27,48,39,35], \"k\": 36 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [15,47,34,46,42,26,23,11], \"k\": 15 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [19,40,43,32,15,7,43,5], \"k\": 85 }\nassert my_solution.minIncrementOperations(**test_input) == 120\n\ntest_input = { \"nums\": [22,45,6,7,7,23,6,3], \"k\": 43 }\nassert my_solution.minIncrementOperations(**test_input) == 56\n\ntest_input = { \"nums\": [25,1,70,71,54,96,46,77], \"k\": 549 }\nassert my_solution.minIncrementOperations(**test_input) == 932\n\ntest_input = { \"nums\": [33,41,14,18,43,20,49,23], \"k\": 25 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [39,26,16,36,19,5,6,28], \"k\": 98 }\nassert my_solution.minIncrementOperations(**test_input) == 175\n\ntest_input = { \"nums\": [44,44,31,36,1,8,39,46], \"k\": 45 }\nassert my_solution.minIncrementOperations(**test_input) == 16\n\ntest_input = { \"nums\": [2,17,43,26,33,12,37,28,34], \"k\": 3 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [3,1,6,1,0,5,4,5,7], \"k\": 10 }\nassert my_solution.minIncrementOperations(**test_input) == 12\n\ntest_input = { \"nums\": [3,10,4,2,9,8,2,1,4], \"k\": 7 }\nassert my_solution.minIncrementOperations(**test_input) == 3\n\ntest_input = { \"nums\": [7,5,4,7,6,5,10,8,8], \"k\": 8 }\nassert my_solution.minIncrementOperations(**test_input) == 2\n\ntest_input = { \"nums\": [7,40,36,45,42,23,10,33,17], \"k\": 25 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [10,4,7,4,8,7,8,4,6], \"k\": 3 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [12,32,12,13,18,38,21,15,13], \"k\": 95 }\nassert my_solution.minIncrementOperations(**test_input) == 214\n\ntest_input = { \"nums\": [17,50,14,27,10,37,24,35,23], \"k\": 45 }\nassert my_solution.minIncrementOperations(**test_input) == 36\n\ntest_input = { \"nums\": [20,17,29,44,18,20,17,26,2], \"k\": 1 }\nassert my_solution.minIncrementOperations(**test_input) == 0\n\ntest_input = { \"nums\": [28,4,38,38,37,13,47,48,49], \"k\": 61 }\nassert my_solution.minIncrementOperations(**test_input) == 60\n\ntest_input = { \"nums\": [29,0,34,5,5,24,43,23,27], \"k\": 98 }\nassert my_solution.minIncrementOperations(**test_input) == 193\n\ntest_input = { \"nums\": [41,53,77,44,79,66,2,46,64], \"k\": 204 }\nassert my_solution.minIncrementOperations(**test_input) == 405", "start_time": 1698546600} +{"task_id": "weekly-contest-369-maximum-points-after-collecting-coins-from-all-nodes", "url": "https://leetcode.com/problems/maximum-points-after-collecting-coins-from-all-nodes", "title": "maximum-points-after-collecting-coins-from-all-nodes", "meta": {"questionId": "3179", "questionFrontendId": "2920", "title": "Maximum Points After Collecting Coins From All Nodes", "titleSlug": "maximum-points-after-collecting-coins-from-all-nodes", "isPaidOnly": false, "difficulty": "Hard", "likes": 161, "dislikes": 11, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nThere exists an undirected tree rooted at node 0 with n nodes labeled from 0 to n - 1. You are given a 2D integer array edges of length n - 1, where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree. You are also given a 0-indexed array coins of size n where coins[i] indicates the number of coins in the vertex i, and an integer k.\n\nStarting from the root, you have to collect all the coins such that the coins at a node can only be collected if the coins of its ancestors have been already collected.\n\nCoins at nodei can be collected in one of the following ways:\n\n * Collect all the coins, but you will get coins[i] - k points. If coins[i] - k is negative then you will lose abs(coins[i] - k) points.\n * Collect all the coins, but you will get floor(coins[i] / 2) points. If this way is used, then for all the nodej present in the subtree of nodei, coins[j] will get reduced to floor(coins[j] / 2).\n\nReturn the maximum points you can get after collecting the coins from all the tree nodes.\n\nExample 1:\n\n[https://assets.leetcode.com/uploads/2023/09/18/ex1-copy.png]\n\nInput: edges = [[0,1],[1,2],[2,3]], coins = [10,10,3,3], k = 5\nOutput: 11\nExplanation:\nCollect all the coins from node 0 using the first way. Total points = 10 - 5 = 5.\nCollect all the coins from node 1 using the first way. Total points = 5 + (10 - 5) = 10.\nCollect all the coins from node 2 using the second way so coins left at node 3 will be floor(3 / 2) = 1. Total points = 10 + floor(3 / 2) = 11.\nCollect all the coins from node 3 using the second way. Total points = 11 + floor(1 / 2) = 11.\nIt can be shown that the maximum points we can get after collecting coins from all the nodes is 11.\n\nExample 2:\n\n[https://assets.leetcode.com/uploads/2023/09/18/ex2.png]\n\nInput: edges = [[0,1],[0,2]], coins = [8,4,4], k = 0\nOutput: 16\nExplanation:\nCoins will be collected from all the nodes using the first way. Therefore, total points = (8 - 0) + (4 - 0) + (4 - 0) = 16.\n\n\nConstraints:\n\n * n == coins.length\n * 2 <= n <= 105\n * 0 <= coins[i] <= 104\n * edges.length == n - 1\n * 0 <= edges[i][0], edges[i][1] < n\n * 0 <= k <= 104\n\"\"\"\nclass Solution:\n def maximumPoints(self, edges: List[List[int]], coins: List[int], k: int) -> int:\n ", "prompt_sft": "There exists an undirected tree rooted at node 0 with n nodes labeled from 0 to n - 1. You are given a 2D integer array edges of length n - 1, where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree. You are also given a 0-indexed array coins of size n where coins[i] indicates the number of coins in the vertex i, and an integer k.\n\nStarting from the root, you have to collect all the coins such that the coins at a node can only be collected if the coins of its ancestors have been already collected.\n\nCoins at nodei can be collected in one of the following ways:\n\n * Collect all the coins, but you will get coins[i] - k points. If coins[i] - k is negative then you will lose abs(coins[i] - k) points.\n * Collect all the coins, but you will get floor(coins[i] / 2) points. If this way is used, then for all the nodej present in the subtree of nodei, coins[j] will get reduced to floor(coins[j] / 2).\n\nReturn the maximum points you can get after collecting the coins from all the tree nodes.\n\nExample 1:\n\n[https://assets.leetcode.com/uploads/2023/09/18/ex1-copy.png]\n\nInput: edges = [[0,1],[1,2],[2,3]], coins = [10,10,3,3], k = 5\nOutput: 11\nExplanation:\nCollect all the coins from node 0 using the first way. Total points = 10 - 5 = 5.\nCollect all the coins from node 1 using the first way. Total points = 5 + (10 - 5) = 10.\nCollect all the coins from node 2 using the second way so coins left at node 3 will be floor(3 / 2) = 1. Total points = 10 + floor(3 / 2) = 11.\nCollect all the coins from node 3 using the second way. Total points = 11 + floor(1 / 2) = 11.\nIt can be shown that the maximum points we can get after collecting coins from all the nodes is 11.\n\nExample 2:\n\n[https://assets.leetcode.com/uploads/2023/09/18/ex2.png]\n\nInput: edges = [[0,1],[0,2]], coins = [8,4,4], k = 0\nOutput: 16\nExplanation:\nCoins will be collected from all the nodes using the first way. Therefore, total points = (8 - 0) + (4 - 0) + (4 - 0) = 16.\n\n\nConstraints:\n\n * n == coins.length\n * 2 <= n <= 105\n * 0 <= coins[i] <= 104\n * edges.length == n - 1\n * 0 <= edges[i][0], edges[i][1] < n\n * 0 <= k <= 104\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def maximumPoints(self, edges: List[List[int]], coins: List[int], k: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"edges\": [[0,1],[1,2],[2,3]], \"coins\": [10,10,3,3], \"k\": 5 }\nassert my_solution.maximumPoints(**test_input) == 11\n\ntest_input = { \"edges\": [[0,1],[0,2]], \"coins\": [8,4,4], \"k\": 0 }\nassert my_solution.maximumPoints(**test_input) == 16\n\ntest_input = { \"edges\": [[0,1],[2,0],[0,3],[4,2]], \"coins\": [7,5,0,9,3], \"k\": 4 }\nassert my_solution.maximumPoints(**test_input) == 10\n\ntest_input = { \"edges\": [[1,0],[0,2],[1,3]], \"coins\": [9,3,8,9], \"k\": 0 }\nassert my_solution.maximumPoints(**test_input) == 29\n\ntest_input = { \"edges\": [[0,1],[0,2],[3,2],[0,4]], \"coins\": [5,6,8,7,4], \"k\": 7 }\nassert my_solution.maximumPoints(**test_input) == 8\n\ntest_input = { \"edges\": [[1,0],[2,1],[3,1]], \"coins\": [8,2,7,1], \"k\": 2 }\nassert my_solution.maximumPoints(**test_input) == 11\n\ntest_input = { \"edges\": [[0,1],[1,2],[0,3]], \"coins\": [6,1,2,3], \"k\": 2 }\nassert my_solution.maximumPoints(**test_input) == 5\n\ntest_input = { \"edges\": [[0,1],[0,2],[0,3],[2,4],[5,4],[6,0],[4,7],[8,5]], \"coins\": [2,3,10,0,0,2,7,3,9], \"k\": 2 }\nassert my_solution.maximumPoints(**test_input) == 20\n\ntest_input = { \"edges\": [[0,1],[0,2],[1,3],[3,4],[0,5],[6,3],[5,7],[3,8],[9,7]], \"coins\": [0,5,10,5,6,5,0,2,0,0], \"k\": 7 }\nassert my_solution.maximumPoints(**test_input) == 4\n\ntest_input = { \"edges\": [[0,1],[2,1],[3,0],[3,4],[5,0],[6,4],[7,1],[6,8],[9,5]], \"coins\": [9,0,9,6,7,6,5,7,1,10], \"k\": 7 }\nassert my_solution.maximumPoints(**test_input) == 14\n\ntest_input = { \"edges\": [[0,1],[2,1],[3,2],[4,0],[5,2],[3,6],[7,2],[8,4],[9,2]], \"coins\": [9,4,0,8,0,7,8,1,10,9], \"k\": 1 }\nassert my_solution.maximumPoints(**test_input) == 46\n\ntest_input = { \"edges\": [[1,0],[2,1],[3,1],[2,4],[5,4],[6,3],[6,7]], \"coins\": [9,9,5,5,7,9,6,9], \"k\": 8 }\nassert my_solution.maximumPoints(**test_input) == 10\n\ntest_input = { \"edges\": [[0,1],[2,1],[2,3],[4,0],[5,2],[6,1]], \"coins\": [1,1,8,6,9,4,1], \"k\": 10 }\nassert my_solution.maximumPoints(**test_input) == 3\n\ntest_input = { \"edges\": [[1,0],[1,2],[0,3]], \"coins\": [10,2,9,3], \"k\": 6 }\nassert my_solution.maximumPoints(**test_input) == 8\n\ntest_input = { \"edges\": [[1,0],[1,2],[1,3],[3,4],[5,3],[4,6],[7,0],[1,8],[9,1]], \"coins\": [2,10,4,0,1,3,6,10,3,6], \"k\": 8 }\nassert my_solution.maximumPoints(**test_input) == 7\n\ntest_input = { \"edges\": [[1,0],[0,2],[3,2],[4,3],[2,5],[1,6],[7,2]], \"coins\": [2,8,3,1,9,4,8,6], \"k\": 6 }\nassert my_solution.maximumPoints(**test_input) == 6\n\ntest_input = { \"edges\": [[1,0],[2,0],[3,0]], \"coins\": [0,0,0,6], \"k\": 0 }\nassert my_solution.maximumPoints(**test_input) == 6\n\ntest_input = { \"edges\": [[1,0],[1,2]], \"coins\": [7,6,0], \"k\": 6 }\nassert my_solution.maximumPoints(**test_input) == 4\n\ntest_input = { \"edges\": [[0,1],[0,2],[1,3],[2,4],[5,4]], \"coins\": [4,2,7,7,4,9], \"k\": 6 }\nassert my_solution.maximumPoints(**test_input) == 5\n\ntest_input = { \"edges\": [[0,1]], \"coins\": [10,9], \"k\": 6 }\nassert my_solution.maximumPoints(**test_input) == 8\n\ntest_input = { \"edges\": [[0,1],[2,1],[3,1],[2,4],[5,0],[6,1]], \"coins\": [6,1,8,10,0,4,10], \"k\": 5 }\nassert my_solution.maximumPoints(**test_input) == 13\n\ntest_input = { \"edges\": [[1,0],[2,0],[0,3],[0,4],[5,1],[6,4],[3,7],[5,8]], \"coins\": [9,0,4,2,0,0,3,1,8], \"k\": 5 }\nassert my_solution.maximumPoints(**test_input) == 8\n\ntest_input = { \"edges\": [[0,1],[1,2],[3,2],[4,0]], \"coins\": [7,5,6,3,6], \"k\": 8 }\nassert my_solution.maximumPoints(**test_input) == 5\n\ntest_input = { \"edges\": [[0,1],[1,2],[3,2],[4,2],[5,3],[6,1],[4,7],[7,8],[2,9]], \"coins\": [4,2,0,8,3,2,7,2,1,6], \"k\": 2 }\nassert my_solution.maximumPoints(**test_input) == 18\n\ntest_input = { \"edges\": [[0,1],[1,2],[1,3],[4,0],[3,5],[6,3],[7,6],[8,0]], \"coins\": [3,3,4,3,1,3,1,6,3], \"k\": 1 }\nassert my_solution.maximumPoints(**test_input) == 18\n\ntest_input = { \"edges\": [[1,0],[2,1],[2,3],[4,1],[4,5],[2,6]], \"coins\": [3,10,1,5,10,1,4], \"k\": 2 }\nassert my_solution.maximumPoints(**test_input) == 21\n\ntest_input = { \"edges\": [[0,1],[2,0]], \"coins\": [7,10,8], \"k\": 10 }\nassert my_solution.maximumPoints(**test_input) == 7\n\ntest_input = { \"edges\": [[1,0],[2,1],[3,1],[4,2],[5,3],[6,0],[7,4]], \"coins\": [1,1,7,10,5,1,7,8], \"k\": 7 }\nassert my_solution.maximumPoints(**test_input) == 2\n\ntest_input = { \"edges\": [[1,0],[0,2],[3,2]], \"coins\": [5,2,10,5], \"k\": 3 }\nassert my_solution.maximumPoints(**test_input) == 12\n\ntest_input = { \"edges\": [[1,0],[2,0],[3,2],[2,4],[4,5],[6,2],[5,7],[8,2]], \"coins\": [4,2,1,4,7,7,2,7,4], \"k\": 2 }\nassert my_solution.maximumPoints(**test_input) == 22\n\ntest_input = { \"edges\": [[1,0]], \"coins\": [8,1], \"k\": 7 }\nassert my_solution.maximumPoints(**test_input) == 4\n\ntest_input = { \"edges\": [[1,0],[0,2],[3,0],[3,4],[3,5],[6,0],[7,5]], \"coins\": [3,9,9,9,5,3,2,0], \"k\": 9 }\nassert my_solution.maximumPoints(**test_input) == 8\n\ntest_input = { \"edges\": [[0,1],[2,1],[3,2],[4,1],[2,5]], \"coins\": [2,10,4,6,7,9], \"k\": 5 }\nassert my_solution.maximumPoints(**test_input) == 11\n\ntest_input = { \"edges\": [[1,0],[2,1],[3,2],[3,4],[5,4],[2,6],[7,3]], \"coins\": [3,3,6,1,10,1,2,5], \"k\": 3 }\nassert my_solution.maximumPoints(**test_input) == 11\n\ntest_input = { \"edges\": [[1,0],[2,0],[0,3],[1,4],[3,5],[0,6],[7,4],[1,8]], \"coins\": [9,7,9,0,3,6,9,4,0], \"k\": 8 }\nassert my_solution.maximumPoints(**test_input) == 13\n\ntest_input = { \"edges\": [[0,1],[2,1],[3,0],[2,4],[1,5],[6,1],[7,3],[5,8]], \"coins\": [4,9,7,6,6,9,0,2,6], \"k\": 2 }\nassert my_solution.maximumPoints(**test_input) == 34\n\ntest_input = { \"edges\": [[1,0],[1,2]], \"coins\": [4,4,6], \"k\": 3 }\nassert my_solution.maximumPoints(**test_input) == 5\n\ntest_input = { \"edges\": [[0,1],[0,2],[3,1],[2,4],[4,5],[6,2],[4,7],[4,8],[9,1]], \"coins\": [8,6,10,9,3,10,3,7,9,1], \"k\": 6 }\nassert my_solution.maximumPoints(**test_input) == 21\n\ntest_input = { \"edges\": [[1,0],[2,1],[0,3],[0,4],[5,3],[6,1],[7,5],[8,2],[9,3]], \"coins\": [1,3,10,0,7,2,8,10,0,5], \"k\": 0 }\nassert my_solution.maximumPoints(**test_input) == 46\n\ntest_input = { \"edges\": [[0,1],[2,0]], \"coins\": [9,4,2], \"k\": 0 }\nassert my_solution.maximumPoints(**test_input) == 15\n\ntest_input = { \"edges\": [[0,1],[2,1]], \"coins\": [0,9,3], \"k\": 3 }\nassert my_solution.maximumPoints(**test_input) == 4\n\ntest_input = { \"edges\": [[1,0],[2,1],[3,2],[4,1],[3,5]], \"coins\": [10,10,8,6,0,0], \"k\": 1 }\nassert my_solution.maximumPoints(**test_input) == 30\n\ntest_input = { \"edges\": [[0,1],[2,0],[3,0],[3,4],[5,1],[6,1],[7,2],[8,3],[0,9]], \"coins\": [6,4,5,2,1,10,10,9,8,10], \"k\": 1 }\nassert my_solution.maximumPoints(**test_input) == 55\n\ntest_input = { \"edges\": [[0,1],[2,1],[3,2],[0,4],[1,5],[6,5],[7,1],[5,8],[1,9]], \"coins\": [8,0,9,5,9,6,2,8,1,8], \"k\": 9 }\nassert my_solution.maximumPoints(**test_input) == 10\n\ntest_input = { \"edges\": [[0,1],[2,1],[2,3],[1,4],[3,5],[6,4],[7,6]], \"coins\": [8,2,3,10,4,5,8,8], \"k\": 1 }\nassert my_solution.maximumPoints(**test_input) == 40\n\ntest_input = { \"edges\": [[0,1],[2,0],[0,3],[4,1],[5,2],[6,1],[7,1]], \"coins\": [3,9,4,4,3,4,10,4], \"k\": 2 }\nassert my_solution.maximumPoints(**test_input) == 25\n\ntest_input = { \"edges\": [[1,0],[1,2],[3,0],[4,1],[5,1],[1,6],[1,7]], \"coins\": [7,4,7,2,5,8,0,7], \"k\": 8 }\nassert my_solution.maximumPoints(**test_input) == 8\n\ntest_input = { \"edges\": [[0,1],[2,1],[3,1],[4,2],[5,4],[6,5],[7,5]], \"coins\": [4,5,7,5,0,4,6,7], \"k\": 4 }\nassert my_solution.maximumPoints(**test_input) == 8\n\ntest_input = { \"edges\": [[1,0],[1,2],[1,3]], \"coins\": [8,4,10,7], \"k\": 1 }\nassert my_solution.maximumPoints(**test_input) == 25\n\ntest_input = { \"edges\": [[0,1],[2,1],[2,3],[3,4],[4,5],[6,3],[3,7],[7,8],[9,8]], \"coins\": [0,2,1,5,8,2,5,3,7,6], \"k\": 10 }\nassert my_solution.maximumPoints(**test_input) == 0\n\ntest_input = { \"edges\": [[1,0],[1,2],[3,0],[4,3],[1,5],[6,2],[7,3],[4,8],[4,9]], \"coins\": [6,5,1,8,8,10,5,7,7,1], \"k\": 5 }\nassert my_solution.maximumPoints(**test_input) == 19\n\ntest_input = { \"edges\": [[0,1],[2,0],[2,3],[4,2],[5,0],[3,6],[7,5],[3,8],[9,8]], \"coins\": [9,6,4,10,4,1,6,1,5,9], \"k\": 6 }\nassert my_solution.maximumPoints(**test_input) == 17\n\ntest_input = { \"edges\": [[0,1],[2,1],[3,1],[0,4],[3,5]], \"coins\": [1,9,3,4,9,3], \"k\": 6 }\nassert my_solution.maximumPoints(**test_input) == 5\n\ntest_input = { \"edges\": [[0,1],[0,2]], \"coins\": [9,3,9], \"k\": 3 }\nassert my_solution.maximumPoints(**test_input) == 13\n\ntest_input = { \"edges\": [[0,1],[2,0],[3,1],[2,4],[5,2],[6,5],[7,3],[8,5],[9,5]], \"coins\": [4,1,3,1,6,1,0,0,0,6], \"k\": 1 }\nassert my_solution.maximumPoints(**test_input) == 15\n\ntest_input = { \"edges\": [[0,1]], \"coins\": [1,7], \"k\": 10 }\nassert my_solution.maximumPoints(**test_input) == 1\n\ntest_input = { \"edges\": [[0,1]], \"coins\": [10,6], \"k\": 10 }\nassert my_solution.maximumPoints(**test_input) == 6\n\ntest_input = { \"edges\": [[1,0],[1,2],[2,3],[0,4]], \"coins\": [6,7,8,1,9], \"k\": 9 }\nassert my_solution.maximumPoints(**test_input) == 7\n\ntest_input = { \"edges\": [[0,1]], \"coins\": [6,6], \"k\": 0 }\nassert my_solution.maximumPoints(**test_input) == 12\n\ntest_input = { \"edges\": [[0,1],[0,2],[0,3],[1,4],[5,4],[2,6]], \"coins\": [9,3,7,2,3,1,2], \"k\": 8 }\nassert my_solution.maximumPoints(**test_input) == 6\n\ntest_input = { \"edges\": [[1,0],[0,2],[3,1],[3,4],[2,5]], \"coins\": [4,0,3,10,5,8], \"k\": 3 }\nassert my_solution.maximumPoints(**test_input) == 12\n\ntest_input = { \"edges\": [[0,1],[2,1],[3,2],[4,1],[4,5],[5,6]], \"coins\": [3,9,2,6,1,9,1], \"k\": 10 }\nassert my_solution.maximumPoints(**test_input) == 3\n\ntest_input = { \"edges\": [[1,0]], \"coins\": [8,8], \"k\": 8 }\nassert my_solution.maximumPoints(**test_input) == 6\n\ntest_input = { \"edges\": [[0,1],[1,2],[1,3],[0,4],[5,2]], \"coins\": [2,3,7,9,7,7], \"k\": 2 }\nassert my_solution.maximumPoints(**test_input) == 23\n\ntest_input = { \"edges\": [[0,1],[2,0],[3,1],[4,0],[3,5],[2,6]], \"coins\": [6,9,7,7,7,9,7], \"k\": 8 }\nassert my_solution.maximumPoints(**test_input) == 11\n\ntest_input = { \"edges\": [[1,0],[2,1],[3,0],[0,4],[5,2],[0,6]], \"coins\": [9,4,7,9,6,2,9], \"k\": 10 }\nassert my_solution.maximumPoints(**test_input) == 13\n\ntest_input = { \"edges\": [[0,1],[1,2],[3,2],[4,2],[0,5],[6,4],[7,3]], \"coins\": [5,5,6,3,0,8,5,7], \"k\": 7 }\nassert my_solution.maximumPoints(**test_input) == 5\n\ntest_input = { \"edges\": [[1,0],[2,0],[2,3],[4,0],[5,2],[2,6],[7,3]], \"coins\": [8,3,4,5,6,1,6,9], \"k\": 6 }\nassert my_solution.maximumPoints(**test_input) == 11\n\ntest_input = { \"edges\": [[0,1],[2,0],[0,3],[4,0],[5,0],[6,1],[7,3],[8,1]], \"coins\": [1,6,3,10,1,9,7,8,7], \"k\": 5 }\nassert my_solution.maximumPoints(**test_input) == 17\n\ntest_input = { \"edges\": [[0,1],[2,0],[3,1],[3,4],[2,5],[6,4],[5,7],[5,8],[6,9]], \"coins\": [3,6,5,6,6,9,5,5,3,10], \"k\": 10 }\nassert my_solution.maximumPoints(**test_input) == 4\n\ntest_input = { \"edges\": [[0,1],[2,0],[3,2],[4,1],[4,5],[6,3],[7,2],[8,2],[3,9]], \"coins\": [2,2,0,0,4,8,8,5,0,10], \"k\": 8 }\nassert my_solution.maximumPoints(**test_input) == 1\n\ntest_input = { \"edges\": [[1,0],[0,2],[3,0],[4,3],[4,5],[6,5],[7,5]], \"coins\": [8,5,7,3,2,3,5,3], \"k\": 6 }\nassert my_solution.maximumPoints(**test_input) == 8\n\ntest_input = { \"edges\": [[0,1],[2,0]], \"coins\": [4,3,8], \"k\": 3 }\nassert my_solution.maximumPoints(**test_input) == 7\n\ntest_input = { \"edges\": [[1,0],[2,1],[3,1],[4,2],[5,0],[4,6],[7,3],[8,2]], \"coins\": [8,9,0,3,9,7,4,8,7], \"k\": 7 }\nassert my_solution.maximumPoints(**test_input) == 12\n\ntest_input = { \"edges\": [[0,1],[2,1]], \"coins\": [1,6,4], \"k\": 4 }\nassert my_solution.maximumPoints(**test_input) == 1\n\ntest_input = { \"edges\": [[0,1],[2,1],[3,1]], \"coins\": [8,9,1,0], \"k\": 3 }\nassert my_solution.maximumPoints(**test_input) == 11\n\ntest_input = { \"edges\": [[1,0],[2,1],[0,3],[4,3],[5,4],[4,6]], \"coins\": [4,1,4,4,0,5,5], \"k\": 8 }\nassert my_solution.maximumPoints(**test_input) == 3\n\ntest_input = { \"edges\": [[1,0],[2,1],[3,2],[3,4],[4,5],[6,5],[7,3]], \"coins\": [10,9,6,8,9,9,0,7], \"k\": 0 }\nassert my_solution.maximumPoints(**test_input) == 58\n\ntest_input = { \"edges\": [[0,1],[1,2],[3,1],[2,4],[3,5],[4,6],[5,7],[1,8],[2,9]], \"coins\": [9,5,7,6,2,5,0,7,5,7], \"k\": 8 }\nassert my_solution.maximumPoints(**test_input) == 8\n\ntest_input = { \"edges\": [[0,1],[1,2],[3,1]], \"coins\": [4,10,2,2], \"k\": 10 }\nassert my_solution.maximumPoints(**test_input) == 4\n\ntest_input = { \"edges\": [[1,0],[1,2],[1,3],[2,4],[3,5],[1,6],[7,4],[8,1],[0,9]], \"coins\": [6,7,1,2,3,7,3,4,8,4], \"k\": 1 }\nassert my_solution.maximumPoints(**test_input) == 35\n\ntest_input = { \"edges\": [[0,1],[2,1]], \"coins\": [4,8,10], \"k\": 6 }\nassert my_solution.maximumPoints(**test_input) == 5\n\ntest_input = { \"edges\": [[0,1],[0,2],[2,3],[2,4],[5,3],[3,6],[7,2],[8,5]], \"coins\": [7,8,4,3,4,8,10,8,1], \"k\": 7 }\nassert my_solution.maximumPoints(**test_input) == 12\n\ntest_input = { \"edges\": [[1,0],[2,1],[3,0],[4,2],[0,5]], \"coins\": [9,9,3,3,4,4], \"k\": 4 }\nassert my_solution.maximumPoints(**test_input) == 15\n\ntest_input = { \"edges\": [[0,1],[0,2],[1,3],[2,4],[5,0]], \"coins\": [7,5,0,10,0,0], \"k\": 8 }\nassert my_solution.maximumPoints(**test_input) == 5\n\ntest_input = { \"edges\": [[1,0],[2,1],[2,3],[4,2],[0,5],[6,2],[4,7],[8,5],[0,9]], \"coins\": [5,2,8,8,6,0,3,2,2,5], \"k\": 3 }\nassert my_solution.maximumPoints(**test_input) == 18\n\ntest_input = { \"edges\": [[1,0],[1,2],[3,0],[4,3],[1,5],[6,1],[7,4],[2,8]], \"coins\": [5,5,2,1,3,8,6,4,3], \"k\": 1 }\nassert my_solution.maximumPoints(**test_input) == 28\n\ntest_input = { \"edges\": [[1,0],[0,2]], \"coins\": [8,2,5], \"k\": 0 }\nassert my_solution.maximumPoints(**test_input) == 15\n\ntest_input = { \"edges\": [[1,0],[1,2],[3,2]], \"coins\": [10,9,2,0], \"k\": 7 }\nassert my_solution.maximumPoints(**test_input) == 7\n\ntest_input = { \"edges\": [[0,1],[2,0],[2,3],[0,4],[2,5],[6,4],[7,1],[8,3]], \"coins\": [10,4,4,8,9,5,5,8,1], \"k\": 0 }\nassert my_solution.maximumPoints(**test_input) == 54\n\ntest_input = { \"edges\": [[0,1],[1,2],[1,3],[2,4],[1,5],[6,2],[3,7],[8,4],[9,3]], \"coins\": [5,1,1,3,5,0,0,1,1,9], \"k\": 5 }\nassert my_solution.maximumPoints(**test_input) == 2\n\ntest_input = { \"edges\": [[0,1],[1,2],[3,1],[1,4],[5,3]], \"coins\": [1,7,1,3,3,7], \"k\": 7 }\nassert my_solution.maximumPoints(**test_input) == 1\n\ntest_input = { \"edges\": [[0,1],[1,2],[3,2],[4,3],[5,2],[0,6],[3,7],[5,8]], \"coins\": [9,1,3,2,1,3,4,2,6], \"k\": 1 }\nassert my_solution.maximumPoints(**test_input) == 22\n\ntest_input = { \"edges\": [[0,1],[0,2]], \"coins\": [5,1,5], \"k\": 10 }\nassert my_solution.maximumPoints(**test_input) == 3\n\ntest_input = { \"edges\": [[0,1],[0,2],[3,1],[1,4],[4,5]], \"coins\": [5,7,8,9,3,10], \"k\": 7 }\nassert my_solution.maximumPoints(**test_input) == 9\n\ntest_input = { \"edges\": [[0,1],[0,2],[0,3],[0,4],[0,5],[5,6],[6,7],[8,5]], \"coins\": [8,3,0,3,4,1,4,0,7], \"k\": 2 }\nassert my_solution.maximumPoints(**test_input) == 16\n\ntest_input = { \"edges\": [[1,0],[0,2],[3,0],[4,3],[2,5],[3,6]], \"coins\": [3,6,7,1,2,8,0], \"k\": 9 }\nassert my_solution.maximumPoints(**test_input) == 4\n\ntest_input = { \"edges\": [[1,0]], \"coins\": [4,0], \"k\": 9 }\nassert my_solution.maximumPoints(**test_input) == 2\n\ntest_input = { \"edges\": [[1,0],[2,0],[3,1],[4,1],[5,2],[6,1],[4,7],[5,8]], \"coins\": [9,7,8,9,6,8,9,1,6], \"k\": 1 }\nassert my_solution.maximumPoints(**test_input) == 54\n\ntest_input = { \"edges\": [[1,0],[0,2],[1,3],[0,4],[5,4],[6,0],[3,7]], \"coins\": [7,10,8,4,6,0,6,2], \"k\": 4 }\nassert my_solution.maximumPoints(**test_input) == 21", "start_time": 1698546600} +{"task_id": "biweekly-contest-116-subarrays-distinct-element-sum-of-squares-i", "url": "https://leetcode.com/problems/subarrays-distinct-element-sum-of-squares-i", "title": "subarrays-distinct-element-sum-of-squares-i", "meta": {"questionId": "3163", "questionFrontendId": "2913", "title": "Subarrays Distinct Element Sum of Squares I", "titleSlug": "subarrays-distinct-element-sum-of-squares-i", "isPaidOnly": false, "difficulty": "Easy", "likes": 82, "dislikes": 9, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed integer array nums.\n\nThe distinct count of a subarray of nums is defined as:\n\n * Let nums[i..j] be a subarray of nums consisting of all the indices from i to j such that 0 <= i <= j < nums.length. Then the number of distinct values in nums[i..j] is called the distinct count of nums[i..j].\n\nReturn the sum of the squares of distinct counts of all subarrays of nums.\n\nA subarray is a contiguous non-empty sequence of elements within an array.\n\nExample 1:\n\nInput: nums = [1,2,1]\nOutput: 15\nExplanation: Six possible subarrays are:\n[1]: 1 distinct value\n[2]: 1 distinct value\n[1]: 1 distinct value\n[1,2]: 2 distinct values\n[2,1]: 2 distinct values\n[1,2,1]: 2 distinct values\nThe sum of the squares of the distinct counts in all subarrays is equal to 12 + 12 + 12 + 22 + 22 + 22 = 15.\n\nExample 2:\n\nInput: nums = [1,1]\nOutput: 3\nExplanation: Three possible subarrays are:\n[1]: 1 distinct value\n[1]: 1 distinct value\n[1,1]: 1 distinct value\nThe sum of the squares of the distinct counts in all subarrays is equal to 12 + 12 + 12 = 3.\n\nConstraints:\n\n * 1 <= nums.length <= 100\n * 1 <= nums[i] <= 100\n\"\"\"\nclass Solution:\n def sumCounts(self, nums: List[int]) -> int:\n ", "prompt_sft": "You are given a 0-indexed integer array nums.\n\nThe distinct count of a subarray of nums is defined as:\n\n * Let nums[i..j] be a subarray of nums consisting of all the indices from i to j such that 0 <= i <= j < nums.length. Then the number of distinct values in nums[i..j] is called the distinct count of nums[i..j].\n\nReturn the sum of the squares of distinct counts of all subarrays of nums.\n\nA subarray is a contiguous non-empty sequence of elements within an array.\n\nExample 1:\n\nInput: nums = [1,2,1]\nOutput: 15\nExplanation: Six possible subarrays are:\n[1]: 1 distinct value\n[2]: 1 distinct value\n[1]: 1 distinct value\n[1,2]: 2 distinct values\n[2,1]: 2 distinct values\n[1,2,1]: 2 distinct values\nThe sum of the squares of the distinct counts in all subarrays is equal to 12 + 12 + 12 + 22 + 22 + 22 = 15.\n\nExample 2:\n\nInput: nums = [1,1]\nOutput: 3\nExplanation: Three possible subarrays are:\n[1]: 1 distinct value\n[1]: 1 distinct value\n[1,1]: 1 distinct value\nThe sum of the squares of the distinct counts in all subarrays is equal to 12 + 12 + 12 = 3.\n\nConstraints:\n\n * 1 <= nums.length <= 100\n * 1 <= nums[i] <= 100\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def sumCounts(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,2,1] }\nassert my_solution.sumCounts(**test_input) == 15\n\ntest_input = { \"nums\": [1,1] }\nassert my_solution.sumCounts(**test_input) == 3\n\ntest_input = { \"nums\": [2,2,5,5] }\nassert my_solution.sumCounts(**test_input) == 22\n\ntest_input = { \"nums\": [5,2,4,2,1,3,2,4,3,1] }\nassert my_solution.sumCounts(**test_input) == 578\n\ntest_input = { \"nums\": [2,3,2,1,2,5,3,4,5,2] }\nassert my_solution.sumCounts(**test_input) == 629\n\ntest_input = { \"nums\": [5,1,5,2,3,5,1,5,1] }\nassert my_solution.sumCounts(**test_input) == 385\n\ntest_input = { \"nums\": [4,5,4,3,4,2] }\nassert my_solution.sumCounts(**test_input) == 120\n\ntest_input = { \"nums\": [2] }\nassert my_solution.sumCounts(**test_input) == 1\n\ntest_input = { \"nums\": [3,4,2,5,2,4,1,2,2,5] }\nassert my_solution.sumCounts(**test_input) == 535\n\ntest_input = { \"nums\": [4,4,2,4,1] }\nassert my_solution.sumCounts(**test_input) == 57\n\ntest_input = { \"nums\": [2,2,5] }\nassert my_solution.sumCounts(**test_input) == 12\n\ntest_input = { \"nums\": [4,5,1,2,2,1,3,3] }\nassert my_solution.sumCounts(**test_input) == 266\n\ntest_input = { \"nums\": [3,1,5,5,2,3,2,2,1] }\nassert my_solution.sumCounts(**test_input) == 334\n\ntest_input = { \"nums\": [2,5,2,5,3,2,5,2] }\nassert my_solution.sumCounts(**test_input) == 205\n\ntest_input = { \"nums\": [5,4,1,4,5,2,4] }\nassert my_solution.sumCounts(**test_input) == 203\n\ntest_input = { \"nums\": [1,3,3,4,3,1,2,1] }\nassert my_solution.sumCounts(**test_input) == 253\n\ntest_input = { \"nums\": [4] }\nassert my_solution.sumCounts(**test_input) == 1\n\ntest_input = { \"nums\": [1,4,2,1,5,4,3,1,4] }\nassert my_solution.sumCounts(**test_input) == 507\n\ntest_input = { \"nums\": [2,4,5,3,2,5,1,5,4,4] }\nassert my_solution.sumCounts(**test_input) == 626\n\ntest_input = { \"nums\": [3,4,1,4,5,2,2] }\nassert my_solution.sumCounts(**test_input) == 220\n\ntest_input = { \"nums\": [3,5,1,1,3] }\nassert my_solution.sumCounts(**test_input) == 62\n\ntest_input = { \"nums\": [4,3,2,5,3] }\nassert my_solution.sumCounts(**test_input) == 89\n\ntest_input = { \"nums\": [2,5] }\nassert my_solution.sumCounts(**test_input) == 6\n\ntest_input = { \"nums\": [1,5,1,4,5] }\nassert my_solution.sumCounts(**test_input) == 70\n\ntest_input = { \"nums\": [5,1] }\nassert my_solution.sumCounts(**test_input) == 6\n\ntest_input = { \"nums\": [4,5,4,3,3,5,3] }\nassert my_solution.sumCounts(**test_input) == 138\n\ntest_input = { \"nums\": [5,4,3] }\nassert my_solution.sumCounts(**test_input) == 20\n\ntest_input = { \"nums\": [5,5,3,3,4,5,4,5,5] }\nassert my_solution.sumCounts(**test_input) == 234\n\ntest_input = { \"nums\": [3,1,5,5,3,4,5,5,1,4] }\nassert my_solution.sumCounts(**test_input) == 456\n\ntest_input = { \"nums\": [4,2,3,1,1] }\nassert my_solution.sumCounts(**test_input) == 81\n\ntest_input = { \"nums\": [4,5,3,1,2,5,5,3,5] }\nassert my_solution.sumCounts(**test_input) == 434\n\ntest_input = { \"nums\": [3,2,1,2,5,2,4,5,1,5] }\nassert my_solution.sumCounts(**test_input) == 531\n\ntest_input = { \"nums\": [1,3,1,4,4] }\nassert my_solution.sumCounts(**test_input) == 62\n\ntest_input = { \"nums\": [5,1,2,1,2,1,2,3,1] }\nassert my_solution.sumCounts(**test_input) == 257\n\ntest_input = { \"nums\": [2,4] }\nassert my_solution.sumCounts(**test_input) == 6\n\ntest_input = { \"nums\": [4,5,4,5] }\nassert my_solution.sumCounts(**test_input) == 28\n\ntest_input = { \"nums\": [3,1,5,5,5,4,3,3,2] }\nassert my_solution.sumCounts(**test_input) == 334\n\ntest_input = { \"nums\": [3,2,5,2,1,5,3] }\nassert my_solution.sumCounts(**test_input) == 203\n\ntest_input = { \"nums\": [4,4,2,5,5,4,2,2,1] }\nassert my_solution.sumCounts(**test_input) == 294\n\ntest_input = { \"nums\": [1] }\nassert my_solution.sumCounts(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,3,3,3,4,4] }\nassert my_solution.sumCounts(**test_input) == 96\n\ntest_input = { \"nums\": [3,2,2,3,4] }\nassert my_solution.sumCounts(**test_input) == 57\n\ntest_input = { \"nums\": [1,5,3,2,4,4] }\nassert my_solution.sumCounts(**test_input) == 161\n\ntest_input = { \"nums\": [5,4,1,1,3] }\nassert my_solution.sumCounts(**test_input) == 69\n\ntest_input = { \"nums\": [4,3,3,5,3,4,5,3,3,1] }\nassert my_solution.sumCounts(**test_input) == 376\n\ntest_input = { \"nums\": [2,3,4,1,5,1,3,3,4] }\nassert my_solution.sumCounts(**test_input) == 432\n\ntest_input = { \"nums\": [5,1,4,2,1,1] }\nassert my_solution.sumCounts(**test_input) == 129\n\ntest_input = { \"nums\": [5,4,4,1] }\nassert my_solution.sumCounts(**test_input) == 30\n\ntest_input = { \"nums\": [1,5,1,3,2,1] }\nassert my_solution.sumCounts(**test_input) == 139\n\ntest_input = { \"nums\": [5,3] }\nassert my_solution.sumCounts(**test_input) == 6\n\ntest_input = { \"nums\": [4,1,4,3] }\nassert my_solution.sumCounts(**test_input) == 38\n\ntest_input = { \"nums\": [1,5,4,3,4,2,4,5,5,4] }\nassert my_solution.sumCounts(**test_input) == 513\n\ntest_input = { \"nums\": [4,2,3,4,3,2,5,4,4] }\nassert my_solution.sumCounts(**test_input) == 378\n\ntest_input = { \"nums\": [2,3,3,2,1,5,2,2] }\nassert my_solution.sumCounts(**test_input) == 262\n\ntest_input = { \"nums\": [2,1,4,2,4,1,4,3] }\nassert my_solution.sumCounts(**test_input) == 243\n\ntest_input = { \"nums\": [1,4,4,1,3] }\nassert my_solution.sumCounts(**test_input) == 57\n\ntest_input = { \"nums\": [2,3,2,1] }\nassert my_solution.sumCounts(**test_input) == 38\n\ntest_input = { \"nums\": [1,4,2,1] }\nassert my_solution.sumCounts(**test_input) == 43\n\ntest_input = { \"nums\": [2,4,3,2,5,1] }\nassert my_solution.sumCounts(**test_input) == 169\n\ntest_input = { \"nums\": [2,5,3,2,1,3,1,3,2] }\nassert my_solution.sumCounts(**test_input) == 348\n\ntest_input = { \"nums\": [4,1] }\nassert my_solution.sumCounts(**test_input) == 6\n\ntest_input = { \"nums\": [4,3,1,4,3,4,3,4,1] }\nassert my_solution.sumCounts(**test_input) == 263\n\ntest_input = { \"nums\": [5,1,1,1,4,3] }\nassert my_solution.sumCounts(**test_input) == 89\n\ntest_input = { \"nums\": [4,5] }\nassert my_solution.sumCounts(**test_input) == 6\n\ntest_input = { \"nums\": [5,2,2,3,1,2,5,3] }\nassert my_solution.sumCounts(**test_input) == 289\n\ntest_input = { \"nums\": [3,2,4] }\nassert my_solution.sumCounts(**test_input) == 20\n\ntest_input = { \"nums\": [5,3,5,2,3,2] }\nassert my_solution.sumCounts(**test_input) == 106\n\ntest_input = { \"nums\": [3,2,1] }\nassert my_solution.sumCounts(**test_input) == 20\n\ntest_input = { \"nums\": [4,4,2,4,3] }\nassert my_solution.sumCounts(**test_input) == 57\n\ntest_input = { \"nums\": [1,4,4] }\nassert my_solution.sumCounts(**test_input) == 12\n\ntest_input = { \"nums\": [1,4,4,3,1,2,1,4,3] }\nassert my_solution.sumCounts(**test_input) == 387\n\ntest_input = { \"nums\": [1,5,4,2,5,5,5,3] }\nassert my_solution.sumCounts(**test_input) == 249\n\ntest_input = { \"nums\": [2,1,5,3] }\nassert my_solution.sumCounts(**test_input) == 50\n\ntest_input = { \"nums\": [2,3,5,1,5,2,3,2,3,4] }\nassert my_solution.sumCounts(**test_input) == 533\n\ntest_input = { \"nums\": [5,3,4,4,3,5,4,5] }\nassert my_solution.sumCounts(**test_input) == 202\n\ntest_input = { \"nums\": [4,4,2,2,4,1] }\nassert my_solution.sumCounts(**test_input) == 80\n\ntest_input = { \"nums\": [2,3] }\nassert my_solution.sumCounts(**test_input) == 6\n\ntest_input = { \"nums\": [4,2,3,2] }\nassert my_solution.sumCounts(**test_input) == 38\n\ntest_input = { \"nums\": [1,2,2] }\nassert my_solution.sumCounts(**test_input) == 12\n\ntest_input = { \"nums\": [4,1,5,1,5,4,5,1] }\nassert my_solution.sumCounts(**test_input) == 205\n\ntest_input = { \"nums\": [4,5,3,1] }\nassert my_solution.sumCounts(**test_input) == 50\n\ntest_input = { \"nums\": [4,2,3,4,2,4,3,3,2] }\nassert my_solution.sumCounts(**test_input) == 275\n\ntest_input = { \"nums\": [4,3] }\nassert my_solution.sumCounts(**test_input) == 6\n\ntest_input = { \"nums\": [1,3,5,4,4,4] }\nassert my_solution.sumCounts(**test_input) == 113\n\ntest_input = { \"nums\": [1,2,4,2,1,2,2,4,1,3] }\nassert my_solution.sumCounts(**test_input) == 391\n\ntest_input = { \"nums\": [4,2,5,3,2] }\nassert my_solution.sumCounts(**test_input) == 89\n\ntest_input = { \"nums\": [3,4,5,3,2,5] }\nassert my_solution.sumCounts(**test_input) == 144\n\ntest_input = { \"nums\": [5,4,5] }\nassert my_solution.sumCounts(**test_input) == 15\n\ntest_input = { \"nums\": [2,4,5,1] }\nassert my_solution.sumCounts(**test_input) == 50\n\ntest_input = { \"nums\": [5,4,1,4,2,1,5] }\nassert my_solution.sumCounts(**test_input) == 203\n\ntest_input = { \"nums\": [2,3,3,2,2,3,1] }\nassert my_solution.sumCounts(**test_input) == 110\n\ntest_input = { \"nums\": [1,4,2,5] }\nassert my_solution.sumCounts(**test_input) == 50\n\ntest_input = { \"nums\": [3] }\nassert my_solution.sumCounts(**test_input) == 1\n\ntest_input = { \"nums\": [5] }\nassert my_solution.sumCounts(**test_input) == 1\n\ntest_input = { \"nums\": [1,3,5,3,2,1,1,4,3] }\nassert my_solution.sumCounts(**test_input) == 441\n\ntest_input = { \"nums\": [1,5,2,2,3,3,3] }\nassert my_solution.sumCounts(**test_input) == 140\n\ntest_input = { \"nums\": [1,2,1,4,5,5,4,1,1,1] }\nassert my_solution.sumCounts(**test_input) == 407\n\ntest_input = { \"nums\": [2,2,1,1,1,2,5,4,5] }\nassert my_solution.sumCounts(**test_input) == 296\n\ntest_input = { \"nums\": [3,2,3] }\nassert my_solution.sumCounts(**test_input) == 15\n\ntest_input = { \"nums\": [2,1,5,4,3,3,2,1,5,5] }\nassert my_solution.sumCounts(**test_input) == 652", "start_time": 1698503400} +{"task_id": "biweekly-contest-116-minimum-number-of-changes-to-make-binary-string-beautiful", "url": "https://leetcode.com/problems/minimum-number-of-changes-to-make-binary-string-beautiful", "title": "minimum-number-of-changes-to-make-binary-string-beautiful", "meta": {"questionId": "3174", "questionFrontendId": "2914", "title": "Minimum Number of Changes to Make Binary String Beautiful", "titleSlug": "minimum-number-of-changes-to-make-binary-string-beautiful", "isPaidOnly": false, "difficulty": "Medium", "likes": 111, "dislikes": 4, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed binary string s having an even length.\n\nA string is beautiful if it's possible to partition it into one or more substrings such that:\n\n * Each substring has an even length.\n * Each substring contains only 1's or only 0's.\n\nYou can change any character in s to 0 or 1.\n\nReturn the minimum number of changes required to make the string s beautiful.\n\nExample 1:\n\nInput: s = \"1001\"\nOutput: 2\nExplanation: We change s[1] to 1 and s[3] to 0 to get string \"1100\".\nIt can be seen that the string \"1100\" is beautiful because we can partition it into \"11|00\".\nIt can be proven that 2 is the minimum number of changes needed to make the string beautiful.\n\nExample 2:\n\nInput: s = \"10\"\nOutput: 1\nExplanation: We change s[1] to 1 to get string \"11\".\nIt can be seen that the string \"11\" is beautiful because we can partition it into \"11\".\nIt can be proven that 1 is the minimum number of changes needed to make the string beautiful.\n\nExample 3:\n\nInput: s = \"0000\"\nOutput: 0\nExplanation: We don't need to make any changes as the string \"0000\" is beautiful already.\n\n\nConstraints:\n\n * 2 <= s.length <= 105\n * s has an even length.\n * s[i] is either '0' or '1'.\n\"\"\"\nclass Solution:\n def minChanges(self, s: str) -> int:\n ", "prompt_sft": "You are given a 0-indexed binary string s having an even length.\n\nA string is beautiful if it's possible to partition it into one or more substrings such that:\n\n * Each substring has an even length.\n * Each substring contains only 1's or only 0's.\n\nYou can change any character in s to 0 or 1.\n\nReturn the minimum number of changes required to make the string s beautiful.\n\nExample 1:\n\nInput: s = \"1001\"\nOutput: 2\nExplanation: We change s[1] to 1 and s[3] to 0 to get string \"1100\".\nIt can be seen that the string \"1100\" is beautiful because we can partition it into \"11|00\".\nIt can be proven that 2 is the minimum number of changes needed to make the string beautiful.\n\nExample 2:\n\nInput: s = \"10\"\nOutput: 1\nExplanation: We change s[1] to 1 to get string \"11\".\nIt can be seen that the string \"11\" is beautiful because we can partition it into \"11\".\nIt can be proven that 1 is the minimum number of changes needed to make the string beautiful.\n\nExample 3:\n\nInput: s = \"0000\"\nOutput: 0\nExplanation: We don't need to make any changes as the string \"0000\" is beautiful already.\n\n\nConstraints:\n\n * 2 <= s.length <= 105\n * s has an even length.\n * s[i] is either '0' or '1'.\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def minChanges(self, s: str) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"s\": \"1001\" }\nassert my_solution.minChanges(**test_input) == 2\n\ntest_input = { \"s\": \"10\" }\nassert my_solution.minChanges(**test_input) == 1\n\ntest_input = { \"s\": \"0000\" }\nassert my_solution.minChanges(**test_input) == 0\n\ntest_input = { \"s\": \"11000111\" }\nassert my_solution.minChanges(**test_input) == 1\n\ntest_input = { \"s\": \"01010001\" }\nassert my_solution.minChanges(**test_input) == 3\n\ntest_input = { \"s\": \"010010\" }\nassert my_solution.minChanges(**test_input) == 2\n\ntest_input = { \"s\": \"111111111110010001\" }\nassert my_solution.minChanges(**test_input) == 3\n\ntest_input = { \"s\": \"01010000011001001101\" }\nassert my_solution.minChanges(**test_input) == 6\n\ntest_input = { \"s\": \"011011100001110111\" }\nassert my_solution.minChanges(**test_input) == 5\n\ntest_input = { \"s\": \"1001000010111010\" }\nassert my_solution.minChanges(**test_input) == 5\n\ntest_input = { \"s\": \"0011\" }\nassert my_solution.minChanges(**test_input) == 0\n\ntest_input = { \"s\": \"11100100010010\" }\nassert my_solution.minChanges(**test_input) == 4\n\ntest_input = { \"s\": \"110100\" }\nassert my_solution.minChanges(**test_input) == 1\n\ntest_input = { \"s\": \"01\" }\nassert my_solution.minChanges(**test_input) == 1\n\ntest_input = { \"s\": \"10110010\" }\nassert my_solution.minChanges(**test_input) == 2\n\ntest_input = { \"s\": \"0010\" }\nassert my_solution.minChanges(**test_input) == 1\n\ntest_input = { \"s\": \"01000011000111\" }\nassert my_solution.minChanges(**test_input) == 2\n\ntest_input = { \"s\": \"0001110001\" }\nassert my_solution.minChanges(**test_input) == 2\n\ntest_input = { \"s\": \"000000001010100011\" }\nassert my_solution.minChanges(**test_input) == 3\n\ntest_input = { \"s\": \"100001\" }\nassert my_solution.minChanges(**test_input) == 2\n\ntest_input = { \"s\": \"10010010\" }\nassert my_solution.minChanges(**test_input) == 3\n\ntest_input = { \"s\": \"101100\" }\nassert my_solution.minChanges(**test_input) == 1\n\ntest_input = { \"s\": \"000010\" }\nassert my_solution.minChanges(**test_input) == 1\n\ntest_input = { \"s\": \"011011000001100011\" }\nassert my_solution.minChanges(**test_input) == 4\n\ntest_input = { \"s\": \"01101111\" }\nassert my_solution.minChanges(**test_input) == 2\n\ntest_input = { \"s\": \"000000011101\" }\nassert my_solution.minChanges(**test_input) == 2\n\ntest_input = { \"s\": \"011011011111111011\" }\nassert my_solution.minChanges(**test_input) == 4\n\ntest_input = { \"s\": \"110011\" }\nassert my_solution.minChanges(**test_input) == 0\n\ntest_input = { \"s\": \"1111101111101011\" }\nassert my_solution.minChanges(**test_input) == 3\n\ntest_input = { \"s\": \"11000101011001100110\" }\nassert my_solution.minChanges(**test_input) == 8\n\ntest_input = { \"s\": \"101101101110110010\" }\nassert my_solution.minChanges(**test_input) == 5\n\ntest_input = { \"s\": \"11011110\" }\nassert my_solution.minChanges(**test_input) == 2\n\ntest_input = { \"s\": \"1011100101\" }\nassert my_solution.minChanges(**test_input) == 4\n\ntest_input = { \"s\": \"0011000101001000\" }\nassert my_solution.minChanges(**test_input) == 3\n\ntest_input = { \"s\": \"00\" }\nassert my_solution.minChanges(**test_input) == 0\n\ntest_input = { \"s\": \"10110111010001000010\" }\nassert my_solution.minChanges(**test_input) == 5\n\ntest_input = { \"s\": \"0101\" }\nassert my_solution.minChanges(**test_input) == 2\n\ntest_input = { \"s\": \"0010101100\" }\nassert my_solution.minChanges(**test_input) == 2\n\ntest_input = { \"s\": \"11001110101001\" }\nassert my_solution.minChanges(**test_input) == 4\n\ntest_input = { \"s\": \"010101000011011111\" }\nassert my_solution.minChanges(**test_input) == 4\n\ntest_input = { \"s\": \"0010111010000001\" }\nassert my_solution.minChanges(**test_input) == 4\n\ntest_input = { \"s\": \"0000010101\" }\nassert my_solution.minChanges(**test_input) == 3\n\ntest_input = { \"s\": \"10100011101010\" }\nassert my_solution.minChanges(**test_input) == 5\n\ntest_input = { \"s\": \"101111\" }\nassert my_solution.minChanges(**test_input) == 1\n\ntest_input = { \"s\": \"11\" }\nassert my_solution.minChanges(**test_input) == 0\n\ntest_input = { \"s\": \"110110\" }\nassert my_solution.minChanges(**test_input) == 2\n\ntest_input = { \"s\": \"001001110111010101\" }\nassert my_solution.minChanges(**test_input) == 6\n\ntest_input = { \"s\": \"11110011\" }\nassert my_solution.minChanges(**test_input) == 0\n\ntest_input = { \"s\": \"1100000101101110\" }\nassert my_solution.minChanges(**test_input) == 4\n\ntest_input = { \"s\": \"111010\" }\nassert my_solution.minChanges(**test_input) == 2\n\ntest_input = { \"s\": \"100000100010011100\" }\nassert my_solution.minChanges(**test_input) == 4\n\ntest_input = { \"s\": \"0111\" }\nassert my_solution.minChanges(**test_input) == 1\n\ntest_input = { \"s\": \"0100110011111101\" }\nassert my_solution.minChanges(**test_input) == 2\n\ntest_input = { \"s\": \"010111\" }\nassert my_solution.minChanges(**test_input) == 2\n\ntest_input = { \"s\": \"000100\" }\nassert my_solution.minChanges(**test_input) == 1\n\ntest_input = { \"s\": \"00110111000111110001\" }\nassert my_solution.minChanges(**test_input) == 3\n\ntest_input = { \"s\": \"01010010\" }\nassert my_solution.minChanges(**test_input) == 3\n\ntest_input = { \"s\": \"01110101001001\" }\nassert my_solution.minChanges(**test_input) == 5\n\ntest_input = { \"s\": \"00111100010111\" }\nassert my_solution.minChanges(**test_input) == 2\n\ntest_input = { \"s\": \"001110\" }\nassert my_solution.minChanges(**test_input) == 1\n\ntest_input = { \"s\": \"00010101111101\" }\nassert my_solution.minChanges(**test_input) == 4\n\ntest_input = { \"s\": \"111011\" }\nassert my_solution.minChanges(**test_input) == 1\n\ntest_input = { \"s\": \"011110\" }\nassert my_solution.minChanges(**test_input) == 2\n\ntest_input = { \"s\": \"1010\" }\nassert my_solution.minChanges(**test_input) == 2\n\ntest_input = { \"s\": \"011101010011101011\" }\nassert my_solution.minChanges(**test_input) == 5\n\ntest_input = { \"s\": \"1001110001111100\" }\nassert my_solution.minChanges(**test_input) == 3\n\ntest_input = { \"s\": \"011000101100\" }\nassert my_solution.minChanges(**test_input) == 3\n\ntest_input = { \"s\": \"1110111000111111\" }\nassert my_solution.minChanges(**test_input) == 2\n\ntest_input = { \"s\": \"1110\" }\nassert my_solution.minChanges(**test_input) == 1\n\ntest_input = { \"s\": \"10110110\" }\nassert my_solution.minChanges(**test_input) == 3\n\ntest_input = { \"s\": \"1000\" }\nassert my_solution.minChanges(**test_input) == 1\n\ntest_input = { \"s\": \"0111110110\" }\nassert my_solution.minChanges(**test_input) == 3\n\ntest_input = { \"s\": \"011000011101\" }\nassert my_solution.minChanges(**test_input) == 4\n\ntest_input = { \"s\": \"0100101000010101\" }\nassert my_solution.minChanges(**test_input) == 6\n\ntest_input = { \"s\": \"0100001100\" }\nassert my_solution.minChanges(**test_input) == 1\n\ntest_input = { \"s\": \"100010010010110001\" }\nassert my_solution.minChanges(**test_input) == 5\n\ntest_input = { \"s\": \"101001111001111001\" }\nassert my_solution.minChanges(**test_input) == 7\n\ntest_input = { \"s\": \"111001\" }\nassert my_solution.minChanges(**test_input) == 2\n\ntest_input = { \"s\": \"111010001000\" }\nassert my_solution.minChanges(**test_input) == 3\n\ntest_input = { \"s\": \"0110\" }\nassert my_solution.minChanges(**test_input) == 2\n\ntest_input = { \"s\": \"11011010\" }\nassert my_solution.minChanges(**test_input) == 3\n\ntest_input = { \"s\": \"100111\" }\nassert my_solution.minChanges(**test_input) == 2\n\ntest_input = { \"s\": \"11000110000001\" }\nassert my_solution.minChanges(**test_input) == 3\n\ntest_input = { \"s\": \"010111010011011000\" }\nassert my_solution.minChanges(**test_input) == 5\n\ntest_input = { \"s\": \"000101\" }\nassert my_solution.minChanges(**test_input) == 2\n\ntest_input = { \"s\": \"000010101010101011\" }\nassert my_solution.minChanges(**test_input) == 6\n\ntest_input = { \"s\": \"11011000\" }\nassert my_solution.minChanges(**test_input) == 2\n\ntest_input = { \"s\": \"010101\" }\nassert my_solution.minChanges(**test_input) == 3\n\ntest_input = { \"s\": \"10011010110110101100\" }\nassert my_solution.minChanges(**test_input) == 7\n\ntest_input = { \"s\": \"10100011\" }\nassert my_solution.minChanges(**test_input) == 2\n\ntest_input = { \"s\": \"11010100000000\" }\nassert my_solution.minChanges(**test_input) == 2\n\ntest_input = { \"s\": \"101100101111010011\" }\nassert my_solution.minChanges(**test_input) == 3\n\ntest_input = { \"s\": \"110111111100\" }\nassert my_solution.minChanges(**test_input) == 1\n\ntest_input = { \"s\": \"111110110100\" }\nassert my_solution.minChanges(**test_input) == 2\n\ntest_input = { \"s\": \"011110110101010100\" }\nassert my_solution.minChanges(**test_input) == 6\n\ntest_input = { \"s\": \"000111\" }\nassert my_solution.minChanges(**test_input) == 1\n\ntest_input = { \"s\": \"00000010001101\" }\nassert my_solution.minChanges(**test_input) == 2\n\ntest_input = { \"s\": \"01111001101001\" }\nassert my_solution.minChanges(**test_input) == 6\n\ntest_input = { \"s\": \"010110011101\" }\nassert my_solution.minChanges(**test_input) == 5\n\ntest_input = { \"s\": \"0111011101\" }\nassert my_solution.minChanges(**test_input) == 3", "start_time": 1698503400} +{"task_id": "biweekly-contest-116-length-of-the-longest-subsequence-that-sums-to-target", "url": "https://leetcode.com/problems/length-of-the-longest-subsequence-that-sums-to-target", "title": "length-of-the-longest-subsequence-that-sums-to-target", "meta": {"questionId": "3106", "questionFrontendId": "2915", "title": "Length of the Longest Subsequence That Sums to Target", "titleSlug": "length-of-the-longest-subsequence-that-sums-to-target", "isPaidOnly": false, "difficulty": "Medium", "likes": 141, "dislikes": 19, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed array of integers nums, and an integer target.\n\nReturn the length of the longest subsequence of nums that sums up to target. If no such subsequence exists, return -1.\n\nA subsequence is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining elements.\n\nExample 1:\n\nInput: nums = [1,2,3,4,5], target = 9\nOutput: 3\nExplanation: There are 3 subsequences with a sum equal to 9: [4,5], [1,3,5], and [2,3,4]. The longest subsequences are [1,3,5], and [2,3,4]. Hence, the answer is 3.\n\nExample 2:\n\nInput: nums = [4,1,3,2,1,5], target = 7\nOutput: 4\nExplanation: There are 5 subsequences with a sum equal to 7: [4,3], [4,1,2], [4,2,1], [1,1,5], and [1,3,2,1]. The longest subsequence is [1,3,2,1]. Hence, the answer is 4.\n\nExample 3:\n\nInput: nums = [1,1,5,4,5], target = 3\nOutput: -1\nExplanation: It can be shown that nums has no subsequence that sums up to 3.\n\n\nConstraints:\n\n * 1 <= nums.length <= 1000\n * 1 <= nums[i] <= 1000\n * 1 <= target <= 1000\n\"\"\"\nclass Solution:\n def lengthOfLongestSubsequence(self, nums: List[int], target: int) -> int:\n ", "prompt_sft": "You are given a 0-indexed array of integers nums, and an integer target.\n\nReturn the length of the longest subsequence of nums that sums up to target. If no such subsequence exists, return -1.\n\nA subsequence is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining elements.\n\nExample 1:\n\nInput: nums = [1,2,3,4,5], target = 9\nOutput: 3\nExplanation: There are 3 subsequences with a sum equal to 9: [4,5], [1,3,5], and [2,3,4]. The longest subsequences are [1,3,5], and [2,3,4]. Hence, the answer is 3.\n\nExample 2:\n\nInput: nums = [4,1,3,2,1,5], target = 7\nOutput: 4\nExplanation: There are 5 subsequences with a sum equal to 7: [4,3], [4,1,2], [4,2,1], [1,1,5], and [1,3,2,1]. The longest subsequence is [1,3,2,1]. Hence, the answer is 4.\n\nExample 3:\n\nInput: nums = [1,1,5,4,5], target = 3\nOutput: -1\nExplanation: It can be shown that nums has no subsequence that sums up to 3.\n\n\nConstraints:\n\n * 1 <= nums.length <= 1000\n * 1 <= nums[i] <= 1000\n * 1 <= target <= 1000\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def lengthOfLongestSubsequence(self, nums: List[int], target: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,2,3,4,5], \"target\": 9 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 3\n\ntest_input = { \"nums\": [4,1,3,2,1,5], \"target\": 7 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 4\n\ntest_input = { \"nums\": [1,1,5,4,5], \"target\": 3 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == -1\n\ntest_input = { \"nums\": [1000], \"target\": 12 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == -1\n\ntest_input = { \"nums\": [1000], \"target\": 1000 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 1\n\ntest_input = { \"nums\": [1,2], \"target\": 10 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == -1\n\ntest_input = { \"nums\": [1,1000], \"target\": 5 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == -1\n\ntest_input = { \"nums\": [2,3], \"target\": 3 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 1\n\ntest_input = { \"nums\": [2,3], \"target\": 5 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 2\n\ntest_input = { \"nums\": [2,3,5], \"target\": 5 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 2\n\ntest_input = { \"nums\": [1,3,3,7], \"target\": 1000 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == -1\n\ntest_input = { \"nums\": [1,3,3,7], \"target\": 2 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == -1\n\ntest_input = { \"nums\": [1,3,3,8], \"target\": 7 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,2,1], \"target\": 2 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,1,1], \"target\": 5 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,1,2], \"target\": 3 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 3\n\ntest_input = { \"nums\": [9,12,8,4,11,13,15,7,5], \"target\": 84 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 9\n\ntest_input = { \"nums\": [11,5,9,11,12,13,12,5,1,8], \"target\": 87 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 10\n\ntest_input = { \"nums\": [9,11,11,15,4,14,3,2,13,7], \"target\": 89 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 10\n\ntest_input = { \"nums\": [11,13,6,13,10], \"target\": 53 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 5\n\ntest_input = { \"nums\": [10,3,5,11,6,12], \"target\": 47 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 6\n\ntest_input = { \"nums\": [13,3,6,6,6,15,4], \"target\": 53 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 7\n\ntest_input = { \"nums\": [1,6,15,6,14,13,14], \"target\": 69 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 7\n\ntest_input = { \"nums\": [10,7,8,14,15], \"target\": 54 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 5\n\ntest_input = { \"nums\": [14,15,8,10,8,7], \"target\": 62 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 6\n\ntest_input = { \"nums\": [7,9,14,14,9,14,5,12,10], \"target\": 94 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 9\n\ntest_input = { \"nums\": [1,10,6,14,5,13,3,7,10,10], \"target\": 79 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 10\n\ntest_input = { \"nums\": [5,2,8,6,7,12,13,4,1], \"target\": 58 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 9\n\ntest_input = { \"nums\": [12,8,2,4,1], \"target\": 27 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 5\n\ntest_input = { \"nums\": [10,14,11,13,2,11], \"target\": 61 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 6\n\ntest_input = { \"nums\": [10,2,13,5,7,15], \"target\": 52 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 6\n\ntest_input = { \"nums\": [3,1,10,1,10,1,2,9,5,13], \"target\": 55 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 10\n\ntest_input = { \"nums\": [5,13,2,13,9,4,5,7], \"target\": 58 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 8\n\ntest_input = { \"nums\": [1,15,5,12,13,10,14,8], \"target\": 78 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 8\n\ntest_input = { \"nums\": [7,4,14,10,13], \"target\": 48 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 5\n\ntest_input = { \"nums\": [6,14,14,6,2,9,1,4,10], \"target\": 66 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 9\n\ntest_input = { \"nums\": [14,15,7,5,7,10,6,14,10,11], \"target\": 99 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 10\n\ntest_input = { \"nums\": [15,13,8,8,6], \"target\": 50 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 5\n\ntest_input = { \"nums\": [2,6,8,9,13,3], \"target\": 41 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 6\n\ntest_input = { \"nums\": [13,15,9,3,8,1,9,2,15,5], \"target\": 80 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 10\n\ntest_input = { \"nums\": [5,13,9,11,6,1], \"target\": 45 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 6\n\ntest_input = { \"nums\": [7,10,15,7,14,2], \"target\": 55 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 6\n\ntest_input = { \"nums\": [12,14,13,13,13], \"target\": 65 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 5\n\ntest_input = { \"nums\": [12,8,7,9,3,10,3,8,2], \"target\": 62 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 9\n\ntest_input = { \"nums\": [11,1,14,13,14,4,14,11], \"target\": 82 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 8\n\ntest_input = { \"nums\": [5,9,11,2,5,2,7,11,5,3], \"target\": 60 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 10\n\ntest_input = { \"nums\": [5,15,3,13,14,15,10], \"target\": 75 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 7\n\ntest_input = { \"nums\": [10,8,2,2,9], \"target\": 31 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 5\n\ntest_input = { \"nums\": [7,15,4,3,9,15,12,1,12], \"target\": 78 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 9\n\ntest_input = { \"nums\": [3,1,12,15,5,10], \"target\": 46 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 6\n\ntest_input = { \"nums\": [5,3,12,7,5,2,12,10,12,5], \"target\": 73 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 10\n\ntest_input = { \"nums\": [6,10,3,1,7,11,9,8,13,12], \"target\": 80 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 10\n\ntest_input = { \"nums\": [11,3,4,11,9], \"target\": 38 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 5\n\ntest_input = { \"nums\": [15,12,12,13,6,6,4,1], \"target\": 69 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 8\n\ntest_input = { \"nums\": [9,2,10,7,10,11,14,11,8], \"target\": 82 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 9\n\ntest_input = { \"nums\": [4,4,3,9,6,8,4,7,7], \"target\": 52 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 9\n\ntest_input = { \"nums\": [10,14,4,15,9,5], \"target\": 57 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 6\n\ntest_input = { \"nums\": [4,13,2,3,13,11,8,6], \"target\": 60 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 8\n\ntest_input = { \"nums\": [1,7,8,14,15,9,8,10,13,7], \"target\": 92 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 10\n\ntest_input = { \"nums\": [7,7,6,14,7,4], \"target\": 45 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 6\n\ntest_input = { \"nums\": [9,10,9,7,14,3,6,4,6], \"target\": 68 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 9\n\ntest_input = { \"nums\": [15,13,14,5,7,13,11,14], \"target\": 92 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 8\n\ntest_input = { \"nums\": [1,1,10,12,5,6,15,6,8], \"target\": 64 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 9\n\ntest_input = { \"nums\": [14,13,13,11,14,13,8], \"target\": 86 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 7\n\ntest_input = { \"nums\": [3,14,4,2,10,3,7], \"target\": 43 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 7\n\ntest_input = { \"nums\": [6,1,3,11,9,2,10,6,12], \"target\": 60 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 9\n\ntest_input = { \"nums\": [6,2,5,4,12], \"target\": 29 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 5\n\ntest_input = { \"nums\": [7,11,15,1,9,9,11], \"target\": 63 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 7\n\ntest_input = { \"nums\": [7,12,10,15,6,15,14,2], \"target\": 81 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 8\n\ntest_input = { \"nums\": [12,3,10,12,13,3,4,7,15], \"target\": 79 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 9\n\ntest_input = { \"nums\": [14,6,11,2,10,1,12,9,2], \"target\": 67 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 9\n\ntest_input = { \"nums\": [5,8,12,6,15,13,11], \"target\": 70 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 7\n\ntest_input = { \"nums\": [11,6,1,6,2,6,15], \"target\": 47 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 7\n\ntest_input = { \"nums\": [12,7,15,10,5,4,7,12,12], \"target\": 84 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 9\n\ntest_input = { \"nums\": [11,4,4,9,10,7,12], \"target\": 57 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 7\n\ntest_input = { \"nums\": [4,12,15,6,15,1,4,4,2], \"target\": 63 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 9\n\ntest_input = { \"nums\": [3,13,4,15,1], \"target\": 36 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 5\n\ntest_input = { \"nums\": [14,3,7,14,7,7,1,6], \"target\": 59 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 8\n\ntest_input = { \"nums\": [15,13,1,14,6,8], \"target\": 57 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 6\n\ntest_input = { \"nums\": [14,2,3,10,15], \"target\": 44 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 5\n\ntest_input = { \"nums\": [5,5,3,7,12,10,11], \"target\": 53 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 7\n\ntest_input = { \"nums\": [3,7,3,5,3,14,8], \"target\": 43 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 7\n\ntest_input = { \"nums\": [5,7,9,14,9,14,4,1,4], \"target\": 67 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 9\n\ntest_input = { \"nums\": [12,7,8,6,3,9,7,3,4,4], \"target\": 63 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 10\n\ntest_input = { \"nums\": [9,12,1,4,9,6,15,9,7], \"target\": 72 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 9\n\ntest_input = { \"nums\": [9,13,12,10,4,9,9,4,4,13], \"target\": 87 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 10\n\ntest_input = { \"nums\": [13,5,6,8,2,13,1,5,6], \"target\": 59 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 9\n\ntest_input = { \"nums\": [7,9,8,9,9,3,5], \"target\": 50 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 7\n\ntest_input = { \"nums\": [15,1,14,8,2,1,10,15,15], \"target\": 81 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 9\n\ntest_input = { \"nums\": [13,14,1,9,12,2], \"target\": 51 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 6\n\ntest_input = { \"nums\": [13,12,12,13,8,11,3,14,13], \"target\": 99 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 9\n\ntest_input = { \"nums\": [2,2,1,12,10,7,11,5,5], \"target\": 55 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 9\n\ntest_input = { \"nums\": [13,10,3,4,10,3], \"target\": 43 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 6\n\ntest_input = { \"nums\": [8,9,1,5,8,7,6,8], \"target\": 52 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 8\n\ntest_input = { \"nums\": [10,1,4,10,9,13,14], \"target\": 61 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 7\n\ntest_input = { \"nums\": [3,14,11,4,7,9,7,6,8,11], \"target\": 80 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 10\n\ntest_input = { \"nums\": [4,11,6,6,14,12,2,9,1], \"target\": 65 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 9\n\ntest_input = { \"nums\": [9,2,15,12,15,6,4,12], \"target\": 75 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 8\n\ntest_input = { \"nums\": [4,3,5,3,2], \"target\": 17 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 5\n\ntest_input = { \"nums\": [4,3,13,6,9], \"target\": 35 }\nassert my_solution.lengthOfLongestSubsequence(**test_input) == 5", "start_time": 1698503400} +{"task_id": "biweekly-contest-116-subarrays-distinct-element-sum-of-squares-ii", "url": "https://leetcode.com/problems/subarrays-distinct-element-sum-of-squares-ii", "title": "subarrays-distinct-element-sum-of-squares-ii", "meta": {"questionId": "3139", "questionFrontendId": "2916", "title": "Subarrays Distinct Element Sum of Squares II", "titleSlug": "subarrays-distinct-element-sum-of-squares-ii", "isPaidOnly": false, "difficulty": "Hard", "likes": 115, "dislikes": 6, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed integer array nums.\n\nThe distinct count of a subarray of nums is defined as:\n\n * Let nums[i..j] be a subarray of nums consisting of all the indices from i to j such that 0 <= i <= j < nums.length. Then the number of distinct values in nums[i..j] is called the distinct count of nums[i..j].\n\nReturn the sum of the squares of distinct counts of all subarrays of nums.\n\nSince the answer may be very large, return it modulo 109 + 7.\n\nA subarray is a contiguous non-empty sequence of elements within an array.\n\nExample 1:\n\nInput: nums = [1,2,1]\nOutput: 15\nExplanation: Six possible subarrays are:\n[1]: 1 distinct value\n[2]: 1 distinct value\n[1]: 1 distinct value\n[1,2]: 2 distinct values\n[2,1]: 2 distinct values\n[1,2,1]: 2 distinct values\nThe sum of the squares of the distinct counts in all subarrays is equal to 12 + 12 + 12 + 22 + 22 + 22 = 15.\n\nExample 2:\n\nInput: nums = [2,2]\nOutput: 3\nExplanation: Three possible subarrays are:\n[2]: 1 distinct value\n[2]: 1 distinct value\n[2,2]: 1 distinct value\nThe sum of the squares of the distinct counts in all subarrays is equal to 12 + 12 + 12 = 3.\n\nConstraints:\n\n * 1 <= nums.length <= 105\n * 1 <= nums[i] <= 105\n\"\"\"\nclass Solution:\n def sumCounts(self, nums: List[int]) -> int:\n ", "prompt_sft": "You are given a 0-indexed integer array nums.\n\nThe distinct count of a subarray of nums is defined as:\n\n * Let nums[i..j] be a subarray of nums consisting of all the indices from i to j such that 0 <= i <= j < nums.length. Then the number of distinct values in nums[i..j] is called the distinct count of nums[i..j].\n\nReturn the sum of the squares of distinct counts of all subarrays of nums.\n\nSince the answer may be very large, return it modulo 109 + 7.\n\nA subarray is a contiguous non-empty sequence of elements within an array.\n\nExample 1:\n\nInput: nums = [1,2,1]\nOutput: 15\nExplanation: Six possible subarrays are:\n[1]: 1 distinct value\n[2]: 1 distinct value\n[1]: 1 distinct value\n[1,2]: 2 distinct values\n[2,1]: 2 distinct values\n[1,2,1]: 2 distinct values\nThe sum of the squares of the distinct counts in all subarrays is equal to 12 + 12 + 12 + 22 + 22 + 22 = 15.\n\nExample 2:\n\nInput: nums = [2,2]\nOutput: 3\nExplanation: Three possible subarrays are:\n[2]: 1 distinct value\n[2]: 1 distinct value\n[2,2]: 1 distinct value\nThe sum of the squares of the distinct counts in all subarrays is equal to 12 + 12 + 12 = 3.\n\nConstraints:\n\n * 1 <= nums.length <= 105\n * 1 <= nums[i] <= 105\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def sumCounts(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,2,1] }\nassert my_solution.sumCounts(**test_input) == 15\n\ntest_input = { \"nums\": [2,2] }\nassert my_solution.sumCounts(**test_input) == 3\n\ntest_input = { \"nums\": [2,2,5,5] }\nassert my_solution.sumCounts(**test_input) == 22\n\ntest_input = { \"nums\": [5,2,4,2,1,3,2,4,3,1] }\nassert my_solution.sumCounts(**test_input) == 578\n\ntest_input = { \"nums\": [2,3,2,1,2,5,3,4,5,2] }\nassert my_solution.sumCounts(**test_input) == 629\n\ntest_input = { \"nums\": [5,1,5,2,3,5,1,5,1] }\nassert my_solution.sumCounts(**test_input) == 385\n\ntest_input = { \"nums\": [4,5,4,3,4,2] }\nassert my_solution.sumCounts(**test_input) == 120\n\ntest_input = { \"nums\": [2] }\nassert my_solution.sumCounts(**test_input) == 1\n\ntest_input = { \"nums\": [3,4,2,5,2,4,1,2,2,5] }\nassert my_solution.sumCounts(**test_input) == 535\n\ntest_input = { \"nums\": [4,4,2,4,1] }\nassert my_solution.sumCounts(**test_input) == 57\n\ntest_input = { \"nums\": [2,2,5] }\nassert my_solution.sumCounts(**test_input) == 12\n\ntest_input = { \"nums\": [4,5,1,2,2,1,3,3] }\nassert my_solution.sumCounts(**test_input) == 266\n\ntest_input = { \"nums\": [3,1,5,5,2,3,2,2,1] }\nassert my_solution.sumCounts(**test_input) == 334\n\ntest_input = { \"nums\": [2,5,2,5,3,2,5,2] }\nassert my_solution.sumCounts(**test_input) == 205\n\ntest_input = { \"nums\": [5,4,1,4,5,2,4] }\nassert my_solution.sumCounts(**test_input) == 203\n\ntest_input = { \"nums\": [1,3,3,4,3,1,2,1] }\nassert my_solution.sumCounts(**test_input) == 253\n\ntest_input = { \"nums\": [4] }\nassert my_solution.sumCounts(**test_input) == 1\n\ntest_input = { \"nums\": [1,4,2,1,5,4,3,1,4] }\nassert my_solution.sumCounts(**test_input) == 507\n\ntest_input = { \"nums\": [2,4,5,3,2,5,1,5,4,4] }\nassert my_solution.sumCounts(**test_input) == 626\n\ntest_input = { \"nums\": [3,4,1,4,5,2,2] }\nassert my_solution.sumCounts(**test_input) == 220\n\ntest_input = { \"nums\": [3,5,1,1,3] }\nassert my_solution.sumCounts(**test_input) == 62\n\ntest_input = { \"nums\": [4,3,2,5,3] }\nassert my_solution.sumCounts(**test_input) == 89\n\ntest_input = { \"nums\": [2,5] }\nassert my_solution.sumCounts(**test_input) == 6\n\ntest_input = { \"nums\": [1,5,1,4,5] }\nassert my_solution.sumCounts(**test_input) == 70\n\ntest_input = { \"nums\": [5,1] }\nassert my_solution.sumCounts(**test_input) == 6\n\ntest_input = { \"nums\": [4,5,4,3,3,5,3] }\nassert my_solution.sumCounts(**test_input) == 138\n\ntest_input = { \"nums\": [5,4,3] }\nassert my_solution.sumCounts(**test_input) == 20\n\ntest_input = { \"nums\": [5,5,3,3,4,5,4,5,5] }\nassert my_solution.sumCounts(**test_input) == 234\n\ntest_input = { \"nums\": [3,1,5,5,3,4,5,5,1,4] }\nassert my_solution.sumCounts(**test_input) == 456\n\ntest_input = { \"nums\": [4,2,3,1,1] }\nassert my_solution.sumCounts(**test_input) == 81\n\ntest_input = { \"nums\": [4,5,3,1,2,5,5,3,5] }\nassert my_solution.sumCounts(**test_input) == 434\n\ntest_input = { \"nums\": [3,2,1,2,5,2,4,5,1,5] }\nassert my_solution.sumCounts(**test_input) == 531\n\ntest_input = { \"nums\": [1,3,1,4,4] }\nassert my_solution.sumCounts(**test_input) == 62\n\ntest_input = { \"nums\": [5,1,2,1,2,1,2,3,1] }\nassert my_solution.sumCounts(**test_input) == 257\n\ntest_input = { \"nums\": [2,4] }\nassert my_solution.sumCounts(**test_input) == 6\n\ntest_input = { \"nums\": [4,5,4,5] }\nassert my_solution.sumCounts(**test_input) == 28\n\ntest_input = { \"nums\": [3,1,5,5,5,4,3,3,2] }\nassert my_solution.sumCounts(**test_input) == 334\n\ntest_input = { \"nums\": [3,2,5,2,1,5,3] }\nassert my_solution.sumCounts(**test_input) == 203\n\ntest_input = { \"nums\": [4,4,2,5,5,4,2,2,1] }\nassert my_solution.sumCounts(**test_input) == 294\n\ntest_input = { \"nums\": [1] }\nassert my_solution.sumCounts(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,3,3,3,4,4] }\nassert my_solution.sumCounts(**test_input) == 96\n\ntest_input = { \"nums\": [3,2,2,3,4] }\nassert my_solution.sumCounts(**test_input) == 57\n\ntest_input = { \"nums\": [1,5,3,2,4,4] }\nassert my_solution.sumCounts(**test_input) == 161\n\ntest_input = { \"nums\": [5,4,1,1,3] }\nassert my_solution.sumCounts(**test_input) == 69\n\ntest_input = { \"nums\": [4,3,3,5,3,4,5,3,3,1] }\nassert my_solution.sumCounts(**test_input) == 376\n\ntest_input = { \"nums\": [2,3,4,1,5,1,3,3,4] }\nassert my_solution.sumCounts(**test_input) == 432\n\ntest_input = { \"nums\": [5,1,4,2,1,1] }\nassert my_solution.sumCounts(**test_input) == 129\n\ntest_input = { \"nums\": [5,4,4,1] }\nassert my_solution.sumCounts(**test_input) == 30\n\ntest_input = { \"nums\": [1,5,1,3,2,1] }\nassert my_solution.sumCounts(**test_input) == 139\n\ntest_input = { \"nums\": [5,3] }\nassert my_solution.sumCounts(**test_input) == 6\n\ntest_input = { \"nums\": [4,1,4,3] }\nassert my_solution.sumCounts(**test_input) == 38\n\ntest_input = { \"nums\": [1,5,4,3,4,2,4,5,5,4] }\nassert my_solution.sumCounts(**test_input) == 513\n\ntest_input = { \"nums\": [4,2,3,4,3,2,5,4,4] }\nassert my_solution.sumCounts(**test_input) == 378\n\ntest_input = { \"nums\": [2,3,3,2,1,5,2,2] }\nassert my_solution.sumCounts(**test_input) == 262\n\ntest_input = { \"nums\": [2,1,4,2,4,1,4,3] }\nassert my_solution.sumCounts(**test_input) == 243\n\ntest_input = { \"nums\": [1,4,4,1,3] }\nassert my_solution.sumCounts(**test_input) == 57\n\ntest_input = { \"nums\": [2,3,2,1] }\nassert my_solution.sumCounts(**test_input) == 38\n\ntest_input = { \"nums\": [1,4,2,1] }\nassert my_solution.sumCounts(**test_input) == 43\n\ntest_input = { \"nums\": [2,4,3,2,5,1] }\nassert my_solution.sumCounts(**test_input) == 169\n\ntest_input = { \"nums\": [2,5,3,2,1,3,1,3,2] }\nassert my_solution.sumCounts(**test_input) == 348\n\ntest_input = { \"nums\": [4,1] }\nassert my_solution.sumCounts(**test_input) == 6\n\ntest_input = { \"nums\": [4,3,1,4,3,4,3,4,1] }\nassert my_solution.sumCounts(**test_input) == 263\n\ntest_input = { \"nums\": [5,1,1,1,4,3] }\nassert my_solution.sumCounts(**test_input) == 89\n\ntest_input = { \"nums\": [4,5] }\nassert my_solution.sumCounts(**test_input) == 6\n\ntest_input = { \"nums\": [5,2,2,3,1,2,5,3] }\nassert my_solution.sumCounts(**test_input) == 289\n\ntest_input = { \"nums\": [3,2,4] }\nassert my_solution.sumCounts(**test_input) == 20\n\ntest_input = { \"nums\": [5,3,5,2,3,2] }\nassert my_solution.sumCounts(**test_input) == 106\n\ntest_input = { \"nums\": [3,2,1] }\nassert my_solution.sumCounts(**test_input) == 20\n\ntest_input = { \"nums\": [4,4,2,4,3] }\nassert my_solution.sumCounts(**test_input) == 57\n\ntest_input = { \"nums\": [1,4,4] }\nassert my_solution.sumCounts(**test_input) == 12\n\ntest_input = { \"nums\": [1,4,4,3,1,2,1,4,3] }\nassert my_solution.sumCounts(**test_input) == 387\n\ntest_input = { \"nums\": [1,5,4,2,5,5,5,3] }\nassert my_solution.sumCounts(**test_input) == 249\n\ntest_input = { \"nums\": [2,1,5,3] }\nassert my_solution.sumCounts(**test_input) == 50\n\ntest_input = { \"nums\": [2,3,5,1,5,2,3,2,3,4] }\nassert my_solution.sumCounts(**test_input) == 533\n\ntest_input = { \"nums\": [5,3,4,4,3,5,4,5] }\nassert my_solution.sumCounts(**test_input) == 202\n\ntest_input = { \"nums\": [4,4,2,2,4,1] }\nassert my_solution.sumCounts(**test_input) == 80\n\ntest_input = { \"nums\": [2,3] }\nassert my_solution.sumCounts(**test_input) == 6\n\ntest_input = { \"nums\": [4,2,3,2] }\nassert my_solution.sumCounts(**test_input) == 38\n\ntest_input = { \"nums\": [1,2,2] }\nassert my_solution.sumCounts(**test_input) == 12\n\ntest_input = { \"nums\": [4,1,5,1,5,4,5,1] }\nassert my_solution.sumCounts(**test_input) == 205\n\ntest_input = { \"nums\": [4,5,3,1] }\nassert my_solution.sumCounts(**test_input) == 50\n\ntest_input = { \"nums\": [4,2,3,4,2,4,3,3,2] }\nassert my_solution.sumCounts(**test_input) == 275\n\ntest_input = { \"nums\": [4,3] }\nassert my_solution.sumCounts(**test_input) == 6\n\ntest_input = { \"nums\": [1,3,5,4,4,4] }\nassert my_solution.sumCounts(**test_input) == 113\n\ntest_input = { \"nums\": [1,2,4,2,1,2,2,4,1,3] }\nassert my_solution.sumCounts(**test_input) == 391\n\ntest_input = { \"nums\": [4,2,5,3,2] }\nassert my_solution.sumCounts(**test_input) == 89\n\ntest_input = { \"nums\": [3,4,5,3,2,5] }\nassert my_solution.sumCounts(**test_input) == 144\n\ntest_input = { \"nums\": [5,4,5] }\nassert my_solution.sumCounts(**test_input) == 15\n\ntest_input = { \"nums\": [2,4,5,1] }\nassert my_solution.sumCounts(**test_input) == 50\n\ntest_input = { \"nums\": [5,4,1,4,2,1,5] }\nassert my_solution.sumCounts(**test_input) == 203\n\ntest_input = { \"nums\": [2,3,3,2,2,3,1] }\nassert my_solution.sumCounts(**test_input) == 110\n\ntest_input = { \"nums\": [1,4,2,5] }\nassert my_solution.sumCounts(**test_input) == 50\n\ntest_input = { \"nums\": [3] }\nassert my_solution.sumCounts(**test_input) == 1\n\ntest_input = { \"nums\": [5] }\nassert my_solution.sumCounts(**test_input) == 1\n\ntest_input = { \"nums\": [1,3,5,3,2,1,1,4,3] }\nassert my_solution.sumCounts(**test_input) == 441\n\ntest_input = { \"nums\": [1,5,2,2,3,3,3] }\nassert my_solution.sumCounts(**test_input) == 140\n\ntest_input = { \"nums\": [1,2,1,4,5,5,4,1,1,1] }\nassert my_solution.sumCounts(**test_input) == 407\n\ntest_input = { \"nums\": [2,2,1,1,1,2,5,4,5] }\nassert my_solution.sumCounts(**test_input) == 296\n\ntest_input = { \"nums\": [3,2,3] }\nassert my_solution.sumCounts(**test_input) == 15\n\ntest_input = { \"nums\": [2,1,5,4,3,3,2,1,5,5] }\nassert my_solution.sumCounts(**test_input) == 652", "start_time": 1698503400} +{"task_id": "weekly-contest-368-minimum-sum-of-mountain-triplets-i", "url": "https://leetcode.com/problems/minimum-sum-of-mountain-triplets-i", "title": "minimum-sum-of-mountain-triplets-i", "meta": {"questionId": "3176", "questionFrontendId": "2908", "title": "Minimum Sum of Mountain Triplets I", "titleSlug": "minimum-sum-of-mountain-triplets-i", "isPaidOnly": false, "difficulty": "Easy", "likes": 113, "dislikes": 3, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed array nums of integers.\n\nA triplet of indices (i, j, k) is a mountain if:\n\n * i < j < k\n * nums[i] < nums[j] and nums[k] < nums[j]\n\nReturn the minimum possible sum of a mountain triplet of nums. If no such triplet exists, return -1.\n\nExample 1:\n\nInput: nums = [8,6,1,5,3]\nOutput: 9\nExplanation: Triplet (2, 3, 4) is a mountain triplet of sum 9 since:\n- 2 < 3 < 4\n- nums[2] < nums[3] and nums[4] < nums[3]\nAnd the sum of this triplet is nums[2] + nums[3] + nums[4] = 9. It can be shown that there are no mountain triplets with a sum of less than 9.\n\nExample 2:\n\nInput: nums = [5,4,8,7,10,2]\nOutput: 13\nExplanation: Triplet (1, 3, 5) is a mountain triplet of sum 13 since:\n- 1 < 3 < 5\n- nums[1] < nums[3] and nums[5] < nums[3]\nAnd the sum of this triplet is nums[1] + nums[3] + nums[5] = 13. It can be shown that there are no mountain triplets with a sum of less than 13.\n\nExample 3:\n\nInput: nums = [6,5,4,3,4,5]\nOutput: -1\nExplanation: It can be shown that there are no mountain triplets in nums.\n\n\nConstraints:\n\n * 3 <= nums.length <= 50\n * 1 <= nums[i] <= 50\n\"\"\"\nclass Solution:\n def minimumSum(self, nums: List[int]) -> int:\n ", "prompt_sft": "You are given a 0-indexed array nums of integers.\n\nA triplet of indices (i, j, k) is a mountain if:\n\n * i < j < k\n * nums[i] < nums[j] and nums[k] < nums[j]\n\nReturn the minimum possible sum of a mountain triplet of nums. If no such triplet exists, return -1.\n\nExample 1:\n\nInput: nums = [8,6,1,5,3]\nOutput: 9\nExplanation: Triplet (2, 3, 4) is a mountain triplet of sum 9 since:\n- 2 < 3 < 4\n- nums[2] < nums[3] and nums[4] < nums[3]\nAnd the sum of this triplet is nums[2] + nums[3] + nums[4] = 9. It can be shown that there are no mountain triplets with a sum of less than 9.\n\nExample 2:\n\nInput: nums = [5,4,8,7,10,2]\nOutput: 13\nExplanation: Triplet (1, 3, 5) is a mountain triplet of sum 13 since:\n- 1 < 3 < 5\n- nums[1] < nums[3] and nums[5] < nums[3]\nAnd the sum of this triplet is nums[1] + nums[3] + nums[5] = 13. It can be shown that there are no mountain triplets with a sum of less than 13.\n\nExample 3:\n\nInput: nums = [6,5,4,3,4,5]\nOutput: -1\nExplanation: It can be shown that there are no mountain triplets in nums.\n\n\nConstraints:\n\n * 3 <= nums.length <= 50\n * 1 <= nums[i] <= 50\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def minimumSum(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [8,6,1,5,3] }\nassert my_solution.minimumSum(**test_input) == 9\n\ntest_input = { \"nums\": [5,4,8,7,10,2] }\nassert my_solution.minimumSum(**test_input) == 13\n\ntest_input = { \"nums\": [6,5,4,3,4,5] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [50,50,50] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [49,50,48] }\nassert my_solution.minimumSum(**test_input) == 147\n\ntest_input = { \"nums\": [48,50,49] }\nassert my_solution.minimumSum(**test_input) == 147\n\ntest_input = { \"nums\": [1,1,1] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,2] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,3] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,2,1] }\nassert my_solution.minimumSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,2] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,2,3] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,3,1] }\nassert my_solution.minimumSum(**test_input) == 5\n\ntest_input = { \"nums\": [1,3,2] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,3,3] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [2,1,1] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [2,1,2] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [2,1,3] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [2,2,1] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [2,2,2] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [2,2,3] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [2,3,1] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [2,3,2] }\nassert my_solution.minimumSum(**test_input) == 7\n\ntest_input = { \"nums\": [2,3,3] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [3,1,1] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [3,1,2] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [3,1,3] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [3,2,1] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [3,2,2] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [3,2,3] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [3,3,1] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [3,3,2] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [3,3,3] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,1,1] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,1,2] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,1,3] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,1,4] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,2,1] }\nassert my_solution.minimumSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,1,2,2] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,2,3] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,2,4] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,3,1] }\nassert my_solution.minimumSum(**test_input) == 5\n\ntest_input = { \"nums\": [1,1,3,2] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,1,3,3] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,3,4] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,4,1] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,1,4,2] }\nassert my_solution.minimumSum(**test_input) == 7\n\ntest_input = { \"nums\": [1,1,4,3] }\nassert my_solution.minimumSum(**test_input) == 8\n\ntest_input = { \"nums\": [1,1,4,4] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,2,1,1] }\nassert my_solution.minimumSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,1,2] }\nassert my_solution.minimumSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,1,3] }\nassert my_solution.minimumSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,1,4] }\nassert my_solution.minimumSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,2,1] }\nassert my_solution.minimumSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,2,2] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,2,2,3] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,2,2,4] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,2,3,1] }\nassert my_solution.minimumSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,3,2] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,2,3,3] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,2,3,4] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,2,4,1] }\nassert my_solution.minimumSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,4,2] }\nassert my_solution.minimumSum(**test_input) == 7\n\ntest_input = { \"nums\": [1,2,4,3] }\nassert my_solution.minimumSum(**test_input) == 8\n\ntest_input = { \"nums\": [1,2,4,4] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,3,1,1] }\nassert my_solution.minimumSum(**test_input) == 5\n\ntest_input = { \"nums\": [1,3,1,2] }\nassert my_solution.minimumSum(**test_input) == 5\n\ntest_input = { \"nums\": [1,3,1,3] }\nassert my_solution.minimumSum(**test_input) == 5\n\ntest_input = { \"nums\": [1,3,1,4] }\nassert my_solution.minimumSum(**test_input) == 5\n\ntest_input = { \"nums\": [1,3,2,1] }\nassert my_solution.minimumSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,3,2,2] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,3,2,3] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,3,2,4] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,3,3,1] }\nassert my_solution.minimumSum(**test_input) == 5\n\ntest_input = { \"nums\": [1,3,3,2] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,3,3,3] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,3,3,4] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,3,4,1] }\nassert my_solution.minimumSum(**test_input) == 5\n\ntest_input = { \"nums\": [1,3,4,2] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,3,4,3] }\nassert my_solution.minimumSum(**test_input) == 8\n\ntest_input = { \"nums\": [1,3,4,4] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,4,1,1] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,4,1,2] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,4,1,3] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,4,1,4] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,4,2,1] }\nassert my_solution.minimumSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,4,2,2] }\nassert my_solution.minimumSum(**test_input) == 7\n\ntest_input = { \"nums\": [1,4,2,3] }\nassert my_solution.minimumSum(**test_input) == 7\n\ntest_input = { \"nums\": [1,4,2,4] }\nassert my_solution.minimumSum(**test_input) == 7\n\ntest_input = { \"nums\": [1,4,3,1] }\nassert my_solution.minimumSum(**test_input) == 5\n\ntest_input = { \"nums\": [1,4,3,2] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,4,3,3] }\nassert my_solution.minimumSum(**test_input) == 8\n\ntest_input = { \"nums\": [1,4,3,4] }\nassert my_solution.minimumSum(**test_input) == 8\n\ntest_input = { \"nums\": [1,4,4,1] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,4,4,2] }\nassert my_solution.minimumSum(**test_input) == 7\n\ntest_input = { \"nums\": [1,4,4,3] }\nassert my_solution.minimumSum(**test_input) == 8\n\ntest_input = { \"nums\": [1,4,4,4] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [2,1,1,1] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [2,1,1,2] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [2,1,1,3] }\nassert my_solution.minimumSum(**test_input) == -1", "start_time": 1697941800} +{"task_id": "weekly-contest-368-minimum-sum-of-mountain-triplets-ii", "url": "https://leetcode.com/problems/minimum-sum-of-mountain-triplets-ii", "title": "minimum-sum-of-mountain-triplets-ii", "meta": {"questionId": "3186", "questionFrontendId": "2909", "title": "Minimum Sum of Mountain Triplets II", "titleSlug": "minimum-sum-of-mountain-triplets-ii", "isPaidOnly": false, "difficulty": "Medium", "likes": 160, "dislikes": 4, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed array nums of integers.\n\nA triplet of indices (i, j, k) is a mountain if:\n\n * i < j < k\n * nums[i] < nums[j] and nums[k] < nums[j]\n\nReturn the minimum possible sum of a mountain triplet of nums. If no such triplet exists, return -1.\n\nExample 1:\n\nInput: nums = [8,6,1,5,3]\nOutput: 9\nExplanation: Triplet (2, 3, 4) is a mountain triplet of sum 9 since:\n- 2 < 3 < 4\n- nums[2] < nums[3] and nums[4] < nums[3]\nAnd the sum of this triplet is nums[2] + nums[3] + nums[4] = 9. It can be shown that there are no mountain triplets with a sum of less than 9.\n\nExample 2:\n\nInput: nums = [5,4,8,7,10,2]\nOutput: 13\nExplanation: Triplet (1, 3, 5) is a mountain triplet of sum 13 since:\n- 1 < 3 < 5\n- nums[1] < nums[3] and nums[5] < nums[3]\nAnd the sum of this triplet is nums[1] + nums[3] + nums[5] = 13. It can be shown that there are no mountain triplets with a sum of less than 13.\n\nExample 3:\n\nInput: nums = [6,5,4,3,4,5]\nOutput: -1\nExplanation: It can be shown that there are no mountain triplets in nums.\n\n\nConstraints:\n\n * 3 <= nums.length <= 105\n * 1 <= nums[i] <= 108\n\"\"\"\nclass Solution:\n def minimumSum(self, nums: List[int]) -> int:\n ", "prompt_sft": "You are given a 0-indexed array nums of integers.\n\nA triplet of indices (i, j, k) is a mountain if:\n\n * i < j < k\n * nums[i] < nums[j] and nums[k] < nums[j]\n\nReturn the minimum possible sum of a mountain triplet of nums. If no such triplet exists, return -1.\n\nExample 1:\n\nInput: nums = [8,6,1,5,3]\nOutput: 9\nExplanation: Triplet (2, 3, 4) is a mountain triplet of sum 9 since:\n- 2 < 3 < 4\n- nums[2] < nums[3] and nums[4] < nums[3]\nAnd the sum of this triplet is nums[2] + nums[3] + nums[4] = 9. It can be shown that there are no mountain triplets with a sum of less than 9.\n\nExample 2:\n\nInput: nums = [5,4,8,7,10,2]\nOutput: 13\nExplanation: Triplet (1, 3, 5) is a mountain triplet of sum 13 since:\n- 1 < 3 < 5\n- nums[1] < nums[3] and nums[5] < nums[3]\nAnd the sum of this triplet is nums[1] + nums[3] + nums[5] = 13. It can be shown that there are no mountain triplets with a sum of less than 13.\n\nExample 3:\n\nInput: nums = [6,5,4,3,4,5]\nOutput: -1\nExplanation: It can be shown that there are no mountain triplets in nums.\n\n\nConstraints:\n\n * 3 <= nums.length <= 105\n * 1 <= nums[i] <= 108\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def minimumSum(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [8,6,1,5,3] }\nassert my_solution.minimumSum(**test_input) == 9\n\ntest_input = { \"nums\": [5,4,8,7,10,2] }\nassert my_solution.minimumSum(**test_input) == 13\n\ntest_input = { \"nums\": [6,5,4,3,4,5] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [50,50,50] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [49,50,48] }\nassert my_solution.minimumSum(**test_input) == 147\n\ntest_input = { \"nums\": [48,50,49] }\nassert my_solution.minimumSum(**test_input) == 147\n\ntest_input = { \"nums\": [99999999,100000000,99999999] }\nassert my_solution.minimumSum(**test_input) == 299999998\n\ntest_input = { \"nums\": [1,1,1] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,2] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,3] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,2,1] }\nassert my_solution.minimumSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,2] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,2,3] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,3,1] }\nassert my_solution.minimumSum(**test_input) == 5\n\ntest_input = { \"nums\": [1,3,2] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,3,3] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [2,1,1] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [2,1,2] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [2,1,3] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [2,2,1] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [2,2,2] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [2,2,3] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [2,3,1] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [2,3,2] }\nassert my_solution.minimumSum(**test_input) == 7\n\ntest_input = { \"nums\": [2,3,3] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [3,1,1] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [3,1,2] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [3,1,3] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [3,2,1] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [3,2,2] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [3,2,3] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [3,3,1] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [3,3,2] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [3,3,3] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,1,1] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,1,2] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,1,3] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,1,4] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,2,1] }\nassert my_solution.minimumSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,1,2,2] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,2,3] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,2,4] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,3,1] }\nassert my_solution.minimumSum(**test_input) == 5\n\ntest_input = { \"nums\": [1,1,3,2] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,1,3,3] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,3,4] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,4,1] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,1,4,2] }\nassert my_solution.minimumSum(**test_input) == 7\n\ntest_input = { \"nums\": [1,1,4,3] }\nassert my_solution.minimumSum(**test_input) == 8\n\ntest_input = { \"nums\": [1,1,4,4] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,2,3,2] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,2,1,1] }\nassert my_solution.minimumSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,1,2] }\nassert my_solution.minimumSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,1,3] }\nassert my_solution.minimumSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,1,4] }\nassert my_solution.minimumSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,2,1] }\nassert my_solution.minimumSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,2,2] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,2,2,3] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,2,2,4] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,2,3,1] }\nassert my_solution.minimumSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,3,3] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,2,3,4] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,2,4,1] }\nassert my_solution.minimumSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,4,2] }\nassert my_solution.minimumSum(**test_input) == 7\n\ntest_input = { \"nums\": [1,2,4,3] }\nassert my_solution.minimumSum(**test_input) == 8\n\ntest_input = { \"nums\": [1,2,4,4] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,3,1,1] }\nassert my_solution.minimumSum(**test_input) == 5\n\ntest_input = { \"nums\": [1,3,1,2] }\nassert my_solution.minimumSum(**test_input) == 5\n\ntest_input = { \"nums\": [1,3,1,3] }\nassert my_solution.minimumSum(**test_input) == 5\n\ntest_input = { \"nums\": [1,3,1,4] }\nassert my_solution.minimumSum(**test_input) == 5\n\ntest_input = { \"nums\": [1,3,2,1] }\nassert my_solution.minimumSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,3,2,2] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,3,2,3] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,3,2,4] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,3,3,1] }\nassert my_solution.minimumSum(**test_input) == 5\n\ntest_input = { \"nums\": [1,3,3,2] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,3,3,3] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,3,3,4] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,3,4,1] }\nassert my_solution.minimumSum(**test_input) == 5\n\ntest_input = { \"nums\": [1,3,4,2] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,3,4,3] }\nassert my_solution.minimumSum(**test_input) == 8\n\ntest_input = { \"nums\": [1,3,4,4] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [1,4,1,1] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,4,1,2] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,4,1,3] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,4,1,4] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,4,2,1] }\nassert my_solution.minimumSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,4,2,2] }\nassert my_solution.minimumSum(**test_input) == 7\n\ntest_input = { \"nums\": [1,4,2,3] }\nassert my_solution.minimumSum(**test_input) == 7\n\ntest_input = { \"nums\": [1,4,2,4] }\nassert my_solution.minimumSum(**test_input) == 7\n\ntest_input = { \"nums\": [1,4,3,1] }\nassert my_solution.minimumSum(**test_input) == 5\n\ntest_input = { \"nums\": [1,4,3,2] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,4,3,3] }\nassert my_solution.minimumSum(**test_input) == 8\n\ntest_input = { \"nums\": [1,4,3,4] }\nassert my_solution.minimumSum(**test_input) == 8\n\ntest_input = { \"nums\": [1,4,4,1] }\nassert my_solution.minimumSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,4,4,2] }\nassert my_solution.minimumSum(**test_input) == 7\n\ntest_input = { \"nums\": [1,4,4,3] }\nassert my_solution.minimumSum(**test_input) == 8\n\ntest_input = { \"nums\": [1,4,4,4] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [2,1,1,1] }\nassert my_solution.minimumSum(**test_input) == -1\n\ntest_input = { \"nums\": [2,1,1,2] }\nassert my_solution.minimumSum(**test_input) == -1", "start_time": 1697941800} +{"task_id": "weekly-contest-368-minimum-number-of-groups-to-create-a-valid-assignment", "url": "https://leetcode.com/problems/minimum-number-of-groups-to-create-a-valid-assignment", "title": "minimum-number-of-groups-to-create-a-valid-assignment", "meta": {"questionId": "3166", "questionFrontendId": "2910", "title": "Minimum Number of Groups to Create a Valid Assignment", "titleSlug": "minimum-number-of-groups-to-create-a-valid-assignment", "isPaidOnly": false, "difficulty": "Medium", "likes": 231, "dislikes": 151, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed integer array nums of length n.\n\nWe want to group the indices so for each index i in the range [0, n - 1], it is assigned to exactly one group.\n\nA group assignment is valid if the following conditions hold:\n\n * For every group g, all indices i assigned to group g have the same value in nums.\n * For any two groups g1 and g2, the difference between the number of indices assigned to g1 and g2 should not exceed 1.\n\nReturn an integer denoting the minimum number of groups needed to create a valid group assignment.\n\nExample 1:\n\nInput: nums = [3,2,3,2,3]\nOutput: 2\nExplanation: One way the indices can be assigned to 2 groups is as follows, where the values in square brackets are indices:\ngroup 1 -> [0,2,4]\ngroup 2 -> [1,3]\nAll indices are assigned to one group.\nIn group 1, nums[0] == nums[2] == nums[4], so all indices have the same value.\nIn group 2, nums[1] == nums[3], so all indices have the same value.\nThe number of indices assigned to group 1 is 3, and the number of indices assigned to group 2 is 2.\nTheir difference doesn't exceed 1.\nIt is not possible to use fewer than 2 groups because, in order to use just 1 group, all indices assigned to that group must have the same value.\nHence, the answer is 2.\n\nExample 2:\n\nInput: nums = [10,10,10,3,1,1]\nOutput: 4\nExplanation: One way the indices can be assigned to 4 groups is as follows, where the values in square brackets are indices:\ngroup 1 -> [0]\ngroup 2 -> [1,2]\ngroup 3 -> [3]\ngroup 4 -> [4,5]\nThe group assignment above satisfies both conditions.\nIt can be shown that it is not possible to create a valid assignment using fewer than 4 groups.\nHence, the answer is 4.\n\nConstraints:\n\n * 1 <= nums.length <= 105\n * 1 <= nums[i] <= 109\n\"\"\"\nclass Solution:\n def minGroupsForValidAssignment(self, nums: List[int]) -> int:\n ", "prompt_sft": "You are given a 0-indexed integer array nums of length n.\n\nWe want to group the indices so for each index i in the range [0, n - 1], it is assigned to exactly one group.\n\nA group assignment is valid if the following conditions hold:\n\n * For every group g, all indices i assigned to group g have the same value in nums.\n * For any two groups g1 and g2, the difference between the number of indices assigned to g1 and g2 should not exceed 1.\n\nReturn an integer denoting the minimum number of groups needed to create a valid group assignment.\n\nExample 1:\n\nInput: nums = [3,2,3,2,3]\nOutput: 2\nExplanation: One way the indices can be assigned to 2 groups is as follows, where the values in square brackets are indices:\ngroup 1 -> [0,2,4]\ngroup 2 -> [1,3]\nAll indices are assigned to one group.\nIn group 1, nums[0] == nums[2] == nums[4], so all indices have the same value.\nIn group 2, nums[1] == nums[3], so all indices have the same value.\nThe number of indices assigned to group 1 is 3, and the number of indices assigned to group 2 is 2.\nTheir difference doesn't exceed 1.\nIt is not possible to use fewer than 2 groups because, in order to use just 1 group, all indices assigned to that group must have the same value.\nHence, the answer is 2.\n\nExample 2:\n\nInput: nums = [10,10,10,3,1,1]\nOutput: 4\nExplanation: One way the indices can be assigned to 4 groups is as follows, where the values in square brackets are indices:\ngroup 1 -> [0]\ngroup 2 -> [1,2]\ngroup 3 -> [3]\ngroup 4 -> [4,5]\nThe group assignment above satisfies both conditions.\nIt can be shown that it is not possible to create a valid assignment using fewer than 4 groups.\nHence, the answer is 4.\n\nConstraints:\n\n * 1 <= nums.length <= 105\n * 1 <= nums[i] <= 109\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def minGroupsForValidAssignment(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [3,2,3,2,3] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [10,10,10,3,1,1] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 4\n\ntest_input = { \"nums\": [1,1] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 1\n\ntest_input = { \"nums\": [1,2] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [1,3] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [2,1] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [2,2] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 1\n\ntest_input = { \"nums\": [3,1] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [3,2] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [3,3] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 1\n\ntest_input = { \"nums\": [3,4] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [10,4] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [10,10] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 1\n\ntest_input = { \"nums\": [14,15] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,1] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,1] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [1,7,10] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 3\n\ntest_input = { \"nums\": [2,1,1] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [2,1,2] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [2,2,1] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [2,2,3] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [2,3,2] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [2,3,3] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [2,8,5] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 3\n\ntest_input = { \"nums\": [3,1,1] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [3,1,3] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [3,2,3] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [3,3,1] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [3,10,3] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [4,2,3] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 3\n\ntest_input = { \"nums\": [5,4,8] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 3\n\ntest_input = { \"nums\": [5,6,8] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 3\n\ntest_input = { \"nums\": [5,9,4] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 3\n\ntest_input = { \"nums\": [6,4,9] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 3\n\ntest_input = { \"nums\": [9,2,2] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [10,5,5] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [14,7,2] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,1,3] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,1,1] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,1,2] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [1,2,3,1] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,3,2] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 3\n\ntest_input = { \"nums\": [1,3,2,3] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 3\n\ntest_input = { \"nums\": [1,3,3,1] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [2,2,1,1] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [2,2,3,3] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [2,3,1,2] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 3\n\ntest_input = { \"nums\": [2,3,2,2] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 3\n\ntest_input = { \"nums\": [2,5,10,4] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 4\n\ntest_input = { \"nums\": [3,2,2,2] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 3\n\ntest_input = { \"nums\": [3,3,2,2] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [5,1,5,1] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [13,11,4,13] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,1,1,1] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,2,3,1] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,2,3,2] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 4\n\ntest_input = { \"nums\": [2,1,1,3,1] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 4\n\ntest_input = { \"nums\": [2,1,3,3,3] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 4\n\ntest_input = { \"nums\": [2,3,1,2,2] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 4\n\ntest_input = { \"nums\": [2,3,2,2,2] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 3\n\ntest_input = { \"nums\": [2,3,3,1,3] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 4\n\ntest_input = { \"nums\": [3,1,1,3,3] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [3,1,3,2,2] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 3\n\ntest_input = { \"nums\": [3,1,3,2,3] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 4\n\ntest_input = { \"nums\": [3,2,2,3,1] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 3\n\ntest_input = { \"nums\": [3,3,1,1,1] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [4,1,7,8,3] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 5\n\ntest_input = { \"nums\": [7,5,9,4,2] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 5\n\ntest_input = { \"nums\": [10,2,2,1,10] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,1,3,1,2] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 4\n\ntest_input = { \"nums\": [1,1,3,1,1,3] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,1,3,3,2] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 3\n\ntest_input = { \"nums\": [1,3,1,2,2,3] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 3\n\ntest_input = { \"nums\": [1,5,12,11,5,9] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 5\n\ntest_input = { \"nums\": [1,6,5,8,7,1] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 5\n\ntest_input = { \"nums\": [2,1,1,1,3,2] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 4\n\ntest_input = { \"nums\": [2,1,2,1,1,1] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 3\n\ntest_input = { \"nums\": [2,1,3,2,1,2] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 4\n\ntest_input = { \"nums\": [2,2,1,1,1,1] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 3\n\ntest_input = { \"nums\": [2,2,1,2,3,3] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 4\n\ntest_input = { \"nums\": [2,3,3,1,2,1] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 3\n\ntest_input = { \"nums\": [2,3,3,1,2,3] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 4\n\ntest_input = { \"nums\": [2,5,9,3,1,4] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 6\n\ntest_input = { \"nums\": [3,2,2,3,3,2] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [3,3,1,2,2,3] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 4\n\ntest_input = { \"nums\": [6,7,4,8,8,10] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 5\n\ntest_input = { \"nums\": [8,5,8,1,4,5] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 4\n\ntest_input = { \"nums\": [8,7,4,5,3,1] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 6\n\ntest_input = { \"nums\": [10,8,3,3,2,3] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 5\n\ntest_input = { \"nums\": [1,2,1,2,1,1,3] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,2,1,1,1,2] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 2\n\ntest_input = { \"nums\": [1,2,3,3,3,3,3] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 5\n\ntest_input = { \"nums\": [1,3,1,7,4,5,8] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 6\n\ntest_input = { \"nums\": [2,1,1,3,3,1,2] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 3\n\ntest_input = { \"nums\": [2,1,3,3,3,1,3] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 4\n\ntest_input = { \"nums\": [2,2,2,1,2,3,1] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 4\n\ntest_input = { \"nums\": [2,2,2,2,2,1,2] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 4\n\ntest_input = { \"nums\": [2,3,1,3,1,3,2] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 3\n\ntest_input = { \"nums\": [2,3,1,3,2,1,3] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 3\n\ntest_input = { \"nums\": [3,1,3,2,3,3,2] }\nassert my_solution.minGroupsForValidAssignment(**test_input) == 4", "start_time": 1697941800} +{"task_id": "weekly-contest-368-minimum-changes-to-make-k-semi-palindromes", "url": "https://leetcode.com/problems/minimum-changes-to-make-k-semi-palindromes", "title": "minimum-changes-to-make-k-semi-palindromes", "meta": {"questionId": "2879", "questionFrontendId": "2911", "title": "Minimum Changes to Make K Semi-palindromes", "titleSlug": "minimum-changes-to-make-k-semi-palindromes", "isPaidOnly": false, "difficulty": "Hard", "likes": 50, "dislikes": 78, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nGiven a string s and an integer k, partition s into k substrings such that the sum of the number of letter changes required to turn each substring into a semi-palindrome is minimized.\n\nReturn an integer denoting the minimum number of letter changes required.\n\nNotes\n\n * A string is a palindrome if it can be read the same way from left to right and right to left.\n * A string with a length of len is considered a semi-palindrome if there exists a positive integer d such that 1 <= d < len and len % d == 0, and if we take indices that have the same modulo by d, they form a palindrome. For example, \"aa\", \"aba\", \"adbgad\", and, \"abab\" are semi-palindrome and \"a\", \"ab\", and, \"abca\" are not.\n * A substring is a contiguous sequence of characters within a string.\n\nExample 1:\n\nInput: s = \"abcac\", k = 2\nOutput: 1\nExplanation: We can divide s into substrings \"ab\" and \"cac\". The string \"cac\" is already a semi-palindrome. If we change \"ab\" to \"aa\", it becomes a semi-palindrome with d = 1.\nIt can be shown that there is no way to divide the string \"abcac\" into two semi-palindrome substrings. Therefore, the answer would be at least 1.\n\nExample 2:\n\nInput: s = \"abcdef\", k = 2\nOutput: 2\nExplanation: We can divide it into substrings \"abc\" and \"def\". Each of the substrings \"abc\" and \"def\" requires one change to become a semi-palindrome, so we need 2 changes in total to make all substrings semi-palindrome.\nIt can be shown that we cannot divide the given string into two substrings in a way that it would require less than 2 changes.\n\nExample 3:\n\nInput: s = \"aabbaa\", k = 3\nOutput: 0\nExplanation: We can divide it into substrings \"aa\", \"bb\" and \"aa\".\nThe strings \"aa\" and \"bb\" are already semi-palindromes. Thus, the answer is zero.\n\n\nConstraints:\n\n * 2 <= s.length <= 200\n * 1 <= k <= s.length / 2\n * s consists only of lowercase English letters.\n\"\"\"\nclass Solution:\n def minimumChanges(self, s: str, k: int) -> int:\n ", "prompt_sft": "Given a string s and an integer k, partition s into k substrings such that the sum of the number of letter changes required to turn each substring into a semi-palindrome is minimized.\n\nReturn an integer denoting the minimum number of letter changes required.\n\nNotes\n\n * A string is a palindrome if it can be read the same way from left to right and right to left.\n * A string with a length of len is considered a semi-palindrome if there exists a positive integer d such that 1 <= d < len and len % d == 0, and if we take indices that have the same modulo by d, they form a palindrome. For example, \"aa\", \"aba\", \"adbgad\", and, \"abab\" are semi-palindrome and \"a\", \"ab\", and, \"abca\" are not.\n * A substring is a contiguous sequence of characters within a string.\n\nExample 1:\n\nInput: s = \"abcac\", k = 2\nOutput: 1\nExplanation: We can divide s into substrings \"ab\" and \"cac\". The string \"cac\" is already a semi-palindrome. If we change \"ab\" to \"aa\", it becomes a semi-palindrome with d = 1.\nIt can be shown that there is no way to divide the string \"abcac\" into two semi-palindrome substrings. Therefore, the answer would be at least 1.\n\nExample 2:\n\nInput: s = \"abcdef\", k = 2\nOutput: 2\nExplanation: We can divide it into substrings \"abc\" and \"def\". Each of the substrings \"abc\" and \"def\" requires one change to become a semi-palindrome, so we need 2 changes in total to make all substrings semi-palindrome.\nIt can be shown that we cannot divide the given string into two substrings in a way that it would require less than 2 changes.\n\nExample 3:\n\nInput: s = \"aabbaa\", k = 3\nOutput: 0\nExplanation: We can divide it into substrings \"aa\", \"bb\" and \"aa\".\nThe strings \"aa\" and \"bb\" are already semi-palindromes. Thus, the answer is zero.\n\n\nConstraints:\n\n * 2 <= s.length <= 200\n * 1 <= k <= s.length / 2\n * s consists only of lowercase English letters.\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def minimumChanges(self, s: str, k: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"s\": \"abcac\", \"k\": 2 }\nassert my_solution.minimumChanges(**test_input) == 1\n\ntest_input = { \"s\": \"abcdef\", \"k\": 2 }\nassert my_solution.minimumChanges(**test_input) == 2\n\ntest_input = { \"s\": \"aabbaa\", \"k\": 3 }\nassert my_solution.minimumChanges(**test_input) == 0\n\ntest_input = { \"s\": \"aq\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 1\n\ntest_input = { \"s\": \"bb\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 0\n\ntest_input = { \"s\": \"aac\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 1\n\ntest_input = { \"s\": \"abcc\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 2\n\ntest_input = { \"s\": \"acba\", \"k\": 2 }\nassert my_solution.minimumChanges(**test_input) == 2\n\ntest_input = { \"s\": \"edaswf\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 2\n\ntest_input = { \"s\": \"aabcbaa\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 0\n\ntest_input = { \"s\": \"dqpldq\", \"k\": 3 }\nassert my_solution.minimumChanges(**test_input) == 3\n\ntest_input = { \"s\": \"eksddulf\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 3\n\ntest_input = { \"s\": \"aaaaacabbb\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 3\n\ntest_input = { \"s\": \"aaabacacbb\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 3\n\ntest_input = { \"s\": \"abbbbacaaa\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 3\n\ntest_input = { \"s\": \"abcccbaccb\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 2\n\ntest_input = { \"s\": \"baacbbbaba\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 2\n\ntest_input = { \"s\": \"babcbaccba\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 1\n\ntest_input = { \"s\": \"cabbcabcbc\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 3\n\ntest_input = { \"s\": \"ccbccaaabb\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 4\n\ntest_input = { \"s\": \"cccbabbbbc\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 2\n\ntest_input = { \"s\": \"cccccbaaac\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 3\n\ntest_input = { \"s\": \"dyfnbbbqbm\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 4\n\ntest_input = { \"s\": \"hafrypzupv\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 4\n\ntest_input = { \"s\": \"aabcacccabc\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 4\n\ntest_input = { \"s\": \"abbcaabaaac\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 5\n\ntest_input = { \"s\": \"baabaabbcb\", \"k\": 2 }\nassert my_solution.minimumChanges(**test_input) == 0\n\ntest_input = { \"s\": \"bbbabcbaccb\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 2\n\ntest_input = { \"s\": \"bcababccaa\", \"k\": 2 }\nassert my_solution.minimumChanges(**test_input) == 1\n\ntest_input = { \"s\": \"bcacacacaab\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 1\n\ntest_input = { \"s\": \"bcacccacbaa\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 4\n\ntest_input = { \"s\": \"bccaaccacb\", \"k\": 2 }\nassert my_solution.minimumChanges(**test_input) == 2\n\ntest_input = { \"s\": \"caacbacbaca\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 4\n\ntest_input = { \"s\": \"ccccaaacca\", \"k\": 2 }\nassert my_solution.minimumChanges(**test_input) == 1\n\ntest_input = { \"s\": \"efrsgmjneph\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 5\n\ntest_input = { \"s\": \"ehdvhthgbxq\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 4\n\ntest_input = { \"s\": \"eymakkvrvc\", \"k\": 2 }\nassert my_solution.minimumChanges(**test_input) == 3\n\ntest_input = { \"s\": \"gilkaelnfr\", \"k\": 2 }\nassert my_solution.minimumChanges(**test_input) == 4\n\ntest_input = { \"s\": \"iiaenfiasiv\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 4\n\ntest_input = { \"s\": \"piazrazesdk\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 5\n\ntest_input = { \"s\": \"pypwcllynf\", \"k\": 2 }\nassert my_solution.minimumChanges(**test_input) == 3\n\ntest_input = { \"s\": \"uqicxuvkorn\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 5\n\ntest_input = { \"s\": \"ziirnywodfz\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 4\n\ntest_input = { \"s\": \"zpogsiabazr\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 5\n\ntest_input = { \"s\": \"aacacaacabba\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 2\n\ntest_input = { \"s\": \"abacacabba\", \"k\": 3 }\nassert my_solution.minimumChanges(**test_input) == 0\n\ntest_input = { \"s\": \"acbcbccccba\", \"k\": 2 }\nassert my_solution.minimumChanges(**test_input) == 2\n\ntest_input = { \"s\": \"bbcaaaaacbb\", \"k\": 2 }\nassert my_solution.minimumChanges(**test_input) == 2\n\ntest_input = { \"s\": \"cbabaabccba\", \"k\": 2 }\nassert my_solution.minimumChanges(**test_input) == 1\n\ntest_input = { \"s\": \"cbacccbabcaa\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 3\n\ntest_input = { \"s\": \"cbbcbcacca\", \"k\": 3 }\nassert my_solution.minimumChanges(**test_input) == 1\n\ntest_input = { \"s\": \"ccaabbbccacb\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 3\n\ntest_input = { \"s\": \"ccabcbbcaa\", \"k\": 3 }\nassert my_solution.minimumChanges(**test_input) == 1\n\ntest_input = { \"s\": \"epenvgssid\", \"k\": 3 }\nassert my_solution.minimumChanges(**test_input) == 3\n\ntest_input = { \"s\": \"grllkopehr\", \"k\": 3 }\nassert my_solution.minimumChanges(**test_input) == 3\n\ntest_input = { \"s\": \"iaemfpyhrtgb\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 4\n\ntest_input = { \"s\": \"iqjvqxzhjc\", \"k\": 3 }\nassert my_solution.minimumChanges(**test_input) == 4\n\ntest_input = { \"s\": \"kpkzjgcvgopr\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 4\n\ntest_input = { \"s\": \"neocjmpaltv\", \"k\": 2 }\nassert my_solution.minimumChanges(**test_input) == 4\n\ntest_input = { \"s\": \"uvdbxsjyso\", \"k\": 3 }\nassert my_solution.minimumChanges(**test_input) == 4\n\ntest_input = { \"s\": \"wsezruidpcy\", \"k\": 2 }\nassert my_solution.minimumChanges(**test_input) == 4\n\ntest_input = { \"s\": \"ybexlzsvsi\", \"k\": 3 }\nassert my_solution.minimumChanges(**test_input) == 3\n\ntest_input = { \"s\": \"abacabccaa\", \"k\": 4 }\nassert my_solution.minimumChanges(**test_input) == 1\n\ntest_input = { \"s\": \"abccbacbcbc\", \"k\": 3 }\nassert my_solution.minimumChanges(**test_input) == 1\n\ntest_input = { \"s\": \"abccccbaaba\", \"k\": 3 }\nassert my_solution.minimumChanges(**test_input) == 2\n\ntest_input = { \"s\": \"acabbbacacbb\", \"k\": 2 }\nassert my_solution.minimumChanges(**test_input) == 1\n\ntest_input = { \"s\": \"acbbbbccacc\", \"k\": 3 }\nassert my_solution.minimumChanges(**test_input) == 1\n\ntest_input = { \"s\": \"acbcbbaaca\", \"k\": 4 }\nassert my_solution.minimumChanges(**test_input) == 2\n\ntest_input = { \"s\": \"accbabbbaacaa\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 2\n\ntest_input = { \"s\": \"baaaccbaaa\", \"k\": 4 }\nassert my_solution.minimumChanges(**test_input) == 2\n\ntest_input = { \"s\": \"baababcacc\", \"k\": 4 }\nassert my_solution.minimumChanges(**test_input) == 2\n\ntest_input = { \"s\": \"baabbccbbc\", \"k\": 4 }\nassert my_solution.minimumChanges(**test_input) == 2\n\ntest_input = { \"s\": \"bacbbaaccb\", \"k\": 4 }\nassert my_solution.minimumChanges(**test_input) == 2\n\ntest_input = { \"s\": \"baccbbccab\", \"k\": 4 }\nassert my_solution.minimumChanges(**test_input) == 3\n\ntest_input = { \"s\": \"bbababccabca\", \"k\": 2 }\nassert my_solution.minimumChanges(**test_input) == 2\n\ntest_input = { \"s\": \"bbacbccbca\", \"k\": 4 }\nassert my_solution.minimumChanges(**test_input) == 2\n\ntest_input = { \"s\": \"bbacccbbaabbb\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 4\n\ntest_input = { \"s\": \"bbccbbbcaab\", \"k\": 3 }\nassert my_solution.minimumChanges(**test_input) == 2\n\ntest_input = { \"s\": \"bbccbcccaba\", \"k\": 3 }\nassert my_solution.minimumChanges(**test_input) == 0\n\ntest_input = { \"s\": \"bcaacaabaa\", \"k\": 4 }\nassert my_solution.minimumChanges(**test_input) == 2\n\ntest_input = { \"s\": \"bcbcbabaabaa\", \"k\": 2 }\nassert my_solution.minimumChanges(**test_input) == 1\n\ntest_input = { \"s\": \"bofqvqapnjo\", \"k\": 3 }\nassert my_solution.minimumChanges(**test_input) == 3\n\ntest_input = { \"s\": \"bvatyzbdffqdp\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 6\n\ntest_input = { \"s\": \"cabbcbcbcbcca\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 3\n\ntest_input = { \"s\": \"cbacbbcbccccc\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 3\n\ntest_input = { \"s\": \"ccaccaacbcaac\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 3\n\ntest_input = { \"s\": \"ccbabcbabb\", \"k\": 4 }\nassert my_solution.minimumChanges(**test_input) == 1\n\ntest_input = { \"s\": \"ccbacacbcbac\", \"k\": 2 }\nassert my_solution.minimumChanges(**test_input) == 2\n\ntest_input = { \"s\": \"edulrtnsbb\", \"k\": 4 }\nassert my_solution.minimumChanges(**test_input) == 3\n\ntest_input = { \"s\": \"feecuhvurk\", \"k\": 4 }\nassert my_solution.minimumChanges(**test_input) == 4\n\ntest_input = { \"s\": \"ffqbqdocclh\", \"k\": 3 }\nassert my_solution.minimumChanges(**test_input) == 2\n\ntest_input = { \"s\": \"gceeouniipz\", \"k\": 3 }\nassert my_solution.minimumChanges(**test_input) == 4\n\ntest_input = { \"s\": \"gdlitshyeehtx\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 6\n\ntest_input = { \"s\": \"hpbijyuygkk\", \"k\": 3 }\nassert my_solution.minimumChanges(**test_input) == 3\n\ntest_input = { \"s\": \"kxvwhuewyftpp\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 6\n\ntest_input = { \"s\": \"mrqvwotsqjtfv\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 6\n\ntest_input = { \"s\": \"qhzievvxauf\", \"k\": 3 }\nassert my_solution.minimumChanges(**test_input) == 4\n\ntest_input = { \"s\": \"rbiuxrgidyzuu\", \"k\": 1 }\nassert my_solution.minimumChanges(**test_input) == 6\n\ntest_input = { \"s\": \"rkyidomzyud\", \"k\": 3 }\nassert my_solution.minimumChanges(**test_input) == 4\n\ntest_input = { \"s\": \"wvewmaevkzjp\", \"k\": 2 }\nassert my_solution.minimumChanges(**test_input) == 3", "start_time": 1697941800} +{"task_id": "weekly-contest-367-find-indices-with-index-and-value-difference-i", "url": "https://leetcode.com/problems/find-indices-with-index-and-value-difference-i", "title": "find-indices-with-index-and-value-difference-i", "meta": {"questionId": "3165", "questionFrontendId": "2903", "title": "Find Indices With Index and Value Difference I", "titleSlug": "find-indices-with-index-and-value-difference-i", "isPaidOnly": false, "difficulty": "Easy", "likes": 97, "dislikes": 7, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed integer array nums having length n, an integer indexDifference, and an integer valueDifference.\n\nYour task is to find two indices i and j, both in the range [0, n - 1], that satisfy the following conditions:\n\n * abs(i - j) >= indexDifference, and\n * abs(nums[i] - nums[j]) >= valueDifference\n\nReturn an integer array answer, where answer = [i, j] if there are two such indices, and answer = [-1, -1] otherwise. If there are multiple choices for the two indices, return any of them.\n\nNote: i and j may be equal.\n\nExample 1:\n\nInput: nums = [5,1,4,1], indexDifference = 2, valueDifference = 4\nOutput: [0,3]\nExplanation: In this example, i = 0 and j = 3 can be selected.\nabs(0 - 3) >= 2 and abs(nums[0] - nums[3]) >= 4.\nHence, a valid answer is [0,3].\n[3,0] is also a valid answer.\n\nExample 2:\n\nInput: nums = [2,1], indexDifference = 0, valueDifference = 0\nOutput: [0,0]\nExplanation: In this example, i = 0 and j = 0 can be selected.\nabs(0 - 0) >= 0 and abs(nums[0] - nums[0]) >= 0.\nHence, a valid answer is [0,0].\nOther valid answers are [0,1], [1,0], and [1,1].\n\nExample 3:\n\nInput: nums = [1,2,3], indexDifference = 2, valueDifference = 4\nOutput: [-1,-1]\nExplanation: In this example, it can be shown that it is impossible to find two indices that satisfy both conditions.\nHence, [-1,-1] is returned.\n\nConstraints:\n\n * 1 <= n == nums.length <= 100\n * 0 <= nums[i] <= 50\n * 0 <= indexDifference <= 100\n * 0 <= valueDifference <= 50\n\"\"\"\nclass Solution:\n def findIndices(self, nums: List[int], indexDifference: int, valueDifference: int) -> List[int]:\n ", "prompt_sft": "You are given a 0-indexed integer array nums having length n, an integer indexDifference, and an integer valueDifference.\n\nYour task is to find two indices i and j, both in the range [0, n - 1], that satisfy the following conditions:\n\n * abs(i - j) >= indexDifference, and\n * abs(nums[i] - nums[j]) >= valueDifference\n\nReturn an integer array answer, where answer = [i, j] if there are two such indices, and answer = [-1, -1] otherwise. If there are multiple choices for the two indices, return any of them.\n\nNote: i and j may be equal.\n\nExample 1:\n\nInput: nums = [5,1,4,1], indexDifference = 2, valueDifference = 4\nOutput: [0,3]\nExplanation: In this example, i = 0 and j = 3 can be selected.\nabs(0 - 3) >= 2 and abs(nums[0] - nums[3]) >= 4.\nHence, a valid answer is [0,3].\n[3,0] is also a valid answer.\n\nExample 2:\n\nInput: nums = [2,1], indexDifference = 0, valueDifference = 0\nOutput: [0,0]\nExplanation: In this example, i = 0 and j = 0 can be selected.\nabs(0 - 0) >= 0 and abs(nums[0] - nums[0]) >= 0.\nHence, a valid answer is [0,0].\nOther valid answers are [0,1], [1,0], and [1,1].\n\nExample 3:\n\nInput: nums = [1,2,3], indexDifference = 2, valueDifference = 4\nOutput: [-1,-1]\nExplanation: In this example, it can be shown that it is impossible to find two indices that satisfy both conditions.\nHence, [-1,-1] is returned.\n\nConstraints:\n\n * 1 <= n == nums.length <= 100\n * 0 <= nums[i] <= 50\n * 0 <= indexDifference <= 100\n * 0 <= valueDifference <= 50\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def findIndices(self, nums: List[int], indexDifference: int, valueDifference: int) -> List[int]:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [5,1,4,1], \"indexDifference\": 2, \"valueDifference\": 4 }\nassert my_solution.findIndices(**test_input) == [0,3]\n\ntest_input = { \"nums\": [2,1], \"indexDifference\": 0, \"valueDifference\": 0 }\nassert my_solution.findIndices(**test_input) == [0,0]\n\ntest_input = { \"nums\": [1,2,3], \"indexDifference\": 2, \"valueDifference\": 4 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [0], \"indexDifference\": 0, \"valueDifference\": 0 }\nassert my_solution.findIndices(**test_input) == [0,0]\n\ntest_input = { \"nums\": [3], \"indexDifference\": 0, \"valueDifference\": 0 }\nassert my_solution.findIndices(**test_input) == [0,0]\n\ntest_input = { \"nums\": [3], \"indexDifference\": 1, \"valueDifference\": 1 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [4], \"indexDifference\": 1, \"valueDifference\": 0 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [5], \"indexDifference\": 1, \"valueDifference\": 3 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [7], \"indexDifference\": 1, \"valueDifference\": 7 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [8], \"indexDifference\": 0, \"valueDifference\": 2 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [8], \"indexDifference\": 1, \"valueDifference\": 7 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [10], \"indexDifference\": 0, \"valueDifference\": 9 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [11], \"indexDifference\": 1, \"valueDifference\": 0 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [18], \"indexDifference\": 1, \"valueDifference\": 4 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [38], \"indexDifference\": 1, \"valueDifference\": 34 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [40], \"indexDifference\": 1, \"valueDifference\": 2 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [5,10], \"indexDifference\": 1, \"valueDifference\": 2 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [5,48], \"indexDifference\": 0, \"valueDifference\": 29 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [6,3], \"indexDifference\": 1, \"valueDifference\": 2 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [7,6], \"indexDifference\": 1, \"valueDifference\": 0 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [8,8], \"indexDifference\": 1, \"valueDifference\": 1 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [17,31], \"indexDifference\": 1, \"valueDifference\": 9 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [21,22], \"indexDifference\": 1, \"valueDifference\": 21 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [48,40], \"indexDifference\": 2, \"valueDifference\": 31 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [2,8,0], \"indexDifference\": 2, \"valueDifference\": 7 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [2,29,0], \"indexDifference\": 0, \"valueDifference\": 12 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [3,0,7], \"indexDifference\": 2, \"valueDifference\": 4 }\nassert my_solution.findIndices(**test_input) == [0,2]\n\ntest_input = { \"nums\": [4,22,43], \"indexDifference\": 0, \"valueDifference\": 34 }\nassert my_solution.findIndices(**test_input) == [0,2]\n\ntest_input = { \"nums\": [5,0,3], \"indexDifference\": 1, \"valueDifference\": 4 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [5,9,2], \"indexDifference\": 0, \"valueDifference\": 1 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [6,2,7], \"indexDifference\": 2, \"valueDifference\": 5 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [6,5,1], \"indexDifference\": 2, \"valueDifference\": 6 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [6,8,0], \"indexDifference\": 1, \"valueDifference\": 3 }\nassert my_solution.findIndices(**test_input) == [0,2]\n\ntest_input = { \"nums\": [7,36,21], \"indexDifference\": 1, \"valueDifference\": 20 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [9,4,7], \"indexDifference\": 0, \"valueDifference\": 9 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [9,50,31], \"indexDifference\": 1, \"valueDifference\": 8 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [31,23,36], \"indexDifference\": 1, \"valueDifference\": 11 }\nassert my_solution.findIndices(**test_input) == [1,2]\n\ntest_input = { \"nums\": [40,21,1], \"indexDifference\": 2, \"valueDifference\": 0 }\nassert my_solution.findIndices(**test_input) == [0,2]\n\ntest_input = { \"nums\": [0,5,10,5], \"indexDifference\": 3, \"valueDifference\": 0 }\nassert my_solution.findIndices(**test_input) == [0,3]\n\ntest_input = { \"nums\": [1,28,24,35], \"indexDifference\": 3, \"valueDifference\": 2 }\nassert my_solution.findIndices(**test_input) == [0,3]\n\ntest_input = { \"nums\": [2,7,10,4], \"indexDifference\": 0, \"valueDifference\": 5 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [3,1,0,3], \"indexDifference\": 2, \"valueDifference\": 0 }\nassert my_solution.findIndices(**test_input) == [0,2]\n\ntest_input = { \"nums\": [7,5,6,2], \"indexDifference\": 2, \"valueDifference\": 2 }\nassert my_solution.findIndices(**test_input) == [0,3]\n\ntest_input = { \"nums\": [9,3,6,4], \"indexDifference\": 1, \"valueDifference\": 5 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [34,46,11,45], \"indexDifference\": 1, \"valueDifference\": 3 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [36,37,40,9], \"indexDifference\": 2, \"valueDifference\": 8 }\nassert my_solution.findIndices(**test_input) == [0,3]\n\ntest_input = { \"nums\": [37,25,48,13], \"indexDifference\": 0, \"valueDifference\": 0 }\nassert my_solution.findIndices(**test_input) == [0,0]\n\ntest_input = { \"nums\": [45,6,29,21], \"indexDifference\": 3, \"valueDifference\": 36 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [1,5,7,9,2], \"indexDifference\": 3, \"valueDifference\": 8 }\nassert my_solution.findIndices(**test_input) == [0,3]\n\ntest_input = { \"nums\": [7,2,1,8,3], \"indexDifference\": 0, \"valueDifference\": 7 }\nassert my_solution.findIndices(**test_input) == [2,3]\n\ntest_input = { \"nums\": [8,9,8,0,4], \"indexDifference\": 1, \"valueDifference\": 6 }\nassert my_solution.findIndices(**test_input) == [0,3]\n\ntest_input = { \"nums\": [9,1,10,0,10], \"indexDifference\": 0, \"valueDifference\": 3 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [9,9,4,5,5], \"indexDifference\": 2, \"valueDifference\": 9 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [10,1,10,12,1], \"indexDifference\": 1, \"valueDifference\": 3 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [17,46,31,28,28], \"indexDifference\": 0, \"valueDifference\": 46 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [17,49,1,47,12], \"indexDifference\": 2, \"valueDifference\": 17 }\nassert my_solution.findIndices(**test_input) == [0,3]\n\ntest_input = { \"nums\": [32,49,3,40,44], \"indexDifference\": 1, \"valueDifference\": 37 }\nassert my_solution.findIndices(**test_input) == [1,2]\n\ntest_input = { \"nums\": [46,43,16,16,34], \"indexDifference\": 3, \"valueDifference\": 13 }\nassert my_solution.findIndices(**test_input) == [0,3]\n\ntest_input = { \"nums\": [49,36,18,4,33], \"indexDifference\": 3, \"valueDifference\": 20 }\nassert my_solution.findIndices(**test_input) == [0,3]\n\ntest_input = { \"nums\": [0,7,10,6,6,5], \"indexDifference\": 1, \"valueDifference\": 5 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [2,0,3,4,0,5], \"indexDifference\": 3, \"valueDifference\": 5 }\nassert my_solution.findIndices(**test_input) == [1,5]\n\ntest_input = { \"nums\": [3,8,9,7,2,3], \"indexDifference\": 3, \"valueDifference\": 6 }\nassert my_solution.findIndices(**test_input) == [1,4]\n\ntest_input = { \"nums\": [3,27,38,47,38,4], \"indexDifference\": 0, \"valueDifference\": 10 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [4,13,48,50,1,26], \"indexDifference\": 4, \"valueDifference\": 34 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [6,1,2,6,4,6], \"indexDifference\": 2, \"valueDifference\": 2 }\nassert my_solution.findIndices(**test_input) == [0,2]\n\ntest_input = { \"nums\": [7,1,0,9,5,9], \"indexDifference\": 2, \"valueDifference\": 5 }\nassert my_solution.findIndices(**test_input) == [0,2]\n\ntest_input = { \"nums\": [7,3,7,5,7,9], \"indexDifference\": 1, \"valueDifference\": 2 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [12,37,7,16,5,34], \"indexDifference\": 3, \"valueDifference\": 27 }\nassert my_solution.findIndices(**test_input) == [1,4]\n\ntest_input = { \"nums\": [17,46,48,25,22,4], \"indexDifference\": 2, \"valueDifference\": 30 }\nassert my_solution.findIndices(**test_input) == [0,2]\n\ntest_input = { \"nums\": [18,18,7,10,9,50], \"indexDifference\": 2, \"valueDifference\": 32 }\nassert my_solution.findIndices(**test_input) == [0,5]\n\ntest_input = { \"nums\": [18,42,37,13,49,42], \"indexDifference\": 3, \"valueDifference\": 46 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [23,31,14,42,0,49], \"indexDifference\": 4, \"valueDifference\": 44 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [50,46,15,16,48,7], \"indexDifference\": 1, \"valueDifference\": 7 }\nassert my_solution.findIndices(**test_input) == [0,2]\n\ntest_input = { \"nums\": [5,6,8,5,6,3,1], \"indexDifference\": 0, \"valueDifference\": 4 }\nassert my_solution.findIndices(**test_input) == [0,6]\n\ntest_input = { \"nums\": [5,50,13,3,44,7,29], \"indexDifference\": 1, \"valueDifference\": 45 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [8,7,18,47,27,25,41], \"indexDifference\": 0, \"valueDifference\": 45 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [9,1,0,6,7,5,8], \"indexDifference\": 1, \"valueDifference\": 1 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [11,3,36,17,13,0,26], \"indexDifference\": 2, \"valueDifference\": 33 }\nassert my_solution.findIndices(**test_input) == [2,5]\n\ntest_input = { \"nums\": [13,0,16,32,47,27,25], \"indexDifference\": 1, \"valueDifference\": 35 }\nassert my_solution.findIndices(**test_input) == [1,4]\n\ntest_input = { \"nums\": [13,16,30,33,50,50,38], \"indexDifference\": 3, \"valueDifference\": 30 }\nassert my_solution.findIndices(**test_input) == [0,4]\n\ntest_input = { \"nums\": [21,44,22,1,21,9,17], \"indexDifference\": 1, \"valueDifference\": 41 }\nassert my_solution.findIndices(**test_input) == [1,3]\n\ntest_input = { \"nums\": [35,31,36,28,49,4,46], \"indexDifference\": 4, \"valueDifference\": 27 }\nassert my_solution.findIndices(**test_input) == [0,5]\n\ntest_input = { \"nums\": [39,18,49,25,40,41,26], \"indexDifference\": 1, \"valueDifference\": 43 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [40,46,11,36,25,46,47], \"indexDifference\": 0, \"valueDifference\": 37 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [46,7,6,3,43,7,48], \"indexDifference\": 0, \"valueDifference\": 48 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [0,1,6,8,8,3,9,10], \"indexDifference\": 2, \"valueDifference\": 6 }\nassert my_solution.findIndices(**test_input) == [0,2]\n\ntest_input = { \"nums\": [1,0,6,4,8,7,2,5], \"indexDifference\": 3, \"valueDifference\": 7 }\nassert my_solution.findIndices(**test_input) == [0,4]\n\ntest_input = { \"nums\": [3,8,3,8,0,5,5,7], \"indexDifference\": 4, \"valueDifference\": 6 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [5,10,4,4,8,6,0,4], \"indexDifference\": 2, \"valueDifference\": 7 }\nassert my_solution.findIndices(**test_input) == [1,6]\n\ntest_input = { \"nums\": [6,1,3,7,4,4,2,1], \"indexDifference\": 0, \"valueDifference\": 5 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [9,36,31,2,46,1,27,37], \"indexDifference\": 3, \"valueDifference\": 45 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [10,4,0,1,4,7,2,0], \"indexDifference\": 5, \"valueDifference\": 8 }\nassert my_solution.findIndices(**test_input) == [0,6]\n\ntest_input = { \"nums\": [26,20,19,36,20,28,33,39], \"indexDifference\": 0, \"valueDifference\": 0 }\nassert my_solution.findIndices(**test_input) == [0,0]\n\ntest_input = { \"nums\": [29,3,30,34,25,40,10,37], \"indexDifference\": 5, \"valueDifference\": 22 }\nassert my_solution.findIndices(**test_input) == [1,7]\n\ntest_input = { \"nums\": [39,26,46,9,5,34,0,20], \"indexDifference\": 0, \"valueDifference\": 24 }\nassert my_solution.findIndices(**test_input) == [0,3]\n\ntest_input = { \"nums\": [46,12,38,21,12,9,18,29], \"indexDifference\": 3, \"valueDifference\": 35 }\nassert my_solution.findIndices(**test_input) == [0,5]\n\ntest_input = { \"nums\": [1,7,7,2,4,10,1,5,9], \"indexDifference\": 4, \"valueDifference\": 4 }\nassert my_solution.findIndices(**test_input) == [0,5]\n\ntest_input = { \"nums\": [2,4,1,5,2,0,3,5,7], \"indexDifference\": 5, \"valueDifference\": 2 }\nassert my_solution.findIndices(**test_input) == [0,5]\n\ntest_input = { \"nums\": [2,5,6,5,9,7,2,3,6], \"indexDifference\": 4, \"valueDifference\": 2 }\nassert my_solution.findIndices(**test_input) == [0,4]\n\ntest_input = { \"nums\": [2,6,9,4,9,4,10,9,2], \"indexDifference\": 0, \"valueDifference\": 4 }\nassert my_solution.findIndices(**test_input) == [0,1]", "start_time": 1697337000} +{"task_id": "weekly-contest-367-shortest-and-lexicographically-smallest-beautiful-string", "url": "https://leetcode.com/problems/shortest-and-lexicographically-smallest-beautiful-string", "title": "shortest-and-lexicographically-smallest-beautiful-string", "meta": {"questionId": "3150", "questionFrontendId": "2904", "title": "Shortest and Lexicographically Smallest Beautiful String", "titleSlug": "shortest-and-lexicographically-smallest-beautiful-string", "isPaidOnly": false, "difficulty": "Medium", "likes": 147, "dislikes": 8, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a binary string s and a positive integer k.\n\nA substring of s is beautiful if the number of 1's in it is exactly k.\n\nLet len be the length of the shortest beautiful substring.\n\nReturn the lexicographically smallest beautiful substring of string s with length equal to len. If s doesn't contain a beautiful substring, return an empty string.\n\nA string a is lexicographically larger than a string b (of the same length) if in the first position where a and b differ, a has a character strictly larger than the corresponding character in b.\n\n * For example, \"abcd\" is lexicographically larger than \"abcc\" because the first position they differ is at the fourth character, and d is greater than c.\n\nExample 1:\n\nInput: s = \"100011001\", k = 3\nOutput: \"11001\"\nExplanation: There are 7 beautiful substrings in this example:\n1. The substring \"100011001\".\n2. The substring \"100011001\".\n3. The substring \"100011001\".\n4. The substring \"100011001\".\n5. The substring \"100011001\".\n6. The substring \"100011001\".\n7. The substring \"100011001\".\nThe length of the shortest beautiful substring is 5.\nThe lexicographically smallest beautiful substring with length 5 is the substring \"11001\".\n\nExample 2:\n\nInput: s = \"1011\", k = 2\nOutput: \"11\"\nExplanation: There are 3 beautiful substrings in this example:\n1. The substring \"1011\".\n2. The substring \"1011\".\n3. The substring \"1011\".\nThe length of the shortest beautiful substring is 2.\nThe lexicographically smallest beautiful substring with length 2 is the substring \"11\".\n\nExample 3:\n\nInput: s = \"000\", k = 1\nOutput: \"\"\nExplanation: There are no beautiful substrings in this example.\n\n\nConstraints:\n\n * 1 <= s.length <= 100\n * 1 <= k <= s.length\n\"\"\"\nclass Solution:\n def shortestBeautifulSubstring(self, s: str, k: int) -> str:\n ", "prompt_sft": "You are given a binary string s and a positive integer k.\n\nA substring of s is beautiful if the number of 1's in it is exactly k.\n\nLet len be the length of the shortest beautiful substring.\n\nReturn the lexicographically smallest beautiful substring of string s with length equal to len. If s doesn't contain a beautiful substring, return an empty string.\n\nA string a is lexicographically larger than a string b (of the same length) if in the first position where a and b differ, a has a character strictly larger than the corresponding character in b.\n\n * For example, \"abcd\" is lexicographically larger than \"abcc\" because the first position they differ is at the fourth character, and d is greater than c.\n\nExample 1:\n\nInput: s = \"100011001\", k = 3\nOutput: \"11001\"\nExplanation: There are 7 beautiful substrings in this example:\n1. The substring \"100011001\".\n2. The substring \"100011001\".\n3. The substring \"100011001\".\n4. The substring \"100011001\".\n5. The substring \"100011001\".\n6. The substring \"100011001\".\n7. The substring \"100011001\".\nThe length of the shortest beautiful substring is 5.\nThe lexicographically smallest beautiful substring with length 5 is the substring \"11001\".\n\nExample 2:\n\nInput: s = \"1011\", k = 2\nOutput: \"11\"\nExplanation: There are 3 beautiful substrings in this example:\n1. The substring \"1011\".\n2. The substring \"1011\".\n3. The substring \"1011\".\nThe length of the shortest beautiful substring is 2.\nThe lexicographically smallest beautiful substring with length 2 is the substring \"11\".\n\nExample 3:\n\nInput: s = \"000\", k = 1\nOutput: \"\"\nExplanation: There are no beautiful substrings in this example.\n\n\nConstraints:\n\n * 1 <= s.length <= 100\n * 1 <= k <= s.length\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def shortestBeautifulSubstring(self, s: str, k: int) -> str:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"s\": \"100011001\", \"k\": 3 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"11001\"\n\ntest_input = { \"s\": \"1011\", \"k\": 2 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"11\"\n\ntest_input = { \"s\": \"000\", \"k\": 1 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"11000111\", \"k\": 1 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"1\"\n\ntest_input = { \"s\": \"10100010\", \"k\": 5 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"0010111\", \"k\": 7 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"111111110010001010\", \"k\": 11 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"11111111001000101\"\n\ntest_input = { \"s\": \"00000110010011010110\", \"k\": 13 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"1100001110111100100\", \"k\": 8 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"11101111001\"\n\ntest_input = { \"s\": \"01011101000111110\", \"k\": 5 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"11111\"\n\ntest_input = { \"s\": \"10001\", \"k\": 5 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"001011010001101\", \"k\": 11 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"1001000\", \"k\": 4 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"001\", \"k\": 1 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"1\"\n\ntest_input = { \"s\": \"000110001\", \"k\": 6 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"10001\", \"k\": 3 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"100011000000000\", \"k\": 9 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"10101000111\", \"k\": 3 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"111\"\n\ntest_input = { \"s\": \"00\", \"k\": 1 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"1100100101011001001\", \"k\": 7 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"1100100101011\"\n\ntest_input = { \"s\": \"0001001\", \"k\": 7 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"101100000\", \"k\": 6 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"100011\", \"k\": 2 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"11\"\n\ntest_input = { \"s\": \"1101\", \"k\": 4 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"110000\", \"k\": 2 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"11\"\n\ntest_input = { \"s\": \"001110101101101111\", \"k\": 10 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"10101101101111\"\n\ntest_input = { \"s\": \"111011110\", \"k\": 1 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"1\"\n\ntest_input = { \"s\": \"1111111011111\", \"k\": 12 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"1111111011111\"\n\ntest_input = { \"s\": \"0101111000101011001\", \"k\": 9 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"101111000101011\"\n\ntest_input = { \"s\": \"0011010\", \"k\": 4 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"01101101110110010\", \"k\": 16 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"10111101011100101001\", \"k\": 14 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"0\", \"k\": 1 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"0101001000001011011\", \"k\": 12 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"01000100\", \"k\": 1 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"1\"\n\ntest_input = { \"s\": \"01001010010\", \"k\": 6 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"01100110011101010\", \"k\": 3 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"111\"\n\ntest_input = { \"s\": \"10\", \"k\": 2 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"01010000110111110010\", \"k\": 12 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"1101\", \"k\": 2 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"11\"\n\ntest_input = { \"s\": \"00000100000\", \"k\": 9 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"10101101000111\", \"k\": 3 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"111\"\n\ntest_input = { \"s\": \"101010111111110110\", \"k\": 4 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"1111\"\n\ntest_input = { \"s\": \"0100111011101010\", \"k\": 16 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"1111001111\", \"k\": 1 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"1\"\n\ntest_input = { \"s\": \"000010110111011\", \"k\": 8 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"10110111011\"\n\ntest_input = { \"s\": \"010100\", \"k\": 1 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"1\"\n\ntest_input = { \"s\": \"00\", \"k\": 2 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"000100\", \"k\": 5 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"1110001110100110011\", \"k\": 13 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"111011001\", \"k\": 9 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"0111000100001101\", \"k\": 9 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"100011\", \"k\": 5 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"111000101010010011\", \"k\": 10 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"01010\", \"k\": 5 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"0100100111100010\", \"k\": 14 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"110\", \"k\": 1 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"1\"\n\ntest_input = { \"s\": \"111000\", \"k\": 2 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"11\"\n\ntest_input = { \"s\": \"101011\", \"k\": 6 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"11101101110110111101\", \"k\": 17 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"010011101\", \"k\": 4 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"11101\"\n\ntest_input = { \"s\": \"100111010111001\", \"k\": 11 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"110001111100011\", \"k\": 2 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"11\"\n\ntest_input = { \"s\": \"0010110\", \"k\": 1 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"1\"\n\ntest_input = { \"s\": \"11101110001111\", \"k\": 7 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"1110001111\"\n\ntest_input = { \"s\": \"110\", \"k\": 2 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"11\"\n\ntest_input = { \"s\": \"110101\", \"k\": 3 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"1101\"\n\ntest_input = { \"s\": \"0110100\", \"k\": 7 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"00111\", \"k\": 3 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"111\"\n\ntest_input = { \"s\": \"1011001100001110101\", \"k\": 4 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"11101\"\n\ntest_input = { \"s\": \"0101000010101010\", \"k\": 6 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"10100001010101\"\n\ntest_input = { \"s\": \"0011000110001\", \"k\": 2 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"11\"\n\ntest_input = { \"s\": \"01001011000110100\", \"k\": 11 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"11\", \"k\": 2 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"11\"\n\ntest_input = { \"s\": \"00111100\", \"k\": 5 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"1110\", \"k\": 3 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"111\"\n\ntest_input = { \"s\": \"00010000110\", \"k\": 9 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"110110100011\", \"k\": 8 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"00111110001100000\", \"k\": 7 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"1111100011\"\n\ntest_input = { \"s\": \"10100100101\", \"k\": 11 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"110\", \"k\": 3 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"1001101100000010100\", \"k\": 1 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"1\"\n\ntest_input = { \"s\": \"0101010101010111101\", \"k\": 15 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"0000101\", \"k\": 1 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"1\"\n\ntest_input = { \"s\": \"110011010110\", \"k\": 10 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"11010\", \"k\": 4 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"10010100\", \"k\": 1 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"1\"\n\ntest_input = { \"s\": \"1\", \"k\": 1 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"1\"\n\ntest_input = { \"s\": \"11\", \"k\": 1 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"1\"\n\ntest_input = { \"s\": \"101000\", \"k\": 2 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"101\"\n\ntest_input = { \"s\": \"000010110010111\", \"k\": 7 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"10110010111\"\n\ntest_input = { \"s\": \"0100111\", \"k\": 4 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"100111\"\n\ntest_input = { \"s\": \"0111111100011111101\", \"k\": 12 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"111111000111111\"\n\ntest_input = { \"s\": \"010001\", \"k\": 3 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"110110101010100000\", \"k\": 10 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"110000001\", \"k\": 4 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"001101\", \"k\": 6 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"01111001101001010101\", \"k\": 16 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"00111010\", \"k\": 6 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"\"\n\ntest_input = { \"s\": \"11011101010100\", \"k\": 7 }\nassert my_solution.shortestBeautifulSubstring(**test_input) == \"1101110101\"", "start_time": 1697337000} +{"task_id": "weekly-contest-367-find-indices-with-index-and-value-difference-ii", "url": "https://leetcode.com/problems/find-indices-with-index-and-value-difference-ii", "title": "find-indices-with-index-and-value-difference-ii", "meta": {"questionId": "3170", "questionFrontendId": "2905", "title": "Find Indices With Index and Value Difference II", "titleSlug": "find-indices-with-index-and-value-difference-ii", "isPaidOnly": false, "difficulty": "Medium", "likes": 218, "dislikes": 6, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed integer array nums having length n, an integer indexDifference, and an integer valueDifference.\n\nYour task is to find two indices i and j, both in the range [0, n - 1], that satisfy the following conditions:\n\n * abs(i - j) >= indexDifference, and\n * abs(nums[i] - nums[j]) >= valueDifference\n\nReturn an integer array answer, where answer = [i, j] if there are two such indices, and answer = [-1, -1] otherwise. If there are multiple choices for the two indices, return any of them.\n\nNote: i and j may be equal.\n\nExample 1:\n\nInput: nums = [5,1,4,1], indexDifference = 2, valueDifference = 4\nOutput: [0,3]\nExplanation: In this example, i = 0 and j = 3 can be selected.\nabs(0 - 3) >= 2 and abs(nums[0] - nums[3]) >= 4.\nHence, a valid answer is [0,3].\n[3,0] is also a valid answer.\n\nExample 2:\n\nInput: nums = [2,1], indexDifference = 0, valueDifference = 0\nOutput: [0,0]\nExplanation: In this example, i = 0 and j = 0 can be selected.\nabs(0 - 0) >= 0 and abs(nums[0] - nums[0]) >= 0.\nHence, a valid answer is [0,0].\nOther valid answers are [0,1], [1,0], and [1,1].\n\nExample 3:\n\nInput: nums = [1,2,3], indexDifference = 2, valueDifference = 4\nOutput: [-1,-1]\nExplanation: In this example, it can be shown that it is impossible to find two indices that satisfy both conditions.\nHence, [-1,-1] is returned.\n\nConstraints:\n\n * 1 <= n == nums.length <= 105\n * 0 <= nums[i] <= 109\n * 0 <= indexDifference <= 105\n * 0 <= valueDifference <= 109\n\"\"\"\nclass Solution:\n def findIndices(self, nums: List[int], indexDifference: int, valueDifference: int) -> List[int]:\n ", "prompt_sft": "You are given a 0-indexed integer array nums having length n, an integer indexDifference, and an integer valueDifference.\n\nYour task is to find two indices i and j, both in the range [0, n - 1], that satisfy the following conditions:\n\n * abs(i - j) >= indexDifference, and\n * abs(nums[i] - nums[j]) >= valueDifference\n\nReturn an integer array answer, where answer = [i, j] if there are two such indices, and answer = [-1, -1] otherwise. If there are multiple choices for the two indices, return any of them.\n\nNote: i and j may be equal.\n\nExample 1:\n\nInput: nums = [5,1,4,1], indexDifference = 2, valueDifference = 4\nOutput: [0,3]\nExplanation: In this example, i = 0 and j = 3 can be selected.\nabs(0 - 3) >= 2 and abs(nums[0] - nums[3]) >= 4.\nHence, a valid answer is [0,3].\n[3,0] is also a valid answer.\n\nExample 2:\n\nInput: nums = [2,1], indexDifference = 0, valueDifference = 0\nOutput: [0,0]\nExplanation: In this example, i = 0 and j = 0 can be selected.\nabs(0 - 0) >= 0 and abs(nums[0] - nums[0]) >= 0.\nHence, a valid answer is [0,0].\nOther valid answers are [0,1], [1,0], and [1,1].\n\nExample 3:\n\nInput: nums = [1,2,3], indexDifference = 2, valueDifference = 4\nOutput: [-1,-1]\nExplanation: In this example, it can be shown that it is impossible to find two indices that satisfy both conditions.\nHence, [-1,-1] is returned.\n\nConstraints:\n\n * 1 <= n == nums.length <= 105\n * 0 <= nums[i] <= 109\n * 0 <= indexDifference <= 105\n * 0 <= valueDifference <= 109\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def findIndices(self, nums: List[int], indexDifference: int, valueDifference: int) -> List[int]:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [5,1,4,1], \"indexDifference\": 2, \"valueDifference\": 4 }\nassert my_solution.findIndices(**test_input) == [0,3]\n\ntest_input = { \"nums\": [2,1], \"indexDifference\": 0, \"valueDifference\": 0 }\nassert my_solution.findIndices(**test_input) == [0,0]\n\ntest_input = { \"nums\": [1,2,3], \"indexDifference\": 2, \"valueDifference\": 4 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [1], \"indexDifference\": 0, \"valueDifference\": 1 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [1], \"indexDifference\": 1, \"valueDifference\": 0 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [2], \"indexDifference\": 0, \"valueDifference\": 2 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [6], \"indexDifference\": 1, \"valueDifference\": 4 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [7], \"indexDifference\": 0, \"valueDifference\": 0 }\nassert my_solution.findIndices(**test_input) == [0,0]\n\ntest_input = { \"nums\": [8], \"indexDifference\": 1, \"valueDifference\": 6 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [9], \"indexDifference\": 0, \"valueDifference\": 1 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [9], \"indexDifference\": 1, \"valueDifference\": 9 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [12], \"indexDifference\": 0, \"valueDifference\": 5 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [16], \"indexDifference\": 0, \"valueDifference\": 16 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [16], \"indexDifference\": 1, \"valueDifference\": 6 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [46], \"indexDifference\": 0, \"valueDifference\": 36 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [0,10], \"indexDifference\": 2, \"valueDifference\": 4 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [2,7], \"indexDifference\": 2, \"valueDifference\": 7 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [5,1], \"indexDifference\": 2, \"valueDifference\": 5 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [5,12], \"indexDifference\": 0, \"valueDifference\": 10 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [8,0], \"indexDifference\": 1, \"valueDifference\": 7 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [8,4], \"indexDifference\": 1, \"valueDifference\": 4 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [9,8], \"indexDifference\": 0, \"valueDifference\": 6 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [15,8], \"indexDifference\": 0, \"valueDifference\": 6 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [20,21], \"indexDifference\": 1, \"valueDifference\": 14 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [23,47], \"indexDifference\": 2, \"valueDifference\": 47 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [32,14], \"indexDifference\": 1, \"valueDifference\": 6 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [36,14], \"indexDifference\": 2, \"valueDifference\": 11 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [40,12], \"indexDifference\": 1, \"valueDifference\": 20 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [45,41], \"indexDifference\": 2, \"valueDifference\": 21 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [50,24], \"indexDifference\": 1, \"valueDifference\": 18 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [2,7,0], \"indexDifference\": 0, \"valueDifference\": 4 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [3,9,3], \"indexDifference\": 0, \"valueDifference\": 3 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [3,12,40], \"indexDifference\": 0, \"valueDifference\": 9 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [4,10,8], \"indexDifference\": 0, \"valueDifference\": 3 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [5,27,26], \"indexDifference\": 1, \"valueDifference\": 15 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [7,8,10], \"indexDifference\": 2, \"valueDifference\": 5 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [8,2,6], \"indexDifference\": 1, \"valueDifference\": 8 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [8,7,5], \"indexDifference\": 2, \"valueDifference\": 3 }\nassert my_solution.findIndices(**test_input) == [0,2]\n\ntest_input = { \"nums\": [9,5,4], \"indexDifference\": 1, \"valueDifference\": 0 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [9,9,8], \"indexDifference\": 1, \"valueDifference\": 3 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [10,4,10], \"indexDifference\": 0, \"valueDifference\": 0 }\nassert my_solution.findIndices(**test_input) == [0,0]\n\ntest_input = { \"nums\": [10,5,2], \"indexDifference\": 2, \"valueDifference\": 5 }\nassert my_solution.findIndices(**test_input) == [0,2]\n\ntest_input = { \"nums\": [37,45,23], \"indexDifference\": 1, \"valueDifference\": 28 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [37,49,25], \"indexDifference\": 1, \"valueDifference\": 29 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [45,32,30], \"indexDifference\": 2, \"valueDifference\": 45 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [0,2,5,8], \"indexDifference\": 1, \"valueDifference\": 3 }\nassert my_solution.findIndices(**test_input) == [0,2]\n\ntest_input = { \"nums\": [0,4,7,2], \"indexDifference\": 2, \"valueDifference\": 7 }\nassert my_solution.findIndices(**test_input) == [0,2]\n\ntest_input = { \"nums\": [1,3,4,4], \"indexDifference\": 2, \"valueDifference\": 2 }\nassert my_solution.findIndices(**test_input) == [0,2]\n\ntest_input = { \"nums\": [1,8,6,10], \"indexDifference\": 2, \"valueDifference\": 5 }\nassert my_solution.findIndices(**test_input) == [0,2]\n\ntest_input = { \"nums\": [2,0,9,2], \"indexDifference\": 2, \"valueDifference\": 4 }\nassert my_solution.findIndices(**test_input) == [0,2]\n\ntest_input = { \"nums\": [7,4,8,3], \"indexDifference\": 3, \"valueDifference\": 7 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [9,4,0,9], \"indexDifference\": 2, \"valueDifference\": 1 }\nassert my_solution.findIndices(**test_input) == [0,2]\n\ntest_input = { \"nums\": [9,9,7,7], \"indexDifference\": 3, \"valueDifference\": 7 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [10,33,39,15], \"indexDifference\": 1, \"valueDifference\": 12 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [22,28,50,25], \"indexDifference\": 0, \"valueDifference\": 28 }\nassert my_solution.findIndices(**test_input) == [0,2]\n\ntest_input = { \"nums\": [36,35,45,34], \"indexDifference\": 1, \"valueDifference\": 31 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [50,21,32,5], \"indexDifference\": 0, \"valueDifference\": 26 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [0,6,2,10,4], \"indexDifference\": 3, \"valueDifference\": 5 }\nassert my_solution.findIndices(**test_input) == [0,3]\n\ntest_input = { \"nums\": [0,8,2,5,10], \"indexDifference\": 0, \"valueDifference\": 10 }\nassert my_solution.findIndices(**test_input) == [0,4]\n\ntest_input = { \"nums\": [0,9,0,5,9], \"indexDifference\": 3, \"valueDifference\": 5 }\nassert my_solution.findIndices(**test_input) == [0,3]\n\ntest_input = { \"nums\": [0,9,4,9,9], \"indexDifference\": 0, \"valueDifference\": 8 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [3,7,7,10,10], \"indexDifference\": 2, \"valueDifference\": 6 }\nassert my_solution.findIndices(**test_input) == [0,3]\n\ntest_input = { \"nums\": [4,0,1,5,0], \"indexDifference\": 0, \"valueDifference\": 3 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [4,1,7,0,3], \"indexDifference\": 1, \"valueDifference\": 0 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [6,0,6,7,9], \"indexDifference\": 0, \"valueDifference\": 0 }\nassert my_solution.findIndices(**test_input) == [0,0]\n\ntest_input = { \"nums\": [6,19,40,41,36], \"indexDifference\": 0, \"valueDifference\": 34 }\nassert my_solution.findIndices(**test_input) == [0,2]\n\ntest_input = { \"nums\": [7,10,4,5,1], \"indexDifference\": 2, \"valueDifference\": 6 }\nassert my_solution.findIndices(**test_input) == [1,4]\n\ntest_input = { \"nums\": [9,1,7,8,5], \"indexDifference\": 2, \"valueDifference\": 1 }\nassert my_solution.findIndices(**test_input) == [0,2]\n\ntest_input = { \"nums\": [10,39,25,12,7], \"indexDifference\": 1, \"valueDifference\": 35 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [15,28,50,37,43], \"indexDifference\": 2, \"valueDifference\": 46 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [0,6,6,0,0,6], \"indexDifference\": 2, \"valueDifference\": 3 }\nassert my_solution.findIndices(**test_input) == [0,2]\n\ntest_input = { \"nums\": [1,7,4,4,5,3], \"indexDifference\": 0, \"valueDifference\": 0 }\nassert my_solution.findIndices(**test_input) == [0,0]\n\ntest_input = { \"nums\": [3,3,1,6,3,3], \"indexDifference\": 3, \"valueDifference\": 6 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [3,3,4,1,3,7], \"indexDifference\": 3, \"valueDifference\": 7 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [4,3,8,6,2,8], \"indexDifference\": 2, \"valueDifference\": 3 }\nassert my_solution.findIndices(**test_input) == [0,2]\n\ntest_input = { \"nums\": [6,1,2,9,6,5], \"indexDifference\": 1, \"valueDifference\": 1 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [6,5,5,10,4,3], \"indexDifference\": 1, \"valueDifference\": 5 }\nassert my_solution.findIndices(**test_input) == [1,3]\n\ntest_input = { \"nums\": [6,7,0,2,2,6], \"indexDifference\": 1, \"valueDifference\": 0 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [7,6,3,5,9,5], \"indexDifference\": 2, \"valueDifference\": 6 }\nassert my_solution.findIndices(**test_input) == [2,4]\n\ntest_input = { \"nums\": [9,1,0,4,3,3], \"indexDifference\": 4, \"valueDifference\": 3 }\nassert my_solution.findIndices(**test_input) == [0,4]\n\ntest_input = { \"nums\": [9,8,8,0,1,4], \"indexDifference\": 3, \"valueDifference\": 9 }\nassert my_solution.findIndices(**test_input) == [0,3]\n\ntest_input = { \"nums\": [25,49,11,15,32,33], \"indexDifference\": 2, \"valueDifference\": 37 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [0,44,42,26,15,37,23], \"indexDifference\": 0, \"valueDifference\": 17 }\nassert my_solution.findIndices(**test_input) == [0,1]\n\ntest_input = { \"nums\": [3,5,3,44,8,47,10], \"indexDifference\": 3, \"valueDifference\": 7 }\nassert my_solution.findIndices(**test_input) == [0,3]\n\ntest_input = { \"nums\": [3,8,8,0,2,0,10], \"indexDifference\": 4, \"valueDifference\": 2 }\nassert my_solution.findIndices(**test_input) == [0,5]\n\ntest_input = { \"nums\": [5,1,0,7,5,2,0], \"indexDifference\": 4, \"valueDifference\": 3 }\nassert my_solution.findIndices(**test_input) == [0,5]\n\ntest_input = { \"nums\": [9,10,1,3,1,5,0], \"indexDifference\": 2, \"valueDifference\": 2 }\nassert my_solution.findIndices(**test_input) == [0,2]\n\ntest_input = { \"nums\": [13,3,15,48,32,19,33], \"indexDifference\": 1, \"valueDifference\": 25 }\nassert my_solution.findIndices(**test_input) == [1,3]\n\ntest_input = { \"nums\": [29,12,42,16,50,22,10], \"indexDifference\": 2, \"valueDifference\": 29 }\nassert my_solution.findIndices(**test_input) == [1,4]\n\ntest_input = { \"nums\": [30,48,12,15,43,17,13], \"indexDifference\": 3, \"valueDifference\": 7 }\nassert my_solution.findIndices(**test_input) == [0,3]\n\ntest_input = { \"nums\": [31,33,46,4,13,45,37], \"indexDifference\": 0, \"valueDifference\": 7 }\nassert my_solution.findIndices(**test_input) == [0,2]\n\ntest_input = { \"nums\": [43,37,25,44,45,21,47], \"indexDifference\": 1, \"valueDifference\": 37 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [0,4,0,4,1,2,1,9], \"indexDifference\": 1, \"valueDifference\": 7 }\nassert my_solution.findIndices(**test_input) == [0,7]\n\ntest_input = { \"nums\": [0,7,3,2,6,1,7,4], \"indexDifference\": 4, \"valueDifference\": 3 }\nassert my_solution.findIndices(**test_input) == [0,4]\n\ntest_input = { \"nums\": [2,10,2,0,6,0,7,7], \"indexDifference\": 2, \"valueDifference\": 3 }\nassert my_solution.findIndices(**test_input) == [1,3]\n\ntest_input = { \"nums\": [3,9,6,10,10,3,2,9], \"indexDifference\": 5, \"valueDifference\": 10 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [4,4,3,0,6,1,7,8], \"indexDifference\": 3, \"valueDifference\": 6 }\nassert my_solution.findIndices(**test_input) == [3,6]\n\ntest_input = { \"nums\": [4,6,3,4,2,4,5,2], \"indexDifference\": 2, \"valueDifference\": 5 }\nassert my_solution.findIndices(**test_input) == [-1,-1]\n\ntest_input = { \"nums\": [6,5,6,3,0,10,9,8], \"indexDifference\": 2, \"valueDifference\": 2 }\nassert my_solution.findIndices(**test_input) == [1,3]\n\ntest_input = { \"nums\": [7,4,3,1,6,6,2,6], \"indexDifference\": 3, \"valueDifference\": 7 }\nassert my_solution.findIndices(**test_input) == [-1,-1]", "start_time": 1697337000} +{"task_id": "weekly-contest-367-construct-product-matrix", "url": "https://leetcode.com/problems/construct-product-matrix", "title": "construct-product-matrix", "meta": {"questionId": "3031", "questionFrontendId": "2906", "title": "Construct Product Matrix", "titleSlug": "construct-product-matrix", "isPaidOnly": false, "difficulty": "Medium", "likes": 187, "dislikes": 11, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nGiven a 0-indexed 2D integer matrix grid of size n * m, we define a 0-indexed 2D matrix p of size n * m as the product matrix of grid if the following condition is met:\n\n * Each element p[i][j] is calculated as the product of all elements in grid except for the element grid[i][j]. This product is then taken modulo 12345.\n\nReturn the product matrix of grid.\n\nExample 1:\n\nInput: grid = [[1,2],[3,4]]\nOutput: [[24,12],[8,6]]\nExplanation: p[0][0] = grid[0][1] * grid[1][0] * grid[1][1] = 2 * 3 * 4 = 24\np[0][1] = grid[0][0] * grid[1][0] * grid[1][1] = 1 * 3 * 4 = 12\np[1][0] = grid[0][0] * grid[0][1] * grid[1][1] = 1 * 2 * 4 = 8\np[1][1] = grid[0][0] * grid[0][1] * grid[1][0] = 1 * 2 * 3 = 6\nSo the answer is [[24,12],[8,6]].\n\nExample 2:\n\nInput: grid = [[12345],[2],[1]]\nOutput: [[2],[0],[0]]\nExplanation: p[0][0] = grid[0][1] * grid[0][2] = 2 * 1 = 2.\np[0][1] = grid[0][0] * grid[0][2] = 12345 * 1 = 12345. 12345 % 12345 = 0. So p[0][1] = 0.\np[0][2] = grid[0][0] * grid[0][1] = 12345 * 2 = 24690. 24690 % 12345 = 0. So p[0][2] = 0.\nSo the answer is [[2],[0],[0]].\n\nConstraints:\n\n * 1 <= n == grid.length <= 105\n * 1 <= m == grid[i].length <= 105\n * 2 <= n * m <= 105\n * 1 <= grid[i][j] <= 109\n\"\"\"\nclass Solution:\n def constructProductMatrix(self, grid: List[List[int]]) -> List[List[int]]:\n ", "prompt_sft": "Given a 0-indexed 2D integer matrix grid of size n * m, we define a 0-indexed 2D matrix p of size n * m as the product matrix of grid if the following condition is met:\n\n * Each element p[i][j] is calculated as the product of all elements in grid except for the element grid[i][j]. This product is then taken modulo 12345.\n\nReturn the product matrix of grid.\n\nExample 1:\n\nInput: grid = [[1,2],[3,4]]\nOutput: [[24,12],[8,6]]\nExplanation: p[0][0] = grid[0][1] * grid[1][0] * grid[1][1] = 2 * 3 * 4 = 24\np[0][1] = grid[0][0] * grid[1][0] * grid[1][1] = 1 * 3 * 4 = 12\np[1][0] = grid[0][0] * grid[0][1] * grid[1][1] = 1 * 2 * 4 = 8\np[1][1] = grid[0][0] * grid[0][1] * grid[1][0] = 1 * 2 * 3 = 6\nSo the answer is [[24,12],[8,6]].\n\nExample 2:\n\nInput: grid = [[12345],[2],[1]]\nOutput: [[2],[0],[0]]\nExplanation: p[0][0] = grid[0][1] * grid[0][2] = 2 * 1 = 2.\np[0][1] = grid[0][0] * grid[0][2] = 12345 * 1 = 12345. 12345 % 12345 = 0. So p[0][1] = 0.\np[0][2] = grid[0][0] * grid[0][1] = 12345 * 2 = 24690. 24690 % 12345 = 0. So p[0][2] = 0.\nSo the answer is [[2],[0],[0]].\n\nConstraints:\n\n * 1 <= n == grid.length <= 105\n * 1 <= m == grid[i].length <= 105\n * 2 <= n * m <= 105\n * 1 <= grid[i][j] <= 109\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def constructProductMatrix(self, grid: List[List[int]]) -> List[List[int]]:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"grid\": [[1,2],[3,4]] }\nassert my_solution.constructProductMatrix(**test_input) == [[24,12],[8,6]]\n\ntest_input = { \"grid\": [[12345],[2],[1]] }\nassert my_solution.constructProductMatrix(**test_input) == [[2],[0],[0]]\n\ntest_input = { \"grid\": [[1],[2]] }\nassert my_solution.constructProductMatrix(**test_input) == [[2],[1]]\n\ntest_input = { \"grid\": [[1,2]] }\nassert my_solution.constructProductMatrix(**test_input) == [[2,1]]\n\ntest_input = { \"grid\": [[12345,12345]] }\nassert my_solution.constructProductMatrix(**test_input) == [[0,0]]\n\ntest_input = { \"grid\": [[1],[4]] }\nassert my_solution.constructProductMatrix(**test_input) == [[4],[1]]\n\ntest_input = { \"grid\": [[3],[4]] }\nassert my_solution.constructProductMatrix(**test_input) == [[4],[3]]\n\ntest_input = { \"grid\": [[4],[3]] }\nassert my_solution.constructProductMatrix(**test_input) == [[3],[4]]\n\ntest_input = { \"grid\": [[1,1,1]] }\nassert my_solution.constructProductMatrix(**test_input) == [[1,1,1]]\n\ntest_input = { \"grid\": [[2,1,1]] }\nassert my_solution.constructProductMatrix(**test_input) == [[1,2,2]]\n\ntest_input = { \"grid\": [[3],[5],[2]] }\nassert my_solution.constructProductMatrix(**test_input) == [[10],[6],[15]]\n\ntest_input = { \"grid\": [[1,2],[1,1],[6,4]] }\nassert my_solution.constructProductMatrix(**test_input) == [[48,24],[48,48],[8,12]]\n\ntest_input = { \"grid\": [[1,2,2],[1,4,3]] }\nassert my_solution.constructProductMatrix(**test_input) == [[48,24,24],[48,12,16]]\n\ntest_input = { \"grid\": [[2],[7],[2],[6]] }\nassert my_solution.constructProductMatrix(**test_input) == [[84],[24],[84],[28]]\n\ntest_input = { \"grid\": [[3],[4],[7],[7]] }\nassert my_solution.constructProductMatrix(**test_input) == [[196],[147],[84],[84]]\n\ntest_input = { \"grid\": [[3,1,1],[1,3,4]] }\nassert my_solution.constructProductMatrix(**test_input) == [[12,36,36],[36,12,9]]\n\ntest_input = { \"grid\": [[4],[8],[3],[7]] }\nassert my_solution.constructProductMatrix(**test_input) == [[168],[84],[224],[96]]\n\ntest_input = { \"grid\": [[5],[8],[8],[3]] }\nassert my_solution.constructProductMatrix(**test_input) == [[192],[120],[120],[320]]\n\ntest_input = { \"grid\": [[6],[5],[8],[5]] }\nassert my_solution.constructProductMatrix(**test_input) == [[200],[240],[150],[240]]\n\ntest_input = { \"grid\": [[8],[1],[3],[8]] }\nassert my_solution.constructProductMatrix(**test_input) == [[24],[192],[64],[24]]\n\ntest_input = { \"grid\": [[1],[10],[3],[10],[9]] }\nassert my_solution.constructProductMatrix(**test_input) == [[2700],[270],[900],[270],[300]]\n\ntest_input = { \"grid\": [[1,1,1,1,1]] }\nassert my_solution.constructProductMatrix(**test_input) == [[1,1,1,1,1]]\n\ntest_input = { \"grid\": [[1,1,2,2,1]] }\nassert my_solution.constructProductMatrix(**test_input) == [[4,4,2,2,4]]\n\ntest_input = { \"grid\": [[1,2,3],[3,3,5],[3,4,2]] }\nassert my_solution.constructProductMatrix(**test_input) == [[6480,3240,2160],[2160,2160,1296],[2160,1620,3240]]\n\ntest_input = { \"grid\": [[2],[7],[5],[3],[4]] }\nassert my_solution.constructProductMatrix(**test_input) == [[420],[120],[168],[280],[210]]\n\ntest_input = { \"grid\": [[2,2,2,2,1]] }\nassert my_solution.constructProductMatrix(**test_input) == [[8,8,8,8,16]]\n\ntest_input = { \"grid\": [[2,2,4,4],[3,2,1,4]] }\nassert my_solution.constructProductMatrix(**test_input) == [[768,768,384,384],[512,768,1536,384]]\n\ntest_input = { \"grid\": [[2,4,1,1],[3,4,4,1]] }\nassert my_solution.constructProductMatrix(**test_input) == [[192,96,384,384],[128,96,96,384]]\n\ntest_input = { \"grid\": [[3,1,1,4],[1,4,1,1]] }\nassert my_solution.constructProductMatrix(**test_input) == [[16,48,48,12],[48,12,48,48]]\n\ntest_input = { \"grid\": [[3,2,5],[6,4,3],[6,3,1]] }\nassert my_solution.constructProductMatrix(**test_input) == [[615,7095,7776],[6480,9720,615],[6480,615,1845]]\n\ntest_input = { \"grid\": [[5,5,5],[4,3,1],[4,5,1]] }\nassert my_solution.constructProductMatrix(**test_input) == [[6000,6000,6000],[7500,10000,5310],[7500,6000,5310]]\n\ntest_input = { \"grid\": [[6,3],[1,5],[2,7],[6,5]] }\nassert my_solution.constructProductMatrix(**test_input) == [[6300,255],[765,7560],[6555,5400],[6300,7560]]\n\ntest_input = { \"grid\": [[6,3,2],[2,3,1],[5,5,4]] }\nassert my_solution.constructProductMatrix(**test_input) == [[3600,7200,10800],[10800,7200,9255],[4320,4320,5400]]\n\ntest_input = { \"grid\": [[6,5,3],[4,4,5],[3,2,5]] }\nassert my_solution.constructProductMatrix(**test_input) == [[11310,6165,10275],[4620,4620,6165],[10275,9240,6165]]\n\ntest_input = { \"grid\": [[8],[5],[5],[9],[8]] }\nassert my_solution.constructProductMatrix(**test_input) == [[1800],[2880],[2880],[1600],[1800]]\n\ntest_input = { \"grid\": [[10],[5],[6],[8],[6]] }\nassert my_solution.constructProductMatrix(**test_input) == [[1440],[2880],[2400],[1800],[2400]]\n\ntest_input = { \"grid\": [[10],[9],[3],[4],[3]] }\nassert my_solution.constructProductMatrix(**test_input) == [[324],[360],[1080],[810],[1080]]\n\ntest_input = { \"grid\": [[1,1,1,2,2,1]] }\nassert my_solution.constructProductMatrix(**test_input) == [[4,4,4,2,2,4]]\n\ntest_input = { \"grid\": [[1,1,2,1,2,1]] }\nassert my_solution.constructProductMatrix(**test_input) == [[4,4,2,4,2,4]]\n\ntest_input = { \"grid\": [[1,1,2,1,2,2]] }\nassert my_solution.constructProductMatrix(**test_input) == [[8,8,4,8,4,4]]\n\ntest_input = { \"grid\": [[1,1,2,2,1,2]] }\nassert my_solution.constructProductMatrix(**test_input) == [[8,8,4,4,8,4]]\n\ntest_input = { \"grid\": [[1,1,2,2,2,2]] }\nassert my_solution.constructProductMatrix(**test_input) == [[16,16,8,8,8,8]]\n\ntest_input = { \"grid\": [[1,1,3,3],[3,4,4,2],[6,6,3,4]] }\nassert my_solution.constructProductMatrix(**test_input) == [[2898,2898,966,966],[966,6897,6897,1449],[483,483,966,6897]]\n\ntest_input = { \"grid\": [[1,2,1,1,1,2]] }\nassert my_solution.constructProductMatrix(**test_input) == [[4,2,4,4,4,2]]\n\ntest_input = { \"grid\": [[1,2,1,1,2,2]] }\nassert my_solution.constructProductMatrix(**test_input) == [[8,4,8,8,4,4]]\n\ntest_input = { \"grid\": [[1,2,2,4,3],[3,4,1,4,2]] }\nassert my_solution.constructProductMatrix(**test_input) == [[4608,2304,2304,1152,1536],[1536,1152,4608,1152,2304]]\n\ntest_input = { \"grid\": [[1,3,1,3,1],[2,1,3,2,3]] }\nassert my_solution.constructProductMatrix(**test_input) == [[324,108,324,108,324],[162,324,108,162,108]]\n\ntest_input = { \"grid\": [[1,3,3,3,4],[2,2,1,4,4]] }\nassert my_solution.constructProductMatrix(**test_input) == [[6912,2304,2304,2304,1728],[3456,3456,6912,1728,1728]]\n\ntest_input = { \"grid\": [[1,4,5],[1,3,2],[7,2,6],[6,2,2]] }\nassert my_solution.constructProductMatrix(**test_input) == [[7365,11100,11349],[7365,6570,9855],[9870,9855,3285],[3285,9855,9855]]\n\ntest_input = { \"grid\": [[1,6,6,4],[4,1,2,5],[5,4,6,2]] }\nassert my_solution.constructProductMatrix(**test_input) == [[12105,8190,8190,12285],[12285,12105,12225,4890],[4890,12285,8190,12225]]\n\ntest_input = { \"grid\": [[2,1,3,2,1],[3,1,3,1,2]] }\nassert my_solution.constructProductMatrix(**test_input) == [[108,216,72,108,216],[72,216,72,216,108]]\n\ntest_input = { \"grid\": [[2,2,2,1,1,1]] }\nassert my_solution.constructProductMatrix(**test_input) == [[4,4,4,8,8,8]]\n\ntest_input = { \"grid\": [[2,2,2,2,1,2]] }\nassert my_solution.constructProductMatrix(**test_input) == [[16,16,16,16,32,16]]\n\ntest_input = { \"grid\": [[2,2,3,2,3],[3,1,3,2,4]] }\nassert my_solution.constructProductMatrix(**test_input) == [[2592,2592,1728,2592,1728],[1728,5184,1728,2592,1296]]\n\ntest_input = { \"grid\": [[2,3,4],[2,4,2],[1,8,1],[8,8,8]] }\nassert my_solution.constructProductMatrix(**test_input) == [[8697,5798,10521],[8697,10521,8697],[5049,11433,5049],[11433,11433,11433]]\n\ntest_input = { \"grid\": [[2,4,4,5],[5,5,1,4],[4,2,2,5]] }\nassert my_solution.constructProductMatrix(**test_input) == [[10405,11375,11375,9100],[9100,9100,8465,11375],[11375,10405,10405,9100]]\n\ntest_input = { \"grid\": [[3,4,1,1],[3,1,4,4],[1,5,1,5]] }\nassert my_solution.constructProductMatrix(**test_input) == [[4800,3600,2055,2055],[4800,2055,3600,3600],[2055,2880,2055,2880]]\n\ntest_input = { \"grid\": [[3,4,6,3],[4,5,4,4],[5,2,6,3]] }\nassert my_solution.constructProductMatrix(**test_input) == [[11625,11805,11985,11625],[11805,6975,11805,11805],[6975,11265,11985,11625]]\n\ntest_input = { \"grid\": [[4,1,4,4,4],[2,2,2,3,3]] }\nassert my_solution.constructProductMatrix(**test_input) == [[4608,6087,4608,4608,4608],[9216,9216,9216,6144,6144]]\n\ntest_input = { \"grid\": [[4,8,8],[6,2,5],[7,3,7],[6,3,5]] }\nassert my_solution.constructProductMatrix(**test_input) == [[3525,7935,7935],[6465,7050,2820],[7305,585,7305],[6465,585,2820]]\n\ntest_input = { \"grid\": [[6],[8],[2],[12],[6],[4]] }\nassert my_solution.constructProductMatrix(**test_input) == [[4608],[3456],[1479],[2304],[4608],[6912]]\n\ntest_input = { \"grid\": [[6,2,5,2],[5,5,2,3],[4,6,5,2]] }\nassert my_solution.constructProductMatrix(**test_input) == [[3990,11970,12195,11970],[12195,12195,11970,7980],[5985,3990,12195,11970]]\n\ntest_input = { \"grid\": [[6,3,4,3],[6,4,2,5],[3,3,6,1]] }\nassert my_solution.constructProductMatrix(**test_input) == [[9795,7245,8520,7245],[9795,8520,4695,4347],[7245,7245,9795,9390]]\n\ntest_input = { \"grid\": [[6,5,6,6],[3,2,6,4],[1,3,4,1]] }\nassert my_solution.constructProductMatrix(**test_input) == [[2415,2898,2415,2415],[4830,7245,2415,9795],[2145,4830,9795,2145]]\n\ntest_input = { \"grid\": [[7],[11],[12],[7],[12],[7]] }\nassert my_solution.constructProductMatrix(**test_input) == [[3546],[12],[8241],[3546],[8241],[3546]]\n\ntest_input = { \"grid\": [[7,4,5],[2,1,2],[5,3,8],[3,6,7]] }\nassert my_solution.constructProductMatrix(**test_input) == [[12135,5805,2175],[11610,10875,11610],[2175,7740,9075],[7740,3870,12135]]\n\ntest_input = { \"grid\": [[8],[6],[7],[2],[7],[4]] }\nassert my_solution.constructProductMatrix(**test_input) == [[2352],[3136],[2688],[9408],[2688],[4704]]\n\ntest_input = { \"grid\": [[8],[6],[7],[5],[3],[6]] }\nassert my_solution.constructProductMatrix(**test_input) == [[3780],[5040],[4320],[6048],[10080],[5040]]\n\ntest_input = { \"grid\": [[8,1],[9,6],[2,4],[1,3],[3,6]] }\nassert my_solution.constructProductMatrix(**test_input) == [[10983,1449],[8391,6414],[6897,9621],[1449,483],[483,6414]]\n\ntest_input = { \"grid\": [[8,4,3],[7,7,4],[1,2,3],[5,2,4]] }\nassert my_solution.constructProductMatrix(**test_input) == [[8955,5565,11535],[3180,3180,5565],[9915,11130,11535],[1983,11130,5565]]\n\ntest_input = { \"grid\": [[12],[8],[4],[3],[9],[5]] }\nassert my_solution.constructProductMatrix(**test_input) == [[4320],[6480],[615],[4935],[5760],[10368]]\n\ntest_input = { \"grid\": [[1,1,1,1,2,2,2]] }\nassert my_solution.constructProductMatrix(**test_input) == [[8,8,8,8,4,4,4]]\n\ntest_input = { \"grid\": [[1,1,1,2,1,1,1]] }\nassert my_solution.constructProductMatrix(**test_input) == [[2,2,2,1,2,2,2]]\n\ntest_input = { \"grid\": [[1,1,2,1,2,1,2]] }\nassert my_solution.constructProductMatrix(**test_input) == [[8,8,4,8,4,8,4]]\n\ntest_input = { \"grid\": [[1,1,6,5,6],[1,6,6,2,5],[3,4,1,1,4]] }\nassert my_solution.constructProductMatrix(**test_input) == [[11805,11805,12255,4830,12255],[11805,12255,12255,12075,4830],[12165,12210,11805,11805,12210]]\n\ntest_input = { \"grid\": [[1,2,1,1,1,2,2]] }\nassert my_solution.constructProductMatrix(**test_input) == [[8,4,8,8,8,4,4]]\n\ntest_input = { \"grid\": [[1,2,1,2,2,1,1]] }\nassert my_solution.constructProductMatrix(**test_input) == [[8,4,8,4,4,8,8]]\n\ntest_input = { \"grid\": [[1,3,1,2,1,2],[3,2,3,4,2,3]] }\nassert my_solution.constructProductMatrix(**test_input) == [[5184,1728,5184,2592,5184,2592],[1728,2592,1728,1296,2592,1728]]\n\ntest_input = { \"grid\": [[1,3,5,2],[1,3,6,5],[8,1,2,7],[6,2,3,5]] }\nassert my_solution.constructProductMatrix(**test_input) == [[2895,9195,10455,7620],[2895,9195,10770,10455],[1905,2895,7620,10995],[10770,7620,9195,10455]]\n\ntest_input = { \"grid\": [[1,4,4,4,3,3],[1,1,3,4,4,1]] }\nassert my_solution.constructProductMatrix(**test_input) == [[2958,6912,6912,6912,9216,9216],[2958,2958,9216,6912,6912,2958]]\n\ntest_input = { \"grid\": [[1,5,5,6],[4,7,6,1],[2,3,3,6],[3,6,3,7]] }\nassert my_solution.constructProductMatrix(**test_input) == [[6570,11190,11190,1095],[7815,11520,1095,6570],[3285,2190,2190,1095],[2190,1095,2190,11520]]\n\ntest_input = { \"grid\": [[1,6,4,4,1],[6,2,5,1,4],[6,4,3,5,6]] }\nassert my_solution.constructProductMatrix(**test_input) == [[3705,10905,10185,10185,3705],[10905,8025,3210,3705,10185],[10905,10185,9465,3210,10905]]\n\ntest_input = { \"grid\": [[1,7,2,8],[3,7,2,5],[2,3,5,6],[5,4,2,7]] }\nassert my_solution.constructProductMatrix(**test_input) == [[4065,7635,8205,11310],[9585,7635,8205,8220],[8205,9585,8220,10965],[8220,10275,8205,7635]]\n\ntest_input = { \"grid\": [[2,1,1,1,1,2,2]] }\nassert my_solution.constructProductMatrix(**test_input) == [[4,8,8,8,8,4,4]]\n\ntest_input = { \"grid\": [[2,1,1,1,2,2,1]] }\nassert my_solution.constructProductMatrix(**test_input) == [[4,8,8,8,4,4,8]]\n\ntest_input = { \"grid\": [[2,1,2,2,2,2,2]] }\nassert my_solution.constructProductMatrix(**test_input) == [[32,64,32,32,32,32,32]]\n\ntest_input = { \"grid\": [[2,1,3,2,4,4],[1,3,2,2,4,1]] }\nassert my_solution.constructProductMatrix(**test_input) == [[4608,9216,3072,4608,2304,2304],[9216,3072,4608,4608,2304,9216]]\n\ntest_input = { \"grid\": [[2,2,2,2,1,2,1]] }\nassert my_solution.constructProductMatrix(**test_input) == [[16,16,16,16,32,16,32]]\n\ntest_input = { \"grid\": [[2,4,3,3,3,4],[3,1,4,3,4,2]] }\nassert my_solution.constructProductMatrix(**test_input) == [[966,483,8874,8874,8874,483],[8874,1932,483,8874,483,966]]\n\ntest_input = { \"grid\": [[2,5,4,8],[4,6,3,3],[1,5,1,4],[8,6,6,5]] }\nassert my_solution.constructProductMatrix(**test_input) == [[30,4950,15,6180],[15,4125,8250,8250],[60,4950,60,15],[6180,4125,4125,4950]]\n\ntest_input = { \"grid\": [[2,7],[10,12],[2,4],[8,11],[2,12],[11,2]] }\nassert my_solution.constructProductMatrix(**test_input) == [[8340,5910],[6606,5505],[8340,4170],[2085,8250],[8340,5505],[8250,8340]]\n\ntest_input = { \"grid\": [[2,9],[1,4],[10,12],[2,7],[4,10],[10,8]] }\nassert my_solution.constructProductMatrix(**test_input) == [[3435,10365],[6870,7890],[5625,10860],[3435,2745],[7890,5625],[5625,3945]]\n\ntest_input = { \"grid\": [[3],[9],[5],[1],[4],[14],[12]] }\nassert my_solution.constructProductMatrix(**test_input) == [[5550],[10080],[5799],[4305],[10335],[6480],[7560]]\n\ntest_input = { \"grid\": [[3,2,2,2,4,3],[4,1,3,1,1,2]] }\nassert my_solution.constructProductMatrix(**test_input) == [[2304,3456,3456,3456,1728,2304],[1728,6912,2304,6912,6912,3456]]\n\ntest_input = { \"grid\": [[3,2,4,2,2,3],[2,2,4,1,2,3]] }\nassert my_solution.constructProductMatrix(**test_input) == [[9216,1479,6912,1479,1479,9216],[1479,1479,6912,2958,1479,9216]]\n\ntest_input = { \"grid\": [[3,6,2,2,5],[1,4,3,4,1],[4,5,2,4,4]] }\nassert my_solution.constructProductMatrix(**test_input) == [[7590,3795,11385,11385,2085],[10425,11865,7590,11865,10425],[11865,2085,11385,11865,11865]]\n\ntest_input = { \"grid\": [[4,1,5,4,5],[6,5,3,4,4],[3,2,6,2,3]] }\nassert my_solution.constructProductMatrix(**test_input) == [[6945,3090,8025,6945,8025],[8745,8025,5145,6945,6945],[5145,1545,8745,1545,5145]]\n\ntest_input = { \"grid\": [[4,3,9],[3,9,10],[9,7,8],[8,4,7],[6,1,3]] }\nassert my_solution.constructProductMatrix(**test_input) == [[3255,225,75],[225,75,11178],[75,1860,7800],[7800,3255,1860],[6285,675,225]]\n\ntest_input = { \"grid\": [[5,1,1,1,5],[3,4,2,6,6],[3,3,2,5,1]] }\nassert my_solution.constructProductMatrix(**test_input) == [[6105,5835,5835,5835,6105],[6060,4545,9090,3030,3030],[6060,6060,9090,6105,5835]]\n\ntest_input = { \"grid\": [[5,3],[9,2],[2,6],[4,9],[12,2],[10,4]] }\nassert my_solution.constructProductMatrix(**test_input) == [[1050,5865],[10185,2625],[2625,9105],[7485,10185],[10725,2625],[525,7485]]", "start_time": 1697337000} +{"task_id": "biweekly-contest-115-last-visited-integers", "url": "https://leetcode.com/problems/last-visited-integers", "title": "last-visited-integers", "meta": {"questionId": "3164", "questionFrontendId": "2899", "title": "Last Visited Integers", "titleSlug": "last-visited-integers", "isPaidOnly": false, "difficulty": "Easy", "likes": 74, "dislikes": 139, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nGiven a 0-indexed array of strings words where words[i] is either a positive integer represented as a string or the string \"prev\".\n\nStart iterating from the beginning of the array; for every \"prev\" string seen in words, find the last visited integer in words which is defined as follows:\n\n * Let k be the number of consecutive \"prev\" strings seen so far (containing the current string). Let nums be the 0-indexed array of integers seen so far and nums_reverse be the reverse of nums, then the integer at (k - 1)th index of nums_reverse will be the last visited integer for this \"prev\".\n * If k is greater than the total visited integers, then the last visited integer will be -1.\n\nReturn an integer array containing the last visited integers.\n\nExample 1:\n\nInput: words = [\"1\",\"2\",\"prev\",\"prev\",\"prev\"]\nOutput: [2,1,-1]\nExplanation:\nFor \"prev\" at index = 2, last visited integer will be 2 as here the number of consecutive \"prev\" strings is 1, and in the array reverse_nums, 2 will be the first element.\nFor \"prev\" at index = 3, last visited integer will be 1 as there are a total of two consecutive \"prev\" strings including this \"prev\" which are visited, and 1 is the second last visited integer.\nFor \"prev\" at index = 4, last visited integer will be -1 as there are a total of three consecutive \"prev\" strings including this \"prev\" which are visited, but the total number of integers visited is two.\n\nExample 2:\n\nInput: words = [\"1\",\"prev\",\"2\",\"prev\",\"prev\"]\nOutput: [1,2,1]\nExplanation:\nFor \"prev\" at index = 1, last visited integer will be 1.\nFor \"prev\" at index = 3, last visited integer will be 2.\nFor \"prev\" at index = 4, last visited integer will be 1 as there are a total of two consecutive \"prev\" strings including this \"prev\" which are visited, and 1 is the second last visited integer.\n\n\nConstraints:\n\n * 1 <= words.length <= 100\n * words[i] == \"prev\" or 1 <= int(words[i]) <= 100\n\"\"\"\nclass Solution:\n def lastVisitedIntegers(self, words: List[str]) -> List[int]:\n ", "prompt_sft": "Given a 0-indexed array of strings words where words[i] is either a positive integer represented as a string or the string \"prev\".\n\nStart iterating from the beginning of the array; for every \"prev\" string seen in words, find the last visited integer in words which is defined as follows:\n\n * Let k be the number of consecutive \"prev\" strings seen so far (containing the current string). Let nums be the 0-indexed array of integers seen so far and nums_reverse be the reverse of nums, then the integer at (k - 1)th index of nums_reverse will be the last visited integer for this \"prev\".\n * If k is greater than the total visited integers, then the last visited integer will be -1.\n\nReturn an integer array containing the last visited integers.\n\nExample 1:\n\nInput: words = [\"1\",\"2\",\"prev\",\"prev\",\"prev\"]\nOutput: [2,1,-1]\nExplanation:\nFor \"prev\" at index = 2, last visited integer will be 2 as here the number of consecutive \"prev\" strings is 1, and in the array reverse_nums, 2 will be the first element.\nFor \"prev\" at index = 3, last visited integer will be 1 as there are a total of two consecutive \"prev\" strings including this \"prev\" which are visited, and 1 is the second last visited integer.\nFor \"prev\" at index = 4, last visited integer will be -1 as there are a total of three consecutive \"prev\" strings including this \"prev\" which are visited, but the total number of integers visited is two.\n\nExample 2:\n\nInput: words = [\"1\",\"prev\",\"2\",\"prev\",\"prev\"]\nOutput: [1,2,1]\nExplanation:\nFor \"prev\" at index = 1, last visited integer will be 1.\nFor \"prev\" at index = 3, last visited integer will be 2.\nFor \"prev\" at index = 4, last visited integer will be 1 as there are a total of two consecutive \"prev\" strings including this \"prev\" which are visited, and 1 is the second last visited integer.\n\n\nConstraints:\n\n * 1 <= words.length <= 100\n * words[i] == \"prev\" or 1 <= int(words[i]) <= 100\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def lastVisitedIntegers(self, words: List[str]) -> List[int]:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"words\": [\"1\",\"2\",\"prev\",\"prev\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [2,1,-1]\n\ntest_input = { \"words\": [\"1\",\"prev\",\"2\",\"prev\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [1,2,1]\n\ntest_input = { \"words\": [\"prev\",\"prev\",\"prev\",\"27\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,-1,-1]\n\ntest_input = { \"words\": [\"17\",\"42\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == []\n\ntest_input = { \"words\": [\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1]\n\ntest_input = { \"words\": [\"prev\",\"prev\",\"prev\",\"52\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,-1,-1,52]\n\ntest_input = { \"words\": [\"prev\",\"prev\",\"68\",\"prev\",\"prev\",\"53\",\"40\",\"23\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,-1,68,-1,23]\n\ntest_input = { \"words\": [\"99\",\"23\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [23]\n\ntest_input = { \"words\": [\"prev\",\"prev\",\"prev\",\"58\",\"99\",\"prev\",\"10\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,-1,-1,99,10]\n\ntest_input = { \"words\": [\"prev\",\"51\",\"prev\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,51,-1]\n\ntest_input = { \"words\": [\"prev\",\"46\",\"9\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,9]\n\ntest_input = { \"words\": [\"prev\",\"prev\",\"prev\",\"prev\",\"prev\",\"26\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,-1,-1,-1,-1]\n\ntest_input = { \"words\": [\"prev\",\"21\",\"prev\",\"76\",\"82\",\"prev\",\"96\",\"prev\",\"57\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,21,82,96,57]\n\ntest_input = { \"words\": [\"52\",\"4\",\"prev\",\"prev\",\"prev\",\"69\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [4,52,-1]\n\ntest_input = { \"words\": [\"24\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [24]\n\ntest_input = { \"words\": [\"46\",\"prev\",\"78\",\"prev\",\"83\",\"21\",\"prev\",\"94\",\"50\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [46,78,21]\n\ntest_input = { \"words\": [\"14\",\"66\",\"prev\",\"prev\",\"46\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [66,14,46]\n\ntest_input = { \"words\": [\"35\",\"90\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == []\n\ntest_input = { \"words\": [\"prev\",\"9\",\"prev\",\"8\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,9,8]\n\ntest_input = { \"words\": [\"prev\",\"prev\",\"88\",\"71\",\"47\",\"65\",\"24\",\"39\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,-1]\n\ntest_input = { \"words\": [\"45\",\"73\",\"78\",\"2\",\"54\",\"prev\",\"85\",\"62\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [54,62]\n\ntest_input = { \"words\": [\"prev\",\"prev\",\"80\",\"9\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,-1,9]\n\ntest_input = { \"words\": [\"79\",\"19\",\"prev\",\"prev\",\"prev\",\"67\",\"prev\",\"16\",\"2\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [19,79,-1,67]\n\ntest_input = { \"words\": [\"94\",\"prev\",\"prev\",\"prev\",\"prev\",\"prev\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [94,-1,-1,-1,-1,-1]\n\ntest_input = { \"words\": [\"prev\",\"prev\",\"prev\",\"82\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,-1,-1,82]\n\ntest_input = { \"words\": [\"94\",\"14\",\"81\",\"43\",\"prev\",\"43\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [43,43]\n\ntest_input = { \"words\": [\"prev\",\"prev\",\"94\",\"56\",\"prev\",\"32\",\"prev\",\"prev\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,-1,56,32,56,94]\n\ntest_input = { \"words\": [\"93\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == []\n\ntest_input = { \"words\": [\"46\",\"91\",\"3\",\"40\",\"31\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [31]\n\ntest_input = { \"words\": [\"41\",\"prev\",\"17\",\"58\",\"78\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [41]\n\ntest_input = { \"words\": [\"prev\",\"prev\",\"82\",\"41\",\"96\",\"89\",\"71\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,-1]\n\ntest_input = { \"words\": [\"4\",\"prev\",\"50\",\"prev\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [4,50,4]\n\ntest_input = { \"words\": [\"59\",\"76\",\"prev\",\"29\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [76,29]\n\ntest_input = { \"words\": [\"prev\",\"62\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1]\n\ntest_input = { \"words\": [\"6\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [6]\n\ntest_input = { \"words\": [\"prev\",\"prev\",\"prev\",\"prev\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,-1,-1,-1,-1]\n\ntest_input = { \"words\": [\"28\",\"5\",\"35\",\"prev\",\"41\",\"27\",\"70\",\"65\",\"84\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [35]\n\ntest_input = { \"words\": [\"94\",\"45\",\"prev\",\"61\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [45]\n\ntest_input = { \"words\": [\"prev\",\"34\",\"prev\",\"prev\",\"prev\",\"prev\",\"21\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,34,-1,-1,-1,21]\n\ntest_input = { \"words\": [\"prev\",\"12\",\"100\",\"33\",\"prev\",\"85\",\"93\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,33]\n\ntest_input = { \"words\": [\"26\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == []\n\ntest_input = { \"words\": [\"27\",\"prev\",\"prev\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [27,-1,-1]\n\ntest_input = { \"words\": [\"prev\",\"prev\",\"22\",\"33\",\"prev\",\"prev\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,-1,33,22,-1]\n\ntest_input = { \"words\": [\"30\",\"prev\",\"87\",\"prev\",\"19\",\"prev\",\"8\",\"prev\",\"81\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [30,87,19,8]\n\ntest_input = { \"words\": [\"35\",\"prev\",\"47\",\"82\",\"86\",\"84\",\"prev\",\"76\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [35,84,76]\n\ntest_input = { \"words\": [\"prev\",\"87\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1]\n\ntest_input = { \"words\": [\"prev\",\"69\",\"78\",\"prev\",\"prev\",\"16\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,78,69]\n\ntest_input = { \"words\": [\"22\",\"97\",\"prev\",\"2\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [97]\n\ntest_input = { \"words\": [\"72\",\"74\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == []\n\ntest_input = { \"words\": [\"84\",\"prev\",\"prev\",\"21\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [84,-1]\n\ntest_input = { \"words\": [\"64\",\"24\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == []\n\ntest_input = { \"words\": [\"17\",\"prev\",\"59\",\"prev\",\"51\",\"11\",\"prev\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [17,59,11,51]\n\ntest_input = { \"words\": [\"57\",\"prev\",\"27\",\"30\",\"prev\",\"prev\",\"75\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [57,30,27]\n\ntest_input = { \"words\": [\"65\",\"prev\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [65,-1]\n\ntest_input = { \"words\": [\"prev\",\"53\",\"76\",\"54\",\"94\",\"77\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1]\n\ntest_input = { \"words\": [\"89\",\"51\",\"prev\",\"prev\",\"12\",\"prev\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [51,89,12,51]\n\ntest_input = { \"words\": [\"prev\",\"28\",\"25\",\"prev\",\"prev\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,25,28,-1]\n\ntest_input = { \"words\": [\"51\",\"prev\",\"prev\",\"76\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [51,-1]\n\ntest_input = { \"words\": [\"2\",\"24\",\"63\",\"prev\",\"43\",\"19\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [63,19]\n\ntest_input = { \"words\": [\"prev\",\"38\",\"1\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1]\n\ntest_input = { \"words\": [\"56\",\"75\",\"prev\",\"prev\",\"94\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [75,56]\n\ntest_input = { \"words\": [\"prev\",\"prev\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,-1,-1]\n\ntest_input = { \"words\": [\"prev\",\"37\",\"25\",\"31\",\"prev\",\"prev\",\"42\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,31,25]\n\ntest_input = { \"words\": [\"73\",\"30\",\"prev\",\"20\",\"prev\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [30,20,30]\n\ntest_input = { \"words\": [\"85\",\"prev\",\"prev\",\"78\",\"prev\",\"100\",\"8\",\"17\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [85,-1,78,17]\n\ntest_input = { \"words\": [\"prev\",\"55\",\"prev\",\"87\",\"19\",\"prev\",\"13\",\"prev\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,55,19,13,19]\n\ntest_input = { \"words\": [\"prev\",\"prev\",\"5\",\"prev\",\"prev\",\"prev\",\"80\",\"17\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,-1,5,-1,-1]\n\ntest_input = { \"words\": [\"100\",\"3\",\"prev\",\"prev\",\"93\",\"35\",\"prev\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [3,100,35,93]\n\ntest_input = { \"words\": [\"75\",\"7\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == []\n\ntest_input = { \"words\": [\"prev\",\"prev\",\"prev\",\"prev\",\"prev\",\"prev\",\"71\",\"prev\",\"27\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,-1,-1,-1,-1,-1,71]\n\ntest_input = { \"words\": [\"prev\",\"prev\",\"prev\",\"91\",\"44\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,-1,-1,44]\n\ntest_input = { \"words\": [\"prev\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,-1]\n\ntest_input = { \"words\": [\"11\",\"prev\",\"87\",\"prev\",\"prev\",\"94\",\"prev\",\"68\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [11,87,11,94]\n\ntest_input = { \"words\": [\"78\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == []\n\ntest_input = { \"words\": [\"prev\",\"prev\",\"73\",\"prev\",\"prev\",\"27\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,-1,73,-1,27]\n\ntest_input = { \"words\": [\"prev\",\"70\",\"prev\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,70,-1]\n\ntest_input = { \"words\": [\"68\",\"prev\",\"38\",\"prev\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [68,38,68]\n\ntest_input = { \"words\": [\"prev\",\"prev\",\"36\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,-1]\n\ntest_input = { \"words\": [\"prev\",\"prev\",\"36\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,-1,36]\n\ntest_input = { \"words\": [\"18\",\"58\",\"41\",\"prev\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [41,58]\n\ntest_input = { \"words\": [\"prev\",\"prev\",\"35\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,-1]\n\ntest_input = { \"words\": [\"prev\",\"72\",\"prev\",\"96\",\"9\",\"50\",\"prev\",\"52\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,72,50]\n\ntest_input = { \"words\": [\"92\",\"95\",\"47\",\"48\",\"prev\",\"50\",\"34\",\"prev\",\"prev\",\"46\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [48,34,50]\n\ntest_input = { \"words\": [\"36\",\"88\",\"15\",\"99\",\"48\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == []\n\ntest_input = { \"words\": [\"93\",\"prev\",\"2\",\"58\",\"83\",\"90\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [93,90]\n\ntest_input = { \"words\": [\"prev\",\"68\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,68]\n\ntest_input = { \"words\": [\"prev\",\"56\",\"prev\",\"prev\",\"36\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,56,-1,36]\n\ntest_input = { \"words\": [\"53\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [53]\n\ntest_input = { \"words\": [\"5\",\"29\",\"94\",\"3\",\"48\",\"prev\",\"59\",\"90\",\"prev\",\"69\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [48,90]\n\ntest_input = { \"words\": [\"89\",\"prev\",\"prev\",\"75\",\"prev\",\"98\",\"80\",\"prev\",\"68\",\"33\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [89,-1,75,80]\n\ntest_input = { \"words\": [\"prev\",\"93\",\"prev\",\"74\",\"33\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,93]\n\ntest_input = { \"words\": [\"prev\",\"prev\",\"10\",\"25\",\"prev\",\"54\",\"prev\",\"prev\",\"prev\",\"76\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,-1,25,54,25,10]\n\ntest_input = { \"words\": [\"9\",\"prev\",\"14\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [9,14]\n\ntest_input = { \"words\": [\"prev\",\"prev\",\"prev\",\"18\",\"66\",\"92\",\"prev\",\"87\",\"85\",\"25\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,-1,-1,92]\n\ntest_input = { \"words\": [\"prev\",\"prev\",\"prev\",\"16\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,-1,-1,16]\n\ntest_input = { \"words\": [\"prev\",\"prev\",\"99\",\"prev\",\"82\",\"prev\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,-1,99,82,99]\n\ntest_input = { \"words\": [\"prev\",\"5\",\"90\",\"71\",\"prev\",\"prev\",\"61\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,71,90]\n\ntest_input = { \"words\": [\"prev\",\"prev\",\"71\",\"54\",\"prev\",\"20\",\"65\",\"prev\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,-1,54,65,20]\n\ntest_input = { \"words\": [\"prev\",\"85\",\"prev\",\"93\",\"prev\",\"98\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,85,93,98]\n\ntest_input = { \"words\": [\"prev\",\"prev\",\"34\",\"prev\"] }\nassert my_solution.lastVisitedIntegers(**test_input) == [-1,-1,34]", "start_time": 1697293800} +{"task_id": "biweekly-contest-115-longest-unequal-adjacent-groups-subsequence-i", "url": "https://leetcode.com/problems/longest-unequal-adjacent-groups-subsequence-i", "title": "longest-unequal-adjacent-groups-subsequence-i", "meta": {"questionId": "3143", "questionFrontendId": "2900", "title": "Longest Unequal Adjacent Groups Subsequence I", "titleSlug": "longest-unequal-adjacent-groups-subsequence-i", "isPaidOnly": false, "difficulty": "Medium", "likes": 86, "dislikes": 26, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given an integer n, a 0-indexed string array words, and a 0-indexed binary array groups, both arrays having length n.\n\nYou need to select the longest subsequence from an array of indices [0, 1, ..., n - 1], such that for the subsequence denoted as [i0, i1, ..., ik - 1] having length k, groups[ij] != groups[ij + 1], for each j where 0 < j + 1 < k.\n\nReturn a string array containing the words corresponding to the indices (in order) in the selected subsequence. If there are multiple answers, return any of them.\n\nA subsequence of an array is a new array that is formed from the original array by deleting some (possibly none) of the elements without disturbing the relative positions of the remaining elements.\n\nNote: strings in words may be unequal in length.\n\nExample 1:\n\nInput: n = 3, words = [\"e\",\"a\",\"b\"], groups = [0,0,1]\nOutput: [\"e\",\"b\"]\nExplanation: A subsequence that can be selected is [0,2] because groups[0] != groups[2].\nSo, a valid answer is [words[0],words[2]] = [\"e\",\"b\"].\nAnother subsequence that can be selected is [1,2] because groups[1] != groups[2].\nThis results in [words[1],words[2]] = [\"a\",\"b\"].\nIt is also a valid answer.\nIt can be shown that the length of the longest subsequence of indices that satisfies the condition is 2.\n\nExample 2:\n\nInput: n = 4, words = [\"a\",\"b\",\"c\",\"d\"], groups = [1,0,1,1]\nOutput: [\"a\",\"b\",\"c\"]\nExplanation: A subsequence that can be selected is [0,1,2] because groups[0] != groups[1] and groups[1] != groups[2].\nSo, a valid answer is [words[0],words[1],words[2]] = [\"a\",\"b\",\"c\"].\nAnother subsequence that can be selected is [0,1,3] because groups[0] != groups[1] and groups[1] != groups[3].\nThis results in [words[0],words[1],words[3]] = [\"a\",\"b\",\"d\"].\nIt is also a valid answer.\nIt can be shown that the length of the longest subsequence of indices that satisfies the condition is 3.\n\n\nConstraints:\n\n * 1 <= n == words.length == groups.length <= 100\n * 1 <= words[i].length <= 10\n * 0 <= groups[i] < 2\n * words consists of distinct strings.\n * words[i] consists of lowercase English letters.\n\"\"\"\nclass Solution:\n def getWordsInLongestSubsequence(self, n: int, words: List[str], groups: List[int]) -> List[str]:\n ", "prompt_sft": "You are given an integer n, a 0-indexed string array words, and a 0-indexed binary array groups, both arrays having length n.\n\nYou need to select the longest subsequence from an array of indices [0, 1, ..., n - 1], such that for the subsequence denoted as [i0, i1, ..., ik - 1] having length k, groups[ij] != groups[ij + 1], for each j where 0 < j + 1 < k.\n\nReturn a string array containing the words corresponding to the indices (in order) in the selected subsequence. If there are multiple answers, return any of them.\n\nA subsequence of an array is a new array that is formed from the original array by deleting some (possibly none) of the elements without disturbing the relative positions of the remaining elements.\n\nNote: strings in words may be unequal in length.\n\nExample 1:\n\nInput: n = 3, words = [\"e\",\"a\",\"b\"], groups = [0,0,1]\nOutput: [\"e\",\"b\"]\nExplanation: A subsequence that can be selected is [0,2] because groups[0] != groups[2].\nSo, a valid answer is [words[0],words[2]] = [\"e\",\"b\"].\nAnother subsequence that can be selected is [1,2] because groups[1] != groups[2].\nThis results in [words[1],words[2]] = [\"a\",\"b\"].\nIt is also a valid answer.\nIt can be shown that the length of the longest subsequence of indices that satisfies the condition is 2.\n\nExample 2:\n\nInput: n = 4, words = [\"a\",\"b\",\"c\",\"d\"], groups = [1,0,1,1]\nOutput: [\"a\",\"b\",\"c\"]\nExplanation: A subsequence that can be selected is [0,1,2] because groups[0] != groups[1] and groups[1] != groups[2].\nSo, a valid answer is [words[0],words[1],words[2]] = [\"a\",\"b\",\"c\"].\nAnother subsequence that can be selected is [0,1,3] because groups[0] != groups[1] and groups[1] != groups[3].\nThis results in [words[0],words[1],words[3]] = [\"a\",\"b\",\"d\"].\nIt is also a valid answer.\nIt can be shown that the length of the longest subsequence of indices that satisfies the condition is 3.\n\n\nConstraints:\n\n * 1 <= n == words.length == groups.length <= 100\n * 1 <= words[i].length <= 10\n * 0 <= groups[i] < 2\n * words consists of distinct strings.\n * words[i] consists of lowercase English letters.\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def getWordsInLongestSubsequence(self, n: int, words: List[str], groups: List[int]) -> List[str]:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"n\": 3, \"words\": [\"e\",\"a\",\"b\"], \"groups\": [0,0,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"e\",\"b\"]\n\ntest_input = { \"n\": 4, \"words\": [\"a\",\"b\",\"c\",\"d\"], \"groups\": [1,0,1,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"a\",\"b\",\"c\"]\n\ntest_input = { \"n\": 1, \"words\": [\"c\"], \"groups\": [0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"c\"]\n\ntest_input = { \"n\": 1, \"words\": [\"d\"], \"groups\": [1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"d\"]\n\ntest_input = { \"n\": 1, \"words\": [\"e\"], \"groups\": [0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"e\"]\n\ntest_input = { \"n\": 1, \"words\": [\"fe\"], \"groups\": [0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"fe\"]\n\ntest_input = { \"n\": 1, \"words\": [\"frl\"], \"groups\": [1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"frl\"]\n\ntest_input = { \"n\": 1, \"words\": [\"ha\"], \"groups\": [1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ha\"]\n\ntest_input = { \"n\": 1, \"words\": [\"l\"], \"groups\": [0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"l\"]\n\ntest_input = { \"n\": 1, \"words\": [\"n\"], \"groups\": [1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"n\"]\n\ntest_input = { \"n\": 1, \"words\": [\"s\"], \"groups\": [1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"s\"]\n\ntest_input = { \"n\": 2, \"words\": [\"d\",\"g\"], \"groups\": [0,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"d\",\"g\"]\n\ntest_input = { \"n\": 2, \"words\": [\"lr\",\"h\"], \"groups\": [0,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"lr\"]\n\ntest_input = { \"n\": 2, \"words\": [\"wx\",\"h\"], \"groups\": [0,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"wx\",\"h\"]\n\ntest_input = { \"n\": 2, \"words\": [\"yw\",\"n\"], \"groups\": [0,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"yw\",\"n\"]\n\ntest_input = { \"n\": 2, \"words\": [\"z\",\"n\"], \"groups\": [0,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"z\"]\n\ntest_input = { \"n\": 2, \"words\": [\"zr\",\"a\"], \"groups\": [0,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"zr\"]\n\ntest_input = { \"n\": 3, \"words\": [\"h\",\"vv\",\"kp\"], \"groups\": [0,1,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"h\",\"vv\",\"kp\"]\n\ntest_input = { \"n\": 3, \"words\": [\"m\",\"v\",\"y\"], \"groups\": [0,1,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"m\",\"v\",\"y\"]\n\ntest_input = { \"n\": 3, \"words\": [\"o\",\"cfy\",\"en\"], \"groups\": [1,0,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"o\",\"cfy\"]\n\ntest_input = { \"n\": 3, \"words\": [\"tu\",\"rv\",\"bn\"], \"groups\": [0,0,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"tu\"]\n\ntest_input = { \"n\": 4, \"words\": [\"c\",\"f\",\"y\",\"i\"], \"groups\": [1,0,1,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"c\",\"f\",\"y\"]\n\ntest_input = { \"n\": 4, \"words\": [\"c\",\"w\",\"h\",\"s\"], \"groups\": [0,0,0,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"c\",\"s\"]\n\ntest_input = { \"n\": 4, \"words\": [\"d\",\"a\",\"v\",\"b\"], \"groups\": [1,0,0,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"d\",\"a\",\"b\"]\n\ntest_input = { \"n\": 4, \"words\": [\"hh\",\"svj\",\"a\",\"nr\"], \"groups\": [1,1,1,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"hh\"]\n\ntest_input = { \"n\": 4, \"words\": [\"im\",\"j\",\"xq\",\"cjs\"], \"groups\": [1,0,0,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"im\",\"j\",\"cjs\"]\n\ntest_input = { \"n\": 4, \"words\": [\"m\",\"dkg\",\"r\",\"h\"], \"groups\": [1,1,1,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"m\",\"h\"]\n\ntest_input = { \"n\": 4, \"words\": [\"ow\",\"qay\",\"r\",\"j\"], \"groups\": [1,1,1,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ow\"]\n\ntest_input = { \"n\": 4, \"words\": [\"r\",\"k\",\"pb\",\"x\"], \"groups\": [0,0,1,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"r\",\"pb\",\"x\"]\n\ntest_input = { \"n\": 4, \"words\": [\"sq\",\"do\",\"bcj\",\"nm\"], \"groups\": [0,1,1,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"sq\",\"do\",\"nm\"]\n\ntest_input = { \"n\": 4, \"words\": [\"sz\",\"mq\",\"j\",\"u\"], \"groups\": [0,0,1,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"sz\",\"j\",\"u\"]\n\ntest_input = { \"n\": 4, \"words\": [\"x\",\"nf\",\"p\",\"asn\"], \"groups\": [1,1,1,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"x\"]\n\ntest_input = { \"n\": 4, \"words\": [\"z\",\"tkt\",\"x\",\"swy\"], \"groups\": [1,0,1,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"z\",\"tkt\",\"x\"]\n\ntest_input = { \"n\": 5, \"words\": [\"ht\",\"lw\",\"ax\",\"vi\",\"fo\"], \"groups\": [0,0,1,0,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ht\",\"ax\",\"vi\"]\n\ntest_input = { \"n\": 5, \"words\": [\"mc\",\"kh\",\"x\",\"q\",\"z\"], \"groups\": [0,0,1,1,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"mc\",\"x\",\"z\"]\n\ntest_input = { \"n\": 5, \"words\": [\"n\",\"fg\",\"fy\",\"tv\",\"gv\"], \"groups\": [1,1,1,1,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"n\"]\n\ntest_input = { \"n\": 5, \"words\": [\"n\",\"l\",\"e\",\"d\",\"m\"], \"groups\": [1,1,0,1,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"n\",\"e\",\"d\"]\n\ntest_input = { \"n\": 5, \"words\": [\"n\",\"m\",\"g\",\"b\",\"d\"], \"groups\": [0,0,1,0,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"n\",\"g\",\"b\"]\n\ntest_input = { \"n\": 5, \"words\": [\"nz\",\"zwt\",\"hig\",\"s\",\"jze\"], \"groups\": [1,1,1,0,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"nz\",\"s\",\"jze\"]\n\ntest_input = { \"n\": 5, \"words\": [\"o\",\"i\",\"b\",\"k\",\"kz\"], \"groups\": [0,0,1,1,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"o\",\"b\"]\n\ntest_input = { \"n\": 5, \"words\": [\"r\",\"o\",\"k\",\"d\",\"f\"], \"groups\": [0,0,0,1,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"r\",\"d\"]\n\ntest_input = { \"n\": 5, \"words\": [\"sfh\",\"exd\",\"j\",\"w\",\"gc\"], \"groups\": [1,0,1,1,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"sfh\",\"exd\",\"j\"]\n\ntest_input = { \"n\": 5, \"words\": [\"v\",\"f\",\"k\",\"l\",\"p\"], \"groups\": [0,0,1,0,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"v\",\"k\",\"l\"]\n\ntest_input = { \"n\": 5, \"words\": [\"vbd\",\"ua\",\"muo\",\"mu\",\"qi\"], \"groups\": [0,0,0,1,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"vbd\",\"mu\",\"qi\"]\n\ntest_input = { \"n\": 5, \"words\": [\"we\",\"ch\",\"tl\",\"yx\",\"utx\"], \"groups\": [1,0,0,1,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"we\",\"ch\",\"yx\"]\n\ntest_input = { \"n\": 5, \"words\": [\"x\",\"vlk\",\"tds\",\"dfn\",\"kr\"], \"groups\": [0,0,1,1,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"x\",\"tds\",\"kr\"]\n\ntest_input = { \"n\": 5, \"words\": [\"y\",\"j\",\"u\",\"r\",\"f\"], \"groups\": [0,0,1,1,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"y\",\"u\",\"f\"]\n\ntest_input = { \"n\": 5, \"words\": [\"y\",\"r\",\"z\",\"x\",\"q\"], \"groups\": [0,1,0,1,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"y\",\"r\",\"z\",\"x\"]\n\ntest_input = { \"n\": 5, \"words\": [\"yc\",\"fgq\",\"gg\",\"og\",\"tca\"], \"groups\": [0,1,1,1,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"yc\",\"fgq\",\"tca\"]\n\ntest_input = { \"n\": 5, \"words\": [\"z\",\"d\",\"p\",\"c\",\"m\"], \"groups\": [0,0,0,0,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"z\"]\n\ntest_input = { \"n\": 6, \"words\": [\"c\",\"i\",\"to\",\"kv\",\"op\",\"u\"], \"groups\": [0,0,1,0,0,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"c\",\"to\",\"kv\"]\n\ntest_input = { \"n\": 6, \"words\": [\"d\",\"h\",\"e\",\"k\",\"j\",\"r\"], \"groups\": [0,1,1,0,1,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"d\",\"h\",\"k\",\"j\",\"r\"]\n\ntest_input = { \"n\": 6, \"words\": [\"l\",\"f\",\"v\",\"b\",\"w\",\"k\"], \"groups\": [1,0,1,1,0,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"l\",\"f\",\"v\",\"w\"]\n\ntest_input = { \"n\": 6, \"words\": [\"lj\",\"vf\",\"pa\",\"w\",\"z\",\"q\"], \"groups\": [0,0,1,0,0,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"lj\",\"pa\",\"w\"]\n\ntest_input = { \"n\": 7, \"words\": [\"cd\",\"oki\",\"ho\",\"oi\",\"m\",\"yvy\",\"i\"], \"groups\": [1,1,0,1,1,1,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"cd\",\"ho\",\"oi\"]\n\ntest_input = { \"n\": 7, \"words\": [\"exb\",\"c\",\"oq\",\"lq\",\"xh\",\"zmo\",\"aug\"], \"groups\": [1,1,0,1,1,0,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"exb\",\"oq\",\"lq\",\"zmo\"]\n\ntest_input = { \"n\": 7, \"words\": [\"f\",\"r\",\"k\",\"h\",\"m\",\"v\",\"p\"], \"groups\": [1,0,0,0,1,0,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"f\",\"r\",\"m\",\"v\"]\n\ntest_input = { \"n\": 7, \"words\": [\"fd\",\"fc\",\"jm\",\"z\",\"lg\",\"kl\",\"ux\"], \"groups\": [0,1,0,1,0,1,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"fd\",\"fc\",\"jm\",\"z\",\"lg\",\"kl\",\"ux\"]\n\ntest_input = { \"n\": 7, \"words\": [\"ft\",\"iw\",\"m\",\"v\",\"gx\",\"d\",\"pm\"], \"groups\": [1,1,1,0,1,1,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ft\",\"v\",\"gx\"]\n\ntest_input = { \"n\": 7, \"words\": [\"lma\",\"i\",\"rt\",\"xar\",\"bfx\",\"np\",\"x\"], \"groups\": [1,1,1,1,1,0,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"lma\",\"np\",\"x\"]\n\ntest_input = { \"n\": 7, \"words\": [\"nsv\",\"r\",\"o\",\"qo\",\"pb\",\"xqv\",\"clb\"], \"groups\": [1,1,0,0,0,0,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"nsv\",\"o\"]\n\ntest_input = { \"n\": 7, \"words\": [\"p\",\"qdb\",\"zcd\",\"l\",\"tv\",\"ln\",\"ogb\"], \"groups\": [1,1,0,1,0,0,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"p\",\"zcd\",\"l\",\"tv\",\"ogb\"]\n\ntest_input = { \"n\": 7, \"words\": [\"z\",\"cee\",\"j\",\"jqu\",\"w\",\"ljr\",\"k\"], \"groups\": [1,0,1,1,0,0,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"z\",\"cee\",\"j\",\"w\",\"k\"]\n\ntest_input = { \"n\": 8, \"words\": [\"h\",\"p\",\"q\",\"t\",\"j\",\"a\",\"c\",\"n\"], \"groups\": [0,1,1,1,0,0,1,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"h\",\"p\",\"j\",\"c\"]\n\ntest_input = { \"n\": 8, \"words\": [\"r\",\"v\",\"c\",\"t\",\"d\",\"a\",\"x\",\"o\"], \"groups\": [1,1,0,1,1,0,0,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"r\",\"c\",\"t\",\"a\",\"o\"]\n\ntest_input = { \"n\": 8, \"words\": [\"u\",\"l\",\"a\",\"y\",\"j\",\"s\",\"h\",\"q\"], \"groups\": [0,0,0,0,0,1,0,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"u\",\"s\",\"h\"]\n\ntest_input = { \"n\": 8, \"words\": [\"x\",\"mr\",\"yyf\",\"l\",\"z\",\"q\",\"zvj\",\"zqt\"], \"groups\": [0,1,1,1,0,1,1,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"x\",\"mr\",\"z\",\"q\",\"zqt\"]\n\ntest_input = { \"n\": 8, \"words\": [\"y\",\"x\",\"i\",\"xtm\",\"ze\",\"n\",\"cma\",\"dgk\"], \"groups\": [0,1,0,0,1,1,0,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"y\",\"x\",\"i\",\"ze\",\"cma\"]\n\ntest_input = { \"n\": 8, \"words\": [\"yun\",\"x\",\"zpp\",\"bpr\",\"ii\",\"ezg\",\"dn\",\"k\"], \"groups\": [0,1,1,1,1,0,1,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"yun\",\"x\",\"ezg\",\"dn\",\"k\"]\n\ntest_input = { \"n\": 9, \"words\": [\"ckr\",\"iz\",\"top\",\"of\",\"sb\",\"wv\",\"hb\",\"da\",\"wd\"], \"groups\": [1,1,0,1,1,0,0,0,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ckr\",\"top\",\"of\",\"wv\",\"wd\"]\n\ntest_input = { \"n\": 9, \"words\": [\"g\",\"h\",\"u\",\"n\",\"w\",\"o\",\"f\",\"p\",\"m\"], \"groups\": [1,0,0,1,1,0,0,1,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"g\",\"h\",\"n\",\"o\",\"p\",\"m\"]\n\ntest_input = { \"n\": 9, \"words\": [\"ilw\",\"t\",\"dyy\",\"irz\",\"oxy\",\"k\",\"rfj\",\"hi\",\"zxe\"], \"groups\": [1,1,1,0,1,1,0,1,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ilw\",\"irz\",\"oxy\",\"rfj\",\"hi\"]\n\ntest_input = { \"n\": 9, \"words\": [\"l\",\"iuz\",\"d\",\"tfw\",\"mu\",\"a\",\"rp\",\"mrb\",\"wnl\"], \"groups\": [1,1,1,1,1,0,1,1,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"l\",\"a\",\"rp\",\"wnl\"]\n\ntest_input = { \"n\": 9, \"words\": [\"mc\",\"b\",\"yr\",\"cj\",\"zk\",\"wi\",\"esm\",\"yu\",\"cw\"], \"groups\": [0,0,1,1,0,0,1,1,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"mc\",\"yr\",\"zk\",\"esm\",\"cw\"]\n\ntest_input = { \"n\": 9, \"words\": [\"nw\",\"hx\",\"ygc\",\"vjo\",\"jmv\",\"p\",\"juv\",\"b\",\"y\"], \"groups\": [0,1,0,0,1,0,0,1,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"nw\",\"hx\",\"ygc\",\"jmv\",\"p\",\"b\",\"y\"]\n\ntest_input = { \"n\": 9, \"words\": [\"osq\",\"qiw\",\"h\",\"tc\",\"xg\",\"tvt\",\"fqp\",\"zq\",\"b\"], \"groups\": [0,0,1,0,1,1,0,1,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"osq\",\"h\",\"tc\",\"xg\",\"fqp\",\"zq\"]\n\ntest_input = { \"n\": 9, \"words\": [\"vr\",\"lw\",\"e\",\"g\",\"dz\",\"kf\",\"qe\",\"h\",\"p\"], \"groups\": [1,0,0,1,1,0,0,0,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"vr\",\"lw\",\"g\",\"kf\"]\n\ntest_input = { \"n\": 10, \"words\": [\"gy\",\"nd\",\"l\",\"hr\",\"i\",\"qf\",\"zz\",\"nq\",\"e\",\"oa\"], \"groups\": [0,1,0,0,1,0,1,1,1,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"gy\",\"nd\",\"l\",\"i\",\"qf\",\"zz\",\"oa\"]\n\ntest_input = { \"n\": 10, \"words\": [\"j\",\"r\",\"h\",\"t\",\"z\",\"b\",\"a\",\"s\",\"v\",\"q\"], \"groups\": [1,0,1,1,1,1,0,0,0,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"j\",\"r\",\"h\",\"a\",\"q\"]\n\ntest_input = { \"n\": 10, \"words\": [\"k\",\"f\",\"u\",\"h\",\"x\",\"w\",\"c\",\"e\",\"l\",\"p\"], \"groups\": [0,1,1,1,1,1,1,1,1,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"k\",\"f\",\"p\"]\n\ntest_input = { \"n\": 10, \"words\": [\"lj\",\"huy\",\"lg\",\"h\",\"o\",\"b\",\"ava\",\"ay\",\"r\",\"us\"], \"groups\": [1,1,1,1,0,0,1,1,1,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"lj\",\"o\",\"ava\"]\n\ntest_input = { \"n\": 10, \"words\": [\"m\",\"d\",\"xv\",\"dp\",\"nq\",\"xi\",\"e\",\"g\",\"n\",\"qw\"], \"groups\": [1,0,1,1,1,1,0,1,0,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"m\",\"d\",\"xv\",\"e\",\"g\",\"n\",\"qw\"]\n\ntest_input = { \"n\": 10, \"words\": [\"n\",\"c\",\"y\",\"h\",\"w\",\"m\",\"g\",\"t\",\"x\",\"v\"], \"groups\": [1,1,1,0,0,1,0,0,0,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"n\",\"h\",\"m\",\"g\",\"v\"]\n\ntest_input = { \"n\": 10, \"words\": [\"o\",\"w\",\"l\",\"g\",\"m\",\"x\",\"f\",\"q\",\"c\",\"v\"], \"groups\": [1,1,1,0,1,1,1,0,0,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"o\",\"g\",\"m\",\"q\",\"v\"]\n\ntest_input = { \"n\": 10, \"words\": [\"p\",\"mw\",\"m\",\"xld\",\"j\",\"jv\",\"n\",\"so\",\"pkd\",\"rwt\"], \"groups\": [0,0,1,0,1,1,0,0,1,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"p\",\"m\",\"xld\",\"j\",\"n\",\"pkd\"]\n\ntest_input = { \"n\": 10, \"words\": [\"vyv\",\"msl\",\"d\",\"bu\",\"ubl\",\"bgk\",\"sz\",\"njv\",\"pf\",\"s\"], \"groups\": [1,0,1,1,0,0,1,0,1,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"vyv\",\"msl\",\"d\",\"ubl\",\"sz\",\"njv\",\"pf\",\"s\"]\n\ntest_input = { \"n\": 10, \"words\": [\"y\",\"mz\",\"lt\",\"ur\",\"o\",\"m\",\"djh\",\"tb\",\"w\",\"j\"], \"groups\": [0,0,1,0,1,1,0,1,0,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"y\",\"lt\",\"ur\",\"o\",\"djh\",\"tb\",\"w\"]\n\ntest_input = { \"n\": 10, \"words\": [\"y\",\"s\",\"i\",\"v\",\"a\",\"w\",\"l\",\"q\",\"k\",\"t\"], \"groups\": [0,1,1,1,0,1,1,1,0,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"y\",\"s\",\"a\",\"w\",\"k\"]\n\ntest_input = { \"n\": 11, \"words\": [\"a\",\"tea\",\"ldt\",\"ybm\",\"zkw\",\"r\",\"d\",\"dms\",\"le\",\"u\",\"ze\"], \"groups\": [1,1,0,0,0,1,1,1,1,0,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"a\",\"ldt\",\"r\",\"u\",\"ze\"]\n\ntest_input = { \"n\": 11, \"words\": [\"c\",\"o\",\"e\",\"r\",\"x\",\"w\",\"b\",\"d\",\"h\",\"y\",\"z\"], \"groups\": [1,0,1,0,1,0,1,1,1,0,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"c\",\"o\",\"e\",\"r\",\"x\",\"w\",\"b\",\"y\",\"z\"]\n\ntest_input = { \"n\": 11, \"words\": [\"chu\",\"a\",\"qdx\",\"fgd\",\"qe\",\"bqc\",\"x\",\"kbx\",\"sv\",\"ly\",\"br\"], \"groups\": [1,0,0,0,0,0,1,0,1,1,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"chu\",\"a\",\"x\",\"kbx\",\"sv\",\"br\"]\n\ntest_input = { \"n\": 11, \"words\": [\"ec\",\"jdf\",\"b\",\"wa\",\"kjd\",\"bb\",\"ty\",\"yi\",\"ybw\",\"ilj\",\"cv\"], \"groups\": [0,1,0,1,1,1,1,1,1,0,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ec\",\"jdf\",\"b\",\"wa\",\"ilj\",\"cv\"]\n\ntest_input = { \"n\": 11, \"words\": [\"ew\",\"isn\",\"fl\",\"mg\",\"pdg\",\"d\",\"p\",\"hh\",\"e\",\"y\",\"whm\"], \"groups\": [0,0,1,1,0,0,0,0,0,1,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ew\",\"fl\",\"pdg\",\"y\"]\n\ntest_input = { \"n\": 11, \"words\": [\"h\",\"o\",\"d\",\"y\",\"r\",\"c\",\"p\",\"b\",\"g\",\"j\",\"k\"], \"groups\": [1,1,0,1,1,0,1,1,0,0,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"h\",\"d\",\"y\",\"c\",\"p\",\"g\"]\n\ntest_input = { \"n\": 11, \"words\": [\"ipr\",\"l\",\"zy\",\"j\",\"h\",\"hdt\",\"m\",\"d\",\"pd\",\"nv\",\"wy\"], \"groups\": [1,1,1,1,0,1,0,1,1,1,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ipr\",\"h\",\"hdt\",\"m\",\"d\"]\n\ntest_input = { \"n\": 11, \"words\": [\"j\",\"g\",\"go\",\"a\",\"f\",\"bg\",\"o\",\"l\",\"ze\",\"kq\",\"w\"], \"groups\": [0,0,1,0,1,0,0,0,1,0,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"j\",\"go\",\"a\",\"f\",\"bg\",\"ze\",\"kq\",\"w\"]\n\ntest_input = { \"n\": 11, \"words\": [\"j\",\"r\",\"a\",\"g\",\"x\",\"b\",\"y\",\"v\",\"k\",\"i\",\"c\"], \"groups\": [0,1,0,0,0,0,1,1,0,0,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"j\",\"r\",\"a\",\"y\",\"k\"]\n\ntest_input = { \"n\": 11, \"words\": [\"kgo\",\"han\",\"nlu\",\"tv\",\"us\",\"pk\",\"xw\",\"cxc\",\"eml\",\"v\",\"msz\"], \"groups\": [1,0,0,1,0,0,1,0,1,1,0] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"kgo\",\"han\",\"tv\",\"us\",\"xw\",\"cxc\",\"eml\",\"msz\"]\n\ntest_input = { \"n\": 11, \"words\": [\"kh\",\"op\",\"ij\",\"te\",\"hk\",\"pmt\",\"v\",\"ne\",\"en\",\"b\",\"zuj\"], \"groups\": [0,0,1,1,1,0,1,1,0,1,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"kh\",\"ij\",\"pmt\",\"v\",\"en\",\"b\"]\n\ntest_input = { \"n\": 11, \"words\": [\"ms\",\"t\",\"oz\",\"x\",\"pw\",\"ik\",\"d\",\"gj\",\"z\",\"ps\",\"i\"], \"groups\": [1,1,0,1,0,0,1,1,0,0,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ms\",\"oz\",\"x\",\"pw\",\"d\",\"z\",\"i\"]", "start_time": 1697293800} +{"task_id": "biweekly-contest-115-longest-unequal-adjacent-groups-subsequence-ii", "url": "https://leetcode.com/problems/longest-unequal-adjacent-groups-subsequence-ii", "title": "longest-unequal-adjacent-groups-subsequence-ii", "meta": {"questionId": "3142", "questionFrontendId": "2901", "title": "Longest Unequal Adjacent Groups Subsequence II", "titleSlug": "longest-unequal-adjacent-groups-subsequence-ii", "isPaidOnly": false, "difficulty": "Medium", "likes": 172, "dislikes": 16, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given an integer n, a 0-indexed string array words, and a 0-indexed array groups, both arrays having length n.\n\nThe hamming distance between two strings of equal length is the number of positions at which the corresponding characters are different.\n\nYou need to select the longest subsequence from an array of indices [0, 1, ..., n - 1], such that for the subsequence denoted as [i0, i1, ..., ik - 1] having length k, the following holds:\n\n * For adjacent indices in the subsequence, their corresponding groups are unequal, i.e., groups[ij] != groups[ij + 1], for each j where 0 < j + 1 < k.\n * words[ij] and words[ij + 1] are equal in length, and the hamming distance between them is 1, where 0 < j + 1 < k, for all indices in the subsequence.\n\nReturn a string array containing the words corresponding to the indices (in order) in the selected subsequence. If there are multiple answers, return any of them.\n\nA subsequence of an array is a new array that is formed from the original array by deleting some (possibly none) of the elements without disturbing the relative positions of the remaining elements.\n\nNote: strings in words may be unequal in length.\n\nExample 1:\n\nInput: n = 3, words = [\"bab\",\"dab\",\"cab\"], groups = [1,2,2]\nOutput: [\"bab\",\"cab\"]\nExplanation: A subsequence that can be selected is [0,2].\n- groups[0] != groups[2]\n- words[0].length == words[2].length, and the hamming distance between them is 1.\nSo, a valid answer is [words[0],words[2]] = [\"bab\",\"cab\"].\nAnother subsequence that can be selected is [0,1].\n- groups[0] != groups[1]\n- words[0].length == words[1].length, and the hamming distance between them is 1.\nSo, another valid answer is [words[0],words[1]] = [\"bab\",\"dab\"].\nIt can be shown that the length of the longest subsequence of indices that satisfies the conditions is 2.\n\nExample 2:\n\nInput: n = 4, words = [\"a\",\"b\",\"c\",\"d\"], groups = [1,2,3,4]\nOutput: [\"a\",\"b\",\"c\",\"d\"]\nExplanation: We can select the subsequence [0,1,2,3].\nIt satisfies both conditions.\nHence, the answer is [words[0],words[1],words[2],words[3]] = [\"a\",\"b\",\"c\",\"d\"].\nIt has the longest length among all subsequences of indices that satisfy the conditions.\nHence, it is the only answer.\n\n\nConstraints:\n\n * 1 <= n == words.length == groups.length <= 1000\n * 1 <= words[i].length <= 10\n * 1 <= groups[i] <= n\n * words consists of distinct strings.\n * words[i] consists of lowercase English letters.\n\"\"\"\nclass Solution:\n def getWordsInLongestSubsequence(self, n: int, words: List[str], groups: List[int]) -> List[str]:\n ", "prompt_sft": "You are given an integer n, a 0-indexed string array words, and a 0-indexed array groups, both arrays having length n.\n\nThe hamming distance between two strings of equal length is the number of positions at which the corresponding characters are different.\n\nYou need to select the longest subsequence from an array of indices [0, 1, ..., n - 1], such that for the subsequence denoted as [i0, i1, ..., ik - 1] having length k, the following holds:\n\n * For adjacent indices in the subsequence, their corresponding groups are unequal, i.e., groups[ij] != groups[ij + 1], for each j where 0 < j + 1 < k.\n * words[ij] and words[ij + 1] are equal in length, and the hamming distance between them is 1, where 0 < j + 1 < k, for all indices in the subsequence.\n\nReturn a string array containing the words corresponding to the indices (in order) in the selected subsequence. If there are multiple answers, return any of them.\n\nA subsequence of an array is a new array that is formed from the original array by deleting some (possibly none) of the elements without disturbing the relative positions of the remaining elements.\n\nNote: strings in words may be unequal in length.\n\nExample 1:\n\nInput: n = 3, words = [\"bab\",\"dab\",\"cab\"], groups = [1,2,2]\nOutput: [\"bab\",\"cab\"]\nExplanation: A subsequence that can be selected is [0,2].\n- groups[0] != groups[2]\n- words[0].length == words[2].length, and the hamming distance between them is 1.\nSo, a valid answer is [words[0],words[2]] = [\"bab\",\"cab\"].\nAnother subsequence that can be selected is [0,1].\n- groups[0] != groups[1]\n- words[0].length == words[1].length, and the hamming distance between them is 1.\nSo, another valid answer is [words[0],words[1]] = [\"bab\",\"dab\"].\nIt can be shown that the length of the longest subsequence of indices that satisfies the conditions is 2.\n\nExample 2:\n\nInput: n = 4, words = [\"a\",\"b\",\"c\",\"d\"], groups = [1,2,3,4]\nOutput: [\"a\",\"b\",\"c\",\"d\"]\nExplanation: We can select the subsequence [0,1,2,3].\nIt satisfies both conditions.\nHence, the answer is [words[0],words[1],words[2],words[3]] = [\"a\",\"b\",\"c\",\"d\"].\nIt has the longest length among all subsequences of indices that satisfy the conditions.\nHence, it is the only answer.\n\n\nConstraints:\n\n * 1 <= n == words.length == groups.length <= 1000\n * 1 <= words[i].length <= 10\n * 1 <= groups[i] <= n\n * words consists of distinct strings.\n * words[i] consists of lowercase English letters.\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def getWordsInLongestSubsequence(self, n: int, words: List[str], groups: List[int]) -> List[str]:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"n\": 3, \"words\": [\"bab\",\"dab\",\"cab\"], \"groups\": [1,2,2] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"bab\",\"cab\"]\n\ntest_input = { \"n\": 4, \"words\": [\"a\",\"b\",\"c\",\"d\"], \"groups\": [1,2,3,4] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"a\",\"b\",\"c\",\"d\"]\n\ntest_input = { \"n\": 1, \"words\": [\"abbbb\"], \"groups\": [1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"abbbb\"]\n\ntest_input = { \"n\": 1, \"words\": [\"ad\"], \"groups\": [1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ad\"]\n\ntest_input = { \"n\": 1, \"words\": [\"baaccb\"], \"groups\": [1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"baaccb\"]\n\ntest_input = { \"n\": 1, \"words\": [\"bc\"], \"groups\": [1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"bc\"]\n\ntest_input = { \"n\": 1, \"words\": [\"bdb\"], \"groups\": [1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"bdb\"]\n\ntest_input = { \"n\": 1, \"words\": [\"cc\"], \"groups\": [1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"cc\"]\n\ntest_input = { \"n\": 1, \"words\": [\"cd\"], \"groups\": [1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"cd\"]\n\ntest_input = { \"n\": 1, \"words\": [\"cdb\"], \"groups\": [1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"cdb\"]\n\ntest_input = { \"n\": 1, \"words\": [\"cea\"], \"groups\": [1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"cea\"]\n\ntest_input = { \"n\": 1, \"words\": [\"cebbbb\"], \"groups\": [1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"cebbbb\"]\n\ntest_input = { \"n\": 1, \"words\": [\"da\"], \"groups\": [1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"da\"]\n\ntest_input = { \"n\": 1, \"words\": [\"daab\"], \"groups\": [1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"daab\"]\n\ntest_input = { \"n\": 2, \"words\": [\"adbe\",\"acace\"], \"groups\": [2,2] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"acace\"]\n\ntest_input = { \"n\": 2, \"words\": [\"ba\",\"dc\"], \"groups\": [1,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"dc\"]\n\ntest_input = { \"n\": 2, \"words\": [\"baa\",\"ada\"], \"groups\": [1,2] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ada\"]\n\ntest_input = { \"n\": 2, \"words\": [\"bebea\",\"ddecc\"], \"groups\": [1,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ddecc\"]\n\ntest_input = { \"n\": 2, \"words\": [\"cedbca\",\"db\"], \"groups\": [1,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"db\"]\n\ntest_input = { \"n\": 2, \"words\": [\"dbcdd\",\"baba\"], \"groups\": [2,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"baba\"]\n\ntest_input = { \"n\": 2, \"words\": [\"ddb\",\"bdb\"], \"groups\": [1,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"bdb\"]\n\ntest_input = { \"n\": 2, \"words\": [\"dee\",\"bb\"], \"groups\": [2,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"bb\"]\n\ntest_input = { \"n\": 2, \"words\": [\"ecd\",\"dbeed\"], \"groups\": [1,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"dbeed\"]\n\ntest_input = { \"n\": 3, \"words\": [\"aaac\",\"dbede\",\"cbdeee\"], \"groups\": [2,2,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"cbdeee\"]\n\ntest_input = { \"n\": 3, \"words\": [\"aab\",\"ca\",\"cbd\"], \"groups\": [3,3,2] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"cbd\"]\n\ntest_input = { \"n\": 3, \"words\": [\"aeb\",\"bc\",\"abdb\"], \"groups\": [2,3,2] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"abdb\"]\n\ntest_input = { \"n\": 3, \"words\": [\"bdb\",\"aaa\",\"ada\"], \"groups\": [2,1,3] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"aaa\",\"ada\"]\n\ntest_input = { \"n\": 3, \"words\": [\"cc\",\"aa\",\"dda\"], \"groups\": [2,2,2] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"dda\"]\n\ntest_input = { \"n\": 3, \"words\": [\"cc\",\"aba\",\"dbd\"], \"groups\": [1,1,2] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"dbd\"]\n\ntest_input = { \"n\": 3, \"words\": [\"ccd\",\"bb\",\"ccc\"], \"groups\": [1,1,2] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ccd\",\"ccc\"]\n\ntest_input = { \"n\": 3, \"words\": [\"cda\",\"bb\",\"bdc\"], \"groups\": [3,1,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"bdc\"]\n\ntest_input = { \"n\": 3, \"words\": [\"ceea\",\"ade\",\"aeacba\"], \"groups\": [2,1,2] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"aeacba\"]\n\ntest_input = { \"n\": 3, \"words\": [\"db\",\"ccce\",\"edbac\"], \"groups\": [3,2,2] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"edbac\"]\n\ntest_input = { \"n\": 3, \"words\": [\"dba\",\"bb\",\"aa\"], \"groups\": [2,2,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"aa\"]\n\ntest_input = { \"n\": 3, \"words\": [\"dbdaad\",\"daca\",\"cdbdb\"], \"groups\": [1,1,3] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"cdbdb\"]\n\ntest_input = { \"n\": 3, \"words\": [\"dc\",\"bca\",\"ddd\"], \"groups\": [1,3,2] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ddd\"]\n\ntest_input = { \"n\": 3, \"words\": [\"dd\",\"bb\",\"aac\"], \"groups\": [3,3,2] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"aac\"]\n\ntest_input = { \"n\": 3, \"words\": [\"dedcc\",\"cbac\",\"dab\"], \"groups\": [1,3,2] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"dab\"]\n\ntest_input = { \"n\": 3, \"words\": [\"eee\",\"abecab\",\"dc\"], \"groups\": [2,2,3] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"dc\"]\n\ntest_input = { \"n\": 4, \"words\": [\"ac\",\"caa\",\"cda\",\"ba\"], \"groups\": [3,1,2,3] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"caa\",\"cda\"]\n\ntest_input = { \"n\": 4, \"words\": [\"bab\",\"bac\",\"dbd\",\"dd\"], \"groups\": [1,1,3,4] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"dd\"]\n\ntest_input = { \"n\": 4, \"words\": [\"bab\",\"bdd\",\"bca\",\"dab\"], \"groups\": [2,4,1,2] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"dab\"]\n\ntest_input = { \"n\": 4, \"words\": [\"bbbd\",\"babca\",\"ebddde\",\"cce\"], \"groups\": [3,4,3,3] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"cce\"]\n\ntest_input = { \"n\": 4, \"words\": [\"beb\",\"eacedc\",\"aeeb\",\"cdd\"], \"groups\": [1,4,3,2] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"cdd\"]\n\ntest_input = { \"n\": 4, \"words\": [\"cac\",\"aaa\",\"dd\",\"cda\"], \"groups\": [1,4,2,3] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"cda\"]\n\ntest_input = { \"n\": 4, \"words\": [\"cbb\",\"db\",\"bdd\",\"bd\"], \"groups\": [2,3,4,3] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"bd\"]\n\ntest_input = { \"n\": 4, \"words\": [\"cdc\",\"dc\",\"bd\",\"aca\"], \"groups\": [3,2,2,3] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"aca\"]\n\ntest_input = { \"n\": 4, \"words\": [\"ceacd\",\"ac\",\"bebdae\",\"dbbbcb\"], \"groups\": [2,3,1,2] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"dbbbcb\"]\n\ntest_input = { \"n\": 4, \"words\": [\"dcaacc\",\"da\",\"ddcbd\",\"dd\"], \"groups\": [2,3,1,4] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"da\",\"dd\"]\n\ntest_input = { \"n\": 4, \"words\": [\"deeb\",\"edbea\",\"ad\",\"ecedd\"], \"groups\": [1,1,1,2] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ecedd\"]\n\ntest_input = { \"n\": 4, \"words\": [\"ebe\",\"bcca\",\"caabaa\",\"abb\"], \"groups\": [1,4,4,2] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"abb\"]\n\ntest_input = { \"n\": 5, \"words\": [\"abd\",\"bab\",\"bc\",\"ac\",\"acd\"], \"groups\": [3,5,3,3,4] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"abd\",\"acd\"]\n\ntest_input = { \"n\": 5, \"words\": [\"acc\",\"ab\",\"baa\",\"dac\",\"aa\"], \"groups\": [3,1,2,3,3] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ab\",\"aa\"]\n\ntest_input = { \"n\": 5, \"words\": [\"acda\",\"caae\",\"ccad\",\"ac\",\"ddeedb\"], \"groups\": [4,2,4,1,3] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ddeedb\"]\n\ntest_input = { \"n\": 5, \"words\": [\"ade\",\"ea\",\"aabd\",\"bc\",\"aaaabe\"], \"groups\": [4,2,4,4,3] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"aaaabe\"]\n\ntest_input = { \"n\": 5, \"words\": [\"ba\",\"ee\",\"ed\",\"ddddd\",\"ce\"], \"groups\": [4,4,4,5,5] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ee\",\"ce\"]\n\ntest_input = { \"n\": 5, \"words\": [\"bacd\",\"adbbab\",\"ba\",\"ec\",\"deecbe\"], \"groups\": [4,4,5,5,4] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"deecbe\"]\n\ntest_input = { \"n\": 5, \"words\": [\"bad\",\"cab\",\"abb\",\"cd\",\"ba\"], \"groups\": [2,5,3,4,2] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ba\"]\n\ntest_input = { \"n\": 5, \"words\": [\"ca\",\"cb\",\"bcd\",\"bb\",\"ddc\"], \"groups\": [2,4,2,5,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ca\",\"cb\",\"bb\"]\n\ntest_input = { \"n\": 5, \"words\": [\"ccb\",\"ac\",\"aa\",\"bad\",\"ab\"], \"groups\": [3,5,2,2,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ac\",\"aa\",\"ab\"]\n\ntest_input = { \"n\": 5, \"words\": [\"cd\",\"dd\",\"ad\",\"aaa\",\"db\"], \"groups\": [2,3,3,5,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"cd\",\"dd\",\"db\"]\n\ntest_input = { \"n\": 5, \"words\": [\"cda\",\"ab\",\"cb\",\"ccb\",\"baa\"], \"groups\": [3,1,2,1,2] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ab\",\"cb\"]\n\ntest_input = { \"n\": 5, \"words\": [\"dc\",\"eca\",\"cdade\",\"aaaccd\",\"deb\"], \"groups\": [3,2,3,1,4] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"deb\"]\n\ntest_input = { \"n\": 5, \"words\": [\"dceba\",\"dbcab\",\"bacd\",\"bacdab\",\"bdeca\"], \"groups\": [4,3,5,3,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"bdeca\"]\n\ntest_input = { \"n\": 5, \"words\": [\"deeb\",\"ee\",\"bbbbe\",\"bddba\",\"cdb\"], \"groups\": [4,4,1,3,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"cdb\"]\n\ntest_input = { \"n\": 6, \"words\": [\"aab\",\"cab\",\"ba\",\"dba\",\"daa\",\"bca\"], \"groups\": [4,3,4,6,4,3] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"dba\",\"daa\"]\n\ntest_input = { \"n\": 6, \"words\": [\"aca\",\"dd\",\"aab\",\"dac\",\"adb\",\"bad\"], \"groups\": [2,6,2,1,4,3] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"aab\",\"adb\"]\n\ntest_input = { \"n\": 6, \"words\": [\"ad\",\"bb\",\"cc\",\"bc\",\"bcb\",\"abc\"], \"groups\": [3,5,5,5,1,5] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"abc\"]\n\ntest_input = { \"n\": 6, \"words\": [\"bcb\",\"cba\",\"cab\",\"cca\",\"ad\",\"cd\"], \"groups\": [6,5,1,5,5,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ad\",\"cd\"]\n\ntest_input = { \"n\": 6, \"words\": [\"bdaaee\",\"cb\",\"ecaad\",\"accdd\",\"ba\",\"adad\"], \"groups\": [2,4,4,6,1,5] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"adad\"]\n\ntest_input = { \"n\": 6, \"words\": [\"bdccb\",\"cece\",\"dbdda\",\"bbc\",\"bcbae\",\"badc\"], \"groups\": [4,2,4,1,1,6] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"badc\"]\n\ntest_input = { \"n\": 6, \"words\": [\"cba\",\"cc\",\"cd\",\"ccc\",\"aba\",\"ac\"], \"groups\": [3,6,2,4,2,6] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"cba\",\"aba\"]\n\ntest_input = { \"n\": 6, \"words\": [\"ccd\",\"db\",\"cbb\",\"cb\",\"cab\",\"acd\"], \"groups\": [5,1,5,5,6,6] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ccd\",\"acd\"]\n\ntest_input = { \"n\": 6, \"words\": [\"eb\",\"eaab\",\"accdba\",\"ecba\",\"aec\",\"dacacd\"], \"groups\": [4,6,1,6,2,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"dacacd\"]\n\ntest_input = { \"n\": 6, \"words\": [\"ee\",\"aab\",\"db\",\"cc\",\"dead\",\"aee\"], \"groups\": [5,5,4,2,5,6] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"aee\"]\n\ntest_input = { \"n\": 7, \"words\": [\"aad\",\"cba\",\"bda\",\"dc\",\"aba\",\"dbc\",\"ac\"], \"groups\": [6,4,1,7,5,2,6] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"dc\",\"ac\"]\n\ntest_input = { \"n\": 7, \"words\": [\"adcaa\",\"db\",\"dced\",\"ded\",\"eeadce\",\"bdbbe\",\"acaadc\"], \"groups\": [7,5,4,2,1,5,3] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"acaadc\"]\n\ntest_input = { \"n\": 7, \"words\": [\"bcabd\",\"cd\",\"cbaadc\",\"cda\",\"bcde\",\"ccedca\",\"ba\"], \"groups\": [7,3,6,7,1,7,5] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ba\"]\n\ntest_input = { \"n\": 7, \"words\": [\"bd\",\"dbd\",\"dcc\",\"cb\",\"ac\",\"abd\",\"bb\"], \"groups\": [1,3,3,6,6,4,5] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"cb\",\"bb\"]\n\ntest_input = { \"n\": 7, \"words\": [\"cbde\",\"aad\",\"dbdceb\",\"ae\",\"eca\",\"bd\",\"bba\"], \"groups\": [7,5,7,6,4,5,3] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"bba\"]\n\ntest_input = { \"n\": 7, \"words\": [\"cdcdad\",\"baaee\",\"cba\",\"ceae\",\"ab\",\"bedbab\",\"eb\"], \"groups\": [5,3,7,1,7,6,7] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"eb\"]\n\ntest_input = { \"n\": 7, \"words\": [\"dabbdb\",\"eacbdb\",\"bbdea\",\"cdcaa\",\"eaeeb\",\"cebabe\",\"ad\"], \"groups\": [3,5,5,6,3,4,2] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ad\"]\n\ntest_input = { \"n\": 7, \"words\": [\"dbcca\",\"dcdd\",\"bebbc\",\"cbed\",\"cb\",\"abed\",\"ac\"], \"groups\": [4,6,6,6,3,7,6] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"cbed\",\"abed\"]\n\ntest_input = { \"n\": 7, \"words\": [\"dcc\",\"cba\",\"ab\",\"cb\",\"aac\",\"aba\",\"db\"], \"groups\": [3,2,1,6,2,6,6] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ab\",\"db\"]\n\ntest_input = { \"n\": 7, \"words\": [\"ddd\",\"cd\",\"adb\",\"bcc\",\"da\",\"ab\",\"ad\"], \"groups\": [2,3,6,7,3,7,2] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ab\",\"ad\"]\n\ntest_input = { \"n\": 7, \"words\": [\"edded\",\"ab\",\"bc\",\"aeac\",\"ec\",\"db\",\"be\"], \"groups\": [3,2,3,6,3,4,3] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ab\",\"db\"]\n\ntest_input = { \"n\": 8, \"words\": [\"addb\",\"beeddc\",\"dcdce\",\"ddaeed\",\"ddbbb\",\"aeea\",\"adee\",\"dbcbdc\"], \"groups\": [1,5,7,1,5,7,7,4] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"dbcbdc\"]\n\ntest_input = { \"n\": 8, \"words\": [\"ba\",\"cca\",\"dcb\",\"cd\",\"aa\",\"bd\",\"cda\",\"bcb\"], \"groups\": [6,1,2,2,3,7,7,7] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"dcb\",\"bcb\"]\n\ntest_input = { \"n\": 8, \"words\": [\"baa\",\"cb\",\"aab\",\"ddc\",\"bba\",\"cdb\",\"abb\",\"dc\"], \"groups\": [1,8,1,1,8,6,1,1] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"baa\",\"bba\"]\n\ntest_input = { \"n\": 8, \"words\": [\"bbde\",\"edea\",\"dcd\",\"eebbed\",\"ddab\",\"ae\",\"ec\",\"ade\"], \"groups\": [7,3,2,4,7,3,6,4] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ade\"]\n\ntest_input = { \"n\": 8, \"words\": [\"bc\",\"aa\",\"cb\",\"dd\",\"aaa\",\"ccb\",\"da\",\"bbb\"], \"groups\": [5,4,6,8,6,7,7,6] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"dd\",\"da\"]\n\ntest_input = { \"n\": 8, \"words\": [\"bcc\",\"aac\",\"ac\",\"dd\",\"bdd\",\"ada\",\"bbb\",\"db\"], \"groups\": [7,7,1,7,1,1,6,7] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"db\"]\n\ntest_input = { \"n\": 8, \"words\": [\"cb\",\"dcc\",\"da\",\"cbb\",\"bd\",\"dbc\",\"ab\",\"db\"], \"groups\": [4,5,5,7,8,1,3,4] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"cb\",\"ab\",\"db\"]\n\ntest_input = { \"n\": 8, \"words\": [\"cbaeeb\",\"decd\",\"dbc\",\"cbdcca\",\"acbcbe\",\"adccc\",\"eb\",\"ecbbea\"], \"groups\": [6,7,8,6,3,5,1,7] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"ecbbea\"]\n\ntest_input = { \"n\": 8, \"words\": [\"cc\",\"aa\",\"cab\",\"dbc\",\"bbb\",\"adc\",\"cba\",\"cca\"], \"groups\": [6,1,6,6,4,8,1,5] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"cba\",\"cca\"]\n\ntest_input = { \"n\": 8, \"words\": [\"cc\",\"dcd\",\"dac\",\"dc\",\"ac\",\"ad\",\"bbb\",\"cbb\"], \"groups\": [7,7,2,5,4,1,6,2] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"cc\",\"dc\",\"ac\",\"ad\"]\n\ntest_input = { \"n\": 8, \"words\": [\"ccdbdc\",\"dcce\",\"ebedde\",\"ceb\",\"edee\",\"ca\",\"ad\",\"dddee\"], \"groups\": [6,6,3,4,7,1,5,6] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"dddee\"]\n\ntest_input = { \"n\": 8, \"words\": [\"cd\",\"bd\",\"ada\",\"ba\",\"ac\",\"bac\",\"aad\",\"ccb\"], \"groups\": [3,4,8,7,6,7,2,4] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"cd\",\"bd\",\"ba\"]\n\ntest_input = { \"n\": 8, \"words\": [\"da\",\"bd\",\"ccd\",\"dd\",\"ab\",\"cc\",\"aab\",\"ac\"], \"groups\": [6,5,4,8,8,2,2,6] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"cc\",\"ac\"]\n\ntest_input = { \"n\": 8, \"words\": [\"dab\",\"ecedc\",\"badca\",\"cedacb\",\"bdeab\",\"bccedc\",\"bebc\",\"aeade\"], \"groups\": [3,7,6,8,6,6,7,5] }\nassert my_solution.getWordsInLongestSubsequence(**test_input) == [\"aeade\"]", "start_time": 1697293800} +{"task_id": "biweekly-contest-115-count-of-sub-multisets-with-bounded-sum", "url": "https://leetcode.com/problems/count-of-sub-multisets-with-bounded-sum", "title": "count-of-sub-multisets-with-bounded-sum", "meta": {"questionId": "3091", "questionFrontendId": "2902", "title": "Count of Sub-Multisets With Bounded Sum", "titleSlug": "count-of-sub-multisets-with-bounded-sum", "isPaidOnly": false, "difficulty": "Hard", "likes": 125, "dislikes": 19, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed array nums of non-negative integers, and two integers l and r.\n\nReturn the count of sub-multisets within nums where the sum of elements in each subset falls within the inclusive range of [l, r].\n\nSince the answer may be large, return it modulo 109 + 7.\n\nA sub-multiset is an unordered collection of elements of the array in which a given value x can occur 0, 1, ..., occ[x] times, where occ[x] is the number of occurrences of x in the array.\n\nNote that:\n\n * Two sub-multisets are the same if sorting both sub-multisets results in identical multisets.\n * The sum of an empty multiset is 0.\n\nExample 1:\n\nInput: nums = [1,2,2,3], l = 6, r = 6\nOutput: 1\nExplanation: The only subset of nums that has a sum of 6 is {1, 2, 3}.\n\nExample 2:\n\nInput: nums = [2,1,4,2,7], l = 1, r = 5\nOutput: 7\nExplanation: The subsets of nums that have a sum within the range [1, 5] are {1}, {2}, {4}, {2, 2}, {1, 2}, {1, 4}, and {1, 2, 2}.\n\nExample 3:\n\nInput: nums = [1,2,1,3,5,2], l = 3, r = 5\nOutput: 9\nExplanation: The subsets of nums that have a sum within the range [3, 5] are {3}, {5}, {1, 2}, {1, 3}, {2, 2}, {2, 3}, {1, 1, 2}, {1, 1, 3}, and {1, 2, 2}.\n\nConstraints:\n\n * 1 <= nums.length <= 2 * 104\n * 0 <= nums[i] <= 2 * 104\n * Sum of nums does not exceed 2 * 104.\n * 0 <= l <= r <= 2 * 104\n\"\"\"\nclass Solution:\n def countSubMultisets(self, nums: List[int], l: int, r: int) -> int:\n ", "prompt_sft": "You are given a 0-indexed array nums of non-negative integers, and two integers l and r.\n\nReturn the count of sub-multisets within nums where the sum of elements in each subset falls within the inclusive range of [l, r].\n\nSince the answer may be large, return it modulo 109 + 7.\n\nA sub-multiset is an unordered collection of elements of the array in which a given value x can occur 0, 1, ..., occ[x] times, where occ[x] is the number of occurrences of x in the array.\n\nNote that:\n\n * Two sub-multisets are the same if sorting both sub-multisets results in identical multisets.\n * The sum of an empty multiset is 0.\n\nExample 1:\n\nInput: nums = [1,2,2,3], l = 6, r = 6\nOutput: 1\nExplanation: The only subset of nums that has a sum of 6 is {1, 2, 3}.\n\nExample 2:\n\nInput: nums = [2,1,4,2,7], l = 1, r = 5\nOutput: 7\nExplanation: The subsets of nums that have a sum within the range [1, 5] are {1}, {2}, {4}, {2, 2}, {1, 2}, {1, 4}, and {1, 2, 2}.\n\nExample 3:\n\nInput: nums = [1,2,1,3,5,2], l = 3, r = 5\nOutput: 9\nExplanation: The subsets of nums that have a sum within the range [3, 5] are {3}, {5}, {1, 2}, {1, 3}, {2, 2}, {2, 3}, {1, 1, 2}, {1, 1, 3}, and {1, 2, 2}.\n\nConstraints:\n\n * 1 <= nums.length <= 2 * 104\n * 0 <= nums[i] <= 2 * 104\n * Sum of nums does not exceed 2 * 104.\n * 0 <= l <= r <= 2 * 104\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def countSubMultisets(self, nums: List[int], l: int, r: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,2,2,3], \"l\": 6, \"r\": 6 }\nassert my_solution.countSubMultisets(**test_input) == 1\n\ntest_input = { \"nums\": [2,1,4,2,7], \"l\": 1, \"r\": 5 }\nassert my_solution.countSubMultisets(**test_input) == 7\n\ntest_input = { \"nums\": [1,2,1,3,5,2], \"l\": 3, \"r\": 5 }\nassert my_solution.countSubMultisets(**test_input) == 9\n\ntest_input = { \"nums\": [0,0,1,2,3], \"l\": 2, \"r\": 3 }\nassert my_solution.countSubMultisets(**test_input) == 9\n\ntest_input = { \"nums\": [0,0,0,0,0], \"l\": 0, \"r\": 0 }\nassert my_solution.countSubMultisets(**test_input) == 6\n\ntest_input = { \"nums\": [0,0,0,1,2,5,2,3], \"l\": 0, \"r\": 3 }\nassert my_solution.countSubMultisets(**test_input) == 20\n\ntest_input = { \"nums\": [1,1], \"l\": 2, \"r\": 2 }\nassert my_solution.countSubMultisets(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,1], \"l\": 2, \"r\": 2 }\nassert my_solution.countSubMultisets(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,2], \"l\": 2, \"r\": 4 }\nassert my_solution.countSubMultisets(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,1], \"l\": 2, \"r\": 2 }\nassert my_solution.countSubMultisets(**test_input) == 2\n\ntest_input = { \"nums\": [1,2,2], \"l\": 3, \"r\": 5 }\nassert my_solution.countSubMultisets(**test_input) == 3\n\ntest_input = { \"nums\": [2,1,1], \"l\": 1, \"r\": 2 }\nassert my_solution.countSubMultisets(**test_input) == 3\n\ntest_input = { \"nums\": [2,1,2], \"l\": 2, \"r\": 2 }\nassert my_solution.countSubMultisets(**test_input) == 1\n\ntest_input = { \"nums\": [2,2,1], \"l\": 4, \"r\": 5 }\nassert my_solution.countSubMultisets(**test_input) == 2\n\ntest_input = { \"nums\": [2,2,2], \"l\": 3, \"r\": 6 }\nassert my_solution.countSubMultisets(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,1,1], \"l\": 3, \"r\": 3 }\nassert my_solution.countSubMultisets(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,1,2], \"l\": 1, \"r\": 1 }\nassert my_solution.countSubMultisets(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,1,3], \"l\": 4, \"r\": 4 }\nassert my_solution.countSubMultisets(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,2,1], \"l\": 3, \"r\": 4 }\nassert my_solution.countSubMultisets(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,2,2], \"l\": 2, \"r\": 3 }\nassert my_solution.countSubMultisets(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,2,3], \"l\": 4, \"r\": 5 }\nassert my_solution.countSubMultisets(**test_input) == 4\n\ntest_input = { \"nums\": [1,1,3,1], \"l\": 2, \"r\": 3 }\nassert my_solution.countSubMultisets(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,3,2], \"l\": 6, \"r\": 6 }\nassert my_solution.countSubMultisets(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,3,3], \"l\": 8, \"r\": 8 }\nassert my_solution.countSubMultisets(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,1,1], \"l\": 3, \"r\": 3 }\nassert my_solution.countSubMultisets(**test_input) == 2\n\ntest_input = { \"nums\": [1,2,1,2], \"l\": 4, \"r\": 5 }\nassert my_solution.countSubMultisets(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,1,3], \"l\": 4, \"r\": 7 }\nassert my_solution.countSubMultisets(**test_input) == 6\n\ntest_input = { \"nums\": [1,2,2,1], \"l\": 4, \"r\": 5 }\nassert my_solution.countSubMultisets(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,2,2], \"l\": 1, \"r\": 7 }\nassert my_solution.countSubMultisets(**test_input) == 7\n\ntest_input = { \"nums\": [1,2,2,3], \"l\": 3, \"r\": 8 }\nassert my_solution.countSubMultisets(**test_input) == 9\n\ntest_input = { \"nums\": [1,2,3,1], \"l\": 1, \"r\": 4 }\nassert my_solution.countSubMultisets(**test_input) == 7\n\ntest_input = { \"nums\": [1,2,3,2], \"l\": 4, \"r\": 8 }\nassert my_solution.countSubMultisets(**test_input) == 7\n\ntest_input = { \"nums\": [1,2,3,3], \"l\": 6, \"r\": 6 }\nassert my_solution.countSubMultisets(**test_input) == 2\n\ntest_input = { \"nums\": [1,3,1,1], \"l\": 6, \"r\": 6 }\nassert my_solution.countSubMultisets(**test_input) == 1\n\ntest_input = { \"nums\": [1,3,1,2], \"l\": 7, \"r\": 7 }\nassert my_solution.countSubMultisets(**test_input) == 1\n\ntest_input = { \"nums\": [1,3,1,3], \"l\": 5, \"r\": 6 }\nassert my_solution.countSubMultisets(**test_input) == 2\n\ntest_input = { \"nums\": [1,3,2,1], \"l\": 2, \"r\": 2 }\nassert my_solution.countSubMultisets(**test_input) == 2\n\ntest_input = { \"nums\": [1,3,2,2], \"l\": 7, \"r\": 8 }\nassert my_solution.countSubMultisets(**test_input) == 2\n\ntest_input = { \"nums\": [1,3,2,3], \"l\": 1, \"r\": 9 }\nassert my_solution.countSubMultisets(**test_input) == 11\n\ntest_input = { \"nums\": [1,3,3,1], \"l\": 7, \"r\": 7 }\nassert my_solution.countSubMultisets(**test_input) == 1\n\ntest_input = { \"nums\": [1,3,3,2], \"l\": 1, \"r\": 6 }\nassert my_solution.countSubMultisets(**test_input) == 8\n\ntest_input = { \"nums\": [1,3,3,3], \"l\": 9, \"r\": 10 }\nassert my_solution.countSubMultisets(**test_input) == 2\n\ntest_input = { \"nums\": [2,1,1,1], \"l\": 2, \"r\": 3 }\nassert my_solution.countSubMultisets(**test_input) == 4\n\ntest_input = { \"nums\": [2,1,1,2], \"l\": 1, \"r\": 4 }\nassert my_solution.countSubMultisets(**test_input) == 6\n\ntest_input = { \"nums\": [2,1,1,3], \"l\": 7, \"r\": 7 }\nassert my_solution.countSubMultisets(**test_input) == 1\n\ntest_input = { \"nums\": [2,1,2,1], \"l\": 3, \"r\": 3 }\nassert my_solution.countSubMultisets(**test_input) == 1\n\ntest_input = { \"nums\": [2,1,2,2], \"l\": 6, \"r\": 7 }\nassert my_solution.countSubMultisets(**test_input) == 2\n\ntest_input = { \"nums\": [2,1,2,3], \"l\": 7, \"r\": 7 }\nassert my_solution.countSubMultisets(**test_input) == 1\n\ntest_input = { \"nums\": [2,1,3,1], \"l\": 4, \"r\": 4 }\nassert my_solution.countSubMultisets(**test_input) == 2\n\ntest_input = { \"nums\": [2,1,3,2], \"l\": 3, \"r\": 4 }\nassert my_solution.countSubMultisets(**test_input) == 4\n\ntest_input = { \"nums\": [2,1,3,3], \"l\": 1, \"r\": 5 }\nassert my_solution.countSubMultisets(**test_input) == 6\n\ntest_input = { \"nums\": [2,2,1,1], \"l\": 6, \"r\": 6 }\nassert my_solution.countSubMultisets(**test_input) == 1\n\ntest_input = { \"nums\": [2,2,1,2], \"l\": 2, \"r\": 4 }\nassert my_solution.countSubMultisets(**test_input) == 3\n\ntest_input = { \"nums\": [2,2,1,3], \"l\": 6, \"r\": 8 }\nassert my_solution.countSubMultisets(**test_input) == 3\n\ntest_input = { \"nums\": [2,2,2,1], \"l\": 4, \"r\": 7 }\nassert my_solution.countSubMultisets(**test_input) == 4\n\ntest_input = { \"nums\": [2,2,2,2], \"l\": 3, \"r\": 7 }\nassert my_solution.countSubMultisets(**test_input) == 2\n\ntest_input = { \"nums\": [2,2,2,3], \"l\": 5, \"r\": 6 }\nassert my_solution.countSubMultisets(**test_input) == 2\n\ntest_input = { \"nums\": [2,2,3,1], \"l\": 7, \"r\": 7 }\nassert my_solution.countSubMultisets(**test_input) == 1\n\ntest_input = { \"nums\": [2,2,3,2], \"l\": 5, \"r\": 9 }\nassert my_solution.countSubMultisets(**test_input) == 4\n\ntest_input = { \"nums\": [2,2,3,3], \"l\": 4, \"r\": 10 }\nassert my_solution.countSubMultisets(**test_input) == 6\n\ntest_input = { \"nums\": [2,3,1,1], \"l\": 4, \"r\": 6 }\nassert my_solution.countSubMultisets(**test_input) == 5\n\ntest_input = { \"nums\": [2,3,1,2], \"l\": 3, \"r\": 4 }\nassert my_solution.countSubMultisets(**test_input) == 4\n\ntest_input = { \"nums\": [2,3,1,3], \"l\": 2, \"r\": 8 }\nassert my_solution.countSubMultisets(**test_input) == 9\n\ntest_input = { \"nums\": [2,3,2,1], \"l\": 3, \"r\": 3 }\nassert my_solution.countSubMultisets(**test_input) == 2\n\ntest_input = { \"nums\": [2,3,2,2], \"l\": 3, \"r\": 3 }\nassert my_solution.countSubMultisets(**test_input) == 1\n\ntest_input = { \"nums\": [2,3,2,3], \"l\": 5, \"r\": 6 }\nassert my_solution.countSubMultisets(**test_input) == 2\n\ntest_input = { \"nums\": [2,3,3,1], \"l\": 9, \"r\": 9 }\nassert my_solution.countSubMultisets(**test_input) == 1\n\ntest_input = { \"nums\": [2,3,3,2], \"l\": 8, \"r\": 8 }\nassert my_solution.countSubMultisets(**test_input) == 1\n\ntest_input = { \"nums\": [2,3,3,3], \"l\": 3, \"r\": 5 }\nassert my_solution.countSubMultisets(**test_input) == 2\n\ntest_input = { \"nums\": [3,1,1,1], \"l\": 4, \"r\": 4 }\nassert my_solution.countSubMultisets(**test_input) == 1\n\ntest_input = { \"nums\": [3,1,1,2], \"l\": 7, \"r\": 7 }\nassert my_solution.countSubMultisets(**test_input) == 1\n\ntest_input = { \"nums\": [3,1,1,3], \"l\": 1, \"r\": 1 }\nassert my_solution.countSubMultisets(**test_input) == 1\n\ntest_input = { \"nums\": [3,1,2,1], \"l\": 4, \"r\": 4 }\nassert my_solution.countSubMultisets(**test_input) == 2\n\ntest_input = { \"nums\": [3,1,2,2], \"l\": 3, \"r\": 8 }\nassert my_solution.countSubMultisets(**test_input) == 9\n\ntest_input = { \"nums\": [3,1,2,3], \"l\": 5, \"r\": 9 }\nassert my_solution.countSubMultisets(**test_input) == 6\n\ntest_input = { \"nums\": [3,1,3,1], \"l\": 1, \"r\": 4 }\nassert my_solution.countSubMultisets(**test_input) == 4\n\ntest_input = { \"nums\": [3,1,3,2], \"l\": 3, \"r\": 5 }\nassert my_solution.countSubMultisets(**test_input) == 4\n\ntest_input = { \"nums\": [3,1,3,3], \"l\": 9, \"r\": 10 }\nassert my_solution.countSubMultisets(**test_input) == 2\n\ntest_input = { \"nums\": [3,2,1,1], \"l\": 1, \"r\": 5 }\nassert my_solution.countSubMultisets(**test_input) == 9\n\ntest_input = { \"nums\": [3,2,1,2], \"l\": 1, \"r\": 6 }\nassert my_solution.countSubMultisets(**test_input) == 9\n\ntest_input = { \"nums\": [3,2,1,3], \"l\": 5, \"r\": 7 }\nassert my_solution.countSubMultisets(**test_input) == 4\n\ntest_input = { \"nums\": [3,2,2,1], \"l\": 4, \"r\": 4 }\nassert my_solution.countSubMultisets(**test_input) == 2\n\ntest_input = { \"nums\": [3,2,2,2], \"l\": 6, \"r\": 7 }\nassert my_solution.countSubMultisets(**test_input) == 2\n\ntest_input = { \"nums\": [3,2,2,3], \"l\": 2, \"r\": 7 }\nassert my_solution.countSubMultisets(**test_input) == 6\n\ntest_input = { \"nums\": [3,2,3,1], \"l\": 2, \"r\": 3 }\nassert my_solution.countSubMultisets(**test_input) == 3\n\ntest_input = { \"nums\": [3,2,3,2], \"l\": 8, \"r\": 10 }\nassert my_solution.countSubMultisets(**test_input) == 2\n\ntest_input = { \"nums\": [3,2,3,3], \"l\": 1, \"r\": 11 }\nassert my_solution.countSubMultisets(**test_input) == 7\n\ntest_input = { \"nums\": [3,3,1,1], \"l\": 8, \"r\": 8 }\nassert my_solution.countSubMultisets(**test_input) == 1\n\ntest_input = { \"nums\": [3,3,1,2], \"l\": 2, \"r\": 5 }\nassert my_solution.countSubMultisets(**test_input) == 5\n\ntest_input = { \"nums\": [3,3,1,3], \"l\": 1, \"r\": 7 }\nassert my_solution.countSubMultisets(**test_input) == 5\n\ntest_input = { \"nums\": [3,3,2,1], \"l\": 4, \"r\": 6 }\nassert my_solution.countSubMultisets(**test_input) == 4\n\ntest_input = { \"nums\": [3,3,2,2], \"l\": 7, \"r\": 10 }\nassert my_solution.countSubMultisets(**test_input) == 3\n\ntest_input = { \"nums\": [3,3,2,3], \"l\": 4, \"r\": 10 }\nassert my_solution.countSubMultisets(**test_input) == 4\n\ntest_input = { \"nums\": [3,3,3,1], \"l\": 6, \"r\": 9 }\nassert my_solution.countSubMultisets(**test_input) == 3\n\ntest_input = { \"nums\": [3,3,3,2], \"l\": 11, \"r\": 11 }\nassert my_solution.countSubMultisets(**test_input) == 1\n\ntest_input = { \"nums\": [3,3,3,3], \"l\": 8, \"r\": 9 }\nassert my_solution.countSubMultisets(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,1,1,1], \"l\": 3, \"r\": 5 }\nassert my_solution.countSubMultisets(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,1,1,2], \"l\": 2, \"r\": 5 }\nassert my_solution.countSubMultisets(**test_input) == 7\n\ntest_input = { \"nums\": [1,1,1,1,3], \"l\": 6, \"r\": 7 }\nassert my_solution.countSubMultisets(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,1,1,4], \"l\": 8, \"r\": 8 }\nassert my_solution.countSubMultisets(**test_input) == 1", "start_time": 1697293800} +{"task_id": "weekly-contest-366-divisible-and-non-divisible-sums-difference", "url": "https://leetcode.com/problems/divisible-and-non-divisible-sums-difference", "title": "divisible-and-non-divisible-sums-difference", "meta": {"questionId": "3172", "questionFrontendId": "2894", "title": "Divisible and Non-divisible Sums Difference", "titleSlug": "divisible-and-non-divisible-sums-difference", "isPaidOnly": false, "difficulty": "Easy", "likes": 115, "dislikes": 10, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given positive integers n and m.\n\nDefine two integers, num1 and num2, as follows:\n\n * num1: The sum of all integers in the range [1, n] that are not divisible by m.\n * num2: The sum of all integers in the range [1, n] that are divisible by m.\n\nReturn the integer num1 - num2.\n\nExample 1:\n\nInput: n = 10, m = 3\nOutput: 19\nExplanation: In the given example:\n- Integers in the range [1, 10] that are not divisible by 3 are [1,2,4,5,7,8,10], num1 is the sum of those integers = 37.\n- Integers in the range [1, 10] that are divisible by 3 are [3,6,9], num2 is the sum of those integers = 18.\nWe return 37 - 18 = 19 as the answer.\n\nExample 2:\n\nInput: n = 5, m = 6\nOutput: 15\nExplanation: In the given example:\n- Integers in the range [1, 5] that are not divisible by 6 are [1,2,3,4,5], num1 is the sum of those integers = 15.\n- Integers in the range [1, 5] that are divisible by 6 are [], num2 is the sum of those integers = 0.\nWe return 15 - 0 = 15 as the answer.\n\nExample 3:\n\nInput: n = 5, m = 1\nOutput: -15\nExplanation: In the given example:\n- Integers in the range [1, 5] that are not divisible by 1 are [], num1 is the sum of those integers = 0.\n- Integers in the range [1, 5] that are divisible by 1 are [1,2,3,4,5], num2 is the sum of those integers = 15.\nWe return 0 - 15 = -15 as the answer.\n\n\nConstraints:\n\n * 1 <= n, m <= 1000\n\"\"\"\nclass Solution:\n def differenceOfSums(self, n: int, m: int) -> int:\n ", "prompt_sft": "You are given positive integers n and m.\n\nDefine two integers, num1 and num2, as follows:\n\n * num1: The sum of all integers in the range [1, n] that are not divisible by m.\n * num2: The sum of all integers in the range [1, n] that are divisible by m.\n\nReturn the integer num1 - num2.\n\nExample 1:\n\nInput: n = 10, m = 3\nOutput: 19\nExplanation: In the given example:\n- Integers in the range [1, 10] that are not divisible by 3 are [1,2,4,5,7,8,10], num1 is the sum of those integers = 37.\n- Integers in the range [1, 10] that are divisible by 3 are [3,6,9], num2 is the sum of those integers = 18.\nWe return 37 - 18 = 19 as the answer.\n\nExample 2:\n\nInput: n = 5, m = 6\nOutput: 15\nExplanation: In the given example:\n- Integers in the range [1, 5] that are not divisible by 6 are [1,2,3,4,5], num1 is the sum of those integers = 15.\n- Integers in the range [1, 5] that are divisible by 6 are [], num2 is the sum of those integers = 0.\nWe return 15 - 0 = 15 as the answer.\n\nExample 3:\n\nInput: n = 5, m = 1\nOutput: -15\nExplanation: In the given example:\n- Integers in the range [1, 5] that are not divisible by 1 are [], num1 is the sum of those integers = 0.\n- Integers in the range [1, 5] that are divisible by 1 are [1,2,3,4,5], num2 is the sum of those integers = 15.\nWe return 0 - 15 = -15 as the answer.\n\n\nConstraints:\n\n * 1 <= n, m <= 1000\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def differenceOfSums(self, n: int, m: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"n\": 10, \"m\": 3 }\nassert my_solution.differenceOfSums(**test_input) == 19\n\ntest_input = { \"n\": 5, \"m\": 6 }\nassert my_solution.differenceOfSums(**test_input) == 15\n\ntest_input = { \"n\": 5, \"m\": 1 }\nassert my_solution.differenceOfSums(**test_input) == -15\n\ntest_input = { \"n\": 15, \"m\": 9 }\nassert my_solution.differenceOfSums(**test_input) == 102\n\ntest_input = { \"n\": 8, \"m\": 10 }\nassert my_solution.differenceOfSums(**test_input) == 36\n\ntest_input = { \"n\": 23, \"m\": 36 }\nassert my_solution.differenceOfSums(**test_input) == 276\n\ntest_input = { \"n\": 1, \"m\": 32 }\nassert my_solution.differenceOfSums(**test_input) == 1\n\ntest_input = { \"n\": 36, \"m\": 7 }\nassert my_solution.differenceOfSums(**test_input) == 456\n\ntest_input = { \"n\": 3, \"m\": 8 }\nassert my_solution.differenceOfSums(**test_input) == 6\n\ntest_input = { \"n\": 4, \"m\": 2 }\nassert my_solution.differenceOfSums(**test_input) == -2\n\ntest_input = { \"n\": 9, \"m\": 7 }\nassert my_solution.differenceOfSums(**test_input) == 31\n\ntest_input = { \"n\": 20, \"m\": 9 }\nassert my_solution.differenceOfSums(**test_input) == 156\n\ntest_input = { \"n\": 3, \"m\": 19 }\nassert my_solution.differenceOfSums(**test_input) == 6\n\ntest_input = { \"n\": 6, \"m\": 16 }\nassert my_solution.differenceOfSums(**test_input) == 21\n\ntest_input = { \"n\": 6, \"m\": 1 }\nassert my_solution.differenceOfSums(**test_input) == -21\n\ntest_input = { \"n\": 5, \"m\": 25 }\nassert my_solution.differenceOfSums(**test_input) == 15\n\ntest_input = { \"n\": 9, \"m\": 3 }\nassert my_solution.differenceOfSums(**test_input) == 9\n\ntest_input = { \"n\": 8, \"m\": 23 }\nassert my_solution.differenceOfSums(**test_input) == 36\n\ntest_input = { \"n\": 17, \"m\": 1 }\nassert my_solution.differenceOfSums(**test_input) == -153\n\ntest_input = { \"n\": 18, \"m\": 9 }\nassert my_solution.differenceOfSums(**test_input) == 117\n\ntest_input = { \"n\": 22, \"m\": 30 }\nassert my_solution.differenceOfSums(**test_input) == 253\n\ntest_input = { \"n\": 1, \"m\": 42 }\nassert my_solution.differenceOfSums(**test_input) == 1\n\ntest_input = { \"n\": 33, \"m\": 19 }\nassert my_solution.differenceOfSums(**test_input) == 523\n\ntest_input = { \"n\": 7, \"m\": 19 }\nassert my_solution.differenceOfSums(**test_input) == 28\n\ntest_input = { \"n\": 12, \"m\": 24 }\nassert my_solution.differenceOfSums(**test_input) == 78\n\ntest_input = { \"n\": 26, \"m\": 25 }\nassert my_solution.differenceOfSums(**test_input) == 301\n\ntest_input = { \"n\": 9, \"m\": 16 }\nassert my_solution.differenceOfSums(**test_input) == 45\n\ntest_input = { \"n\": 1, \"m\": 8 }\nassert my_solution.differenceOfSums(**test_input) == 1\n\ntest_input = { \"n\": 29, \"m\": 42 }\nassert my_solution.differenceOfSums(**test_input) == 435\n\ntest_input = { \"n\": 2, \"m\": 11 }\nassert my_solution.differenceOfSums(**test_input) == 3\n\ntest_input = { \"n\": 36, \"m\": 10 }\nassert my_solution.differenceOfSums(**test_input) == 546\n\ntest_input = { \"n\": 45, \"m\": 4 }\nassert my_solution.differenceOfSums(**test_input) == 507\n\ntest_input = { \"n\": 3, \"m\": 7 }\nassert my_solution.differenceOfSums(**test_input) == 6\n\ntest_input = { \"n\": 6, \"m\": 12 }\nassert my_solution.differenceOfSums(**test_input) == 21\n\ntest_input = { \"n\": 3, \"m\": 4 }\nassert my_solution.differenceOfSums(**test_input) == 6\n\ntest_input = { \"n\": 8, \"m\": 28 }\nassert my_solution.differenceOfSums(**test_input) == 36\n\ntest_input = { \"n\": 18, \"m\": 23 }\nassert my_solution.differenceOfSums(**test_input) == 171\n\ntest_input = { \"n\": 11, \"m\": 6 }\nassert my_solution.differenceOfSums(**test_input) == 54\n\ntest_input = { \"n\": 35, \"m\": 10 }\nassert my_solution.differenceOfSums(**test_input) == 510\n\ntest_input = { \"n\": 29, \"m\": 18 }\nassert my_solution.differenceOfSums(**test_input) == 399\n\ntest_input = { \"n\": 1, \"m\": 1 }\nassert my_solution.differenceOfSums(**test_input) == -1\n\ntest_input = { \"n\": 12, \"m\": 8 }\nassert my_solution.differenceOfSums(**test_input) == 62\n\ntest_input = { \"n\": 7, \"m\": 12 }\nassert my_solution.differenceOfSums(**test_input) == 28\n\ntest_input = { \"n\": 17, \"m\": 3 }\nassert my_solution.differenceOfSums(**test_input) == 63\n\ntest_input = { \"n\": 16, \"m\": 15 }\nassert my_solution.differenceOfSums(**test_input) == 106\n\ntest_input = { \"n\": 18, \"m\": 3 }\nassert my_solution.differenceOfSums(**test_input) == 45\n\ntest_input = { \"n\": 4, \"m\": 12 }\nassert my_solution.differenceOfSums(**test_input) == 10\n\ntest_input = { \"n\": 3, \"m\": 21 }\nassert my_solution.differenceOfSums(**test_input) == 6\n\ntest_input = { \"n\": 15, \"m\": 4 }\nassert my_solution.differenceOfSums(**test_input) == 72\n\ntest_input = { \"n\": 9, \"m\": 39 }\nassert my_solution.differenceOfSums(**test_input) == 45\n\ntest_input = { \"n\": 19, \"m\": 18 }\nassert my_solution.differenceOfSums(**test_input) == 154\n\ntest_input = { \"n\": 2, \"m\": 4 }\nassert my_solution.differenceOfSums(**test_input) == 3\n\ntest_input = { \"n\": 41, \"m\": 1 }\nassert my_solution.differenceOfSums(**test_input) == -861\n\ntest_input = { \"n\": 3, \"m\": 1 }\nassert my_solution.differenceOfSums(**test_input) == -6\n\ntest_input = { \"n\": 16, \"m\": 13 }\nassert my_solution.differenceOfSums(**test_input) == 110\n\ntest_input = { \"n\": 32, \"m\": 10 }\nassert my_solution.differenceOfSums(**test_input) == 408\n\ntest_input = { \"n\": 41, \"m\": 34 }\nassert my_solution.differenceOfSums(**test_input) == 793\n\ntest_input = { \"n\": 33, \"m\": 40 }\nassert my_solution.differenceOfSums(**test_input) == 561\n\ntest_input = { \"n\": 36, \"m\": 8 }\nassert my_solution.differenceOfSums(**test_input) == 506\n\ntest_input = { \"n\": 8, \"m\": 34 }\nassert my_solution.differenceOfSums(**test_input) == 36\n\ntest_input = { \"n\": 40, \"m\": 12 }\nassert my_solution.differenceOfSums(**test_input) == 676\n\ntest_input = { \"n\": 28, \"m\": 9 }\nassert my_solution.differenceOfSums(**test_input) == 298\n\ntest_input = { \"n\": 20, \"m\": 6 }\nassert my_solution.differenceOfSums(**test_input) == 138\n\ntest_input = { \"n\": 13, \"m\": 6 }\nassert my_solution.differenceOfSums(**test_input) == 55\n\ntest_input = { \"n\": 2, \"m\": 37 }\nassert my_solution.differenceOfSums(**test_input) == 3\n\ntest_input = { \"n\": 14, \"m\": 17 }\nassert my_solution.differenceOfSums(**test_input) == 105\n\ntest_input = { \"n\": 35, \"m\": 4 }\nassert my_solution.differenceOfSums(**test_input) == 342\n\ntest_input = { \"n\": 2, \"m\": 14 }\nassert my_solution.differenceOfSums(**test_input) == 3\n\ntest_input = { \"n\": 5, \"m\": 2 }\nassert my_solution.differenceOfSums(**test_input) == 3\n\ntest_input = { \"n\": 7, \"m\": 7 }\nassert my_solution.differenceOfSums(**test_input) == 14\n\ntest_input = { \"n\": 12, \"m\": 26 }\nassert my_solution.differenceOfSums(**test_input) == 78\n\ntest_input = { \"n\": 14, \"m\": 1 }\nassert my_solution.differenceOfSums(**test_input) == -105\n\ntest_input = { \"n\": 2, \"m\": 1 }\nassert my_solution.differenceOfSums(**test_input) == -3\n\ntest_input = { \"n\": 20, \"m\": 3 }\nassert my_solution.differenceOfSums(**test_input) == 84\n\ntest_input = { \"n\": 8, \"m\": 27 }\nassert my_solution.differenceOfSums(**test_input) == 36\n\ntest_input = { \"n\": 1, \"m\": 12 }\nassert my_solution.differenceOfSums(**test_input) == 1\n\ntest_input = { \"n\": 13, \"m\": 19 }\nassert my_solution.differenceOfSums(**test_input) == 91\n\ntest_input = { \"n\": 7, \"m\": 1 }\nassert my_solution.differenceOfSums(**test_input) == -28\n\ntest_input = { \"n\": 31, \"m\": 4 }\nassert my_solution.differenceOfSums(**test_input) == 272\n\ntest_input = { \"n\": 11, \"m\": 25 }\nassert my_solution.differenceOfSums(**test_input) == 66\n\ntest_input = { \"n\": 5, \"m\": 19 }\nassert my_solution.differenceOfSums(**test_input) == 15\n\ntest_input = { \"n\": 33, \"m\": 12 }\nassert my_solution.differenceOfSums(**test_input) == 489\n\ntest_input = { \"n\": 4, \"m\": 26 }\nassert my_solution.differenceOfSums(**test_input) == 10\n\ntest_input = { \"n\": 1, \"m\": 24 }\nassert my_solution.differenceOfSums(**test_input) == 1\n\ntest_input = { \"n\": 13, \"m\": 20 }\nassert my_solution.differenceOfSums(**test_input) == 91\n\ntest_input = { \"n\": 6, \"m\": 8 }\nassert my_solution.differenceOfSums(**test_input) == 21\n\ntest_input = { \"n\": 8, \"m\": 26 }\nassert my_solution.differenceOfSums(**test_input) == 36\n\ntest_input = { \"n\": 4, \"m\": 1 }\nassert my_solution.differenceOfSums(**test_input) == -10\n\ntest_input = { \"n\": 1, \"m\": 6 }\nassert my_solution.differenceOfSums(**test_input) == 1\n\ntest_input = { \"n\": 2, \"m\": 25 }\nassert my_solution.differenceOfSums(**test_input) == 3\n\ntest_input = { \"n\": 4, \"m\": 4 }\nassert my_solution.differenceOfSums(**test_input) == 2\n\ntest_input = { \"n\": 8, \"m\": 2 }\nassert my_solution.differenceOfSums(**test_input) == -4\n\ntest_input = { \"n\": 15, \"m\": 21 }\nassert my_solution.differenceOfSums(**test_input) == 120\n\ntest_input = { \"n\": 1, \"m\": 2 }\nassert my_solution.differenceOfSums(**test_input) == 1\n\ntest_input = { \"n\": 12, \"m\": 2 }\nassert my_solution.differenceOfSums(**test_input) == -6\n\ntest_input = { \"n\": 40, \"m\": 14 }\nassert my_solution.differenceOfSums(**test_input) == 736\n\ntest_input = { \"n\": 14, \"m\": 19 }\nassert my_solution.differenceOfSums(**test_input) == 105\n\ntest_input = { \"n\": 18, \"m\": 1 }\nassert my_solution.differenceOfSums(**test_input) == -171\n\ntest_input = { \"n\": 1, \"m\": 28 }\nassert my_solution.differenceOfSums(**test_input) == 1\n\ntest_input = { \"n\": 31, \"m\": 18 }\nassert my_solution.differenceOfSums(**test_input) == 460", "start_time": 1696732200} +{"task_id": "weekly-contest-366-minimum-processing-time", "url": "https://leetcode.com/problems/minimum-processing-time", "title": "minimum-processing-time", "meta": {"questionId": "3151", "questionFrontendId": "2895", "title": "Minimum Processing Time", "titleSlug": "minimum-processing-time", "isPaidOnly": false, "difficulty": "Medium", "likes": 119, "dislikes": 22, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou have n processors each having 4 cores and n * 4 tasks that need to be executed such that each core should perform only one task.\n\nGiven a 0-indexed integer array processorTime representing the time at which each processor becomes available for the first time and a 0-indexed integer array tasks representing the time it takes to execute each task, return the minimum time when all of the tasks have been executed by the processors.\n\nNote: Each core executes the task independently of the others.\n\nExample 1:\n\nInput: processorTime = [8,10], tasks = [2,2,3,1,8,7,4,5]\nOutput: 16\nExplanation:\nIt's optimal to assign the tasks at indexes 4, 5, 6, 7 to the first processor which becomes available at time = 8, and the tasks at indexes 0, 1, 2, 3 to the second processor which becomes available at time = 10.\nTime taken by the first processor to finish execution of all tasks = max(8 + 8, 8 + 7, 8 + 4, 8 + 5) = 16.\nTime taken by the second processor to finish execution of all tasks = max(10 + 2, 10 + 2, 10 + 3, 10 + 1) = 13.\nHence, it can be shown that the minimum time taken to execute all the tasks is 16.\n\nExample 2:\n\nInput: processorTime = [10,20], tasks = [2,3,1,2,5,8,4,3]\nOutput: 23\nExplanation:\nIt's optimal to assign the tasks at indexes 1, 4, 5, 6 to the first processor which becomes available at time = 10, and the tasks at indexes 0, 2, 3, 7 to the second processor which becomes available at time = 20.\nTime taken by the first processor to finish execution of all tasks = max(10 + 3, 10 + 5, 10 + 8, 10 + 4) = 18.\nTime taken by the second processor to finish execution of all tasks = max(20 + 2, 20 + 1, 20 + 2, 20 + 3) = 23.\nHence, it can be shown that the minimum time taken to execute all the tasks is 23.\n\n\nConstraints:\n\n * 1 <= n == processorTime.length <= 25000\n * 1 <= tasks.length <= 105\n * 0 <= processorTime[i] <= 109\n * 1 <= tasks[i] <= 109\n * tasks.length == 4 * n\n\"\"\"\nclass Solution:\n def minProcessingTime(self, processorTime: List[int], tasks: List[int]) -> int:\n ", "prompt_sft": "You have n processors each having 4 cores and n * 4 tasks that need to be executed such that each core should perform only one task.\n\nGiven a 0-indexed integer array processorTime representing the time at which each processor becomes available for the first time and a 0-indexed integer array tasks representing the time it takes to execute each task, return the minimum time when all of the tasks have been executed by the processors.\n\nNote: Each core executes the task independently of the others.\n\nExample 1:\n\nInput: processorTime = [8,10], tasks = [2,2,3,1,8,7,4,5]\nOutput: 16\nExplanation:\nIt's optimal to assign the tasks at indexes 4, 5, 6, 7 to the first processor which becomes available at time = 8, and the tasks at indexes 0, 1, 2, 3 to the second processor which becomes available at time = 10.\nTime taken by the first processor to finish execution of all tasks = max(8 + 8, 8 + 7, 8 + 4, 8 + 5) = 16.\nTime taken by the second processor to finish execution of all tasks = max(10 + 2, 10 + 2, 10 + 3, 10 + 1) = 13.\nHence, it can be shown that the minimum time taken to execute all the tasks is 16.\n\nExample 2:\n\nInput: processorTime = [10,20], tasks = [2,3,1,2,5,8,4,3]\nOutput: 23\nExplanation:\nIt's optimal to assign the tasks at indexes 1, 4, 5, 6 to the first processor which becomes available at time = 10, and the tasks at indexes 0, 2, 3, 7 to the second processor which becomes available at time = 20.\nTime taken by the first processor to finish execution of all tasks = max(10 + 3, 10 + 5, 10 + 8, 10 + 4) = 18.\nTime taken by the second processor to finish execution of all tasks = max(20 + 2, 20 + 1, 20 + 2, 20 + 3) = 23.\nHence, it can be shown that the minimum time taken to execute all the tasks is 23.\n\n\nConstraints:\n\n * 1 <= n == processorTime.length <= 25000\n * 1 <= tasks.length <= 105\n * 0 <= processorTime[i] <= 109\n * 1 <= tasks[i] <= 109\n * tasks.length == 4 * n\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def minProcessingTime(self, processorTime: List[int], tasks: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"processorTime\": [8,10], \"tasks\": [2,2,3,1,8,7,4,5] }\nassert my_solution.minProcessingTime(**test_input) == 16\n\ntest_input = { \"processorTime\": [10,20], \"tasks\": [2,3,1,2,5,8,4,3] }\nassert my_solution.minProcessingTime(**test_input) == 23\n\ntest_input = { \"processorTime\": [121,99], \"tasks\": [287,315,293,260,333,362,69,233] }\nassert my_solution.minProcessingTime(**test_input) == 461\n\ntest_input = { \"processorTime\": [33,320], \"tasks\": [132,68,232,166,30,300,112,138] }\nassert my_solution.minProcessingTime(**test_input) == 452\n\ntest_input = { \"processorTime\": [50,82], \"tasks\": [288,138,205,295,367,100,258,308] }\nassert my_solution.minProcessingTime(**test_input) == 417\n\ntest_input = { \"processorTime\": [291], \"tasks\": [125,169,269,32] }\nassert my_solution.minProcessingTime(**test_input) == 560\n\ntest_input = { \"processorTime\": [55,350,166,210,389], \"tasks\": [276,253,157,237,92,396,331,19,82,301,136,396,251,92,280,70,253,47,81,84] }\nassert my_solution.minProcessingTime(**test_input) == 470\n\ntest_input = { \"processorTime\": [143,228,349,231,392], \"tasks\": [102,365,363,211,38,96,98,79,365,289,252,201,259,346,21,68,128,56,167,183] }\nassert my_solution.minProcessingTime(**test_input) == 517\n\ntest_input = { \"processorTime\": [168,32,299,303,96], \"tasks\": [382,183,337,73,115,350,6,18,93,238,102,302,96,381,327,385,387,288,138,83] }\nassert my_solution.minProcessingTime(**test_input) == 456\n\ntest_input = { \"processorTime\": [324,117,374,219,303], \"tasks\": [374,202,328,11,353,208,383,287,107,236,226,387,21,183,352,164,207,182,15,65] }\nassert my_solution.minProcessingTime(**test_input) == 571\n\ntest_input = { \"processorTime\": [376], \"tasks\": [21,247,274,38] }\nassert my_solution.minProcessingTime(**test_input) == 650\n\ntest_input = { \"processorTime\": [93,3,281,218], \"tasks\": [182,16,241,312,81,339,207,330,306,166,82,290,7,317,396,389] }\nassert my_solution.minProcessingTime(**test_input) == 459\n\ntest_input = { \"processorTime\": [374,250,197,170], \"tasks\": [247,56,330,361,240,261,67,65,138,181,308,26,59,150,137,244] }\nassert my_solution.minProcessingTime(**test_input) == 531\n\ntest_input = { \"processorTime\": [115,271,137], \"tasks\": [34,72,328,312,159,32,283,6,234,280,46,349] }\nassert my_solution.minProcessingTime(**test_input) == 464\n\ntest_input = { \"processorTime\": [47,217,349,233,283], \"tasks\": [195,188,181,259,145,96,298,322,213,154,278,292,315,191,177,228,291,204,310,266] }\nassert my_solution.minProcessingTime(**test_input) == 526\n\ntest_input = { \"processorTime\": [177,6,326,318,294], \"tasks\": [136,215,260,259,35,248,340,377,144,248,83,150,63,48,269,197,317,135,36,344] }\nassert my_solution.minProcessingTime(**test_input) == 542\n\ntest_input = { \"processorTime\": [266,372], \"tasks\": [260,325,159,316,296,366,335,146] }\nassert my_solution.minProcessingTime(**test_input) == 668\n\ntest_input = { \"processorTime\": [63,339], \"tasks\": [79,316,98,354,220,267,333,11] }\nassert my_solution.minProcessingTime(**test_input) == 559\n\ntest_input = { \"processorTime\": [149,60,172,5,212], \"tasks\": [230,374,276,281,55,96,52,83,56,399,69,333,145,6,50,101,216,327,120,209] }\nassert my_solution.minProcessingTime(**test_input) == 404\n\ntest_input = { \"processorTime\": [220,375,285,267,150], \"tasks\": [53,317,367,258,337,280,232,322,153,169,121,211,171,345,76,370,265,107,45,320] }\nassert my_solution.minProcessingTime(**test_input) == 542\n\ntest_input = { \"processorTime\": [373,367,267], \"tasks\": [214,221,78,330,340,309,330,338,396,337,285,207] }\nassert my_solution.minProcessingTime(**test_input) == 697\n\ntest_input = { \"processorTime\": [92,20], \"tasks\": [11,354,399,11,20,9,217,372] }\nassert my_solution.minProcessingTime(**test_input) == 419\n\ntest_input = { \"processorTime\": [51], \"tasks\": [349,186,191,183] }\nassert my_solution.minProcessingTime(**test_input) == 400\n\ntest_input = { \"processorTime\": [362,220,10,219], \"tasks\": [160,369,385,145,122,124,147,231,162,37,293,160,68,232,232,130] }\nassert my_solution.minProcessingTime(**test_input) == 486\n\ntest_input = { \"processorTime\": [210,348,3,57,174], \"tasks\": [328,296,222,161,190,381,283,137,353,227,284,134,170,13,275,113,148,198,33,260] }\nassert my_solution.minProcessingTime(**test_input) == 482\n\ntest_input = { \"processorTime\": [153], \"tasks\": [342,166,234,175] }\nassert my_solution.minProcessingTime(**test_input) == 495\n\ntest_input = { \"processorTime\": [23,204,114,380,3], \"tasks\": [40,105,311,221,247,34,399,190,23,289,16,129,68,12,32,364,364,111,361,49] }\nassert my_solution.minProcessingTime(**test_input) == 412\n\ntest_input = { \"processorTime\": [167,110,221,19,211], \"tasks\": [140,351,307,4,262,228,161,200,108,206,280,266,240,258,396,194,333,328,121,179] }\nassert my_solution.minProcessingTime(**test_input) == 425\n\ntest_input = { \"processorTime\": [179,127,280,242], \"tasks\": [244,243,92,188,134,84,22,258,100,77,237,83,41,396,218,87] }\nassert my_solution.minProcessingTime(**test_input) == 523\n\ntest_input = { \"processorTime\": [45,249,396,163], \"tasks\": [131,365,52,366,229,340,242,371,20,181,103,97,141,106,46,119] }\nassert my_solution.minProcessingTime(**test_input) == 493\n\ntest_input = { \"processorTime\": [205], \"tasks\": [117,63,174,87] }\nassert my_solution.minProcessingTime(**test_input) == 379\n\ntest_input = { \"processorTime\": [128,101,302,53], \"tasks\": [265,96,358,287,148,117,331,47,173,347,62,145,73,47,206,29] }\nassert my_solution.minProcessingTime(**test_input) == 411\n\ntest_input = { \"processorTime\": [228], \"tasks\": [321,378,268,351] }\nassert my_solution.minProcessingTime(**test_input) == 606\n\ntest_input = { \"processorTime\": [136,22,229,187], \"tasks\": [246,326,188,341,375,207,334,1,189,301,62,39,44,239,346,376] }\nassert my_solution.minProcessingTime(**test_input) == 470\n\ntest_input = { \"processorTime\": [47,238,274], \"tasks\": [251,312,87,111,142,62,112,325,305,164,85,338] }\nassert my_solution.minProcessingTime(**test_input) == 489\n\ntest_input = { \"processorTime\": [386,121,249], \"tasks\": [5,376,53,187,287,369,400,178,293,121,164,336] }\nassert my_solution.minProcessingTime(**test_input) == 550\n\ntest_input = { \"processorTime\": [82,152], \"tasks\": [82,46,149,255,225,93,227,131] }\nassert my_solution.minProcessingTime(**test_input) == 337\n\ntest_input = { \"processorTime\": [394,6], \"tasks\": [231,236,288,35,247,204,141,41] }\nassert my_solution.minProcessingTime(**test_input) == 598\n\ntest_input = { \"processorTime\": [389,54], \"tasks\": [353,358,211,133,225,358,19,310] }\nassert my_solution.minProcessingTime(**test_input) == 614\n\ntest_input = { \"processorTime\": [106,291,291,301], \"tasks\": [192,120,93,5,293,147,299,81,334,137,259,48,296,117,379,182] }\nassert my_solution.minProcessingTime(**test_input) == 584\n\ntest_input = { \"processorTime\": [320,139], \"tasks\": [210,255,304,181,216,255,375,360] }\nassert my_solution.minProcessingTime(**test_input) == 575\n\ntest_input = { \"processorTime\": [306,207,295], \"tasks\": [335,188,355,209,201,113,122,206,46,355,350,38] }\nassert my_solution.minProcessingTime(**test_input) == 562\n\ntest_input = { \"processorTime\": [175,111], \"tasks\": [225,110,163,100,353,77,12,124] }\nassert my_solution.minProcessingTime(**test_input) == 464\n\ntest_input = { \"processorTime\": [233,201], \"tasks\": [1,389,291,333,42,399,399,300] }\nassert my_solution.minProcessingTime(**test_input) == 600\n\ntest_input = { \"processorTime\": [302,5,102,195], \"tasks\": [311,144,7,277,253,96,136,251,81,195,171,140,73,2,84,42] }\nassert my_solution.minProcessingTime(**test_input) == 375\n\ntest_input = { \"processorTime\": [151,185,3,137], \"tasks\": [294,230,221,216,299,24,79,194,375,387,77,388,366,51,117,126] }\nassert my_solution.minProcessingTime(**test_input) == 436\n\ntest_input = { \"processorTime\": [39,141,145,199], \"tasks\": [99,257,161,121,56,80,235,168,171,228,290,180,118,307,66,151] }\nassert my_solution.minProcessingTime(**test_input) == 369\n\ntest_input = { \"processorTime\": [40,67], \"tasks\": [259,217,337,295,126,335,369,123] }\nassert my_solution.minProcessingTime(**test_input) == 409\n\ntest_input = { \"processorTime\": [310,56,207,396], \"tasks\": [260,255,30,243,66,11,285,31,358,219,218,90,176,346,134,74] }\nassert my_solution.minProcessingTime(**test_input) == 486\n\ntest_input = { \"processorTime\": [174,48], \"tasks\": [106,323,4,247,70,281,348,12] }\nassert my_solution.minProcessingTime(**test_input) == 396\n\ntest_input = { \"processorTime\": [16,52,13], \"tasks\": [281,261,55,165,317,150,68,26,52,227,176,399] }\nassert my_solution.minProcessingTime(**test_input) == 412\n\ntest_input = { \"processorTime\": [8,315,115,123], \"tasks\": [134,371,160,138,289,330,48,349,376,88,46,235,298,321,343,365] }\nassert my_solution.minProcessingTime(**test_input) == 458\n\ntest_input = { \"processorTime\": [221,24,372,6,50], \"tasks\": [274,79,78,37,57,39,102,272,242,283,95,155,105,363,174,1,333,400,375,376] }\nassert my_solution.minProcessingTime(**test_input) == 429\n\ntest_input = { \"processorTime\": [289,98,7,303,219], \"tasks\": [363,140,173,92,52,348,350,316,281,327,40,259,39,235,263,244,42,354,11,232] }\nassert my_solution.minProcessingTime(**test_input) == 478\n\ntest_input = { \"processorTime\": [348,268], \"tasks\": [104,397,333,188,373,325,57,202] }\nassert my_solution.minProcessingTime(**test_input) == 665\n\ntest_input = { \"processorTime\": [18,377,305,188,311], \"tasks\": [207,365,369,66,263,47,257,317,221,292,386,308,357,105,99,314,133,106,311,90] }\nassert my_solution.minProcessingTime(**test_input) == 597\n\ntest_input = { \"processorTime\": [44,254], \"tasks\": [277,361,398,276,84,105,350,134] }\nassert my_solution.minProcessingTime(**test_input) == 530\n\ntest_input = { \"processorTime\": [270,257,58], \"tasks\": [212,151,50,78,91,110,399,360,108,192,142,115] }\nassert my_solution.minProcessingTime(**test_input) == 457\n\ntest_input = { \"processorTime\": [108,301], \"tasks\": [150,143,119,160,340,139,72,349] }\nassert my_solution.minProcessingTime(**test_input) == 457\n\ntest_input = { \"processorTime\": [231,207,162,49], \"tasks\": [318,289,351,103,19,77,65,116,94,234,139,246,80,184,286,397] }\nassert my_solution.minProcessingTime(**test_input) == 448\n\ntest_input = { \"processorTime\": [252], \"tasks\": [384,281,207,33] }\nassert my_solution.minProcessingTime(**test_input) == 636\n\ntest_input = { \"processorTime\": [199,8,129,204], \"tasks\": [308,133,366,272,373,343,357,159,378,149,185,248,190,1,142,199] }\nassert my_solution.minProcessingTime(**test_input) == 472\n\ntest_input = { \"processorTime\": [135,65,19,225], \"tasks\": [183,135,138,142,282,141,349,236,57,333,258,353,152,396,152,191] }\nassert my_solution.minProcessingTime(**test_input) == 415\n\ntest_input = { \"processorTime\": [199,371,283,70], \"tasks\": [244,7,226,230,331,232,332,288,151,360,26,87,49,188,269,375] }\nassert my_solution.minProcessingTime(**test_input) == 513\n\ntest_input = { \"processorTime\": [184,378], \"tasks\": [105,239,221,343,276,359,86,84] }\nassert my_solution.minProcessingTime(**test_input) == 599\n\ntest_input = { \"processorTime\": [297,229,142,8,47], \"tasks\": [373,256,210,92,304,134,20,246,116,139,376,139,10,210,192,43,282,278,322,167] }\nassert my_solution.minProcessingTime(**test_input) == 389\n\ntest_input = { \"processorTime\": [224,358,58,352], \"tasks\": [177,274,306,295,142,353,44,111,325,328,394,168,300,15,252,389] }\nassert my_solution.minProcessingTime(**test_input) == 626\n\ntest_input = { \"processorTime\": [318,321,264,259], \"tasks\": [316,284,127,227,269,332,317,364,220,130,330,155,45,205,369,42] }\nassert my_solution.minProcessingTime(**test_input) == 628\n\ntest_input = { \"processorTime\": [295,214,130], \"tasks\": [316,395,280,122,27,224,40,210,99,366,55,183] }\nassert my_solution.minProcessingTime(**test_input) == 525\n\ntest_input = { \"processorTime\": [81,38,313,121], \"tasks\": [158,304,127,214,34,298,95,188,56,391,317,99,304,101,266,302] }\nassert my_solution.minProcessingTime(**test_input) == 429\n\ntest_input = { \"processorTime\": [8,400,28,348,193], \"tasks\": [72,391,149,264,370,183,365,102,201,348,341,176,338,186,97,156,47,125,61,202] }\nassert my_solution.minProcessingTime(**test_input) == 504\n\ntest_input = { \"processorTime\": [0], \"tasks\": [8,369,353,14] }\nassert my_solution.minProcessingTime(**test_input) == 369\n\ntest_input = { \"processorTime\": [55,364,28,246], \"tasks\": [396,357,37,400,239,327,5,387,70,389,323,213,322,111,179,19] }\nassert my_solution.minProcessingTime(**test_input) == 485\n\ntest_input = { \"processorTime\": [288,219,356,146,282], \"tasks\": [390,46,24,391,222,241,281,33,400,312,290,11,147,282,204,214,22,178,77,156] }\nassert my_solution.minProcessingTime(**test_input) == 546\n\ntest_input = { \"processorTime\": [60,309,40,219,294], \"tasks\": [267,94,238,338,279,48,164,371,302,110,247,392,83,107,389,46,92,273,131,136] }\nassert my_solution.minProcessingTime(**test_input) == 466\n\ntest_input = { \"processorTime\": [357], \"tasks\": [211,344,270,324] }\nassert my_solution.minProcessingTime(**test_input) == 701\n\ntest_input = { \"processorTime\": [220,355,190,393], \"tasks\": [158,27,113,335,382,172,285,373,104,177,247,321,197,22,347,136] }\nassert my_solution.minProcessingTime(**test_input) == 572\n\ntest_input = { \"processorTime\": [67,105,290,26,343], \"tasks\": [50,118,302,74,198,56,292,46,337,27,394,69,109,287,274,283,346,132,77,352] }\nassert my_solution.minProcessingTime(**test_input) == 420\n\ntest_input = { \"processorTime\": [77,143,142,23], \"tasks\": [336,190,105,87,102,254,295,243,400,254,96,303,350,191,331,70] }\nassert my_solution.minProcessingTime(**test_input) == 423\n\ntest_input = { \"processorTime\": [319,58,155,360], \"tasks\": [311,257,35,330,235,159,293,204,298,240,233,250,309,242,262,324] }\nassert my_solution.minProcessingTime(**test_input) == 593\n\ntest_input = { \"processorTime\": [28,225,347], \"tasks\": [176,57,60,81,161,66,13,294,145,239,295,210] }\nassert my_solution.minProcessingTime(**test_input) == 413\n\ntest_input = { \"processorTime\": [291,337], \"tasks\": [210,378,169,400,182,290,386,360] }\nassert my_solution.minProcessingTime(**test_input) == 691\n\ntest_input = { \"processorTime\": [141,310], \"tasks\": [396,56,241,289,21,254,196,165] }\nassert my_solution.minProcessingTime(**test_input) == 537\n\ntest_input = { \"processorTime\": [204,390,104], \"tasks\": [355,4,287,161,230,242,218,12,321,28,341,326] }\nassert my_solution.minProcessingTime(**test_input) == 551\n\ntest_input = { \"processorTime\": [299,258], \"tasks\": [20,44,341,172,118,185,369,249] }\nassert my_solution.minProcessingTime(**test_input) == 627\n\ntest_input = { \"processorTime\": [107,141,178,211,62], \"tasks\": [215,318,196,251,71,144,10,208,113,17,13,263,367,42,85,267,212,54,36,54] }\nassert my_solution.minProcessingTime(**test_input) == 429\n\ntest_input = { \"processorTime\": [101,383,326,62], \"tasks\": [304,256,281,240,180,387,318,368,331,267,14,91,93,147,156,394] }\nassert my_solution.minProcessingTime(**test_input) == 582\n\ntest_input = { \"processorTime\": [221,62,187,104,266], \"tasks\": [284,378,9,288,173,327,329,202,3,383,105,213,175,201,196,305,162,161,127,347] }\nassert my_solution.minProcessingTime(**test_input) == 445\n\ntest_input = { \"processorTime\": [328,162,249,357,35], \"tasks\": [77,275,231,298,273,257,88,339,261,147,229,392,156,63,90,97,219,353,66,91] }\nassert my_solution.minProcessingTime(**test_input) == 480\n\ntest_input = { \"processorTime\": [7], \"tasks\": [132,278,270,176] }\nassert my_solution.minProcessingTime(**test_input) == 285\n\ntest_input = { \"processorTime\": [326], \"tasks\": [269,211,137,244] }\nassert my_solution.minProcessingTime(**test_input) == 595\n\ntest_input = { \"processorTime\": [310,44], \"tasks\": [109,250,222,275,268,332,146,328] }\nassert my_solution.minProcessingTime(**test_input) == 560\n\ntest_input = { \"processorTime\": [184,254,121,90,389], \"tasks\": [124,365,400,167,109,207,369,37,174,287,41,114,388,158,125,283,119,254,210,399] }\nassert my_solution.minProcessingTime(**test_input) == 503\n\ntest_input = { \"processorTime\": [94,171,66], \"tasks\": [261,134,26,281,29,253,84,333,90,157,382,263] }\nassert my_solution.minProcessingTime(**test_input) == 448\n\ntest_input = { \"processorTime\": [5,99,318,252,151], \"tasks\": [264,235,250,347,376,57,73,7,178,45,220,148,159,379,89,73,159,172,228,39] }\nassert my_solution.minProcessingTime(**test_input) == 400\n\ntest_input = { \"processorTime\": [303,52,2,118,305], \"tasks\": [398,173,5,301,169,389,126,212,384,359,222,340,267,173,264,238,141,44,144,148] }\nassert my_solution.minProcessingTime(**test_input) == 476\n\ntest_input = { \"processorTime\": [177], \"tasks\": [164,277,289,197] }\nassert my_solution.minProcessingTime(**test_input) == 466\n\ntest_input = { \"processorTime\": [297,259,318,30,213], \"tasks\": [162,97,265,153,216,233,286,346,389,208,55,345,308,197,266,292,369,320,1,235] }\nassert my_solution.minProcessingTime(**test_input) == 533\n\ntest_input = { \"processorTime\": [290], \"tasks\": [333,282,72,362] }\nassert my_solution.minProcessingTime(**test_input) == 652\n\ntest_input = { \"processorTime\": [372,189,344], \"tasks\": [191,26,247,99,395,270,192,340,60,78,260,395] }\nassert my_solution.minProcessingTime(**test_input) == 604", "start_time": 1696732200} +{"task_id": "weekly-contest-366-apply-operations-to-make-two-strings-equal", "url": "https://leetcode.com/problems/apply-operations-to-make-two-strings-equal", "title": "apply-operations-to-make-two-strings-equal", "meta": {"questionId": "3033", "questionFrontendId": "2896", "title": "Apply Operations to Make Two Strings Equal", "titleSlug": "apply-operations-to-make-two-strings-equal", "isPaidOnly": false, "difficulty": "Medium", "likes": 291, "dislikes": 62, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given two 0-indexed binary strings s1 and s2, both of length n, and a positive integer x.\n\nYou can perform any of the following operations on the string s1 any number of times:\n\n * Choose two indices i and j, and flip both s1[i] and s1[j]. The cost of this operation is x.\n * Choose an index i such that i < n - 1 and flip both s1[i] and s1[i + 1]. The cost of this operation is 1.\n\nReturn the minimum cost needed to make the strings s1 and s2 equal, or return -1 if it is impossible.\n\nNote that flipping a character means changing it from 0 to 1 or vice-versa.\n\nExample 1:\n\nInput: s1 = \"1100011000\", s2 = \"0101001010\", x = 2\nOutput: 4\nExplanation: We can do the following operations:\n- Choose i = 3 and apply the second operation. The resulting string is s1 = \"1101111000\".\n- Choose i = 4 and apply the second operation. The resulting string is s1 = \"1101001000\".\n- Choose i = 0 and j = 8 and apply the first operation. The resulting string is s1 = \"0101001010\" = s2.\nThe total cost is 1 + 1 + 2 = 4. It can be shown that it is the minimum cost possible.\n\nExample 2:\n\nInput: s1 = \"10110\", s2 = \"00011\", x = 4\nOutput: -1\nExplanation: It is not possible to make the two strings equal.\n\n\nConstraints:\n\n * n == s1.length == s2.length\n * 1 <= n, x <= 500\n * s1 and s2 consist only of the characters '0' and '1'.\n\"\"\"\nclass Solution:\n def minOperations(self, s1: str, s2: str, x: int) -> int:\n ", "prompt_sft": "You are given two 0-indexed binary strings s1 and s2, both of length n, and a positive integer x.\n\nYou can perform any of the following operations on the string s1 any number of times:\n\n * Choose two indices i and j, and flip both s1[i] and s1[j]. The cost of this operation is x.\n * Choose an index i such that i < n - 1 and flip both s1[i] and s1[i + 1]. The cost of this operation is 1.\n\nReturn the minimum cost needed to make the strings s1 and s2 equal, or return -1 if it is impossible.\n\nNote that flipping a character means changing it from 0 to 1 or vice-versa.\n\nExample 1:\n\nInput: s1 = \"1100011000\", s2 = \"0101001010\", x = 2\nOutput: 4\nExplanation: We can do the following operations:\n- Choose i = 3 and apply the second operation. The resulting string is s1 = \"1101111000\".\n- Choose i = 4 and apply the second operation. The resulting string is s1 = \"1101001000\".\n- Choose i = 0 and j = 8 and apply the first operation. The resulting string is s1 = \"0101001010\" = s2.\nThe total cost is 1 + 1 + 2 = 4. It can be shown that it is the minimum cost possible.\n\nExample 2:\n\nInput: s1 = \"10110\", s2 = \"00011\", x = 4\nOutput: -1\nExplanation: It is not possible to make the two strings equal.\n\n\nConstraints:\n\n * n == s1.length == s2.length\n * 1 <= n, x <= 500\n * s1 and s2 consist only of the characters '0' and '1'.\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def minOperations(self, s1: str, s2: str, x: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"s1\": \"1100011000\", \"s2\": \"0101001010\", \"x\": 2 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"s1\": \"10110\", \"s2\": \"00011\", \"x\": 4 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"101101\", \"s2\": \"000000\", \"x\": 6 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"s1\": \"0\", \"s2\": \"1\", \"x\": 2 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"1011100100111000\", \"s2\": \"1001010001011100\", \"x\": 19 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"00101101100010\", \"s2\": \"00001010001111\", \"x\": 30 }\nassert my_solution.minOperations(**test_input) == 8\n\ntest_input = { \"s1\": \"1011000\", \"s2\": \"0001101\", \"x\": 30 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"s1\": \"1111110101010110\", \"s2\": \"1000100111100101\", \"x\": 19 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"1011100000100100101\", \"s2\": \"1110001001110000011\", \"x\": 14 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"0\", \"s2\": \"1\", \"x\": 17 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"0\", \"s2\": \"1\", \"x\": 3 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"0001110010\", \"s2\": \"0110100111\", \"x\": 29 }\nassert my_solution.minOperations(**test_input) == 5\n\ntest_input = { \"s1\": \"01111101010100110100\", \"s2\": \"10010011011001011000\", \"x\": 21 }\nassert my_solution.minOperations(**test_input) == 7\n\ntest_input = { \"s1\": \"00000101\", \"s2\": \"01001010\", \"x\": 10 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"01\", \"s2\": \"00\", \"x\": 30 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"11111\", \"s2\": \"01011\", \"x\": 4 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"s1\": \"001010101011001\", \"s2\": \"110111000101110\", \"x\": 14 }\nassert my_solution.minOperations(**test_input) == 7\n\ntest_input = { \"s1\": \"010011101\", \"s2\": \"101111000\", \"x\": 17 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"s1\": \"11110111\", \"s2\": \"10011111\", \"x\": 16 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"0011\", \"s2\": \"1100\", \"x\": 14 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"s1\": \"000011\", \"s2\": \"010101\", \"x\": 27 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"01111010\", \"s2\": \"10110011\", \"x\": 21 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"s1\": \"10010111001\", \"s2\": \"11101011110\", \"x\": 1 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"s1\": \"10001\", \"s2\": \"11000\", \"x\": 11 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"s1\": \"11001011111\", \"s2\": \"01111000110\", \"x\": 2 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"s1\": \"111010100001011\", \"s2\": \"100000101100111\", \"x\": 29 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"010000110111000111\", \"s2\": \"100011100010010111\", \"x\": 15 }\nassert my_solution.minOperations(**test_input) == 6\n\ntest_input = { \"s1\": \"010010111\", \"s2\": \"011100010\", \"x\": 21 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"01011111\", \"s2\": \"11110101\", \"x\": 7 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"s1\": \"00001011110000\", \"s2\": \"01011110001001\", \"x\": 12 }\nassert my_solution.minOperations(**test_input) == 8\n\ntest_input = { \"s1\": \"1100110100001001\", \"s2\": \"0100111010111001\", \"x\": 18 }\nassert my_solution.minOperations(**test_input) == 8\n\ntest_input = { \"s1\": \"00101101\", \"s2\": \"10010101\", \"x\": 6 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"s1\": \"110010\", \"s2\": \"011011\", \"x\": 21 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"00101\", \"s2\": \"11000\", \"x\": 25 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"s1\": \"110\", \"s2\": \"100\", \"x\": 27 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"1101\", \"s2\": \"0000\", \"x\": 9 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"11\", \"s2\": \"01\", \"x\": 7 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"100000000\", \"s2\": \"001011111\", \"x\": 26 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"0111001011\", \"s2\": \"0010011111\", \"x\": 21 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"s1\": \"10\", \"s2\": \"00\", \"x\": 19 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"110111\", \"s2\": \"101101\", \"x\": 3 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"1010111\", \"s2\": \"0110011\", \"x\": 25 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"001\", \"s2\": \"101\", \"x\": 19 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"111100000100111\", \"s2\": \"110100010110001\", \"x\": 7 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"111\", \"s2\": \"110\", \"x\": 4 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"10000010010\", \"s2\": \"11100000010\", \"x\": 22 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"00100110\", \"s2\": \"10101111\", \"x\": 16 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"0110010001101011010\", \"s2\": \"1011110101000001100\", \"x\": 3 }\nassert my_solution.minOperations(**test_input) == 8\n\ntest_input = { \"s1\": \"0001100000001\", \"s2\": \"0011000011101\", \"x\": 28 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"0000110011\", \"s2\": \"0000000011\", \"x\": 3 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"s1\": \"11101100\", \"s2\": \"11111011\", \"x\": 10 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"s1\": \"011101110001001010\", \"s2\": \"111000011001101010\", \"x\": 30 }\nassert my_solution.minOperations(**test_input) == 8\n\ntest_input = { \"s1\": \"1111111100\", \"s2\": \"1010001010\", \"x\": 5 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"s1\": \"111011\", \"s2\": \"111010\", \"x\": 19 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"00010\", \"s2\": \"00010\", \"x\": 9 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"s1\": \"11100000\", \"s2\": \"11110010\", \"x\": 13 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"s1\": \"111101000111\", \"s2\": \"101111010010\", \"x\": 16 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"0\", \"s2\": \"0\", \"x\": 20 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"s1\": \"0011111100011\", \"s2\": \"1001100101000\", \"x\": 26 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"1000101111101001\", \"s2\": \"0110000010110010\", \"x\": 25 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"11000010000\", \"s2\": \"11111000001\", \"x\": 17 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"1110111001000001\", \"s2\": \"0110011110101101\", \"x\": 1 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"s1\": \"0111101101\", \"s2\": \"0000111001\", \"x\": 2 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"000001110\", \"s2\": \"000101001\", \"x\": 22 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"s1\": \"1110000000\", \"s2\": \"1100111100\", \"x\": 5 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"1101101010\", \"s2\": \"0101010011\", \"x\": 15 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"0010011011000101001\", \"s2\": \"1110101001110100010\", \"x\": 19 }\nassert my_solution.minOperations(**test_input) == 9\n\ntest_input = { \"s1\": \"11010011101011110111\", \"s2\": \"11101111011010010011\", \"x\": 8 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"101100010\", \"s2\": \"100011110\", \"x\": 29 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"00100001\", \"s2\": \"10011101\", \"x\": 29 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"111111110110010\", \"s2\": \"111011111010001\", \"x\": 29 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"11011110110010\", \"s2\": \"01010100000111\", \"x\": 9 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"011101010101\", \"s2\": \"111001010100\", \"x\": 19 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"00001\", \"s2\": \"11111\", \"x\": 27 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"s1\": \"110\", \"s2\": \"101\", \"x\": 15 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"s1\": \"11011001111000111001\", \"s2\": \"11100011111011110001\", \"x\": 12 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"1010100\", \"s2\": \"0100111\", \"x\": 2 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"000\", \"s2\": \"010\", \"x\": 21 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"1011010100111101\", \"s2\": \"1010001100110110\", \"x\": 18 }\nassert my_solution.minOperations(**test_input) == 9\n\ntest_input = { \"s1\": \"111\", \"s2\": \"000\", \"x\": 4 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"00101100110110010\", \"s2\": \"00001111111011011\", \"x\": 22 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"000110011\", \"s2\": \"010010001\", \"x\": 8 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"1011000000\", \"s2\": \"0001010010\", \"x\": 16 }\nassert my_solution.minOperations(**test_input) == 5\n\ntest_input = { \"s1\": \"01101100110011011011\", \"s2\": \"10101101010011001011\", \"x\": 5 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"00010\", \"s2\": \"00011\", \"x\": 8 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"1010110111000111\", \"s2\": \"1110110001001000\", \"x\": 22 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"011110100000\", \"s2\": \"101100010100\", \"x\": 21 }\nassert my_solution.minOperations(**test_input) == 5\n\ntest_input = { \"s1\": \"1011010010100101101\", \"s2\": \"1001001110101100000\", \"x\": 29 }\nassert my_solution.minOperations(**test_input) == 9\n\ntest_input = { \"s1\": \"1111100\", \"s2\": \"0010100\", \"x\": 20 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"0100100110001\", \"s2\": \"1001111110001\", \"x\": 4 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"110\", \"s2\": \"011\", \"x\": 2 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"s1\": \"111111010101\", \"s2\": \"000011101101\", \"x\": 30 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"101111110110010100\", \"s2\": \"010001111100000100\", \"x\": 3 }\nassert my_solution.minOperations(**test_input) == 7\n\ntest_input = { \"s1\": \"0110111\", \"s2\": \"0111010\", \"x\": 19 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"1101010101\", \"s2\": \"1011000110\", \"x\": 14 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"01100101\", \"s2\": \"11010111\", \"x\": 17 }\nassert my_solution.minOperations(**test_input) == 5\n\ntest_input = { \"s1\": \"0011111\", \"s2\": \"0110101\", \"x\": 13 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"11110110111111011\", \"s2\": \"11101101111010110\", \"x\": 19 }\nassert my_solution.minOperations(**test_input) == 6\n\ntest_input = { \"s1\": \"110100\", \"s2\": \"000011\", \"x\": 20 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"s1\": \"0101\", \"s2\": \"0010\", \"x\": 29 }\nassert my_solution.minOperations(**test_input) == -1", "start_time": 1696732200} +{"task_id": "weekly-contest-366-apply-operations-on-array-to-maximize-sum-of-squares", "url": "https://leetcode.com/problems/apply-operations-on-array-to-maximize-sum-of-squares", "title": "apply-operations-on-array-to-maximize-sum-of-squares", "meta": {"questionId": "3153", "questionFrontendId": "2897", "title": "Apply Operations on Array to Maximize Sum of Squares", "titleSlug": "apply-operations-on-array-to-maximize-sum-of-squares", "isPaidOnly": false, "difficulty": "Hard", "likes": 159, "dislikes": 3, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed integer array nums and a positive integer k.\n\nYou can do the following operation on the array any number of times:\n\n * Choose any two distinct indices i and j and simultaneously update the values of nums[i] to (nums[i] AND nums[j]) and nums[j] to (nums[i] OR nums[j]). Here, OR denotes the bitwise OR operation, and AND denotes the bitwise AND operation.\n\nYou have to choose k elements from the final array and calculate the sum of their squares.\n\nReturn the maximum sum of squares you can achieve.\n\nSince the answer can be very large, return it modulo 109 + 7.\n\nExample 1:\n\nInput: nums = [2,6,5,8], k = 2\nOutput: 261\nExplanation: We can do the following operations on the array:\n- Choose i = 0 and j = 3, then change nums[0] to (2 AND 8) = 0 and nums[3] to (2 OR 8) = 10. The resulting array is nums = [0,6,5,10].\n- Choose i = 2 and j = 3, then change nums[2] to (5 AND 10) = 0 and nums[3] to (5 OR 10) = 15. The resulting array is nums = [0,6,0,15].\nWe can choose the elements 15 and 6 from the final array. The sum of squares is 152 + 62 = 261.\nIt can be shown that this is the maximum value we can get.\n\nExample 2:\n\nInput: nums = [4,5,4,7], k = 3\nOutput: 90\nExplanation: We do not need to apply any operations.\nWe can choose the elements 7, 5, and 4 with a sum of squares: 72 + 52 + 42 = 90.\nIt can be shown that this is the maximum value we can get.\n\n\nConstraints:\n\n * 1 <= k <= nums.length <= 105\n * 1 <= nums[i] <= 109\n\"\"\"\nclass Solution:\n def maxSum(self, nums: List[int], k: int) -> int:\n ", "prompt_sft": "You are given a 0-indexed integer array nums and a positive integer k.\n\nYou can do the following operation on the array any number of times:\n\n * Choose any two distinct indices i and j and simultaneously update the values of nums[i] to (nums[i] AND nums[j]) and nums[j] to (nums[i] OR nums[j]). Here, OR denotes the bitwise OR operation, and AND denotes the bitwise AND operation.\n\nYou have to choose k elements from the final array and calculate the sum of their squares.\n\nReturn the maximum sum of squares you can achieve.\n\nSince the answer can be very large, return it modulo 109 + 7.\n\nExample 1:\n\nInput: nums = [2,6,5,8], k = 2\nOutput: 261\nExplanation: We can do the following operations on the array:\n- Choose i = 0 and j = 3, then change nums[0] to (2 AND 8) = 0 and nums[3] to (2 OR 8) = 10. The resulting array is nums = [0,6,5,10].\n- Choose i = 2 and j = 3, then change nums[2] to (5 AND 10) = 0 and nums[3] to (5 OR 10) = 15. The resulting array is nums = [0,6,0,15].\nWe can choose the elements 15 and 6 from the final array. The sum of squares is 152 + 62 = 261.\nIt can be shown that this is the maximum value we can get.\n\nExample 2:\n\nInput: nums = [4,5,4,7], k = 3\nOutput: 90\nExplanation: We do not need to apply any operations.\nWe can choose the elements 7, 5, and 4 with a sum of squares: 72 + 52 + 42 = 90.\nIt can be shown that this is the maximum value we can get.\n\n\nConstraints:\n\n * 1 <= k <= nums.length <= 105\n * 1 <= nums[i] <= 109\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def maxSum(self, nums: List[int], k: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [2,6,5,8], \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 261\n\ntest_input = { \"nums\": [4,5,4,7], \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 90\n\ntest_input = { \"nums\": [32,85,61], \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 15625\n\ntest_input = { \"nums\": [123], \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 15129\n\ntest_input = { \"nums\": [96,66,60,58,32,17,63,21,30,44,15,8,98,93], \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 32258\n\ntest_input = { \"nums\": [30,8,63,69,52,94,41,28,94,86,28,13,68,38,53,11,21,33], \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 32258\n\ntest_input = { \"nums\": [2,38,15,2,73,100,47,14,25,58,40,64,23,9,53,38,91,75,9,2], \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 48387\n\ntest_input = { \"nums\": [25,52,75,65], \"k\": 4 }\nassert my_solution.maxSum(**test_input) == 24051\n\ntest_input = { \"nums\": [96,36,72,61,13,25,5,33,9,51,9,78,40], \"k\": 13 }\nassert my_solution.maxSum(**test_input) == 53776\n\ntest_input = { \"nums\": [38,21,15,84,65,35,57,82,94,26,27,89,73,22,25,6,97,17], \"k\": 4 }\nassert my_solution.maxSum(**test_input) == 64516\n\ntest_input = { \"nums\": [18,72,52,56,7,21,55,68,98,31,35,49,100,49,64,20], \"k\": 4 }\nassert my_solution.maxSum(**test_input) == 62548\n\ntest_input = { \"nums\": [2,73,75], \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 11250\n\ntest_input = { \"nums\": [73,37,41,84], \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 27506\n\ntest_input = { \"nums\": [62,83,11,3,53], \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 20459\n\ntest_input = { \"nums\": [53,59,71,38,5,15,98,86,9,8,35,54,65,77,3,68,11,5,41,18], \"k\": 9 }\nassert my_solution.maxSum(**test_input) == 95273\n\ntest_input = { \"nums\": [53,67,91,79,21,27,63,34,60,94,51], \"k\": 4 }\nassert my_solution.maxSum(**test_input) == 64516\n\ntest_input = { \"nums\": [41,15,6,31,40,97,11,45,81,91,91,62], \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 48387\n\ntest_input = { \"nums\": [10,9], \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 185\n\ntest_input = { \"nums\": [9,6,8,32,92,12,47,45,62,96,5,66,82,90,34,39,49,86,16], \"k\": 13 }\nassert my_solution.maxSum(**test_input) == 102770\n\ntest_input = { \"nums\": [1,19,29,30,68,13,80,16,71,32,8,76,41,24,16,2,30], \"k\": 14 }\nassert my_solution.maxSum(**test_input) == 53470\n\ntest_input = { \"nums\": [22,64,30,71,28,69,86,12,26,39,69,92], \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 25154\n\ntest_input = { \"nums\": [91,26,29,38,97,40,1,18,15,3,43,37,9,55,4,46], \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 32258\n\ntest_input = { \"nums\": [27,73], \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 8281\n\ntest_input = { \"nums\": [12,33,29,75,94,48,25,21], \"k\": 8 }\nassert my_solution.maxSum(**test_input) == 34565\n\ntest_input = { \"nums\": [39,91,84,10,65,28,94,28,62,77,78,50,93,65,21,16,5,35,81], \"k\": 14 }\nassert my_solution.maxSum(**test_input) == 110106\n\ntest_input = { \"nums\": [14,45,76,33,35,53,67,19,6,31,33], \"k\": 10 }\nassert my_solution.maxSum(**test_input) == 40008\n\ntest_input = { \"nums\": [59,88,2,47,75], \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 31258\n\ntest_input = { \"nums\": [96,77,77,33,5,86,90,21,84,73,86,45,88,35,93,14,63,25], \"k\": 17 }\nassert my_solution.maxSum(**test_input) == 121571\n\ntest_input = { \"nums\": [35,5,21,65,34,90,60,8,34,35,28,78,77], \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 16129\n\ntest_input = { \"nums\": [14,10,19], \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 1061\n\ntest_input = { \"nums\": [100,4,88,29,13,78,89,11,62,63,66,46,99,87,41,29,36,71,57], \"k\": 18 }\nassert my_solution.maxSum(**test_input) == 129739\n\ntest_input = { \"nums\": [86,52,100,68,30,40,49,28,61,30,3,80], \"k\": 11 }\nassert my_solution.maxSum(**test_input) == 69063\n\ntest_input = { \"nums\": [29,30,61,12,98,95], \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 32258\n\ntest_input = { \"nums\": [23,13,35,41,29,57,84,67,70,96,55,85,15,72,23,52,1,11,62,1], \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 16129\n\ntest_input = { \"nums\": [34,60,85,22,83], \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 30290\n\ntest_input = { \"nums\": [65,26,44,70,79,65,46,18], \"k\": 8 }\nassert my_solution.maxSum(**test_input) == 44587\n\ntest_input = { \"nums\": [99,50,13,62,12,60,6,29], \"k\": 6 }\nassert my_solution.maxSum(**test_input) == 28071\n\ntest_input = { \"nums\": [73,66,75,44], \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 23130\n\ntest_input = { \"nums\": [43,85,7,66,16,96], \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 16129\n\ntest_input = { \"nums\": [45,5,3,84,81,54,21,37,99,60], \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 32258\n\ntest_input = { \"nums\": [97,6,44,57,63,5], \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 16129\n\ntest_input = { \"nums\": [65,43,82,46,34,42,65,67,8,67,3,83,87,71,98,31,15,22], \"k\": 5 }\nassert my_solution.maxSum(**test_input) == 80645\n\ntest_input = { \"nums\": [79,33,75,32,64,68,30,46,60,50,6,54,18,34,43,11,84,78,54,4], \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 16129\n\ntest_input = { \"nums\": [17,9,3,23,33,99,94,15,93,17,39,55,13,26,22,44,13], \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 48387\n\ntest_input = { \"nums\": [83,29,2,67,79,88,71,98,70], \"k\": 4 }\nassert my_solution.maxSum(**test_input) == 39220\n\ntest_input = { \"nums\": [60,81,60,88,37,38,10,42,84,70], \"k\": 10 }\nassert my_solution.maxSum(**test_input) == 67626\n\ntest_input = { \"nums\": [33,51,100,33,46], \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 18739\n\ntest_input = { \"nums\": [29,4,67,44,74,62,41,86,91,11,26,58,59,48,46,41,26,68,4,81], \"k\": 4 }\nassert my_solution.maxSum(**test_input) == 64516\n\ntest_input = { \"nums\": [86,54,20,57,87,63,2,24,73,87,7,16,50,1,58], \"k\": 7 }\nassert my_solution.maxSum(**test_input) == 69543\n\ntest_input = { \"nums\": [91,2,16,77,2], \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 9025\n\ntest_input = { \"nums\": [19,94], \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 9349\n\ntest_input = { \"nums\": [14,67,79,58], \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 22370\n\ntest_input = { \"nums\": [44,17,10,19,3,97,45,65,98,7,73,30,76,5,52,33,62], \"k\": 4 }\nassert my_solution.maxSum(**test_input) == 64516\n\ntest_input = { \"nums\": [8,80,93], \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 8649\n\ntest_input = { \"nums\": [51,79,26,30,41,74,6,11,10,66,61,25,41,32,83,52,71,70], \"k\": 18 }\nassert my_solution.maxSum(**test_input) == 98085\n\ntest_input = { \"nums\": [15,58,38,69,71,43], \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 16129\n\ntest_input = { \"nums\": [13,57,34,69,80,98,63,22,29,38,70,94,79,95,13,76,39,22], \"k\": 5 }\nassert my_solution.maxSum(**test_input) == 80645\n\ntest_input = { \"nums\": [98,88,17,85,57,97,42,15,25,71,31,72,76,89,28,47,73,85], \"k\": 9 }\nassert my_solution.maxSum(**test_input) == 114889\n\ntest_input = { \"nums\": [95,28,26,65,87,4,14,25,47,97,67,48,29,14,96,76,77,25], \"k\": 9 }\nassert my_solution.maxSum(**test_input) == 100409\n\ntest_input = { \"nums\": [37,16,76,9,88,44,71,61,95,32,63,10,29,33], \"k\": 11 }\nassert my_solution.maxSum(**test_input) == 72360\n\ntest_input = { \"nums\": [54,96,73,18,15,35,79,96,2,12,50,75,7,93,66,35,40,16], \"k\": 18 }\nassert my_solution.maxSum(**test_input) == 104436\n\ntest_input = { \"nums\": [66,84,85,7,45,34,61,91,83,13,87,89,51,52,65], \"k\": 6 }\nassert my_solution.maxSum(**test_input) == 88214\n\ntest_input = { \"nums\": [76,22,86,88,58,10,61,21,42], \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 32258\n\ntest_input = { \"nums\": [16,52,8,99,68,73], \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 31754\n\ntest_input = { \"nums\": [46,91,73,38,36,79,24,78,24,42], \"k\": 8 }\nassert my_solution.maxSum(**test_input) == 60911\n\ntest_input = { \"nums\": [5,100,85,52,5,28,79,30,9,67,87,50,17,29,99,57], \"k\": 14 }\nassert my_solution.maxSum(**test_input) == 91019\n\ntest_input = { \"nums\": [52,57,77,95,79,28,9,94,70,8,89,75,27,53,41,88,68,8,10,59], \"k\": 5 }\nassert my_solution.maxSum(**test_input) == 80645\n\ntest_input = { \"nums\": [66,64,52,90,73,84,2], \"k\": 6 }\nassert my_solution.maxSum(**test_input) == 39881\n\ntest_input = { \"nums\": [97,100], \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 10201\n\ntest_input = { \"nums\": [27,85,57,44,16,55,77,77,24,62,72], \"k\": 10 }\nassert my_solution.maxSum(**test_input) == 66334\n\ntest_input = { \"nums\": [15,6,18,22,72,63,38,72,4,84,9,19,70,76,72,98,35,51,11,9], \"k\": 20 }\nassert my_solution.maxSum(**test_input) == 96344\n\ntest_input = { \"nums\": [10,67,54,100,6,93,91,4,59], \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 48387\n\ntest_input = { \"nums\": [90,48,91,62,39,94,75,8,21,72,9,55,16,30,27,73,81,39,97], \"k\": 8 }\nassert my_solution.maxSum(**test_input) == 114080\n\ntest_input = { \"nums\": [43,58,51,40,39,92,36,57], \"k\": 4 }\nassert my_solution.maxSum(**test_input) == 27548\n\ntest_input = { \"nums\": [85,51,49,13,7,66,21,59,100,14,5,66], \"k\": 8 }\nassert my_solution.maxSum(**test_input) == 63152\n\ntest_input = { \"nums\": [54,52,36,17,34,100,81,82,16,46,26,73,77,55,43,53], \"k\": 14 }\nassert my_solution.maxSum(**test_input) == 91703\n\ntest_input = { \"nums\": [97,1,30,41,82,77,99,56,21,68,14,39,15,26,72], \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 16129\n\ntest_input = { \"nums\": [17,10,28,78,68,68,29,44], \"k\": 5 }\nassert my_solution.maxSum(**test_input) == 33906\n\ntest_input = { \"nums\": [59,30,26,58,87,1,6,98,29,50,57,64,64], \"k\": 10 }\nassert my_solution.maxSum(**test_input) == 69321\n\ntest_input = { \"nums\": [77,23,43,94,74,41,26,39,83,57,85,49,83,34,63,37,42,55,20,18], \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 48387\n\ntest_input = { \"nums\": [54,19,69,95,26,59,68,90,77,62,67,54,42,25,50,23,30,53,29,78], \"k\": 12 }\nassert my_solution.maxSum(**test_input) == 117170\n\ntest_input = { \"nums\": [54,17,16,30,35,63,34,38,26,41,33], \"k\": 9 }\nassert my_solution.maxSum(**test_input) == 22133\n\ntest_input = { \"nums\": [17,24,8,57,68,54,64,53], \"k\": 6 }\nassert my_solution.maxSum(**test_input) == 35987\n\ntest_input = { \"nums\": [11,90,27,72,22,24,54,64,68,94,1,20,45,5,63], \"k\": 10 }\nassert my_solution.maxSum(**test_input) == 69082\n\ntest_input = { \"nums\": [92,84,89,72,80,1,8], \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 25042\n\ntest_input = { \"nums\": [29,14,37,61,7,10,53,95,47,81,1,59,18,25,3,53,43,64,33], \"k\": 5 }\nassert my_solution.maxSum(**test_input) == 56325\n\ntest_input = { \"nums\": [44,94,83,38,63,16,45,90,74,20], \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 16129\n\ntest_input = { \"nums\": [13,65], \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 5930\n\ntest_input = { \"nums\": [16,9,2,66], \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 8285\n\ntest_input = { \"nums\": [30,68,85,13,49,96,59,61,39], \"k\": 7 }\nassert my_solution.maxSum(**test_input) == 54942\n\ntest_input = { \"nums\": [29,47,38,4], \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 6178\n\ntest_input = { \"nums\": [49,30], \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 4225\n\ntest_input = { \"nums\": [64,71,33,46,77,45,33,55,84,30,1,40,2,92,54,88], \"k\": 8 }\nassert my_solution.maxSum(**test_input) == 98815\n\ntest_input = { \"nums\": [55,72,75], \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 16129\n\ntest_input = { \"nums\": [3,34,63,27,49,28,86], \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 24067\n\ntest_input = { \"nums\": [99,29,94,21,54,43,20,79,27,40,90,76,55,27,40,46,76,70,34], \"k\": 13 }\nassert my_solution.maxSum(**test_input) == 118264\n\ntest_input = { \"nums\": [64,11,2,12,11,82,10,42,63,98,99,13], \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 16129\n\ntest_input = { \"nums\": [23,25,45,88,88,93,91,25,34,83,9,85,18], \"k\": 8 }\nassert my_solution.maxSum(**test_input) == 67760\n\ntest_input = { \"nums\": [84,95,7,53,19,46,41,48,48,38], \"k\": 7 }\nassert my_solution.maxSum(**test_input) == 44981\n\ntest_input = { \"nums\": [92,88,27,34], \"k\": 4 }\nassert my_solution.maxSum(**test_input) == 24805", "start_time": 1696732200} +{"task_id": "weekly-contest-365-maximum-value-of-an-ordered-triplet-i", "url": "https://leetcode.com/problems/maximum-value-of-an-ordered-triplet-i", "title": "maximum-value-of-an-ordered-triplet-i", "meta": {"questionId": "3154", "questionFrontendId": "2873", "title": "Maximum Value of an Ordered Triplet I", "titleSlug": "maximum-value-of-an-ordered-triplet-i", "isPaidOnly": false, "difficulty": "Easy", "likes": 130, "dislikes": 10, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed integer array nums.\n\nReturn the maximum value over all triplets of indices (i, j, k) such that i < j < k. If all such triplets have a negative value, return 0.\n\nThe value of a triplet of indices (i, j, k) is equal to (nums[i] - nums[j]) * nums[k].\n\nExample 1:\n\nInput: nums = [12,6,1,2,7]\nOutput: 77\nExplanation: The value of the triplet (0, 2, 4) is (nums[0] - nums[2]) * nums[4] = 77.\nIt can be shown that there are no ordered triplets of indices with a value greater than 77.\n\nExample 2:\n\nInput: nums = [1,10,3,4,19]\nOutput: 133\nExplanation: The value of the triplet (1, 2, 4) is (nums[1] - nums[2]) * nums[4] = 133.\nIt can be shown that there are no ordered triplets of indices with a value greater than 133.\n\nExample 3:\n\nInput: nums = [1,2,3]\nOutput: 0\nExplanation: The only ordered triplet of indices (0, 1, 2) has a negative value of (nums[0] - nums[1]) * nums[2] = -3. Hence, the answer would be 0.\n\n\nConstraints:\n\n * 3 <= nums.length <= 100\n * 1 <= nums[i] <= 106\n\"\"\"\nclass Solution:\n def maximumTripletValue(self, nums: List[int]) -> int:\n ", "prompt_sft": "You are given a 0-indexed integer array nums.\n\nReturn the maximum value over all triplets of indices (i, j, k) such that i < j < k. If all such triplets have a negative value, return 0.\n\nThe value of a triplet of indices (i, j, k) is equal to (nums[i] - nums[j]) * nums[k].\n\nExample 1:\n\nInput: nums = [12,6,1,2,7]\nOutput: 77\nExplanation: The value of the triplet (0, 2, 4) is (nums[0] - nums[2]) * nums[4] = 77.\nIt can be shown that there are no ordered triplets of indices with a value greater than 77.\n\nExample 2:\n\nInput: nums = [1,10,3,4,19]\nOutput: 133\nExplanation: The value of the triplet (1, 2, 4) is (nums[1] - nums[2]) * nums[4] = 133.\nIt can be shown that there are no ordered triplets of indices with a value greater than 133.\n\nExample 3:\n\nInput: nums = [1,2,3]\nOutput: 0\nExplanation: The only ordered triplet of indices (0, 1, 2) has a negative value of (nums[0] - nums[1]) * nums[2] = -3. Hence, the answer would be 0.\n\n\nConstraints:\n\n * 3 <= nums.length <= 100\n * 1 <= nums[i] <= 106\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def maximumTripletValue(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [12,6,1,2,7] }\nassert my_solution.maximumTripletValue(**test_input) == 77\n\ntest_input = { \"nums\": [1,10,3,4,19] }\nassert my_solution.maximumTripletValue(**test_input) == 133\n\ntest_input = { \"nums\": [1,2,3] }\nassert my_solution.maximumTripletValue(**test_input) == 0\n\ntest_input = { \"nums\": [2,3,1] }\nassert my_solution.maximumTripletValue(**test_input) == 0\n\ntest_input = { \"nums\": [5,7,8,4] }\nassert my_solution.maximumTripletValue(**test_input) == 0\n\ntest_input = { \"nums\": [1000000,1,1000000] }\nassert my_solution.maximumTripletValue(**test_input) == 999999000000\n\ntest_input = { \"nums\": [18,15,8,13,10,9,17,10,2,16,17] }\nassert my_solution.maximumTripletValue(**test_input) == 272\n\ntest_input = { \"nums\": [8,6,3,13,2,12,19,5,19,6,10,11,9] }\nassert my_solution.maximumTripletValue(**test_input) == 266\n\ntest_input = { \"nums\": [6,11,12,12,7,9,2,11,12,4,19,14,16,8,16] }\nassert my_solution.maximumTripletValue(**test_input) == 190\n\ntest_input = { \"nums\": [15,14,17,13,18,17,10,19,2,20,12,9] }\nassert my_solution.maximumTripletValue(**test_input) == 340\n\ntest_input = { \"nums\": [6,14,20,19,19,10,3,15,12,13,8,1,2,15,3] }\nassert my_solution.maximumTripletValue(**test_input) == 285\n\ntest_input = { \"nums\": [2,7,19,4,8,20] }\nassert my_solution.maximumTripletValue(**test_input) == 300\n\ntest_input = { \"nums\": [10,13,6,2] }\nassert my_solution.maximumTripletValue(**test_input) == 14\n\ntest_input = { \"nums\": [1,19,1,3,18,10,16,9,3,17,8,9] }\nassert my_solution.maximumTripletValue(**test_input) == 324\n\ntest_input = { \"nums\": [16,2,10,20,16,2,13,8,19] }\nassert my_solution.maximumTripletValue(**test_input) == 342\n\ntest_input = { \"nums\": [19,11,12,4,17,1,7,20,13,10,14,20,11,19,3] }\nassert my_solution.maximumTripletValue(**test_input) == 360\n\ntest_input = { \"nums\": [16,15,12,5,4,12,15,17,5,18,6,16,1,17,4] }\nassert my_solution.maximumTripletValue(**test_input) == 289\n\ntest_input = { \"nums\": [8,10,17,11,2,8,13] }\nassert my_solution.maximumTripletValue(**test_input) == 195\n\ntest_input = { \"nums\": [13,4,3,19,16,14,17,6,20,6,16,4] }\nassert my_solution.maximumTripletValue(**test_input) == 260\n\ntest_input = { \"nums\": [1,8,9,18,4,10,3,13,9] }\nassert my_solution.maximumTripletValue(**test_input) == 195\n\ntest_input = { \"nums\": [10,10,5,19,2] }\nassert my_solution.maximumTripletValue(**test_input) == 95\n\ntest_input = { \"nums\": [15,3,3,18,19,13,7,5,18,1,8,5] }\nassert my_solution.maximumTripletValue(**test_input) == 252\n\ntest_input = { \"nums\": [10,20,10] }\nassert my_solution.maximumTripletValue(**test_input) == 0\n\ntest_input = { \"nums\": [14,9,4,20,9] }\nassert my_solution.maximumTripletValue(**test_input) == 200\n\ntest_input = { \"nums\": [12,20,5,2,13,17,16,1,5,8,18,15,12] }\nassert my_solution.maximumTripletValue(**test_input) == 342\n\ntest_input = { \"nums\": [7,1,17,17,4,20,14,20] }\nassert my_solution.maximumTripletValue(**test_input) == 260\n\ntest_input = { \"nums\": [16,19,8,8,5,18,12,16,8,14,14,7,19] }\nassert my_solution.maximumTripletValue(**test_input) == 266\n\ntest_input = { \"nums\": [17,9,13,7,3,5] }\nassert my_solution.maximumTripletValue(**test_input) == 104\n\ntest_input = { \"nums\": [15,12,2,14,15,18,15,20,14,5,14,14,11,13,7] }\nassert my_solution.maximumTripletValue(**test_input) == 260\n\ntest_input = { \"nums\": [17,20,17,13,5,12,8,12,14,10,14,20] }\nassert my_solution.maximumTripletValue(**test_input) == 300\n\ntest_input = { \"nums\": [1,19,10] }\nassert my_solution.maximumTripletValue(**test_input) == 0\n\ntest_input = { \"nums\": [11,16,10,15,10,5,7,3] }\nassert my_solution.maximumTripletValue(**test_input) == 90\n\ntest_input = { \"nums\": [5,14,19,12,2,5,18,3,20,12,1,11] }\nassert my_solution.maximumTripletValue(**test_input) == 340\n\ntest_input = { \"nums\": [10,8,12,14] }\nassert my_solution.maximumTripletValue(**test_input) == 28\n\ntest_input = { \"nums\": [2,17,18,16,14,20,11,3,18,5,20,6,7] }\nassert my_solution.maximumTripletValue(**test_input) == 340\n\ntest_input = { \"nums\": [19,12,3,19,2,18,3,12,9] }\nassert my_solution.maximumTripletValue(**test_input) == 306\n\ntest_input = { \"nums\": [12,9,11,2,11,3,11,17,13,19] }\nassert my_solution.maximumTripletValue(**test_input) == 190\n\ntest_input = { \"nums\": [8,13,9,8,7,18,20] }\nassert my_solution.maximumTripletValue(**test_input) == 120\n\ntest_input = { \"nums\": [20,8,12,1,7,8,3,3,6] }\nassert my_solution.maximumTripletValue(**test_input) == 152\n\ntest_input = { \"nums\": [8,2,16,6,14,14,13,2,11,5,2,12,15,3,3] }\nassert my_solution.maximumTripletValue(**test_input) == 210\n\ntest_input = { \"nums\": [19,9,9,9,5] }\nassert my_solution.maximumTripletValue(**test_input) == 90\n\ntest_input = { \"nums\": [19,10,5,13,6,9,5,15,19] }\nassert my_solution.maximumTripletValue(**test_input) == 266\n\ntest_input = { \"nums\": [14,18,17,8,2,8,14] }\nassert my_solution.maximumTripletValue(**test_input) == 224\n\ntest_input = { \"nums\": [11,5,17,13,5,8,8,19,17,1] }\nassert my_solution.maximumTripletValue(**test_input) == 228\n\ntest_input = { \"nums\": [18,12,18,14,17,19] }\nassert my_solution.maximumTripletValue(**test_input) == 114\n\ntest_input = { \"nums\": [18,17,8,8,18,9] }\nassert my_solution.maximumTripletValue(**test_input) == 180\n\ntest_input = { \"nums\": [15,3,2,10,11,10,13,18] }\nassert my_solution.maximumTripletValue(**test_input) == 234\n\ntest_input = { \"nums\": [17,17,5,10,19,1,16,3,1,19] }\nassert my_solution.maximumTripletValue(**test_input) == 342\n\ntest_input = { \"nums\": [1,18,4,20,16] }\nassert my_solution.maximumTripletValue(**test_input) == 280\n\ntest_input = { \"nums\": [6,20,4,4,2,19,14,10,9,7,20,5,8] }\nassert my_solution.maximumTripletValue(**test_input) == 360\n\ntest_input = { \"nums\": [5,14,15,18,2,9,15,13,11,16,12,20] }\nassert my_solution.maximumTripletValue(**test_input) == 320\n\ntest_input = { \"nums\": [7,19,17] }\nassert my_solution.maximumTripletValue(**test_input) == 0\n\ntest_input = { \"nums\": [5,7,14,18,13,11,15,20,8,11,12,4,17,2,16] }\nassert my_solution.maximumTripletValue(**test_input) == 288\n\ntest_input = { \"nums\": [4,12,7,2,8,6,9,5,4,1,8] }\nassert my_solution.maximumTripletValue(**test_input) == 90\n\ntest_input = { \"nums\": [11,17,2,18,5] }\nassert my_solution.maximumTripletValue(**test_input) == 270\n\ntest_input = { \"nums\": [19,13,2,2,19] }\nassert my_solution.maximumTripletValue(**test_input) == 323\n\ntest_input = { \"nums\": [14,11,7,6,2,20,16,14,4,12,1,9,16,7,10] }\nassert my_solution.maximumTripletValue(**test_input) == 304\n\ntest_input = { \"nums\": [8,15,6,16,16,9,6,14,4] }\nassert my_solution.maximumTripletValue(**test_input) == 144\n\ntest_input = { \"nums\": [16,19,1,7,18,6,18,5,19,18,19] }\nassert my_solution.maximumTripletValue(**test_input) == 342\n\ntest_input = { \"nums\": [16,14,11,2,17,9,10] }\nassert my_solution.maximumTripletValue(**test_input) == 238\n\ntest_input = { \"nums\": [3,4,18,2,20,1,1,16,15,8,7,14,19,6] }\nassert my_solution.maximumTripletValue(**test_input) == 361\n\ntest_input = { \"nums\": [12,20,14,18,11,16,16,9,12,5,14,17] }\nassert my_solution.maximumTripletValue(**test_input) == 255\n\ntest_input = { \"nums\": [12,19,2,9,6] }\nassert my_solution.maximumTripletValue(**test_input) == 153\n\ntest_input = { \"nums\": [17,19,14,7,10,18] }\nassert my_solution.maximumTripletValue(**test_input) == 216\n\ntest_input = { \"nums\": [3,4,19,10,16,13,6,20] }\nassert my_solution.maximumTripletValue(**test_input) == 260\n\ntest_input = { \"nums\": [11,6,8,9] }\nassert my_solution.maximumTripletValue(**test_input) == 45\n\ntest_input = { \"nums\": [7,12,9,19,10,18,16,2,1,3,7,9,7,7] }\nassert my_solution.maximumTripletValue(**test_input) == 162\n\ntest_input = { \"nums\": [20,9,20,7,3,7,19] }\nassert my_solution.maximumTripletValue(**test_input) == 323\n\ntest_input = { \"nums\": [10,11,3,3,3,2,9,8] }\nassert my_solution.maximumTripletValue(**test_input) == 81\n\ntest_input = { \"nums\": [4,20,15,1,17,2,2,4,10,15,2,8,16,6] }\nassert my_solution.maximumTripletValue(**test_input) == 323\n\ntest_input = { \"nums\": [15,10,1,18,18,16,7,13,9,11] }\nassert my_solution.maximumTripletValue(**test_input) == 252\n\ntest_input = { \"nums\": [10,6,17,11,15,15,18] }\nassert my_solution.maximumTripletValue(**test_input) == 108\n\ntest_input = { \"nums\": [3,6,18] }\nassert my_solution.maximumTripletValue(**test_input) == 0\n\ntest_input = { \"nums\": [4,7,20] }\nassert my_solution.maximumTripletValue(**test_input) == 0\n\ntest_input = { \"nums\": [16,12,5] }\nassert my_solution.maximumTripletValue(**test_input) == 20\n\ntest_input = { \"nums\": [4,17,15,12,2,16,16,13,6,20,14,17,18,16] }\nassert my_solution.maximumTripletValue(**test_input) == 300\n\ntest_input = { \"nums\": [1,7,18,3,1,11,7,17] }\nassert my_solution.maximumTripletValue(**test_input) == 289\n\ntest_input = { \"nums\": [18,16,10,2] }\nassert my_solution.maximumTripletValue(**test_input) == 20\n\ntest_input = { \"nums\": [3,10,18,10,7,8] }\nassert my_solution.maximumTripletValue(**test_input) == 88\n\ntest_input = { \"nums\": [8,6,20,20,4,12,14,7,13,16,12,15,12] }\nassert my_solution.maximumTripletValue(**test_input) == 256\n\ntest_input = { \"nums\": [5,19,11,18,19,14,8,11,4,10] }\nassert my_solution.maximumTripletValue(**test_input) == 152\n\ntest_input = { \"nums\": [17,1,16] }\nassert my_solution.maximumTripletValue(**test_input) == 256\n\ntest_input = { \"nums\": [20,8,17,14,15,2,7,9,1,10,10,4,19,2,1] }\nassert my_solution.maximumTripletValue(**test_input) == 361\n\ntest_input = { \"nums\": [9,16,16] }\nassert my_solution.maximumTripletValue(**test_input) == 0\n\ntest_input = { \"nums\": [2,16,2,19,5,20,2,20,6,6] }\nassert my_solution.maximumTripletValue(**test_input) == 360\n\ntest_input = { \"nums\": [18,3,6,17,4,20,14,6,13,9,5,11] }\nassert my_solution.maximumTripletValue(**test_input) == 300\n\ntest_input = { \"nums\": [12,2,19,15,4,3,18,6,11,9,9,6,15] }\nassert my_solution.maximumTripletValue(**test_input) == 288\n\ntest_input = { \"nums\": [10,15,10,13,7,18,18,3,13,15,20,4,6,15] }\nassert my_solution.maximumTripletValue(**test_input) == 300\n\ntest_input = { \"nums\": [10,15,4,19,6,17,7,10,4,12,14,16,9,14] }\nassert my_solution.maximumTripletValue(**test_input) == 240\n\ntest_input = { \"nums\": [17,6,3,8,13] }\nassert my_solution.maximumTripletValue(**test_input) == 182\n\ntest_input = { \"nums\": [6,18,8,8,16,14,7,18] }\nassert my_solution.maximumTripletValue(**test_input) == 198\n\ntest_input = { \"nums\": [7,7,2,19,16,11,3,15,3,15,16,17] }\nassert my_solution.maximumTripletValue(**test_input) == 272\n\ntest_input = { \"nums\": [9,3,3,12,9,12,5,7,6,2,9,9,14,9,5] }\nassert my_solution.maximumTripletValue(**test_input) == 140\n\ntest_input = { \"nums\": [19,14,15,1,20,10,20,4,10,20,15,15,2,7] }\nassert my_solution.maximumTripletValue(**test_input) == 360\n\ntest_input = { \"nums\": [17,4,10,16,8,20,4,9,11,15,2,7] }\nassert my_solution.maximumTripletValue(**test_input) == 260\n\ntest_input = { \"nums\": [3,8,17,10,10,20,20,8,14,20,1,10,1] }\nassert my_solution.maximumTripletValue(**test_input) == 240\n\ntest_input = { \"nums\": [3,4,11,18,10,19,9,11,14,11,18,15,17,19,3] }\nassert my_solution.maximumTripletValue(**test_input) == 190\n\ntest_input = { \"nums\": [18,10,5,16,13,1,19,10,17,14,14,20] }\nassert my_solution.maximumTripletValue(**test_input) == 340\n\ntest_input = { \"nums\": [18,3,16,14,15,9,13,2,3] }\nassert my_solution.maximumTripletValue(**test_input) == 240\n\ntest_input = { \"nums\": [2,6,19,10,19,14,18,8,3,2] }\nassert my_solution.maximumTripletValue(**test_input) == 171", "start_time": 1696127400} +{"task_id": "weekly-contest-365-maximum-value-of-an-ordered-triplet-ii", "url": "https://leetcode.com/problems/maximum-value-of-an-ordered-triplet-ii", "title": "maximum-value-of-an-ordered-triplet-ii", "meta": {"questionId": "3152", "questionFrontendId": "2874", "title": "Maximum Value of an Ordered Triplet II", "titleSlug": "maximum-value-of-an-ordered-triplet-ii", "isPaidOnly": false, "difficulty": "Medium", "likes": 238, "dislikes": 8, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed integer array nums.\n\nReturn the maximum value over all triplets of indices (i, j, k) such that i < j < k. If all such triplets have a negative value, return 0.\n\nThe value of a triplet of indices (i, j, k) is equal to (nums[i] - nums[j]) * nums[k].\n\nExample 1:\n\nInput: nums = [12,6,1,2,7]\nOutput: 77\nExplanation: The value of the triplet (0, 2, 4) is (nums[0] - nums[2]) * nums[4] = 77.\nIt can be shown that there are no ordered triplets of indices with a value greater than 77.\n\nExample 2:\n\nInput: nums = [1,10,3,4,19]\nOutput: 133\nExplanation: The value of the triplet (1, 2, 4) is (nums[1] - nums[2]) * nums[4] = 133.\nIt can be shown that there are no ordered triplets of indices with a value greater than 133.\n\nExample 3:\n\nInput: nums = [1,2,3]\nOutput: 0\nExplanation: The only ordered triplet of indices (0, 1, 2) has a negative value of (nums[0] - nums[1]) * nums[2] = -3. Hence, the answer would be 0.\n\n\nConstraints:\n\n * 3 <= nums.length <= 105\n * 1 <= nums[i] <= 106\n\"\"\"\nclass Solution:\n def maximumTripletValue(self, nums: List[int]) -> int:\n ", "prompt_sft": "You are given a 0-indexed integer array nums.\n\nReturn the maximum value over all triplets of indices (i, j, k) such that i < j < k. If all such triplets have a negative value, return 0.\n\nThe value of a triplet of indices (i, j, k) is equal to (nums[i] - nums[j]) * nums[k].\n\nExample 1:\n\nInput: nums = [12,6,1,2,7]\nOutput: 77\nExplanation: The value of the triplet (0, 2, 4) is (nums[0] - nums[2]) * nums[4] = 77.\nIt can be shown that there are no ordered triplets of indices with a value greater than 77.\n\nExample 2:\n\nInput: nums = [1,10,3,4,19]\nOutput: 133\nExplanation: The value of the triplet (1, 2, 4) is (nums[1] - nums[2]) * nums[4] = 133.\nIt can be shown that there are no ordered triplets of indices with a value greater than 133.\n\nExample 3:\n\nInput: nums = [1,2,3]\nOutput: 0\nExplanation: The only ordered triplet of indices (0, 1, 2) has a negative value of (nums[0] - nums[1]) * nums[2] = -3. Hence, the answer would be 0.\n\n\nConstraints:\n\n * 3 <= nums.length <= 105\n * 1 <= nums[i] <= 106\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def maximumTripletValue(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [12,6,1,2,7] }\nassert my_solution.maximumTripletValue(**test_input) == 77\n\ntest_input = { \"nums\": [1,10,3,4,19] }\nassert my_solution.maximumTripletValue(**test_input) == 133\n\ntest_input = { \"nums\": [1,2,3] }\nassert my_solution.maximumTripletValue(**test_input) == 0\n\ntest_input = { \"nums\": [2,3,1] }\nassert my_solution.maximumTripletValue(**test_input) == 0\n\ntest_input = { \"nums\": [5,7,8,4] }\nassert my_solution.maximumTripletValue(**test_input) == 0\n\ntest_input = { \"nums\": [1000000,1,1000000] }\nassert my_solution.maximumTripletValue(**test_input) == 999999000000\n\ntest_input = { \"nums\": [18,15,8,13,10,9,17,10,2,16,17] }\nassert my_solution.maximumTripletValue(**test_input) == 272\n\ntest_input = { \"nums\": [8,6,3,13,2,12,19,5,19,6,10,11,9] }\nassert my_solution.maximumTripletValue(**test_input) == 266\n\ntest_input = { \"nums\": [6,11,12,12,7,9,2,11,12,4,19,14,16,8,16] }\nassert my_solution.maximumTripletValue(**test_input) == 190\n\ntest_input = { \"nums\": [15,14,17,13,18,17,10,19,2,20,12,9] }\nassert my_solution.maximumTripletValue(**test_input) == 340\n\ntest_input = { \"nums\": [6,14,20,19,19,10,3,15,12,13,8,1,2,15,3] }\nassert my_solution.maximumTripletValue(**test_input) == 285\n\ntest_input = { \"nums\": [2,7,19,4,8,20] }\nassert my_solution.maximumTripletValue(**test_input) == 300\n\ntest_input = { \"nums\": [10,13,6,2] }\nassert my_solution.maximumTripletValue(**test_input) == 14\n\ntest_input = { \"nums\": [1,19,1,3,18,10,16,9,3,17,8,9] }\nassert my_solution.maximumTripletValue(**test_input) == 324\n\ntest_input = { \"nums\": [16,2,10,20,16,2,13,8,19] }\nassert my_solution.maximumTripletValue(**test_input) == 342\n\ntest_input = { \"nums\": [19,11,12,4,17,1,7,20,13,10,14,20,11,19,3] }\nassert my_solution.maximumTripletValue(**test_input) == 360\n\ntest_input = { \"nums\": [16,15,12,5,4,12,15,17,5,18,6,16,1,17,4] }\nassert my_solution.maximumTripletValue(**test_input) == 289\n\ntest_input = { \"nums\": [8,10,17,11,2,8,13] }\nassert my_solution.maximumTripletValue(**test_input) == 195\n\ntest_input = { \"nums\": [13,4,3,19,16,14,17,6,20,6,16,4] }\nassert my_solution.maximumTripletValue(**test_input) == 260\n\ntest_input = { \"nums\": [1,8,9,18,4,10,3,13,9] }\nassert my_solution.maximumTripletValue(**test_input) == 195\n\ntest_input = { \"nums\": [10,10,5,19,2] }\nassert my_solution.maximumTripletValue(**test_input) == 95\n\ntest_input = { \"nums\": [15,3,3,18,19,13,7,5,18,1,8,5] }\nassert my_solution.maximumTripletValue(**test_input) == 252\n\ntest_input = { \"nums\": [10,20,10] }\nassert my_solution.maximumTripletValue(**test_input) == 0\n\ntest_input = { \"nums\": [14,9,4,20,9] }\nassert my_solution.maximumTripletValue(**test_input) == 200\n\ntest_input = { \"nums\": [12,20,5,2,13,17,16,1,5,8,18,15,12] }\nassert my_solution.maximumTripletValue(**test_input) == 342\n\ntest_input = { \"nums\": [7,1,17,17,4,20,14,20] }\nassert my_solution.maximumTripletValue(**test_input) == 260\n\ntest_input = { \"nums\": [16,19,8,8,5,18,12,16,8,14,14,7,19] }\nassert my_solution.maximumTripletValue(**test_input) == 266\n\ntest_input = { \"nums\": [17,9,13,7,3,5] }\nassert my_solution.maximumTripletValue(**test_input) == 104\n\ntest_input = { \"nums\": [15,12,2,14,15,18,15,20,14,5,14,14,11,13,7] }\nassert my_solution.maximumTripletValue(**test_input) == 260\n\ntest_input = { \"nums\": [17,20,17,13,5,12,8,12,14,10,14,20] }\nassert my_solution.maximumTripletValue(**test_input) == 300\n\ntest_input = { \"nums\": [1,19,10] }\nassert my_solution.maximumTripletValue(**test_input) == 0\n\ntest_input = { \"nums\": [11,16,10,15,10,5,7,3] }\nassert my_solution.maximumTripletValue(**test_input) == 90\n\ntest_input = { \"nums\": [5,14,19,12,2,5,18,3,20,12,1,11] }\nassert my_solution.maximumTripletValue(**test_input) == 340\n\ntest_input = { \"nums\": [10,8,12,14] }\nassert my_solution.maximumTripletValue(**test_input) == 28\n\ntest_input = { \"nums\": [2,17,18,16,14,20,11,3,18,5,20,6,7] }\nassert my_solution.maximumTripletValue(**test_input) == 340\n\ntest_input = { \"nums\": [19,12,3,19,2,18,3,12,9] }\nassert my_solution.maximumTripletValue(**test_input) == 306\n\ntest_input = { \"nums\": [12,9,11,2,11,3,11,17,13,19] }\nassert my_solution.maximumTripletValue(**test_input) == 190\n\ntest_input = { \"nums\": [8,13,9,8,7,18,20] }\nassert my_solution.maximumTripletValue(**test_input) == 120\n\ntest_input = { \"nums\": [20,8,12,1,7,8,3,3,6] }\nassert my_solution.maximumTripletValue(**test_input) == 152\n\ntest_input = { \"nums\": [8,2,16,6,14,14,13,2,11,5,2,12,15,3,3] }\nassert my_solution.maximumTripletValue(**test_input) == 210\n\ntest_input = { \"nums\": [19,9,9,9,5] }\nassert my_solution.maximumTripletValue(**test_input) == 90\n\ntest_input = { \"nums\": [19,10,5,13,6,9,5,15,19] }\nassert my_solution.maximumTripletValue(**test_input) == 266\n\ntest_input = { \"nums\": [14,18,17,8,2,8,14] }\nassert my_solution.maximumTripletValue(**test_input) == 224\n\ntest_input = { \"nums\": [11,5,17,13,5,8,8,19,17,1] }\nassert my_solution.maximumTripletValue(**test_input) == 228\n\ntest_input = { \"nums\": [18,12,18,14,17,19] }\nassert my_solution.maximumTripletValue(**test_input) == 114\n\ntest_input = { \"nums\": [18,17,8,8,18,9] }\nassert my_solution.maximumTripletValue(**test_input) == 180\n\ntest_input = { \"nums\": [15,3,2,10,11,10,13,18] }\nassert my_solution.maximumTripletValue(**test_input) == 234\n\ntest_input = { \"nums\": [17,17,5,10,19,1,16,3,1,19] }\nassert my_solution.maximumTripletValue(**test_input) == 342\n\ntest_input = { \"nums\": [1,18,4,20,16] }\nassert my_solution.maximumTripletValue(**test_input) == 280\n\ntest_input = { \"nums\": [6,20,4,4,2,19,14,10,9,7,20,5,8] }\nassert my_solution.maximumTripletValue(**test_input) == 360\n\ntest_input = { \"nums\": [5,14,15,18,2,9,15,13,11,16,12,20] }\nassert my_solution.maximumTripletValue(**test_input) == 320\n\ntest_input = { \"nums\": [7,19,17] }\nassert my_solution.maximumTripletValue(**test_input) == 0\n\ntest_input = { \"nums\": [5,7,14,18,13,11,15,20,8,11,12,4,17,2,16] }\nassert my_solution.maximumTripletValue(**test_input) == 288\n\ntest_input = { \"nums\": [4,12,7,2,8,6,9,5,4,1,8] }\nassert my_solution.maximumTripletValue(**test_input) == 90\n\ntest_input = { \"nums\": [11,17,2,18,5] }\nassert my_solution.maximumTripletValue(**test_input) == 270\n\ntest_input = { \"nums\": [19,13,2,2,19] }\nassert my_solution.maximumTripletValue(**test_input) == 323\n\ntest_input = { \"nums\": [14,11,7,6,2,20,16,14,4,12,1,9,16,7,10] }\nassert my_solution.maximumTripletValue(**test_input) == 304\n\ntest_input = { \"nums\": [8,15,6,16,16,9,6,14,4] }\nassert my_solution.maximumTripletValue(**test_input) == 144\n\ntest_input = { \"nums\": [16,19,1,7,18,6,18,5,19,18,19] }\nassert my_solution.maximumTripletValue(**test_input) == 342\n\ntest_input = { \"nums\": [16,14,11,2,17,9,10] }\nassert my_solution.maximumTripletValue(**test_input) == 238\n\ntest_input = { \"nums\": [3,4,18,2,20,1,1,16,15,8,7,14,19,6] }\nassert my_solution.maximumTripletValue(**test_input) == 361\n\ntest_input = { \"nums\": [12,20,14,18,11,16,16,9,12,5,14,17] }\nassert my_solution.maximumTripletValue(**test_input) == 255\n\ntest_input = { \"nums\": [12,19,2,9,6] }\nassert my_solution.maximumTripletValue(**test_input) == 153\n\ntest_input = { \"nums\": [17,19,14,7,10,18] }\nassert my_solution.maximumTripletValue(**test_input) == 216\n\ntest_input = { \"nums\": [3,4,19,10,16,13,6,20] }\nassert my_solution.maximumTripletValue(**test_input) == 260\n\ntest_input = { \"nums\": [11,6,8,9] }\nassert my_solution.maximumTripletValue(**test_input) == 45\n\ntest_input = { \"nums\": [7,12,9,19,10,18,16,2,1,3,7,9,7,7] }\nassert my_solution.maximumTripletValue(**test_input) == 162\n\ntest_input = { \"nums\": [20,9,20,7,3,7,19] }\nassert my_solution.maximumTripletValue(**test_input) == 323\n\ntest_input = { \"nums\": [10,11,3,3,3,2,9,8] }\nassert my_solution.maximumTripletValue(**test_input) == 81\n\ntest_input = { \"nums\": [4,20,15,1,17,2,2,4,10,15,2,8,16,6] }\nassert my_solution.maximumTripletValue(**test_input) == 323\n\ntest_input = { \"nums\": [15,10,1,18,18,16,7,13,9,11] }\nassert my_solution.maximumTripletValue(**test_input) == 252\n\ntest_input = { \"nums\": [10,6,17,11,15,15,18] }\nassert my_solution.maximumTripletValue(**test_input) == 108\n\ntest_input = { \"nums\": [3,6,18] }\nassert my_solution.maximumTripletValue(**test_input) == 0\n\ntest_input = { \"nums\": [4,7,20] }\nassert my_solution.maximumTripletValue(**test_input) == 0\n\ntest_input = { \"nums\": [16,12,5] }\nassert my_solution.maximumTripletValue(**test_input) == 20\n\ntest_input = { \"nums\": [4,17,15,12,2,16,16,13,6,20,14,17,18,16] }\nassert my_solution.maximumTripletValue(**test_input) == 300\n\ntest_input = { \"nums\": [1,7,18,3,1,11,7,17] }\nassert my_solution.maximumTripletValue(**test_input) == 289\n\ntest_input = { \"nums\": [18,16,10,2] }\nassert my_solution.maximumTripletValue(**test_input) == 20\n\ntest_input = { \"nums\": [3,10,18,10,7,8] }\nassert my_solution.maximumTripletValue(**test_input) == 88\n\ntest_input = { \"nums\": [8,6,20,20,4,12,14,7,13,16,12,15,12] }\nassert my_solution.maximumTripletValue(**test_input) == 256\n\ntest_input = { \"nums\": [5,19,11,18,19,14,8,11,4,10] }\nassert my_solution.maximumTripletValue(**test_input) == 152\n\ntest_input = { \"nums\": [17,1,16] }\nassert my_solution.maximumTripletValue(**test_input) == 256\n\ntest_input = { \"nums\": [20,8,17,14,15,2,7,9,1,10,10,4,19,2,1] }\nassert my_solution.maximumTripletValue(**test_input) == 361\n\ntest_input = { \"nums\": [9,16,16] }\nassert my_solution.maximumTripletValue(**test_input) == 0\n\ntest_input = { \"nums\": [2,16,2,19,5,20,2,20,6,6] }\nassert my_solution.maximumTripletValue(**test_input) == 360\n\ntest_input = { \"nums\": [18,3,6,17,4,20,14,6,13,9,5,11] }\nassert my_solution.maximumTripletValue(**test_input) == 300\n\ntest_input = { \"nums\": [12,2,19,15,4,3,18,6,11,9,9,6,15] }\nassert my_solution.maximumTripletValue(**test_input) == 288\n\ntest_input = { \"nums\": [10,15,10,13,7,18,18,3,13,15,20,4,6,15] }\nassert my_solution.maximumTripletValue(**test_input) == 300\n\ntest_input = { \"nums\": [10,15,4,19,6,17,7,10,4,12,14,16,9,14] }\nassert my_solution.maximumTripletValue(**test_input) == 240\n\ntest_input = { \"nums\": [17,6,3,8,13] }\nassert my_solution.maximumTripletValue(**test_input) == 182\n\ntest_input = { \"nums\": [6,18,8,8,16,14,7,18] }\nassert my_solution.maximumTripletValue(**test_input) == 198\n\ntest_input = { \"nums\": [7,7,2,19,16,11,3,15,3,15,16,17] }\nassert my_solution.maximumTripletValue(**test_input) == 272\n\ntest_input = { \"nums\": [9,3,3,12,9,12,5,7,6,2,9,9,14,9,5] }\nassert my_solution.maximumTripletValue(**test_input) == 140\n\ntest_input = { \"nums\": [19,14,15,1,20,10,20,4,10,20,15,15,2,7] }\nassert my_solution.maximumTripletValue(**test_input) == 360\n\ntest_input = { \"nums\": [17,4,10,16,8,20,4,9,11,15,2,7] }\nassert my_solution.maximumTripletValue(**test_input) == 260\n\ntest_input = { \"nums\": [3,8,17,10,10,20,20,8,14,20,1,10,1] }\nassert my_solution.maximumTripletValue(**test_input) == 240\n\ntest_input = { \"nums\": [3,4,11,18,10,19,9,11,14,11,18,15,17,19,3] }\nassert my_solution.maximumTripletValue(**test_input) == 190\n\ntest_input = { \"nums\": [18,10,5,16,13,1,19,10,17,14,14,20] }\nassert my_solution.maximumTripletValue(**test_input) == 340\n\ntest_input = { \"nums\": [18,3,16,14,15,9,13,2,3] }\nassert my_solution.maximumTripletValue(**test_input) == 240\n\ntest_input = { \"nums\": [2,6,19,10,19,14,18,8,3,2] }\nassert my_solution.maximumTripletValue(**test_input) == 171", "start_time": 1696127400} +{"task_id": "weekly-contest-365-minimum-size-subarray-in-infinite-array", "url": "https://leetcode.com/problems/minimum-size-subarray-in-infinite-array", "title": "minimum-size-subarray-in-infinite-array", "meta": {"questionId": "3141", "questionFrontendId": "2875", "title": "Minimum Size Subarray in Infinite Array", "titleSlug": "minimum-size-subarray-in-infinite-array", "isPaidOnly": false, "difficulty": "Medium", "likes": 309, "dislikes": 19, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed array nums and an integer target.\n\nA 0-indexed array infinite_nums is generated by infinitely appending the elements of nums to itself.\n\nReturn the length of the shortest subarray of the array infinite_nums with a sum equal to target. If there is no such subarray return -1.\n\nExample 1:\n\nInput: nums = [1,2,3], target = 5\nOutput: 2\nExplanation: In this example infinite_nums = [1,2,3,1,2,3,1,2,...].\nThe subarray in the range [1,2], has the sum equal to target = 5 and length = 2.\nIt can be proven that 2 is the shortest length of a subarray with sum equal to target = 5.\n\nExample 2:\n\nInput: nums = [1,1,1,2,3], target = 4\nOutput: 2\nExplanation: In this example infinite_nums = [1,1,1,2,3,1,1,1,2,3,1,1,...].\nThe subarray in the range [4,5], has the sum equal to target = 4 and length = 2.\nIt can be proven that 2 is the shortest length of a subarray with sum equal to target = 4.\n\nExample 3:\n\nInput: nums = [2,4,6,8], target = 3\nOutput: -1\nExplanation: In this example infinite_nums = [2,4,6,8,2,4,6,8,...].\nIt can be proven that there is no subarray with sum equal to target = 3.\n\n\nConstraints:\n\n * 1 <= nums.length <= 105\n * 1 <= nums[i] <= 105\n * 1 <= target <= 109\n\"\"\"\nclass Solution:\n def minSizeSubarray(self, nums: List[int], target: int) -> int:\n ", "prompt_sft": "You are given a 0-indexed array nums and an integer target.\n\nA 0-indexed array infinite_nums is generated by infinitely appending the elements of nums to itself.\n\nReturn the length of the shortest subarray of the array infinite_nums with a sum equal to target. If there is no such subarray return -1.\n\nExample 1:\n\nInput: nums = [1,2,3], target = 5\nOutput: 2\nExplanation: In this example infinite_nums = [1,2,3,1,2,3,1,2,...].\nThe subarray in the range [1,2], has the sum equal to target = 5 and length = 2.\nIt can be proven that 2 is the shortest length of a subarray with sum equal to target = 5.\n\nExample 2:\n\nInput: nums = [1,1,1,2,3], target = 4\nOutput: 2\nExplanation: In this example infinite_nums = [1,1,1,2,3,1,1,1,2,3,1,1,...].\nThe subarray in the range [4,5], has the sum equal to target = 4 and length = 2.\nIt can be proven that 2 is the shortest length of a subarray with sum equal to target = 4.\n\nExample 3:\n\nInput: nums = [2,4,6,8], target = 3\nOutput: -1\nExplanation: In this example infinite_nums = [2,4,6,8,2,4,6,8,...].\nIt can be proven that there is no subarray with sum equal to target = 3.\n\n\nConstraints:\n\n * 1 <= nums.length <= 105\n * 1 <= nums[i] <= 105\n * 1 <= target <= 109\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def minSizeSubarray(self, nums: List[int], target: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,2,3], \"target\": 5 }\nassert my_solution.minSizeSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,1,2,3], \"target\": 4 }\nassert my_solution.minSizeSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [2,4,6,8], \"target\": 3 }\nassert my_solution.minSizeSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [2,1,5,7,7,1,6,3], \"target\": 39 }\nassert my_solution.minSizeSubarray(**test_input) == 9\n\ntest_input = { \"nums\": [17,4,3,14,17,6,15], \"target\": 85 }\nassert my_solution.minSizeSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [18,3,11,19,7,16,6,7,3,6,18,9,9,1,14,17,15,14,12,10], \"target\": 7 }\nassert my_solution.minSizeSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [2,3,5,2,3,4,4,1,3,5,2,2,5,1,1,2,5], \"target\": 19 }\nassert my_solution.minSizeSubarray(**test_input) == 6\n\ntest_input = { \"nums\": [4,1,5,7,1,6,1,7,2,2,5,5,5,6,3], \"target\": 20 }\nassert my_solution.minSizeSubarray(**test_input) == 5\n\ntest_input = { \"nums\": [7,3,5], \"target\": 36 }\nassert my_solution.minSizeSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [1,11,6,4,13], \"target\": 22 }\nassert my_solution.minSizeSubarray(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,2,2,1,2,1,2,1,2,1], \"target\": 83 }\nassert my_solution.minSizeSubarray(**test_input) == 53\n\ntest_input = { \"nums\": [4,3,5,4,5,4,4,4,5,7,4,5,6,3,1,4,6,3,7], \"target\": 15 }\nassert my_solution.minSizeSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,3,2,1,5,3,4,5], \"target\": 53 }\nassert my_solution.minSizeSubarray(**test_input) == 19\n\ntest_input = { \"nums\": [2,5,6,4], \"target\": 95 }\nassert my_solution.minSizeSubarray(**test_input) == 22\n\ntest_input = { \"nums\": [6,6,4,5,2,8,1,8,7,6,6,7,4,1,9,6,8,8], \"target\": 55 }\nassert my_solution.minSizeSubarray(**test_input) == 9\n\ntest_input = { \"nums\": [1,2,8,19,17,2,3,11,8,12,16,18,7], \"target\": 36 }\nassert my_solution.minSizeSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [12,14,4,14,13,16,5], \"target\": 36 }\nassert my_solution.minSizeSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], \"target\": 37 }\nassert my_solution.minSizeSubarray(**test_input) == 37\n\ntest_input = { \"nums\": [5,7,2,6,4,1,6,7,1,4,7,6,7,7,6,6,4,6,8], \"target\": 90 }\nassert my_solution.minSizeSubarray(**test_input) == 17\n\ntest_input = { \"nums\": [3,5,15,17,6,17,10,15,10,4,6], \"target\": 25 }\nassert my_solution.minSizeSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [14,5], \"target\": 23 }\nassert my_solution.minSizeSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,5,9], \"target\": 68 }\nassert my_solution.minSizeSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [11,1,17,14,9,16,5,3,7,16,14,18,17,10], \"target\": 82 }\nassert my_solution.minSizeSubarray(**test_input) == 6\n\ntest_input = { \"nums\": [9,6,8,4,3,4,6,4,7,2,6,9,2,4,5,4], \"target\": 71 }\nassert my_solution.minSizeSubarray(**test_input) == 14\n\ntest_input = { \"nums\": [2,4,4,3,2,3,2,5,3,1,5,1,4,2,6], \"target\": 23 }\nassert my_solution.minSizeSubarray(**test_input) == 7\n\ntest_input = { \"nums\": [3,6], \"target\": 66 }\nassert my_solution.minSizeSubarray(**test_input) == 15\n\ntest_input = { \"nums\": [1,4,8,5,9,8,8,2,3,1,6,2,7,5,5,3,3,5,6], \"target\": 57 }\nassert my_solution.minSizeSubarray(**test_input) == 10\n\ntest_input = { \"nums\": [1,6,5,5,1,1,2,5,3,1,5,3,2,4,6,6], \"target\": 56 }\nassert my_solution.minSizeSubarray(**test_input) == 16\n\ntest_input = { \"nums\": [5,3,5,4,3,1,3,3,1,3,3,5,5,4,5,5,5,5], \"target\": 8 }\nassert my_solution.minSizeSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [2,2,1,3,2,2,2,3,3,2,1,3,3,2,3,3], \"target\": 93 }\nassert my_solution.minSizeSubarray(**test_input) == 40\n\ntest_input = { \"nums\": [5,1,4,1,5,6], \"target\": 71 }\nassert my_solution.minSizeSubarray(**test_input) == 19\n\ntest_input = { \"nums\": [3,5,6,6,1,8,4,9,6,2,3,9,6,8,7,3,6,1,8,6], \"target\": 60 }\nassert my_solution.minSizeSubarray(**test_input) == 11\n\ntest_input = { \"nums\": [12,15,9,3,3,12,13,14,7,11,7,15,12,5,11], \"target\": 18 }\nassert my_solution.minSizeSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [3,11,10,12,9,13,9], \"target\": 19 }\nassert my_solution.minSizeSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [3,4,4], \"target\": 35 }\nassert my_solution.minSizeSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [4,5,2,5,5,5,1], \"target\": 87 }\nassert my_solution.minSizeSubarray(**test_input) == 23\n\ntest_input = { \"nums\": [2,13,15,3,6,7,16,7,9,10,4,3,12,9,13,2,9,13,15], \"target\": 4 }\nassert my_solution.minSizeSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,16,10,15,15,13,11,10,6,12,15,9], \"target\": 30 }\nassert my_solution.minSizeSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [3,5], \"target\": 85 }\nassert my_solution.minSizeSubarray(**test_input) == 21\n\ntest_input = { \"nums\": [1,4,3,1,4,4,2,3], \"target\": 6 }\nassert my_solution.minSizeSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [2,10,12,10,4,4,12,5,12,12,5], \"target\": 33 }\nassert my_solution.minSizeSubarray(**test_input) == 4\n\ntest_input = { \"nums\": [5,9,7,10,4,7,9,11,6,3,1,8,6,1,11,1,1], \"target\": 72 }\nassert my_solution.minSizeSubarray(**test_input) == 11\n\ntest_input = { \"nums\": [19,18,6], \"target\": 56 }\nassert my_solution.minSizeSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [3,5,7,6,5,3,7,7,1,5,3,1,5,6,3,1,6,1,3], \"target\": 20 }\nassert my_solution.minSizeSubarray(**test_input) == 4\n\ntest_input = { \"nums\": [5,5,4,1,2,2,2,3,2,4,2,5], \"target\": 56 }\nassert my_solution.minSizeSubarray(**test_input) == 16\n\ntest_input = { \"nums\": [1,1,1,1,1,1,1,1], \"target\": 22 }\nassert my_solution.minSizeSubarray(**test_input) == 22\n\ntest_input = { \"nums\": [1,2], \"target\": 72 }\nassert my_solution.minSizeSubarray(**test_input) == 48\n\ntest_input = { \"nums\": [4,3,6,6,2,6,1,6,7,5,7,6,1,5,7], \"target\": 82 }\nassert my_solution.minSizeSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [4,1,5,2,3,1,2,4,1,5,3,3,5,2,6,6,5,2,1], \"target\": 63 }\nassert my_solution.minSizeSubarray(**test_input) == 20\n\ntest_input = { \"nums\": [8,2,5,4,1,6,6,6,6,4,4,5,5,9,6,6,9,2], \"target\": 4 }\nassert my_solution.minSizeSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [18,12,13,9,17,11], \"target\": 82 }\nassert my_solution.minSizeSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [13,3,1,5,13,7,12,5], \"target\": 35 }\nassert my_solution.minSizeSubarray(**test_input) == 5\n\ntest_input = { \"nums\": [4,10,12,6,2,2,4,12,6,1,1,2,2,10,6,11,5,4,9], \"target\": 49 }\nassert my_solution.minSizeSubarray(**test_input) == 7\n\ntest_input = { \"nums\": [8], \"target\": 68 }\nassert my_solution.minSizeSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [7,2,6,7,6,4,4,1,6,4,1,7,7,2,2,4,4,4], \"target\": 29 }\nassert my_solution.minSizeSubarray(**test_input) == 6\n\ntest_input = { \"nums\": [4,7,6,12,10,13,7,6,6,1,15,2,4,8,12], \"target\": 43 }\nassert my_solution.minSizeSubarray(**test_input) == 6\n\ntest_input = { \"nums\": [4,10], \"target\": 10 }\nassert my_solution.minSizeSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [4,3,2,4,5,3,7,12,2,2,10], \"target\": 43 }\nassert my_solution.minSizeSubarray(**test_input) == 8\n\ntest_input = { \"nums\": [1,1,1,1,1,1,1,1,1,1,1,1], \"target\": 58 }\nassert my_solution.minSizeSubarray(**test_input) == 58\n\ntest_input = { \"nums\": [1,1,1,1,1], \"target\": 20 }\nassert my_solution.minSizeSubarray(**test_input) == 20\n\ntest_input = { \"nums\": [4,3], \"target\": 23 }\nassert my_solution.minSizeSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [3,2,1,3,2,1,3,1,1,1,2,1,2,1,2,3,3,1], \"target\": 78 }\nassert my_solution.minSizeSubarray(**test_input) == 41\n\ntest_input = { \"nums\": [3,2,4,2,4,2,5,4,5,3,4,4,2,4,4,1], \"target\": 19 }\nassert my_solution.minSizeSubarray(**test_input) == 5\n\ntest_input = { \"nums\": [17], \"target\": 1 }\nassert my_solution.minSizeSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [10,12,1,11,9,5,4,5,1,10,8,12,5,4], \"target\": 82 }\nassert my_solution.minSizeSubarray(**test_input) == 10\n\ntest_input = { \"nums\": [6], \"target\": 44 }\nassert my_solution.minSizeSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [4,6,2,6,3,5,2,5,5,4,3,1,5,4,5,5,4,5,5,6], \"target\": 12 }\nassert my_solution.minSizeSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [14,4,13,12,18,8,4,15,4,14,17,4,2], \"target\": 8 }\nassert my_solution.minSizeSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [4,4,6,5,3,4,1,4,2,6,3], \"target\": 32 }\nassert my_solution.minSizeSubarray(**test_input) == 9\n\ntest_input = { \"nums\": [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], \"target\": 28 }\nassert my_solution.minSizeSubarray(**test_input) == 28\n\ntest_input = { \"nums\": [5,10,1,3,14,7,13,6,5,7,10,3,10,5,8,5,7,5,6,7], \"target\": 25 }\nassert my_solution.minSizeSubarray(**test_input) == 4\n\ntest_input = { \"nums\": [12,3,4,10,5,8,12,7,12,7,5,8,4,8,11,11], \"target\": 48 }\nassert my_solution.minSizeSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [3,11,5,5,3,10,12,12,12,3,10], \"target\": 88 }\nassert my_solution.minSizeSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [8,2,10,5], \"target\": 28 }\nassert my_solution.minSizeSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [3,5,1,4,5,2,5,3,1,2,1,1,1,3,3,3,5], \"target\": 68 }\nassert my_solution.minSizeSubarray(**test_input) == 23\n\ntest_input = { \"nums\": [1,4,1,4,4], \"target\": 21 }\nassert my_solution.minSizeSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [15,8,8,19,8,12,15,3,15,8,10,9], \"target\": 77 }\nassert my_solution.minSizeSubarray(**test_input) == 7\n\ntest_input = { \"nums\": [4,4], \"target\": 80 }\nassert my_solution.minSizeSubarray(**test_input) == 20\n\ntest_input = { \"nums\": [4,9,3,7,5,4,5,1,3,5], \"target\": 69 }\nassert my_solution.minSizeSubarray(**test_input) == 14\n\ntest_input = { \"nums\": [2,8,2,8,1,5,8,9,3,4,6,6,6,1,7,9], \"target\": 93 }\nassert my_solution.minSizeSubarray(**test_input) == 17\n\ntest_input = { \"nums\": [7,11,14,12,3,16,11,9], \"target\": 10 }\nassert my_solution.minSizeSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [2,1,2,1,3,2,1,1,2], \"target\": 17 }\nassert my_solution.minSizeSubarray(**test_input) == 10\n\ntest_input = { \"nums\": [5,20,18,2,8], \"target\": 45 }\nassert my_solution.minSizeSubarray(**test_input) == 4\n\ntest_input = { \"nums\": [2,1,2,1,2,1,1,1,2,2], \"target\": 58 }\nassert my_solution.minSizeSubarray(**test_input) == 38\n\ntest_input = { \"nums\": [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], \"target\": 17 }\nassert my_solution.minSizeSubarray(**test_input) == 17\n\ntest_input = { \"nums\": [18,6,8,17,3,10,14,12,4,13,12,10,5,18,11], \"target\": 95 }\nassert my_solution.minSizeSubarray(**test_input) == 9\n\ntest_input = { \"nums\": [19,12,14], \"target\": 57 }\nassert my_solution.minSizeSubarray(**test_input) == 4\n\ntest_input = { \"nums\": [3,13,14], \"target\": 11 }\nassert my_solution.minSizeSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [17,6,8,7,4,6,6,3,8,1,8,10,18,13,2], \"target\": 32 }\nassert my_solution.minSizeSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [3,12,4,9,5,2,2,9,9,6,9,11,9], \"target\": 41 }\nassert my_solution.minSizeSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [3,14,2,9,5,14,15,4,3,4,17,11], \"target\": 3 }\nassert my_solution.minSizeSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [2,5,3,6,3,6,1,1,5,1], \"target\": 37 }\nassert my_solution.minSizeSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [13,6,4,7,3,6,4,10,13,10,5,4,2,1,7,11,3,3,12], \"target\": 51 }\nassert my_solution.minSizeSubarray(**test_input) == 7\n\ntest_input = { \"nums\": [1,10,9,16,3,10,2,5,1,10], \"target\": 83 }\nassert my_solution.minSizeSubarray(**test_input) == 11\n\ntest_input = { \"nums\": [2,10,13,3,4,19,14,20,11,15,4,3,17,8,2,3,1,13,8], \"target\": 1 }\nassert my_solution.minSizeSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [4,5,5,3,5,4,2,11,5,9,4,6], \"target\": 41 }\nassert my_solution.minSizeSubarray(**test_input) == 7\n\ntest_input = { \"nums\": [2,8,9,6,11,17,3,6,9,7,2,8,9,11,19], \"target\": 39 }\nassert my_solution.minSizeSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [8,13,9,5,8,6,17,16,14,7,10,15,16], \"target\": 8 }\nassert my_solution.minSizeSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [10,20,16,1,11,18,13,6,13,6,9,14,16,12,13,7,19], \"target\": 59 }\nassert my_solution.minSizeSubarray(**test_input) == 5\n\ntest_input = { \"nums\": [1,1,1,1,1,1,1,1,1,1,1,1], \"target\": 6 }\nassert my_solution.minSizeSubarray(**test_input) == 6", "start_time": 1696127400} +{"task_id": "weekly-contest-365-count-visited-nodes-in-a-directed-graph", "url": "https://leetcode.com/problems/count-visited-nodes-in-a-directed-graph", "title": "count-visited-nodes-in-a-directed-graph", "meta": {"questionId": "3140", "questionFrontendId": "2876", "title": "Count Visited Nodes in a Directed Graph", "titleSlug": "count-visited-nodes-in-a-directed-graph", "isPaidOnly": false, "difficulty": "Hard", "likes": 274, "dislikes": 4, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nThere is a directed graph consisting of n nodes numbered from 0 to n - 1 and n directed edges.\n\nYou are given a 0-indexed array edges where edges[i] indicates that there is an edge from node i to node edges[i].\n\nConsider the following process on the graph:\n\n * You start from a node x and keep visiting other nodes through edges until you reach a node that you have already visited before on this same process.\n\nReturn an array answer where answer[i] is the number of different nodes that you will visit if you perform the process starting from node i.\n\nExample 1:\n\n[https://assets.leetcode.com/uploads/2023/08/31/graaphdrawio-1.png]\n\nInput: edges = [1,2,0,0]\nOutput: [3,3,3,4]\nExplanation: We perform the process starting from each node in the following way:\n- Starting from node 0, we visit the nodes 0 -> 1 -> 2 -> 0. The number of different nodes we visit is 3.\n- Starting from node 1, we visit the nodes 1 -> 2 -> 0 -> 1. The number of different nodes we visit is 3.\n- Starting from node 2, we visit the nodes 2 -> 0 -> 1 -> 2. The number of different nodes we visit is 3.\n- Starting from node 3, we visit the nodes 3 -> 0 -> 1 -> 2 -> 0. The number of different nodes we visit is 4.\n\nExample 2:\n\n[https://assets.leetcode.com/uploads/2023/08/31/graaph2drawio.png]\n\nInput: edges = [1,2,3,4,0]\nOutput: [5,5,5,5,5]\nExplanation: Starting from any node we can visit every node in the graph in the process.\n\n\nConstraints:\n\n * n == edges.length\n * 2 <= n <= 105\n * 0 <= edges[i] <= n - 1\n * edges[i] != i\n\"\"\"\nclass Solution:\n def countVisitedNodes(self, edges: List[int]) -> List[int]:\n ", "prompt_sft": "There is a directed graph consisting of n nodes numbered from 0 to n - 1 and n directed edges.\n\nYou are given a 0-indexed array edges where edges[i] indicates that there is an edge from node i to node edges[i].\n\nConsider the following process on the graph:\n\n * You start from a node x and keep visiting other nodes through edges until you reach a node that you have already visited before on this same process.\n\nReturn an array answer where answer[i] is the number of different nodes that you will visit if you perform the process starting from node i.\n\nExample 1:\n\n[https://assets.leetcode.com/uploads/2023/08/31/graaphdrawio-1.png]\n\nInput: edges = [1,2,0,0]\nOutput: [3,3,3,4]\nExplanation: We perform the process starting from each node in the following way:\n- Starting from node 0, we visit the nodes 0 -> 1 -> 2 -> 0. The number of different nodes we visit is 3.\n- Starting from node 1, we visit the nodes 1 -> 2 -> 0 -> 1. The number of different nodes we visit is 3.\n- Starting from node 2, we visit the nodes 2 -> 0 -> 1 -> 2. The number of different nodes we visit is 3.\n- Starting from node 3, we visit the nodes 3 -> 0 -> 1 -> 2 -> 0. The number of different nodes we visit is 4.\n\nExample 2:\n\n[https://assets.leetcode.com/uploads/2023/08/31/graaph2drawio.png]\n\nInput: edges = [1,2,3,4,0]\nOutput: [5,5,5,5,5]\nExplanation: Starting from any node we can visit every node in the graph in the process.\n\n\nConstraints:\n\n * n == edges.length\n * 2 <= n <= 105\n * 0 <= edges[i] <= n - 1\n * edges[i] != i\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def countVisitedNodes(self, edges: List[int]) -> List[int]:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"edges\": [1,2,0,0] }\nassert my_solution.countVisitedNodes(**test_input) == [3,3,3,4]\n\ntest_input = { \"edges\": [1,2,3,4,0] }\nassert my_solution.countVisitedNodes(**test_input) == [5,5,5,5,5]\n\ntest_input = { \"edges\": [3,6,1,0,5,7,4,3] }\nassert my_solution.countVisitedNodes(**test_input) == [2,7,8,2,5,4,6,3]\n\ntest_input = { \"edges\": [7,0,7,0,5,3,3,0] }\nassert my_solution.countVisitedNodes(**test_input) == [2,3,3,3,5,4,4,2]\n\ntest_input = { \"edges\": [6,3,6,1,0,8,0,6,6] }\nassert my_solution.countVisitedNodes(**test_input) == [2,2,3,2,3,4,2,3,3]\n\ntest_input = { \"edges\": [8,17,14,8,14,12,16,11,4,14,19,6,8,8,2,10,2,1,1,18] }\nassert my_solution.countVisitedNodes(**test_input) == [5,2,2,5,3,6,4,6,4,3,5,5,5,5,2,6,3,2,3,4]\n\ntest_input = { \"edges\": [11,9,6,8,3,2,8,11,14,2,3,7,2,2,1] }\nassert my_solution.countVisitedNodes(**test_input) == [3,6,6,7,8,7,6,2,6,6,8,2,7,7,6]\n\ntest_input = { \"edges\": [9,4,4,8,5,2,3,6,5,5] }\nassert my_solution.countVisitedNodes(**test_input) == [5,4,3,5,3,3,6,7,4,4]\n\ntest_input = { \"edges\": [1,0,1,1] }\nassert my_solution.countVisitedNodes(**test_input) == [2,2,3,3]\n\ntest_input = { \"edges\": [4,0,3,2,3] }\nassert my_solution.countVisitedNodes(**test_input) == [4,5,2,2,3]\n\ntest_input = { \"edges\": [7,7,0,9,5,6,10,16,7,4,15,13,2,16,1,7,6] }\nassert my_solution.countVisitedNodes(**test_input) == [6,6,7,9,7,6,5,5,6,8,5,7,8,6,7,5,5]\n\ntest_input = { \"edges\": [2,6,3,1,5,3,5] }\nassert my_solution.countVisitedNodes(**test_input) == [6,4,5,4,5,4,4]\n\ntest_input = { \"edges\": [15,4,13,12,12,2,11,6,14,10,15,3,5,5,2,4] }\nassert my_solution.countVisitedNodes(**test_input) == [7,6,3,5,5,3,7,8,5,8,7,6,4,3,4,6]\n\ntest_input = { \"edges\": [1,5,0,5,2,7,1,2] }\nassert my_solution.countVisitedNodes(**test_input) == [5,5,5,6,6,5,6,5]\n\ntest_input = { \"edges\": [9,6,13,1,11,4,17,9,2,18,15,4,14,15,7,2,18,16,1] }\nassert my_solution.countVisitedNodes(**test_input) == [7,5,3,6,2,3,5,7,4,6,4,2,9,3,8,3,5,5,5]\n\ntest_input = { \"edges\": [18,18,4,6,1,8,14,4,16,11,13,6,10,10,6,18,14,11,4] }\nassert my_solution.countVisitedNodes(**test_input) == [4,3,4,3,3,5,2,4,4,4,2,3,3,2,2,4,3,4,3]\n\ntest_input = { \"edges\": [5,4,1,6,3,10,3,10,11,10,8,1] }\nassert my_solution.countVisitedNodes(**test_input) == [9,4,5,2,3,8,2,8,6,8,7,5]\n\ntest_input = { \"edges\": [8,6,3,1,0,6,8,1,4,7,8] }\nassert my_solution.countVisitedNodes(**test_input) == [3,5,7,6,3,5,4,6,3,7,4]\n\ntest_input = { \"edges\": [9,5,18,15,8,4,3,3,18,5,13,0,1,18,9,6,18,9,14,15] }\nassert my_solution.countVisitedNodes(**test_input) == [7,7,7,3,6,6,3,4,6,6,8,8,8,7,6,3,7,7,6,4]\n\ntest_input = { \"edges\": [5,2,1,0,6,9,10,12,12,2,16,2,9,17,0,4,9,6] }\nassert my_solution.countVisitedNodes(**test_input) == [5,2,2,6,7,4,6,5,5,3,5,3,4,8,6,8,4,7]\n\ntest_input = { \"edges\": [6,4,1,2,3,2,0] }\nassert my_solution.countVisitedNodes(**test_input) == [2,4,4,4,4,5,2]\n\ntest_input = { \"edges\": [1,13,4,12,15,11,1,8,15,10,1,3,0,3,2,2] }\nassert my_solution.countVisitedNodes(**test_input) == [5,5,3,5,3,7,6,5,4,7,6,6,5,5,4,3]\n\ntest_input = { \"edges\": [2,2,0] }\nassert my_solution.countVisitedNodes(**test_input) == [2,3,2]\n\ntest_input = { \"edges\": [11,8,8,11,5,8,9,11,6,8,0,12,9,12] }\nassert my_solution.countVisitedNodes(**test_input) == [6,4,4,6,5,4,3,6,3,3,7,5,4,5]\n\ntest_input = { \"edges\": [2,3,6,8,0,4,8,6,1] }\nassert my_solution.countVisitedNodes(**test_input) == [6,3,5,3,7,8,4,5,3]\n\ntest_input = { \"edges\": [2,7,17,14,3,14,11,12,9,0,15,18,1,18,0,19,11,4,1,0] }\nassert my_solution.countVisitedNodes(**test_input) == [6,3,6,6,6,7,6,3,8,7,9,5,3,5,6,8,6,6,4,7]\n\ntest_input = { \"edges\": [5,17,10,13,16,4,7,10,19,6,15,6,9,0,1,0,12,18,10,16] }\nassert my_solution.countVisitedNodes(**test_input) == [10,13,11,12,10,10,10,10,12,10,10,11,10,11,14,10,10,12,11,11]\n\ntest_input = { \"edges\": [1,2,6,6,1,4,4] }\nassert my_solution.countVisitedNodes(**test_input) == [5,4,4,5,4,5,4]\n\ntest_input = { \"edges\": [2,0,0,2] }\nassert my_solution.countVisitedNodes(**test_input) == [2,3,2,3]\n\ntest_input = { \"edges\": [12,10,5,0,12,8,0,4,3,1,9,4,6] }\nassert my_solution.countVisitedNodes(**test_input) == [3,3,7,4,4,6,3,5,5,3,3,5,3]\n\ntest_input = { \"edges\": [8,4,0,0,8,2,3,8,7] }\nassert my_solution.countVisitedNodes(**test_input) == [3,4,4,4,3,5,5,2,2]\n\ntest_input = { \"edges\": [6,7,1,10,2,10,3,5,10,4,2] }\nassert my_solution.countVisitedNodes(**test_input) == [8,5,5,6,6,5,7,5,6,7,5]\n\ntest_input = { \"edges\": [2,7,5,4,8,7,2,3,0] }\nassert my_solution.countVisitedNodes(**test_input) == [7,8,7,7,7,7,8,7,7]\n\ntest_input = { \"edges\": [2,3,1,1,0,4] }\nassert my_solution.countVisitedNodes(**test_input) == [4,2,3,2,5,6]\n\ntest_input = { \"edges\": [5,2,3,1,3,1] }\nassert my_solution.countVisitedNodes(**test_input) == [5,3,3,3,4,4]\n\ntest_input = { \"edges\": [7,6,12,0,1,9,13,6,9,6,0,0,3,9,12,13,0] }\nassert my_solution.countVisitedNodes(**test_input) == [5,4,8,6,5,4,3,4,4,3,6,6,7,3,8,4,6]\n\ntest_input = { \"edges\": [1,4,9,11,11,11,14,10,11,14,2,0,14,5,10] }\nassert my_solution.countVisitedNodes(**test_input) == [4,4,4,5,4,5,5,5,5,4,4,4,5,6,4]\n\ntest_input = { \"edges\": [4,3,3,1,3] }\nassert my_solution.countVisitedNodes(**test_input) == [4,2,3,2,3]\n\ntest_input = { \"edges\": [7,7,6,8,0,7,8,0,0,10,9] }\nassert my_solution.countVisitedNodes(**test_input) == [2,3,5,4,3,3,4,2,3,2,2]\n\ntest_input = { \"edges\": [16,5,11,9,7,17,16,8,14,5,5,1,0,8,0,16,14,15,19,4] }\nassert my_solution.countVisitedNodes(**test_input) == [3,7,9,8,6,6,4,5,4,7,7,8,4,5,3,4,3,5,8,7]\n\ntest_input = { \"edges\": [1,8,10,6,2,1,8,9,6,12,5,10,3] }\nassert my_solution.countVisitedNodes(**test_input) == [4,3,6,3,7,4,2,6,2,5,5,6,4]\n\ntest_input = { \"edges\": [4,0,1,5,0,2] }\nassert my_solution.countVisitedNodes(**test_input) == [2,3,4,6,2,5]\n\ntest_input = { \"edges\": [9,13,1,2,13,1,0,5,10,8,2,2,3,12] }\nassert my_solution.countVisitedNodes(**test_input) == [9,5,5,5,6,6,10,7,7,8,6,6,5,5]\n\ntest_input = { \"edges\": [12,13,16,11,17,11,2,15,12,14,4,9,3,4,17,3,4,9] }\nassert my_solution.countVisitedNodes(**test_input) == [7,6,6,5,4,5,7,7,7,3,5,4,6,5,3,6,5,3]\n\ntest_input = { \"edges\": [2,0,1] }\nassert my_solution.countVisitedNodes(**test_input) == [3,3,3]\n\ntest_input = { \"edges\": [7,10,15,18,7,1,7,16,11,8,2,13,13,15,16,0,18,5,16] }\nassert my_solution.countVisitedNodes(**test_input) == [4,8,6,3,4,9,4,3,8,9,7,7,7,6,3,5,2,10,2]\n\ntest_input = { \"edges\": [1,2,0] }\nassert my_solution.countVisitedNodes(**test_input) == [3,3,3]\n\ntest_input = { \"edges\": [10,13,4,11,11,6,9,2,7,4,5,7,0,11] }\nassert my_solution.countVisitedNodes(**test_input) == [9,6,4,5,4,7,6,4,5,5,8,4,10,5]\n\ntest_input = { \"edges\": [12,15,15,2,10,1,5,6,1,2,11,13,10,4,2,0,1] }\nassert my_solution.countVisitedNodes(**test_input) == [6,8,8,9,4,9,10,11,9,9,4,4,5,4,9,7,9]\n\ntest_input = { \"edges\": [1,0] }\nassert my_solution.countVisitedNodes(**test_input) == [2,2]\n\ntest_input = { \"edges\": [7,17,3,7,7,12,15,1,14,15,16,3,13,0,3,8,0,11,1] }\nassert my_solution.countVisitedNodes(**test_input) == [6,5,6,5,6,9,9,5,7,9,8,5,8,7,6,8,7,5,6]\n\ntest_input = { \"edges\": [9,4,6,2,8,6,7,4,9,8,0,2,7] }\nassert my_solution.countVisitedNodes(**test_input) == [3,4,6,7,3,6,5,4,2,2,4,7,5]\n\ntest_input = { \"edges\": [13,10,6,12,12,3,4,3,10,12,1,7,8,12,9] }\nassert my_solution.countVisitedNodes(**test_input) == [6,2,7,5,5,6,6,6,3,5,2,7,4,5,6]\n\ntest_input = { \"edges\": [10,3,4,4,5,7,2,9,7,0,5] }\nassert my_solution.countVisitedNodes(**test_input) == [5,8,7,7,6,5,8,5,6,5,5]\n\ntest_input = { \"edges\": [2,4,0,4,2] }\nassert my_solution.countVisitedNodes(**test_input) == [2,4,2,4,3]\n\ntest_input = { \"edges\": [2,2,1] }\nassert my_solution.countVisitedNodes(**test_input) == [3,2,2]\n\ntest_input = { \"edges\": [19,15,1,6,8,15,5,6,4,4,19,13,3,0,15,10,13,5,6,3] }\nassert my_solution.countVisitedNodes(**test_input) == [7,7,8,6,2,6,6,7,2,3,6,9,7,8,7,6,9,7,7,6]\n\ntest_input = { \"edges\": [11,9,5,0,5,3,9,8,1,10,4,4] }\nassert my_solution.countVisitedNodes(**test_input) == [5,8,6,5,5,5,8,10,9,7,6,5]\n\ntest_input = { \"edges\": [13,10,12,11,5,17,0,10,7,16,5,4,9,3,15,5,4,1] }\nassert my_solution.countVisitedNodes(**test_input) == [9,4,9,7,5,4,10,5,6,7,4,6,8,8,6,5,6,4]\n\ntest_input = { \"edges\": [7,0,9,0,7,6,2,0,7,7] }\nassert my_solution.countVisitedNodes(**test_input) == [2,3,4,3,3,6,5,2,3,3]\n\ntest_input = { \"edges\": [1,0,0] }\nassert my_solution.countVisitedNodes(**test_input) == [2,2,3]\n\ntest_input = { \"edges\": [5,9,10,17,12,3,15,5,0,3,15,5,5,15,17,5,13,15,1] }\nassert my_solution.countVisitedNodes(**test_input) == [5,6,6,4,6,4,5,5,6,5,5,5,5,5,5,4,6,4,7]\n\ntest_input = { \"edges\": [1,5,1,8,1,0,1,4,6] }\nassert my_solution.countVisitedNodes(**test_input) == [3,3,4,6,4,3,4,5,5]\n\ntest_input = { \"edges\": [5,3,3,4,1,4] }\nassert my_solution.countVisitedNodes(**test_input) == [5,3,4,3,3,4]\n\ntest_input = { \"edges\": [7,12,12,5,10,11,5,0,3,12,12,9,1,3,7] }\nassert my_solution.countVisitedNodes(**test_input) == [2,2,3,6,4,5,6,2,7,3,3,4,2,7,3]\n\ntest_input = { \"edges\": [3,3,3,1] }\nassert my_solution.countVisitedNodes(**test_input) == [3,2,3,2]\n\ntest_input = { \"edges\": [13,3,15,10,12,7,13,15,3,0,1,5,15,12,10,9] }\nassert my_solution.countVisitedNodes(**test_input) == [5,3,6,3,6,7,6,6,4,5,3,8,5,5,4,5]\n\ntest_input = { \"edges\": [8,9,0,9,0,0,9,0,7,6,5,0] }\nassert my_solution.countVisitedNodes(**test_input) == [3,3,4,3,4,4,2,3,3,2,5,4]\n\ntest_input = { \"edges\": [2,0,7,7,3,3,0,4,5,8] }\nassert my_solution.countVisitedNodes(**test_input) == [5,6,4,3,3,4,6,3,5,6]\n\ntest_input = { \"edges\": [13,8,7,13,10,6,11,13,13,6,8,6,0,10] }\nassert my_solution.countVisitedNodes(**test_input) == [4,4,5,4,4,3,2,4,3,3,3,2,5,3]\n\ntest_input = { \"edges\": [12,14,5,17,7,0,15,18,5,10,6,18,10,11,1,1,18,16,0] }\nassert my_solution.countVisitedNodes(**test_input) == [7,2,9,11,10,8,4,9,9,6,5,9,6,10,2,3,9,10,8]\n\ntest_input = { \"edges\": [8,6,17,7,12,10,13,14,10,10,2,15,11,5,4,13,12,12] }\nassert my_solution.countVisitedNodes(**test_input) == [10,10,8,12,9,8,9,11,9,9,8,8,8,8,10,8,9,8]\n\ntest_input = { \"edges\": [1,0,1,1,1] }\nassert my_solution.countVisitedNodes(**test_input) == [2,2,3,3,3]\n\ntest_input = { \"edges\": [17,16,15,5,11,4,4,10,14,1,17,1,4,3,12,17,14,10] }\nassert my_solution.countVisitedNodes(**test_input) == [3,6,4,8,6,7,7,3,7,7,2,6,6,9,6,3,6,2]\n\ntest_input = { \"edges\": [14,10,16,16,12,13,13,16,13,14,15,14,1,4,13,11,4,7] }\nassert my_solution.countVisitedNodes(**test_input) == [9,8,10,10,8,9,9,10,9,9,8,8,8,8,8,8,9,11]\n\ntest_input = { \"edges\": [2,3,0,1] }\nassert my_solution.countVisitedNodes(**test_input) == [2,2,2,2]\n\ntest_input = { \"edges\": [8,0,11,2,0,12,0,4,11,12,0,7,3] }\nassert my_solution.countVisitedNodes(**test_input) == [5,6,6,7,5,9,6,5,5,9,6,5,8]\n\ntest_input = { \"edges\": [3,0,1,0] }\nassert my_solution.countVisitedNodes(**test_input) == [2,3,4,2]\n\ntest_input = { \"edges\": [1,3,0,1,10,11,2,6,0,5,1,4] }\nassert my_solution.countVisitedNodes(**test_input) == [3,2,4,2,4,6,5,6,4,7,3,5]\n\ntest_input = { \"edges\": [1,16,10,6,15,10,7,9,2,15,5,6,13,1,0,16,13] }\nassert my_solution.countVisitedNodes(**test_input) == [4,3,3,8,5,2,7,6,4,5,2,8,4,3,5,4,3]\n\ntest_input = { \"edges\": [4,15,10,11,0,7,9,10,1,2,9,12,5,10,6,13] }\nassert my_solution.countVisitedNodes(**test_input) == [2,6,3,8,2,5,4,4,7,3,3,7,6,4,5,5]\n\ntest_input = { \"edges\": [4,9,8,9,1,4,7,11,5,6,4,6,4,4,2] }\nassert my_solution.countVisitedNodes(**test_input) == [7,5,9,5,6,7,3,3,8,4,7,3,7,7,10]\n\ntest_input = { \"edges\": [16,14,1,6,6,1,1,15,16,16,13,14,9,3,3,11,10] }\nassert my_solution.countVisitedNodes(**test_input) == [8,4,5,4,5,5,4,7,8,8,6,5,9,5,4,6,7]\n\ntest_input = { \"edges\": [6,11,15,7,5,8,11,5,14,2,6,0,8,5,13,5] }\nassert my_solution.countVisitedNodes(**test_input) == [3,4,6,6,5,4,3,5,4,7,4,3,5,4,4,5]\n\ntest_input = { \"edges\": [14,17,11,8,5,4,10,17,3,3,2,17,13,1,17,5,5,0] }\nassert my_solution.countVisitedNodes(**test_input) == [3,4,5,2,2,2,7,4,2,3,6,4,6,5,3,3,3,3]\n\ntest_input = { \"edges\": [1,6,8,6,2,4,2,5,9,3] }\nassert my_solution.countVisitedNodes(**test_input) == [7,6,5,5,6,7,5,8,5,5]\n\ntest_input = { \"edges\": [1,5,4,1,5,3,4,0] }\nassert my_solution.countVisitedNodes(**test_input) == [4,3,5,3,4,3,5,5]\n\ntest_input = { \"edges\": [17,4,3,7,3,1,15,15,13,18,4,14,1,10,13,1,0,15,16] }\nassert my_solution.countVisitedNodes(**test_input) == [7,5,6,5,5,6,6,5,8,10,6,9,6,7,8,5,8,6,9]\n\ntest_input = { \"edges\": [12,2,6,6,7,8,8,13,1,12,15,1,8,3,8,2,6] }\nassert my_solution.countVisitedNodes(**test_input) == [6,4,4,5,8,5,4,7,4,6,6,5,5,6,5,5,5]\n\ntest_input = { \"edges\": [3,0,0,2] }\nassert my_solution.countVisitedNodes(**test_input) == [3,4,3,3]\n\ntest_input = { \"edges\": [5,0,1,1,2,0] }\nassert my_solution.countVisitedNodes(**test_input) == [2,3,4,4,5,2]\n\ntest_input = { \"edges\": [16,2,13,6,7,10,1,1,7,14,7,13,9,16,4,8,15] }\nassert my_solution.countVisitedNodes(**test_input) == [8,7,7,9,8,9,8,7,7,10,8,8,11,7,9,7,7]\n\ntest_input = { \"edges\": [14,5,0,16,7,15,1,18,18,6,11,15,0,2,3,0,17,4,12] }\nassert my_solution.countVisitedNodes(**test_input) == [9,12,10,9,9,11,13,9,10,14,12,11,9,11,9,10,9,9,9]\n\ntest_input = { \"edges\": [7,8,1,9,7,10,1,4,2,0,9] }\nassert my_solution.countVisitedNodes(**test_input) == [3,3,3,5,2,6,4,2,3,4,5]\n\ntest_input = { \"edges\": [5,3,6,2,1,3,1,3] }\nassert my_solution.countVisitedNodes(**test_input) == [6,4,4,4,5,5,4,5]\n\ntest_input = { \"edges\": [8,14,5,13,6,9,8,11,9,4,11,14,5,12,10,10,12] }\nassert my_solution.countVisitedNodes(**test_input) == [5,4,6,8,4,5,4,4,4,4,3,3,6,7,3,4,7]\n\ntest_input = { \"edges\": [6,13,11,11,6,3,3,6,1,12,4,7,14,11,0,10] }\nassert my_solution.countVisitedNodes(**test_input) == [5,6,5,4,5,5,4,4,7,8,6,4,7,5,6,7]\n\ntest_input = { \"edges\": [12,8,6,1,5,0,1,1,11,0,12,2,0] }\nassert my_solution.countVisitedNodes(**test_input) == [2,5,5,6,4,3,5,6,5,3,3,5,2]\n\ntest_input = { \"edges\": [8,2,7,17,5,1,5,17,10,2,12,3,1,0,11,3,7,4] }\nassert my_solution.countVisitedNodes(**test_input) == [10,6,6,7,6,6,7,6,9,7,8,8,7,11,9,8,7,6]\n\ntest_input = { \"edges\": [4,2,4,2,3] }\nassert my_solution.countVisitedNodes(**test_input) == [4,4,3,3,3]", "start_time": 1696127400} +{"task_id": "biweekly-contest-114-minimum-operations-to-collect-elements", "url": "https://leetcode.com/problems/minimum-operations-to-collect-elements", "title": "minimum-operations-to-collect-elements", "meta": {"questionId": "3044", "questionFrontendId": "2869", "title": "Minimum Operations to Collect Elements", "titleSlug": "minimum-operations-to-collect-elements", "isPaidOnly": false, "difficulty": "Easy", "likes": 130, "dislikes": 10, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given an array nums of positive integers and an integer k.\n\nIn one operation, you can remove the last element of the array and add it to your collection.\n\nReturn the minimum number of operations needed to collect elements 1, 2, ..., k.\n\nExample 1:\n\nInput: nums = [3,1,5,4,2], k = 2\nOutput: 4\nExplanation: After 4 operations, we collect elements 2, 4, 5, and 1, in this order. Our collection contains elements 1 and 2. Hence, the answer is 4.\n\nExample 2:\n\nInput: nums = [3,1,5,4,2], k = 5\nOutput: 5\nExplanation: After 5 operations, we collect elements 2, 4, 5, 1, and 3, in this order. Our collection contains elements 1 through 5. Hence, the answer is 5.\n\nExample 3:\n\nInput: nums = [3,2,5,3,1], k = 3\nOutput: 4\nExplanation: After 4 operations, we collect elements 1, 3, 5, and 2, in this order. Our collection contains elements 1 through 3. Hence, the answer is 4.\n\n\nConstraints:\n\n * 1 <= nums.length <= 50\n * 1 <= nums[i] <= nums.length\n * 1 <= k <= nums.length\n * The input is generated such that you can collect elements 1, 2, ..., k.\n\"\"\"\nclass Solution:\n def minOperations(self, nums: List[int], k: int) -> int:\n ", "prompt_sft": "You are given an array nums of positive integers and an integer k.\n\nIn one operation, you can remove the last element of the array and add it to your collection.\n\nReturn the minimum number of operations needed to collect elements 1, 2, ..., k.\n\nExample 1:\n\nInput: nums = [3,1,5,4,2], k = 2\nOutput: 4\nExplanation: After 4 operations, we collect elements 2, 4, 5, and 1, in this order. Our collection contains elements 1 and 2. Hence, the answer is 4.\n\nExample 2:\n\nInput: nums = [3,1,5,4,2], k = 5\nOutput: 5\nExplanation: After 5 operations, we collect elements 2, 4, 5, 1, and 3, in this order. Our collection contains elements 1 through 5. Hence, the answer is 5.\n\nExample 3:\n\nInput: nums = [3,2,5,3,1], k = 3\nOutput: 4\nExplanation: After 4 operations, we collect elements 1, 3, 5, and 2, in this order. Our collection contains elements 1 through 3. Hence, the answer is 4.\n\n\nConstraints:\n\n * 1 <= nums.length <= 50\n * 1 <= nums[i] <= nums.length\n * 1 <= k <= nums.length\n * The input is generated such that you can collect elements 1, 2, ..., k.\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def minOperations(self, nums: List[int], k: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [3,1,5,4,2], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [3,1,5,4,2], \"k\": 5 }\nassert my_solution.minOperations(**test_input) == 5\n\ntest_input = { \"nums\": [3,2,5,3,1], \"k\": 3 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [1], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,1], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,2], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,2], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [2,1], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [2,1], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,1], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,2], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,2], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,3], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,2,1], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,1], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,2,2], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,2], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,3], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,3], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,3], \"k\": 3 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,3,1], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,3,2], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,3,2], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,3,2], \"k\": 3 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,3,3], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [2,1,1], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [2,1,1], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [2,1,2], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [2,1,2], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [2,1,3], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [2,1,3], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [2,1,3], \"k\": 3 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [2,2,1], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [2,2,1], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [2,3,1], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [2,3,1], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [2,3,1], \"k\": 3 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [3,1,1], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [3,1,2], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [3,1,2], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [3,1,2], \"k\": 3 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [3,1,3], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [3,2,1], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [3,2,1], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [3,2,1], \"k\": 3 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [3,3,1], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,1,1], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,1,2], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,1,2], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,1,3], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,1,4], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,2,1], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,2,1], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,2,2], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,2,2], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,2,3], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,2,3], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,2,3], \"k\": 3 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,2,4], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,2,4], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,3,1], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,3,2], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,3,2], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,3,2], \"k\": 3 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,3,3], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,3,4], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,4,1], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,4,2], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,4,2], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,4,3], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,4,4], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,1,1], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,1,1], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,1,2], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,2,1,2], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,2,1,3], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,2,1,3], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,1,3], \"k\": 3 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,1,4], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,2,1,4], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,2,1], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,2,1], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,2,2,2], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,2,2], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,2,3], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,2,3], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,2,3], \"k\": 3 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,2,4], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,2,4], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,3,1], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,3,1], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,3,1], \"k\": 3 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,3,2], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,3,2], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,3,2], \"k\": 3 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,3,3], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,3,3], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,3,3], \"k\": 3 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,3,4], \"k\": 1 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,3,4], \"k\": 2 }\nassert my_solution.minOperations(**test_input) == 4", "start_time": 1696084200} +{"task_id": "biweekly-contest-114-minimum-number-of-operations-to-make-array-empty", "url": "https://leetcode.com/problems/minimum-number-of-operations-to-make-array-empty", "title": "minimum-number-of-operations-to-make-array-empty", "meta": {"questionId": "3094", "questionFrontendId": "2870", "title": "Minimum Number of Operations to Make Array Empty", "titleSlug": "minimum-number-of-operations-to-make-array-empty", "isPaidOnly": false, "difficulty": "Medium", "likes": 147, "dislikes": 5, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed array nums consisting of positive integers.\n\nThere are two types of operations that you can apply on the array any number of times:\n\n * Choose two elements with equal values and delete them from the array.\n * Choose three elements with equal values and delete them from the array.\n\nReturn the minimum number of operations required to make the array empty, or -1 if it is not possible.\n\nExample 1:\n\nInput: nums = [2,3,3,2,2,4,2,3,4]\nOutput: 4\nExplanation: We can apply the following operations to make the array empty:\n- Apply the first operation on the elements at indices 0 and 3. The resulting array is nums = [3,3,2,4,2,3,4].\n- Apply the first operation on the elements at indices 2 and 4. The resulting array is nums = [3,3,4,3,4].\n- Apply the second operation on the elements at indices 0, 1, and 3. The resulting array is nums = [4,4].\n- Apply the first operation on the elements at indices 0 and 1. The resulting array is nums = [].\nIt can be shown that we cannot make the array empty in less than 4 operations.\n\nExample 2:\n\nInput: nums = [2,1,2,2,3,3]\nOutput: -1\nExplanation: It is impossible to empty the array.\n\n\nConstraints:\n\n * 2 <= nums.length <= 105\n * 1 <= nums[i] <= 106\n\"\"\"\nclass Solution:\n def minOperations(self, nums: List[int]) -> int:\n ", "prompt_sft": "You are given a 0-indexed array nums consisting of positive integers.\n\nThere are two types of operations that you can apply on the array any number of times:\n\n * Choose two elements with equal values and delete them from the array.\n * Choose three elements with equal values and delete them from the array.\n\nReturn the minimum number of operations required to make the array empty, or -1 if it is not possible.\n\nExample 1:\n\nInput: nums = [2,3,3,2,2,4,2,3,4]\nOutput: 4\nExplanation: We can apply the following operations to make the array empty:\n- Apply the first operation on the elements at indices 0 and 3. The resulting array is nums = [3,3,2,4,2,3,4].\n- Apply the first operation on the elements at indices 2 and 4. The resulting array is nums = [3,3,4,3,4].\n- Apply the second operation on the elements at indices 0, 1, and 3. The resulting array is nums = [4,4].\n- Apply the first operation on the elements at indices 0 and 1. The resulting array is nums = [].\nIt can be shown that we cannot make the array empty in less than 4 operations.\n\nExample 2:\n\nInput: nums = [2,1,2,2,3,3]\nOutput: -1\nExplanation: It is impossible to empty the array.\n\n\nConstraints:\n\n * 2 <= nums.length <= 105\n * 1 <= nums[i] <= 106\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def minOperations(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [2,3,3,2,2,4,2,3,4] }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [2,1,2,2,3,3] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [3,3] }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [14,12,14,14,12,14,14,12,12,12,12,14,14,12,14,14,14,12,12] }\nassert my_solution.minOperations(**test_input) == 7\n\ntest_input = { \"nums\": [2,2,2,2,2,2,2,2,2] }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [15,3,3,15,15,13,8,15,6,15,3,1,8,8,15] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [19,19,19,19,19,19,19,19,19,19,19,19,19] }\nassert my_solution.minOperations(**test_input) == 5\n\ntest_input = { \"nums\": [13,7,13,7,13,7,13,13,7] }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [5,5] }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [3,3,3,3,3,3,3,3,3,3,3,3,3,3,3] }\nassert my_solution.minOperations(**test_input) == 5\n\ntest_input = { \"nums\": [3,14,3,14,3,14,14,3,3,14,14,14,3,14,14,3,14,14,14,3] }\nassert my_solution.minOperations(**test_input) == 7\n\ntest_input = { \"nums\": [16,16,16,19,16,3,16,8,16,16,16,19,3,16,16] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [11,11,11,11,19,11,11,11,11,11,19,11,11,11,11,11,19] }\nassert my_solution.minOperations(**test_input) == 6\n\ntest_input = { \"nums\": [1,1,1,5,1,5,1,1,1,1,1,1,1] }\nassert my_solution.minOperations(**test_input) == 5\n\ntest_input = { \"nums\": [16,16,16,3,16,16,3] }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [14,4,4,19,19] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [1,14,1,1,1] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [3,10,11,3,3,11,3,3,3,3,3,3,3,3,10,3,3,3] }\nassert my_solution.minOperations(**test_input) == 7\n\ntest_input = { \"nums\": [3,8,8,8,8,3,8,8,8,8,8,8,8,8] }\nassert my_solution.minOperations(**test_input) == 5\n\ntest_input = { \"nums\": [9,9,9] }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [6,6,6,6,6,8,8,8,8,6,8,6,15,15,6,15,6,6] }\nassert my_solution.minOperations(**test_input) == 7\n\ntest_input = { \"nums\": [9,19,19,19,9,9,19,19,19,9,9,19,9,19,19,19] }\nassert my_solution.minOperations(**test_input) == 6\n\ntest_input = { \"nums\": [9,4,9,20,20,4,20] }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [6,9,18,16,18,1,9,1,1,1,1,16,1,6,1,1,9,6] }\nassert my_solution.minOperations(**test_input) == 7\n\ntest_input = { \"nums\": [11,18,11,18,11,18,11] }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [20,20,20,20,20] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [12,7,7] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [10,7,9,9,10,9,9,10,10,9,10,9,10,10] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [9,9,9,8,9,9,9,9,2,9,9,9,9,9] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [5,5,18,1,5,5] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [13,13,16,4,16,13,2,16,16,16,2,16,6,16,13,18,9] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [8,8,8,8,8,8,8,8,8,7,8,8,8,8,8,7,8] }\nassert my_solution.minOperations(**test_input) == 6\n\ntest_input = { \"nums\": [20,20,19,19,20,19,20,20,20,19,20,20,20,20,20,20,20,20,20] }\nassert my_solution.minOperations(**test_input) == 7\n\ntest_input = { \"nums\": [4,4,20,20,4,20,1,4,4,4,4,4,4,4,20,4,4] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [16,17,17,8,17,17,16,8,17,16,17] }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [10,10,10,9,10,10,10,9,10,18,10,4,20,2,10,10] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [11,20,20,11,11,20,14,20,11,11,20,1] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [14,14,14,14,15,20,15] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [17,7,17,5,17,17,17,7,17,17,17,17,5,17,17,7,5] }\nassert my_solution.minOperations(**test_input) == 6\n\ntest_input = { \"nums\": [4,4,4,4,4,4,4,4,4] }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [17,17] }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [15,2,15,2,8,15,15,15,15,15,15,8,2] }\nassert my_solution.minOperations(**test_input) == 5\n\ntest_input = { \"nums\": [1,12,12,1,1,1,1,12,1] }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [12,4,9,10,17,12,5,17,4,12,12,12,4,10,4] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [7,7,7,7,7,7,7,16,7,7,7,16,7,16,7,16,16,16,16,7] }\nassert my_solution.minOperations(**test_input) == 8\n\ntest_input = { \"nums\": [20,20,20,20,19] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [13,13,13,13,13,13,13,13] }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [15,12,18,18,15,15,15,12,12,12,12,12,12,15,18] }\nassert my_solution.minOperations(**test_input) == 6\n\ntest_input = { \"nums\": [14,14,14,1] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [2,2,2,2,2,2,8,2,8,2,2,2,2] }\nassert my_solution.minOperations(**test_input) == 5\n\ntest_input = { \"nums\": [10,16,6,6,10,6] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [18,17,3,18,6,13,3,6,14,6,15,3] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [15,15] }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [9,9,9,9,9,9,9,9,9,9,9] }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [11,4,4,18,11,12,18,18,12,4,4,12,4] }\nassert my_solution.minOperations(**test_input) == 5\n\ntest_input = { \"nums\": [2,5,20,20,5,20,20,16,20,20,20,20,20,20,3,20,20,20] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [12,13,13,13,12,13,13,13,13,13,11,13,13,13] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,1,1] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [10,10,10,10,3,10,10,3,10] }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [7,14,7,7,2,2,7] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [1,10,1,10,1] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [11,11,11,11,11,11,11,11,11,11] }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18] }\nassert my_solution.minOperations(**test_input) == 7\n\ntest_input = { \"nums\": [13,13,13,13,13,13,13] }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [19,19,19,19,18,19,15,7,19,19,15,5] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [2,12,12,12,17,12,12,12,12,12,12,12,12,12,12] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [19,16,19,19,16,16,16,16] }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [15,15,15,15,15,15,11,13,15,15,11,15,13,15,11,13] }\nassert my_solution.minOperations(**test_input) == 6\n\ntest_input = { \"nums\": [15,16,16,15,16] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [9,7,14,9,14,7,7,9,9,9,9,9,9,14,14] }\nassert my_solution.minOperations(**test_input) == 6\n\ntest_input = { \"nums\": [12,16,5,5,7,10,2,16,12,7,2,12,5,16,2,11] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11] }\nassert my_solution.minOperations(**test_input) == 6\n\ntest_input = { \"nums\": [18,13,13,18,18,13,13,18,13,13] }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [4,4,8,10,8,10,19,19,19,19,8,8,19,4] }\nassert my_solution.minOperations(**test_input) == 6\n\ntest_input = { \"nums\": [1,18,14,16,14] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [7,7,7,7,3,7,7,3,7,7] }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [13,13] }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [6,11,6,8,6,13,17,14] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [10,2,2,10] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [19,17,17,17,17,17,17,17,19,19,19,17,19,17] }\nassert my_solution.minOperations(**test_input) == 5\n\ntest_input = { \"nums\": [4,16,12,7,16,16,16] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [11,11,11,11,11,11,11,11,11,11,11,11,11,11,11] }\nassert my_solution.minOperations(**test_input) == 5\n\ntest_input = { \"nums\": [6,6,6,13,6,18,13,18,5,18,12,3,12,12,18,6,18,3,18,6] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [4,4,3,3,4,4] }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [11,11,11,11,9,11,9,9,11,11,9,9,11,11,9] }\nassert my_solution.minOperations(**test_input) == 5\n\ntest_input = { \"nums\": [16,16] }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [4,4,4,4,4,4,4,4,4,4,4,4,4,4] }\nassert my_solution.minOperations(**test_input) == 5\n\ntest_input = { \"nums\": [17,16,16,17,16,16,16] }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [10,18,10,10] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [8,8] }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [8,6,6,6,8,8,6,8,8,6,8,6,8,8,6,6,6,8] }\nassert my_solution.minOperations(**test_input) == 6\n\ntest_input = { \"nums\": [15,14,20,15,20,14,14,14,20,14,20,20] }\nassert my_solution.minOperations(**test_input) == 5\n\ntest_input = { \"nums\": [19,3,3,3,3,3,3,15,17,3,3,18,10,17,17,15,17,3,3] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,16,2,16,1,2,2,2,2,2,1,2,2,2,16] }\nassert my_solution.minOperations(**test_input) == 6\n\ntest_input = { \"nums\": [1,1,4,4,4] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1] }\nassert my_solution.minOperations(**test_input) == 7\n\ntest_input = { \"nums\": [16,18,18,20] }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [2,2,2,20,15,2,20,15,2,15] }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [16,16,16,16,16] }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,14,14,14,14,1,14,14,1,14,14,14,14,1,14,14,1,14] }\nassert my_solution.minOperations(**test_input) == 7", "start_time": 1696084200} +{"task_id": "biweekly-contest-114-split-array-into-maximum-number-of-subarrays", "url": "https://leetcode.com/problems/split-array-into-maximum-number-of-subarrays", "title": "split-array-into-maximum-number-of-subarrays", "meta": {"questionId": "3080", "questionFrontendId": "2871", "title": "Split Array Into Maximum Number of Subarrays", "titleSlug": "split-array-into-maximum-number-of-subarrays", "isPaidOnly": false, "difficulty": "Medium", "likes": 188, "dislikes": 24, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given an array nums consisting of non-negative integers.\n\nWe define the score of subarray nums[l..r] such that l <= r as nums[l] AND nums[l + 1] AND ... AND nums[r] where AND is the bitwise AND operation.\n\nConsider splitting the array into one or more subarrays such that the following conditions are satisfied:\n\n * Each element of the array belongs to exactly one subarray.\n * The sum of scores of the subarrays is the minimum possible.\n\nReturn the maximum number of subarrays in a split that satisfies the conditions above.\n\nA subarray is a contiguous part of an array.\n\nExample 1:\n\nInput: nums = [1,0,2,0,1,2]\nOutput: 3\nExplanation: We can split the array into the following subarrays:\n- [1,0]. The score of this subarray is 1 AND 0 = 0.\n- [2,0]. The score of this subarray is 2 AND 0 = 0.\n- [1,2]. The score of this subarray is 1 AND 2 = 0.\nThe sum of scores is 0 + 0 + 0 = 0, which is the minimum possible score that we can obtain.\nIt can be shown that we cannot split the array into more than 3 subarrays with a total score of 0. So we return 3.\n\nExample 2:\n\nInput: nums = [5,7,1,3]\nOutput: 1\nExplanation: We can split the array into one subarray: [5,7,1,3] with a score of 1, which is the minimum possible score that we can obtain.\nIt can be shown that we cannot split the array into more than 1 subarray with a total score of 1. So we return 1.\n\n\nConstraints:\n\n * 1 <= nums.length <= 105\n * 0 <= nums[i] <= 106\n\"\"\"\nclass Solution:\n def maxSubarrays(self, nums: List[int]) -> int:\n ", "prompt_sft": "You are given an array nums consisting of non-negative integers.\n\nWe define the score of subarray nums[l..r] such that l <= r as nums[l] AND nums[l + 1] AND ... AND nums[r] where AND is the bitwise AND operation.\n\nConsider splitting the array into one or more subarrays such that the following conditions are satisfied:\n\n * Each element of the array belongs to exactly one subarray.\n * The sum of scores of the subarrays is the minimum possible.\n\nReturn the maximum number of subarrays in a split that satisfies the conditions above.\n\nA subarray is a contiguous part of an array.\n\nExample 1:\n\nInput: nums = [1,0,2,0,1,2]\nOutput: 3\nExplanation: We can split the array into the following subarrays:\n- [1,0]. The score of this subarray is 1 AND 0 = 0.\n- [2,0]. The score of this subarray is 2 AND 0 = 0.\n- [1,2]. The score of this subarray is 1 AND 2 = 0.\nThe sum of scores is 0 + 0 + 0 = 0, which is the minimum possible score that we can obtain.\nIt can be shown that we cannot split the array into more than 3 subarrays with a total score of 0. So we return 3.\n\nExample 2:\n\nInput: nums = [5,7,1,3]\nOutput: 1\nExplanation: We can split the array into one subarray: [5,7,1,3] with a score of 1, which is the minimum possible score that we can obtain.\nIt can be shown that we cannot split the array into more than 1 subarray with a total score of 1. So we return 1.\n\n\nConstraints:\n\n * 1 <= nums.length <= 105\n * 0 <= nums[i] <= 106\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def maxSubarrays(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,0,2,0,1,2] }\nassert my_solution.maxSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [5,7,1,3] }\nassert my_solution.maxSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [1,0,2,1] }\nassert my_solution.maxSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [0] }\nassert my_solution.maxSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [0,0] }\nassert my_solution.maxSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [100000] }\nassert my_solution.maxSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,2,1] }\nassert my_solution.maxSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [30,18,19,20,11,21,12,22,26] }\nassert my_solution.maxSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [0,8,0,0,0,23] }\nassert my_solution.maxSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [8,10,23,26,21,28,21,14,21,14,9,16,24,29,7,26] }\nassert my_solution.maxSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [18,12,16,28,7,15,24,7,8,26,22,6,23,7,17,1,16] }\nassert my_solution.maxSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [22] }\nassert my_solution.maxSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [15,24,20,28,11,16,0,0,0,22,7,18] }\nassert my_solution.maxSubarrays(**test_input) == 5\n\ntest_input = { \"nums\": [0,0,27] }\nassert my_solution.maxSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [18,7,20,10,0,14,0,28,7,0,0,9,12,0] }\nassert my_solution.maxSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [0,29,16,0,6,17] }\nassert my_solution.maxSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [4,7,13,0,23,6,4] }\nassert my_solution.maxSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [4,27] }\nassert my_solution.maxSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [29,5,0,25,0,15,19,24,20,0,23] }\nassert my_solution.maxSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [24,6] }\nassert my_solution.maxSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [13,20,16,16,27,0,7,18,3,0,23,16,25,0,5,1,4] }\nassert my_solution.maxSubarrays(**test_input) == 5\n\ntest_input = { \"nums\": [0,0,30,20,6,13] }\nassert my_solution.maxSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [21,24,8,8,20,12,24,28,17,9,17] }\nassert my_solution.maxSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [0,0,18,0,0,4,5,25,0,0,0,30,0,18,0,0,12,21,21,18] }\nassert my_solution.maxSubarrays(**test_input) == 12\n\ntest_input = { \"nums\": [12,3,0,27,23,0,29,18,0,0,0,20,29,0,2,0,17,10,0,0] }\nassert my_solution.maxSubarrays(**test_input) == 11\n\ntest_input = { \"nums\": [26,28,7,14,24,15,1,16,5,24,4,10,24] }\nassert my_solution.maxSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [30,11,0,9,15,0,0,0] }\nassert my_solution.maxSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [16,18,14,6,25,30,7,0,22,0,15,0] }\nassert my_solution.maxSubarrays(**test_input) == 5\n\ntest_input = { \"nums\": [16,12,6,21,26,25,2,0,6,0,13] }\nassert my_solution.maxSubarrays(**test_input) == 5\n\ntest_input = { \"nums\": [13,1,13,18,2,15,15,27,3,3,14,12,23,8,29,10,29,15,10] }\nassert my_solution.maxSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [0,29,0,28,20,0,21,8,0,0,26,8,0,0,8,12] }\nassert my_solution.maxSubarrays(**test_input) == 8\n\ntest_input = { \"nums\": [0,18,0,0,0,22,0,15] }\nassert my_solution.maxSubarrays(**test_input) == 5\n\ntest_input = { \"nums\": [0,30,26] }\nassert my_solution.maxSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [0,1,3,29,16,0,0,0,11] }\nassert my_solution.maxSubarrays(**test_input) == 5\n\ntest_input = { \"nums\": [0,10,11,14,0,19,1,0,28,10,27,27,25,17,0,25,19] }\nassert my_solution.maxSubarrays(**test_input) == 5\n\ntest_input = { \"nums\": [18,4,0,6,0,10,23,3,26,0] }\nassert my_solution.maxSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [11,22,22,22,18,15,8,8,19,12,20,11] }\nassert my_solution.maxSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [0,23,0,0,0,17,0,0] }\nassert my_solution.maxSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [0,23,0,14,4,5,23,23,8,8,15,0,0,13,6,26,0] }\nassert my_solution.maxSubarrays(**test_input) == 7\n\ntest_input = { \"nums\": [0,3,0,16,15,0,1,0,24,16,27,0,23,15,0,13,0,0] }\nassert my_solution.maxSubarrays(**test_input) == 9\n\ntest_input = { \"nums\": [12,0,16,0,0,0,29,18] }\nassert my_solution.maxSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [0,27,15,13] }\nassert my_solution.maxSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [15,10,0,2,0,3,8,0,0,26,25,27,0,0,0,28,0,10,27,3] }\nassert my_solution.maxSubarrays(**test_input) == 9\n\ntest_input = { \"nums\": [11,10,12,6,15,25,17,21,22] }\nassert my_solution.maxSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [2,19,13] }\nassert my_solution.maxSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [27,4] }\nassert my_solution.maxSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [0,0,12,0,7,0,18,26,9,29,0,4,30,21,0,1] }\nassert my_solution.maxSubarrays(**test_input) == 7\n\ntest_input = { \"nums\": [6,8,0,0,25,0,30,18,18,0] }\nassert my_solution.maxSubarrays(**test_input) == 5\n\ntest_input = { \"nums\": [21,5,18,18,18,0,0,17,0] }\nassert my_solution.maxSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [25,29,23,27] }\nassert my_solution.maxSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [28,28,0,16,21,27,12,3,10,0,19,0,0] }\nassert my_solution.maxSubarrays(**test_input) == 5\n\ntest_input = { \"nums\": [9,2,22,14,17,3,21,1,29,3,30,13,16,17,25,26,17] }\nassert my_solution.maxSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [0,9,4,25,21,0,25,11,13,9,0,0,19,0,16,8,17,26,0,0] }\nassert my_solution.maxSubarrays(**test_input) == 9\n\ntest_input = { \"nums\": [11,0,0,2,3,0,9,26,0,0,25,7,1,12,16,14] }\nassert my_solution.maxSubarrays(**test_input) == 7\n\ntest_input = { \"nums\": [7,11,27,13,23,16,13,5,27,5,16] }\nassert my_solution.maxSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [18] }\nassert my_solution.maxSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [20,19,2,20,26,1,17,6,23,25,7,14,16,8] }\nassert my_solution.maxSubarrays(**test_input) == 5\n\ntest_input = { \"nums\": [28,0,29,9,0,11,13,22,10,16,21,30,18,19,0,0,0] }\nassert my_solution.maxSubarrays(**test_input) == 7\n\ntest_input = { \"nums\": [20,26,0,0,0,11,30] }\nassert my_solution.maxSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [16,12,0,2,15,30,0,16,7,25] }\nassert my_solution.maxSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [0,7,16,17,29,0,18,0,14,21,17,2,28,7,26,0,14] }\nassert my_solution.maxSubarrays(**test_input) == 7\n\ntest_input = { \"nums\": [29,0,19,23,13] }\nassert my_solution.maxSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [0,13,1,12,18,24,11,26,7] }\nassert my_solution.maxSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [7,26,28,12,24,10,11,26,19,29,1,26] }\nassert my_solution.maxSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [28,15,24,9,0] }\nassert my_solution.maxSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [22,6,21,16,24,7,18,25,25,26,15,10,26,22,23,15] }\nassert my_solution.maxSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [0,23,0,1,26,5,18,12,25,23,5,19] }\nassert my_solution.maxSubarrays(**test_input) == 5\n\ntest_input = { \"nums\": [16,19,0,0] }\nassert my_solution.maxSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [13] }\nassert my_solution.maxSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [8,9] }\nassert my_solution.maxSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [0,0,0,11,0,24,8,0,0,17,21,7,0,25,25] }\nassert my_solution.maxSubarrays(**test_input) == 7\n\ntest_input = { \"nums\": [0,0,10,0,0,30,5,0] }\nassert my_solution.maxSubarrays(**test_input) == 5\n\ntest_input = { \"nums\": [29,22,30,22,19,26] }\nassert my_solution.maxSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [17,15,14,24,30,14,25,28,10,11] }\nassert my_solution.maxSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [0,0,13,2,12,2,27] }\nassert my_solution.maxSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [0,18,9,0,20,0,30,22,0] }\nassert my_solution.maxSubarrays(**test_input) == 5\n\ntest_input = { \"nums\": [2,6,23,0,0,6,12,22,0,19,18,0,0,14,19,3,11,28,0,17] }\nassert my_solution.maxSubarrays(**test_input) == 7\n\ntest_input = { \"nums\": [16,12,7] }\nassert my_solution.maxSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [0,22,0,0,0,26,7] }\nassert my_solution.maxSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [0,19,5,25,0,0,4,0,0,1,0,10,25,2,3] }\nassert my_solution.maxSubarrays(**test_input) == 7\n\ntest_input = { \"nums\": [7,8,18,14,4,6,22,22,7] }\nassert my_solution.maxSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [8,9,13,0,0,20] }\nassert my_solution.maxSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [29,20,13,11,19,27,20,4,24,20,10,21,18,26,3,23,15,18,23,25] }\nassert my_solution.maxSubarrays(**test_input) == 5\n\ntest_input = { \"nums\": [25,0,18,13,22,5,0,0] }\nassert my_solution.maxSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [9,3,0,2,18,11,15,1,10,0,0,16,0,11] }\nassert my_solution.maxSubarrays(**test_input) == 5\n\ntest_input = { \"nums\": [9,0,0,11,14,0,23,0] }\nassert my_solution.maxSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [6,3,22,28,0,0,25,2,23,0,0,23,15,0] }\nassert my_solution.maxSubarrays(**test_input) == 7\n\ntest_input = { \"nums\": [0,10,11,25,14] }\nassert my_solution.maxSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [26,9,27,25,30,25,10,3,14,29,2,6,5,7,8,18] }\nassert my_solution.maxSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [5,9,0,28,23,11,1,3] }\nassert my_solution.maxSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [0,22,3,0,15,0,11,3,20,23,0,7,13,20,11,6,19] }\nassert my_solution.maxSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [0,16,6] }\nassert my_solution.maxSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [26,9,20,26,22,12,18,21,23,30,3,9,12,19,16] }\nassert my_solution.maxSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [14,10,8] }\nassert my_solution.maxSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [0,0,0,19,0] }\nassert my_solution.maxSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [3,27] }\nassert my_solution.maxSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [7,14,27] }\nassert my_solution.maxSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [16,4,29,17,0,0,13,22,1,6,0,29,1,3,0,7] }\nassert my_solution.maxSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [5,0,0,9,0,0,19,0,0,0,0,7,19,14,3,0,10,29] }\nassert my_solution.maxSubarrays(**test_input) == 9\n\ntest_input = { \"nums\": [16,22,0,0,0,0,27,0,0,0,24,22,0,0] }\nassert my_solution.maxSubarrays(**test_input) == 9", "start_time": 1696084200} +{"task_id": "biweekly-contest-114-maximum-number-of-k-divisible-components", "url": "https://leetcode.com/problems/maximum-number-of-k-divisible-components", "title": "maximum-number-of-k-divisible-components", "meta": {"questionId": "3058", "questionFrontendId": "2872", "title": "Maximum Number of K-Divisible Components", "titleSlug": "maximum-number-of-k-divisible-components", "isPaidOnly": false, "difficulty": "Hard", "likes": 170, "dislikes": 3, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nThere is an undirected tree with n nodes labeled from 0 to n - 1. You are given the integer n and a 2D integer array edges of length n - 1, where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree.\n\nYou are also given a 0-indexed integer array values of length n, where values[i] is the value associated with the ith node, and an integer k.\n\nA valid split of the tree is obtained by removing any set of edges, possibly empty, from the tree such that the resulting components all have values that are divisible by k, where the value of a connected component is the sum of the values of its nodes.\n\nReturn the maximum number of components in any valid split.\n\nExample 1:\n\n[https://assets.leetcode.com/uploads/2023/08/07/example12-cropped2svg.jpg]\n\nInput: n = 5, edges = [[0,2],[1,2],[1,3],[2,4]], values = [1,8,1,4,4], k = 6\nOutput: 2\nExplanation: We remove the edge connecting node 1 with 2. The resulting split is valid because:\n- The value of the component containing nodes 1 and 3 is values[1] + values[3] = 12.\n- The value of the component containing nodes 0, 2, and 4 is values[0] + values[2] + values[4] = 6.\nIt can be shown that no other valid split has more than 2 connected components.\n\nExample 2:\n\n[https://assets.leetcode.com/uploads/2023/08/07/example21svg-1.jpg]\n\nInput: n = 7, edges = [[0,1],[0,2],[1,3],[1,4],[2,5],[2,6]], values = [3,0,6,1,5,2,1], k = 3\nOutput: 3\nExplanation: We remove the edge connecting node 0 with 2, and the edge connecting node 0 with 1. The resulting split is valid because:\n- The value of the component containing node 0 is values[0] = 3.\n- The value of the component containing nodes 2, 5, and 6 is values[2] + values[5] + values[6] = 9.\n- The value of the component containing nodes 1, 3, and 4 is values[1] + values[3] + values[4] = 6.\nIt can be shown that no other valid split has more than 3 connected components.\n\n\nConstraints:\n\n * 1 <= n <= 3 * 104\n * edges.length == n - 1\n * edges[i].length == 2\n * 0 <= ai, bi < n\n * values.length == n\n * 0 <= values[i] <= 109\n * 1 <= k <= 109\n * Sum of values is divisible by k.\n * The input is generated such that edges represents a valid tree.\n\"\"\"\nclass Solution:\n def maxKDivisibleComponents(self, n: int, edges: List[List[int]], values: List[int], k: int) -> int:\n ", "prompt_sft": "There is an undirected tree with n nodes labeled from 0 to n - 1. You are given the integer n and a 2D integer array edges of length n - 1, where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree.\n\nYou are also given a 0-indexed integer array values of length n, where values[i] is the value associated with the ith node, and an integer k.\n\nA valid split of the tree is obtained by removing any set of edges, possibly empty, from the tree such that the resulting components all have values that are divisible by k, where the value of a connected component is the sum of the values of its nodes.\n\nReturn the maximum number of components in any valid split.\n\nExample 1:\n\n[https://assets.leetcode.com/uploads/2023/08/07/example12-cropped2svg.jpg]\n\nInput: n = 5, edges = [[0,2],[1,2],[1,3],[2,4]], values = [1,8,1,4,4], k = 6\nOutput: 2\nExplanation: We remove the edge connecting node 1 with 2. The resulting split is valid because:\n- The value of the component containing nodes 1 and 3 is values[1] + values[3] = 12.\n- The value of the component containing nodes 0, 2, and 4 is values[0] + values[2] + values[4] = 6.\nIt can be shown that no other valid split has more than 2 connected components.\n\nExample 2:\n\n[https://assets.leetcode.com/uploads/2023/08/07/example21svg-1.jpg]\n\nInput: n = 7, edges = [[0,1],[0,2],[1,3],[1,4],[2,5],[2,6]], values = [3,0,6,1,5,2,1], k = 3\nOutput: 3\nExplanation: We remove the edge connecting node 0 with 2, and the edge connecting node 0 with 1. The resulting split is valid because:\n- The value of the component containing node 0 is values[0] = 3.\n- The value of the component containing nodes 2, 5, and 6 is values[2] + values[5] + values[6] = 9.\n- The value of the component containing nodes 1, 3, and 4 is values[1] + values[3] + values[4] = 6.\nIt can be shown that no other valid split has more than 3 connected components.\n\n\nConstraints:\n\n * 1 <= n <= 3 * 104\n * edges.length == n - 1\n * edges[i].length == 2\n * 0 <= ai, bi < n\n * values.length == n\n * 0 <= values[i] <= 109\n * 1 <= k <= 109\n * Sum of values is divisible by k.\n * The input is generated such that edges represents a valid tree.\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def maxKDivisibleComponents(self, n: int, edges: List[List[int]], values: List[int], k: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"n\": 5, \"edges\": [[0,2],[1,2],[1,3],[2,4]], \"values\": [1,8,1,4,4], \"k\": 6 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 2\n\ntest_input = { \"n\": 7, \"edges\": [[0,1],[0,2],[1,3],[1,4],[2,5],[2,6]], \"values\": [3,0,6,1,5,2,1], \"k\": 3 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 3\n\ntest_input = { \"n\": 1, \"edges\": [], \"values\": [0], \"k\": 1 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 1\n\ntest_input = { \"n\": 1, \"edges\": [], \"values\": [10000], \"k\": 100 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 1\n\ntest_input = { \"n\": 2, \"edges\": [[1,0]], \"values\": [0,0], \"k\": 100000000 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 2\n\ntest_input = { \"n\": 2, \"edges\": [[0,1]], \"values\": [1,2], \"k\": 1 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 2\n\ntest_input = { \"n\": 2, \"edges\": [[1,0]], \"values\": [10000,10000], \"k\": 4 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 2\n\ntest_input = { \"n\": 3, \"edges\": [[0,2],[2,1]], \"values\": [0,0,0], \"k\": 1 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 3\n\ntest_input = { \"n\": 3, \"edges\": [[1,0],[2,0]], \"values\": [1,1,2], \"k\": 2 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 2\n\ntest_input = { \"n\": 3, \"edges\": [[1,2],[2,0]], \"values\": [0,2,2], \"k\": 4 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 2\n\ntest_input = { \"n\": 3, \"edges\": [[1,0],[0,2]], \"values\": [0,1,2], \"k\": 3 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 1\n\ntest_input = { \"n\": 4, \"edges\": [[0,1],[1,2],[2,3]], \"values\": [0,0,0,0], \"k\": 9999999 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 4\n\ntest_input = { \"n\": 9, \"edges\": [[1,2],[1,7],[0,6],[0,8],[0,3],[3,4],[0,5],[2,5]], \"values\": [1,4,4,0,2,1,1,6,2], \"k\": 7 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 2\n\ntest_input = { \"n\": 9, \"edges\": [[5,0],[5,1],[1,6],[1,7],[5,8],[0,3],[2,4],[5,2]], \"values\": [3,0,10,0,6,1,1,3,0], \"k\": 8 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 4\n\ntest_input = { \"n\": 6, \"edges\": [[5,0],[1,4],[4,3],[4,2],[5,4]], \"values\": [1,2,2,2,0,2], \"k\": 3 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 2\n\ntest_input = { \"n\": 4, \"edges\": [[0,3],[1,2],[0,2]], \"values\": [12,6,0,18], \"k\": 6 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 4\n\ntest_input = { \"n\": 10, \"edges\": [[8,7],[8,3],[7,6],[6,2],[6,4],[3,9],[4,1],[6,0],[2,5]], \"values\": [2,2,2,0,1,3,1,0,3,1], \"k\": 1 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 10\n\ntest_input = { \"n\": 8, \"edges\": [[0,4],[4,1],[0,3],[1,2],[0,5],[5,7],[1,6]], \"values\": [2,6,2,2,2,0,0,0], \"k\": 7 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 4\n\ntest_input = { \"n\": 9, \"edges\": [[1,5],[5,2],[1,8],[2,0],[2,6],[1,7],[6,4],[7,3]], \"values\": [8,8,12,12,8,8,8,8,4], \"k\": 4 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 9\n\ntest_input = { \"n\": 7, \"edges\": [[0,3],[3,2],[3,5],[0,6],[0,1],[6,4]], \"values\": [12,6,6,12,18,18,12], \"k\": 6 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 7\n\ntest_input = { \"n\": 4, \"edges\": [[1,3],[0,2],[1,0]], \"values\": [2,6,1,9], \"k\": 3 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 3\n\ntest_input = { \"n\": 5, \"edges\": [[2,0],[0,1],[2,3],[2,4]], \"values\": [0,2,10,0,18], \"k\": 6 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 3\n\ntest_input = { \"n\": 6, \"edges\": [[3,5],[3,0],[5,2],[5,4],[3,1]], \"values\": [3,3,0,18,0,0], \"k\": 8 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 4\n\ntest_input = { \"n\": 10, \"edges\": [[9,5],[4,9],[5,8],[3,6],[8,6],[0,1],[9,0],[6,2],[3,7]], \"values\": [10,14,12,4,12,1,8,36,12,11], \"k\": 12 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 7\n\ntest_input = { \"n\": 7, \"edges\": [[3,0],[0,4],[2,6],[3,6],[2,1],[1,5]], \"values\": [5,36,21,7,36,36,15], \"k\": 12 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 5\n\ntest_input = { \"n\": 5, \"edges\": [[2,3],[2,0],[2,4],[3,1]], \"values\": [3,0,3,15,3], \"k\": 8 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 2\n\ntest_input = { \"n\": 10, \"edges\": [[9,1],[1,7],[7,3],[3,6],[1,8],[9,4],[3,0],[3,5],[9,2]], \"values\": [9,9,18,9,9,18,9,9,18,27], \"k\": 9 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 10\n\ntest_input = { \"n\": 4, \"edges\": [[2,1],[2,0],[2,3]], \"values\": [2,0,8,10], \"k\": 5 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 3\n\ntest_input = { \"n\": 5, \"edges\": [[2,4],[4,0],[0,1],[0,3]], \"values\": [10,20,10,30,30], \"k\": 10 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 5\n\ntest_input = { \"n\": 10, \"edges\": [[5,6],[5,4],[5,1],[5,0],[1,7],[0,8],[0,2],[8,9],[3,8]], \"values\": [4,0,2,9,2,8,0,2,0,0], \"k\": 9 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 5\n\ntest_input = { \"n\": 9, \"edges\": [[5,6],[5,1],[6,0],[6,8],[8,2],[7,3],[8,3],[8,4]], \"values\": [33,11,33,6,11,11,33,16,33], \"k\": 11 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 8\n\ntest_input = { \"n\": 4, \"edges\": [[3,0],[0,2],[3,1]], \"values\": [8,8,12,4], \"k\": 4 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 4\n\ntest_input = { \"n\": 8, \"edges\": [[1,6],[5,7],[6,7],[3,2],[3,4],[4,0],[1,2]], \"values\": [6,6,6,6,3,8,15,6], \"k\": 7 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 3\n\ntest_input = { \"n\": 9, \"edges\": [[7,8],[4,6],[8,6],[3,0],[3,5],[5,1],[1,2],[7,0]], \"values\": [5,0,1,1,1,3,9,30,10], \"k\": 10 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 4\n\ntest_input = { \"n\": 4, \"edges\": [[2,1],[1,0],[2,3]], \"values\": [1,0,1,2], \"k\": 2 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 2\n\ntest_input = { \"n\": 4, \"edges\": [[1,2],[1,0],[2,3]], \"values\": [2,1,0,1], \"k\": 1 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 4\n\ntest_input = { \"n\": 4, \"edges\": [[2,1],[2,3],[2,0]], \"values\": [3,6,9,6], \"k\": 3 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 4\n\ntest_input = { \"n\": 7, \"edges\": [[0,4],[0,1],[4,6],[4,3],[6,5],[2,4]], \"values\": [2,0,2,0,0,0,0], \"k\": 2 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 7\n\ntest_input = { \"n\": 9, \"edges\": [[6,0],[1,2],[6,2],[2,3],[3,7],[3,8],[0,5],[3,4]], \"values\": [1,1,0,3,3,3,1,1,3], \"k\": 1 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 9\n\ntest_input = { \"n\": 5, \"edges\": [[0,4],[0,1],[1,3],[0,2]], \"values\": [2,12,14,0,0], \"k\": 7 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 4\n\ntest_input = { \"n\": 6, \"edges\": [[1,2],[0,5],[5,4],[0,3],[2,0]], \"values\": [2,2,2,0,0,2], \"k\": 2 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 6\n\ntest_input = { \"n\": 10, \"edges\": [[3,1],[1,4],[4,5],[3,0],[4,7],[7,2],[0,9],[0,8],[1,6]], \"values\": [0,0,0,1,0,0,0,0,0,0], \"k\": 1 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 10\n\ntest_input = { \"n\": 5, \"edges\": [[3,1],[0,3],[4,2],[1,2]], \"values\": [3,1,3,2,6], \"k\": 3 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 4\n\ntest_input = { \"n\": 10, \"edges\": [[6,3],[3,9],[3,7],[3,4],[7,8],[8,0],[8,5],[3,2],[0,1]], \"values\": [0,0,0,0,0,0,2,0,0,0], \"k\": 1 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 10\n\ntest_input = { \"n\": 5, \"edges\": [[4,3],[3,1],[1,2],[1,0]], \"values\": [8,6,0,8,2], \"k\": 8 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 3\n\ntest_input = { \"n\": 8, \"edges\": [[1,3],[0,3],[7,4],[4,6],[0,7],[0,2],[4,5]], \"values\": [12,10,6,2,6,12,3,9], \"k\": 6 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 5\n\ntest_input = { \"n\": 9, \"edges\": [[5,4],[2,1],[2,0],[0,7],[7,8],[5,2],[6,3],[2,3]], \"values\": [1,2,3,2,2,4,4,0,0], \"k\": 6 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 5\n\ntest_input = { \"n\": 7, \"edges\": [[4,6],[4,2],[2,1],[2,5],[4,3],[0,5]], \"values\": [27,0,1,1,4,2,1], \"k\": 9 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 3\n\ntest_input = { \"n\": 7, \"edges\": [[4,6],[0,2],[0,5],[2,3],[3,1],[4,2]], \"values\": [1,0,0,1,2,0,0], \"k\": 2 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 5\n\ntest_input = { \"n\": 9, \"edges\": [[3,2],[2,1],[1,4],[4,6],[4,8],[6,0],[0,5],[5,7]], \"values\": [10,10,15,5,5,15,15,10,15], \"k\": 5 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 9\n\ntest_input = { \"n\": 10, \"edges\": [[9,6],[9,0],[9,3],[3,8],[6,5],[0,7],[8,2],[6,4],[4,1]], \"values\": [0,0,3,0,0,0,3,0,3,3], \"k\": 4 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 6\n\ntest_input = { \"n\": 8, \"edges\": [[4,3],[3,6],[6,1],[6,7],[1,2],[7,0],[4,5]], \"values\": [30,10,10,20,10,10,30,10], \"k\": 10 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 8\n\ntest_input = { \"n\": 4, \"edges\": [[2,1],[1,0],[0,3]], \"values\": [9,6,6,9], \"k\": 3 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 4\n\ntest_input = { \"n\": 5, \"edges\": [[3,4],[3,2],[4,0],[2,1]], \"values\": [3,2,2,3,1], \"k\": 1 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 5\n\ntest_input = { \"n\": 5, \"edges\": [[1,3],[3,4],[4,2],[2,0]], \"values\": [27,14,0,0,4], \"k\": 9 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 3\n\ntest_input = { \"n\": 4, \"edges\": [[1,2],[2,0],[0,3]], \"values\": [3,1,2,3], \"k\": 1 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 4\n\ntest_input = { \"n\": 7, \"edges\": [[6,1],[6,4],[1,3],[3,0],[2,5],[4,2]], \"values\": [33,18,7,22,11,4,4], \"k\": 11 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 5\n\ntest_input = { \"n\": 10, \"edges\": [[6,2],[5,2],[0,3],[0,7],[0,1],[6,7],[2,4],[8,9],[5,9]], \"values\": [3,0,1,0,3,3,2,0,6,3], \"k\": 3 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 9\n\ntest_input = { \"n\": 8, \"edges\": [[6,1],[0,5],[5,7],[5,2],[5,4],[1,4],[0,3]], \"values\": [15,24,9,12,0,3,24,9], \"k\": 12 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 5\n\ntest_input = { \"n\": 6, \"edges\": [[3,1],[3,5],[1,4],[1,0],[3,2]], \"values\": [12,12,36,12,24,36], \"k\": 12 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 6\n\ntest_input = { \"n\": 7, \"edges\": [[6,4],[6,5],[3,1],[1,0],[0,2],[4,2]], \"values\": [0,0,0,1,0,0,1], \"k\": 1 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 7\n\ntest_input = { \"n\": 8, \"edges\": [[6,1],[2,0],[0,7],[1,2],[4,5],[7,5],[1,3]], \"values\": [1,14,5,21,18,3,7,1], \"k\": 7 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 5\n\ntest_input = { \"n\": 4, \"edges\": [[1,3],[1,0],[1,2]], \"values\": [18,18,9,27], \"k\": 9 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 4\n\ntest_input = { \"n\": 5, \"edges\": [[1,2],[1,3],[3,4],[1,0]], \"values\": [2,3,0,0,0], \"k\": 1 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 5\n\ntest_input = { \"n\": 5, \"edges\": [[2,3],[2,4],[4,1],[2,0]], \"values\": [0,0,1,0,0], \"k\": 1 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 5\n\ntest_input = { \"n\": 6, \"edges\": [[1,4],[1,3],[1,2],[4,0],[2,5]], \"values\": [0,3,0,0,0,0], \"k\": 1 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 6\n\ntest_input = { \"n\": 6, \"edges\": [[4,1],[0,2],[4,2],[3,5],[1,5]], \"values\": [3,9,6,3,9,6], \"k\": 3 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 6\n\ntest_input = { \"n\": 4, \"edges\": [[1,3],[0,2],[1,2]], \"values\": [4,1,0,3], \"k\": 4 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 3\n\ntest_input = { \"n\": 7, \"edges\": [[4,5],[5,2],[2,0],[0,6],[5,3],[2,1]], \"values\": [15,15,10,5,2,8,5], \"k\": 5 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 6\n\ntest_input = { \"n\": 5, \"edges\": [[2,4],[2,0],[0,3],[2,1]], \"values\": [36,24,10,24,2], \"k\": 12 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 4\n\ntest_input = { \"n\": 7, \"edges\": [[2,4],[2,1],[2,5],[1,3],[4,0],[1,6]], \"values\": [2,0,2,2,0,2,0], \"k\": 4 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 2\n\ntest_input = { \"n\": 4, \"edges\": [[3,2],[2,1],[2,0]], \"values\": [6,2,2,6], \"k\": 8 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 1\n\ntest_input = { \"n\": 10, \"edges\": [[7,4],[7,2],[4,1],[6,5],[6,0],[7,6],[1,8],[9,3],[7,9]], \"values\": [12,4,3,2,1,18,3,3,22,20], \"k\": 11 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 4\n\ntest_input = { \"n\": 5, \"edges\": [[0,3],[3,2],[3,1],[0,4]], \"values\": [12,36,36,36,12], \"k\": 12 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 5\n\ntest_input = { \"n\": 5, \"edges\": [[0,1],[1,2],[2,3],[3,4]], \"values\": [3,0,0,18,3], \"k\": 8 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 1\n\ntest_input = { \"n\": 4, \"edges\": [[3,2],[3,0],[3,1]], \"values\": [9,0,15,3], \"k\": 9 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 3\n\ntest_input = { \"n\": 5, \"edges\": [[0,2],[0,3],[3,4],[1,3]], \"values\": [3,3,0,0,0], \"k\": 1 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 5\n\ntest_input = { \"n\": 5, \"edges\": [[1,4],[1,3],[0,3],[1,2]], \"values\": [10,2,15,2,1], \"k\": 5 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 3\n\ntest_input = { \"n\": 6, \"edges\": [[1,4],[4,5],[0,3],[1,0],[0,2]], \"values\": [6,9,6,3,6,3], \"k\": 3 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 6\n\ntest_input = { \"n\": 6, \"edges\": [[5,1],[0,1],[2,4],[2,3],[1,4]], \"values\": [21,4,3,1,3,3], \"k\": 7 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 3\n\ntest_input = { \"n\": 6, \"edges\": [[5,1],[1,2],[5,3],[1,4],[2,0]], \"values\": [0,4,0,2,0,2], \"k\": 4 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 5\n\ntest_input = { \"n\": 10, \"edges\": [[3,6],[3,4],[6,0],[3,9],[5,7],[6,5],[0,2],[6,1],[9,8]], \"values\": [0,12,12,3,9,8,3,4,12,3], \"k\": 6 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 6\n\ntest_input = { \"n\": 7, \"edges\": [[0,2],[2,5],[2,3],[5,4],[2,1],[3,6]], \"values\": [9,9,3,6,3,0,0], \"k\": 10 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 2\n\ntest_input = { \"n\": 6, \"edges\": [[4,1],[4,5],[4,2],[4,0],[3,1]], \"values\": [0,6,6,22,2,8], \"k\": 11 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 3\n\ntest_input = { \"n\": 8, \"edges\": [[2,7],[1,4],[2,4],[4,3],[2,5],[7,0],[7,6]], \"values\": [12,3,12,4,1,8,12,12], \"k\": 4 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 7\n\ntest_input = { \"n\": 5, \"edges\": [[0,3],[0,1],[0,2],[0,4]], \"values\": [3,3,0,18,0], \"k\": 8 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 3\n\ntest_input = { \"n\": 4, \"edges\": [[2,0],[2,1],[0,3]], \"values\": [10,15,5,15], \"k\": 5 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 4\n\ntest_input = { \"n\": 7, \"edges\": [[2,5],[5,1],[5,4],[1,6],[4,3],[3,0]], \"values\": [0,0,6,2,0,2,2], \"k\": 6 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 3\n\ntest_input = { \"n\": 8, \"edges\": [[5,2],[2,4],[5,1],[5,3],[1,0],[2,6],[2,7]], \"values\": [18,9,9,9,27,9,9,18], \"k\": 9 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 8\n\ntest_input = { \"n\": 7, \"edges\": [[5,6],[6,4],[5,2],[6,3],[1,0],[5,1]], \"values\": [9,21,6,20,2,8,4], \"k\": 10 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 3\n\ntest_input = { \"n\": 8, \"edges\": [[3,1],[3,0],[0,4],[3,5],[7,6],[1,6],[6,2]], \"values\": [10,10,5,15,5,15,3,2], \"k\": 5 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 7\n\ntest_input = { \"n\": 5, \"edges\": [[2,4],[2,1],[2,0],[0,3]], \"values\": [1,2,1,0,2], \"k\": 6 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 2\n\ntest_input = { \"n\": 8, \"edges\": [[1,0],[0,2],[0,6],[2,5],[1,3],[2,4],[2,7]], \"values\": [0,3,18,9,0,0,0,3], \"k\": 11 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 4\n\ntest_input = { \"n\": 9, \"edges\": [[5,0],[2,4],[0,2],[2,3],[4,1],[2,7],[8,6],[0,8]], \"values\": [10,10,2,20,18,20,6,10,24], \"k\": 10 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 7\n\ntest_input = { \"n\": 10, \"edges\": [[0,9],[9,7],[1,4],[0,4],[8,2],[4,2],[2,3],[3,5],[0,6]], \"values\": [6,4,6,18,8,18,12,18,6,12], \"k\": 6 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 9\n\ntest_input = { \"n\": 7, \"edges\": [[4,2],[6,4],[5,3],[3,1],[4,5],[2,0]], \"values\": [9,3,0,9,9,15,18], \"k\": 9 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 5\n\ntest_input = { \"n\": 5, \"edges\": [[2,3],[3,1],[3,0],[1,4]], \"values\": [0,0,3,0,3], \"k\": 2 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 2\n\ntest_input = { \"n\": 10, \"edges\": [[3,6],[4,3],[0,8],[0,5],[8,9],[0,1],[8,7],[5,2],[3,8]], \"values\": [6,6,0,4,7,0,3,0,3,6], \"k\": 7 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 6\n\ntest_input = { \"n\": 6, \"edges\": [[2,3],[4,5],[4,1],[2,4],[2,0]], \"values\": [20,0,30,30,12,8], \"k\": 10 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 5\n\ntest_input = { \"n\": 9, \"edges\": [[5,7],[5,4],[5,6],[7,2],[7,1],[4,3],[2,0],[3,8]], \"values\": [6,6,6,18,6,12,18,6,6], \"k\": 6 }\nassert my_solution.maxKDivisibleComponents(**test_input) == 9", "start_time": 1696084200} +{"task_id": "weekly-contest-364-maximum-odd-binary-number", "url": "https://leetcode.com/problems/maximum-odd-binary-number", "title": "maximum-odd-binary-number", "meta": {"questionId": "3055", "questionFrontendId": "2864", "title": "Maximum Odd Binary Number", "titleSlug": "maximum-odd-binary-number", "isPaidOnly": false, "difficulty": "Easy", "likes": 149, "dislikes": 1, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a binary string s that contains at least one '1'.\n\nYou have to rearrange the bits in such a way that the resulting binary number is the maximum odd binary number that can be created from this combination.\n\nReturn a string representing the maximum odd binary number that can be created from the given combination.\n\nNote that the resulting string can have leading zeros.\n\nExample 1:\n\nInput: s = \"010\"\nOutput: \"001\"\nExplanation: Because there is just one '1', it must be in the last position. So the answer is \"001\".\n\nExample 2:\n\nInput: s = \"0101\"\nOutput: \"1001\"\nExplanation: One of the '1's must be in the last position. The maximum number that can be made with the remaining digits is \"100\". So the answer is \"1001\".\n\n\nConstraints:\n\n * 1 <= s.length <= 100\n * s consists only of '0' and '1'.\n * s contains at least one '1'.\n\"\"\"\nclass Solution:\n def maximumOddBinaryNumber(self, s: str) -> str:\n ", "prompt_sft": "You are given a binary string s that contains at least one '1'.\n\nYou have to rearrange the bits in such a way that the resulting binary number is the maximum odd binary number that can be created from this combination.\n\nReturn a string representing the maximum odd binary number that can be created from the given combination.\n\nNote that the resulting string can have leading zeros.\n\nExample 1:\n\nInput: s = \"010\"\nOutput: \"001\"\nExplanation: Because there is just one '1', it must be in the last position. So the answer is \"001\".\n\nExample 2:\n\nInput: s = \"0101\"\nOutput: \"1001\"\nExplanation: One of the '1's must be in the last position. The maximum number that can be made with the remaining digits is \"100\". So the answer is \"1001\".\n\n\nConstraints:\n\n * 1 <= s.length <= 100\n * s consists only of '0' and '1'.\n * s contains at least one '1'.\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def maximumOddBinaryNumber(self, s: str) -> str:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"s\": \"010\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"001\"\n\ntest_input = { \"s\": \"0101\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1001\"\n\ntest_input = { \"s\": \"1\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1\"\n\ntest_input = { \"s\": \"01\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"01\"\n\ntest_input = { \"s\": \"10\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"01\"\n\ntest_input = { \"s\": \"11\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"11\"\n\ntest_input = { \"s\": \"001\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"001\"\n\ntest_input = { \"s\": \"011\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"101\"\n\ntest_input = { \"s\": \"100\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"001\"\n\ntest_input = { \"s\": \"101\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"101\"\n\ntest_input = { \"s\": \"110\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"101\"\n\ntest_input = { \"s\": \"111\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"111\"\n\ntest_input = { \"s\": \"0010\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"0001\"\n\ntest_input = { \"s\": \"0011\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1001\"\n\ntest_input = { \"s\": \"0100\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"0001\"\n\ntest_input = { \"s\": \"0111\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1101\"\n\ntest_input = { \"s\": \"1000\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"0001\"\n\ntest_input = { \"s\": \"1001\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1001\"\n\ntest_input = { \"s\": \"1011\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1101\"\n\ntest_input = { \"s\": \"1100\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1001\"\n\ntest_input = { \"s\": \"1101\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1101\"\n\ntest_input = { \"s\": \"1111\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1111\"\n\ntest_input = { \"s\": \"00001\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"00001\"\n\ntest_input = { \"s\": \"00011\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"10001\"\n\ntest_input = { \"s\": \"00100\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"00001\"\n\ntest_input = { \"s\": \"00101\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"10001\"\n\ntest_input = { \"s\": \"00111\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"11001\"\n\ntest_input = { \"s\": \"01011\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"11001\"\n\ntest_input = { \"s\": \"01100\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"10001\"\n\ntest_input = { \"s\": \"01110\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"11001\"\n\ntest_input = { \"s\": \"01111\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"11101\"\n\ntest_input = { \"s\": \"10000\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"00001\"\n\ntest_input = { \"s\": \"10100\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"10001\"\n\ntest_input = { \"s\": \"11010\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"11001\"\n\ntest_input = { \"s\": \"11011\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"11101\"\n\ntest_input = { \"s\": \"11110\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"11101\"\n\ntest_input = { \"s\": \"000001\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"000001\"\n\ntest_input = { \"s\": \"000100\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"000001\"\n\ntest_input = { \"s\": \"000101\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"100001\"\n\ntest_input = { \"s\": \"000110\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"100001\"\n\ntest_input = { \"s\": \"000111\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"110001\"\n\ntest_input = { \"s\": \"001100\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"100001\"\n\ntest_input = { \"s\": \"001110\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"110001\"\n\ntest_input = { \"s\": \"001111\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"111001\"\n\ntest_input = { \"s\": \"010001\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"100001\"\n\ntest_input = { \"s\": \"010101\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"110001\"\n\ntest_input = { \"s\": \"010111\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"111001\"\n\ntest_input = { \"s\": \"011010\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"110001\"\n\ntest_input = { \"s\": \"011100\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"110001\"\n\ntest_input = { \"s\": \"011111\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"111101\"\n\ntest_input = { \"s\": \"100100\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"100001\"\n\ntest_input = { \"s\": \"100101\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"110001\"\n\ntest_input = { \"s\": \"100111\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"111001\"\n\ntest_input = { \"s\": \"101010\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"110001\"\n\ntest_input = { \"s\": \"101100\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"110001\"\n\ntest_input = { \"s\": \"101101\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"111001\"\n\ntest_input = { \"s\": \"110000\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"100001\"\n\ntest_input = { \"s\": \"110010\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"110001\"\n\ntest_input = { \"s\": \"110011\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"111001\"\n\ntest_input = { \"s\": \"110100\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"110001\"\n\ntest_input = { \"s\": \"110101\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"111001\"\n\ntest_input = { \"s\": \"110110\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"111001\"\n\ntest_input = { \"s\": \"111000\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"110001\"\n\ntest_input = { \"s\": \"111010\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"111001\"\n\ntest_input = { \"s\": \"111101\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"111101\"\n\ntest_input = { \"s\": \"111111\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"111111\"\n\ntest_input = { \"s\": \"0000010\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"0000001\"\n\ntest_input = { \"s\": \"0000100\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"0000001\"\n\ntest_input = { \"s\": \"0001001\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1000001\"\n\ntest_input = { \"s\": \"0001110\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1100001\"\n\ntest_input = { \"s\": \"0010000\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"0000001\"\n\ntest_input = { \"s\": \"0010101\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1100001\"\n\ntest_input = { \"s\": \"0010110\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1100001\"\n\ntest_input = { \"s\": \"0010111\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1110001\"\n\ntest_input = { \"s\": \"0011101\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1110001\"\n\ntest_input = { \"s\": \"0011111\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1111001\"\n\ntest_input = { \"s\": \"0100100\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1000001\"\n\ntest_input = { \"s\": \"0101001\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1100001\"\n\ntest_input = { \"s\": \"0110010\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1100001\"\n\ntest_input = { \"s\": \"0110110\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1110001\"\n\ntest_input = { \"s\": \"0110111\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1111001\"\n\ntest_input = { \"s\": \"0111011\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1111001\"\n\ntest_input = { \"s\": \"0111101\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1111001\"\n\ntest_input = { \"s\": \"1000011\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1100001\"\n\ntest_input = { \"s\": \"1000100\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1000001\"\n\ntest_input = { \"s\": \"1000101\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1100001\"\n\ntest_input = { \"s\": \"1000111\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1110001\"\n\ntest_input = { \"s\": \"1001100\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1100001\"\n\ntest_input = { \"s\": \"1001101\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1110001\"\n\ntest_input = { \"s\": \"1010000\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1000001\"\n\ntest_input = { \"s\": \"1010100\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1100001\"\n\ntest_input = { \"s\": \"1010111\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1111001\"\n\ntest_input = { \"s\": \"1011000\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1100001\"\n\ntest_input = { \"s\": \"1011010\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1110001\"\n\ntest_input = { \"s\": \"1011011\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1111001\"\n\ntest_input = { \"s\": \"1100100\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1100001\"\n\ntest_input = { \"s\": \"1100101\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1110001\"\n\ntest_input = { \"s\": \"1101010\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1110001\"\n\ntest_input = { \"s\": \"1101011\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1111001\"\n\ntest_input = { \"s\": \"1101110\" }\nassert my_solution.maximumOddBinaryNumber(**test_input) == \"1111001\"", "start_time": 1695522600} +{"task_id": "weekly-contest-364-beautiful-towers-i", "url": "https://leetcode.com/problems/beautiful-towers-i", "title": "beautiful-towers-i", "meta": {"questionId": "3114", "questionFrontendId": "2865", "title": "Beautiful Towers I", "titleSlug": "beautiful-towers-i", "isPaidOnly": false, "difficulty": "Medium", "likes": 160, "dislikes": 26, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed array maxHeights of n integers.\n\nYou are tasked with building n towers in the coordinate line. The ith tower is built at coordinate i and has a height of heights[i].\n\nA configuration of towers is beautiful if the following conditions hold:\n\n 1. 1 <= heights[i] <= maxHeights[i]\n 2. heights is a mountain array.\n\nArray heights is a mountain if there exists an index i such that:\n\n * For all 0 < j <= i, heights[j - 1] <= heights[j]\n * For all i <= k < n - 1, heights[k + 1] <= heights[k]\n\nReturn the maximum possible sum of heights of a beautiful configuration of towers.\n\nExample 1:\n\nInput: maxHeights = [5,3,4,1,1]\nOutput: 13\nExplanation: One beautiful configuration with a maximum sum is heights = [5,3,3,1,1]. This configuration is beautiful since:\n- 1 <= heights[i] <= maxHeights[i]\n- heights is a mountain of peak i = 0.\nIt can be shown that there exists no other beautiful configuration with a sum of heights greater than 13.\n\nExample 2:\n\nInput: maxHeights = [6,5,3,9,2,7]\nOutput: 22\nExplanation: One beautiful configuration with a maximum sum is heights = [3,3,3,9,2,2]. This configuration is beautiful since:\n- 1 <= heights[i] <= maxHeights[i]\n- heights is a mountain of peak i = 3.\nIt can be shown that there exists no other beautiful configuration with a sum of heights greater than 22.\n\nExample 3:\n\nInput: maxHeights = [3,2,5,5,2,3]\nOutput: 18\nExplanation: One beautiful configuration with a maximum sum is heights = [2,2,5,5,2,2]. This configuration is beautiful since:\n- 1 <= heights[i] <= maxHeights[i]\n- heights is a mountain of peak i = 2.\nNote that, for this configuration, i = 3 can also be considered a peak.\nIt can be shown that there exists no other beautiful configuration with a sum of heights greater than 18.\n\n\nConstraints:\n\n * 1 <= n == maxHeights <= 103\n * 1 <= maxHeights[i] <= 109\n\"\"\"\nclass Solution:\n def maximumSumOfHeights(self, maxHeights: List[int]) -> int:\n ", "prompt_sft": "You are given a 0-indexed array maxHeights of n integers.\n\nYou are tasked with building n towers in the coordinate line. The ith tower is built at coordinate i and has a height of heights[i].\n\nA configuration of towers is beautiful if the following conditions hold:\n\n 1. 1 <= heights[i] <= maxHeights[i]\n 2. heights is a mountain array.\n\nArray heights is a mountain if there exists an index i such that:\n\n * For all 0 < j <= i, heights[j - 1] <= heights[j]\n * For all i <= k < n - 1, heights[k + 1] <= heights[k]\n\nReturn the maximum possible sum of heights of a beautiful configuration of towers.\n\nExample 1:\n\nInput: maxHeights = [5,3,4,1,1]\nOutput: 13\nExplanation: One beautiful configuration with a maximum sum is heights = [5,3,3,1,1]. This configuration is beautiful since:\n- 1 <= heights[i] <= maxHeights[i]\n- heights is a mountain of peak i = 0.\nIt can be shown that there exists no other beautiful configuration with a sum of heights greater than 13.\n\nExample 2:\n\nInput: maxHeights = [6,5,3,9,2,7]\nOutput: 22\nExplanation: One beautiful configuration with a maximum sum is heights = [3,3,3,9,2,2]. This configuration is beautiful since:\n- 1 <= heights[i] <= maxHeights[i]\n- heights is a mountain of peak i = 3.\nIt can be shown that there exists no other beautiful configuration with a sum of heights greater than 22.\n\nExample 3:\n\nInput: maxHeights = [3,2,5,5,2,3]\nOutput: 18\nExplanation: One beautiful configuration with a maximum sum is heights = [2,2,5,5,2,2]. This configuration is beautiful since:\n- 1 <= heights[i] <= maxHeights[i]\n- heights is a mountain of peak i = 2.\nNote that, for this configuration, i = 3 can also be considered a peak.\nIt can be shown that there exists no other beautiful configuration with a sum of heights greater than 18.\n\n\nConstraints:\n\n * 1 <= n == maxHeights <= 103\n * 1 <= maxHeights[i] <= 109\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def maximumSumOfHeights(self, maxHeights: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"maxHeights\": [5,3,4,1,1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 13\n\ntest_input = { \"maxHeights\": [6,5,3,9,2,7] }\nassert my_solution.maximumSumOfHeights(**test_input) == 22\n\ntest_input = { \"maxHeights\": [3,2,5,5,2,3] }\nassert my_solution.maximumSumOfHeights(**test_input) == 18\n\ntest_input = { \"maxHeights\": [1000000000] }\nassert my_solution.maximumSumOfHeights(**test_input) == 1000000000\n\ntest_input = { \"maxHeights\": [1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 1\n\ntest_input = { \"maxHeights\": [933754743] }\nassert my_solution.maximumSumOfHeights(**test_input) == 933754743\n\ntest_input = { \"maxHeights\": [1,1000000000] }\nassert my_solution.maximumSumOfHeights(**test_input) == 1000000001\n\ntest_input = { \"maxHeights\": [1000000000,1000000000] }\nassert my_solution.maximumSumOfHeights(**test_input) == 2000000000\n\ntest_input = { \"maxHeights\": [999999999,1000000000] }\nassert my_solution.maximumSumOfHeights(**test_input) == 1999999999\n\ntest_input = { \"maxHeights\": [1000000000,999999999] }\nassert my_solution.maximumSumOfHeights(**test_input) == 1999999999\n\ntest_input = { \"maxHeights\": [30,1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 31\n\ntest_input = { \"maxHeights\": [1,12,19] }\nassert my_solution.maximumSumOfHeights(**test_input) == 32\n\ntest_input = { \"maxHeights\": [1000000000,1000000000,1000000000] }\nassert my_solution.maximumSumOfHeights(**test_input) == 3000000000\n\ntest_input = { \"maxHeights\": [999999999,1000000000,999999999] }\nassert my_solution.maximumSumOfHeights(**test_input) == 2999999998\n\ntest_input = { \"maxHeights\": [1000000000,999999999,999999998] }\nassert my_solution.maximumSumOfHeights(**test_input) == 2999999997\n\ntest_input = { \"maxHeights\": [999999998,999999999,1000000000] }\nassert my_solution.maximumSumOfHeights(**test_input) == 2999999997\n\ntest_input = { \"maxHeights\": [1,1,1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 3\n\ntest_input = { \"maxHeights\": [1,1,4,3,3,3,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 20\n\ntest_input = { \"maxHeights\": [2,4,1,3,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 11\n\ntest_input = { \"maxHeights\": [1,5,2,5,6,4,6,3,4,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 33\n\ntest_input = { \"maxHeights\": [3,6,3,5,5,1,2,5,5,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 24\n\ntest_input = { \"maxHeights\": [1,6,5,6,2,4,1,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 23\n\ntest_input = { \"maxHeights\": [5,1,6,5,4,4,2] }\nassert my_solution.maximumSumOfHeights(**test_input) == 23\n\ntest_input = { \"maxHeights\": [3,4,3,1,1,3] }\nassert my_solution.maximumSumOfHeights(**test_input) == 13\n\ntest_input = { \"maxHeights\": [4,1,6,5,3,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 19\n\ntest_input = { \"maxHeights\": [3,5,5,6,4,6,5,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 35\n\ntest_input = { \"maxHeights\": [6,4,3,3] }\nassert my_solution.maximumSumOfHeights(**test_input) == 16\n\ntest_input = { \"maxHeights\": [6,4,3,6,1,2,2,3] }\nassert my_solution.maximumSumOfHeights(**test_input) == 20\n\ntest_input = { \"maxHeights\": [6,5,1,4,6,1,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 16\n\ntest_input = { \"maxHeights\": [2,3,4,4,3,2,3,5,5,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 30\n\ntest_input = { \"maxHeights\": [5,4,6,1,2] }\nassert my_solution.maximumSumOfHeights(**test_input) == 16\n\ntest_input = { \"maxHeights\": [1,4,2] }\nassert my_solution.maximumSumOfHeights(**test_input) == 7\n\ntest_input = { \"maxHeights\": [5,2,4,4] }\nassert my_solution.maximumSumOfHeights(**test_input) == 12\n\ntest_input = { \"maxHeights\": [1,5,5,3,3] }\nassert my_solution.maximumSumOfHeights(**test_input) == 17\n\ntest_input = { \"maxHeights\": [3,1,1,4,5,5,4,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 25\n\ntest_input = { \"maxHeights\": [1,4,3,4,5,1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 17\n\ntest_input = { \"maxHeights\": [5,5,3,1,1,2,5,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 18\n\ntest_input = { \"maxHeights\": [3,1,3,2,6,1,4,4,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 20\n\ntest_input = { \"maxHeights\": [5,3,3] }\nassert my_solution.maximumSumOfHeights(**test_input) == 11\n\ntest_input = { \"maxHeights\": [5,2,1,4,3,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 14\n\ntest_input = { \"maxHeights\": [1,3,2,1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 7\n\ntest_input = { \"maxHeights\": [1,3,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 10\n\ntest_input = { \"maxHeights\": [5,5,5,3,3,3,3] }\nassert my_solution.maximumSumOfHeights(**test_input) == 27\n\ntest_input = { \"maxHeights\": [1,3,3,2,1,2] }\nassert my_solution.maximumSumOfHeights(**test_input) == 11\n\ntest_input = { \"maxHeights\": [5,5,4,1,4,4,5,6,4] }\nassert my_solution.maximumSumOfHeights(**test_input) == 27\n\ntest_input = { \"maxHeights\": [3,5,5,6,2] }\nassert my_solution.maximumSumOfHeights(**test_input) == 21\n\ntest_input = { \"maxHeights\": [4,6,6,1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 17\n\ntest_input = { \"maxHeights\": [4,2,6,1,4,1,5,3,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 18\n\ntest_input = { \"maxHeights\": [4,1,6,3,6,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 20\n\ntest_input = { \"maxHeights\": [5,2,1,4,1,6,1,5,3,4] }\nassert my_solution.maximumSumOfHeights(**test_input) == 18\n\ntest_input = { \"maxHeights\": [1,4,6,3,5,1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 18\n\ntest_input = { \"maxHeights\": [6,1,2,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 9\n\ntest_input = { \"maxHeights\": [6,1,5,1,6,2,2] }\nassert my_solution.maximumSumOfHeights(**test_input) == 14\n\ntest_input = { \"maxHeights\": [6,1,2,3,4,4] }\nassert my_solution.maximumSumOfHeights(**test_input) == 15\n\ntest_input = { \"maxHeights\": [6,1,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 8\n\ntest_input = { \"maxHeights\": [1,6,6,3,5,6,1,1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 24\n\ntest_input = { \"maxHeights\": [2,6,1,5,1,2,3] }\nassert my_solution.maximumSumOfHeights(**test_input) == 13\n\ntest_input = { \"maxHeights\": [3,5,1,6,3,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 15\n\ntest_input = { \"maxHeights\": [4,4,5,3] }\nassert my_solution.maximumSumOfHeights(**test_input) == 16\n\ntest_input = { \"maxHeights\": [3,5,4,4,3,1,1,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 22\n\ntest_input = { \"maxHeights\": [5,6,4,4,5,1,2,3,5,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 28\n\ntest_input = { \"maxHeights\": [2,5,1,5,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 13\n\ntest_input = { \"maxHeights\": [1,2,6,2,6,5,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 23\n\ntest_input = { \"maxHeights\": [1,1,6,4,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 16\n\ntest_input = { \"maxHeights\": [3,4,1,6,2] }\nassert my_solution.maximumSumOfHeights(**test_input) == 11\n\ntest_input = { \"maxHeights\": [1,3,3,5,6,4,6,5,2,2] }\nassert my_solution.maximumSumOfHeights(**test_input) == 34\n\ntest_input = { \"maxHeights\": [2,4,6,4,6,3,1,5,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 26\n\ntest_input = { \"maxHeights\": [1,6,1,6,4] }\nassert my_solution.maximumSumOfHeights(**test_input) == 13\n\ntest_input = { \"maxHeights\": [4,2,1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 7\n\ntest_input = { \"maxHeights\": [1,2,4,1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 8\n\ntest_input = { \"maxHeights\": [1,3,3,2,5,1,4,3,1,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 17\n\ntest_input = { \"maxHeights\": [4,3,1,4] }\nassert my_solution.maximumSumOfHeights(**test_input) == 9\n\ntest_input = { \"maxHeights\": [5,1,3,4,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 14\n\ntest_input = { \"maxHeights\": [1,5,4,2] }\nassert my_solution.maximumSumOfHeights(**test_input) == 12\n\ntest_input = { \"maxHeights\": [2,6,4,3,2,2,2,5,6,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 30\n\ntest_input = { \"maxHeights\": [2,6,1,2,1,1,2,4] }\nassert my_solution.maximumSumOfHeights(**test_input) == 14\n\ntest_input = { \"maxHeights\": [1,2,5,3,3,3,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 20\n\ntest_input = { \"maxHeights\": [2,5,2,2,1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 12\n\ntest_input = { \"maxHeights\": [3,5,3,4] }\nassert my_solution.maximumSumOfHeights(**test_input) == 14\n\ntest_input = { \"maxHeights\": [4,6,6,3,4,1,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 24\n\ntest_input = { \"maxHeights\": [2,3,5,3,4,1,1,1,3,2] }\nassert my_solution.maximumSumOfHeights(**test_input) == 21\n\ntest_input = { \"maxHeights\": [6,6,5,3,5,4,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 29\n\ntest_input = { \"maxHeights\": [5,5,2,2,4,2,3,2,4,4] }\nassert my_solution.maximumSumOfHeights(**test_input) == 26\n\ntest_input = { \"maxHeights\": [1,2,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 8\n\ntest_input = { \"maxHeights\": [3,6,2,4,5,2,2,5,1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 22\n\ntest_input = { \"maxHeights\": [6,2,6,3,4,6,2] }\nassert my_solution.maximumSumOfHeights(**test_input) == 22\n\ntest_input = { \"maxHeights\": [6,2,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 10\n\ntest_input = { \"maxHeights\": [5,4,2,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 13\n\ntest_input = { \"maxHeights\": [2,6,5,3] }\nassert my_solution.maximumSumOfHeights(**test_input) == 16\n\ntest_input = { \"maxHeights\": [4,5,4,1,6,5,1,3] }\nassert my_solution.maximumSumOfHeights(**test_input) == 18\n\ntest_input = { \"maxHeights\": [4,1,2,4,6,2,6,3] }\nassert my_solution.maximumSumOfHeights(**test_input) == 20\n\ntest_input = { \"maxHeights\": [6,4,4,4,2] }\nassert my_solution.maximumSumOfHeights(**test_input) == 20\n\ntest_input = { \"maxHeights\": [5,5,4,2] }\nassert my_solution.maximumSumOfHeights(**test_input) == 16\n\ntest_input = { \"maxHeights\": [5,3,3,4,2,2,1,4] }\nassert my_solution.maximumSumOfHeights(**test_input) == 20\n\ntest_input = { \"maxHeights\": [6,5,6,6,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 28\n\ntest_input = { \"maxHeights\": [6,3,5,6,2,2,3] }\nassert my_solution.maximumSumOfHeights(**test_input) == 23\n\ntest_input = { \"maxHeights\": [4,6,4,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 18\n\ntest_input = { \"maxHeights\": [3,5,4,2,1,1,5,6,1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 19\n\ntest_input = { \"maxHeights\": [2,3,5,6,2,4] }\nassert my_solution.maximumSumOfHeights(**test_input) == 20\n\ntest_input = { \"maxHeights\": [4,5,2,1,4,6,6,1,6,2] }\nassert my_solution.maximumSumOfHeights(**test_input) == 23", "start_time": 1695522600} +{"task_id": "weekly-contest-364-beautiful-towers-ii", "url": "https://leetcode.com/problems/beautiful-towers-ii", "title": "beautiful-towers-ii", "meta": {"questionId": "3113", "questionFrontendId": "2866", "title": "Beautiful Towers II", "titleSlug": "beautiful-towers-ii", "isPaidOnly": false, "difficulty": "Medium", "likes": 348, "dislikes": 22, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed array maxHeights of n integers.\n\nYou are tasked with building n towers in the coordinate line. The ith tower is built at coordinate i and has a height of heights[i].\n\nA configuration of towers is beautiful if the following conditions hold:\n\n 1. 1 <= heights[i] <= maxHeights[i]\n 2. heights is a mountain array.\n\nArray heights is a mountain if there exists an index i such that:\n\n * For all 0 < j <= i, heights[j - 1] <= heights[j]\n * For all i <= k < n - 1, heights[k + 1] <= heights[k]\n\nReturn the maximum possible sum of heights of a beautiful configuration of towers.\n\nExample 1:\n\nInput: maxHeights = [5,3,4,1,1]\nOutput: 13\nExplanation: One beautiful configuration with a maximum sum is heights = [5,3,3,1,1]. This configuration is beautiful since:\n- 1 <= heights[i] <= maxHeights[i]\n- heights is a mountain of peak i = 0.\nIt can be shown that there exists no other beautiful configuration with a sum of heights greater than 13.\n\nExample 2:\n\nInput: maxHeights = [6,5,3,9,2,7]\nOutput: 22\nExplanation: One beautiful configuration with a maximum sum is heights = [3,3,3,9,2,2]. This configuration is beautiful since:\n- 1 <= heights[i] <= maxHeights[i]\n- heights is a mountain of peak i = 3.\nIt can be shown that there exists no other beautiful configuration with a sum of heights greater than 22.\n\nExample 3:\n\nInput: maxHeights = [3,2,5,5,2,3]\nOutput: 18\nExplanation: One beautiful configuration with a maximum sum is heights = [2,2,5,5,2,2]. This configuration is beautiful since:\n- 1 <= heights[i] <= maxHeights[i]\n- heights is a mountain of peak i = 2.\nNote that, for this configuration, i = 3 can also be considered a peak.\nIt can be shown that there exists no other beautiful configuration with a sum of heights greater than 18.\n\n\nConstraints:\n\n * 1 <= n == maxHeights <= 105\n * 1 <= maxHeights[i] <= 109\n\"\"\"\nclass Solution:\n def maximumSumOfHeights(self, maxHeights: List[int]) -> int:\n ", "prompt_sft": "You are given a 0-indexed array maxHeights of n integers.\n\nYou are tasked with building n towers in the coordinate line. The ith tower is built at coordinate i and has a height of heights[i].\n\nA configuration of towers is beautiful if the following conditions hold:\n\n 1. 1 <= heights[i] <= maxHeights[i]\n 2. heights is a mountain array.\n\nArray heights is a mountain if there exists an index i such that:\n\n * For all 0 < j <= i, heights[j - 1] <= heights[j]\n * For all i <= k < n - 1, heights[k + 1] <= heights[k]\n\nReturn the maximum possible sum of heights of a beautiful configuration of towers.\n\nExample 1:\n\nInput: maxHeights = [5,3,4,1,1]\nOutput: 13\nExplanation: One beautiful configuration with a maximum sum is heights = [5,3,3,1,1]. This configuration is beautiful since:\n- 1 <= heights[i] <= maxHeights[i]\n- heights is a mountain of peak i = 0.\nIt can be shown that there exists no other beautiful configuration with a sum of heights greater than 13.\n\nExample 2:\n\nInput: maxHeights = [6,5,3,9,2,7]\nOutput: 22\nExplanation: One beautiful configuration with a maximum sum is heights = [3,3,3,9,2,2]. This configuration is beautiful since:\n- 1 <= heights[i] <= maxHeights[i]\n- heights is a mountain of peak i = 3.\nIt can be shown that there exists no other beautiful configuration with a sum of heights greater than 22.\n\nExample 3:\n\nInput: maxHeights = [3,2,5,5,2,3]\nOutput: 18\nExplanation: One beautiful configuration with a maximum sum is heights = [2,2,5,5,2,2]. This configuration is beautiful since:\n- 1 <= heights[i] <= maxHeights[i]\n- heights is a mountain of peak i = 2.\nNote that, for this configuration, i = 3 can also be considered a peak.\nIt can be shown that there exists no other beautiful configuration with a sum of heights greater than 18.\n\n\nConstraints:\n\n * 1 <= n == maxHeights <= 105\n * 1 <= maxHeights[i] <= 109\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def maximumSumOfHeights(self, maxHeights: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"maxHeights\": [5,3,4,1,1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 13\n\ntest_input = { \"maxHeights\": [6,5,3,9,2,7] }\nassert my_solution.maximumSumOfHeights(**test_input) == 22\n\ntest_input = { \"maxHeights\": [3,2,5,5,2,3] }\nassert my_solution.maximumSumOfHeights(**test_input) == 18\n\ntest_input = { \"maxHeights\": [1000000000] }\nassert my_solution.maximumSumOfHeights(**test_input) == 1000000000\n\ntest_input = { \"maxHeights\": [1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 1\n\ntest_input = { \"maxHeights\": [352939501] }\nassert my_solution.maximumSumOfHeights(**test_input) == 352939501\n\ntest_input = { \"maxHeights\": [1,1000000000] }\nassert my_solution.maximumSumOfHeights(**test_input) == 1000000001\n\ntest_input = { \"maxHeights\": [1000000000,1000000000] }\nassert my_solution.maximumSumOfHeights(**test_input) == 2000000000\n\ntest_input = { \"maxHeights\": [999999999,1000000000] }\nassert my_solution.maximumSumOfHeights(**test_input) == 1999999999\n\ntest_input = { \"maxHeights\": [1000000000,999999999] }\nassert my_solution.maximumSumOfHeights(**test_input) == 1999999999\n\ntest_input = { \"maxHeights\": [2,1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 3\n\ntest_input = { \"maxHeights\": [26,30,30] }\nassert my_solution.maximumSumOfHeights(**test_input) == 86\n\ntest_input = { \"maxHeights\": [1000000000,1000000000,1000000000] }\nassert my_solution.maximumSumOfHeights(**test_input) == 3000000000\n\ntest_input = { \"maxHeights\": [999999999,1000000000,999999999] }\nassert my_solution.maximumSumOfHeights(**test_input) == 2999999998\n\ntest_input = { \"maxHeights\": [1000000000,999999999,999999998] }\nassert my_solution.maximumSumOfHeights(**test_input) == 2999999997\n\ntest_input = { \"maxHeights\": [999999998,999999999,1000000000] }\nassert my_solution.maximumSumOfHeights(**test_input) == 2999999997\n\ntest_input = { \"maxHeights\": [1,1,1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 3\n\ntest_input = { \"maxHeights\": [1,1,5,6,2,2,3] }\nassert my_solution.maximumSumOfHeights(**test_input) == 19\n\ntest_input = { \"maxHeights\": [3,5,3,5,1,5,4,4,4] }\nassert my_solution.maximumSumOfHeights(**test_input) == 22\n\ntest_input = { \"maxHeights\": [4,2,4,2,1,5,4,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 19\n\ntest_input = { \"maxHeights\": [5,3,2,4,6,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 21\n\ntest_input = { \"maxHeights\": [6,5,2,1,5,4,4,2] }\nassert my_solution.maximumSumOfHeights(**test_input) == 19\n\ntest_input = { \"maxHeights\": [4,3,2,4,6,3] }\nassert my_solution.maximumSumOfHeights(**test_input) == 19\n\ntest_input = { \"maxHeights\": [2,6,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 13\n\ntest_input = { \"maxHeights\": [6,5,3,4,6,1,2,3,2,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 25\n\ntest_input = { \"maxHeights\": [2,1,6,2,3] }\nassert my_solution.maximumSumOfHeights(**test_input) == 12\n\ntest_input = { \"maxHeights\": [6,5,1,5,4,3,4,2,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 22\n\ntest_input = { \"maxHeights\": [1,1,6,4,2,2,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 18\n\ntest_input = { \"maxHeights\": [2,2,2,5,6,1,4,3] }\nassert my_solution.maximumSumOfHeights(**test_input) == 20\n\ntest_input = { \"maxHeights\": [3,1,5,3,6,5,1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 20\n\ntest_input = { \"maxHeights\": [1,4,6,1,4,6,1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 15\n\ntest_input = { \"maxHeights\": [4,4,2,3,3,2,2] }\nassert my_solution.maximumSumOfHeights(**test_input) == 18\n\ntest_input = { \"maxHeights\": [4,4,1,6,2,1,2] }\nassert my_solution.maximumSumOfHeights(**test_input) == 13\n\ntest_input = { \"maxHeights\": [6,3,3,5,4,1,5,2,4,1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 23\n\ntest_input = { \"maxHeights\": [3,2,4] }\nassert my_solution.maximumSumOfHeights(**test_input) == 8\n\ntest_input = { \"maxHeights\": [3,1,4,3,2,3] }\nassert my_solution.maximumSumOfHeights(**test_input) == 13\n\ntest_input = { \"maxHeights\": [3,1,4,5,4,4,6,4] }\nassert my_solution.maximumSumOfHeights(**test_input) == 28\n\ntest_input = { \"maxHeights\": [1,2,5,5,5,6,5,6,3] }\nassert my_solution.maximumSumOfHeights(**test_input) == 37\n\ntest_input = { \"maxHeights\": [6,1,1,6,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 14\n\ntest_input = { \"maxHeights\": [1,6,6,6,2,6,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 25\n\ntest_input = { \"maxHeights\": [4,1,4,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 11\n\ntest_input = { \"maxHeights\": [1,5,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 12\n\ntest_input = { \"maxHeights\": [1,4,4,5,6,6,2,4,1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 31\n\ntest_input = { \"maxHeights\": [2,6,6,4,6,1,6,2,1,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 27\n\ntest_input = { \"maxHeights\": [2,4,6,4,4] }\nassert my_solution.maximumSumOfHeights(**test_input) == 20\n\ntest_input = { \"maxHeights\": [5,2,6,1,6,6,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 21\n\ntest_input = { \"maxHeights\": [3,6,1,4,5,5,2,5,1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 22\n\ntest_input = { \"maxHeights\": [3,2,6,5,6,6,2,1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 29\n\ntest_input = { \"maxHeights\": [1,4,2,1,6,3,2,1,2,2] }\nassert my_solution.maximumSumOfHeights(**test_input) == 18\n\ntest_input = { \"maxHeights\": [3,3,4,3,5,6,1,3] }\nassert my_solution.maximumSumOfHeights(**test_input) == 25\n\ntest_input = { \"maxHeights\": [4,4,2,4,1,4,5,5,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 25\n\ntest_input = { \"maxHeights\": [6,5,3] }\nassert my_solution.maximumSumOfHeights(**test_input) == 14\n\ntest_input = { \"maxHeights\": [2,2,4] }\nassert my_solution.maximumSumOfHeights(**test_input) == 8\n\ntest_input = { \"maxHeights\": [6,2,6,5,3,6,2,5,1,2] }\nassert my_solution.maximumSumOfHeights(**test_input) == 27\n\ntest_input = { \"maxHeights\": [4,6,3,4,6,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 25\n\ntest_input = { \"maxHeights\": [6,4,6,3] }\nassert my_solution.maximumSumOfHeights(**test_input) == 17\n\ntest_input = { \"maxHeights\": [4,3,5,1,4] }\nassert my_solution.maximumSumOfHeights(**test_input) == 13\n\ntest_input = { \"maxHeights\": [3,5,6,6,3,6,1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 27\n\ntest_input = { \"maxHeights\": [6,1,6,5,5,1,1,2] }\nassert my_solution.maximumSumOfHeights(**test_input) == 21\n\ntest_input = { \"maxHeights\": [4,3,3,1,5,3,3,6,3,3] }\nassert my_solution.maximumSumOfHeights(**test_input) == 25\n\ntest_input = { \"maxHeights\": [1,4,6,1,6,4] }\nassert my_solution.maximumSumOfHeights(**test_input) == 14\n\ntest_input = { \"maxHeights\": [6,2,1,4,2] }\nassert my_solution.maximumSumOfHeights(**test_input) == 11\n\ntest_input = { \"maxHeights\": [1,4,6,4,2,6,6,5,5,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 36\n\ntest_input = { \"maxHeights\": [6,1,2,1,3,3,1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 12\n\ntest_input = { \"maxHeights\": [6,4,3,3,6,1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 20\n\ntest_input = { \"maxHeights\": [3,1,4,4] }\nassert my_solution.maximumSumOfHeights(**test_input) == 10\n\ntest_input = { \"maxHeights\": [2,4,1,6,5,3,2] }\nassert my_solution.maximumSumOfHeights(**test_input) == 19\n\ntest_input = { \"maxHeights\": [2,5,5,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 18\n\ntest_input = { \"maxHeights\": [5,2,1,4] }\nassert my_solution.maximumSumOfHeights(**test_input) == 9\n\ntest_input = { \"maxHeights\": [5,5,3,3,3,3,1,3,2] }\nassert my_solution.maximumSumOfHeights(**test_input) == 25\n\ntest_input = { \"maxHeights\": [5,6,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 16\n\ntest_input = { \"maxHeights\": [1,1,6,2,3,1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 13\n\ntest_input = { \"maxHeights\": [2,4,2,2,2,6,1,4,4] }\nassert my_solution.maximumSumOfHeights(**test_input) == 19\n\ntest_input = { \"maxHeights\": [6,2,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 10\n\ntest_input = { \"maxHeights\": [5,6,1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 12\n\ntest_input = { \"maxHeights\": [6,6,4,3,6,3,6,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 31\n\ntest_input = { \"maxHeights\": [3,2,4,2,3,2,3,6,1,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 23\n\ntest_input = { \"maxHeights\": [6,3,3,3,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 18\n\ntest_input = { \"maxHeights\": [5,5,2,1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 13\n\ntest_input = { \"maxHeights\": [3,5,4,5,5,4] }\nassert my_solution.maximumSumOfHeights(**test_input) == 25\n\ntest_input = { \"maxHeights\": [3,4,6,3,1,5,5,2] }\nassert my_solution.maximumSumOfHeights(**test_input) == 20\n\ntest_input = { \"maxHeights\": [4,3,6,6,5,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 28\n\ntest_input = { \"maxHeights\": [3,5,5,2,2,3,4,1,1,4] }\nassert my_solution.maximumSumOfHeights(**test_input) == 24\n\ntest_input = { \"maxHeights\": [5,6,1,2,5,1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 15\n\ntest_input = { \"maxHeights\": [6,3,3,6,4,4,2,1,6,4] }\nassert my_solution.maximumSumOfHeights(**test_input) == 28\n\ntest_input = { \"maxHeights\": [1,5,3,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 13\n\ntest_input = { \"maxHeights\": [5,2,3,5,3,2,5,5,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 28\n\ntest_input = { \"maxHeights\": [5,4,2,6,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 18\n\ntest_input = { \"maxHeights\": [5,5,4,4,1,4,3,1,4,2] }\nassert my_solution.maximumSumOfHeights(**test_input) == 24\n\ntest_input = { \"maxHeights\": [4,4,4,6,4] }\nassert my_solution.maximumSumOfHeights(**test_input) == 22\n\ntest_input = { \"maxHeights\": [3,3,3,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 14\n\ntest_input = { \"maxHeights\": [2,2,2] }\nassert my_solution.maximumSumOfHeights(**test_input) == 6\n\ntest_input = { \"maxHeights\": [4,4,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 13\n\ntest_input = { \"maxHeights\": [1,1,6,5,4,6,6,2,5] }\nassert my_solution.maximumSumOfHeights(**test_input) == 30\n\ntest_input = { \"maxHeights\": [6,6,3,3,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 21\n\ntest_input = { \"maxHeights\": [1,3,2,5,2,1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 13\n\ntest_input = { \"maxHeights\": [1,5,3,3,1,6] }\nassert my_solution.maximumSumOfHeights(**test_input) == 14\n\ntest_input = { \"maxHeights\": [4,2,4,3] }\nassert my_solution.maximumSumOfHeights(**test_input) == 11\n\ntest_input = { \"maxHeights\": [6,4,5,1,2,3,1] }\nassert my_solution.maximumSumOfHeights(**test_input) == 18\n\ntest_input = { \"maxHeights\": [4,4,1,6,1,4] }\nassert my_solution.maximumSumOfHeights(**test_input) == 12", "start_time": 1695522600} +{"task_id": "weekly-contest-364-count-valid-paths-in-a-tree", "url": "https://leetcode.com/problems/count-valid-paths-in-a-tree", "title": "count-valid-paths-in-a-tree", "meta": {"questionId": "3112", "questionFrontendId": "2867", "title": "Count Valid Paths in a Tree", "titleSlug": "count-valid-paths-in-a-tree", "isPaidOnly": false, "difficulty": "Hard", "likes": 212, "dislikes": 5, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nThere is an undirected tree with n nodes labeled from 1 to n. You are given the integer n and a 2D integer array edges of length n - 1, where edges[i] = [ui, vi] indicates that there is an edge between nodes ui and vi in the tree.\n\nReturn the number of valid paths in the tree.\n\nA path (a, b) is valid if there exists exactly one prime number among the node labels in the path from a to b.\n\nNote that:\n\n * The path (a, b) is a sequence of distinct nodes starting with node a and ending with node b such that every two adjacent nodes in the sequence share an edge in the tree.\n * Path (a, b) and path (b, a) are considered the same and counted only once.\n\nExample 1:\n\n[https://assets.leetcode.com/uploads/2023/08/27/example1.png]\n\nInput: n = 5, edges = [[1,2],[1,3],[2,4],[2,5]]\nOutput: 4\nExplanation: The pairs with exactly one prime number on the path between them are:\n- (1, 2) since the path from 1 to 2 contains prime number 2.\n- (1, 3) since the path from 1 to 3 contains prime number 3.\n- (1, 4) since the path from 1 to 4 contains prime number 2.\n- (2, 4) since the path from 2 to 4 contains prime number 2.\nIt can be shown that there are only 4 valid paths.\n\nExample 2:\n\n[https://assets.leetcode.com/uploads/2023/08/27/example2.png]\n\nInput: n = 6, edges = [[1,2],[1,3],[2,4],[3,5],[3,6]]\nOutput: 6\nExplanation: The pairs with exactly one prime number on the path between them are:\n- (1, 2) since the path from 1 to 2 contains prime number 2.\n- (1, 3) since the path from 1 to 3 contains prime number 3.\n- (1, 4) since the path from 1 to 4 contains prime number 2.\n- (1, 6) since the path from 1 to 6 contains prime number 3.\n- (2, 4) since the path from 2 to 4 contains prime number 2.\n- (3, 6) since the path from 3 to 6 contains prime number 3.\nIt can be shown that there are only 6 valid paths.\n\n\nConstraints:\n\n * 1 <= n <= 105\n * edges.length == n - 1\n * edges[i].length == 2\n * 1 <= ui, vi <= n\n * The input is generated such that edges represent a valid tree.\n\"\"\"\nclass Solution:\n def countPaths(self, n: int, edges: List[List[int]]) -> int:\n ", "prompt_sft": "There is an undirected tree with n nodes labeled from 1 to n. You are given the integer n and a 2D integer array edges of length n - 1, where edges[i] = [ui, vi] indicates that there is an edge between nodes ui and vi in the tree.\n\nReturn the number of valid paths in the tree.\n\nA path (a, b) is valid if there exists exactly one prime number among the node labels in the path from a to b.\n\nNote that:\n\n * The path (a, b) is a sequence of distinct nodes starting with node a and ending with node b such that every two adjacent nodes in the sequence share an edge in the tree.\n * Path (a, b) and path (b, a) are considered the same and counted only once.\n\nExample 1:\n\n[https://assets.leetcode.com/uploads/2023/08/27/example1.png]\n\nInput: n = 5, edges = [[1,2],[1,3],[2,4],[2,5]]\nOutput: 4\nExplanation: The pairs with exactly one prime number on the path between them are:\n- (1, 2) since the path from 1 to 2 contains prime number 2.\n- (1, 3) since the path from 1 to 3 contains prime number 3.\n- (1, 4) since the path from 1 to 4 contains prime number 2.\n- (2, 4) since the path from 2 to 4 contains prime number 2.\nIt can be shown that there are only 4 valid paths.\n\nExample 2:\n\n[https://assets.leetcode.com/uploads/2023/08/27/example2.png]\n\nInput: n = 6, edges = [[1,2],[1,3],[2,4],[3,5],[3,6]]\nOutput: 6\nExplanation: The pairs with exactly one prime number on the path between them are:\n- (1, 2) since the path from 1 to 2 contains prime number 2.\n- (1, 3) since the path from 1 to 3 contains prime number 3.\n- (1, 4) since the path from 1 to 4 contains prime number 2.\n- (1, 6) since the path from 1 to 6 contains prime number 3.\n- (2, 4) since the path from 2 to 4 contains prime number 2.\n- (3, 6) since the path from 3 to 6 contains prime number 3.\nIt can be shown that there are only 6 valid paths.\n\n\nConstraints:\n\n * 1 <= n <= 105\n * edges.length == n - 1\n * edges[i].length == 2\n * 1 <= ui, vi <= n\n * The input is generated such that edges represent a valid tree.\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def countPaths(self, n: int, edges: List[List[int]]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"n\": 5, \"edges\": [[1,2],[1,3],[2,4],[2,5]] }\nassert my_solution.countPaths(**test_input) == 4\n\ntest_input = { \"n\": 6, \"edges\": [[1,2],[1,3],[2,4],[3,5],[3,6]] }\nassert my_solution.countPaths(**test_input) == 6\n\ntest_input = { \"n\": 1, \"edges\": [] }\nassert my_solution.countPaths(**test_input) == 0\n\ntest_input = { \"n\": 2, \"edges\": [[2,1]] }\nassert my_solution.countPaths(**test_input) == 1\n\ntest_input = { \"n\": 4, \"edges\": [[1,2],[4,1],[3,4]] }\nassert my_solution.countPaths(**test_input) == 4\n\ntest_input = { \"n\": 5, \"edges\": [[1,3],[4,3],[2,3],[5,2]] }\nassert my_solution.countPaths(**test_input) == 3\n\ntest_input = { \"n\": 5, \"edges\": [[1,5],[2,1],[4,5],[3,2]] }\nassert my_solution.countPaths(**test_input) == 4\n\ntest_input = { \"n\": 5, \"edges\": [[2,3],[4,2],[1,3],[5,1]] }\nassert my_solution.countPaths(**test_input) == 3\n\ntest_input = { \"n\": 5, \"edges\": [[4,1],[5,4],[2,1],[3,4]] }\nassert my_solution.countPaths(**test_input) == 6\n\ntest_input = { \"n\": 5, \"edges\": [[3,5],[1,5],[4,3],[2,5]] }\nassert my_solution.countPaths(**test_input) == 2\n\ntest_input = { \"n\": 4, \"edges\": [[2,1],[4,2],[3,2]] }\nassert my_solution.countPaths(**test_input) == 3\n\ntest_input = { \"n\": 5, \"edges\": [[1,4],[2,4],[3,2],[5,4]] }\nassert my_solution.countPaths(**test_input) == 4\n\ntest_input = { \"n\": 5, \"edges\": [[5,4],[3,4],[1,4],[2,4]] }\nassert my_solution.countPaths(**test_input) == 6\n\ntest_input = { \"n\": 4, \"edges\": [[3,4],[1,3],[2,4]] }\nassert my_solution.countPaths(**test_input) == 4\n\ntest_input = { \"n\": 10, \"edges\": [[10,9],[2,10],[1,10],[3,2],[6,10],[4,3],[8,6],[5,8],[7,6]] }\nassert my_solution.countPaths(**test_input) == 16\n\ntest_input = { \"n\": 8, \"edges\": [[7,2],[6,2],[5,2],[1,2],[4,7],[8,1],[3,6]] }\nassert my_solution.countPaths(**test_input) == 7\n\ntest_input = { \"n\": 5, \"edges\": [[3,2],[4,3],[5,4],[1,4]] }\nassert my_solution.countPaths(**test_input) == 4\n\ntest_input = { \"n\": 9, \"edges\": [[7,4],[3,4],[5,4],[1,5],[6,4],[9,5],[8,7],[2,8]] }\nassert my_solution.countPaths(**test_input) == 17\n\ntest_input = { \"n\": 9, \"edges\": [[1,8],[5,8],[4,8],[6,5],[3,1],[9,1],[7,4],[2,8]] }\nassert my_solution.countPaths(**test_input) == 21\n\ntest_input = { \"n\": 10, \"edges\": [[2,9],[7,2],[10,9],[5,7],[4,5],[6,7],[8,2],[1,5],[3,10]] }\nassert my_solution.countPaths(**test_input) == 11\n\ntest_input = { \"n\": 8, \"edges\": [[6,1],[8,1],[3,6],[4,1],[7,3],[2,8],[5,1]] }\nassert my_solution.countPaths(**test_input) == 12\n\ntest_input = { \"n\": 10, \"edges\": [[9,1],[8,9],[5,9],[10,8],[7,5],[2,8],[3,8],[6,7],[4,1]] }\nassert my_solution.countPaths(**test_input) == 16\n\ntest_input = { \"n\": 5, \"edges\": [[5,3],[4,5],[2,5],[1,4]] }\nassert my_solution.countPaths(**test_input) == 2\n\ntest_input = { \"n\": 7, \"edges\": [[7,6],[2,6],[5,2],[3,5],[4,5],[1,6]] }\nassert my_solution.countPaths(**test_input) == 5\n\ntest_input = { \"n\": 8, \"edges\": [[4,5],[8,4],[6,4],[2,5],[1,6],[3,1],[7,8]] }\nassert my_solution.countPaths(**test_input) == 12\n\ntest_input = { \"n\": 10, \"edges\": [[9,6],[5,6],[10,6],[8,5],[4,8],[3,9],[1,3],[2,6],[7,1]] }\nassert my_solution.countPaths(**test_input) == 22\n\ntest_input = { \"n\": 5, \"edges\": [[1,4],[2,4],[5,4],[3,4]] }\nassert my_solution.countPaths(**test_input) == 6\n\ntest_input = { \"n\": 10, \"edges\": [[9,4],[7,9],[10,9],[6,7],[8,7],[2,7],[3,2],[1,9],[5,10]] }\nassert my_solution.countPaths(**test_input) == 19\n\ntest_input = { \"n\": 7, \"edges\": [[4,7],[6,7],[1,7],[3,7],[2,6],[5,6]] }\nassert my_solution.countPaths(**test_input) == 8\n\ntest_input = { \"n\": 5, \"edges\": [[1,4],[2,1],[5,2],[3,1]] }\nassert my_solution.countPaths(**test_input) == 4\n\ntest_input = { \"n\": 5, \"edges\": [[4,5],[2,5],[1,4],[3,1]] }\nassert my_solution.countPaths(**test_input) == 4\n\ntest_input = { \"n\": 10, \"edges\": [[4,3],[5,3],[1,4],[7,5],[6,3],[8,3],[9,1],[10,8],[2,10]] }\nassert my_solution.countPaths(**test_input) == 19\n\ntest_input = { \"n\": 5, \"edges\": [[1,3],[4,1],[2,1],[5,1]] }\nassert my_solution.countPaths(**test_input) == 6\n\ntest_input = { \"n\": 7, \"edges\": [[5,2],[3,5],[4,5],[1,2],[6,2],[7,2]] }\nassert my_solution.countPaths(**test_input) == 4\n\ntest_input = { \"n\": 5, \"edges\": [[3,4],[1,4],[5,3],[2,5]] }\nassert my_solution.countPaths(**test_input) == 2\n\ntest_input = { \"n\": 8, \"edges\": [[1,8],[2,1],[6,8],[3,6],[4,3],[5,8],[7,2]] }\nassert my_solution.countPaths(**test_input) == 13\n\ntest_input = { \"n\": 9, \"edges\": [[2,1],[6,1],[8,2],[9,8],[4,9],[7,9],[3,1],[5,2]] }\nassert my_solution.countPaths(**test_input) == 16\n\ntest_input = { \"n\": 5, \"edges\": [[4,3],[5,4],[1,5],[2,3]] }\nassert my_solution.countPaths(**test_input) == 4\n\ntest_input = { \"n\": 8, \"edges\": [[2,4],[3,4],[6,4],[7,3],[8,7],[5,6],[1,5]] }\nassert my_solution.countPaths(**test_input) == 10\n\ntest_input = { \"n\": 6, \"edges\": [[3,6],[1,3],[2,3],[5,2],[4,5]] }\nassert my_solution.countPaths(**test_input) == 4\n\ntest_input = { \"n\": 10, \"edges\": [[7,5],[4,7],[10,5],[6,5],[8,6],[2,8],[9,4],[3,10],[1,9]] }\nassert my_solution.countPaths(**test_input) == 11\n\ntest_input = { \"n\": 8, \"edges\": [[3,2],[8,3],[7,3],[6,2],[4,7],[5,6],[1,8]] }\nassert my_solution.countPaths(**test_input) == 5\n\ntest_input = { \"n\": 8, \"edges\": [[2,6],[3,6],[5,2],[1,6],[7,2],[8,1],[4,1]] }\nassert my_solution.countPaths(**test_input) == 8\n\ntest_input = { \"n\": 9, \"edges\": [[3,7],[6,7],[4,7],[1,6],[8,4],[9,1],[2,7],[5,2]] }\nassert my_solution.countPaths(**test_input) == 11\n\ntest_input = { \"n\": 6, \"edges\": [[6,2],[5,6],[1,2],[3,2],[4,3]] }\nassert my_solution.countPaths(**test_input) == 5\n\ntest_input = { \"n\": 6, \"edges\": [[6,2],[1,6],[3,1],[5,3],[4,3]] }\nassert my_solution.countPaths(**test_input) == 7\n\ntest_input = { \"n\": 8, \"edges\": [[2,3],[8,3],[5,3],[6,3],[4,3],[7,8],[1,2]] }\nassert my_solution.countPaths(**test_input) == 8\n\ntest_input = { \"n\": 7, \"edges\": [[4,6],[5,6],[7,6],[3,4],[2,6],[1,5]] }\nassert my_solution.countPaths(**test_input) == 11\n\ntest_input = { \"n\": 6, \"edges\": [[4,2],[5,4],[1,5],[6,1],[3,1]] }\nassert my_solution.countPaths(**test_input) == 8\n\ntest_input = { \"n\": 6, \"edges\": [[4,1],[6,1],[5,4],[3,5],[2,1]] }\nassert my_solution.countPaths(**test_input) == 6\n\ntest_input = { \"n\": 7, \"edges\": [[6,7],[1,6],[4,6],[2,7],[3,2],[5,7]] }\nassert my_solution.countPaths(**test_input) == 3\n\ntest_input = { \"n\": 6, \"edges\": [[4,3],[5,3],[6,5],[2,4],[1,5]] }\nassert my_solution.countPaths(**test_input) == 5\n\ntest_input = { \"n\": 10, \"edges\": [[2,5],[3,5],[10,2],[8,3],[7,5],[4,3],[1,8],[9,5],[6,8]] }\nassert my_solution.countPaths(**test_input) == 9\n\ntest_input = { \"n\": 8, \"edges\": [[2,8],[1,8],[5,2],[4,5],[6,5],[7,2],[3,5]] }\nassert my_solution.countPaths(**test_input) == 5\n\ntest_input = { \"n\": 8, \"edges\": [[7,2],[6,7],[5,7],[8,6],[1,7],[3,5],[4,2]] }\nassert my_solution.countPaths(**test_input) == 6\n\ntest_input = { \"n\": 7, \"edges\": [[5,7],[3,5],[2,7],[4,3],[6,3],[1,4]] }\nassert my_solution.countPaths(**test_input) == 5\n\ntest_input = { \"n\": 7, \"edges\": [[2,3],[1,3],[7,3],[4,1],[6,3],[5,1]] }\nassert my_solution.countPaths(**test_input) == 7\n\ntest_input = { \"n\": 7, \"edges\": [[4,2],[6,4],[1,6],[7,6],[5,2],[3,7]] }\nassert my_solution.countPaths(**test_input) == 6\n\ntest_input = { \"n\": 6, \"edges\": [[3,4],[6,3],[1,4],[5,4],[2,6]] }\nassert my_solution.countPaths(**test_input) == 8\n\ntest_input = { \"n\": 10, \"edges\": [[2,7],[1,2],[8,7],[4,2],[6,8],[10,7],[5,4],[9,8],[3,6]] }\nassert my_solution.countPaths(**test_input) == 14\n\ntest_input = { \"n\": 8, \"edges\": [[6,2],[7,2],[5,6],[8,2],[3,6],[1,8],[4,2]] }\nassert my_solution.countPaths(**test_input) == 11\n\ntest_input = { \"n\": 10, \"edges\": [[9,6],[1,9],[2,1],[8,1],[10,6],[7,6],[3,8],[4,3],[5,3]] }\nassert my_solution.countPaths(**test_input) == 21\n\ntest_input = { \"n\": 8, \"edges\": [[4,6],[1,6],[7,6],[2,1],[8,7],[5,6],[3,5]] }\nassert my_solution.countPaths(**test_input) == 13\n\ntest_input = { \"n\": 7, \"edges\": [[3,7],[6,7],[4,6],[1,3],[5,3],[2,3]] }\nassert my_solution.countPaths(**test_input) == 3\n\ntest_input = { \"n\": 10, \"edges\": [[2,9],[3,9],[8,9],[10,3],[1,9],[4,8],[7,10],[6,1],[5,10]] }\nassert my_solution.countPaths(**test_input) == 18\n\ntest_input = { \"n\": 8, \"edges\": [[5,6],[3,6],[7,5],[4,6],[8,6],[2,3],[1,3]] }\nassert my_solution.countPaths(**test_input) == 10\n\ntest_input = { \"n\": 9, \"edges\": [[9,3],[4,3],[2,9],[7,3],[8,7],[1,7],[5,4],[6,2]] }\nassert my_solution.countPaths(**test_input) == 10\n\ntest_input = { \"n\": 6, \"edges\": [[5,1],[2,1],[4,2],[6,5],[3,4]] }\nassert my_solution.countPaths(**test_input) == 7\n\ntest_input = { \"n\": 7, \"edges\": [[3,6],[2,6],[5,6],[7,2],[1,6],[4,2]] }\nassert my_solution.countPaths(**test_input) == 9\n\ntest_input = { \"n\": 5, \"edges\": [[1,5],[3,5],[4,3],[2,5]] }\nassert my_solution.countPaths(**test_input) == 2\n\ntest_input = { \"n\": 8, \"edges\": [[2,8],[6,2],[1,2],[4,1],[7,2],[3,2],[5,7]] }\nassert my_solution.countPaths(**test_input) == 9\n\ntest_input = { \"n\": 9, \"edges\": [[5,3],[1,3],[7,3],[4,5],[6,7],[8,7],[9,5],[2,5]] }\nassert my_solution.countPaths(**test_input) == 7\n\ntest_input = { \"n\": 10, \"edges\": [[8,10],[3,10],[1,8],[7,8],[6,10],[2,3],[5,8],[9,5],[4,6]] }\nassert my_solution.countPaths(**test_input) == 21\n\ntest_input = { \"n\": 10, \"edges\": [[4,8],[6,8],[9,4],[1,6],[5,8],[2,8],[10,9],[7,6],[3,5]] }\nassert my_solution.countPaths(**test_input) == 18\n\ntest_input = { \"n\": 9, \"edges\": [[4,6],[9,4],[3,6],[7,6],[1,4],[5,9],[2,7],[8,4]] }\nassert my_solution.countPaths(**test_input) == 15\n\ntest_input = { \"n\": 7, \"edges\": [[7,6],[2,6],[1,7],[3,2],[5,2],[4,5]] }\nassert my_solution.countPaths(**test_input) == 5\n\ntest_input = { \"n\": 9, \"edges\": [[1,8],[5,8],[3,8],[2,1],[9,2],[7,1],[6,5],[4,9]] }\nassert my_solution.countPaths(**test_input) == 17\n\ntest_input = { \"n\": 7, \"edges\": [[3,5],[4,3],[6,5],[2,4],[7,3],[1,4]] }\nassert my_solution.countPaths(**test_input) == 5\n\ntest_input = { \"n\": 10, \"edges\": [[5,2],[8,5],[10,5],[3,8],[4,2],[1,4],[9,10],[7,5],[6,8]] }\nassert my_solution.countPaths(**test_input) == 12\n\ntest_input = { \"n\": 8, \"edges\": [[7,4],[1,4],[5,7],[6,1],[8,5],[3,8],[2,6]] }\nassert my_solution.countPaths(**test_input) == 8\n\ntest_input = { \"n\": 10, \"edges\": [[8,2],[7,8],[9,2],[4,2],[6,4],[3,9],[5,4],[1,9],[10,8]] }\nassert my_solution.countPaths(**test_input) == 24\n\ntest_input = { \"n\": 8, \"edges\": [[3,8],[2,8],[1,8],[6,8],[4,3],[7,6],[5,2]] }\nassert my_solution.countPaths(**test_input) == 13\n\ntest_input = { \"n\": 9, \"edges\": [[5,4],[2,4],[9,5],[3,2],[7,3],[1,4],[8,2],[6,4]] }\nassert my_solution.countPaths(**test_input) == 14\n\ntest_input = { \"n\": 10, \"edges\": [[10,8],[5,10],[1,10],[3,10],[7,3],[2,10],[6,8],[9,6],[4,6]] }\nassert my_solution.countPaths(**test_input) == 18\n\ntest_input = { \"n\": 9, \"edges\": [[6,7],[5,7],[8,7],[9,6],[2,5],[4,5],[1,8],[3,6]] }\nassert my_solution.countPaths(**test_input) == 11\n\ntest_input = { \"n\": 10, \"edges\": [[1,6],[9,1],[5,9],[10,6],[4,9],[8,9],[7,8],[2,1],[3,1]] }\nassert my_solution.countPaths(**test_input) == 24\n\ntest_input = { \"n\": 8, \"edges\": [[4,5],[3,4],[6,5],[1,4],[2,3],[8,4],[7,3]] }\nassert my_solution.countPaths(**test_input) == 10\n\ntest_input = { \"n\": 7, \"edges\": [[7,4],[6,4],[2,6],[5,6],[3,2],[1,5]] }\nassert my_solution.countPaths(**test_input) == 9\n\ntest_input = { \"n\": 10, \"edges\": [[3,2],[5,3],[1,2],[9,5],[7,5],[6,3],[4,3],[8,6],[10,1]] }\nassert my_solution.countPaths(**test_input) == 8\n\ntest_input = { \"n\": 8, \"edges\": [[2,8],[5,2],[4,2],[7,4],[3,2],[1,3],[6,3]] }\nassert my_solution.countPaths(**test_input) == 7\n\ntest_input = { \"n\": 6, \"edges\": [[6,3],[2,3],[4,2],[5,2],[1,6]] }\nassert my_solution.countPaths(**test_input) == 3\n\ntest_input = { \"n\": 9, \"edges\": [[7,3],[5,3],[4,3],[9,7],[6,5],[8,3],[2,4],[1,5]] }\nassert my_solution.countPaths(**test_input) == 8\n\ntest_input = { \"n\": 5, \"edges\": [[1,2],[5,1],[4,5],[3,4]] }\nassert my_solution.countPaths(**test_input) == 5\n\ntest_input = { \"n\": 9, \"edges\": [[8,3],[6,8],[2,8],[4,3],[5,4],[7,5],[9,4],[1,5]] }\nassert my_solution.countPaths(**test_input) == 15\n\ntest_input = { \"n\": 5, \"edges\": [[2,1],[4,2],[5,1],[3,2]] }\nassert my_solution.countPaths(**test_input) == 4\n\ntest_input = { \"n\": 6, \"edges\": [[4,2],[6,2],[3,2],[1,6],[5,2]] }\nassert my_solution.countPaths(**test_input) == 5\n\ntest_input = { \"n\": 10, \"edges\": [[10,5],[3,10],[4,3],[8,3],[7,4],[1,7],[6,5],[9,1],[2,5]] }\nassert my_solution.countPaths(**test_input) == 14\n\ntest_input = { \"n\": 9, \"edges\": [[4,7],[6,4],[8,4],[2,8],[5,2],[9,7],[1,6],[3,7]] }\nassert my_solution.countPaths(**test_input) == 13\n\ntest_input = { \"n\": 10, \"edges\": [[7,3],[1,3],[2,3],[10,2],[4,2],[8,1],[9,4],[5,3],[6,3]] }\nassert my_solution.countPaths(**test_input) == 10\n\ntest_input = { \"n\": 7, \"edges\": [[4,7],[2,7],[3,4],[1,7],[6,4],[5,4]] }\nassert my_solution.countPaths(**test_input) == 9", "start_time": 1695522600} +{"task_id": "weekly-contest-363-sum-of-values-at-indices-with-k-set-bits", "url": "https://leetcode.com/problems/sum-of-values-at-indices-with-k-set-bits", "title": "sum-of-values-at-indices-with-k-set-bits", "meta": {"questionId": "3093", "questionFrontendId": "2859", "title": "Sum of Values at Indices With K Set Bits", "titleSlug": "sum-of-values-at-indices-with-k-set-bits", "isPaidOnly": false, "difficulty": "Easy", "likes": 154, "dislikes": 16, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed integer array nums and an integer k.\n\nReturn an integer that denotes the sum of elements in nums whose corresponding indices have exactly k set bits in their binary representation.\n\nThe set bits in an integer are the 1's present when it is written in binary.\n\n * For example, the binary representation of 21 is 10101, which has 3 set bits.\n\nExample 1:\n\nInput: nums = [5,10,1,5,2], k = 1\nOutput: 13\nExplanation: The binary representation of the indices are:\n0 = 0002\n1 = 0012\n2 = 0102\n3 = 0112\n4 = 1002\nIndices 1, 2, and 4 have k = 1 set bits in their binary representation.\nHence, the answer is nums[1] + nums[2] + nums[4] = 13.\n\nExample 2:\n\nInput: nums = [4,3,2,1], k = 2\nOutput: 1\nExplanation: The binary representation of the indices are:\n0 = 002\n1 = 012\n2 = 102\n3 = 112\nOnly index 3 has k = 2 set bits in its binary representation.\nHence, the answer is nums[3] = 1.\n\n\nConstraints:\n\n * 1 <= nums.length <= 1000\n * 1 <= nums[i] <= 105\n * 0 <= k <= 10\n\"\"\"\nclass Solution:\n def sumIndicesWithKSetBits(self, nums: List[int], k: int) -> int:\n ", "prompt_sft": "You are given a 0-indexed integer array nums and an integer k.\n\nReturn an integer that denotes the sum of elements in nums whose corresponding indices have exactly k set bits in their binary representation.\n\nThe set bits in an integer are the 1's present when it is written in binary.\n\n * For example, the binary representation of 21 is 10101, which has 3 set bits.\n\nExample 1:\n\nInput: nums = [5,10,1,5,2], k = 1\nOutput: 13\nExplanation: The binary representation of the indices are:\n0 = 0002\n1 = 0012\n2 = 0102\n3 = 0112\n4 = 1002\nIndices 1, 2, and 4 have k = 1 set bits in their binary representation.\nHence, the answer is nums[1] + nums[2] + nums[4] = 13.\n\nExample 2:\n\nInput: nums = [4,3,2,1], k = 2\nOutput: 1\nExplanation: The binary representation of the indices are:\n0 = 002\n1 = 012\n2 = 102\n3 = 112\nOnly index 3 has k = 2 set bits in its binary representation.\nHence, the answer is nums[3] = 1.\n\n\nConstraints:\n\n * 1 <= nums.length <= 1000\n * 1 <= nums[i] <= 105\n * 0 <= k <= 10\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def sumIndicesWithKSetBits(self, nums: List[int], k: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [5,10,1,5,2], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 13\n\ntest_input = { \"nums\": [4,3,2,1], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 1\n\ntest_input = { \"nums\": [1], \"k\": 0 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 1\n\ntest_input = { \"nums\": [100000], \"k\": 0 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 100000\n\ntest_input = { \"nums\": [2,2], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 2\n\ntest_input = { \"nums\": [2,4], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 4\n\ntest_input = { \"nums\": [2,7], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 7\n\ntest_input = { \"nums\": [3,3], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 3\n\ntest_input = { \"nums\": [3,9], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 9\n\ntest_input = { \"nums\": [4,7], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 7\n\ntest_input = { \"nums\": [4,8], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 8\n\ntest_input = { \"nums\": [6,6], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 6\n\ntest_input = { \"nums\": [7,2], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 2\n\ntest_input = { \"nums\": [7,4], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 4\n\ntest_input = { \"nums\": [8,4], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 4\n\ntest_input = { \"nums\": [8,9], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 9\n\ntest_input = { \"nums\": [9,9], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 9\n\ntest_input = { \"nums\": [15,43], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 43\n\ntest_input = { \"nums\": [35,86], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 86\n\ntest_input = { \"nums\": [36,14], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 14\n\ntest_input = { \"nums\": [47,61], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 61\n\ntest_input = { \"nums\": [60,46], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 46\n\ntest_input = { \"nums\": [70,7], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 7\n\ntest_input = { \"nums\": [1,51,55], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 106\n\ntest_input = { \"nums\": [2,2,5], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 7\n\ntest_input = { \"nums\": [2,3,2], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 5\n\ntest_input = { \"nums\": [3,2,5], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 7\n\ntest_input = { \"nums\": [3,7,5], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 12\n\ntest_input = { \"nums\": [4,5,9], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 14\n\ntest_input = { \"nums\": [5,5,5], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 10\n\ntest_input = { \"nums\": [5,7,7], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 14\n\ntest_input = { \"nums\": [6,2,1], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 3\n\ntest_input = { \"nums\": [6,9,8], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 17\n\ntest_input = { \"nums\": [7,1,2], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 3\n\ntest_input = { \"nums\": [7,9,1], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 10\n\ntest_input = { \"nums\": [8,5,4], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 9\n\ntest_input = { \"nums\": [9,1,6], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 7\n\ntest_input = { \"nums\": [9,3,5], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 8\n\ntest_input = { \"nums\": [57,48,69], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 117\n\ntest_input = { \"nums\": [78,37,59], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 96\n\ntest_input = { \"nums\": [96,71,53], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 124\n\ntest_input = { \"nums\": [900,914,367], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 1281\n\ntest_input = { \"nums\": [1,4,9,2], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 2\n\ntest_input = { \"nums\": [1,5,9,5], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 5\n\ntest_input = { \"nums\": [1,8,5,6], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 13\n\ntest_input = { \"nums\": [2,2,1,2], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 3\n\ntest_input = { \"nums\": [2,4,5,2], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 2\n\ntest_input = { \"nums\": [2,5,8,1], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 13\n\ntest_input = { \"nums\": [2,7,3,9], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 10\n\ntest_input = { \"nums\": [3,5,4,2], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 2\n\ntest_input = { \"nums\": [4,1,6,3], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 3\n\ntest_input = { \"nums\": [6,3,8,8], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 8\n\ntest_input = { \"nums\": [6,6,1,4], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 4\n\ntest_input = { \"nums\": [7,1,9,6], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 6\n\ntest_input = { \"nums\": [7,5,2,1], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 7\n\ntest_input = { \"nums\": [7,5,3,4], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 8\n\ntest_input = { \"nums\": [7,8,6,2], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 14\n\ntest_input = { \"nums\": [8,3,9,8], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 8\n\ntest_input = { \"nums\": [8,7,3,2], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 2\n\ntest_input = { \"nums\": [9,4,2,2], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 6\n\ntest_input = { \"nums\": [9,6,8,8], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 14\n\ntest_input = { \"nums\": [9,7,8,9], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 9\n\ntest_input = { \"nums\": [9,40,73,19], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 19\n\ntest_input = { \"nums\": [41,51,58,2], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 109\n\ntest_input = { \"nums\": [44,96,36,56], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 56\n\ntest_input = { \"nums\": [1,1,3,1,6], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 1\n\ntest_input = { \"nums\": [2,1,1,3,5], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 7\n\ntest_input = { \"nums\": [2,5,4,3,1], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 3\n\ntest_input = { \"nums\": [3,2,7,1,5], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 14\n\ntest_input = { \"nums\": [4,2,8,8,2], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 8\n\ntest_input = { \"nums\": [4,3,7,8,8], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 8\n\ntest_input = { \"nums\": [4,6,2,2,7], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 15\n\ntest_input = { \"nums\": [4,7,5,1,1], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 1\n\ntest_input = { \"nums\": [5,6,6,6,3], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 15\n\ntest_input = { \"nums\": [6,4,8,4,2], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 4\n\ntest_input = { \"nums\": [7,7,9,5,8], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 24\n\ntest_input = { \"nums\": [7,9,1,3,2], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 3\n\ntest_input = { \"nums\": [8,5,6,9,7], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 9\n\ntest_input = { \"nums\": [8,6,9,4,4], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 4\n\ntest_input = { \"nums\": [8,8,2,9,2], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 12\n\ntest_input = { \"nums\": [9,3,7,9,6], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 16\n\ntest_input = { \"nums\": [9,5,5,5,5], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 15\n\ntest_input = { \"nums\": [27,73,37,82,78], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 188\n\ntest_input = { \"nums\": [36,28,94,49,79], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 49\n\ntest_input = { \"nums\": [48,54,75,72,77], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 206\n\ntest_input = { \"nums\": [574,419,838,216,442], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 1699\n\ntest_input = { \"nums\": [1,1,1,2,5,7], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 9\n\ntest_input = { \"nums\": [2,6,6,8,6,4], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 12\n\ntest_input = { \"nums\": [2,8,2,9,2,8], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 17\n\ntest_input = { \"nums\": [2,9,1,6,5,7], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 13\n\ntest_input = { \"nums\": [2,9,1,6,6,7], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 13\n\ntest_input = { \"nums\": [3,5,4,5,8,9], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 17\n\ntest_input = { \"nums\": [5,5,3,7,9,7], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 17\n\ntest_input = { \"nums\": [5,9,4,8,7,2], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 10\n\ntest_input = { \"nums\": [5,9,6,6,4,5], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 11\n\ntest_input = { \"nums\": [6,4,7,8,4,7], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 15\n\ntest_input = { \"nums\": [6,8,6,2,7,3], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 5\n\ntest_input = { \"nums\": [7,2,5,4,4,4], \"k\": 1 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 11\n\ntest_input = { \"nums\": [7,2,9,7,8,7], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 14\n\ntest_input = { \"nums\": [7,6,6,7,6,1], \"k\": 2 }\nassert my_solution.sumIndicesWithKSetBits(**test_input) == 8", "start_time": 1694917800} +{"task_id": "weekly-contest-363-happy-students", "url": "https://leetcode.com/problems/happy-students", "title": "happy-students", "meta": {"questionId": "3104", "questionFrontendId": "2860", "title": "Happy Students", "titleSlug": "happy-students", "isPaidOnly": false, "difficulty": "Medium", "likes": 144, "dislikes": 272, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed integer array nums of length n where n is the total number of students in the class. The class teacher tries to select a group of students so that all the students remain happy.\n\nThe ith student will become happy if one of these two conditions is met:\n\n * The student is selected and the total number of selected students is strictly greater than nums[i].\n * The student is not selected and the total number of selected students is strictly less than nums[i].\n\nReturn the number of ways to select a group of students so that everyone remains happy.\n\nExample 1:\n\nInput: nums = [1,1]\nOutput: 2\nExplanation:\nThe two possible ways are:\nThe class teacher selects no student.\nThe class teacher selects both students to form the group.\nIf the class teacher selects just one student to form a group then the both students will not be happy. Therefore, there are only two possible ways.\n\nExample 2:\n\nInput: nums = [6,0,3,3,6,7,2,7]\nOutput: 3\nExplanation:\nThe three possible ways are:\nThe class teacher selects the student with index = 1 to form the group.\nThe class teacher selects the students with index = 1, 2, 3, 6 to form the group.\nThe class teacher selects all the students to form the group.\n\n\nConstraints:\n\n * 1 <= nums.length <= 105\n * 0 <= nums[i] < nums.length\n\"\"\"\nclass Solution:\n def countWays(self, nums: List[int]) -> int:\n ", "prompt_sft": "You are given a 0-indexed integer array nums of length n where n is the total number of students in the class. The class teacher tries to select a group of students so that all the students remain happy.\n\nThe ith student will become happy if one of these two conditions is met:\n\n * The student is selected and the total number of selected students is strictly greater than nums[i].\n * The student is not selected and the total number of selected students is strictly less than nums[i].\n\nReturn the number of ways to select a group of students so that everyone remains happy.\n\nExample 1:\n\nInput: nums = [1,1]\nOutput: 2\nExplanation:\nThe two possible ways are:\nThe class teacher selects no student.\nThe class teacher selects both students to form the group.\nIf the class teacher selects just one student to form a group then the both students will not be happy. Therefore, there are only two possible ways.\n\nExample 2:\n\nInput: nums = [6,0,3,3,6,7,2,7]\nOutput: 3\nExplanation:\nThe three possible ways are:\nThe class teacher selects the student with index = 1 to form the group.\nThe class teacher selects the students with index = 1, 2, 3, 6 to form the group.\nThe class teacher selects all the students to form the group.\n\n\nConstraints:\n\n * 1 <= nums.length <= 105\n * 0 <= nums[i] < nums.length\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def countWays(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,1] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [6,0,3,3,6,7,2,7] }\nassert my_solution.countWays(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,0,1] }\nassert my_solution.countWays(**test_input) == 1\n\ntest_input = { \"nums\": [5,0,3,4,2,1,2,4] }\nassert my_solution.countWays(**test_input) == 1\n\ntest_input = { \"nums\": [0,4,4,4,4,4,2] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [0,1,5,6,8,7,4,7,2] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [0] }\nassert my_solution.countWays(**test_input) == 1\n\ntest_input = { \"nums\": [2,2,7,1,2,2,4,7] }\nassert my_solution.countWays(**test_input) == 3\n\ntest_input = { \"nums\": [0,2,2,2,3,3,3,3] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [7,7,7,7,7,7,7,7,2] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [4,2,3,6,6,0,6,8,3] }\nassert my_solution.countWays(**test_input) == 3\n\ntest_input = { \"nums\": [0,0,1,7,2,0,6,5] }\nassert my_solution.countWays(**test_input) == 1\n\ntest_input = { \"nums\": [6,6,6,6,6,6,6,7,1,7] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [2,2,4,5,0,1,4,4,7] }\nassert my_solution.countWays(**test_input) == 1\n\ntest_input = { \"nums\": [4,4,4,4,4] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [0,4,0,3,4] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [6,5,5,8,4,2,6,4,8] }\nassert my_solution.countWays(**test_input) == 3\n\ntest_input = { \"nums\": [0,9,4,6,8,8,1,7,4,7] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [1,0,0] }\nassert my_solution.countWays(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,2,2,2,3,3,3,3] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [4,5,0,4,2,0,2] }\nassert my_solution.countWays(**test_input) == 1\n\ntest_input = { \"nums\": [8,1,2,1,2,1,2,4,0] }\nassert my_solution.countWays(**test_input) == 1\n\ntest_input = { \"nums\": [0,1] }\nassert my_solution.countWays(**test_input) == 1\n\ntest_input = { \"nums\": [8,4,1,8,8,7,4,5,3] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,0,2,5,5,4] }\nassert my_solution.countWays(**test_input) == 1\n\ntest_input = { \"nums\": [6,3,1,5,5,4,5] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [0,1,1,5,5,5,5,5,5] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [2,3,5,3,0,3] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [2,2,2,0,2] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,1] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [7,7,7,7,7,7,7,7,4,5] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [2,2,2,2,4] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [3,3,3,3] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [1,0] }\nassert my_solution.countWays(**test_input) == 1\n\ntest_input = { \"nums\": [6,6,6,6,6,6,6,0,4,9] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [4,4,4,4,4,5] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [2,3,2,1] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [3,3,3,3,2,2,2,2,1] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [1,5,3,0,3,6,2] }\nassert my_solution.countWays(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,1,1,1] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [0,0] }\nassert my_solution.countWays(**test_input) == 1\n\ntest_input = { \"nums\": [4,4,4,4,4,0,1] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [4,3,1,5,1,4,2,1,6] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [6,4,0,7,5,7,5,6,0] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [5,5,5,5,5,5] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [0,3,4,3,4,1] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,1,3] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [0,1,0] }\nassert my_solution.countWays(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,0] }\nassert my_solution.countWays(**test_input) == 1\n\ntest_input = { \"nums\": [1,7,6,4,1,2,1,6,4] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [2,2,2,4,4,4,4,4] }\nassert my_solution.countWays(**test_input) == 3\n\ntest_input = { \"nums\": [1,3,5,2,4,6,7,5,6] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,1,1,2,2,2,3] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [3,5,3,2,0,3,3,7] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [6,6,6,6,6,6,6] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [7,9,0,3,6,9,4,0,8,7] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [0,0,0] }\nassert my_solution.countWays(**test_input) == 1\n\ntest_input = { \"nums\": [2,2,2,2,1,3,3,6] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [2,2,2,2,2,2,6] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [5,3,9,2,4,2,1,2,8,6] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [2,2,2,0,0,6,6,2,5,4] }\nassert my_solution.countWays(**test_input) == 1\n\ntest_input = { \"nums\": [2,0,1] }\nassert my_solution.countWays(**test_input) == 1\n\ntest_input = { \"nums\": [2,2,0] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [2,2,2,2,1,0] }\nassert my_solution.countWays(**test_input) == 1\n\ntest_input = { \"nums\": [2,2,2,2,4,5,0] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [0,1,2] }\nassert my_solution.countWays(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,3,3,3,3,7,8,2] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [1,2,0,4,4] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,0,0] }\nassert my_solution.countWays(**test_input) == 1\n\ntest_input = { \"nums\": [1,7,8,7,1,0,7,3,8] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [2,2,2,1] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [1,8,6,3,3,4,3,2,3] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [8,1,6,4,1,2,2,3,3] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [2,2,2,1,1,5] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [1,3,3,3,2] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [1,3,2,3] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,2] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [0,3,6,3,0,2,3] }\nassert my_solution.countWays(**test_input) == 1\n\ntest_input = { \"nums\": [7,7,7,7,7,7,7,7,2,0] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [5,4,4,4,4,7,1,4] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [3,3,3,3,0] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [7,7,4,0,2,1,5,2] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [0,2,2] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [7,7,7,7,7,7,7,7] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [2,2,0,3] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [3,3,3,3,0,5] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [4,4,4,2,5,0] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,3,2] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [0,3,0,2,4] }\nassert my_solution.countWays(**test_input) == 1\n\ntest_input = { \"nums\": [0,3,3,3,3,1,1] }\nassert my_solution.countWays(**test_input) == 1\n\ntest_input = { \"nums\": [0,4,1,2,0,6,6] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [4,4,4,4,4,5,3,6,5,5] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [2,0,1,0] }\nassert my_solution.countWays(**test_input) == 1\n\ntest_input = { \"nums\": [0,5,5,5,5,5,5] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [0,5,4,4,3,5] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [6,6,6,6,6,6,6,2,7] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [1,5,3,7,2,3,1,2,8] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [3,3,3,3,2] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [3,3,3,3,0,2] }\nassert my_solution.countWays(**test_input) == 2\n\ntest_input = { \"nums\": [2,3,9,0,1,3,9,2,6,1] }\nassert my_solution.countWays(**test_input) == 2", "start_time": 1694917800} +{"task_id": "weekly-contest-363-maximum-number-of-alloys", "url": "https://leetcode.com/problems/maximum-number-of-alloys", "title": "maximum-number-of-alloys", "meta": {"questionId": "3095", "questionFrontendId": "2861", "title": "Maximum Number of Alloys", "titleSlug": "maximum-number-of-alloys", "isPaidOnly": false, "difficulty": "Medium", "likes": 227, "dislikes": 36, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are the owner of a company that creates alloys using various types of metals. There are n different types of metals available, and you have access to k machines that can be used to create alloys. Each machine requires a specific amount of each metal type to create an alloy.\n\nFor the ith machine to create an alloy, it needs composition[i][j] units of metal of type j. Initially, you have stock[i] units of metal type i, and purchasing one unit of metal type i costs cost[i] coins.\n\nGiven integers n, k, budget, a 1-indexed 2D array composition, and 1-indexed arrays stock and cost, your goal is to maximize the number of alloys the company can create while staying within the budget of budget coins.\n\nAll alloys must be created with the same machine.\n\nReturn the maximum number of alloys that the company can create.\n\nExample 1:\n\nInput: n = 3, k = 2, budget = 15, composition = [[1,1,1],[1,1,10]], stock = [0,0,0], cost = [1,2,3]\nOutput: 2\nExplanation: It is optimal to use the 1st machine to create alloys.\nTo create 2 alloys we need to buy the:\n- 2 units of metal of the 1st type.\n- 2 units of metal of the 2nd type.\n- 2 units of metal of the 3rd type.\nIn total, we need 2 * 1 + 2 * 2 + 2 * 3 = 12 coins, which is smaller than or equal to budget = 15.\nNotice that we have 0 units of metal of each type and we have to buy all the required units of metal.\nIt can be proven that we can create at most 2 alloys.\n\nExample 2:\n\nInput: n = 3, k = 2, budget = 15, composition = [[1,1,1],[1,1,10]], stock = [0,0,100], cost = [1,2,3]\nOutput: 5\nExplanation: It is optimal to use the 2nd machine to create alloys.\nTo create 5 alloys we need to buy:\n- 5 units of metal of the 1st type.\n- 5 units of metal of the 2nd type.\n- 0 units of metal of the 3rd type.\nIn total, we need 5 * 1 + 5 * 2 + 0 * 3 = 15 coins, which is smaller than or equal to budget = 15.\nIt can be proven that we can create at most 5 alloys.\n\nExample 3:\n\nInput: n = 2, k = 3, budget = 10, composition = [[2,1],[1,2],[1,1]], stock = [1,1], cost = [5,5]\nOutput: 2\nExplanation: It is optimal to use the 3rd machine to create alloys.\nTo create 2 alloys we need to buy the:\n- 1 unit of metal of the 1st type.\n- 1 unit of metal of the 2nd type.\nIn total, we need 1 * 5 + 1 * 5 = 10 coins, which is smaller than or equal to budget = 10.\nIt can be proven that we can create at most 2 alloys.\n\n\nConstraints:\n\n * 1 <= n, k <= 100\n * 0 <= budget <= 108\n * composition.length == k\n * composition[i].length == n\n * 1 <= composition[i][j] <= 100\n * stock.length == cost.length == n\n * 0 <= stock[i] <= 108\n * 1 <= cost[i] <= 100\n\"\"\"\nclass Solution:\n def maxNumberOfAlloys(self, n: int, k: int, budget: int, composition: List[List[int]], stock: List[int], cost: List[int]) -> int:\n ", "prompt_sft": "You are the owner of a company that creates alloys using various types of metals. There are n different types of metals available, and you have access to k machines that can be used to create alloys. Each machine requires a specific amount of each metal type to create an alloy.\n\nFor the ith machine to create an alloy, it needs composition[i][j] units of metal of type j. Initially, you have stock[i] units of metal type i, and purchasing one unit of metal type i costs cost[i] coins.\n\nGiven integers n, k, budget, a 1-indexed 2D array composition, and 1-indexed arrays stock and cost, your goal is to maximize the number of alloys the company can create while staying within the budget of budget coins.\n\nAll alloys must be created with the same machine.\n\nReturn the maximum number of alloys that the company can create.\n\nExample 1:\n\nInput: n = 3, k = 2, budget = 15, composition = [[1,1,1],[1,1,10]], stock = [0,0,0], cost = [1,2,3]\nOutput: 2\nExplanation: It is optimal to use the 1st machine to create alloys.\nTo create 2 alloys we need to buy the:\n- 2 units of metal of the 1st type.\n- 2 units of metal of the 2nd type.\n- 2 units of metal of the 3rd type.\nIn total, we need 2 * 1 + 2 * 2 + 2 * 3 = 12 coins, which is smaller than or equal to budget = 15.\nNotice that we have 0 units of metal of each type and we have to buy all the required units of metal.\nIt can be proven that we can create at most 2 alloys.\n\nExample 2:\n\nInput: n = 3, k = 2, budget = 15, composition = [[1,1,1],[1,1,10]], stock = [0,0,100], cost = [1,2,3]\nOutput: 5\nExplanation: It is optimal to use the 2nd machine to create alloys.\nTo create 5 alloys we need to buy:\n- 5 units of metal of the 1st type.\n- 5 units of metal of the 2nd type.\n- 0 units of metal of the 3rd type.\nIn total, we need 5 * 1 + 5 * 2 + 0 * 3 = 15 coins, which is smaller than or equal to budget = 15.\nIt can be proven that we can create at most 5 alloys.\n\nExample 3:\n\nInput: n = 2, k = 3, budget = 10, composition = [[2,1],[1,2],[1,1]], stock = [1,1], cost = [5,5]\nOutput: 2\nExplanation: It is optimal to use the 3rd machine to create alloys.\nTo create 2 alloys we need to buy the:\n- 1 unit of metal of the 1st type.\n- 1 unit of metal of the 2nd type.\nIn total, we need 1 * 5 + 1 * 5 = 10 coins, which is smaller than or equal to budget = 10.\nIt can be proven that we can create at most 2 alloys.\n\n\nConstraints:\n\n * 1 <= n, k <= 100\n * 0 <= budget <= 108\n * composition.length == k\n * composition[i].length == n\n * 1 <= composition[i][j] <= 100\n * stock.length == cost.length == n\n * 0 <= stock[i] <= 108\n * 1 <= cost[i] <= 100\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def maxNumberOfAlloys(self, n: int, k: int, budget: int, composition: List[List[int]], stock: List[int], cost: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"n\": 3, \"k\": 2, \"budget\": 15, \"composition\": [[1,1,1],[1,1,10]], \"stock\": [0,0,0], \"cost\": [1,2,3] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 2\n\ntest_input = { \"n\": 3, \"k\": 2, \"budget\": 15, \"composition\": [[1,1,1],[1,1,10]], \"stock\": [0,0,100], \"cost\": [1,2,3] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 5\n\ntest_input = { \"n\": 2, \"k\": 3, \"budget\": 10, \"composition\": [[2,1],[1,2],[1,1]], \"stock\": [1,1], \"cost\": [5,5] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 2\n\ntest_input = { \"n\": 4, \"k\": 4, \"budget\": 17, \"composition\": [[10,10,1,5],[9,7,7,1],[6,3,5,9],[2,10,2,7]], \"stock\": [9,8,2,7], \"cost\": [9,2,6,10] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 4, \"k\": 9, \"budget\": 55, \"composition\": [[8,3,4,2],[3,9,5,5],[1,7,9,8],[7,6,5,1],[4,6,9,4],[6,8,7,1],[5,10,3,4],[10,1,2,4],[10,3,7,2]], \"stock\": [9,1,10,0], \"cost\": [3,4,9,9] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 10, \"k\": 10, \"budget\": 142, \"composition\": [[5,3,7,3,5,5,1,6,4,3],[4,8,10,8,8,3,10,6,3,8],[10,2,5,10,9,2,8,5,10,7],[10,8,8,8,10,8,9,6,1,8],[6,2,2,3,6,3,1,10,5,8],[10,7,3,10,7,6,6,10,4,5],[10,2,8,10,1,8,7,6,6,7],[4,1,9,6,8,8,7,1,1,4],[10,9,1,2,6,4,6,8,9,4],[5,6,7,2,7,10,7,8,3,5]], \"stock\": [0,6,3,0,0,8,1,2,8,6], \"cost\": [2,2,2,7,4,2,10,8,9,8] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 9, \"k\": 3, \"budget\": 90, \"composition\": [[10,9,1,3,3,5,5,10,7],[2,6,4,9,9,1,9,6,7],[1,4,7,6,7,7,10,6,6]], \"stock\": [3,10,10,8,10,5,7,1,2], \"cost\": [9,8,10,9,9,3,9,5,8] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 8, \"k\": 4, \"budget\": 196, \"composition\": [[5,2,3,4,7,3,3,1],[1,5,9,9,6,1,9,7],[5,8,3,10,2,4,8,7],[9,9,5,9,6,8,4,3]], \"stock\": [3,5,3,6,1,5,8,1], \"cost\": [4,5,4,9,4,8,7,5] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 2\n\ntest_input = { \"n\": 2, \"k\": 5, \"budget\": 48, \"composition\": [[6,3],[9,5],[1,9],[1,8],[3,3]], \"stock\": [4,8], \"cost\": [10,1] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 5\n\ntest_input = { \"n\": 3, \"k\": 8, \"budget\": 50, \"composition\": [[10,8,5],[9,8,8],[2,3,1],[6,2,7],[5,5,3],[3,5,6],[8,2,9],[10,2,1]], \"stock\": [3,9,5], \"cost\": [1,10,6] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 4\n\ntest_input = { \"n\": 6, \"k\": 1, \"budget\": 195, \"composition\": [[4,7,7,9,6,9]], \"stock\": [7,4,1,4,4,0], \"cost\": [6,6,9,10,7,9] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 0\n\ntest_input = { \"n\": 10, \"k\": 4, \"budget\": 149, \"composition\": [[9,10,1,7,6,4,9,5,7,8],[9,7,2,10,7,9,10,10,1,8],[1,10,9,3,5,6,6,1,8,4],[9,6,2,3,9,10,6,8,7,3]], \"stock\": [5,0,7,5,7,8,2,2,6,10], \"cost\": [7,5,3,3,10,9,9,3,6,8] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 5, \"k\": 3, \"budget\": 110, \"composition\": [[5,8,9,3,10],[10,10,2,1,9],[7,8,2,3,4]], \"stock\": [7,3,4,8,4], \"cost\": [2,2,6,5,7] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 2\n\ntest_input = { \"n\": 2, \"k\": 3, \"budget\": 12, \"composition\": [[5,9],[7,8],[1,1]], \"stock\": [0,9], \"cost\": [8,5] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 9, \"k\": 5, \"budget\": 172, \"composition\": [[8,8,7,6,5,3,6,10,8],[9,5,4,5,9,9,2,8,5],[1,9,7,8,4,10,5,1,2],[10,10,4,4,5,5,5,5,9],[7,10,4,7,9,6,3,1,8]], \"stock\": [5,0,10,0,0,8,10,9,8], \"cost\": [3,7,6,10,10,5,2,10,6] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 0\n\ntest_input = { \"n\": 7, \"k\": 10, \"budget\": 31, \"composition\": [[10,6,2,1,6,3,9],[9,7,1,4,3,3,6],[4,8,3,10,7,2,10],[8,1,3,3,9,3,6],[6,3,2,4,9,7,5],[4,2,10,2,9,8,2],[9,3,6,1,3,8,1],[9,5,6,9,4,10,3],[1,8,8,2,5,4,10],[1,6,6,6,10,6,4]], \"stock\": [3,9,10,4,4,8,9], \"cost\": [6,6,9,2,1,9,6] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 4, \"k\": 9, \"budget\": 103, \"composition\": [[5,9,6,3],[1,5,7,5],[5,4,10,6],[2,2,4,6],[1,1,2,2],[10,6,5,4],[9,7,8,9],[3,7,8,2],[8,2,4,4]], \"stock\": [7,7,7,3], \"cost\": [4,7,6,10] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 5\n\ntest_input = { \"n\": 10, \"k\": 1, \"budget\": 197, \"composition\": [[7,6,6,1,2,4,8,6,4,10]], \"stock\": [1,3,2,1,3,4,2,6,1,1], \"cost\": [10,6,2,1,6,2,6,5,9,8] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 0\n\ntest_input = { \"n\": 10, \"k\": 4, \"budget\": 152, \"composition\": [[1,7,1,3,9,6,8,9,10,4],[8,8,9,3,10,10,4,3,2,2],[3,6,4,6,1,9,4,1,4,5],[2,5,1,8,3,10,6,3,8,4]], \"stock\": [7,2,9,6,9,4,6,6,3,6], \"cost\": [8,2,3,9,1,10,1,9,5,4] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 6, \"k\": 9, \"budget\": 72, \"composition\": [[1,10,8,5,4,3],[6,7,3,6,10,3],[10,9,8,6,2,10],[8,9,10,7,9,10],[2,7,2,7,6,9],[4,2,8,2,7,9],[2,1,1,8,8,9],[5,7,1,7,3,5],[4,4,4,3,10,4]], \"stock\": [3,3,1,6,10,8], \"cost\": [1,8,9,8,3,3] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 10, \"budget\": 177, \"composition\": [[6],[3],[8],[8],[7],[7],[4],[5],[10],[1]], \"stock\": [2], \"cost\": [7] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 27\n\ntest_input = { \"n\": 2, \"k\": 6, \"budget\": 196, \"composition\": [[6,5],[7,10],[3,10],[5,8],[5,7],[5,6]], \"stock\": [6,3], \"cost\": [3,4] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 5\n\ntest_input = { \"n\": 7, \"k\": 9, \"budget\": 148, \"composition\": [[5,8,7,7,5,8,4],[8,6,2,6,3,3,2],[5,6,9,6,6,2,5],[8,2,10,5,4,5,10],[2,8,10,4,9,6,1],[4,1,2,2,5,5,5],[9,9,1,4,1,4,4],[3,8,4,4,10,4,6],[8,2,8,4,5,5,10]], \"stock\": [7,8,7,9,3,8,2], \"cost\": [7,5,4,5,1,3,10] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 2\n\ntest_input = { \"n\": 8, \"k\": 5, \"budget\": 151, \"composition\": [[5,9,10,2,8,10,2,8],[1,5,8,9,3,4,6,6],[10,10,10,6,1,7,9,4],[6,7,6,2,10,8,6,10],[5,2,6,2,8,1,6,2]], \"stock\": [0,6,2,2,9,8,0,3], \"cost\": [6,7,4,6,10,3,5,1] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 8, \"k\": 3, \"budget\": 187, \"composition\": [[1,4,8,6,8,5,1,4],[10,9,4,3,1,2,5,9],[4,10,7,8,7,7,1,9]], \"stock\": [2,6,4,0,2,8,2,3], \"cost\": [9,2,5,7,6,10,2,7] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 3, \"budget\": 90, \"composition\": [[5],[3],[9]], \"stock\": [5], \"cost\": [10] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 4\n\ntest_input = { \"n\": 10, \"k\": 5, \"budget\": 91, \"composition\": [[7,8,3,2,9,3,4,4,2,3],[3,2,4,1,4,5,10,9,10,7],[1,4,3,4,9,5,2,2,9,9],[6,9,9,6,2,7,1,10,5,3],[10,7,8,2,2,2,9,6,1,4]], \"stock\": [9,5,5,0,0,8,1,4,5,3], \"cost\": [7,3,6,4,10,10,5,4,2,1] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 0\n\ntest_input = { \"n\": 8, \"k\": 3, \"budget\": 97, \"composition\": [[3,3,7,1,5,5,8,2],[10,5,1,3,1,5,1,5],[7,2,2,10,7,10,6,8]], \"stock\": [1,1,8,3,0,1,0,6], \"cost\": [4,1,4,5,5,3,5,4] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 9, \"k\": 3, \"budget\": 19, \"composition\": [[5,9,4,6,6,1,4,5,3],[6,9,2,3,5,4,1,4,5],[6,10,5,4,7,5,3,4,3]], \"stock\": [8,7,6,3,4,7,7,0,4], \"cost\": [10,8,1,6,9,7,3,7,3] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 0\n\ntest_input = { \"n\": 8, \"k\": 2, \"budget\": 168, \"composition\": [[5,7,8,6,7,4,10,8],[3,7,7,4,8,9,9,9]], \"stock\": [6,4,5,10,2,5,3,8], \"cost\": [5,1,10,3,4,4,7,4] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 3, \"k\": 3, \"budget\": 108, \"composition\": [[6,1,10],[5,3,6],[2,8,7]], \"stock\": [3,9,7], \"cost\": [4,2,3] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 3\n\ntest_input = { \"n\": 10, \"k\": 5, \"budget\": 197, \"composition\": [[7,2,9,6,2,3,8,9,10,10],[2,1,7,7,3,1,3,8,1,2],[4,5,1,3,6,3,2,4,4,6],[8,5,9,10,8,3,7,10,1,7],[8,3,2,4,1,5,3,6,9,6]], \"stock\": [5,2,9,8,1,3,6,4,2,3], \"cost\": [6,6,10,4,9,5,2,6,4,6] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 2\n\ntest_input = { \"n\": 8, \"k\": 8, \"budget\": 90, \"composition\": [[6,6,9,7,6,7,7,5],[5,10,4,2,8,5,6,6],[7,7,1,10,3,3,2,2],[7,9,8,10,7,10,8,2],[7,1,2,2,1,2,3,6],[2,8,10,10,6,2,6,3],[3,2,2,2,4,7,4,3],[2,5,3,2,3,7,6,4]], \"stock\": [1,1,6,10,3,0,8,6], \"cost\": [3,2,1,3,2,3,8,7] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 2\n\ntest_input = { \"n\": 4, \"k\": 7, \"budget\": 87, \"composition\": [[8,8,5,3],[7,8,8,9],[1,7,3,10],[4,3,9,8],[4,7,2,2],[5,8,2,2],[6,1,2,7]], \"stock\": [3,7,9,8], \"cost\": [6,3,1,4] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 2\n\ntest_input = { \"n\": 2, \"k\": 3, \"budget\": 184, \"composition\": [[7,1],[6,7],[4,6]], \"stock\": [1,6], \"cost\": [8,2] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 4\n\ntest_input = { \"n\": 4, \"k\": 3, \"budget\": 25, \"composition\": [[7,4,5,3],[10,8,1,2],[6,4,3,4]], \"stock\": [1,3,0,5], \"cost\": [1,2,6,4] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 10, \"k\": 8, \"budget\": 33, \"composition\": [[3,2,9,8,3,7,10,2,6,7],[6,6,5,6,3,3,4,6,5,7],[6,8,5,10,8,4,1,8,4,2],[7,10,7,10,4,4,10,7,5,3],[2,6,3,3,8,8,2,6,4,2],[2,2,2,4,8,2,7,3,7,4],[10,9,7,9,9,2,3,9,2,1],[8,9,10,7,10,9,7,2,3,8]], \"stock\": [0,2,5,5,8,2,5,9,1,1], \"cost\": [3,4,10,5,8,8,8,9,8,7] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 0\n\ntest_input = { \"n\": 7, \"k\": 9, \"budget\": 8, \"composition\": [[5,4,8,9,2,2,2],[2,8,7,6,8,10,3],[6,8,4,4,5,4,10],[5,3,7,8,2,2,9],[8,4,3,2,6,4,3],[5,2,8,5,4,5,10],[9,5,4,9,6,5,7],[10,1,6,7,2,7,5],[3,6,9,9,3,7,6]], \"stock\": [3,9,1,5,1,7,9], \"cost\": [5,7,1,6,8,3,9] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 0\n\ntest_input = { \"n\": 1, \"k\": 3, \"budget\": 96, \"composition\": [[4],[8],[3]], \"stock\": [0], \"cost\": [6] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 5\n\ntest_input = { \"n\": 4, \"k\": 2, \"budget\": 113, \"composition\": [[6,9,5,7],[4,9,7,1]], \"stock\": [4,1,0,4], \"cost\": [9,2,3,5] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 2\n\ntest_input = { \"n\": 6, \"k\": 6, \"budget\": 97, \"composition\": [[9,3,10,2,6,3],[9,4,3,7,1,7],[10,10,9,2,1,6],[4,5,2,3,3,10],[2,6,8,3,6,1],[4,9,6,10,3,10]], \"stock\": [2,8,10,8,9,0], \"cost\": [4,5,6,3,10,1] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 2\n\ntest_input = { \"n\": 9, \"k\": 6, \"budget\": 18, \"composition\": [[5,10,2,4,3,3,2,10,3],[2,7,1,7,10,7,8,8,7],[6,2,10,2,4,3,4,8,9],[5,7,2,10,6,10,4,10,3],[1,9,4,4,9,9,4,2,6],[7,5,1,4,10,9,2,2,3]], \"stock\": [5,4,0,1,1,6,1,8,0], \"cost\": [8,1,6,5,10,4,10,9,7] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 0\n\ntest_input = { \"n\": 2, \"k\": 10, \"budget\": 197, \"composition\": [[8,1],[7,4],[2,3],[10,3],[6,3],[9,8],[8,7],[3,4],[2,6],[4,5]], \"stock\": [5,9], \"cost\": [10,2] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 10\n\ntest_input = { \"n\": 10, \"k\": 4, \"budget\": 115, \"composition\": [[4,6,5,10,9,5,2,2,10,1],[6,7,2,2,4,10,3,8,3,7],[1,9,10,5,4,6,2,1,8,4],[7,10,9,5,10,6,9,5,8,4]], \"stock\": [7,8,8,8,6,10,7,8,2,3], \"cost\": [3,5,1,8,7,7,10,4,7,8] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 6, \"k\": 3, \"budget\": 168, \"composition\": [[1,2,10,5,5,8],[1,3,6,1,3,6],[8,5,6,6,5,10]], \"stock\": [7,0,3,1,6,8], \"cost\": [5,6,2,5,3,1] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 4\n\ntest_input = { \"n\": 4, \"k\": 1, \"budget\": 13, \"composition\": [[6,10,1,10]], \"stock\": [2,9,7,3], \"cost\": [7,8,5,5] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 0\n\ntest_input = { \"n\": 1, \"k\": 3, \"budget\": 144, \"composition\": [[4],[10],[9]], \"stock\": [10], \"cost\": [1] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 38\n\ntest_input = { \"n\": 8, \"k\": 4, \"budget\": 34, \"composition\": [[9,1,1,9,1,10,6,4],[10,8,6,5,7,5,2,9],[7,4,5,10,7,2,6,2],[3,8,3,6,9,9,10,5]], \"stock\": [9,9,6,5,5,7,5,4], \"cost\": [7,4,2,2,8,10,10,4] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 0\n\ntest_input = { \"n\": 10, \"k\": 3, \"budget\": 64, \"composition\": [[7,2,7,4,4,6,8,3,5,6],[10,10,6,5,4,7,5,1,3,2],[10,10,8,4,6,8,9,1,8,10]], \"stock\": [8,9,7,3,10,6,6,0,6,10], \"cost\": [7,8,4,6,9,7,7,8,2,9] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 9, \"k\": 5, \"budget\": 37, \"composition\": [[7,5,8,5,3,1,4,10,6],[4,5,5,5,7,4,2,8,1],[3,8,3,6,7,9,10,2,7],[5,3,5,1,10,3,4,10,6],[6,2,9,3,10,6,3,9,7]], \"stock\": [1,4,1,7,10,8,8,3,6], \"cost\": [7,4,2,7,3,10,9,8,10] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 0\n\ntest_input = { \"n\": 3, \"k\": 10, \"budget\": 67, \"composition\": [[5,3,10],[7,5,4],[3,9,9],[10,2,9],[9,4,8],[8,5,7],[5,2,3],[1,7,2],[3,9,1],[7,1,4]], \"stock\": [2,9,4], \"cost\": [4,9,1] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 3\n\ntest_input = { \"n\": 4, \"k\": 7, \"budget\": 113, \"composition\": [[6,10,4,10],[7,8,1,1],[1,5,4,1],[4,7,8,9],[7,9,2,4],[5,1,10,4],[3,3,9,4]], \"stock\": [0,5,5,10], \"cost\": [1,10,8,4] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 2\n\ntest_input = { \"n\": 10, \"k\": 7, \"budget\": 128, \"composition\": [[5,1,1,4,5,9,2,9,2,2],[6,10,4,8,3,10,8,4,5,10],[3,3,8,5,2,6,4,5,4,8],[5,5,4,1,3,2,10,5,3,10],[9,4,2,4,2,4,7,7,1,4],[9,2,10,5,1,5,5,9,5,6],[10,7,9,1,4,7,6,7,5,7]], \"stock\": [3,8,4,5,3,5,4,10,4,9], \"cost\": [4,1,8,4,2,9,1,2,1,10] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 2\n\ntest_input = { \"n\": 1, \"k\": 7, \"budget\": 48, \"composition\": [[1],[5],[9],[6],[4],[2],[4]], \"stock\": [6], \"cost\": [1] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 54\n\ntest_input = { \"n\": 9, \"k\": 4, \"budget\": 21, \"composition\": [[7,2,7,7,8,1,6,7,3],[8,10,4,3,7,2,3,2,5],[6,9,3,2,7,6,10,6,5],[10,2,4,10,7,9,5,8,6]], \"stock\": [9,10,5,2,10,9,8,10,10], \"cost\": [6,5,2,8,10,1,2,7,1] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 8, \"k\": 8, \"budget\": 164, \"composition\": [[8,8,7,7,4,8,8,3],[8,1,5,9,4,5,10,8],[6,3,7,5,5,5,8,7],[7,1,6,2,6,10,5,6],[9,10,1,10,3,8,9,9],[1,5,5,4,5,10,5,9],[8,3,5,3,5,4,7,1],[10,2,3,6,2,4,8,6]], \"stock\": [10,3,10,2,1,4,8,8], \"cost\": [2,9,7,7,4,3,2,10] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 2\n\ntest_input = { \"n\": 1, \"k\": 6, \"budget\": 149, \"composition\": [[4],[8],[1],[9],[1],[9]], \"stock\": [6], \"cost\": [7] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 27\n\ntest_input = { \"n\": 6, \"k\": 7, \"budget\": 136, \"composition\": [[8,9,8,5,9,8],[4,2,1,9,3,8],[6,8,3,1,9,9],[8,1,4,5,2,7],[4,5,6,3,4,9],[5,9,8,2,1,10],[10,10,9,9,2,8]], \"stock\": [4,1,2,9,9,2], \"cost\": [8,1,7,8,1,1] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 2\n\ntest_input = { \"n\": 6, \"k\": 1, \"budget\": 55, \"composition\": [[3,5,3,8,9,8]], \"stock\": [9,7,0,1,9,4], \"cost\": [3,3,1,1,1,2] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 3, \"k\": 1, \"budget\": 195, \"composition\": [[7,3,7]], \"stock\": [0,10,7], \"cost\": [7,6,10] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 2\n\ntest_input = { \"n\": 1, \"k\": 8, \"budget\": 69, \"composition\": [[8],[9],[10],[10],[4],[4],[7],[6]], \"stock\": [10], \"cost\": [9] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 4\n\ntest_input = { \"n\": 9, \"k\": 2, \"budget\": 176, \"composition\": [[8,10,1,2,6,3,5,7,7],[4,6,4,8,4,5,3,6,6]], \"stock\": [10,9,1,3,10,1,10,5,2], \"cost\": [3,8,8,2,5,6,5,8,1] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 8, \"k\": 3, \"budget\": 17, \"composition\": [[3,1,4,8,7,8,5,5],[7,10,6,6,3,10,10,9],[5,6,7,1,4,7,5,1]], \"stock\": [0,4,0,4,4,9,2,1], \"cost\": [10,1,3,9,9,3,1,10] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 0\n\ntest_input = { \"n\": 1, \"k\": 9, \"budget\": 109, \"composition\": [[8],[10],[4],[3],[9],[7],[9],[8],[7]], \"stock\": [10], \"cost\": [9] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 7\n\ntest_input = { \"n\": 7, \"k\": 6, \"budget\": 130, \"composition\": [[4,2,10,2,2,9,4],[9,4,8,8,4,9,9],[9,10,7,8,7,1,4],[8,2,5,5,6,4,7],[9,8,4,3,8,6,2],[1,2,3,9,4,10,1]], \"stock\": [10,1,7,10,1,10,5], \"cost\": [3,7,6,5,1,5,7] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 2\n\ntest_input = { \"n\": 1, \"k\": 8, \"budget\": 48, \"composition\": [[5],[6],[10],[9],[2],[8],[9],[8]], \"stock\": [9], \"cost\": [5] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 9\n\ntest_input = { \"n\": 10, \"k\": 3, \"budget\": 124, \"composition\": [[5,8,7,1,7,7,5,4,5,2],[9,1,2,8,2,8,3,5,2,4],[7,4,6,4,4,2,4,10,4,8]], \"stock\": [9,8,7,0,9,1,4,3,1,1], \"cost\": [9,3,5,4,3,5,2,10,7,4] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 7, \"k\": 10, \"budget\": 177, \"composition\": [[1,8,4,1,9,7,4],[8,1,3,3,9,4,5],[8,5,4,2,9,9,10],[2,10,3,3,3,10,8],[6,3,1,3,7,1,7],[3,5,7,6,8,10,10],[2,10,10,2,2,7,7],[3,2,10,9,4,1,2],[2,7,1,8,2,7,10],[10,9,2,8,10,1,4]], \"stock\": [0,3,5,10,0,9,9], \"cost\": [3,5,4,8,10,1,2] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 6, \"k\": 3, \"budget\": 135, \"composition\": [[7,8,3,4,10,5],[6,5,10,3,1,1],[5,2,9,9,8,1]], \"stock\": [10,0,5,1,0,7], \"cost\": [3,10,3,3,3,8] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 10, \"k\": 1, \"budget\": 131, \"composition\": [[10,2,8,4,3,6,10,8,8,6]], \"stock\": [1,7,10,1,4,8,4,6,7,0], \"cost\": [1,10,9,3,9,8,3,2,9,6] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 10, \"k\": 7, \"budget\": 79, \"composition\": [[3,8,9,10,7,3,8,4,2,2],[7,9,1,1,2,1,8,7,5,7],[5,9,6,2,9,4,10,1,8,5],[4,3,7,2,4,7,4,6,2,10],[4,5,2,5,5,2,7,7,1,8],[9,2,9,4,9,4,7,3,4,4],[8,4,10,8,2,8,7,5,6,10]], \"stock\": [0,4,5,5,7,9,9,7,3,0], \"cost\": [10,8,1,2,7,7,4,7,6,6] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 0\n\ntest_input = { \"n\": 8, \"k\": 7, \"budget\": 86, \"composition\": [[10,5,6,8,9,10,6,5],[7,8,9,9,3,3,9,4],[5,4,4,4,10,2,6,3],[9,7,1,10,10,4,4,6],[10,9,10,3,4,2,9,4],[2,1,4,8,3,6,4,1],[1,8,2,2,3,3,10,8]], \"stock\": [0,6,0,5,6,0,10,1], \"cost\": [7,9,10,10,5,5,7,1] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 6, \"k\": 8, \"budget\": 48, \"composition\": [[10,2,1,4,9,1],[5,10,6,3,3,9],[10,10,10,9,2,9],[1,5,2,2,10,9],[7,9,10,5,10,3],[3,3,10,5,6,2],[6,6,6,8,9,9],[2,4,2,7,3,3]], \"stock\": [5,6,5,1,3,5], \"cost\": [4,3,8,6,1,7] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 2, \"k\": 8, \"budget\": 44, \"composition\": [[8,5],[1,6],[3,10],[4,6],[5,8],[10,5],[7,5],[5,1]], \"stock\": [8,0], \"cost\": [8,6] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 2\n\ntest_input = { \"n\": 9, \"k\": 3, \"budget\": 107, \"composition\": [[8,1,9,10,10,5,4,9,1],[8,10,6,8,10,2,10,9,4],[9,6,4,7,10,2,7,4,2]], \"stock\": [9,2,4,1,1,3,8,9,0], \"cost\": [6,2,8,3,1,3,5,9,9] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 3, \"k\": 5, \"budget\": 125, \"composition\": [[10,8,9],[10,7,8],[7,7,6],[9,2,5],[8,4,6]], \"stock\": [8,3,1], \"cost\": [4,10,10] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 6, \"k\": 10, \"budget\": 118, \"composition\": [[10,7,8,10,5,9],[2,4,4,5,4,2],[6,7,2,6,3,10],[3,8,10,8,1,6],[2,9,3,8,5,5],[1,6,8,1,7,7],[4,9,1,8,9,5],[9,4,10,4,1,4],[1,5,10,2,5,3],[2,1,3,3,2,9]], \"stock\": [9,6,2,2,6,5], \"cost\": [2,1,7,5,10,9] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 2\n\ntest_input = { \"n\": 1, \"k\": 2, \"budget\": 148, \"composition\": [[1],[8]], \"stock\": [4], \"cost\": [2] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 78\n\ntest_input = { \"n\": 5, \"k\": 5, \"budget\": 91, \"composition\": [[2,4,10,5,5],[4,3,8,8,10],[9,6,2,7,3],[7,7,3,6,6],[6,4,5,3,4]], \"stock\": [6,4,7,3,3], \"cost\": [4,10,9,7,3] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 8, \"k\": 5, \"budget\": 143, \"composition\": [[8,3,3,6,2,5,8,9],[6,8,3,6,4,10,10,6],[9,6,10,9,6,5,1,1],[1,1,10,3,4,10,2,2],[10,6,4,9,9,3,9,2]], \"stock\": [2,1,4,5,6,8,2,8], \"cost\": [1,8,3,9,9,7,1,8] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 4, \"k\": 9, \"budget\": 172, \"composition\": [[9,2,2,2],[4,5,3,2],[4,6,1,9],[5,3,3,5],[2,4,3,9],[7,4,4,3],[1,3,2,6],[7,2,5,4],[4,4,2,2]], \"stock\": [6,7,5,2], \"cost\": [2,8,5,2] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 5\n\ntest_input = { \"n\": 5, \"k\": 2, \"budget\": 110, \"composition\": [[2,8,10,7,4],[5,3,5,5,5]], \"stock\": [6,8,8,1,6], \"cost\": [8,5,8,6,7] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 3, \"k\": 10, \"budget\": 21, \"composition\": [[9,8,5],[2,9,9],[2,6,8],[7,4,10],[10,8,6],[2,6,5],[6,6,8],[4,7,7],[8,9,10],[6,1,7]], \"stock\": [6,4,10], \"cost\": [7,9,4] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 5, \"k\": 1, \"budget\": 176, \"composition\": [[5,6,2,5,4]], \"stock\": [1,4,3,10,7], \"cost\": [10,9,9,8,10] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 9, \"k\": 1, \"budget\": 112, \"composition\": [[10,4,3,5,2,10,10,8,9]], \"stock\": [4,4,3,0,5,0,7,6,2], \"cost\": [7,9,8,9,2,6,10,5,5] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 0\n\ntest_input = { \"n\": 8, \"k\": 9, \"budget\": 41, \"composition\": [[10,6,7,3,6,9,9,8],[5,9,5,2,4,10,2,5],[4,10,9,3,5,10,7,1],[8,3,1,4,2,5,3,1],[1,10,10,10,7,1,10,4],[6,9,7,10,8,7,6,9],[4,9,10,4,10,7,1,7],[3,5,9,5,2,8,3,10],[8,7,1,9,3,8,6,3]], \"stock\": [5,4,10,10,7,8,7,6], \"cost\": [5,1,10,4,9,9,4,6] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 2, \"k\": 10, \"budget\": 2, \"composition\": [[9,6],[10,1],[7,3],[5,5],[7,6],[10,2],[7,3],[7,6],[7,3],[2,7]], \"stock\": [6,10], \"cost\": [1,4] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 2, \"k\": 7, \"budget\": 168, \"composition\": [[8,2],[4,7],[8,3],[1,6],[3,3],[9,7],[8,4]], \"stock\": [1,7], \"cost\": [5,3] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 8\n\ntest_input = { \"n\": 8, \"k\": 9, \"budget\": 195, \"composition\": [[2,5,4,2,2,4,4,1],[5,4,5,8,9,1,2,5],[1,10,3,9,6,7,1,3],[4,10,3,3,6,4,7,6],[4,3,10,2,7,8,4,9],[4,1,6,2,8,7,3,3],[10,7,5,2,1,5,4,5],[7,4,3,10,4,10,1,2],[9,7,9,8,9,2,3,10]], \"stock\": [1,1,7,10,1,6,3,9], \"cost\": [1,4,7,6,4,5,5,2] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 3\n\ntest_input = { \"n\": 7, \"k\": 6, \"budget\": 167, \"composition\": [[2,2,3,4,6,2,4],[5,7,3,7,4,6,7],[5,7,4,10,5,1,1],[2,3,10,6,9,5,6],[3,9,7,8,5,10,2],[6,7,8,8,1,6,6]], \"stock\": [10,10,8,9,7,8,4], \"cost\": [2,6,1,9,9,9,8] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 2\n\ntest_input = { \"n\": 6, \"k\": 9, \"budget\": 73, \"composition\": [[1,1,9,4,1,7],[6,8,7,7,6,2],[2,1,5,10,2,5],[3,10,7,7,5,10],[6,1,6,8,4,6],[3,10,10,9,8,2],[10,8,7,7,4,2],[10,2,3,8,7,4],[7,5,9,10,4,3]], \"stock\": [1,9,8,6,10,6], \"cost\": [6,3,9,7,1,4] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 5, \"k\": 3, \"budget\": 128, \"composition\": [[4,6,5,5,1],[1,4,8,8,7],[3,3,5,4,5]], \"stock\": [6,8,8,0,2], \"cost\": [2,4,9,7,6] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 2\n\ntest_input = { \"n\": 10, \"k\": 7, \"budget\": 96, \"composition\": [[9,3,10,2,8,6,1,7,2,4],[2,10,4,5,5,3,7,5,2,10],[8,7,7,10,6,6,3,2,3,8],[8,1,5,4,7,8,1,9,2,10],[6,7,10,9,8,8,8,3,1,2],[1,6,9,1,8,4,9,4,9,7],[5,6,5,2,1,8,9,4,3,6]], \"stock\": [4,6,3,0,7,0,7,10,8,10], \"cost\": [4,3,6,5,6,2,7,3,1,3] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 5, \"k\": 9, \"budget\": 81, \"composition\": [[4,4,9,5,5],[7,9,10,6,8],[4,7,4,2,10],[2,9,6,9,8],[2,5,7,3,4],[4,9,9,2,5],[5,6,1,2,9],[5,3,8,7,8],[8,6,9,9,3]], \"stock\": [2,9,6,5,3], \"cost\": [3,3,8,7,6] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 10, \"k\": 10, \"budget\": 102, \"composition\": [[9,4,10,4,9,4,3,2,2,4],[10,8,3,4,5,6,4,10,2,7],[4,1,10,9,4,5,7,9,6,8],[1,5,9,7,8,5,10,3,8,7],[6,2,10,2,8,10,7,5,10,7],[7,2,2,6,8,7,9,10,6,8],[9,4,8,3,10,3,2,5,6,6],[3,1,3,5,10,5,8,8,1,10],[6,4,3,9,3,8,8,6,3,5],[8,9,1,2,7,8,1,10,8,1]], \"stock\": [3,6,1,3,3,7,7,2,2,2], \"cost\": [3,10,9,7,1,3,2,9,7,3] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 0\n\ntest_input = { \"n\": 6, \"k\": 6, \"budget\": 115, \"composition\": [[2,5,8,6,2,3],[7,10,7,2,10,5],[2,7,10,10,3,8],[3,3,8,4,3,10],[10,10,4,10,4,3],[8,9,9,5,7,5]], \"stock\": [7,1,10,7,6,2], \"cost\": [3,8,9,7,8,4] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1\n\ntest_input = { \"n\": 8, \"k\": 10, \"budget\": 19, \"composition\": [[7,6,3,10,2,9,7,2],[5,10,3,3,10,6,6,10],[10,4,9,10,10,7,7,9],[10,6,9,3,4,9,9,5],[7,1,3,4,8,2,8,8],[9,2,3,1,1,2,2,5],[2,6,9,3,7,9,5,8],[3,10,5,2,8,5,8,10],[8,10,1,1,2,1,7,8],[10,8,4,8,5,5,10,2]], \"stock\": [6,0,9,2,5,0,10,8], \"cost\": [2,4,9,8,4,10,3,1] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 0\n\ntest_input = { \"n\": 7, \"k\": 10, \"budget\": 179, \"composition\": [[10,5,2,6,5,2,7],[1,6,8,2,4,8,3],[8,6,1,2,7,7,4],[4,1,9,6,3,8,10],[7,6,3,5,3,4,2],[8,10,9,3,8,1,5],[5,4,1,7,7,6,3],[10,9,8,1,10,4,8],[9,4,6,2,3,3,9],[6,5,2,3,10,6,8]], \"stock\": [9,0,2,10,3,7,6], \"cost\": [6,2,7,10,1,2,7] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 2\n\ntest_input = { \"n\": 9, \"k\": 10, \"budget\": 123, \"composition\": [[4,9,5,9,9,4,8,10,10],[3,1,5,8,4,4,8,6,3],[5,7,2,8,2,7,3,9,5],[9,4,6,7,2,3,4,3,3],[3,6,2,1,3,7,10,7,3],[2,6,9,7,5,7,3,10,1],[1,7,10,6,9,6,6,9,8],[10,8,2,1,6,8,3,8,6],[6,5,1,3,5,1,2,3,1],[8,2,6,1,8,8,3,2,1]], \"stock\": [2,6,3,4,6,1,7,2,6], \"cost\": [5,5,9,1,5,10,4,1,2] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 2\n\ntest_input = { \"n\": 6, \"k\": 1, \"budget\": 161, \"composition\": [[4,6,9,8,5,5]], \"stock\": [7,4,5,1,9,4], \"cost\": [6,5,5,6,3,1] }\nassert my_solution.maxNumberOfAlloys(**test_input) == 1", "start_time": 1694917800} +{"task_id": "weekly-contest-363-maximum-element-sum-of-a-complete-subset-of-indices", "url": "https://leetcode.com/problems/maximum-element-sum-of-a-complete-subset-of-indices", "title": "maximum-element-sum-of-a-complete-subset-of-indices", "meta": {"questionId": "3047", "questionFrontendId": "2862", "title": "Maximum Element-Sum of a Complete Subset of Indices", "titleSlug": "maximum-element-sum-of-a-complete-subset-of-indices", "isPaidOnly": false, "difficulty": "Hard", "likes": 157, "dislikes": 27, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 1-indexed array nums of n integers.\n\nA set of numbers is complete if the product of every pair of its elements is a perfect square.\n\nFor a subset of the indices set {1, 2, ..., n} represented as {i1, i2, ..., ik}, we define its element-sum as: nums[i1] + nums[i2] + ... + nums[ik].\n\nReturn the maximum element-sum of a complete subset of the indices set {1, 2, ..., n}.\n\nA perfect square is a number that can be expressed as the product of an integer by itself.\n\nExample 1:\n\nInput: nums = [8,7,3,5,7,2,4,9]\nOutput: 16\nExplanation: Apart from the subsets consisting of a single index, there are two other complete subsets of indices: {1,4} and {2,8}.\nThe sum of the elements corresponding to indices 1 and 4 is equal to nums[1] + nums[4] = 8 + 5 = 13.\nThe sum of the elements corresponding to indices 2 and 8 is equal to nums[2] + nums[8] = 7 + 9 = 16.\nHence, the maximum element-sum of a complete subset of indices is 16.\n\nExample 2:\n\nInput: nums = [5,10,3,10,1,13,7,9,4]\nOutput: 19\nExplanation: Apart from the subsets consisting of a single index, there are four other complete subsets of indices: {1,4}, {1,9}, {2,8}, {4,9}, and {1,4,9}.\nThe sum of the elements corresponding to indices 1 and 4 is equal to nums[1] + nums[4] = 5 + 10 = 15.\nThe sum of the elements corresponding to indices 1 and 9 is equal to nums[1] + nums[9] = 5 + 4 = 9.\nThe sum of the elements corresponding to indices 2 and 8 is equal to nums[2] + nums[8] = 10 + 9 = 19.\nThe sum of the elements corresponding to indices 4 and 9 is equal to nums[4] + nums[9] = 10 + 4 = 14.\nThe sum of the elements corresponding to indices 1, 4, and 9 is equal to nums[1] + nums[4] + nums[9] = 5 + 10 + 4 = 19.\nHence, the maximum element-sum of a complete subset of indices is 19.\n\n\nConstraints:\n\n * 1 <= n == nums.length <= 104\n * 1 <= nums[i] <= 109\n\"\"\"\nclass Solution:\n def maximumSum(self, nums: List[int]) -> int:\n ", "prompt_sft": "You are given a 1-indexed array nums of n integers.\n\nA set of numbers is complete if the product of every pair of its elements is a perfect square.\n\nFor a subset of the indices set {1, 2, ..., n} represented as {i1, i2, ..., ik}, we define its element-sum as: nums[i1] + nums[i2] + ... + nums[ik].\n\nReturn the maximum element-sum of a complete subset of the indices set {1, 2, ..., n}.\n\nA perfect square is a number that can be expressed as the product of an integer by itself.\n\nExample 1:\n\nInput: nums = [8,7,3,5,7,2,4,9]\nOutput: 16\nExplanation: Apart from the subsets consisting of a single index, there are two other complete subsets of indices: {1,4} and {2,8}.\nThe sum of the elements corresponding to indices 1 and 4 is equal to nums[1] + nums[4] = 8 + 5 = 13.\nThe sum of the elements corresponding to indices 2 and 8 is equal to nums[2] + nums[8] = 7 + 9 = 16.\nHence, the maximum element-sum of a complete subset of indices is 16.\n\nExample 2:\n\nInput: nums = [5,10,3,10,1,13,7,9,4]\nOutput: 19\nExplanation: Apart from the subsets consisting of a single index, there are four other complete subsets of indices: {1,4}, {1,9}, {2,8}, {4,9}, and {1,4,9}.\nThe sum of the elements corresponding to indices 1 and 4 is equal to nums[1] + nums[4] = 5 + 10 = 15.\nThe sum of the elements corresponding to indices 1 and 9 is equal to nums[1] + nums[9] = 5 + 4 = 9.\nThe sum of the elements corresponding to indices 2 and 8 is equal to nums[2] + nums[8] = 10 + 9 = 19.\nThe sum of the elements corresponding to indices 4 and 9 is equal to nums[4] + nums[9] = 10 + 4 = 14.\nThe sum of the elements corresponding to indices 1, 4, and 9 is equal to nums[1] + nums[4] + nums[9] = 5 + 10 + 4 = 19.\nHence, the maximum element-sum of a complete subset of indices is 19.\n\n\nConstraints:\n\n * 1 <= n == nums.length <= 104\n * 1 <= nums[i] <= 109\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def maximumSum(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [8,7,3,5,7,2,4,9] }\nassert my_solution.maximumSum(**test_input) == 16\n\ntest_input = { \"nums\": [5,10,3,10,1,13,7,9,4] }\nassert my_solution.maximumSum(**test_input) == 19\n\ntest_input = { \"nums\": [1,1,1,1] }\nassert my_solution.maximumSum(**test_input) == 2\n\ntest_input = { \"nums\": [1,100,100,1] }\nassert my_solution.maximumSum(**test_input) == 100\n\ntest_input = { \"nums\": [998244353,998244353,998244353,998244353] }\nassert my_solution.maximumSum(**test_input) == 1996488706\n\ntest_input = { \"nums\": [1000000000,1,1,1000000000] }\nassert my_solution.maximumSum(**test_input) == 2000000000\n\ntest_input = { \"nums\": [1,1,1000000000,1] }\nassert my_solution.maximumSum(**test_input) == 1000000000\n\ntest_input = { \"nums\": [5,10,3,10,1,13,7,20,4] }\nassert my_solution.maximumSum(**test_input) == 30\n\ntest_input = { \"nums\": [5,3,3,10,1,13,7,67,4] }\nassert my_solution.maximumSum(**test_input) == 70\n\ntest_input = { \"nums\": [35,45,29,16,42,49,25,19,46] }\nassert my_solution.maximumSum(**test_input) == 97\n\ntest_input = { \"nums\": [34,43,47,50,45] }\nassert my_solution.maximumSum(**test_input) == 84\n\ntest_input = { \"nums\": [4,31,45,34,44] }\nassert my_solution.maximumSum(**test_input) == 45\n\ntest_input = { \"nums\": [12,5,49,26] }\nassert my_solution.maximumSum(**test_input) == 49\n\ntest_input = { \"nums\": [41] }\nassert my_solution.maximumSum(**test_input) == 41\n\ntest_input = { \"nums\": [38,9,37,11,20,43] }\nassert my_solution.maximumSum(**test_input) == 49\n\ntest_input = { \"nums\": [47,50,17,49,12,22] }\nassert my_solution.maximumSum(**test_input) == 96\n\ntest_input = { \"nums\": [23,13,17,3,21,23] }\nassert my_solution.maximumSum(**test_input) == 26\n\ntest_input = { \"nums\": [38,28] }\nassert my_solution.maximumSum(**test_input) == 38\n\ntest_input = { \"nums\": [16,31,37,29,28,34,25,36] }\nassert my_solution.maximumSum(**test_input) == 67\n\ntest_input = { \"nums\": [19,46,37,44,4,40,24,17,49] }\nassert my_solution.maximumSum(**test_input) == 112\n\ntest_input = { \"nums\": [28,40,37] }\nassert my_solution.maximumSum(**test_input) == 40\n\ntest_input = { \"nums\": [19,6,30,23,25,45,15,2,3,46] }\nassert my_solution.maximumSum(**test_input) == 46\n\ntest_input = { \"nums\": [5,16,4,13,37,44,49,7] }\nassert my_solution.maximumSum(**test_input) == 49\n\ntest_input = { \"nums\": [40,8,19,26] }\nassert my_solution.maximumSum(**test_input) == 66\n\ntest_input = { \"nums\": [3,37,2] }\nassert my_solution.maximumSum(**test_input) == 37\n\ntest_input = { \"nums\": [1,5,35,20,32,18,6,49,34,15] }\nassert my_solution.maximumSum(**test_input) == 55\n\ntest_input = { \"nums\": [25,31,4,20,45] }\nassert my_solution.maximumSum(**test_input) == 45\n\ntest_input = { \"nums\": [32,3,25,15,37,37,21,24,8,33] }\nassert my_solution.maximumSum(**test_input) == 55\n\ntest_input = { \"nums\": [13] }\nassert my_solution.maximumSum(**test_input) == 13\n\ntest_input = { \"nums\": [41,25,20,28,40,22,37,43,6,32] }\nassert my_solution.maximumSum(**test_input) == 75\n\ntest_input = { \"nums\": [23,9,7,24,30,34,10,47] }\nassert my_solution.maximumSum(**test_input) == 56\n\ntest_input = { \"nums\": [11,31,1,34,8,20,15,20,49] }\nassert my_solution.maximumSum(**test_input) == 94\n\ntest_input = { \"nums\": [41,21,4,15,25,38,26,7,6] }\nassert my_solution.maximumSum(**test_input) == 62\n\ntest_input = { \"nums\": [46,31,28,34,12,40,11,31,8,25] }\nassert my_solution.maximumSum(**test_input) == 88\n\ntest_input = { \"nums\": [50] }\nassert my_solution.maximumSum(**test_input) == 50\n\ntest_input = { \"nums\": [41,43,17,35] }\nassert my_solution.maximumSum(**test_input) == 76\n\ntest_input = { \"nums\": [20,6] }\nassert my_solution.maximumSum(**test_input) == 20\n\ntest_input = { \"nums\": [43,18,10,19,20,9,49] }\nassert my_solution.maximumSum(**test_input) == 62\n\ntest_input = { \"nums\": [3,39,29,5,6,36,38,26,14,10] }\nassert my_solution.maximumSum(**test_input) == 65\n\ntest_input = { \"nums\": [47,2,48,16,10,3,45,20,39] }\nassert my_solution.maximumSum(**test_input) == 102\n\ntest_input = { \"nums\": [11,47,27,17,7] }\nassert my_solution.maximumSum(**test_input) == 47\n\ntest_input = { \"nums\": [48,17,41,23,40,9,3,26,44,34] }\nassert my_solution.maximumSum(**test_input) == 115\n\ntest_input = { \"nums\": [47,2,42,10,15,44,35,50] }\nassert my_solution.maximumSum(**test_input) == 57\n\ntest_input = { \"nums\": [45,48,50,24,23,14,2,33] }\nassert my_solution.maximumSum(**test_input) == 81\n\ntest_input = { \"nums\": [7,39,27,39,43,42,31,37,15] }\nassert my_solution.maximumSum(**test_input) == 76\n\ntest_input = { \"nums\": [10,36,23,31] }\nassert my_solution.maximumSum(**test_input) == 41\n\ntest_input = { \"nums\": [27,27,13,37] }\nassert my_solution.maximumSum(**test_input) == 64\n\ntest_input = { \"nums\": [34,17,26,13] }\nassert my_solution.maximumSum(**test_input) == 47\n\ntest_input = { \"nums\": [9,42] }\nassert my_solution.maximumSum(**test_input) == 42\n\ntest_input = { \"nums\": [23,42,4,28,30,36,30,39] }\nassert my_solution.maximumSum(**test_input) == 81\n\ntest_input = { \"nums\": [10,28,28,21,25,14,38] }\nassert my_solution.maximumSum(**test_input) == 38\n\ntest_input = { \"nums\": [40,34,26,9,23,15,23,27,49] }\nassert my_solution.maximumSum(**test_input) == 98\n\ntest_input = { \"nums\": [27,42,40,2,1] }\nassert my_solution.maximumSum(**test_input) == 42\n\ntest_input = { \"nums\": [48,19,21,21,32,20,50,41,49,30] }\nassert my_solution.maximumSum(**test_input) == 118\n\ntest_input = { \"nums\": [10,13,6,39,9] }\nassert my_solution.maximumSum(**test_input) == 49\n\ntest_input = { \"nums\": [50,37,24,4,10,43,35] }\nassert my_solution.maximumSum(**test_input) == 54\n\ntest_input = { \"nums\": [39,24] }\nassert my_solution.maximumSum(**test_input) == 39\n\ntest_input = { \"nums\": [21] }\nassert my_solution.maximumSum(**test_input) == 21\n\ntest_input = { \"nums\": [20,15] }\nassert my_solution.maximumSum(**test_input) == 20\n\ntest_input = { \"nums\": [23,27,42,3,33,36,43,32,27,48,40,22,5,36,48] }\nassert my_solution.maximumSum(**test_input) == 64\n\ntest_input = { \"nums\": [39,46,12,14,25,37,24,44,6,38,4] }\nassert my_solution.maximumSum(**test_input) == 90\n\ntest_input = { \"nums\": [36,5,23,17,32,47,23,41,18,44,21,4,22,6,21] }\nassert my_solution.maximumSum(**test_input) == 71\n\ntest_input = { \"nums\": [46,26,37,17,15,26,45,45,17,42,16,14,36,40] }\nassert my_solution.maximumSum(**test_input) == 80\n\ntest_input = { \"nums\": [46,40,16,48,24,1,13,15,6,5,12,15,4] }\nassert my_solution.maximumSum(**test_input) == 100\n\ntest_input = { \"nums\": [11,27,28,26,4,22,10,49,4,23,30,6,5] }\nassert my_solution.maximumSum(**test_input) == 76\n\ntest_input = { \"nums\": [37,17,17,18,10,28,47,38,43,20,10] }\nassert my_solution.maximumSum(**test_input) == 98\n\ntest_input = { \"nums\": [12,17,9,30,38,20,28,36,34,15,4,15,48] }\nassert my_solution.maximumSum(**test_input) == 76\n\ntest_input = { \"nums\": [28,32,22,9,33,26,10,15,15,37,33,48,2,14,35] }\nassert my_solution.maximumSum(**test_input) == 70\n\ntest_input = { \"nums\": [35,28,45,34,49,45,38,15,36,33,15,16] }\nassert my_solution.maximumSum(**test_input) == 105\n\ntest_input = { \"nums\": [50,18,24,30,6,49,3,20,22,19,25,35,30,33] }\nassert my_solution.maximumSum(**test_input) == 102\n\ntest_input = { \"nums\": [10,19,37,1,31,6,2,37,10,1,36,48,7,40] }\nassert my_solution.maximumSum(**test_input) == 85\n\ntest_input = { \"nums\": [45,49,32,44,12,39,8,7,3,48,37,27,41,20,18] }\nassert my_solution.maximumSum(**test_input) == 92\n\ntest_input = { \"nums\": [40,9,16,40,9,28,29,36,4,17,29] }\nassert my_solution.maximumSum(**test_input) == 84\n\ntest_input = { \"nums\": [21,32,24,39,2,13,37,33,50,43,9,43,14] }\nassert my_solution.maximumSum(**test_input) == 110\n\ntest_input = { \"nums\": [36,25,21,29,42,40,16,41,22,24,45,7,33] }\nassert my_solution.maximumSum(**test_input) == 87\n\ntest_input = { \"nums\": [32,33,7,45,23,13,45,4,15,12] }\nassert my_solution.maximumSum(**test_input) == 92\n\ntest_input = { \"nums\": [10,7,1,15,12,22,34,3,36,44,10,12] }\nassert my_solution.maximumSum(**test_input) == 61\n\ntest_input = { \"nums\": [26,4,44,3,37,50,27,22,48,14,12,3,39,31] }\nassert my_solution.maximumSum(**test_input) == 77\n\ntest_input = { \"nums\": [47,48,8,24,1,17,32,13,19,25,15,30,12] }\nassert my_solution.maximumSum(**test_input) == 90\n\ntest_input = { \"nums\": [31,18,11,28,7,34,32,38,47,44,1,13,46] }\nassert my_solution.maximumSum(**test_input) == 106\n\ntest_input = { \"nums\": [47,12,35,10,37,36,44,38,19,31,28,21,3,34] }\nassert my_solution.maximumSum(**test_input) == 76\n\ntest_input = { \"nums\": [19,47,46,5,7,42,35,3,39,2,1,31] }\nassert my_solution.maximumSum(**test_input) == 77\n\ntest_input = { \"nums\": [15,50,14,27,37,44,11,38,23,39,27,36,22] }\nassert my_solution.maximumSum(**test_input) == 88\n\ntest_input = { \"nums\": [31,31,18,24,9,27,33,10,23,38,44,4,17,11,14] }\nassert my_solution.maximumSum(**test_input) == 78\n\ntest_input = { \"nums\": [38,27,13,20,36,23,6,7,37,20,49,31,25,12] }\nassert my_solution.maximumSum(**test_input) == 95\n\ntest_input = { \"nums\": [6,21,11,15,17,47,50,14,24,18,38,19,48,43] }\nassert my_solution.maximumSum(**test_input) == 50\n\ntest_input = { \"nums\": [31,4,1,5,50,46,14,17,13,14,17,39,46,18] }\nassert my_solution.maximumSum(**test_input) == 50\n\ntest_input = { \"nums\": [39,13,6,45,44,14,44,37,24,20,21,47,6,6,5] }\nassert my_solution.maximumSum(**test_input) == 108\n\ntest_input = { \"nums\": [17,16,48,41,7,39,50,29,2,33] }\nassert my_solution.maximumSum(**test_input) == 60\n\ntest_input = { \"nums\": [3,8,19,47,29,4,16,31,11,30] }\nassert my_solution.maximumSum(**test_input) == 61\n\ntest_input = { \"nums\": [20,1,46,36,35,32,49,14,48,25,17,50,22] }\nassert my_solution.maximumSum(**test_input) == 104\n\ntest_input = { \"nums\": [49,20,12,42,33,21,29,30,35,4,5,50] }\nassert my_solution.maximumSum(**test_input) == 126\n\ntest_input = { \"nums\": [36,1,8,14,39,2,31,23,10,46,42] }\nassert my_solution.maximumSum(**test_input) == 60\n\ntest_input = { \"nums\": [33,29,23,4,48,31,31,26,11,39] }\nassert my_solution.maximumSum(**test_input) == 55\n\ntest_input = { \"nums\": [33,36,31,21,2,41,14,36,6,1,22,13,34] }\nassert my_solution.maximumSum(**test_input) == 72\n\ntest_input = { \"nums\": [35,32,43,20,4,13,6,19,36,20] }\nassert my_solution.maximumSum(**test_input) == 91\n\ntest_input = { \"nums\": [16,41,16,41,11,39,40,7,24,28,13] }\nassert my_solution.maximumSum(**test_input) == 81\n\ntest_input = { \"nums\": [32,24,29,24,29,45,10,37,22,35,37,28,15] }\nassert my_solution.maximumSum(**test_input) == 78\n\ntest_input = { \"nums\": [45,8,19,1,33,2,32,40,16,33,44,27] }\nassert my_solution.maximumSum(**test_input) == 62\n\ntest_input = { \"nums\": [3,42,14,18,1,20,19,7,37,3,2,3,48] }\nassert my_solution.maximumSum(**test_input) == 58", "start_time": 1694917800} +{"task_id": "biweekly-contest-113-minimum-right-shifts-to-sort-the-array", "url": "https://leetcode.com/problems/minimum-right-shifts-to-sort-the-array", "title": "minimum-right-shifts-to-sort-the-array", "meta": {"questionId": "3045", "questionFrontendId": "2855", "title": "Minimum Right Shifts to Sort the Array", "titleSlug": "minimum-right-shifts-to-sort-the-array", "isPaidOnly": false, "difficulty": "Easy", "likes": 169, "dislikes": 6, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed array nums of length n containing distinct positive integers. Return the minimum number of right shifts required to sort nums and -1 if this is not possible.\n\nA right shift is defined as shifting the element at index i to index (i + 1) % n, for all indices.\n\nExample 1:\n\nInput: nums = [3,4,5,1,2]\nOutput: 2\nExplanation:\nAfter the first right shift, nums = [2,3,4,5,1].\nAfter the second right shift, nums = [1,2,3,4,5].\nNow nums is sorted; therefore the answer is 2.\n\nExample 2:\n\nInput: nums = [1,3,5]\nOutput: 0\nExplanation: nums is already sorted therefore, the answer is 0.\n\nExample 3:\n\nInput: nums = [2,1,4]\nOutput: -1\nExplanation: It's impossible to sort the array using right shifts.\n\n\nConstraints:\n\n * 1 <= nums.length <= 100\n * 1 <= nums[i] <= 100\n * nums contains distinct integers.\n\"\"\"\nclass Solution:\n def minimumRightShifts(self, nums: List[int]) -> int:\n ", "prompt_sft": "You are given a 0-indexed array nums of length n containing distinct positive integers. Return the minimum number of right shifts required to sort nums and -1 if this is not possible.\n\nA right shift is defined as shifting the element at index i to index (i + 1) % n, for all indices.\n\nExample 1:\n\nInput: nums = [3,4,5,1,2]\nOutput: 2\nExplanation:\nAfter the first right shift, nums = [2,3,4,5,1].\nAfter the second right shift, nums = [1,2,3,4,5].\nNow nums is sorted; therefore the answer is 2.\n\nExample 2:\n\nInput: nums = [1,3,5]\nOutput: 0\nExplanation: nums is already sorted therefore, the answer is 0.\n\nExample 3:\n\nInput: nums = [2,1,4]\nOutput: -1\nExplanation: It's impossible to sort the array using right shifts.\n\n\nConstraints:\n\n * 1 <= nums.length <= 100\n * 1 <= nums[i] <= 100\n * nums contains distinct integers.\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def minimumRightShifts(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [3,4,5,1,2] }\nassert my_solution.minimumRightShifts(**test_input) == 2\n\ntest_input = { \"nums\": [1,3,5] }\nassert my_solution.minimumRightShifts(**test_input) == 0\n\ntest_input = { \"nums\": [2,1,4] }\nassert my_solution.minimumRightShifts(**test_input) == -1\n\ntest_input = { \"nums\": [31,72,79,25] }\nassert my_solution.minimumRightShifts(**test_input) == 1\n\ntest_input = { \"nums\": [27,33,42,58,81,8,9,17] }\nassert my_solution.minimumRightShifts(**test_input) == 3\n\ntest_input = { \"nums\": [72,13,21,35,52] }\nassert my_solution.minimumRightShifts(**test_input) == 4\n\ntest_input = { \"nums\": [65,73,77,1] }\nassert my_solution.minimumRightShifts(**test_input) == 1\n\ntest_input = { \"nums\": [100,8,14,68,80,84] }\nassert my_solution.minimumRightShifts(**test_input) == 5\n\ntest_input = { \"nums\": [53,60,64,69,98,40] }\nassert my_solution.minimumRightShifts(**test_input) == 1\n\ntest_input = { \"nums\": [21] }\nassert my_solution.minimumRightShifts(**test_input) == 0\n\ntest_input = { \"nums\": [78,12,18,21,23,36,64,70] }\nassert my_solution.minimumRightShifts(**test_input) == 7\n\ntest_input = { \"nums\": [25,26,53,91,92,99,10,24] }\nassert my_solution.minimumRightShifts(**test_input) == 2\n\ntest_input = { \"nums\": [63,51,65,87,6,17,32,14,42,46] }\nassert my_solution.minimumRightShifts(**test_input) == -1\n\ntest_input = { \"nums\": [43,46,75,76,85,96,9,19,25] }\nassert my_solution.minimumRightShifts(**test_input) == 3\n\ntest_input = { \"nums\": [5] }\nassert my_solution.minimumRightShifts(**test_input) == 0\n\ntest_input = { \"nums\": [35,72,76,82,96,97,24,26] }\nassert my_solution.minimumRightShifts(**test_input) == 2\n\ntest_input = { \"nums\": [82,30,94,55,76,51,3,89,52,96] }\nassert my_solution.minimumRightShifts(**test_input) == -1\n\ntest_input = { \"nums\": [57,59,88,97,6,27,41,46,52] }\nassert my_solution.minimumRightShifts(**test_input) == 5\n\ntest_input = { \"nums\": [17] }\nassert my_solution.minimumRightShifts(**test_input) == 0\n\ntest_input = { \"nums\": [62] }\nassert my_solution.minimumRightShifts(**test_input) == 0\n\ntest_input = { \"nums\": [24,46,55,61,71,78,1,4] }\nassert my_solution.minimumRightShifts(**test_input) == 2\n\ntest_input = { \"nums\": [83,2,21,42,73,77,80] }\nassert my_solution.minimumRightShifts(**test_input) == 6\n\ntest_input = { \"nums\": [83,94,14,43,50,62,63] }\nassert my_solution.minimumRightShifts(**test_input) == 5\n\ntest_input = { \"nums\": [38,46,66,77,7,15,17,35] }\nassert my_solution.minimumRightShifts(**test_input) == 4\n\ntest_input = { \"nums\": [35,68,82,90,9,18,29,34] }\nassert my_solution.minimumRightShifts(**test_input) == 4\n\ntest_input = { \"nums\": [71] }\nassert my_solution.minimumRightShifts(**test_input) == 0\n\ntest_input = { \"nums\": [71,73,88,12,49,55,59,70] }\nassert my_solution.minimumRightShifts(**test_input) == 5\n\ntest_input = { \"nums\": [54,65,75,81,24,37] }\nassert my_solution.minimumRightShifts(**test_input) == 2\n\ntest_input = { \"nums\": [57,67,73,78,79,2,45,48,51] }\nassert my_solution.minimumRightShifts(**test_input) == 4\n\ntest_input = { \"nums\": [36,62,65,85,95,9,21] }\nassert my_solution.minimumRightShifts(**test_input) == 2\n\ntest_input = { \"nums\": [68,12] }\nassert my_solution.minimumRightShifts(**test_input) == 1\n\ntest_input = { \"nums\": [34,9,86,20,67,94,65,82,40,79] }\nassert my_solution.minimumRightShifts(**test_input) == -1\n\ntest_input = { \"nums\": [92,84,37,19,16,85,20,79,25,89] }\nassert my_solution.minimumRightShifts(**test_input) == -1\n\ntest_input = { \"nums\": [3,16,38,44,67,79,84] }\nassert my_solution.minimumRightShifts(**test_input) == 0\n\ntest_input = { \"nums\": [14,24,58,69,71,94,13] }\nassert my_solution.minimumRightShifts(**test_input) == 1\n\ntest_input = { \"nums\": [100,18] }\nassert my_solution.minimumRightShifts(**test_input) == 1\n\ntest_input = { \"nums\": [13] }\nassert my_solution.minimumRightShifts(**test_input) == 0\n\ntest_input = { \"nums\": [94,30,53,56,67,72,82] }\nassert my_solution.minimumRightShifts(**test_input) == 6\n\ntest_input = { \"nums\": [92,14,65,80,85] }\nassert my_solution.minimumRightShifts(**test_input) == 4\n\ntest_input = { \"nums\": [43,53,81,87,93,19,31,39] }\nassert my_solution.minimumRightShifts(**test_input) == 3\n\ntest_input = { \"nums\": [80,38] }\nassert my_solution.minimumRightShifts(**test_input) == 1\n\ntest_input = { \"nums\": [52,72,78,83,85,99,20] }\nassert my_solution.minimumRightShifts(**test_input) == 1\n\ntest_input = { \"nums\": [3,6,89] }\nassert my_solution.minimumRightShifts(**test_input) == 0\n\ntest_input = { \"nums\": [3] }\nassert my_solution.minimumRightShifts(**test_input) == 0\n\ntest_input = { \"nums\": [55,56,63,91,3,46] }\nassert my_solution.minimumRightShifts(**test_input) == 2\n\ntest_input = { \"nums\": [58,10,31,37,41] }\nassert my_solution.minimumRightShifts(**test_input) == 4\n\ntest_input = { \"nums\": [17,33,53,58,78] }\nassert my_solution.minimumRightShifts(**test_input) == 0\n\ntest_input = { \"nums\": [82,44] }\nassert my_solution.minimumRightShifts(**test_input) == 1\n\ntest_input = { \"nums\": [89,96,35,48,57,71] }\nassert my_solution.minimumRightShifts(**test_input) == 4\n\ntest_input = { \"nums\": [43,69,4,29,37] }\nassert my_solution.minimumRightShifts(**test_input) == 3\n\ntest_input = { \"nums\": [65,88] }\nassert my_solution.minimumRightShifts(**test_input) == 0\n\ntest_input = { \"nums\": [42,44,59,76,86] }\nassert my_solution.minimumRightShifts(**test_input) == 0\n\ntest_input = { \"nums\": [29,56,78,96,1,10,27] }\nassert my_solution.minimumRightShifts(**test_input) == 3\n\ntest_input = { \"nums\": [48,100] }\nassert my_solution.minimumRightShifts(**test_input) == 0\n\ntest_input = { \"nums\": [4,33,17,3,8,91,28,13,72,42] }\nassert my_solution.minimumRightShifts(**test_input) == -1\n\ntest_input = { \"nums\": [5,35,53,56] }\nassert my_solution.minimumRightShifts(**test_input) == 0\n\ntest_input = { \"nums\": [65,67,70,27,41,50,52,57,60] }\nassert my_solution.minimumRightShifts(**test_input) == 6\n\ntest_input = { \"nums\": [94,32,45,62] }\nassert my_solution.minimumRightShifts(**test_input) == 3\n\ntest_input = { \"nums\": [23,25,34,47,61,65,6,21] }\nassert my_solution.minimumRightShifts(**test_input) == 2\n\ntest_input = { \"nums\": [99,11,12,21,22,55,62,83] }\nassert my_solution.minimumRightShifts(**test_input) == 7\n\ntest_input = { \"nums\": [92,13,33,58,61,85] }\nassert my_solution.minimumRightShifts(**test_input) == 5\n\ntest_input = { \"nums\": [46] }\nassert my_solution.minimumRightShifts(**test_input) == 0\n\ntest_input = { \"nums\": [12,27,30,36] }\nassert my_solution.minimumRightShifts(**test_input) == 0\n\ntest_input = { \"nums\": [33,44,57,16,22,26,30] }\nassert my_solution.minimumRightShifts(**test_input) == 4\n\ntest_input = { \"nums\": [67,24] }\nassert my_solution.minimumRightShifts(**test_input) == 1\n\ntest_input = { \"nums\": [12,44,83,87] }\nassert my_solution.minimumRightShifts(**test_input) == 0\n\ntest_input = { \"nums\": [19,52,3,8,12] }\nassert my_solution.minimumRightShifts(**test_input) == 3\n\ntest_input = { \"nums\": [82,86,88,6,35,47,52,58,62] }\nassert my_solution.minimumRightShifts(**test_input) == 6\n\ntest_input = { \"nums\": [48] }\nassert my_solution.minimumRightShifts(**test_input) == 0\n\ntest_input = { \"nums\": [60,11] }\nassert my_solution.minimumRightShifts(**test_input) == 1\n\ntest_input = { \"nums\": [69,60] }\nassert my_solution.minimumRightShifts(**test_input) == 1\n\ntest_input = { \"nums\": [22,28,36,16,82,77,41,85,44,97] }\nassert my_solution.minimumRightShifts(**test_input) == -1\n\ntest_input = { \"nums\": [63,94,2,14] }\nassert my_solution.minimumRightShifts(**test_input) == 2\n\ntest_input = { \"nums\": [41,45,74,84,90,93,100,18,31] }\nassert my_solution.minimumRightShifts(**test_input) == 2\n\ntest_input = { \"nums\": [21,38,57,64,12] }\nassert my_solution.minimumRightShifts(**test_input) == 1\n\ntest_input = { \"nums\": [99,2,9,17,33,58,59,72] }\nassert my_solution.minimumRightShifts(**test_input) == 7\n\ntest_input = { \"nums\": [36,89,90,98,11,14,23] }\nassert my_solution.minimumRightShifts(**test_input) == 3\n\ntest_input = { \"nums\": [84,90,5,57,78] }\nassert my_solution.minimumRightShifts(**test_input) == 3\n\ntest_input = { \"nums\": [48,73,76,30] }\nassert my_solution.minimumRightShifts(**test_input) == 1\n\ntest_input = { \"nums\": [74] }\nassert my_solution.minimumRightShifts(**test_input) == 0\n\ntest_input = { \"nums\": [21,84,35,65,12,74,30,95,46,23] }\nassert my_solution.minimumRightShifts(**test_input) == -1\n\ntest_input = { \"nums\": [64,76,46,53,54] }\nassert my_solution.minimumRightShifts(**test_input) == 3\n\ntest_input = { \"nums\": [77,84,89,47,52,74] }\nassert my_solution.minimumRightShifts(**test_input) == 3\n\ntest_input = { \"nums\": [12,29,31,52,88,89,10] }\nassert my_solution.minimumRightShifts(**test_input) == 1\n\ntest_input = { \"nums\": [20,25,28,41,57,89] }\nassert my_solution.minimumRightShifts(**test_input) == 0\n\ntest_input = { \"nums\": [1,28,51,59] }\nassert my_solution.minimumRightShifts(**test_input) == 0\n\ntest_input = { \"nums\": [59,76,2,26,49,78,36,70,64,24] }\nassert my_solution.minimumRightShifts(**test_input) == -1\n\ntest_input = { \"nums\": [35,43,49,63,21] }\nassert my_solution.minimumRightShifts(**test_input) == 1\n\ntest_input = { \"nums\": [1,35,38,47,54,56,58,74] }\nassert my_solution.minimumRightShifts(**test_input) == 0\n\ntest_input = { \"nums\": [49,94,97] }\nassert my_solution.minimumRightShifts(**test_input) == 0\n\ntest_input = { \"nums\": [32,30] }\nassert my_solution.minimumRightShifts(**test_input) == 1\n\ntest_input = { \"nums\": [37,36] }\nassert my_solution.minimumRightShifts(**test_input) == 1\n\ntest_input = { \"nums\": [31,41,65,14] }\nassert my_solution.minimumRightShifts(**test_input) == 1\n\ntest_input = { \"nums\": [45,57,73,77,17,30,42,43] }\nassert my_solution.minimumRightShifts(**test_input) == 4\n\ntest_input = { \"nums\": [17,65,11] }\nassert my_solution.minimumRightShifts(**test_input) == 1\n\ntest_input = { \"nums\": [32,84,93,31,61,78,15,52,100,65] }\nassert my_solution.minimumRightShifts(**test_input) == -1\n\ntest_input = { \"nums\": [61,72,90,3,8,17,23,55] }\nassert my_solution.minimumRightShifts(**test_input) == 5\n\ntest_input = { \"nums\": [19,30,44,95,13] }\nassert my_solution.minimumRightShifts(**test_input) == 1\n\ntest_input = { \"nums\": [42,46,66,71,87,3,4,5,14] }\nassert my_solution.minimumRightShifts(**test_input) == 4\n\ntest_input = { \"nums\": [13,57,7] }\nassert my_solution.minimumRightShifts(**test_input) == 1", "start_time": 1694874600} +{"task_id": "biweekly-contest-113-minimum-array-length-after-pair-removals", "url": "https://leetcode.com/problems/minimum-array-length-after-pair-removals", "title": "minimum-array-length-after-pair-removals", "meta": {"questionId": "3081", "questionFrontendId": "2856", "title": "Minimum Array Length After Pair Removals", "titleSlug": "minimum-array-length-after-pair-removals", "isPaidOnly": false, "difficulty": "Medium", "likes": 259, "dislikes": 88, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed sorted array of integers nums.\n\nYou can perform the following operation any number of times:\n\n * Choose two indices, i and j, where i < j, such that nums[i] < nums[j].\n * Then, remove the elements at indices i and j from nums. The remaining elements retain their original order, and the array is re-indexed.\n\nReturn an integer that denotes the minimum length of nums after performing the operation any number of times (including zero).\n\nNote that nums is sorted in non-decreasing order.\n\nExample 1:\n\nInput: nums = [1,3,4,9]\nOutput: 0\nExplanation: Initially, nums = [1, 3, 4, 9].\nIn the first operation, we can choose index 0 and 1 because nums[0] < nums[1] <=> 1 < 3.\nRemove indices 0 and 1, and nums becomes [4, 9].\nFor the next operation, we can choose index 0 and 1 because nums[0] < nums[1] <=> 4 < 9.\nRemove indices 0 and 1, and nums becomes an empty array [].\nHence, the minimum length achievable is 0.\n\nExample 2:\n\nInput: nums = [2,3,6,9]\nOutput: 0\nExplanation: Initially, nums = [2, 3, 6, 9].\nIn the first operation, we can choose index 0 and 2 because nums[0] < nums[2] <=> 2 < 6.\nRemove indices 0 and 2, and nums becomes [3, 9].\nFor the next operation, we can choose index 0 and 1 because nums[0] < nums[1] <=> 3 < 9.\nRemove indices 0 and 1, and nums becomes an empty array [].\nHence, the minimum length achievable is 0.\n\nExample 3:\n\nInput: nums = [1,1,2]\nOutput: 1\nExplanation: Initially, nums = [1, 1, 2].\nIn an operation, we can choose index 0 and 2 because nums[0] < nums[2] <=> 1 < 2.\nRemove indices 0 and 2, and nums becomes [1].\nIt is no longer possible to perform an operation on the array.\nHence, the minimum achievable length is 1.\n\n\nConstraints:\n\n * 1 <= nums.length <= 105\n * 1 <= nums[i] <= 109\n * nums is sorted in non-decreasing order.\n\"\"\"\nclass Solution:\n def minLengthAfterRemovals(self, nums: List[int]) -> int:\n ", "prompt_sft": "You are given a 0-indexed sorted array of integers nums.\n\nYou can perform the following operation any number of times:\n\n * Choose two indices, i and j, where i < j, such that nums[i] < nums[j].\n * Then, remove the elements at indices i and j from nums. The remaining elements retain their original order, and the array is re-indexed.\n\nReturn an integer that denotes the minimum length of nums after performing the operation any number of times (including zero).\n\nNote that nums is sorted in non-decreasing order.\n\nExample 1:\n\nInput: nums = [1,3,4,9]\nOutput: 0\nExplanation: Initially, nums = [1, 3, 4, 9].\nIn the first operation, we can choose index 0 and 1 because nums[0] < nums[1] <=> 1 < 3.\nRemove indices 0 and 1, and nums becomes [4, 9].\nFor the next operation, we can choose index 0 and 1 because nums[0] < nums[1] <=> 4 < 9.\nRemove indices 0 and 1, and nums becomes an empty array [].\nHence, the minimum length achievable is 0.\n\nExample 2:\n\nInput: nums = [2,3,6,9]\nOutput: 0\nExplanation: Initially, nums = [2, 3, 6, 9].\nIn the first operation, we can choose index 0 and 2 because nums[0] < nums[2] <=> 2 < 6.\nRemove indices 0 and 2, and nums becomes [3, 9].\nFor the next operation, we can choose index 0 and 1 because nums[0] < nums[1] <=> 3 < 9.\nRemove indices 0 and 1, and nums becomes an empty array [].\nHence, the minimum length achievable is 0.\n\nExample 3:\n\nInput: nums = [1,1,2]\nOutput: 1\nExplanation: Initially, nums = [1, 1, 2].\nIn an operation, we can choose index 0 and 2 because nums[0] < nums[2] <=> 1 < 2.\nRemove indices 0 and 2, and nums becomes [1].\nIt is no longer possible to perform an operation on the array.\nHence, the minimum achievable length is 1.\n\n\nConstraints:\n\n * 1 <= nums.length <= 105\n * 1 <= nums[i] <= 109\n * nums is sorted in non-decreasing order.\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def minLengthAfterRemovals(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,3,4,9] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [2,3,6,9] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,2] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [1] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [2] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [3] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [5] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [1,1] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 2\n\ntest_input = { \"nums\": [1,2] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [1,4] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [2,3] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [3,3] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 2\n\ntest_input = { \"nums\": [4,5] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,1] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,2] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [1,3,3] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [2,2,2] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 3\n\ntest_input = { \"nums\": [2,3,3] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [2,3,4] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [3,4,5] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,1,1] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 4\n\ntest_input = { \"nums\": [1,1,2,2] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,3,3] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [2,3,3,3] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,1,1,1] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 5\n\ntest_input = { \"nums\": [1,1,2,3,3] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,2,5,6] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [1,3,3,3,4] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [2,3,4,4,4] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,1,1,1,1] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 6\n\ntest_input = { \"nums\": [1,1,2,3,4,4] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,4,4,5,5] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [1,2,2,2,3,3] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [1,2,3,3,3,3] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 2\n\ntest_input = { \"nums\": [3,4,7,8,9,9] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,1,1,1,1,1] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 7\n\ntest_input = { \"nums\": [1,1,1,1,2,2,2] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,1,1,2,3,3] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,1,2,2,3,3] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,1,3,3,3,3] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,2,2,3,3,4] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,2,3,4,5,5] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,3,3,3,3,3] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 3\n\ntest_input = { \"nums\": [2,2,2,3,3,3,3] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,1,1,1,1,1,1] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 8\n\ntest_input = { \"nums\": [1,1,1,1,2,2,2,2] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,2,2,3,3,4,5] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,3,4,4,4,5,5] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [1,2,2,2,4,4,4,5] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [2,3,3,3,4,4,5,5] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,1,1,1,1,1,1,1] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 9\n\ntest_input = { \"nums\": [1,1,1,1,1,1,1,2,2] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 5\n\ntest_input = { \"nums\": [1,1,1,1,2,2,2,3,3] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,1,2,2,2,2,2,2] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,1,5,5,5,5,5,5] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,2,2,2,2,3,3,3] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,2,2,2,3,3,3,3] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,4,4,5,5,5,6,6] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,1,1,1,1,1,1,1,1] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 10\n\ntest_input = { \"nums\": [1,1,1,1,1,2,2,2,3,4] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,1,1,2,2,2,2,2,2] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,2,2,2,3,3,3,3,3] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,2,2,2,3,3,3,3,4] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [1,2,2,4,5,6,6,7,7,8] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,1,1,1,1,1,1,1,1,1] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 11\n\ntest_input = { \"nums\": [1,1,1,1,1,1,2,2,2,2,2] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,1,2,2,2,2,2,2,2,2] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 5\n\ntest_input = { \"nums\": [1,1,1,2,2,2,3,3,3,3,3] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,1,2,2,3,4,6,6,8,8] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,2,2,2,2,2,3,3,3,3] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,2,2,2,2,3,3,3,3,3] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,2,2,2,2,3,3,3,4,4] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,2,2,3,3,4,5,5,6,6] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,1,1,1,1,1,1,1,1,1,1] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 12\n\ntest_input = { \"nums\": [1,1,1,1,1,1,1,1,1,2,2,2] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 6\n\ntest_input = { \"nums\": [1,1,1,1,1,2,2,3,3,4,4,4] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,1,2,2,2,2,2,2,2,2,2] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 6\n\ntest_input = { \"nums\": [1,1,1,2,2,3,3,3,4,5,5,5] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,1,2,4,4,4,4,4,5,6,6] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,2,2,2,2,2,2,2,2,3,3] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 4\n\ntest_input = { \"nums\": [1,1,2,2,2,2,2,3,3,3,5,5] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,2,2,2,3,3,4,4,4,5,5] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,1,1,1,1,1,1,1,1,1,1,1] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 13\n\ntest_input = { \"nums\": [1,1,1,1,1,1,1,2,2,4,4,4,4] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,1,1,1,2,3,3,3,3,3,3,5] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,1,1,2,2,2,2,2,3,3,3,3] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,2,2,3,3,3,3,4,4,4,6,7] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,2,2,2,2,2,3,3,4,6,7,7] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,1,1,1,1,1,1,1,1,1,1,1,1] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 14\n\ntest_input = { \"nums\": [1,1,1,1,1,1,2,2,2,2,3,3,3,3] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,1,1,1,2,2,2,2,2,2,2,2,2] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 4\n\ntest_input = { \"nums\": [1,1,1,2,2,2,3,3,3,4,4,4,5,5] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,1,2,2,3,3,3,3,4,4,5,5,6] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,2,2,2,3,3,3,5,6,7,9,9,10] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [1,3,3,3,3,3,3,3,4,4,4,4,5,5] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [2,2,2,2,2,2,2,3,3,3,3,3,3,3] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,1,1,1,1,1,1,1,1,2,2,2,2,2] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 5\n\ntest_input = { \"nums\": [1,1,1,1,1,1,1,1,1,2,2,2,2,2,2] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,1,1,1,1,2,2,2,4,4,4,5,5,5] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,1,3,5,6,6,7,7,8,8,8,8,9,9] }\nassert my_solution.minLengthAfterRemovals(**test_input) == 1", "start_time": 1694874600} +{"task_id": "biweekly-contest-113-count-pairs-of-points-with-distance-k", "url": "https://leetcode.com/problems/count-pairs-of-points-with-distance-k", "title": "count-pairs-of-points-with-distance-k", "meta": {"questionId": "2953", "questionFrontendId": "2857", "title": "Count Pairs of Points With Distance k", "titleSlug": "count-pairs-of-points-with-distance-k", "isPaidOnly": false, "difficulty": "Medium", "likes": 238, "dislikes": 34, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 2D integer array coordinates and an integer k, where coordinates[i] = [xi, yi] are the coordinates of the ith point in a 2D plane.\n\nWe define the distance between two points (x1, y1) and (x2, y2) as (x1 XOR x2) + (y1 XOR y2) where XOR is the bitwise XOR operation.\n\nReturn the number of pairs (i, j) such that i < j and the distance between points i and j is equal to k.\n\nExample 1:\n\nInput: coordinates = [[1,2],[4,2],[1,3],[5,2]], k = 5\nOutput: 2\nExplanation: We can choose the following pairs:\n- (0,1): Because we have (1 XOR 4) + (2 XOR 2) = 5.\n- (2,3): Because we have (1 XOR 5) + (3 XOR 2) = 5.\n\nExample 2:\n\nInput: coordinates = [[1,3],[1,3],[1,3],[1,3],[1,3]], k = 0\nOutput: 10\nExplanation: Any two chosen pairs will have a distance of 0. There are 10 ways to choose two pairs.\n\n\nConstraints:\n\n * 2 <= coordinates.length <= 50000\n * 0 <= xi, yi <= 106\n * 0 <= k <= 100\n\"\"\"\nclass Solution:\n def countPairs(self, coordinates: List[List[int]], k: int) -> int:\n ", "prompt_sft": "You are given a 2D integer array coordinates and an integer k, where coordinates[i] = [xi, yi] are the coordinates of the ith point in a 2D plane.\n\nWe define the distance between two points (x1, y1) and (x2, y2) as (x1 XOR x2) + (y1 XOR y2) where XOR is the bitwise XOR operation.\n\nReturn the number of pairs (i, j) such that i < j and the distance between points i and j is equal to k.\n\nExample 1:\n\nInput: coordinates = [[1,2],[4,2],[1,3],[5,2]], k = 5\nOutput: 2\nExplanation: We can choose the following pairs:\n- (0,1): Because we have (1 XOR 4) + (2 XOR 2) = 5.\n- (2,3): Because we have (1 XOR 5) + (3 XOR 2) = 5.\n\nExample 2:\n\nInput: coordinates = [[1,3],[1,3],[1,3],[1,3],[1,3]], k = 0\nOutput: 10\nExplanation: Any two chosen pairs will have a distance of 0. There are 10 ways to choose two pairs.\n\n\nConstraints:\n\n * 2 <= coordinates.length <= 50000\n * 0 <= xi, yi <= 106\n * 0 <= k <= 100\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def countPairs(self, coordinates: List[List[int]], k: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"coordinates\": [[1,2],[4,2],[1,3],[5,2]], \"k\": 5 }\nassert my_solution.countPairs(**test_input) == 2\n\ntest_input = { \"coordinates\": [[1,3],[1,3],[1,3],[1,3],[1,3]], \"k\": 0 }\nassert my_solution.countPairs(**test_input) == 10\n\ntest_input = { \"coordinates\": [[27,94],[61,68],[47,0],[100,4],[127,89],[61,103],[26,4],[51,54],[91,26],[98,23],[80,74],[19,93]], \"k\": 95 }\nassert my_solution.countPairs(**test_input) == 5\n\ntest_input = { \"coordinates\": [[39,29],[98,59],[65,77],[41,26],[95,12],[71,66],[41,93],[28,33],[96,40],[39,8],[106,54],[8,49],[68,59],[21,15],[3,66],[77,85],[111,51]], \"k\": 21 }\nassert my_solution.countPairs(**test_input) == 6\n\ntest_input = { \"coordinates\": [[100,32],[69,8],[85,31],[69,47],[62,34],[102,43],[81,39],[90,0],[123,6],[79,18],[21,94],[13,36],[49,97],[76,59],[42,74],[60,68],[21,11],[71,21],[64,13],[64,95],[5,85],[118,53],[70,44],[38,57],[32,119],[80,61],[13,68],[43,108],[86,49]], \"k\": 39 }\nassert my_solution.countPairs(**test_input) == 20\n\ntest_input = { \"coordinates\": [[60,55],[35,32],[99,2],[58,57],[16,2],[43,28],[30,35],[35,83],[104,41],[20,69],[58,14],[12,92],[71,49],[7,82],[65,68],[9,40],[15,56],[57,46],[21,8],[37,64],[42,94],[73,91],[12,121],[10,21],[41,89]], \"k\": 54 }\nassert my_solution.countPairs(**test_input) == 10\n\ntest_input = { \"coordinates\": [[94,23],[86,58],[126,55],[107,23],[121,60],[89,28],[123,15],[127,3],[100,49],[5,3],[81,49],[93,0],[95,37],[92,25]], \"k\": 53 }\nassert my_solution.countPairs(**test_input) == 18\n\ntest_input = { \"coordinates\": [[40,54],[8,68],[33,11],[51,93],[95,95],[17,53],[35,39],[59,42],[28,63],[41,63],[54,0],[88,31],[5,107],[32,124],[74,64],[15,27],[61,92],[16,47],[62,22],[2,28],[27,14],[53,39],[21,91],[7,11]], \"k\": 60 }\nassert my_solution.countPairs(**test_input) == 11\n\ntest_input = { \"coordinates\": [[28,14],[2,13],[28,14],[4,7],[23,1],[54,0],[43,22],[98,16]], \"k\": 33 }\nassert my_solution.countPairs(**test_input) == 5\n\ntest_input = { \"coordinates\": [[84,92],[84,92],[84,92],[84,92],[84,92],[54,59],[84,92],[93,44]], \"k\": 0 }\nassert my_solution.countPairs(**test_input) == 15\n\ntest_input = { \"coordinates\": [[10,57],[12,62],[92,44],[7,60],[8,55],[13,50],[5,55],[71,82],[64,26],[68,43],[61,88],[9,44],[95,16],[17,16],[12,53],[9,59],[81,44],[3,56],[70,94],[0,58],[84,29],[13,63],[79,87],[19,39],[74,35],[92,7],[31,6],[2,50]], \"k\": 13 }\nassert my_solution.countPairs(**test_input) == 19\n\ntest_input = { \"coordinates\": [[56,47],[26,50],[51,2],[40,7],[24,34],[55,2],[13,92],[57,50],[47,35],[32,96],[14,0],[4,84],[86,95]], \"k\": 56 }\nassert my_solution.countPairs(**test_input) == 4\n\ntest_input = { \"coordinates\": [[34,60],[17,93],[87,90],[32,125],[71,27],[27,26],[127,115],[91,27],[63,68],[97,48],[69,73],[120,78],[43,55],[101,125],[86,87],[12,35],[5,20],[46,12],[17,24],[107,62],[86,88],[26,80],[30,41],[110,114]], \"k\": 81 }\nassert my_solution.countPairs(**test_input) == 17\n\ntest_input = { \"coordinates\": [[65,19],[12,80],[90,64],[38,68],[17,25],[49,36],[91,47],[20,31],[81,54],[83,20],[90,100],[0,6],[93,121]], \"k\": 36 }\nassert my_solution.countPairs(**test_input) == 3\n\ntest_input = { \"coordinates\": [[24,75],[22,67]], \"k\": 23 }\nassert my_solution.countPairs(**test_input) == 0\n\ntest_input = { \"coordinates\": [[42,32],[62,60],[57,61],[100,56],[91,62],[57,21],[100,56],[63,63],[45,52],[59,75],[32,61],[57,43],[61,57],[64,52],[24,54],[92,15],[53,25],[84,63],[1,18],[21,57],[29,9],[68,91],[22,43],[105,27]], \"k\": 48 }\nassert my_solution.countPairs(**test_input) == 18\n\ntest_input = { \"coordinates\": [[70,98],[79,66],[71,63],[111,94],[3,50],[64,111],[98,67],[23,41],[66,14],[40,19],[15,13],[32,86],[59,58],[73,94],[18,10],[77,50],[20,60],[66,8],[15,30],[71,2],[55,9]], \"k\": 60 }\nassert my_solution.countPairs(**test_input) == 7\n\ntest_input = { \"coordinates\": [[5,100],[60,9],[84,65],[38,66],[83,35],[17,80],[88,76],[80,101],[55,74],[46,62],[28,73],[54,40],[119,71],[10,94],[45,82],[20,90],[47,27],[41,97],[66,5],[33,0],[101,5],[89,125],[6,58],[61,107],[25,17],[104,0],[29,2]], \"k\": 73 }\nassert my_solution.countPairs(**test_input) == 15\n\ntest_input = { \"coordinates\": [[29,23],[8,19],[26,5],[12,25],[37,2],[37,27],[18,68],[3,53],[81,85],[27,94],[29,39],[41,64],[26,28],[23,80],[13,46],[5,68],[16,18],[21,77]], \"k\": 25 }\nassert my_solution.countPairs(**test_input) == 8\n\ntest_input = { \"coordinates\": [[90,31],[113,54],[92,36],[67,49],[123,124],[127,112],[16,24],[85,50],[58,94],[115,48],[83,30],[51,112],[39,23],[0,21],[27,44],[99,100],[122,63],[34,39],[25,48],[44,49],[84,97],[31,61]], \"k\": 84 }\nassert my_solution.countPairs(**test_input) == 10\n\ntest_input = { \"coordinates\": [[51,47],[51,47],[8,14],[82,68],[55,85],[8,14],[51,47],[87,97],[75,65],[78,10],[51,47],[87,97],[74,19],[51,47],[56,66],[8,14],[78,10],[74,66],[65,92],[51,47],[3,31]], \"k\": 0 }\nassert my_solution.countPairs(**test_input) == 20\n\ntest_input = { \"coordinates\": [[25,82],[86,89],[25,82],[47,118],[14,58],[22,51],[0,93],[26,9],[67,27],[43,22],[78,49],[82,15],[93,22],[67,34],[54,43],[61,55],[74,77],[115,108],[54,55],[9,30],[31,3],[26,5],[60,49]], \"k\": 90 }\nassert my_solution.countPairs(**test_input) == 22\n\ntest_input = { \"coordinates\": [[29,23],[48,3],[58,62],[16,19],[0,30],[59,5],[96,50],[7,46],[5,18],[42,32],[78,55]], \"k\": 17 }\nassert my_solution.countPairs(**test_input) == 3\n\ntest_input = { \"coordinates\": [[47,68],[55,68],[36,73],[33,70],[36,81],[60,81],[32,18],[38,95],[34,75],[33,5],[33,78],[32,10],[36,93],[56,77],[43,17],[99,70],[15,77],[42,87],[30,18],[36,56],[47,68],[45,70],[48,77],[53,94],[0,86],[53,9],[68,35],[32,77],[95,90]], \"k\": 24 }\nassert my_solution.countPairs(**test_input) == 31\n\ntest_input = { \"coordinates\": [[5,100],[19,21],[83,36],[24,59],[92,49],[6,73],[57,78],[69,33],[3,81],[53,59],[23,40],[6,21],[57,55],[98,43],[33,15],[8,83],[29,29],[85,41],[47,64],[10,32],[82,94],[14,29],[13,99],[19,20],[85,108],[41,9]], \"k\": 78 }\nassert my_solution.countPairs(**test_input) == 12\n\ntest_input = { \"coordinates\": [[8,94],[19,13],[72,75],[17,8],[57,45],[17,15],[14,95],[74,78],[17,15],[9,95],[79,76],[13,91],[28,76],[94,12],[11,90],[94,11],[94,11],[15,89],[20,13],[23,14],[22,8],[21,71]], \"k\": 7 }\nassert my_solution.countPairs(**test_input) == 24\n\ntest_input = { \"coordinates\": [[37,76],[109,71],[66,1],[55,6],[90,22],[71,24],[3,19],[46,24],[74,74],[85,94],[2,96],[1,48],[31,86],[22,78],[93,80],[3,112],[11,11],[98,18],[81,86],[55,54],[82,18],[127,23]], \"k\": 83 }\nassert my_solution.countPairs(**test_input) == 11\n\ntest_input = { \"coordinates\": [[9,25],[56,25],[7,58],[9,48],[77,55],[6,10],[33,98],[22,26],[41,57],[18,4],[40,74]], \"k\": 49 }\nassert my_solution.countPairs(**test_input) == 8\n\ntest_input = { \"coordinates\": [[91,12],[86,8],[74,12],[85,58],[65,10],[49,51],[43,83],[34,91],[89,63],[26,44],[68,6],[71,8],[92,12],[49,79],[64,26],[0,87],[22,85],[15,72],[17,54],[33,37],[70,9],[88,95],[85,67],[32,85],[94,69],[87,77]], \"k\": 17 }\nassert my_solution.countPairs(**test_input) == 16\n\ntest_input = { \"coordinates\": [[54,60],[31,62],[76,56],[79,44]], \"k\": 52 }\nassert my_solution.countPairs(**test_input) == 0\n\ntest_input = { \"coordinates\": [[41,13],[15,74],[43,51],[44,10],[49,72],[63,48],[50,40],[90,86],[105,13],[11,118],[55,8],[3,39],[27,3],[55,72],[33,98],[10,59],[40,45],[10,59],[40,30],[97,43],[96,55],[47,32],[43,86],[57,61],[1,64]], \"k\": 64 }\nassert my_solution.countPairs(**test_input) == 23\n\ntest_input = { \"coordinates\": [[29,96],[82,101],[1,88],[9,100],[55,42],[37,77],[89,95],[40,10],[111,114],[89,53],[91,33],[93,18],[90,14],[50,49],[27,91],[99,92],[26,15],[69,17],[61,64]], \"k\": 84 }\nassert my_solution.countPairs(**test_input) == 7\n\ntest_input = { \"coordinates\": [[57,88],[83,2],[82,23],[19,7],[43,84],[54,87],[51,38],[61,68],[68,31],[74,49],[64,80],[2,19],[18,73],[52,73],[75,26],[32,71],[91,83],[84,15],[49,76]], \"k\": 30 }\nassert my_solution.countPairs(**test_input) == 8\n\ntest_input = { \"coordinates\": [[34,96],[53,25],[97,70],[48,31],[48,20],[54,26],[42,99],[52,24],[56,100],[35,106],[16,71],[34,69],[42,72],[28,8],[35,97],[103,67],[12,81],[8,86]], \"k\": 11 }\nassert my_solution.countPairs(**test_input) == 10\n\ntest_input = { \"coordinates\": [[60,56],[48,34],[21,82],[63,26],[97,51],[35,63],[39,29],[5,46],[16,115],[19,71],[34,54],[6,65],[11,21],[54,66],[2,103],[13,64],[30,73],[23,58],[31,75],[6,63],[16,66],[21,100]], \"k\": 38 }\nassert my_solution.countPairs(**test_input) == 10\n\ntest_input = { \"coordinates\": [[5,28],[16,39],[38,16],[21,34],[5,22],[73,52],[3,24],[24,37],[11,26]], \"k\": 10 }\nassert my_solution.countPairs(**test_input) == 5\n\ntest_input = { \"coordinates\": [[34,76],[50,71],[55,74],[36,6],[56,77],[56,86],[9,25],[7,38],[34,76],[96,85],[29,32]], \"k\": 27 }\nassert my_solution.countPairs(**test_input) == 8\n\ntest_input = { \"coordinates\": [[69,99],[60,80],[59,72],[74,67],[34,78],[73,95],[65,72],[86,64],[42,89],[90,25],[84,48]], \"k\": 31 }\nassert my_solution.countPairs(**test_input) == 8\n\ntest_input = { \"coordinates\": [[50,75],[84,10],[3,1],[8,12],[41,82],[68,39],[55,31],[4,103],[50,19],[15,85],[20,50],[118,81],[47,14],[1,40],[1,58],[8,58],[18,110],[62,10],[98,69],[25,31],[99,10],[74,29],[124,73]], \"k\": 98 }\nassert my_solution.countPairs(**test_input) == 15\n\ntest_input = { \"coordinates\": [[65,100],[43,13],[80,116],[40,82],[50,5],[53,14],[62,16],[38,8],[83,107],[56,11],[82,92],[62,16],[59,21],[38,8],[55,50],[67,76],[36,65]], \"k\": 33 }\nassert my_solution.countPairs(**test_input) == 14\n\ntest_input = { \"coordinates\": [[52,32],[42,21],[1,56],[93,52],[85,87],[14,58],[39,21],[3,105],[18,13],[5,119],[108,77],[91,81],[22,71],[76,39],[2,59],[23,54],[83,26],[28,23],[33,69],[27,91],[92,19],[53,5],[39,32],[14,124]], \"k\": 83 }\nassert my_solution.countPairs(**test_input) == 21\n\ntest_input = { \"coordinates\": [[84,63],[92,55],[56,94],[89,27],[53,93],[85,80],[65,91],[77,16],[28,99],[48,86],[54,44],[33,47],[47,10],[11,62],[2,17]], \"k\": 16 }\nassert my_solution.countPairs(**test_input) == 4\n\ntest_input = { \"coordinates\": [[78,84],[91,79],[1,35],[73,76],[89,92],[69,94],[78,1],[27,71],[17,58],[18,33],[82,67],[24,59],[23,53],[82,86]], \"k\": 21 }\nassert my_solution.countPairs(**test_input) == 8\n\ntest_input = { \"coordinates\": [[29,53],[40,74],[42,73],[24,53],[79,50],[13,7],[43,72],[26,54],[41,75],[66,27],[43,72],[81,75],[47,73],[74,43],[97,60],[42,76],[46,77],[21,69],[88,77]], \"k\": 5 }\nassert my_solution.countPairs(**test_input) == 16\n\ntest_input = { \"coordinates\": [[21,95],[53,15],[71,7],[22,40],[8,89],[66,62]], \"k\": 74 }\nassert my_solution.countPairs(**test_input) == 1\n\ntest_input = { \"coordinates\": [[93,3],[89,13],[70,48],[75,6],[43,82],[121,49],[80,1],[122,45],[57,45],[96,96],[86,82],[46,62],[63,79],[10,6],[55,36],[63,61],[79,99]], \"k\": 92 }\nassert my_solution.countPairs(**test_input) == 8\n\ntest_input = { \"coordinates\": [[0,36],[77,49],[25,41]], \"k\": 98 }\nassert my_solution.countPairs(**test_input) == 1\n\ntest_input = { \"coordinates\": [[42,18],[48,0],[64,62],[61,7],[33,51],[50,26],[1,91],[24,92]], \"k\": 44 }\nassert my_solution.countPairs(**test_input) == 4\n\ntest_input = { \"coordinates\": [[69,94],[83,39],[2,37],[117,117],[82,54],[20,84],[91,88],[67,63],[43,69],[109,42],[9,69],[46,42],[60,99],[69,74],[81,80],[12,19]], \"k\": 91 }\nassert my_solution.countPairs(**test_input) == 11\n\ntest_input = { \"coordinates\": [[75,44],[90,42],[62,96],[80,91],[82,78],[77,42]], \"k\": 23 }\nassert my_solution.countPairs(**test_input) == 3\n\ntest_input = { \"coordinates\": [[81,20],[74,53],[70,49],[99,66],[11,88]], \"k\": 60 }\nassert my_solution.countPairs(**test_input) == 2\n\ntest_input = { \"coordinates\": [[33,37],[35,52],[49,38],[47,32],[98,98],[84,83],[50,54],[45,34],[105,106],[54,44],[80,57],[96,80],[83,81],[36,22]], \"k\": 19 }\nassert my_solution.countPairs(**test_input) == 7\n\ntest_input = { \"coordinates\": [[45,38],[47,5],[13,69],[88,65],[123,11],[15,30],[91,45],[66,100],[25,50],[63,10],[46,70],[36,77],[27,9],[78,91]], \"k\": 98 }\nassert my_solution.countPairs(**test_input) == 6\n\ntest_input = { \"coordinates\": [[71,58],[60,37],[27,97],[7,56],[56,126],[24,59],[46,76],[15,79],[18,3],[98,8],[110,62],[76,30],[38,63]], \"k\": 66 }\nassert my_solution.countPairs(**test_input) == 8\n\ntest_input = { \"coordinates\": [[21,80],[17,111],[0,126],[20,81],[50,76],[80,32],[7,97],[21,19],[50,91],[58,68],[55,4],[37,56],[20,42],[6,35],[38,72],[96,6],[11,70],[10,91],[11,94],[46,88],[81,64],[37,78],[15,75],[90,79],[13,103],[46,66],[2,95]], \"k\": 67 }\nassert my_solution.countPairs(**test_input) == 26\n\ntest_input = { \"coordinates\": [[65,15],[73,72],[60,97],[101,107],[3,2],[4,20],[90,74],[71,7],[113,95],[39,17],[87,56],[2,76],[27,122],[48,41]], \"k\": 79 }\nassert my_solution.countPairs(**test_input) == 9\n\ntest_input = { \"coordinates\": [[82,41],[27,65],[94,92],[15,82],[56,69],[30,57],[28,28],[5,53],[100,2],[112,44],[23,6],[92,29],[18,69],[124,26],[125,88],[97,54],[7,31],[50,80]], \"k\": 39 }\nassert my_solution.countPairs(**test_input) == 7\n\ntest_input = { \"coordinates\": [[72,31],[86,19],[63,97],[11,118],[8,67],[14,6],[6,69],[51,1],[70,34],[98,68],[84,29],[47,37],[94,75],[73,15],[34,59],[71,42],[45,98],[22,52],[70,94],[67,78],[64,110],[104,5],[65,28],[87,100],[93,10]], \"k\": 75 }\nassert my_solution.countPairs(**test_input) == 10\n\ntest_input = { \"coordinates\": [[90,16],[30,5],[16,71],[21,75],[33,55],[76,76],[16,50],[19,42],[18,59],[30,46],[6,21],[19,73],[35,78],[36,98],[30,77],[6,65],[87,31],[69,46],[62,42],[14,50],[44,29],[86,56]], \"k\": 17 }\nassert my_solution.countPairs(**test_input) == 5\n\ntest_input = { \"coordinates\": [[27,30],[15,52],[26,30],[26,30],[15,53],[75,57],[27,30],[95,67],[26,31],[27,31],[15,53],[90,84],[27,30],[90,85],[10,3],[48,59]], \"k\": 1 }\nassert my_solution.countPairs(**test_input) == 15\n\ntest_input = { \"coordinates\": [[6,12],[53,6],[16,65],[22,42],[66,85]], \"k\": 54 }\nassert my_solution.countPairs(**test_input) == 1\n\ntest_input = { \"coordinates\": [[45,11],[43,19],[35,27],[43,13],[38,28],[41,59],[68,39],[29,47]], \"k\": 30 }\nassert my_solution.countPairs(**test_input) == 5\n\ntest_input = { \"coordinates\": [[39,98],[1,97],[41,90],[1,83],[65,2],[7,27],[79,51],[124,88],[32,97]], \"k\": 87 }\nassert my_solution.countPairs(**test_input) == 2\n\ntest_input = { \"coordinates\": [[54,49],[98,5],[98,25],[75,53],[117,42],[111,6],[31,85],[124,49],[120,115]], \"k\": 70 }\nassert my_solution.countPairs(**test_input) == 4\n\ntest_input = { \"coordinates\": [[33,9],[59,5],[71,12],[36,2],[6,92],[32,81],[45,72],[54,67],[17,83],[64,19],[24,68],[58,56],[69,87],[76,23],[86,14],[40,25],[50,38],[50,71]], \"k\": 38 }\nassert my_solution.countPairs(**test_input) == 8\n\ntest_input = { \"coordinates\": [[7,7],[44,51],[93,41],[43,37],[31,2],[39,52],[12,68],[92,78],[59,78],[95,70],[62,45],[30,79],[7,17],[3,89],[60,35]], \"k\": 29 }\nassert my_solution.countPairs(**test_input) == 6\n\ntest_input = { \"coordinates\": [[77,91],[3,84],[91,18],[83,18],[56,94],[92,19],[69,83],[88,0],[73,95],[65,87],[95,89],[90,90],[19,36],[94,1],[20,18],[14,62],[77,62],[76,92],[14,55],[22,39],[75,95],[94,17],[21,38]], \"k\": 8 }\nassert my_solution.countPairs(**test_input) == 10\n\ntest_input = { \"coordinates\": [[27,49],[44,38],[99,7],[32,33],[60,98],[98,84],[93,89],[85,80]], \"k\": 95 }\nassert my_solution.countPairs(**test_input) == 1\n\ntest_input = { \"coordinates\": [[86,74],[117,67],[106,78],[66,82],[15,75],[76,72],[116,64],[85,51],[109,87],[75,69],[103,89],[80,20],[101,95],[124,76],[91,53],[100,84],[112,108],[45,94],[14,96]], \"k\": 44 }\nassert my_solution.countPairs(**test_input) == 19\n\ntest_input = { \"coordinates\": [[43,81],[53,103],[106,66],[75,67],[88,96],[112,90],[23,87],[26,70],[75,78],[102,100],[82,15],[69,5],[32,106],[38,116],[10,32],[48,46],[7,93],[61,43],[11,38],[4,99],[58,4],[29,10],[28,6],[40,80],[7,110],[95,91],[24,56],[92,53]], \"k\": 84 }\nassert my_solution.countPairs(**test_input) == 19\n\ntest_input = { \"coordinates\": [[28,78],[90,77],[51,40],[67,125],[31,62],[19,116],[3,79],[61,5],[39,7],[27,9],[56,33],[100,69],[30,72],[0,66],[17,54],[123,6],[87,72],[11,25],[24,49],[103,81],[37,58],[26,53],[23,45],[120,1],[39,96],[58,84],[97,5]], \"k\": 73 }\nassert my_solution.countPairs(**test_input) == 17\n\ntest_input = { \"coordinates\": [[63,22],[10,98],[61,3],[7,4],[0,111],[56,17],[50,11],[30,97],[16,2],[59,77],[4,48],[42,94],[63,1],[42,3],[13,9],[27,100],[60,30],[1,34],[54,43],[3,32],[15,60],[39,9],[52,82],[19,7],[42,82],[88,96]], \"k\": 23 }\nassert my_solution.countPairs(**test_input) == 18\n\ntest_input = { \"coordinates\": [[76,84],[58,43],[15,66],[83,35],[38,10],[12,44],[70,34],[20,36],[13,29],[17,24],[53,100]], \"k\": 61 }\nassert my_solution.countPairs(**test_input) == 3\n\ntest_input = { \"coordinates\": [[5,32],[28,98],[26,96],[30,100],[29,101],[32,50],[0,73],[29,101],[65,92],[54,15],[1,36],[68,46],[98,62],[67,90],[28,98],[12,81],[16,83],[55,77],[49,14],[0,12],[25,101],[27,99],[4,47],[19,99],[63,62],[56,92]], \"k\": 8 }\nassert my_solution.countPairs(**test_input) == 18\n\ntest_input = { \"coordinates\": [[95,54],[53,94],[90,47],[89,90],[90,47],[73,36],[73,84],[72,49],[63,91],[39,66],[57,80],[80,59]], \"k\": 30 }\nassert my_solution.countPairs(**test_input) == 8\n\ntest_input = { \"coordinates\": [[66,53],[64,2],[94,55],[85,23],[74,7],[18,83],[32,95],[55,13],[81,34],[25,125],[73,75],[49,32],[57,19],[0,19],[72,79],[65,8],[118,38],[44,44],[68,16],[62,62],[0,116],[60,21]], \"k\": 57 }\nassert my_solution.countPairs(**test_input) == 7\n\ntest_input = { \"coordinates\": [[38,73],[37,117],[95,92],[28,22],[16,64],[53,0],[65,85],[91,16],[82,28],[57,9],[53,75],[47,45],[30,43],[91,47],[56,94],[53,39]], \"k\": 63 }\nassert my_solution.countPairs(**test_input) == 5\n\ntest_input = { \"coordinates\": [[11,11],[96,86],[86,64],[94,11],[121,100],[68,1],[84,54],[21,40],[8,3],[96,44],[96,127],[42,25],[43,119],[94,10],[71,0],[84,96],[79,73],[37,11],[74,15],[4,53],[27,59],[0,67]], \"k\": 83 }\nassert my_solution.countPairs(**test_input) == 13\n\ntest_input = { \"coordinates\": [[0,8],[45,94],[87,72],[12,98],[4,16],[91,88],[26,100],[8,31],[56,89],[13,54],[22,26],[2,18],[7,36],[19,13],[61,72],[44,10],[44,87],[1,38],[25,23],[24,36],[21,50],[27,13],[95,68],[15,13],[54,68],[5,62]], \"k\": 28 }\nassert my_solution.countPairs(**test_input) == 17\n\ntest_input = { \"coordinates\": [[97,95],[100,90],[99,87],[100,80],[102,82],[4,7],[0,69],[99,89]], \"k\": 10 }\nassert my_solution.countPairs(**test_input) == 6\n\ntest_input = { \"coordinates\": [[22,68],[75,70],[67,78]], \"k\": 95 }\nassert my_solution.countPairs(**test_input) == 2\n\ntest_input = { \"coordinates\": [[36,33],[73,78],[41,27],[58,34],[10,67]], \"k\": 80 }\nassert my_solution.countPairs(**test_input) == 1\n\ntest_input = { \"coordinates\": [[2,37],[39,2],[12,57],[33,38],[73,36],[85,22],[9,95],[31,64],[22,3]], \"k\": 76 }\nassert my_solution.countPairs(**test_input) == 4\n\ntest_input = { \"coordinates\": [[44,0],[95,53],[37,6],[40,4],[5,73],[33,2],[16,71],[36,8],[87,50],[31,71],[83,57],[4,31],[35,79],[12,70],[93,55],[21,77],[97,9],[95,53],[10,73],[78,100],[22,48],[87,50],[74,64]], \"k\": 15 }\nassert my_solution.countPairs(**test_input) == 17\n\ntest_input = { \"coordinates\": [[16,39],[17,57],[14,38],[22,62],[69,40],[2,53],[23,63],[20,35],[25,49]], \"k\": 31 }\nassert my_solution.countPairs(**test_input) == 15\n\ntest_input = { \"coordinates\": [[0,46],[13,69],[38,80],[60,17],[72,83],[27,78],[21,9],[9,29],[84,39],[59,117],[79,65],[1,116],[90,71],[53,91],[46,3],[100,73],[105,23],[12,81],[113,84],[111,25],[27,1],[48,49],[51,53],[93,83],[48,29],[27,21],[9,71]], \"k\": 91 }\nassert my_solution.countPairs(**test_input) == 19\n\ntest_input = { \"coordinates\": [[50,93],[12,98],[26,22],[50,19],[20,70],[53,119],[1,127],[38,100],[52,116],[89,71],[9,98],[34,94],[12,98],[29,119],[60,29],[97,81],[102,84],[13,15],[10,28],[40,26],[16,87],[45,83],[55,83],[62,35],[30,94],[7,75],[14,86],[16,12],[73,88],[60,124]], \"k\": 78 }\nassert my_solution.countPairs(**test_input) == 26\n\ntest_input = { \"coordinates\": [[19,26],[2,28],[3,10],[42,61],[56,56]], \"k\": 23 }\nassert my_solution.countPairs(**test_input) == 3\n\ntest_input = { \"coordinates\": [[56,55],[42,83],[35,97],[28,32],[52,76],[34,20],[68,88],[90,38],[99,76],[32,20],[22,85],[50,34],[4,11],[17,92],[59,80],[66,65],[47,60]], \"k\": 59 }\nassert my_solution.countPairs(**test_input) == 6\n\ntest_input = { \"coordinates\": [[87,78],[72,88],[82,69],[88,79],[36,24],[42,15],[66,94],[32,10],[92,71],[46,89],[74,86],[37,23],[61,44],[66,87],[35,17],[91,78],[43,15],[61,75],[62,70],[61,70],[34,7],[85,64],[35,20],[42,22],[41,27],[82,85],[90,89],[41,13]], \"k\": 16 }\nassert my_solution.countPairs(**test_input) == 20\n\ntest_input = { \"coordinates\": [[48,86],[98,33],[46,68],[91,21],[39,73]], \"k\": 22 }\nassert my_solution.countPairs(**test_input) == 1\n\ntest_input = { \"coordinates\": [[71,47],[68,44],[65,45],[97,43],[97,45],[97,45],[71,41],[103,43],[96,20],[99,41],[57,4],[17,77],[68,44],[16,72],[17,75],[64,69],[19,75],[99,41],[2,21],[71,47],[91,4],[57,2]], \"k\": 6 }\nassert my_solution.countPairs(**test_input) == 21\n\ntest_input = { \"coordinates\": [[5,11],[16,87],[48,55],[26,15],[41,58],[12,14],[81,66],[30,5]], \"k\": 14 }\nassert my_solution.countPairs(**test_input) == 2\n\ntest_input = { \"coordinates\": [[85,89],[119,89],[34,16],[54,41],[55,29],[33,34],[54,30],[80,74],[12,92],[42,49],[69,7],[47,13],[26,38],[39,96],[61,58],[24,48],[46,47]], \"k\": 34 }\nassert my_solution.countPairs(**test_input) == 6\n\ntest_input = { \"coordinates\": [[35,45],[58,17],[64,60],[117,23],[18,63],[26,55],[65,54]], \"k\": 85 }\nassert my_solution.countPairs(**test_input) == 4\n\ntest_input = { \"coordinates\": [[60,1],[57,6],[39,3],[58,7],[61,14],[19,80],[46,0],[84,35],[43,3],[46,4],[48,71],[48,75],[85,40],[46,45],[6,20],[35,7],[57,6],[51,78],[68,25],[17,0]], \"k\": 12 }\nassert my_solution.countPairs(**test_input) == 12\n\ntest_input = { \"coordinates\": [[95,0],[36,24],[68,27],[80,14],[39,2],[93,52],[107,52],[86,63],[82,13],[55,14],[8,52],[99,20],[101,36],[50,70],[26,98],[95,41]], \"k\": 54 }\nassert my_solution.countPairs(**test_input) == 8\n\ntest_input = { \"coordinates\": [[43,14],[55,83],[33,89],[44,74],[46,84],[51,87],[61,69],[1,89]], \"k\": 32 }\nassert my_solution.countPairs(**test_input) == 10\n\ntest_input = { \"coordinates\": [[88,15],[93,65],[52,39],[20,24],[100,36],[39,17],[26,77],[52,39],[47,83],[98,99],[43,28],[72,29],[21,48],[43,32],[60,108],[44,47],[45,125],[84,94]], \"k\": 83 }\nassert my_solution.countPairs(**test_input) == 13\n\ntest_input = { \"coordinates\": [[12,2],[43,87],[21,100],[79,63],[5,6],[70,75],[20,55],[23,55],[17,31],[121,89],[27,71],[27,22],[42,34],[15,14],[16,40],[49,68],[30,48],[45,43],[88,23],[47,15],[16,41],[8,5]], \"k\": 81 }\nassert my_solution.countPairs(**test_input) == 8", "start_time": 1694874600} +{"task_id": "biweekly-contest-113-minimum-edge-reversals-so-every-node-is-reachable", "url": "https://leetcode.com/problems/minimum-edge-reversals-so-every-node-is-reachable", "title": "minimum-edge-reversals-so-every-node-is-reachable", "meta": {"questionId": "3105", "questionFrontendId": "2858", "title": "Minimum Edge Reversals So Every Node Is Reachable", "titleSlug": "minimum-edge-reversals-so-every-node-is-reachable", "isPaidOnly": false, "difficulty": "Hard", "likes": 227, "dislikes": 3, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nThere is a simple directed graph with n nodes labeled from 0 to n - 1. The graph would form a tree if its edges were bi-directional.\n\nYou are given an integer n and a 2D integer array edges, where edges[i] = [ui, vi] represents a directed edge going from node ui to node vi.\n\nAn edge reversal changes the direction of an edge, i.e., a directed edge going from node ui to node vi becomes a directed edge going from node vi to node ui.\n\nFor every node i in the range [0, n - 1], your task is to independently calculate the minimum number of edge reversals required so it is possible to reach any other node starting from node i through a sequence of directed edges.\n\nReturn an integer array answer, where answer[i] is the minimum number of edge reversals required so it is possible to reach any other node starting from node i through a sequence of directed edges.\n\nExample 1:\n\n[https://assets.leetcode.com/uploads/2023/08/26/image-20230826221104-3.png]\n\nInput: n = 4, edges = [[2,0],[2,1],[1,3]]\nOutput: [1,1,0,2]\nExplanation: The image above shows the graph formed by the edges.\nFor node 0: after reversing the edge [2,0], it is possible to reach any other node starting from node 0.\nSo, answer[0] = 1.\nFor node 1: after reversing the edge [2,1], it is possible to reach any other node starting from node 1.\nSo, answer[1] = 1.\nFor node 2: it is already possible to reach any other node starting from node 2.\nSo, answer[2] = 0.\nFor node 3: after reversing the edges [1,3] and [2,1], it is possible to reach any other node starting from node 3.\nSo, answer[3] = 2.\n\nExample 2:\n\n[https://assets.leetcode.com/uploads/2023/08/26/image-20230826225541-2.png]\n\nInput: n = 3, edges = [[1,2],[2,0]]\nOutput: [2,0,1]\nExplanation: The image above shows the graph formed by the edges.\nFor node 0: after reversing the edges [2,0] and [1,2], it is possible to reach any other node starting from node 0.\nSo, answer[0] = 2.\nFor node 1: it is already possible to reach any other node starting from node 1.\nSo, answer[1] = 0.\nFor node 2: after reversing the edge [1, 2], it is possible to reach any other node starting from node 2.\nSo, answer[2] = 1.\n\n\nConstraints:\n\n * 2 <= n <= 105\n * edges.length == n - 1\n * edges[i].length == 2\n * 0 <= ui == edges[i][0] < n\n * 0 <= vi == edges[i][1] < n\n * ui != vi\n * The input is generated such that if the edges were bi-directional, the graph would be a tree.\n\"\"\"\nclass Solution:\n def minEdgeReversals(self, n: int, edges: List[List[int]]) -> List[int]:\n ", "prompt_sft": "There is a simple directed graph with n nodes labeled from 0 to n - 1. The graph would form a tree if its edges were bi-directional.\n\nYou are given an integer n and a 2D integer array edges, where edges[i] = [ui, vi] represents a directed edge going from node ui to node vi.\n\nAn edge reversal changes the direction of an edge, i.e., a directed edge going from node ui to node vi becomes a directed edge going from node vi to node ui.\n\nFor every node i in the range [0, n - 1], your task is to independently calculate the minimum number of edge reversals required so it is possible to reach any other node starting from node i through a sequence of directed edges.\n\nReturn an integer array answer, where answer[i] is the minimum number of edge reversals required so it is possible to reach any other node starting from node i through a sequence of directed edges.\n\nExample 1:\n\n[https://assets.leetcode.com/uploads/2023/08/26/image-20230826221104-3.png]\n\nInput: n = 4, edges = [[2,0],[2,1],[1,3]]\nOutput: [1,1,0,2]\nExplanation: The image above shows the graph formed by the edges.\nFor node 0: after reversing the edge [2,0], it is possible to reach any other node starting from node 0.\nSo, answer[0] = 1.\nFor node 1: after reversing the edge [2,1], it is possible to reach any other node starting from node 1.\nSo, answer[1] = 1.\nFor node 2: it is already possible to reach any other node starting from node 2.\nSo, answer[2] = 0.\nFor node 3: after reversing the edges [1,3] and [2,1], it is possible to reach any other node starting from node 3.\nSo, answer[3] = 2.\n\nExample 2:\n\n[https://assets.leetcode.com/uploads/2023/08/26/image-20230826225541-2.png]\n\nInput: n = 3, edges = [[1,2],[2,0]]\nOutput: [2,0,1]\nExplanation: The image above shows the graph formed by the edges.\nFor node 0: after reversing the edges [2,0] and [1,2], it is possible to reach any other node starting from node 0.\nSo, answer[0] = 2.\nFor node 1: it is already possible to reach any other node starting from node 1.\nSo, answer[1] = 0.\nFor node 2: after reversing the edge [1, 2], it is possible to reach any other node starting from node 2.\nSo, answer[2] = 1.\n\n\nConstraints:\n\n * 2 <= n <= 105\n * edges.length == n - 1\n * edges[i].length == 2\n * 0 <= ui == edges[i][0] < n\n * 0 <= vi == edges[i][1] < n\n * ui != vi\n * The input is generated such that if the edges were bi-directional, the graph would be a tree.\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def minEdgeReversals(self, n: int, edges: List[List[int]]) -> List[int]:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"n\": 4, \"edges\": [[2,0],[2,1],[1,3]] }\nassert my_solution.minEdgeReversals(**test_input) == [1,1,0,2]\n\ntest_input = { \"n\": 3, \"edges\": [[1,2],[2,0]] }\nassert my_solution.minEdgeReversals(**test_input) == [2,0,1]\n\ntest_input = { \"n\": 2, \"edges\": [[0,1]] }\nassert my_solution.minEdgeReversals(**test_input) == [0,1]\n\ntest_input = { \"n\": 3, \"edges\": [[2,0],[2,1]] }\nassert my_solution.minEdgeReversals(**test_input) == [1,1,0]\n\ntest_input = { \"n\": 4, \"edges\": [[0,1],[3,0],[2,3]] }\nassert my_solution.minEdgeReversals(**test_input) == [2,3,0,1]\n\ntest_input = { \"n\": 4, \"edges\": [[0,2],[0,3],[3,1]] }\nassert my_solution.minEdgeReversals(**test_input) == [0,2,1,1]\n\ntest_input = { \"n\": 4, \"edges\": [[0,3],[1,2],[2,3]] }\nassert my_solution.minEdgeReversals(**test_input) == [2,1,2,3]\n\ntest_input = { \"n\": 4, \"edges\": [[0,3],[1,2],[3,1]] }\nassert my_solution.minEdgeReversals(**test_input) == [0,2,3,1]\n\ntest_input = { \"n\": 4, \"edges\": [[0,3],[2,1],[3,1]] }\nassert my_solution.minEdgeReversals(**test_input) == [1,3,2,2]\n\ntest_input = { \"n\": 4, \"edges\": [[1,0],[2,0],[3,2]] }\nassert my_solution.minEdgeReversals(**test_input) == [3,2,2,1]\n\ntest_input = { \"n\": 5, \"edges\": [[0,1],[0,4],[2,3],[4,2]] }\nassert my_solution.minEdgeReversals(**test_input) == [0,1,2,3,1]\n\ntest_input = { \"n\": 5, \"edges\": [[0,1],[2,0],[0,4],[3,4]] }\nassert my_solution.minEdgeReversals(**test_input) == [2,3,1,2,3]\n\ntest_input = { \"n\": 5, \"edges\": [[0,2],[0,1],[3,1],[4,1]] }\nassert my_solution.minEdgeReversals(**test_input) == [2,3,3,2,2]\n\ntest_input = { \"n\": 5, \"edges\": [[0,2],[0,1],[3,1],[4,3]] }\nassert my_solution.minEdgeReversals(**test_input) == [2,3,3,2,1]\n\ntest_input = { \"n\": 5, \"edges\": [[0,2],[1,3],[1,4],[2,4]] }\nassert my_solution.minEdgeReversals(**test_input) == [1,2,2,3,3]\n\ntest_input = { \"n\": 5, \"edges\": [[0,2],[1,3],[2,3],[4,2]] }\nassert my_solution.minEdgeReversals(**test_input) == [2,3,3,4,2]\n\ntest_input = { \"n\": 5, \"edges\": [[0,2],[2,1],[2,3],[4,3]] }\nassert my_solution.minEdgeReversals(**test_input) == [1,3,2,3,2]\n\ntest_input = { \"n\": 5, \"edges\": [[0,3],[0,4],[1,2],[4,1]] }\nassert my_solution.minEdgeReversals(**test_input) == [0,2,3,1,1]\n\ntest_input = { \"n\": 5, \"edges\": [[1,0],[3,0],[0,4],[2,3]] }\nassert my_solution.minEdgeReversals(**test_input) == [3,2,1,2,4]\n\ntest_input = { \"n\": 5, \"edges\": [[3,0],[0,4],[1,3],[2,3]] }\nassert my_solution.minEdgeReversals(**test_input) == [3,1,1,2,4]\n\ntest_input = { \"n\": 6, \"edges\": [[0,1],[0,5],[1,2],[3,2],[2,4]] }\nassert my_solution.minEdgeReversals(**test_input) == [1,2,3,2,4,2]\n\ntest_input = { \"n\": 6, \"edges\": [[0,1],[2,1],[1,5],[2,3],[4,3]] }\nassert my_solution.minEdgeReversals(**test_input) == [2,3,2,3,2,4]\n\ntest_input = { \"n\": 6, \"edges\": [[0,2],[0,3],[0,1],[0,5],[1,4]] }\nassert my_solution.minEdgeReversals(**test_input) == [0,1,1,1,2,1]\n\ntest_input = { \"n\": 6, \"edges\": [[0,2],[1,3],[1,2],[2,4],[2,5]] }\nassert my_solution.minEdgeReversals(**test_input) == [1,1,2,2,3,3]\n\ntest_input = { \"n\": 6, \"edges\": [[0,4],[1,2],[3,1],[5,1],[4,5]] }\nassert my_solution.minEdgeReversals(**test_input) == [1,4,5,3,2,3]\n\ntest_input = { \"n\": 6, \"edges\": [[1,0],[0,4],[2,4],[2,3],[3,5]] }\nassert my_solution.minEdgeReversals(**test_input) == [2,1,2,3,3,4]\n\ntest_input = { \"n\": 6, \"edges\": [[1,0],[3,1],[1,4],[2,5],[4,5]] }\nassert my_solution.minEdgeReversals(**test_input) == [3,2,3,1,3,4]\n\ntest_input = { \"n\": 7, \"edges\": [[0,5],[2,0],[1,3],[6,2],[4,3],[3,5]] }\nassert my_solution.minEdgeReversals(**test_input) == [5,4,4,5,4,6,3]\n\ntest_input = { \"n\": 7, \"edges\": [[0,6],[2,1],[6,1],[2,5],[5,3],[6,4]] }\nassert my_solution.minEdgeReversals(**test_input) == [1,3,2,4,3,3,2]\n\ntest_input = { \"n\": 7, \"edges\": [[5,0],[2,0],[6,1],[2,4],[2,3],[3,6]] }\nassert my_solution.minEdgeReversals(**test_input) == [2,4,1,2,2,1,3]\n\ntest_input = { \"n\": 8, \"edges\": [[0,4],[0,3],[7,0],[1,4],[2,5],[2,3],[6,5]] }\nassert my_solution.minEdgeReversals(**test_input) == [4,4,4,5,5,5,4,3]\n\ntest_input = { \"n\": 8, \"edges\": [[0,5],[1,0],[1,6],[1,2],[2,3],[2,7],[4,7]] }\nassert my_solution.minEdgeReversals(**test_input) == [2,1,2,3,2,3,2,3]\n\ntest_input = { \"n\": 8, \"edges\": [[1,0],[7,1],[2,6],[5,2],[3,6],[5,4],[5,7]] }\nassert my_solution.minEdgeReversals(**test_input) == [4,3,2,2,2,1,3,2]\n\ntest_input = { \"n\": 8, \"edges\": [[2,0],[5,0],[3,1],[1,4],[6,2],[4,5],[7,5]] }\nassert my_solution.minEdgeReversals(**test_input) == [7,4,6,3,5,6,5,5]\n\ntest_input = { \"n\": 8, \"edges\": [[4,0],[0,1],[1,3],[3,2],[6,2],[2,7],[5,7]] }\nassert my_solution.minEdgeReversals(**test_input) == [3,4,6,5,2,6,5,7]\n\ntest_input = { \"n\": 8, \"edges\": [[4,0],[7,1],[2,3],[7,2],[5,3],[4,6],[7,6]] }\nassert my_solution.minEdgeReversals(**test_input) == [3,3,3,4,2,3,3,2]\n\ntest_input = { \"n\": 9, \"edges\": [[0,5],[0,2],[0,7],[0,4],[7,1],[3,2],[6,3],[8,4]] }\nassert my_solution.minEdgeReversals(**test_input) == [3,5,4,3,4,4,2,4,3]\n\ntest_input = { \"n\": 9, \"edges\": [[0,5],[0,6],[0,2],[5,1],[7,2],[4,2],[3,6],[8,4]] }\nassert my_solution.minEdgeReversals(**test_input) == [4,6,5,4,4,5,5,4,3]\n\ntest_input = { \"n\": 9, \"edges\": [[0,5],[7,0],[1,6],[1,3],[2,8],[3,4],[3,7],[7,8]] }\nassert my_solution.minEdgeReversals(**test_input) == [4,1,3,2,3,5,2,3,4]\n\ntest_input = { \"n\": 9, \"edges\": [[2,0],[1,6],[1,5],[2,3],[2,5],[4,5],[5,7],[8,7]] }\nassert my_solution.minEdgeReversals(**test_input) == [4,3,3,4,3,4,4,5,4]\n\ntest_input = { \"n\": 9, \"edges\": [[7,0],[0,6],[1,2],[2,6],[3,6],[4,5],[5,8],[8,6]] }\nassert my_solution.minEdgeReversals(**test_input) == [7,6,7,7,5,6,8,6,7]\n\ntest_input = { \"n\": 10, \"edges\": [[0,1],[0,2],[2,4],[6,2],[3,9],[5,4],[4,8],[5,7],[9,6]] }\nassert my_solution.minEdgeReversals(**test_input) == [4,5,5,2,6,5,4,6,7,3]\n\ntest_input = { \"n\": 10, \"edges\": [[0,3],[0,5],[0,1],[8,1],[6,1],[2,3],[4,6],[9,4],[5,7]] }\nassert my_solution.minEdgeReversals(**test_input) == [5,6,5,6,4,6,5,7,5,3]\n\ntest_input = { \"n\": 10, \"edges\": [[0,5],[1,3],[1,9],[2,7],[4,2],[6,3],[3,4],[5,4],[7,8]] }\nassert my_solution.minEdgeReversals(**test_input) == [3,3,6,4,5,4,3,7,8,4]\n\ntest_input = { \"n\": 10, \"edges\": [[1,0],[0,5],[6,0],[2,3],[4,2],[2,6],[8,2],[2,9],[8,7]] }\nassert my_solution.minEdgeReversals(**test_input) == [5,4,3,4,2,6,4,3,2,4]\n\ntest_input = { \"n\": 10, \"edges\": [[6,0],[7,0],[4,1],[1,9],[2,7],[9,2],[3,7],[5,7],[8,9]] }\nassert my_solution.minEdgeReversals(**test_input) == [9,5,7,7,4,7,8,8,5,6]\n\ntest_input = { \"n\": 10, \"edges\": [[7,0],[1,2],[1,9],[2,3],[2,8],[5,3],[4,6],[6,7],[7,9]] }\nassert my_solution.minEdgeReversals(**test_input) == [5,4,5,6,2,5,3,4,6,5]\n\ntest_input = { \"n\": 10, \"edges\": [[7,0],[1,5],[2,6],[8,2],[7,3],[4,5],[5,6],[9,7],[8,9]] }\nassert my_solution.minEdgeReversals(**test_input) == [6,3,4,6,3,4,5,5,3,4]\n\ntest_input = { \"n\": 11, \"edges\": [[0,1],[1,2],[8,1],[2,4],[3,9],[3,7],[6,4],[5,7],[5,6],[10,8]] }\nassert my_solution.minEdgeReversals(**test_input) == [5,6,7,6,8,6,7,7,5,7,4]\n\ntest_input = { \"n\": 11, \"edges\": [[0,3],[0,2],[1,4],[1,5],[2,9],[3,5],[7,6],[7,9],[7,8],[8,10]] }\nassert my_solution.minEdgeReversals(**test_input) == [2,3,3,3,4,4,4,3,4,4,5]\n\ntest_input = { \"n\": 11, \"edges\": [[0,3],[0,7],[0,9],[0,10],[1,4],[4,2],[2,6],[6,3],[5,6],[7,8]] }\nassert my_solution.minEdgeReversals(**test_input) == [5,2,4,6,3,4,5,6,7,6,6]\n\ntest_input = { \"n\": 11, \"edges\": [[2,0],[0,9],[1,5],[2,8],[3,5],[3,8],[9,4],[9,6],[6,10],[7,10]] }\nassert my_solution.minEdgeReversals(**test_input) == [4,3,3,3,6,4,6,6,4,5,7]\n\ntest_input = { \"n\": 11, \"edges\": [[6,0],[0,1],[1,4],[2,8],[9,3],[4,10],[5,8],[5,6],[6,9],[10,7]] }\nassert my_solution.minEdgeReversals(**test_input) == [3,4,1,4,5,1,2,7,2,3,6]\n\ntest_input = { \"n\": 11, \"edges\": [[7,0],[1,0],[1,6],[5,1],[4,2],[8,2],[9,2],[7,3],[5,9],[10,5]] }\nassert my_solution.minEdgeReversals(**test_input) == [6,5,6,6,5,4,6,5,5,5,3]\n\ntest_input = { \"n\": 11, \"edges\": [[8,0],[6,1],[7,1],[1,10],[3,2],[4,3],[3,8],[5,8],[8,9],[9,10]] }\nassert my_solution.minEdgeReversals(**test_input) == [7,7,6,5,4,5,6,6,6,7,8]\n\ntest_input = { \"n\": 11, \"edges\": [[10,0],[1,2],[1,10],[2,8],[3,9],[3,5],[4,6],[7,4],[4,8],[5,8]] }\nassert my_solution.minEdgeReversals(**test_input) == [6,4,5,4,5,5,6,4,6,5,5]\n\ntest_input = { \"n\": 12, \"edges\": [[0,10],[1,3],[1,10],[2,7],[2,11],[3,4],[5,9],[5,11],[6,9],[9,8],[9,10]] }\nassert my_solution.minEdgeReversals(**test_input) == [5,5,4,6,7,4,4,5,6,5,6,5]\n\ntest_input = { \"n\": 12, \"edges\": [[3,0],[10,0],[6,0],[1,9],[3,2],[4,6],[4,7],[5,11],[11,7],[8,10],[9,11]] }\nassert my_solution.minEdgeReversals(**test_input) == [9,5,9,8,7,6,8,8,7,6,8,7]\n\ntest_input = { \"n\": 12, \"edges\": [[4,0],[11,0],[1,9],[1,3],[6,2],[2,7],[2,3],[3,10],[4,10],[5,6],[10,8]] }\nassert my_solution.minEdgeReversals(**test_input) == [7,5,5,6,6,3,4,6,8,6,7,6]\n\ntest_input = { \"n\": 12, \"edges\": [[10,0],[0,3],[1,6],[1,8],[1,5],[2,3],[2,4],[3,5],[4,7],[4,11],[10,9]] }\nassert my_solution.minEdgeReversals(**test_input) == [3,4,3,4,4,5,5,5,5,3,2,5]\n\ntest_input = { \"n\": 13, \"edges\": [[0,5],[1,10],[2,4],[2,7],[10,2],[3,5],[5,12],[11,6],[6,12],[8,10],[8,11],[10,9]] }\nassert my_solution.minEdgeReversals(**test_input) == [5,4,6,5,7,6,6,7,4,6,5,5,7]\n\ntest_input = { \"n\": 13, \"edges\": [[0,11],[1,4],[1,8],[1,3],[3,2],[10,3],[12,3],[12,5],[6,11],[10,7],[9,10],[11,12]] }\nassert my_solution.minEdgeReversals(**test_input) == [4,6,8,7,7,7,4,7,7,5,6,5,6]\n\ntest_input = { \"n\": 13, \"edges\": [[5,0],[0,2],[0,9],[10,1],[6,1],[7,2],[2,6],[3,7],[8,4],[4,11],[4,12],[9,12]] }\nassert my_solution.minEdgeReversals(**test_input) == [6,9,7,5,7,5,8,6,6,7,8,8,8]\n\ntest_input = { \"n\": 13, \"edges\": [[7,0],[3,1],[2,4],[2,8],[10,2],[3,10],[9,5],[5,7],[6,11],[6,12],[12,7],[10,12]] }\nassert my_solution.minEdgeReversals(**test_input) == [7,4,5,3,6,5,4,6,6,4,4,5,5]\n\ntest_input = { \"n\": 14, \"edges\": [[0,1],[0,7],[2,6],[2,8],[11,3],[4,12],[4,11],[5,10],[7,11],[13,7],[8,10],[10,9],[9,12]] }\nassert my_solution.minEdgeReversals(**test_input) == [7,8,5,10,8,6,6,8,6,8,7,9,9,7]\n\ntest_input = { \"n\": 14, \"edges\": [[0,1],[1,2],[2,8],[9,2],[6,2],[13,2],[3,4],[5,4],[7,5],[6,10],[12,6],[11,7],[11,10]] }\nassert my_solution.minEdgeReversals(**test_input) == [6,7,8,9,10,9,7,8,9,7,8,7,6,7]\n\ntest_input = { \"n\": 14, \"edges\": [[0,2],[0,3],[0,13],[1,3],[2,4],[8,2],[11,3],[12,3],[4,6],[5,7],[7,9],[7,11],[10,12]] }\nassert my_solution.minEdgeReversals(**test_input) == [7,7,8,8,9,5,10,6,7,7,6,7,7,8]\n\ntest_input = { \"n\": 14, \"edges\": [[0,4],[0,8],[1,3],[1,13],[2,9],[4,11],[4,12],[5,11],[8,6],[13,6],[7,9],[7,8],[10,8]] }\nassert my_solution.minEdgeReversals(**test_input) == [6,6,6,7,7,7,8,6,7,7,6,8,8,7]\n\ntest_input = { \"n\": 14, \"edges\": [[0,6],[5,0],[2,0],[12,1],[13,2],[12,3],[4,7],[5,7],[7,12],[8,13],[9,11],[9,10],[10,13]] }\nassert my_solution.minEdgeReversals(**test_input) == [7,9,6,9,6,6,8,7,4,3,4,4,8,5]\n\ntest_input = { \"n\": 14, \"edges\": [[0,9],[0,11],[0,5],[1,6],[1,11],[7,2],[3,5],[3,12],[3,13],[11,4],[6,10],[9,7],[11,8]] }\nassert my_solution.minEdgeReversals(**test_input) == [2,2,5,2,4,3,3,4,4,3,4,3,3,3]\n\ntest_input = { \"n\": 14, \"edges\": [[0,11],[1,2],[1,10],[1,6],[3,6],[4,11],[10,4],[5,12],[13,6],[8,7],[8,9],[8,12],[8,13]] }\nassert my_solution.minEdgeReversals(**test_input) == [7,5,6,5,7,4,6,5,4,5,6,8,5,5]\n\ntest_input = { \"n\": 14, \"edges\": [[1,0],[1,8],[7,2],[2,11],[2,13],[3,9],[8,3],[3,11],[4,12],[4,8],[5,11],[6,10],[10,12]] }\nassert my_solution.minEdgeReversals(**test_input) == [7,6,8,8,6,8,5,7,7,9,6,9,7,9]\n\ntest_input = { \"n\": 14, \"edges\": [[1,0],[11,0],[6,0],[7,2],[2,8],[10,3],[4,10],[5,12],[12,6],[13,6],[7,10],[9,8],[8,12]] }\nassert my_solution.minEdgeReversals(**test_input) == [11,10,7,8,6,8,10,6,8,7,7,10,9,9]\n\ntest_input = { \"n\": 14, \"edges\": [[3,0],[5,0],[0,7],[1,8],[1,4],[12,2],[4,3],[10,3],[12,5],[13,6],[7,13],[9,10],[10,11]] }\nassert my_solution.minEdgeReversals(**test_input) == [7,4,6,6,5,6,10,8,5,4,5,6,5,9]\n\ntest_input = { \"n\": 15, \"edges\": [[0,5],[1,9],[4,1],[1,5],[14,1],[2,5],[4,3],[4,6],[5,11],[5,7],[10,6],[7,8],[13,7],[14,12]] }\nassert my_solution.minEdgeReversals(**test_input) == [6,6,6,6,5,7,6,8,9,7,5,8,6,7,5]\n\ntest_input = { \"n\": 15, \"edges\": [[0,6],[13,0],[1,2],[10,1],[3,12],[4,11],[5,12],[10,7],[9,7],[7,13],[11,8],[8,9],[12,11],[13,14]] }\nassert my_solution.minEdgeReversals(**test_input) == [10,8,9,3,4,3,11,8,6,7,7,5,4,9,10]\n\ntest_input = { \"n\": 15, \"edges\": [[0,7],[12,1],[5,2],[4,2],[3,8],[3,14],[12,4],[4,7],[5,6],[10,5],[11,5],[6,9],[7,14],[13,12]] }\nassert my_solution.minEdgeReversals(**test_input) == [7,7,8,8,7,7,8,8,9,9,6,6,6,5,9]\n\ntest_input = { \"n\": 15, \"edges\": [[1,0],[10,1],[2,8],[2,3],[5,3],[4,8],[9,5],[6,12],[7,12],[8,7],[9,11],[11,10],[10,13],[10,14]] }\nassert my_solution.minEdgeReversals(**test_input) == [7,6,4,5,4,4,6,6,5,3,5,4,7,6,6]\n\ntest_input = { \"n\": 15, \"edges\": [[2,0],[0,7],[0,5],[1,6],[1,7],[3,4],[8,4],[10,4],[5,12],[5,10],[11,7],[9,13],[10,14],[13,14]] }\nassert my_solution.minEdgeReversals(**test_input) == [7,7,6,9,10,8,8,8,9,8,9,7,9,9,10]\n\ntest_input = { \"n\": 15, \"edges\": [[8,0],[1,0],[1,13],[1,14],[9,2],[3,13],[4,11],[4,14],[5,8],[12,6],[9,6],[7,8],[14,9],[10,13]] }\nassert my_solution.minEdgeReversals(**test_input) == [8,7,10,7,7,6,10,6,7,9,7,8,9,8,8]\n\ntest_input = { \"n\": 15, \"edges\": [[12,0],[0,8],[1,3],[2,1],[2,7],[12,2],[9,3],[4,11],[11,5],[5,7],[6,13],[6,9],[8,14],[10,12]] }\nassert my_solution.minEdgeReversals(**test_input) == [7,8,7,9,5,7,7,8,8,8,5,6,6,8,9]\n\ntest_input = { \"n\": 15, \"edges\": [[12,0],[1,12],[1,7],[2,12],[3,7],[3,14],[4,6],[5,6],[5,7],[6,8],[6,10],[11,6],[7,13],[9,14]] }\nassert my_solution.minEdgeReversals(**test_input) == [8,6,6,6,6,6,7,7,8,6,8,6,7,8,7]\n\ntest_input = { \"n\": 16, \"edges\": [[0,1],[5,0],[0,2],[0,4],[2,12],[10,3],[3,15],[4,7],[8,6],[6,9],[7,14],[7,13],[11,9],[13,9],[10,13]] }\nassert my_solution.minEdgeReversals(**test_input) == [5,6,6,8,6,4,8,7,7,9,7,8,7,8,8,9]\n\ntest_input = { \"n\": 16, \"edges\": [[2,0],[0,4],[4,1],[1,11],[5,2],[8,3],[4,3],[4,13],[14,4],[7,5],[5,12],[6,9],[12,9],[10,14],[11,15]] }\nassert my_solution.minEdgeReversals(**test_input) == [7,9,6,9,8,5,6,4,8,7,6,10,6,9,7,11]\n\ntest_input = { \"n\": 16, \"edges\": [[8,0],[1,6],[10,1],[8,2],[3,15],[14,4],[12,5],[13,5],[8,6],[6,9],[6,13],[11,7],[7,13],[15,10],[11,14]] }\nassert my_solution.minEdgeReversals(**test_input) == [8,7,8,4,9,10,8,8,7,9,6,7,9,9,8,5]\n\ntest_input = { \"n\": 17, \"edges\": [[0,4],[0,9],[13,1],[5,1],[6,2],[13,2],[3,8],[3,15],[3,9],[4,5],[5,10],[11,6],[7,16],[12,9],[16,9],[12,14]] }\nassert my_solution.minEdgeReversals(**test_input) == [7,10,10,7,8,9,9,6,8,8,10,8,7,9,8,8,7]\n\ntest_input = { \"n\": 17, \"edges\": [[0,7],[15,1],[2,3],[2,7],[3,8],[15,3],[5,4],[4,16],[6,14],[16,7],[16,9],[10,14],[10,16],[16,11],[12,14],[15,13]] }\nassert my_solution.minEdgeReversals(**test_input) == [8,9,8,9,7,6,7,9,10,9,7,9,7,9,8,8,8]\n\ntest_input = { \"n\": 17, \"edges\": [[0,10],[12,0],[0,14],[0,7],[0,16],[1,8],[1,7],[2,8],[3,5],[4,15],[5,9],[11,5],[14,6],[11,7],[15,8],[13,16]] }\nassert my_solution.minEdgeReversals(**test_input) == [8,8,8,8,7,9,10,9,9,10,9,8,7,8,9,8,9]\n\ntest_input = { \"n\": 17, \"edges\": [[0,12],[1,2],[1,13],[1,14],[4,3],[3,15],[5,4],[10,6],[14,6],[6,15],[7,11],[8,11],[13,9],[10,11],[15,12],[16,15]] }\nassert my_solution.minEdgeReversals(**test_input) == [11,8,9,10,9,8,10,9,9,10,9,10,12,9,9,11,10]\n\ntest_input = { \"n\": 17, \"edges\": [[0,13],[15,0],[1,5],[1,6],[11,1],[1,13],[8,2],[3,16],[4,16],[7,14],[11,8],[9,10],[9,16],[14,12],[14,15],[15,16]] }\nassert my_solution.minEdgeReversals(**test_input) == [8,8,9,7,7,9,9,5,8,7,8,7,7,9,6,7,8]\n\ntest_input = { \"n\": 17, \"edges\": [[8,0],[0,10],[6,1],[1,15],[15,2],[3,2],[12,3],[9,4],[5,7],[13,7],[9,10],[10,11],[10,14],[13,12],[16,12],[14,15]] }\nassert my_solution.minEdgeReversals(**test_input) == [9,11,13,12,10,10,10,11,8,9,10,11,11,10,11,12,10]\n\ntest_input = { \"n\": 17, \"edges\": [[10,0],[0,5],[1,8],[1,16],[7,2],[2,8],[3,5],[8,3],[4,11],[13,4],[16,6],[16,9],[14,12],[14,13],[14,15],[15,16]] }\nassert my_solution.minEdgeReversals(**test_input) == [8,6,6,8,7,9,8,5,7,8,7,8,6,6,5,6,7]\n\ntest_input = { \"n\": 18, \"edges\": [[0,3],[16,1],[1,10],[2,13],[2,8],[14,3],[4,12],[5,10],[13,6],[7,11],[10,7],[9,7],[14,8],[9,8],[9,17],[12,14],[13,15]] }\nassert my_solution.minEdgeReversals(**test_input) == [9,8,9,10,7,8,11,10,10,9,9,11,8,10,9,11,7,10]\n\ntest_input = { \"n\": 18, \"edges\": [[0,10],[0,17],[1,3],[1,2],[2,9],[2,17],[16,3],[4,7],[4,13],[4,6],[5,12],[5,17],[6,17],[8,15],[11,8],[16,11],[13,14]] }\nassert my_solution.minEdgeReversals(**test_input) == [6,5,6,6,5,6,6,6,7,7,7,6,7,6,7,8,5,7]\n\ntest_input = { \"n\": 18, \"edges\": [[11,0],[5,1],[1,10],[1,3],[1,17],[14,2],[2,13],[3,13],[4,7],[4,12],[4,17],[6,17],[7,8],[15,9],[16,11],[11,14],[14,15]] }\nassert my_solution.minEdgeReversals(**test_input) == [7,7,8,8,7,6,7,8,9,9,8,6,8,9,7,8,5,8]\n\ntest_input = { \"n\": 19, \"edges\": [[0,3],[0,5],[4,0],[12,1],[1,5],[2,17],[2,4],[3,13],[4,8],[5,7],[18,6],[18,8],[14,9],[9,15],[16,9],[10,12],[11,17],[12,16]] }\nassert my_solution.minEdgeReversals(**test_input) == [8,8,6,9,7,9,8,10,8,9,6,6,7,10,8,10,8,7,7]\n\ntest_input = { \"n\": 19, \"edges\": [[0,5],[0,9],[14,1],[2,11],[3,12],[3,8],[10,3],[4,13],[4,12],[6,17],[10,7],[7,14],[8,11],[16,8],[9,14],[9,17],[15,17],[15,18]] }\nassert my_solution.minEdgeReversals(**test_input) == [7,10,9,8,8,8,8,8,9,8,7,10,9,9,9,8,8,9,9]\n\ntest_input = { \"n\": 19, \"edges\": [[0,12],[13,1],[12,1],[14,2],[2,11],[3,9],[11,3],[15,4],[4,11],[5,12],[17,6],[8,7],[8,10],[16,8],[9,12],[11,18],[16,18],[17,18]] }\nassert my_solution.minEdgeReversals(**test_input) == [11,13,8,10,8,11,10,11,10,11,11,9,12,12,7,7,9,9,10]\n\ntest_input = { \"n\": 19, \"edges\": [[0,18],[8,1],[5,1],[9,2],[6,2],[3,11],[17,3],[4,12],[4,6],[18,4],[14,5],[5,16],[6,7],[16,7],[17,7],[15,8],[10,14],[14,13]] }\nassert my_solution.minEdgeReversals(**test_input) == [8,11,12,12,10,10,11,12,10,11,8,13,11,10,9,9,11,11,9]\n\ntest_input = { \"n\": 19, \"edges\": [[1,0],[0,13],[15,0],[1,9],[5,2],[2,13],[3,12],[3,16],[4,12],[5,7],[8,6],[12,8],[16,10],[13,10],[17,11],[13,11],[14,13],[15,18]] }\nassert my_solution.minEdgeReversals(**test_input) == [9,8,9,9,9,8,12,9,11,9,11,11,10,10,9,8,10,10,9]", "start_time": 1694874600} +{"task_id": "weekly-contest-362-points-that-intersect-with-cars", "url": "https://leetcode.com/problems/points-that-intersect-with-cars", "title": "points-that-intersect-with-cars", "meta": {"questionId": "3034", "questionFrontendId": "2848", "title": "Points That Intersect With Cars", "titleSlug": "points-that-intersect-with-cars", "isPaidOnly": false, "difficulty": "Easy", "likes": 211, "dislikes": 13, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed 2D integer array nums representing the coordinates of the cars parking on a number line. For any index i, nums[i] = [starti, endi] where starti is the starting point of the ith car and endi is the ending point of the ith car.\n\nReturn the number of integer points on the line that are covered with any part of a car.\n\nExample 1:\n\nInput: nums = [[3,6],[1,5],[4,7]]\nOutput: 7\nExplanation: All the points from 1 to 7 intersect at least one car, therefore the answer would be 7.\n\nExample 2:\n\nInput: nums = [[1,3],[5,8]]\nOutput: 7\nExplanation: Points intersecting at least one car are 1, 2, 3, 5, 6, 7, 8. There are a total of 7 points, therefore the answer would be 7.\n\n\nConstraints:\n\n * 1 <= nums.length <= 100\n * nums[i].length == 2\n * 1 <= starti <= endi <= 100\n\"\"\"\nclass Solution:\n def numberOfPoints(self, nums: List[List[int]]) -> int:\n ", "prompt_sft": "You are given a 0-indexed 2D integer array nums representing the coordinates of the cars parking on a number line. For any index i, nums[i] = [starti, endi] where starti is the starting point of the ith car and endi is the ending point of the ith car.\n\nReturn the number of integer points on the line that are covered with any part of a car.\n\nExample 1:\n\nInput: nums = [[3,6],[1,5],[4,7]]\nOutput: 7\nExplanation: All the points from 1 to 7 intersect at least one car, therefore the answer would be 7.\n\nExample 2:\n\nInput: nums = [[1,3],[5,8]]\nOutput: 7\nExplanation: Points intersecting at least one car are 1, 2, 3, 5, 6, 7, 8. There are a total of 7 points, therefore the answer would be 7.\n\n\nConstraints:\n\n * 1 <= nums.length <= 100\n * nums[i].length == 2\n * 1 <= starti <= endi <= 100\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def numberOfPoints(self, nums: List[List[int]]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [[3,6],[1,5],[4,7]] }\nassert my_solution.numberOfPoints(**test_input) == 7\n\ntest_input = { \"nums\": [[1,3],[5,8]] }\nassert my_solution.numberOfPoints(**test_input) == 7\n\ntest_input = { \"nums\": [[4,4],[9,10],[9,10],[3,8]] }\nassert my_solution.numberOfPoints(**test_input) == 8\n\ntest_input = { \"nums\": [[2,5],[3,8],[1,6],[4,10]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[2,3],[3,9],[5,7],[4,10],[9,10]] }\nassert my_solution.numberOfPoints(**test_input) == 9\n\ntest_input = { \"nums\": [[4,10]] }\nassert my_solution.numberOfPoints(**test_input) == 7\n\ntest_input = { \"nums\": [[1,9],[2,10],[6,7],[8,9],[5,8],[1,3]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[5,10],[3,8],[3,9]] }\nassert my_solution.numberOfPoints(**test_input) == 8\n\ntest_input = { \"nums\": [[2,3],[3,10],[5,8],[4,8],[2,7],[3,4],[3,10],[7,8]] }\nassert my_solution.numberOfPoints(**test_input) == 9\n\ntest_input = { \"nums\": [[1,3],[2,4],[6,6],[6,9],[2,10],[4,10],[3,6],[1,4],[1,3]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[4,10],[3,9],[3,5],[4,10],[7,10],[1,7],[7,9],[4,8]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[1,6],[6,7],[1,6],[1,3],[1,8],[2,9],[3,8],[1,9]] }\nassert my_solution.numberOfPoints(**test_input) == 9\n\ntest_input = { \"nums\": [[1,6],[8,10],[3,7],[6,10],[3,10],[1,10],[7,8]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[6,8],[2,8],[3,9],[3,5],[6,10],[1,2],[5,5]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[4,5],[5,9],[2,3],[5,10],[1,9],[1,8],[2,9],[2,10]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[8,9],[6,7],[6,9],[3,5],[7,10],[5,9],[10,10]] }\nassert my_solution.numberOfPoints(**test_input) == 8\n\ntest_input = { \"nums\": [[6,8],[7,10],[9,10],[6,10],[1,10],[5,10]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[9,9],[2,8],[5,8],[3,5],[2,2],[7,9],[5,10]] }\nassert my_solution.numberOfPoints(**test_input) == 9\n\ntest_input = { \"nums\": [[3,9],[5,9]] }\nassert my_solution.numberOfPoints(**test_input) == 7\n\ntest_input = { \"nums\": [[5,10],[2,3],[3,10],[4,7],[1,9],[5,10],[2,6],[1,7],[8,9],[2,9]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[2,3],[2,3],[1,5]] }\nassert my_solution.numberOfPoints(**test_input) == 5\n\ntest_input = { \"nums\": [[4,7],[4,7]] }\nassert my_solution.numberOfPoints(**test_input) == 4\n\ntest_input = { \"nums\": [[7,9],[5,9],[2,10],[9,9],[5,8],[4,6],[6,7],[3,9],[2,4]] }\nassert my_solution.numberOfPoints(**test_input) == 9\n\ntest_input = { \"nums\": [[5,9],[7,7],[3,10],[7,9],[3,4],[1,1],[1,1],[1,7],[1,2],[6,6]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[7,8],[1,7],[5,5],[4,4],[5,8],[2,6]] }\nassert my_solution.numberOfPoints(**test_input) == 8\n\ntest_input = { \"nums\": [[3,5],[8,8],[5,10],[1,7],[2,6],[7,10],[6,6],[5,9],[8,9],[5,6]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[4,9]] }\nassert my_solution.numberOfPoints(**test_input) == 6\n\ntest_input = { \"nums\": [[2,7],[1,9],[5,6],[6,8],[1,10]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[1,4],[2,4],[7,10],[2,8],[1,6],[1,10],[3,5]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[1,4]] }\nassert my_solution.numberOfPoints(**test_input) == 4\n\ntest_input = { \"nums\": [[6,9],[4,7]] }\nassert my_solution.numberOfPoints(**test_input) == 6\n\ntest_input = { \"nums\": [[5,7]] }\nassert my_solution.numberOfPoints(**test_input) == 3\n\ntest_input = { \"nums\": [[1,9],[6,8],[4,7],[7,9],[8,9],[7,9],[4,6],[6,8],[4,9],[8,8]] }\nassert my_solution.numberOfPoints(**test_input) == 9\n\ntest_input = { \"nums\": [[3,6],[3,5],[1,9],[3,4],[3,8],[2,7],[3,8],[2,8]] }\nassert my_solution.numberOfPoints(**test_input) == 9\n\ntest_input = { \"nums\": [[2,5],[8,8],[1,6],[4,4],[4,5],[2,4]] }\nassert my_solution.numberOfPoints(**test_input) == 7\n\ntest_input = { \"nums\": [[4,7],[2,6]] }\nassert my_solution.numberOfPoints(**test_input) == 6\n\ntest_input = { \"nums\": [[5,8],[4,10],[2,9]] }\nassert my_solution.numberOfPoints(**test_input) == 9\n\ntest_input = { \"nums\": [[5,9],[2,4],[2,6]] }\nassert my_solution.numberOfPoints(**test_input) == 8\n\ntest_input = { \"nums\": [[2,3],[1,7],[1,8],[7,9],[1,5]] }\nassert my_solution.numberOfPoints(**test_input) == 9\n\ntest_input = { \"nums\": [[6,8],[6,7],[1,6],[2,10],[2,2],[6,8],[2,8],[8,9]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[3,4],[2,5],[4,10],[3,6],[4,6],[1,8],[2,6],[6,9],[4,10],[3,6]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[3,5],[2,5],[8,8]] }\nassert my_solution.numberOfPoints(**test_input) == 5\n\ntest_input = { \"nums\": [[5,8],[1,3],[8,8]] }\nassert my_solution.numberOfPoints(**test_input) == 7\n\ntest_input = { \"nums\": [[2,8],[5,7],[2,3],[2,7],[5,8],[1,10],[4,7],[10,10],[6,10]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[1,3],[5,10],[3,10],[5,9]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[4,10],[3,6]] }\nassert my_solution.numberOfPoints(**test_input) == 8\n\ntest_input = { \"nums\": [[7,8],[6,10],[7,8],[6,10],[7,10]] }\nassert my_solution.numberOfPoints(**test_input) == 5\n\ntest_input = { \"nums\": [[7,7],[4,4],[2,7],[2,3],[4,6],[4,8]] }\nassert my_solution.numberOfPoints(**test_input) == 7\n\ntest_input = { \"nums\": [[3,4],[1,4],[4,8],[1,7],[2,10],[8,10]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[1,4],[7,10],[1,5],[8,9],[3,5],[3,8],[6,7],[3,5],[1,3],[2,8]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[1,6],[5,10],[7,8],[7,10],[1,3]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[2,3],[4,4],[2,7],[5,5],[4,7],[6,9],[2,4]] }\nassert my_solution.numberOfPoints(**test_input) == 8\n\ntest_input = { \"nums\": [[6,8],[6,8],[6,10]] }\nassert my_solution.numberOfPoints(**test_input) == 5\n\ntest_input = { \"nums\": [[3,10],[3,5],[2,3],[7,9]] }\nassert my_solution.numberOfPoints(**test_input) == 9\n\ntest_input = { \"nums\": [[4,4],[8,10],[2,7],[8,9],[1,8],[1,3],[1,9],[7,7],[3,6],[3,5]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[2,6],[1,4],[3,8],[1,9]] }\nassert my_solution.numberOfPoints(**test_input) == 9\n\ntest_input = { \"nums\": [[1,2],[1,9],[2,9],[6,10],[3,5],[1,2]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[6,7],[1,10],[4,4],[5,5],[5,10],[2,3],[2,8],[9,10]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[1,1],[2,9],[3,3],[2,2],[2,4],[8,9],[3,9]] }\nassert my_solution.numberOfPoints(**test_input) == 9\n\ntest_input = { \"nums\": [[4,6],[1,10],[4,10],[1,10],[5,7]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[2,3],[9,10],[2,9],[2,8],[8,9],[1,2]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[4,9],[4,6],[2,7],[1,9],[6,10],[7,10],[3,9],[2,9]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[7,10],[4,10],[4,10],[4,5],[3,10],[2,4],[8,9],[3,9],[4,5],[6,9]] }\nassert my_solution.numberOfPoints(**test_input) == 9\n\ntest_input = { \"nums\": [[2,7],[2,5],[3,3],[4,4],[5,6],[3,4],[4,10],[5,5],[4,5]] }\nassert my_solution.numberOfPoints(**test_input) == 9\n\ntest_input = { \"nums\": [[3,7],[7,8],[2,6],[10,10],[1,4]] }\nassert my_solution.numberOfPoints(**test_input) == 9\n\ntest_input = { \"nums\": [[3,4],[3,8],[5,8]] }\nassert my_solution.numberOfPoints(**test_input) == 6\n\ntest_input = { \"nums\": [[6,9],[1,8],[7,9]] }\nassert my_solution.numberOfPoints(**test_input) == 9\n\ntest_input = { \"nums\": [[7,8],[1,5]] }\nassert my_solution.numberOfPoints(**test_input) == 7\n\ntest_input = { \"nums\": [[5,10],[5,9],[5,6],[6,8],[1,5],[7,8],[3,5]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[6,8]] }\nassert my_solution.numberOfPoints(**test_input) == 3\n\ntest_input = { \"nums\": [[5,5],[5,9],[2,8],[5,9],[5,6]] }\nassert my_solution.numberOfPoints(**test_input) == 8\n\ntest_input = { \"nums\": [[7,9],[3,8],[1,8],[8,8],[5,9],[1,3],[2,6]] }\nassert my_solution.numberOfPoints(**test_input) == 9\n\ntest_input = { \"nums\": [[3,6],[4,8],[7,9],[3,3],[9,10],[5,8],[1,2],[7,8],[3,10]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[1,8],[4,5],[1,5],[6,7],[2,9]] }\nassert my_solution.numberOfPoints(**test_input) == 9\n\ntest_input = { \"nums\": [[6,8],[2,8],[6,9],[10,10],[2,5],[4,6],[1,10],[8,8],[9,10]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[9,10],[4,8],[9,10],[5,7],[2,5],[2,7],[6,10],[5,7],[9,10]] }\nassert my_solution.numberOfPoints(**test_input) == 9\n\ntest_input = { \"nums\": [[1,7],[2,7],[2,4],[6,7]] }\nassert my_solution.numberOfPoints(**test_input) == 7\n\ntest_input = { \"nums\": [[2,10],[4,5],[4,10]] }\nassert my_solution.numberOfPoints(**test_input) == 9\n\ntest_input = { \"nums\": [[2,10],[3,6],[2,10],[4,10],[4,9],[10,10],[1,1]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[3,5],[6,9],[4,7],[6,6],[4,5],[2,4],[2,7]] }\nassert my_solution.numberOfPoints(**test_input) == 8\n\ntest_input = { \"nums\": [[1,1],[1,7]] }\nassert my_solution.numberOfPoints(**test_input) == 7\n\ntest_input = { \"nums\": [[1,8],[2,8]] }\nassert my_solution.numberOfPoints(**test_input) == 8\n\ntest_input = { \"nums\": [[3,7]] }\nassert my_solution.numberOfPoints(**test_input) == 5\n\ntest_input = { \"nums\": [[1,6],[10,10],[5,7],[2,9]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[7,8]] }\nassert my_solution.numberOfPoints(**test_input) == 2\n\ntest_input = { \"nums\": [[2,10],[1,10],[5,9],[7,7],[1,6],[3,5],[2,9],[2,10],[7,10]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[3,8],[2,9],[6,10],[4,8],[3,4],[2,3],[5,9],[1,5],[7,9]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[6,7],[1,5],[4,6],[4,9],[6,8],[1,7],[5,10],[3,4]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[1,2],[4,10],[3,7],[2,10],[1,2],[3,4],[9,9],[5,9],[3,7],[3,5]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[1,6],[3,4],[4,8],[8,10],[3,8]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[3,6],[8,10],[2,5],[9,10],[2,8],[5,10],[7,10],[8,8],[8,10],[8,9]] }\nassert my_solution.numberOfPoints(**test_input) == 9\n\ntest_input = { \"nums\": [[1,8],[2,6],[2,3],[3,6],[1,10],[5,8]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[3,7],[7,10],[6,6],[4,10],[5,10],[2,8],[1,10],[7,8],[6,6],[4,7]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[6,9]] }\nassert my_solution.numberOfPoints(**test_input) == 4\n\ntest_input = { \"nums\": [[7,8],[1,1],[4,10],[1,9],[2,6],[4,6],[8,9],[4,5]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[2,7],[7,10],[7,8],[3,5],[1,7],[1,4]] }\nassert my_solution.numberOfPoints(**test_input) == 10\n\ntest_input = { \"nums\": [[2,9]] }\nassert my_solution.numberOfPoints(**test_input) == 8\n\ntest_input = { \"nums\": [[7,9],[2,2],[2,7]] }\nassert my_solution.numberOfPoints(**test_input) == 8\n\ntest_input = { \"nums\": [[2,10],[8,9],[6,8],[9,10]] }\nassert my_solution.numberOfPoints(**test_input) == 9\n\ntest_input = { \"nums\": [[3,3]] }\nassert my_solution.numberOfPoints(**test_input) == 1", "start_time": 1694313000} +{"task_id": "weekly-contest-362-determine-if-a-cell-is-reachable-at-a-given-time", "url": "https://leetcode.com/problems/determine-if-a-cell-is-reachable-at-a-given-time", "title": "determine-if-a-cell-is-reachable-at-a-given-time", "meta": {"questionId": "3056", "questionFrontendId": "2849", "title": "Determine if a Cell Is Reachable at a Given Time", "titleSlug": "determine-if-a-cell-is-reachable-at-a-given-time", "isPaidOnly": false, "difficulty": "Medium", "likes": 782, "dislikes": 730, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given four integers sx, sy, fx, fy, and a non-negative integer t.\n\nIn an infinite 2D grid, you start at the cell (sx, sy). Each second, you must move to any of its adjacent cells.\n\nReturn true if you can reach cell (fx, fy) after exactly t seconds, or false otherwise.\n\nA cell's adjacent cells are the 8 cells around it that share at least one corner with it. You can visit the same cell several times.\n\nExample 1:\n\n[https://assets.leetcode.com/uploads/2023/08/05/example2.svg]\n\nInput: sx = 2, sy = 4, fx = 7, fy = 7, t = 6\nOutput: true\nExplanation: Starting at cell (2, 4), we can reach cell (7, 7) in exactly 6 seconds by going through the cells depicted in the picture above.\n\nExample 2:\n\n[https://assets.leetcode.com/uploads/2023/08/05/example1.svg]\n\nInput: sx = 3, sy = 1, fx = 7, fy = 3, t = 3\nOutput: false\nExplanation: Starting at cell (3, 1), it takes at least 4 seconds to reach cell (7, 3) by going through the cells depicted in the picture above. Hence, we cannot reach cell (7, 3) at the third second.\n\n\nConstraints:\n\n * 1 <= sx, sy, fx, fy <= 109\n * 0 <= t <= 109\n\"\"\"\nclass Solution:\n def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n ", "prompt_sft": "You are given four integers sx, sy, fx, fy, and a non-negative integer t.\n\nIn an infinite 2D grid, you start at the cell (sx, sy). Each second, you must move to any of its adjacent cells.\n\nReturn true if you can reach cell (fx, fy) after exactly t seconds, or false otherwise.\n\nA cell's adjacent cells are the 8 cells around it that share at least one corner with it. You can visit the same cell several times.\n\nExample 1:\n\n[https://assets.leetcode.com/uploads/2023/08/05/example2.svg]\n\nInput: sx = 2, sy = 4, fx = 7, fy = 7, t = 6\nOutput: true\nExplanation: Starting at cell (2, 4), we can reach cell (7, 7) in exactly 6 seconds by going through the cells depicted in the picture above.\n\nExample 2:\n\n[https://assets.leetcode.com/uploads/2023/08/05/example1.svg]\n\nInput: sx = 3, sy = 1, fx = 7, fy = 3, t = 3\nOutput: false\nExplanation: Starting at cell (3, 1), it takes at least 4 seconds to reach cell (7, 3) by going through the cells depicted in the picture above. Hence, we cannot reach cell (7, 3) at the third second.\n\n\nConstraints:\n\n * 1 <= sx, sy, fx, fy <= 109\n * 0 <= t <= 109\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"sx\": 3, \"sy\": 1, \"fx\": 7, \"fy\": 3, \"t\": 3 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 2, \"sy\": 4, \"fx\": 7, \"fy\": 7, \"t\": 6 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 1, \"fx\": 1, \"fy\": 2, \"t\": 0 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 1, \"fx\": 2, \"fy\": 4, \"t\": 0 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 1, \"fx\": 3, \"fy\": 4, \"t\": 1 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 1, \"fx\": 3, \"fy\": 5, \"t\": 1 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 1, \"fx\": 1, \"fy\": 1, \"t\": 3 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 1, \"fx\": 1, \"fy\": 3, \"t\": 2 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 1, \"fx\": 4, \"fy\": 1, \"t\": 0 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 1, \"fx\": 4, \"fy\": 2, \"t\": 1 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 1, \"fx\": 1, \"fy\": 4, \"t\": 3 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 1, \"fx\": 1, \"fy\": 5, \"t\": 8 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 1, \"fx\": 2, \"fy\": 1, \"t\": 2 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 1, \"fx\": 4, \"fy\": 3, \"t\": 2 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 1, \"fx\": 2, \"fy\": 2, \"t\": 1 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 1, \"fx\": 4, \"fy\": 4, \"t\": 0 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 1, \"fx\": 5, \"fy\": 1, \"t\": 0 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 1, \"fx\": 2, \"fy\": 3, \"t\": 2 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 1, \"fx\": 5, \"fy\": 2, \"t\": 0 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 1, \"fx\": 2, \"fy\": 5, \"t\": 6 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 1, \"fx\": 3, \"fy\": 1, \"t\": 3 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 1, \"fx\": 3, \"fy\": 2, \"t\": 4 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 1, \"fx\": 3, \"fy\": 3, \"t\": 9 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 1, \"fx\": 4, \"fy\": 5, \"t\": 9 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 1, \"fx\": 5, \"fy\": 3, \"t\": 9 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 1, \"fx\": 5, \"fy\": 4, \"t\": 0 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 2, \"fx\": 1, \"fy\": 1, \"t\": 2 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 1, \"fx\": 5, \"fy\": 5, \"t\": 0 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 2, \"fx\": 1, \"fy\": 2, \"t\": 1 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 2, \"fx\": 1, \"fy\": 3, \"t\": 6 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 2, \"fx\": 1, \"fy\": 4, \"t\": 4 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 2, \"fx\": 2, \"fy\": 5, \"t\": 0 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 2, \"fx\": 3, \"fy\": 4, \"t\": 0 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 2, \"fx\": 1, \"fy\": 5, \"t\": 5 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 2, \"fx\": 3, \"fy\": 5, \"t\": 0 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 2, \"fx\": 4, \"fy\": 1, \"t\": 0 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 2, \"fx\": 2, \"fy\": 1, \"t\": 10 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 2, \"fx\": 2, \"fy\": 2, \"t\": 9 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 2, \"fx\": 2, \"fy\": 3, \"t\": 1 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 2, \"fx\": 4, \"fy\": 2, \"t\": 1 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 2, \"fx\": 2, \"fy\": 4, \"t\": 2 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 2, \"fx\": 4, \"fy\": 3, \"t\": 1 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 2, \"fx\": 4, \"fy\": 4, \"t\": 0 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 2, \"fx\": 3, \"fy\": 1, \"t\": 2 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 2, \"fx\": 3, \"fy\": 2, \"t\": 2 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 2, \"fx\": 4, \"fy\": 5, \"t\": 2 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 2, \"fx\": 3, \"fy\": 3, \"t\": 4 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 2, \"fx\": 5, \"fy\": 1, \"t\": 0 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 2, \"fx\": 5, \"fy\": 3, \"t\": 0 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 2, \"fx\": 5, \"fy\": 2, \"t\": 4 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 2, \"fx\": 5, \"fy\": 4, \"t\": 0 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 3, \"fx\": 1, \"fy\": 1, \"t\": 2 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 3, \"fx\": 1, \"fy\": 2, \"t\": 3 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 2, \"fx\": 5, \"fy\": 5, \"t\": 2 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 3, \"fx\": 2, \"fy\": 1, \"t\": 0 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 3, \"fx\": 2, \"fy\": 4, \"t\": 0 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 3, \"fx\": 1, \"fy\": 3, \"t\": 0 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 3, \"fx\": 1, \"fy\": 4, \"t\": 4 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 3, \"fx\": 1, \"fy\": 5, \"t\": 4 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 3, \"fx\": 2, \"fy\": 2, \"t\": 2 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 3, \"fx\": 2, \"fy\": 3, \"t\": 3 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 3, \"fx\": 3, \"fy\": 1, \"t\": 3 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 3, \"fx\": 2, \"fy\": 5, \"t\": 0 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 3, \"fx\": 4, \"fy\": 1, \"t\": 1 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 3, \"fx\": 3, \"fy\": 2, \"t\": 2 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 3, \"fx\": 3, \"fy\": 3, \"t\": 8 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 3, \"fx\": 4, \"fy\": 5, \"t\": 1 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 3, \"fx\": 5, \"fy\": 1, \"t\": 3 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 3, \"fx\": 5, \"fy\": 2, \"t\": 2 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 3, \"fx\": 5, \"fy\": 3, \"t\": 3 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 3, \"fx\": 5, \"fy\": 4, \"t\": 3 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 3, \"fx\": 5, \"fy\": 5, \"t\": 1 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 3, \"fx\": 3, \"fy\": 4, \"t\": 4 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 3, \"fx\": 3, \"fy\": 5, \"t\": 2 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 4, \"fx\": 1, \"fy\": 2, \"t\": 1 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 3, \"fx\": 4, \"fy\": 2, \"t\": 3 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 3, \"fx\": 4, \"fy\": 3, \"t\": 10 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 3, \"fx\": 4, \"fy\": 4, \"t\": 10 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 4, \"fx\": 1, \"fy\": 1, \"t\": 4 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 4, \"fx\": 1, \"fy\": 3, \"t\": 1 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 4, \"fx\": 1, \"fy\": 4, \"t\": 6 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 4, \"fx\": 2, \"fy\": 2, \"t\": 0 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 4, \"fx\": 1, \"fy\": 5, \"t\": 6 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 4, \"fx\": 2, \"fy\": 4, \"t\": 0 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 4, \"fx\": 2, \"fy\": 1, \"t\": 4 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 4, \"fx\": 3, \"fy\": 3, \"t\": 0 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 4, \"fx\": 2, \"fy\": 3, \"t\": 3 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 4, \"fx\": 2, \"fy\": 5, \"t\": 3 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 4, \"fx\": 3, \"fy\": 1, \"t\": 4 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 4, \"fx\": 3, \"fy\": 2, \"t\": 5 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 4, \"fx\": 4, \"fy\": 1, \"t\": 7 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 4, \"fx\": 3, \"fy\": 4, \"t\": 1 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 4, \"fx\": 4, \"fy\": 4, \"t\": 10 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 4, \"fx\": 4, \"fy\": 5, \"t\": 3 }\nassert my_solution.isReachableAtTime(**test_input) == True\n\ntest_input = { \"sx\": 1, \"sy\": 4, \"fx\": 3, \"fy\": 5, \"t\": 0 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 4, \"fx\": 4, \"fy\": 2, \"t\": 0 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 4, \"fx\": 4, \"fy\": 3, \"t\": 1 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 4, \"fx\": 5, \"fy\": 2, \"t\": 1 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 4, \"fx\": 5, \"fy\": 4, \"t\": 3 }\nassert my_solution.isReachableAtTime(**test_input) == False\n\ntest_input = { \"sx\": 1, \"sy\": 4, \"fx\": 5, \"fy\": 5, \"t\": 0 }\nassert my_solution.isReachableAtTime(**test_input) == False", "start_time": 1694313000} +{"task_id": "weekly-contest-362-minimum-moves-to-spread-stones-over-grid", "url": "https://leetcode.com/problems/minimum-moves-to-spread-stones-over-grid", "title": "minimum-moves-to-spread-stones-over-grid", "meta": {"questionId": "3092", "questionFrontendId": "2850", "title": "Minimum Moves to Spread Stones Over Grid", "titleSlug": "minimum-moves-to-spread-stones-over-grid", "isPaidOnly": false, "difficulty": "Medium", "likes": 419, "dislikes": 43, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed 2D integer matrix grid of size 3 * 3, representing the number of stones in each cell. The grid contains exactly 9 stones, and there can be multiple stones in a single cell.\n\nIn one move, you can move a single stone from its current cell to any other cell if the two cells share a side.\n\nReturn the minimum number of moves required to place one stone in each cell.\n\nExample 1:\n\n[https://assets.leetcode.com/uploads/2023/08/23/example1-3.svg]\n\nInput: grid = [[1,1,0],[1,1,1],[1,2,1]]\nOutput: 3\nExplanation: One possible sequence of moves to place one stone in each cell is:\n1- Move one stone from cell (2,1) to cell (2,2).\n2- Move one stone from cell (2,2) to cell (1,2).\n3- Move one stone from cell (1,2) to cell (0,2).\nIn total, it takes 3 moves to place one stone in each cell of the grid.\nIt can be shown that 3 is the minimum number of moves required to place one stone in each cell.\n\nExample 2:\n\n[https://assets.leetcode.com/uploads/2023/08/23/example2-2.svg]\n\nInput: grid = [[1,3,0],[1,0,0],[1,0,3]]\nOutput: 4\nExplanation: One possible sequence of moves to place one stone in each cell is:\n1- Move one stone from cell (0,1) to cell (0,2).\n2- Move one stone from cell (0,1) to cell (1,1).\n3- Move one stone from cell (2,2) to cell (1,2).\n4- Move one stone from cell (2,2) to cell (2,1).\nIn total, it takes 4 moves to place one stone in each cell of the grid.\nIt can be shown that 4 is the minimum number of moves required to place one stone in each cell.\n\n\nConstraints:\n\n * grid.length == grid[i].length == 3\n * 0 <= grid[i][j] <= 9\n * Sum of grid is equal to 9.\n\"\"\"\nclass Solution:\n def minimumMoves(self, grid: List[List[int]]) -> int:\n ", "prompt_sft": "You are given a 0-indexed 2D integer matrix grid of size 3 * 3, representing the number of stones in each cell. The grid contains exactly 9 stones, and there can be multiple stones in a single cell.\n\nIn one move, you can move a single stone from its current cell to any other cell if the two cells share a side.\n\nReturn the minimum number of moves required to place one stone in each cell.\n\nExample 1:\n\n[https://assets.leetcode.com/uploads/2023/08/23/example1-3.svg]\n\nInput: grid = [[1,1,0],[1,1,1],[1,2,1]]\nOutput: 3\nExplanation: One possible sequence of moves to place one stone in each cell is:\n1- Move one stone from cell (2,1) to cell (2,2).\n2- Move one stone from cell (2,2) to cell (1,2).\n3- Move one stone from cell (1,2) to cell (0,2).\nIn total, it takes 3 moves to place one stone in each cell of the grid.\nIt can be shown that 3 is the minimum number of moves required to place one stone in each cell.\n\nExample 2:\n\n[https://assets.leetcode.com/uploads/2023/08/23/example2-2.svg]\n\nInput: grid = [[1,3,0],[1,0,0],[1,0,3]]\nOutput: 4\nExplanation: One possible sequence of moves to place one stone in each cell is:\n1- Move one stone from cell (0,1) to cell (0,2).\n2- Move one stone from cell (0,1) to cell (1,1).\n3- Move one stone from cell (2,2) to cell (1,2).\n4- Move one stone from cell (2,2) to cell (2,1).\nIn total, it takes 4 moves to place one stone in each cell of the grid.\nIt can be shown that 4 is the minimum number of moves required to place one stone in each cell.\n\n\nConstraints:\n\n * grid.length == grid[i].length == 3\n * 0 <= grid[i][j] <= 9\n * Sum of grid is equal to 9.\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def minimumMoves(self, grid: List[List[int]]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"grid\": [[1,1,0],[1,1,1],[1,2,1]] }\nassert my_solution.minimumMoves(**test_input) == 3\n\ntest_input = { \"grid\": [[1,3,0],[1,0,0],[1,0,3]] }\nassert my_solution.minimumMoves(**test_input) == 4\n\ntest_input = { \"grid\": [[1,2,2],[1,1,0],[0,1,1]] }\nassert my_solution.minimumMoves(**test_input) == 4\n\ntest_input = { \"grid\": [[1,3,3],[1,0,0],[0,1,0]] }\nassert my_solution.minimumMoves(**test_input) == 7\n\ntest_input = { \"grid\": [[3,2,0],[0,1,0],[0,3,0]] }\nassert my_solution.minimumMoves(**test_input) == 7\n\ntest_input = { \"grid\": [[1,0,4],[2,0,0],[2,0,0]] }\nassert my_solution.minimumMoves(**test_input) == 6\n\ntest_input = { \"grid\": [[0,1,3],[3,1,0],[0,1,0]] }\nassert my_solution.minimumMoves(**test_input) == 5\n\ntest_input = { \"grid\": [[3,0,0],[0,2,1],[1,0,2]] }\nassert my_solution.minimumMoves(**test_input) == 5\n\ntest_input = { \"grid\": [[1,0,0],[4,1,1],[0,2,0]] }\nassert my_solution.minimumMoves(**test_input) == 7\n\ntest_input = { \"grid\": [[0,2,3],[2,0,1],[0,1,0]] }\nassert my_solution.minimumMoves(**test_input) == 6\n\ntest_input = { \"grid\": [[4,0,0],[0,0,2],[3,0,0]] }\nassert my_solution.minimumMoves(**test_input) == 8\n\ntest_input = { \"grid\": [[3,0,0],[4,1,0],[1,0,0]] }\nassert my_solution.minimumMoves(**test_input) == 10\n\ntest_input = { \"grid\": [[0,2,1],[1,2,0],[3,0,0]] }\nassert my_solution.minimumMoves(**test_input) == 5\n\ntest_input = { \"grid\": [[1,3,0],[0,0,1],[2,1,1]] }\nassert my_solution.minimumMoves(**test_input) == 3\n\ntest_input = { \"grid\": [[3,0,0],[1,0,1],[0,2,2]] }\nassert my_solution.minimumMoves(**test_input) == 6\n\ntest_input = { \"grid\": [[4,2,2],[0,1,0],[0,0,0]] }\nassert my_solution.minimumMoves(**test_input) == 10\n\ntest_input = { \"grid\": [[3,2,1],[1,1,0],[1,0,0]] }\nassert my_solution.minimumMoves(**test_input) == 9\n\ntest_input = { \"grid\": [[0,3,0],[2,0,0],[1,3,0]] }\nassert my_solution.minimumMoves(**test_input) == 6\n\ntest_input = { \"grid\": [[0,0,0],[3,0,0],[4,2,0]] }\nassert my_solution.minimumMoves(**test_input) == 13\n\ntest_input = { \"grid\": [[1,1,2],[0,0,0],[0,4,1]] }\nassert my_solution.minimumMoves(**test_input) == 5\n\ntest_input = { \"grid\": [[4,0,0],[0,0,0],[1,2,2]] }\nassert my_solution.minimumMoves(**test_input) == 6\n\ntest_input = { \"grid\": [[1,3,1],[0,0,0],[1,2,1]] }\nassert my_solution.minimumMoves(**test_input) == 5\n\ntest_input = { \"grid\": [[3,1,0],[1,2,2],[0,0,0]] }\nassert my_solution.minimumMoves(**test_input) == 6\n\ntest_input = { \"grid\": [[2,3,2],[0,1,0],[0,0,1]] }\nassert my_solution.minimumMoves(**test_input) == 7\n\ntest_input = { \"grid\": [[0,1,4],[0,3,0],[0,1,0]] }\nassert my_solution.minimumMoves(**test_input) == 8\n\ntest_input = { \"grid\": [[0,1,0],[1,4,0],[0,3,0]] }\nassert my_solution.minimumMoves(**test_input) == 7\n\ntest_input = { \"grid\": [[0,0,1],[0,0,3],[2,2,1]] }\nassert my_solution.minimumMoves(**test_input) == 7\n\ntest_input = { \"grid\": [[1,0,1],[1,2,0],[1,0,3]] }\nassert my_solution.minimumMoves(**test_input) == 3\n\ntest_input = { \"grid\": [[0,0,0],[4,1,2],[1,1,0]] }\nassert my_solution.minimumMoves(**test_input) == 7\n\ntest_input = { \"grid\": [[2,2,1],[0,2,1],[0,1,0]] }\nassert my_solution.minimumMoves(**test_input) == 6\n\ntest_input = { \"grid\": [[1,0,0],[0,2,0],[4,2,0]] }\nassert my_solution.minimumMoves(**test_input) == 10\n\ntest_input = { \"grid\": [[2,0,1],[4,0,0],[0,2,0]] }\nassert my_solution.minimumMoves(**test_input) == 6\n\ntest_input = { \"grid\": [[0,0,3],[0,2,0],[1,3,0]] }\nassert my_solution.minimumMoves(**test_input) == 7\n\ntest_input = { \"grid\": [[2,0,1],[1,0,0],[4,0,1]] }\nassert my_solution.minimumMoves(**test_input) == 7\n\ntest_input = { \"grid\": [[0,1,0],[1,0,3],[0,3,1]] }\nassert my_solution.minimumMoves(**test_input) == 6\n\ntest_input = { \"grid\": [[0,3,1],[0,0,0],[3,1,1]] }\nassert my_solution.minimumMoves(**test_input) == 6\n\ntest_input = { \"grid\": [[3,0,1],[0,3,1],[0,0,1]] }\nassert my_solution.minimumMoves(**test_input) == 5\n\ntest_input = { \"grid\": [[0,4,0],[1,0,0],[0,2,2]] }\nassert my_solution.minimumMoves(**test_input) == 5\n\ntest_input = { \"grid\": [[4,2,0],[0,0,0],[1,1,1]] }\nassert my_solution.minimumMoves(**test_input) == 7\n\ntest_input = { \"grid\": [[0,2,0],[2,1,2],[0,2,0]] }\nassert my_solution.minimumMoves(**test_input) == 4\n\ntest_input = { \"grid\": [[0,1,0],[2,1,1],[4,0,0]] }\nassert my_solution.minimumMoves(**test_input) == 8\n\ntest_input = { \"grid\": [[0,4,1],[1,0,1],[0,0,2]] }\nassert my_solution.minimumMoves(**test_input) == 6\n\ntest_input = { \"grid\": [[1,0,0],[0,0,0],[1,3,4]] }\nassert my_solution.minimumMoves(**test_input) == 9\n\ntest_input = { \"grid\": [[0,7,1],[0,1,0],[0,0,0]] }\nassert my_solution.minimumMoves(**test_input) == 13\n\ntest_input = { \"grid\": [[0,1,1],[0,2,1],[2,0,2]] }\nassert my_solution.minimumMoves(**test_input) == 4\n\ntest_input = { \"grid\": [[0,2,0],[3,0,0],[3,1,0]] }\nassert my_solution.minimumMoves(**test_input) == 8\n\ntest_input = { \"grid\": [[0,0,0],[2,0,2],[0,2,3]] }\nassert my_solution.minimumMoves(**test_input) == 8\n\ntest_input = { \"grid\": [[0,3,4],[0,1,0],[1,0,0]] }\nassert my_solution.minimumMoves(**test_input) == 9\n\ntest_input = { \"grid\": [[1,0,0],[0,0,1],[7,0,0]] }\nassert my_solution.minimumMoves(**test_input) == 13\n\ntest_input = { \"grid\": [[0,0,2],[2,0,0],[1,4,0]] }\nassert my_solution.minimumMoves(**test_input) == 6\n\ntest_input = { \"grid\": [[2,0,1],[1,3,0],[0,2,0]] }\nassert my_solution.minimumMoves(**test_input) == 5\n\ntest_input = { \"grid\": [[1,0,2],[2,3,0],[1,0,0]] }\nassert my_solution.minimumMoves(**test_input) == 6\n\ntest_input = { \"grid\": [[1,1,2],[0,0,0],[3,1,1]] }\nassert my_solution.minimumMoves(**test_input) == 4\n\ntest_input = { \"grid\": [[0,2,0],[0,1,0],[0,0,6]] }\nassert my_solution.minimumMoves(**test_input) == 10\n\ntest_input = { \"grid\": [[1,1,1],[3,0,0],[2,1,0]] }\nassert my_solution.minimumMoves(**test_input) == 5\n\ntest_input = { \"grid\": [[2,0,0],[2,0,1],[3,1,0]] }\nassert my_solution.minimumMoves(**test_input) == 8\n\ntest_input = { \"grid\": [[1,1,0],[0,2,2],[0,3,0]] }\nassert my_solution.minimumMoves(**test_input) == 4\n\ntest_input = { \"grid\": [[1,0,3],[1,1,0],[1,0,2]] }\nassert my_solution.minimumMoves(**test_input) == 3\n\ntest_input = { \"grid\": [[1,3,0],[2,0,0],[3,0,0]] }\nassert my_solution.minimumMoves(**test_input) == 7\n\ntest_input = { \"grid\": [[1,0,1],[0,0,1],[0,1,5]] }\nassert my_solution.minimumMoves(**test_input) == 10\n\ntest_input = { \"grid\": [[2,0,0],[0,2,1],[1,1,2]] }\nassert my_solution.minimumMoves(**test_input) == 4\n\ntest_input = { \"grid\": [[1,2,3],[1,0,1],[0,0,1]] }\nassert my_solution.minimumMoves(**test_input) == 8\n\ntest_input = { \"grid\": [[0,2,3],[1,0,0],[0,1,2]] }\nassert my_solution.minimumMoves(**test_input) == 6\n\ntest_input = { \"grid\": [[4,1,0],[0,1,1],[2,0,0]] }\nassert my_solution.minimumMoves(**test_input) == 8\n\ntest_input = { \"grid\": [[2,0,1],[1,0,1],[1,2,1]] }\nassert my_solution.minimumMoves(**test_input) == 2\n\ntest_input = { \"grid\": [[3,0,3],[0,0,0],[1,1,1]] }\nassert my_solution.minimumMoves(**test_input) == 5\n\ntest_input = { \"grid\": [[0,0,0],[3,4,2],[0,0,0]] }\nassert my_solution.minimumMoves(**test_input) == 7\n\ntest_input = { \"grid\": [[2,1,2],[0,0,1],[3,0,0]] }\nassert my_solution.minimumMoves(**test_input) == 6\n\ntest_input = { \"grid\": [[1,0,0],[0,3,3],[0,0,2]] }\nassert my_solution.minimumMoves(**test_input) == 7\n\ntest_input = { \"grid\": [[0,2,0],[1,0,1],[1,3,1]] }\nassert my_solution.minimumMoves(**test_input) == 5\n\ntest_input = { \"grid\": [[0,1,0],[2,0,4],[1,0,1]] }\nassert my_solution.minimumMoves(**test_input) == 5\n\ntest_input = { \"grid\": [[1,0,3],[0,0,2],[0,1,2]] }\nassert my_solution.minimumMoves(**test_input) == 7\n\ntest_input = { \"grid\": [[2,1,1],[0,0,0],[0,1,4]] }\nassert my_solution.minimumMoves(**test_input) == 6\n\ntest_input = { \"grid\": [[2,0,1],[0,2,0],[1,3,0]] }\nassert my_solution.minimumMoves(**test_input) == 5\n\ntest_input = { \"grid\": [[2,0,2],[0,0,2],[0,0,3]] }\nassert my_solution.minimumMoves(**test_input) == 6\n\ntest_input = { \"grid\": [[0,2,2],[2,0,1],[1,1,0]] }\nassert my_solution.minimumMoves(**test_input) == 4\n\ntest_input = { \"grid\": [[0,0,1],[2,3,2],[1,0,0]] }\nassert my_solution.minimumMoves(**test_input) == 4\n\ntest_input = { \"grid\": [[1,1,0],[3,0,4],[0,0,0]] }\nassert my_solution.minimumMoves(**test_input) == 6\n\ntest_input = { \"grid\": [[1,0,0],[0,0,0],[5,1,2]] }\nassert my_solution.minimumMoves(**test_input) == 11\n\ntest_input = { \"grid\": [[1,0,0],[3,5,0],[0,0,0]] }\nassert my_solution.minimumMoves(**test_input) == 9\n\ntest_input = { \"grid\": [[3,1,1],[1,1,0],[2,0,0]] }\nassert my_solution.minimumMoves(**test_input) == 8\n\ntest_input = { \"grid\": [[0,1,3],[0,0,1],[1,2,1]] }\nassert my_solution.minimumMoves(**test_input) == 6\n\ntest_input = { \"grid\": [[0,0,0],[1,2,0],[3,0,3]] }\nassert my_solution.minimumMoves(**test_input) == 7\n\ntest_input = { \"grid\": [[0,0,0],[1,2,2],[2,0,2]] }\nassert my_solution.minimumMoves(**test_input) == 5\n\ntest_input = { \"grid\": [[4,0,0],[2,3,0],[0,0,0]] }\nassert my_solution.minimumMoves(**test_input) == 10\n\ntest_input = { \"grid\": [[1,1,0],[1,0,1],[4,1,0]] }\nassert my_solution.minimumMoves(**test_input) == 8\n\ntest_input = { \"grid\": [[0,0,1],[0,1,2],[1,0,4]] }\nassert my_solution.minimumMoves(**test_input) == 10\n\ntest_input = { \"grid\": [[0,1,3],[2,0,0],[0,3,0]] }\nassert my_solution.minimumMoves(**test_input) == 6\n\ntest_input = { \"grid\": [[0,0,0],[5,0,1],[1,1,1]] }\nassert my_solution.minimumMoves(**test_input) == 7\n\ntest_input = { \"grid\": [[0,1,1],[0,0,3],[2,1,1]] }\nassert my_solution.minimumMoves(**test_input) == 5\n\ntest_input = { \"grid\": [[2,0,1],[0,0,1],[2,2,1]] }\nassert my_solution.minimumMoves(**test_input) == 3\n\ntest_input = { \"grid\": [[3,0,2],[2,1,0],[0,0,1]] }\nassert my_solution.minimumMoves(**test_input) == 6\n\ntest_input = { \"grid\": [[0,0,2],[0,0,2],[4,0,1]] }\nassert my_solution.minimumMoves(**test_input) == 6\n\ntest_input = { \"grid\": [[3,0,0],[0,2,0],[0,0,4]] }\nassert my_solution.minimumMoves(**test_input) == 8\n\ntest_input = { \"grid\": [[0,1,3],[1,0,0],[0,4,0]] }\nassert my_solution.minimumMoves(**test_input) == 6\n\ntest_input = { \"grid\": [[2,1,2],[0,2,1],[1,0,0]] }\nassert my_solution.minimumMoves(**test_input) == 4\n\ntest_input = { \"grid\": [[0,0,2],[1,0,3],[1,0,2]] }\nassert my_solution.minimumMoves(**test_input) == 6\n\ntest_input = { \"grid\": [[0,2,2],[0,1,4],[0,0,0]] }\nassert my_solution.minimumMoves(**test_input) == 10\n\ntest_input = { \"grid\": [[1,0,1],[0,0,5],[1,1,0]] }\nassert my_solution.minimumMoves(**test_input) == 6\n\ntest_input = { \"grid\": [[3,1,0],[0,0,0],[0,1,4]] }\nassert my_solution.minimumMoves(**test_input) == 8", "start_time": 1694313000} +{"task_id": "weekly-contest-362-string-transformation", "url": "https://leetcode.com/problems/string-transformation", "title": "string-transformation", "meta": {"questionId": "3024", "questionFrontendId": "2851", "title": "String Transformation", "titleSlug": "string-transformation", "isPaidOnly": false, "difficulty": "Hard", "likes": 140, "dislikes": 19, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given two strings s and t of equal length n. You can perform the following operation on the string s:\n\n * Remove a suffix of s of length l where 0 < l < n and append it at the start of s.\n For example, let s = 'abcd' then in one operation you can remove the suffix 'cd' and append it in front of s making s = 'cdab'.\n\nYou are also given an integer k. Return the number of ways in which s can be transformed into t in exactly k operations.\n\nSince the answer can be large, return it modulo 109 + 7.\n\nExample 1:\n\nInput: s = \"abcd\", t = \"cdab\", k = 2\nOutput: 2\nExplanation:\nFirst way:\nIn first operation, choose suffix from index = 3, so resulting s = \"dabc\".\nIn second operation, choose suffix from index = 3, so resulting s = \"cdab\".\n\nSecond way:\nIn first operation, choose suffix from index = 1, so resulting s = \"bcda\".\nIn second operation, choose suffix from index = 1, so resulting s = \"cdab\".\n\nExample 2:\n\nInput: s = \"ababab\", t = \"ababab\", k = 1\nOutput: 2\nExplanation:\nFirst way:\nChoose suffix from index = 2, so resulting s = \"ababab\".\n\nSecond way:\nChoose suffix from index = 4, so resulting s = \"ababab\".\n\n\nConstraints:\n\n * 2 <= s.length <= 5 * 105\n * 1 <= k <= 1015\n * s.length == t.length\n * s and t consist of only lowercase English alphabets.\n\"\"\"\nclass Solution:\n def numberOfWays(self, s: str, t: str, k: int) -> int:\n ", "prompt_sft": "You are given two strings s and t of equal length n. You can perform the following operation on the string s:\n\n * Remove a suffix of s of length l where 0 < l < n and append it at the start of s.\n For example, let s = 'abcd' then in one operation you can remove the suffix 'cd' and append it in front of s making s = 'cdab'.\n\nYou are also given an integer k. Return the number of ways in which s can be transformed into t in exactly k operations.\n\nSince the answer can be large, return it modulo 109 + 7.\n\nExample 1:\n\nInput: s = \"abcd\", t = \"cdab\", k = 2\nOutput: 2\nExplanation:\nFirst way:\nIn first operation, choose suffix from index = 3, so resulting s = \"dabc\".\nIn second operation, choose suffix from index = 3, so resulting s = \"cdab\".\n\nSecond way:\nIn first operation, choose suffix from index = 1, so resulting s = \"bcda\".\nIn second operation, choose suffix from index = 1, so resulting s = \"cdab\".\n\nExample 2:\n\nInput: s = \"ababab\", t = \"ababab\", k = 1\nOutput: 2\nExplanation:\nFirst way:\nChoose suffix from index = 2, so resulting s = \"ababab\".\n\nSecond way:\nChoose suffix from index = 4, so resulting s = \"ababab\".\n\n\nConstraints:\n\n * 2 <= s.length <= 5 * 105\n * 1 <= k <= 1015\n * s.length == t.length\n * s and t consist of only lowercase English alphabets.\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def numberOfWays(self, s: str, t: str, k: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"s\": \"abcd\", \"t\": \"cdab\", \"k\": 2 }\nassert my_solution.numberOfWays(**test_input) == 2\n\ntest_input = { \"s\": \"ababab\", \"t\": \"ababab\", \"k\": 1 }\nassert my_solution.numberOfWays(**test_input) == 2\n\ntest_input = { \"s\": \"goxoq\", \"t\": \"dfqgl\", \"k\": 244326024901249 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"s\": \"ceoceo\", \"t\": \"eoceoc\", \"k\": 4 }\nassert my_solution.numberOfWays(**test_input) == 208\n\ntest_input = { \"s\": \"ib\", \"t\": \"ib\", \"k\": 10 }\nassert my_solution.numberOfWays(**test_input) == 1\n\ntest_input = { \"s\": \"ttttttt\", \"t\": \"ttttttt\", \"k\": 5 }\nassert my_solution.numberOfWays(**test_input) == 7776\n\ntest_input = { \"s\": \"aaaa\", \"t\": \"aaaa\", \"k\": 8 }\nassert my_solution.numberOfWays(**test_input) == 6561\n\ntest_input = { \"s\": \"meplrmeplr\", \"t\": \"eplrmeplrm\", \"k\": 7 }\nassert my_solution.numberOfWays(**test_input) == 956594\n\ntest_input = { \"s\": \"dsmn\", \"t\": \"smnd\", \"k\": 3 }\nassert my_solution.numberOfWays(**test_input) == 7\n\ntest_input = { \"s\": \"jjj\", \"t\": \"jjj\", \"k\": 10 }\nassert my_solution.numberOfWays(**test_input) == 1024\n\ntest_input = { \"s\": \"rrrrr\", \"t\": \"rrrrr\", \"k\": 1 }\nassert my_solution.numberOfWays(**test_input) == 4\n\ntest_input = { \"s\": \"fefe\", \"t\": \"fefe\", \"k\": 9 }\nassert my_solution.numberOfWays(**test_input) == 9841\n\ntest_input = { \"s\": \"pfly\", \"t\": \"wvqr\", \"k\": 840550364246523 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"s\": \"ltjwwltjww\", \"t\": \"jwwltjwwlt\", \"k\": 1 }\nassert my_solution.numberOfWays(**test_input) == 2\n\ntest_input = { \"s\": \"mb\", \"t\": \"mb\", \"k\": 3 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"s\": \"jjjjjjjjjj\", \"t\": \"jjjjjjjjjj\", \"k\": 3 }\nassert my_solution.numberOfWays(**test_input) == 729\n\ntest_input = { \"s\": \"oqytlmi\", \"t\": \"lmioqyt\", \"k\": 8 }\nassert my_solution.numberOfWays(**test_input) == 239945\n\ntest_input = { \"s\": \"hpcg\", \"t\": \"pcgh\", \"k\": 5 }\nassert my_solution.numberOfWays(**test_input) == 61\n\ntest_input = { \"s\": \"bqbqbqbqbq\", \"t\": \"bqbqbqbqbq\", \"k\": 9 }\nassert my_solution.numberOfWays(**test_input) == 193710244\n\ntest_input = { \"s\": \"ccccccccc\", \"t\": \"ccccccccc\", \"k\": 7 }\nassert my_solution.numberOfWays(**test_input) == 2097152\n\ntest_input = { \"s\": \"jjjjjjjjjj\", \"t\": \"jjjjjjjjjj\", \"k\": 9 }\nassert my_solution.numberOfWays(**test_input) == 387420489\n\ntest_input = { \"s\": \"qqqq\", \"t\": \"qqqq\", \"k\": 9 }\nassert my_solution.numberOfWays(**test_input) == 19683\n\ntest_input = { \"s\": \"loppaqg\", \"t\": \"nvbxtmh\", \"k\": 104865546226045 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"s\": \"qqqqqqqqqq\", \"t\": \"qqqqqqqqqq\", \"k\": 3 }\nassert my_solution.numberOfWays(**test_input) == 729\n\ntest_input = { \"s\": \"qsqsqsqsqs\", \"t\": \"qsqsqsqsqs\", \"k\": 2 }\nassert my_solution.numberOfWays(**test_input) == 41\n\ntest_input = { \"s\": \"nnnnn\", \"t\": \"nnnnn\", \"k\": 5 }\nassert my_solution.numberOfWays(**test_input) == 1024\n\ntest_input = { \"s\": \"klncccd\", \"t\": \"klncccd\", \"k\": 1 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"s\": \"qqqqq\", \"t\": \"qqqqq\", \"k\": 9 }\nassert my_solution.numberOfWays(**test_input) == 262144\n\ntest_input = { \"s\": \"qvxrlh\", \"t\": \"hqvxrl\", \"k\": 6 }\nassert my_solution.numberOfWays(**test_input) == 2604\n\ntest_input = { \"s\": \"uuuu\", \"t\": \"uuuu\", \"k\": 9 }\nassert my_solution.numberOfWays(**test_input) == 19683\n\ntest_input = { \"s\": \"sss\", \"t\": \"sss\", \"k\": 7 }\nassert my_solution.numberOfWays(**test_input) == 128\n\ntest_input = { \"s\": \"gggggggggg\", \"t\": \"gggggggggg\", \"k\": 1 }\nassert my_solution.numberOfWays(**test_input) == 9\n\ntest_input = { \"s\": \"ks\", \"t\": \"cj\", \"k\": 400700574233583 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"s\": \"lllllllll\", \"t\": \"lllllllll\", \"k\": 5 }\nassert my_solution.numberOfWays(**test_input) == 32768\n\ntest_input = { \"s\": \"uhixx\", \"t\": \"xxuhi\", \"k\": 3 }\nassert my_solution.numberOfWays(**test_input) == 13\n\ntest_input = { \"s\": \"vkrvkrvkr\", \"t\": \"rvkrvkrvk\", \"k\": 2 }\nassert my_solution.numberOfWays(**test_input) == 21\n\ntest_input = { \"s\": \"xtxtxtxt\", \"t\": \"xtxtxtxt\", \"k\": 8 }\nassert my_solution.numberOfWays(**test_input) == 2882401\n\ntest_input = { \"s\": \"nzybrhi\", \"t\": \"rhinzyb\", \"k\": 6 }\nassert my_solution.numberOfWays(**test_input) == 6665\n\ntest_input = { \"s\": \"ff\", \"t\": \"ff\", \"k\": 4 }\nassert my_solution.numberOfWays(**test_input) == 1\n\ntest_input = { \"s\": \"ubagdasws\", \"t\": \"aswsubagd\", \"k\": 9 }\nassert my_solution.numberOfWays(**test_input) == 14913081\n\ntest_input = { \"s\": \"aaaaa\", \"t\": \"aaaaa\", \"k\": 10 }\nassert my_solution.numberOfWays(**test_input) == 1048576\n\ntest_input = { \"s\": \"iiiiiiiiii\", \"t\": \"iiiiiiiiii\", \"k\": 4 }\nassert my_solution.numberOfWays(**test_input) == 6561\n\ntest_input = { \"s\": \"nnjqjmgome\", \"t\": \"gbfuecwlqc\", \"k\": 359221508193514 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"s\": \"slmzyj\", \"t\": \"slmzyj\", \"k\": 4 }\nassert my_solution.numberOfWays(**test_input) == 105\n\ntest_input = { \"s\": \"vfyxl\", \"t\": \"vfyxl\", \"k\": 10 }\nassert my_solution.numberOfWays(**test_input) == 209716\n\ntest_input = { \"s\": \"sxzfvsxzfv\", \"t\": \"vsxzfvsxzf\", \"k\": 2 }\nassert my_solution.numberOfWays(**test_input) == 16\n\ntest_input = { \"s\": \"kalt\", \"t\": \"ltka\", \"k\": 7 }\nassert my_solution.numberOfWays(**test_input) == 547\n\ntest_input = { \"s\": \"jj\", \"t\": \"jj\", \"k\": 7 }\nassert my_solution.numberOfWays(**test_input) == 1\n\ntest_input = { \"s\": \"bcriunp\", \"t\": \"criunpb\", \"k\": 2 }\nassert my_solution.numberOfWays(**test_input) == 5\n\ntest_input = { \"s\": \"rutmzyj\", \"t\": \"zyjrutm\", \"k\": 6 }\nassert my_solution.numberOfWays(**test_input) == 6665\n\ntest_input = { \"s\": \"vvvvv\", \"t\": \"vvvvv\", \"k\": 3 }\nassert my_solution.numberOfWays(**test_input) == 64\n\ntest_input = { \"s\": \"hlld\", \"t\": \"hlld\", \"k\": 9 }\nassert my_solution.numberOfWays(**test_input) == 4920\n\ntest_input = { \"s\": \"kctcsgswa\", \"t\": \"qfyyjeohe\", \"k\": 966836940319300 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"s\": \"otwqxmpktt\", \"t\": \"totwqxmpkt\", \"k\": 7 }\nassert my_solution.numberOfWays(**test_input) == 478297\n\ntest_input = { \"s\": \"kkkkkkk\", \"t\": \"kkkkkkk\", \"k\": 7 }\nassert my_solution.numberOfWays(**test_input) == 279936\n\ntest_input = { \"s\": \"iyl\", \"t\": \"iyl\", \"k\": 6 }\nassert my_solution.numberOfWays(**test_input) == 22\n\ntest_input = { \"s\": \"glao\", \"t\": \"ogla\", \"k\": 10 }\nassert my_solution.numberOfWays(**test_input) == 14762\n\ntest_input = { \"s\": \"jp\", \"t\": \"jp\", \"k\": 8 }\nassert my_solution.numberOfWays(**test_input) == 1\n\ntest_input = { \"s\": \"uuuuuu\", \"t\": \"uuuuuu\", \"k\": 7 }\nassert my_solution.numberOfWays(**test_input) == 78125\n\ntest_input = { \"s\": \"achach\", \"t\": \"achach\", \"k\": 10 }\nassert my_solution.numberOfWays(**test_input) == 3255209\n\ntest_input = { \"s\": \"uuuuuuuu\", \"t\": \"uuuuuuuu\", \"k\": 7 }\nassert my_solution.numberOfWays(**test_input) == 823543\n\ntest_input = { \"s\": \"gjh\", \"t\": \"jhg\", \"k\": 9 }\nassert my_solution.numberOfWays(**test_input) == 171\n\ntest_input = { \"s\": \"cliuw\", \"t\": \"fphcn\", \"k\": 647756904366432 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"s\": \"zmcum\", \"t\": \"mzmcu\", \"k\": 1 }\nassert my_solution.numberOfWays(**test_input) == 1\n\ntest_input = { \"s\": \"ll\", \"t\": \"ll\", \"k\": 5 }\nassert my_solution.numberOfWays(**test_input) == 1\n\ntest_input = { \"s\": \"ccccc\", \"t\": \"ccccc\", \"k\": 1 }\nassert my_solution.numberOfWays(**test_input) == 4\n\ntest_input = { \"s\": \"rrrr\", \"t\": \"rrrr\", \"k\": 1 }\nassert my_solution.numberOfWays(**test_input) == 3\n\ntest_input = { \"s\": \"ih\", \"t\": \"hi\", \"k\": 8 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"s\": \"qfgihqrw\", \"t\": \"rwqfgihq\", \"k\": 8 }\nassert my_solution.numberOfWays(**test_input) == 720600\n\ntest_input = { \"s\": \"cd\", \"t\": \"cd\", \"k\": 2 }\nassert my_solution.numberOfWays(**test_input) == 1\n\ntest_input = { \"s\": \"oooooooooo\", \"t\": \"oooooooooo\", \"k\": 4 }\nassert my_solution.numberOfWays(**test_input) == 6561\n\ntest_input = { \"s\": \"wp\", \"t\": \"wp\", \"k\": 6 }\nassert my_solution.numberOfWays(**test_input) == 1\n\ntest_input = { \"s\": \"rqq\", \"t\": \"nln\", \"k\": 776508964349618 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"s\": \"rr\", \"t\": \"rr\", \"k\": 9 }\nassert my_solution.numberOfWays(**test_input) == 1\n\ntest_input = { \"s\": \"knwppsd\", \"t\": \"psdknwp\", \"k\": 2 }\nassert my_solution.numberOfWays(**test_input) == 5\n\ntest_input = { \"s\": \"epfeepfe\", \"t\": \"feepfeep\", \"k\": 9 }\nassert my_solution.numberOfWays(**test_input) == 10088402\n\ntest_input = { \"s\": \"wwwww\", \"t\": \"wwwww\", \"k\": 9 }\nassert my_solution.numberOfWays(**test_input) == 262144\n\ntest_input = { \"s\": \"cdcdcdcd\", \"t\": \"cdcdcdcd\", \"k\": 6 }\nassert my_solution.numberOfWays(**test_input) == 58825\n\ntest_input = { \"s\": \"uphfr\", \"t\": \"fruph\", \"k\": 7 }\nassert my_solution.numberOfWays(**test_input) == 3277\n\ntest_input = { \"s\": \"cocococo\", \"t\": \"cocococo\", \"k\": 3 }\nassert my_solution.numberOfWays(**test_input) == 171\n\ntest_input = { \"s\": \"vhzjo\", \"t\": \"jovhz\", \"k\": 1 }\nassert my_solution.numberOfWays(**test_input) == 1\n\ntest_input = { \"s\": \"bbbbbbbbbb\", \"t\": \"bbbbbbbbbb\", \"k\": 1 }\nassert my_solution.numberOfWays(**test_input) == 9\n\ntest_input = { \"s\": \"pgnrstuh\", \"t\": \"yjzhldlg\", \"k\": 618648276258027 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"s\": \"cccccc\", \"t\": \"cccccc\", \"k\": 5 }\nassert my_solution.numberOfWays(**test_input) == 3125\n\ntest_input = { \"s\": \"kkkkkkk\", \"t\": \"kkkkkkk\", \"k\": 3 }\nassert my_solution.numberOfWays(**test_input) == 216\n\ntest_input = { \"s\": \"lxqqzsvej\", \"t\": \"svejlxqqz\", \"k\": 3 }\nassert my_solution.numberOfWays(**test_input) == 57\n\ntest_input = { \"s\": \"lllll\", \"t\": \"lllll\", \"k\": 3 }\nassert my_solution.numberOfWays(**test_input) == 64\n\ntest_input = { \"s\": \"hhhhhhhhhh\", \"t\": \"hhhhhhhhhh\", \"k\": 8 }\nassert my_solution.numberOfWays(**test_input) == 43046721\n\ntest_input = { \"s\": \"gggg\", \"t\": \"gggg\", \"k\": 5 }\nassert my_solution.numberOfWays(**test_input) == 243\n\ntest_input = { \"s\": \"jj\", \"t\": \"jj\", \"k\": 6 }\nassert my_solution.numberOfWays(**test_input) == 1\n\ntest_input = { \"s\": \"uuuuuuuuu\", \"t\": \"uuuuuuuuu\", \"k\": 10 }\nassert my_solution.numberOfWays(**test_input) == 73741817\n\ntest_input = { \"s\": \"qvx\", \"t\": \"vxq\", \"k\": 8 }\nassert my_solution.numberOfWays(**test_input) == 85\n\ntest_input = { \"s\": \"nolnqlgqcs\", \"t\": \"jkguybcfcu\", \"k\": 179216079747558 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"s\": \"xpk\", \"t\": \"xpk\", \"k\": 6 }\nassert my_solution.numberOfWays(**test_input) == 22\n\ntest_input = { \"s\": \"xzoyb\", \"t\": \"bxzoy\", \"k\": 5 }\nassert my_solution.numberOfWays(**test_input) == 205\n\ntest_input = { \"s\": \"krxjvvg\", \"t\": \"krxjvvg\", \"k\": 2 }\nassert my_solution.numberOfWays(**test_input) == 6\n\ntest_input = { \"s\": \"ks\", \"t\": \"sk\", \"k\": 2 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"s\": \"ty\", \"t\": \"ty\", \"k\": 6 }\nassert my_solution.numberOfWays(**test_input) == 1\n\ntest_input = { \"s\": \"otototot\", \"t\": \"totototo\", \"k\": 7 }\nassert my_solution.numberOfWays(**test_input) == 411772\n\ntest_input = { \"s\": \"uoaowbdznp\", \"t\": \"npuoaowbdz\", \"k\": 10 }\nassert my_solution.numberOfWays(**test_input) == 348678440", "start_time": 1694313000} +{"task_id": "weekly-contest-361-count-symmetric-integers", "url": "https://leetcode.com/problems/count-symmetric-integers", "title": "count-symmetric-integers", "meta": {"questionId": "2998", "questionFrontendId": "2843", "title": " Count Symmetric Integers", "titleSlug": "count-symmetric-integers", "isPaidOnly": false, "difficulty": "Easy", "likes": 210, "dislikes": 9, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given two positive integers low and high.\n\nAn integer x consisting of 2 * n digits is symmetric if the sum of the first n digits of x is equal to the sum of the last n digits of x. Numbers with an odd number of digits are never symmetric.\n\nReturn the number of symmetric integers in the range [low, high].\n\nExample 1:\n\nInput: low = 1, high = 100\nOutput: 9\nExplanation: There are 9 symmetric integers between 1 and 100: 11, 22, 33, 44, 55, 66, 77, 88, and 99.\n\nExample 2:\n\nInput: low = 1200, high = 1230\nOutput: 4\nExplanation: There are 4 symmetric integers between 1200 and 1230: 1203, 1212, 1221, and 1230.\n\n\nConstraints:\n\n * 1 <= low <= high <= 104\n\"\"\"\nclass Solution:\n def countSymmetricIntegers(self, low: int, high: int) -> int:\n ", "prompt_sft": "You are given two positive integers low and high.\n\nAn integer x consisting of 2 * n digits is symmetric if the sum of the first n digits of x is equal to the sum of the last n digits of x. Numbers with an odd number of digits are never symmetric.\n\nReturn the number of symmetric integers in the range [low, high].\n\nExample 1:\n\nInput: low = 1, high = 100\nOutput: 9\nExplanation: There are 9 symmetric integers between 1 and 100: 11, 22, 33, 44, 55, 66, 77, 88, and 99.\n\nExample 2:\n\nInput: low = 1200, high = 1230\nOutput: 4\nExplanation: There are 4 symmetric integers between 1200 and 1230: 1203, 1212, 1221, and 1230.\n\n\nConstraints:\n\n * 1 <= low <= high <= 104\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def countSymmetricIntegers(self, low: int, high: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"low\": 1, \"high\": 100 }\nassert my_solution.countSymmetricIntegers(**test_input) == 9\n\ntest_input = { \"low\": 1200, \"high\": 1230 }\nassert my_solution.countSymmetricIntegers(**test_input) == 4\n\ntest_input = { \"low\": 1, \"high\": 1 }\nassert my_solution.countSymmetricIntegers(**test_input) == 0\n\ntest_input = { \"low\": 1, \"high\": 2 }\nassert my_solution.countSymmetricIntegers(**test_input) == 0\n\ntest_input = { \"low\": 1, \"high\": 3 }\nassert my_solution.countSymmetricIntegers(**test_input) == 0\n\ntest_input = { \"low\": 1, \"high\": 4 }\nassert my_solution.countSymmetricIntegers(**test_input) == 0\n\ntest_input = { \"low\": 1, \"high\": 5 }\nassert my_solution.countSymmetricIntegers(**test_input) == 0\n\ntest_input = { \"low\": 1, \"high\": 6 }\nassert my_solution.countSymmetricIntegers(**test_input) == 0\n\ntest_input = { \"low\": 1, \"high\": 7 }\nassert my_solution.countSymmetricIntegers(**test_input) == 0\n\ntest_input = { \"low\": 1, \"high\": 8 }\nassert my_solution.countSymmetricIntegers(**test_input) == 0\n\ntest_input = { \"low\": 1, \"high\": 9 }\nassert my_solution.countSymmetricIntegers(**test_input) == 0\n\ntest_input = { \"low\": 1, \"high\": 10 }\nassert my_solution.countSymmetricIntegers(**test_input) == 0\n\ntest_input = { \"low\": 1, \"high\": 11 }\nassert my_solution.countSymmetricIntegers(**test_input) == 1\n\ntest_input = { \"low\": 1, \"high\": 12 }\nassert my_solution.countSymmetricIntegers(**test_input) == 1\n\ntest_input = { \"low\": 1, \"high\": 13 }\nassert my_solution.countSymmetricIntegers(**test_input) == 1\n\ntest_input = { \"low\": 1, \"high\": 14 }\nassert my_solution.countSymmetricIntegers(**test_input) == 1\n\ntest_input = { \"low\": 1, \"high\": 15 }\nassert my_solution.countSymmetricIntegers(**test_input) == 1\n\ntest_input = { \"low\": 1, \"high\": 16 }\nassert my_solution.countSymmetricIntegers(**test_input) == 1\n\ntest_input = { \"low\": 1, \"high\": 17 }\nassert my_solution.countSymmetricIntegers(**test_input) == 1\n\ntest_input = { \"low\": 1, \"high\": 18 }\nassert my_solution.countSymmetricIntegers(**test_input) == 1\n\ntest_input = { \"low\": 1, \"high\": 19 }\nassert my_solution.countSymmetricIntegers(**test_input) == 1\n\ntest_input = { \"low\": 1, \"high\": 20 }\nassert my_solution.countSymmetricIntegers(**test_input) == 1\n\ntest_input = { \"low\": 1, \"high\": 21 }\nassert my_solution.countSymmetricIntegers(**test_input) == 1\n\ntest_input = { \"low\": 1, \"high\": 22 }\nassert my_solution.countSymmetricIntegers(**test_input) == 2\n\ntest_input = { \"low\": 1, \"high\": 23 }\nassert my_solution.countSymmetricIntegers(**test_input) == 2\n\ntest_input = { \"low\": 1, \"high\": 24 }\nassert my_solution.countSymmetricIntegers(**test_input) == 2\n\ntest_input = { \"low\": 1, \"high\": 25 }\nassert my_solution.countSymmetricIntegers(**test_input) == 2\n\ntest_input = { \"low\": 1, \"high\": 26 }\nassert my_solution.countSymmetricIntegers(**test_input) == 2\n\ntest_input = { \"low\": 1, \"high\": 27 }\nassert my_solution.countSymmetricIntegers(**test_input) == 2\n\ntest_input = { \"low\": 1, \"high\": 28 }\nassert my_solution.countSymmetricIntegers(**test_input) == 2\n\ntest_input = { \"low\": 1, \"high\": 29 }\nassert my_solution.countSymmetricIntegers(**test_input) == 2\n\ntest_input = { \"low\": 1, \"high\": 30 }\nassert my_solution.countSymmetricIntegers(**test_input) == 2\n\ntest_input = { \"low\": 1, \"high\": 31 }\nassert my_solution.countSymmetricIntegers(**test_input) == 2\n\ntest_input = { \"low\": 1, \"high\": 32 }\nassert my_solution.countSymmetricIntegers(**test_input) == 2\n\ntest_input = { \"low\": 1, \"high\": 33 }\nassert my_solution.countSymmetricIntegers(**test_input) == 3\n\ntest_input = { \"low\": 1, \"high\": 34 }\nassert my_solution.countSymmetricIntegers(**test_input) == 3\n\ntest_input = { \"low\": 1, \"high\": 35 }\nassert my_solution.countSymmetricIntegers(**test_input) == 3\n\ntest_input = { \"low\": 1, \"high\": 36 }\nassert my_solution.countSymmetricIntegers(**test_input) == 3\n\ntest_input = { \"low\": 1, \"high\": 37 }\nassert my_solution.countSymmetricIntegers(**test_input) == 3\n\ntest_input = { \"low\": 1, \"high\": 38 }\nassert my_solution.countSymmetricIntegers(**test_input) == 3\n\ntest_input = { \"low\": 1, \"high\": 39 }\nassert my_solution.countSymmetricIntegers(**test_input) == 3\n\ntest_input = { \"low\": 1, \"high\": 40 }\nassert my_solution.countSymmetricIntegers(**test_input) == 3\n\ntest_input = { \"low\": 1, \"high\": 41 }\nassert my_solution.countSymmetricIntegers(**test_input) == 3\n\ntest_input = { \"low\": 1, \"high\": 42 }\nassert my_solution.countSymmetricIntegers(**test_input) == 3\n\ntest_input = { \"low\": 1, \"high\": 43 }\nassert my_solution.countSymmetricIntegers(**test_input) == 3\n\ntest_input = { \"low\": 1, \"high\": 44 }\nassert my_solution.countSymmetricIntegers(**test_input) == 4\n\ntest_input = { \"low\": 1, \"high\": 45 }\nassert my_solution.countSymmetricIntegers(**test_input) == 4\n\ntest_input = { \"low\": 1, \"high\": 46 }\nassert my_solution.countSymmetricIntegers(**test_input) == 4\n\ntest_input = { \"low\": 1, \"high\": 47 }\nassert my_solution.countSymmetricIntegers(**test_input) == 4\n\ntest_input = { \"low\": 1, \"high\": 48 }\nassert my_solution.countSymmetricIntegers(**test_input) == 4\n\ntest_input = { \"low\": 100, \"high\": 1782 }\nassert my_solution.countSymmetricIntegers(**test_input) == 44\n\ntest_input = { \"low\": 1, \"high\": 49 }\nassert my_solution.countSymmetricIntegers(**test_input) == 4\n\ntest_input = { \"low\": 1, \"high\": 50 }\nassert my_solution.countSymmetricIntegers(**test_input) == 4\n\ntest_input = { \"low\": 1, \"high\": 51 }\nassert my_solution.countSymmetricIntegers(**test_input) == 4\n\ntest_input = { \"low\": 1, \"high\": 52 }\nassert my_solution.countSymmetricIntegers(**test_input) == 4\n\ntest_input = { \"low\": 1, \"high\": 53 }\nassert my_solution.countSymmetricIntegers(**test_input) == 4\n\ntest_input = { \"low\": 1, \"high\": 54 }\nassert my_solution.countSymmetricIntegers(**test_input) == 4\n\ntest_input = { \"low\": 1, \"high\": 55 }\nassert my_solution.countSymmetricIntegers(**test_input) == 5\n\ntest_input = { \"low\": 1, \"high\": 56 }\nassert my_solution.countSymmetricIntegers(**test_input) == 5\n\ntest_input = { \"low\": 1, \"high\": 57 }\nassert my_solution.countSymmetricIntegers(**test_input) == 5\n\ntest_input = { \"low\": 1, \"high\": 58 }\nassert my_solution.countSymmetricIntegers(**test_input) == 5\n\ntest_input = { \"low\": 1, \"high\": 59 }\nassert my_solution.countSymmetricIntegers(**test_input) == 5\n\ntest_input = { \"low\": 1, \"high\": 60 }\nassert my_solution.countSymmetricIntegers(**test_input) == 5\n\ntest_input = { \"low\": 2, \"high\": 2 }\nassert my_solution.countSymmetricIntegers(**test_input) == 0\n\ntest_input = { \"low\": 2, \"high\": 3 }\nassert my_solution.countSymmetricIntegers(**test_input) == 0\n\ntest_input = { \"low\": 2, \"high\": 4 }\nassert my_solution.countSymmetricIntegers(**test_input) == 0\n\ntest_input = { \"low\": 2, \"high\": 5 }\nassert my_solution.countSymmetricIntegers(**test_input) == 0\n\ntest_input = { \"low\": 2, \"high\": 6 }\nassert my_solution.countSymmetricIntegers(**test_input) == 0\n\ntest_input = { \"low\": 2, \"high\": 7 }\nassert my_solution.countSymmetricIntegers(**test_input) == 0\n\ntest_input = { \"low\": 2, \"high\": 8 }\nassert my_solution.countSymmetricIntegers(**test_input) == 0\n\ntest_input = { \"low\": 2, \"high\": 9 }\nassert my_solution.countSymmetricIntegers(**test_input) == 0\n\ntest_input = { \"low\": 2, \"high\": 10 }\nassert my_solution.countSymmetricIntegers(**test_input) == 0\n\ntest_input = { \"low\": 2, \"high\": 11 }\nassert my_solution.countSymmetricIntegers(**test_input) == 1\n\ntest_input = { \"low\": 2, \"high\": 12 }\nassert my_solution.countSymmetricIntegers(**test_input) == 1\n\ntest_input = { \"low\": 2, \"high\": 13 }\nassert my_solution.countSymmetricIntegers(**test_input) == 1\n\ntest_input = { \"low\": 2, \"high\": 14 }\nassert my_solution.countSymmetricIntegers(**test_input) == 1\n\ntest_input = { \"low\": 2, \"high\": 15 }\nassert my_solution.countSymmetricIntegers(**test_input) == 1\n\ntest_input = { \"low\": 2, \"high\": 16 }\nassert my_solution.countSymmetricIntegers(**test_input) == 1\n\ntest_input = { \"low\": 2, \"high\": 17 }\nassert my_solution.countSymmetricIntegers(**test_input) == 1\n\ntest_input = { \"low\": 2, \"high\": 18 }\nassert my_solution.countSymmetricIntegers(**test_input) == 1\n\ntest_input = { \"low\": 2, \"high\": 19 }\nassert my_solution.countSymmetricIntegers(**test_input) == 1\n\ntest_input = { \"low\": 2, \"high\": 20 }\nassert my_solution.countSymmetricIntegers(**test_input) == 1\n\ntest_input = { \"low\": 2, \"high\": 21 }\nassert my_solution.countSymmetricIntegers(**test_input) == 1\n\ntest_input = { \"low\": 2, \"high\": 22 }\nassert my_solution.countSymmetricIntegers(**test_input) == 2\n\ntest_input = { \"low\": 2, \"high\": 23 }\nassert my_solution.countSymmetricIntegers(**test_input) == 2\n\ntest_input = { \"low\": 2, \"high\": 24 }\nassert my_solution.countSymmetricIntegers(**test_input) == 2\n\ntest_input = { \"low\": 2, \"high\": 25 }\nassert my_solution.countSymmetricIntegers(**test_input) == 2\n\ntest_input = { \"low\": 2, \"high\": 26 }\nassert my_solution.countSymmetricIntegers(**test_input) == 2\n\ntest_input = { \"low\": 2, \"high\": 27 }\nassert my_solution.countSymmetricIntegers(**test_input) == 2\n\ntest_input = { \"low\": 2, \"high\": 28 }\nassert my_solution.countSymmetricIntegers(**test_input) == 2\n\ntest_input = { \"low\": 2, \"high\": 29 }\nassert my_solution.countSymmetricIntegers(**test_input) == 2\n\ntest_input = { \"low\": 2, \"high\": 30 }\nassert my_solution.countSymmetricIntegers(**test_input) == 2\n\ntest_input = { \"low\": 2, \"high\": 31 }\nassert my_solution.countSymmetricIntegers(**test_input) == 2\n\ntest_input = { \"low\": 2, \"high\": 32 }\nassert my_solution.countSymmetricIntegers(**test_input) == 2\n\ntest_input = { \"low\": 2, \"high\": 33 }\nassert my_solution.countSymmetricIntegers(**test_input) == 3\n\ntest_input = { \"low\": 2, \"high\": 34 }\nassert my_solution.countSymmetricIntegers(**test_input) == 3\n\ntest_input = { \"low\": 2, \"high\": 35 }\nassert my_solution.countSymmetricIntegers(**test_input) == 3\n\ntest_input = { \"low\": 2, \"high\": 36 }\nassert my_solution.countSymmetricIntegers(**test_input) == 3\n\ntest_input = { \"low\": 2, \"high\": 37 }\nassert my_solution.countSymmetricIntegers(**test_input) == 3\n\ntest_input = { \"low\": 2, \"high\": 38 }\nassert my_solution.countSymmetricIntegers(**test_input) == 3", "start_time": 1693708200} +{"task_id": "weekly-contest-361-minimum-operations-to-make-a-special-number", "url": "https://leetcode.com/problems/minimum-operations-to-make-a-special-number", "title": "minimum-operations-to-make-a-special-number", "meta": {"questionId": "3046", "questionFrontendId": "2844", "title": "Minimum Operations to Make a Special Number", "titleSlug": "minimum-operations-to-make-a-special-number", "isPaidOnly": false, "difficulty": "Medium", "likes": 317, "dislikes": 48, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed string num representing a non-negative integer.\n\nIn one operation, you can pick any digit of num and delete it. Note that if you delete all the digits of num, num becomes 0.\n\nReturn the minimum number of operations required to make num special.\n\nAn integer x is considered special if it is divisible by 25.\n\nExample 1:\n\nInput: num = \"2245047\"\nOutput: 2\nExplanation: Delete digits num[5] and num[6]. The resulting number is \"22450\" which is special since it is divisible by 25.\nIt can be shown that 2 is the minimum number of operations required to get a special number.\n\nExample 2:\n\nInput: num = \"2908305\"\nOutput: 3\nExplanation: Delete digits num[3], num[4], and num[6]. The resulting number is \"2900\" which is special since it is divisible by 25.\nIt can be shown that 3 is the minimum number of operations required to get a special number.\n\nExample 3:\n\nInput: num = \"10\"\nOutput: 1\nExplanation: Delete digit num[0]. The resulting number is \"0\" which is special since it is divisible by 25.\nIt can be shown that 1 is the minimum number of operations required to get a special number.\n\n\nConstraints:\n\n * 1 <= num.length <= 100\n * num only consists of digits '0' through '9'.\n * num does not contain any leading zeros.\n\"\"\"\nclass Solution:\n def minimumOperations(self, num: str) -> int:\n ", "prompt_sft": "You are given a 0-indexed string num representing a non-negative integer.\n\nIn one operation, you can pick any digit of num and delete it. Note that if you delete all the digits of num, num becomes 0.\n\nReturn the minimum number of operations required to make num special.\n\nAn integer x is considered special if it is divisible by 25.\n\nExample 1:\n\nInput: num = \"2245047\"\nOutput: 2\nExplanation: Delete digits num[5] and num[6]. The resulting number is \"22450\" which is special since it is divisible by 25.\nIt can be shown that 2 is the minimum number of operations required to get a special number.\n\nExample 2:\n\nInput: num = \"2908305\"\nOutput: 3\nExplanation: Delete digits num[3], num[4], and num[6]. The resulting number is \"2900\" which is special since it is divisible by 25.\nIt can be shown that 3 is the minimum number of operations required to get a special number.\n\nExample 3:\n\nInput: num = \"10\"\nOutput: 1\nExplanation: Delete digit num[0]. The resulting number is \"0\" which is special since it is divisible by 25.\nIt can be shown that 1 is the minimum number of operations required to get a special number.\n\n\nConstraints:\n\n * 1 <= num.length <= 100\n * num only consists of digits '0' through '9'.\n * num does not contain any leading zeros.\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def minimumOperations(self, num: str) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"num\": \"2245047\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"2908305\" }\nassert my_solution.minimumOperations(**test_input) == 3\n\ntest_input = { \"num\": \"10\" }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"num\": \"1\" }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"num\": \"2\" }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"num\": \"3\" }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"num\": \"4\" }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"num\": \"5\" }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"num\": \"6\" }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"num\": \"7\" }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"num\": \"8\" }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"num\": \"9\" }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"num\": \"11\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"12\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"13\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"14\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"15\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"16\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"17\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"18\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"19\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"20\" }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"num\": \"21\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"22\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"23\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"24\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"25\" }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"num\": \"26\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"27\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"28\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"29\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"30\" }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"num\": \"31\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"32\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"33\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"34\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"35\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"36\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"37\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"38\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"39\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"40\" }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"num\": \"41\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"42\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"43\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"44\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"45\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"46\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"47\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"48\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"49\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"50\" }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"num\": \"51\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"52\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"53\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"54\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"55\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"56\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"57\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"58\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"59\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"60\" }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"num\": \"61\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"62\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"63\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"64\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"65\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"66\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"67\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"68\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"69\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"70\" }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"num\": \"71\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"72\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"73\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"74\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"75\" }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"num\": \"76\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"77\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"78\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"79\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"80\" }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"num\": \"81\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"82\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"83\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"84\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"85\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"86\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"87\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"88\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"89\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"90\" }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"num\": \"91\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"92\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"93\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"94\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"95\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"96\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"97\" }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"num\": \"98\" }\nassert my_solution.minimumOperations(**test_input) == 2", "start_time": 1693708200} +{"task_id": "weekly-contest-361-count-of-interesting-subarrays", "url": "https://leetcode.com/problems/count-of-interesting-subarrays", "title": "count-of-interesting-subarrays", "meta": {"questionId": "2915", "questionFrontendId": "2845", "title": "Count of Interesting Subarrays", "titleSlug": "count-of-interesting-subarrays", "isPaidOnly": false, "difficulty": "Medium", "likes": 449, "dislikes": 62, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed integer array nums, an integer modulo, and an integer k.\n\nYour task is to find the count of subarrays that are interesting.\n\nA subarray nums[l..r] is interesting if the following condition holds:\n\n * Let cnt be the number of indices i in the range [l, r] such that nums[i] % modulo == k. Then, cnt % modulo == k.\n\nReturn an integer denoting the count of interesting subarrays.\n\nNote: A subarray is a contiguous non-empty sequence of elements within an array.\n\nExample 1:\n\nInput: nums = [3,2,4], modulo = 2, k = 1\nOutput: 3\nExplanation: In this example the interesting subarrays are:\nThe subarray nums[0..0] which is [3].\n- There is only one index, i = 0, in the range [0, 0] that satisfies nums[i] % modulo == k.\n- Hence, cnt = 1 and cnt % modulo == k.\nThe subarray nums[0..1] which is [3,2].\n- There is only one index, i = 0, in the range [0, 1] that satisfies nums[i] % modulo == k.\n- Hence, cnt = 1 and cnt % modulo == k.\nThe subarray nums[0..2] which is [3,2,4].\n- There is only one index, i = 0, in the range [0, 2] that satisfies nums[i] % modulo == k.\n- Hence, cnt = 1 and cnt % modulo == k.\nIt can be shown that there are no other interesting subarrays. So, the answer is 3.\n\nExample 2:\n\nInput: nums = [3,1,9,6], modulo = 3, k = 0\nOutput: 2\nExplanation: In this example the interesting subarrays are:\nThe subarray nums[0..3] which is [3,1,9,6].\n- There are three indices, i = 0, 2, 3, in the range [0, 3] that satisfy nums[i] % modulo == k.\n- Hence, cnt = 3 and cnt % modulo == k.\nThe subarray nums[1..1] which is [1].\n- There is no index, i, in the range [1, 1] that satisfies nums[i] % modulo == k.\n- Hence, cnt = 0 and cnt % modulo == k.\nIt can be shown that there are no other interesting subarrays. So, the answer is 2.\n\nConstraints:\n\n * 1 <= nums.length <= 105\n * 1 <= nums[i] <= 109\n * 1 <= modulo <= 109\n * 0 <= k < modulo\n\"\"\"\nclass Solution:\n def countInterestingSubarrays(self, nums: List[int], modulo: int, k: int) -> int:\n ", "prompt_sft": "You are given a 0-indexed integer array nums, an integer modulo, and an integer k.\n\nYour task is to find the count of subarrays that are interesting.\n\nA subarray nums[l..r] is interesting if the following condition holds:\n\n * Let cnt be the number of indices i in the range [l, r] such that nums[i] % modulo == k. Then, cnt % modulo == k.\n\nReturn an integer denoting the count of interesting subarrays.\n\nNote: A subarray is a contiguous non-empty sequence of elements within an array.\n\nExample 1:\n\nInput: nums = [3,2,4], modulo = 2, k = 1\nOutput: 3\nExplanation: In this example the interesting subarrays are:\nThe subarray nums[0..0] which is [3].\n- There is only one index, i = 0, in the range [0, 0] that satisfies nums[i] % modulo == k.\n- Hence, cnt = 1 and cnt % modulo == k.\nThe subarray nums[0..1] which is [3,2].\n- There is only one index, i = 0, in the range [0, 1] that satisfies nums[i] % modulo == k.\n- Hence, cnt = 1 and cnt % modulo == k.\nThe subarray nums[0..2] which is [3,2,4].\n- There is only one index, i = 0, in the range [0, 2] that satisfies nums[i] % modulo == k.\n- Hence, cnt = 1 and cnt % modulo == k.\nIt can be shown that there are no other interesting subarrays. So, the answer is 3.\n\nExample 2:\n\nInput: nums = [3,1,9,6], modulo = 3, k = 0\nOutput: 2\nExplanation: In this example the interesting subarrays are:\nThe subarray nums[0..3] which is [3,1,9,6].\n- There are three indices, i = 0, 2, 3, in the range [0, 3] that satisfy nums[i] % modulo == k.\n- Hence, cnt = 3 and cnt % modulo == k.\nThe subarray nums[1..1] which is [1].\n- There is no index, i, in the range [1, 1] that satisfies nums[i] % modulo == k.\n- Hence, cnt = 0 and cnt % modulo == k.\nIt can be shown that there are no other interesting subarrays. So, the answer is 2.\n\nConstraints:\n\n * 1 <= nums.length <= 105\n * 1 <= nums[i] <= 109\n * 1 <= modulo <= 109\n * 0 <= k < modulo\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def countInterestingSubarrays(self, nums: List[int], modulo: int, k: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [3,2,4], \"modulo\": 2, \"k\": 1 }\nassert my_solution.countInterestingSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [3,1,9,6], \"modulo\": 3, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [11,12,21,31], \"modulo\": 10, \"k\": 1 }\nassert my_solution.countInterestingSubarrays(**test_input) == 5\n\ntest_input = { \"nums\": [2,4], \"modulo\": 7, \"k\": 2 }\nassert my_solution.countInterestingSubarrays(**test_input) == 0\n\ntest_input = { \"nums\": [2,7], \"modulo\": 7, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [2,45], \"modulo\": 13, \"k\": 2 }\nassert my_solution.countInterestingSubarrays(**test_input) == 0\n\ntest_input = { \"nums\": [3,3], \"modulo\": 5, \"k\": 3 }\nassert my_solution.countInterestingSubarrays(**test_input) == 0\n\ntest_input = { \"nums\": [3,4], \"modulo\": 8, \"k\": 3 }\nassert my_solution.countInterestingSubarrays(**test_input) == 0\n\ntest_input = { \"nums\": [4,5], \"modulo\": 1, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [5,1], \"modulo\": 6, \"k\": 1 }\nassert my_solution.countInterestingSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [7,2], \"modulo\": 7, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [7,4], \"modulo\": 7, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [8,8], \"modulo\": 4, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 0\n\ntest_input = { \"nums\": [9,2], \"modulo\": 2, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [18,43], \"modulo\": 3, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [19,67], \"modulo\": 47, \"k\": 19 }\nassert my_solution.countInterestingSubarrays(**test_input) == 0\n\ntest_input = { \"nums\": [20,8], \"modulo\": 41, \"k\": 8 }\nassert my_solution.countInterestingSubarrays(**test_input) == 0\n\ntest_input = { \"nums\": [26,5], \"modulo\": 21, \"k\": 5 }\nassert my_solution.countInterestingSubarrays(**test_input) == 0\n\ntest_input = { \"nums\": [81,36], \"modulo\": 4, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [2,1,5], \"modulo\": 9, \"k\": 1 }\nassert my_solution.countInterestingSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [2,2,5], \"modulo\": 3, \"k\": 2 }\nassert my_solution.countInterestingSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [2,2,5], \"modulo\": 4, \"k\": 2 }\nassert my_solution.countInterestingSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [2,3,2], \"modulo\": 6, \"k\": 2 }\nassert my_solution.countInterestingSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [3,2,5], \"modulo\": 1, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [5,1,6], \"modulo\": 2, \"k\": 1 }\nassert my_solution.countInterestingSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [5,2,8], \"modulo\": 2, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [6,5,6], \"modulo\": 6, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [7,1,2], \"modulo\": 1, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [7,2,9], \"modulo\": 4, \"k\": 1 }\nassert my_solution.countInterestingSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [7,5,6], \"modulo\": 4, \"k\": 1 }\nassert my_solution.countInterestingSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [9,1,6], \"modulo\": 7, \"k\": 1 }\nassert my_solution.countInterestingSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [40,1,24], \"modulo\": 41, \"k\": 1 }\nassert my_solution.countInterestingSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [48,36,27], \"modulo\": 9, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [1,9,6,1], \"modulo\": 2, \"k\": 1 }\nassert my_solution.countInterestingSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [2,2,1,2], \"modulo\": 3, \"k\": 2 }\nassert my_solution.countInterestingSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [3,5,4,2], \"modulo\": 5, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [4,18,38,15], \"modulo\": 21, \"k\": 4 }\nassert my_solution.countInterestingSubarrays(**test_input) == 0\n\ntest_input = { \"nums\": [6,6,1,4], \"modulo\": 7, \"k\": 6 }\nassert my_solution.countInterestingSubarrays(**test_input) == 0\n\ntest_input = { \"nums\": [7,5,2,1], \"modulo\": 1, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 10\n\ntest_input = { \"nums\": [7,5,3,4], \"modulo\": 3, \"k\": 1 }\nassert my_solution.countInterestingSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [8,6,5,6], \"modulo\": 3, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [8,7,3,2], \"modulo\": 6, \"k\": 2 }\nassert my_solution.countInterestingSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [9,2,2,6], \"modulo\": 7, \"k\": 2 }\nassert my_solution.countInterestingSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [9,7,4,1], \"modulo\": 2, \"k\": 1 }\nassert my_solution.countInterestingSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [9,7,8,9], \"modulo\": 5, \"k\": 4 }\nassert my_solution.countInterestingSubarrays(**test_input) == 0\n\ntest_input = { \"nums\": [9,48,32,11], \"modulo\": 2, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [53,44,40,37], \"modulo\": 2, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [91,5,60,93], \"modulo\": 59, \"k\": 1 }\nassert my_solution.countInterestingSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [2,1,1,3,5], \"modulo\": 4, \"k\": 1 }\nassert my_solution.countInterestingSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [2,2,5,4,3], \"modulo\": 5, \"k\": 2 }\nassert my_solution.countInterestingSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [2,2,5,6,1], \"modulo\": 1, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 15\n\ntest_input = { \"nums\": [2,6,2,3,1], \"modulo\": 9, \"k\": 2 }\nassert my_solution.countInterestingSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [2,7,4,8,5], \"modulo\": 2, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 7\n\ntest_input = { \"nums\": [4,2,1,8,8], \"modulo\": 3, \"k\": 2 }\nassert my_solution.countInterestingSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [4,2,8,8,2], \"modulo\": 9, \"k\": 2 }\nassert my_solution.countInterestingSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [5,6,3,9,3], \"modulo\": 9, \"k\": 3 }\nassert my_solution.countInterestingSubarrays(**test_input) == 0\n\ntest_input = { \"nums\": [6,7,1,9,2], \"modulo\": 1, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 15\n\ntest_input = { \"nums\": [6,9,5,1,6], \"modulo\": 5, \"k\": 1 }\nassert my_solution.countInterestingSubarrays(**test_input) == 7\n\ntest_input = { \"nums\": [7,3,6,2,6], \"modulo\": 1, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 15\n\ntest_input = { \"nums\": [7,7,9,5,8], \"modulo\": 4, \"k\": 1 }\nassert my_solution.countInterestingSubarrays(**test_input) == 5\n\ntest_input = { \"nums\": [7,9,1,3,2], \"modulo\": 8, \"k\": 1 }\nassert my_solution.countInterestingSubarrays(**test_input) == 5\n\ntest_input = { \"nums\": [8,6,9,4,4], \"modulo\": 9, \"k\": 4 }\nassert my_solution.countInterestingSubarrays(**test_input) == 0\n\ntest_input = { \"nums\": [8,8,6,8,9], \"modulo\": 9, \"k\": 8 }\nassert my_solution.countInterestingSubarrays(**test_input) == 0\n\ntest_input = { \"nums\": [9,7,8,7,8], \"modulo\": 7, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [26,9,14,4,24], \"modulo\": 26, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 10\n\ntest_input = { \"nums\": [31,30,24,34,20], \"modulo\": 22, \"k\": 2 }\nassert my_solution.countInterestingSubarrays(**test_input) == 0\n\ntest_input = { \"nums\": [39,41,6,30,38], \"modulo\": 43, \"k\": 6 }\nassert my_solution.countInterestingSubarrays(**test_input) == 0\n\ntest_input = { \"nums\": [1,2,7,1,6,6], \"modulo\": 5, \"k\": 1 }\nassert my_solution.countInterestingSubarrays(**test_input) == 8\n\ntest_input = { \"nums\": [1,6,2,1,9,7], \"modulo\": 3, \"k\": 1 }\nassert my_solution.countInterestingSubarrays(**test_input) == 11\n\ntest_input = { \"nums\": [1,7,8,2,5,9], \"modulo\": 7, \"k\": 1 }\nassert my_solution.countInterestingSubarrays(**test_input) == 10\n\ntest_input = { \"nums\": [2,4,6,6,5,1], \"modulo\": 8, \"k\": 6 }\nassert my_solution.countInterestingSubarrays(**test_input) == 0\n\ntest_input = { \"nums\": [2,8,2,9,2,8], \"modulo\": 5, \"k\": 2 }\nassert my_solution.countInterestingSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [2,9,1,6,5,7], \"modulo\": 7, \"k\": 2 }\nassert my_solution.countInterestingSubarrays(**test_input) == 5\n\ntest_input = { \"nums\": [2,9,1,6,6,7], \"modulo\": 9, \"k\": 6 }\nassert my_solution.countInterestingSubarrays(**test_input) == 0\n\ntest_input = { \"nums\": [2,9,6,8,8,3], \"modulo\": 1, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 21\n\ntest_input = { \"nums\": [4,8,4,3,7,5], \"modulo\": 4, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [4,9,4,9,7,7], \"modulo\": 9, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 5\n\ntest_input = { \"nums\": [5,3,7,9,8,7], \"modulo\": 3, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 5\n\ntest_input = { \"nums\": [7,1,6,1,7,2], \"modulo\": 6, \"k\": 1 }\nassert my_solution.countInterestingSubarrays(**test_input) == 7\n\ntest_input = { \"nums\": [7,3,1,9,1,3], \"modulo\": 5, \"k\": 1 }\nassert my_solution.countInterestingSubarrays(**test_input) == 10\n\ntest_input = { \"nums\": [7,4,9,8,3,4], \"modulo\": 1, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 21\n\ntest_input = { \"nums\": [7,5,1,7,7,7], \"modulo\": 8, \"k\": 7 }\nassert my_solution.countInterestingSubarrays(**test_input) == 0\n\ntest_input = { \"nums\": [8,4,5,6,7,4], \"modulo\": 4, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [8,7,3,8,4,8], \"modulo\": 8, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [8,7,5,5,2,1], \"modulo\": 5, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [8,18,36,50,12,37], \"modulo\": 18, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 7\n\ntest_input = { \"nums\": [9,9,6,7,2,3], \"modulo\": 5, \"k\": 2 }\nassert my_solution.countInterestingSubarrays(**test_input) == 8\n\ntest_input = { \"nums\": [16,1,33,39,15,1], \"modulo\": 30, \"k\": 1 }\nassert my_solution.countInterestingSubarrays(**test_input) == 12\n\ntest_input = { \"nums\": [17,25,9,20,41,26], \"modulo\": 38, \"k\": 3 }\nassert my_solution.countInterestingSubarrays(**test_input) == 0\n\ntest_input = { \"nums\": [21,26,39,21,31,49], \"modulo\": 22, \"k\": 21 }\nassert my_solution.countInterestingSubarrays(**test_input) == 0\n\ntest_input = { \"nums\": [37,44,17,22,50,15], \"modulo\": 6, \"k\": 2 }\nassert my_solution.countInterestingSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [40,10,31,40,30,32], \"modulo\": 50, \"k\": 40 }\nassert my_solution.countInterestingSubarrays(**test_input) == 0\n\ntest_input = { \"nums\": [40,22,22,35,2,16], \"modulo\": 24, \"k\": 16 }\nassert my_solution.countInterestingSubarrays(**test_input) == 0\n\ntest_input = { \"nums\": [98,23,66,13,70,34], \"modulo\": 74, \"k\": 13 }\nassert my_solution.countInterestingSubarrays(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,4,8,3,2,7], \"modulo\": 9, \"k\": 1 }\nassert my_solution.countInterestingSubarrays(**test_input) == 7\n\ntest_input = { \"nums\": [1,8,6,3,2,8,8], \"modulo\": 2, \"k\": 0 }\nassert my_solution.countInterestingSubarrays(**test_input) == 13\n\ntest_input = { \"nums\": [1,9,2,1,5,4,8], \"modulo\": 4, \"k\": 1 }\nassert my_solution.countInterestingSubarrays(**test_input) == 8\n\ntest_input = { \"nums\": [4,6,8,3,4,3,4], \"modulo\": 7, \"k\": 4 }\nassert my_solution.countInterestingSubarrays(**test_input) == 0\n\ntest_input = { \"nums\": [5,4,5,8,9,1,9], \"modulo\": 4, \"k\": 1 }\nassert my_solution.countInterestingSubarrays(**test_input) == 11\n\ntest_input = { \"nums\": [5,4,6,1,3,2,7], \"modulo\": 9, \"k\": 1 }\nassert my_solution.countInterestingSubarrays(**test_input) == 16", "start_time": 1693708200} +{"task_id": "weekly-contest-361-minimum-edge-weight-equilibrium-queries-in-a-tree", "url": "https://leetcode.com/problems/minimum-edge-weight-equilibrium-queries-in-a-tree", "title": "minimum-edge-weight-equilibrium-queries-in-a-tree", "meta": {"questionId": "3079", "questionFrontendId": "2846", "title": "Minimum Edge Weight Equilibrium Queries in a Tree", "titleSlug": "minimum-edge-weight-equilibrium-queries-in-a-tree", "isPaidOnly": false, "difficulty": "Hard", "likes": 260, "dislikes": 4, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nThere is an undirected tree with n nodes labeled from 0 to n - 1. You are given the integer n and a 2D integer array edges of length n - 1, where edges[i] = [ui, vi, wi] indicates that there is an edge between nodes ui and vi with weight wi in the tree.\n\nYou are also given a 2D integer array queries of length m, where queries[i] = [ai, bi]. For each query, find the minimum number of operations required to make the weight of every edge on the path from ai to bi equal. In one operation, you can choose any edge of the tree and change its weight to any value.\n\nNote that:\n\n * Queries are independent of each other, meaning that the tree returns to its initial state on each new query.\n * The path from ai to bi is a sequence of distinct nodes starting with node ai and ending with node bi such that every two adjacent nodes in the sequence share an edge in the tree.\n\nReturn an array answer of length m where answer[i] is the answer to the ith query.\n\nExample 1:\n\n[https://assets.leetcode.com/uploads/2023/08/11/graph-6-1.png]\n\nInput: n = 7, edges = [[0,1,1],[1,2,1],[2,3,1],[3,4,2],[4,5,2],[5,6,2]], queries = [[0,3],[3,6],[2,6],[0,6]]\nOutput: [0,0,1,3]\nExplanation: In the first query, all the edges in the path from 0 to 3 have a weight of 1. Hence, the answer is 0.\nIn the second query, all the edges in the path from 3 to 6 have a weight of 2. Hence, the answer is 0.\nIn the third query, we change the weight of edge [2,3] to 2. After this operation, all the edges in the path from 2 to 6 have a weight of 2. Hence, the answer is 1.\nIn the fourth query, we change the weights of edges [0,1], [1,2] and [2,3] to 2. After these operations, all the edges in the path from 0 to 6 have a weight of 2. Hence, the answer is 3.\nFor each queries[i], it can be shown that answer[i] is the minimum number of operations needed to equalize all the edge weights in the path from ai to bi.\n\nExample 2:\n\n[https://assets.leetcode.com/uploads/2023/08/11/graph-9-1.png]\n\nInput: n = 8, edges = [[1,2,6],[1,3,4],[2,4,6],[2,5,3],[3,6,6],[3,0,8],[7,0,2]], queries = [[4,6],[0,4],[6,5],[7,4]]\nOutput: [1,2,2,3]\nExplanation: In the first query, we change the weight of edge [1,3] to 6. After this operation, all the edges in the path from 4 to 6 have a weight of 6. Hence, the answer is 1.\nIn the second query, we change the weight of edges [0,3] and [3,1] to 6. After these operations, all the edges in the path from 0 to 4 have a weight of 6. Hence, the answer is 2.\nIn the third query, we change the weight of edges [1,3] and [5,2] to 6. After these operations, all the edges in the path from 6 to 5 have a weight of 6. Hence, the answer is 2.\nIn the fourth query, we change the weights of edges [0,7], [0,3] and [1,3] to 6. After these operations, all the edges in the path from 7 to 4 have a weight of 6. Hence, the answer is 3.\nFor each queries[i], it can be shown that answer[i] is the minimum number of operations needed to equalize all the edge weights in the path from ai to bi.\n\n\nConstraints:\n\n * 1 <= n <= 104\n * edges.length == n - 1\n * edges[i].length == 3\n * 0 <= ui, vi < n\n * 1 <= wi <= 26\n * The input is generated such that edges represents a valid tree.\n * 1 <= queries.length == m <= 2 * 104\n * queries[i].length == 2\n * 0 <= ai, bi < n\n\"\"\"\nclass Solution:\n def minOperationsQueries(self, n: int, edges: List[List[int]], queries: List[List[int]]) -> List[int]:\n ", "prompt_sft": "There is an undirected tree with n nodes labeled from 0 to n - 1. You are given the integer n and a 2D integer array edges of length n - 1, where edges[i] = [ui, vi, wi] indicates that there is an edge between nodes ui and vi with weight wi in the tree.\n\nYou are also given a 2D integer array queries of length m, where queries[i] = [ai, bi]. For each query, find the minimum number of operations required to make the weight of every edge on the path from ai to bi equal. In one operation, you can choose any edge of the tree and change its weight to any value.\n\nNote that:\n\n * Queries are independent of each other, meaning that the tree returns to its initial state on each new query.\n * The path from ai to bi is a sequence of distinct nodes starting with node ai and ending with node bi such that every two adjacent nodes in the sequence share an edge in the tree.\n\nReturn an array answer of length m where answer[i] is the answer to the ith query.\n\nExample 1:\n\n[https://assets.leetcode.com/uploads/2023/08/11/graph-6-1.png]\n\nInput: n = 7, edges = [[0,1,1],[1,2,1],[2,3,1],[3,4,2],[4,5,2],[5,6,2]], queries = [[0,3],[3,6],[2,6],[0,6]]\nOutput: [0,0,1,3]\nExplanation: In the first query, all the edges in the path from 0 to 3 have a weight of 1. Hence, the answer is 0.\nIn the second query, all the edges in the path from 3 to 6 have a weight of 2. Hence, the answer is 0.\nIn the third query, we change the weight of edge [2,3] to 2. After this operation, all the edges in the path from 2 to 6 have a weight of 2. Hence, the answer is 1.\nIn the fourth query, we change the weights of edges [0,1], [1,2] and [2,3] to 2. After these operations, all the edges in the path from 0 to 6 have a weight of 2. Hence, the answer is 3.\nFor each queries[i], it can be shown that answer[i] is the minimum number of operations needed to equalize all the edge weights in the path from ai to bi.\n\nExample 2:\n\n[https://assets.leetcode.com/uploads/2023/08/11/graph-9-1.png]\n\nInput: n = 8, edges = [[1,2,6],[1,3,4],[2,4,6],[2,5,3],[3,6,6],[3,0,8],[7,0,2]], queries = [[4,6],[0,4],[6,5],[7,4]]\nOutput: [1,2,2,3]\nExplanation: In the first query, we change the weight of edge [1,3] to 6. After this operation, all the edges in the path from 4 to 6 have a weight of 6. Hence, the answer is 1.\nIn the second query, we change the weight of edges [0,3] and [3,1] to 6. After these operations, all the edges in the path from 0 to 4 have a weight of 6. Hence, the answer is 2.\nIn the third query, we change the weight of edges [1,3] and [5,2] to 6. After these operations, all the edges in the path from 6 to 5 have a weight of 6. Hence, the answer is 2.\nIn the fourth query, we change the weights of edges [0,7], [0,3] and [1,3] to 6. After these operations, all the edges in the path from 7 to 4 have a weight of 6. Hence, the answer is 3.\nFor each queries[i], it can be shown that answer[i] is the minimum number of operations needed to equalize all the edge weights in the path from ai to bi.\n\n\nConstraints:\n\n * 1 <= n <= 104\n * edges.length == n - 1\n * edges[i].length == 3\n * 0 <= ui, vi < n\n * 1 <= wi <= 26\n * The input is generated such that edges represents a valid tree.\n * 1 <= queries.length == m <= 2 * 104\n * queries[i].length == 2\n * 0 <= ai, bi < n\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def minOperationsQueries(self, n: int, edges: List[List[int]], queries: List[List[int]]) -> List[int]:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"n\": 7, \"edges\": [[0,1,1],[1,2,1],[2,3,1],[3,4,2],[4,5,2],[5,6,2]], \"queries\": [[0,3],[3,6],[2,6],[0,6]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,0,1,3]\n\ntest_input = { \"n\": 8, \"edges\": [[1,2,6],[1,3,4],[2,4,6],[2,5,3],[3,6,6],[3,0,8],[7,0,2]], \"queries\": [[4,6],[0,4],[6,5],[7,4]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,2,2,3]\n\ntest_input = { \"n\": 1, \"edges\": [], \"queries\": [[0,0]] }\nassert my_solution.minOperationsQueries(**test_input) == [0]\n\ntest_input = { \"n\": 2, \"edges\": [[0,1,26]], \"queries\": [[0,1],[0,0],[1,1]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,0,0]\n\ntest_input = { \"n\": 3, \"edges\": [[2,1,1],[2,0,2]], \"queries\": [[0,1],[0,2],[1,2],[0,0],[1,1],[2,2]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,0,0,0,0,0]\n\ntest_input = { \"n\": 6, \"edges\": [[1,3,3],[4,1,3],[0,3,5],[5,4,2],[2,5,1]], \"queries\": [[2,1],[2,0],[3,0],[2,2],[2,5],[4,1],[5,2]] }\nassert my_solution.minOperationsQueries(**test_input) == [2,3,0,0,0,0,0]\n\ntest_input = { \"n\": 7, \"edges\": [[2,1,2],[4,2,4],[5,2,4],[3,4,5],[6,3,5],[0,6,5]], \"queries\": [[4,4],[6,2],[3,4],[6,1],[2,0],[4,2],[5,0],[3,2],[3,5]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,1,0,2,1,0,2,1,1]\n\ntest_input = { \"n\": 5, \"edges\": [[1,2,1],[4,1,5],[3,2,3],[0,1,2]], \"queries\": [[1,2],[0,4],[0,0],[4,3],[4,2],[0,2],[3,3],[3,2]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,1,0,2,1,1,0,0]\n\ntest_input = { \"n\": 10, \"edges\": [[9,7,1],[5,9,2],[0,9,4],[3,9,5],[1,9,5],[4,0,4],[2,0,2],[8,7,4],[6,3,2]], \"queries\": [[4,3],[8,1],[9,6],[7,0],[1,1],[5,0],[4,8],[3,6],[8,2],[9,7]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,2,1,1,0,1,1,0,2,0]\n\ntest_input = { \"n\": 10, \"edges\": [[7,1,2],[9,7,3],[8,7,1],[3,7,4],[4,8,2],[5,7,2],[6,4,5],[0,1,4],[2,1,5]], \"queries\": [[0,4],[9,6],[8,0],[2,6],[5,9],[3,2],[4,1],[9,4]] }\nassert my_solution.minOperationsQueries(**test_input) == [2,3,2,3,1,2,1,2]\n\ntest_input = { \"n\": 5, \"edges\": [[4,2,4],[3,4,3],[0,4,1],[1,3,1]], \"queries\": [[4,3],[3,1],[1,1],[4,2],[1,4],[2,3],[3,3],[4,1]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,0,0,0,1,1,0,1]\n\ntest_input = { \"n\": 6, \"edges\": [[4,0,4],[1,0,5],[3,4,4],[5,0,4],[2,4,4]], \"queries\": [[4,4],[1,2],[4,0],[0,4],[4,3],[1,4],[3,2],[3,5],[5,2]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,1,0,0,0,1,0,0,0]\n\ntest_input = { \"n\": 6, \"edges\": [[4,3,2],[5,3,2],[1,4,5],[0,4,2],[2,1,1]], \"queries\": [[0,4],[2,1],[5,4],[2,0],[4,2],[4,5],[3,3],[5,0],[3,5],[5,2]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,0,0,2,1,0,0,0,0,2]\n\ntest_input = { \"n\": 5, \"edges\": [[0,1,5],[2,0,1],[3,0,1],[4,2,1]], \"queries\": [[2,1],[4,3],[4,2],[1,4],[0,2],[2,2],[3,2],[1,3]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,0,0,1,0,0,0,1]\n\ntest_input = { \"n\": 9, \"edges\": [[6,2,1],[5,2,1],[4,2,2],[7,4,4],[1,7,4],[0,1,4],[3,2,2],[8,3,1]], \"queries\": [[4,4],[7,4],[2,4],[6,2],[1,1],[6,8],[5,7],[4,2],[2,6]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,0,0,0,0,1,2,0,0]\n\ntest_input = { \"n\": 8, \"edges\": [[6,1,2],[2,1,5],[3,6,1],[7,1,3],[5,7,4],[4,7,5],[0,5,5]], \"queries\": [[4,0],[7,1],[3,4],[4,6],[5,7],[4,5],[3,3],[0,2],[7,2],[1,0]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,0,3,2,0,1,0,2,1,2]\n\ntest_input = { \"n\": 10, \"edges\": [[5,3,5],[6,3,1],[1,6,4],[2,6,3],[9,1,5],[4,3,5],[7,3,4],[0,1,1],[8,6,4]], \"queries\": [[6,5],[6,8],[0,3],[5,1],[5,7],[2,3],[7,9],[9,8],[5,9],[3,5]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,0,1,2,1,1,2,1,2,0]\n\ntest_input = { \"n\": 5, \"edges\": [[0,3,2],[4,3,2],[2,3,3],[1,4,5]], \"queries\": [[2,1],[0,0],[4,3],[1,1],[2,0],[3,0],[2,3],[1,0]] }\nassert my_solution.minOperationsQueries(**test_input) == [2,0,0,0,1,0,0,1]\n\ntest_input = { \"n\": 7, \"edges\": [[1,2,4],[3,2,4],[6,2,4],[0,6,5],[4,6,1],[5,1,5]], \"queries\": [[4,4],[5,5],[0,4],[0,0],[5,4],[5,1],[2,3],[2,2],[3,2],[4,1]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,0,1,0,2,0,0,0,0,1]\n\ntest_input = { \"n\": 10, \"edges\": [[7,0,2],[4,0,2],[6,7,3],[1,6,4],[9,1,3],[8,1,4],[3,6,3],[2,7,5],[5,7,5]], \"queries\": [[6,2],[0,4],[5,1],[2,3],[4,7],[8,9],[4,8],[9,1],[6,3],[1,9]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,0,2,1,0,1,3,0,0,0]\n\ntest_input = { \"n\": 9, \"edges\": [[1,5,4],[4,5,1],[0,4,2],[8,0,2],[6,1,5],[3,8,5],[2,3,2],[7,5,2]], \"queries\": [[0,1],[0,4],[3,1],[1,1],[5,4],[7,0],[5,1],[8,0],[0,3],[4,7]] }\nassert my_solution.minOperationsQueries(**test_input) == [2,0,3,0,0,1,0,0,1,1]\n\ntest_input = { \"n\": 10, \"edges\": [[4,8,4],[5,4,3],[6,5,3],[7,4,3],[2,8,5],[9,4,4],[1,6,1],[3,9,5],[0,8,2]], \"queries\": [[8,8],[9,0],[6,2],[2,1],[7,7],[8,7],[9,6],[5,0],[7,5]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,1,2,3,0,1,1,2,0]\n\ntest_input = { \"n\": 10, \"edges\": [[4,3,1],[9,3,1],[2,3,5],[1,4,2],[5,4,2],[0,2,5],[7,1,3],[6,2,2],[8,0,4]], \"queries\": [[0,7],[9,3],[5,8],[9,6],[5,7],[1,4],[2,9],[0,8],[3,5]] }\nassert my_solution.minOperationsQueries(**test_input) == [3,0,3,2,1,0,1,0,1]\n\ntest_input = { \"n\": 10, \"edges\": [[4,0,1],[7,4,1],[3,0,3],[1,7,4],[6,7,1],[9,7,5],[5,4,5],[2,9,1],[8,9,2]], \"queries\": [[6,2],[8,1],[1,1],[6,4],[2,9],[5,0],[2,5],[9,7],[1,9],[2,8]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,2,0,0,0,1,2,0,1,1]\n\ntest_input = { \"n\": 7, \"edges\": [[6,5,4],[0,5,5],[4,0,1],[1,6,4],[3,1,5],[2,3,1]], \"queries\": [[4,1],[0,2],[3,3],[2,6],[5,6],[0,5],[5,3],[1,3],[5,2]] }\nassert my_solution.minOperationsQueries(**test_input) == [2,3,0,2,0,0,1,0,2]\n\ntest_input = { \"n\": 7, \"edges\": [[2,3,2],[4,2,2],[0,2,4],[5,3,5],[6,3,2],[1,3,4]], \"queries\": [[6,2],[4,6],[2,0],[3,0],[0,2],[0,5],[5,3],[3,5]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,0,0,1,0,2,0,0]\n\ntest_input = { \"n\": 9, \"edges\": [[7,6,2],[3,7,5],[4,3,4],[2,6,5],[8,4,5],[5,2,3],[1,2,4],[0,6,2]], \"queries\": [[4,4],[3,8],[0,4],[8,1],[3,1],[7,0],[4,5],[3,6],[4,7]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,1,2,3,2,0,3,1,1]\n\ntest_input = { \"n\": 6, \"edges\": [[4,1,3],[2,4,4],[5,2,5],[3,1,5],[0,4,2]], \"queries\": [[3,4],[4,3],[0,3],[4,2],[3,0],[3,3],[5,3],[5,2]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,1,2,0,2,0,2,0]\n\ntest_input = { \"n\": 8, \"edges\": [[0,3,3],[4,0,5],[5,4,2],[6,3,1],[1,3,3],[2,3,2],[7,3,4]], \"queries\": [[6,2],[4,0],[3,4],[2,7],[4,3],[7,0],[7,3],[7,6],[6,3],[4,1]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,0,1,1,1,1,0,1,0,1]\n\ntest_input = { \"n\": 5, \"edges\": [[0,3,2],[2,0,2],[4,3,3],[1,2,3]], \"queries\": [[0,1],[2,1],[4,3],[1,4],[2,3],[0,2],[3,3],[3,2],[1,3]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,0,0,2,0,0,0,0,1]\n\ntest_input = { \"n\": 10, \"edges\": [[8,0,5],[6,0,4],[7,6,3],[3,7,5],[5,3,5],[2,8,5],[1,8,4],[4,6,3],[9,4,4]], \"queries\": [[9,0],[3,4],[6,5],[0,3],[2,3],[1,7],[7,6],[5,0],[2,5]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,1,1,2,2,2,0,2,2]\n\ntest_input = { \"n\": 9, \"edges\": [[2,3,1],[4,2,1],[1,3,3],[0,4,3],[5,2,3],[7,2,1],[8,5,3],[6,4,2]], \"queries\": [[7,7],[4,3],[3,1],[5,4],[1,8],[1,4],[7,3],[7,6],[8,2],[3,5]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,0,0,1,1,1,0,1,0,1]\n\ntest_input = { \"n\": 5, \"edges\": [[4,1,4],[3,1,5],[0,4,3],[2,1,4]], \"queries\": [[0,1],[2,4],[1,2],[0,4],[3,4],[0,0],[1,1]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,0,0,0,1,0,0]\n\ntest_input = { \"n\": 4, \"edges\": [[1,2,4],[3,2,5],[0,1,5]], \"queries\": [[1,2],[3,1],[1,1],[2,0],[3,0],[3,3]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,1,0,1,1,0]\n\ntest_input = { \"n\": 4, \"edges\": [[1,2,3],[0,2,1],[3,2,5]], \"queries\": [[3,1],[1,1],[3,0],[2,3],[3,3],[2,2],[1,0],[3,2]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,0,1,0,0,0,1,0]\n\ntest_input = { \"n\": 8, \"edges\": [[4,6,3],[7,4,1],[3,7,4],[1,4,1],[0,6,4],[5,7,3],[2,1,3]], \"queries\": [[2,4],[6,2],[7,1],[5,1],[4,2],[1,7],[1,3],[3,5]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,1,0,1,1,0,1,1]\n\ntest_input = { \"n\": 9, \"edges\": [[1,7,4],[5,1,2],[6,1,4],[2,5,2],[3,2,5],[8,3,2],[0,3,2],[4,5,2]], \"queries\": [[7,4],[4,0],[3,4],[6,1],[0,3],[3,3],[6,0],[5,3],[3,2],[6,3]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,1,1,0,0,0,2,1,0,2]\n\ntest_input = { \"n\": 5, \"edges\": [[0,3,4],[2,0,5],[4,2,1],[1,4,4]], \"queries\": [[0,1],[0,4],[4,1],[2,0],[4,2],[0,2],[3,3],[1,0],[1,3]] }\nassert my_solution.minOperationsQueries(**test_input) == [2,1,0,0,0,0,0,2,2]\n\ntest_input = { \"n\": 8, \"edges\": [[5,4,1],[0,5,3],[2,0,5],[3,5,4],[7,2,4],[1,7,5],[6,5,2]], \"queries\": [[2,4],[4,0],[6,5],[5,4],[5,1],[0,6],[6,0],[3,5]] }\nassert my_solution.minOperationsQueries(**test_input) == [2,1,0,0,2,1,1,0]\n\ntest_input = { \"n\": 8, \"edges\": [[4,2,3],[3,2,3],[6,3,3],[7,4,5],[5,3,4],[0,6,5],[1,5,3]], \"queries\": [[0,1],[2,4],[3,4],[4,2],[7,3],[4,5],[3,6],[6,6],[6,3]] }\nassert my_solution.minOperationsQueries(**test_input) == [2,0,0,0,1,1,0,0,0]\n\ntest_input = { \"n\": 10, \"edges\": [[2,4,2],[1,2,4],[5,2,1],[0,1,1],[9,4,4],[7,9,1],[3,9,5],[8,5,1],[6,2,5]], \"queries\": [[1,2],[4,0],[8,4],[0,3],[6,7],[3,3],[1,6],[3,2],[9,1],[7,8]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,2,1,3,3,0,1,2,1,2]\n\ntest_input = { \"n\": 5, \"edges\": [[0,1,5],[4,1,5],[3,4,4],[2,0,2]], \"queries\": [[2,4],[1,2],[0,4],[3,4],[0,0],[4,3],[1,1],[1,4],[3,0],[0,2]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,1,0,0,0,0,0,0,1,0]\n\ntest_input = { \"n\": 8, \"edges\": [[0,2,5],[7,2,2],[1,7,4],[5,0,1],[4,2,2],[3,2,3],[6,4,3]], \"queries\": [[7,4],[0,4],[6,5],[0,0],[6,1],[2,0],[5,7],[7,2],[2,2],[1,0]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,1,3,0,2,0,2,0,0,2]\n\ntest_input = { \"n\": 8, \"edges\": [[7,5,4],[0,5,3],[6,7,5],[3,0,3],[2,6,3],[4,2,4],[1,4,3]], \"queries\": [[5,5],[7,1],[3,4],[2,7],[4,3],[6,1],[1,4],[3,0],[6,0]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,2,3,1,3,1,0,0,2]\n\ntest_input = { \"n\": 5, \"edges\": [[4,0,4],[2,4,4],[3,2,1],[1,4,4]], \"queries\": [[0,1],[0,4],[3,4],[4,3],[1,1],[1,4],[0,2],[3,3],[1,3]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,0,1,1,0,0,0,0,1]\n\ntest_input = { \"n\": 4, \"edges\": [[0,2,1],[3,2,2],[1,2,1]], \"queries\": [[0,3],[2,3],[0,2],[3,3],[2,2],[1,0]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,0,0,0,0,0]\n\ntest_input = { \"n\": 5, \"edges\": [[4,2,5],[1,4,5],[0,4,4],[3,4,4]], \"queries\": [[0,1],[0,4],[3,1],[0,3],[4,2],[3,0],[1,4],[1,0]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,0,1,0,0,0,0,1]\n\ntest_input = { \"n\": 4, \"edges\": [[1,3,4],[2,3,5],[0,3,2]], \"queries\": [[1,2],[0,3],[2,0],[3,0],[0,2],[2,2],[3,2],[1,3]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,0,1,0,1,0,0,0]\n\ntest_input = { \"n\": 9, \"edges\": [[5,8,2],[3,8,3],[6,5,3],[7,5,3],[1,6,1],[0,8,1],[4,5,2],[2,1,4]], \"queries\": [[8,8],[3,4],[6,5],[2,7],[8,1],[6,7],[2,5],[3,5]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,1,0,2,2,0,2,1]\n\ntest_input = { \"n\": 10, \"edges\": [[4,5,5],[1,4,3],[8,4,5],[2,1,3],[0,1,2],[6,0,1],[7,0,1],[3,7,4],[9,2,1]], \"queries\": [[3,8],[1,5],[0,3],[4,6],[4,2],[2,3],[6,3],[2,5],[9,1],[1,9]] }\nassert my_solution.minOperationsQueries(**test_input) == [4,1,1,2,0,3,1,1,1,1]\n\ntest_input = { \"n\": 8, \"edges\": [[0,5,5],[2,0,2],[3,5,2],[1,5,1],[7,1,5],[4,0,4],[6,2,4]], \"queries\": [[7,4],[0,4],[7,1],[6,4],[5,0],[5,6],[2,2],[2,5]] }\nassert my_solution.minOperationsQueries(**test_input) == [2,0,0,1,0,2,0,1]\n\ntest_input = { \"n\": 9, \"edges\": [[0,3,1],[4,0,5],[8,4,5],[5,8,4],[1,4,3],[6,4,4],[7,0,1],[2,5,5]], \"queries\": [[1,2],[8,4],[2,1],[6,5],[3,4],[4,0],[2,0],[6,0],[7,8],[2,8]] }\nassert my_solution.minOperationsQueries(**test_input) == [2,0,2,1,1,0,1,1,1,1]\n\ntest_input = { \"n\": 5, \"edges\": [[1,2,5],[4,2,5],[0,4,2],[3,1,1]], \"queries\": [[0,4],[0,0],[4,3],[1,4],[3,0],[2,3],[2,2],[1,0],[1,3]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,0,1,0,2,1,0,1,0]\n\ntest_input = { \"n\": 7, \"edges\": [[4,1,3],[5,4,5],[0,1,2],[2,4,3],[3,4,2],[6,1,5]], \"queries\": [[2,4],[4,0],[1,2],[3,4],[1,5],[6,1],[2,0],[3,5]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,1,0,0,1,0,1,1]\n\ntest_input = { \"n\": 9, \"edges\": [[8,5,5],[0,5,3],[4,5,3],[6,5,2],[1,0,2],[3,6,4],[2,4,2],[7,3,3]], \"queries\": [[0,4],[7,7],[1,5],[8,7],[1,1],[5,1],[2,3],[8,3],[3,6],[3,2]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,0,1,3,0,1,2,2,0,2]\n\ntest_input = { \"n\": 9, \"edges\": [[6,3,1],[1,6,1],[8,3,2],[7,1,1],[0,8,2],[5,3,2],[4,3,5],[2,6,4]], \"queries\": [[8,1],[8,7],[6,1],[7,3],[1,0],[1,6],[0,8],[1,3],[5,2]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,1,0,0,2,0,0,0,2]\n\ntest_input = { \"n\": 9, \"edges\": [[2,0,1],[5,0,1],[3,2,4],[4,5,2],[1,4,3],[7,3,5],[6,1,1],[8,5,5]], \"queries\": [[4,0],[7,1],[6,5],[4,1],[8,7],[5,7],[2,3],[1,7],[1,3],[5,2]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,4,2,0,3,2,0,4,3,0]\n\ntest_input = { \"n\": 5, \"edges\": [[3,4,2],[2,3,2],[0,4,3],[1,0,1]], \"queries\": [[4,4],[0,1],[4,0],[1,2],[0,0],[1,4],[2,3],[0,2]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,0,0,2,0,1,0,1]\n\ntest_input = { \"n\": 4, \"edges\": [[3,2,1],[0,3,2],[1,3,4]], \"queries\": [[0,1],[1,2],[3,1],[1,1],[2,0],[0,2],[2,2],[1,0]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,1,0,0,1,1,0,1]\n\ntest_input = { \"n\": 5, \"edges\": [[0,2,2],[4,0,5],[3,2,2],[1,3,3]], \"queries\": [[2,4],[1,2],[0,0],[0,3],[4,2],[3,0],[1,0],[3,2],[1,3]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,1,0,0,1,0,1,0,0]\n\ntest_input = { \"n\": 7, \"edges\": [[5,2,2],[3,5,2],[1,5,2],[0,3,4],[6,2,2],[4,0,4]], \"queries\": [[1,5],[2,0],[6,4],[0,5],[2,2],[5,3],[1,3],[3,5]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,1,2,1,0,0,0,0]\n\ntest_input = { \"n\": 4, \"edges\": [[0,3,3],[1,3,1],[2,1,2]], \"queries\": [[0,1],[1,2],[2,1],[0,0],[3,1],[1,1],[0,2],[2,2],[1,0],[3,2]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,0,0,0,0,0,2,0,1,1]\n\ntest_input = { \"n\": 6, \"edges\": [[0,5,3],[2,5,4],[4,5,1],[3,4,4],[1,3,5]], \"queries\": [[4,4],[2,1],[4,1],[3,1],[0,3],[2,2],[1,0],[1,3]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,2,1,0,2,0,3,0]\n\ntest_input = { \"n\": 8, \"edges\": [[0,7,1],[4,7,4],[3,7,5],[1,3,2],[5,4,3],[2,3,3],[6,0,4]], \"queries\": [[4,4],[7,4],[1,2],[7,7],[0,0],[6,1],[0,6],[2,6],[4,1],[4,7]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,0,1,0,0,3,0,3,2,0]\n\ntest_input = { \"n\": 5, \"edges\": [[0,3,3],[2,0,1],[1,2,5],[4,0,3]], \"queries\": [[0,4],[2,1],[3,4],[0,0],[4,3],[3,1],[1,1],[0,2],[4,1]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,0,0,0,0,2,0,0,2]\n\ntest_input = { \"n\": 7, \"edges\": [[4,1,3],[2,1,2],[0,4,3],[6,0,3],[3,4,2],[5,0,5]], \"queries\": [[0,1],[6,2],[5,4],[1,4],[3,0],[0,2],[5,6],[3,6],[1,0],[6,3]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,1,1,0,1,1,1,1,0,1]\n\ntest_input = { \"n\": 9, \"edges\": [[8,0,4],[4,8,5],[1,8,1],[7,0,2],[2,7,4],[3,0,1],[6,0,1],[5,2,1]], \"queries\": [[4,4],[0,4],[3,4],[2,7],[0,0],[8,7],[8,6],[0,5],[6,6],[8,5]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,1,2,0,0,1,1,2,0,2]\n\ntest_input = { \"n\": 9, \"edges\": [[0,4,2],[5,4,3],[8,5,1],[2,5,5],[7,2,5],[1,0,5],[3,4,1],[6,2,5]], \"queries\": [[6,5],[8,1],[0,0],[1,4],[7,3],[8,6],[4,8],[1,0],[3,5]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,3,0,1,2,1,1,0,1]\n\ntest_input = { \"n\": 7, \"edges\": [[0,5,2],[2,5,5],[4,2,3],[3,5,2],[6,3,5],[1,3,4]], \"queries\": [[0,1],[3,4],[4,1],[4,2],[3,0],[4,5],[0,5],[3,2],[1,3]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,2,3,0,0,1,0,1,0]\n\ntest_input = { \"n\": 9, \"edges\": [[0,6,3],[1,0,1],[4,1,5],[3,1,4],[2,3,4],[5,6,2],[8,0,2],[7,5,4]], \"queries\": [[7,4],[3,8],[8,4],[2,1],[6,8],[1,4],[7,6],[4,1],[7,8],[5,2]] }\nassert my_solution.minOperationsQueries(**test_input) == [4,2,2,0,1,0,1,0,2,3]\n\ntest_input = { \"n\": 6, \"edges\": [[0,4,5],[1,0,3],[5,0,5],[2,1,3],[3,4,2]], \"queries\": [[1,2],[5,5],[4,3],[2,0],[5,1],[0,5],[5,3],[5,2]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,0,0,0,1,0,1,1]\n\ntest_input = { \"n\": 10, \"edges\": [[6,7,1],[5,7,1],[0,5,1],[8,7,2],[3,6,2],[4,8,2],[1,3,1],[2,6,4],[9,6,5]], \"queries\": [[0,7],[7,7],[4,3],[4,9],[9,8],[0,5],[9,1],[4,7],[9,4]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,0,1,2,2,0,2,0,2]\n\ntest_input = { \"n\": 4, \"edges\": [[3,0,5],[1,0,5],[2,0,5]], \"queries\": [[0,1],[1,2],[2,1],[3,1],[1,1],[3,0],[2,3]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,0,0,0,0,0,0]\n\ntest_input = { \"n\": 9, \"edges\": [[6,8,4],[7,6,2],[1,7,1],[4,6,4],[0,7,2],[5,4,5],[3,5,2],[2,0,5]], \"queries\": [[4,3],[6,4],[1,4],[2,2],[7,5],[1,3],[7,8],[0,8]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,0,2,0,2,3,1,1]\n\ntest_input = { \"n\": 8, \"edges\": [[5,3,1],[0,5,3],[1,5,2],[7,3,5],[4,0,2],[6,4,4],[2,0,1]], \"queries\": [[0,7],[2,7],[5,4],[4,6],[5,1],[0,2],[5,0],[5,6],[2,2],[1,6]] }\nassert my_solution.minOperationsQueries(**test_input) == [2,2,1,0,0,0,0,2,0,2]\n\ntest_input = { \"n\": 7, \"edges\": [[2,5,2],[6,2,1],[3,6,2],[1,5,1],[4,3,3],[0,2,2]], \"queries\": [[0,4],[2,1],[6,1],[5,4],[0,3],[6,4],[0,5],[3,2],[6,3]] }\nassert my_solution.minOperationsQueries(**test_input) == [2,1,1,2,1,1,0,1,0]\n\ntest_input = { \"n\": 7, \"edges\": [[2,3,5],[6,2,1],[0,3,4],[1,0,4],[5,1,1],[4,2,1]], \"queries\": [[4,4],[0,4],[3,4],[0,0],[1,1],[0,3],[0,6],[0,2],[3,3],[6,0]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,2,1,0,0,0,2,1,0,2]\n\ntest_input = { \"n\": 6, \"edges\": [[0,2,2],[4,2,1],[5,4,5],[1,0,4],[3,4,5]], \"queries\": [[0,4],[3,4],[3,1],[1,1],[5,4],[2,0],[2,2],[5,2]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,0,3,0,0,0,0,1]\n\ntest_input = { \"n\": 9, \"edges\": [[3,7,2],[1,7,3],[4,3,5],[6,4,3],[8,1,2],[5,1,2],[2,6,1],[0,5,2]], \"queries\": [[3,8],[2,4],[8,1],[6,8],[7,3],[3,0],[1,0],[8,2],[7,5],[8,5]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,1,0,3,0,1,0,4,1,0]\n\ntest_input = { \"n\": 9, \"edges\": [[1,4,3],[3,4,3],[8,4,4],[7,1,5],[2,7,3],[5,8,4],[6,7,4],[0,2,4]], \"queries\": [[4,4],[0,7],[1,8],[8,3],[3,3],[5,0],[7,6],[6,6],[2,5],[4,1]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,1,1,1,0,3,0,0,3,0]\n\ntest_input = { \"n\": 9, \"edges\": [[6,5,3],[3,5,3],[2,5,5],[1,5,2],[8,2,3],[7,6,3],[4,7,2],[0,7,4]], \"queries\": [[2,4],[8,1],[8,7],[6,1],[4,6],[0,3],[3,2],[3,0],[0,8],[3,5]] }\nassert my_solution.minOperationsQueries(**test_input) == [2,2,1,1,1,1,1,1,2,0]\n\ntest_input = { \"n\": 6, \"edges\": [[3,5,4],[4,3,5],[0,5,2],[1,4,3],[2,5,4]], \"queries\": [[1,2],[1,5],[5,4],[5,1],[1,4],[0,2],[0,5],[2,5],[1,3],[5,2]] }\nassert my_solution.minOperationsQueries(**test_input) == [2,2,1,2,0,1,0,0,1,0]\n\ntest_input = { \"n\": 5, \"edges\": [[3,0,1],[2,3,1],[4,2,1],[1,0,3]], \"queries\": [[4,0],[3,4],[4,3],[3,1],[2,0],[3,3],[3,2],[1,3]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,0,0,1,0,0,0,1]\n\ntest_input = { \"n\": 6, \"edges\": [[4,2,1],[3,4,4],[1,2,5],[5,2,3],[0,3,5]], \"queries\": [[5,5],[0,4],[3,1],[5,4],[0,3],[1,4],[0,5],[3,2],[2,5]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,1,2,1,0,1,3,1,0]\n\ntest_input = { \"n\": 6, \"edges\": [[3,5,2],[1,3,5],[2,3,4],[0,1,5],[4,1,3]], \"queries\": [[0,1],[1,1],[5,3],[5,1],[4,5],[0,2],[3,3],[0,5],[1,0],[3,5]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,0,0,1,2,1,0,1,0,0]\n\ntest_input = { \"n\": 7, \"edges\": [[2,3,3],[1,2,1],[0,3,5],[5,1,2],[6,5,4],[4,6,2]], \"queries\": [[6,2],[4,0],[0,4],[2,3],[0,2],[3,3],[5,0],[0,5],[1,3],[3,5]] }\nassert my_solution.minOperationsQueries(**test_input) == [2,4,4,0,1,0,3,3,1,2]\n\ntest_input = { \"n\": 7, \"edges\": [[2,5,1],[1,2,2],[3,2,4],[0,5,1],[4,5,1],[6,3,2]], \"queries\": [[2,4],[3,1],[0,3],[5,1],[4,2],[5,0],[2,2],[1,3]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,1,1,1,0,0,0,1]\n\ntest_input = { \"n\": 8, \"edges\": [[5,6,2],[7,6,1],[3,5,2],[1,6,3],[0,1,1],[4,6,5],[2,7,3]], \"queries\": [[6,2],[7,1],[7,7],[4,2],[3,0],[2,3],[7,6],[5,3],[7,5]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,1,0,2,2,2,0,0,1]\n\ntest_input = { \"n\": 5, \"edges\": [[3,1,5],[0,1,3],[2,3,5],[4,3,3]], \"queries\": [[0,1],[4,0],[0,4],[4,3],[0,3],[1,4],[0,2],[3,3],[2,2],[1,3]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,1,1,0,1,1,1,0,0,0]\n\ntest_input = { \"n\": 6, \"edges\": [[2,0,1],[1,0,1],[3,2,5],[5,2,4],[4,2,4]], \"queries\": [[2,4],[3,4],[0,0],[4,1],[0,3],[5,1],[0,2],[4,5],[0,5],[1,3]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,1,0,1,1,1,0,0,1,1]\n\ntest_input = { \"n\": 10, \"edges\": [[2,9,2],[5,2,3],[7,5,1],[0,5,1],[8,2,3],[4,9,3],[3,5,2],[1,0,4],[6,4,3]], \"queries\": [[9,3],[0,0],[9,9],[4,1],[9,6],[3,7],[4,2],[9,7],[5,2]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,0,0,3,0,1,1,2,0]\n\ntest_input = { \"n\": 5, \"edges\": [[4,0,4],[2,0,1],[3,0,4],[1,3,5]], \"queries\": [[3,4],[0,0],[3,1],[2,0],[2,3],[3,3],[1,3]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,0,0,0,1,0,0]\n\ntest_input = { \"n\": 8, \"edges\": [[5,3,2],[2,3,2],[0,5,4],[1,5,1],[4,0,3],[6,1,1],[7,3,3]], \"queries\": [[0,1],[5,5],[7,7],[2,1],[3,1],[4,6],[2,0],[7,6],[5,3],[7,5]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,0,0,1,1,2,1,2,0,1]\n\ntest_input = { \"n\": 5, \"edges\": [[0,3,1],[2,0,2],[1,3,2],[4,1,4]], \"queries\": [[0,4],[3,4],[0,0],[1,1],[2,0],[3,0],[2,3],[4,1]] }\nassert my_solution.minOperationsQueries(**test_input) == [2,1,0,0,0,0,1,0]\n\ntest_input = { \"n\": 5, \"edges\": [[3,4,3],[0,3,1],[1,4,3],[2,0,1]], \"queries\": [[0,1],[4,4],[4,0],[2,1],[4,3],[3,1],[0,2],[3,3],[1,3]] }\nassert my_solution.minOperationsQueries(**test_input) == [1,0,1,2,0,0,0,0,0]\n\ntest_input = { \"n\": 7, \"edges\": [[1,0,2],[4,1,5],[5,0,2],[6,5,3],[2,5,5],[3,4,3]], \"queries\": [[4,4],[2,4],[6,4],[1,4],[5,0],[5,6],[2,2],[1,3]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,2,2,0,0,0,0,1]\n\ntest_input = { \"n\": 9, \"edges\": [[6,8,1],[1,6,2],[0,8,2],[4,8,5],[3,4,4],[5,8,4],[2,5,2],[7,1,2]], \"queries\": [[0,0],[8,1],[8,3],[1,7],[2,6],[3,3],[0,5],[2,2],[7,5],[2,5]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,1,1,0,2,0,1,0,2,0]\n\ntest_input = { \"n\": 9, \"edges\": [[0,1,5],[8,1,4],[2,8,1],[3,2,1],[6,3,2],[4,2,3],[7,8,2],[5,2,3]], \"queries\": [[8,8],[6,2],[3,7],[1,8],[2,0],[1,4],[6,3],[7,8],[5,2]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,1,1,0,2,2,0,0,0]\n\ntest_input = { \"n\": 8, \"edges\": [[4,5,2],[7,4,2],[0,5,2],[6,0,1],[2,6,1],[3,2,1],[1,7,5]], \"queries\": [[4,4],[3,7],[4,6],[5,7],[3,0],[0,2],[1,7],[3,6],[4,7]] }\nassert my_solution.minOperationsQueries(**test_input) == [0,3,1,0,0,0,0,0,0]\n\ntest_input = { \"n\": 9, \"edges\": [[5,8,1],[4,8,2],[1,5,1],[7,8,5],[0,8,2],[6,1,5],[2,8,3],[3,1,2]], \"queries\": [[6,2],[2,7],[5,4],[1,8],[5,7],[3,0],[6,6],[0,8]] }\nassert my_solution.minOperationsQueries(**test_input) == [2,1,1,0,1,2,0,0]", "start_time": 1693708200} +{"task_id": "biweekly-contest-112-check-if-strings-can-be-made-equal-with-operations-i", "url": "https://leetcode.com/problems/check-if-strings-can-be-made-equal-with-operations-i", "title": "check-if-strings-can-be-made-equal-with-operations-i", "meta": {"questionId": "2999", "questionFrontendId": "2839", "title": "Check if Strings Can be Made Equal With Operations I", "titleSlug": "check-if-strings-can-be-made-equal-with-operations-i", "isPaidOnly": false, "difficulty": "Easy", "likes": 164, "dislikes": 20, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given two strings s1 and s2, both of length 4, consisting of lowercase English letters.\n\nYou can apply the following operation on any of the two strings any number of times:\n\n * Choose any two indices i and j such that j - i = 2, then swap the two characters at those indices in the string.\n\nReturn true if you can make the strings s1 and s2 equal, and false otherwise.\n\nExample 1:\n\nInput: s1 = \"abcd\", s2 = \"cdab\"\nOutput: true\nExplanation: We can do the following operations on s1:\n- Choose the indices i = 0, j = 2. The resulting string is s1 = \"cbad\".\n- Choose the indices i = 1, j = 3. The resulting string is s1 = \"cdab\" = s2.\n\nExample 2:\n\nInput: s1 = \"abcd\", s2 = \"dacb\"\nOutput: false\nExplanation: It is not possible to make the two strings equal.\n\n\nConstraints:\n\n * s1.length == s2.length == 4\n * s1 and s2 consist only of lowercase English letters.\n\"\"\"\nclass Solution:\n def canBeEqual(self, s1: str, s2: str) -> bool:\n ", "prompt_sft": "You are given two strings s1 and s2, both of length 4, consisting of lowercase English letters.\n\nYou can apply the following operation on any of the two strings any number of times:\n\n * Choose any two indices i and j such that j - i = 2, then swap the two characters at those indices in the string.\n\nReturn true if you can make the strings s1 and s2 equal, and false otherwise.\n\nExample 1:\n\nInput: s1 = \"abcd\", s2 = \"cdab\"\nOutput: true\nExplanation: We can do the following operations on s1:\n- Choose the indices i = 0, j = 2. The resulting string is s1 = \"cbad\".\n- Choose the indices i = 1, j = 3. The resulting string is s1 = \"cdab\" = s2.\n\nExample 2:\n\nInput: s1 = \"abcd\", s2 = \"dacb\"\nOutput: false\nExplanation: It is not possible to make the two strings equal.\n\n\nConstraints:\n\n * s1.length == s2.length == 4\n * s1 and s2 consist only of lowercase English letters.\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def canBeEqual(self, s1: str, s2: str) -> bool:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"s1\": \"abcd\", \"s2\": \"cdab\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"abcd\", \"s2\": \"dacb\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"gudo\", \"s2\": \"ogdu\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"bnxw\", \"s2\": \"bwxn\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"zzon\", \"s2\": \"zozn\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"cmpr\", \"s2\": \"rmcp\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"qnde\", \"s2\": \"flsi\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"vofo\", \"s2\": \"oofv\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"xsvc\", \"s2\": \"vcxs\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"hvsz\", \"s2\": \"hzsv\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"ifjz\", \"s2\": \"jzfi\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"zrmq\", \"s2\": \"mrzq\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"hazw\", \"s2\": \"pfmp\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"kina\", \"s2\": \"kina\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"fymg\", \"s2\": \"famj\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"riti\", \"s2\": \"riti\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"goze\", \"s2\": \"gezo\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"seeo\", \"s2\": \"vfvm\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"ybyd\", \"s2\": \"himj\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"gcdm\", \"s2\": \"dmgc\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"kvne\", \"s2\": \"nekv\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"cbyo\", \"s2\": \"cbyo\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"fezu\", \"s2\": \"zufe\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"homs\", \"s2\": \"fhdu\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"zlek\", \"s2\": \"zlek\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"bxqt\", \"s2\": \"xbtq\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"waso\", \"s2\": \"wyjd\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"nibi\", \"s2\": \"seua\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"oynw\", \"s2\": \"sgxl\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"ehui\", \"s2\": \"uhei\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"vchn\", \"s2\": \"jfwr\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"zgmt\", \"s2\": \"zgmt\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"eobz\", \"s2\": \"boez\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"zpzg\", \"s2\": \"zzpg\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"bbfp\", \"s2\": \"fbbp\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"vxqp\", \"s2\": \"xpvq\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"ihtv\", \"s2\": \"ixji\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"ahsk\", \"s2\": \"aksh\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"zexw\", \"s2\": \"miva\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"iicq\", \"s2\": \"ihda\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"kunv\", \"s2\": \"ziac\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"gqzd\", \"s2\": \"gqzd\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"ppeb\", \"s2\": \"ebpp\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"uouc\", \"s2\": \"ucuo\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"laxa\", \"s2\": \"xala\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"rbwe\", \"s2\": \"wbre\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"mswt\", \"s2\": \"wsmt\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"yfyz\", \"s2\": \"deyv\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"jlai\", \"s2\": \"alji\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"uliu\", \"s2\": \"bsmu\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"bhag\", \"s2\": \"kuws\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"bvwr\", \"s2\": \"wrbv\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"safs\", \"s2\": \"safs\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"hzfp\", \"s2\": \"hpfz\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"xide\", \"s2\": \"dixe\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"qpye\", \"s2\": \"qpye\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"zaus\", \"s2\": \"zsua\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"lpsc\", \"s2\": \"cslp\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"taxc\", \"s2\": \"taxc\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"kkjc\", \"s2\": \"kcjk\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"pshr\", \"s2\": \"prhs\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"kpdr\", \"s2\": \"djoe\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"vzla\", \"s2\": \"lzva\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"tcar\", \"s2\": \"tacr\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"zkyt\", \"s2\": \"yfzr\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"puwg\", \"s2\": \"pgwu\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"ownv\", \"s2\": \"ovnw\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"rayz\", \"s2\": \"bpnf\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"zbwg\", \"s2\": \"wbzg\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"rypk\", \"s2\": \"pyrk\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"qchw\", \"s2\": \"bcqn\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"qtpf\", \"s2\": \"qfpt\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"apnl\", \"s2\": \"nlap\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"pkmh\", \"s2\": \"mkph\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"ouxw\", \"s2\": \"xuow\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"dlgd\", \"s2\": \"gdld\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"xbcx\", \"s2\": \"cxxb\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"eaba\", \"s2\": \"uaul\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"fyro\", \"s2\": \"rofy\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"bzqb\", \"s2\": \"bzqb\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"zyjv\", \"s2\": \"xjzr\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"jdvv\", \"s2\": \"djvv\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"nyxb\", \"s2\": \"ocry\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"gxlx\", \"s2\": \"lxgx\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"kgkr\", \"s2\": \"krkg\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"edfw\", \"s2\": \"fdew\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"vxkq\", \"s2\": \"kqxv\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"qnjc\", \"s2\": \"jivc\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"zzaf\", \"s2\": \"azzf\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"esgr\", \"s2\": \"gres\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"meuu\", \"s2\": \"yqlh\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"gjda\", \"s2\": \"djga\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"qaqz\", \"s2\": \"qaqz\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"legy\", \"s2\": \"lyge\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"eeum\", \"s2\": \"emue\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"vsvs\", \"s2\": \"vsvs\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"mxlk\", \"s2\": \"mxlk\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"nbre\", \"s2\": \"renb\" }\nassert my_solution.canBeEqual(**test_input) == True\n\ntest_input = { \"s1\": \"erfk\", \"s2\": \"gmfy\" }\nassert my_solution.canBeEqual(**test_input) == False\n\ntest_input = { \"s1\": \"gsic\", \"s2\": \"snvs\" }\nassert my_solution.canBeEqual(**test_input) == False", "start_time": 1693665000} +{"task_id": "biweekly-contest-112-check-if-strings-can-be-made-equal-with-operations-ii", "url": "https://leetcode.com/problems/check-if-strings-can-be-made-equal-with-operations-ii", "title": "check-if-strings-can-be-made-equal-with-operations-ii", "meta": {"questionId": "2978", "questionFrontendId": "2840", "title": "Check if Strings Can be Made Equal With Operations II", "titleSlug": "check-if-strings-can-be-made-equal-with-operations-ii", "isPaidOnly": false, "difficulty": "Medium", "likes": 231, "dislikes": 2, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given two strings s1 and s2, both of length n, consisting of lowercase English letters.\n\nYou can apply the following operation on any of the two strings any number of times:\n\n * Choose any two indices i and j such that i < j and the difference j - i is even, then swap the two characters at those indices in the string.\n\nReturn true if you can make the strings s1 and s2 equal, and false otherwise.\n\nExample 1:\n\nInput: s1 = \"abcdba\", s2 = \"cabdab\"\nOutput: true\nExplanation: We can apply the following operations on s1:\n- Choose the indices i = 0, j = 2. The resulting string is s1 = \"cbadba\".\n- Choose the indices i = 2, j = 4. The resulting string is s1 = \"cbbdaa\".\n- Choose the indices i = 1, j = 5. The resulting string is s1 = \"cabdab\" = s2.\n\nExample 2:\n\nInput: s1 = \"abe\", s2 = \"bea\"\nOutput: false\nExplanation: It is not possible to make the two strings equal.\n\n\nConstraints:\n\n * n == s1.length == s2.length\n * 1 <= n <= 105\n * s1 and s2 consist only of lowercase English letters.\n\"\"\"\nclass Solution:\n def checkStrings(self, s1: str, s2: str) -> bool:\n ", "prompt_sft": "You are given two strings s1 and s2, both of length n, consisting of lowercase English letters.\n\nYou can apply the following operation on any of the two strings any number of times:\n\n * Choose any two indices i and j such that i < j and the difference j - i is even, then swap the two characters at those indices in the string.\n\nReturn true if you can make the strings s1 and s2 equal, and false otherwise.\n\nExample 1:\n\nInput: s1 = \"abcdba\", s2 = \"cabdab\"\nOutput: true\nExplanation: We can apply the following operations on s1:\n- Choose the indices i = 0, j = 2. The resulting string is s1 = \"cbadba\".\n- Choose the indices i = 2, j = 4. The resulting string is s1 = \"cbbdaa\".\n- Choose the indices i = 1, j = 5. The resulting string is s1 = \"cabdab\" = s2.\n\nExample 2:\n\nInput: s1 = \"abe\", s2 = \"bea\"\nOutput: false\nExplanation: It is not possible to make the two strings equal.\n\n\nConstraints:\n\n * n == s1.length == s2.length\n * 1 <= n <= 105\n * s1 and s2 consist only of lowercase English letters.\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def checkStrings(self, s1: str, s2: str) -> bool:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"s1\": \"abe\", \"s2\": \"bea\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"abcdba\", \"s2\": \"cabdab\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"ublnlasppynwgx\", \"s2\": \"ganplbuylnswpx\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"jghn\", \"s2\": \"jghn\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"pqtsprqmvi\", \"s2\": \"qrvqpitmps\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"aavizsxpqhxztrwi\", \"s2\": \"zvisqatzpaxhixwr\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"slmqqdbrwyvm\", \"s2\": \"qyldmmwsrqvb\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"shvqocguj\", \"s2\": \"vqsghujco\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"ktjpralqanofuuqsyal\", \"s2\": \"qjlornpasktfuyluaqa\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"mgflranpdjdkrh\", \"s2\": \"fpcgobmkdxbzyl\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"usvpwcehhvlg\", \"s2\": \"ehuvvshcwplg\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"jh\", \"s2\": \"fy\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"kfqofkvsoiiirznw\", \"s2\": \"hosthwbinxrsikkf\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"ppmfd\", \"s2\": \"pfdpm\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"ntuuwwh\", \"s2\": \"jyjwmdf\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"lcgcm\", \"s2\": \"brdxe\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"hjswnccgwjcapko\", \"s2\": \"acwjnjoscchgwpk\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"epjtzubboiallzd\", \"s2\": \"dboilpzzjteualb\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"c\", \"s2\": \"c\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"oziiqbotydegrm\", \"s2\": \"ytizriobogqmed\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"ztmuzn\", \"s2\": \"muztzn\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"jkzcqlh\", \"s2\": \"hkqczlj\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"qnh\", \"s2\": \"cmq\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"azagmtvhske\", \"s2\": \"mkazstvhage\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"jitb\", \"s2\": \"zqbg\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"tgznpamgczyvqjzvp\", \"s2\": \"mpyzvzzjvaqntgpgc\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"tcl\", \"s2\": \"lct\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"datuhdkoqe\", \"s2\": \"hetddokuqa\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"ztnpdilyrxz\", \"s2\": \"yxzitnrdlzp\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"vx\", \"s2\": \"zv\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"tpfcyceq\", \"s2\": \"fceqtpyc\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"rcugebinbszkhy\", \"s2\": \"zkebryhcbginus\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"ryykp\", \"s2\": \"rkpyy\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"lpyfmysemgoxgawwr\", \"s2\": \"wfoyspygralemxgwm\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"bfylavpyffcnj\", \"s2\": \"cljfbfyvpnayf\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"chhbmikpp\", \"s2\": \"hpcimbkhp\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"nateujd\", \"s2\": \"jeutnad\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"sxrjofoedghtplnex\", \"s2\": \"sgdeolnepthfojrxx\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"ajvfujrczdciilihi\", \"s2\": \"jcriaviuiflicdhzj\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"gajpuahzcexdunltldh\", \"s2\": \"xxatubgvqzmxjvzcxah\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"hnisnfvikgrhkfoe\", \"s2\": \"hgkivsifrekfonnh\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"fvfsxftpuemgpnkzz\", \"s2\": \"mgknxpuztffvzepsf\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"zrwzpibwp\", \"s2\": \"pwpiwzbrz\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"zoqpcssnhugxffcptsj\", \"s2\": \"chgospjssfxnfpcuqzt\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"ldpjhj\", \"s2\": \"jdlpjh\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"zodbh\", \"s2\": \"pqdpy\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"mdcvitezgqur\", \"s2\": \"mvigcqrdeztu\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"rdyau\", \"s2\": \"dyrau\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"pyymcw\", \"s2\": \"ptlqxp\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"ebicv\", \"s2\": \"vibce\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"xkzknvrbvajwbj\", \"s2\": \"rnkwzbvvxkjbja\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"zoxpiqxvnk\", \"s2\": \"xvkpxinqoz\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"obhmqltgmoszljeyh\", \"s2\": \"ogmmlbhoeysjtlhzq\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"wfsdirrheuglhfkbjk\", \"s2\": \"wfsuhhglifkrebrdjk\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"shn\", \"s2\": \"hsn\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"xdicugry\", \"s2\": \"igucxdry\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"bkfmkrbybim\", \"s2\": \"brbimkkmbyf\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"dwowyfgreakdvfi\", \"s2\": \"yfiddfvwerkaowg\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"bdywnvbgmum\", \"s2\": \"guymbwdbnmv\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"tmujoqerfvupnyy\", \"s2\": \"uvortyfmuqypnje\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"hggckwudke\", \"s2\": \"ylkgulkehd\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"zrppcm\", \"s2\": \"okurkg\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"ennl\", \"s2\": \"ennl\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"spznlxodciidngyvvkl\", \"s2\": \"lnvnzdixivoglydscpk\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"nxezcoklmdbekyjp\", \"s2\": \"cdkenlkyeomxjzbp\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"yui\", \"s2\": \"iyu\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"zphe\", \"s2\": \"hpze\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"oyjngnej\", \"s2\": \"oynjjeng\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"kvwdssgl\", \"s2\": \"wskxsdgv\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"ozzfbhzkowpcv\", \"s2\": \"vzpwzkbhzfoco\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"h\", \"s2\": \"h\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"mqkdv\", \"s2\": \"kqvdm\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"hphfqesitgprud\", \"s2\": \"tpisuhqhfgdrpe\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"yrbto\", \"s2\": \"orytb\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"lvahby\", \"s2\": \"ilbyaz\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"bbaiabphflgyfo\", \"s2\": \"bhglybaoaipbff\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"uielps\", \"s2\": \"uselpi\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"ftyhgkgwg\", \"s2\": \"gtfhgwgky\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"mzrfxrwlliuoi\", \"s2\": \"llrouzirwimfx\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"drofbzocwolcznzfi\", \"s2\": \"wzocdnirzfbclozfo\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"popefwbkepdxy\", \"s2\": \"pxbwpeekfoypd\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"swgzqluzcvhskegvdry\", \"s2\": \"seuwkvclqzyvdsgrgzh\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"hik\", \"s2\": \"ihk\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"zq\", \"s2\": \"zq\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"igdzd\", \"s2\": \"phcyi\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"cazutcxkhcklpuogt\", \"s2\": \"ockghuukctcztxapl\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"bx\", \"s2\": \"bx\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"bkujvjwgjzxdzuw\", \"s2\": \"zgjubjwkwzxdujv\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"ujpudt\", \"s2\": \"dtujpu\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"hkalpd\", \"s2\": \"hlpkad\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"kbcpjzadbv\", \"s2\": \"dsgzcapzao\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"rubbbf\", \"s2\": \"rbbubf\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"ybudbyrlmiddsxks\", \"s2\": \"nuyyabyisyptvdnb\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"wiijtcgqez\", \"s2\": \"ctqzwjgiei\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"bgalfvefwmhodexazkd\", \"s2\": \"fbgmdfholzakvxaweed\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"oxlphorosradotpshnt\", \"s2\": \"hdotpaoorosrlhtsxpn\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"mnvnzakjaymsxhojq\", \"s2\": \"oaxjoeanksmyqmglm\" }\nassert my_solution.checkStrings(**test_input) == False\n\ntest_input = { \"s1\": \"hsm\", \"s2\": \"hsm\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"qgloiyhewunm\", \"s2\": \"qehuwonmiylg\" }\nassert my_solution.checkStrings(**test_input) == True\n\ntest_input = { \"s1\": \"drdu\", \"s2\": \"dudr\" }\nassert my_solution.checkStrings(**test_input) == True", "start_time": 1693665000} +{"task_id": "biweekly-contest-112-maximum-sum-of-almost-unique-subarray", "url": "https://leetcode.com/problems/maximum-sum-of-almost-unique-subarray", "title": "maximum-sum-of-almost-unique-subarray", "meta": {"questionId": "2954", "questionFrontendId": "2841", "title": "Maximum Sum of Almost Unique Subarray", "titleSlug": "maximum-sum-of-almost-unique-subarray", "isPaidOnly": false, "difficulty": "Medium", "likes": 230, "dislikes": 133, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given an integer array nums and two positive integers m and k.\n\nReturn the maximum sum out of all almost unique subarrays of length k of nums. If no such subarray exists, return 0.\n\nA subarray of nums is almost unique if it contains at least m distinct elements.\n\nA subarray is a contiguous non-empty sequence of elements within an array.\n\nExample 1:\n\nInput: nums = [2,6,7,3,1,7], m = 3, k = 4\nOutput: 18\nExplanation: There are 3 almost unique subarrays of size k = 4. These subarrays are [2, 6, 7, 3], [6, 7, 3, 1], and [7, 3, 1, 7]. Among these subarrays, the one with the maximum sum is [2, 6, 7, 3] which has a sum of 18.\n\nExample 2:\n\nInput: nums = [5,9,9,2,4,5,4], m = 1, k = 3\nOutput: 23\nExplanation: There are 5 almost unique subarrays of size k. These subarrays are [5, 9, 9], [9, 9, 2], [9, 2, 4], [2, 4, 5], and [4, 5, 4]. Among these subarrays, the one with the maximum sum is [5, 9, 9] which has a sum of 23.\n\nExample 3:\n\nInput: nums = [1,2,1,2,1,2,1], m = 3, k = 3\nOutput: 0\nExplanation: There are no subarrays of size k = 3 that contain at least m = 3 distinct elements in the given array [1,2,1,2,1,2,1]. Therefore, no almost unique subarrays exist, and the maximum sum is 0.\n\n\nConstraints:\n\n * 1 <= nums.length <= 2 * 104\n * 1 <= m <= k <= nums.length\n * 1 <= nums[i] <= 109\n\"\"\"\nclass Solution:\n def maxSum(self, nums: List[int], m: int, k: int) -> int:\n ", "prompt_sft": "You are given an integer array nums and two positive integers m and k.\n\nReturn the maximum sum out of all almost unique subarrays of length k of nums. If no such subarray exists, return 0.\n\nA subarray of nums is almost unique if it contains at least m distinct elements.\n\nA subarray is a contiguous non-empty sequence of elements within an array.\n\nExample 1:\n\nInput: nums = [2,6,7,3,1,7], m = 3, k = 4\nOutput: 18\nExplanation: There are 3 almost unique subarrays of size k = 4. These subarrays are [2, 6, 7, 3], [6, 7, 3, 1], and [7, 3, 1, 7]. Among these subarrays, the one with the maximum sum is [2, 6, 7, 3] which has a sum of 18.\n\nExample 2:\n\nInput: nums = [5,9,9,2,4,5,4], m = 1, k = 3\nOutput: 23\nExplanation: There are 5 almost unique subarrays of size k. These subarrays are [5, 9, 9], [9, 9, 2], [9, 2, 4], [2, 4, 5], and [4, 5, 4]. Among these subarrays, the one with the maximum sum is [5, 9, 9] which has a sum of 23.\n\nExample 3:\n\nInput: nums = [1,2,1,2,1,2,1], m = 3, k = 3\nOutput: 0\nExplanation: There are no subarrays of size k = 3 that contain at least m = 3 distinct elements in the given array [1,2,1,2,1,2,1]. Therefore, no almost unique subarrays exist, and the maximum sum is 0.\n\n\nConstraints:\n\n * 1 <= nums.length <= 2 * 104\n * 1 <= m <= k <= nums.length\n * 1 <= nums[i] <= 109\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def maxSum(self, nums: List[int], m: int, k: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [2,6,7,3,1,7], \"m\": 3, \"k\": 4 }\nassert my_solution.maxSum(**test_input) == 18\n\ntest_input = { \"nums\": [5,9,9,2,4,5,4], \"m\": 1, \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 23\n\ntest_input = { \"nums\": [1,2,1,2,1,2,1], \"m\": 3, \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 0\n\ntest_input = { \"nums\": [1], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 1\n\ntest_input = { \"nums\": [1,1], \"m\": 2, \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,1], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,1,1], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,1,2], \"m\": 2, \"k\": 4 }\nassert my_solution.maxSum(**test_input) == 5\n\ntest_input = { \"nums\": [1,1,1,3], \"m\": 2, \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,1,1,4], \"m\": 2, \"k\": 4 }\nassert my_solution.maxSum(**test_input) == 7\n\ntest_input = { \"nums\": [1,1,2], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,2,1], \"m\": 2, \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,2,2], \"m\": 1, \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 5\n\ntest_input = { \"nums\": [1,1,2,3], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,2,4], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,1,3], \"m\": 1, \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,1,3,1], \"m\": 2, \"k\": 4 }\nassert my_solution.maxSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,1,3,2], \"m\": 1, \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 5\n\ntest_input = { \"nums\": [1,1,3,3], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,3,4], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,1,4], \"m\": 1, \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,1,4,1], \"m\": 1, \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,1,4,2], \"m\": 2, \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,1,4,3], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,1,4,4], \"m\": 3, \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 0\n\ntest_input = { \"nums\": [1,2], \"m\": 1, \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,1], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 2\n\ntest_input = { \"nums\": [1,2,1,1], \"m\": 1, \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,1,2], \"m\": 2, \"k\": 4 }\nassert my_solution.maxSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,2,1,3], \"m\": 1, \"k\": 4 }\nassert my_solution.maxSum(**test_input) == 7\n\ntest_input = { \"nums\": [1,2,1,4], \"m\": 2, \"k\": 4 }\nassert my_solution.maxSum(**test_input) == 8\n\ntest_input = { \"nums\": [1,2,2], \"m\": 2, \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,2,1], \"m\": 2, \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,2,2], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 2\n\ntest_input = { \"nums\": [1,2,2,3], \"m\": 3, \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 0\n\ntest_input = { \"nums\": [1,2,2,4], \"m\": 1, \"k\": 4 }\nassert my_solution.maxSum(**test_input) == 9\n\ntest_input = { \"nums\": [1,2,3], \"m\": 1, \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 5\n\ntest_input = { \"nums\": [1,2,3,1], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,3,2], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,3,3], \"m\": 2, \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 8\n\ntest_input = { \"nums\": [1,2,3,4], \"m\": 1, \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 7\n\ntest_input = { \"nums\": [1,2,4], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,4,1], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,4,2], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,4,3], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,4,4], \"m\": 1, \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 8\n\ntest_input = { \"nums\": [1,3], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 3\n\ntest_input = { \"nums\": [1,3,1], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 3\n\ntest_input = { \"nums\": [1,3,1,1], \"m\": 2, \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 5\n\ntest_input = { \"nums\": [1,3,1,2], \"m\": 4, \"k\": 4 }\nassert my_solution.maxSum(**test_input) == 0\n\ntest_input = { \"nums\": [1,3,1,3], \"m\": 2, \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,3,1,4], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,3,2], \"m\": 1, \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 5\n\ntest_input = { \"nums\": [1,3,2,1], \"m\": 2, \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 5\n\ntest_input = { \"nums\": [1,3,2,2], \"m\": 1, \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 5\n\ntest_input = { \"nums\": [1,3,2,3], \"m\": 1, \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 8\n\ntest_input = { \"nums\": [1,3,2,4], \"m\": 3, \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 9\n\ntest_input = { \"nums\": [1,3,3], \"m\": 2, \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 7\n\ntest_input = { \"nums\": [1,3,3,1], \"m\": 2, \"k\": 4 }\nassert my_solution.maxSum(**test_input) == 8\n\ntest_input = { \"nums\": [1,3,3,2], \"m\": 2, \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 8\n\ntest_input = { \"nums\": [1,3,3,3], \"m\": 1, \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,3,3,4], \"m\": 2, \"k\": 4 }\nassert my_solution.maxSum(**test_input) == 11\n\ntest_input = { \"nums\": [1,3,4], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,3,4,1], \"m\": 2, \"k\": 4 }\nassert my_solution.maxSum(**test_input) == 9\n\ntest_input = { \"nums\": [1,3,4,2], \"m\": 3, \"k\": 4 }\nassert my_solution.maxSum(**test_input) == 10\n\ntest_input = { \"nums\": [1,3,4,3], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,3,4,4], \"m\": 1, \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 8\n\ntest_input = { \"nums\": [1,4], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,4,1], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,4,1,1], \"m\": 1, \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,4,1,2], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,4,1,3], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,4,1,4], \"m\": 2, \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 9\n\ntest_input = { \"nums\": [1,4,2], \"m\": 3, \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 7\n\ntest_input = { \"nums\": [1,4,2,1], \"m\": 2, \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 6\n\ntest_input = { \"nums\": [1,4,2,2], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,4,2,3], \"m\": 3, \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 9\n\ntest_input = { \"nums\": [1,4,2,4], \"m\": 1, \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 10\n\ntest_input = { \"nums\": [1,4,3], \"m\": 3, \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 8\n\ntest_input = { \"nums\": [1,4,3,1], \"m\": 1, \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 7\n\ntest_input = { \"nums\": [1,4,3,2], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,4,3,3], \"m\": 2, \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 7\n\ntest_input = { \"nums\": [1,4,3,4], \"m\": 3, \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 8\n\ntest_input = { \"nums\": [1,4,4], \"m\": 2, \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 9\n\ntest_input = { \"nums\": [1,4,4,1], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 4\n\ntest_input = { \"nums\": [1,4,4,2], \"m\": 1, \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 8\n\ntest_input = { \"nums\": [1,4,4,3], \"m\": 3, \"k\": 4 }\nassert my_solution.maxSum(**test_input) == 12\n\ntest_input = { \"nums\": [1,4,4,4], \"m\": 3, \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 0\n\ntest_input = { \"nums\": [2], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 2\n\ntest_input = { \"nums\": [2,1], \"m\": 2, \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 3\n\ntest_input = { \"nums\": [2,1,1], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 2\n\ntest_input = { \"nums\": [2,1,1,1], \"m\": 4, \"k\": 4 }\nassert my_solution.maxSum(**test_input) == 0\n\ntest_input = { \"nums\": [2,1,1,2], \"m\": 2, \"k\": 4 }\nassert my_solution.maxSum(**test_input) == 6\n\ntest_input = { \"nums\": [2,1,1,3], \"m\": 3, \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 0\n\ntest_input = { \"nums\": [2,1,1,4], \"m\": 2, \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 5\n\ntest_input = { \"nums\": [2,1,2], \"m\": 1, \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 5\n\ntest_input = { \"nums\": [2,1,2,1], \"m\": 2, \"k\": 2 }\nassert my_solution.maxSum(**test_input) == 3\n\ntest_input = { \"nums\": [2,1,2,2], \"m\": 1, \"k\": 1 }\nassert my_solution.maxSum(**test_input) == 2\n\ntest_input = { \"nums\": [2,1,2,3], \"m\": 1, \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 6\n\ntest_input = { \"nums\": [2,1,2,4], \"m\": 1, \"k\": 3 }\nassert my_solution.maxSum(**test_input) == 7", "start_time": 1693665000} +{"task_id": "biweekly-contest-112-count-k-subsequences-of-a-string-with-maximum-beauty", "url": "https://leetcode.com/problems/count-k-subsequences-of-a-string-with-maximum-beauty", "title": "count-k-subsequences-of-a-string-with-maximum-beauty", "meta": {"questionId": "3057", "questionFrontendId": "2842", "title": "Count K-Subsequences of a String With Maximum Beauty", "titleSlug": "count-k-subsequences-of-a-string-with-maximum-beauty", "isPaidOnly": false, "difficulty": "Hard", "likes": 286, "dislikes": 21, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a string s and an integer k.\n\nA k-subsequence is a subsequence of s, having length k, and all its characters are unique, i.e., every character occurs once.\n\nLet f(c) denote the number of times the character c occurs in s.\n\nThe beauty of a k-subsequence is the sum of f(c) for every character c in the k-subsequence.\n\nFor example, consider s = \"abbbdd\" and k = 2:\n\n * f('a') = 1, f('b') = 3, f('d') = 2\n * Some k-subsequences of s are:\n * \"abbbdd\" -> \"ab\" having a beauty of f('a') + f('b') = 4\n * \"abbbdd\" -> \"ad\" having a beauty of f('a') + f('d') = 3\n * \"abbbdd\" -> \"bd\" having a beauty of f('b') + f('d') = 5\n\nReturn an integer denoting the number of k-subsequences whose beauty is the maximum among all k-subsequences. Since the answer may be too large, return it modulo 109 + 7.\n\nA subsequence of a string is a new string formed from the original string by deleting some (possibly none) of the characters without disturbing the relative positions of the remaining characters.\n\nNotes\n\n * f(c) is the number of times a character c occurs in s, not a k-subsequence.\n * Two k-subsequences are considered different if one is formed by an index that is not present in the other. So, two k-subsequences may form the same string.\n\nExample 1:\n\nInput: s = \"bcca\", k = 2\nOutput: 4\nExplanation: From s we have f('a') = 1, f('b') = 1, and f('c') = 2.\nThe k-subsequences of s are:\nbcca having a beauty of f('b') + f('c') = 3\nbcca having a beauty of f('b') + f('c') = 3\nbcca having a beauty of f('b') + f('a') = 2\nbcca having a beauty of f('c') + f('a') = 3\nbcca having a beauty of f('c') + f('a') = 3\nThere are 4 k-subsequences that have the maximum beauty, 3.\nHence, the answer is 4.\n\nExample 2:\n\nInput: s = \"abbcd\", k = 4\nOutput: 2\nExplanation: From s we have f('a') = 1, f('b') = 2, f('c') = 1, and f('d') = 1.\nThe k-subsequences of s are:\nabbcd having a beauty of f('a') + f('b') + f('c') + f('d') = 5\nabbcd having a beauty of f('a') + f('b') + f('c') + f('d') = 5\nThere are 2 k-subsequences that have the maximum beauty, 5.\nHence, the answer is 2.\n\n\nConstraints:\n\n * 1 <= s.length <= 2 * 105\n * 1 <= k <= s.length\n * s consists only of lowercase English letters.\n\"\"\"\nclass Solution:\n def countKSubsequencesWithMaxBeauty(self, s: str, k: int) -> int:\n ", "prompt_sft": "You are given a string s and an integer k.\n\nA k-subsequence is a subsequence of s, having length k, and all its characters are unique, i.e., every character occurs once.\n\nLet f(c) denote the number of times the character c occurs in s.\n\nThe beauty of a k-subsequence is the sum of f(c) for every character c in the k-subsequence.\n\nFor example, consider s = \"abbbdd\" and k = 2:\n\n * f('a') = 1, f('b') = 3, f('d') = 2\n * Some k-subsequences of s are:\n * \"abbbdd\" -> \"ab\" having a beauty of f('a') + f('b') = 4\n * \"abbbdd\" -> \"ad\" having a beauty of f('a') + f('d') = 3\n * \"abbbdd\" -> \"bd\" having a beauty of f('b') + f('d') = 5\n\nReturn an integer denoting the number of k-subsequences whose beauty is the maximum among all k-subsequences. Since the answer may be too large, return it modulo 109 + 7.\n\nA subsequence of a string is a new string formed from the original string by deleting some (possibly none) of the characters without disturbing the relative positions of the remaining characters.\n\nNotes\n\n * f(c) is the number of times a character c occurs in s, not a k-subsequence.\n * Two k-subsequences are considered different if one is formed by an index that is not present in the other. So, two k-subsequences may form the same string.\n\nExample 1:\n\nInput: s = \"bcca\", k = 2\nOutput: 4\nExplanation: From s we have f('a') = 1, f('b') = 1, and f('c') = 2.\nThe k-subsequences of s are:\nbcca having a beauty of f('b') + f('c') = 3\nbcca having a beauty of f('b') + f('c') = 3\nbcca having a beauty of f('b') + f('a') = 2\nbcca having a beauty of f('c') + f('a') = 3\nbcca having a beauty of f('c') + f('a') = 3\nThere are 4 k-subsequences that have the maximum beauty, 3.\nHence, the answer is 4.\n\nExample 2:\n\nInput: s = \"abbcd\", k = 4\nOutput: 2\nExplanation: From s we have f('a') = 1, f('b') = 2, f('c') = 1, and f('d') = 1.\nThe k-subsequences of s are:\nabbcd having a beauty of f('a') + f('b') + f('c') + f('d') = 5\nabbcd having a beauty of f('a') + f('b') + f('c') + f('d') = 5\nThere are 2 k-subsequences that have the maximum beauty, 5.\nHence, the answer is 2.\n\n\nConstraints:\n\n * 1 <= s.length <= 2 * 105\n * 1 <= k <= s.length\n * s consists only of lowercase English letters.\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def countKSubsequencesWithMaxBeauty(self, s: str, k: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"s\": \"bcca\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 4\n\ntest_input = { \"s\": \"abbcd\", \"k\": 4 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 2\n\ntest_input = { \"s\": \"am\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1\n\ntest_input = { \"s\": \"az\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1\n\ntest_input = { \"s\": \"ci\", \"k\": 1 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 2\n\ntest_input = { \"s\": \"dd\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 0\n\ntest_input = { \"s\": \"di\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1\n\ntest_input = { \"s\": \"dw\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1\n\ntest_input = { \"s\": \"ef\", \"k\": 1 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 2\n\ntest_input = { \"s\": \"gq\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1\n\ntest_input = { \"s\": \"hj\", \"k\": 1 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 2\n\ntest_input = { \"s\": \"hx\", \"k\": 1 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 2\n\ntest_input = { \"s\": \"ii\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 0\n\ntest_input = { \"s\": \"il\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1\n\ntest_input = { \"s\": \"jb\", \"k\": 1 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 2\n\ntest_input = { \"s\": \"kx\", \"k\": 1 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 2\n\ntest_input = { \"s\": \"qh\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1\n\ntest_input = { \"s\": \"qk\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1\n\ntest_input = { \"s\": \"qr\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1\n\ntest_input = { \"s\": \"rg\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1\n\ntest_input = { \"s\": \"rn\", \"k\": 1 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 2\n\ntest_input = { \"s\": \"st\", \"k\": 1 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 2\n\ntest_input = { \"s\": \"tb\", \"k\": 1 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 2\n\ntest_input = { \"s\": \"tl\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1\n\ntest_input = { \"s\": \"xc\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1\n\ntest_input = { \"s\": \"auy\", \"k\": 1 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 3\n\ntest_input = { \"s\": \"axm\", \"k\": 3 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1\n\ntest_input = { \"s\": \"dqc\", \"k\": 1 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 3\n\ntest_input = { \"s\": \"fkp\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 3\n\ntest_input = { \"s\": \"fmk\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 3\n\ntest_input = { \"s\": \"fvl\", \"k\": 3 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1\n\ntest_input = { \"s\": \"hcx\", \"k\": 3 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1\n\ntest_input = { \"s\": \"iua\", \"k\": 3 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1\n\ntest_input = { \"s\": \"kzb\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 3\n\ntest_input = { \"s\": \"mhb\", \"k\": 3 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1\n\ntest_input = { \"s\": \"nzo\", \"k\": 1 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 3\n\ntest_input = { \"s\": \"oof\", \"k\": 3 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 0\n\ntest_input = { \"s\": \"rfh\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 3\n\ntest_input = { \"s\": \"sty\", \"k\": 1 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 3\n\ntest_input = { \"s\": \"sue\", \"k\": 3 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1\n\ntest_input = { \"s\": \"tba\", \"k\": 3 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1\n\ntest_input = { \"s\": \"tmc\", \"k\": 1 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 3\n\ntest_input = { \"s\": \"wes\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 3\n\ntest_input = { \"s\": \"wvl\", \"k\": 1 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 3\n\ntest_input = { \"s\": \"xho\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 3\n\ntest_input = { \"s\": \"xke\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 3\n\ntest_input = { \"s\": \"ysu\", \"k\": 3 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1\n\ntest_input = { \"s\": \"yxn\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 3\n\ntest_input = { \"s\": \"zco\", \"k\": 1 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 3\n\ntest_input = { \"s\": \"zpq\", \"k\": 3 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1\n\ntest_input = { \"s\": \"axgn\", \"k\": 4 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1\n\ntest_input = { \"s\": \"dfyq\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 6\n\ntest_input = { \"s\": \"dogq\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 6\n\ntest_input = { \"s\": \"drbs\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 6\n\ntest_input = { \"s\": \"elex\", \"k\": 4 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 0\n\ntest_input = { \"s\": \"fsaj\", \"k\": 1 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 4\n\ntest_input = { \"s\": \"fxau\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 6\n\ntest_input = { \"s\": \"glbq\", \"k\": 4 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1\n\ntest_input = { \"s\": \"hzcj\", \"k\": 4 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1\n\ntest_input = { \"s\": \"minc\", \"k\": 3 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 4\n\ntest_input = { \"s\": \"nkim\", \"k\": 1 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 4\n\ntest_input = { \"s\": \"otpl\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 6\n\ntest_input = { \"s\": \"pvrz\", \"k\": 4 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1\n\ntest_input = { \"s\": \"qwmy\", \"k\": 4 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1\n\ntest_input = { \"s\": \"rliu\", \"k\": 4 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1\n\ntest_input = { \"s\": \"tpig\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 6\n\ntest_input = { \"s\": \"ucvh\", \"k\": 4 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1\n\ntest_input = { \"s\": \"vevt\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 4\n\ntest_input = { \"s\": \"xstt\", \"k\": 3 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 2\n\ntest_input = { \"s\": \"ypmv\", \"k\": 3 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 4\n\ntest_input = { \"s\": \"znoq\", \"k\": 3 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 4\n\ntest_input = { \"s\": \"bicnt\", \"k\": 1 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 5\n\ntest_input = { \"s\": \"bnhom\", \"k\": 5 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1\n\ntest_input = { \"s\": \"culhr\", \"k\": 5 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1\n\ntest_input = { \"s\": \"dpfki\", \"k\": 1 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 5\n\ntest_input = { \"s\": \"dscbu\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 10\n\ntest_input = { \"s\": \"edwlo\", \"k\": 3 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 10\n\ntest_input = { \"s\": \"ggsgo\", \"k\": 3 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 3\n\ntest_input = { \"s\": \"guzzf\", \"k\": 4 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 2\n\ntest_input = { \"s\": \"gzzzl\", \"k\": 3 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 3\n\ntest_input = { \"s\": \"kjojr\", \"k\": 3 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 6\n\ntest_input = { \"s\": \"kvsds\", \"k\": 5 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 0\n\ntest_input = { \"s\": \"ljdvp\", \"k\": 1 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 5\n\ntest_input = { \"s\": \"mdccc\", \"k\": 5 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 0\n\ntest_input = { \"s\": \"mmqny\", \"k\": 4 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 2\n\ntest_input = { \"s\": \"mrbrj\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 6\n\ntest_input = { \"s\": \"pwtbx\", \"k\": 4 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 5\n\ntest_input = { \"s\": \"qcxkr\", \"k\": 3 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 10\n\ntest_input = { \"s\": \"qvauy\", \"k\": 1 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 5\n\ntest_input = { \"s\": \"tzwoq\", \"k\": 3 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 10\n\ntest_input = { \"s\": \"ufxge\", \"k\": 4 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 5\n\ntest_input = { \"s\": \"unzxd\", \"k\": 4 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 5\n\ntest_input = { \"s\": \"vhqqj\", \"k\": 3 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 6\n\ntest_input = { \"s\": \"vnkbt\", \"k\": 1 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 5\n\ntest_input = { \"s\": \"wpbkz\", \"k\": 2 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 10\n\ntest_input = { \"s\": \"xdgvy\", \"k\": 1 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 5\n\ntest_input = { \"s\": \"yelem\", \"k\": 5 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 0\n\ntest_input = { \"s\": \"zwkhq\", \"k\": 3 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 10\n\ntest_input = { \"s\": \"anxnfi\", \"k\": 5 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 2\n\ntest_input = { \"s\": \"cfbyuf\", \"k\": 5 }\nassert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 2", "start_time": 1693665000} +{"task_id": "weekly-contest-360-furthest-point-from-origin", "url": "https://leetcode.com/problems/furthest-point-from-origin", "title": "furthest-point-from-origin", "meta": {"questionId": "3019", "questionFrontendId": "2833", "title": "Furthest Point From Origin", "titleSlug": "furthest-point-from-origin", "isPaidOnly": false, "difficulty": "Easy", "likes": 203, "dislikes": 29, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a string moves of length n consisting only of characters 'L', 'R', and '_'. The string represents your movement on a number line starting from the origin 0.\n\nIn the ith move, you can choose one of the following directions:\n\n * move to the left if moves[i] = 'L' or moves[i] = '_'\n * move to the right if moves[i] = 'R' or moves[i] = '_'\n\nReturn the distance from the origin of the furthest point you can get to after n moves.\n\nExample 1:\n\nInput: moves = \"L_RL__R\"\nOutput: 3\nExplanation: The furthest point we can reach from the origin 0 is point -3 through the following sequence of moves \"LLRLLLR\".\n\nExample 2:\n\nInput: moves = \"_R__LL_\"\nOutput: 5\nExplanation: The furthest point we can reach from the origin 0 is point -5 through the following sequence of moves \"LRLLLLL\".\n\nExample 3:\n\nInput: moves = \"_______\"\nOutput: 7\nExplanation: The furthest point we can reach from the origin 0 is point 7 through the following sequence of moves \"RRRRRRR\".\n\n\nConstraints:\n\n * 1 <= moves.length == n <= 50\n * moves consists only of characters 'L', 'R' and '_'.\n\"\"\"\nclass Solution:\n def furthestDistanceFromOrigin(self, moves: str) -> int:\n ", "prompt_sft": "You are given a string moves of length n consisting only of characters 'L', 'R', and '_'. The string represents your movement on a number line starting from the origin 0.\n\nIn the ith move, you can choose one of the following directions:\n\n * move to the left if moves[i] = 'L' or moves[i] = '_'\n * move to the right if moves[i] = 'R' or moves[i] = '_'\n\nReturn the distance from the origin of the furthest point you can get to after n moves.\n\nExample 1:\n\nInput: moves = \"L_RL__R\"\nOutput: 3\nExplanation: The furthest point we can reach from the origin 0 is point -3 through the following sequence of moves \"LLRLLLR\".\n\nExample 2:\n\nInput: moves = \"_R__LL_\"\nOutput: 5\nExplanation: The furthest point we can reach from the origin 0 is point -5 through the following sequence of moves \"LRLLLLL\".\n\nExample 3:\n\nInput: moves = \"_______\"\nOutput: 7\nExplanation: The furthest point we can reach from the origin 0 is point 7 through the following sequence of moves \"RRRRRRR\".\n\n\nConstraints:\n\n * 1 <= moves.length == n <= 50\n * moves consists only of characters 'L', 'R' and '_'.\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def furthestDistanceFromOrigin(self, moves: str) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"moves\": \"L_RL__R\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 3\n\ntest_input = { \"moves\": \"_R__LL_\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 5\n\ntest_input = { \"moves\": \"_______\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 7\n\ntest_input = { \"moves\": \"L\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 1\n\ntest_input = { \"moves\": \"R\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 1\n\ntest_input = { \"moves\": \"_\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 1\n\ntest_input = { \"moves\": \"LL\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"LR\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 0\n\ntest_input = { \"moves\": \"L_\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"RL\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 0\n\ntest_input = { \"moves\": \"RR\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"R_\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"_L\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"_R\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"__\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"LLL\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 3\n\ntest_input = { \"moves\": \"LLR\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 1\n\ntest_input = { \"moves\": \"LL_\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 3\n\ntest_input = { \"moves\": \"LRL\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 1\n\ntest_input = { \"moves\": \"LRR\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 1\n\ntest_input = { \"moves\": \"LR_\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 1\n\ntest_input = { \"moves\": \"L_L\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 3\n\ntest_input = { \"moves\": \"L_R\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 1\n\ntest_input = { \"moves\": \"L__\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 3\n\ntest_input = { \"moves\": \"RLL\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 1\n\ntest_input = { \"moves\": \"RLR\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 1\n\ntest_input = { \"moves\": \"RL_\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 1\n\ntest_input = { \"moves\": \"RRL\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 1\n\ntest_input = { \"moves\": \"RRR\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 3\n\ntest_input = { \"moves\": \"RR_\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 3\n\ntest_input = { \"moves\": \"R_L\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 1\n\ntest_input = { \"moves\": \"R_R\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 3\n\ntest_input = { \"moves\": \"R__\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 3\n\ntest_input = { \"moves\": \"_LL\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 3\n\ntest_input = { \"moves\": \"_LR\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 1\n\ntest_input = { \"moves\": \"_L_\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 3\n\ntest_input = { \"moves\": \"_RL\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 1\n\ntest_input = { \"moves\": \"_RR\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 3\n\ntest_input = { \"moves\": \"_R_\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 3\n\ntest_input = { \"moves\": \"__L\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 3\n\ntest_input = { \"moves\": \"__R\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 3\n\ntest_input = { \"moves\": \"___\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 3\n\ntest_input = { \"moves\": \"LLLL\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 4\n\ntest_input = { \"moves\": \"LLLR\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"LLL_\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 4\n\ntest_input = { \"moves\": \"LLRL\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"LLRR\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 0\n\ntest_input = { \"moves\": \"LLR_\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"LL_L\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 4\n\ntest_input = { \"moves\": \"LL_R\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"LL__\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 4\n\ntest_input = { \"moves\": \"LRLL\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"LRLR\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 0\n\ntest_input = { \"moves\": \"LRL_\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"LRRL\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 0\n\ntest_input = { \"moves\": \"LRRR\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"LRR_\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"LR_L\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"LR_R\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"LR__\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"L_LL\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 4\n\ntest_input = { \"moves\": \"L_LR\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"L_L_\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 4\n\ntest_input = { \"moves\": \"L_RL\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"L_RR\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"L_R_\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"L__L\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 4\n\ntest_input = { \"moves\": \"L__R\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"L___\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 4\n\ntest_input = { \"moves\": \"RLLL\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"RLLR\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 0\n\ntest_input = { \"moves\": \"RLL_\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"RLRL\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 0\n\ntest_input = { \"moves\": \"RLRR\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"RLR_\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"RL_L\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"RL_R\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"RL__\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"RRLL\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 0\n\ntest_input = { \"moves\": \"RRLR\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"RRL_\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"RRRL\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"RRRR\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 4\n\ntest_input = { \"moves\": \"RRR_\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 4\n\ntest_input = { \"moves\": \"RR_L\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"RR_R\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 4\n\ntest_input = { \"moves\": \"RR__\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 4\n\ntest_input = { \"moves\": \"R_LL\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"R_LR\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"R_L_\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"R_RL\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"R_RR\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 4\n\ntest_input = { \"moves\": \"R_R_\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 4\n\ntest_input = { \"moves\": \"R__L\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"R__R\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 4\n\ntest_input = { \"moves\": \"R___\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 4\n\ntest_input = { \"moves\": \"_LLL\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 4\n\ntest_input = { \"moves\": \"_LLR\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2\n\ntest_input = { \"moves\": \"_LL_\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 4\n\ntest_input = { \"moves\": \"_LRL\" }\nassert my_solution.furthestDistanceFromOrigin(**test_input) == 2", "start_time": 1693103400} +{"task_id": "weekly-contest-360-find-the-minimum-possible-sum-of-a-beautiful-array", "url": "https://leetcode.com/problems/find-the-minimum-possible-sum-of-a-beautiful-array", "title": "find-the-minimum-possible-sum-of-a-beautiful-array", "meta": {"questionId": "3026", "questionFrontendId": "2834", "title": "Find the Minimum Possible Sum of a Beautiful Array", "titleSlug": "find-the-minimum-possible-sum-of-a-beautiful-array", "isPaidOnly": false, "difficulty": "Medium", "likes": 276, "dislikes": 37, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given positive integers n and target.\n\nAn array nums is beautiful if it meets the following conditions:\n\n * nums.length == n.\n * nums consists of pairwise distinct positive integers.\n * There doesn't exist two distinct indices, i and j, in the range [0, n - 1], such that nums[i] + nums[j] == target.\n\nReturn the minimum possible sum that a beautiful array could have modulo 109 + 7.\n\nExample 1:\n\nInput: n = 2, target = 3\nOutput: 4\nExplanation: We can see that nums = [1,3] is beautiful.\n- The array nums has length n = 2.\n- The array nums consists of pairwise distinct positive integers.\n- There doesn't exist two distinct indices, i and j, with nums[i] + nums[j] == 3.\nIt can be proven that 4 is the minimum possible sum that a beautiful array could have.\n\nExample 2:\n\nInput: n = 3, target = 3\nOutput: 8\nExplanation: We can see that nums = [1,3,4] is beautiful.\n- The array nums has length n = 3.\n- The array nums consists of pairwise distinct positive integers.\n- There doesn't exist two distinct indices, i and j, with nums[i] + nums[j] == 3.\nIt can be proven that 8 is the minimum possible sum that a beautiful array could have.\n\nExample 3:\n\nInput: n = 1, target = 1\nOutput: 1\nExplanation: We can see, that nums = [1] is beautiful.\n\n\nConstraints:\n\n * 1 <= n <= 109\n * 1 <= target <= 109\n\"\"\"\nclass Solution:\n def minimumPossibleSum(self, n: int, target: int) -> int:\n ", "prompt_sft": "You are given positive integers n and target.\n\nAn array nums is beautiful if it meets the following conditions:\n\n * nums.length == n.\n * nums consists of pairwise distinct positive integers.\n * There doesn't exist two distinct indices, i and j, in the range [0, n - 1], such that nums[i] + nums[j] == target.\n\nReturn the minimum possible sum that a beautiful array could have modulo 109 + 7.\n\nExample 1:\n\nInput: n = 2, target = 3\nOutput: 4\nExplanation: We can see that nums = [1,3] is beautiful.\n- The array nums has length n = 2.\n- The array nums consists of pairwise distinct positive integers.\n- There doesn't exist two distinct indices, i and j, with nums[i] + nums[j] == 3.\nIt can be proven that 4 is the minimum possible sum that a beautiful array could have.\n\nExample 2:\n\nInput: n = 3, target = 3\nOutput: 8\nExplanation: We can see that nums = [1,3,4] is beautiful.\n- The array nums has length n = 3.\n- The array nums consists of pairwise distinct positive integers.\n- There doesn't exist two distinct indices, i and j, with nums[i] + nums[j] == 3.\nIt can be proven that 8 is the minimum possible sum that a beautiful array could have.\n\nExample 3:\n\nInput: n = 1, target = 1\nOutput: 1\nExplanation: We can see, that nums = [1] is beautiful.\n\n\nConstraints:\n\n * 1 <= n <= 109\n * 1 <= target <= 109\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def minimumPossibleSum(self, n: int, target: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"n\": 2, \"target\": 3 }\nassert my_solution.minimumPossibleSum(**test_input) == 4\n\ntest_input = { \"n\": 3, \"target\": 3 }\nassert my_solution.minimumPossibleSum(**test_input) == 8\n\ntest_input = { \"n\": 1, \"target\": 1 }\nassert my_solution.minimumPossibleSum(**test_input) == 1\n\ntest_input = { \"n\": 16, \"target\": 6 }\nassert my_solution.minimumPossibleSum(**test_input) == 162\n\ntest_input = { \"n\": 16, \"target\": 32 }\nassert my_solution.minimumPossibleSum(**test_input) == 136\n\ntest_input = { \"n\": 13, \"target\": 50 }\nassert my_solution.minimumPossibleSum(**test_input) == 91\n\ntest_input = { \"n\": 36, \"target\": 21 }\nassert my_solution.minimumPossibleSum(**test_input) == 926\n\ntest_input = { \"n\": 40, \"target\": 17 }\nassert my_solution.minimumPossibleSum(**test_input) == 1076\n\ntest_input = { \"n\": 37, \"target\": 46 }\nassert my_solution.minimumPossibleSum(**test_input) == 1011\n\ntest_input = { \"n\": 33, \"target\": 7 }\nassert my_solution.minimumPossibleSum(**test_input) == 651\n\ntest_input = { \"n\": 42, \"target\": 46 }\nassert my_solution.minimumPossibleSum(**test_input) == 1321\n\ntest_input = { \"n\": 46, \"target\": 29 }\nassert my_solution.minimumPossibleSum(**test_input) == 1529\n\ntest_input = { \"n\": 9, \"target\": 43 }\nassert my_solution.minimumPossibleSum(**test_input) == 45\n\ntest_input = { \"n\": 30, \"target\": 31 }\nassert my_solution.minimumPossibleSum(**test_input) == 690\n\ntest_input = { \"n\": 14, \"target\": 47 }\nassert my_solution.minimumPossibleSum(**test_input) == 105\n\ntest_input = { \"n\": 5, \"target\": 3 }\nassert my_solution.minimumPossibleSum(**test_input) == 19\n\ntest_input = { \"n\": 41, \"target\": 23 }\nassert my_solution.minimumPossibleSum(**test_input) == 1191\n\ntest_input = { \"n\": 17, \"target\": 13 }\nassert my_solution.minimumPossibleSum(**test_input) == 219\n\ntest_input = { \"n\": 9, \"target\": 13 }\nassert my_solution.minimumPossibleSum(**test_input) == 63\n\ntest_input = { \"n\": 29, \"target\": 18 }\nassert my_solution.minimumPossibleSum(**test_input) == 595\n\ntest_input = { \"n\": 21, \"target\": 14 }\nassert my_solution.minimumPossibleSum(**test_input) == 315\n\ntest_input = { \"n\": 4, \"target\": 6 }\nassert my_solution.minimumPossibleSum(**test_input) == 12\n\ntest_input = { \"n\": 38, \"target\": 15 }\nassert my_solution.minimumPossibleSum(**test_input) == 958\n\ntest_input = { \"n\": 14, \"target\": 7 }\nassert my_solution.minimumPossibleSum(**test_input) == 138\n\ntest_input = { \"n\": 18, \"target\": 26 }\nassert my_solution.minimumPossibleSum(**test_input) == 231\n\ntest_input = { \"n\": 11, \"target\": 15 }\nassert my_solution.minimumPossibleSum(**test_input) == 94\n\ntest_input = { \"n\": 7, \"target\": 8 }\nassert my_solution.minimumPossibleSum(**test_input) == 37\n\ntest_input = { \"n\": 11, \"target\": 22 }\nassert my_solution.minimumPossibleSum(**test_input) == 66\n\ntest_input = { \"n\": 36, \"target\": 11 }\nassert my_solution.minimumPossibleSum(**test_input) == 821\n\ntest_input = { \"n\": 18, \"target\": 29 }\nassert my_solution.minimumPossibleSum(**test_input) == 227\n\ntest_input = { \"n\": 26, \"target\": 17 }\nassert my_solution.minimumPossibleSum(**test_input) == 495\n\ntest_input = { \"n\": 37, \"target\": 13 }\nassert my_solution.minimumPossibleSum(**test_input) == 889\n\ntest_input = { \"n\": 46, \"target\": 38 }\nassert my_solution.minimumPossibleSum(**test_input) == 1567\n\ntest_input = { \"n\": 13, \"target\": 7 }\nassert my_solution.minimumPossibleSum(**test_input) == 121\n\ntest_input = { \"n\": 33, \"target\": 34 }\nassert my_solution.minimumPossibleSum(**test_input) == 817\n\ntest_input = { \"n\": 39, \"target\": 12 }\nassert my_solution.minimumPossibleSum(**test_input) == 945\n\ntest_input = { \"n\": 1, \"target\": 45 }\nassert my_solution.minimumPossibleSum(**test_input) == 1\n\ntest_input = { \"n\": 37, \"target\": 36 }\nassert my_solution.minimumPossibleSum(**test_input) == 1026\n\ntest_input = { \"n\": 16, \"target\": 19 }\nassert my_solution.minimumPossibleSum(**test_input) == 199\n\ntest_input = { \"n\": 22, \"target\": 15 }\nassert my_solution.minimumPossibleSum(**test_input) == 358\n\ntest_input = { \"n\": 34, \"target\": 42 }\nassert my_solution.minimumPossibleSum(**test_input) == 855\n\ntest_input = { \"n\": 50, \"target\": 22 }\nassert my_solution.minimumPossibleSum(**test_input) == 1665\n\ntest_input = { \"n\": 42, \"target\": 44 }\nassert my_solution.minimumPossibleSum(**test_input) == 1323\n\ntest_input = { \"n\": 40, \"target\": 8 }\nassert my_solution.minimumPossibleSum(**test_input) == 928\n\ntest_input = { \"n\": 7, \"target\": 19 }\nassert my_solution.minimumPossibleSum(**test_input) == 28\n\ntest_input = { \"n\": 44, \"target\": 10 }\nassert my_solution.minimumPossibleSum(**test_input) == 1146\n\ntest_input = { \"n\": 21, \"target\": 6 }\nassert my_solution.minimumPossibleSum(**test_input) == 267\n\ntest_input = { \"n\": 27, \"target\": 26 }\nassert my_solution.minimumPossibleSum(**test_input) == 546\n\ntest_input = { \"n\": 49, \"target\": 4 }\nassert my_solution.minimumPossibleSum(**test_input) == 1272\n\ntest_input = { \"n\": 35, \"target\": 2 }\nassert my_solution.minimumPossibleSum(**test_input) == 630\n\ntest_input = { \"n\": 32, \"target\": 29 }\nassert my_solution.minimumPossibleSum(**test_input) == 780\n\ntest_input = { \"n\": 20, \"target\": 41 }\nassert my_solution.minimumPossibleSum(**test_input) == 210\n\ntest_input = { \"n\": 30, \"target\": 48 }\nassert my_solution.minimumPossibleSum(**test_input) == 603\n\ntest_input = { \"n\": 12, \"target\": 34 }\nassert my_solution.minimumPossibleSum(**test_input) == 78\n\ntest_input = { \"n\": 50, \"target\": 44 }\nassert my_solution.minimumPossibleSum(**test_input) == 1863\n\ntest_input = { \"n\": 42, \"target\": 26 }\nassert my_solution.minimumPossibleSum(**test_input) == 1251\n\ntest_input = { \"n\": 3, \"target\": 18 }\nassert my_solution.minimumPossibleSum(**test_input) == 6\n\ntest_input = { \"n\": 11, \"target\": 3 }\nassert my_solution.minimumPossibleSum(**test_input) == 76\n\ntest_input = { \"n\": 38, \"target\": 29 }\nassert my_solution.minimumPossibleSum(**test_input) == 1077\n\ntest_input = { \"n\": 17, \"target\": 24 }\nassert my_solution.minimumPossibleSum(**test_input) == 208\n\ntest_input = { \"n\": 50, \"target\": 31 }\nassert my_solution.minimumPossibleSum(**test_input) == 1800\n\ntest_input = { \"n\": 32, \"target\": 41 }\nassert my_solution.minimumPossibleSum(**test_input) == 768\n\ntest_input = { \"n\": 12, \"target\": 24 }\nassert my_solution.minimumPossibleSum(**test_input) == 78\n\ntest_input = { \"n\": 35, \"target\": 43 }\nassert my_solution.minimumPossibleSum(**test_input) == 924\n\ntest_input = { \"n\": 9, \"target\": 47 }\nassert my_solution.minimumPossibleSum(**test_input) == 45\n\ntest_input = { \"n\": 32, \"target\": 26 }\nassert my_solution.minimumPossibleSum(**test_input) == 756\n\ntest_input = { \"n\": 6, \"target\": 42 }\nassert my_solution.minimumPossibleSum(**test_input) == 21\n\ntest_input = { \"n\": 11, \"target\": 1 }\nassert my_solution.minimumPossibleSum(**test_input) == 66\n\ntest_input = { \"n\": 11, \"target\": 24 }\nassert my_solution.minimumPossibleSum(**test_input) == 66\n\ntest_input = { \"n\": 39, \"target\": 38 }\nassert my_solution.minimumPossibleSum(**test_input) == 1140\n\ntest_input = { \"n\": 18, \"target\": 8 }\nassert my_solution.minimumPossibleSum(**test_input) == 213\n\ntest_input = { \"n\": 29, \"target\": 5 }\nassert my_solution.minimumPossibleSum(**test_input) == 489\n\ntest_input = { \"n\": 44, \"target\": 6 }\nassert my_solution.minimumPossibleSum(**test_input) == 1072\n\ntest_input = { \"n\": 29, \"target\": 30 }\nassert my_solution.minimumPossibleSum(**test_input) == 631\n\ntest_input = { \"n\": 13, \"target\": 47 }\nassert my_solution.minimumPossibleSum(**test_input) == 91\n\ntest_input = { \"n\": 46, \"target\": 21 }\nassert my_solution.minimumPossibleSum(**test_input) == 1441\n\ntest_input = { \"n\": 46, \"target\": 6 }\nassert my_solution.minimumPossibleSum(**test_input) == 1167\n\ntest_input = { \"n\": 27, \"target\": 30 }\nassert my_solution.minimumPossibleSum(**test_input) == 546\n\ntest_input = { \"n\": 5, \"target\": 35 }\nassert my_solution.minimumPossibleSum(**test_input) == 15\n\ntest_input = { \"n\": 12, \"target\": 32 }\nassert my_solution.minimumPossibleSum(**test_input) == 78\n\ntest_input = { \"n\": 13, \"target\": 39 }\nassert my_solution.minimumPossibleSum(**test_input) == 91\n\ntest_input = { \"n\": 10, \"target\": 11 }\nassert my_solution.minimumPossibleSum(**test_input) == 80\n\ntest_input = { \"n\": 46, \"target\": 14 }\nassert my_solution.minimumPossibleSum(**test_input) == 1315\n\ntest_input = { \"n\": 37, \"target\": 18 }\nassert my_solution.minimumPossibleSum(**test_input) == 927\n\ntest_input = { \"n\": 32, \"target\": 8 }\nassert my_solution.minimumPossibleSum(**test_input) == 612\n\ntest_input = { \"n\": 26, \"target\": 14 }\nassert my_solution.minimumPossibleSum(**test_input) == 465\n\ntest_input = { \"n\": 33, \"target\": 41 }\nassert my_solution.minimumPossibleSum(**test_input) == 821\n\ntest_input = { \"n\": 44, \"target\": 39 }\nassert my_solution.minimumPossibleSum(**test_input) == 1465\n\ntest_input = { \"n\": 3, \"target\": 21 }\nassert my_solution.minimumPossibleSum(**test_input) == 6\n\ntest_input = { \"n\": 9, \"target\": 11 }\nassert my_solution.minimumPossibleSum(**test_input) == 65\n\ntest_input = { \"n\": 16, \"target\": 43 }\nassert my_solution.minimumPossibleSum(**test_input) == 136\n\ntest_input = { \"n\": 7, \"target\": 22 }\nassert my_solution.minimumPossibleSum(**test_input) == 28\n\ntest_input = { \"n\": 21, \"target\": 49 }\nassert my_solution.minimumPossibleSum(**test_input) == 231\n\ntest_input = { \"n\": 23, \"target\": 16 }\nassert my_solution.minimumPossibleSum(**test_input) == 381\n\ntest_input = { \"n\": 33, \"target\": 32 }\nassert my_solution.minimumPossibleSum(**test_input) == 816\n\ntest_input = { \"n\": 22, \"target\": 1 }\nassert my_solution.minimumPossibleSum(**test_input) == 253\n\ntest_input = { \"n\": 5, \"target\": 47 }\nassert my_solution.minimumPossibleSum(**test_input) == 15\n\ntest_input = { \"n\": 38, \"target\": 7 }\nassert my_solution.minimumPossibleSum(**test_input) == 846\n\ntest_input = { \"n\": 38, \"target\": 24 }\nassert my_solution.minimumPossibleSum(**test_input) == 1027\n\ntest_input = { \"n\": 13, \"target\": 36 }\nassert my_solution.minimumPossibleSum(**test_input) == 91", "start_time": 1693103400} +{"task_id": "weekly-contest-360-minimum-operations-to-form-subsequence-with-target-sum", "url": "https://leetcode.com/problems/minimum-operations-to-form-subsequence-with-target-sum", "title": "minimum-operations-to-form-subsequence-with-target-sum", "meta": {"questionId": "3025", "questionFrontendId": "2835", "title": "Minimum Operations to Form Subsequence With Target Sum", "titleSlug": "minimum-operations-to-form-subsequence-with-target-sum", "isPaidOnly": false, "difficulty": "Hard", "likes": 503, "dislikes": 125, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed array nums consisting of non-negative powers of 2, and an integer target.\n\nIn one operation, you must apply the following changes to the array:\n\n * Choose any element of the array nums[i] such that nums[i] > 1.\n * Remove nums[i] from the array.\n * Add two occurrences of nums[i] / 2 to the end of nums.\n\nReturn the minimum number of operations you need to perform so that nums contains a subsequence whose elements sum to target. If it is impossible to obtain such a subsequence, return -1.\n\nA subsequence is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining elements.\n\nExample 1:\n\nInput: nums = [1,2,8], target = 7\nOutput: 1\nExplanation: In the first operation, we choose element nums[2]. The array becomes equal to nums = [1,2,4,4].\nAt this stage, nums contains the subsequence [1,2,4] which sums up to 7.\nIt can be shown that there is no shorter sequence of operations that results in a subsequnce that sums up to 7.\n\nExample 2:\n\nInput: nums = [1,32,1,2], target = 12\nOutput: 2\nExplanation: In the first operation, we choose element nums[1]. The array becomes equal to nums = [1,1,2,16,16].\nIn the second operation, we choose element nums[3]. The array becomes equal to nums = [1,1,2,16,8,8]\nAt this stage, nums contains the subsequence [1,1,2,8] which sums up to 12.\nIt can be shown that there is no shorter sequence of operations that results in a subsequence that sums up to 12.\n\nExample 3:\n\nInput: nums = [1,32,1], target = 35\nOutput: -1\nExplanation: It can be shown that no sequence of operations results in a subsequence that sums up to 35.\n\n\nConstraints:\n\n * 1 <= nums.length <= 1000\n * 1 <= nums[i] <= 230\n * nums consists only of non-negative powers of two.\n * 1 <= target < 231\n\"\"\"\nclass Solution:\n def minOperations(self, nums: List[int], target: int) -> int:\n ", "prompt_sft": "You are given a 0-indexed array nums consisting of non-negative powers of 2, and an integer target.\n\nIn one operation, you must apply the following changes to the array:\n\n * Choose any element of the array nums[i] such that nums[i] > 1.\n * Remove nums[i] from the array.\n * Add two occurrences of nums[i] / 2 to the end of nums.\n\nReturn the minimum number of operations you need to perform so that nums contains a subsequence whose elements sum to target. If it is impossible to obtain such a subsequence, return -1.\n\nA subsequence is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining elements.\n\nExample 1:\n\nInput: nums = [1,2,8], target = 7\nOutput: 1\nExplanation: In the first operation, we choose element nums[2]. The array becomes equal to nums = [1,2,4,4].\nAt this stage, nums contains the subsequence [1,2,4] which sums up to 7.\nIt can be shown that there is no shorter sequence of operations that results in a subsequnce that sums up to 7.\n\nExample 2:\n\nInput: nums = [1,32,1,2], target = 12\nOutput: 2\nExplanation: In the first operation, we choose element nums[1]. The array becomes equal to nums = [1,1,2,16,16].\nIn the second operation, we choose element nums[3]. The array becomes equal to nums = [1,1,2,16,8,8]\nAt this stage, nums contains the subsequence [1,1,2,8] which sums up to 12.\nIt can be shown that there is no shorter sequence of operations that results in a subsequence that sums up to 12.\n\nExample 3:\n\nInput: nums = [1,32,1], target = 35\nOutput: -1\nExplanation: It can be shown that no sequence of operations results in a subsequence that sums up to 35.\n\n\nConstraints:\n\n * 1 <= nums.length <= 1000\n * 1 <= nums[i] <= 230\n * nums consists only of non-negative powers of two.\n * 1 <= target < 231\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def minOperations(self, nums: List[int], target: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,2,8], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,32,1,2], \"target\": 12 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,32,1], \"target\": 35 }\nassert my_solution.minOperations(**test_input) == -1\n\ntest_input = { \"nums\": [1], \"target\": 1 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [16,128,32], \"target\": 1 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [1,1], \"target\": 2 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [64,128,128], \"target\": 2 }\nassert my_solution.minOperations(**test_input) == 5\n\ntest_input = { \"nums\": [2], \"target\": 2 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [32,256,4], \"target\": 2 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,1], \"target\": 3 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [1,256,16,128], \"target\": 3 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,2], \"target\": 3 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [16,16,4], \"target\": 3 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,1,1], \"target\": 4 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [128,1,128,1,64], \"target\": 4 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [2,1,1], \"target\": 4 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [8,2,64,32], \"target\": 4 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [16,128,8,1,1], \"target\": 4 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,1], \"target\": 4 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [128,8,8,2], \"target\": 4 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [2,2], \"target\": 4 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [128,32,16], \"target\": 4 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [4], \"target\": 4 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [128,32,256], \"target\": 4 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,1,1,1], \"target\": 5 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,128,256,1,16], \"target\": 5 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [2,1,1,1], \"target\": 5 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [32,1,8,1,64], \"target\": 5 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [128,256,32,1,1,1], \"target\": 5 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,2,1], \"target\": 5 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [16,16,1,1,128], \"target\": 5 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [2,2,1], \"target\": 5 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [64,32,2,8], \"target\": 5 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,4], \"target\": 5 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [8,64,128], \"target\": 5 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,1,1,1,1], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [128,1,256,1,1,1,32], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,1,1,2], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [1,256,1,1,8,64], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,128,1,128,1,8,1], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,1,2,1], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [64,1,16,1,1,64], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [2,1,2,1], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [2,1,8,64,64], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [4,1,1], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [16,64,4,128], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,1,8,128,1,8], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,1,1,1], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [64,128,1,32,1,2], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,1,256,1,8,64], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,128,1,256,32,1], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,1,2], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [256,2,32,32,1], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,16,1,1,1,16,256], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,2,1,1], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,64,8,16,1], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,16,128,1,1,32,1], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [128,1,1,1,64,32], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [64,16,16,1,1], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [32,1,1,32,1,64,1], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [8,64,2,1,1,8], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,256,1,64,1,128], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [1,1,64,64,32,2], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [2,32,128,1,64], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [2,2,2], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [64,8,2,128], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [4,2], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [8,8,16], \"target\": 6 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,1,1,1,1,1], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,1,1,128,1,64,8], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [2,1,1,1,1,1], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [1,2,64,32,16,1,1], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,1,16,128,256,1,1], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,1,2,1,1], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [2,8,8,1,128,1,1], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,1,1,2], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [32,1,2,1,256,128], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,1,4], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [1,8,256,32,1], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [64,1,1,1,16,1,64,1], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,1,1,2,1], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [1,256,1,8,1,2,16], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [32,1,1,1,32,32,1,1], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,1,1,1,1], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [64,1,32,256,1,1,1], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [2,1,2,1,1], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [2,32,32,32,2,1], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,8,1,1,64,1,128], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,1,1,1,2], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [64,128,2,128,1,1,1], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [1,1,1,128,8,32,1,1], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [64,256,1,1,1,32,2], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,2,1,1], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [1,256,64,2,1,128], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [256,1,1,1,64,1,1,64], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 4\n\ntest_input = { \"nums\": [2,1,8,256,1,128,1], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,16,1,1,256,1,128], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,8,128,1,1,1,256], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 1\n\ntest_input = { \"nums\": [2,2,1,1,1], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 0\n\ntest_input = { \"nums\": [64,2,64,1,32,1], \"target\": 7 }\nassert my_solution.minOperations(**test_input) == 3", "start_time": 1693103400} +{"task_id": "weekly-contest-360-maximize-value-of-function-in-a-ball-passing-game", "url": "https://leetcode.com/problems/maximize-value-of-function-in-a-ball-passing-game", "title": "maximize-value-of-function-in-a-ball-passing-game", "meta": {"questionId": "3032", "questionFrontendId": "2836", "title": "Maximize Value of Function in a Ball Passing Game", "titleSlug": "maximize-value-of-function-in-a-ball-passing-game", "isPaidOnly": false, "difficulty": "Hard", "likes": 202, "dislikes": 85, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed integer array receiver of length n and an integer k.\n\nThere are n players having a unique id in the range [0, n - 1] who will play a ball passing game, and receiver[i] is the id of the player who receives passes from the player with id i. Players can pass to themselves, i.e. receiver[i] may be equal to i.\n\nYou must choose one of the n players as the starting player for the game, and the ball will be passed exactly k times starting from the chosen player.\n\nFor a chosen starting player having id x, we define a function f(x) that denotes the sum of x and the ids of all players who receive the ball during the k passes, including repetitions. In other words, f(x) = x + receiver[x] + receiver[receiver[x]] + ... + receiver(k)[x].\n\nYour task is to choose a starting player having id x that maximizes the value of f(x).\n\nReturn an integer denoting the maximum value of the function.\n\nNote: receiver may contain duplicates.\n\nExample 1:\n\nPass Number Sender ID Receiver ID x + Receiver IDs       2 1 2 1 3 2 1 0 3 3 0 2 5 4 2 1 6\n\nInput: receiver = [2,0,1], k = 4\nOutput: 6\nExplanation: The table above shows a simulation of the game starting with the player having id x = 2.\nFrom the table, f(2) is equal to 6.\nIt can be shown that 6 is the maximum achievable value of the function.\nHence, the output is 6.\n\nExample 2:\n\nPass Number Sender ID Receiver ID x + Receiver IDs       4 1 4 3 7 2 3 2 9 3 2 1 10\n\nInput: receiver = [1,1,1,2,3], k = 3\nOutput: 10\nExplanation: The table above shows a simulation of the game starting with the player having id x = 4.\nFrom the table, f(4) is equal to 10.\nIt can be shown that 10 is the maximum achievable value of the function.\nHence, the output is 10.\n\n\nConstraints:\n\n * 1 <= receiver.length == n <= 105\n * 0 <= receiver[i] <= n - 1\n * 1 <= k <= 1010\n\"\"\"\nclass Solution:\n def getMaxFunctionValue(self, receiver: List[int], k: int) -> int:\n ", "prompt_sft": "You are given a 0-indexed integer array receiver of length n and an integer k.\n\nThere are n players having a unique id in the range [0, n - 1] who will play a ball passing game, and receiver[i] is the id of the player who receives passes from the player with id i. Players can pass to themselves, i.e. receiver[i] may be equal to i.\n\nYou must choose one of the n players as the starting player for the game, and the ball will be passed exactly k times starting from the chosen player.\n\nFor a chosen starting player having id x, we define a function f(x) that denotes the sum of x and the ids of all players who receive the ball during the k passes, including repetitions. In other words, f(x) = x + receiver[x] + receiver[receiver[x]] + ... + receiver(k)[x].\n\nYour task is to choose a starting player having id x that maximizes the value of f(x).\n\nReturn an integer denoting the maximum value of the function.\n\nNote: receiver may contain duplicates.\n\nExample 1:\n\nPass Number Sender ID Receiver ID x + Receiver IDs       2 1 2 1 3 2 1 0 3 3 0 2 5 4 2 1 6\n\nInput: receiver = [2,0,1], k = 4\nOutput: 6\nExplanation: The table above shows a simulation of the game starting with the player having id x = 2.\nFrom the table, f(2) is equal to 6.\nIt can be shown that 6 is the maximum achievable value of the function.\nHence, the output is 6.\n\nExample 2:\n\nPass Number Sender ID Receiver ID x + Receiver IDs       4 1 4 3 7 2 3 2 9 3 2 1 10\n\nInput: receiver = [1,1,1,2,3], k = 3\nOutput: 10\nExplanation: The table above shows a simulation of the game starting with the player having id x = 4.\nFrom the table, f(4) is equal to 10.\nIt can be shown that 10 is the maximum achievable value of the function.\nHence, the output is 10.\n\n\nConstraints:\n\n * 1 <= receiver.length == n <= 105\n * 0 <= receiver[i] <= n - 1\n * 1 <= k <= 1010\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def getMaxFunctionValue(self, receiver: List[int], k: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"receiver\": [2,0,1], \"k\": 4 }\nassert my_solution.getMaxFunctionValue(**test_input) == 6\n\ntest_input = { \"receiver\": [1,1,1,2,3], \"k\": 3 }\nassert my_solution.getMaxFunctionValue(**test_input) == 10\n\ntest_input = { \"receiver\": [0], \"k\": 1 }\nassert my_solution.getMaxFunctionValue(**test_input) == 0\n\ntest_input = { \"receiver\": [0], \"k\": 2 }\nassert my_solution.getMaxFunctionValue(**test_input) == 0\n\ntest_input = { \"receiver\": [0], \"k\": 3 }\nassert my_solution.getMaxFunctionValue(**test_input) == 0\n\ntest_input = { \"receiver\": [0], \"k\": 100 }\nassert my_solution.getMaxFunctionValue(**test_input) == 0\n\ntest_input = { \"receiver\": [0,0], \"k\": 1 }\nassert my_solution.getMaxFunctionValue(**test_input) == 1\n\ntest_input = { \"receiver\": [0,0], \"k\": 7 }\nassert my_solution.getMaxFunctionValue(**test_input) == 1\n\ntest_input = { \"receiver\": [0,0], \"k\": 10 }\nassert my_solution.getMaxFunctionValue(**test_input) == 1\n\ntest_input = { \"receiver\": [0,0], \"k\": 13 }\nassert my_solution.getMaxFunctionValue(**test_input) == 1\n\ntest_input = { \"receiver\": [0,0], \"k\": 16 }\nassert my_solution.getMaxFunctionValue(**test_input) == 1\n\ntest_input = { \"receiver\": [0,1], \"k\": 1 }\nassert my_solution.getMaxFunctionValue(**test_input) == 2\n\ntest_input = { \"receiver\": [0,1], \"k\": 3 }\nassert my_solution.getMaxFunctionValue(**test_input) == 4\n\ntest_input = { \"receiver\": [0,1], \"k\": 5 }\nassert my_solution.getMaxFunctionValue(**test_input) == 6\n\ntest_input = { \"receiver\": [0,1], \"k\": 8 }\nassert my_solution.getMaxFunctionValue(**test_input) == 9\n\ntest_input = { \"receiver\": [0,1], \"k\": 13 }\nassert my_solution.getMaxFunctionValue(**test_input) == 14\n\ntest_input = { \"receiver\": [0,1], \"k\": 14 }\nassert my_solution.getMaxFunctionValue(**test_input) == 15\n\ntest_input = { \"receiver\": [0,1], \"k\": 15 }\nassert my_solution.getMaxFunctionValue(**test_input) == 16\n\ntest_input = { \"receiver\": [1,0], \"k\": 5 }\nassert my_solution.getMaxFunctionValue(**test_input) == 3\n\ntest_input = { \"receiver\": [1,0], \"k\": 6 }\nassert my_solution.getMaxFunctionValue(**test_input) == 4\n\ntest_input = { \"receiver\": [1,0], \"k\": 7 }\nassert my_solution.getMaxFunctionValue(**test_input) == 4\n\ntest_input = { \"receiver\": [1,0], \"k\": 10 }\nassert my_solution.getMaxFunctionValue(**test_input) == 6\n\ntest_input = { \"receiver\": [1,0], \"k\": 12 }\nassert my_solution.getMaxFunctionValue(**test_input) == 7\n\ntest_input = { \"receiver\": [1,0], \"k\": 14 }\nassert my_solution.getMaxFunctionValue(**test_input) == 8\n\ntest_input = { \"receiver\": [1,0], \"k\": 57 }\nassert my_solution.getMaxFunctionValue(**test_input) == 29\n\ntest_input = { \"receiver\": [1,1], \"k\": 1 }\nassert my_solution.getMaxFunctionValue(**test_input) == 2\n\ntest_input = { \"receiver\": [1,1], \"k\": 2 }\nassert my_solution.getMaxFunctionValue(**test_input) == 3\n\ntest_input = { \"receiver\": [1,1], \"k\": 7 }\nassert my_solution.getMaxFunctionValue(**test_input) == 8\n\ntest_input = { \"receiver\": [0,0,0], \"k\": 1 }\nassert my_solution.getMaxFunctionValue(**test_input) == 2\n\ntest_input = { \"receiver\": [0,0,0], \"k\": 4 }\nassert my_solution.getMaxFunctionValue(**test_input) == 2\n\ntest_input = { \"receiver\": [0,0,0], \"k\": 6 }\nassert my_solution.getMaxFunctionValue(**test_input) == 2\n\ntest_input = { \"receiver\": [0,0,0], \"k\": 10 }\nassert my_solution.getMaxFunctionValue(**test_input) == 2\n\ntest_input = { \"receiver\": [0,0,1], \"k\": 3 }\nassert my_solution.getMaxFunctionValue(**test_input) == 3\n\ntest_input = { \"receiver\": [0,0,1], \"k\": 9 }\nassert my_solution.getMaxFunctionValue(**test_input) == 3\n\ntest_input = { \"receiver\": [0,0,2], \"k\": 11 }\nassert my_solution.getMaxFunctionValue(**test_input) == 24\n\ntest_input = { \"receiver\": [0,0,2], \"k\": 14 }\nassert my_solution.getMaxFunctionValue(**test_input) == 30\n\ntest_input = { \"receiver\": [0,0,2], \"k\": 82 }\nassert my_solution.getMaxFunctionValue(**test_input) == 166\n\ntest_input = { \"receiver\": [0,1,0], \"k\": 5 }\nassert my_solution.getMaxFunctionValue(**test_input) == 6\n\ntest_input = { \"receiver\": [0,1,1], \"k\": 2 }\nassert my_solution.getMaxFunctionValue(**test_input) == 4\n\ntest_input = { \"receiver\": [0,1,2], \"k\": 3 }\nassert my_solution.getMaxFunctionValue(**test_input) == 8\n\ntest_input = { \"receiver\": [0,1,2], \"k\": 6 }\nassert my_solution.getMaxFunctionValue(**test_input) == 14\n\ntest_input = { \"receiver\": [1,0,0], \"k\": 6 }\nassert my_solution.getMaxFunctionValue(**test_input) == 5\n\ntest_input = { \"receiver\": [1,0,1], \"k\": 2 }\nassert my_solution.getMaxFunctionValue(**test_input) == 3\n\ntest_input = { \"receiver\": [1,0,2], \"k\": 10 }\nassert my_solution.getMaxFunctionValue(**test_input) == 22\n\ntest_input = { \"receiver\": [1,1,1], \"k\": 4 }\nassert my_solution.getMaxFunctionValue(**test_input) == 6\n\ntest_input = { \"receiver\": [1,1,1], \"k\": 6 }\nassert my_solution.getMaxFunctionValue(**test_input) == 8\n\ntest_input = { \"receiver\": [1,1,2], \"k\": 8 }\nassert my_solution.getMaxFunctionValue(**test_input) == 18\n\ntest_input = { \"receiver\": [1,2,0], \"k\": 3 }\nassert my_solution.getMaxFunctionValue(**test_input) == 5\n\ntest_input = { \"receiver\": [1,2,0], \"k\": 8 }\nassert my_solution.getMaxFunctionValue(**test_input) == 9\n\ntest_input = { \"receiver\": [1,2,1], \"k\": 6 }\nassert my_solution.getMaxFunctionValue(**test_input) == 11\n\ntest_input = { \"receiver\": [1,2,2], \"k\": 7 }\nassert my_solution.getMaxFunctionValue(**test_input) == 16\n\ntest_input = { \"receiver\": [2,0,2], \"k\": 6 }\nassert my_solution.getMaxFunctionValue(**test_input) == 14\n\ntest_input = { \"receiver\": [2,1,0], \"k\": 3 }\nassert my_solution.getMaxFunctionValue(**test_input) == 4\n\ntest_input = { \"receiver\": [2,1,0], \"k\": 8 }\nassert my_solution.getMaxFunctionValue(**test_input) == 10\n\ntest_input = { \"receiver\": [2,1,0], \"k\": 10 }\nassert my_solution.getMaxFunctionValue(**test_input) == 12\n\ntest_input = { \"receiver\": [2,1,1], \"k\": 4 }\nassert my_solution.getMaxFunctionValue(**test_input) == 6\n\ntest_input = { \"receiver\": [2,1,2], \"k\": 2 }\nassert my_solution.getMaxFunctionValue(**test_input) == 6\n\ntest_input = { \"receiver\": [2,1,2], \"k\": 15 }\nassert my_solution.getMaxFunctionValue(**test_input) == 32\n\ntest_input = { \"receiver\": [2,2,0], \"k\": 4 }\nassert my_solution.getMaxFunctionValue(**test_input) == 6\n\ntest_input = { \"receiver\": [2,2,0], \"k\": 9 }\nassert my_solution.getMaxFunctionValue(**test_input) == 11\n\ntest_input = { \"receiver\": [2,2,1], \"k\": 1 }\nassert my_solution.getMaxFunctionValue(**test_input) == 3\n\ntest_input = { \"receiver\": [2,2,1], \"k\": 10 }\nassert my_solution.getMaxFunctionValue(**test_input) == 17\n\ntest_input = { \"receiver\": [2,2,2], \"k\": 15 }\nassert my_solution.getMaxFunctionValue(**test_input) == 32\n\ntest_input = { \"receiver\": [0,0,3,0], \"k\": 4 }\nassert my_solution.getMaxFunctionValue(**test_input) == 5\n\ntest_input = { \"receiver\": [0,1,0,1], \"k\": 11 }\nassert my_solution.getMaxFunctionValue(**test_input) == 14\n\ntest_input = { \"receiver\": [0,1,1,3], \"k\": 5 }\nassert my_solution.getMaxFunctionValue(**test_input) == 18\n\ntest_input = { \"receiver\": [0,2,1,3], \"k\": 5 }\nassert my_solution.getMaxFunctionValue(**test_input) == 18\n\ntest_input = { \"receiver\": [0,2,3,1], \"k\": 6 }\nassert my_solution.getMaxFunctionValue(**test_input) == 15\n\ntest_input = { \"receiver\": [0,2,3,3], \"k\": 8 }\nassert my_solution.getMaxFunctionValue(**test_input) == 27\n\ntest_input = { \"receiver\": [0,2,3,3], \"k\": 15 }\nassert my_solution.getMaxFunctionValue(**test_input) == 48\n\ntest_input = { \"receiver\": [0,3,3,0], \"k\": 10 }\nassert my_solution.getMaxFunctionValue(**test_input) == 5\n\ntest_input = { \"receiver\": [1,0,0,2], \"k\": 9 }\nassert my_solution.getMaxFunctionValue(**test_input) == 9\n\ntest_input = { \"receiver\": [1,0,1,2], \"k\": 15 }\nassert my_solution.getMaxFunctionValue(**test_input) == 12\n\ntest_input = { \"receiver\": [1,0,3,1], \"k\": 6 }\nassert my_solution.getMaxFunctionValue(**test_input) == 8\n\ntest_input = { \"receiver\": [1,0,3,2], \"k\": 2 }\nassert my_solution.getMaxFunctionValue(**test_input) == 8\n\ntest_input = { \"receiver\": [1,1,0,0], \"k\": 2 }\nassert my_solution.getMaxFunctionValue(**test_input) == 4\n\ntest_input = { \"receiver\": [1,1,0,3], \"k\": 3 }\nassert my_solution.getMaxFunctionValue(**test_input) == 12\n\ntest_input = { \"receiver\": [1,1,1,3], \"k\": 7 }\nassert my_solution.getMaxFunctionValue(**test_input) == 24\n\ntest_input = { \"receiver\": [1,2,0,0], \"k\": 14 }\nassert my_solution.getMaxFunctionValue(**test_input) == 16\n\ntest_input = { \"receiver\": [1,2,0,1], \"k\": 5 }\nassert my_solution.getMaxFunctionValue(**test_input) == 9\n\ntest_input = { \"receiver\": [1,2,3,1], \"k\": 47 }\nassert my_solution.getMaxFunctionValue(**test_input) == 96\n\ntest_input = { \"receiver\": [1,3,0,1], \"k\": 2 }\nassert my_solution.getMaxFunctionValue(**test_input) == 7\n\ntest_input = { \"receiver\": [1,3,3,0], \"k\": 7 }\nassert my_solution.getMaxFunctionValue(**test_input) == 13\n\ntest_input = { \"receiver\": [2,0,0,1], \"k\": 9 }\nassert my_solution.getMaxFunctionValue(**test_input) == 12\n\ntest_input = { \"receiver\": [2,0,0,2], \"k\": 12 }\nassert my_solution.getMaxFunctionValue(**test_input) == 15\n\ntest_input = { \"receiver\": [2,0,2,0], \"k\": 5 }\nassert my_solution.getMaxFunctionValue(**test_input) == 12\n\ntest_input = { \"receiver\": [2,1,0,0], \"k\": 8 }\nassert my_solution.getMaxFunctionValue(**test_input) == 11\n\ntest_input = { \"receiver\": [2,1,0,1], \"k\": 97 }\nassert my_solution.getMaxFunctionValue(**test_input) == 100\n\ntest_input = { \"receiver\": [2,2,2,0], \"k\": 1 }\nassert my_solution.getMaxFunctionValue(**test_input) == 4\n\ntest_input = { \"receiver\": [2,2,3,2], \"k\": 8 }\nassert my_solution.getMaxFunctionValue(**test_input) == 23\n\ntest_input = { \"receiver\": [2,3,2,1], \"k\": 56 }\nassert my_solution.getMaxFunctionValue(**test_input) == 115\n\ntest_input = { \"receiver\": [2,3,3,1], \"k\": 15 }\nassert my_solution.getMaxFunctionValue(**test_input) == 33\n\ntest_input = { \"receiver\": [2,3,3,3], \"k\": 2 }\nassert my_solution.getMaxFunctionValue(**test_input) == 9\n\ntest_input = { \"receiver\": [3,0,0,1], \"k\": 4 }\nassert my_solution.getMaxFunctionValue(**test_input) == 8\n\ntest_input = { \"receiver\": [3,0,0,2], \"k\": 85 }\nassert my_solution.getMaxFunctionValue(**test_input) == 145\n\ntest_input = { \"receiver\": [3,0,1,3], \"k\": 9 }\nassert my_solution.getMaxFunctionValue(**test_input) == 30\n\ntest_input = { \"receiver\": [3,1,1,2], \"k\": 7 }\nassert my_solution.getMaxFunctionValue(**test_input) == 11\n\ntest_input = { \"receiver\": [3,1,2,0], \"k\": 60 }\nassert my_solution.getMaxFunctionValue(**test_input) == 122\n\ntest_input = { \"receiver\": [3,2,0,3], \"k\": 12 }\nassert my_solution.getMaxFunctionValue(**test_input) == 39\n\ntest_input = { \"receiver\": [3,3,0,1], \"k\": 1 }\nassert my_solution.getMaxFunctionValue(**test_input) == 4", "start_time": 1693103400} +{"task_id": "weekly-contest-359-check-if-a-string-is-an-acronym-of-words", "url": "https://leetcode.com/problems/check-if-a-string-is-an-acronym-of-words", "title": "check-if-a-string-is-an-acronym-of-words", "meta": {"questionId": "2977", "questionFrontendId": "2828", "title": "Check if a String Is an Acronym of Words", "titleSlug": "check-if-a-string-is-an-acronym-of-words", "isPaidOnly": false, "difficulty": "Easy", "likes": 257, "dislikes": 7, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nGiven an array of strings words and a string s, determine if s is an acronym of words.\n\nThe string s is considered an acronym of words if it can be formed by concatenating the first character of each string in words in order. For example, \"ab\" can be formed from [\"apple\", \"banana\"], but it can't be formed from [\"bear\", \"aardvark\"].\n\nReturn true if s is an acronym of words, and false otherwise.\n\nExample 1:\n\nInput: words = [\"alice\",\"bob\",\"charlie\"], s = \"abc\"\nOutput: true\nExplanation: The first character in the words \"alice\", \"bob\", and \"charlie\" are 'a', 'b', and 'c', respectively. Hence, s = \"abc\" is the acronym.\n\nExample 2:\n\nInput: words = [\"an\",\"apple\"], s = \"a\"\nOutput: false\nExplanation: The first character in the words \"an\" and \"apple\" are 'a' and 'a', respectively.\nThe acronym formed by concatenating these characters is \"aa\".\nHence, s = \"a\" is not the acronym.\n\nExample 3:\n\nInput: words = [\"never\",\"gonna\",\"give\",\"up\",\"on\",\"you\"], s = \"ngguoy\"\nOutput: true\nExplanation: By concatenating the first character of the words in the array, we get the string \"ngguoy\".\nHence, s = \"ngguoy\" is the acronym.\n\n\nConstraints:\n\n * 1 <= words.length <= 100\n * 1 <= words[i].length <= 10\n * 1 <= s.length <= 100\n * words[i] and s consist of lowercase English letters.\n\"\"\"\nclass Solution:\n def isAcronym(self, words: List[str], s: str) -> bool:\n ", "prompt_sft": "Given an array of strings words and a string s, determine if s is an acronym of words.\n\nThe string s is considered an acronym of words if it can be formed by concatenating the first character of each string in words in order. For example, \"ab\" can be formed from [\"apple\", \"banana\"], but it can't be formed from [\"bear\", \"aardvark\"].\n\nReturn true if s is an acronym of words, and false otherwise.\n\nExample 1:\n\nInput: words = [\"alice\",\"bob\",\"charlie\"], s = \"abc\"\nOutput: true\nExplanation: The first character in the words \"alice\", \"bob\", and \"charlie\" are 'a', 'b', and 'c', respectively. Hence, s = \"abc\" is the acronym.\n\nExample 2:\n\nInput: words = [\"an\",\"apple\"], s = \"a\"\nOutput: false\nExplanation: The first character in the words \"an\" and \"apple\" are 'a' and 'a', respectively.\nThe acronym formed by concatenating these characters is \"aa\".\nHence, s = \"a\" is not the acronym.\n\nExample 3:\n\nInput: words = [\"never\",\"gonna\",\"give\",\"up\",\"on\",\"you\"], s = \"ngguoy\"\nOutput: true\nExplanation: By concatenating the first character of the words in the array, we get the string \"ngguoy\".\nHence, s = \"ngguoy\" is the acronym.\n\n\nConstraints:\n\n * 1 <= words.length <= 100\n * 1 <= words[i].length <= 10\n * 1 <= s.length <= 100\n * words[i] and s consist of lowercase English letters.\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def isAcronym(self, words: List[str], s: str) -> bool:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"words\": [\"an\",\"apple\"], \"s\": \"a\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"alice\",\"bob\",\"charlie\"], \"s\": \"abc\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"never\",\"gonna\",\"give\",\"up\",\"on\",\"you\"], \"s\": \"ngguoy\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"ad\",\"uadhrwxki\"], \"s\": \"au\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"afqcpzsx\",\"icenu\"], \"s\": \"yi\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"afkc\",\"icxufam\"], \"s\": \"ai\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"ahbibag\",\"aoximesw\"], \"s\": \"aa\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"auqoc\",\"koioxa\"], \"s\": \"ak\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"b\",\"x\"], \"s\": \"bx\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"c\",\"df\"], \"s\": \"bd\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"dv\",\"g\"], \"s\": \"sg\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"dvn\",\"acafe\"], \"s\": \"dp\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"bpctc\",\"kaqquqbpmw\"], \"s\": \"bk\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"c\",\"evlvvhrsqa\"], \"s\": \"ce\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"dwrvgkxdtm\",\"wy\"], \"s\": \"hw\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"eceekigel\",\"gmgdfvsrkw\"], \"s\": \"wg\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"cfsrsyt\",\"md\"], \"s\": \"cm\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"envpklvi\",\"jpymde\"], \"s\": \"en\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"espleklys\",\"dg\"], \"s\": \"ea\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"euptjhixnu\",\"fwci\"], \"s\": \"kf\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"ddnlfpvy\",\"exs\"], \"s\": \"de\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"deacf\",\"hldiauk\"], \"s\": \"dh\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"dllcn\",\"tnzrnzypg\"], \"s\": \"dt\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"dmekslxlpo\",\"wqdgxqwdk\"], \"s\": \"dw\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"eyzywjsxza\",\"jxeimcc\"], \"s\": \"ex\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"f\",\"oylvtltvo\"], \"s\": \"ho\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"eo\",\"e\"], \"s\": \"ee\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"eucvcqdgg\",\"qtdwhygerb\"], \"s\": \"eq\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"fnpow\",\"ysqwqli\"], \"s\": \"jy\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"gpqyvv\",\"kihi\"], \"s\": \"ik\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"exrgiw\",\"irexgmrl\"], \"s\": \"ei\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"ez\",\"acnmits\"], \"s\": \"ea\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"fvkekkv\",\"jfbv\"], \"s\": \"fj\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"kncge\",\"nje\"], \"s\": \"kw\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"fyocwzlz\",\"lz\"], \"s\": \"fl\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"mnh\",\"clep\"], \"s\": \"pc\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"mnpdwq\",\"hziusbxr\"], \"s\": \"mg\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"g\",\"r\"], \"s\": \"gr\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"n\",\"fddigeie\"], \"s\": \"hf\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"gle\",\"irt\"], \"s\": \"gi\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"h\",\"xhtkcj\"], \"s\": \"hx\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"n\",\"ityua\"], \"s\": \"ei\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"nmxysdim\",\"xnpqsauh\"], \"s\": \"ne\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"ovdhflcck\",\"ndd\"], \"s\": \"oi\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"piiyodecdf\",\"wdwfxsjfou\"], \"s\": \"pp\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"hdmwkr\",\"jfrqh\"], \"s\": \"hj\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"hflf\",\"fvnotmdcpw\"], \"s\": \"hf\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"hnwphhozqw\",\"cfhsjlqj\"], \"s\": \"hc\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"pxcsaaa\",\"lrvxsc\"], \"s\": \"pz\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"htlsq\",\"y\"], \"s\": \"hy\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"iakfeop\",\"pd\"], \"s\": \"ip\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"qir\",\"qyyzmntl\"], \"s\": \"qa\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"iakfmr\",\"gzggxzwor\"], \"s\": \"ig\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"jna\",\"rjdbu\"], \"s\": \"jr\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"qunqyc\",\"ouzjotitvn\"], \"s\": \"co\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"rdednrsn\",\"yfrgdeapme\"], \"s\": \"ny\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"rtnbfaemv\",\"kgpcwaoik\"], \"s\": \"rf\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"s\",\"n\"], \"s\": \"sx\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"siiyqtkyis\",\"mogzgabcgk\"], \"s\": \"fm\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"tit\",\"pmuqzrs\"], \"s\": \"tz\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"uip\",\"hhstwupgg\"], \"s\": \"eh\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"uyj\",\"jlfnksqlt\"], \"s\": \"ur\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"kabfejv\",\"g\"], \"s\": \"kg\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"w\",\"eshensjifo\"], \"s\": \"ez\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"khhhdsaevp\",\"dnod\"], \"s\": \"kd\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"wefmc\",\"tmunsmg\"], \"s\": \"jt\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"wo\",\"jhaabx\"], \"s\": \"wx\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"kltil\",\"mubemf\"], \"s\": \"km\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"kxkvhylsh\",\"gyshntskq\"], \"s\": \"kg\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"wseopbedw\",\"iihrgujev\"], \"s\": \"wq\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"kzxp\",\"fy\"], \"s\": \"kf\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"wvdx\",\"jerzn\"], \"s\": \"cj\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"y\",\"qppnclhhbd\"], \"s\": \"mq\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"yegnsnddq\",\"kusrkz\"], \"s\": \"bk\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"couqsa\",\"sncuru\",\"jhgxpxipg\"], \"s\": \"csa\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"csm\",\"hexhvojfj\",\"l\"], \"s\": \"chh\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"lbor\",\"zx\"], \"s\": \"lz\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"losinu\",\"ptsjoihvj\"], \"s\": \"lp\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"maczdfm\",\"ywj\"], \"s\": \"my\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"d\",\"geviina\",\"tyljs\"], \"s\": \"dvt\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"mammhva\",\"igyzbwpj\"], \"s\": \"mi\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"ecmlkida\",\"vrjwdpe\",\"vocff\"], \"s\": \"hvv\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"emqlklvrw\",\"das\",\"bzuq\"], \"s\": \"edm\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"hawikjbs\",\"qi\",\"ssvgttkzd\"], \"s\": \"rornirdphvargyce\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"hd\",\"f\",\"meivn\"], \"s\": \"hpm\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"mqhptbyzzv\",\"mfubjraiqz\"], \"s\": \"mm\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"mvftnzftb\",\"ga\"], \"s\": \"mg\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"ncgutvi\",\"rsh\"], \"s\": \"nr\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"ntf\",\"txayzc\"], \"s\": \"nt\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"nubibbe\",\"wzwdrjcck\"], \"s\": \"nw\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"hphfek\",\"kezkkq\",\"oh\"], \"s\": \"hmo\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"odtclcvcj\",\"ufhrhk\"], \"s\": \"ou\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"ojcn\",\"naujlz\"], \"s\": \"on\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"iho\",\"ignyipken\",\"q\"], \"s\": \"wiq\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"olynt\",\"xf\"], \"s\": \"ox\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"ir\",\"wzhmxee\",\"kjfwful\"], \"s\": \"iwn\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"ixo\",\"wigba\",\"raaphui\"], \"s\": \"dwr\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"opup\",\"eme\"], \"s\": \"oe\" }\nassert my_solution.isAcronym(**test_input) == True\n\ntest_input = { \"words\": [\"kmmoq\",\"aoh\",\"hznkpurdh\"], \"s\": \"kar\" }\nassert my_solution.isAcronym(**test_input) == False\n\ntest_input = { \"words\": [\"ottxwi\",\"akpixfvbel\"], \"s\": \"oa\" }\nassert my_solution.isAcronym(**test_input) == True", "start_time": 1692498600} +{"task_id": "weekly-contest-359-determine-the-minimum-sum-of-a-k-avoiding-array", "url": "https://leetcode.com/problems/determine-the-minimum-sum-of-a-k-avoiding-array", "title": "determine-the-minimum-sum-of-a-k-avoiding-array", "meta": {"questionId": "2811", "questionFrontendId": "2829", "title": "Determine the Minimum Sum of a k-avoiding Array", "titleSlug": "determine-the-minimum-sum-of-a-k-avoiding-array", "isPaidOnly": false, "difficulty": "Medium", "likes": 305, "dislikes": 8, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given two integers, n and k.\n\nAn array of distinct positive integers is called a k-avoiding array if there does not exist any pair of distinct elements that sum to k.\n\nReturn the minimum possible sum of a k-avoiding array of length n.\n\nExample 1:\n\nInput: n = 5, k = 4\nOutput: 18\nExplanation: Consider the k-avoiding array [1,2,4,5,6], which has a sum of 18.\nIt can be proven that there is no k-avoiding array with a sum less than 18.\n\nExample 2:\n\nInput: n = 2, k = 6\nOutput: 3\nExplanation: We can construct the array [1,2], which has a sum of 3.\nIt can be proven that there is no k-avoiding array with a sum less than 3.\n\n\nConstraints:\n\n * 1 <= n, k <= 50\n\"\"\"\nclass Solution:\n def minimumSum(self, n: int, k: int) -> int:\n ", "prompt_sft": "You are given two integers, n and k.\n\nAn array of distinct positive integers is called a k-avoiding array if there does not exist any pair of distinct elements that sum to k.\n\nReturn the minimum possible sum of a k-avoiding array of length n.\n\nExample 1:\n\nInput: n = 5, k = 4\nOutput: 18\nExplanation: Consider the k-avoiding array [1,2,4,5,6], which has a sum of 18.\nIt can be proven that there is no k-avoiding array with a sum less than 18.\n\nExample 2:\n\nInput: n = 2, k = 6\nOutput: 3\nExplanation: We can construct the array [1,2], which has a sum of 3.\nIt can be proven that there is no k-avoiding array with a sum less than 3.\n\n\nConstraints:\n\n * 1 <= n, k <= 50\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def minimumSum(self, n: int, k: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"n\": 5, \"k\": 4 }\nassert my_solution.minimumSum(**test_input) == 18\n\ntest_input = { \"n\": 2, \"k\": 6 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 1, \"k\": 1 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 2 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 3 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 4 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 5 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 6 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 7 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 8 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 9 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 10 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 11 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 12 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 13 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 14 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 15 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 16 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 17 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 18 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 19 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 20 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 21 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 22 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 23 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 24 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 25 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 26 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 27 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 28 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 29 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 30 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 31 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 32 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 33 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 34 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 35 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 36 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 37 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 38 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 39 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 40 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 41 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 42 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 43 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 44 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 45 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 46 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 47 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 48 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 49 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 1, \"k\": 50 }\nassert my_solution.minimumSum(**test_input) == 1\n\ntest_input = { \"n\": 2, \"k\": 1 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 2 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 3 }\nassert my_solution.minimumSum(**test_input) == 4\n\ntest_input = { \"n\": 2, \"k\": 4 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 5 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 7 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 8 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 9 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 10 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 11 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 12 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 13 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 14 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 15 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 16 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 17 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 18 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 19 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 20 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 21 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 22 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 23 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 24 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 25 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 26 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 27 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 28 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 29 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 30 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 31 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 32 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 33 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 34 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 35 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 36 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 37 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 38 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 39 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 40 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 41 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 42 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 43 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 44 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 45 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 46 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 47 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 48 }\nassert my_solution.minimumSum(**test_input) == 3\n\ntest_input = { \"n\": 2, \"k\": 49 }\nassert my_solution.minimumSum(**test_input) == 3", "start_time": 1692498600} +{"task_id": "weekly-contest-359-maximize-the-profit-as-the-salesman", "url": "https://leetcode.com/problems/maximize-the-profit-as-the-salesman", "title": "maximize-the-profit-as-the-salesman", "meta": {"questionId": "2979", "questionFrontendId": "2830", "title": "Maximize the Profit as the Salesman", "titleSlug": "maximize-the-profit-as-the-salesman", "isPaidOnly": false, "difficulty": "Medium", "likes": 603, "dislikes": 19, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given an integer n representing the number of houses on a number line, numbered from 0 to n - 1.\n\nAdditionally, you are given a 2D integer array offers where offers[i] = [starti, endi, goldi], indicating that ith buyer wants to buy all the houses from starti to endi for goldi amount of gold.\n\nAs a salesman, your goal is to maximize your earnings by strategically selecting and selling houses to buyers.\n\nReturn the maximum amount of gold you can earn.\n\nNote that different buyers can't buy the same house, and some houses may remain unsold.\n\nExample 1:\n\nInput: n = 5, offers = [[0,0,1],[0,2,2],[1,3,2]]\nOutput: 3\nExplanation: There are 5 houses numbered from 0 to 4 and there are 3 purchase offers.\nWe sell houses in the range [0,0] to 1st buyer for 1 gold and houses in the range [1,3] to 3rd buyer for 2 golds.\nIt can be proven that 3 is the maximum amount of gold we can achieve.\n\nExample 2:\n\nInput: n = 5, offers = [[0,0,1],[0,2,10],[1,3,2]]\nOutput: 10\nExplanation: There are 5 houses numbered from 0 to 4 and there are 3 purchase offers.\nWe sell houses in the range [0,2] to 2nd buyer for 10 golds.\nIt can be proven that 10 is the maximum amount of gold we can achieve.\n\n\nConstraints:\n\n * 1 <= n <= 105\n * 1 <= offers.length <= 105\n * offers[i].length == 3\n * 0 <= starti <= endi <= n - 1\n * 1 <= goldi <= 103\n\"\"\"\nclass Solution:\n def maximizeTheProfit(self, n: int, offers: List[List[int]]) -> int:\n ", "prompt_sft": "You are given an integer n representing the number of houses on a number line, numbered from 0 to n - 1.\n\nAdditionally, you are given a 2D integer array offers where offers[i] = [starti, endi, goldi], indicating that ith buyer wants to buy all the houses from starti to endi for goldi amount of gold.\n\nAs a salesman, your goal is to maximize your earnings by strategically selecting and selling houses to buyers.\n\nReturn the maximum amount of gold you can earn.\n\nNote that different buyers can't buy the same house, and some houses may remain unsold.\n\nExample 1:\n\nInput: n = 5, offers = [[0,0,1],[0,2,2],[1,3,2]]\nOutput: 3\nExplanation: There are 5 houses numbered from 0 to 4 and there are 3 purchase offers.\nWe sell houses in the range [0,0] to 1st buyer for 1 gold and houses in the range [1,3] to 3rd buyer for 2 golds.\nIt can be proven that 3 is the maximum amount of gold we can achieve.\n\nExample 2:\n\nInput: n = 5, offers = [[0,0,1],[0,2,10],[1,3,2]]\nOutput: 10\nExplanation: There are 5 houses numbered from 0 to 4 and there are 3 purchase offers.\nWe sell houses in the range [0,2] to 2nd buyer for 10 golds.\nIt can be proven that 10 is the maximum amount of gold we can achieve.\n\n\nConstraints:\n\n * 1 <= n <= 105\n * 1 <= offers.length <= 105\n * offers[i].length == 3\n * 0 <= starti <= endi <= n - 1\n * 1 <= goldi <= 103\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def maximizeTheProfit(self, n: int, offers: List[List[int]]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"n\": 5, \"offers\": [[0,0,1],[0,2,2],[1,3,2]] }\nassert my_solution.maximizeTheProfit(**test_input) == 3\n\ntest_input = { \"n\": 5, \"offers\": [[0,0,1],[0,2,10],[1,3,2]] }\nassert my_solution.maximizeTheProfit(**test_input) == 10\n\ntest_input = { \"n\": 4, \"offers\": [[1,3,10],[1,3,3],[0,0,1],[0,0,7]] }\nassert my_solution.maximizeTheProfit(**test_input) == 17\n\ntest_input = { \"n\": 4, \"offers\": [[0,0,6],[1,2,8],[0,3,7],[2,2,5],[0,1,5],[2,3,2],[0,2,8],[2,3,10],[0,3,2]] }\nassert my_solution.maximizeTheProfit(**test_input) == 16\n\ntest_input = { \"n\": 15, \"offers\": [[5,5,10],[2,6,6],[8,11,5],[7,11,9],[2,4,1],[3,8,5],[0,6,9],[0,10,5],[5,10,8],[4,5,1]] }\nassert my_solution.maximizeTheProfit(**test_input) == 20\n\ntest_input = { \"n\": 10, \"offers\": [[1,6,1],[0,1,10],[3,6,2],[0,5,10],[0,0,3],[0,0,4],[1,1,4],[0,6,7],[4,4,1]] }\nassert my_solution.maximizeTheProfit(**test_input) == 12\n\ntest_input = { \"n\": 11, \"offers\": [[7,8,6],[6,6,4],[4,6,9],[6,7,4],[5,5,8],[1,5,9],[7,7,8],[1,2,5],[0,2,9],[1,3,8],[0,2,7],[2,2,8]] }\nassert my_solution.maximizeTheProfit(**test_input) == 29\n\ntest_input = { \"n\": 3, \"offers\": [[0,0,6],[0,1,8],[1,2,1],[0,1,4],[0,1,2],[0,0,7],[0,0,6],[0,0,5]] }\nassert my_solution.maximizeTheProfit(**test_input) == 8\n\ntest_input = { \"n\": 4, \"offers\": [[0,1,9],[1,1,4]] }\nassert my_solution.maximizeTheProfit(**test_input) == 9\n\ntest_input = { \"n\": 11, \"offers\": [[1,10,6],[1,10,5],[0,2,7],[0,0,8],[8,10,7]] }\nassert my_solution.maximizeTheProfit(**test_input) == 15\n\ntest_input = { \"n\": 3, \"offers\": [[0,1,8],[1,1,6],[2,2,7],[0,2,6],[0,2,2],[0,0,6],[0,0,9],[0,1,4]] }\nassert my_solution.maximizeTheProfit(**test_input) == 22\n\ntest_input = { \"n\": 6, \"offers\": [[0,2,4]] }\nassert my_solution.maximizeTheProfit(**test_input) == 4\n\ntest_input = { \"n\": 10, \"offers\": [[5,9,3],[1,5,8],[0,0,6],[5,8,10]] }\nassert my_solution.maximizeTheProfit(**test_input) == 16\n\ntest_input = { \"n\": 5, \"offers\": [[1,1,3],[1,1,3],[0,0,8],[1,3,8],[0,2,1],[3,3,9],[0,0,7],[0,2,3],[0,0,5],[0,3,10],[1,3,10],[4,4,6],[0,1,1],[2,4,10]] }\nassert my_solution.maximizeTheProfit(**test_input) == 26\n\ntest_input = { \"n\": 13, \"offers\": [[2,2,5],[1,8,10],[2,3,3]] }\nassert my_solution.maximizeTheProfit(**test_input) == 10\n\ntest_input = { \"n\": 2, \"offers\": [[1,1,8],[1,1,8],[1,1,10],[1,1,7],[0,0,7],[0,0,3],[0,1,8],[0,0,4],[0,0,4],[0,0,7],[0,0,10],[0,1,4],[1,1,1],[0,1,5]] }\nassert my_solution.maximizeTheProfit(**test_input) == 20\n\ntest_input = { \"n\": 3, \"offers\": [[0,1,7],[1,1,3],[0,0,2],[1,1,6],[0,0,10],[1,1,7],[0,2,3],[0,1,2],[0,0,7]] }\nassert my_solution.maximizeTheProfit(**test_input) == 17\n\ntest_input = { \"n\": 5, \"offers\": [[0,0,5],[1,3,9],[0,2,2],[1,1,6],[1,2,10],[0,2,10],[1,1,3]] }\nassert my_solution.maximizeTheProfit(**test_input) == 15\n\ntest_input = { \"n\": 10, \"offers\": [[0,1,9],[5,6,10],[1,3,8],[1,9,7],[7,8,1],[2,7,1],[0,8,7],[1,6,6],[1,4,4],[0,5,4],[0,0,3],[0,8,6]] }\nassert my_solution.maximizeTheProfit(**test_input) == 22\n\ntest_input = { \"n\": 4, \"offers\": [[0,0,1],[0,0,10],[0,2,1],[0,0,6],[0,3,10],[0,1,5],[1,2,10],[0,0,2],[3,3,1],[0,0,9],[0,1,2],[0,0,4],[1,3,5],[1,1,1]] }\nassert my_solution.maximizeTheProfit(**test_input) == 21\n\ntest_input = { \"n\": 9, \"offers\": [[0,3,10],[5,6,5],[1,5,2],[1,8,9],[1,1,9],[1,7,1],[3,7,9],[2,3,2],[4,6,1],[4,5,7],[2,2,2],[6,8,10],[1,3,10],[1,4,10]] }\nassert my_solution.maximizeTheProfit(**test_input) == 28\n\ntest_input = { \"n\": 10, \"offers\": [[0,2,2]] }\nassert my_solution.maximizeTheProfit(**test_input) == 2\n\ntest_input = { \"n\": 10, \"offers\": [[2,7,4],[2,4,9],[1,8,7],[0,4,3]] }\nassert my_solution.maximizeTheProfit(**test_input) == 9\n\ntest_input = { \"n\": 6, \"offers\": [[0,1,4],[1,2,4],[0,1,10],[1,2,4],[2,2,5],[1,1,8],[2,3,2],[4,4,4],[0,0,3]] }\nassert my_solution.maximizeTheProfit(**test_input) == 20\n\ntest_input = { \"n\": 1, \"offers\": [[0,0,8],[0,0,3],[0,0,8],[0,0,8],[0,0,5],[0,0,9],[0,0,6],[0,0,1],[0,0,8],[0,0,1],[0,0,5],[0,0,9],[0,0,2]] }\nassert my_solution.maximizeTheProfit(**test_input) == 9\n\ntest_input = { \"n\": 15, \"offers\": [[8,10,5],[4,12,6],[6,11,7],[8,11,3],[7,13,1],[7,7,8],[8,10,5],[0,11,3],[1,1,9],[2,11,6],[3,11,8]] }\nassert my_solution.maximizeTheProfit(**test_input) == 22\n\ntest_input = { \"n\": 10, \"offers\": [[5,6,9],[0,2,9]] }\nassert my_solution.maximizeTheProfit(**test_input) == 18\n\ntest_input = { \"n\": 11, \"offers\": [[7,9,5],[0,0,8],[6,6,3],[4,9,1],[3,7,5],[0,4,7]] }\nassert my_solution.maximizeTheProfit(**test_input) == 16\n\ntest_input = { \"n\": 7, \"offers\": [[0,2,9],[2,4,8],[0,3,6],[4,4,10],[2,2,2],[1,1,10],[0,0,8],[4,4,9],[4,4,4],[3,3,5],[2,5,2],[0,3,6],[3,4,5]] }\nassert my_solution.maximizeTheProfit(**test_input) == 35\n\ntest_input = { \"n\": 9, \"offers\": [[3,8,1],[0,6,7],[0,3,6],[1,6,2],[2,3,10],[3,3,2],[1,2,2],[1,3,9],[0,0,7],[1,2,9],[5,5,4],[5,6,6],[1,5,5],[0,1,2],[0,6,1]] }\nassert my_solution.maximizeTheProfit(**test_input) == 24\n\ntest_input = { \"n\": 8, \"offers\": [[0,0,7],[0,1,8],[1,1,1],[2,2,7],[2,3,1]] }\nassert my_solution.maximizeTheProfit(**test_input) == 15\n\ntest_input = { \"n\": 8, \"offers\": [[6,6,5],[0,1,7],[1,7,10]] }\nassert my_solution.maximizeTheProfit(**test_input) == 12\n\ntest_input = { \"n\": 13, \"offers\": [[0,9,5],[6,8,7],[0,0,3],[4,4,2],[1,9,7],[9,12,9],[1,2,9],[1,1,10],[3,3,3],[0,3,3],[4,8,5],[0,0,9],[7,10,7]] }\nassert my_solution.maximizeTheProfit(**test_input) == 40\n\ntest_input = { \"n\": 11, \"offers\": [[2,5,1]] }\nassert my_solution.maximizeTheProfit(**test_input) == 1\n\ntest_input = { \"n\": 3, \"offers\": [[0,0,9],[0,2,6],[1,1,1],[1,2,10],[0,0,10],[0,0,4],[0,2,7],[0,0,1],[0,0,9],[2,2,5]] }\nassert my_solution.maximizeTheProfit(**test_input) == 20\n\ntest_input = { \"n\": 5, \"offers\": [[1,1,3],[1,2,1],[0,2,3],[1,1,10],[3,3,3],[2,4,3],[0,3,5],[4,4,2],[2,3,10],[3,3,8],[3,3,9],[0,2,8],[0,2,2],[1,1,3],[0,0,8]] }\nassert my_solution.maximizeTheProfit(**test_input) == 30\n\ntest_input = { \"n\": 13, \"offers\": [[6,9,3],[6,9,6],[5,12,10],[11,12,4],[4,4,2],[0,7,8],[2,6,6],[6,6,4]] }\nassert my_solution.maximizeTheProfit(**test_input) == 12\n\ntest_input = { \"n\": 3, \"offers\": [[0,2,9],[1,1,8],[0,1,1],[2,2,4],[2,2,1],[0,0,4],[1,1,9],[0,0,6],[0,1,7]] }\nassert my_solution.maximizeTheProfit(**test_input) == 19\n\ntest_input = { \"n\": 3, \"offers\": [[1,2,8],[0,0,1],[0,1,1],[0,0,3],[1,2,2],[0,0,7],[0,0,10],[1,1,6]] }\nassert my_solution.maximizeTheProfit(**test_input) == 18\n\ntest_input = { \"n\": 2, \"offers\": [[0,0,3],[1,1,10],[0,1,6]] }\nassert my_solution.maximizeTheProfit(**test_input) == 13\n\ntest_input = { \"n\": 3, \"offers\": [[0,0,9],[1,1,1],[0,2,7],[1,1,7],[1,2,6],[0,0,8],[0,2,3],[1,2,10],[2,2,3],[2,2,5]] }\nassert my_solution.maximizeTheProfit(**test_input) == 21\n\ntest_input = { \"n\": 5, \"offers\": [[2,3,2],[0,1,7],[0,1,1],[0,0,9],[2,4,1],[3,4,5],[1,3,10],[0,0,8]] }\nassert my_solution.maximizeTheProfit(**test_input) == 19\n\ntest_input = { \"n\": 15, \"offers\": [[4,6,9],[4,10,9],[3,5,4],[0,2,6],[3,13,7],[1,11,6],[1,8,4],[4,12,4],[3,8,8],[13,13,7],[4,12,3]] }\nassert my_solution.maximizeTheProfit(**test_input) == 22\n\ntest_input = { \"n\": 8, \"offers\": [[1,5,9],[0,4,9],[0,0,3],[1,2,9],[0,0,10],[4,7,9],[7,7,2],[0,2,6],[1,1,5],[1,4,3],[2,4,8],[0,1,1],[2,3,1]] }\nassert my_solution.maximizeTheProfit(**test_input) == 28\n\ntest_input = { \"n\": 4, \"offers\": [[0,2,7],[2,3,9],[2,3,2],[1,2,1],[1,2,9],[0,3,7],[0,2,9],[1,2,8],[0,3,10],[0,3,8],[0,0,5],[2,2,6]] }\nassert my_solution.maximizeTheProfit(**test_input) == 14\n\ntest_input = { \"n\": 12, \"offers\": [[0,0,4],[5,8,2],[2,2,10],[3,5,7],[1,2,1],[5,7,8],[8,11,3]] }\nassert my_solution.maximizeTheProfit(**test_input) == 25\n\ntest_input = { \"n\": 2, \"offers\": [[0,0,7],[0,1,3],[0,0,8]] }\nassert my_solution.maximizeTheProfit(**test_input) == 8\n\ntest_input = { \"n\": 4, \"offers\": [[2,3,8],[0,1,1],[3,3,2]] }\nassert my_solution.maximizeTheProfit(**test_input) == 9\n\ntest_input = { \"n\": 14, \"offers\": [[2,12,4],[7,11,4],[4,4,5],[0,1,6],[3,4,1],[4,11,9],[10,12,7],[7,12,1],[11,11,1],[0,0,5],[12,12,8],[6,7,6]] }\nassert my_solution.maximizeTheProfit(**test_input) == 26\n\ntest_input = { \"n\": 10, \"offers\": [[1,4,6],[7,9,9],[1,4,5],[8,8,2],[4,7,1],[6,8,8],[2,3,1],[0,1,4]] }\nassert my_solution.maximizeTheProfit(**test_input) == 15\n\ntest_input = { \"n\": 7, \"offers\": [[2,5,5],[1,2,9],[1,3,7],[2,4,3],[0,0,6],[0,0,1],[4,4,9],[1,5,7],[2,2,10]] }\nassert my_solution.maximizeTheProfit(**test_input) == 25\n\ntest_input = { \"n\": 11, \"offers\": [[0,4,10]] }\nassert my_solution.maximizeTheProfit(**test_input) == 10\n\ntest_input = { \"n\": 3, \"offers\": [[0,1,10],[1,2,2],[0,2,6],[0,0,1],[0,0,3],[0,1,8],[0,0,2],[2,2,8],[0,0,3],[2,2,3],[1,2,6],[0,0,4],[1,2,5]] }\nassert my_solution.maximizeTheProfit(**test_input) == 18\n\ntest_input = { \"n\": 14, \"offers\": [[11,11,4],[1,11,10],[11,12,2],[7,8,2]] }\nassert my_solution.maximizeTheProfit(**test_input) == 10\n\ntest_input = { \"n\": 2, \"offers\": [[0,0,1],[0,0,1],[1,1,9],[0,0,1],[1,1,2],[0,1,10]] }\nassert my_solution.maximizeTheProfit(**test_input) == 10\n\ntest_input = { \"n\": 6, \"offers\": [[0,5,6],[1,2,10],[0,2,4],[2,4,5],[4,4,6],[2,2,2],[0,0,7],[2,5,9],[2,2,3]] }\nassert my_solution.maximizeTheProfit(**test_input) == 23\n\ntest_input = { \"n\": 6, \"offers\": [[0,0,7],[2,5,5]] }\nassert my_solution.maximizeTheProfit(**test_input) == 12\n\ntest_input = { \"n\": 10, \"offers\": [[2,3,2],[0,1,6],[0,0,2],[1,1,5],[3,3,8],[2,8,7],[1,7,8],[0,1,4],[7,7,8],[1,3,7],[5,5,10],[2,6,6],[0,0,4],[5,7,4],[1,9,4]] }\nassert my_solution.maximizeTheProfit(**test_input) == 35\n\ntest_input = { \"n\": 10, \"offers\": [[0,2,4],[1,4,7],[0,1,10],[0,5,1]] }\nassert my_solution.maximizeTheProfit(**test_input) == 10\n\ntest_input = { \"n\": 12, \"offers\": [[0,5,6],[4,10,9],[7,11,10],[10,11,1],[6,10,1],[2,2,6]] }\nassert my_solution.maximizeTheProfit(**test_input) == 16\n\ntest_input = { \"n\": 11, \"offers\": [[3,7,8],[2,7,10],[3,9,3]] }\nassert my_solution.maximizeTheProfit(**test_input) == 10\n\ntest_input = { \"n\": 4, \"offers\": [[0,0,3],[0,2,6],[0,0,1],[1,1,2],[0,2,8],[1,1,3],[1,3,8],[1,1,10],[1,2,7],[1,1,8],[0,0,9]] }\nassert my_solution.maximizeTheProfit(**test_input) == 19\n\ntest_input = { \"n\": 1, \"offers\": [[0,0,9]] }\nassert my_solution.maximizeTheProfit(**test_input) == 9\n\ntest_input = { \"n\": 3, \"offers\": [[0,1,5],[0,0,5],[0,0,6],[0,1,6],[0,2,10],[1,2,6],[0,0,9],[1,2,9]] }\nassert my_solution.maximizeTheProfit(**test_input) == 18\n\ntest_input = { \"n\": 4, \"offers\": [[0,0,2],[2,3,9],[0,1,8],[0,0,9],[0,0,1],[3,3,9],[1,2,1],[1,3,5],[0,1,4],[0,1,4]] }\nassert my_solution.maximizeTheProfit(**test_input) == 19\n\ntest_input = { \"n\": 3, \"offers\": [[0,0,7],[2,2,1],[1,1,3],[0,0,3],[1,1,7],[0,1,5],[0,2,3],[1,1,5],[0,1,10],[1,1,5],[1,1,6],[0,1,3],[0,0,8],[1,2,7],[1,1,4]] }\nassert my_solution.maximizeTheProfit(**test_input) == 16\n\ntest_input = { \"n\": 14, \"offers\": [[5,7,2],[1,5,3],[11,13,2],[12,12,5],[4,5,6],[5,10,2],[4,10,8],[1,1,4],[4,4,2],[3,7,9],[5,10,1],[0,3,2]] }\nassert my_solution.maximizeTheProfit(**test_input) == 18\n\ntest_input = { \"n\": 11, \"offers\": [[1,1,5],[4,4,9],[0,0,1],[1,3,3],[3,7,4],[3,9,6],[7,10,2],[3,7,5],[4,4,8],[7,8,10],[1,3,7],[1,4,5],[0,0,10]] }\nassert my_solution.maximizeTheProfit(**test_input) == 36\n\ntest_input = { \"n\": 13, \"offers\": [[4,9,9],[1,9,8],[1,9,8],[0,0,8],[8,11,3],[2,3,6],[9,9,10],[5,12,1],[4,6,4]] }\nassert my_solution.maximizeTheProfit(**test_input) == 28\n\ntest_input = { \"n\": 5, \"offers\": [[2,2,7],[0,2,10],[2,3,10]] }\nassert my_solution.maximizeTheProfit(**test_input) == 10\n\ntest_input = { \"n\": 10, \"offers\": [[0,4,6],[1,1,1],[0,5,1],[1,6,3],[8,9,1],[2,3,7],[2,3,10],[1,2,1],[0,0,8],[3,5,5],[0,0,10]] }\nassert my_solution.maximizeTheProfit(**test_input) == 22\n\ntest_input = { \"n\": 4, \"offers\": [[0,1,1],[0,0,9],[1,1,8],[3,3,1],[1,1,5],[0,0,9],[0,1,9],[0,0,7],[2,2,2],[2,3,5],[1,1,10],[1,2,8]] }\nassert my_solution.maximizeTheProfit(**test_input) == 24\n\ntest_input = { \"n\": 7, \"offers\": [[0,1,9],[0,1,4],[0,0,3],[0,0,1],[1,6,5],[4,6,9],[4,5,7],[0,0,3],[1,5,9],[0,2,2]] }\nassert my_solution.maximizeTheProfit(**test_input) == 18\n\ntest_input = { \"n\": 12, \"offers\": [[8,8,6],[8,8,6],[1,10,7],[0,0,3],[9,10,7],[1,7,2],[1,1,1],[2,3,6],[0,11,1],[1,8,5],[1,5,7],[1,2,4],[9,9,5],[0,3,1]] }\nassert my_solution.maximizeTheProfit(**test_input) == 23\n\ntest_input = { \"n\": 15, \"offers\": [[5,6,3],[2,2,7],[0,0,5],[1,7,10],[11,14,5],[13,14,1],[2,12,1],[0,4,5],[0,6,2],[6,9,10],[3,5,2],[0,1,1],[1,14,1],[1,6,1]] }\nassert my_solution.maximizeTheProfit(**test_input) == 29\n\ntest_input = { \"n\": 7, \"offers\": [[1,1,5],[1,1,4],[0,0,9],[1,1,6],[0,6,4],[2,6,3],[2,5,9],[0,6,3],[0,2,1],[1,1,6],[4,5,5]] }\nassert my_solution.maximizeTheProfit(**test_input) == 24\n\ntest_input = { \"n\": 1, \"offers\": [[0,0,5],[0,0,3],[0,0,4],[0,0,8],[0,0,10],[0,0,6],[0,0,7],[0,0,7],[0,0,7],[0,0,3],[0,0,4],[0,0,5]] }\nassert my_solution.maximizeTheProfit(**test_input) == 10\n\ntest_input = { \"n\": 7, \"offers\": [[2,2,3],[2,6,4],[4,6,5],[0,0,4],[1,1,4],[2,3,1],[2,4,3],[0,2,8],[1,3,10],[1,3,2],[1,6,7],[0,6,9],[2,2,2],[1,1,9],[4,4,2]] }\nassert my_solution.maximizeTheProfit(**test_input) == 21\n\ntest_input = { \"n\": 12, \"offers\": [[0,0,7],[0,2,3],[0,7,2],[2,3,1],[2,11,6],[2,10,2],[1,3,6],[4,7,9],[7,9,3],[4,6,1],[5,6,8],[0,2,4],[0,0,3],[5,5,9],[2,5,3]] }\nassert my_solution.maximizeTheProfit(**test_input) == 25\n\ntest_input = { \"n\": 9, \"offers\": [[1,8,4],[5,6,5],[0,2,6],[4,5,4]] }\nassert my_solution.maximizeTheProfit(**test_input) == 11\n\ntest_input = { \"n\": 8, \"offers\": [[0,4,6],[2,3,6],[2,5,9],[2,6,7],[6,6,5],[4,4,4],[1,1,5],[2,5,7]] }\nassert my_solution.maximizeTheProfit(**test_input) == 20\n\ntest_input = { \"n\": 13, \"offers\": [[0,6,10]] }\nassert my_solution.maximizeTheProfit(**test_input) == 10\n\ntest_input = { \"n\": 6, \"offers\": [[0,1,2],[0,0,9],[3,3,10],[0,3,7],[0,0,2],[0,0,3],[2,2,2],[2,3,2],[5,5,6],[0,1,2],[0,5,2]] }\nassert my_solution.maximizeTheProfit(**test_input) == 27\n\ntest_input = { \"n\": 14, \"offers\": [[3,12,7],[1,3,2],[4,11,3],[0,1,7],[1,5,2],[1,1,4]] }\nassert my_solution.maximizeTheProfit(**test_input) == 14\n\ntest_input = { \"n\": 14, \"offers\": [[0,0,3],[0,1,3],[1,11,3],[6,7,6],[7,7,5],[1,2,8],[7,10,9]] }\nassert my_solution.maximizeTheProfit(**test_input) == 20\n\ntest_input = { \"n\": 13, \"offers\": [[0,12,7],[2,2,4],[2,2,8],[3,3,2],[1,11,5],[1,7,2]] }\nassert my_solution.maximizeTheProfit(**test_input) == 10\n\ntest_input = { \"n\": 1, \"offers\": [[0,0,2],[0,0,8],[0,0,1]] }\nassert my_solution.maximizeTheProfit(**test_input) == 8\n\ntest_input = { \"n\": 1, \"offers\": [[0,0,1],[0,0,4],[0,0,7],[0,0,2],[0,0,5],[0,0,1],[0,0,4],[0,0,2],[0,0,6],[0,0,6],[0,0,3],[0,0,3]] }\nassert my_solution.maximizeTheProfit(**test_input) == 7\n\ntest_input = { \"n\": 1, \"offers\": [[0,0,6],[0,0,6],[0,0,3],[0,0,6],[0,0,6],[0,0,10],[0,0,1],[0,0,2]] }\nassert my_solution.maximizeTheProfit(**test_input) == 10\n\ntest_input = { \"n\": 9, \"offers\": [[4,6,7],[1,3,10]] }\nassert my_solution.maximizeTheProfit(**test_input) == 17\n\ntest_input = { \"n\": 13, \"offers\": [[2,6,3],[1,12,6],[2,11,3],[7,7,2],[5,12,4],[0,1,2],[0,1,8],[1,1,3],[6,6,4],[8,9,7],[8,8,2],[2,2,2],[0,0,9],[9,11,7],[8,9,7]] }\nassert my_solution.maximizeTheProfit(**test_input) == 29\n\ntest_input = { \"n\": 8, \"offers\": [[0,1,8],[0,0,6],[5,5,9]] }\nassert my_solution.maximizeTheProfit(**test_input) == 17\n\ntest_input = { \"n\": 1, \"offers\": [[0,0,10],[0,0,3],[0,0,8],[0,0,9],[0,0,1],[0,0,8],[0,0,2],[0,0,7],[0,0,10],[0,0,8],[0,0,5],[0,0,3],[0,0,2],[0,0,4]] }\nassert my_solution.maximizeTheProfit(**test_input) == 10\n\ntest_input = { \"n\": 9, \"offers\": [[0,2,6],[1,3,5],[1,1,5],[2,3,10],[4,8,4],[5,8,5],[6,6,10]] }\nassert my_solution.maximizeTheProfit(**test_input) == 25\n\ntest_input = { \"n\": 6, \"offers\": [[0,0,7]] }\nassert my_solution.maximizeTheProfit(**test_input) == 7\n\ntest_input = { \"n\": 8, \"offers\": [[1,1,5],[1,2,9],[1,2,6],[0,3,6],[1,1,10],[3,4,1],[3,5,3],[1,5,8],[0,2,6],[5,7,9]] }\nassert my_solution.maximizeTheProfit(**test_input) == 20\n\ntest_input = { \"n\": 14, \"offers\": [[3,4,4],[6,8,1],[0,4,1]] }\nassert my_solution.maximizeTheProfit(**test_input) == 5\n\ntest_input = { \"n\": 11, \"offers\": [[4,4,2],[1,2,7],[2,8,10],[1,1,3],[8,10,4],[1,2,1],[4,6,10]] }\nassert my_solution.maximizeTheProfit(**test_input) == 21\n\ntest_input = { \"n\": 11, \"offers\": [[1,8,1],[1,5,5],[0,1,3],[10,10,10],[1,1,8],[1,2,1],[2,3,10],[2,10,10],[2,2,9],[0,9,4]] }\nassert my_solution.maximizeTheProfit(**test_input) == 28\n\ntest_input = { \"n\": 6, \"offers\": [[2,2,6],[0,1,2],[2,2,2]] }\nassert my_solution.maximizeTheProfit(**test_input) == 8", "start_time": 1692498600} +{"task_id": "weekly-contest-359-find-the-longest-equal-subarray", "url": "https://leetcode.com/problems/find-the-longest-equal-subarray", "title": "find-the-longest-equal-subarray", "meta": {"questionId": "2832", "questionFrontendId": "2831", "title": "Find the Longest Equal Subarray", "titleSlug": "find-the-longest-equal-subarray", "isPaidOnly": false, "difficulty": "Medium", "likes": 579, "dislikes": 14, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed integer array nums and an integer k.\n\nA subarray is called equal if all of its elements are equal. Note that the empty subarray is an equal subarray.\n\nReturn the length of the longest possible equal subarray after deleting at most k elements from nums.\n\nA subarray is a contiguous, possibly empty sequence of elements within an array.\n\nExample 1:\n\nInput: nums = [1,3,2,3,1,3], k = 3\nOutput: 3\nExplanation: It's optimal to delete the elements at index 2 and index 4.\nAfter deleting them, nums becomes equal to [1, 3, 3, 3].\nThe longest equal subarray starts at i = 1 and ends at j = 3 with length equal to 3.\nIt can be proven that no longer equal subarrays can be created.\n\nExample 2:\n\nInput: nums = [1,1,2,2,1,1], k = 2\nOutput: 4\nExplanation: It's optimal to delete the elements at index 2 and index 3.\nAfter deleting them, nums becomes equal to [1, 1, 1, 1].\nThe array itself is an equal subarray, so the answer is 4.\nIt can be proven that no longer equal subarrays can be created.\n\n\nConstraints:\n\n * 1 <= nums.length <= 105\n * 1 <= nums[i] <= nums.length\n * 0 <= k <= nums.length\n\"\"\"\nclass Solution:\n def longestEqualSubarray(self, nums: List[int], k: int) -> int:\n ", "prompt_sft": "You are given a 0-indexed integer array nums and an integer k.\n\nA subarray is called equal if all of its elements are equal. Note that the empty subarray is an equal subarray.\n\nReturn the length of the longest possible equal subarray after deleting at most k elements from nums.\n\nA subarray is a contiguous, possibly empty sequence of elements within an array.\n\nExample 1:\n\nInput: nums = [1,3,2,3,1,3], k = 3\nOutput: 3\nExplanation: It's optimal to delete the elements at index 2 and index 4.\nAfter deleting them, nums becomes equal to [1, 3, 3, 3].\nThe longest equal subarray starts at i = 1 and ends at j = 3 with length equal to 3.\nIt can be proven that no longer equal subarrays can be created.\n\nExample 2:\n\nInput: nums = [1,1,2,2,1,1], k = 2\nOutput: 4\nExplanation: It's optimal to delete the elements at index 2 and index 3.\nAfter deleting them, nums becomes equal to [1, 1, 1, 1].\nThe array itself is an equal subarray, so the answer is 4.\nIt can be proven that no longer equal subarrays can be created.\n\n\nConstraints:\n\n * 1 <= nums.length <= 105\n * 1 <= nums[i] <= nums.length\n * 0 <= k <= nums.length\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def longestEqualSubarray(self, nums: List[int], k: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,3,2,3,1,3], \"k\": 3 }\nassert my_solution.longestEqualSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,2,2,1,1], \"k\": 2 }\nassert my_solution.longestEqualSubarray(**test_input) == 4\n\ntest_input = { \"nums\": [1], \"k\": 0 }\nassert my_solution.longestEqualSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [1], \"k\": 1 }\nassert my_solution.longestEqualSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [2,1], \"k\": 1 }\nassert my_solution.longestEqualSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [2,2], \"k\": 1 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [1,1], \"k\": 0 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [2,1], \"k\": 0 }\nassert my_solution.longestEqualSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [1,2], \"k\": 1 }\nassert my_solution.longestEqualSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [2,2], \"k\": 2 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [2,3,2], \"k\": 1 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [3,2,2], \"k\": 1 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [3,1,1], \"k\": 2 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [1,2,3], \"k\": 2 }\nassert my_solution.longestEqualSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,3], \"k\": 3 }\nassert my_solution.longestEqualSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [2,3,1], \"k\": 2 }\nassert my_solution.longestEqualSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [2,2,1], \"k\": 1 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [1,3,2], \"k\": 3 }\nassert my_solution.longestEqualSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [2,3,3], \"k\": 3 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [3,2,3], \"k\": 3 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [2,2,3], \"k\": 0 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [2,2,2], \"k\": 1 }\nassert my_solution.longestEqualSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,1], \"k\": 0 }\nassert my_solution.longestEqualSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [3,3,3], \"k\": 2 }\nassert my_solution.longestEqualSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,2], \"k\": 1 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,3], \"k\": 1 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [1,2,3], \"k\": 1 }\nassert my_solution.longestEqualSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,2], \"k\": 3 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [3,2,4,2], \"k\": 1 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [3,4,2,1], \"k\": 0 }\nassert my_solution.longestEqualSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [1,3,4,2], \"k\": 0 }\nassert my_solution.longestEqualSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [2,4,2,2], \"k\": 3 }\nassert my_solution.longestEqualSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [4,2,2,3], \"k\": 1 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [4,1,3,2], \"k\": 4 }\nassert my_solution.longestEqualSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,2,1], \"k\": 4 }\nassert my_solution.longestEqualSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [2,4,1,3], \"k\": 3 }\nassert my_solution.longestEqualSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,1,2], \"k\": 3 }\nassert my_solution.longestEqualSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [4,2,1,4], \"k\": 4 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,4,1], \"k\": 4 }\nassert my_solution.longestEqualSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [2,1,4,1], \"k\": 4 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [2,4,3,3], \"k\": 2 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [1,2,2,4], \"k\": 3 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [2,2,2,4], \"k\": 3 }\nassert my_solution.longestEqualSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [2,3,3,1], \"k\": 3 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [2,4,1,4], \"k\": 1 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [3,4,1,4], \"k\": 2 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [3,2,3,1], \"k\": 3 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [3,1,1,3], \"k\": 3 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [2,3,2,5,1], \"k\": 0 }\nassert my_solution.longestEqualSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [5,3,3,1,3], \"k\": 3 }\nassert my_solution.longestEqualSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [4,4,2,2,4], \"k\": 1 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [5,4,2,3,3], \"k\": 5 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [4,4,4,3,4], \"k\": 1 }\nassert my_solution.longestEqualSubarray(**test_input) == 4\n\ntest_input = { \"nums\": [1,5,5,5,3], \"k\": 2 }\nassert my_solution.longestEqualSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [2,1,4,5,2], \"k\": 1 }\nassert my_solution.longestEqualSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [5,1,5,2,3], \"k\": 3 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [5,3,2,3,4], \"k\": 1 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [3,2,1,4,1], \"k\": 0 }\nassert my_solution.longestEqualSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [3,2,2,5,3], \"k\": 5 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [2,2,4,4,2], \"k\": 1 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [4,3,3,4,3], \"k\": 2 }\nassert my_solution.longestEqualSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [1,5,4,3,4], \"k\": 0 }\nassert my_solution.longestEqualSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [4,4,2,5,3], \"k\": 0 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [3,3,5,2,3], \"k\": 4 }\nassert my_solution.longestEqualSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,1,1,3], \"k\": 5 }\nassert my_solution.longestEqualSubarray(**test_input) == 4\n\ntest_input = { \"nums\": [1,3,2,5,1], \"k\": 1 }\nassert my_solution.longestEqualSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [3,3,1,4,5], \"k\": 2 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [1,2,5,5,4], \"k\": 3 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [3,1,5,3,1,1], \"k\": 0 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [6,4,1,5,5,3], \"k\": 0 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [2,2,2,1,2,4], \"k\": 4 }\nassert my_solution.longestEqualSubarray(**test_input) == 4\n\ntest_input = { \"nums\": [1,1,2,2,6,2], \"k\": 1 }\nassert my_solution.longestEqualSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,3,6,6,2], \"k\": 4 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [2,4,5,1,4,1], \"k\": 2 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [1,5,6,4,6,3], \"k\": 3 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [5,4,2,4,1,3], \"k\": 2 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [2,1,1,3,1,3], \"k\": 2 }\nassert my_solution.longestEqualSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [2,4,6,6,6,4], \"k\": 3 }\nassert my_solution.longestEqualSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [3,6,2,5,4,5], \"k\": 1 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,5,6,1,4], \"k\": 4 }\nassert my_solution.longestEqualSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [4,6,6,6,2,4], \"k\": 3 }\nassert my_solution.longestEqualSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [2,5,5,5,6,4], \"k\": 1 }\nassert my_solution.longestEqualSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [2,3,3,2,3,3], \"k\": 2 }\nassert my_solution.longestEqualSubarray(**test_input) == 4\n\ntest_input = { \"nums\": [5,2,5,3,3,2], \"k\": 6 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [3,5,3,2,3,6], \"k\": 6 }\nassert my_solution.longestEqualSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [4,3,2,5,4,2], \"k\": 4 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [1,2,4,2,1,3], \"k\": 3 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [3,1,3,4,1,6], \"k\": 6 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [2,3,7,7,3,2,2], \"k\": 7 }\nassert my_solution.longestEqualSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [5,6,7,7,4,4,2], \"k\": 5 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [7,2,4,1,3,3,4], \"k\": 4 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [5,3,1,7,5,5,7], \"k\": 6 }\nassert my_solution.longestEqualSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [4,2,6,2,3,4,6], \"k\": 6 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [2,7,6,7,3,7,4], \"k\": 5 }\nassert my_solution.longestEqualSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [3,2,5,1,4,3,4], \"k\": 4 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [2,3,3,7,2,5,1], \"k\": 2 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [4,1,6,7,5,3,5], \"k\": 1 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [3,1,4,1,5,5,6], \"k\": 6 }\nassert my_solution.longestEqualSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [1,5,5,7,7,7,4], \"k\": 0 }\nassert my_solution.longestEqualSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [5,7,4,4,1,6,7], \"k\": 5 }\nassert my_solution.longestEqualSubarray(**test_input) == 2", "start_time": 1692498600} +{"task_id": "biweekly-contest-111-count-pairs-whose-sum-is-less-than-target", "url": "https://leetcode.com/problems/count-pairs-whose-sum-is-less-than-target", "title": "count-pairs-whose-sum-is-less-than-target", "meta": {"questionId": "2917", "questionFrontendId": "2824", "title": "Count Pairs Whose Sum is Less than Target", "titleSlug": "count-pairs-whose-sum-is-less-than-target", "isPaidOnly": false, "difficulty": "Easy", "likes": 358, "dislikes": 23, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nGiven a 0-indexed integer array nums of length n and an integer target, return the number of pairs (i, j) where 0 <= i < j < n and nums[i] + nums[j] < target.\n\nExample 1:\n\nInput: nums = [-1,1,2,3,1], target = 2\nOutput: 3\nExplanation: There are 3 pairs of indices that satisfy the conditions in the statement:\n- (0, 1) since 0 < 1 and nums[0] + nums[1] = 0 < target\n- (0, 2) since 0 < 2 and nums[0] + nums[2] = 1 < target\n- (0, 4) since 0 < 4 and nums[0] + nums[4] = 0 < target\nNote that (0, 3) is not counted since nums[0] + nums[3] is not strictly less than the target.\n\nExample 2:\n\nInput: nums = [-6,2,5,-2,-7,-1,3], target = -2\nOutput: 10\nExplanation: There are 10 pairs of indices that satisfy the conditions in the statement:\n- (0, 1) since 0 < 1 and nums[0] + nums[1] = -4 < target\n- (0, 3) since 0 < 3 and nums[0] + nums[3] = -8 < target\n- (0, 4) since 0 < 4 and nums[0] + nums[4] = -13 < target\n- (0, 5) since 0 < 5 and nums[0] + nums[5] = -7 < target\n- (0, 6) since 0 < 6 and nums[0] + nums[6] = -3 < target\n- (1, 4) since 1 < 4 and nums[1] + nums[4] = -5 < target\n- (3, 4) since 3 < 4 and nums[3] + nums[4] = -9 < target\n- (3, 5) since 3 < 5 and nums[3] + nums[5] = -3 < target\n- (4, 5) since 4 < 5 and nums[4] + nums[5] = -8 < target\n- (4, 6) since 4 < 6 and nums[4] + nums[6] = -4 < target\n\n\nConstraints:\n\n * 1 <= nums.length == n <= 50\n * -50 <= nums[i], target <= 50\n\"\"\"\nclass Solution:\n def countPairs(self, nums: List[int], target: int) -> int:\n ", "prompt_sft": "Given a 0-indexed integer array nums of length n and an integer target, return the number of pairs (i, j) where 0 <= i < j < n and nums[i] + nums[j] < target.\n\nExample 1:\n\nInput: nums = [-1,1,2,3,1], target = 2\nOutput: 3\nExplanation: There are 3 pairs of indices that satisfy the conditions in the statement:\n- (0, 1) since 0 < 1 and nums[0] + nums[1] = 0 < target\n- (0, 2) since 0 < 2 and nums[0] + nums[2] = 1 < target\n- (0, 4) since 0 < 4 and nums[0] + nums[4] = 0 < target\nNote that (0, 3) is not counted since nums[0] + nums[3] is not strictly less than the target.\n\nExample 2:\n\nInput: nums = [-6,2,5,-2,-7,-1,3], target = -2\nOutput: 10\nExplanation: There are 10 pairs of indices that satisfy the conditions in the statement:\n- (0, 1) since 0 < 1 and nums[0] + nums[1] = -4 < target\n- (0, 3) since 0 < 3 and nums[0] + nums[3] = -8 < target\n- (0, 4) since 0 < 4 and nums[0] + nums[4] = -13 < target\n- (0, 5) since 0 < 5 and nums[0] + nums[5] = -7 < target\n- (0, 6) since 0 < 6 and nums[0] + nums[6] = -3 < target\n- (1, 4) since 1 < 4 and nums[1] + nums[4] = -5 < target\n- (3, 4) since 3 < 4 and nums[3] + nums[4] = -9 < target\n- (3, 5) since 3 < 5 and nums[3] + nums[5] = -3 < target\n- (4, 5) since 4 < 5 and nums[4] + nums[5] = -8 < target\n- (4, 6) since 4 < 6 and nums[4] + nums[6] = -4 < target\n\n\nConstraints:\n\n * 1 <= nums.length == n <= 50\n * -50 <= nums[i], target <= 50\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def countPairs(self, nums: List[int], target: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [-1,1,2,3,1], \"target\": 2 }\nassert my_solution.countPairs(**test_input) == 3\n\ntest_input = { \"nums\": [-6,2,5,-2,-7,-1,3], \"target\": -2 }\nassert my_solution.countPairs(**test_input) == 10\n\ntest_input = { \"nums\": [9,-5,-5,5,-5,-4,-6,6,-6], \"target\": 3 }\nassert my_solution.countPairs(**test_input) == 27\n\ntest_input = { \"nums\": [-8,-5,5,-4,10], \"target\": 2 }\nassert my_solution.countPairs(**test_input) == 6\n\ntest_input = { \"nums\": [-5,0,-7,-1,9,8,-9,9], \"target\": -14 }\nassert my_solution.countPairs(**test_input) == 1\n\ntest_input = { \"nums\": [6,-1,7,4,2,3], \"target\": 8 }\nassert my_solution.countPairs(**test_input) == 8\n\ntest_input = { \"nums\": [2,8,2,8,7], \"target\": 10 }\nassert my_solution.countPairs(**test_input) == 3\n\ntest_input = { \"nums\": [-6,1,1,-1,-10,-7,1,-5,-4,0], \"target\": -15 }\nassert my_solution.countPairs(**test_input) == 2\n\ntest_input = { \"nums\": [10,-2,-1,7,8,5,3,-4,-9], \"target\": -10 }\nassert my_solution.countPairs(**test_input) == 2\n\ntest_input = { \"nums\": [3,8,-3,4,10,-6], \"target\": 1 }\nassert my_solution.countPairs(**test_input) == 4\n\ntest_input = { \"nums\": [-4,-6,-7,8], \"target\": -13 }\nassert my_solution.countPairs(**test_input) == 0\n\ntest_input = { \"nums\": [-4,0,10,8,-2], \"target\": 0 }\nassert my_solution.countPairs(**test_input) == 3\n\ntest_input = { \"nums\": [-8,-5,-3,1,-7], \"target\": -6 }\nassert my_solution.countPairs(**test_input) == 7\n\ntest_input = { \"nums\": [4,-8,-2,5,2,-9,6,5,-4], \"target\": -4 }\nassert my_solution.countPairs(**test_input) == 9\n\ntest_input = { \"nums\": [-1,-5,4,4,-10], \"target\": -6 }\nassert my_solution.countPairs(**test_input) == 2\n\ntest_input = { \"nums\": [-5,4,-6,-5,-10,-1,10,3], \"target\": 6 }\nassert my_solution.countPairs(**test_input) == 24\n\ntest_input = { \"nums\": [-9,6,-4,10,1,8], \"target\": 11 }\nassert my_solution.countPairs(**test_input) == 11\n\ntest_input = { \"nums\": [-10,-6,-8,-9,6,6,-6,-6,-3], \"target\": -2 }\nassert my_solution.countPairs(**test_input) == 25\n\ntest_input = { \"nums\": [-7,7,6,-9,-4,10,8,-8,2,2], \"target\": -1 }\nassert my_solution.countPairs(**test_input) == 17\n\ntest_input = { \"nums\": [0,-1,0,-6,-9], \"target\": -9 }\nassert my_solution.countPairs(**test_input) == 2\n\ntest_input = { \"nums\": [8,-10,-9,6,-3,5,-2,-2,-7], \"target\": -4 }\nassert my_solution.countPairs(**test_input) == 15\n\ntest_input = { \"nums\": [-1,3,8,3], \"target\": 2 }\nassert my_solution.countPairs(**test_input) == 0\n\ntest_input = { \"nums\": [7,2,9,-10,-4,4,-3,0], \"target\": -20 }\nassert my_solution.countPairs(**test_input) == 0\n\ntest_input = { \"nums\": [6,4,1,-7], \"target\": 7 }\nassert my_solution.countPairs(**test_input) == 4\n\ntest_input = { \"nums\": [3,8,6,-2,6,1,7], \"target\": 7 }\nassert my_solution.countPairs(**test_input) == 7\n\ntest_input = { \"nums\": [1,3,-10,5,-8,0,-5,-9], \"target\": -7 }\nassert my_solution.countPairs(**test_input) == 11\n\ntest_input = { \"nums\": [-6,9,2,4,-9,2,4,-6,6,-9], \"target\": 11 }\nassert my_solution.countPairs(**test_input) == 40\n\ntest_input = { \"nums\": [-10,-7,-5,-1,2,4,-6,6], \"target\": -3 }\nassert my_solution.countPairs(**test_input) == 15\n\ntest_input = { \"nums\": [-1,0,1,9,-2,-8,-8,7], \"target\": 1 }\nassert my_solution.countPairs(**test_input) == 16\n\ntest_input = { \"nums\": [1,9,3,2,9,-5,6,0,-6,6], \"target\": 9 }\nassert my_solution.countPairs(**test_input) == 29\n\ntest_input = { \"nums\": [-3,-3,-4,1,4,9], \"target\": 6 }\nassert my_solution.countPairs(**test_input) == 11\n\ntest_input = { \"nums\": [-10,3,-5,2,-10,7,9], \"target\": 4 }\nassert my_solution.countPairs(**test_input) == 14\n\ntest_input = { \"nums\": [7,10,9,8,-9,1,-7,10,-4,2], \"target\": 4 }\nassert my_solution.countPairs(**test_input) == 21\n\ntest_input = { \"nums\": [9,-9,0,5,4], \"target\": 14 }\nassert my_solution.countPairs(**test_input) == 9\n\ntest_input = { \"nums\": [7,9,7,-10,-6,-8,-5], \"target\": 2 }\nassert my_solution.countPairs(**test_input) == 14\n\ntest_input = { \"nums\": [8,-5,0,4], \"target\": 0 }\nassert my_solution.countPairs(**test_input) == 2\n\ntest_input = { \"nums\": [5,2,-1,9,-1,-1], \"target\": 4 }\nassert my_solution.countPairs(**test_input) == 6\n\ntest_input = { \"nums\": [-7,-4,3,9,10,5,-1,1,-7], \"target\": -4 }\nassert my_solution.countPairs(**test_input) == 8\n\ntest_input = { \"nums\": [0,8,9,-9,8,-2,-1,2,5], \"target\": -1 }\nassert my_solution.countPairs(**test_input) == 7\n\ntest_input = { \"nums\": [10,4,-9,8,-10,3], \"target\": -7 }\nassert my_solution.countPairs(**test_input) == 1\n\ntest_input = { \"nums\": [-6,-6,6,-4,-5,-1,10,-8,1], \"target\": -13 }\nassert my_solution.countPairs(**test_input) == 2\n\ntest_input = { \"nums\": [7,3,-4,1,-9,-8,10,4,-1], \"target\": -2 }\nassert my_solution.countPairs(**test_input) == 13\n\ntest_input = { \"nums\": [4,3,-3,1,-3,-1], \"target\": -2 }\nassert my_solution.countPairs(**test_input) == 3\n\ntest_input = { \"nums\": [10,-8,-9,-7,2,-10,4,7,6,6], \"target\": 14 }\nassert my_solution.countPairs(**test_input) == 41\n\ntest_input = { \"nums\": [9,-5,-4,-2,9], \"target\": 4 }\nassert my_solution.countPairs(**test_input) == 3\n\ntest_input = { \"nums\": [-1,2,-3,-4,-10,-8,2], \"target\": -1 }\nassert my_solution.countPairs(**test_input) == 16\n\ntest_input = { \"nums\": [-8,-9,-10,0,-5,-5], \"target\": -15 }\nassert my_solution.countPairs(**test_input) == 3\n\ntest_input = { \"nums\": [-8,9,-10,2,-10,-6,-1,-8], \"target\": -4 }\nassert my_solution.countPairs(**test_input) == 19\n\ntest_input = { \"nums\": [4,-7,8,7,-4,3,7,7,-2,-10], \"target\": 4 }\nassert my_solution.countPairs(**test_input) == 25\n\ntest_input = { \"nums\": [6,3,4,5,-4], \"target\": 0 }\nassert my_solution.countPairs(**test_input) == 1\n\ntest_input = { \"nums\": [2,-4,5,3,7,10,9,-1,9,0], \"target\": 9 }\nassert my_solution.countPairs(**test_input) == 23\n\ntest_input = { \"nums\": [-2,-5,9,-3,-8,5,-1,3,-9], \"target\": 1 }\nassert my_solution.countPairs(**test_input) == 23\n\ntest_input = { \"nums\": [0,-2,-3,-1,-6,-7,3], \"target\": -10 }\nassert my_solution.countPairs(**test_input) == 1\n\ntest_input = { \"nums\": [10,4,-3,9,-8,6], \"target\": 14 }\nassert my_solution.countPairs(**test_input) == 11\n\ntest_input = { \"nums\": [-10,-6,6,-7,1,-7,9,3,1], \"target\": 15 }\nassert my_solution.countPairs(**test_input) == 35\n\ntest_input = { \"nums\": [2,-3,-6,-2,5], \"target\": -4 }\nassert my_solution.countPairs(**test_input) == 3\n\ntest_input = { \"nums\": [-10,-8,8,-2], \"target\": 0 }\nassert my_solution.countPairs(**test_input) == 4\n\ntest_input = { \"nums\": [-2,2,-7,-5,1,6,8], \"target\": 0 }\nassert my_solution.countPairs(**test_input) == 9\n\ntest_input = { \"nums\": [4,-4,-5,-8,9], \"target\": -10 }\nassert my_solution.countPairs(**test_input) == 2\n\ntest_input = { \"nums\": [-5,-4,-6,-7,9,-10,0,4,9,-1], \"target\": -7 }\nassert my_solution.countPairs(**test_input) == 13\n\ntest_input = { \"nums\": [-10,-6,6,-3,10,-6,4,-8], \"target\": -9 }\nassert my_solution.countPairs(**test_input) == 8\n\ntest_input = { \"nums\": [-8,-1,-9,1], \"target\": -17 }\nassert my_solution.countPairs(**test_input) == 0\n\ntest_input = { \"nums\": [6,-4,2,1,10,-1], \"target\": 1 }\nassert my_solution.countPairs(**test_input) == 4\n\ntest_input = { \"nums\": [9,4,-8,8,9,-4], \"target\": -16 }\nassert my_solution.countPairs(**test_input) == 0\n\ntest_input = { \"nums\": [9,-4,8,-9,-2,-2], \"target\": -11 }\nassert my_solution.countPairs(**test_input) == 1\n\ntest_input = { \"nums\": [-7,1,3,7,6,3], \"target\": 10 }\nassert my_solution.countPairs(**test_input) == 12\n\ntest_input = { \"nums\": [10,10,-2,-4], \"target\": 8 }\nassert my_solution.countPairs(**test_input) == 3\n\ntest_input = { \"nums\": [-3,2,6,-6,9], \"target\": 3 }\nassert my_solution.countPairs(**test_input) == 4\n\ntest_input = { \"nums\": [5,0,2,4,2,-7], \"target\": 2 }\nassert my_solution.countPairs(**test_input) == 5\n\ntest_input = { \"nums\": [4,-5,-4,-2,-9,-6,-10,-10,2,-8], \"target\": -19 }\nassert my_solution.countPairs(**test_input) == 1\n\ntest_input = { \"nums\": [-10,10,-9,-2,3,-2,-7,-1,-6,7], \"target\": -17 }\nassert my_solution.countPairs(**test_input) == 1\n\ntest_input = { \"nums\": [-9,-9,3,7,-9,-10,2,3,-4], \"target\": -13 }\nassert my_solution.countPairs(**test_input) == 7\n\ntest_input = { \"nums\": [-5,-4,-10,7], \"target\": 14 }\nassert my_solution.countPairs(**test_input) == 6\n\ntest_input = { \"nums\": [-3,4,-6,-6,1,-10,-1,-8], \"target\": -11 }\nassert my_solution.countPairs(**test_input) == 7\n\ntest_input = { \"nums\": [-7,1,-5,8,-7,-3,2,-2,-2,7], \"target\": -5 }\nassert my_solution.countPairs(**test_input) == 14\n\ntest_input = { \"nums\": [8,0,-8,-8,-1,5], \"target\": 0 }\nassert my_solution.countPairs(**test_input) == 8\n\ntest_input = { \"nums\": [9,7,2,4,3], \"target\": 7 }\nassert my_solution.countPairs(**test_input) == 2\n\ntest_input = { \"nums\": [8,-1,-5,7,7,5,-6,2], \"target\": -2 }\nassert my_solution.countPairs(**test_input) == 5\n\ntest_input = { \"nums\": [-1,3,3,3,9], \"target\": 8 }\nassert my_solution.countPairs(**test_input) == 6\n\ntest_input = { \"nums\": [-8,0,-1,-6,-9,2,3,1], \"target\": -9 }\nassert my_solution.countPairs(**test_input) == 4\n\ntest_input = { \"nums\": [3,-3,-7,-6,-5,-2], \"target\": -2 }\nassert my_solution.countPairs(**test_input) == 12\n\ntest_input = { \"nums\": [3,6,0,-4,-2,5], \"target\": -6 }\nassert my_solution.countPairs(**test_input) == 0\n\ntest_input = { \"nums\": [-8,9,2,5,9,-4,3], \"target\": 6 }\nassert my_solution.countPairs(**test_input) == 12\n\ntest_input = { \"nums\": [0,-6,-5,-8,-4,0,7], \"target\": 7 }\nassert my_solution.countPairs(**test_input) == 19\n\ntest_input = { \"nums\": [0,9,2,-4], \"target\": -8 }\nassert my_solution.countPairs(**test_input) == 0\n\ntest_input = { \"nums\": [-7,9,-3,-5,-9,-3,-8,-2,1,2], \"target\": -8 }\nassert my_solution.countPairs(**test_input) == 15\n\ntest_input = { \"nums\": [4,10,-7,0,-3,5,9,6,8,-4], \"target\": 13 }\nassert my_solution.countPairs(**test_input) == 34\n\ntest_input = { \"nums\": [2,-6,0,5,-9,-8,6,5], \"target\": -3 }\nassert my_solution.countPairs(**test_input) == 11\n\ntest_input = { \"nums\": [-4,6,-2,10,-5,-7,-8,-1], \"target\": -5 }\nassert my_solution.countPairs(**test_input) == 13\n\ntest_input = { \"nums\": [10,4,8,-1,9,-5,-1,-7,-9], \"target\": 19 }\nassert my_solution.countPairs(**test_input) == 35\n\ntest_input = { \"nums\": [-6,5,3,-2,0,3,-7,-7], \"target\": -8 }\nassert my_solution.countPairs(**test_input) == 5\n\ntest_input = { \"nums\": [-3,-1,7,4,-10,-6,2], \"target\": -4 }\nassert my_solution.countPairs(**test_input) == 7\n\ntest_input = { \"nums\": [-7,8,3,-1,2,1,-10], \"target\": -7 }\nassert my_solution.countPairs(**test_input) == 5\n\ntest_input = { \"nums\": [7,-3,-5,9,-10,-1,-3,-3,-3,1], \"target\": 6 }\nassert my_solution.countPairs(**test_input) == 36\n\ntest_input = { \"nums\": [-5,-10,-7,-3,-2,-2], \"target\": -15 }\nassert my_solution.countPairs(**test_input) == 1\n\ntest_input = { \"nums\": [-4,6,-9,-8,-9,-9], \"target\": -17 }\nassert my_solution.countPairs(**test_input) == 3\n\ntest_input = { \"nums\": [-3,-8,-6,-4,-8,-10,-2,5,-2], \"target\": 1 }\nassert my_solution.countPairs(**test_input) == 32\n\ntest_input = { \"nums\": [1,1,-6,8,2,10,-7,-9,-9], \"target\": -7 }\nassert my_solution.countPairs(**test_input) == 10\n\ntest_input = { \"nums\": [-9,-6,-3,5,-4], \"target\": 2 }\nassert my_solution.countPairs(**test_input) == 9\n\ntest_input = { \"nums\": [-5,10,-5,1,7,-8,8,-6,-6], \"target\": 2 }\nassert my_solution.countPairs(**test_input) == 19", "start_time": 1692455400} +{"task_id": "biweekly-contest-111-make-string-a-subsequence-using-cyclic-increments", "url": "https://leetcode.com/problems/make-string-a-subsequence-using-cyclic-increments", "title": "make-string-a-subsequence-using-cyclic-increments", "meta": {"questionId": "3018", "questionFrontendId": "2825", "title": "Make String a Subsequence Using Cyclic Increments", "titleSlug": "make-string-a-subsequence-using-cyclic-increments", "isPaidOnly": false, "difficulty": "Medium", "likes": 273, "dislikes": 9, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given two 0-indexed strings str1 and str2.\n\nIn an operation, you select a set of indices in str1, and for each index i in the set, increment str1[i] to the next character cyclically. That is 'a' becomes 'b', 'b' becomes 'c', and so on, and 'z' becomes 'a'.\n\nReturn true if it is possible to make str2 a subsequence of str1 by performing the operation at most once, and false otherwise.\n\nNote: A subsequence of a string is a new string that is formed from the original string by deleting some (possibly none) of the characters without disturbing the relative positions of the remaining characters.\n\nExample 1:\n\nInput: str1 = \"abc\", str2 = \"ad\"\nOutput: true\nExplanation: Select index 2 in str1.\nIncrement str1[2] to become 'd'.\nHence, str1 becomes \"abd\" and str2 is now a subsequence. Therefore, true is returned.\n\nExample 2:\n\nInput: str1 = \"zc\", str2 = \"ad\"\nOutput: true\nExplanation: Select indices 0 and 1 in str1.\nIncrement str1[0] to become 'a'.\nIncrement str1[1] to become 'd'.\nHence, str1 becomes \"ad\" and str2 is now a subsequence. Therefore, true is returned.\n\nExample 3:\n\nInput: str1 = \"ab\", str2 = \"d\"\nOutput: false\nExplanation: In this example, it can be shown that it is impossible to make str2 a subsequence of str1 using the operation at most once.\nTherefore, false is returned.\n\nConstraints:\n\n * 1 <= str1.length <= 105\n * 1 <= str2.length <= 105\n * str1 and str2 consist of only lowercase English letters.\n\"\"\"\nclass Solution:\n def canMakeSubsequence(self, str1: str, str2: str) -> bool:\n ", "prompt_sft": "You are given two 0-indexed strings str1 and str2.\n\nIn an operation, you select a set of indices in str1, and for each index i in the set, increment str1[i] to the next character cyclically. That is 'a' becomes 'b', 'b' becomes 'c', and so on, and 'z' becomes 'a'.\n\nReturn true if it is possible to make str2 a subsequence of str1 by performing the operation at most once, and false otherwise.\n\nNote: A subsequence of a string is a new string that is formed from the original string by deleting some (possibly none) of the characters without disturbing the relative positions of the remaining characters.\n\nExample 1:\n\nInput: str1 = \"abc\", str2 = \"ad\"\nOutput: true\nExplanation: Select index 2 in str1.\nIncrement str1[2] to become 'd'.\nHence, str1 becomes \"abd\" and str2 is now a subsequence. Therefore, true is returned.\n\nExample 2:\n\nInput: str1 = \"zc\", str2 = \"ad\"\nOutput: true\nExplanation: Select indices 0 and 1 in str1.\nIncrement str1[0] to become 'a'.\nIncrement str1[1] to become 'd'.\nHence, str1 becomes \"ad\" and str2 is now a subsequence. Therefore, true is returned.\n\nExample 3:\n\nInput: str1 = \"ab\", str2 = \"d\"\nOutput: false\nExplanation: In this example, it can be shown that it is impossible to make str2 a subsequence of str1 using the operation at most once.\nTherefore, false is returned.\n\nConstraints:\n\n * 1 <= str1.length <= 105\n * 1 <= str2.length <= 105\n * str1 and str2 consist of only lowercase English letters.\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def canMakeSubsequence(self, str1: str, str2: str) -> bool:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"str1\": \"ab\", \"str2\": \"d\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"a\", \"str2\": \"d\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"abc\", \"str2\": \"ad\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"b\", \"str2\": \"v\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"c\", \"str2\": \"b\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"c\", \"str2\": \"k\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"zc\", \"str2\": \"ad\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"b\", \"str2\": \"c\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"c\", \"str2\": \"m\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"d\", \"str2\": \"h\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"f\", \"str2\": \"f\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"f\", \"str2\": \"g\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"d\", \"str2\": \"m\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"g\", \"str2\": \"g\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"h\", \"str2\": \"i\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"d\", \"str2\": \"x\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"i\", \"str2\": \"j\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"j\", \"str2\": \"j\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"j\", \"str2\": \"k\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"f\", \"str2\": \"s\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"i\", \"str2\": \"e\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"k\", \"str2\": \"k\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"l\", \"str2\": \"d\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"k\", \"str2\": \"l\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"m\", \"str2\": \"e\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"l\", \"str2\": \"l\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"m\", \"str2\": \"n\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"o\", \"str2\": \"p\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"o\", \"str2\": \"c\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"o\", \"str2\": \"n\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"p\", \"str2\": \"a\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"p\", \"str2\": \"s\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"q\", \"str2\": \"q\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"q\", \"str2\": \"j\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"s\", \"str2\": \"f\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"s\", \"str2\": \"u\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"r\", \"str2\": \"s\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"t\", \"str2\": \"h\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"t\", \"str2\": \"k\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"t\", \"str2\": \"u\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"u\", \"str2\": \"w\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"u\", \"str2\": \"u\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"w\", \"str2\": \"y\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"u\", \"str2\": \"v\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"at\", \"str2\": \"se\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"cl\", \"str2\": \"qs\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"v\", \"str2\": \"v\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"w\", \"str2\": \"w\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"cq\", \"str2\": \"xz\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"y\", \"str2\": \"y\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"ct\", \"str2\": \"xb\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"z\", \"str2\": \"a\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"fs\", \"str2\": \"rd\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"z\", \"str2\": \"z\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"gq\", \"str2\": \"kn\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"hq\", \"str2\": \"dk\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"dm\", \"str2\": \"e\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"eh\", \"str2\": \"e\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"ir\", \"str2\": \"ka\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"is\", \"str2\": \"af\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"ja\", \"str2\": \"zz\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"jq\", \"str2\": \"zi\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"ke\", \"str2\": \"qw\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"fp\", \"str2\": \"p\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"hz\", \"str2\": \"z\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"ia\", \"str2\": \"a\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"lo\", \"str2\": \"fa\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"km\", \"str2\": \"l\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"mu\", \"str2\": \"za\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"np\", \"str2\": \"q\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"nh\", \"str2\": \"pa\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"oj\", \"str2\": \"j\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"oh\", \"str2\": \"hu\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"pg\", \"str2\": \"xb\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"uq\", \"str2\": \"v\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"pl\", \"str2\": \"yi\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"ww\", \"str2\": \"x\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"xh\", \"str2\": \"x\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"yg\", \"str2\": \"y\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"px\", \"str2\": \"dh\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"rm\", \"str2\": \"au\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"se\", \"str2\": \"vs\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"yw\", \"str2\": \"w\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"st\", \"str2\": \"zf\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"dby\", \"str2\": \"z\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"sx\", \"str2\": \"fx\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"ei\", \"str2\": \"ei\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"ff\", \"str2\": \"fg\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"to\", \"str2\": \"yv\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"tv\", \"str2\": \"ei\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"va\", \"str2\": \"ow\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"jc\", \"str2\": \"jd\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"jrg\", \"str2\": \"h\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"lf\", \"str2\": \"lg\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"agb\", \"str2\": \"vgz\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"amk\", \"str2\": \"nto\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"atd\", \"str2\": \"xrr\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"pc\", \"str2\": \"qc\" }\nassert my_solution.canMakeSubsequence(**test_input) == True\n\ntest_input = { \"str1\": \"ayt\", \"str2\": \"nov\" }\nassert my_solution.canMakeSubsequence(**test_input) == False\n\ntest_input = { \"str1\": \"qv\", \"str2\": \"rv\" }\nassert my_solution.canMakeSubsequence(**test_input) == True", "start_time": 1692455400} +{"task_id": "biweekly-contest-111-sorting-three-groups", "url": "https://leetcode.com/problems/sorting-three-groups", "title": "sorting-three-groups", "meta": {"questionId": "2904", "questionFrontendId": "2826", "title": "Sorting Three Groups", "titleSlug": "sorting-three-groups", "isPaidOnly": false, "difficulty": "Medium", "likes": 347, "dislikes": 72, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed integer array nums of length n.\n\nThe numbers from 0 to n - 1 are divided into three groups numbered from 1 to 3, where number i belongs to group nums[i]. Notice that some groups may be empty.\n\nYou are allowed to perform this operation any number of times:\n\n * Pick number x and change its group. More formally, change nums[x] to any number from 1 to 3.\n\nA new array res is constructed using the following procedure:\n\n 1. Sort the numbers in each group independently.\n 2. Append the elements of groups 1, 2, and 3 to res in this order.\n\nArray nums is called a beautiful array if the constructed array res is sorted in non-decreasing order.\n\nReturn the minimum number of operations to make nums a beautiful array.\n\nExample 1:\n\nInput: nums = [2,1,3,2,1]\nOutput: 3\nExplanation: It's optimal to perform three operations:\n1. change nums[0] to 1.\n2. change nums[2] to 1.\n3. change nums[3] to 1.\nAfter performing the operations and sorting the numbers in each group, group 1 becomes equal to [0,1,2,3,4] and group 2 and group 3 become empty. Hence, res is equal to [0,1,2,3,4] which is sorted in non-decreasing order.\nIt can be proven that there is no valid sequence of less than three operations.\n\nExample 2:\n\nInput: nums = [1,3,2,1,3,3]\nOutput: 2\nExplanation: It's optimal to perform two operations:\n1. change nums[1] to 1.\n2. change nums[2] to 1.\nAfter performing the operations and sorting the numbers in each group, group 1 becomes equal to [0,1,2,3], group 2 becomes empty, and group 3 becomes equal to [4,5]. Hence, res is equal to [0,1,2,3,4,5] which is sorted in non-decreasing order.\nIt can be proven that there is no valid sequence of less than two operations.\n\nExample 3:\n\nInput: nums = [2,2,2,2,3,3]\nOutput: 0\nExplanation: It's optimal to not perform operations.\nAfter sorting the numbers in each group, group 1 becomes empty, group 2 becomes equal to [0,1,2,3] and group 3 becomes equal to [4,5]. Hence, res is equal to [0,1,2,3,4,5] which is sorted in non-decreasing order.\n\n\nConstraints:\n\n * 1 <= nums.length <= 100\n * 1 <= nums[i] <= 3\n\"\"\"\nclass Solution:\n def minimumOperations(self, nums: List[int]) -> int:\n ", "prompt_sft": "You are given a 0-indexed integer array nums of length n.\n\nThe numbers from 0 to n - 1 are divided into three groups numbered from 1 to 3, where number i belongs to group nums[i]. Notice that some groups may be empty.\n\nYou are allowed to perform this operation any number of times:\n\n * Pick number x and change its group. More formally, change nums[x] to any number from 1 to 3.\n\nA new array res is constructed using the following procedure:\n\n 1. Sort the numbers in each group independently.\n 2. Append the elements of groups 1, 2, and 3 to res in this order.\n\nArray nums is called a beautiful array if the constructed array res is sorted in non-decreasing order.\n\nReturn the minimum number of operations to make nums a beautiful array.\n\nExample 1:\n\nInput: nums = [2,1,3,2,1]\nOutput: 3\nExplanation: It's optimal to perform three operations:\n1. change nums[0] to 1.\n2. change nums[2] to 1.\n3. change nums[3] to 1.\nAfter performing the operations and sorting the numbers in each group, group 1 becomes equal to [0,1,2,3,4] and group 2 and group 3 become empty. Hence, res is equal to [0,1,2,3,4] which is sorted in non-decreasing order.\nIt can be proven that there is no valid sequence of less than three operations.\n\nExample 2:\n\nInput: nums = [1,3,2,1,3,3]\nOutput: 2\nExplanation: It's optimal to perform two operations:\n1. change nums[1] to 1.\n2. change nums[2] to 1.\nAfter performing the operations and sorting the numbers in each group, group 1 becomes equal to [0,1,2,3], group 2 becomes empty, and group 3 becomes equal to [4,5]. Hence, res is equal to [0,1,2,3,4,5] which is sorted in non-decreasing order.\nIt can be proven that there is no valid sequence of less than two operations.\n\nExample 3:\n\nInput: nums = [2,2,2,2,3,3]\nOutput: 0\nExplanation: It's optimal to not perform operations.\nAfter sorting the numbers in each group, group 1 becomes empty, group 2 becomes equal to [0,1,2,3] and group 3 becomes equal to [4,5]. Hence, res is equal to [0,1,2,3,4,5] which is sorted in non-decreasing order.\n\n\nConstraints:\n\n * 1 <= nums.length <= 100\n * 1 <= nums[i] <= 3\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def minimumOperations(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [2,1,3,2,1] }\nassert my_solution.minimumOperations(**test_input) == 3\n\ntest_input = { \"nums\": [1,3,2,1,3,3] }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"nums\": [2,2,2,2,3,3] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [1] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [2] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [3] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [1,2] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [2,2] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [3,2] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,3] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [2,3] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [3,3] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,2] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [2,1,2] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [3,1,2] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,2] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [2,2,2] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [3,2,2] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,3,2] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [2,3,2] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [3,3,2] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,3] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [2,1,3] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [3,1,3] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,3] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [2,2,3] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [3,2,3] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,3,3] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [2,3,3] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [3,3,3] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,1,2] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [2,1,1,2] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [3,1,1,2] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,1,2] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [2,2,1,2] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [3,2,1,2] }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,3,1,2] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [2,3,1,2] }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"nums\": [3,3,1,2] }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,2,2] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [2,1,2,2] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [3,1,2,2] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,2,2] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [2,2,2,2] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [3,2,2,2] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,3,2,2] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [2,3,2,2] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [3,3,2,2] }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,3,2] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [2,1,3,2] }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"nums\": [3,1,3,2] }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,2,3,2] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [2,2,3,2] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [3,2,3,2] }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,3,3,2] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [2,3,3,2] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [3,3,3,2] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,1,3] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [2,1,1,3] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [3,1,1,3] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,1,3] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [2,2,1,3] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [3,2,1,3] }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,3,1,3] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [2,3,1,3] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [3,3,1,3] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,2,3] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [2,1,2,3] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [3,1,2,3] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,2,3] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [2,2,2,3] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [3,2,2,3] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,3,2,3] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [2,3,2,3] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [3,3,2,3] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,3,3] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [2,1,3,3] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [3,1,3,3] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,3,3] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [2,2,3,3] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [3,2,3,3] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,3,3,3] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [2,3,3,3] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [3,3,3,3] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,1,1,2] }\nassert my_solution.minimumOperations(**test_input) == 0\n\ntest_input = { \"nums\": [2,1,1,1,2] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [3,1,1,1,2] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,1,1,2] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [2,2,1,1,2] }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"nums\": [3,2,1,1,2] }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,3,1,1,2] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [2,3,1,1,2] }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"nums\": [3,3,1,1,2] }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,2,1,2] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [2,1,2,1,2] }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"nums\": [3,1,2,1,2] }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,2,2,1,2] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [2,2,2,1,2] }\nassert my_solution.minimumOperations(**test_input) == 1\n\ntest_input = { \"nums\": [3,2,2,1,2] }\nassert my_solution.minimumOperations(**test_input) == 2\n\ntest_input = { \"nums\": [1,3,2,1,2] }\nassert my_solution.minimumOperations(**test_input) == 2", "start_time": 1692455400} +{"task_id": "biweekly-contest-111-number-of-beautiful-integers-in-the-range", "url": "https://leetcode.com/problems/number-of-beautiful-integers-in-the-range", "title": "number-of-beautiful-integers-in-the-range", "meta": {"questionId": "3017", "questionFrontendId": "2827", "title": "Number of Beautiful Integers in the Range", "titleSlug": "number-of-beautiful-integers-in-the-range", "isPaidOnly": false, "difficulty": "Hard", "likes": 313, "dislikes": 24, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given positive integers low, high, and k.\n\nA number is beautiful if it meets both of the following conditions:\n\n * The count of even digits in the number is equal to the count of odd digits.\n * The number is divisible by k.\n\nReturn the number of beautiful integers in the range [low, high].\n\nExample 1:\n\nInput: low = 10, high = 20, k = 3\nOutput: 2\nExplanation: There are 2 beautiful integers in the given range: [12,18].\n- 12 is beautiful because it contains 1 odd digit and 1 even digit, and is divisible by k = 3.\n- 18 is beautiful because it contains 1 odd digit and 1 even digit, and is divisible by k = 3.\nAdditionally we can see that:\n- 16 is not beautiful because it is not divisible by k = 3.\n- 15 is not beautiful because it does not contain equal counts even and odd digits.\nIt can be shown that there are only 2 beautiful integers in the given range.\n\nExample 2:\n\nInput: low = 1, high = 10, k = 1\nOutput: 1\nExplanation: There is 1 beautiful integer in the given range: [10].\n- 10 is beautiful because it contains 1 odd digit and 1 even digit, and is divisible by k = 1.\nIt can be shown that there is only 1 beautiful integer in the given range.\n\nExample 3:\n\nInput: low = 5, high = 5, k = 2\nOutput: 0\nExplanation: There are 0 beautiful integers in the given range.\n- 5 is not beautiful because it is not divisible by k = 2 and it does not contain equal even and odd digits.\n\n\nConstraints:\n\n * 0 < low <= high <= 109\n * 0 < k <= 20\n\"\"\"\nclass Solution:\n def numberOfBeautifulIntegers(self, low: int, high: int, k: int) -> int:\n ", "prompt_sft": "You are given positive integers low, high, and k.\n\nA number is beautiful if it meets both of the following conditions:\n\n * The count of even digits in the number is equal to the count of odd digits.\n * The number is divisible by k.\n\nReturn the number of beautiful integers in the range [low, high].\n\nExample 1:\n\nInput: low = 10, high = 20, k = 3\nOutput: 2\nExplanation: There are 2 beautiful integers in the given range: [12,18].\n- 12 is beautiful because it contains 1 odd digit and 1 even digit, and is divisible by k = 3.\n- 18 is beautiful because it contains 1 odd digit and 1 even digit, and is divisible by k = 3.\nAdditionally we can see that:\n- 16 is not beautiful because it is not divisible by k = 3.\n- 15 is not beautiful because it does not contain equal counts even and odd digits.\nIt can be shown that there are only 2 beautiful integers in the given range.\n\nExample 2:\n\nInput: low = 1, high = 10, k = 1\nOutput: 1\nExplanation: There is 1 beautiful integer in the given range: [10].\n- 10 is beautiful because it contains 1 odd digit and 1 even digit, and is divisible by k = 1.\nIt can be shown that there is only 1 beautiful integer in the given range.\n\nExample 3:\n\nInput: low = 5, high = 5, k = 2\nOutput: 0\nExplanation: There are 0 beautiful integers in the given range.\n- 5 is not beautiful because it is not divisible by k = 2 and it does not contain equal even and odd digits.\n\n\nConstraints:\n\n * 0 < low <= high <= 109\n * 0 < k <= 20\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def numberOfBeautifulIntegers(self, low: int, high: int, k: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"low\": 10, \"high\": 20, \"k\": 3 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 2\n\ntest_input = { \"low\": 1, \"high\": 10, \"k\": 1 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 1\n\ntest_input = { \"low\": 5, \"high\": 5, \"k\": 2 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 3, \"high\": 31, \"k\": 16 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 1\n\ntest_input = { \"low\": 25, \"high\": 31, \"k\": 11 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 9, \"high\": 25, \"k\": 4 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 2\n\ntest_input = { \"low\": 58, \"high\": 72, \"k\": 16 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 5, \"high\": 79, \"k\": 12 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 3\n\ntest_input = { \"low\": 26, \"high\": 74, \"k\": 7 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 4\n\ntest_input = { \"low\": 36, \"high\": 65, \"k\": 7 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 3\n\ntest_input = { \"low\": 12, \"high\": 84, \"k\": 8 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 4\n\ntest_input = { \"low\": 13, \"high\": 91, \"k\": 13 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 3\n\ntest_input = { \"low\": 8, \"high\": 18, \"k\": 4 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 2\n\ntest_input = { \"low\": 22, \"high\": 59, \"k\": 6 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 3\n\ntest_input = { \"low\": 15, \"high\": 27, \"k\": 9 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 2\n\ntest_input = { \"low\": 4, \"high\": 9, \"k\": 19 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 14, \"high\": 81, \"k\": 17 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 1\n\ntest_input = { \"low\": 12, \"high\": 33, \"k\": 18 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 1\n\ntest_input = { \"low\": 10, \"high\": 17, \"k\": 8 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 1\n\ntest_input = { \"low\": 42, \"high\": 58, \"k\": 3 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 2\n\ntest_input = { \"low\": 22, \"high\": 42, \"k\": 4 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 2\n\ntest_input = { \"low\": 5, \"high\": 8, \"k\": 5 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 12, \"high\": 75, \"k\": 13 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 2\n\ntest_input = { \"low\": 2, \"high\": 28, \"k\": 1 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 9\n\ntest_input = { \"low\": 29, \"high\": 35, \"k\": 17 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 1\n\ntest_input = { \"low\": 13, \"high\": 21, \"k\": 9 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 1\n\ntest_input = { \"low\": 1, \"high\": 13, \"k\": 15 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 12, \"high\": 21, \"k\": 16 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 1\n\ntest_input = { \"low\": 47, \"high\": 72, \"k\": 13 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 2\n\ntest_input = { \"low\": 1, \"high\": 35, \"k\": 12 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 1\n\ntest_input = { \"low\": 38, \"high\": 52, \"k\": 4 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 1\n\ntest_input = { \"low\": 10, \"high\": 74, \"k\": 3 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 11\n\ntest_input = { \"low\": 60, \"high\": 92, \"k\": 11 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 3, \"high\": 25, \"k\": 15 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 63, \"high\": 65, \"k\": 20 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 22, \"high\": 77, \"k\": 7 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 4\n\ntest_input = { \"low\": 1, \"high\": 1, \"k\": 4 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 28, \"high\": 73, \"k\": 20 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 21, \"high\": 32, \"k\": 6 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 1\n\ntest_input = { \"low\": 43, \"high\": 43, \"k\": 11 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 31, \"high\": 68, \"k\": 16 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 1\n\ntest_input = { \"low\": 1, \"high\": 8, \"k\": 4 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 47, \"high\": 100, \"k\": 18 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 3\n\ntest_input = { \"low\": 45, \"high\": 84, \"k\": 19 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 1\n\ntest_input = { \"low\": 31, \"high\": 80, \"k\": 11 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 14, \"high\": 14, \"k\": 5 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 21, \"high\": 88, \"k\": 10 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 3\n\ntest_input = { \"low\": 11, \"high\": 42, \"k\": 3 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 6\n\ntest_input = { \"low\": 19, \"high\": 53, \"k\": 16 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 1\n\ntest_input = { \"low\": 57, \"high\": 98, \"k\": 6 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 4\n\ntest_input = { \"low\": 57, \"high\": 69, \"k\": 9 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 1\n\ntest_input = { \"low\": 17, \"high\": 64, \"k\": 1 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 23\n\ntest_input = { \"low\": 29, \"high\": 40, \"k\": 15 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 1\n\ntest_input = { \"low\": 36, \"high\": 60, \"k\": 3 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 3\n\ntest_input = { \"low\": 16, \"high\": 23, \"k\": 13 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 36, \"high\": 99, \"k\": 3 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 11\n\ntest_input = { \"low\": 23, \"high\": 83, \"k\": 4 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 6\n\ntest_input = { \"low\": 4, \"high\": 5, \"k\": 9 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 15, \"high\": 21, \"k\": 2 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 2\n\ntest_input = { \"low\": 51, \"high\": 76, \"k\": 7 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 3\n\ntest_input = { \"low\": 24, \"high\": 34, \"k\": 8 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 1\n\ntest_input = { \"low\": 24, \"high\": 99, \"k\": 1 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 38\n\ntest_input = { \"low\": 37, \"high\": 63, \"k\": 10 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 1\n\ntest_input = { \"low\": 19, \"high\": 23, \"k\": 6 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 35, \"high\": 70, \"k\": 17 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 3, \"high\": 18, \"k\": 19 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 30, \"high\": 64, \"k\": 12 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 1\n\ntest_input = { \"low\": 3, \"high\": 12, \"k\": 9 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 14, \"high\": 21, \"k\": 16 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 1\n\ntest_input = { \"low\": 19, \"high\": 21, \"k\": 12 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 54, \"high\": 78, \"k\": 16 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 24, \"high\": 36, \"k\": 20 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 54, \"high\": 58, \"k\": 13 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 74, \"high\": 88, \"k\": 12 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 45, \"high\": 58, \"k\": 14 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 1\n\ntest_input = { \"low\": 51, \"high\": 99, \"k\": 8 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 3\n\ntest_input = { \"low\": 8, \"high\": 26, \"k\": 13 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 12, \"high\": 92, \"k\": 3 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 15\n\ntest_input = { \"low\": 18, \"high\": 91, \"k\": 11 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 14, \"high\": 53, \"k\": 15 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 2\n\ntest_input = { \"low\": 4, \"high\": 10, \"k\": 11 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 7, \"high\": 24, \"k\": 5 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 1\n\ntest_input = { \"low\": 1, \"high\": 25, \"k\": 8 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 1\n\ntest_input = { \"low\": 7, \"high\": 20, \"k\": 15 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 51, \"high\": 92, \"k\": 1 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 21\n\ntest_input = { \"low\": 73, \"high\": 73, \"k\": 3 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 50, \"high\": 63, \"k\": 19 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 30, \"high\": 51, \"k\": 19 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 1\n\ntest_input = { \"low\": 2, \"high\": 65, \"k\": 7 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 5\n\ntest_input = { \"low\": 49, \"high\": 87, \"k\": 20 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 3, \"high\": 6, \"k\": 1 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 16, \"high\": 17, \"k\": 6 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 17, \"high\": 32, \"k\": 16 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 1\n\ntest_input = { \"low\": 13, \"high\": 14, \"k\": 6 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 25, \"high\": 42, \"k\": 11 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 18, \"high\": 46, \"k\": 5 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 3\n\ntest_input = { \"low\": 1, \"high\": 65, \"k\": 6 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 5\n\ntest_input = { \"low\": 6, \"high\": 43, \"k\": 15 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 1\n\ntest_input = { \"low\": 5, \"high\": 9, \"k\": 12 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 0\n\ntest_input = { \"low\": 1, \"high\": 75, \"k\": 9 }\nassert my_solution.numberOfBeautifulIntegers(**test_input) == 7", "start_time": 1692455400} +{"task_id": "weekly-contest-358-max-pair-sum-in-an-array", "url": "https://leetcode.com/problems/max-pair-sum-in-an-array", "title": "max-pair-sum-in-an-array", "meta": {"questionId": "2902", "questionFrontendId": "2815", "title": "Max Pair Sum in an Array", "titleSlug": "max-pair-sum-in-an-array", "isPaidOnly": false, "difficulty": "Easy", "likes": 274, "dislikes": 91, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed integer array nums. You have to find the maximum sum of a pair of numbers from nums such that the maximum digit in both numbers are equal.\n\nReturn the maximum sum or -1 if no such pair exists.\n\nExample 1:\n\nInput: nums = [51,71,17,24,42]\nOutput: 88\nExplanation:\nFor i = 1 and j = 2, nums[i] and nums[j] have equal maximum digits with a pair sum of 71 + 17 = 88.\nFor i = 3 and j = 4, nums[i] and nums[j] have equal maximum digits with a pair sum of 24 + 42 = 66.\nIt can be shown that there are no other pairs with equal maximum digits, so the answer is 88.\n\nExample 2:\n\nInput: nums = [1,2,3,4]\nOutput: -1\nExplanation: No pair exists in nums with equal maximum digits.\n\n\nConstraints:\n\n * 2 <= nums.length <= 100\n * 1 <= nums[i] <= 104\n\"\"\"\nclass Solution:\n def maxSum(self, nums: List[int]) -> int:\n ", "prompt_sft": "You are given a 0-indexed integer array nums. You have to find the maximum sum of a pair of numbers from nums such that the maximum digit in both numbers are equal.\n\nReturn the maximum sum or -1 if no such pair exists.\n\nExample 1:\n\nInput: nums = [51,71,17,24,42]\nOutput: 88\nExplanation:\nFor i = 1 and j = 2, nums[i] and nums[j] have equal maximum digits with a pair sum of 71 + 17 = 88.\nFor i = 3 and j = 4, nums[i] and nums[j] have equal maximum digits with a pair sum of 24 + 42 = 66.\nIt can be shown that there are no other pairs with equal maximum digits, so the answer is 88.\n\nExample 2:\n\nInput: nums = [1,2,3,4]\nOutput: -1\nExplanation: No pair exists in nums with equal maximum digits.\n\n\nConstraints:\n\n * 2 <= nums.length <= 100\n * 1 <= nums[i] <= 104\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def maxSum(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [51,71,17,24,42] }\nassert my_solution.maxSum(**test_input) == 88\n\ntest_input = { \"nums\": [1,2,3,4] }\nassert my_solution.maxSum(**test_input) == -1\n\ntest_input = { \"nums\": [31,25,72,79,74] }\nassert my_solution.maxSum(**test_input) == 146\n\ntest_input = { \"nums\": [84,91,18,59,27,9,81,33,17,58] }\nassert my_solution.maxSum(**test_input) == 165\n\ntest_input = { \"nums\": [8,75,28,35,21,13,21] }\nassert my_solution.maxSum(**test_input) == 42\n\ntest_input = { \"nums\": [35,52,74,92,25,65,77,1,73,32] }\nassert my_solution.maxSum(**test_input) == 151\n\ntest_input = { \"nums\": [68,8,100,84,80,14,88] }\nassert my_solution.maxSum(**test_input) == 172\n\ntest_input = { \"nums\": [53,98,69,64,40,60,23] }\nassert my_solution.maxSum(**test_input) == 167\n\ntest_input = { \"nums\": [21,76] }\nassert my_solution.maxSum(**test_input) == -1\n\ntest_input = { \"nums\": [99,63,23,70,18,64] }\nassert my_solution.maxSum(**test_input) == 127\n\ntest_input = { \"nums\": [21,21,78] }\nassert my_solution.maxSum(**test_input) == 42\n\ntest_input = { \"nums\": [58,88,58,99,26,92] }\nassert my_solution.maxSum(**test_input) == 191\n\ntest_input = { \"nums\": [10,24,25,20,92,73,63,51] }\nassert my_solution.maxSum(**test_input) == 76\n\ntest_input = { \"nums\": [87,6,17,32,14,42,46,65,43,9] }\nassert my_solution.maxSum(**test_input) == 111\n\ntest_input = { \"nums\": [96,46,85,19,29] }\nassert my_solution.maxSum(**test_input) == 125\n\ntest_input = { \"nums\": [5,24] }\nassert my_solution.maxSum(**test_input) == -1\n\ntest_input = { \"nums\": [26,76,24,96,82,97,97,72,35] }\nassert my_solution.maxSum(**test_input) == 194\n\ntest_input = { \"nums\": [77,82,30,94] }\nassert my_solution.maxSum(**test_input) == -1\n\ntest_input = { \"nums\": [76,94,51,82,3,89,52,96] }\nassert my_solution.maxSum(**test_input) == 190\n\ntest_input = { \"nums\": [27,59,57,97,6,46,88,41,52,46] }\nassert my_solution.maxSum(**test_input) == 156\n\ntest_input = { \"nums\": [17,2] }\nassert my_solution.maxSum(**test_input) == -1\n\ntest_input = { \"nums\": [62,69] }\nassert my_solution.maxSum(**test_input) == -1\n\ntest_input = { \"nums\": [63,24,1] }\nassert my_solution.maxSum(**test_input) == -1\n\ntest_input = { \"nums\": [55,46,4,61,78,21,85,52,83,77] }\nassert my_solution.maxSum(**test_input) == 168\n\ntest_input = { \"nums\": [21,73,2,80,99,98,89] }\nassert my_solution.maxSum(**test_input) == 197\n\ntest_input = { \"nums\": [94,63,50,43,62,14,83,91] }\nassert my_solution.maxSum(**test_input) == 185\n\ntest_input = { \"nums\": [66,17,17,35,46,77,7,15,38] }\nassert my_solution.maxSum(**test_input) == 112\n\ntest_input = { \"nums\": [61,90,34,29,68,35] }\nassert my_solution.maxSum(**test_input) == 119\n\ntest_input = { \"nums\": [18,82,78] }\nassert my_solution.maxSum(**test_input) == 160\n\ntest_input = { \"nums\": [8,71,2,59,70,12] }\nassert my_solution.maxSum(**test_input) == 141\n\ntest_input = { \"nums\": [55,88,59] }\nassert my_solution.maxSum(**test_input) == -1\n\ntest_input = { \"nums\": [49,47,46,65,37,24,75,81,54,39] }\nassert my_solution.maxSum(**test_input) == 122\n\ntest_input = { \"nums\": [73,79,48,45,57,73,51,78,67,78] }\nassert my_solution.maxSum(**test_input) == 156\n\ntest_input = { \"nums\": [2,82,80,74,34,54,65] }\nassert my_solution.maxSum(**test_input) == 162\n\ntest_input = { \"nums\": [9,62,85,95,36,62,21,38,16,12] }\nassert my_solution.maxSum(**test_input) == 124\n\ntest_input = { \"nums\": [50,80,34,9,86,20,67,94,65,82] }\nassert my_solution.maxSum(**test_input) == 168\n\ntest_input = { \"nums\": [79,74,92,84,37,19] }\nassert my_solution.maxSum(**test_input) == 171\n\ntest_input = { \"nums\": [85,20,79] }\nassert my_solution.maxSum(**test_input) == -1\n\ntest_input = { \"nums\": [89,55,67,84,3] }\nassert my_solution.maxSum(**test_input) == -1\n\ntest_input = { \"nums\": [16,44,2,54,58,94] }\nassert my_solution.maxSum(**test_input) == -1\n\ntest_input = { \"nums\": [71,14,24,13,21,14,100,18,84,37] }\nassert my_solution.maxSum(**test_input) == 108\n\ntest_input = { \"nums\": [13,26] }\nassert my_solution.maxSum(**test_input) == -1\n\ntest_input = { \"nums\": [82,30,53,72,56,94,72,67] }\nassert my_solution.maxSum(**test_input) == 144\n\ntest_input = { \"nums\": [14,80,92,65,85,70] }\nassert my_solution.maxSum(**test_input) == 165\n\ntest_input = { \"nums\": [81,39,43,31,53,43,87,19,93] }\nassert my_solution.maxSum(**test_input) == 168\n\ntest_input = { \"nums\": [27,12,80,38,94,92,67,54,56,20] }\nassert my_solution.maxSum(**test_input) == 186\n\ntest_input = { \"nums\": [52,32,24,6,3,89,100,3,5,3] }\nassert my_solution.maxSum(**test_input) == 57\n\ntest_input = { \"nums\": [93,1,13,88,47,48,46,63] }\nassert my_solution.maxSum(**test_input) == 136\n\ntest_input = { \"nums\": [3,55,40,93,97,37,31,31] }\nassert my_solution.maxSum(**test_input) == 190\n\ntest_input = { \"nums\": [58,41,10,74,40,17] }\nassert my_solution.maxSum(**test_input) == 91\n\ntest_input = { \"nums\": [58,33,78,53,88,1,15,44,82] }\nassert my_solution.maxSum(**test_input) == 170\n\ntest_input = { \"nums\": [41,48,96,71,35,89,57,71] }\nassert my_solution.maxSum(**test_input) == 185\n\ntest_input = { \"nums\": [43,4,69,29,37,50] }\nassert my_solution.maxSum(**test_input) == 98\n\ntest_input = { \"nums\": [65,88,2] }\nassert my_solution.maxSum(**test_input) == -1\n\ntest_input = { \"nums\": [86,42,59,44,76,6] }\nassert my_solution.maxSum(**test_input) == 86\n\ntest_input = { \"nums\": [29,96,1,10,27,78,56,62] }\nassert my_solution.maxSum(**test_input) == 125\n\ntest_input = { \"nums\": [100,48,6] }\nassert my_solution.maxSum(**test_input) == -1\n\ntest_input = { \"nums\": [33,17] }\nassert my_solution.maxSum(**test_input) == -1\n\ntest_input = { \"nums\": [8,91] }\nassert my_solution.maxSum(**test_input) == -1\n\ntest_input = { \"nums\": [91,13,72,42,28] }\nassert my_solution.maxSum(**test_input) == -1\n\ntest_input = { \"nums\": [5,53,35,88,77,1,66,57] }\nassert my_solution.maxSum(**test_input) == 134\n\ntest_input = { \"nums\": [50,27,52,70,67,60,65] }\nassert my_solution.maxSum(**test_input) == 137\n\ntest_input = { \"nums\": [84,82,31,45,94,62,45,32] }\nassert my_solution.maxSum(**test_input) == 166\n\ntest_input = { \"nums\": [61,61,61,23,47,34,21,6,65,25] }\nassert my_solution.maxSum(**test_input) == 126\n\ntest_input = { \"nums\": [60,21,11,99] }\nassert my_solution.maxSum(**test_input) == -1\n\ntest_input = { \"nums\": [22,83,62,12,63,100,41,33] }\nassert my_solution.maxSum(**test_input) == 125\n\ntest_input = { \"nums\": [92,58,85] }\nassert my_solution.maxSum(**test_input) == 143\n\ntest_input = { \"nums\": [93,5,46,26,25,36,27,12,30] }\nassert my_solution.maxSum(**test_input) == 82\n\ntest_input = { \"nums\": [52,30,16] }\nassert my_solution.maxSum(**test_input) == -1\n\ntest_input = { \"nums\": [22,57,33,26,76,14,67] }\nassert my_solution.maxSum(**test_input) == 143\n\ntest_input = { \"nums\": [90,72,37,30] }\nassert my_solution.maxSum(**test_input) == 109\n\ntest_input = { \"nums\": [44,87,16] }\nassert my_solution.maxSum(**test_input) == -1\n\ntest_input = { \"nums\": [19,12,52,8,3,58] }\nassert my_solution.maxSum(**test_input) == 66\n\ntest_input = { \"nums\": [88,52,35,6,58,47,62,82,47,86] }\nassert my_solution.maxSum(**test_input) == 174\n\ntest_input = { \"nums\": [84,1,48,76,16,10,11,60] }\nassert my_solution.maxSum(**test_input) == 132\n\ntest_input = { \"nums\": [12,60,69,63,78,22,28] }\nassert my_solution.maxSum(**test_input) == 123\n\ntest_input = { \"nums\": [16,28,82,77,41,22] }\nassert my_solution.maxSum(**test_input) == 110\n\ntest_input = { \"nums\": [97,31,63,2,94,14,47] }\nassert my_solution.maxSum(**test_input) == 191\n\ntest_input = { \"nums\": [93,100,45,74,31,41,84,90,18,21] }\nassert my_solution.maxSum(**test_input) == 183\n\ntest_input = { \"nums\": [21,12,38,64,57,24] }\nassert my_solution.maxSum(**test_input) == 33\n\ntest_input = { \"nums\": [33,17,99,2,58,59,72,9,62] }\nassert my_solution.maxSum(**test_input) == 158\n\ntest_input = { \"nums\": [36,11,23,98,14,89,90,53] }\nassert my_solution.maxSum(**test_input) == 188\n\ntest_input = { \"nums\": [57,90,5,78,84,51] }\nassert my_solution.maxSum(**test_input) == 162\n\ntest_input = { \"nums\": [73,73,76,48,30] }\nassert my_solution.maxSum(**test_input) == 149\n\ntest_input = { \"nums\": [2,74,37,75] }\nassert my_solution.maxSum(**test_input) == 149\n\ntest_input = { \"nums\": [84,35,65,12] }\nassert my_solution.maxSum(**test_input) == -1\n\ntest_input = { \"nums\": [95,46,23,81,35] }\nassert my_solution.maxSum(**test_input) == -1\n\ntest_input = { \"nums\": [64,76,46,54,64,94,90,95] }\nassert my_solution.maxSum(**test_input) == 189\n\ntest_input = { \"nums\": [77,52,74,84,47,89,53] }\nassert my_solution.maxSum(**test_input) == 151\n\ntest_input = { \"nums\": [29,31,52,12,89,88,10,18] }\nassert my_solution.maxSum(**test_input) == 118\n\ntest_input = { \"nums\": [28,57,28,41,25,89,20] }\nassert my_solution.maxSum(**test_input) == 56\n\ntest_input = { \"nums\": [31,28] }\nassert my_solution.maxSum(**test_input) == -1\n\ntest_input = { \"nums\": [51,1,98,73,84,11,100,100,75] }\nassert my_solution.maxSum(**test_input) == 200\n\ntest_input = { \"nums\": [76,2,26,49,78,36,2,70,64] }\nassert my_solution.maxSum(**test_input) == 146\n\ntest_input = { \"nums\": [34,63,21,49] }\nassert my_solution.maxSum(**test_input) == -1\n\ntest_input = { \"nums\": [35,19,1,21,11,59,38] }\nassert my_solution.maxSum(**test_input) == 78\n\ntest_input = { \"nums\": [1,35,74,58,56,54,75] }\nassert my_solution.maxSum(**test_input) == 149\n\ntest_input = { \"nums\": [20,49] }\nassert my_solution.maxSum(**test_input) == -1\n\ntest_input = { \"nums\": [97,92,13,30] }\nassert my_solution.maxSum(**test_input) == 189\n\ntest_input = { \"nums\": [89,49,10,36,37] }\nassert my_solution.maxSum(**test_input) == 138", "start_time": 1691893800} +{"task_id": "weekly-contest-358-double-a-number-represented-as-a-linked-list", "url": "https://leetcode.com/problems/double-a-number-represented-as-a-linked-list", "title": "double-a-number-represented-as-a-linked-list", "meta": {"questionId": "2871", "questionFrontendId": "2816", "title": "Double a Number Represented as a Linked List", "titleSlug": "double-a-number-represented-as-a-linked-list", "isPaidOnly": false, "difficulty": "Medium", "likes": 397, "dislikes": 5, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given the head of a non-empty linked list representing a non-negative integer without leading zeroes.\n\nReturn the head of the linked list after doubling it.\n\nExample 1:\n\n[https://assets.leetcode.com/uploads/2023/05/28/example.png]\n\nInput: head = [1,8,9]\nOutput: [3,7,8]\nExplanation: The figure above corresponds to the given linked list which represents the number 189. Hence, the returned linked list represents the number 189 * 2 = 378.\n\nExample 2:\n\n[https://assets.leetcode.com/uploads/2023/05/28/example2.png]\n\nInput: head = [9,9,9]\nOutput: [1,9,9,8]\nExplanation: The figure above corresponds to the given linked list which represents the number 999. Hence, the returned linked list reprersents the number 999 * 2 = 1998.\n\n\nConstraints:\n\n * The number of nodes in the list is in the range [1, 104]\n * 0 <= Node.val <= 9\n * The input is generated such that the list represents a number that does not have leading zeros, except the number 0 itself.\n\"\"\"\n# Definition for singly-linked list.\nclass ListNode:\n def __init__(self, val=0, next=None):\n self.val = val\n self.next = next\nclass Solution:\n def doubleIt(self, head: Optional[ListNode]) -> Optional[ListNode]:\n ", "prompt_sft": "You are given the head of a non-empty linked list representing a non-negative integer without leading zeroes.\n\nReturn the head of the linked list after doubling it.\n\nExample 1:\n\n[https://assets.leetcode.com/uploads/2023/05/28/example.png]\n\nInput: head = [1,8,9]\nOutput: [3,7,8]\nExplanation: The figure above corresponds to the given linked list which represents the number 189. Hence, the returned linked list represents the number 189 * 2 = 378.\n\nExample 2:\n\n[https://assets.leetcode.com/uploads/2023/05/28/example2.png]\n\nInput: head = [9,9,9]\nOutput: [1,9,9,8]\nExplanation: The figure above corresponds to the given linked list which represents the number 999. Hence, the returned linked list reprersents the number 999 * 2 = 1998.\n\n\nConstraints:\n\n * The number of nodes in the list is in the range [1, 104]\n * 0 <= Node.val <= 9\n * The input is generated such that the list represents a number that does not have leading zeros, except the number 0 itself.\n\n\nPlease complete the code below to solve above prblem:\n```python\n# Definition for singly-linked list.\nclass ListNode:\n def __init__(self, val=0, next=None):\n self.val = val\n self.next = next\nclass Solution:\n def doubleIt(self, head: Optional[ListNode]) -> Optional[ListNode]:\n \n```", "test": "\nmy_solution = Solution()\n\n_f1 = lambda lst: ListNode(lst[0], _f1(lst[1:])) if lst else None\n_f2 = lambda node: [node.val] + _f2(node.next) if node else []\n\n\ntest_input = { \"head\": _f1([1,8,9]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [3,7,8]\n\ntest_input = { \"head\": _f1([9,9,9]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,9,9,8]\n\ntest_input = { \"head\": _f1([0]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [0]\n\ntest_input = { \"head\": _f1([1]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [2]\n\ntest_input = { \"head\": _f1([2]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [4]\n\ntest_input = { \"head\": _f1([3]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [6]\n\ntest_input = { \"head\": _f1([4]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [8]\n\ntest_input = { \"head\": _f1([5]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,0]\n\ntest_input = { \"head\": _f1([6]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,2]\n\ntest_input = { \"head\": _f1([7]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,4]\n\ntest_input = { \"head\": _f1([8]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,6]\n\ntest_input = { \"head\": _f1([9]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,8]\n\ntest_input = { \"head\": _f1([1,0]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [2,0]\n\ntest_input = { \"head\": _f1([1,1]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [2,2]\n\ntest_input = { \"head\": _f1([1,2]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [2,4]\n\ntest_input = { \"head\": _f1([1,3]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [2,6]\n\ntest_input = { \"head\": _f1([1,4]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [2,8]\n\ntest_input = { \"head\": _f1([1,5]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [3,0]\n\ntest_input = { \"head\": _f1([1,6]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [3,2]\n\ntest_input = { \"head\": _f1([1,7]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [3,4]\n\ntest_input = { \"head\": _f1([1,8]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [3,6]\n\ntest_input = { \"head\": _f1([1,9]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [3,8]\n\ntest_input = { \"head\": _f1([2,0]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [4,0]\n\ntest_input = { \"head\": _f1([2,1]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [4,2]\n\ntest_input = { \"head\": _f1([2,2]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [4,4]\n\ntest_input = { \"head\": _f1([2,3]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [4,6]\n\ntest_input = { \"head\": _f1([2,4]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [4,8]\n\ntest_input = { \"head\": _f1([2,5]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [5,0]\n\ntest_input = { \"head\": _f1([2,6]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [5,2]\n\ntest_input = { \"head\": _f1([2,7]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [5,4]\n\ntest_input = { \"head\": _f1([2,8]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [5,6]\n\ntest_input = { \"head\": _f1([2,9]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [5,8]\n\ntest_input = { \"head\": _f1([3,0]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [6,0]\n\ntest_input = { \"head\": _f1([3,1]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [6,2]\n\ntest_input = { \"head\": _f1([3,2]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [6,4]\n\ntest_input = { \"head\": _f1([3,3]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [6,6]\n\ntest_input = { \"head\": _f1([3,4]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [6,8]\n\ntest_input = { \"head\": _f1([3,5]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [7,0]\n\ntest_input = { \"head\": _f1([3,6]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [7,2]\n\ntest_input = { \"head\": _f1([3,7]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [7,4]\n\ntest_input = { \"head\": _f1([3,8]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [7,6]\n\ntest_input = { \"head\": _f1([3,9]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [7,8]\n\ntest_input = { \"head\": _f1([4,0]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [8,0]\n\ntest_input = { \"head\": _f1([4,1]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [8,2]\n\ntest_input = { \"head\": _f1([4,2]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [8,4]\n\ntest_input = { \"head\": _f1([4,3]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [8,6]\n\ntest_input = { \"head\": _f1([4,4]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [8,8]\n\ntest_input = { \"head\": _f1([4,5]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [9,0]\n\ntest_input = { \"head\": _f1([4,6]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [9,2]\n\ntest_input = { \"head\": _f1([4,7]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [9,4]\n\ntest_input = { \"head\": _f1([4,8]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [9,6]\n\ntest_input = { \"head\": _f1([4,9]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [9,8]\n\ntest_input = { \"head\": _f1([5,0]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,0,0]\n\ntest_input = { \"head\": _f1([5,1]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,0,2]\n\ntest_input = { \"head\": _f1([5,2]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,0,4]\n\ntest_input = { \"head\": _f1([5,3]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,0,6]\n\ntest_input = { \"head\": _f1([5,4]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,0,8]\n\ntest_input = { \"head\": _f1([5,5]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,1,0]\n\ntest_input = { \"head\": _f1([5,6]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,1,2]\n\ntest_input = { \"head\": _f1([5,7]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,1,4]\n\ntest_input = { \"head\": _f1([5,8]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,1,6]\n\ntest_input = { \"head\": _f1([5,9]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,1,8]\n\ntest_input = { \"head\": _f1([6,0]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,2,0]\n\ntest_input = { \"head\": _f1([6,1]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,2,2]\n\ntest_input = { \"head\": _f1([6,2]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,2,4]\n\ntest_input = { \"head\": _f1([6,3]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,2,6]\n\ntest_input = { \"head\": _f1([6,4]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,2,8]\n\ntest_input = { \"head\": _f1([6,5]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,3,0]\n\ntest_input = { \"head\": _f1([6,6]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,3,2]\n\ntest_input = { \"head\": _f1([6,7]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,3,4]\n\ntest_input = { \"head\": _f1([6,8]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,3,6]\n\ntest_input = { \"head\": _f1([6,9]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,3,8]\n\ntest_input = { \"head\": _f1([7,0]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,4,0]\n\ntest_input = { \"head\": _f1([7,1]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,4,2]\n\ntest_input = { \"head\": _f1([7,2]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,4,4]\n\ntest_input = { \"head\": _f1([7,3]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,4,6]\n\ntest_input = { \"head\": _f1([7,4]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,4,8]\n\ntest_input = { \"head\": _f1([7,5]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,5,0]\n\ntest_input = { \"head\": _f1([7,6]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,5,2]\n\ntest_input = { \"head\": _f1([7,7]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,5,4]\n\ntest_input = { \"head\": _f1([7,8]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,5,6]\n\ntest_input = { \"head\": _f1([7,9]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,5,8]\n\ntest_input = { \"head\": _f1([8,0]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,6,0]\n\ntest_input = { \"head\": _f1([8,1]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,6,2]\n\ntest_input = { \"head\": _f1([8,2]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,6,4]\n\ntest_input = { \"head\": _f1([8,3]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,6,6]\n\ntest_input = { \"head\": _f1([8,4]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,6,8]\n\ntest_input = { \"head\": _f1([8,5]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,7,0]\n\ntest_input = { \"head\": _f1([8,6]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,7,2]\n\ntest_input = { \"head\": _f1([8,7]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,7,4]\n\ntest_input = { \"head\": _f1([8,8]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,7,6]\n\ntest_input = { \"head\": _f1([8,9]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,7,8]\n\ntest_input = { \"head\": _f1([9,0]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,8,0]\n\ntest_input = { \"head\": _f1([9,1]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,8,2]\n\ntest_input = { \"head\": _f1([9,2]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,8,4]\n\ntest_input = { \"head\": _f1([9,3]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,8,6]\n\ntest_input = { \"head\": _f1([9,4]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,8,8]\n\ntest_input = { \"head\": _f1([9,5]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,9,0]\n\ntest_input = { \"head\": _f1([9,6]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,9,2]\n\ntest_input = { \"head\": _f1([9,7]) }\nassert _f2(my_solution.doubleIt(**test_input)) == [1,9,4]", "start_time": 1691893800} +{"task_id": "weekly-contest-358-minimum-absolute-difference-between-elements-with-constraint", "url": "https://leetcode.com/problems/minimum-absolute-difference-between-elements-with-constraint", "title": "minimum-absolute-difference-between-elements-with-constraint", "meta": {"questionId": "3000", "questionFrontendId": "2817", "title": "Minimum Absolute Difference Between Elements With Constraint", "titleSlug": "minimum-absolute-difference-between-elements-with-constraint", "isPaidOnly": false, "difficulty": "Medium", "likes": 618, "dislikes": 64, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed integer array nums and an integer x.\n\nFind the minimum absolute difference between two elements in the array that are at least x indices apart.\n\nIn other words, find two indices i and j such that abs(i - j) >= x and abs(nums[i] - nums[j]) is minimized.\n\nReturn an integer denoting the minimum absolute difference between two elements that are at least x indices apart.\n\nExample 1:\n\nInput: nums = [4,3,2,4], x = 2\nOutput: 0\nExplanation: We can select nums[0] = 4 and nums[3] = 4.\nThey are at least 2 indices apart, and their absolute difference is the minimum, 0.\nIt can be shown that 0 is the optimal answer.\n\nExample 2:\n\nInput: nums = [5,3,2,10,15], x = 1\nOutput: 1\nExplanation: We can select nums[1] = 3 and nums[2] = 2.\nThey are at least 1 index apart, and their absolute difference is the minimum, 1.\nIt can be shown that 1 is the optimal answer.\n\nExample 3:\n\nInput: nums = [1,2,3,4], x = 3\nOutput: 3\nExplanation: We can select nums[0] = 1 and nums[3] = 4.\nThey are at least 3 indices apart, and their absolute difference is the minimum, 3.\nIt can be shown that 3 is the optimal answer.\n\n\nConstraints:\n\n * 1 <= nums.length <= 105\n * 1 <= nums[i] <= 109\n * 0 <= x < nums.length\n\"\"\"\nclass Solution:\n def minAbsoluteDifference(self, nums: List[int], x: int) -> int:\n ", "prompt_sft": "You are given a 0-indexed integer array nums and an integer x.\n\nFind the minimum absolute difference between two elements in the array that are at least x indices apart.\n\nIn other words, find two indices i and j such that abs(i - j) >= x and abs(nums[i] - nums[j]) is minimized.\n\nReturn an integer denoting the minimum absolute difference between two elements that are at least x indices apart.\n\nExample 1:\n\nInput: nums = [4,3,2,4], x = 2\nOutput: 0\nExplanation: We can select nums[0] = 4 and nums[3] = 4.\nThey are at least 2 indices apart, and their absolute difference is the minimum, 0.\nIt can be shown that 0 is the optimal answer.\n\nExample 2:\n\nInput: nums = [5,3,2,10,15], x = 1\nOutput: 1\nExplanation: We can select nums[1] = 3 and nums[2] = 2.\nThey are at least 1 index apart, and their absolute difference is the minimum, 1.\nIt can be shown that 1 is the optimal answer.\n\nExample 3:\n\nInput: nums = [1,2,3,4], x = 3\nOutput: 3\nExplanation: We can select nums[0] = 1 and nums[3] = 4.\nThey are at least 3 indices apart, and their absolute difference is the minimum, 3.\nIt can be shown that 3 is the optimal answer.\n\n\nConstraints:\n\n * 1 <= nums.length <= 105\n * 1 <= nums[i] <= 109\n * 0 <= x < nums.length\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def minAbsoluteDifference(self, nums: List[int], x: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [4,3,2,4], \"x\": 2 }\nassert my_solution.minAbsoluteDifference(**test_input) == 0\n\ntest_input = { \"nums\": [5,3,2,10,15], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,3,4], \"x\": 3 }\nassert my_solution.minAbsoluteDifference(**test_input) == 3\n\ntest_input = { \"nums\": [1,67], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 66\n\ntest_input = { \"nums\": [7,398], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 391\n\ntest_input = { \"nums\": [12,141], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 129\n\ntest_input = { \"nums\": [21,75], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 54\n\ntest_input = { \"nums\": [22,147], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 125\n\ntest_input = { \"nums\": [25,197], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 172\n\ntest_input = { \"nums\": [27,275], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 248\n\ntest_input = { \"nums\": [37,192], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 155\n\ntest_input = { \"nums\": [41,163], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 122\n\ntest_input = { \"nums\": [45,49], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 4\n\ntest_input = { \"nums\": [48,195], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 147\n\ntest_input = { \"nums\": [68,68], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 0\n\ntest_input = { \"nums\": [71,4], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 67\n\ntest_input = { \"nums\": [72,169], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 97\n\ntest_input = { \"nums\": [74,62], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 12\n\ntest_input = { \"nums\": [75,1], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 74\n\ntest_input = { \"nums\": [76,49], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 27\n\ntest_input = { \"nums\": [88,72], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 16\n\ntest_input = { \"nums\": [99,370], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 271\n\ntest_input = { \"nums\": [103,39], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 64\n\ntest_input = { \"nums\": [109,99], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 10\n\ntest_input = { \"nums\": [111,161], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 50\n\ntest_input = { \"nums\": [113,117], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 4\n\ntest_input = { \"nums\": [119,184], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 65\n\ntest_input = { \"nums\": [122,118], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 4\n\ntest_input = { \"nums\": [123,13], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 110\n\ntest_input = { \"nums\": [123,162], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 39\n\ntest_input = { \"nums\": [126,69], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 57\n\ntest_input = { \"nums\": [127,18], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 109\n\ntest_input = { \"nums\": [127,346], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 219\n\ntest_input = { \"nums\": [132,110], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 22\n\ntest_input = { \"nums\": [134,23], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 111\n\ntest_input = { \"nums\": [136,150], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 14\n\ntest_input = { \"nums\": [139,215], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 76\n\ntest_input = { \"nums\": [153,3], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 150\n\ntest_input = { \"nums\": [156,67], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 89\n\ntest_input = { \"nums\": [160,168], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 8\n\ntest_input = { \"nums\": [161,93], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 68\n\ntest_input = { \"nums\": [164,81], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 83\n\ntest_input = { \"nums\": [167,83], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 84\n\ntest_input = { \"nums\": [174,58], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 116\n\ntest_input = { \"nums\": [174,102], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 72\n\ntest_input = { \"nums\": [175,137], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 38\n\ntest_input = { \"nums\": [176,99], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 77\n\ntest_input = { \"nums\": [178,179], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 1\n\ntest_input = { \"nums\": [228,359], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 131\n\ntest_input = { \"nums\": [243,280], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 37\n\ntest_input = { \"nums\": [283,62], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 221\n\ntest_input = { \"nums\": [288,149], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 139\n\ntest_input = { \"nums\": [293,278], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 15\n\ntest_input = { \"nums\": [327,425], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 98\n\ntest_input = { \"nums\": [337,187], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 150\n\ntest_input = { \"nums\": [346,160], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 186\n\ntest_input = { \"nums\": [347,369], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 22\n\ntest_input = { \"nums\": [355,199], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 156\n\ntest_input = { \"nums\": [413,311], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 102\n\ntest_input = { \"nums\": [417,320], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 97\n\ntest_input = { \"nums\": [418,131], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 287\n\ntest_input = { \"nums\": [3274,71], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 3203\n\ntest_input = { \"nums\": [5,14,81], \"x\": 2 }\nassert my_solution.minAbsoluteDifference(**test_input) == 76\n\ntest_input = { \"nums\": [9,25,15], \"x\": 2 }\nassert my_solution.minAbsoluteDifference(**test_input) == 6\n\ntest_input = { \"nums\": [9,113,136], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 23\n\ntest_input = { \"nums\": [13,19,12], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 1\n\ntest_input = { \"nums\": [13,94,59], \"x\": 2 }\nassert my_solution.minAbsoluteDifference(**test_input) == 46\n\ntest_input = { \"nums\": [14,111,16], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 2\n\ntest_input = { \"nums\": [17,173,69], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 52\n\ntest_input = { \"nums\": [24,39,28], \"x\": 2 }\nassert my_solution.minAbsoluteDifference(**test_input) == 4\n\ntest_input = { \"nums\": [32,129,93], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 36\n\ntest_input = { \"nums\": [33,18,131], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 15\n\ntest_input = { \"nums\": [36,19,27], \"x\": 2 }\nassert my_solution.minAbsoluteDifference(**test_input) == 9\n\ntest_input = { \"nums\": [40,18,17], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 1\n\ntest_input = { \"nums\": [43,49,20], \"x\": 2 }\nassert my_solution.minAbsoluteDifference(**test_input) == 23\n\ntest_input = { \"nums\": [44,186,163], \"x\": 2 }\nassert my_solution.minAbsoluteDifference(**test_input) == 119\n\ntest_input = { \"nums\": [56,23,158], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 33\n\ntest_input = { \"nums\": [62,37,182], \"x\": 2 }\nassert my_solution.minAbsoluteDifference(**test_input) == 120\n\ntest_input = { \"nums\": [63,116,12], \"x\": 2 }\nassert my_solution.minAbsoluteDifference(**test_input) == 51\n\ntest_input = { \"nums\": [66,345,278], \"x\": 2 }\nassert my_solution.minAbsoluteDifference(**test_input) == 212\n\ntest_input = { \"nums\": [67,81,165], \"x\": 2 }\nassert my_solution.minAbsoluteDifference(**test_input) == 98\n\ntest_input = { \"nums\": [70,184,70], \"x\": 2 }\nassert my_solution.minAbsoluteDifference(**test_input) == 0\n\ntest_input = { \"nums\": [73,106,172], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 33\n\ntest_input = { \"nums\": [74,199,57], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 17\n\ntest_input = { \"nums\": [83,14,14], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 0\n\ntest_input = { \"nums\": [86,1,129], \"x\": 2 }\nassert my_solution.minAbsoluteDifference(**test_input) == 43\n\ntest_input = { \"nums\": [87,194,107], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 20\n\ntest_input = { \"nums\": [88,75,122], \"x\": 2 }\nassert my_solution.minAbsoluteDifference(**test_input) == 34\n\ntest_input = { \"nums\": [93,96,28], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 3\n\ntest_input = { \"nums\": [95,86,132], \"x\": 2 }\nassert my_solution.minAbsoluteDifference(**test_input) == 37\n\ntest_input = { \"nums\": [96,41,24], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 17\n\ntest_input = { \"nums\": [116,6,3], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 3\n\ntest_input = { \"nums\": [120,102,184], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 18\n\ntest_input = { \"nums\": [123,113,20], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 10\n\ntest_input = { \"nums\": [125,14,141], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 16\n\ntest_input = { \"nums\": [126,2,180], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 54\n\ntest_input = { \"nums\": [136,24,114], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 22\n\ntest_input = { \"nums\": [136,177,98], \"x\": 2 }\nassert my_solution.minAbsoluteDifference(**test_input) == 38\n\ntest_input = { \"nums\": [136,177,123], \"x\": 1 }\nassert my_solution.minAbsoluteDifference(**test_input) == 13\n\ntest_input = { \"nums\": [136,178,18], \"x\": 2 }\nassert my_solution.minAbsoluteDifference(**test_input) == 118", "start_time": 1691893800} +{"task_id": "weekly-contest-358-apply-operations-to-maximize-score", "url": "https://leetcode.com/problems/apply-operations-to-maximize-score", "title": "apply-operations-to-maximize-score", "meta": {"questionId": "3001", "questionFrontendId": "2818", "title": "Apply Operations to Maximize Score", "titleSlug": "apply-operations-to-maximize-score", "isPaidOnly": false, "difficulty": "Hard", "likes": 301, "dislikes": 9, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given an array nums of n positive integers and an integer k.\n\nInitially, you start with a score of 1. You have to maximize your score by applying the following operation at most k times:\n\n * Choose any non-empty subarray nums[l, ..., r] that you haven't chosen previously.\n * Choose an element x of nums[l, ..., r] with the highest prime score. If multiple such elements exist, choose the one with the smallest index.\n * Multiply your score by x.\n\nHere, nums[l, ..., r] denotes the subarray of nums starting at index l and ending at the index r, both ends being inclusive.\n\nThe prime score of an integer x is equal to the number of distinct prime factors of x. For example, the prime score of 300 is 3 since 300 = 2 * 2 * 3 * 5 * 5.\n\nReturn the maximum possible score after applying at most k operations.\n\nSince the answer may be large, return it modulo 109 + 7.\n\nExample 1:\n\nInput: nums = [8,3,9,3,8], k = 2\nOutput: 81\nExplanation: To get a score of 81, we can apply the following operations:\n- Choose subarray nums[2, ..., 2]. nums[2] is the only element in this subarray. Hence, we multiply the score by nums[2]. The score becomes 1 * 9 = 9.\n- Choose subarray nums[2, ..., 3]. Both nums[2] and nums[3] have a prime score of 1, but nums[2] has the smaller index. Hence, we multiply the score by nums[2]. The score becomes 9 * 9 = 81.\nIt can be proven that 81 is the highest score one can obtain.\n\nExample 2:\n\nInput: nums = [19,12,14,6,10,18], k = 3\nOutput: 4788\nExplanation: To get a score of 4788, we can apply the following operations:\n- Choose subarray nums[0, ..., 0]. nums[0] is the only element in this subarray. Hence, we multiply the score by nums[0]. The score becomes 1 * 19 = 19.\n- Choose subarray nums[5, ..., 5]. nums[5] is the only element in this subarray. Hence, we multiply the score by nums[5]. The score becomes 19 * 18 = 342.\n- Choose subarray nums[2, ..., 3]. Both nums[2] and nums[3] have a prime score of 2, but nums[2] has the smaller index. Hence, we multipy the score by nums[2]. The score becomes 342 * 14 = 4788.\nIt can be proven that 4788 is the highest score one can obtain.\n\n\nConstraints:\n\n * 1 <= nums.length == n <= 105\n * 1 <= nums[i] <= 105\n * 1 <= k <= min(n * (n + 1) / 2, 109)\n\"\"\"\nclass Solution:\n def maximumScore(self, nums: List[int], k: int) -> int:\n ", "prompt_sft": "You are given an array nums of n positive integers and an integer k.\n\nInitially, you start with a score of 1. You have to maximize your score by applying the following operation at most k times:\n\n * Choose any non-empty subarray nums[l, ..., r] that you haven't chosen previously.\n * Choose an element x of nums[l, ..., r] with the highest prime score. If multiple such elements exist, choose the one with the smallest index.\n * Multiply your score by x.\n\nHere, nums[l, ..., r] denotes the subarray of nums starting at index l and ending at the index r, both ends being inclusive.\n\nThe prime score of an integer x is equal to the number of distinct prime factors of x. For example, the prime score of 300 is 3 since 300 = 2 * 2 * 3 * 5 * 5.\n\nReturn the maximum possible score after applying at most k operations.\n\nSince the answer may be large, return it modulo 109 + 7.\n\nExample 1:\n\nInput: nums = [8,3,9,3,8], k = 2\nOutput: 81\nExplanation: To get a score of 81, we can apply the following operations:\n- Choose subarray nums[2, ..., 2]. nums[2] is the only element in this subarray. Hence, we multiply the score by nums[2]. The score becomes 1 * 9 = 9.\n- Choose subarray nums[2, ..., 3]. Both nums[2] and nums[3] have a prime score of 1, but nums[2] has the smaller index. Hence, we multiply the score by nums[2]. The score becomes 9 * 9 = 81.\nIt can be proven that 81 is the highest score one can obtain.\n\nExample 2:\n\nInput: nums = [19,12,14,6,10,18], k = 3\nOutput: 4788\nExplanation: To get a score of 4788, we can apply the following operations:\n- Choose subarray nums[0, ..., 0]. nums[0] is the only element in this subarray. Hence, we multiply the score by nums[0]. The score becomes 1 * 19 = 19.\n- Choose subarray nums[5, ..., 5]. nums[5] is the only element in this subarray. Hence, we multiply the score by nums[5]. The score becomes 19 * 18 = 342.\n- Choose subarray nums[2, ..., 3]. Both nums[2] and nums[3] have a prime score of 2, but nums[2] has the smaller index. Hence, we multipy the score by nums[2]. The score becomes 342 * 14 = 4788.\nIt can be proven that 4788 is the highest score one can obtain.\n\n\nConstraints:\n\n * 1 <= nums.length == n <= 105\n * 1 <= nums[i] <= 105\n * 1 <= k <= min(n * (n + 1) / 2, 109)\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def maximumScore(self, nums: List[int], k: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [8,3,9,3,8], \"k\": 2 }\nassert my_solution.maximumScore(**test_input) == 81\n\ntest_input = { \"nums\": [19,12,14,6,10,18], \"k\": 3 }\nassert my_solution.maximumScore(**test_input) == 4788\n\ntest_input = { \"nums\": [3289,2832,14858,22011], \"k\": 6 }\nassert my_solution.maximumScore(**test_input) == 256720975\n\ntest_input = { \"nums\": [1,7,11,1,5], \"k\": 14 }\nassert my_solution.maximumScore(**test_input) == 823751938\n\ntest_input = { \"nums\": [1,1,2,18,1,9,3,1], \"k\": 32 }\nassert my_solution.maximumScore(**test_input) == 346264255\n\ntest_input = { \"nums\": [1,1,1], \"k\": 2 }\nassert my_solution.maximumScore(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,1,12,1,3], \"k\": 3 }\nassert my_solution.maximumScore(**test_input) == 1728\n\ntest_input = { \"nums\": [12,5,1,6,9,1,17,14], \"k\": 12 }\nassert my_solution.maximumScore(**test_input) == 62996359\n\ntest_input = { \"nums\": [1], \"k\": 1 }\nassert my_solution.maximumScore(**test_input) == 1\n\ntest_input = { \"nums\": [1,10,15,1,3], \"k\": 13 }\nassert my_solution.maximumScore(**test_input) == 499978741\n\ntest_input = { \"nums\": [6,1,13,10,1,17,6], \"k\": 27 }\nassert my_solution.maximumScore(**test_input) == 630596200\n\ntest_input = { \"nums\": [1,14], \"k\": 1 }\nassert my_solution.maximumScore(**test_input) == 14\n\ntest_input = { \"nums\": [2,1,14,5,18,1,8,5], \"k\": 34 }\nassert my_solution.maximumScore(**test_input) == 799392504\n\ntest_input = { \"nums\": [5,12,11,15,10,18], \"k\": 18 }\nassert my_solution.maximumScore(**test_input) == 557423913\n\ntest_input = { \"nums\": [4,1], \"k\": 3 }\nassert my_solution.maximumScore(**test_input) == 16\n\ntest_input = { \"nums\": [1,2,5,1,10,1,1], \"k\": 20 }\nassert my_solution.maximumScore(**test_input) == 600000014\n\ntest_input = { \"nums\": [13,16,12,15,12,1,13,1,18,1], \"k\": 46 }\nassert my_solution.maximumScore(**test_input) == 912532739\n\ntest_input = { \"nums\": [10,11], \"k\": 3 }\nassert my_solution.maximumScore(**test_input) == 1100\n\ntest_input = { \"nums\": [15,16,12,1,10,14], \"k\": 19 }\nassert my_solution.maximumScore(**test_input) == 311972352\n\ntest_input = { \"nums\": [14,12,5,2,14], \"k\": 6 }\nassert my_solution.maximumScore(**test_input) == 7529536\n\ntest_input = { \"nums\": [1,13,12,1,9,12,1,18], \"k\": 31 }\nassert my_solution.maximumScore(**test_input) == 846374420\n\ntest_input = { \"nums\": [1,6,14,10,16], \"k\": 4 }\nassert my_solution.maximumScore(**test_input) == 43904\n\ntest_input = { \"nums\": [14,1,9,1,10], \"k\": 3 }\nassert my_solution.maximumScore(**test_input) == 2744\n\ntest_input = { \"nums\": [13,1,1,15,9,1,1], \"k\": 22 }\nassert my_solution.maximumScore(**test_input) == 925331761\n\ntest_input = { \"nums\": [1,17,3,9,10,17,1,1,1,11], \"k\": 22 }\nassert my_solution.maximumScore(**test_input) == 407065837\n\ntest_input = { \"nums\": [1,1,1], \"k\": 5 }\nassert my_solution.maximumScore(**test_input) == 1\n\ntest_input = { \"nums\": [1,13,4,1,1], \"k\": 14 }\nassert my_solution.maximumScore(**test_input) == 206765780\n\ntest_input = { \"nums\": [3,1,3,10,2,16], \"k\": 16 }\nassert my_solution.maximumScore(**test_input) == 996976007\n\ntest_input = { \"nums\": [1,2,1,1,16,8,11,6], \"k\": 27 }\nassert my_solution.maximumScore(**test_input) == 33977400\n\ntest_input = { \"nums\": [1,10,13,1,9,15,1], \"k\": 2 }\nassert my_solution.maximumScore(**test_input) == 225\n\ntest_input = { \"nums\": [18,1], \"k\": 3 }\nassert my_solution.maximumScore(**test_input) == 324\n\ntest_input = { \"nums\": [16], \"k\": 1 }\nassert my_solution.maximumScore(**test_input) == 16\n\ntest_input = { \"nums\": [14,6,18,10,1,8,1,17], \"k\": 25 }\nassert my_solution.maximumScore(**test_input) == 677968714\n\ntest_input = { \"nums\": [15,16,12], \"k\": 6 }\nassert my_solution.maximumScore(**test_input) == 7776000\n\ntest_input = { \"nums\": [1,10,1,2], \"k\": 7 }\nassert my_solution.maximumScore(**test_input) == 2000000\n\ntest_input = { \"nums\": [13,1,10,1,15,6,1,12,6], \"k\": 10 }\nassert my_solution.maximumScore(**test_input) == 650386593\n\ntest_input = { \"nums\": [1,15,5,1,1,15,1,1], \"k\": 17 }\nassert my_solution.maximumScore(**test_input) == 10486853\n\ntest_input = { \"nums\": [1,9], \"k\": 2 }\nassert my_solution.maximumScore(**test_input) == 81\n\ntest_input = { \"nums\": [13,8,14,6,3,14,13,10,1], \"k\": 21 }\nassert my_solution.maximumScore(**test_input) == 247566578\n\ntest_input = { \"nums\": [4], \"k\": 1 }\nassert my_solution.maximumScore(**test_input) == 4\n\ntest_input = { \"nums\": [1,12,5,1,12], \"k\": 15 }\nassert my_solution.maximumScore(**test_input) == 209137175\n\ntest_input = { \"nums\": [1,5,1,11], \"k\": 4 }\nassert my_solution.maximumScore(**test_input) == 3025\n\ntest_input = { \"nums\": [3,6,17,1,1,17,18,12,16,5], \"k\": 9 }\nassert my_solution.maximumScore(**test_input) == 359288982\n\ntest_input = { \"nums\": [2,2,15,2,15,15], \"k\": 10 }\nassert my_solution.maximumScore(**test_input) == 650386593\n\ntest_input = { \"nums\": [1,12], \"k\": 1 }\nassert my_solution.maximumScore(**test_input) == 12\n\ntest_input = { \"nums\": [2,11,1,1], \"k\": 2 }\nassert my_solution.maximumScore(**test_input) == 121\n\ntest_input = { \"nums\": [11,15,18,4,11,7,1,1], \"k\": 32 }\nassert my_solution.maximumScore(**test_input) == 179964426\n\ntest_input = { \"nums\": [10,1,15], \"k\": 1 }\nassert my_solution.maximumScore(**test_input) == 15\n\ntest_input = { \"nums\": [10,1,1,9,14,6,4,18,8], \"k\": 10 }\nassert my_solution.maximumScore(**test_input) == 420565606\n\ntest_input = { \"nums\": [6,8], \"k\": 3 }\nassert my_solution.maximumScore(**test_input) == 288\n\ntest_input = { \"nums\": [13,1,10,6], \"k\": 4 }\nassert my_solution.maximumScore(**test_input) == 16900\n\ntest_input = { \"nums\": [8,10,16,1,1,1], \"k\": 2 }\nassert my_solution.maximumScore(**test_input) == 256\n\ntest_input = { \"nums\": [11,2,1], \"k\": 4 }\nassert my_solution.maximumScore(**test_input) == 2662\n\ntest_input = { \"nums\": [15], \"k\": 1 }\nassert my_solution.maximumScore(**test_input) == 15\n\ntest_input = { \"nums\": [5,5,16,12,8,1,1,7,12], \"k\": 34 }\nassert my_solution.maximumScore(**test_input) == 15762264\n\ntest_input = { \"nums\": [1,1], \"k\": 1 }\nassert my_solution.maximumScore(**test_input) == 1\n\ntest_input = { \"nums\": [3,18,12,8,1,3,6], \"k\": 23 }\nassert my_solution.maximumScore(**test_input) == 18966086\n\ntest_input = { \"nums\": [13,1,5,6], \"k\": 8 }\nassert my_solution.maximumScore(**test_input) == 14236560\n\ntest_input = { \"nums\": [1,1,15,1,9,1,1], \"k\": 23 }\nassert my_solution.maximumScore(**test_input) == 929527145\n\ntest_input = { \"nums\": [6,2,1,17,9,14,1], \"k\": 25 }\nassert my_solution.maximumScore(**test_input) == 808455901\n\ntest_input = { \"nums\": [1,18], \"k\": 3 }\nassert my_solution.maximumScore(**test_input) == 324\n\ntest_input = { \"nums\": [1,10], \"k\": 2 }\nassert my_solution.maximumScore(**test_input) == 100\n\ntest_input = { \"nums\": [17], \"k\": 1 }\nassert my_solution.maximumScore(**test_input) == 17\n\ntest_input = { \"nums\": [18,13,12,1,11], \"k\": 8 }\nassert my_solution.maximumScore(**test_input) == 537271275\n\ntest_input = { \"nums\": [10,14,18,6,12,14,3,13], \"k\": 23 }\nassert my_solution.maximumScore(**test_input) == 795923147\n\ntest_input = { \"nums\": [16,1,14,13,3,1], \"k\": 6 }\nassert my_solution.maximumScore(**test_input) == 9834496\n\ntest_input = { \"nums\": [10,4,4,3,10,1], \"k\": 15 }\nassert my_solution.maximumScore(**test_input) == 997200007\n\ntest_input = { \"nums\": [2,4,1,5,14,13,13,17], \"k\": 19 }\nassert my_solution.maximumScore(**test_input) == 241329678\n\ntest_input = { \"nums\": [6,1,15,1,13], \"k\": 12 }\nassert my_solution.maximumScore(**test_input) == 820232542\n\ntest_input = { \"nums\": [14,13,1,14], \"k\": 5 }\nassert my_solution.maximumScore(**test_input) == 537824\n\ntest_input = { \"nums\": [10,4,12,12,16,9,1,18], \"k\": 36 }\nassert my_solution.maximumScore(**test_input) == 892891506\n\ntest_input = { \"nums\": [6], \"k\": 1 }\nassert my_solution.maximumScore(**test_input) == 6\n\ntest_input = { \"nums\": [12], \"k\": 1 }\nassert my_solution.maximumScore(**test_input) == 12\n\ntest_input = { \"nums\": [10,17,17,15,1,15,1], \"k\": 19 }\nassert my_solution.maximumScore(**test_input) == 301460564\n\ntest_input = { \"nums\": [10,3,1,1,4,2,14], \"k\": 10 }\nassert my_solution.maximumScore(**test_input) == 295359475\n\ntest_input = { \"nums\": [10,12], \"k\": 3 }\nassert my_solution.maximumScore(**test_input) == 1200\n\ntest_input = { \"nums\": [9,10,2,3,2,1,11,1,1,13], \"k\": 49 }\nassert my_solution.maximumScore(**test_input) == 900432644\n\ntest_input = { \"nums\": [1,10,18,18,3,1,8,1,15,15], \"k\": 18 }\nassert my_solution.maximumScore(**test_input) == 38759446\n\ntest_input = { \"nums\": [15,1,11,13,16], \"k\": 14 }\nassert my_solution.maximumScore(**test_input) == 753886562\n\ntest_input = { \"nums\": [12,1,6,1,1,4,8,17,18,1], \"k\": 2 }\nassert my_solution.maximumScore(**test_input) == 324\n\ntest_input = { \"nums\": [1,1,1,17,8,18,8,1], \"k\": 14 }\nassert my_solution.maximumScore(**test_input) == 958387476\n\ntest_input = { \"nums\": [7,1,6,9,11,7,13,12,1], \"k\": 39 }\nassert my_solution.maximumScore(**test_input) == 21295572\n\ntest_input = { \"nums\": [12,1,1,15,2,1,1,16,1,1], \"k\": 8 }\nassert my_solution.maximumScore(**test_input) == 294967268\n\ntest_input = { \"nums\": [3,14,13,1,11,1,1,1], \"k\": 22 }\nassert my_solution.maximumScore(**test_input) == 810815174\n\ntest_input = { \"nums\": [14,3,6,6,1,7,13,16], \"k\": 28 }\nassert my_solution.maximumScore(**test_input) == 312142986\n\ntest_input = { \"nums\": [3,4,4,15,18,12,6], \"k\": 8 }\nassert my_solution.maximumScore(**test_input) == 428674972\n\ntest_input = { \"nums\": [6,15,17,9,9,17], \"k\": 5 }\nassert my_solution.maximumScore(**test_input) == 1419857\n\ntest_input = { \"nums\": [2,12,1,11,12], \"k\": 5 }\nassert my_solution.maximumScore(**test_input) == 248832\n\ntest_input = { \"nums\": [1,15,15], \"k\": 4 }\nassert my_solution.maximumScore(**test_input) == 50625\n\ntest_input = { \"nums\": [7,11,3,1,12,10], \"k\": 15 }\nassert my_solution.maximumScore(**test_input) == 784368200\n\ntest_input = { \"nums\": [18,1,11,15,16,18,18,13,10,10], \"k\": 41 }\nassert my_solution.maximumScore(**test_input) == 911212578\n\ntest_input = { \"nums\": [11,15,2,14,6,15], \"k\": 2 }\nassert my_solution.maximumScore(**test_input) == 225\n\ntest_input = { \"nums\": [11,2,15,1,1,11,7,1], \"k\": 16 }\nassert my_solution.maximumScore(**test_input) == 734032462\n\ntest_input = { \"nums\": [1,6,12,4,10,13,7,6,17,1], \"k\": 50 }\nassert my_solution.maximumScore(**test_input) == 377786273\n\ntest_input = { \"nums\": [1,5,4,18,12,1,1,1,7,12], \"k\": 3 }\nassert my_solution.maximumScore(**test_input) == 5832\n\ntest_input = { \"nums\": [5,1,17,10,12], \"k\": 9 }\nassert my_solution.maximumScore(**test_input) == 467999979\n\ntest_input = { \"nums\": [6,1,1,4,10,15,16,8], \"k\": 12 }\nassert my_solution.maximumScore(**test_input) == 999939527\n\ntest_input = { \"nums\": [1,1], \"k\": 3 }\nassert my_solution.maximumScore(**test_input) == 1\n\ntest_input = { \"nums\": [8], \"k\": 1 }\nassert my_solution.maximumScore(**test_input) == 8\n\ntest_input = { \"nums\": [9,8,14,1,14,14,5,1,6], \"k\": 44 }\nassert my_solution.maximumScore(**test_input) == 439903801", "start_time": 1691893800} +{"task_id": "weekly-contest-357-faulty-keyboard", "url": "https://leetcode.com/problems/faulty-keyboard", "title": "faulty-keyboard", "meta": {"questionId": "2886", "questionFrontendId": "2810", "title": "Faulty Keyboard", "titleSlug": "faulty-keyboard", "isPaidOnly": false, "difficulty": "Easy", "likes": 343, "dislikes": 5, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYour laptop keyboard is faulty, and whenever you type a character 'i' on it, it reverses the string that you have written. Typing other characters works as expected.\n\nYou are given a 0-indexed string s, and you type each character of s using your faulty keyboard.\n\nReturn the final string that will be present on your laptop screen.\n\nExample 1:\n\nInput: s = \"string\"\nOutput: \"rtsng\"\nExplanation:\nAfter typing first character, the text on the screen is \"s\".\nAfter the second character, the text is \"st\".\nAfter the third character, the text is \"str\".\nSince the fourth character is an 'i', the text gets reversed and becomes \"rts\".\nAfter the fifth character, the text is \"rtsn\".\nAfter the sixth character, the text is \"rtsng\".\nTherefore, we return \"rtsng\".\n\nExample 2:\n\nInput: s = \"poiinter\"\nOutput: \"ponter\"\nExplanation:\nAfter the first character, the text on the screen is \"p\".\nAfter the second character, the text is \"po\".\nSince the third character you type is an 'i', the text gets reversed and becomes \"op\".\nSince the fourth character you type is an 'i', the text gets reversed and becomes \"po\".\nAfter the fifth character, the text is \"pon\".\nAfter the sixth character, the text is \"pont\".\nAfter the seventh character, the text is \"ponte\".\nAfter the eighth character, the text is \"ponter\".\nTherefore, we return \"ponter\".\n\nConstraints:\n\n * 1 <= s.length <= 100\n * s consists of lowercase English letters.\n * s[0] != 'i'\n\"\"\"\nclass Solution:\n def finalString(self, s: str) -> str:\n ", "prompt_sft": "Your laptop keyboard is faulty, and whenever you type a character 'i' on it, it reverses the string that you have written. Typing other characters works as expected.\n\nYou are given a 0-indexed string s, and you type each character of s using your faulty keyboard.\n\nReturn the final string that will be present on your laptop screen.\n\nExample 1:\n\nInput: s = \"string\"\nOutput: \"rtsng\"\nExplanation:\nAfter typing first character, the text on the screen is \"s\".\nAfter the second character, the text is \"st\".\nAfter the third character, the text is \"str\".\nSince the fourth character is an 'i', the text gets reversed and becomes \"rts\".\nAfter the fifth character, the text is \"rtsn\".\nAfter the sixth character, the text is \"rtsng\".\nTherefore, we return \"rtsng\".\n\nExample 2:\n\nInput: s = \"poiinter\"\nOutput: \"ponter\"\nExplanation:\nAfter the first character, the text on the screen is \"p\".\nAfter the second character, the text is \"po\".\nSince the third character you type is an 'i', the text gets reversed and becomes \"op\".\nSince the fourth character you type is an 'i', the text gets reversed and becomes \"po\".\nAfter the fifth character, the text is \"pon\".\nAfter the sixth character, the text is \"pont\".\nAfter the seventh character, the text is \"ponte\".\nAfter the eighth character, the text is \"ponter\".\nTherefore, we return \"ponter\".\n\nConstraints:\n\n * 1 <= s.length <= 100\n * s consists of lowercase English letters.\n * s[0] != 'i'\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def finalString(self, s: str) -> str:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"s\": \"string\" }\nassert my_solution.finalString(**test_input) == \"rtsng\"\n\ntest_input = { \"s\": \"poiinter\" }\nassert my_solution.finalString(**test_input) == \"ponter\"\n\ntest_input = { \"s\": \"goci\" }\nassert my_solution.finalString(**test_input) == \"cog\"\n\ntest_input = { \"s\": \"ksi\" }\nassert my_solution.finalString(**test_input) == \"sk\"\n\ntest_input = { \"s\": \"fii\" }\nassert my_solution.finalString(**test_input) == \"f\"\n\ntest_input = { \"s\": \"qskyviiiii\" }\nassert my_solution.finalString(**test_input) == \"vyksq\"\n\ntest_input = { \"s\": \"pft\" }\nassert my_solution.finalString(**test_input) == \"pft\"\n\ntest_input = { \"s\": \"viwif\" }\nassert my_solution.finalString(**test_input) == \"wvf\"\n\ntest_input = { \"s\": \"wiie\" }\nassert my_solution.finalString(**test_input) == \"we\"\n\ntest_input = { \"s\": \"kiis\" }\nassert my_solution.finalString(**test_input) == \"ks\"\n\ntest_input = { \"s\": \"xihbosxitx\" }\nassert my_solution.finalString(**test_input) == \"xsobhxtx\"\n\ntest_input = { \"s\": \"uwioili\" }\nassert my_solution.finalString(**test_input) == \"lwuo\"\n\ntest_input = { \"s\": \"aapziai\" }\nassert my_solution.finalString(**test_input) == \"aaapz\"\n\ntest_input = { \"s\": \"pviist\" }\nassert my_solution.finalString(**test_input) == \"pvst\"\n\ntest_input = { \"s\": \"miiuiei\" }\nassert my_solution.finalString(**test_input) == \"emu\"\n\ntest_input = { \"s\": \"diiiiq\" }\nassert my_solution.finalString(**test_input) == \"dq\"\n\ntest_input = { \"s\": \"eirov\" }\nassert my_solution.finalString(**test_input) == \"erov\"\n\ntest_input = { \"s\": \"niiiiisiii\" }\nassert my_solution.finalString(**test_input) == \"sn\"\n\ntest_input = { \"s\": \"siiuii\" }\nassert my_solution.finalString(**test_input) == \"su\"\n\ntest_input = { \"s\": \"piijciivq\" }\nassert my_solution.finalString(**test_input) == \"pjcvq\"\n\ntest_input = { \"s\": \"tidtwitik\" }\nassert my_solution.finalString(**test_input) == \"ttdtwk\"\n\ntest_input = { \"s\": \"z\" }\nassert my_solution.finalString(**test_input) == \"z\"\n\ntest_input = { \"s\": \"ffyuidnn\" }\nassert my_solution.finalString(**test_input) == \"uyffdnn\"\n\ntest_input = { \"s\": \"xitiiinix\" }\nassert my_solution.finalString(**test_input) == \"nxtx\"\n\ntest_input = { \"s\": \"ciiiuifab\" }\nassert my_solution.finalString(**test_input) == \"ucfab\"\n\ntest_input = { \"s\": \"x\" }\nassert my_solution.finalString(**test_input) == \"x\"\n\ntest_input = { \"s\": \"v\" }\nassert my_solution.finalString(**test_input) == \"v\"\n\ntest_input = { \"s\": \"liinii\" }\nassert my_solution.finalString(**test_input) == \"ln\"\n\ntest_input = { \"s\": \"ziii\" }\nassert my_solution.finalString(**test_input) == \"z\"\n\ntest_input = { \"s\": \"ei\" }\nassert my_solution.finalString(**test_input) == \"e\"\n\ntest_input = { \"s\": \"tidiiiii\" }\nassert my_solution.finalString(**test_input) == \"dt\"\n\ntest_input = { \"s\": \"krjiqjii\" }\nassert my_solution.finalString(**test_input) == \"jrkqj\"\n\ntest_input = { \"s\": \"mxczii\" }\nassert my_solution.finalString(**test_input) == \"mxcz\"\n\ntest_input = { \"s\": \"bz\" }\nassert my_solution.finalString(**test_input) == \"bz\"\n\ntest_input = { \"s\": \"zbwri\" }\nassert my_solution.finalString(**test_input) == \"rwbz\"\n\ntest_input = { \"s\": \"biiq\" }\nassert my_solution.finalString(**test_input) == \"bq\"\n\ntest_input = { \"s\": \"mmiiliir\" }\nassert my_solution.finalString(**test_input) == \"mmlr\"\n\ntest_input = { \"s\": \"plibeici\" }\nassert my_solution.finalString(**test_input) == \"clpbe\"\n\ntest_input = { \"s\": \"cii\" }\nassert my_solution.finalString(**test_input) == \"c\"\n\ntest_input = { \"s\": \"wiilg\" }\nassert my_solution.finalString(**test_input) == \"wlg\"\n\ntest_input = { \"s\": \"cdidi\" }\nassert my_solution.finalString(**test_input) == \"dcd\"\n\ntest_input = { \"s\": \"fsq\" }\nassert my_solution.finalString(**test_input) == \"fsq\"\n\ntest_input = { \"s\": \"hkjciaiii\" }\nassert my_solution.finalString(**test_input) == \"ahkjc\"\n\ntest_input = { \"s\": \"l\" }\nassert my_solution.finalString(**test_input) == \"l\"\n\ntest_input = { \"s\": \"vilcoizi\" }\nassert my_solution.finalString(**test_input) == \"zvlco\"\n\ntest_input = { \"s\": \"tgigivipx\" }\nassert my_solution.finalString(**test_input) == \"vgtgpx\"\n\ntest_input = { \"s\": \"ri\" }\nassert my_solution.finalString(**test_input) == \"r\"\n\ntest_input = { \"s\": \"kficiiioiy\" }\nassert my_solution.finalString(**test_input) == \"ofkcy\"\n\ntest_input = { \"s\": \"o\" }\nassert my_solution.finalString(**test_input) == \"o\"\n\ntest_input = { \"s\": \"piifwiiit\" }\nassert my_solution.finalString(**test_input) == \"wfpt\"\n\ntest_input = { \"s\": \"sifsiui\" }\nassert my_solution.finalString(**test_input) == \"usfs\"\n\ntest_input = { \"s\": \"sxiuiiiii\" }\nassert my_solution.finalString(**test_input) == \"usx\"\n\ntest_input = { \"s\": \"tiiiihiw\" }\nassert my_solution.finalString(**test_input) == \"htw\"\n\ntest_input = { \"s\": \"ko\" }\nassert my_solution.finalString(**test_input) == \"ko\"\n\ntest_input = { \"s\": \"gagi\" }\nassert my_solution.finalString(**test_input) == \"gag\"\n\ntest_input = { \"s\": \"yyigiir\" }\nassert my_solution.finalString(**test_input) == \"yygr\"\n\ntest_input = { \"s\": \"jimiiaci\" }\nassert my_solution.finalString(**test_input) == \"camj\"\n\ntest_input = { \"s\": \"xiiiei\" }\nassert my_solution.finalString(**test_input) == \"ex\"\n\ntest_input = { \"s\": \"hwi\" }\nassert my_solution.finalString(**test_input) == \"wh\"\n\ntest_input = { \"s\": \"ji\" }\nassert my_solution.finalString(**test_input) == \"j\"\n\ntest_input = { \"s\": \"heii\" }\nassert my_solution.finalString(**test_input) == \"he\"\n\ntest_input = { \"s\": \"zitjcq\" }\nassert my_solution.finalString(**test_input) == \"ztjcq\"\n\ntest_input = { \"s\": \"upmipaw\" }\nassert my_solution.finalString(**test_input) == \"mpupaw\"\n\ntest_input = { \"s\": \"fiixkgp\" }\nassert my_solution.finalString(**test_input) == \"fxkgp\"\n\ntest_input = { \"s\": \"ldr\" }\nassert my_solution.finalString(**test_input) == \"ldr\"\n\ntest_input = { \"s\": \"kiboiithi\" }\nassert my_solution.finalString(**test_input) == \"htobk\"\n\ntest_input = { \"s\": \"svcii\" }\nassert my_solution.finalString(**test_input) == \"svc\"\n\ntest_input = { \"s\": \"d\" }\nassert my_solution.finalString(**test_input) == \"d\"\n\ntest_input = { \"s\": \"edgijwiua\" }\nassert my_solution.finalString(**test_input) == \"wjedgua\"\n\ntest_input = { \"s\": \"wiidqoiwov\" }\nassert my_solution.finalString(**test_input) == \"oqdwwov\"\n\ntest_input = { \"s\": \"zimxiiqqi\" }\nassert my_solution.finalString(**test_input) == \"qqxmz\"\n\ntest_input = { \"s\": \"githpgiini\" }\nassert my_solution.finalString(**test_input) == \"ngphtg\"\n\ntest_input = { \"s\": \"fy\" }\nassert my_solution.finalString(**test_input) == \"fy\"\n\ntest_input = { \"s\": \"hesi\" }\nassert my_solution.finalString(**test_input) == \"seh\"\n\ntest_input = { \"s\": \"eiiii\" }\nassert my_solution.finalString(**test_input) == \"e\"\n\ntest_input = { \"s\": \"be\" }\nassert my_solution.finalString(**test_input) == \"be\"\n\ntest_input = { \"s\": \"rpi\" }\nassert my_solution.finalString(**test_input) == \"pr\"\n\ntest_input = { \"s\": \"mi\" }\nassert my_solution.finalString(**test_input) == \"m\"\n\ntest_input = { \"s\": \"wiiiiii\" }\nassert my_solution.finalString(**test_input) == \"w\"\n\ntest_input = { \"s\": \"rbiiiii\" }\nassert my_solution.finalString(**test_input) == \"br\"\n\ntest_input = { \"s\": \"diiii\" }\nassert my_solution.finalString(**test_input) == \"d\"\n\ntest_input = { \"s\": \"poiiifl\" }\nassert my_solution.finalString(**test_input) == \"opfl\"\n\ntest_input = { \"s\": \"loifiicii\" }\nassert my_solution.finalString(**test_input) == \"olfc\"\n\ntest_input = { \"s\": \"bii\" }\nassert my_solution.finalString(**test_input) == \"b\"\n\ntest_input = { \"s\": \"nirii\" }\nassert my_solution.finalString(**test_input) == \"nr\"\n\ntest_input = { \"s\": \"wiigipio\" }\nassert my_solution.finalString(**test_input) == \"pwgo\"\n\ntest_input = { \"s\": \"gimliibin\" }\nassert my_solution.finalString(**test_input) == \"blmgn\"\n\ntest_input = { \"s\": \"zi\" }\nassert my_solution.finalString(**test_input) == \"z\"\n\ntest_input = { \"s\": \"tjn\" }\nassert my_solution.finalString(**test_input) == \"tjn\"\n\ntest_input = { \"s\": \"ly\" }\nassert my_solution.finalString(**test_input) == \"ly\"\n\ntest_input = { \"s\": \"sqzviyiimi\" }\nassert my_solution.finalString(**test_input) == \"mysqzv\"\n\ntest_input = { \"s\": \"jhmaxm\" }\nassert my_solution.finalString(**test_input) == \"jhmaxm\"\n\ntest_input = { \"s\": \"py\" }\nassert my_solution.finalString(**test_input) == \"py\"\n\ntest_input = { \"s\": \"yyilwiib\" }\nassert my_solution.finalString(**test_input) == \"yylwb\"\n\ntest_input = { \"s\": \"ryjiilj\" }\nassert my_solution.finalString(**test_input) == \"ryjlj\"\n\ntest_input = { \"s\": \"tnokpgfii\" }\nassert my_solution.finalString(**test_input) == \"tnokpgf\"\n\ntest_input = { \"s\": \"niihiliiv\" }\nassert my_solution.finalString(**test_input) == \"hnlv\"\n\ntest_input = { \"s\": \"gvhms\" }\nassert my_solution.finalString(**test_input) == \"gvhms\"\n\ntest_input = { \"s\": \"yg\" }\nassert my_solution.finalString(**test_input) == \"yg\"\n\ntest_input = { \"s\": \"eiiiuizgi\" }\nassert my_solution.finalString(**test_input) == \"gzeu\"", "start_time": 1691289000} +{"task_id": "weekly-contest-357-check-if-it-is-possible-to-split-array", "url": "https://leetcode.com/problems/check-if-it-is-possible-to-split-array", "title": "check-if-it-is-possible-to-split-array", "meta": {"questionId": "2916", "questionFrontendId": "2811", "title": "Check if it is Possible to Split Array", "titleSlug": "check-if-it-is-possible-to-split-array", "isPaidOnly": false, "difficulty": "Medium", "likes": 425, "dislikes": 84, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given an array nums of length n and an integer m. You need to determine if it is possible to split the array into n non-empty arrays by performing a series of steps.\n\nIn each step, you can select an existing array (which may be the result of previous steps) with a length of at least two and split it into two subarrays, if, for each resulting subarray, at least one of the following holds:\n\n * The length of the subarray is one, or\n * The sum of elements of the subarray is greater than or equal to m.\n\nReturn true if you can split the given array into n arrays, otherwise return false.\n\nNote: A subarray is a contiguous non-empty sequence of elements within an array.\n\nExample 1:\n\nInput: nums = [2, 2, 1], m = 4\nOutput: true\nExplanation: We can split the array into [2, 2] and [1] in the first step. Then, in the second step, we can split [2, 2] into [2] and [2]. As a result, the answer is true.\n\nExample 2:\n\nInput: nums = [2, 1, 3], m = 5\nOutput: false\nExplanation: We can try splitting the array in two different ways: the first way is to have [2, 1] and [3], and the second way is to have [2] and [1, 3]. However, both of these ways are not valid. So, the answer is false.\n\nExample 3:\n\nInput: nums = [2, 3, 3, 2, 3], m = 6\nOutput: true\nExplanation: We can split the array into [2, 3, 3, 2] and [3] in the first step. Then, in the second step, we can split [2, 3, 3, 2] into [2, 3, 3] and [2]. Then, in the third step, we can split [2, 3, 3] into [2] and [3, 3]. And in the last step we can split [3, 3] into [3] and [3]. As a result, the answer is true.\n\n\nConstraints:\n\n * 1 <= n == nums.length <= 100\n * 1 <= nums[i] <= 100\n * 1 <= m <= 200\n\"\"\"\nclass Solution:\n def canSplitArray(self, nums: List[int], m: int) -> bool:\n ", "prompt_sft": "You are given an array nums of length n and an integer m. You need to determine if it is possible to split the array into n non-empty arrays by performing a series of steps.\n\nIn each step, you can select an existing array (which may be the result of previous steps) with a length of at least two and split it into two subarrays, if, for each resulting subarray, at least one of the following holds:\n\n * The length of the subarray is one, or\n * The sum of elements of the subarray is greater than or equal to m.\n\nReturn true if you can split the given array into n arrays, otherwise return false.\n\nNote: A subarray is a contiguous non-empty sequence of elements within an array.\n\nExample 1:\n\nInput: nums = [2, 2, 1], m = 4\nOutput: true\nExplanation: We can split the array into [2, 2] and [1] in the first step. Then, in the second step, we can split [2, 2] into [2] and [2]. As a result, the answer is true.\n\nExample 2:\n\nInput: nums = [2, 1, 3], m = 5\nOutput: false\nExplanation: We can try splitting the array in two different ways: the first way is to have [2, 1] and [3], and the second way is to have [2] and [1, 3]. However, both of these ways are not valid. So, the answer is false.\n\nExample 3:\n\nInput: nums = [2, 3, 3, 2, 3], m = 6\nOutput: true\nExplanation: We can split the array into [2, 3, 3, 2] and [3] in the first step. Then, in the second step, we can split [2, 3, 3, 2] into [2, 3, 3] and [2]. Then, in the third step, we can split [2, 3, 3] into [2] and [3, 3]. And in the last step we can split [3, 3] into [3] and [3]. As a result, the answer is true.\n\n\nConstraints:\n\n * 1 <= n == nums.length <= 100\n * 1 <= nums[i] <= 100\n * 1 <= m <= 200\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def canSplitArray(self, nums: List[int], m: int) -> bool:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [2, 2, 1], \"m\": 4 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [2, 3, 3, 2, 3], \"m\": 6 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [1], \"m\": 1 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [2, 1, 3], \"m\": 5 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [1, 1, 1], \"m\": 3 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [2], \"m\": 1 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [2, 1, 2], \"m\": 4 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [1, 2, 1], \"m\": 5 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [2, 2, 2], \"m\": 5 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [3, 1, 2], \"m\": 5 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [3], \"m\": 1 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [1], \"m\": 2 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [2], \"m\": 2 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [1, 3, 1], \"m\": 6 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [1, 3, 2], \"m\": 6 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [2, 1, 1], \"m\": 6 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [2, 2, 1], \"m\": 6 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [2, 2, 3], \"m\": 6 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [3], \"m\": 2 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [3, 1, 1], \"m\": 6 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [3, 1, 3], \"m\": 6 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [3], \"m\": 3 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [7], \"m\": 5 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [4], \"m\": 7 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [9], \"m\": 7 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [2], \"m\": 8 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [3, 2, 2], \"m\": 6 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [4], \"m\": 8 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [10], \"m\": 11 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [6], \"m\": 12 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [3, 2, 3], \"m\": 6 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [3, 3, 6], \"m\": 10 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [2], \"m\": 14 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [5, 3, 6], \"m\": 10 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [3], \"m\": 18 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [4, 6, 5], \"m\": 12 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [9, 7], \"m\": 1 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [1, 2], \"m\": 2 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [9, 1, 7], \"m\": 14 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [8, 2, 4], \"m\": 16 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [1, 3], \"m\": 2 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [2, 1], \"m\": 2 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [9, 5, 7], \"m\": 20 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [2, 3], \"m\": 2 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [1, 2, 1, 1], \"m\": 4 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [1, 2, 2, 5], \"m\": 8 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [4, 4, 4, 2], \"m\": 9 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [3, 2], \"m\": 2 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [8, 1, 2, 5], \"m\": 10 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [10, 2, 9, 3], \"m\": 14 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [3, 3], \"m\": 2 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [10, 4, 8, 6], \"m\": 16 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [14, 1, 1, 15], \"m\": 17 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [6, 11, 2, 12], \"m\": 18 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [14, 3, 12, 3], \"m\": 18 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [1, 1], \"m\": 3 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [1, 2], \"m\": 3 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [1, 1, 2, 2, 1], \"m\": 5 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [2, 2, 1, 3, 1], \"m\": 5 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [1, 3], \"m\": 3 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [3, 1, 1, 3, 1], \"m\": 5 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [2, 2], \"m\": 3 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [2, 3], \"m\": 3 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [2, 10], \"m\": 3 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [3, 1], \"m\": 3 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [3, 3], \"m\": 3 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [7, 9], \"m\": 3 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [3, 3, 1, 5, 1], \"m\": 7 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [1, 4, 2, 4, 2], \"m\": 8 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [2, 9, 2, 3, 2], \"m\": 12 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [1, 3], \"m\": 4 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [2, 2], \"m\": 4 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [4, 4, 4, 7, 5], \"m\": 13 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [5, 2, 6, 5, 4], \"m\": 13 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [2, 3], \"m\": 4 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [3, 1], \"m\": 4 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [13, 2, 13, 4, 11], \"m\": 18 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [5, 6, 10, 7, 4], \"m\": 19 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [16, 1, 12, 6, 7], \"m\": 19 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [3, 3], \"m\": 4 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [9, 9, 8, 10, 8], \"m\": 20 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [9, 4], \"m\": 5 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [10, 2], \"m\": 5 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [16, 2, 2, 16, 2], \"m\": 20 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [6, 2], \"m\": 7 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [1, 3, 1, 2, 1, 4], \"m\": 6 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [5, 1], \"m\": 8 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [1, 4, 4, 2, 1, 5], \"m\": 9 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [2, 5], \"m\": 12 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [10, 9], \"m\": 15 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [8, 4], \"m\": 18 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [3, 4, 3, 5, 2, 1], \"m\": 9 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [3, 7, 2, 8, 2, 4], \"m\": 11 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [8, 1], \"m\": 19 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [1, 1, 2], \"m\": 3 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [5, 1, 1, 9, 1, 5], \"m\": 11 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [1, 1, 3], \"m\": 3 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [6, 4, 7, 2, 5, 4], \"m\": 12 }\nassert my_solution.canSplitArray(**test_input) == False\n\ntest_input = { \"nums\": [1, 2, 1], \"m\": 3 }\nassert my_solution.canSplitArray(**test_input) == True\n\ntest_input = { \"nums\": [1, 3, 1], \"m\": 3 }\nassert my_solution.canSplitArray(**test_input) == True", "start_time": 1691289000} +{"task_id": "weekly-contest-357-find-the-safest-path-in-a-grid", "url": "https://leetcode.com/problems/find-the-safest-path-in-a-grid", "title": "find-the-safest-path-in-a-grid", "meta": {"questionId": "2914", "questionFrontendId": "2812", "title": "Find the Safest Path in a Grid", "titleSlug": "find-the-safest-path-in-a-grid", "isPaidOnly": false, "difficulty": "Medium", "likes": 706, "dislikes": 68, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed 2D matrix grid of size n x n, where (r, c) represents:\n\n * A cell containing a thief if grid[r][c] = 1\n * An empty cell if grid[r][c] = 0\n\nYou are initially positioned at cell (0, 0). In one move, you can move to any adjacent cell in the grid, including cells containing thieves.\n\nThe safeness factor of a path on the grid is defined as the minimum manhattan distance from any cell in the path to any thief in the grid.\n\nReturn the maximum safeness factor of all paths leading to cell (n - 1, n - 1).\n\nAn adjacent cell of cell (r, c), is one of the cells (r, c + 1), (r, c - 1), (r + 1, c) and (r - 1, c) if it exists.\n\nThe Manhattan distance between two cells (a, b) and (x, y) is equal to |a - x| + |b - y|, where |val| denotes the absolute value of val.\n\nExample 1:\n\n[https://assets.leetcode.com/uploads/2023/07/02/example1.png]\n\nInput: grid = [[1,0,0],[0,0,0],[0,0,1]]\nOutput: 0\nExplanation: All paths from (0, 0) to (n - 1, n - 1) go through the thieves in cells (0, 0) and (n - 1, n - 1).\n\nExample 2:\n\n[https://assets.leetcode.com/uploads/2023/07/02/example2.png]\n\nInput: grid = [[0,0,1],[0,0,0],[0,0,0]]\nOutput: 2\nExplanation: The path depicted in the picture above has a safeness factor of 2 since:\n- The closest cell of the path to the thief at cell (0, 2) is cell (0, 0). The distance between them is | 0 - 0 | + | 0 - 2 | = 2.\nIt can be shown that there are no other paths with a higher safeness factor.\n\nExample 3:\n\n[https://assets.leetcode.com/uploads/2023/07/02/example3.png]\n\nInput: grid = [[0,0,0,1],[0,0,0,0],[0,0,0,0],[1,0,0,0]]\nOutput: 2\nExplanation: The path depicted in the picture above has a safeness factor of 2 since:\n- The closest cell of the path to the thief at cell (0, 3) is cell (1, 2). The distance between them is | 0 - 1 | + | 3 - 2 | = 2.\n- The closest cell of the path to the thief at cell (3, 0) is cell (3, 2). The distance between them is | 3 - 3 | + | 0 - 2 | = 2.\nIt can be shown that there are no other paths with a higher safeness factor.\n\n\nConstraints:\n\n * 1 <= grid.length == n <= 400\n * grid[i].length == n\n * grid[i][j] is either 0 or 1.\n * There is at least one thief in the grid.\n\"\"\"\nclass Solution:\n def maximumSafenessFactor(self, grid: List[List[int]]) -> int:\n ", "prompt_sft": "You are given a 0-indexed 2D matrix grid of size n x n, where (r, c) represents:\n\n * A cell containing a thief if grid[r][c] = 1\n * An empty cell if grid[r][c] = 0\n\nYou are initially positioned at cell (0, 0). In one move, you can move to any adjacent cell in the grid, including cells containing thieves.\n\nThe safeness factor of a path on the grid is defined as the minimum manhattan distance from any cell in the path to any thief in the grid.\n\nReturn the maximum safeness factor of all paths leading to cell (n - 1, n - 1).\n\nAn adjacent cell of cell (r, c), is one of the cells (r, c + 1), (r, c - 1), (r + 1, c) and (r - 1, c) if it exists.\n\nThe Manhattan distance between two cells (a, b) and (x, y) is equal to |a - x| + |b - y|, where |val| denotes the absolute value of val.\n\nExample 1:\n\n[https://assets.leetcode.com/uploads/2023/07/02/example1.png]\n\nInput: grid = [[1,0,0],[0,0,0],[0,0,1]]\nOutput: 0\nExplanation: All paths from (0, 0) to (n - 1, n - 1) go through the thieves in cells (0, 0) and (n - 1, n - 1).\n\nExample 2:\n\n[https://assets.leetcode.com/uploads/2023/07/02/example2.png]\n\nInput: grid = [[0,0,1],[0,0,0],[0,0,0]]\nOutput: 2\nExplanation: The path depicted in the picture above has a safeness factor of 2 since:\n- The closest cell of the path to the thief at cell (0, 2) is cell (0, 0). The distance between them is | 0 - 0 | + | 0 - 2 | = 2.\nIt can be shown that there are no other paths with a higher safeness factor.\n\nExample 3:\n\n[https://assets.leetcode.com/uploads/2023/07/02/example3.png]\n\nInput: grid = [[0,0,0,1],[0,0,0,0],[0,0,0,0],[1,0,0,0]]\nOutput: 2\nExplanation: The path depicted in the picture above has a safeness factor of 2 since:\n- The closest cell of the path to the thief at cell (0, 3) is cell (1, 2). The distance between them is | 0 - 1 | + | 3 - 2 | = 2.\n- The closest cell of the path to the thief at cell (3, 0) is cell (3, 2). The distance between them is | 3 - 3 | + | 0 - 2 | = 2.\nIt can be shown that there are no other paths with a higher safeness factor.\n\n\nConstraints:\n\n * 1 <= grid.length == n <= 400\n * grid[i].length == n\n * grid[i][j] is either 0 or 1.\n * There is at least one thief in the grid.\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def maximumSafenessFactor(self, grid: List[List[int]]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"grid\": [[1,0,0],[0,0,0],[0,0,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[0,0,1],[0,0,0],[0,0,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 2\n\ntest_input = { \"grid\": [[0,0,0,1],[0,0,0,0],[0,0,0,0],[1,0,0,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 2\n\ntest_input = { \"grid\": [[1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1],[1,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,1,1],[1,1,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,1,1],[1,1,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,1,1],[1,0,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,1,1],[1,0,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,1,1],[0,1,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,1,1],[0,1,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,1,1],[0,0,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,1,1],[0,0,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,1,0],[1,1,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,1,0],[1,1,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,1,0],[1,0,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,1,0],[1,0,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,1,0],[0,1,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,1,0],[0,1,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,1,0],[0,0,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,1,0],[0,0,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,0,1],[1,1,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,0,1],[1,1,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,0,1],[1,0,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,0,1],[1,0,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,0,1],[0,1,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,0,1],[0,1,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,0,1],[0,0,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,0,1],[0,0,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,0,0],[1,1,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,0,0],[1,1,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,0,0],[1,0,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,0,0],[1,0,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,0,0],[0,1,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,0,0],[0,1,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,0,0],[0,0,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[1,0,0],[0,0,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1],[1,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,1,1],[1,1,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,1,1],[1,1,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,1,1],[1,0,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,1,1],[1,0,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,1,1],[0,1,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,1,1],[0,1,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,1,1],[0,0,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,1,1],[0,0,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,1,0],[1,1,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,1,0],[1,1,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,1,0],[1,0,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,1,0],[1,0,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,1,0],[0,1,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,1,0],[0,1,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,1,0],[0,0,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,1,0],[0,0,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,0,1],[1,1,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,0,1],[1,1,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,0,1],[1,0,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,0,1],[1,0,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,0,1],[0,1,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,0,1],[0,1,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,0,1],[0,0,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,0,1],[0,0,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,0,0],[1,1,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,0,0],[1,1,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,0,0],[1,0,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,0,0],[1,0,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,0,0],[0,1,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,0,0],[0,1,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,0,0],[0,0,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,1],[0,0,0],[0,0,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1],[0,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,0],[1,1,1],[1,1,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,0],[1,1,1],[1,1,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,0],[1,1,1],[1,0,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,0],[1,1,1],[1,0,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,0],[1,1,1],[0,1,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,0],[1,1,1],[0,1,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,0],[1,1,1],[0,0,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,0],[1,1,1],[0,0,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,0],[1,1,0],[1,1,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,0],[1,1,0],[1,1,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,0],[1,1,0],[1,0,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,0],[1,1,0],[1,0,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,0],[1,1,0],[0,1,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,0],[1,1,0],[0,1,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,0],[1,1,0],[0,0,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,0],[1,1,0],[0,0,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,0],[1,0,1],[1,1,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,0],[1,0,1],[1,1,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,0],[1,0,1],[1,0,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,0],[1,0,1],[1,0,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,0],[1,0,1],[0,1,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,0],[1,0,1],[0,1,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,0],[1,0,1],[0,0,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,0],[1,0,1],[0,0,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,0],[1,0,0],[1,1,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,0],[1,0,0],[1,1,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,0],[1,0,0],[1,0,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,0],[1,0,0],[1,0,0]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0\n\ntest_input = { \"grid\": [[1,1,0],[1,0,0],[0,1,1]] }\nassert my_solution.maximumSafenessFactor(**test_input) == 0", "start_time": 1691289000} +{"task_id": "weekly-contest-357-maximum-elegance-of-a-k-length-subsequence", "url": "https://leetcode.com/problems/maximum-elegance-of-a-k-length-subsequence", "title": "maximum-elegance-of-a-k-length-subsequence", "meta": {"questionId": "2894", "questionFrontendId": "2813", "title": "Maximum Elegance of a K-Length Subsequence", "titleSlug": "maximum-elegance-of-a-k-length-subsequence", "isPaidOnly": false, "difficulty": "Hard", "likes": 270, "dislikes": 3, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed 2D integer array items of length n and an integer k.\n\nitems[i] = [profiti, categoryi], where profiti and categoryi denote the profit and category of the ith item respectively.\n\nLet's define the elegance of a subsequence of items as total_profit + distinct_categories2, where total_profit is the sum of all profits in the subsequence, and distinct_categories is the number of distinct categories from all the categories in the selected subsequence.\n\nYour task is to find the maximum elegance from all subsequences of size k in items.\n\nReturn an integer denoting the maximum elegance of a subsequence of items with size exactly k.\n\nNote: A subsequence of an array is a new array generated from the original array by deleting some elements (possibly none) without changing the remaining elements' relative order.\n\nExample 1:\n\nInput: items = [[3,2],[5,1],[10,1]], k = 2\nOutput: 17\nExplanation: In this example, we have to select a subsequence of size 2.\nWe can select items[0] = [3,2] and items[2] = [10,1].\nThe total profit in this subsequence is 3 + 10 = 13, and the subsequence contains 2 distinct categories [2,1].\nHence, the elegance is 13 + 22 = 17, and we can show that it is the maximum achievable elegance.\n\nExample 2:\n\nInput: items = [[3,1],[3,1],[2,2],[5,3]], k = 3\nOutput: 19\nExplanation: In this example, we have to select a subsequence of size 3.\nWe can select items[0] = [3,1], items[2] = [2,2], and items[3] = [5,3].\nThe total profit in this subsequence is 3 + 2 + 5 = 10, and the subsequence contains 3 distinct categories [1,2,3].\nHence, the elegance is 10 + 32 = 19, and we can show that it is the maximum achievable elegance.\n\nExample 3:\n\nInput: items = [[1,1],[2,1],[3,1]], k = 3\nOutput: 7\nExplanation: In this example, we have to select a subsequence of size 3.\nWe should select all the items.\nThe total profit will be 1 + 2 + 3 = 6, and the subsequence contains 1 distinct category [1].\nHence, the maximum elegance is 6 + 12 = 7.\n\nConstraints:\n\n * 1 <= items.length == n <= 105\n * items[i].length == 2\n * items[i][0] == profiti\n * items[i][1] == categoryi\n * 1 <= profiti <= 109\n * 1 <= categoryi <= n\n * 1 <= k <= n\n\"\"\"\nclass Solution:\n def findMaximumElegance(self, items: List[List[int]], k: int) -> int:\n ", "prompt_sft": "You are given a 0-indexed 2D integer array items of length n and an integer k.\n\nitems[i] = [profiti, categoryi], where profiti and categoryi denote the profit and category of the ith item respectively.\n\nLet's define the elegance of a subsequence of items as total_profit + distinct_categories2, where total_profit is the sum of all profits in the subsequence, and distinct_categories is the number of distinct categories from all the categories in the selected subsequence.\n\nYour task is to find the maximum elegance from all subsequences of size k in items.\n\nReturn an integer denoting the maximum elegance of a subsequence of items with size exactly k.\n\nNote: A subsequence of an array is a new array generated from the original array by deleting some elements (possibly none) without changing the remaining elements' relative order.\n\nExample 1:\n\nInput: items = [[3,2],[5,1],[10,1]], k = 2\nOutput: 17\nExplanation: In this example, we have to select a subsequence of size 2.\nWe can select items[0] = [3,2] and items[2] = [10,1].\nThe total profit in this subsequence is 3 + 10 = 13, and the subsequence contains 2 distinct categories [2,1].\nHence, the elegance is 13 + 22 = 17, and we can show that it is the maximum achievable elegance.\n\nExample 2:\n\nInput: items = [[3,1],[3,1],[2,2],[5,3]], k = 3\nOutput: 19\nExplanation: In this example, we have to select a subsequence of size 3.\nWe can select items[0] = [3,1], items[2] = [2,2], and items[3] = [5,3].\nThe total profit in this subsequence is 3 + 2 + 5 = 10, and the subsequence contains 3 distinct categories [1,2,3].\nHence, the elegance is 10 + 32 = 19, and we can show that it is the maximum achievable elegance.\n\nExample 3:\n\nInput: items = [[1,1],[2,1],[3,1]], k = 3\nOutput: 7\nExplanation: In this example, we have to select a subsequence of size 3.\nWe should select all the items.\nThe total profit will be 1 + 2 + 3 = 6, and the subsequence contains 1 distinct category [1].\nHence, the maximum elegance is 6 + 12 = 7.\n\nConstraints:\n\n * 1 <= items.length == n <= 105\n * items[i].length == 2\n * items[i][0] == profiti\n * items[i][1] == categoryi\n * 1 <= profiti <= 109\n * 1 <= categoryi <= n\n * 1 <= k <= n\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def findMaximumElegance(self, items: List[List[int]], k: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"items\": [[3,2],[5,1],[10,1]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 17\n\ntest_input = { \"items\": [[3,1],[3,1],[2,2],[5,3]], \"k\": 3 }\nassert my_solution.findMaximumElegance(**test_input) == 19\n\ntest_input = { \"items\": [[1,1],[2,1],[3,1]], \"k\": 3 }\nassert my_solution.findMaximumElegance(**test_input) == 7\n\ntest_input = { \"items\": [[1,1],[1,2]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 6\n\ntest_input = { \"items\": [[1,1],[4,1]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 5\n\ntest_input = { \"items\": [[1,1],[4,1]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 6\n\ntest_input = { \"items\": [[1,1],[6,1]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 7\n\ntest_input = { \"items\": [[1,1],[6,1]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 8\n\ntest_input = { \"items\": [[1,1],[8,2]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 13\n\ntest_input = { \"items\": [[1,2],[6,2]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 7\n\ntest_input = { \"items\": [[1,2],[10,1]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 11\n\ntest_input = { \"items\": [[2,1],[6,1]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 9\n\ntest_input = { \"items\": [[2,1],[7,1]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 10\n\ntest_input = { \"items\": [[2,1],[9,2]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 10\n\ntest_input = { \"items\": [[2,2],[2,2]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 3\n\ntest_input = { \"items\": [[2,2],[2,2]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 5\n\ntest_input = { \"items\": [[2,2],[3,1]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 9\n\ntest_input = { \"items\": [[2,2],[6,1]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 12\n\ntest_input = { \"items\": [[3,1],[1,2]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 8\n\ntest_input = { \"items\": [[3,1],[9,1]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 13\n\ntest_input = { \"items\": [[3,1],[9,2]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 10\n\ntest_input = { \"items\": [[3,1],[10,2]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 17\n\ntest_input = { \"items\": [[3,2],[3,1]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 4\n\ntest_input = { \"items\": [[3,2],[5,2]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 6\n\ntest_input = { \"items\": [[3,2],[10,1]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 17\n\ntest_input = { \"items\": [[3,2],[10,2]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 14\n\ntest_input = { \"items\": [[4,1],[7,2]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 15\n\ntest_input = { \"items\": [[4,1],[9,2]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 10\n\ntest_input = { \"items\": [[4,2],[2,1]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 10\n\ntest_input = { \"items\": [[4,2],[3,1]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 11\n\ntest_input = { \"items\": [[4,2],[5,2]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 6\n\ntest_input = { \"items\": [[4,2],[7,2]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 8\n\ntest_input = { \"items\": [[4,2],[8,1]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 16\n\ntest_input = { \"items\": [[4,2],[10,1]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 18\n\ntest_input = { \"items\": [[5,1],[4,2]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 6\n\ntest_input = { \"items\": [[5,1],[8,1]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 14\n\ntest_input = { \"items\": [[5,1],[8,2]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 9\n\ntest_input = { \"items\": [[5,1],[9,1]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 10\n\ntest_input = { \"items\": [[5,2],[2,1]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 6\n\ntest_input = { \"items\": [[5,2],[4,2]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 10\n\ntest_input = { \"items\": [[5,2],[5,1]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 14\n\ntest_input = { \"items\": [[6,1],[1,1]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 7\n\ntest_input = { \"items\": [[6,1],[4,1]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 7\n\ntest_input = { \"items\": [[6,1],[7,1]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 8\n\ntest_input = { \"items\": [[6,1],[7,2]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 17\n\ntest_input = { \"items\": [[6,1],[8,1]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 15\n\ntest_input = { \"items\": [[6,1],[8,2]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 18\n\ntest_input = { \"items\": [[6,1],[9,1]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 10\n\ntest_input = { \"items\": [[6,2],[2,1]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 7\n\ntest_input = { \"items\": [[6,2],[4,2]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 7\n\ntest_input = { \"items\": [[6,2],[5,1]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 7\n\ntest_input = { \"items\": [[6,2],[6,2]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 7\n\ntest_input = { \"items\": [[6,2],[6,2]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 13\n\ntest_input = { \"items\": [[6,2],[7,1]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 8\n\ntest_input = { \"items\": [[6,2],[7,1]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 17\n\ntest_input = { \"items\": [[6,2],[8,2]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 15\n\ntest_input = { \"items\": [[6,2],[10,2]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 17\n\ntest_input = { \"items\": [[7,1],[1,1]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 8\n\ntest_input = { \"items\": [[7,1],[3,2]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 8\n\ntest_input = { \"items\": [[7,1],[6,1]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 14\n\ntest_input = { \"items\": [[7,2],[5,1]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 16\n\ntest_input = { \"items\": [[7,2],[5,2]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 8\n\ntest_input = { \"items\": [[7,2],[7,2]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 15\n\ntest_input = { \"items\": [[7,2],[10,2]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 18\n\ntest_input = { \"items\": [[8,1],[2,1]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 9\n\ntest_input = { \"items\": [[8,1],[2,2]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 9\n\ntest_input = { \"items\": [[8,1],[4,2]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 9\n\ntest_input = { \"items\": [[8,1],[5,1]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 9\n\ntest_input = { \"items\": [[8,1],[6,2]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 9\n\ntest_input = { \"items\": [[8,1],[8,1]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 17\n\ntest_input = { \"items\": [[8,1],[9,1]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 10\n\ntest_input = { \"items\": [[8,1],[9,2]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 21\n\ntest_input = { \"items\": [[8,2],[1,1]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 9\n\ntest_input = { \"items\": [[8,2],[1,2]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 9\n\ntest_input = { \"items\": [[8,2],[2,1]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 9\n\ntest_input = { \"items\": [[8,2],[8,2]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 9\n\ntest_input = { \"items\": [[8,2],[9,1]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 21\n\ntest_input = { \"items\": [[8,2],[9,2]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 18\n\ntest_input = { \"items\": [[8,2],[10,1]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 22\n\ntest_input = { \"items\": [[9,1],[1,1]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 10\n\ntest_input = { \"items\": [[9,1],[3,2]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 16\n\ntest_input = { \"items\": [[9,1],[4,2]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 17\n\ntest_input = { \"items\": [[9,1],[6,2]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 10\n\ntest_input = { \"items\": [[9,1],[9,2]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 10\n\ntest_input = { \"items\": [[9,1],[10,2]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 11\n\ntest_input = { \"items\": [[9,2],[1,2]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 10\n\ntest_input = { \"items\": [[9,2],[2,1]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 15\n\ntest_input = { \"items\": [[9,2],[6,1]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 19\n\ntest_input = { \"items\": [[9,2],[6,2]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 16\n\ntest_input = { \"items\": [[9,2],[8,2]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 10\n\ntest_input = { \"items\": [[10,1],[2,2]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 11\n\ntest_input = { \"items\": [[10,1],[4,2]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 11\n\ntest_input = { \"items\": [[10,1],[5,1]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 16\n\ntest_input = { \"items\": [[10,1],[5,2]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 19\n\ntest_input = { \"items\": [[10,1],[7,1]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 11\n\ntest_input = { \"items\": [[10,2],[1,2]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 11\n\ntest_input = { \"items\": [[10,2],[4,1]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 11\n\ntest_input = { \"items\": [[10,2],[5,1]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 11\n\ntest_input = { \"items\": [[10,2],[7,1]], \"k\": 1 }\nassert my_solution.findMaximumElegance(**test_input) == 11\n\ntest_input = { \"items\": [[10,2],[8,2]], \"k\": 2 }\nassert my_solution.findMaximumElegance(**test_input) == 19", "start_time": 1691289000} +{"task_id": "biweekly-contest-110-account-balance-after-rounded-purchase", "url": "https://leetcode.com/problems/account-balance-after-rounded-purchase", "title": "account-balance-after-rounded-purchase", "meta": {"questionId": "2955", "questionFrontendId": "2806", "title": "Account Balance After Rounded Purchase", "titleSlug": "account-balance-after-rounded-purchase", "isPaidOnly": false, "difficulty": "Easy", "likes": 178, "dislikes": 37, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nInitially, you have a bank account balance of 100 dollars.\n\nYou are given an integer purchaseAmount representing the amount you will spend on a purchase in dollars.\n\nAt the store where you will make the purchase, the purchase amount is rounded to the nearest multiple of 10. In other words, you pay a non-negative amount, roundedAmount, such that roundedAmount is a multiple of 10 and abs(roundedAmount - purchaseAmount) is minimized.\n\nIf there is more than one nearest multiple of 10, the largest multiple is chosen.\n\nReturn an integer denoting your account balance after making a purchase worth purchaseAmount dollars from the store.\n\nNote: 0 is considered to be a multiple of 10 in this problem.\n\nExample 1:\n\nInput: purchaseAmount = 9\nOutput: 90\nExplanation: In this example, the nearest multiple of 10 to 9 is 10. Hence, your account balance becomes 100 - 10 = 90.\n\nExample 2:\n\nInput: purchaseAmount = 15\nOutput: 80\nExplanation: In this example, there are two nearest multiples of 10 to 15: 10 and 20. So, the larger multiple, 20, is chosen.\nHence, your account balance becomes 100 - 20 = 80.\n\n\nConstraints:\n\n * 0 <= purchaseAmount <= 100\n\"\"\"\nclass Solution:\n def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n ", "prompt_sft": "Initially, you have a bank account balance of 100 dollars.\n\nYou are given an integer purchaseAmount representing the amount you will spend on a purchase in dollars.\n\nAt the store where you will make the purchase, the purchase amount is rounded to the nearest multiple of 10. In other words, you pay a non-negative amount, roundedAmount, such that roundedAmount is a multiple of 10 and abs(roundedAmount - purchaseAmount) is minimized.\n\nIf there is more than one nearest multiple of 10, the largest multiple is chosen.\n\nReturn an integer denoting your account balance after making a purchase worth purchaseAmount dollars from the store.\n\nNote: 0 is considered to be a multiple of 10 in this problem.\n\nExample 1:\n\nInput: purchaseAmount = 9\nOutput: 90\nExplanation: In this example, the nearest multiple of 10 to 9 is 10. Hence, your account balance becomes 100 - 10 = 90.\n\nExample 2:\n\nInput: purchaseAmount = 15\nOutput: 80\nExplanation: In this example, there are two nearest multiples of 10 to 15: 10 and 20. So, the larger multiple, 20, is chosen.\nHence, your account balance becomes 100 - 20 = 80.\n\n\nConstraints:\n\n * 0 <= purchaseAmount <= 100\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"purchaseAmount\": 9 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 90\n\ntest_input = { \"purchaseAmount\": 15 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 80\n\ntest_input = { \"purchaseAmount\": 10 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 90\n\ntest_input = { \"purchaseAmount\": 11 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 90\n\ntest_input = { \"purchaseAmount\": 12 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 90\n\ntest_input = { \"purchaseAmount\": 13 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 90\n\ntest_input = { \"purchaseAmount\": 14 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 90\n\ntest_input = { \"purchaseAmount\": 16 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 80\n\ntest_input = { \"purchaseAmount\": 17 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 80\n\ntest_input = { \"purchaseAmount\": 18 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 80\n\ntest_input = { \"purchaseAmount\": 19 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 80\n\ntest_input = { \"purchaseAmount\": 1 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 100\n\ntest_input = { \"purchaseAmount\": 2 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 100\n\ntest_input = { \"purchaseAmount\": 3 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 100\n\ntest_input = { \"purchaseAmount\": 4 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 100\n\ntest_input = { \"purchaseAmount\": 5 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 90\n\ntest_input = { \"purchaseAmount\": 6 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 90\n\ntest_input = { \"purchaseAmount\": 7 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 90\n\ntest_input = { \"purchaseAmount\": 8 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 90\n\ntest_input = { \"purchaseAmount\": 20 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 80\n\ntest_input = { \"purchaseAmount\": 21 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 80\n\ntest_input = { \"purchaseAmount\": 22 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 80\n\ntest_input = { \"purchaseAmount\": 23 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 80\n\ntest_input = { \"purchaseAmount\": 24 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 80\n\ntest_input = { \"purchaseAmount\": 25 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 70\n\ntest_input = { \"purchaseAmount\": 26 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 70\n\ntest_input = { \"purchaseAmount\": 27 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 70\n\ntest_input = { \"purchaseAmount\": 28 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 70\n\ntest_input = { \"purchaseAmount\": 29 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 70\n\ntest_input = { \"purchaseAmount\": 30 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 70\n\ntest_input = { \"purchaseAmount\": 31 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 70\n\ntest_input = { \"purchaseAmount\": 32 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 70\n\ntest_input = { \"purchaseAmount\": 33 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 70\n\ntest_input = { \"purchaseAmount\": 34 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 70\n\ntest_input = { \"purchaseAmount\": 35 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 60\n\ntest_input = { \"purchaseAmount\": 36 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 60\n\ntest_input = { \"purchaseAmount\": 37 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 60\n\ntest_input = { \"purchaseAmount\": 38 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 60\n\ntest_input = { \"purchaseAmount\": 39 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 60\n\ntest_input = { \"purchaseAmount\": 40 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 60\n\ntest_input = { \"purchaseAmount\": 41 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 60\n\ntest_input = { \"purchaseAmount\": 42 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 60\n\ntest_input = { \"purchaseAmount\": 43 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 60\n\ntest_input = { \"purchaseAmount\": 44 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 60\n\ntest_input = { \"purchaseAmount\": 45 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 50\n\ntest_input = { \"purchaseAmount\": 46 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 50\n\ntest_input = { \"purchaseAmount\": 47 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 50\n\ntest_input = { \"purchaseAmount\": 48 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 50\n\ntest_input = { \"purchaseAmount\": 49 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 50\n\ntest_input = { \"purchaseAmount\": 50 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 50\n\ntest_input = { \"purchaseAmount\": 51 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 50\n\ntest_input = { \"purchaseAmount\": 52 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 50\n\ntest_input = { \"purchaseAmount\": 53 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 50\n\ntest_input = { \"purchaseAmount\": 54 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 50\n\ntest_input = { \"purchaseAmount\": 55 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 40\n\ntest_input = { \"purchaseAmount\": 56 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 40\n\ntest_input = { \"purchaseAmount\": 57 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 40\n\ntest_input = { \"purchaseAmount\": 58 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 40\n\ntest_input = { \"purchaseAmount\": 59 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 40\n\ntest_input = { \"purchaseAmount\": 60 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 40\n\ntest_input = { \"purchaseAmount\": 61 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 40\n\ntest_input = { \"purchaseAmount\": 62 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 40\n\ntest_input = { \"purchaseAmount\": 63 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 40\n\ntest_input = { \"purchaseAmount\": 64 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 40\n\ntest_input = { \"purchaseAmount\": 65 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 30\n\ntest_input = { \"purchaseAmount\": 66 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 30\n\ntest_input = { \"purchaseAmount\": 67 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 30\n\ntest_input = { \"purchaseAmount\": 68 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 30\n\ntest_input = { \"purchaseAmount\": 69 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 30\n\ntest_input = { \"purchaseAmount\": 70 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 30\n\ntest_input = { \"purchaseAmount\": 71 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 30\n\ntest_input = { \"purchaseAmount\": 72 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 30\n\ntest_input = { \"purchaseAmount\": 73 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 30\n\ntest_input = { \"purchaseAmount\": 74 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 30\n\ntest_input = { \"purchaseAmount\": 75 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 20\n\ntest_input = { \"purchaseAmount\": 76 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 20\n\ntest_input = { \"purchaseAmount\": 77 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 20\n\ntest_input = { \"purchaseAmount\": 78 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 20\n\ntest_input = { \"purchaseAmount\": 79 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 20\n\ntest_input = { \"purchaseAmount\": 80 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 20\n\ntest_input = { \"purchaseAmount\": 81 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 20\n\ntest_input = { \"purchaseAmount\": 82 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 20\n\ntest_input = { \"purchaseAmount\": 83 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 20\n\ntest_input = { \"purchaseAmount\": 84 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 20\n\ntest_input = { \"purchaseAmount\": 85 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 10\n\ntest_input = { \"purchaseAmount\": 86 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 10\n\ntest_input = { \"purchaseAmount\": 87 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 10\n\ntest_input = { \"purchaseAmount\": 88 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 10\n\ntest_input = { \"purchaseAmount\": 89 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 10\n\ntest_input = { \"purchaseAmount\": 90 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 10\n\ntest_input = { \"purchaseAmount\": 91 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 10\n\ntest_input = { \"purchaseAmount\": 92 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 10\n\ntest_input = { \"purchaseAmount\": 93 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 10\n\ntest_input = { \"purchaseAmount\": 94 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 10\n\ntest_input = { \"purchaseAmount\": 95 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 0\n\ntest_input = { \"purchaseAmount\": 96 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 0\n\ntest_input = { \"purchaseAmount\": 97 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 0\n\ntest_input = { \"purchaseAmount\": 98 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 0\n\ntest_input = { \"purchaseAmount\": 99 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 0\n\ntest_input = { \"purchaseAmount\": 100 }\nassert my_solution.accountBalanceAfterPurchase(**test_input) == 0", "start_time": 1691245800} +{"task_id": "biweekly-contest-110-insert-greatest-common-divisors-in-linked-list", "url": "https://leetcode.com/problems/insert-greatest-common-divisors-in-linked-list", "title": "insert-greatest-common-divisors-in-linked-list", "meta": {"questionId": "2903", "questionFrontendId": "2807", "title": "Insert Greatest Common Divisors in Linked List", "titleSlug": "insert-greatest-common-divisors-in-linked-list", "isPaidOnly": false, "difficulty": "Medium", "likes": 390, "dislikes": 12, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nGiven the head of a linked list head, in which each node contains an integer value.\n\nBetween every pair of adjacent nodes, insert a new node with a value equal to the greatest common divisor of them.\n\nReturn the linked list after insertion.\n\nThe greatest common divisor of two numbers is the largest positive integer that evenly divides both numbers.\n\nExample 1:\n\n[https://assets.leetcode.com/uploads/2023/07/18/ex1_copy.png]\n\nInput: head = [18,6,10,3]\nOutput: [18,6,6,2,10,1,3]\nExplanation: The 1st diagram denotes the initial linked list and the 2nd diagram denotes the linked list after inserting the new nodes (nodes in blue are the inserted nodes).\n- We insert the greatest common divisor of 18 and 6 = 6 between the 1st and the 2nd nodes.\n- We insert the greatest common divisor of 6 and 10 = 2 between the 2nd and the 3rd nodes.\n- We insert the greatest common divisor of 10 and 3 = 1 between the 3rd and the 4th nodes.\nThere are no more adjacent nodes, so we return the linked list.\n\nExample 2:\n\n[https://assets.leetcode.com/uploads/2023/07/18/ex2_copy1.png]\n\nInput: head = [7]\nOutput: [7]\nExplanation: The 1st diagram denotes the initial linked list and the 2nd diagram denotes the linked list after inserting the new nodes.\nThere are no pairs of adjacent nodes, so we return the initial linked list.\n\n\nConstraints:\n\n * The number of nodes in the list is in the range [1, 5000].\n * 1 <= Node.val <= 1000\n\"\"\"\n# Definition for singly-linked list.\nclass ListNode:\n def __init__(self, val=0, next=None):\n self.val = val\n self.next = next\nclass Solution:\n def insertGreatestCommonDivisors(self, head: Optional[ListNode]) -> Optional[ListNode]:\n ", "prompt_sft": "Given the head of a linked list head, in which each node contains an integer value.\n\nBetween every pair of adjacent nodes, insert a new node with a value equal to the greatest common divisor of them.\n\nReturn the linked list after insertion.\n\nThe greatest common divisor of two numbers is the largest positive integer that evenly divides both numbers.\n\nExample 1:\n\n[https://assets.leetcode.com/uploads/2023/07/18/ex1_copy.png]\n\nInput: head = [18,6,10,3]\nOutput: [18,6,6,2,10,1,3]\nExplanation: The 1st diagram denotes the initial linked list and the 2nd diagram denotes the linked list after inserting the new nodes (nodes in blue are the inserted nodes).\n- We insert the greatest common divisor of 18 and 6 = 6 between the 1st and the 2nd nodes.\n- We insert the greatest common divisor of 6 and 10 = 2 between the 2nd and the 3rd nodes.\n- We insert the greatest common divisor of 10 and 3 = 1 between the 3rd and the 4th nodes.\nThere are no more adjacent nodes, so we return the linked list.\n\nExample 2:\n\n[https://assets.leetcode.com/uploads/2023/07/18/ex2_copy1.png]\n\nInput: head = [7]\nOutput: [7]\nExplanation: The 1st diagram denotes the initial linked list and the 2nd diagram denotes the linked list after inserting the new nodes.\nThere are no pairs of adjacent nodes, so we return the initial linked list.\n\n\nConstraints:\n\n * The number of nodes in the list is in the range [1, 5000].\n * 1 <= Node.val <= 1000\n\n\nPlease complete the code below to solve above prblem:\n```python\n# Definition for singly-linked list.\nclass ListNode:\n def __init__(self, val=0, next=None):\n self.val = val\n self.next = next\nclass Solution:\n def insertGreatestCommonDivisors(self, head: Optional[ListNode]) -> Optional[ListNode]:\n \n```", "test": "\nmy_solution = Solution()\n\n_f1 = lambda lst: ListNode(lst[0], _f1(lst[1:])) if lst else None\n_f2 = lambda node: [node.val] + _f2(node.next) if node else []\n\n\ntest_input = { \"head\": _f1([18,6,10,3]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [18,6,6,2,10,1,3]\n\ntest_input = { \"head\": _f1([7]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [7]\n\ntest_input = { \"head\": _f1([19]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [19]\n\ntest_input = { \"head\": _f1([2]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [2]\n\ntest_input = { \"head\": _f1([13]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [13]\n\ntest_input = { \"head\": _f1([8]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [8]\n\ntest_input = { \"head\": _f1([1]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [1]\n\ntest_input = { \"head\": _f1([3]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [3]\n\ntest_input = { \"head\": _f1([20]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [20]\n\ntest_input = { \"head\": _f1([14]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [14]\n\ntest_input = { \"head\": _f1([16]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [16]\n\ntest_input = { \"head\": _f1([12]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [12]\n\ntest_input = { \"head\": _f1([9]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [9]\n\ntest_input = { \"head\": _f1([5]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [5]\n\ntest_input = { \"head\": _f1([4]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [4]\n\ntest_input = { \"head\": _f1([18]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [18]\n\ntest_input = { \"head\": _f1([11]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [11]\n\ntest_input = { \"head\": _f1([17]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [17]\n\ntest_input = { \"head\": _f1([15]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [15]\n\ntest_input = { \"head\": _f1([11,13]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [11,1,13]\n\ntest_input = { \"head\": _f1([7,13]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [7,1,13]\n\ntest_input = { \"head\": _f1([18,17]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [18,1,17]\n\ntest_input = { \"head\": _f1([15,17]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [15,1,17]\n\ntest_input = { \"head\": _f1([13,8]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [13,1,8]\n\ntest_input = { \"head\": _f1([12,16]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [12,4,16]\n\ntest_input = { \"head\": _f1([12,8]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [12,4,8]\n\ntest_input = { \"head\": _f1([18,16]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [18,2,16]\n\ntest_input = { \"head\": _f1([16,16]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [16,16,16]\n\ntest_input = { \"head\": _f1([6,12]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [6,6,12]\n\ntest_input = { \"head\": _f1([9,6]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [9,3,6]\n\ntest_input = { \"head\": _f1([2,17]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [2,1,17]\n\ntest_input = { \"head\": _f1([7,5]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [7,1,5]\n\ntest_input = { \"head\": _f1([15,6]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [15,3,6]\n\ntest_input = { \"head\": _f1([3,14]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [3,1,14]\n\ntest_input = { \"head\": _f1([6,16]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [6,2,16]\n\ntest_input = { \"head\": _f1([3,16]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [3,1,16]\n\ntest_input = { \"head\": _f1([11,9]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [11,1,9]\n\ntest_input = { \"head\": _f1([4,15]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [4,1,15]\n\ntest_input = { \"head\": _f1([16,2]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [16,2,2]\n\ntest_input = { \"head\": _f1([12,7]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [12,1,7]\n\ntest_input = { \"head\": _f1([7,9]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [7,1,9]\n\ntest_input = { \"head\": _f1([7,3]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [7,1,3]\n\ntest_input = { \"head\": _f1([8,4]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [8,4,4]\n\ntest_input = { \"head\": _f1([4,11]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [4,1,11]\n\ntest_input = { \"head\": _f1([6,15]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [6,3,15]\n\ntest_input = { \"head\": _f1([9,7]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [9,1,7]\n\ntest_input = { \"head\": _f1([19,4]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [19,1,4]\n\ntest_input = { \"head\": _f1([17,6,18]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [17,1,6,6,18]\n\ntest_input = { \"head\": _f1([10,8,3]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [10,2,8,1,3]\n\ntest_input = { \"head\": _f1([11,4,10]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [11,1,4,2,10]\n\ntest_input = { \"head\": _f1([5,3,13]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [5,1,3,1,13]\n\ntest_input = { \"head\": _f1([2,1,15]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [2,1,1,1,15]\n\ntest_input = { \"head\": _f1([17,13,9]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [17,1,13,1,9]\n\ntest_input = { \"head\": _f1([2,15,12]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [2,1,15,3,12]\n\ntest_input = { \"head\": _f1([16,12,13]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [16,4,12,1,13]\n\ntest_input = { \"head\": _f1([1,12,19]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [1,1,12,1,19]\n\ntest_input = { \"head\": _f1([4,3,3]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [4,1,3,3,3]\n\ntest_input = { \"head\": _f1([15,11,3]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [15,1,11,1,3]\n\ntest_input = { \"head\": _f1([15,18,16]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [15,3,18,2,16]\n\ntest_input = { \"head\": _f1([20,6,7]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [20,2,6,1,7]\n\ntest_input = { \"head\": _f1([9,4,7]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [9,1,4,1,7]\n\ntest_input = { \"head\": _f1([20,11,6]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [20,1,11,1,6]\n\ntest_input = { \"head\": _f1([11,8,16]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [11,1,8,8,16]\n\ntest_input = { \"head\": _f1([1,4,12]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [1,1,4,4,12]\n\ntest_input = { \"head\": _f1([18,12,19]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [18,6,12,1,19]\n\ntest_input = { \"head\": _f1([8,11,5]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [8,1,11,1,5]\n\ntest_input = { \"head\": _f1([6,10,6]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [6,2,10,2,6]\n\ntest_input = { \"head\": _f1([3,10,16]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [3,1,10,2,16]\n\ntest_input = { \"head\": _f1([15,6,15]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [15,3,6,3,15]\n\ntest_input = { \"head\": _f1([9,5,1]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [9,1,5,1,1]\n\ntest_input = { \"head\": _f1([15,15,18]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [15,15,15,3,18]\n\ntest_input = { \"head\": _f1([3,16,13]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [3,1,16,1,13]\n\ntest_input = { \"head\": _f1([9,3,6]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [9,3,3,3,6]\n\ntest_input = { \"head\": _f1([4,14,9]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [4,2,14,1,9]\n\ntest_input = { \"head\": _f1([15,2,20]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [15,1,2,2,20]\n\ntest_input = { \"head\": _f1([13,7,19]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [13,1,7,1,19]\n\ntest_input = { \"head\": _f1([19,19,12]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [19,19,19,1,12]\n\ntest_input = { \"head\": _f1([8,6,1]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [8,2,6,1,1]\n\ntest_input = { \"head\": _f1([19,10,19]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [19,1,10,1,19]\n\ntest_input = { \"head\": _f1([6,9,17]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [6,3,9,1,17]\n\ntest_input = { \"head\": _f1([3,19,8]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [3,1,19,1,8]\n\ntest_input = { \"head\": _f1([12,6,9]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [12,6,6,3,9]\n\ntest_input = { \"head\": _f1([14,16,19]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [14,2,16,1,19]\n\ntest_input = { \"head\": _f1([12,14,16,12]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [12,2,14,2,16,4,12]\n\ntest_input = { \"head\": _f1([20,13,19,12]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [20,1,13,1,19,1,12]\n\ntest_input = { \"head\": _f1([14,13,8,8]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [14,1,13,1,8,8,8]\n\ntest_input = { \"head\": _f1([13,3,3,5]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [13,1,3,3,3,1,5]\n\ntest_input = { \"head\": _f1([11,7,15,7]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [11,1,7,1,15,1,7]\n\ntest_input = { \"head\": _f1([11,7,5,1]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [11,1,7,1,5,1,1]\n\ntest_input = { \"head\": _f1([8,7,15,13]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [8,1,7,1,15,1,13]\n\ntest_input = { \"head\": _f1([1,19,3,19]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [1,1,19,1,3,1,19]\n\ntest_input = { \"head\": _f1([15,19,1,7]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [15,1,19,1,1,1,7]\n\ntest_input = { \"head\": _f1([13,20,9,1]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [13,1,20,1,9,1,1]\n\ntest_input = { \"head\": _f1([18,16,6,9]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [18,2,16,2,6,3,9]\n\ntest_input = { \"head\": _f1([16,6,13,11]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [16,2,6,1,13,1,11]\n\ntest_input = { \"head\": _f1([9,5,1,6]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [9,1,5,1,1,1,6]\n\ntest_input = { \"head\": _f1([3,15,10,12]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [3,3,15,5,10,2,12]\n\ntest_input = { \"head\": _f1([1,9,19,15]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [1,1,9,1,19,1,15]\n\ntest_input = { \"head\": _f1([14,14,19,2]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [14,14,14,1,19,1,2]\n\ntest_input = { \"head\": _f1([5,13,5,4]) }\nassert _f2(my_solution.insertGreatestCommonDivisors(**test_input)) == [5,1,13,1,5,1,4]", "start_time": 1691245800} +{"task_id": "biweekly-contest-110-minimum-seconds-to-equalize-a-circular-array", "url": "https://leetcode.com/problems/minimum-seconds-to-equalize-a-circular-array", "title": "minimum-seconds-to-equalize-a-circular-array", "meta": {"questionId": "2920", "questionFrontendId": "2808", "title": "Minimum Seconds to Equalize a Circular Array", "titleSlug": "minimum-seconds-to-equalize-a-circular-array", "isPaidOnly": false, "difficulty": "Medium", "likes": 481, "dislikes": 25, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed array nums containing n integers.\n\nAt each second, you perform the following operation on the array:\n\n * For every index i in the range [0, n - 1], replace nums[i] with either nums[i], nums[(i - 1 + n) % n], or nums[(i + 1) % n].\n\nNote that all the elements get replaced simultaneously.\n\nReturn the minimum number of seconds needed to make all elements in the array nums equal.\n\nExample 1:\n\nInput: nums = [1,2,1,2]\nOutput: 1\nExplanation: We can equalize the array in 1 second in the following way:\n- At 1st second, replace values at each index with [nums[3],nums[1],nums[3],nums[3]]. After replacement, nums = [2,2,2,2].\nIt can be proven that 1 second is the minimum amount of seconds needed for equalizing the array.\n\nExample 2:\n\nInput: nums = [2,1,3,3,2]\nOutput: 2\nExplanation: We can equalize the array in 2 seconds in the following way:\n- At 1st second, replace values at each index with [nums[0],nums[2],nums[2],nums[2],nums[3]]. After replacement, nums = [2,3,3,3,3].\n- At 2nd second, replace values at each index with [nums[1],nums[1],nums[2],nums[3],nums[4]]. After replacement, nums = [3,3,3,3,3].\nIt can be proven that 2 seconds is the minimum amount of seconds needed for equalizing the array.\n\nExample 3:\n\nInput: nums = [5,5,5,5]\nOutput: 0\nExplanation: We don't need to perform any operations as all elements in the initial array are the same.\n\n\nConstraints:\n\n * 1 <= n == nums.length <= 105\n * 1 <= nums[i] <= 109\n\"\"\"\nclass Solution:\n def minimumSeconds(self, nums: List[int]) -> int:\n ", "prompt_sft": "You are given a 0-indexed array nums containing n integers.\n\nAt each second, you perform the following operation on the array:\n\n * For every index i in the range [0, n - 1], replace nums[i] with either nums[i], nums[(i - 1 + n) % n], or nums[(i + 1) % n].\n\nNote that all the elements get replaced simultaneously.\n\nReturn the minimum number of seconds needed to make all elements in the array nums equal.\n\nExample 1:\n\nInput: nums = [1,2,1,2]\nOutput: 1\nExplanation: We can equalize the array in 1 second in the following way:\n- At 1st second, replace values at each index with [nums[3],nums[1],nums[3],nums[3]]. After replacement, nums = [2,2,2,2].\nIt can be proven that 1 second is the minimum amount of seconds needed for equalizing the array.\n\nExample 2:\n\nInput: nums = [2,1,3,3,2]\nOutput: 2\nExplanation: We can equalize the array in 2 seconds in the following way:\n- At 1st second, replace values at each index with [nums[0],nums[2],nums[2],nums[2],nums[3]]. After replacement, nums = [2,3,3,3,3].\n- At 2nd second, replace values at each index with [nums[1],nums[1],nums[2],nums[3],nums[4]]. After replacement, nums = [3,3,3,3,3].\nIt can be proven that 2 seconds is the minimum amount of seconds needed for equalizing the array.\n\nExample 3:\n\nInput: nums = [5,5,5,5]\nOutput: 0\nExplanation: We don't need to perform any operations as all elements in the initial array are the same.\n\n\nConstraints:\n\n * 1 <= n == nums.length <= 105\n * 1 <= nums[i] <= 109\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def minimumSeconds(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,2,1,2] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [2,1,3,3,2] }\nassert my_solution.minimumSeconds(**test_input) == 2\n\ntest_input = { \"nums\": [5,5,5,5] }\nassert my_solution.minimumSeconds(**test_input) == 0\n\ntest_input = { \"nums\": [4,18] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [11,7] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [14,2] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [14,9] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [20,1] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [17,15] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [11,13] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [7,13] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [18,17] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [15,17] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [13,8] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [12,16] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [12,8] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [18,16] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [16,16] }\nassert my_solution.minimumSeconds(**test_input) == 0\n\ntest_input = { \"nums\": [6,12] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [9,6] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [2,17] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [7,5] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [15,6] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [3,14] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [6,16] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [3,16] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [11,9] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [4,15] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [16,2] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [12,7] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [7,9] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [7,3] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [8,4] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [4,11] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [6,15] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [9,7] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [19,4] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [17,6] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [18,10] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [8,3] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [11,4,10] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [5,3,13] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [2,1,15] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [17,13,9] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [2,15,12] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [16,12,13] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [1,12,19] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [4,3,3] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [15,11,3] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [15,18,16] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [20,6,7] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [9,4,7] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [20,11,6] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [11,8,16] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [1,4,12] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [18,12,19] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [8,11,5] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [6,10,6] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [3,10,16] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [15,6,15] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [9,5,1] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [15,15,18] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [3,16,13] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [9,3,6] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [4,14,9] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [15,2,20] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [13,7,19] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [19,19,12] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [8,6,1] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [19,10,19] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [6,9,17] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [3,19,8,12] }\nassert my_solution.minimumSeconds(**test_input) == 2\n\ntest_input = { \"nums\": [6,9,14,16] }\nassert my_solution.minimumSeconds(**test_input) == 2\n\ntest_input = { \"nums\": [19,12,14,16] }\nassert my_solution.minimumSeconds(**test_input) == 2\n\ntest_input = { \"nums\": [12,20,13,19] }\nassert my_solution.minimumSeconds(**test_input) == 2\n\ntest_input = { \"nums\": [12,14,13,8] }\nassert my_solution.minimumSeconds(**test_input) == 2\n\ntest_input = { \"nums\": [8,13,3,3] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [5,11,7,15] }\nassert my_solution.minimumSeconds(**test_input) == 2\n\ntest_input = { \"nums\": [7,11,7,5] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [1,8,7,15] }\nassert my_solution.minimumSeconds(**test_input) == 2\n\ntest_input = { \"nums\": [13,1,19,3] }\nassert my_solution.minimumSeconds(**test_input) == 2\n\ntest_input = { \"nums\": [19,15,19,1] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [7,13,20,9] }\nassert my_solution.minimumSeconds(**test_input) == 2\n\ntest_input = { \"nums\": [1,18,16,6] }\nassert my_solution.minimumSeconds(**test_input) == 2\n\ntest_input = { \"nums\": [9,16,6,13] }\nassert my_solution.minimumSeconds(**test_input) == 2\n\ntest_input = { \"nums\": [11,9,5,1] }\nassert my_solution.minimumSeconds(**test_input) == 2\n\ntest_input = { \"nums\": [6,3,15,10] }\nassert my_solution.minimumSeconds(**test_input) == 2\n\ntest_input = { \"nums\": [12,1,9,19] }\nassert my_solution.minimumSeconds(**test_input) == 2\n\ntest_input = { \"nums\": [15,14,14,19] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [2,5,13,5] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [4,8,8,13] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [3,9,10,13] }\nassert my_solution.minimumSeconds(**test_input) == 2\n\ntest_input = { \"nums\": [7,17,11,8] }\nassert my_solution.minimumSeconds(**test_input) == 2\n\ntest_input = { \"nums\": [4,5,15,11] }\nassert my_solution.minimumSeconds(**test_input) == 2\n\ntest_input = { \"nums\": [11,15,19,12] }\nassert my_solution.minimumSeconds(**test_input) == 2\n\ntest_input = { \"nums\": [8,20,5,10] }\nassert my_solution.minimumSeconds(**test_input) == 2\n\ntest_input = { \"nums\": [5,3,5,17] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [14,19,8,8] }\nassert my_solution.minimumSeconds(**test_input) == 1\n\ntest_input = { \"nums\": [16,20,4,13] }\nassert my_solution.minimumSeconds(**test_input) == 2\n\ntest_input = { \"nums\": [17,16,2,16] }\nassert my_solution.minimumSeconds(**test_input) == 1", "start_time": 1691245800} +{"task_id": "biweekly-contest-110-minimum-time-to-make-array-sum-at-most-x", "url": "https://leetcode.com/problems/minimum-time-to-make-array-sum-at-most-x", "title": "minimum-time-to-make-array-sum-at-most-x", "meta": {"questionId": "2952", "questionFrontendId": "2809", "title": "Minimum Time to Make Array Sum At Most x", "titleSlug": "minimum-time-to-make-array-sum-at-most-x", "isPaidOnly": false, "difficulty": "Hard", "likes": 207, "dislikes": 10, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given two 0-indexed integer arrays nums1 and nums2 of equal length. Every second, for all indices 0 <= i < nums1.length, value of nums1[i] is incremented by nums2[i]. After this is done, you can do the following operation:\n\n * Choose an index 0 <= i < nums1.length and make nums1[i] = 0.\n\nYou are also given an integer x.\n\nReturn the minimum time in which you can make the sum of all elements of nums1 to be less than or equal to x, or -1 if this is not possible.\n\nExample 1:\n\nInput: nums1 = [1,2,3], nums2 = [1,2,3], x = 4\nOutput: 3\nExplanation:\nFor the 1st second, we apply the operation on i = 0. Therefore nums1 = [0,2+2,3+3] = [0,4,6].\nFor the 2nd second, we apply the operation on i = 1. Therefore nums1 = [0+1,0,6+3] = [1,0,9].\nFor the 3rd second, we apply the operation on i = 2. Therefore nums1 = [1+1,0+2,0] = [2,2,0].\nNow sum of nums1 = 4. It can be shown that these operations are optimal, so we return 3.\n\nExample 2:\n\nInput: nums1 = [1,2,3], nums2 = [3,3,3], x = 4\nOutput: -1\nExplanation: It can be shown that the sum of nums1 will always be greater than x, no matter which operations are performed.\n\n\nConstraints:\n\n * 1 <= nums1.length <= 103\n * 1 <= nums1[i] <= 103\n * 0 <= nums2[i] <= 103\n * nums1.length == nums2.length\n * 0 <= x <= 106\n\"\"\"\nclass Solution:\n def minimumTime(self, nums1: List[int], nums2: List[int], x: int) -> int:\n ", "prompt_sft": "You are given two 0-indexed integer arrays nums1 and nums2 of equal length. Every second, for all indices 0 <= i < nums1.length, value of nums1[i] is incremented by nums2[i]. After this is done, you can do the following operation:\n\n * Choose an index 0 <= i < nums1.length and make nums1[i] = 0.\n\nYou are also given an integer x.\n\nReturn the minimum time in which you can make the sum of all elements of nums1 to be less than or equal to x, or -1 if this is not possible.\n\nExample 1:\n\nInput: nums1 = [1,2,3], nums2 = [1,2,3], x = 4\nOutput: 3\nExplanation:\nFor the 1st second, we apply the operation on i = 0. Therefore nums1 = [0,2+2,3+3] = [0,4,6].\nFor the 2nd second, we apply the operation on i = 1. Therefore nums1 = [0+1,0,6+3] = [1,0,9].\nFor the 3rd second, we apply the operation on i = 2. Therefore nums1 = [1+1,0+2,0] = [2,2,0].\nNow sum of nums1 = 4. It can be shown that these operations are optimal, so we return 3.\n\nExample 2:\n\nInput: nums1 = [1,2,3], nums2 = [3,3,3], x = 4\nOutput: -1\nExplanation: It can be shown that the sum of nums1 will always be greater than x, no matter which operations are performed.\n\n\nConstraints:\n\n * 1 <= nums1.length <= 103\n * 1 <= nums1[i] <= 103\n * 0 <= nums2[i] <= 103\n * nums1.length == nums2.length\n * 0 <= x <= 106\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def minimumTime(self, nums1: List[int], nums2: List[int], x: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums1\": [1,2,3], \"nums2\": [1,2,3], \"x\": 4 }\nassert my_solution.minimumTime(**test_input) == 3\n\ntest_input = { \"nums1\": [1,2,3], \"nums2\": [3,3,3], \"x\": 4 }\nassert my_solution.minimumTime(**test_input) == -1\n\ntest_input = { \"nums1\": [4,4,9,10], \"nums2\": [4,4,1,3], \"x\": 16 }\nassert my_solution.minimumTime(**test_input) == 4\n\ntest_input = { \"nums1\": [5,3], \"nums2\": [3,2], \"x\": 4 }\nassert my_solution.minimumTime(**test_input) == 2\n\ntest_input = { \"nums1\": [4,5,3,2,3,9,5,7,10,4], \"nums2\": [4,4,0,4,1,2,4,0,4,0], \"x\": 47 }\nassert my_solution.minimumTime(**test_input) == -1\n\ntest_input = { \"nums1\": [7,9,8,5,8,3], \"nums2\": [0,1,4,2,3,1], \"x\": 37 }\nassert my_solution.minimumTime(**test_input) == 2\n\ntest_input = { \"nums1\": [8,2,3], \"nums2\": [1,4,2], \"x\": 13 }\nassert my_solution.minimumTime(**test_input) == 0\n\ntest_input = { \"nums1\": [4,7,2,3,4,3,10,8], \"nums2\": [3,4,0,1,1,0,2,2], \"x\": 36 }\nassert my_solution.minimumTime(**test_input) == 4\n\ntest_input = { \"nums1\": [2,10,10,4,6,3], \"nums2\": [1,0,0,1,3,1], \"x\": 35 }\nassert my_solution.minimumTime(**test_input) == 0\n\ntest_input = { \"nums1\": [9,5,3], \"nums2\": [4,1,3], \"x\": 17 }\nassert my_solution.minimumTime(**test_input) == 0\n\ntest_input = { \"nums1\": [1,7,9,4,8,8,1], \"nums2\": [2,2,3,2,0,1,0], \"x\": 20 }\nassert my_solution.minimumTime(**test_input) == 6\n\ntest_input = { \"nums1\": [9,2,8,3,1,9,7,6], \"nums2\": [0,3,4,1,3,4,2,1], \"x\": 40 }\nassert my_solution.minimumTime(**test_input) == 8\n\ntest_input = { \"nums1\": [10], \"nums2\": [3], \"x\": 10 }\nassert my_solution.minimumTime(**test_input) == 0\n\ntest_input = { \"nums1\": [7,6,8,2,8,9,3,3], \"nums2\": [2,2,4,0,0,2,2,3], \"x\": 45 }\nassert my_solution.minimumTime(**test_input) == 5\n\ntest_input = { \"nums1\": [4,9,5,2,3], \"nums2\": [4,2,0,4,0], \"x\": 18 }\nassert my_solution.minimumTime(**test_input) == 3\n\ntest_input = { \"nums1\": [2,10,2,7,8,9,7,6,6], \"nums2\": [4,2,1,4,3,2,4,4,4], \"x\": 55 }\nassert my_solution.minimumTime(**test_input) == -1\n\ntest_input = { \"nums1\": [6,8,10,7,10,9], \"nums2\": [4,2,0,4,4,2], \"x\": 38 }\nassert my_solution.minimumTime(**test_input) == 5\n\ntest_input = { \"nums1\": [9,2,8,5,8,3,5,2,2], \"nums2\": [4,3,4,2,0,1,4,4,2], \"x\": 41 }\nassert my_solution.minimumTime(**test_input) == -1\n\ntest_input = { \"nums1\": [5,3,2,3,10,4,7,9,1,10], \"nums2\": [2,0,2,0,3,3,4,4,0,1], \"x\": 30 }\nassert my_solution.minimumTime(**test_input) == -1\n\ntest_input = { \"nums1\": [2,3,5], \"nums2\": [0,0,1], \"x\": 8 }\nassert my_solution.minimumTime(**test_input) == 1\n\ntest_input = { \"nums1\": [7,9,7,9], \"nums2\": [4,2,0,4], \"x\": 32 }\nassert my_solution.minimumTime(**test_input) == 0\n\ntest_input = { \"nums1\": [8,5,6,4,7,6,3,9,4], \"nums2\": [0,4,2,4,3,3,1,4,4], \"x\": 38 }\nassert my_solution.minimumTime(**test_input) == -1\n\ntest_input = { \"nums1\": [3,1,1,1], \"nums2\": [0,0,3,0], \"x\": 3 }\nassert my_solution.minimumTime(**test_input) == 2\n\ntest_input = { \"nums1\": [6,6,8,7,1,7], \"nums2\": [2,2,1,1,2,3], \"x\": 27 }\nassert my_solution.minimumTime(**test_input) == 5\n\ntest_input = { \"nums1\": [10,5], \"nums2\": [1,3], \"x\": 14 }\nassert my_solution.minimumTime(**test_input) == 1\n\ntest_input = { \"nums1\": [10,7,1,2,6], \"nums2\": [4,3,2,2,4], \"x\": 17 }\nassert my_solution.minimumTime(**test_input) == -1\n\ntest_input = { \"nums1\": [9,5,6,1,9,4,5,7], \"nums2\": [0,4,0,2,2,3,2,4], \"x\": 24 }\nassert my_solution.minimumTime(**test_input) == -1\n\ntest_input = { \"nums1\": [4,1,2,4,10,7,8], \"nums2\": [0,2,0,4,0,2,1], \"x\": 18 }\nassert my_solution.minimumTime(**test_input) == 5\n\ntest_input = { \"nums1\": [4], \"nums2\": [0], \"x\": 4 }\nassert my_solution.minimumTime(**test_input) == 0\n\ntest_input = { \"nums1\": [4,7,1,7,5,10], \"nums2\": [0,4,3,2,3,1], \"x\": 29 }\nassert my_solution.minimumTime(**test_input) == 4\n\ntest_input = { \"nums1\": [9,8,9,7,4,6,8,6,4], \"nums2\": [4,3,3,3,1,2,2,1,0], \"x\": 42 }\nassert my_solution.minimumTime(**test_input) == -1\n\ntest_input = { \"nums1\": [8,3,2], \"nums2\": [3,1,3], \"x\": 7 }\nassert my_solution.minimumTime(**test_input) == 3\n\ntest_input = { \"nums1\": [6,5,2,8,8,1,6,4], \"nums2\": [1,2,1,0,1,0,3,1], \"x\": 23 }\nassert my_solution.minimumTime(**test_input) == 6\n\ntest_input = { \"nums1\": [3,8,5,4,10,2], \"nums2\": [4,1,4,2,1,0], \"x\": 26 }\nassert my_solution.minimumTime(**test_input) == 4\n\ntest_input = { \"nums1\": [5,3], \"nums2\": [0,3], \"x\": 4 }\nassert my_solution.minimumTime(**test_input) == 2\n\ntest_input = { \"nums1\": [8], \"nums2\": [4], \"x\": 7 }\nassert my_solution.minimumTime(**test_input) == 1\n\ntest_input = { \"nums1\": [1,8,6,8,6], \"nums2\": [3,0,2,4,0], \"x\": 16 }\nassert my_solution.minimumTime(**test_input) == 4\n\ntest_input = { \"nums1\": [8,6], \"nums2\": [0,3], \"x\": 14 }\nassert my_solution.minimumTime(**test_input) == 0\n\ntest_input = { \"nums1\": [3,4,5,2,4,10,6,3,6,4], \"nums2\": [3,0,0,2,4,2,4,1,2,1], \"x\": 28 }\nassert my_solution.minimumTime(**test_input) == -1\n\ntest_input = { \"nums1\": [3,2,5,8,8], \"nums2\": [1,3,2,1,0], \"x\": 20 }\nassert my_solution.minimumTime(**test_input) == 3\n\ntest_input = { \"nums1\": [9,2,8,7,5,2,3,2], \"nums2\": [3,2,3,0,4,3,1,4], \"x\": 37 }\nassert my_solution.minimumTime(**test_input) == -1\n\ntest_input = { \"nums1\": [6,4,3,1,10,5,10,3,5,9], \"nums2\": [0,4,1,2,1,2,3,3,4,2], \"x\": 41 }\nassert my_solution.minimumTime(**test_input) == -1\n\ntest_input = { \"nums1\": [6,10,7,10,6,7,7,4], \"nums2\": [1,3,0,0,1,2,1,3], \"x\": 55 }\nassert my_solution.minimumTime(**test_input) == 1\n\ntest_input = { \"nums1\": [6,4,3,1], \"nums2\": [1,1,3,3], \"x\": 7 }\nassert my_solution.minimumTime(**test_input) == -1\n\ntest_input = { \"nums1\": [2,10,8,10,1,4,7,10,5,1], \"nums2\": [4,3,1,2,3,1,3,2,2,1], \"x\": 29 }\nassert my_solution.minimumTime(**test_input) == -1\n\ntest_input = { \"nums1\": [2,8,5], \"nums2\": [2,0,2], \"x\": 14 }\nassert my_solution.minimumTime(**test_input) == 1\n\ntest_input = { \"nums1\": [7,10,1,3,7,3,2], \"nums2\": [1,1,3,0,2,2,3], \"x\": 22 }\nassert my_solution.minimumTime(**test_input) == 7\n\ntest_input = { \"nums1\": [6,4,2,3,8,6,6,8,10], \"nums2\": [2,1,4,1,2,1,0,1,4], \"x\": 39 }\nassert my_solution.minimumTime(**test_input) == 9\n\ntest_input = { \"nums1\": [4,4,8,10,2,7,9,8,1,8], \"nums2\": [1,0,4,0,3,3,1,2,2,1], \"x\": 44 }\nassert my_solution.minimumTime(**test_input) == 10\n\ntest_input = { \"nums1\": [2,4,1,8,3,9], \"nums2\": [0,2,0,0,0,4], \"x\": 21 }\nassert my_solution.minimumTime(**test_input) == 1\n\ntest_input = { \"nums1\": [6,10], \"nums2\": [2,1], \"x\": 8 }\nassert my_solution.minimumTime(**test_input) == 1\n\ntest_input = { \"nums1\": [8,6], \"nums2\": [3,0], \"x\": 10 }\nassert my_solution.minimumTime(**test_input) == 1\n\ntest_input = { \"nums1\": [5,5,5,10], \"nums2\": [0,1,0,3], \"x\": 21 }\nassert my_solution.minimumTime(**test_input) == 1\n\ntest_input = { \"nums1\": [7,1,1,2,9,3,3,2,2], \"nums2\": [0,1,4,3,4,1,2,1,2], \"x\": 15 }\nassert my_solution.minimumTime(**test_input) == -1\n\ntest_input = { \"nums1\": [10,4,1,10,7,5,6,3,2,10], \"nums2\": [4,0,4,0,3,4,3,0,0,3], \"x\": 50 }\nassert my_solution.minimumTime(**test_input) == 9\n\ntest_input = { \"nums1\": [9,4,6,2], \"nums2\": [3,4,0,4], \"x\": 15 }\nassert my_solution.minimumTime(**test_input) == 4\n\ntest_input = { \"nums1\": [7,3,9,2,9,10,7,10,10,4], \"nums2\": [1,4,2,1,4,1,1,0,3,4], \"x\": 69 }\nassert my_solution.minimumTime(**test_input) == 8\n\ntest_input = { \"nums1\": [4,5,6], \"nums2\": [4,4,0], \"x\": 13 }\nassert my_solution.minimumTime(**test_input) == 2\n\ntest_input = { \"nums1\": [2,3,3,4,4], \"nums2\": [2,2,1,1,1], \"x\": 12 }\nassert my_solution.minimumTime(**test_input) == 5\n\ntest_input = { \"nums1\": [4,5,5,3,7], \"nums2\": [3,3,2,0,4], \"x\": 21 }\nassert my_solution.minimumTime(**test_input) == 4\n\ntest_input = { \"nums1\": [1,3,3,4], \"nums2\": [1,3,2,3], \"x\": 6 }\nassert my_solution.minimumTime(**test_input) == -1\n\ntest_input = { \"nums1\": [9,1,8,9,7,2], \"nums2\": [3,3,0,2,3,4], \"x\": 26 }\nassert my_solution.minimumTime(**test_input) == 6\n\ntest_input = { \"nums1\": [5,5,6,8,6,1,5,7,8], \"nums2\": [2,1,0,3,2,2,2,2,4], \"x\": 33 }\nassert my_solution.minimumTime(**test_input) == -1\n\ntest_input = { \"nums1\": [2,9,5,5,6,7,7,9], \"nums2\": [1,3,0,3,3,3,4,2], \"x\": 47 }\nassert my_solution.minimumTime(**test_input) == 8\n\ntest_input = { \"nums1\": [3], \"nums2\": [0], \"x\": 2 }\nassert my_solution.minimumTime(**test_input) == 1\n\ntest_input = { \"nums1\": [3,6,4,8,7,9,3,3,9], \"nums2\": [4,3,2,0,0,3,3,1,4], \"x\": 34 }\nassert my_solution.minimumTime(**test_input) == -1\n\ntest_input = { \"nums1\": [8], \"nums2\": [1], \"x\": 6 }\nassert my_solution.minimumTime(**test_input) == 1\n\ntest_input = { \"nums1\": [1,7,6,2,9], \"nums2\": [4,2,3,3,0], \"x\": 23 }\nassert my_solution.minimumTime(**test_input) == 4\n\ntest_input = { \"nums1\": [9,10,10,5,2,4], \"nums2\": [2,4,0,3,3,4], \"x\": 40 }\nassert my_solution.minimumTime(**test_input) == 0\n\ntest_input = { \"nums1\": [9,10,9,4,8,9,10,7,5], \"nums2\": [2,0,3,0,2,4,3,2,4], \"x\": 69 }\nassert my_solution.minimumTime(**test_input) == 7\n\ntest_input = { \"nums1\": [1,7,2,7], \"nums2\": [1,0,2,3], \"x\": 10 }\nassert my_solution.minimumTime(**test_input) == 2\n\ntest_input = { \"nums1\": [10,4], \"nums2\": [2,4], \"x\": 10 }\nassert my_solution.minimumTime(**test_input) == 1\n\ntest_input = { \"nums1\": [2,10,3,6,2,10,4], \"nums2\": [4,1,4,4,4,0,0], \"x\": 30 }\nassert my_solution.minimumTime(**test_input) == 7\n\ntest_input = { \"nums1\": [5,9,6], \"nums2\": [1,3,2], \"x\": 20 }\nassert my_solution.minimumTime(**test_input) == 0\n\ntest_input = { \"nums1\": [4,5,2,4,2,7], \"nums2\": [0,0,0,0,3,0], \"x\": 23 }\nassert my_solution.minimumTime(**test_input) == 1\n\ntest_input = { \"nums1\": [8], \"nums2\": [0], \"x\": 7 }\nassert my_solution.minimumTime(**test_input) == 1\n\ntest_input = { \"nums1\": [3], \"nums2\": [3], \"x\": 3 }\nassert my_solution.minimumTime(**test_input) == 0\n\ntest_input = { \"nums1\": [6,1,10,10], \"nums2\": [3,2,4,0], \"x\": 13 }\nassert my_solution.minimumTime(**test_input) == 3\n\ntest_input = { \"nums1\": [8,9,2,10,10,1,5], \"nums2\": [4,3,3,0,2,1,2], \"x\": 38 }\nassert my_solution.minimumTime(**test_input) == 5\n\ntest_input = { \"nums1\": [10,2], \"nums2\": [3,4], \"x\": 10 }\nassert my_solution.minimumTime(**test_input) == 1\n\ntest_input = { \"nums1\": [8,9,2], \"nums2\": [2,4,1], \"x\": 16 }\nassert my_solution.minimumTime(**test_input) == 1\n\ntest_input = { \"nums1\": [4,2,3], \"nums2\": [4,2,2], \"x\": 4 }\nassert my_solution.minimumTime(**test_input) == -1\n\ntest_input = { \"nums1\": [9,8,7,6,5,1,4], \"nums2\": [2,4,1,2,3,3,0], \"x\": 28 }\nassert my_solution.minimumTime(**test_input) == 7\n\ntest_input = { \"nums1\": [3,4,10,1,2,4,10,3,7,2], \"nums2\": [4,0,0,1,1,4,4,4,2,1], \"x\": 44 }\nassert my_solution.minimumTime(**test_input) == -1\n\ntest_input = { \"nums1\": [3,5,5,1,6,4,3], \"nums2\": [1,3,4,3,3,1,4], \"x\": 23 }\nassert my_solution.minimumTime(**test_input) == -1\n\ntest_input = { \"nums1\": [3,8,10,2,5,10], \"nums2\": [4,0,3,2,4,3], \"x\": 37 }\nassert my_solution.minimumTime(**test_input) == 4\n\ntest_input = { \"nums1\": [8,8,10,8,9,6,1,8], \"nums2\": [2,0,0,1,2,1,0,4], \"x\": 38 }\nassert my_solution.minimumTime(**test_input) == 4\n\ntest_input = { \"nums1\": [10,7,3,10,7,6,6,10], \"nums2\": [1,2,4,0,3,4,0,3], \"x\": 41 }\nassert my_solution.minimumTime(**test_input) == 7\n\ntest_input = { \"nums1\": [6,7,4,1,9,6], \"nums2\": [3,3,3,0,0,1], \"x\": 32 }\nassert my_solution.minimumTime(**test_input) == 2\n\ntest_input = { \"nums1\": [2], \"nums2\": [2], \"x\": 1 }\nassert my_solution.minimumTime(**test_input) == 1\n\ntest_input = { \"nums1\": [8,9,4,5,6,7], \"nums2\": [0,3,4,3,3,1], \"x\": 27 }\nassert my_solution.minimumTime(**test_input) == 6\n\ntest_input = { \"nums1\": [7], \"nums2\": [1], \"x\": 3 }\nassert my_solution.minimumTime(**test_input) == 1\n\ntest_input = { \"nums1\": [9], \"nums2\": [0], \"x\": 5 }\nassert my_solution.minimumTime(**test_input) == 1\n\ntest_input = { \"nums1\": [7,2,2,2,7,4,2,10,8], \"nums2\": [4,3,2,4,4,0,1,1,2], \"x\": 31 }\nassert my_solution.minimumTime(**test_input) == -1\n\ntest_input = { \"nums1\": [7,2,6,4,9,9,1,9,6,7], \"nums2\": [0,1,3,2,3,3,4,2,2,1], \"x\": 58 }\nassert my_solution.minimumTime(**test_input) == -1\n\ntest_input = { \"nums1\": [6,8,2,3,9,8,10,9,9], \"nums2\": [1,4,2,3,2,0,1,1,3], \"x\": 40 }\nassert my_solution.minimumTime(**test_input) == -1\n\ntest_input = { \"nums1\": [1,1,5], \"nums2\": [4,4,2], \"x\": 3 }\nassert my_solution.minimumTime(**test_input) == -1\n\ntest_input = { \"nums1\": [7,5,8,3,10,2,4,8,7], \"nums2\": [4,4,2,4,2,3,1,1,1], \"x\": 49 }\nassert my_solution.minimumTime(**test_input) == -1\n\ntest_input = { \"nums1\": [4,7,2,6,9,2], \"nums2\": [1,2,1,4,1,3], \"x\": 28 }\nassert my_solution.minimumTime(**test_input) == 3\n\ntest_input = { \"nums1\": [3,6,3,9,5], \"nums2\": [0,4,0,3,1], \"x\": 23 }\nassert my_solution.minimumTime(**test_input) == 1", "start_time": 1691245800} +{"task_id": "weekly-contest-356-number-of-employees-who-met-the-target", "url": "https://leetcode.com/problems/number-of-employees-who-met-the-target", "title": "number-of-employees-who-met-the-target", "meta": {"questionId": "2876", "questionFrontendId": "2798", "title": "Number of Employees Who Met the Target", "titleSlug": "number-of-employees-who-met-the-target", "isPaidOnly": false, "difficulty": "Easy", "likes": 362, "dislikes": 46, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nThere are n employees in a company, numbered from 0 to n - 1. Each employee i has worked for hours[i] hours in the company.\n\nThe company requires each employee to work for at least target hours.\n\nYou are given a 0-indexed array of non-negative integers hours of length n and a non-negative integer target.\n\nReturn the integer denoting the number of employees who worked at least target hours.\n\nExample 1:\n\nInput: hours = [0,1,2,3,4], target = 2\nOutput: 3\nExplanation: The company wants each employee to work for at least 2 hours.\n- Employee 0 worked for 0 hours and didn't meet the target.\n- Employee 1 worked for 1 hours and didn't meet the target.\n- Employee 2 worked for 2 hours and met the target.\n- Employee 3 worked for 3 hours and met the target.\n- Employee 4 worked for 4 hours and met the target.\nThere are 3 employees who met the target.\n\nExample 2:\n\nInput: hours = [5,1,4,2,2], target = 6\nOutput: 0\nExplanation: The company wants each employee to work for at least 6 hours.\nThere are 0 employees who met the target.\n\n\nConstraints:\n\n * 1 <= n == hours.length <= 50\n * 0 <= hours[i], target <= 105\n\"\"\"\nclass Solution:\n def numberOfEmployeesWhoMetTarget(self, hours: List[int], target: int) -> int:\n ", "prompt_sft": "There are n employees in a company, numbered from 0 to n - 1. Each employee i has worked for hours[i] hours in the company.\n\nThe company requires each employee to work for at least target hours.\n\nYou are given a 0-indexed array of non-negative integers hours of length n and a non-negative integer target.\n\nReturn the integer denoting the number of employees who worked at least target hours.\n\nExample 1:\n\nInput: hours = [0,1,2,3,4], target = 2\nOutput: 3\nExplanation: The company wants each employee to work for at least 2 hours.\n- Employee 0 worked for 0 hours and didn't meet the target.\n- Employee 1 worked for 1 hours and didn't meet the target.\n- Employee 2 worked for 2 hours and met the target.\n- Employee 3 worked for 3 hours and met the target.\n- Employee 4 worked for 4 hours and met the target.\nThere are 3 employees who met the target.\n\nExample 2:\n\nInput: hours = [5,1,4,2,2], target = 6\nOutput: 0\nExplanation: The company wants each employee to work for at least 6 hours.\nThere are 0 employees who met the target.\n\n\nConstraints:\n\n * 1 <= n == hours.length <= 50\n * 0 <= hours[i], target <= 105\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def numberOfEmployeesWhoMetTarget(self, hours: List[int], target: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"hours\": [0,1,2,3,4], \"target\": 2 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 3\n\ntest_input = { \"hours\": [5,1,4,2,2], \"target\": 6 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [98], \"target\": 5 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [19], \"target\": 13 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [70], \"target\": 13 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [26], \"target\": 14 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [2], \"target\": 16 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [77], \"target\": 19 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [6], \"target\": 21 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [27], \"target\": 21 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [36], \"target\": 22 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [42], \"target\": 25 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [70], \"target\": 27 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [2], \"target\": 28 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [14], \"target\": 31 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [45], \"target\": 34 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [44], \"target\": 35 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [11], \"target\": 39 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [71], \"target\": 39 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [91], \"target\": 45 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [81], \"target\": 51 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [15], \"target\": 52 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [90], \"target\": 59 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [40], \"target\": 64 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [12], \"target\": 69 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [83], \"target\": 70 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [38], \"target\": 74 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [18], \"target\": 78 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [60], \"target\": 83 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [50], \"target\": 87 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [75], \"target\": 92 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [91], \"target\": 96 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [11], \"target\": 97 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [48,28], \"target\": 2 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 2\n\ntest_input = { \"hours\": [38,46], \"target\": 3 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 2\n\ntest_input = { \"hours\": [30,79], \"target\": 6 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 2\n\ntest_input = { \"hours\": [45,78], \"target\": 6 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 2\n\ntest_input = { \"hours\": [20,69], \"target\": 10 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 2\n\ntest_input = { \"hours\": [82,67], \"target\": 11 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 2\n\ntest_input = { \"hours\": [29,75], \"target\": 12 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 2\n\ntest_input = { \"hours\": [97,37], \"target\": 17 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 2\n\ntest_input = { \"hours\": [42,100], \"target\": 20 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 2\n\ntest_input = { \"hours\": [11,58], \"target\": 21 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [12,46], \"target\": 21 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [70,84], \"target\": 37 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 2\n\ntest_input = { \"hours\": [7,100], \"target\": 38 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [47,94], \"target\": 40 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 2\n\ntest_input = { \"hours\": [18,34], \"target\": 50 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [47,79], \"target\": 55 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [74,99], \"target\": 56 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 2\n\ntest_input = { \"hours\": [53,81], \"target\": 67 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [36,61], \"target\": 68 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [48,98], \"target\": 71 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [71,94], \"target\": 72 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [60,99], \"target\": 73 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [12,12], \"target\": 74 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [100,87], \"target\": 75 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 2\n\ntest_input = { \"hours\": [12,56], \"target\": 77 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [15,36], \"target\": 86 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [53,45], \"target\": 86 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [4,77], \"target\": 89 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [23,29], \"target\": 93 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [76,62,96], \"target\": 5 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 3\n\ntest_input = { \"hours\": [82,67,33], \"target\": 5 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 3\n\ntest_input = { \"hours\": [28,96,39], \"target\": 10 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 3\n\ntest_input = { \"hours\": [42,93,58], \"target\": 13 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 3\n\ntest_input = { \"hours\": [53,22,48], \"target\": 13 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 3\n\ntest_input = { \"hours\": [68,81,61], \"target\": 13 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 3\n\ntest_input = { \"hours\": [68,32,33], \"target\": 22 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 3\n\ntest_input = { \"hours\": [59,65,70], \"target\": 26 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 3\n\ntest_input = { \"hours\": [15,43,21], \"target\": 29 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [40,80,75], \"target\": 33 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 3\n\ntest_input = { \"hours\": [64,11,73], \"target\": 34 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 2\n\ntest_input = { \"hours\": [1,74,34], \"target\": 44 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [96,79,91], \"target\": 44 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 3\n\ntest_input = { \"hours\": [59,9,9], \"target\": 48 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [79,48,62], \"target\": 53 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 2\n\ntest_input = { \"hours\": [58,83,2], \"target\": 54 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 2\n\ntest_input = { \"hours\": [51,40,12], \"target\": 57 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [54,2,80], \"target\": 60 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [92,45,91], \"target\": 65 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 2\n\ntest_input = { \"hours\": [93,23,46], \"target\": 67 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [17,60,1], \"target\": 70 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [9,63,77], \"target\": 73 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [44,86,37], \"target\": 73 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [75,37,68], \"target\": 73 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [33,26,77], \"target\": 78 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [11,88,27], \"target\": 79 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [12,48,44], \"target\": 80 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [19,88,13], \"target\": 82 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [61,56,67], \"target\": 82 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [46,24,38], \"target\": 84 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [93,51,83], \"target\": 85 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 1\n\ntest_input = { \"hours\": [58,14,83], \"target\": 87 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [52,33,56], \"target\": 89 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [34,73,46], \"target\": 91 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [26,59,55], \"target\": 94 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [41,89,34], \"target\": 100 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 0\n\ntest_input = { \"hours\": [9,26,77,55], \"target\": 0 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 4\n\ntest_input = { \"hours\": [24,79,63,37], \"target\": 1 }\nassert my_solution.numberOfEmployeesWhoMetTarget(**test_input) == 4", "start_time": 1690684200} +{"task_id": "weekly-contest-356-count-complete-subarrays-in-an-array", "url": "https://leetcode.com/problems/count-complete-subarrays-in-an-array", "title": "count-complete-subarrays-in-an-array", "meta": {"questionId": "2856", "questionFrontendId": "2799", "title": "Count Complete Subarrays in an Array", "titleSlug": "count-complete-subarrays-in-an-array", "isPaidOnly": false, "difficulty": "Medium", "likes": 464, "dislikes": 9, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given an array nums consisting of positive integers.\n\nWe call a subarray of an array complete if the following condition is satisfied:\n\n * The number of distinct elements in the subarray is equal to the number of distinct elements in the whole array.\n\nReturn the number of complete subarrays.\n\nA subarray is a contiguous non-empty part of an array.\n\nExample 1:\n\nInput: nums = [1,3,1,2,2]\nOutput: 4\nExplanation: The complete subarrays are the following: [1,3,1,2], [1,3,1,2,2], [3,1,2] and [3,1,2,2].\n\nExample 2:\n\nInput: nums = [5,5,5,5]\nOutput: 10\nExplanation: The array consists only of the integer 5, so any subarray is complete. The number of subarrays that we can choose is 10.\n\n\nConstraints:\n\n * 1 <= nums.length <= 1000\n * 1 <= nums[i] <= 2000\n\"\"\"\nclass Solution:\n def countCompleteSubarrays(self, nums: List[int]) -> int:\n ", "prompt_sft": "You are given an array nums consisting of positive integers.\n\nWe call a subarray of an array complete if the following condition is satisfied:\n\n * The number of distinct elements in the subarray is equal to the number of distinct elements in the whole array.\n\nReturn the number of complete subarrays.\n\nA subarray is a contiguous non-empty part of an array.\n\nExample 1:\n\nInput: nums = [1,3,1,2,2]\nOutput: 4\nExplanation: The complete subarrays are the following: [1,3,1,2], [1,3,1,2,2], [3,1,2] and [3,1,2,2].\n\nExample 2:\n\nInput: nums = [5,5,5,5]\nOutput: 10\nExplanation: The array consists only of the integer 5, so any subarray is complete. The number of subarrays that we can choose is 10.\n\n\nConstraints:\n\n * 1 <= nums.length <= 1000\n * 1 <= nums[i] <= 2000\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def countCompleteSubarrays(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,3,1,2,2] }\nassert my_solution.countCompleteSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [5,5,5,5] }\nassert my_solution.countCompleteSubarrays(**test_input) == 10\n\ntest_input = { \"nums\": [459,459,962,1579,1435,756,1872,1597] }\nassert my_solution.countCompleteSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [1786,1786,1786,114] }\nassert my_solution.countCompleteSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [1632,1632,528,359,1671,1632,511,1087,424,1684] }\nassert my_solution.countCompleteSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [1430,12,1430,1075,1722] }\nassert my_solution.countCompleteSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [1917,1917,608,608,1313,751,558,1561,608] }\nassert my_solution.countCompleteSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [254,1690,1690,1068,1779] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [1116] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [1677,1677,1352,1219,1666,1677,1892,1892,319] }\nassert my_solution.countCompleteSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [1386,1997,1997,574,574,1360,989] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [50,48,1118,540,1248,1984,1698,41,1984,186] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [273,524,40,1323,1323] }\nassert my_solution.countCompleteSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [246,376,828,191,1942,210] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [463,1497,1676,127,1379,17,1075,190] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [765,1370] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [1110,804,1110,839,728,839] }\nassert my_solution.countCompleteSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [1001] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [665,867,954,1411,728,1006,372,1411] }\nassert my_solution.countCompleteSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [1213,1203,1277,369,1277] }\nassert my_solution.countCompleteSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [1898,370,822,1659,1360,128,370,360,261,1898] }\nassert my_solution.countCompleteSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [1881,1446] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [474,315,155,155,1986] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [1389,1817,401,1067,1356,1997] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [1586,1332,1055,1586,1586,1861,892,1445] }\nassert my_solution.countCompleteSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [1601,1601] }\nassert my_solution.countCompleteSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [1417,1417,1160,387,928,1572,1832] }\nassert my_solution.countCompleteSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [1497,1237,1237,946,682,331,742] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [377,377] }\nassert my_solution.countCompleteSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [356,356,356,356,356,315] }\nassert my_solution.countCompleteSubarrays(**test_input) == 5\n\ntest_input = { \"nums\": [285] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [211,211,731,226] }\nassert my_solution.countCompleteSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [1253,188,188,5,1393,1696,1062] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [90,1297,482,482,90,1836,1045,1497,482] }\nassert my_solution.countCompleteSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [1857,273,609,609,1803,1491,223,609,1857,1052] }\nassert my_solution.countCompleteSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [617,1014,679,934,955] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [577,577] }\nassert my_solution.countCompleteSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [1793,997,1082,1411,997,546,224,336,307,336] }\nassert my_solution.countCompleteSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [1150,1150] }\nassert my_solution.countCompleteSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [634] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [1454,1789,1454] }\nassert my_solution.countCompleteSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [1657,1090,1682,1376,547,547,407,755,1124,1376] }\nassert my_solution.countCompleteSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [379] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [1673,1584,1584,1055,1971,1122,1086,1692,75] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [722,1427] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [1641,448,1641,1437,448,1406,1437] }\nassert my_solution.countCompleteSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [1440,704,1440,1440,749] }\nassert my_solution.countCompleteSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [832,832] }\nassert my_solution.countCompleteSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [1635,1759,1759,1976,700] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [1577,1674,1745,156,596,1973,1390,156,1497,415] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [1646,1991] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [1613,881,1660,1270,1783,881,773,1783,1229,111] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [431] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [113] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [151] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [999,701,389,999,409,488,993,999,517,1860] }\nassert my_solution.countCompleteSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [236,596,1263,1563,860,596,1184,575] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [278,338] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [939] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [1293,564,614,694,1386,564] }\nassert my_solution.countCompleteSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [681,448] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [1563,558,1778,1404,1973] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [1508,1508,649] }\nassert my_solution.countCompleteSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [1077,445,1947,445,789,789,789,956,1988,189] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [1984,526,30,1205,1691,1984,1241,280,280,1984] }\nassert my_solution.countCompleteSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [1802,1876,1143,1802,1012,1876,1802,1821] }\nassert my_solution.countCompleteSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [1338,901,613,575,613] }\nassert my_solution.countCompleteSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [406,406,242,242,770,1063,1436,1063,1063] }\nassert my_solution.countCompleteSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [1235,1235] }\nassert my_solution.countCompleteSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [1337,1088,1088,892,1209,1269] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [1941,1941] }\nassert my_solution.countCompleteSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [319] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [1891,1891,1748,1748,923,1748,923,763,1062,1748] }\nassert my_solution.countCompleteSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [1111,503,1980] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [213,1666,469,1675] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [769,1774,1654,928,1204] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [294,294,294,294,1351,294,1351,62,585] }\nassert my_solution.countCompleteSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [1197] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [21,1549,21,1549,1998,1219,1549,1021] }\nassert my_solution.countCompleteSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [1124,1124,556,1322,556] }\nassert my_solution.countCompleteSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [908,908,863,1977,908,8,427,1322] }\nassert my_solution.countCompleteSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [770] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [517,1497,334,334,996,1497,1394,534] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [564,750,750,750,1965,1965,1402] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [403,1080,365,1962,1589,1740,1335,1335,1589] }\nassert my_solution.countCompleteSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [1712,1621,1295,522,1734,522,1371,1935,684] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [270,1443,807,1704,1487] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [1880,1880,1880,604,1634,1412,1880,67,1759,1488] }\nassert my_solution.countCompleteSubarrays(**test_input) == 4\n\ntest_input = { \"nums\": [540,1799,1784,1799,972,1786,1578,1480,178,532] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [1235,471,367] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [1887,1373,190,1764,1764,959,959,1373,17] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [1313,910,1172,1541,1758,140,1380,492,240,1664] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [381,1304,381,758,1304,381,758] }\nassert my_solution.countCompleteSubarrays(**test_input) == 14\n\ntest_input = { \"nums\": [1517,665] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [1555,223,379,223,379,1982] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [1268,1268,1268,1268] }\nassert my_solution.countCompleteSubarrays(**test_input) == 10\n\ntest_input = { \"nums\": [1051,266,266,94,761,1051,255] }\nassert my_solution.countCompleteSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [420,945,3,172] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [1045,1120,1045,511,1045,1777,1224,336,560,153] }\nassert my_solution.countCompleteSubarrays(**test_input) == 2\n\ntest_input = { \"nums\": [627,592,592,1416,370,229,526,633] }\nassert my_solution.countCompleteSubarrays(**test_input) == 1", "start_time": 1690684200} +{"task_id": "weekly-contest-356-shortest-string-that-contains-three-strings", "url": "https://leetcode.com/problems/shortest-string-that-contains-three-strings", "title": "shortest-string-that-contains-three-strings", "meta": {"questionId": "2877", "questionFrontendId": "2800", "title": "Shortest String That Contains Three Strings", "titleSlug": "shortest-string-that-contains-three-strings", "isPaidOnly": false, "difficulty": "Medium", "likes": 301, "dislikes": 244, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nGiven three strings a, b, and c, your task is to find a string that has the minimum length and contains all three strings as substrings.\n\nIf there are multiple such strings, return the lexicographically smallest one.\n\nReturn a string denoting the answer to the problem.\n\nNotes\n\n * A string a is lexicographically smaller than a string b (of the same length) if in the first position where a and b differ, string a has a letter that appears earlier in the alphabet than the corresponding letter in b.\n * A substring is a contiguous sequence of characters within a string.\n\nExample 1:\n\nInput: a = \"abc\", b = \"bca\", c = \"aaa\"\nOutput: \"aaabca\"\nExplanation: We show that \"aaabca\" contains all the given strings: a = ans[2...4], b = ans[3..5], c = ans[0..2]. It can be shown that the length of the resulting string would be at least 6 and \"aaabca\" is the lexicographically smallest one.\n\nExample 2:\n\nInput: a = \"ab\", b = \"ba\", c = \"aba\"\nOutput: \"aba\"\nExplanation: We show that the string \"aba\" contains all the given strings: a = ans[0..1], b = ans[1..2], c = ans[0..2]. Since the length of c is 3, the length of the resulting string would be at least 3. It can be shown that \"aba\" is the lexicographically smallest one.\n\n\nConstraints:\n\n * 1 <= a.length, b.length, c.length <= 100\n * a, b, c consist only of lowercase English letters.\n\"\"\"\nclass Solution:\n def minimumString(self, a: str, b: str, c: str) -> str:\n ", "prompt_sft": "Given three strings a, b, and c, your task is to find a string that has the minimum length and contains all three strings as substrings.\n\nIf there are multiple such strings, return the lexicographically smallest one.\n\nReturn a string denoting the answer to the problem.\n\nNotes\n\n * A string a is lexicographically smaller than a string b (of the same length) if in the first position where a and b differ, string a has a letter that appears earlier in the alphabet than the corresponding letter in b.\n * A substring is a contiguous sequence of characters within a string.\n\nExample 1:\n\nInput: a = \"abc\", b = \"bca\", c = \"aaa\"\nOutput: \"aaabca\"\nExplanation: We show that \"aaabca\" contains all the given strings: a = ans[2...4], b = ans[3..5], c = ans[0..2]. It can be shown that the length of the resulting string would be at least 6 and \"aaabca\" is the lexicographically smallest one.\n\nExample 2:\n\nInput: a = \"ab\", b = \"ba\", c = \"aba\"\nOutput: \"aba\"\nExplanation: We show that the string \"aba\" contains all the given strings: a = ans[0..1], b = ans[1..2], c = ans[0..2]. Since the length of c is 3, the length of the resulting string would be at least 3. It can be shown that \"aba\" is the lexicographically smallest one.\n\n\nConstraints:\n\n * 1 <= a.length, b.length, c.length <= 100\n * a, b, c consist only of lowercase English letters.\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def minimumString(self, a: str, b: str, c: str) -> str:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"a\": \"abc\", \"b\": \"bca\", \"c\": \"aaa\" }\nassert my_solution.minimumString(**test_input) == \"aaabca\"\n\ntest_input = { \"a\": \"ab\", \"b\": \"ba\", \"c\": \"aba\" }\nassert my_solution.minimumString(**test_input) == \"aba\"\n\ntest_input = { \"a\": \"xyyyz\", \"b\": \"xzyz\", \"c\": \"zzz\" }\nassert my_solution.minimumString(**test_input) == \"xyyyzxzyzzz\"\n\ntest_input = { \"a\": \"a\", \"b\": \"a\", \"c\": \"a\" }\nassert my_solution.minimumString(**test_input) == \"a\"\n\ntest_input = { \"a\": \"a\", \"b\": \"a\", \"c\": \"b\" }\nassert my_solution.minimumString(**test_input) == \"ab\"\n\ntest_input = { \"a\": \"a\", \"b\": \"c\", \"c\": \"a\" }\nassert my_solution.minimumString(**test_input) == \"ac\"\n\ntest_input = { \"a\": \"a\", \"b\": \"b\", \"c\": \"b\" }\nassert my_solution.minimumString(**test_input) == \"ab\"\n\ntest_input = { \"a\": \"a\", \"b\": \"a\", \"c\": \"c\" }\nassert my_solution.minimumString(**test_input) == \"ac\"\n\ntest_input = { \"a\": \"a\", \"b\": \"c\", \"c\": \"b\" }\nassert my_solution.minimumString(**test_input) == \"abc\"\n\ntest_input = { \"a\": \"c\", \"b\": \"c\", \"c\": \"a\" }\nassert my_solution.minimumString(**test_input) == \"ac\"\n\ntest_input = { \"a\": \"k\", \"b\": \"e\", \"c\": \"a\" }\nassert my_solution.minimumString(**test_input) == \"aek\"\n\ntest_input = { \"a\": \"a\", \"b\": \"b\", \"c\": \"a\" }\nassert my_solution.minimumString(**test_input) == \"ab\"\n\ntest_input = { \"a\": \"b\", \"b\": \"b\", \"c\": \"a\" }\nassert my_solution.minimumString(**test_input) == \"ab\"\n\ntest_input = { \"a\": \"b\", \"b\": \"b\", \"c\": \"b\" }\nassert my_solution.minimumString(**test_input) == \"b\"\n\ntest_input = { \"a\": \"b\", \"b\": \"b\", \"c\": \"c\" }\nassert my_solution.minimumString(**test_input) == \"bc\"\n\ntest_input = { \"a\": \"c\", \"b\": \"b\", \"c\": \"b\" }\nassert my_solution.minimumString(**test_input) == \"bc\"\n\ntest_input = { \"a\": \"b\", \"b\": \"c\", \"c\": \"c\" }\nassert my_solution.minimumString(**test_input) == \"bc\"\n\ntest_input = { \"a\": \"b\", \"b\": \"c\", \"c\": \"a\" }\nassert my_solution.minimumString(**test_input) == \"abc\"\n\ntest_input = { \"a\": \"c\", \"b\": \"a\", \"c\": \"c\" }\nassert my_solution.minimumString(**test_input) == \"ac\"\n\ntest_input = { \"a\": \"c\", \"b\": \"b\", \"c\": \"c\" }\nassert my_solution.minimumString(**test_input) == \"bc\"\n\ntest_input = { \"a\": \"c\", \"b\": \"c\", \"c\": \"c\" }\nassert my_solution.minimumString(**test_input) == \"c\"\n\ntest_input = { \"a\": \"e\", \"b\": \"k\", \"c\": \"y\" }\nassert my_solution.minimumString(**test_input) == \"eky\"\n\ntest_input = { \"a\": \"z\", \"b\": \"p\", \"c\": \"m\" }\nassert my_solution.minimumString(**test_input) == \"mpz\"\n\ntest_input = { \"a\": \"a\", \"b\": \"aa\", \"c\": \"a\" }\nassert my_solution.minimumString(**test_input) == \"aa\"\n\ntest_input = { \"a\": \"ac\", \"b\": \"a\", \"c\": \"a\" }\nassert my_solution.minimumString(**test_input) == \"ac\"\n\ntest_input = { \"a\": \"ca\", \"b\": \"a\", \"c\": \"a\" }\nassert my_solution.minimumString(**test_input) == \"ca\"\n\ntest_input = { \"a\": \"a\", \"b\": \"cc\", \"c\": \"a\" }\nassert my_solution.minimumString(**test_input) == \"acc\"\n\ntest_input = { \"a\": \"a\", \"b\": \"a\", \"c\": \"aa\" }\nassert my_solution.minimumString(**test_input) == \"aa\"\n\ntest_input = { \"a\": \"c\", \"b\": \"a\", \"c\": \"aa\" }\nassert my_solution.minimumString(**test_input) == \"aac\"\n\ntest_input = { \"a\": \"a\", \"b\": \"ab\", \"c\": \"a\" }\nassert my_solution.minimumString(**test_input) == \"ab\"\n\ntest_input = { \"a\": \"ab\", \"b\": \"b\", \"c\": \"a\" }\nassert my_solution.minimumString(**test_input) == \"ab\"\n\ntest_input = { \"a\": \"ab\", \"b\": \"a\", \"c\": \"c\" }\nassert my_solution.minimumString(**test_input) == \"abc\"\n\ntest_input = { \"a\": \"c\", \"b\": \"ac\", \"c\": \"a\" }\nassert my_solution.minimumString(**test_input) == \"ac\"\n\ntest_input = { \"a\": \"ab\", \"b\": \"a\", \"c\": \"b\" }\nassert my_solution.minimumString(**test_input) == \"ab\"\n\ntest_input = { \"a\": \"b\", \"b\": \"a\", \"c\": \"ba\" }\nassert my_solution.minimumString(**test_input) == \"ba\"\n\ntest_input = { \"a\": \"ba\", \"b\": \"a\", \"c\": \"a\" }\nassert my_solution.minimumString(**test_input) == \"ba\"\n\ntest_input = { \"a\": \"b\", \"b\": \"ba\", \"c\": \"a\" }\nassert my_solution.minimumString(**test_input) == \"ba\"\n\ntest_input = { \"a\": \"a\", \"b\": \"bc\", \"c\": \"a\" }\nassert my_solution.minimumString(**test_input) == \"abc\"\n\ntest_input = { \"a\": \"c\", \"b\": \"a\", \"c\": \"bc\" }\nassert my_solution.minimumString(**test_input) == \"abc\"\n\ntest_input = { \"a\": \"a\", \"b\": \"c\", \"c\": \"ab\" }\nassert my_solution.minimumString(**test_input) == \"abc\"\n\ntest_input = { \"a\": \"c\", \"b\": \"a\", \"c\": \"ac\" }\nassert my_solution.minimumString(**test_input) == \"ac\"\n\ntest_input = { \"a\": \"a\", \"b\": \"c\", \"c\": \"ca\" }\nassert my_solution.minimumString(**test_input) == \"ca\"\n\ntest_input = { \"a\": \"c\", \"b\": \"a\", \"c\": \"cc\" }\nassert my_solution.minimumString(**test_input) == \"acc\"\n\ntest_input = { \"a\": \"a\", \"b\": \"ca\", \"c\": \"a\" }\nassert my_solution.minimumString(**test_input) == \"ca\"\n\ntest_input = { \"a\": \"a\", \"b\": \"cc\", \"c\": \"c\" }\nassert my_solution.minimumString(**test_input) == \"acc\"\n\ntest_input = { \"a\": \"aa\", \"b\": \"a\", \"c\": \"a\" }\nassert my_solution.minimumString(**test_input) == \"aa\"\n\ntest_input = { \"a\": \"aa\", \"b\": \"b\", \"c\": \"a\" }\nassert my_solution.minimumString(**test_input) == \"aab\"\n\ntest_input = { \"a\": \"a\", \"b\": \"aa\", \"c\": \"c\" }\nassert my_solution.minimumString(**test_input) == \"aac\"\n\ntest_input = { \"a\": \"b\", \"b\": \"c\", \"c\": \"aa\" }\nassert my_solution.minimumString(**test_input) == \"aabc\"\n\ntest_input = { \"a\": \"b\", \"b\": \"b\", \"c\": \"ab\" }\nassert my_solution.minimumString(**test_input) == \"ab\"\n\ntest_input = { \"a\": \"ab\", \"b\": \"b\", \"c\": \"c\" }\nassert my_solution.minimumString(**test_input) == \"abc\"\n\ntest_input = { \"a\": \"ac\", \"b\": \"c\", \"c\": \"b\" }\nassert my_solution.minimumString(**test_input) == \"acb\"\n\ntest_input = { \"a\": \"c\", \"b\": \"c\", \"c\": \"ac\" }\nassert my_solution.minimumString(**test_input) == \"ac\"\n\ntest_input = { \"a\": \"ba\", \"b\": \"b\", \"c\": \"a\" }\nassert my_solution.minimumString(**test_input) == \"ba\"\n\ntest_input = { \"a\": \"a\", \"b\": \"b\", \"c\": \"ca\" }\nassert my_solution.minimumString(**test_input) == \"bca\"\n\ntest_input = { \"a\": \"b\", \"b\": \"a\", \"c\": \"aa\" }\nassert my_solution.minimumString(**test_input) == \"aab\"\n\ntest_input = { \"a\": \"b\", \"b\": \"b\", \"c\": \"aa\" }\nassert my_solution.minimumString(**test_input) == \"aab\"\n\ntest_input = { \"a\": \"b\", \"b\": \"ab\", \"c\": \"a\" }\nassert my_solution.minimumString(**test_input) == \"ab\"\n\ntest_input = { \"a\": \"b\", \"b\": \"ab\", \"c\": \"b\" }\nassert my_solution.minimumString(**test_input) == \"ab\"\n\ntest_input = { \"a\": \"ac\", \"b\": \"b\", \"c\": \"a\" }\nassert my_solution.minimumString(**test_input) == \"acb\"\n\ntest_input = { \"a\": \"b\", \"b\": \"b\", \"c\": \"ac\" }\nassert my_solution.minimumString(**test_input) == \"acb\"\n\ntest_input = { \"a\": \"bb\", \"b\": \"b\", \"c\": \"b\" }\nassert my_solution.minimumString(**test_input) == \"bb\"\n\ntest_input = { \"a\": \"b\", \"b\": \"bc\", \"c\": \"b\" }\nassert my_solution.minimumString(**test_input) == \"bc\"\n\ntest_input = { \"a\": \"b\", \"b\": \"b\", \"c\": \"ca\" }\nassert my_solution.minimumString(**test_input) == \"bca\"\n\ntest_input = { \"a\": \"cb\", \"b\": \"b\", \"c\": \"b\" }\nassert my_solution.minimumString(**test_input) == \"cb\"\n\ntest_input = { \"a\": \"b\", \"b\": \"b\", \"c\": \"bb\" }\nassert my_solution.minimumString(**test_input) == \"bb\"\n\ntest_input = { \"a\": \"b\", \"b\": \"a\", \"c\": \"bc\" }\nassert my_solution.minimumString(**test_input) == \"abc\"\n\ntest_input = { \"a\": \"b\", \"b\": \"bc\", \"c\": \"c\" }\nassert my_solution.minimumString(**test_input) == \"bc\"\n\ntest_input = { \"a\": \"b\", \"b\": \"ab\", \"c\": \"c\" }\nassert my_solution.minimumString(**test_input) == \"abc\"\n\ntest_input = { \"a\": \"b\", \"b\": \"bb\", \"c\": \"c\" }\nassert my_solution.minimumString(**test_input) == \"bbc\"\n\ntest_input = { \"a\": \"c\", \"b\": \"b\", \"c\": \"bc\" }\nassert my_solution.minimumString(**test_input) == \"bc\"\n\ntest_input = { \"a\": \"b\", \"b\": \"cb\", \"c\": \"c\" }\nassert my_solution.minimumString(**test_input) == \"cb\"\n\ntest_input = { \"a\": \"b\", \"b\": \"cc\", \"c\": \"c\" }\nassert my_solution.minimumString(**test_input) == \"bcc\"\n\ntest_input = { \"a\": \"b\", \"b\": \"cb\", \"c\": \"a\" }\nassert my_solution.minimumString(**test_input) == \"acb\"\n\ntest_input = { \"a\": \"b\", \"b\": \"b\", \"c\": \"cb\" }\nassert my_solution.minimumString(**test_input) == \"cb\"\n\ntest_input = { \"a\": \"c\", \"b\": \"b\", \"c\": \"cb\" }\nassert my_solution.minimumString(**test_input) == \"cb\"\n\ntest_input = { \"a\": \"a\", \"b\": \"ba\", \"c\": \"b\" }\nassert my_solution.minimumString(**test_input) == \"ba\"\n\ntest_input = { \"a\": \"ba\", \"b\": \"a\", \"c\": \"b\" }\nassert my_solution.minimumString(**test_input) == \"ba\"\n\ntest_input = { \"a\": \"ba\", \"b\": \"b\", \"c\": \"b\" }\nassert my_solution.minimumString(**test_input) == \"ba\"\n\ntest_input = { \"a\": \"b\", \"b\": \"ba\", \"c\": \"c\" }\nassert my_solution.minimumString(**test_input) == \"bac\"\n\ntest_input = { \"a\": \"c\", \"b\": \"ba\", \"c\": \"b\" }\nassert my_solution.minimumString(**test_input) == \"bac\"\n\ntest_input = { \"a\": \"c\", \"b\": \"c\", \"c\": \"ba\" }\nassert my_solution.minimumString(**test_input) == \"bac\"\n\ntest_input = { \"a\": \"bb\", \"b\": \"a\", \"c\": \"b\" }\nassert my_solution.minimumString(**test_input) == \"abb\"\n\ntest_input = { \"a\": \"b\", \"b\": \"bb\", \"c\": \"b\" }\nassert my_solution.minimumString(**test_input) == \"bb\"\n\ntest_input = { \"a\": \"c\", \"b\": \"bb\", \"c\": \"b\" }\nassert my_solution.minimumString(**test_input) == \"bbc\"\n\ntest_input = { \"a\": \"a\", \"b\": \"bc\", \"c\": \"b\" }\nassert my_solution.minimumString(**test_input) == \"abc\"\n\ntest_input = { \"a\": \"bc\", \"b\": \"b\", \"c\": \"c\" }\nassert my_solution.minimumString(**test_input) == \"bc\"\n\ntest_input = { \"a\": \"bc\", \"b\": \"c\", \"c\": \"b\" }\nassert my_solution.minimumString(**test_input) == \"bc\"\n\ntest_input = { \"a\": \"bc\", \"b\": \"c\", \"c\": \"c\" }\nassert my_solution.minimumString(**test_input) == \"bc\"\n\ntest_input = { \"a\": \"ac\", \"b\": \"a\", \"c\": \"c\" }\nassert my_solution.minimumString(**test_input) == \"ac\"\n\ntest_input = { \"a\": \"c\", \"b\": \"c\", \"c\": \"aa\" }\nassert my_solution.minimumString(**test_input) == \"aac\"\n\ntest_input = { \"a\": \"cb\", \"b\": \"b\", \"c\": \"c\" }\nassert my_solution.minimumString(**test_input) == \"cb\"\n\ntest_input = { \"a\": \"c\", \"b\": \"b\", \"c\": \"cc\" }\nassert my_solution.minimumString(**test_input) == \"bcc\"\n\ntest_input = { \"a\": \"ba\", \"b\": \"b\", \"c\": \"c\" }\nassert my_solution.minimumString(**test_input) == \"bac\"\n\ntest_input = { \"a\": \"aa\", \"b\": \"c\", \"c\": \"c\" }\nassert my_solution.minimumString(**test_input) == \"aac\"\n\ntest_input = { \"a\": \"c\", \"b\": \"bc\", \"c\": \"c\" }\nassert my_solution.minimumString(**test_input) == \"bc\"\n\ntest_input = { \"a\": \"c\", \"b\": \"ca\", \"c\": \"c\" }\nassert my_solution.minimumString(**test_input) == \"ca\"\n\ntest_input = { \"a\": \"c\", \"b\": \"cb\", \"c\": \"c\" }\nassert my_solution.minimumString(**test_input) == \"cb\"\n\ntest_input = { \"a\": \"c\", \"b\": \"c\", \"c\": \"cc\" }\nassert my_solution.minimumString(**test_input) == \"cc\"\n\ntest_input = { \"a\": \"ca\", \"b\": \"c\", \"c\": \"a\" }\nassert my_solution.minimumString(**test_input) == \"ca\"", "start_time": 1690684200} +{"task_id": "weekly-contest-356-count-stepping-numbers-in-range", "url": "https://leetcode.com/problems/count-stepping-numbers-in-range", "title": "count-stepping-numbers-in-range", "meta": {"questionId": "2921", "questionFrontendId": "2801", "title": "Count Stepping Numbers in Range", "titleSlug": "count-stepping-numbers-in-range", "isPaidOnly": false, "difficulty": "Hard", "likes": 312, "dislikes": 8, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nGiven two positive integers low and high represented as strings, find the count of stepping numbers in the inclusive range [low, high].\n\nA stepping number is an integer such that all of its adjacent digits have an absolute difference of exactly 1.\n\nReturn an integer denoting the count of stepping numbers in the inclusive range [low, high].\n\nSince the answer may be very large, return it modulo 109 + 7.\n\nNote: A stepping number should not have a leading zero.\n\nExample 1:\n\nInput: low = \"1\", high = \"11\"\nOutput: 10\nExplanation: The stepping numbers in the range [1,11] are 1, 2, 3, 4, 5, 6, 7, 8, 9 and 10. There are a total of 10 stepping numbers in the range. Hence, the output is 10.\n\nExample 2:\n\nInput: low = \"90\", high = \"101\"\nOutput: 2\nExplanation: The stepping numbers in the range [90,101] are 98 and 101. There are a total of 2 stepping numbers in the range. Hence, the output is 2.\n\nConstraints:\n\n * 1 <= int(low) <= int(high) < 10100\n * 1 <= low.length, high.length <= 100\n * low and high consist of only digits.\n * low and high don't have any leading zeros.\n\"\"\"\nclass Solution:\n def countSteppingNumbers(self, low: str, high: str) -> int:\n ", "prompt_sft": "Given two positive integers low and high represented as strings, find the count of stepping numbers in the inclusive range [low, high].\n\nA stepping number is an integer such that all of its adjacent digits have an absolute difference of exactly 1.\n\nReturn an integer denoting the count of stepping numbers in the inclusive range [low, high].\n\nSince the answer may be very large, return it modulo 109 + 7.\n\nNote: A stepping number should not have a leading zero.\n\nExample 1:\n\nInput: low = \"1\", high = \"11\"\nOutput: 10\nExplanation: The stepping numbers in the range [1,11] are 1, 2, 3, 4, 5, 6, 7, 8, 9 and 10. There are a total of 10 stepping numbers in the range. Hence, the output is 10.\n\nExample 2:\n\nInput: low = \"90\", high = \"101\"\nOutput: 2\nExplanation: The stepping numbers in the range [90,101] are 98 and 101. There are a total of 2 stepping numbers in the range. Hence, the output is 2.\n\nConstraints:\n\n * 1 <= int(low) <= int(high) < 10100\n * 1 <= low.length, high.length <= 100\n * low and high consist of only digits.\n * low and high don't have any leading zeros.\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def countSteppingNumbers(self, low: str, high: str) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"low\": \"1\", \"high\": \"11\" }\nassert my_solution.countSteppingNumbers(**test_input) == 10\n\ntest_input = { \"low\": \"90\", \"high\": \"101\" }\nassert my_solution.countSteppingNumbers(**test_input) == 2\n\ntest_input = { \"low\": \"2\", \"high\": \"40\" }\nassert my_solution.countSteppingNumbers(**test_input) == 14\n\ntest_input = { \"low\": \"26\", \"high\": \"60\" }\nassert my_solution.countSteppingNumbers(**test_input) == 6\n\ntest_input = { \"low\": \"40\", \"high\": \"70\" }\nassert my_solution.countSteppingNumbers(**test_input) == 6\n\ntest_input = { \"low\": \"46\", \"high\": \"66\" }\nassert my_solution.countSteppingNumbers(**test_input) == 3\n\ntest_input = { \"low\": \"58\", \"high\": \"58\" }\nassert my_solution.countSteppingNumbers(**test_input) == 0\n\ntest_input = { \"low\": \"23\", \"high\": \"99\" }\nassert my_solution.countSteppingNumbers(**test_input) == 14\n\ntest_input = { \"low\": \"44\", \"high\": \"86\" }\nassert my_solution.countSteppingNumbers(**test_input) == 7\n\ntest_input = { \"low\": \"20\", \"high\": \"111\" }\nassert my_solution.countSteppingNumbers(**test_input) == 16\n\ntest_input = { \"low\": \"70\", \"high\": \"75\" }\nassert my_solution.countSteppingNumbers(**test_input) == 0\n\ntest_input = { \"low\": \"37\", \"high\": \"111\" }\nassert my_solution.countSteppingNumbers(**test_input) == 12\n\ntest_input = { \"low\": \"17\", \"high\": \"149\" }\nassert my_solution.countSteppingNumbers(**test_input) == 18\n\ntest_input = { \"low\": \"21\", \"high\": \"145\" }\nassert my_solution.countSteppingNumbers(**test_input) == 18\n\ntest_input = { \"low\": \"47\", \"high\": \"124\" }\nassert my_solution.countSteppingNumbers(**test_input) == 12\n\ntest_input = { \"low\": \"81\", \"high\": \"91\" }\nassert my_solution.countSteppingNumbers(**test_input) == 2\n\ntest_input = { \"low\": \"18\", \"high\": \"159\" }\nassert my_solution.countSteppingNumbers(**test_input) == 18\n\ntest_input = { \"low\": \"85\", \"high\": \"92\" }\nassert my_solution.countSteppingNumbers(**test_input) == 2\n\ntest_input = { \"low\": \"66\", \"high\": \"112\" }\nassert my_solution.countSteppingNumbers(**test_input) == 7\n\ntest_input = { \"low\": \"84\", \"high\": \"102\" }\nassert my_solution.countSteppingNumbers(**test_input) == 4\n\ntest_input = { \"low\": \"41\", \"high\": \"156\" }\nassert my_solution.countSteppingNumbers(**test_input) == 14\n\ntest_input = { \"low\": \"64\", \"high\": \"135\" }\nassert my_solution.countSteppingNumbers(**test_input) == 10\n\ntest_input = { \"low\": \"57\", \"high\": \"143\" }\nassert my_solution.countSteppingNumbers(**test_input) == 10\n\ntest_input = { \"low\": \"85\", \"high\": \"116\" }\nassert my_solution.countSteppingNumbers(**test_input) == 4\n\ntest_input = { \"low\": \"103\", \"high\": \"104\" }\nassert my_solution.countSteppingNumbers(**test_input) == 0\n\ntest_input = { \"low\": \"98\", \"high\": \"118\" }\nassert my_solution.countSteppingNumbers(**test_input) == 2\n\ntest_input = { \"low\": \"28\", \"high\": \"197\" }\nassert my_solution.countSteppingNumbers(**test_input) == 16\n\ntest_input = { \"low\": \"6\", \"high\": \"220\" }\nassert my_solution.countSteppingNumbers(**test_input) == 26\n\ntest_input = { \"low\": \"106\", \"high\": \"121\" }\nassert my_solution.countSteppingNumbers(**test_input) == 1\n\ntest_input = { \"low\": \"7\", \"high\": \"226\" }\nassert my_solution.countSteppingNumbers(**test_input) == 25\n\ntest_input = { \"low\": \"105\", \"high\": \"136\" }\nassert my_solution.countSteppingNumbers(**test_input) == 2\n\ntest_input = { \"low\": \"30\", \"high\": \"221\" }\nassert my_solution.countSteppingNumbers(**test_input) == 18\n\ntest_input = { \"low\": \"113\", \"high\": \"139\" }\nassert my_solution.countSteppingNumbers(**test_input) == 2\n\ntest_input = { \"low\": \"44\", \"high\": \"210\" }\nassert my_solution.countSteppingNumbers(**test_input) == 14\n\ntest_input = { \"low\": \"13\", \"high\": \"242\" }\nassert my_solution.countSteppingNumbers(**test_input) == 22\n\ntest_input = { \"low\": \"12\", \"high\": \"257\" }\nassert my_solution.countSteppingNumbers(**test_input) == 23\n\ntest_input = { \"low\": \"70\", \"high\": \"205\" }\nassert my_solution.countSteppingNumbers(**test_input) == 8\n\ntest_input = { \"low\": \"55\", \"high\": \"229\" }\nassert my_solution.countSteppingNumbers(**test_input) == 13\n\ntest_input = { \"low\": \"16\", \"high\": \"276\" }\nassert my_solution.countSteppingNumbers(**test_input) == 22\n\ntest_input = { \"low\": \"140\", \"high\": \"153\" }\nassert my_solution.countSteppingNumbers(**test_input) == 0\n\ntest_input = { \"low\": \"79\", \"high\": \"218\" }\nassert my_solution.countSteppingNumbers(**test_input) == 8\n\ntest_input = { \"low\": \"99\", \"high\": \"200\" }\nassert my_solution.countSteppingNumbers(**test_input) == 3\n\ntest_input = { \"low\": \"90\", \"high\": \"210\" }\nassert my_solution.countSteppingNumbers(**test_input) == 5\n\ntest_input = { \"low\": \"123\", \"high\": \"186\" }\nassert my_solution.countSteppingNumbers(**test_input) == 1\n\ntest_input = { \"low\": \"149\", \"high\": \"160\" }\nassert my_solution.countSteppingNumbers(**test_input) == 0\n\ntest_input = { \"low\": \"138\", \"high\": \"180\" }\nassert my_solution.countSteppingNumbers(**test_input) == 0\n\ntest_input = { \"low\": \"160\", \"high\": \"163\" }\nassert my_solution.countSteppingNumbers(**test_input) == 0\n\ntest_input = { \"low\": \"79\", \"high\": \"246\" }\nassert my_solution.countSteppingNumbers(**test_input) == 10\n\ntest_input = { \"low\": \"137\", \"high\": \"189\" }\nassert my_solution.countSteppingNumbers(**test_input) == 0\n\ntest_input = { \"low\": \"163\", \"high\": \"163\" }\nassert my_solution.countSteppingNumbers(**test_input) == 0\n\ntest_input = { \"low\": \"37\", \"high\": \"289\" }\nassert my_solution.countSteppingNumbers(**test_input) == 18\n\ntest_input = { \"low\": \"79\", \"high\": \"255\" }\nassert my_solution.countSteppingNumbers(**test_input) == 10\n\ntest_input = { \"low\": \"140\", \"high\": \"197\" }\nassert my_solution.countSteppingNumbers(**test_input) == 0\n\ntest_input = { \"low\": \"22\", \"high\": \"317\" }\nassert my_solution.countSteppingNumbers(**test_input) == 21\n\ntest_input = { \"low\": \"146\", \"high\": \"199\" }\nassert my_solution.countSteppingNumbers(**test_input) == 0\n\ntest_input = { \"low\": \"57\", \"high\": \"288\" }\nassert my_solution.countSteppingNumbers(**test_input) == 14\n\ntest_input = { \"low\": \"109\", \"high\": \"237\" }\nassert my_solution.countSteppingNumbers(**test_input) == 6\n\ntest_input = { \"low\": \"48\", \"high\": \"299\" }\nassert my_solution.countSteppingNumbers(**test_input) == 16\n\ntest_input = { \"low\": \"158\", \"high\": \"194\" }\nassert my_solution.countSteppingNumbers(**test_input) == 0\n\ntest_input = { \"low\": \"29\", \"high\": \"326\" }\nassert my_solution.countSteppingNumbers(**test_input) == 22\n\ntest_input = { \"low\": \"133\", \"high\": \"223\" }\nassert my_solution.countSteppingNumbers(**test_input) == 2\n\ntest_input = { \"low\": \"109\", \"high\": \"249\" }\nassert my_solution.countSteppingNumbers(**test_input) == 6\n\ntest_input = { \"low\": \"20\", \"high\": \"341\" }\nassert my_solution.countSteppingNumbers(**test_input) == 24\n\ntest_input = { \"low\": \"9\", \"high\": \"352\" }\nassert my_solution.countSteppingNumbers(**test_input) == 29\n\ntest_input = { \"low\": \"115\", \"high\": \"253\" }\nassert my_solution.countSteppingNumbers(**test_input) == 6\n\ntest_input = { \"low\": \"181\", \"high\": \"188\" }\nassert my_solution.countSteppingNumbers(**test_input) == 0\n\ntest_input = { \"low\": \"120\", \"high\": \"250\" }\nassert my_solution.countSteppingNumbers(**test_input) == 6\n\ntest_input = { \"low\": \"100\", \"high\": \"273\" }\nassert my_solution.countSteppingNumbers(**test_input) == 7\n\ntest_input = { \"low\": \"105\", \"high\": \"269\" }\nassert my_solution.countSteppingNumbers(**test_input) == 6\n\ntest_input = { \"low\": \"189\", \"high\": \"190\" }\nassert my_solution.countSteppingNumbers(**test_input) == 0\n\ntest_input = { \"low\": \"148\", \"high\": \"237\" }\nassert my_solution.countSteppingNumbers(**test_input) == 4\n\ntest_input = { \"low\": \"126\", \"high\": \"267\" }\nassert my_solution.countSteppingNumbers(**test_input) == 4\n\ntest_input = { \"low\": \"141\", \"high\": \"252\" }\nassert my_solution.countSteppingNumbers(**test_input) == 4\n\ntest_input = { \"low\": \"185\", \"high\": \"209\" }\nassert my_solution.countSteppingNumbers(**test_input) == 0\n\ntest_input = { \"low\": \"14\", \"high\": \"381\" }\nassert my_solution.countSteppingNumbers(**test_input) == 26\n\ntest_input = { \"low\": \"7\", \"high\": \"388\" }\nassert my_solution.countSteppingNumbers(**test_input) == 31\n\ntest_input = { \"low\": \"15\", \"high\": \"383\" }\nassert my_solution.countSteppingNumbers(**test_input) == 26\n\ntest_input = { \"low\": \"78\", \"high\": \"325\" }\nassert my_solution.countSteppingNumbers(**test_input) == 13\n\ntest_input = { \"low\": \"131\", \"high\": \"274\" }\nassert my_solution.countSteppingNumbers(**test_input) == 4\n\ntest_input = { \"low\": \"177\", \"high\": \"230\" }\nassert my_solution.countSteppingNumbers(**test_input) == 2\n\ntest_input = { \"low\": \"66\", \"high\": \"346\" }\nassert my_solution.countSteppingNumbers(**test_input) == 17\n\ntest_input = { \"low\": \"144\", \"high\": \"271\" }\nassert my_solution.countSteppingNumbers(**test_input) == 4\n\ntest_input = { \"low\": \"96\", \"high\": \"322\" }\nassert my_solution.countSteppingNumbers(**test_input) == 9\n\ntest_input = { \"low\": \"112\", \"high\": \"307\" }\nassert my_solution.countSteppingNumbers(**test_input) == 6\n\ntest_input = { \"low\": \"73\", \"high\": \"349\" }\nassert my_solution.countSteppingNumbers(**test_input) == 16\n\ntest_input = { \"low\": \"128\", \"high\": \"296\" }\nassert my_solution.countSteppingNumbers(**test_input) == 4\n\ntest_input = { \"low\": \"189\", \"high\": \"237\" }\nassert my_solution.countSteppingNumbers(**test_input) == 4\n\ntest_input = { \"low\": \"141\", \"high\": \"286\" }\nassert my_solution.countSteppingNumbers(**test_input) == 4\n\ntest_input = { \"low\": \"47\", \"high\": \"382\" }\nassert my_solution.countSteppingNumbers(**test_input) == 20\n\ntest_input = { \"low\": \"27\", \"high\": \"411\" }\nassert my_solution.countSteppingNumbers(**test_input) == 24\n\ntest_input = { \"low\": \"16\", \"high\": \"423\" }\nassert my_solution.countSteppingNumbers(**test_input) == 26\n\ntest_input = { \"low\": \"22\", \"high\": \"417\" }\nassert my_solution.countSteppingNumbers(**test_input) == 25\n\ntest_input = { \"low\": \"174\", \"high\": \"266\" }\nassert my_solution.countSteppingNumbers(**test_input) == 4\n\ntest_input = { \"low\": \"101\", \"high\": \"342\" }\nassert my_solution.countSteppingNumbers(**test_input) == 9\n\ntest_input = { \"low\": \"76\", \"high\": \"370\" }\nassert my_solution.countSteppingNumbers(**test_input) == 16\n\ntest_input = { \"low\": \"147\", \"high\": \"301\" }\nassert my_solution.countSteppingNumbers(**test_input) == 4\n\ntest_input = { \"low\": \"72\", \"high\": \"376\" }\nassert my_solution.countSteppingNumbers(**test_input) == 16\n\ntest_input = { \"low\": \"154\", \"high\": \"297\" }\nassert my_solution.countSteppingNumbers(**test_input) == 4\n\ntest_input = { \"low\": \"15\", \"high\": \"439\" }\nassert my_solution.countSteppingNumbers(**test_input) == 28\n\ntest_input = { \"low\": \"73\", \"high\": \"381\" }\nassert my_solution.countSteppingNumbers(**test_input) == 16", "start_time": 1690684200} +{"task_id": "weekly-contest-355-split-strings-by-separator", "url": "https://leetcode.com/problems/split-strings-by-separator", "title": "split-strings-by-separator", "meta": {"questionId": "2881", "questionFrontendId": "2788", "title": "Split Strings by Separator", "titleSlug": "split-strings-by-separator", "isPaidOnly": false, "difficulty": "Easy", "likes": 262, "dislikes": 4, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nGiven an array of strings words and a character separator, split each string in words by separator.\n\nReturn an array of strings containing the new strings formed after the splits, excluding empty strings.\n\nNotes\n\n * separator is used to determine where the split should occur, but it is not included as part of the resulting strings.\n * A split may result in more than two strings.\n * The resulting strings must maintain the same order as they were initially given.\n\nExample 1:\n\nInput: words = [\"one.two.three\",\"four.five\",\"six\"], separator = \".\"\nOutput: [\"one\",\"two\",\"three\",\"four\",\"five\",\"six\"]\nExplanation: In this example we split as follows:\n\n\"one.two.three\" splits into \"one\", \"two\", \"three\"\n\"four.five\" splits into \"four\", \"five\"\n\"six\" splits into \"six\"\n\nHence, the resulting array is [\"one\",\"two\",\"three\",\"four\",\"five\",\"six\"].\n\nExample 2:\n\nInput: words = [\"$easy$\",\"$problem$\"], separator = \"$\"\nOutput: [\"easy\",\"problem\"]\nExplanation: In this example we split as follows:\n\n\"$easy$\" splits into \"easy\" (excluding empty strings)\n\"$problem$\" splits into \"problem\" (excluding empty strings)\n\nHence, the resulting array is [\"easy\",\"problem\"].\n\nExample 3:\n\nInput: words = [\"|||\"], separator = \"|\"\nOutput: []\nExplanation: In this example the resulting split of \"|||\" will contain only empty strings, so we return an empty array [].\n\nConstraints:\n\n * 1 <= words.length <= 100\n * 1 <= words[i].length <= 20\n * characters in words[i] are either lowercase English letters or characters from the string \".,|$#@\" (excluding the quotes)\n * separator is a character from the string \".,|$#@\" (excluding the quotes)\n\"\"\"\nclass Solution:\n def splitWordsBySeparator(self, words: List[str], separator: str) -> List[str]:\n ", "prompt_sft": "Given an array of strings words and a character separator, split each string in words by separator.\n\nReturn an array of strings containing the new strings formed after the splits, excluding empty strings.\n\nNotes\n\n * separator is used to determine where the split should occur, but it is not included as part of the resulting strings.\n * A split may result in more than two strings.\n * The resulting strings must maintain the same order as they were initially given.\n\nExample 1:\n\nInput: words = [\"one.two.three\",\"four.five\",\"six\"], separator = \".\"\nOutput: [\"one\",\"two\",\"three\",\"four\",\"five\",\"six\"]\nExplanation: In this example we split as follows:\n\n\"one.two.three\" splits into \"one\", \"two\", \"three\"\n\"four.five\" splits into \"four\", \"five\"\n\"six\" splits into \"six\"\n\nHence, the resulting array is [\"one\",\"two\",\"three\",\"four\",\"five\",\"six\"].\n\nExample 2:\n\nInput: words = [\"$easy$\",\"$problem$\"], separator = \"$\"\nOutput: [\"easy\",\"problem\"]\nExplanation: In this example we split as follows:\n\n\"$easy$\" splits into \"easy\" (excluding empty strings)\n\"$problem$\" splits into \"problem\" (excluding empty strings)\n\nHence, the resulting array is [\"easy\",\"problem\"].\n\nExample 3:\n\nInput: words = [\"|||\"], separator = \"|\"\nOutput: []\nExplanation: In this example the resulting split of \"|||\" will contain only empty strings, so we return an empty array [].\n\nConstraints:\n\n * 1 <= words.length <= 100\n * 1 <= words[i].length <= 20\n * characters in words[i] are either lowercase English letters or characters from the string \".,|$#@\" (excluding the quotes)\n * separator is a character from the string \".,|$#@\" (excluding the quotes)\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def splitWordsBySeparator(self, words: List[str], separator: str) -> List[str]:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"words\": [\"one.two.three\",\"four.five\",\"six\"], \"separator\": \".\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"one\",\"two\",\"three\",\"four\",\"five\",\"six\"]\n\ntest_input = { \"words\": [\"$easy$\",\"$problem$\"], \"separator\": \"$\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"easy\",\"problem\"]\n\ntest_input = { \"words\": [\"|||\"], \"separator\": \"|\" }\nassert my_solution.splitWordsBySeparator(**test_input) == []\n\ntest_input = { \"words\": [\"stars.bars.$\"], \"separator\": \".\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"stars\",\"bars\",\"$\"]\n\ntest_input = { \"words\": [\"###x#i@f\"], \"separator\": \"#\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"x\",\"i@f\"]\n\ntest_input = { \"words\": [\"##q@t#\"], \"separator\": \"#\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"q@t\"]\n\ntest_input = { \"words\": [\"#,\"], \"separator\": \"#\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\",\"]\n\ntest_input = { \"words\": [\"#@\"], \"separator\": \"@\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"#\"]\n\ntest_input = { \"words\": [\"#a$f$nwgq#vw\"], \"separator\": \"$\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"#a\",\"f\",\"nwgq#vw\"]\n\ntest_input = { \"words\": [\"#uyddd,trxiwfv\"], \"separator\": \",\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"#uyddd\",\"trxiwfv\"]\n\ntest_input = { \"words\": [\"#x\"], \"separator\": \"$\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"#x\"]\n\ntest_input = { \"words\": [\"#x#,\"], \"separator\": \",\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"#x#\"]\n\ntest_input = { \"words\": [\"#|\"], \"separator\": \"#\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"|\"]\n\ntest_input = { \"words\": [\"#|a|b|##|#|#g#u|\"], \"separator\": \"|\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"#\",\"a\",\"b\",\"##\",\"#\",\"#g#u\"]\n\ntest_input = { \"words\": [\"$$.o.$$.\"], \"separator\": \"$\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\".o.\",\".\"]\n\ntest_input = { \"words\": [\"$,,\"], \"separator\": \",\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"$\"]\n\ntest_input = { \"words\": [\"$j@@@\"], \"separator\": \"@\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"$j\"]\n\ntest_input = { \"words\": [\",$$\"], \"separator\": \"$\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\",\"]\n\ntest_input = { \"words\": [\",,\"], \"separator\": \"|\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\",,\"]\n\ntest_input = { \"words\": [\",,,@@n\"], \"separator\": \",\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"@@n\"]\n\ntest_input = { \"words\": [\",,,@o,\"], \"separator\": \",\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"@o\"]\n\ntest_input = { \"words\": [\",,,p,#r#\"], \"separator\": \",\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"p\",\"#r#\"]\n\ntest_input = { \"words\": [\",,.\"], \"separator\": \",\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\".\"]\n\ntest_input = { \"words\": [\",,ulxh|,u|ustg||ulo\"], \"separator\": \"|\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\",,ulxh\",\",u\",\"ustg\",\"ulo\"]\n\ntest_input = { \"words\": [\",esplco\"], \"separator\": \".\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\",esplco\"]\n\ntest_input = { \"words\": [\",g#,,,#\"], \"separator\": \",\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"g#\",\"#\"]\n\ntest_input = { \"words\": [\",gko\"], \"separator\": \".\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\",gko\"]\n\ntest_input = { \"words\": [\",h,u.f\"], \"separator\": \",\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"h\",\"u.f\"]\n\ntest_input = { \"words\": [\",y|z|bg,\"], \"separator\": \"|\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\",y\",\"z\",\"bg,\"]\n\ntest_input = { \"words\": [\".#z.###b\"], \"separator\": \"#\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\".\",\"z.\",\"b\"]\n\ntest_input = { \"words\": [\"..\"], \"separator\": \".\" }\nassert my_solution.splitWordsBySeparator(**test_input) == []\n\ntest_input = { \"words\": [\".@\"], \"separator\": \".\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"@\"]\n\ntest_input = { \"words\": [\".n#.#..\"], \"separator\": \"#\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\".n\",\".\",\"..\"]\n\ntest_input = { \"words\": [\".trs.t..cvvw.,..p\"], \"separator\": \".\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"trs\",\"t\",\"cvvw\",\",\",\"p\"]\n\ntest_input = { \"words\": [\".vy.$$.qw\"], \"separator\": \".\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"vy\",\"$$\",\"qw\"]\n\ntest_input = { \"words\": [\"@,,\"], \"separator\": \"@\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\",,\"]\n\ntest_input = { \"words\": [\"@..@@.s.@u@.@\"], \"separator\": \".\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"@\",\"@@\",\"s\",\"@u@\",\"@\"]\n\ntest_input = { \"words\": [\"@@..@@@.@vn@\"], \"separator\": \".\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"@@\",\"@@@\",\"@vn@\"]\n\ntest_input = { \"words\": [\"@@@@@@@...@@@\"], \"separator\": \".\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"@@@@@@@\",\"@@@\"]\n\ntest_input = { \"words\": [\"@@@@@@g@@v\"], \"separator\": \"@\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"g\",\"v\"]\n\ntest_input = { \"words\": [\"@@||@\"], \"separator\": \"|\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"@@\",\"@\"]\n\ntest_input = { \"words\": [\"@acp.@\"], \"separator\": \".\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"@acp\",\"@\"]\n\ntest_input = { \"words\": [\"@iw\"], \"separator\": \"|\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"@iw\"]\n\ntest_input = { \"words\": [\"@z#y@@ni\"], \"separator\": \"#\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"@z\",\"y@@ni\"]\n\ntest_input = { \"words\": [\"aovx\"], \"separator\": \"$\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"aovx\"]\n\ntest_input = { \"words\": [\"b\"], \"separator\": \"|\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"b\"]\n\ntest_input = { \"words\": [\"b,,\"], \"separator\": \".\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"b,,\"]\n\ntest_input = { \"words\": [\"b,s\"], \"separator\": \",\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"b\",\"s\"]\n\ntest_input = { \"words\": [\"bqukl,bv\"], \"separator\": \",\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"bqukl\",\"bv\"]\n\ntest_input = { \"words\": [\"cmypa#\"], \"separator\": \"#\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"cmypa\"]\n\ntest_input = { \"words\": [\"cq,,,,y\"], \"separator\": \"$\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"cq,,,,y\"]\n\ntest_input = { \"words\": [\"d,,,@d\"], \"separator\": \",\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"d\",\"@d\"]\n\ntest_input = { \"words\": [\"dgjtc\"], \"separator\": \".\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"dgjtc\"]\n\ntest_input = { \"words\": [\"e$,$,w$,,z,,$$,\"], \"separator\": \",\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"e$\",\"$\",\"w$\",\"z\",\"$$\"]\n\ntest_input = { \"words\": [\"e,,$,$,,,\"], \"separator\": \",\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"e\",\"$\",\"$\"]\n\ntest_input = { \"words\": [\"edz.\"], \"separator\": \"$\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"edz.\"]\n\ntest_input = { \"words\": [\"f\"], \"separator\": \".\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"f\"]\n\ntest_input = { \"words\": [\"f.\"], \"separator\": \"|\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"f.\"]\n\ntest_input = { \"words\": [\"g\"], \"separator\": \"|\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"g\"]\n\ntest_input = { \"words\": [\"g###\"], \"separator\": \"@\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"g###\"]\n\ntest_input = { \"words\": [\"g|@@@@@|\"], \"separator\": \"@\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"g|\",\"|\"]\n\ntest_input = { \"words\": [\"h\"], \"separator\": \".\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"h\"]\n\ntest_input = { \"words\": [\"h#\"], \"separator\": \"#\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"h\"]\n\ntest_input = { \"words\": [\"hpo\"], \"separator\": \",\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"hpo\"]\n\ntest_input = { \"words\": [\"imq#zect\"], \"separator\": \",\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"imq#zect\"]\n\ntest_input = { \"words\": [\"io@\"], \"separator\": \".\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"io@\"]\n\ntest_input = { \"words\": [\"j@..@f.v@.\"], \"separator\": \"@\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"j\",\"..\",\"f.v\",\".\"]\n\ntest_input = { \"words\": [\"jxe|xfim\"], \"separator\": \"|\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"jxe\",\"xfim\"]\n\ntest_input = { \"words\": [\"lyegjxsg\"], \"separator\": \",\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"lyegjxsg\"]\n\ntest_input = { \"words\": [\"l|\"], \"separator\": \"$\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"l|\"]\n\ntest_input = { \"words\": [\"mm..,.j..\"], \"separator\": \".\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"mm\",\",\",\"j\"]\n\ntest_input = { \"words\": [\"n.\"], \"separator\": \".\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"n\"]\n\ntest_input = { \"words\": [\"no#\"], \"separator\": \",\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"no#\"]\n\ntest_input = { \"words\": [\"nyy|\"], \"separator\": \"|\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"nyy\"]\n\ntest_input = { \"words\": [\"pfx|ons\"], \"separator\": \"@\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"pfx|ons\"]\n\ntest_input = { \"words\": [\"pl\"], \"separator\": \"#\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"pl\"]\n\ntest_input = { \"words\": [\"q\"], \"separator\": \"@\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"q\"]\n\ntest_input = { \"words\": [\"q\"], \"separator\": \"|\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"q\"]\n\ntest_input = { \"words\": [\"qv\"], \"separator\": \"$\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"qv\"]\n\ntest_input = { \"words\": [\"r\"], \"separator\": \"@\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"r\"]\n\ntest_input = { \"words\": [\"rxs|$mg\"], \"separator\": \"$\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"rxs|\",\"mg\"]\n\ntest_input = { \"words\": [\"sls,l,xn\"], \"separator\": \",\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"sls\",\"l\",\"xn\"]\n\ntest_input = { \"words\": [\"t@\"], \"separator\": \"@\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"t\"]\n\ntest_input = { \"words\": [\"tsklm|dhmsr\"], \"separator\": \"|\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"tsklm\",\"dhmsr\"]\n\ntest_input = { \"words\": [\"t|@@w||\"], \"separator\": \"|\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"t\",\"@@w\"]\n\ntest_input = { \"words\": [\"u\"], \"separator\": \"|\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"u\"]\n\ntest_input = { \"words\": [\"ufjvddie\"], \"separator\": \"|\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"ufjvddie\"]\n\ntest_input = { \"words\": [\"unvywqeuqvdq\"], \"separator\": \"$\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"unvywqeuqvdq\"]\n\ntest_input = { \"words\": [\"vt@\"], \"separator\": \"@\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"vt\"]\n\ntest_input = { \"words\": [\"w,xu#v,m,jh,\"], \"separator\": \",\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"w\",\"xu#v\",\"m\",\"jh\"]\n\ntest_input = { \"words\": [\"w|vip|\"], \"separator\": \"|\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"w\",\"vip\"]\n\ntest_input = { \"words\": [\"xjmjh$@\"], \"separator\": \"@\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"xjmjh$\"]\n\ntest_input = { \"words\": [\"xm,tjd$\"], \"separator\": \"$\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"xm,tjd\"]\n\ntest_input = { \"words\": [\"yww\"], \"separator\": \"@\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"yww\"]\n\ntest_input = { \"words\": [\"z\"], \"separator\": \"$\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"z\"]\n\ntest_input = { \"words\": [\"z#|||###\"], \"separator\": \"|\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"z#\",\"###\"]\n\ntest_input = { \"words\": [\"zb@\"], \"separator\": \",\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\"zb@\"]\n\ntest_input = { \"words\": [\"|,,|,|||\"], \"separator\": \"|\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\",,\",\",\"]\n\ntest_input = { \"words\": [\"|,r,fg\"], \"separator\": \"|\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\",r,fg\"]\n\ntest_input = { \"words\": [\"|.\"], \"separator\": \"|\" }\nassert my_solution.splitWordsBySeparator(**test_input) == [\".\"]", "start_time": 1690079400} +{"task_id": "weekly-contest-355-largest-element-in-an-array-after-merge-operations", "url": "https://leetcode.com/problems/largest-element-in-an-array-after-merge-operations", "title": "largest-element-in-an-array-after-merge-operations", "meta": {"questionId": "2872", "questionFrontendId": "2789", "title": "Largest Element in an Array after Merge Operations", "titleSlug": "largest-element-in-an-array-after-merge-operations", "isPaidOnly": false, "difficulty": "Medium", "likes": 413, "dislikes": 26, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed array nums consisting of positive integers.\n\nYou can do the following operation on the array any number of times:\n\n * Choose an integer i such that 0 <= i < nums.length - 1 and nums[i] <= nums[i + 1]. Replace the element nums[i + 1] with nums[i] + nums[i + 1] and delete the element nums[i] from the array.\n\nReturn the value of the largest element that you can possibly obtain in the final array.\n\nExample 1:\n\nInput: nums = [2,3,7,9,3]\nOutput: 21\nExplanation: We can apply the following operations on the array:\n- Choose i = 0. The resulting array will be nums = [5,7,9,3].\n- Choose i = 1. The resulting array will be nums = [5,16,3].\n- Choose i = 0. The resulting array will be nums = [21,3].\nThe largest element in the final array is 21. It can be shown that we cannot obtain a larger element.\n\nExample 2:\n\nInput: nums = [5,3,3]\nOutput: 11\nExplanation: We can do the following operations on the array:\n- Choose i = 1. The resulting array will be nums = [5,6].\n- Choose i = 0. The resulting array will be nums = [11].\nThere is only one element in the final array, which is 11.\n\n\nConstraints:\n\n * 1 <= nums.length <= 105\n * 1 <= nums[i] <= 106\n\"\"\"\nclass Solution:\n def maxArrayValue(self, nums: List[int]) -> int:\n ", "prompt_sft": "You are given a 0-indexed array nums consisting of positive integers.\n\nYou can do the following operation on the array any number of times:\n\n * Choose an integer i such that 0 <= i < nums.length - 1 and nums[i] <= nums[i + 1]. Replace the element nums[i + 1] with nums[i] + nums[i + 1] and delete the element nums[i] from the array.\n\nReturn the value of the largest element that you can possibly obtain in the final array.\n\nExample 1:\n\nInput: nums = [2,3,7,9,3]\nOutput: 21\nExplanation: We can apply the following operations on the array:\n- Choose i = 0. The resulting array will be nums = [5,7,9,3].\n- Choose i = 1. The resulting array will be nums = [5,16,3].\n- Choose i = 0. The resulting array will be nums = [21,3].\nThe largest element in the final array is 21. It can be shown that we cannot obtain a larger element.\n\nExample 2:\n\nInput: nums = [5,3,3]\nOutput: 11\nExplanation: We can do the following operations on the array:\n- Choose i = 1. The resulting array will be nums = [5,6].\n- Choose i = 0. The resulting array will be nums = [11].\nThere is only one element in the final array, which is 11.\n\n\nConstraints:\n\n * 1 <= nums.length <= 105\n * 1 <= nums[i] <= 106\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def maxArrayValue(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [2,3,7,9,3] }\nassert my_solution.maxArrayValue(**test_input) == 21\n\ntest_input = { \"nums\": [5,3,3] }\nassert my_solution.maxArrayValue(**test_input) == 11\n\ntest_input = { \"nums\": [77] }\nassert my_solution.maxArrayValue(**test_input) == 77\n\ntest_input = { \"nums\": [34,95,50,12,25,100,21,3,25,16,76,73,93,46,18] }\nassert my_solution.maxArrayValue(**test_input) == 623\n\ntest_input = { \"nums\": [40,15,35,98,77,79,24,62,53,84,97,16,30,22,49] }\nassert my_solution.maxArrayValue(**test_input) == 781\n\ntest_input = { \"nums\": [64,35,42,19,95,8,83,89,33,21,97,11,51,93,36,34,67,53] }\nassert my_solution.maxArrayValue(**test_input) == 878\n\ntest_input = { \"nums\": [65,68,55,6,79,30,81,25,61,2,28,59,63,15,35,8,10,83] }\nassert my_solution.maxArrayValue(**test_input) == 773\n\ntest_input = { \"nums\": [56] }\nassert my_solution.maxArrayValue(**test_input) == 56\n\ntest_input = { \"nums\": [100] }\nassert my_solution.maxArrayValue(**test_input) == 100\n\ntest_input = { \"nums\": [35,23,71,38] }\nassert my_solution.maxArrayValue(**test_input) == 129\n\ntest_input = { \"nums\": [56,67,18,81,95,41,39,56,63,70,56,31,84,46,28,38,27,56,13,10,58,16,85,21,63,8] }\nassert my_solution.maxArrayValue(**test_input) == 1134\n\ntest_input = { \"nums\": [72,72] }\nassert my_solution.maxArrayValue(**test_input) == 144\n\ntest_input = { \"nums\": [16,31,55] }\nassert my_solution.maxArrayValue(**test_input) == 102\n\ntest_input = { \"nums\": [6,65,68,7,35,19,28] }\nassert my_solution.maxArrayValue(**test_input) == 228\n\ntest_input = { \"nums\": [38,37,88,60,93,4,5,65,74,25,59,28,86,33,28,33,93] }\nassert my_solution.maxArrayValue(**test_input) == 849\n\ntest_input = { \"nums\": [29,9,3,55,25,38,88,39,38,73,47,57,40,56,4,52,1,44,88,20,18,8] }\nassert my_solution.maxArrayValue(**test_input) == 786\n\ntest_input = { \"nums\": [34,92,42,24,98,87,40,82,51,67,70,75,45,57,67] }\nassert my_solution.maxArrayValue(**test_input) == 931\n\ntest_input = { \"nums\": [31,75,44,92,13,10,3,41,47,89,5,92,17,62,65,40,43,68,30,45,85,24,40,77,80,65] }\nassert my_solution.maxArrayValue(**test_input) == 1218\n\ntest_input = { \"nums\": [63,58,61,58,82,48,83,24,24,61,31,16,26,50] }\nassert my_solution.maxArrayValue(**test_input) == 685\n\ntest_input = { \"nums\": [10,82,74,54,20,43,74,95,17,28,44,74,25,19,75,2,84,99] }\nassert my_solution.maxArrayValue(**test_input) == 919\n\ntest_input = { \"nums\": [91,32,21,55,44,29,82,75,66,29,77,62,55,94,49,80,12,46,80,64,88,51,2,24,11,10,86,39,16] }\nassert my_solution.maxArrayValue(**test_input) == 1415\n\ntest_input = { \"nums\": [18,16,56,64,82,25,16,2,19] }\nassert my_solution.maxArrayValue(**test_input) == 236\n\ntest_input = { \"nums\": [29,79,47,55,13,47,48,91,29,28,34,85,98,44,93,56,24,77,61] }\nassert my_solution.maxArrayValue(**test_input) == 977\n\ntest_input = { \"nums\": [74,8,1,57,25,62] }\nassert my_solution.maxArrayValue(**test_input) == 227\n\ntest_input = { \"nums\": [25,36,55,32,15,16,73,67,82,23,17,29,78,34,4,91,1,1,55,65] }\nassert my_solution.maxArrayValue(**test_input) == 799\n\ntest_input = { \"nums\": [6,36,69,97,86,44,27,46] }\nassert my_solution.maxArrayValue(**test_input) == 411\n\ntest_input = { \"nums\": [18,36,100,34,31,89,96,6,73,10,82,20,26,13,24,51,87,70,63,36] }\nassert my_solution.maxArrayValue(**test_input) == 796\n\ntest_input = { \"nums\": [86,57,57,56,38,97,82,48,33,55,19,21,57,85,11,11,71,94,61,41,1,78,39,45] }\nassert my_solution.maxArrayValue(**test_input) == 1243\n\ntest_input = { \"nums\": [33,9,11,6,68,43,76,40,91] }\nassert my_solution.maxArrayValue(**test_input) == 377\n\ntest_input = { \"nums\": [89,45,50,98,23,79,10,98,69,65,47,46,95] }\nassert my_solution.maxArrayValue(**test_input) == 814\n\ntest_input = { \"nums\": [58,95] }\nassert my_solution.maxArrayValue(**test_input) == 153\n\ntest_input = { \"nums\": [91,50] }\nassert my_solution.maxArrayValue(**test_input) == 91\n\ntest_input = { \"nums\": [99,82,49,52,5,69,65,94,94,57,46,26,28,84,42,61,19,87,71,66,1,72] }\nassert my_solution.maxArrayValue(**test_input) == 1269\n\ntest_input = { \"nums\": [75,75,93,44,16,27,43,71,65,90,100,97,39,100,55,15,10,7,25,23,47] }\nassert my_solution.maxArrayValue(**test_input) == 1117\n\ntest_input = { \"nums\": [65] }\nassert my_solution.maxArrayValue(**test_input) == 65\n\ntest_input = { \"nums\": [50] }\nassert my_solution.maxArrayValue(**test_input) == 50\n\ntest_input = { \"nums\": [56,8,10,87,83,79,33,72,32,59,75,2,46,9] }\nassert my_solution.maxArrayValue(**test_input) == 594\n\ntest_input = { \"nums\": [26,77,78,94,90,90,57,100,60,1,98,85,78,77,63,30,88,60,41,55] }\nassert my_solution.maxArrayValue(**test_input) == 1348\n\ntest_input = { \"nums\": [65,53,93,76,75,18,32,88,4] }\nassert my_solution.maxArrayValue(**test_input) == 500\n\ntest_input = { \"nums\": [24,89,92,48,81,49,83,4,53,39,48,10,53,51,41,23,83,8,53,91,43,58,82] }\nassert my_solution.maxArrayValue(**test_input) == 1206\n\ntest_input = { \"nums\": [59,17,33] }\nassert my_solution.maxArrayValue(**test_input) == 59\n\ntest_input = { \"nums\": [15,35,97,93,34,34,90,2,21] }\nassert my_solution.maxArrayValue(**test_input) == 398\n\ntest_input = { \"nums\": [87,64,21,27,41,63,28,75,64,22,30,76,77,91,84,81,99,86,1,74,46,4,7] }\nassert my_solution.maxArrayValue(**test_input) == 1030\n\ntest_input = { \"nums\": [89,49,59,59,2,77,55,44,51,47,100,77,30,71,47,100,13,17,12,38,26,55,89,41] }\nassert my_solution.maxArrayValue(**test_input) == 1207\n\ntest_input = { \"nums\": [71,4,53,51,9,92,91,86,84,58,31,39,38,49,56,27,91,17,10,56,52,78,35,76,39] }\nassert my_solution.maxArrayValue(**test_input) == 1254\n\ntest_input = { \"nums\": [9,46,6,42,81,7,61,88,37,15,20,67] }\nassert my_solution.maxArrayValue(**test_input) == 479\n\ntest_input = { \"nums\": [50,64,31,70,46,30,41,69,80,45,73,4,100,88,7,3,59] }\nassert my_solution.maxArrayValue(**test_input) == 703\n\ntest_input = { \"nums\": [20,41,58,61,79,7,58,42,89,39] }\nassert my_solution.maxArrayValue(**test_input) == 455\n\ntest_input = { \"nums\": [68,86,34,99,4,6,24,88,26,83,2,33,37,79,30,60,56,44,53,4,86,60,13,81,95,28,83,24] }\nassert my_solution.maxArrayValue(**test_input) == 1362\n\ntest_input = { \"nums\": [5,61,59,13,21,90,32,93,84,16,71,78,53,90,5,50,47,85,83,72,88,20,97,28,73,75,59,34,21] }\nassert my_solution.maxArrayValue(**test_input) == 1489\n\ntest_input = { \"nums\": [99,57,14,77,78,88,47,12,45,72,70,73,75,35,50,88,26,38,77,23,86,27,9,16] }\nassert my_solution.maxArrayValue(**test_input) == 1230\n\ntest_input = { \"nums\": [68,65,95,53,51,26,2,3,17,26,15,37,50,79,20,71,99,72,82,37,29,34,74,93] }\nassert my_solution.maxArrayValue(**test_input) == 1198\n\ntest_input = { \"nums\": [68,21,61,74,38,91,99,32,98,12,52] }\nassert my_solution.maxArrayValue(**test_input) == 582\n\ntest_input = { \"nums\": [98,95,15,53,31,15,9,24,59] }\nassert my_solution.maxArrayValue(**test_input) == 399\n\ntest_input = { \"nums\": [51,18,21,99,6,55,41,20,74,43,98,41,58,29,75,16,8,83,23,79,73,68,95,10,67] }\nassert my_solution.maxArrayValue(**test_input) == 1174\n\ntest_input = { \"nums\": [78,91,52,92,42,53,77,88,40,33,86,70,85,50,65,43,75,60,28,97,95,95] }\nassert my_solution.maxArrayValue(**test_input) == 1495\n\ntest_input = { \"nums\": [99,6] }\nassert my_solution.maxArrayValue(**test_input) == 99\n\ntest_input = { \"nums\": [59,50,38,100,42,42,99,7] }\nassert my_solution.maxArrayValue(**test_input) == 430\n\ntest_input = { \"nums\": [35,23,73,45,29,94,1,18,46,7,52,6,47,47,19,93,48,70,85,98,50,89,23] }\nassert my_solution.maxArrayValue(**test_input) == 1075\n\ntest_input = { \"nums\": [2,55,19,10,28,45,86,31,45,32,38,95,65,23,50,39,51,24,40,15,16] }\nassert my_solution.maxArrayValue(**test_input) == 778\n\ntest_input = { \"nums\": [31,59,12,90,39] }\nassert my_solution.maxArrayValue(**test_input) == 192\n\ntest_input = { \"nums\": [53,87,11,58,79,42,44,24,68,61] }\nassert my_solution.maxArrayValue(**test_input) == 466\n\ntest_input = { \"nums\": [20,45] }\nassert my_solution.maxArrayValue(**test_input) == 65\n\ntest_input = { \"nums\": [85,36,99,11,91,88,55,25,68,88,27,98,7,14,40,27,18,51,90,21,77,12,87,11,37,80,70] }\nassert my_solution.maxArrayValue(**test_input) == 1343\n\ntest_input = { \"nums\": [43,50,40,92,31,2,92] }\nassert my_solution.maxArrayValue(**test_input) == 350\n\ntest_input = { \"nums\": [79,90,32,30,33,18,55,96] }\nassert my_solution.maxArrayValue(**test_input) == 433\n\ntest_input = { \"nums\": [65,15,18,94,96,22,37,19,23,11,27,94,5,99] }\nassert my_solution.maxArrayValue(**test_input) == 625\n\ntest_input = { \"nums\": [74,26,11,96,49,19,25,77,47,31,87,96,19,40,95,91,48,79,33,96] }\nassert my_solution.maxArrayValue(**test_input) == 1139\n\ntest_input = { \"nums\": [17,90,66] }\nassert my_solution.maxArrayValue(**test_input) == 107\n\ntest_input = { \"nums\": [60,11,95,75,10,64,62,20] }\nassert my_solution.maxArrayValue(**test_input) == 166\n\ntest_input = { \"nums\": [99,6,67,44,84,29,87,13,44,12,92,53,26,47,88,44,75,33,19] }\nassert my_solution.maxArrayValue(**test_input) == 910\n\ntest_input = { \"nums\": [69,21,11,10,42,3,38,36,50,28,25,93,37,45,73,37,97] }\nassert my_solution.maxArrayValue(**test_input) == 715\n\ntest_input = { \"nums\": [32,76,65,61,84,11,94,96,17,14,79,15,62] }\nassert my_solution.maxArrayValue(**test_input) == 629\n\ntest_input = { \"nums\": [59,91,27,74,57,30,51,67,88,26,89,10,70,31,32,26,42] }\nassert my_solution.maxArrayValue(**test_input) == 870\n\ntest_input = { \"nums\": [8,73,22,37,39,1,66,59,5,20,16,68,55,50,48,6,8,46,93,76,48,14,92] }\nassert my_solution.maxArrayValue(**test_input) == 950\n\ntest_input = { \"nums\": [58,34,72,5,33,34,68,96,63,85,84,74,87,33,75,43,36,28,62,44,95,39,2] }\nassert my_solution.maxArrayValue(**test_input) == 1209\n\ntest_input = { \"nums\": [49,88,44,17,36,65,94,92,75,23,67,55,68,80,95,11,68,66,77,66,3,32,16,81,34,20,56,87,87,29] }\nassert my_solution.maxArrayValue(**test_input) == 1652\n\ntest_input = { \"nums\": [94,27,5,47] }\nassert my_solution.maxArrayValue(**test_input) == 94\n\ntest_input = { \"nums\": [83,85,59,55] }\nassert my_solution.maxArrayValue(**test_input) == 168\n\ntest_input = { \"nums\": [72,56,30,65,94,91,12,99,9] }\nassert my_solution.maxArrayValue(**test_input) == 519\n\ntest_input = { \"nums\": [9,99,20,61,57,88,50,36,21,100,62,98,94,81,96,3,98,37,88] }\nassert my_solution.maxArrayValue(**test_input) == 1198\n\ntest_input = { \"nums\": [45,18,13,66,54,45,64,70,94,67,26,48,84,57,81,85,35,17,20,84,78,24,63,9] }\nassert my_solution.maxArrayValue(**test_input) == 1238\n\ntest_input = { \"nums\": [5,38,82,83,92,97] }\nassert my_solution.maxArrayValue(**test_input) == 397\n\ntest_input = { \"nums\": [95,15,19,26,59,58] }\nassert my_solution.maxArrayValue(**test_input) == 214\n\ntest_input = { \"nums\": [94,75,16,33,2,70,56,4,64] }\nassert my_solution.maxArrayValue(**test_input) == 414\n\ntest_input = { \"nums\": [64,50,26,66] }\nassert my_solution.maxArrayValue(**test_input) == 206\n\ntest_input = { \"nums\": [3,48,11,71,57,72,83,61,59,25,36,29,11,69,75,48,44,44] }\nassert my_solution.maxArrayValue(**test_input) == 846\n\ntest_input = { \"nums\": [88,7,38,15,43,8,87,7,25,2,51,29,74,34,84,87,83,34,74,22,45,96,71,4,23,28,27,68,61] }\nassert my_solution.maxArrayValue(**test_input) == 1254\n\ntest_input = { \"nums\": [30,58,2,20,54] }\nassert my_solution.maxArrayValue(**test_input) == 164\n\ntest_input = { \"nums\": [17,34,71,23,88,84,35,49,89,39,33,13,87,49,48,97] }\nassert my_solution.maxArrayValue(**test_input) == 856\n\ntest_input = { \"nums\": [50,67,98,47,18,91,80,3,19,74,40,89,85,99,95,81,72,96,56,15,48,93,64] }\nassert my_solution.maxArrayValue(**test_input) == 1416\n\ntest_input = { \"nums\": [58,10,99,6,16,94,45,47,4,30,58] }\nassert my_solution.maxArrayValue(**test_input) == 467\n\ntest_input = { \"nums\": [92,58,90,38,37,95,47,82,6,86,99,9,91,80,73,54,45] }\nassert my_solution.maxArrayValue(**test_input) == 830\n\ntest_input = { \"nums\": [31,100,59,88,81,74,49,21,31,53,9,89,67,4,84,46,41] }\nassert my_solution.maxArrayValue(**test_input) == 840\n\ntest_input = { \"nums\": [25,3,94,55,70,23,43,8,65,34,83,60,53,62,97,55,3,10] }\nassert my_solution.maxArrayValue(**test_input) == 775\n\ntest_input = { \"nums\": [27,53,99,55,15,59,85,40,46,45,45,71,42,67] }\nassert my_solution.maxArrayValue(**test_input) == 749\n\ntest_input = { \"nums\": [8,62,12,10,79,36,59,73,76,24,45,98,72,83,61,6,19,49] }\nassert my_solution.maxArrayValue(**test_input) == 872\n\ntest_input = { \"nums\": [2,24,30,18,94,26,22,60,50,3,27,31] }\nassert my_solution.maxArrayValue(**test_input) == 387\n\ntest_input = { \"nums\": [64,17,57,72,24,88,29,2,23,82,15,69,80,93,38,47,9,10,68,89,65,16] }\nassert my_solution.maxArrayValue(**test_input) == 976\n\ntest_input = { \"nums\": [99,58,59,5,67,15,6,91,71,75,79,59,40,1,18,49,48,75,92,72,81,43,31,31,29,94,39] }\nassert my_solution.maxArrayValue(**test_input) == 1388", "start_time": 1690079400} +{"task_id": "weekly-contest-355-maximum-number-of-groups-with-increasing-length", "url": "https://leetcode.com/problems/maximum-number-of-groups-with-increasing-length", "title": "maximum-number-of-groups-with-increasing-length", "meta": {"questionId": "2919", "questionFrontendId": "2790", "title": "Maximum Number of Groups With Increasing Length", "titleSlug": "maximum-number-of-groups-with-increasing-length", "isPaidOnly": false, "difficulty": "Hard", "likes": 383, "dislikes": 38, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed array usageLimits of length n.\n\nYour task is to create groups using numbers from 0 to n - 1, ensuring that each number, i, is used no more than usageLimits[i] times in total across all groups. You must also satisfy the following conditions:\n\n * Each group must consist of distinct numbers, meaning that no duplicate numbers are allowed within a single group.\n * Each group (except the first one) must have a length strictly greater than the previous group.\n\nReturn an integer denoting the maximum number of groups you can create while satisfying these conditions.\n\nExample 1:\n\nInput: usageLimits = [1,2,5]\nOutput: 3\nExplanation: In this example, we can use 0 at most once, 1 at most twice, and 2 at most five times.\nOne way of creating the maximum number of groups while satisfying the conditions is:\nGroup 1 contains the number [2].\nGroup 2 contains the numbers [1,2].\nGroup 3 contains the numbers [0,1,2].\nIt can be shown that the maximum number of groups is 3.\nSo, the output is 3.\n\nExample 2:\n\nInput: usageLimits = [2,1,2]\nOutput: 2\nExplanation: In this example, we can use 0 at most twice, 1 at most once, and 2 at most twice.\nOne way of creating the maximum number of groups while satisfying the conditions is:\nGroup 1 contains the number [0].\nGroup 2 contains the numbers [1,2].\nIt can be shown that the maximum number of groups is 2.\nSo, the output is 2.\n\nExample 3:\n\nInput: usageLimits = [1,1]\nOutput: 1\nExplanation: In this example, we can use both 0 and 1 at most once.\nOne way of creating the maximum number of groups while satisfying the conditions is:\nGroup 1 contains the number [0].\nIt can be shown that the maximum number of groups is 1.\nSo, the output is 1.\n\n\nConstraints:\n\n * 1 <= usageLimits.length <= 105\n * 1 <= usageLimits[i] <= 109\n\"\"\"\nclass Solution:\n def maxIncreasingGroups(self, usageLimits: List[int]) -> int:\n ", "prompt_sft": "You are given a 0-indexed array usageLimits of length n.\n\nYour task is to create groups using numbers from 0 to n - 1, ensuring that each number, i, is used no more than usageLimits[i] times in total across all groups. You must also satisfy the following conditions:\n\n * Each group must consist of distinct numbers, meaning that no duplicate numbers are allowed within a single group.\n * Each group (except the first one) must have a length strictly greater than the previous group.\n\nReturn an integer denoting the maximum number of groups you can create while satisfying these conditions.\n\nExample 1:\n\nInput: usageLimits = [1,2,5]\nOutput: 3\nExplanation: In this example, we can use 0 at most once, 1 at most twice, and 2 at most five times.\nOne way of creating the maximum number of groups while satisfying the conditions is:\nGroup 1 contains the number [2].\nGroup 2 contains the numbers [1,2].\nGroup 3 contains the numbers [0,1,2].\nIt can be shown that the maximum number of groups is 3.\nSo, the output is 3.\n\nExample 2:\n\nInput: usageLimits = [2,1,2]\nOutput: 2\nExplanation: In this example, we can use 0 at most twice, 1 at most once, and 2 at most twice.\nOne way of creating the maximum number of groups while satisfying the conditions is:\nGroup 1 contains the number [0].\nGroup 2 contains the numbers [1,2].\nIt can be shown that the maximum number of groups is 2.\nSo, the output is 2.\n\nExample 3:\n\nInput: usageLimits = [1,1]\nOutput: 1\nExplanation: In this example, we can use both 0 and 1 at most once.\nOne way of creating the maximum number of groups while satisfying the conditions is:\nGroup 1 contains the number [0].\nIt can be shown that the maximum number of groups is 1.\nSo, the output is 1.\n\n\nConstraints:\n\n * 1 <= usageLimits.length <= 105\n * 1 <= usageLimits[i] <= 109\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def maxIncreasingGroups(self, usageLimits: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"usageLimits\": [1,2,5] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [2,1,2] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [1,1] }\nassert my_solution.maxIncreasingGroups(**test_input) == 1\n\ntest_input = { \"usageLimits\": [1,4] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [1,5] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [1,7] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [1,8] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [2,1] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [2,2] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [2,3] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [2,4] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [2,5] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [2,7] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [2,8] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [2,9] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [3,1] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [3,4] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [3,7] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [3,10] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [4,1] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [4,2] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [4,4] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [4,5] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [4,7] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [4,10] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [5,8] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [5,10] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [6,2] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [6,3] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [6,4] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [6,5] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [6,6] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [6,7] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [6,9] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [6,19] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [7,1] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [7,2] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [7,3] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [7,4] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [7,7] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [7,13] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [8,3] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [8,6] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [9,1] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [9,3] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [9,4] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [9,6] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [9,8] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [9,10] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [10,2] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [10,3] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [10,8] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [10,11] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [13,11] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [13,13] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [16,9] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [18,6] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [32,42] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [1,1,5] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [1,1,10] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [1,4,3] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [1,4,5] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [1,6,4] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [1,6,8] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [1,7,19] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [1,8,6] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [1,9,5] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [1,9,6] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [1,10,6] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [2,2,2] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [2,3,8] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [2,6,10] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [2,7,2] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [2,7,7] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [2,8,7] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [2,9,9] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [3,1,1] }\nassert my_solution.maxIncreasingGroups(**test_input) == 2\n\ntest_input = { \"usageLimits\": [3,5,5] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [3,5,8] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [3,6,5] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [3,7,4] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [3,7,10] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [3,8,1] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [3,9,9] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [3,10,9] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [4,2,5] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [4,2,15] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [4,5,5] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [4,7,9] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [4,8,2] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [4,8,4] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [4,10,3] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [4,10,4] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [5,1,5] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [5,2,9] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [5,2,10] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [5,6,1] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [5,6,5] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [5,7,4] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3\n\ntest_input = { \"usageLimits\": [5,10,3] }\nassert my_solution.maxIncreasingGroups(**test_input) == 3", "start_time": 1690079400} +{"task_id": "weekly-contest-355-count-paths-that-can-form-a-palindrome-in-a-tree", "url": "https://leetcode.com/problems/count-paths-that-can-form-a-palindrome-in-a-tree", "title": "count-paths-that-can-form-a-palindrome-in-a-tree", "meta": {"questionId": "2905", "questionFrontendId": "2791", "title": "Count Paths That Can Form a Palindrome in a Tree", "titleSlug": "count-paths-that-can-form-a-palindrome-in-a-tree", "isPaidOnly": false, "difficulty": "Hard", "likes": 343, "dislikes": 4, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a tree (i.e. a connected, undirected graph that has no cycles) rooted at node 0 consisting of n nodes numbered from 0 to n - 1. The tree is represented by a 0-indexed array parent of size n, where parent[i] is the parent of node i. Since node 0 is the root, parent[0] == -1.\n\nYou are also given a string s of length n, where s[i] is the character assigned to the edge between i and parent[i]. s[0] can be ignored.\n\nReturn the number of pairs of nodes (u, v) such that u < v and the characters assigned to edges on the path from u to v can be rearranged to form a palindrome.\n\nA string is a palindrome when it reads the same backwards as forwards.\n\nExample 1:\n\n[https://assets.leetcode.com/uploads/2023/07/15/treedrawio-8drawio.png]\n\nInput: parent = [-1,0,0,1,1,2], s = \"acaabc\"\nOutput: 8\nExplanation: The valid pairs are:\n- All the pairs (0,1), (0,2), (1,3), (1,4) and (2,5) result in one character which is always a palindrome.\n- The pair (2,3) result in the string \"aca\" which is a palindrome.\n- The pair (1,5) result in the string \"cac\" which is a palindrome.\n- The pair (3,5) result in the string \"acac\" which can be rearranged into the palindrome \"acca\".\n\nExample 2:\n\nInput: parent = [-1,0,0,0,0], s = \"aaaaa\"\nOutput: 10\nExplanation: Any pair of nodes (u,v) where u < v is valid.\n\n\nConstraints:\n\n * n == parent.length == s.length\n * 1 <= n <= 105\n * 0 <= parent[i] <= n - 1 for all i >= 1\n * parent[0] == -1\n * parent represents a valid tree.\n * s consists of only lowercase English letters.\n\"\"\"\nclass Solution:\n def countPalindromePaths(self, parent: List[int], s: str) -> int:\n ", "prompt_sft": "You are given a tree (i.e. a connected, undirected graph that has no cycles) rooted at node 0 consisting of n nodes numbered from 0 to n - 1. The tree is represented by a 0-indexed array parent of size n, where parent[i] is the parent of node i. Since node 0 is the root, parent[0] == -1.\n\nYou are also given a string s of length n, where s[i] is the character assigned to the edge between i and parent[i]. s[0] can be ignored.\n\nReturn the number of pairs of nodes (u, v) such that u < v and the characters assigned to edges on the path from u to v can be rearranged to form a palindrome.\n\nA string is a palindrome when it reads the same backwards as forwards.\n\nExample 1:\n\n[https://assets.leetcode.com/uploads/2023/07/15/treedrawio-8drawio.png]\n\nInput: parent = [-1,0,0,1,1,2], s = \"acaabc\"\nOutput: 8\nExplanation: The valid pairs are:\n- All the pairs (0,1), (0,2), (1,3), (1,4) and (2,5) result in one character which is always a palindrome.\n- The pair (2,3) result in the string \"aca\" which is a palindrome.\n- The pair (1,5) result in the string \"cac\" which is a palindrome.\n- The pair (3,5) result in the string \"acac\" which can be rearranged into the palindrome \"acca\".\n\nExample 2:\n\nInput: parent = [-1,0,0,0,0], s = \"aaaaa\"\nOutput: 10\nExplanation: Any pair of nodes (u,v) where u < v is valid.\n\n\nConstraints:\n\n * n == parent.length == s.length\n * 1 <= n <= 105\n * 0 <= parent[i] <= n - 1 for all i >= 1\n * parent[0] == -1\n * parent represents a valid tree.\n * s consists of only lowercase English letters.\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def countPalindromePaths(self, parent: List[int], s: str) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"parent\": [-1,0,0,1,1,2], \"s\": \"acaabc\" }\nassert my_solution.countPalindromePaths(**test_input) == 8\n\ntest_input = { \"parent\": [-1,0,0,0,0], \"s\": \"aaaaa\" }\nassert my_solution.countPalindromePaths(**test_input) == 10\n\ntest_input = { \"parent\": [-1,0], \"s\": \"pi\" }\nassert my_solution.countPalindromePaths(**test_input) == 1\n\ntest_input = { \"parent\": [-1,5,0,5,5,2], \"s\": \"xsbcqq\" }\nassert my_solution.countPalindromePaths(**test_input) == 7\n\ntest_input = { \"parent\": [-1,6,8,5,0,4,2,0,4], \"s\": \"tiaiaivea\" }\nassert my_solution.countPalindromePaths(**test_input) == 20\n\ntest_input = { \"parent\": [-1,0,0,0,1,3,7,2], \"s\": \"pxxgtgpp\" }\nassert my_solution.countPalindromePaths(**test_input) == 18\n\ntest_input = { \"parent\": [-1,0,1,4,1,0], \"s\": \"hfhmmf\" }\nassert my_solution.countPalindromePaths(**test_input) == 12\n\ntest_input = { \"parent\": [-1,0,1], \"s\": \"cri\" }\nassert my_solution.countPalindromePaths(**test_input) == 2\n\ntest_input = { \"parent\": [-1,0,0,5,7,0,0,1,2,0], \"s\": \"snlzlzngna\" }\nassert my_solution.countPalindromePaths(**test_input) == 19\n\ntest_input = { \"parent\": [-1,0,0], \"s\": \"sat\" }\nassert my_solution.countPalindromePaths(**test_input) == 2\n\ntest_input = { \"parent\": [-1,0], \"s\": \"ko\" }\nassert my_solution.countPalindromePaths(**test_input) == 1\n\ntest_input = { \"parent\": [-1,0,6,4,1,6,3,1], \"s\": \"jibwrfoi\" }\nassert my_solution.countPalindromePaths(**test_input) == 8\n\ntest_input = { \"parent\": [-1,4,0,4,6,0,5,5], \"s\": \"bhrlorou\" }\nassert my_solution.countPalindromePaths(**test_input) == 18\n\ntest_input = { \"parent\": [-1,4,4,6,0,7,1,1], \"s\": \"boqvndoo\" }\nassert my_solution.countPalindromePaths(**test_input) == 18\n\ntest_input = { \"parent\": [-1,2,0,1,0], \"s\": \"eixnx\" }\nassert my_solution.countPalindromePaths(**test_input) == 6\n\ntest_input = { \"parent\": [-1,5,0,2,2,3], \"s\": \"jwlllw\" }\nassert my_solution.countPalindromePaths(**test_input) == 14\n\ntest_input = { \"parent\": [-1,2,6,2,5,2,7,0], \"s\": \"pipfippl\" }\nassert my_solution.countPalindromePaths(**test_input) == 15\n\ntest_input = { \"parent\": [-1,6,0,6,5,6,2,6,5,6], \"s\": \"zwrdhnhwtf\" }\nassert my_solution.countPalindromePaths(**test_input) == 11\n\ntest_input = { \"parent\": [-1,4,1,1,5,0], \"s\": \"gndfnj\" }\nassert my_solution.countPalindromePaths(**test_input) == 9\n\ntest_input = { \"parent\": [-1,0,0,0,1], \"s\": \"crwkr\" }\nassert my_solution.countPalindromePaths(**test_input) == 7\n\ntest_input = { \"parent\": [-1,4,4,4,0,2,0], \"s\": \"wwwwewd\" }\nassert my_solution.countPalindromePaths(**test_input) == 13\n\ntest_input = { \"parent\": [-1,2,0], \"s\": \"mwz\" }\nassert my_solution.countPalindromePaths(**test_input) == 2\n\ntest_input = { \"parent\": [-1,0,1,6,5,0,1,1,1,0], \"s\": \"mqgmjzrwuq\" }\nassert my_solution.countPalindromePaths(**test_input) == 14\n\ntest_input = { \"parent\": [-1,2,3,0,3,3,3,3], \"s\": \"bnievjov\" }\nassert my_solution.countPalindromePaths(**test_input) == 8\n\ntest_input = { \"parent\": [-1,0,0], \"s\": \"kyr\" }\nassert my_solution.countPalindromePaths(**test_input) == 2\n\ntest_input = { \"parent\": [-1,0,5,1,2,3,2,3,9,4], \"s\": \"xukzwzsnww\" }\nassert my_solution.countPalindromePaths(**test_input) == 18\n\ntest_input = { \"parent\": [-1,6,0,1,5,0,2,2,6,0], \"s\": \"snlpzocqpt\" }\nassert my_solution.countPalindromePaths(**test_input) == 10\n\ntest_input = { \"parent\": [-1,3,0,5,5,2], \"s\": \"pxlxpl\" }\nassert my_solution.countPalindromePaths(**test_input) == 12\n\ntest_input = { \"parent\": [-1,5,5,5,5,0], \"s\": \"ketewj\" }\nassert my_solution.countPalindromePaths(**test_input) == 6\n\ntest_input = { \"parent\": [-1,0,4,0,0], \"s\": \"zrrqq\" }\nassert my_solution.countPalindromePaths(**test_input) == 7\n\ntest_input = { \"parent\": [-1,0,0], \"s\": \"qlw\" }\nassert my_solution.countPalindromePaths(**test_input) == 2\n\ntest_input = { \"parent\": [-1,0,0], \"s\": \"bds\" }\nassert my_solution.countPalindromePaths(**test_input) == 2\n\ntest_input = { \"parent\": [-1,2,6,6,0,4,4,2], \"s\": \"odggsrsp\" }\nassert my_solution.countPalindromePaths(**test_input) == 13\n\ntest_input = { \"parent\": [-1,0,1], \"s\": \"ldk\" }\nassert my_solution.countPalindromePaths(**test_input) == 2\n\ntest_input = { \"parent\": [-1,0,7,0,6,2,3,3,3], \"s\": \"elllffflv\" }\nassert my_solution.countPalindromePaths(**test_input) == 28\n\ntest_input = { \"parent\": [-1,4,4,0,0], \"s\": \"ntzhc\" }\nassert my_solution.countPalindromePaths(**test_input) == 4\n\ntest_input = { \"parent\": [-1,5,4,1,1,0,4], \"s\": \"gmcmavf\" }\nassert my_solution.countPalindromePaths(**test_input) == 8\n\ntest_input = { \"parent\": [-1,0,0,4,0], \"s\": \"aogkg\" }\nassert my_solution.countPalindromePaths(**test_input) == 6\n\ntest_input = { \"parent\": [-1,2,0], \"s\": \"xmt\" }\nassert my_solution.countPalindromePaths(**test_input) == 2\n\ntest_input = { \"parent\": [-1,2,0], \"s\": \"dff\" }\nassert my_solution.countPalindromePaths(**test_input) == 3\n\ntest_input = { \"parent\": [-1,0,1,1], \"s\": \"lsvw\" }\nassert my_solution.countPalindromePaths(**test_input) == 3\n\ntest_input = { \"parent\": [-1,0,0], \"s\": \"ovi\" }\nassert my_solution.countPalindromePaths(**test_input) == 2\n\ntest_input = { \"parent\": [-1,6,0,5,2,2,0,3], \"s\": \"lpnfznpf\" }\nassert my_solution.countPalindromePaths(**test_input) == 19\n\ntest_input = { \"parent\": [-1,7,5,5,0,0,2,2], \"s\": \"hqitxxwi\" }\nassert my_solution.countPalindromePaths(**test_input) == 16\n\ntest_input = { \"parent\": [-1,2,0], \"s\": \"pyw\" }\nassert my_solution.countPalindromePaths(**test_input) == 2\n\ntest_input = { \"parent\": [-1,0,0,0], \"s\": \"ybfa\" }\nassert my_solution.countPalindromePaths(**test_input) == 3\n\ntest_input = { \"parent\": [-1,3,6,6,6,0,0,4], \"s\": \"ulicllkc\" }\nassert my_solution.countPalindromePaths(**test_input) == 11\n\ntest_input = { \"parent\": [-1,3,1,0], \"s\": \"ukne\" }\nassert my_solution.countPalindromePaths(**test_input) == 3\n\ntest_input = { \"parent\": [-1,2,0,1,0,0], \"s\": \"rhlxdd\" }\nassert my_solution.countPalindromePaths(**test_input) == 6\n\ntest_input = { \"parent\": [-1,4,5,0,2,0], \"s\": \"zenbnb\" }\nassert my_solution.countPalindromePaths(**test_input) == 12\n\ntest_input = { \"parent\": [-1,0,5,4,5,1,3,9,7,4], \"s\": \"jigognjnlb\" }\nassert my_solution.countPalindromePaths(**test_input) == 12\n\ntest_input = { \"parent\": [-1,4,4,6,3,0,5,3,6], \"s\": \"imrcmdkew\" }\nassert my_solution.countPalindromePaths(**test_input) == 11\n\ntest_input = { \"parent\": [-1,4,4,0,6,4,0,0], \"s\": \"dqpipiyz\" }\nassert my_solution.countPalindromePaths(**test_input) == 9\n\ntest_input = { \"parent\": [-1,0,0], \"s\": \"mgm\" }\nassert my_solution.countPalindromePaths(**test_input) == 2\n\ntest_input = { \"parent\": [-1,0,4,0,1], \"s\": \"pzlob\" }\nassert my_solution.countPalindromePaths(**test_input) == 4\n\ntest_input = { \"parent\": [-1,8,0,8,8,3,4,4,0,6], \"s\": \"vvbvyovyvy\" }\nassert my_solution.countPalindromePaths(**test_input) == 30\n\ntest_input = { \"parent\": [-1,0,4,0,5,1,1], \"s\": \"dvrvpea\" }\nassert my_solution.countPalindromePaths(**test_input) == 9\n\ntest_input = { \"parent\": [-1,0,1], \"s\": \"jnx\" }\nassert my_solution.countPalindromePaths(**test_input) == 2\n\ntest_input = { \"parent\": [-1,0,1,2], \"s\": \"wxjj\" }\nassert my_solution.countPalindromePaths(**test_input) == 5\n\ntest_input = { \"parent\": [-1,3,3,0,1,2,1], \"s\": \"erorchx\" }\nassert my_solution.countPalindromePaths(**test_input) == 9\n\ntest_input = { \"parent\": [-1,0,4,1,1,4,3], \"s\": \"ywzwzcw\" }\nassert my_solution.countPalindromePaths(**test_input) == 14\n\ntest_input = { \"parent\": [-1,4,6,2,3,3,0], \"s\": \"bititzq\" }\nassert my_solution.countPalindromePaths(**test_input) == 10\n\ntest_input = { \"parent\": [-1,2,0], \"s\": \"uup\" }\nassert my_solution.countPalindromePaths(**test_input) == 2\n\ntest_input = { \"parent\": [-1,2,3,0,0], \"s\": \"siiou\" }\nassert my_solution.countPalindromePaths(**test_input) == 6\n\ntest_input = { \"parent\": [-1,2,0,2,0], \"s\": \"dilfs\" }\nassert my_solution.countPalindromePaths(**test_input) == 4\n\ntest_input = { \"parent\": [-1,3,7,0,1,0,2,3,0], \"s\": \"wqojvjoqq\" }\nassert my_solution.countPalindromePaths(**test_input) == 22\n\ntest_input = { \"parent\": [-1,0], \"s\": \"hi\" }\nassert my_solution.countPalindromePaths(**test_input) == 1\n\ntest_input = { \"parent\": [-1,3,1,4,0,6,3,1], \"s\": \"fwvwwqqw\" }\nassert my_solution.countPalindromePaths(**test_input) == 21\n\ntest_input = { \"parent\": [-1,0,4,2,1,1,1], \"s\": \"hkmmkmk\" }\nassert my_solution.countPalindromePaths(**test_input) == 16\n\ntest_input = { \"parent\": [-1,4,3,1,0], \"s\": \"bzeez\" }\nassert my_solution.countPalindromePaths(**test_input) == 9\n\ntest_input = { \"parent\": [-1,3,3,0], \"s\": \"zyuj\" }\nassert my_solution.countPalindromePaths(**test_input) == 3\n\ntest_input = { \"parent\": [-1,0,1,4,6,2,2], \"s\": \"tlcpcll\" }\nassert my_solution.countPalindromePaths(**test_input) == 13\n\ntest_input = { \"parent\": [-1,2,0], \"s\": \"vjw\" }\nassert my_solution.countPalindromePaths(**test_input) == 2\n\ntest_input = { \"parent\": [-1,0], \"s\": \"nz\" }\nassert my_solution.countPalindromePaths(**test_input) == 1\n\ntest_input = { \"parent\": [-1,0,0], \"s\": \"iot\" }\nassert my_solution.countPalindromePaths(**test_input) == 2\n\ntest_input = { \"parent\": [-1,2,8,8,3,1,2,0,0], \"s\": \"rlurrluxm\" }\nassert my_solution.countPalindromePaths(**test_input) == 19\n\ntest_input = { \"parent\": [-1,5,0,0,0,4], \"s\": \"zxrddx\" }\nassert my_solution.countPalindromePaths(**test_input) == 10\n\ntest_input = { \"parent\": [-1,0,1,2], \"s\": \"tffc\" }\nassert my_solution.countPalindromePaths(**test_input) == 5\n\ntest_input = { \"parent\": [-1,5,3,0,3,0], \"s\": \"ltdewr\" }\nassert my_solution.countPalindromePaths(**test_input) == 5\n\ntest_input = { \"parent\": [-1,0,4,5,0,1], \"s\": \"gjwwjv\" }\nassert my_solution.countPalindromePaths(**test_input) == 9\n\ntest_input = { \"parent\": [-1,7,7,0,8,2,2,4,3,8], \"s\": \"cnssgsoogy\" }\nassert my_solution.countPalindromePaths(**test_input) == 20\n\ntest_input = { \"parent\": [-1,7,1,6,0,0,7,0], \"s\": \"zaceoxax\" }\nassert my_solution.countPalindromePaths(**test_input) == 13\n\ntest_input = { \"parent\": [-1,0,1,0,3,0], \"s\": \"zrvyyc\" }\nassert my_solution.countPalindromePaths(**test_input) == 8\n\ntest_input = { \"parent\": [-1,4,9,0,3,3,7,4,2,0], \"s\": \"qxixxxxxix\" }\nassert my_solution.countPalindromePaths(**test_input) == 41\n\ntest_input = { \"parent\": [-1,2,0,5,5,2,5], \"s\": \"hoptvuu\" }\nassert my_solution.countPalindromePaths(**test_input) == 9\n\ntest_input = { \"parent\": [-1,7,3,0,3,1,0,3], \"s\": \"kopflpao\" }\nassert my_solution.countPalindromePaths(**test_input) == 13\n\ntest_input = { \"parent\": [-1,0,1,6,1,1,1], \"s\": \"bhhslhl\" }\nassert my_solution.countPalindromePaths(**test_input) == 11\n\ntest_input = { \"parent\": [-1,0,0,1,2], \"s\": \"khhch\" }\nassert my_solution.countPalindromePaths(**test_input) == 8\n\ntest_input = { \"parent\": [-1,0,3,0], \"s\": \"koss\" }\nassert my_solution.countPalindromePaths(**test_input) == 5\n\ntest_input = { \"parent\": [-1,3,4,4,0], \"s\": \"owzoq\" }\nassert my_solution.countPalindromePaths(**test_input) == 4\n\ntest_input = { \"parent\": [-1,2,0,1,1], \"s\": \"zqqww\" }\nassert my_solution.countPalindromePaths(**test_input) == 8\n\ntest_input = { \"parent\": [-1,0,1,1,1,2,2], \"s\": \"lacccdb\" }\nassert my_solution.countPalindromePaths(**test_input) == 13\n\ntest_input = { \"parent\": [-1,4,3,4,6,6,7,0,6], \"s\": \"sjoooorrm\" }\nassert my_solution.countPalindromePaths(**test_input) == 24\n\ntest_input = { \"parent\": [-1,7,4,2,0,6,2,3,7], \"s\": \"guqyxxtau\" }\nassert my_solution.countPalindromePaths(**test_input) == 9\n\ntest_input = { \"parent\": [-1,4,4,0,0], \"s\": \"scicc\" }\nassert my_solution.countPalindromePaths(**test_input) == 8\n\ntest_input = { \"parent\": [-1,5,8,6,3,0,2,3,1], \"s\": \"naphhahhp\" }\nassert my_solution.countPalindromePaths(**test_input) == 29\n\ntest_input = { \"parent\": [-1,3,8,8,5,0,4,0,0,2], \"s\": \"ciiyggofij\" }\nassert my_solution.countPalindromePaths(**test_input) == 23\n\ntest_input = { \"parent\": [-1,2,0,2,2,3,7,8,4,2], \"s\": \"stthtthddt\" }\nassert my_solution.countPalindromePaths(**test_input) == 34\n\ntest_input = { \"parent\": [-1,2,0,7,3,7,4,0], \"s\": \"mjjsjdsj\" }\nassert my_solution.countPalindromePaths(**test_input) == 18\n\ntest_input = { \"parent\": [-1,0], \"s\": \"ey\" }\nassert my_solution.countPalindromePaths(**test_input) == 1", "start_time": 1690079400} +{"task_id": "biweekly-contest-109-check-if-array-is-good", "url": "https://leetcode.com/problems/check-if-array-is-good", "title": "check-if-array-is-good", "meta": {"questionId": "2892", "questionFrontendId": "2784", "title": "Check if Array is Good", "titleSlug": "check-if-array-is-good", "isPaidOnly": false, "difficulty": "Easy", "likes": 233, "dislikes": 43, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given an integer array nums. We consider an array good if it is a permutation of an array base[n].\n\nbase[n] = [1, 2, ..., n - 1, n, n] (in other words, it is an array of length n + 1 which contains 1 to n - 1 exactly once, plus two occurrences of n). For example, base[1] = [1, 1] and base[3] = [1, 2, 3, 3].\n\nReturn true if the given array is good, otherwise return false.\n\nNote: A permutation of integers represents an arrangement of these numbers.\n\nExample 1:\n\nInput: nums = [2, 1, 3]\nOutput: false\nExplanation: Since the maximum element of the array is 3, the only candidate n for which this array could be a permutation of base[n], is n = 3. However, base[3] has four elements but array nums has three. Therefore, it can not be a permutation of base[3] = [1, 2, 3, 3]. So the answer is false.\n\nExample 2:\n\nInput: nums = [1, 3, 3, 2]\nOutput: true\nExplanation: Since the maximum element of the array is 3, the only candidate n for which this array could be a permutation of base[n], is n = 3. It can be seen that nums is a permutation of base[3] = [1, 2, 3, 3] (by swapping the second and fourth elements in nums, we reach base[3]). Therefore, the answer is true.\n\nExample 3:\n\nInput: nums = [1, 1]\nOutput: true\nExplanation: Since the maximum element of the array is 1, the only candidate n for which this array could be a permutation of base[n], is n = 1. It can be seen that nums is a permutation of base[1] = [1, 1]. Therefore, the answer is true.\n\nExample 4:\n\nInput: nums = [3, 4, 4, 1, 2, 1]\nOutput: false\nExplanation: Since the maximum element of the array is 4, the only candidate n for which this array could be a permutation of base[n], is n = 4. However, base[4] has five elements but array nums has six. Therefore, it can not be a permutation of base[4] = [1, 2, 3, 4, 4]. So the answer is false.\n\n\nConstraints:\n\n * 1 <= nums.length <= 100\n * 1 <= num[i] <= 200\n\"\"\"\nclass Solution:\n def isGood(self, nums: List[int]) -> bool:\n ", "prompt_sft": "You are given an integer array nums. We consider an array good if it is a permutation of an array base[n].\n\nbase[n] = [1, 2, ..., n - 1, n, n] (in other words, it is an array of length n + 1 which contains 1 to n - 1 exactly once, plus two occurrences of n). For example, base[1] = [1, 1] and base[3] = [1, 2, 3, 3].\n\nReturn true if the given array is good, otherwise return false.\n\nNote: A permutation of integers represents an arrangement of these numbers.\n\nExample 1:\n\nInput: nums = [2, 1, 3]\nOutput: false\nExplanation: Since the maximum element of the array is 3, the only candidate n for which this array could be a permutation of base[n], is n = 3. However, base[3] has four elements but array nums has three. Therefore, it can not be a permutation of base[3] = [1, 2, 3, 3]. So the answer is false.\n\nExample 2:\n\nInput: nums = [1, 3, 3, 2]\nOutput: true\nExplanation: Since the maximum element of the array is 3, the only candidate n for which this array could be a permutation of base[n], is n = 3. It can be seen that nums is a permutation of base[3] = [1, 2, 3, 3] (by swapping the second and fourth elements in nums, we reach base[3]). Therefore, the answer is true.\n\nExample 3:\n\nInput: nums = [1, 1]\nOutput: true\nExplanation: Since the maximum element of the array is 1, the only candidate n for which this array could be a permutation of base[n], is n = 1. It can be seen that nums is a permutation of base[1] = [1, 1]. Therefore, the answer is true.\n\nExample 4:\n\nInput: nums = [3, 4, 4, 1, 2, 1]\nOutput: false\nExplanation: Since the maximum element of the array is 4, the only candidate n for which this array could be a permutation of base[n], is n = 4. However, base[4] has five elements but array nums has six. Therefore, it can not be a permutation of base[4] = [1, 2, 3, 4, 4]. So the answer is false.\n\n\nConstraints:\n\n * 1 <= nums.length <= 100\n * 1 <= num[i] <= 200\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def isGood(self, nums: List[int]) -> bool:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1, 3, 3, 2] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [2, 1, 3] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [1, 1] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [1, 2, 2] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [3, 4, 4, 1, 2, 1] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [2, 2, 1] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [1] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [2] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [3] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [3, 3, 1, 2] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [1, 3, 4, 4, 2] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [4] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [1, 4, 2, 4, 3] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [5] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [4, 4, 1, 2, 3] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [6] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [4, 4, 2, 3, 1] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [8] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [9] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [5, 5, 1, 3, 2, 4] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [1, 5, 3, 6, 6, 4, 2] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [5, 4, 6, 6, 3, 2, 1] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [10] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [6, 3, 6, 4, 2, 1, 5] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [6, 3, 6, 5, 1, 2, 4] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [12] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [7, 2, 5, 7, 3, 6, 1, 4] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [1, 2, 8, 8, 6, 5, 4, 3, 7] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [1, 8, 4, 8, 2, 7, 6, 3, 5] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [13] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [14] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [2, 8, 6, 1, 7, 5, 3, 4, 8] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [4, 1, 3, 2, 8, 5, 8, 6, 7] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [15] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [7, 2, 1, 5, 6, 8, 8, 4, 3] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [82] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [1, 8] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [8, 6, 2, 5, 7, 4, 1, 8, 3] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [4, 6, 1, 9, 8, 9, 5, 7, 3, 2] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [1, 13] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [2, 3] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [9, 5, 8, 9, 6, 1, 2, 7, 4, 3] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [1, 2, 10, 9, 10, 5, 6, 4, 8, 7, 3] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [1, 9, 2, 6, 5, 4, 7, 10, 3, 10, 8] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [1, 10, 7, 8, 10, 4, 6, 3, 5, 2, 9] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [8, 2, 1, 4, 3, 10, 9, 5, 10, 7, 6] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [10, 9, 5, 3, 6, 4, 2, 10, 8, 7, 1] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [2, 9] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [1, 4, 5, 10, 11, 2, 9, 7, 6, 11, 3, 8] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [2, 11] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [11, 5, 9, 10, 3, 11, 1, 2, 8, 4, 7, 6] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [11, 9, 8, 1, 12, 4, 2, 15, 16, 10, 13, 6, 3, 16, 7, 5, 14] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [11, 16, 9, 5, 14, 13, 4, 1, 3, 16, 15, 8, 10, 7, 12, 2, 6] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [2, 12] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [17, 1, 18, 11, 9, 4, 7, 6, 3, 21, 16, 14, 10, 8, 20, 21, 5, 2, 12, 19, 15, 13] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [3, 1] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [20, 13, 7, 10, 16, 12, 19, 2, 21, 17, 3, 11, 5, 15, 21, 1, 18, 6, 8, 14, 9, 4] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [8, 19, 16, 17, 20, 15, 11, 4, 22, 3, 13, 10, 1, 18, 9, 12, 22, 7, 6, 2, 5, 21, 14] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [22, 1, 17, 13, 8, 22, 9, 5, 21, 6, 14, 12, 10, 11, 2, 18, 4, 7, 19, 20, 3, 15, 16] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [21, 15, 16, 13, 3, 4, 11, 22, 7, 14, 20, 10, 18, 17, 6, 8, 9, 1, 19, 5, 2, 12, 23, 24, 24] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [22, 24, 24, 12, 17, 15, 14, 16, 8, 11, 23, 5, 2, 10, 6, 21, 9, 13, 3, 20, 19, 7, 4, 18, 1] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [3, 2] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [6, 16, 26, 9, 4, 24, 12, 26, 22, 3, 11, 23, 15, 2, 17, 5, 1, 21, 14, 19, 18, 20, 13, 25, 8, 7, 10] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [29, 24, 5, 6, 4, 25, 9, 8, 21, 13, 27, 7, 20, 18, 3, 15, 23, 28, 29, 19, 17, 10, 22, 26, 1, 11, 12, 14, 16, 2] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [25, 21, 6, 10, 20, 15, 16, 26, 7, 3, 30, 1, 12, 29, 11, 30, 14, 19, 2, 28, 23, 9, 8, 24, 17, 5, 4, 27, 22, 18, 13] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [3, 11] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [2, 25, 20, 30, 4, 6, 1, 29, 15, 11, 10, 19, 14, 12, 32, 3, 21, 27, 16, 17, 28, 13, 5, 32, 8, 24, 22, 7, 31, 23, 18, 26, 9] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [4, 10] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [4, 12] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [5, 9] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [5, 12] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [5, 13] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [4, 29, 5, 24, 19, 1, 8, 31, 18, 21, 9, 28, 32, 27, 10, 17, 22, 2, 11, 15, 13, 23, 6, 16, 7, 30, 12, 33, 14, 25, 33, 26, 3, 20] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [6, 1] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [30, 32, 1, 35, 19, 34, 4, 23, 18, 6, 11, 8, 22, 33, 31, 16, 17, 20, 24, 10, 21, 7, 14, 15, 29, 9, 12, 2, 36, 3, 26, 36, 5, 13, 25, 27, 28] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [5, 34, 42, 17, 9, 44, 40, 24, 38, 21, 30, 14, 39, 11, 18, 36, 4, 43, 12, 32, 2, 6, 45, 46, 37, 47, 8, 3, 26, 1, 31, 28, 16, 20, 22, 35, 25, 15, 10, 29, 7, 27, 19, 33, 41, 47, 23, 13] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [6, 7] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [5, 41, 8, 2, 32, 24, 9, 44, 27, 6, 22, 36, 14, 21, 43, 28, 45, 37, 17, 18, 20, 26, 3, 12, 10, 33, 30, 13, 29, 38, 4, 47, 46, 15, 25, 11, 1, 19, 47, 16, 39, 31, 40, 34, 23, 7, 42, 35] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [6, 10] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [6, 12] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [6, 15] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [7, 9] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [8, 4] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [8, 6] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [26, 35, 9, 3, 46, 33, 13, 8, 47, 27, 17, 40, 15, 20, 37, 12, 16, 44, 34, 2, 14, 30, 1, 29, 10, 11, 25, 18, 43, 42, 6, 5, 47, 38, 41, 32, 24, 31, 7, 4, 45, 19, 39, 22, 28, 36, 21, 23] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [8, 9] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [8, 10] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [8, 13] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [32, 39, 25, 49, 6, 48, 9, 7, 34, 3, 8, 26, 14, 27, 43, 30, 1, 21, 36, 10, 31, 38, 40, 12, 2, 46, 20, 15, 11, 24, 22, 28, 33, 4, 19, 18, 44, 41, 35, 29, 16, 37, 45, 47, 49, 23, 42, 13, 5, 17] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [9, 7] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [18, 35, 44, 41, 8, 33, 28, 9, 3, 14, 43, 56, 6, 10, 25, 53, 61, 22, 17, 23, 32, 50, 31, 13, 1, 29, 45, 34, 30, 48, 36, 58, 46, 15, 4, 7, 52, 60, 16, 12, 54, 19, 24, 40, 26, 55, 49, 42, 21, 38, 2, 20, 57, 61, 5, 37, 47, 27, 39, 11, 51, 59] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [9, 9] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [10, 4] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [10, 11] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [11, 1] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [60, 62, 16, 59, 8, 49, 51, 41, 42, 40, 46, 3, 10, 13, 53, 2, 63, 54, 32, 33, 31, 14, 12, 15, 1, 66, 61, 18, 52, 4, 55, 11, 26, 28, 47, 21, 25, 43, 65, 58, 45, 50, 17, 64, 23, 22, 30, 9, 38, 19, 24, 44, 37, 39, 48, 20, 35, 36, 27, 34, 56, 57, 29, 5, 7, 6, 66] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [46, 9, 21, 14, 24, 15, 6, 58, 22, 40, 63, 39, 49, 65, 30, 5, 43, 36, 29, 55, 67, 45, 61, 35, 67, 56, 16, 23, 50, 17, 19, 13, 26, 66, 47, 59, 2, 51, 27, 28, 31, 1, 44, 42, 53, 57, 11, 25, 4, 54, 37, 20, 48, 52, 41, 32, 10, 7, 64, 34, 60, 12, 33, 38, 3, 18, 62, 8] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [11, 5] }\nassert my_solution.isGood(**test_input) == False\n\ntest_input = { \"nums\": [57, 40, 35, 55, 42, 24, 43, 29, 30, 59, 21, 52, 67, 72, 32, 78, 13, 51, 36, 48, 74, 64, 69, 65, 9, 4, 37, 31, 6, 27, 7, 2, 38, 61, 15, 19, 71, 49, 44, 47, 46, 54, 76, 26, 63, 17, 22, 3, 16, 12, 18, 41, 25, 62, 8, 10, 23, 50, 56, 11, 20, 5, 28, 77, 66, 53, 14, 33, 68, 34, 73, 45, 1, 78, 39, 70, 75, 60, 58] }\nassert my_solution.isGood(**test_input) == True\n\ntest_input = { \"nums\": [14, 38, 18, 10, 21, 9, 67, 68, 23, 19, 80, 13, 74, 75, 32, 55, 65, 45, 5, 28, 43, 8, 17, 42, 40, 44, 31, 1, 7, 25, 6, 47, 27, 50, 4, 76, 63, 52, 71, 34, 83, 56, 77, 81, 16, 12, 60, 79, 46, 41, 24, 35, 33, 2, 49, 70, 78, 36, 48, 69, 26, 66, 37, 72, 61, 30, 22, 58, 20, 39, 82, 64, 73, 59, 57, 3, 51, 29, 83, 53, 15, 54, 11, 62] }\nassert my_solution.isGood(**test_input) == True", "start_time": 1690036200} +{"task_id": "biweekly-contest-109-sort-vowels-in-a-string", "url": "https://leetcode.com/problems/sort-vowels-in-a-string", "title": "sort-vowels-in-a-string", "meta": {"questionId": "2887", "questionFrontendId": "2785", "title": "Sort Vowels in a String", "titleSlug": "sort-vowels-in-a-string", "isPaidOnly": false, "difficulty": "Medium", "likes": 883, "dislikes": 50, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nGiven a 0-indexed string s, permute s to get a new string t such that:\n\n * All consonants remain in their original places. More formally, if there is an index i with 0 <= i < s.length such that s[i] is a consonant, then t[i] = s[i].\n * The vowels must be sorted in the nondecreasing order of their ASCII values. More formally, for pairs of indices i, j with 0 <= i < j < s.length such that s[i] and s[j] are vowels, then t[i] must not have a higher ASCII value than t[j].\n\nReturn the resulting string.\n\nThe vowels are 'a', 'e', 'i', 'o', and 'u', and they can appear in lowercase or uppercase. Consonants comprise all letters that are not vowels.\n\nExample 1:\n\nInput: s = \"lEetcOde\"\nOutput: \"lEOtcede\"\nExplanation: 'E', 'O', and 'e' are the vowels in s; 'l', 't', 'c', and 'd' are all consonants. The vowels are sorted according to their ASCII values, and the consonants remain in the same places.\n\nExample 2:\n\nInput: s = \"lYmpH\"\nOutput: \"lYmpH\"\nExplanation: There are no vowels in s (all characters in s are consonants), so we return \"lYmpH\".\n\n\nConstraints:\n\n * 1 <= s.length <= 105\n * s consists only of letters of the English alphabet in uppercase and lowercase.\n\"\"\"\nclass Solution:\n def sortVowels(self, s: str) -> str:\n ", "prompt_sft": "Given a 0-indexed string s, permute s to get a new string t such that:\n\n * All consonants remain in their original places. More formally, if there is an index i with 0 <= i < s.length such that s[i] is a consonant, then t[i] = s[i].\n * The vowels must be sorted in the nondecreasing order of their ASCII values. More formally, for pairs of indices i, j with 0 <= i < j < s.length such that s[i] and s[j] are vowels, then t[i] must not have a higher ASCII value than t[j].\n\nReturn the resulting string.\n\nThe vowels are 'a', 'e', 'i', 'o', and 'u', and they can appear in lowercase or uppercase. Consonants comprise all letters that are not vowels.\n\nExample 1:\n\nInput: s = \"lEetcOde\"\nOutput: \"lEOtcede\"\nExplanation: 'E', 'O', and 'e' are the vowels in s; 'l', 't', 'c', and 'd' are all consonants. The vowels are sorted according to their ASCII values, and the consonants remain in the same places.\n\nExample 2:\n\nInput: s = \"lYmpH\"\nOutput: \"lYmpH\"\nExplanation: There are no vowels in s (all characters in s are consonants), so we return \"lYmpH\".\n\n\nConstraints:\n\n * 1 <= s.length <= 105\n * s consists only of letters of the English alphabet in uppercase and lowercase.\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def sortVowels(self, s: str) -> str:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"s\": \"lEetcOde\" }\nassert my_solution.sortVowels(**test_input) == \"lEOtcede\"\n\ntest_input = { \"s\": \"lYmpH\" }\nassert my_solution.sortVowels(**test_input) == \"lYmpH\"\n\ntest_input = { \"s\": \"mDVD\" }\nassert my_solution.sortVowels(**test_input) == \"mDVD\"\n\ntest_input = { \"s\": \"xdX\" }\nassert my_solution.sortVowels(**test_input) == \"xdX\"\n\ntest_input = { \"s\": \"xdE\" }\nassert my_solution.sortVowels(**test_input) == \"xdE\"\n\ntest_input = { \"s\": \"RiQYo\" }\nassert my_solution.sortVowels(**test_input) == \"RiQYo\"\n\ntest_input = { \"s\": \"LQRamBOHfq\" }\nassert my_solution.sortVowels(**test_input) == \"LQROmBaHfq\"\n\ntest_input = { \"s\": \"UpjPbEnOj\" }\nassert my_solution.sortVowels(**test_input) == \"EpjPbOnUj\"\n\ntest_input = { \"s\": \"ziF\" }\nassert my_solution.sortVowels(**test_input) == \"ziF\"\n\ntest_input = { \"s\": \"WxkKdjhL\" }\nassert my_solution.sortVowels(**test_input) == \"WxkKdjhL\"\n\ntest_input = { \"s\": \"uZcPmqAd\" }\nassert my_solution.sortVowels(**test_input) == \"AZcPmqud\"\n\ntest_input = { \"s\": \"UjshJXjkjS\" }\nassert my_solution.sortVowels(**test_input) == \"UjshJXjkjS\"\n\ntest_input = { \"s\": \"nElwWTQHJ\" }\nassert my_solution.sortVowels(**test_input) == \"nElwWTQHJ\"\n\ntest_input = { \"s\": \"kwcJqvsgM\" }\nassert my_solution.sortVowels(**test_input) == \"kwcJqvsgM\"\n\ntest_input = { \"s\": \"z\" }\nassert my_solution.sortVowels(**test_input) == \"z\"\n\ntest_input = { \"s\": \"Pz\" }\nassert my_solution.sortVowels(**test_input) == \"Pz\"\n\ntest_input = { \"s\": \"T\" }\nassert my_solution.sortVowels(**test_input) == \"T\"\n\ntest_input = { \"s\": \"syRWvFi\" }\nassert my_solution.sortVowels(**test_input) == \"syRWvFi\"\n\ntest_input = { \"s\": \"G\" }\nassert my_solution.sortVowels(**test_input) == \"G\"\n\ntest_input = { \"s\": \"MuQYHVy\" }\nassert my_solution.sortVowels(**test_input) == \"MuQYHVy\"\n\ntest_input = { \"s\": \"gsc\" }\nassert my_solution.sortVowels(**test_input) == \"gsc\"\n\ntest_input = { \"s\": \"nynBd\" }\nassert my_solution.sortVowels(**test_input) == \"nynBd\"\n\ntest_input = { \"s\": \"qUSUCJeJZt\" }\nassert my_solution.sortVowels(**test_input) == \"qUSUCJeJZt\"\n\ntest_input = { \"s\": \"PoEvPD\" }\nassert my_solution.sortVowels(**test_input) == \"PEovPD\"\n\ntest_input = { \"s\": \"SrSuArHDvA\" }\nassert my_solution.sortVowels(**test_input) == \"SrSAArHDvu\"\n\ntest_input = { \"s\": \"zI\" }\nassert my_solution.sortVowels(**test_input) == \"zI\"\n\ntest_input = { \"s\": \"zpVZt\" }\nassert my_solution.sortVowels(**test_input) == \"zpVZt\"\n\ntest_input = { \"s\": \"dZVLG\" }\nassert my_solution.sortVowels(**test_input) == \"dZVLG\"\n\ntest_input = { \"s\": \"EHhQZGJBbp\" }\nassert my_solution.sortVowels(**test_input) == \"EHhQZGJBbp\"\n\ntest_input = { \"s\": \"aPLCji\" }\nassert my_solution.sortVowels(**test_input) == \"aPLCji\"\n\ntest_input = { \"s\": \"HSe\" }\nassert my_solution.sortVowels(**test_input) == \"HSe\"\n\ntest_input = { \"s\": \"HvDMPPU\" }\nassert my_solution.sortVowels(**test_input) == \"HvDMPPU\"\n\ntest_input = { \"s\": \"LYACGrvJLZ\" }\nassert my_solution.sortVowels(**test_input) == \"LYACGrvJLZ\"\n\ntest_input = { \"s\": \"RepLvwHFI\" }\nassert my_solution.sortVowels(**test_input) == \"RIpLvwHFe\"\n\ntest_input = { \"s\": \"vjbObvLfs\" }\nassert my_solution.sortVowels(**test_input) == \"vjbObvLfs\"\n\ntest_input = { \"s\": \"sKQwLo\" }\nassert my_solution.sortVowels(**test_input) == \"sKQwLo\"\n\ntest_input = { \"s\": \"PoqU\" }\nassert my_solution.sortVowels(**test_input) == \"PUqo\"\n\ntest_input = { \"s\": \"QgUxRvJTfH\" }\nassert my_solution.sortVowels(**test_input) == \"QgUxRvJTfH\"\n\ntest_input = { \"s\": \"wUMnwnblpu\" }\nassert my_solution.sortVowels(**test_input) == \"wUMnwnblpu\"\n\ntest_input = { \"s\": \"JpqXrPuMd\" }\nassert my_solution.sortVowels(**test_input) == \"JpqXrPuMd\"\n\ntest_input = { \"s\": \"wdtDPSQdKl\" }\nassert my_solution.sortVowels(**test_input) == \"wdtDPSQdKl\"\n\ntest_input = { \"s\": \"Dl\" }\nassert my_solution.sortVowels(**test_input) == \"Dl\"\n\ntest_input = { \"s\": \"v\" }\nassert my_solution.sortVowels(**test_input) == \"v\"\n\ntest_input = { \"s\": \"axRukCyOHm\" }\nassert my_solution.sortVowels(**test_input) == \"OxRakCyuHm\"\n\ntest_input = { \"s\": \"sQyytiAh\" }\nassert my_solution.sortVowels(**test_input) == \"sQyytAih\"\n\ntest_input = { \"s\": \"ieTwHeOR\" }\nassert my_solution.sortVowels(**test_input) == \"OeTwHeiR\"\n\ntest_input = { \"s\": \"LLxyZ\" }\nassert my_solution.sortVowels(**test_input) == \"LLxyZ\"\n\ntest_input = { \"s\": \"s\" }\nassert my_solution.sortVowels(**test_input) == \"s\"\n\ntest_input = { \"s\": \"oefu\" }\nassert my_solution.sortVowels(**test_input) == \"eofu\"\n\ntest_input = { \"s\": \"XV\" }\nassert my_solution.sortVowels(**test_input) == \"XV\"\n\ntest_input = { \"s\": \"VkfjDpSH\" }\nassert my_solution.sortVowels(**test_input) == \"VkfjDpSH\"\n\ntest_input = { \"s\": \"rg\" }\nassert my_solution.sortVowels(**test_input) == \"rg\"\n\ntest_input = { \"s\": \"ecV\" }\nassert my_solution.sortVowels(**test_input) == \"ecV\"\n\ntest_input = { \"s\": \"RUnxytMua\" }\nassert my_solution.sortVowels(**test_input) == \"RUnxytMau\"\n\ntest_input = { \"s\": \"gUyMeyzOZo\" }\nassert my_solution.sortVowels(**test_input) == \"gOyMUyzeZo\"\n\ntest_input = { \"s\": \"WEir\" }\nassert my_solution.sortVowels(**test_input) == \"WEir\"\n\ntest_input = { \"s\": \"zZWs\" }\nassert my_solution.sortVowels(**test_input) == \"zZWs\"\n\ntest_input = { \"s\": \"WULsDqIhp\" }\nassert my_solution.sortVowels(**test_input) == \"WILsDqUhp\"\n\ntest_input = { \"s\": \"pw\" }\nassert my_solution.sortVowels(**test_input) == \"pw\"\n\ntest_input = { \"s\": \"nOWxdSzo\" }\nassert my_solution.sortVowels(**test_input) == \"nOWxdSzo\"\n\ntest_input = { \"s\": \"NfK\" }\nassert my_solution.sortVowels(**test_input) == \"NfK\"\n\ntest_input = { \"s\": \"wXRFu\" }\nassert my_solution.sortVowels(**test_input) == \"wXRFu\"\n\ntest_input = { \"s\": \"XXtjDoinAD\" }\nassert my_solution.sortVowels(**test_input) == \"XXtjDAinoD\"\n\ntest_input = { \"s\": \"SGUzEv\" }\nassert my_solution.sortVowels(**test_input) == \"SGEzUv\"\n\ntest_input = { \"s\": \"RFOvEt\" }\nassert my_solution.sortVowels(**test_input) == \"RFEvOt\"\n\ntest_input = { \"s\": \"umQePdr\" }\nassert my_solution.sortVowels(**test_input) == \"emQuPdr\"\n\ntest_input = { \"s\": \"wRqZ\" }\nassert my_solution.sortVowels(**test_input) == \"wRqZ\"\n\ntest_input = { \"s\": \"blu\" }\nassert my_solution.sortVowels(**test_input) == \"blu\"\n\ntest_input = { \"s\": \"QeOQEatFaW\" }\nassert my_solution.sortVowels(**test_input) == \"QEOQaatFeW\"\n\ntest_input = { \"s\": \"jzWiXrYa\" }\nassert my_solution.sortVowels(**test_input) == \"jzWaXrYi\"\n\ntest_input = { \"s\": \"xs\" }\nassert my_solution.sortVowels(**test_input) == \"xs\"\n\ntest_input = { \"s\": \"DwROc\" }\nassert my_solution.sortVowels(**test_input) == \"DwROc\"\n\ntest_input = { \"s\": \"XMhLlJd\" }\nassert my_solution.sortVowels(**test_input) == \"XMhLlJd\"\n\ntest_input = { \"s\": \"uAmir\" }\nassert my_solution.sortVowels(**test_input) == \"Aimur\"\n\ntest_input = { \"s\": \"PTlFpeAI\" }\nassert my_solution.sortVowels(**test_input) == \"PTlFpAIe\"\n\ntest_input = { \"s\": \"XLYy\" }\nassert my_solution.sortVowels(**test_input) == \"XLYy\"\n\ntest_input = { \"s\": \"vA\" }\nassert my_solution.sortVowels(**test_input) == \"vA\"\n\ntest_input = { \"s\": \"y\" }\nassert my_solution.sortVowels(**test_input) == \"y\"\n\ntest_input = { \"s\": \"C\" }\nassert my_solution.sortVowels(**test_input) == \"C\"\n\ntest_input = { \"s\": \"wrnMlek\" }\nassert my_solution.sortVowels(**test_input) == \"wrnMlek\"\n\ntest_input = { \"s\": \"JWbfCfGgf\" }\nassert my_solution.sortVowels(**test_input) == \"JWbfCfGgf\"\n\ntest_input = { \"s\": \"OPGlnq\" }\nassert my_solution.sortVowels(**test_input) == \"OPGlnq\"\n\ntest_input = { \"s\": \"DeOMW\" }\nassert my_solution.sortVowels(**test_input) == \"DOeMW\"\n\ntest_input = { \"s\": \"xG\" }\nassert my_solution.sortVowels(**test_input) == \"xG\"\n\ntest_input = { \"s\": \"ZcaBhfkWC\" }\nassert my_solution.sortVowels(**test_input) == \"ZcaBhfkWC\"\n\ntest_input = { \"s\": \"pKa\" }\nassert my_solution.sortVowels(**test_input) == \"pKa\"\n\ntest_input = { \"s\": \"DXSEKrfJCe\" }\nassert my_solution.sortVowels(**test_input) == \"DXSEKrfJCe\"\n\ntest_input = { \"s\": \"xA\" }\nassert my_solution.sortVowels(**test_input) == \"xA\"\n\ntest_input = { \"s\": \"Jb\" }\nassert my_solution.sortVowels(**test_input) == \"Jb\"\n\ntest_input = { \"s\": \"SBQT\" }\nassert my_solution.sortVowels(**test_input) == \"SBQT\"\n\ntest_input = { \"s\": \"LWRfYb\" }\nassert my_solution.sortVowels(**test_input) == \"LWRfYb\"\n\ntest_input = { \"s\": \"tvLWAeGDFK\" }\nassert my_solution.sortVowels(**test_input) == \"tvLWAeGDFK\"\n\ntest_input = { \"s\": \"jFkj\" }\nassert my_solution.sortVowels(**test_input) == \"jFkj\"\n\ntest_input = { \"s\": \"zC\" }\nassert my_solution.sortVowels(**test_input) == \"zC\"\n\ntest_input = { \"s\": \"ikYSsAveh\" }\nassert my_solution.sortVowels(**test_input) == \"AkYSsevih\"\n\ntest_input = { \"s\": \"YXkS\" }\nassert my_solution.sortVowels(**test_input) == \"YXkS\"\n\ntest_input = { \"s\": \"SOEo\" }\nassert my_solution.sortVowels(**test_input) == \"SEOo\"\n\ntest_input = { \"s\": \"qoJx\" }\nassert my_solution.sortVowels(**test_input) == \"qoJx\"\n\ntest_input = { \"s\": \"qGJbgTQ\" }\nassert my_solution.sortVowels(**test_input) == \"qGJbgTQ\"\n\ntest_input = { \"s\": \"yiYYO\" }\nassert my_solution.sortVowels(**test_input) == \"yOYYi\"", "start_time": 1690036200} +{"task_id": "biweekly-contest-109-visit-array-positions-to-maximize-score", "url": "https://leetcode.com/problems/visit-array-positions-to-maximize-score", "title": "visit-array-positions-to-maximize-score", "meta": {"questionId": "2893", "questionFrontendId": "2786", "title": "Visit Array Positions to Maximize Score", "titleSlug": "visit-array-positions-to-maximize-score", "isPaidOnly": false, "difficulty": "Medium", "likes": 438, "dislikes": 21, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed integer array nums and a positive integer x.\n\nYou are initially at position 0 in the array and you can visit other positions according to the following rules:\n\n * If you are currently in position i, then you can move to any position j such that i < j.\n * For each position i that you visit, you get a score of nums[i].\n * If you move from a position i to a position j and the parities of nums[i] and nums[j] differ, then you lose a score of x.\n\nReturn the maximum total score you can get.\n\nNote that initially you have nums[0] points.\n\nExample 1:\n\nInput: nums = [2,3,6,1,9,2], x = 5\nOutput: 13\nExplanation: We can visit the following positions in the array: 0 -> 2 -> 3 -> 4.\nThe corresponding values are 2, 6, 1 and 9. Since the integers 6 and 1 have different parities, the move 2 -> 3 will make you lose a score of x = 5.\nThe total score will be: 2 + 6 + 1 + 9 - 5 = 13.\n\nExample 2:\n\nInput: nums = [2,4,6,8], x = 3\nOutput: 20\nExplanation: All the integers in the array have the same parities, so we can visit all of them without losing any score.\nThe total score is: 2 + 4 + 6 + 8 = 20.\n\n\nConstraints:\n\n * 2 <= nums.length <= 105\n * 1 <= nums[i], x <= 106\n\"\"\"\nclass Solution:\n def maxScore(self, nums: List[int], x: int) -> int:\n ", "prompt_sft": "You are given a 0-indexed integer array nums and a positive integer x.\n\nYou are initially at position 0 in the array and you can visit other positions according to the following rules:\n\n * If you are currently in position i, then you can move to any position j such that i < j.\n * For each position i that you visit, you get a score of nums[i].\n * If you move from a position i to a position j and the parities of nums[i] and nums[j] differ, then you lose a score of x.\n\nReturn the maximum total score you can get.\n\nNote that initially you have nums[0] points.\n\nExample 1:\n\nInput: nums = [2,3,6,1,9,2], x = 5\nOutput: 13\nExplanation: We can visit the following positions in the array: 0 -> 2 -> 3 -> 4.\nThe corresponding values are 2, 6, 1 and 9. Since the integers 6 and 1 have different parities, the move 2 -> 3 will make you lose a score of x = 5.\nThe total score will be: 2 + 6 + 1 + 9 - 5 = 13.\n\nExample 2:\n\nInput: nums = [2,4,6,8], x = 3\nOutput: 20\nExplanation: All the integers in the array have the same parities, so we can visit all of them without losing any score.\nThe total score is: 2 + 4 + 6 + 8 = 20.\n\n\nConstraints:\n\n * 2 <= nums.length <= 105\n * 1 <= nums[i], x <= 106\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def maxScore(self, nums: List[int], x: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [2,3,6,1,9,2], \"x\": 5 }\nassert my_solution.maxScore(**test_input) == 13\n\ntest_input = { \"nums\": [2,4,6,8], \"x\": 3 }\nassert my_solution.maxScore(**test_input) == 20\n\ntest_input = { \"nums\": [38,92,23,30,25,96,6,71,78,77,33,23,71,48,87,77,53,28,6,20,90,83,42,21,64,95,84,29,22,21,33,36,53,51,85,25,80,56,71,69,5,21,4,84,28,16,65,7], \"x\": 52 }\nassert my_solution.maxScore(**test_input) == 1545\n\ntest_input = { \"nums\": [18,13,60,61,57,21,10,98,51,3,13,36,72,70,68,62,52,83,63,63,53,42,59,98,95,48,22,64,94,80,14,14], \"x\": 2 }\nassert my_solution.maxScore(**test_input) == 1633\n\ntest_input = { \"nums\": [90,87,79,59,91,19,96], \"x\": 51 }\nassert my_solution.maxScore(**test_input) == 419\n\ntest_input = { \"nums\": [96,81,48,3,60,78,74,82,14,7,87,72,42,41,80,4,92,82,59,16,19,94,70,45,83,58,2,91,11,96,17,62,79,34,44,47,89,76,85,21,5,57,35,51], \"x\": 24 }\nassert my_solution.maxScore(**test_input) == 1952\n\ntest_input = { \"nums\": [99,88,98,15,34,40,29,81,2,6,12,9,82,93,5,81,84,71,83,31,12,22,9,65,56,9,68,79,39,84,50,7,25,3,49], \"x\": 19 }\nassert my_solution.maxScore(**test_input) == 1363\n\ntest_input = { \"nums\": [8,50,65,85,8,73,55,50,29,95,5,68,52,79], \"x\": 74 }\nassert my_solution.maxScore(**test_input) == 470\n\ntest_input = { \"nums\": [45,9,20,89,18,94,12,51,38,77,100,95,46,1,76,41,8,90,82,33,92,32,76,43,6,61,85,40,63,10,74,18,44,43,17,100,17,33,100,77,97,8,99,85,88,9,63,31,32], \"x\": 68 }\nassert my_solution.maxScore(**test_input) == 1694\n\ntest_input = { \"nums\": [87,23,53,57,21,60,68,84,66,49,48,61,32,95,71,11,15,61,10,86,50,53,38,20,63], \"x\": 92 }\nassert my_solution.maxScore(**test_input) == 814\n\ntest_input = { \"nums\": [39,47,76,64,90,17,30,57,19,40,9,76,68,33,36,61,19,93,8,1,31,2,55,70,24,85,97,40,35,93,56,67,64,67,52,2,75,13,89,97], \"x\": 77 }\nassert my_solution.maxScore(**test_input) == 1390\n\ntest_input = { \"nums\": [92,87,85,27,27,10,24,94,26,78,24,61,4,46,3,76,29,65,52,61,34,67,74,61,90,40,81,60,10,98,87,57,28,77,55,33,10,91,57,72,3,72,4,39,99], \"x\": 70 }\nassert my_solution.maxScore(**test_input) == 1551\n\ntest_input = { \"nums\": [20,90,68], \"x\": 39 }\nassert my_solution.maxScore(**test_input) == 178\n\ntest_input = { \"nums\": [43,100,72,33,45,9,51,10,22,42,7,74,41,68,100,24,20,20,79,30,99,82], \"x\": 1 }\nassert my_solution.maxScore(**test_input) == 1060\n\ntest_input = { \"nums\": [100,87,29,94,56,41,53,98,34,17,52,3,54,51,22,39,37,9,76], \"x\": 40 }\nassert my_solution.maxScore(**test_input) == 670\n\ntest_input = { \"nums\": [55,37,87,45,96,7,66,62,91,51,33,92,65,99], \"x\": 81 }\nassert my_solution.maxScore(**test_input) == 625\n\ntest_input = { \"nums\": [2,75,65,43], \"x\": 39 }\nassert my_solution.maxScore(**test_input) == 146\n\ntest_input = { \"nums\": [74,82,80,95,72,23,49,43,76,28,87,27,58,39,7,77,26,63,56,96,77,75,82,60,90,69,83,20,13,82,16,90,40,23,36,17,77,15,18,10], \"x\": 40 }\nassert my_solution.maxScore(**test_input) == 1571\n\ntest_input = { \"nums\": [75,99,45,34,63,19,71,48,73,66,2,14,76,41,92,23,6,31,49,6,70,40,69,25,97,58,20,84,21,37,100,75,73,10,59,87,30], \"x\": 96 }\nassert my_solution.maxScore(**test_input) == 1181\n\ntest_input = { \"nums\": [9,58,17,54,91,90,32,6,13,67,24,80,8,56,29,66,85,38,45,13,20,73,16,98,28,56,23,2,47,85,11,97,72,2,28,52,33], \"x\": 90 }\nassert my_solution.maxScore(**test_input) == 886\n\ntest_input = { \"nums\": [96,89,30,38,58,26,47,52,27,77,87,92,6], \"x\": 83 }\nassert my_solution.maxScore(**test_input) == 423\n\ntest_input = { \"nums\": [35,11,46,34,57,2,21,98,85,7,65,26,22,14,48,14,38,72,56,63,73,11,70,92,62,3,9,72,32,99,8,71,85,66,73,29,74,88,41,24,21,40,41,19,49,90], \"x\": 11 }\nassert my_solution.maxScore(**test_input) == 1948\n\ntest_input = { \"nums\": [31,17,68,37,56,25,43,71,46,59,6,30,98,69,91], \"x\": 78 }\nassert my_solution.maxScore(**test_input) == 443\n\ntest_input = { \"nums\": [53,49,57,84,69,39,97,78,19,42,10,16,16,62,79,74,49,59,21,29,76,6,14,64,76,29,8,27,26], \"x\": 80 }\nassert my_solution.maxScore(**test_input) == 855\n\ntest_input = { \"nums\": [42,60,23,29,66,46,82,83,97,56,71,39,19,31,23,60,34,63,14,73,4,92,37,65,50,49,100,72,63], \"x\": 88 }\nassert my_solution.maxScore(**test_input) == 943\n\ntest_input = { \"nums\": [79,60,100,62,25,2,86,9,66,67,20,14,92,27,93,52,12,67,9,8,69,21,31,77,71,52,60], \"x\": 84 }\nassert my_solution.maxScore(**test_input) == 906\n\ntest_input = { \"nums\": [40,54,14,66,95,97,3,10,34,100,68,35,54,35,48,3,79,69,71,2,44,82,85,67,47,5,37,61,68,64,61,49,36,87,77,57,69,31,40,45,50,17,2,50,71], \"x\": 69 }\nassert my_solution.maxScore(**test_input) == 1564\n\ntest_input = { \"nums\": [53,15,2,58,28,93,55,41,88,69,93,67,67,40,37,99,17,30,10,7,94,50,73,53,37,84,50,37,81,91,72,28,22,22,67], \"x\": 82 }\nassert my_solution.maxScore(**test_input) == 1165\n\ntest_input = { \"nums\": [41,35,43,93,79,62,66,16,92,29,74,67,93,100,56,73], \"x\": 69 }\nassert my_solution.maxScore(**test_input) == 714\n\ntest_input = { \"nums\": [67,9,2,39,28,92,99,62,37,75,3,53,26,32,76,14,88,16,68,56,60], \"x\": 91 }\nassert my_solution.maxScore(**test_input) == 727\n\ntest_input = { \"nums\": [95,29,91,86,23,30,46,95,6,84,62,23,71,6,13,19,25,65,29,6,65,92], \"x\": 28 }\nassert my_solution.maxScore(**test_input) == 886\n\ntest_input = { \"nums\": [74,47,86,24,44,91,88,64,37], \"x\": 24 }\nassert my_solution.maxScore(**test_input) == 436\n\ntest_input = { \"nums\": [36,62,82,46,40], \"x\": 54 }\nassert my_solution.maxScore(**test_input) == 266\n\ntest_input = { \"nums\": [66,28,100,33,15,47,80,43,61,16,10], \"x\": 3 }\nassert my_solution.maxScore(**test_input) == 487\n\ntest_input = { \"nums\": [62,1,66,47,85,69,35,42,42,7,20,91], \"x\": 41 }\nassert my_solution.maxScore(**test_input) == 436\n\ntest_input = { \"nums\": [8,23,19,37,12,78,25,62,99,88,86,27,1,78,40,57,5,62,12,93,10,42], \"x\": 60 }\nassert my_solution.maxScore(**test_input) == 578\n\ntest_input = { \"nums\": [35,49,85,37,74,50,77,21,68,49,86,92,36,31,70,66,10,75,6,70,55,72,40,99,24,74,55,46,4,46,22,36,58,36,68,68,54,9,36,76,57,83,86,92,6,47,44,31], \"x\": 55 }\nassert my_solution.maxScore(**test_input) == 1797\n\ntest_input = { \"nums\": [75,96,53,79,89,57,75,94,24,75,71,8,44,70,12,92,38,24,3,38,88,10], \"x\": 31 }\nassert my_solution.maxScore(**test_input) == 1057\n\ntest_input = { \"nums\": [93,68,62,23,56,95,7,38,43,87,76,60,34,32,40,4,49,15,41,18,76,50], \"x\": 46 }\nassert my_solution.maxScore(**test_input) == 776\n\ntest_input = { \"nums\": [53,78,79,81,75,36,35,37], \"x\": 61 }\nassert my_solution.maxScore(**test_input) == 360\n\ntest_input = { \"nums\": [60,55,100,61,23,45,43,31], \"x\": 62 }\nassert my_solution.maxScore(**test_input) == 301\n\ntest_input = { \"nums\": [98,48,29,44,96,57], \"x\": 40 }\nassert my_solution.maxScore(**test_input) == 303\n\ntest_input = { \"nums\": [96,18,77,100,88,19,41,32,15,41,14], \"x\": 30 }\nassert my_solution.maxScore(**test_input) == 405\n\ntest_input = { \"nums\": [46,69,20,84,52,23,13,52,68,49,99,23,14,60,56,71,68,43,44,66,96,58,94], \"x\": 6 }\nassert my_solution.maxScore(**test_input) == 1208\n\ntest_input = { \"nums\": [85,12], \"x\": 79 }\nassert my_solution.maxScore(**test_input) == 85\n\ntest_input = { \"nums\": [63,95,35,79,39,14,55,5,44,57,31,23,67,61,75,61,40,51,55,27,53,100,15,100,23,89,76,99,31,47,49,52,47], \"x\": 49 }\nassert my_solution.maxScore(**test_input) == 1419\n\ntest_input = { \"nums\": [60,94,97,97,57,16,45,84,10,44,16], \"x\": 10 }\nassert my_solution.maxScore(**test_input) == 584\n\ntest_input = { \"nums\": [24,28,63,5,13,83,2,15,81,34,9,10,54,88,12,36,81,87,81,42,56,82,85,85,31,47,29,59,21,55,73,31,80,75,61,70,82,90,23,44,71,94], \"x\": 57 }\nassert my_solution.maxScore(**test_input) == 1665\n\ntest_input = { \"nums\": [92,7,95,1,79,49,58,77,54,12,38,18,9,23,75,98,76,86,40,33,22,14,62,67,60,36,67,51,85,100,75,30,55,63,28,100,94,4], \"x\": 89 }\nassert my_solution.maxScore(**test_input) == 1282\n\ntest_input = { \"nums\": [76,24,85,30,37,86,3,50,94,19,48,95,31], \"x\": 93 }\nassert my_solution.maxScore(**test_input) == 441\n\ntest_input = { \"nums\": [50,19,12,63,20,33,21,77,25,24,46,22,46,57,86,65,13,99,36,23,85,99,10], \"x\": 7 }\nassert my_solution.maxScore(**test_input) == 949\n\ntest_input = { \"nums\": [68,26,50,20,54,30,12,66,30,75,31,89,78,30,17,38,97,15,43,39,82,25,3,78,66,6,68,86,29,20,99], \"x\": 97 }\nassert my_solution.maxScore(**test_input) == 985\n\ntest_input = { \"nums\": [62,1,18,37,87,73,16], \"x\": 44 }\nassert my_solution.maxScore(**test_input) == 233\n\ntest_input = { \"nums\": [35,60,95,31,19,87,19,37,78,82,81,96,23,58,93,96,92,41,48,67,90,70,6,97,6,2,77,47,34,17,51,15,13,93,12,46], \"x\": 1 }\nassert my_solution.maxScore(**test_input) == 1895\n\ntest_input = { \"nums\": [21,29], \"x\": 68 }\nassert my_solution.maxScore(**test_input) == 50\n\ntest_input = { \"nums\": [37,98,2,60,89,82,99,80,28,54,12,15,16,88,82,72,63,8,45,56,99,19,29,38,26,35], \"x\": 94 }\nassert my_solution.maxScore(**test_input) == 813\n\ntest_input = { \"nums\": [84,8,44,48,85,77,18,34,17,46,53,84,52,77,12,94,18,67,46,45], \"x\": 44 }\nassert my_solution.maxScore(**test_input) == 684\n\ntest_input = { \"nums\": [50,1,21,95,20,65,80,75,47,74,95,23,89,61,48,25,84,76,81,51,52,37,84,24,15,32,11,88], \"x\": 65 }\nassert my_solution.maxScore(**test_input) == 982\n\ntest_input = { \"nums\": [54,2,22,17,41,23,51,16,5,42,12,77,9,71,92,87,78,50,14,74,72,42,90], \"x\": 52 }\nassert my_solution.maxScore(**test_input) == 780\n\ntest_input = { \"nums\": [3,34,22,49,66,40,13,7,71,35,1,96,36,83,31,55,60,20,90,76,51,95,21,47,82,91,75,99,72,48,53,2,56,64], \"x\": 70 }\nassert my_solution.maxScore(**test_input) == 1105\n\ntest_input = { \"nums\": [75,34,33,97,3,25,4,71,8,73], \"x\": 27 }\nassert my_solution.maxScore(**test_input) == 377\n\ntest_input = { \"nums\": [27,91,78,7,48,79,23,34,17,42,94,85,48,36,26,57,53,10,38,32,45,89,74,5,35,39,9,59,71,39,1,60,39,50,47,47,48,74,71,91,85,86,22], \"x\": 74 }\nassert my_solution.maxScore(**test_input) == 1292\n\ntest_input = { \"nums\": [26,97,16,94,49,98,78,84,76,21,75,88,22,49,34,98,7,94,100,98,72,70,47,6,56,8,50,9,37,37,34,36,48,95,8,63,35,81,26,57,91,4,83,38,64,45,98,51], \"x\": 86 }\nassert my_solution.maxScore(**test_input) == 1919\n\ntest_input = { \"nums\": [14,64,4,14,94,58,67,15,79,26,66,34,47,42,20,67,5,21,63,73,44,96,29,72,26,20,84,84,62,39,93,53,13,35,32,82,22,58], \"x\": 87 }\nassert my_solution.maxScore(**test_input) == 1252\n\ntest_input = { \"nums\": [42,98,75,46,10,21,10,35,4,59,100,78,62,51,84,99,92,2,4,12,59,8,42,85,86,81,20,1,43,41,56,2,30,25,21,56,43,82,38,45,89,54,15,63,69,20,64], \"x\": 45 }\nassert my_solution.maxScore(**test_input) == 1442\n\ntest_input = { \"nums\": [99,80,22,56,93,18,65,63,8,16,80], \"x\": 39 }\nassert my_solution.maxScore(**test_input) == 465\n\ntest_input = { \"nums\": [2,17,64,100,23,2,8,93,31,6,16,28,32,98,18,33,22,54,73,35,47,16,76,74,17,5,6,1,7,19,100,17,70,98,94,5,78,38,10,80], \"x\": 59 }\nassert my_solution.maxScore(**test_input) == 1246\n\ntest_input = { \"nums\": [15,10,55,18,55,54,63,79,97,9,98,10,95,3,88,43,75,17,19,36,64,44,85,10,45,42,58,75,79,7,55,75,50,89,8,89,58,87,30,36,59,59,25], \"x\": 4 }\nassert my_solution.maxScore(**test_input) == 2072\n\ntest_input = { \"nums\": [97,60,79,8,79,39,37,66,78,58,32,59,83,23,36,82,34,70,17,17,33,91,1,55,54,45,30,11,30,19,8,8,98,36,39,30,87,34,99,83,6,90], \"x\": 91 }\nassert my_solution.maxScore(**test_input) == 1214\n\ntest_input = { \"nums\": [52,83,17,67,51,47,8,86,59,56,96,74,36,38,73,96,95,50,25,45,5,48,16,3,65,22,92,11,80,46,15], \"x\": 4 }\nassert my_solution.maxScore(**test_input) == 1497\n\ntest_input = { \"nums\": [38,97,36,48,88,68,66,39,40,36,39,53,96,21,3,28,86,94,31,53,76,24,54,45,10,99,92,21,52,25,15,42,12,17,89,51], \"x\": 14 }\nassert my_solution.maxScore(**test_input) == 1547\n\ntest_input = { \"nums\": [6,13,9], \"x\": 98 }\nassert my_solution.maxScore(**test_input) == 6\n\ntest_input = { \"nums\": [52,66,40,14,6,26,37,93,23,2,40,10,42,1,85,22,45,46,16,14,70,76,48,100,68,85,72,31,15,56,65,61,83,90,31,31,2,27,55,91,50,32], \"x\": 18 }\nassert my_solution.maxScore(**test_input) == 1679\n\ntest_input = { \"nums\": [8,60,58], \"x\": 18 }\nassert my_solution.maxScore(**test_input) == 126\n\ntest_input = { \"nums\": [74,24,7,80,13,46,52,19,20,6,70,95,20,82,97,32,28,16,4,21,19,56,9,56,30,99,64,94,61,5,28,51,58,49,49,92,68,66,17,84,54], \"x\": 51 }\nassert my_solution.maxScore(**test_input) == 1331\n\ntest_input = { \"nums\": [99,30,17,54,77,71,48,19,80,43,20,59,95,76,64,32,29,84,80,33,90,11,76,65,76,51,50,36,99], \"x\": 6 }\nassert my_solution.maxScore(**test_input) == 1533\n\ntest_input = { \"nums\": [21,99,29,76,1,25,62,67,82,90,99,12,51,53,62,78,41,14,55,66,90,73,30,76,97], \"x\": 60 }\nassert my_solution.maxScore(**test_input) == 935\n\ntest_input = { \"nums\": [59,78,89,17,43,89,21,43,73,76,68,94,69,76,26,3,86,65,45,29,68,53,41,87,79,37,11,55,82,97,9,48,64,13,56,56,60,22,22,50,23,51,14,36,2], \"x\": 81 }\nassert my_solution.maxScore(**test_input) == 1655\n\ntest_input = { \"nums\": [5,2,24,57,9,5,71,90,20,80,9,99,45,27,60,7,65,23,55,46,49,57,7,22,28,35], \"x\": 77 }\nassert my_solution.maxScore(**test_input) == 661\n\ntest_input = { \"nums\": [76,60,37,9,31,30,86,64,83,71,70,18,32,74,38,11,6,4,9,62,52,14,20,41,60,54,40,15,90,52,27,46,47,1,7,79,22,49,99,82], \"x\": 100 }\nassert my_solution.maxScore(**test_input) == 1230\n\ntest_input = { \"nums\": [20,89,67,20,1,84,36,92,41,79,35,85,58,76,42,12,96,38,44,93,54,80,44,49,55,6,34,84,3,74,13], \"x\": 23 }\nassert my_solution.maxScore(**test_input) == 1403\n\ntest_input = { \"nums\": [69,86,56,72,35,8,57,10,42,90,92,46,7,22,69,16,62,9,57,74,52,49,14,23,13,43,73,63,88,18,31,89,94,3,23,14,39,82,70,78], \"x\": 95 }\nassert my_solution.maxScore(**test_input) == 1234\n\ntest_input = { \"nums\": [28,66,78,21,47,6,18,60,8,82,34,19,62,26,34,56,59,56,7,75,35,42,19,23,92,88,83,65,74,24,69,83,12,63,4,71,78,40,64,98,15,17,81,19], \"x\": 84 }\nassert my_solution.maxScore(**test_input) == 1430\n\ntest_input = { \"nums\": [77,48,31,26], \"x\": 53 }\nassert my_solution.maxScore(**test_input) == 108\n\ntest_input = { \"nums\": [33,69,10,90,86,82,66,19,28,33,9,98,87,7,7,17,69,79,85,65,31,38,75], \"x\": 21 }\nassert my_solution.maxScore(**test_input) == 1042\n\ntest_input = { \"nums\": [16,99,70,71,62,42], \"x\": 83 }\nassert my_solution.maxScore(**test_input) == 190\n\ntest_input = { \"nums\": [55,64,59,68,50,32,56,75,84,53,97,7,40,62,56,80,36,52,43,77,82,47,7,96,94,43,77,71,36,92], \"x\": 48 }\nassert my_solution.maxScore(**test_input) == 1267\n\ntest_input = { \"nums\": [61,12,92,54,88,10,49,19,83,24,82,29,64,96,67,12,27,97,15,96,35,43,92,96,28,84,49,72,16,92,29,41], \"x\": 73 }\nassert my_solution.maxScore(**test_input) == 1151\n\ntest_input = { \"nums\": [90,84,13,56,24,54,29,20], \"x\": 31 }\nassert my_solution.maxScore(**test_input) == 328\n\ntest_input = { \"nums\": [94,12,26,83,92,8,64,21,80,32,47,71,30], \"x\": 66 }\nassert my_solution.maxScore(**test_input) == 460\n\ntest_input = { \"nums\": [42,11,1], \"x\": 16 }\nassert my_solution.maxScore(**test_input) == 42\n\ntest_input = { \"nums\": [22,56,65,84,34,80,56,63,22,52,94,29,99,45,20,66,50,62,44,10,3,70,13,23,99,99,71,61,11,28,48,66,41,4,5,18,22,44,36,92,10,90,20], \"x\": 36 }\nassert my_solution.maxScore(**test_input) == 1706\n\ntest_input = { \"nums\": [6,45,84,69,49,47,49,13,6,25,82,38,1,4,99,68,89,78,53,29,73,96,71,58,88,18,97,61,37,80,20,93,77,38,84], \"x\": 40 }\nassert my_solution.maxScore(**test_input) == 1336\n\ntest_input = { \"nums\": [85,71,5,91,31,75,36,4,42,81,92,42,40,14,57,72,33,66,4,1,26,81,45,56,64,76,43,39,53,9,37,38,53,26,2,55,6,70,9,45,35,60,73,38,62,58,3], \"x\": 86 }\nassert my_solution.maxScore(**test_input) == 1343\n\ntest_input = { \"nums\": [32,53,27,49,7,40,22,85,53,46,28,95,59,85,78,16,15,63,24,64,90,9,84,9,66,41,75,8,22,53,72,29,15,32,49,29,37,66,82,63,59,58], \"x\": 70 }\nassert my_solution.maxScore(**test_input) == 1221\n\ntest_input = { \"nums\": [76,100,47,98,31,46,73,18,40,46,4,70,33,43,58,21,72,24,97,17,18,61,86,9,8,96,54,55], \"x\": 43 }\nassert my_solution.maxScore(**test_input) == 997\n\ntest_input = { \"nums\": [78,66,10,19,59,87,27,40,49,80,25,3,33,54,29,97,9,36,73,80,59,68], \"x\": 97 }\nassert my_solution.maxScore(**test_input) == 626\n\ntest_input = { \"nums\": [13,26,3,19,21,43,33,62,32,61,40,22,56,69,15,21,10,87,84,66,26,35,54,64,7,53,32,14,7], \"x\": 76 }\nassert my_solution.maxScore(**test_input) == 649\n\ntest_input = { \"nums\": [73,93,27,67,11,40,18,88,78,77,79,80,15,100,83,33,36,63,90,44,89,23,25,79,56,41,8,62,32,98,58], \"x\": 10 }\nassert my_solution.maxScore(**test_input) == 1641\n\ntest_input = { \"nums\": [38,97,76,72,85,23,70,90,89,1,65,50,1,93,41,33,94,43,45,39,98,52,85,18,70,79,79,33,22,93,72,25,20,42,19,66,64,64,95,29,3,75,54,40,17,86,71,23,26,23], \"x\": 66 }\nassert my_solution.maxScore(**test_input) == 1683", "start_time": 1690036200} +{"task_id": "biweekly-contest-109-ways-to-express-an-integer-as-sum-of-powers", "url": "https://leetcode.com/problems/ways-to-express-an-integer-as-sum-of-powers", "title": "ways-to-express-an-integer-as-sum-of-powers", "meta": {"questionId": "2882", "questionFrontendId": "2787", "title": "Ways to Express an Integer as Sum of Powers", "titleSlug": "ways-to-express-an-integer-as-sum-of-powers", "isPaidOnly": false, "difficulty": "Medium", "likes": 346, "dislikes": 11, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nGiven two positive integers n and x.\n\nReturn the number of ways n can be expressed as the sum of the xth power of unique positive integers, in other words, the number of sets of unique integers [n1, n2, ..., nk] where n = n1x + n2x + ... + nkx.\n\nSince the result can be very large, return it modulo 109 + 7.\n\nFor example, if n = 160 and x = 3, one way to express n is n = 23 + 33 + 53.\n\nExample 1:\n\nInput: n = 10, x = 2\nOutput: 1\nExplanation: We can express n as the following: n = 32 + 12 = 10.\nIt can be shown that it is the only way to express 10 as the sum of the 2nd power of unique integers.\n\nExample 2:\n\nInput: n = 4, x = 1\nOutput: 2\nExplanation: We can express n in the following ways:\n- n = 41 = 4.\n- n = 31 + 11 = 4.\n\n\nConstraints:\n\n * 1 <= n <= 300\n * 1 <= x <= 5\n\"\"\"\nclass Solution:\n def numberOfWays(self, n: int, x: int) -> int:\n ", "prompt_sft": "Given two positive integers n and x.\n\nReturn the number of ways n can be expressed as the sum of the xth power of unique positive integers, in other words, the number of sets of unique integers [n1, n2, ..., nk] where n = n1x + n2x + ... + nkx.\n\nSince the result can be very large, return it modulo 109 + 7.\n\nFor example, if n = 160 and x = 3, one way to express n is n = 23 + 33 + 53.\n\nExample 1:\n\nInput: n = 10, x = 2\nOutput: 1\nExplanation: We can express n as the following: n = 32 + 12 = 10.\nIt can be shown that it is the only way to express 10 as the sum of the 2nd power of unique integers.\n\nExample 2:\n\nInput: n = 4, x = 1\nOutput: 2\nExplanation: We can express n in the following ways:\n- n = 41 = 4.\n- n = 31 + 11 = 4.\n\n\nConstraints:\n\n * 1 <= n <= 300\n * 1 <= x <= 5\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def numberOfWays(self, n: int, x: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"n\": 10, \"x\": 2 }\nassert my_solution.numberOfWays(**test_input) == 1\n\ntest_input = { \"n\": 4, \"x\": 1 }\nassert my_solution.numberOfWays(**test_input) == 2\n\ntest_input = { \"n\": 1, \"x\": 1 }\nassert my_solution.numberOfWays(**test_input) == 1\n\ntest_input = { \"n\": 1, \"x\": 2 }\nassert my_solution.numberOfWays(**test_input) == 1\n\ntest_input = { \"n\": 1, \"x\": 3 }\nassert my_solution.numberOfWays(**test_input) == 1\n\ntest_input = { \"n\": 1, \"x\": 4 }\nassert my_solution.numberOfWays(**test_input) == 1\n\ntest_input = { \"n\": 1, \"x\": 5 }\nassert my_solution.numberOfWays(**test_input) == 1\n\ntest_input = { \"n\": 2, \"x\": 1 }\nassert my_solution.numberOfWays(**test_input) == 1\n\ntest_input = { \"n\": 2, \"x\": 2 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 2, \"x\": 3 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 2, \"x\": 4 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 2, \"x\": 5 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 3, \"x\": 1 }\nassert my_solution.numberOfWays(**test_input) == 2\n\ntest_input = { \"n\": 3, \"x\": 2 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 3, \"x\": 3 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 3, \"x\": 4 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 3, \"x\": 5 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 4, \"x\": 2 }\nassert my_solution.numberOfWays(**test_input) == 1\n\ntest_input = { \"n\": 4, \"x\": 3 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 4, \"x\": 4 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 4, \"x\": 5 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 5, \"x\": 1 }\nassert my_solution.numberOfWays(**test_input) == 3\n\ntest_input = { \"n\": 5, \"x\": 2 }\nassert my_solution.numberOfWays(**test_input) == 1\n\ntest_input = { \"n\": 5, \"x\": 3 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 5, \"x\": 4 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 5, \"x\": 5 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 6, \"x\": 1 }\nassert my_solution.numberOfWays(**test_input) == 4\n\ntest_input = { \"n\": 6, \"x\": 2 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 6, \"x\": 3 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 6, \"x\": 4 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 6, \"x\": 5 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 7, \"x\": 1 }\nassert my_solution.numberOfWays(**test_input) == 5\n\ntest_input = { \"n\": 7, \"x\": 2 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 7, \"x\": 3 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 7, \"x\": 4 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 7, \"x\": 5 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 8, \"x\": 1 }\nassert my_solution.numberOfWays(**test_input) == 6\n\ntest_input = { \"n\": 8, \"x\": 2 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 8, \"x\": 3 }\nassert my_solution.numberOfWays(**test_input) == 1\n\ntest_input = { \"n\": 8, \"x\": 4 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 8, \"x\": 5 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 9, \"x\": 1 }\nassert my_solution.numberOfWays(**test_input) == 8\n\ntest_input = { \"n\": 9, \"x\": 2 }\nassert my_solution.numberOfWays(**test_input) == 1\n\ntest_input = { \"n\": 9, \"x\": 3 }\nassert my_solution.numberOfWays(**test_input) == 1\n\ntest_input = { \"n\": 9, \"x\": 4 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 9, \"x\": 5 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 10, \"x\": 1 }\nassert my_solution.numberOfWays(**test_input) == 10\n\ntest_input = { \"n\": 10, \"x\": 3 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 10, \"x\": 4 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 10, \"x\": 5 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 11, \"x\": 1 }\nassert my_solution.numberOfWays(**test_input) == 12\n\ntest_input = { \"n\": 11, \"x\": 2 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 11, \"x\": 3 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 11, \"x\": 4 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 11, \"x\": 5 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 12, \"x\": 1 }\nassert my_solution.numberOfWays(**test_input) == 15\n\ntest_input = { \"n\": 12, \"x\": 2 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 12, \"x\": 3 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 12, \"x\": 4 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 12, \"x\": 5 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 13, \"x\": 1 }\nassert my_solution.numberOfWays(**test_input) == 18\n\ntest_input = { \"n\": 13, \"x\": 2 }\nassert my_solution.numberOfWays(**test_input) == 1\n\ntest_input = { \"n\": 13, \"x\": 3 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 13, \"x\": 4 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 13, \"x\": 5 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 14, \"x\": 1 }\nassert my_solution.numberOfWays(**test_input) == 22\n\ntest_input = { \"n\": 14, \"x\": 2 }\nassert my_solution.numberOfWays(**test_input) == 1\n\ntest_input = { \"n\": 14, \"x\": 3 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 14, \"x\": 4 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 14, \"x\": 5 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 15, \"x\": 1 }\nassert my_solution.numberOfWays(**test_input) == 27\n\ntest_input = { \"n\": 15, \"x\": 2 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 15, \"x\": 3 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 15, \"x\": 4 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 15, \"x\": 5 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 16, \"x\": 1 }\nassert my_solution.numberOfWays(**test_input) == 32\n\ntest_input = { \"n\": 16, \"x\": 2 }\nassert my_solution.numberOfWays(**test_input) == 1\n\ntest_input = { \"n\": 16, \"x\": 3 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 16, \"x\": 4 }\nassert my_solution.numberOfWays(**test_input) == 1\n\ntest_input = { \"n\": 16, \"x\": 5 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 17, \"x\": 1 }\nassert my_solution.numberOfWays(**test_input) == 38\n\ntest_input = { \"n\": 17, \"x\": 2 }\nassert my_solution.numberOfWays(**test_input) == 1\n\ntest_input = { \"n\": 17, \"x\": 3 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 17, \"x\": 4 }\nassert my_solution.numberOfWays(**test_input) == 1\n\ntest_input = { \"n\": 17, \"x\": 5 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 18, \"x\": 1 }\nassert my_solution.numberOfWays(**test_input) == 46\n\ntest_input = { \"n\": 18, \"x\": 2 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 18, \"x\": 3 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 18, \"x\": 4 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 18, \"x\": 5 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 19, \"x\": 1 }\nassert my_solution.numberOfWays(**test_input) == 54\n\ntest_input = { \"n\": 19, \"x\": 2 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 19, \"x\": 3 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 19, \"x\": 4 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 19, \"x\": 5 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 20, \"x\": 1 }\nassert my_solution.numberOfWays(**test_input) == 64\n\ntest_input = { \"n\": 20, \"x\": 2 }\nassert my_solution.numberOfWays(**test_input) == 1\n\ntest_input = { \"n\": 20, \"x\": 3 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 20, \"x\": 4 }\nassert my_solution.numberOfWays(**test_input) == 0\n\ntest_input = { \"n\": 20, \"x\": 5 }\nassert my_solution.numberOfWays(**test_input) == 0", "start_time": 1690036200} +{"task_id": "weekly-contest-354-sum-of-squares-of-special-elements", "url": "https://leetcode.com/problems/sum-of-squares-of-special-elements", "title": "sum-of-squares-of-special-elements", "meta": {"questionId": "2844", "questionFrontendId": "2778", "title": "Sum of Squares of Special Elements ", "titleSlug": "sum-of-squares-of-special-elements", "isPaidOnly": false, "difficulty": "Easy", "likes": 218, "dislikes": 65, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 1-indexed integer array nums of length n.\n\nAn element nums[i] of nums is called special if i divides n, i.e. n % i == 0.\n\nReturn the sum of the squares of all special elements of nums.\n\nExample 1:\n\nInput: nums = [1,2,3,4]\nOutput: 21\nExplanation: There are exactly 3 special elements in nums: nums[1] since 1 divides 4, nums[2] since 2 divides 4, and nums[4] since 4 divides 4.\nHence, the sum of the squares of all special elements of nums is nums[1] * nums[1] + nums[2] * nums[2] + nums[4] * nums[4] = 1 * 1 + 2 * 2 + 4 * 4 = 21.\n\nExample 2:\n\nInput: nums = [2,7,1,19,18,3]\nOutput: 63\nExplanation: There are exactly 4 special elements in nums: nums[1] since 1 divides 6, nums[2] since 2 divides 6, nums[3] since 3 divides 6, and nums[6] since 6 divides 6.\nHence, the sum of the squares of all special elements of nums is nums[1] * nums[1] + nums[2] * nums[2] + nums[3] * nums[3] + nums[6] * nums[6] = 2 * 2 + 7 * 7 + 1 * 1 + 3 * 3 = 63.\n\n\nConstraints:\n\n * 1 <= nums.length == n <= 50\n * 1 <= nums[i] <= 50\n\"\"\"\nclass Solution:\n def sumOfSquares(self, nums: List[int]) -> int:\n ", "prompt_sft": "You are given a 1-indexed integer array nums of length n.\n\nAn element nums[i] of nums is called special if i divides n, i.e. n % i == 0.\n\nReturn the sum of the squares of all special elements of nums.\n\nExample 1:\n\nInput: nums = [1,2,3,4]\nOutput: 21\nExplanation: There are exactly 3 special elements in nums: nums[1] since 1 divides 4, nums[2] since 2 divides 4, and nums[4] since 4 divides 4.\nHence, the sum of the squares of all special elements of nums is nums[1] * nums[1] + nums[2] * nums[2] + nums[4] * nums[4] = 1 * 1 + 2 * 2 + 4 * 4 = 21.\n\nExample 2:\n\nInput: nums = [2,7,1,19,18,3]\nOutput: 63\nExplanation: There are exactly 4 special elements in nums: nums[1] since 1 divides 6, nums[2] since 2 divides 6, nums[3] since 3 divides 6, and nums[6] since 6 divides 6.\nHence, the sum of the squares of all special elements of nums is nums[1] * nums[1] + nums[2] * nums[2] + nums[3] * nums[3] + nums[6] * nums[6] = 2 * 2 + 7 * 7 + 1 * 1 + 3 * 3 = 63.\n\n\nConstraints:\n\n * 1 <= nums.length == n <= 50\n * 1 <= nums[i] <= 50\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def sumOfSquares(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,2,3,4] }\nassert my_solution.sumOfSquares(**test_input) == 21\n\ntest_input = { \"nums\": [2,7,1,19,18,3] }\nassert my_solution.sumOfSquares(**test_input) == 63\n\ntest_input = { \"nums\": [1] }\nassert my_solution.sumOfSquares(**test_input) == 1\n\ntest_input = { \"nums\": [2] }\nassert my_solution.sumOfSquares(**test_input) == 4\n\ntest_input = { \"nums\": [3] }\nassert my_solution.sumOfSquares(**test_input) == 9\n\ntest_input = { \"nums\": [4] }\nassert my_solution.sumOfSquares(**test_input) == 16\n\ntest_input = { \"nums\": [5] }\nassert my_solution.sumOfSquares(**test_input) == 25\n\ntest_input = { \"nums\": [6] }\nassert my_solution.sumOfSquares(**test_input) == 36\n\ntest_input = { \"nums\": [7] }\nassert my_solution.sumOfSquares(**test_input) == 49\n\ntest_input = { \"nums\": [8] }\nassert my_solution.sumOfSquares(**test_input) == 64\n\ntest_input = { \"nums\": [9] }\nassert my_solution.sumOfSquares(**test_input) == 81\n\ntest_input = { \"nums\": [10] }\nassert my_solution.sumOfSquares(**test_input) == 100\n\ntest_input = { \"nums\": [11] }\nassert my_solution.sumOfSquares(**test_input) == 121\n\ntest_input = { \"nums\": [12] }\nassert my_solution.sumOfSquares(**test_input) == 144\n\ntest_input = { \"nums\": [13] }\nassert my_solution.sumOfSquares(**test_input) == 169\n\ntest_input = { \"nums\": [14] }\nassert my_solution.sumOfSquares(**test_input) == 196\n\ntest_input = { \"nums\": [15] }\nassert my_solution.sumOfSquares(**test_input) == 225\n\ntest_input = { \"nums\": [16] }\nassert my_solution.sumOfSquares(**test_input) == 256\n\ntest_input = { \"nums\": [17] }\nassert my_solution.sumOfSquares(**test_input) == 289\n\ntest_input = { \"nums\": [18] }\nassert my_solution.sumOfSquares(**test_input) == 324\n\ntest_input = { \"nums\": [19] }\nassert my_solution.sumOfSquares(**test_input) == 361\n\ntest_input = { \"nums\": [20] }\nassert my_solution.sumOfSquares(**test_input) == 400\n\ntest_input = { \"nums\": [21] }\nassert my_solution.sumOfSquares(**test_input) == 441\n\ntest_input = { \"nums\": [22] }\nassert my_solution.sumOfSquares(**test_input) == 484\n\ntest_input = { \"nums\": [23] }\nassert my_solution.sumOfSquares(**test_input) == 529\n\ntest_input = { \"nums\": [24] }\nassert my_solution.sumOfSquares(**test_input) == 576\n\ntest_input = { \"nums\": [25] }\nassert my_solution.sumOfSquares(**test_input) == 625\n\ntest_input = { \"nums\": [26] }\nassert my_solution.sumOfSquares(**test_input) == 676\n\ntest_input = { \"nums\": [27] }\nassert my_solution.sumOfSquares(**test_input) == 729\n\ntest_input = { \"nums\": [28] }\nassert my_solution.sumOfSquares(**test_input) == 784\n\ntest_input = { \"nums\": [29] }\nassert my_solution.sumOfSquares(**test_input) == 841\n\ntest_input = { \"nums\": [30] }\nassert my_solution.sumOfSquares(**test_input) == 900\n\ntest_input = { \"nums\": [31] }\nassert my_solution.sumOfSquares(**test_input) == 961\n\ntest_input = { \"nums\": [32] }\nassert my_solution.sumOfSquares(**test_input) == 1024\n\ntest_input = { \"nums\": [33] }\nassert my_solution.sumOfSquares(**test_input) == 1089\n\ntest_input = { \"nums\": [34] }\nassert my_solution.sumOfSquares(**test_input) == 1156\n\ntest_input = { \"nums\": [35] }\nassert my_solution.sumOfSquares(**test_input) == 1225\n\ntest_input = { \"nums\": [36] }\nassert my_solution.sumOfSquares(**test_input) == 1296\n\ntest_input = { \"nums\": [37] }\nassert my_solution.sumOfSquares(**test_input) == 1369\n\ntest_input = { \"nums\": [38] }\nassert my_solution.sumOfSquares(**test_input) == 1444\n\ntest_input = { \"nums\": [39] }\nassert my_solution.sumOfSquares(**test_input) == 1521\n\ntest_input = { \"nums\": [40] }\nassert my_solution.sumOfSquares(**test_input) == 1600\n\ntest_input = { \"nums\": [41] }\nassert my_solution.sumOfSquares(**test_input) == 1681\n\ntest_input = { \"nums\": [42] }\nassert my_solution.sumOfSquares(**test_input) == 1764\n\ntest_input = { \"nums\": [43] }\nassert my_solution.sumOfSquares(**test_input) == 1849\n\ntest_input = { \"nums\": [44] }\nassert my_solution.sumOfSquares(**test_input) == 1936\n\ntest_input = { \"nums\": [45] }\nassert my_solution.sumOfSquares(**test_input) == 2025\n\ntest_input = { \"nums\": [46] }\nassert my_solution.sumOfSquares(**test_input) == 2116\n\ntest_input = { \"nums\": [47] }\nassert my_solution.sumOfSquares(**test_input) == 2209\n\ntest_input = { \"nums\": [48] }\nassert my_solution.sumOfSquares(**test_input) == 2304\n\ntest_input = { \"nums\": [49] }\nassert my_solution.sumOfSquares(**test_input) == 2401\n\ntest_input = { \"nums\": [50] }\nassert my_solution.sumOfSquares(**test_input) == 2500\n\ntest_input = { \"nums\": [16,16] }\nassert my_solution.sumOfSquares(**test_input) == 512\n\ntest_input = { \"nums\": [13,36] }\nassert my_solution.sumOfSquares(**test_input) == 1465\n\ntest_input = { \"nums\": [40,37] }\nassert my_solution.sumOfSquares(**test_input) == 2969\n\ntest_input = { \"nums\": [33,42] }\nassert my_solution.sumOfSquares(**test_input) == 2853\n\ntest_input = { \"nums\": [46,9] }\nassert my_solution.sumOfSquares(**test_input) == 2197\n\ntest_input = { \"nums\": [30,14] }\nassert my_solution.sumOfSquares(**test_input) == 1096\n\ntest_input = { \"nums\": [5,41] }\nassert my_solution.sumOfSquares(**test_input) == 1706\n\ntest_input = { \"nums\": [17,9] }\nassert my_solution.sumOfSquares(**test_input) == 370\n\ntest_input = { \"nums\": [29,21] }\nassert my_solution.sumOfSquares(**test_input) == 1282\n\ntest_input = { \"nums\": [4,38] }\nassert my_solution.sumOfSquares(**test_input) == 1460\n\ntest_input = { \"nums\": [14,18] }\nassert my_solution.sumOfSquares(**test_input) == 520\n\ntest_input = { \"nums\": [11,7] }\nassert my_solution.sumOfSquares(**test_input) == 170\n\ntest_input = { \"nums\": [11,36] }\nassert my_solution.sumOfSquares(**test_input) == 1417\n\ntest_input = { \"nums\": [18,26] }\nassert my_solution.sumOfSquares(**test_input) == 1000\n\ntest_input = { \"nums\": [37,46] }\nassert my_solution.sumOfSquares(**test_input) == 3485\n\ntest_input = { \"nums\": [13,33] }\nassert my_solution.sumOfSquares(**test_input) == 1258\n\ntest_input = { \"nums\": [39,1] }\nassert my_solution.sumOfSquares(**test_input) == 1522\n\ntest_input = { \"nums\": [37,16] }\nassert my_solution.sumOfSquares(**test_input) == 1625\n\ntest_input = { \"nums\": [22,34] }\nassert my_solution.sumOfSquares(**test_input) == 1640\n\ntest_input = { \"nums\": [4,50] }\nassert my_solution.sumOfSquares(**test_input) == 2516\n\ntest_input = { \"nums\": [42,40] }\nassert my_solution.sumOfSquares(**test_input) == 3364\n\ntest_input = { \"nums\": [7,44] }\nassert my_solution.sumOfSquares(**test_input) == 1985\n\ntest_input = { \"nums\": [21,27] }\nassert my_solution.sumOfSquares(**test_input) == 1170\n\ntest_input = { \"nums\": [49,35] }\nassert my_solution.sumOfSquares(**test_input) == 3626\n\ntest_input = { \"nums\": [32,20] }\nassert my_solution.sumOfSquares(**test_input) == 1424\n\ntest_input = { \"nums\": [30,12] }\nassert my_solution.sumOfSquares(**test_input) == 1044\n\ntest_input = { \"nums\": [50,42] }\nassert my_solution.sumOfSquares(**test_input) == 4264\n\ntest_input = { \"nums\": [3,11] }\nassert my_solution.sumOfSquares(**test_input) == 130\n\ntest_input = { \"nums\": [38,17] }\nassert my_solution.sumOfSquares(**test_input) == 1733\n\ntest_input = { \"nums\": [50,32] }\nassert my_solution.sumOfSquares(**test_input) == 3524\n\ntest_input = { \"nums\": [12,35] }\nassert my_solution.sumOfSquares(**test_input) == 1369\n\ntest_input = { \"nums\": [9,32] }\nassert my_solution.sumOfSquares(**test_input) == 1105\n\ntest_input = { \"nums\": [6,11] }\nassert my_solution.sumOfSquares(**test_input) == 157\n\ntest_input = { \"nums\": [11,39] }\nassert my_solution.sumOfSquares(**test_input) == 1642\n\ntest_input = { \"nums\": [18,29] }\nassert my_solution.sumOfSquares(**test_input) == 1165\n\ntest_input = { \"nums\": [44,29] }\nassert my_solution.sumOfSquares(**test_input) == 2777\n\ntest_input = { \"nums\": [50,13] }\nassert my_solution.sumOfSquares(**test_input) == 2669\n\ntest_input = { \"nums\": [46,46] }\nassert my_solution.sumOfSquares(**test_input) == 4232\n\ntest_input = { \"nums\": [27,5] }\nassert my_solution.sumOfSquares(**test_input) == 754\n\ntest_input = { \"nums\": [12,13] }\nassert my_solution.sumOfSquares(**test_input) == 313\n\ntest_input = { \"nums\": [10,46] }\nassert my_solution.sumOfSquares(**test_input) == 2216\n\ntest_input = { \"nums\": [37,32] }\nassert my_solution.sumOfSquares(**test_input) == 2393\n\ntest_input = { \"nums\": [26,33] }\nassert my_solution.sumOfSquares(**test_input) == 1765\n\ntest_input = { \"nums\": [44,3] }\nassert my_solution.sumOfSquares(**test_input) == 1945\n\ntest_input = { \"nums\": [9,16] }\nassert my_solution.sumOfSquares(**test_input) == 337\n\ntest_input = { \"nums\": [7,21] }\nassert my_solution.sumOfSquares(**test_input) == 490\n\ntest_input = { \"nums\": [23,33] }\nassert my_solution.sumOfSquares(**test_input) == 1618\n\ntest_input = { \"nums\": [22,5] }\nassert my_solution.sumOfSquares(**test_input) == 509", "start_time": 1689474600} +{"task_id": "weekly-contest-354-maximum-beauty-of-an-array-after-applying-operation", "url": "https://leetcode.com/problems/maximum-beauty-of-an-array-after-applying-operation", "title": "maximum-beauty-of-an-array-after-applying-operation", "meta": {"questionId": "2891", "questionFrontendId": "2779", "title": "Maximum Beauty of an Array After Applying Operation", "titleSlug": "maximum-beauty-of-an-array-after-applying-operation", "isPaidOnly": false, "difficulty": "Medium", "likes": 559, "dislikes": 12, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed array nums and a non-negative integer k.\n\nIn one operation, you can do the following:\n\n * Choose an index i that hasn't been chosen before from the range [0, nums.length - 1].\n * Replace nums[i] with any integer from the range [nums[i] - k, nums[i] + k].\n\nThe beauty of the array is the length of the longest subsequence consisting of equal elements.\n\nReturn the maximum possible beauty of the array nums after applying the operation any number of times.\n\nNote that you can apply the operation to each index only once.\n\nA subsequence of an array is a new array generated from the original array by deleting some elements (possibly none) without changing the order of the remaining elements.\n\nExample 1:\n\nInput: nums = [4,6,1,2], k = 2\nOutput: 3\nExplanation: In this example, we apply the following operations:\n- Choose index 1, replace it with 4 (from range [4,8]), nums = [4,4,1,2].\n- Choose index 3, replace it with 4 (from range [0,4]), nums = [4,4,1,4].\nAfter the applied operations, the beauty of the array nums is 3 (subsequence consisting of indices 0, 1, and 3).\nIt can be proven that 3 is the maximum possible length we can achieve.\n\nExample 2:\n\nInput: nums = [1,1,1,1], k = 10\nOutput: 4\nExplanation: In this example we don't have to apply any operations.\nThe beauty of the array nums is 4 (whole array).\n\n\nConstraints:\n\n * 1 <= nums.length <= 105\n * 0 <= nums[i], k <= 105\n\"\"\"\nclass Solution:\n def maximumBeauty(self, nums: List[int], k: int) -> int:\n ", "prompt_sft": "You are given a 0-indexed array nums and a non-negative integer k.\n\nIn one operation, you can do the following:\n\n * Choose an index i that hasn't been chosen before from the range [0, nums.length - 1].\n * Replace nums[i] with any integer from the range [nums[i] - k, nums[i] + k].\n\nThe beauty of the array is the length of the longest subsequence consisting of equal elements.\n\nReturn the maximum possible beauty of the array nums after applying the operation any number of times.\n\nNote that you can apply the operation to each index only once.\n\nA subsequence of an array is a new array generated from the original array by deleting some elements (possibly none) without changing the order of the remaining elements.\n\nExample 1:\n\nInput: nums = [4,6,1,2], k = 2\nOutput: 3\nExplanation: In this example, we apply the following operations:\n- Choose index 1, replace it with 4 (from range [4,8]), nums = [4,4,1,2].\n- Choose index 3, replace it with 4 (from range [0,4]), nums = [4,4,1,4].\nAfter the applied operations, the beauty of the array nums is 3 (subsequence consisting of indices 0, 1, and 3).\nIt can be proven that 3 is the maximum possible length we can achieve.\n\nExample 2:\n\nInput: nums = [1,1,1,1], k = 10\nOutput: 4\nExplanation: In this example we don't have to apply any operations.\nThe beauty of the array nums is 4 (whole array).\n\n\nConstraints:\n\n * 1 <= nums.length <= 105\n * 0 <= nums[i], k <= 105\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def maximumBeauty(self, nums: List[int], k: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [4,6,1,2], \"k\": 2 }\nassert my_solution.maximumBeauty(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,1,1], \"k\": 10 }\nassert my_solution.maximumBeauty(**test_input) == 4\n\ntest_input = { \"nums\": [12,71], \"k\": 10 }\nassert my_solution.maximumBeauty(**test_input) == 1\n\ntest_input = { \"nums\": [27,55], \"k\": 1 }\nassert my_solution.maximumBeauty(**test_input) == 1\n\ntest_input = { \"nums\": [52,34], \"k\": 21 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [76,0], \"k\": 16 }\nassert my_solution.maximumBeauty(**test_input) == 1\n\ntest_input = { \"nums\": [56,40], \"k\": 26 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [49,26], \"k\": 12 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [69,66], \"k\": 14 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [64,98], \"k\": 12 }\nassert my_solution.maximumBeauty(**test_input) == 1\n\ntest_input = { \"nums\": [83,81], \"k\": 7 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [44,93], \"k\": 15 }\nassert my_solution.maximumBeauty(**test_input) == 1\n\ntest_input = { \"nums\": [44,31], \"k\": 26 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [70,60], \"k\": 15 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [60,22], \"k\": 11 }\nassert my_solution.maximumBeauty(**test_input) == 1\n\ntest_input = { \"nums\": [33,20], \"k\": 1 }\nassert my_solution.maximumBeauty(**test_input) == 1\n\ntest_input = { \"nums\": [64,24], \"k\": 4 }\nassert my_solution.maximumBeauty(**test_input) == 1\n\ntest_input = { \"nums\": [59,20], \"k\": 28 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [10,98], \"k\": 27 }\nassert my_solution.maximumBeauty(**test_input) == 1\n\ntest_input = { \"nums\": [54,21], \"k\": 20 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [61,11], \"k\": 15 }\nassert my_solution.maximumBeauty(**test_input) == 1\n\ntest_input = { \"nums\": [99,40], \"k\": 27 }\nassert my_solution.maximumBeauty(**test_input) == 1\n\ntest_input = { \"nums\": [32,91], \"k\": 3 }\nassert my_solution.maximumBeauty(**test_input) == 1\n\ntest_input = { \"nums\": [91,57], \"k\": 21 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [60,92], \"k\": 26 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [4,45], \"k\": 6 }\nassert my_solution.maximumBeauty(**test_input) == 1\n\ntest_input = { \"nums\": [24,35], \"k\": 6 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [11,29], \"k\": 3 }\nassert my_solution.maximumBeauty(**test_input) == 1\n\ntest_input = { \"nums\": [51,29], \"k\": 3 }\nassert my_solution.maximumBeauty(**test_input) == 1\n\ntest_input = { \"nums\": [43,21], \"k\": 14 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [32,25], \"k\": 18 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [13,66], \"k\": 5 }\nassert my_solution.maximumBeauty(**test_input) == 1\n\ntest_input = { \"nums\": [89,71], \"k\": 28 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [36,29], \"k\": 20 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [11,43], \"k\": 21 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [15,36], \"k\": 4 }\nassert my_solution.maximumBeauty(**test_input) == 1\n\ntest_input = { \"nums\": [11,51], \"k\": 1 }\nassert my_solution.maximumBeauty(**test_input) == 1\n\ntest_input = { \"nums\": [2,57], \"k\": 20 }\nassert my_solution.maximumBeauty(**test_input) == 1\n\ntest_input = { \"nums\": [94,66], \"k\": 26 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [87,51], \"k\": 8 }\nassert my_solution.maximumBeauty(**test_input) == 1\n\ntest_input = { \"nums\": [5,57,46], \"k\": 15 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [81,46,85], \"k\": 23 }\nassert my_solution.maximumBeauty(**test_input) == 3\n\ntest_input = { \"nums\": [51,83,0], \"k\": 11 }\nassert my_solution.maximumBeauty(**test_input) == 1\n\ntest_input = { \"nums\": [75,15,9], \"k\": 28 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [10,59,86], \"k\": 23 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [41,11,59], \"k\": 17 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [62,77,100], \"k\": 5 }\nassert my_solution.maximumBeauty(**test_input) == 1\n\ntest_input = { \"nums\": [27,35,15], \"k\": 6 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [81,76,40], \"k\": 5 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [84,43,96], \"k\": 7 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [62,1,93], \"k\": 30 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [13,46,71], \"k\": 29 }\nassert my_solution.maximumBeauty(**test_input) == 3\n\ntest_input = { \"nums\": [92,99,44], \"k\": 28 }\nassert my_solution.maximumBeauty(**test_input) == 3\n\ntest_input = { \"nums\": [73,30,40], \"k\": 26 }\nassert my_solution.maximumBeauty(**test_input) == 3\n\ntest_input = { \"nums\": [83,89,17], \"k\": 5 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [38,20,11], \"k\": 9 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [63,56,23], \"k\": 14 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [32,16,98], \"k\": 0 }\nassert my_solution.maximumBeauty(**test_input) == 1\n\ntest_input = { \"nums\": [57,58,71], \"k\": 2 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [61,50,35], \"k\": 2 }\nassert my_solution.maximumBeauty(**test_input) == 1\n\ntest_input = { \"nums\": [22,97,13], \"k\": 22 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [89,52,33], \"k\": 14 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [89,4,77], \"k\": 20 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [50,26,72], \"k\": 30 }\nassert my_solution.maximumBeauty(**test_input) == 3\n\ntest_input = { \"nums\": [72,75,47], \"k\": 7 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [23,1,73], \"k\": 25 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [36,74,20], \"k\": 20 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [34,64,11], \"k\": 18 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [29,94,45], \"k\": 27 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [22,80,34], \"k\": 28 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [52,63,75], \"k\": 11 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [53,63,93,89], \"k\": 23 }\nassert my_solution.maximumBeauty(**test_input) == 4\n\ntest_input = { \"nums\": [47,76,100,51], \"k\": 27 }\nassert my_solution.maximumBeauty(**test_input) == 4\n\ntest_input = { \"nums\": [73,83,46,88], \"k\": 13 }\nassert my_solution.maximumBeauty(**test_input) == 3\n\ntest_input = { \"nums\": [50,28,30,51], \"k\": 2 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [88,87,9,17], \"k\": 10 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [27,56,27,40], \"k\": 6 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [88,19,2,30], \"k\": 6 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [58,50,0,97], \"k\": 18 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [83,10,99,99], \"k\": 18 }\nassert my_solution.maximumBeauty(**test_input) == 3\n\ntest_input = { \"nums\": [58,75,1,25], \"k\": 12 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [77,35,1,69], \"k\": 15 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [23,33,62,20], \"k\": 12 }\nassert my_solution.maximumBeauty(**test_input) == 3\n\ntest_input = { \"nums\": [42,34,18,0], \"k\": 5 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [10,58,37,46], \"k\": 0 }\nassert my_solution.maximumBeauty(**test_input) == 1\n\ntest_input = { \"nums\": [34,73,57,55], \"k\": 27 }\nassert my_solution.maximumBeauty(**test_input) == 4\n\ntest_input = { \"nums\": [53,100,74,5], \"k\": 4 }\nassert my_solution.maximumBeauty(**test_input) == 1\n\ntest_input = { \"nums\": [48,93,96,19], \"k\": 24 }\nassert my_solution.maximumBeauty(**test_input) == 3\n\ntest_input = { \"nums\": [91,12,29,31], \"k\": 22 }\nassert my_solution.maximumBeauty(**test_input) == 3\n\ntest_input = { \"nums\": [48,9,35,36], \"k\": 12 }\nassert my_solution.maximumBeauty(**test_input) == 3\n\ntest_input = { \"nums\": [24,64,40,30], \"k\": 3 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [19,58,41,42], \"k\": 14 }\nassert my_solution.maximumBeauty(**test_input) == 3\n\ntest_input = { \"nums\": [72,44,29,76], \"k\": 4 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [37,19,10,16], \"k\": 16 }\nassert my_solution.maximumBeauty(**test_input) == 4\n\ntest_input = { \"nums\": [54,84,73,31], \"k\": 30 }\nassert my_solution.maximumBeauty(**test_input) == 4\n\ntest_input = { \"nums\": [83,92,30,60], \"k\": 19 }\nassert my_solution.maximumBeauty(**test_input) == 3\n\ntest_input = { \"nums\": [14,51,99,64], \"k\": 15 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [7,60,16,2], \"k\": 17 }\nassert my_solution.maximumBeauty(**test_input) == 3\n\ntest_input = { \"nums\": [7,89,54,54], \"k\": 5 }\nassert my_solution.maximumBeauty(**test_input) == 2\n\ntest_input = { \"nums\": [43,86,33,18], \"k\": 23 }\nassert my_solution.maximumBeauty(**test_input) == 3", "start_time": 1689474600} +{"task_id": "weekly-contest-354-minimum-index-of-a-valid-split", "url": "https://leetcode.com/problems/minimum-index-of-a-valid-split", "title": "minimum-index-of-a-valid-split", "meta": {"questionId": "2888", "questionFrontendId": "2780", "title": "Minimum Index of a Valid Split", "titleSlug": "minimum-index-of-a-valid-split", "isPaidOnly": false, "difficulty": "Medium", "likes": 282, "dislikes": 11, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nAn element x of an integer array arr of length m is dominant if freq(x) * 2 > m, where freq(x) is the number of occurrences of x in arr. Note that this definition implies that arr can have at most one dominant element.\n\nYou are given a 0-indexed integer array nums of length n with one dominant element.\n\nYou can split nums at an index i into two arrays nums[0, ..., i] and nums[i + 1, ..., n - 1], but the split is only valid if:\n\n * 0 <= i < n - 1\n * nums[0, ..., i], and nums[i + 1, ..., n - 1] have the same dominant element.\n\nHere, nums[i, ..., j] denotes the subarray of nums starting at index i and ending at index j, both ends being inclusive. Particularly, if j < i then nums[i, ..., j] denotes an empty subarray.\n\nReturn the minimum index of a valid split. If no valid split exists, return -1.\n\nExample 1:\n\nInput: nums = [1,2,2,2]\nOutput: 2\nExplanation: We can split the array at index 2 to obtain arrays [1,2,2] and [2].\nIn array [1,2,2], element 2 is dominant since it occurs twice in the array and 2 * 2 > 3.\nIn array [2], element 2 is dominant since it occurs once in the array and 1 * 2 > 1.\nBoth [1,2,2] and [2] have the same dominant element as nums, so this is a valid split.\nIt can be shown that index 2 is the minimum index of a valid split.\n\nExample 2:\n\nInput: nums = [2,1,3,1,1,1,7,1,2,1]\nOutput: 4\nExplanation: We can split the array at index 4 to obtain arrays [2,1,3,1,1] and [1,7,1,2,1].\nIn array [2,1,3,1,1], element 1 is dominant since it occurs thrice in the array and 3 * 2 > 5.\nIn array [1,7,1,2,1], element 1 is dominant since it occurs thrice in the array and 3 * 2 > 5.\nBoth [2,1,3,1,1] and [1,7,1,2,1] have the same dominant element as nums, so this is a valid split.\nIt can be shown that index 4 is the minimum index of a valid split.\n\nExample 3:\n\nInput: nums = [3,3,3,3,7,2,2]\nOutput: -1\nExplanation: It can be shown that there is no valid split.\n\n\nConstraints:\n\n * 1 <= nums.length <= 105\n * 1 <= nums[i] <= 109\n * nums has exactly one dominant element.\n\"\"\"\nclass Solution:\n def minimumIndex(self, nums: List[int]) -> int:\n ", "prompt_sft": "An element x of an integer array arr of length m is dominant if freq(x) * 2 > m, where freq(x) is the number of occurrences of x in arr. Note that this definition implies that arr can have at most one dominant element.\n\nYou are given a 0-indexed integer array nums of length n with one dominant element.\n\nYou can split nums at an index i into two arrays nums[0, ..., i] and nums[i + 1, ..., n - 1], but the split is only valid if:\n\n * 0 <= i < n - 1\n * nums[0, ..., i], and nums[i + 1, ..., n - 1] have the same dominant element.\n\nHere, nums[i, ..., j] denotes the subarray of nums starting at index i and ending at index j, both ends being inclusive. Particularly, if j < i then nums[i, ..., j] denotes an empty subarray.\n\nReturn the minimum index of a valid split. If no valid split exists, return -1.\n\nExample 1:\n\nInput: nums = [1,2,2,2]\nOutput: 2\nExplanation: We can split the array at index 2 to obtain arrays [1,2,2] and [2].\nIn array [1,2,2], element 2 is dominant since it occurs twice in the array and 2 * 2 > 3.\nIn array [2], element 2 is dominant since it occurs once in the array and 1 * 2 > 1.\nBoth [1,2,2] and [2] have the same dominant element as nums, so this is a valid split.\nIt can be shown that index 2 is the minimum index of a valid split.\n\nExample 2:\n\nInput: nums = [2,1,3,1,1,1,7,1,2,1]\nOutput: 4\nExplanation: We can split the array at index 4 to obtain arrays [2,1,3,1,1] and [1,7,1,2,1].\nIn array [2,1,3,1,1], element 1 is dominant since it occurs thrice in the array and 3 * 2 > 5.\nIn array [1,7,1,2,1], element 1 is dominant since it occurs thrice in the array and 3 * 2 > 5.\nBoth [2,1,3,1,1] and [1,7,1,2,1] have the same dominant element as nums, so this is a valid split.\nIt can be shown that index 4 is the minimum index of a valid split.\n\nExample 3:\n\nInput: nums = [3,3,3,3,7,2,2]\nOutput: -1\nExplanation: It can be shown that there is no valid split.\n\n\nConstraints:\n\n * 1 <= nums.length <= 105\n * 1 <= nums[i] <= 109\n * nums has exactly one dominant element.\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def minimumIndex(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,2,2,2] }\nassert my_solution.minimumIndex(**test_input) == 2\n\ntest_input = { \"nums\": [2,1,3,1,1,1,7,1,2,1] }\nassert my_solution.minimumIndex(**test_input) == 4\n\ntest_input = { \"nums\": [3,3,3,3,7,2,2] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [1] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [1,1] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,1] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,1,1] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,1,2] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,1,3] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,1,4] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,2] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,2,1] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,3] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,3,1] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,4] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [1,1,4,1] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [1,2,1] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [1,2,1,1] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [1,2,2] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [1,3,1] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [1,3,1,1] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [1,3,3] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [1,3,3,3] }\nassert my_solution.minimumIndex(**test_input) == 2\n\ntest_input = { \"nums\": [1,4,1] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [1,4,1,1] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [1,4,4] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [1,4,4,4] }\nassert my_solution.minimumIndex(**test_input) == 2\n\ntest_input = { \"nums\": [2] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [2,1,1] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [2,1,1,1] }\nassert my_solution.minimumIndex(**test_input) == 2\n\ntest_input = { \"nums\": [2,1,2] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [2,1,2,2] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [2,2] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [2,2,1] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [2,2,1,2] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [2,2,2] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [2,2,2,1] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [2,2,2,2] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [2,2,2,3] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [2,2,2,4] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [2,2,3] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [2,2,3,2] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [2,2,4] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [2,2,4,2] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [2,3,2] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [2,3,2,2] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [2,3,3] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [2,3,3,3] }\nassert my_solution.minimumIndex(**test_input) == 2\n\ntest_input = { \"nums\": [2,4,2] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [2,4,2,2] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [2,4,4] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [2,4,4,4] }\nassert my_solution.minimumIndex(**test_input) == 2\n\ntest_input = { \"nums\": [3] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [3,1,1] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [3,1,1,1] }\nassert my_solution.minimumIndex(**test_input) == 2\n\ntest_input = { \"nums\": [3,1,3] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [3,1,3,3] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [3,2,2] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [3,2,2,2] }\nassert my_solution.minimumIndex(**test_input) == 2\n\ntest_input = { \"nums\": [3,2,3] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [3,2,3,3] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [3,3] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [3,3,1] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [3,3,1,3] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [3,3,2] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [3,3,2,3] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [3,3,3] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [3,3,3,1] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [3,3,3,2] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [3,3,3,3] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [3,3,3,4] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [3,3,4] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [3,3,4,3] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [3,4,3] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [3,4,3,3] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [3,4,4] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [3,4,4,4] }\nassert my_solution.minimumIndex(**test_input) == 2\n\ntest_input = { \"nums\": [4] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [4,1,1] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [4,1,1,1] }\nassert my_solution.minimumIndex(**test_input) == 2\n\ntest_input = { \"nums\": [4,1,4] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [4,1,4,4] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [4,2,2] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [4,2,2,2] }\nassert my_solution.minimumIndex(**test_input) == 2\n\ntest_input = { \"nums\": [4,2,4] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [4,2,4,4] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [4,3,3] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [4,3,3,3] }\nassert my_solution.minimumIndex(**test_input) == 2\n\ntest_input = { \"nums\": [4,3,4] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [4,3,4,4] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [4,4] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [4,4,1] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [4,4,1,4] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [4,4,2] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [4,4,2,4] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [4,4,3] }\nassert my_solution.minimumIndex(**test_input) == -1\n\ntest_input = { \"nums\": [4,4,3,4] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [4,4,4] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [4,4,4,1] }\nassert my_solution.minimumIndex(**test_input) == 0\n\ntest_input = { \"nums\": [4,4,4,2] }\nassert my_solution.minimumIndex(**test_input) == 0", "start_time": 1689474600} +{"task_id": "weekly-contest-354-length-of-the-longest-valid-substring", "url": "https://leetcode.com/problems/length-of-the-longest-valid-substring", "title": "length-of-the-longest-valid-substring", "meta": {"questionId": "2884", "questionFrontendId": "2781", "title": "Length of the Longest Valid Substring", "titleSlug": "length-of-the-longest-valid-substring", "isPaidOnly": false, "difficulty": "Hard", "likes": 447, "dislikes": 9, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a string word and an array of strings forbidden.\n\nA string is called valid if none of its substrings are present in forbidden.\n\nReturn the length of the longest valid substring of the string word.\n\nA substring is a contiguous sequence of characters in a string, possibly empty.\n\nExample 1:\n\nInput: word = \"cbaaaabc\", forbidden = [\"aaa\",\"cb\"]\nOutput: 4\nExplanation: There are 11 valid substrings in word: \"c\", \"b\", \"a\", \"ba\", \"aa\", \"bc\", \"baa\", \"aab\", \"ab\", \"abc\" and \"aabc\". The length of the longest valid substring is 4.\nIt can be shown that all other substrings contain either \"aaa\" or \"cb\" as a substring.\n\nExample 2:\n\nInput: word = \"leetcode\", forbidden = [\"de\",\"le\",\"e\"]\nOutput: 4\nExplanation: There are 11 valid substrings in word: \"l\", \"t\", \"c\", \"o\", \"d\", \"tc\", \"co\", \"od\", \"tco\", \"cod\", and \"tcod\". The length of the longest valid substring is 4.\nIt can be shown that all other substrings contain either \"de\", \"le\", or \"e\" as a substring.\n\n\nConstraints:\n\n * 1 <= word.length <= 105\n * word consists only of lowercase English letters.\n * 1 <= forbidden.length <= 105\n * 1 <= forbidden[i].length <= 10\n * forbidden[i] consists only of lowercase English letters.\n\"\"\"\nclass Solution:\n def longestValidSubstring(self, word: str, forbidden: List[str]) -> int:\n ", "prompt_sft": "You are given a string word and an array of strings forbidden.\n\nA string is called valid if none of its substrings are present in forbidden.\n\nReturn the length of the longest valid substring of the string word.\n\nA substring is a contiguous sequence of characters in a string, possibly empty.\n\nExample 1:\n\nInput: word = \"cbaaaabc\", forbidden = [\"aaa\",\"cb\"]\nOutput: 4\nExplanation: There are 11 valid substrings in word: \"c\", \"b\", \"a\", \"ba\", \"aa\", \"bc\", \"baa\", \"aab\", \"ab\", \"abc\" and \"aabc\". The length of the longest valid substring is 4.\nIt can be shown that all other substrings contain either \"aaa\" or \"cb\" as a substring.\n\nExample 2:\n\nInput: word = \"leetcode\", forbidden = [\"de\",\"le\",\"e\"]\nOutput: 4\nExplanation: There are 11 valid substrings in word: \"l\", \"t\", \"c\", \"o\", \"d\", \"tc\", \"co\", \"od\", \"tco\", \"cod\", and \"tcod\". The length of the longest valid substring is 4.\nIt can be shown that all other substrings contain either \"de\", \"le\", or \"e\" as a substring.\n\n\nConstraints:\n\n * 1 <= word.length <= 105\n * word consists only of lowercase English letters.\n * 1 <= forbidden.length <= 105\n * 1 <= forbidden[i].length <= 10\n * forbidden[i] consists only of lowercase English letters.\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def longestValidSubstring(self, word: str, forbidden: List[str]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"word\": \"cbaaaabc\", \"forbidden\": [\"aaa\",\"cb\"] }\nassert my_solution.longestValidSubstring(**test_input) == 4\n\ntest_input = { \"word\": \"leetcode\", \"forbidden\": [\"de\",\"le\",\"e\"] }\nassert my_solution.longestValidSubstring(**test_input) == 4\n\ntest_input = { \"word\": \"a\", \"forbidden\": [\"n\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"a\", \"forbidden\": [\"s\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"a\", \"forbidden\": [\"a\"] }\nassert my_solution.longestValidSubstring(**test_input) == 0\n\ntest_input = { \"word\": \"b\", \"forbidden\": [\"g\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"b\", \"forbidden\": [\"t\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"b\", \"forbidden\": [\"b\"] }\nassert my_solution.longestValidSubstring(**test_input) == 0\n\ntest_input = { \"word\": \"c\", \"forbidden\": [\"k\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"c\", \"forbidden\": [\"s\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"c\", \"forbidden\": [\"c\"] }\nassert my_solution.longestValidSubstring(**test_input) == 0\n\ntest_input = { \"word\": \"d\", \"forbidden\": [\"h\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"d\", \"forbidden\": [\"n\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"d\", \"forbidden\": [\"d\"] }\nassert my_solution.longestValidSubstring(**test_input) == 0\n\ntest_input = { \"word\": \"e\", \"forbidden\": [\"s\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"e\", \"forbidden\": [\"e\"] }\nassert my_solution.longestValidSubstring(**test_input) == 0\n\ntest_input = { \"word\": \"f\", \"forbidden\": [\"b\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"f\", \"forbidden\": [\"s\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"f\", \"forbidden\": [\"f\"] }\nassert my_solution.longestValidSubstring(**test_input) == 0\n\ntest_input = { \"word\": \"g\", \"forbidden\": [\"r\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"g\", \"forbidden\": [\"y\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"g\", \"forbidden\": [\"g\"] }\nassert my_solution.longestValidSubstring(**test_input) == 0\n\ntest_input = { \"word\": \"h\", \"forbidden\": [\"v\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"h\", \"forbidden\": [\"b\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"h\", \"forbidden\": [\"h\"] }\nassert my_solution.longestValidSubstring(**test_input) == 0\n\ntest_input = { \"word\": \"i\", \"forbidden\": [\"k\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"i\", \"forbidden\": [\"y\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"i\", \"forbidden\": [\"i\"] }\nassert my_solution.longestValidSubstring(**test_input) == 0\n\ntest_input = { \"word\": \"j\", \"forbidden\": [\"v\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"j\", \"forbidden\": [\"u\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"j\", \"forbidden\": [\"j\"] }\nassert my_solution.longestValidSubstring(**test_input) == 0\n\ntest_input = { \"word\": \"k\", \"forbidden\": [\"z\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"k\", \"forbidden\": [\"o\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"k\", \"forbidden\": [\"k\"] }\nassert my_solution.longestValidSubstring(**test_input) == 0\n\ntest_input = { \"word\": \"l\", \"forbidden\": [\"i\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"l\", \"forbidden\": [\"r\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"l\", \"forbidden\": [\"l\"] }\nassert my_solution.longestValidSubstring(**test_input) == 0\n\ntest_input = { \"word\": \"m\", \"forbidden\": [\"s\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"m\", \"forbidden\": [\"g\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"m\", \"forbidden\": [\"m\"] }\nassert my_solution.longestValidSubstring(**test_input) == 0\n\ntest_input = { \"word\": \"n\", \"forbidden\": [\"e\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"n\", \"forbidden\": [\"i\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"n\", \"forbidden\": [\"n\"] }\nassert my_solution.longestValidSubstring(**test_input) == 0\n\ntest_input = { \"word\": \"o\", \"forbidden\": [\"j\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"o\", \"forbidden\": [\"f\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"o\", \"forbidden\": [\"o\"] }\nassert my_solution.longestValidSubstring(**test_input) == 0\n\ntest_input = { \"word\": \"p\", \"forbidden\": [\"z\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"p\", \"forbidden\": [\"i\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"p\", \"forbidden\": [\"p\"] }\nassert my_solution.longestValidSubstring(**test_input) == 0\n\ntest_input = { \"word\": \"q\", \"forbidden\": [\"j\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"q\", \"forbidden\": [\"z\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"q\", \"forbidden\": [\"q\"] }\nassert my_solution.longestValidSubstring(**test_input) == 0\n\ntest_input = { \"word\": \"r\", \"forbidden\": [\"v\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"r\", \"forbidden\": [\"p\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"r\", \"forbidden\": [\"r\"] }\nassert my_solution.longestValidSubstring(**test_input) == 0\n\ntest_input = { \"word\": \"s\", \"forbidden\": [\"m\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"s\", \"forbidden\": [\"x\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"s\", \"forbidden\": [\"s\"] }\nassert my_solution.longestValidSubstring(**test_input) == 0\n\ntest_input = { \"word\": \"t\", \"forbidden\": [\"v\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"t\", \"forbidden\": [\"m\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"t\", \"forbidden\": [\"t\"] }\nassert my_solution.longestValidSubstring(**test_input) == 0\n\ntest_input = { \"word\": \"u\", \"forbidden\": [\"l\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"u\", \"forbidden\": [\"n\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"u\", \"forbidden\": [\"u\"] }\nassert my_solution.longestValidSubstring(**test_input) == 0\n\ntest_input = { \"word\": \"v\", \"forbidden\": [\"o\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"v\", \"forbidden\": [\"v\"] }\nassert my_solution.longestValidSubstring(**test_input) == 0\n\ntest_input = { \"word\": \"w\", \"forbidden\": [\"w\"] }\nassert my_solution.longestValidSubstring(**test_input) == 0\n\ntest_input = { \"word\": \"w\", \"forbidden\": [\"s\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"x\", \"forbidden\": [\"r\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"x\", \"forbidden\": [\"q\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"x\", \"forbidden\": [\"x\"] }\nassert my_solution.longestValidSubstring(**test_input) == 0\n\ntest_input = { \"word\": \"y\", \"forbidden\": [\"w\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"y\", \"forbidden\": [\"t\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"y\", \"forbidden\": [\"y\"] }\nassert my_solution.longestValidSubstring(**test_input) == 0\n\ntest_input = { \"word\": \"z\", \"forbidden\": [\"l\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"z\", \"forbidden\": [\"o\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"z\", \"forbidden\": [\"z\"] }\nassert my_solution.longestValidSubstring(**test_input) == 0\n\ntest_input = { \"word\": \"acbc\", \"forbidden\": [\"cbc\",\"acb\",\"acb\",\"acbc\"] }\nassert my_solution.longestValidSubstring(**test_input) == 2\n\ntest_input = { \"word\": \"cabba\", \"forbidden\": [\"aaba\",\"abba\",\"acabb\",\"cabb\"] }\nassert my_solution.longestValidSubstring(**test_input) == 3\n\ntest_input = { \"word\": \"bbc\", \"forbidden\": [\"baba\",\"babc\",\"bbc\",\"bbc\"] }\nassert my_solution.longestValidSubstring(**test_input) == 2\n\ntest_input = { \"word\": \"acb\", \"forbidden\": [\"acb\",\"caccc\",\"baaab\",\"baa\"] }\nassert my_solution.longestValidSubstring(**test_input) == 2\n\ntest_input = { \"word\": \"aaac\", \"forbidden\": [\"aaac\",\"aac\",\"aaa\",\"aaac\"] }\nassert my_solution.longestValidSubstring(**test_input) == 2\n\ntest_input = { \"word\": \"ca\", \"forbidden\": [\"ababa\",\"ca\",\"caac\",\"babb\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"babbb\", \"forbidden\": [\"bbb\",\"aacb\",\"babbb\",\"bcab\"] }\nassert my_solution.longestValidSubstring(**test_input) == 4\n\ntest_input = { \"word\": \"cbbba\", \"forbidden\": [\"bca\",\"cbbba\",\"acbcc\",\"aabb\"] }\nassert my_solution.longestValidSubstring(**test_input) == 4\n\ntest_input = { \"word\": \"abab\", \"forbidden\": [\"aab\",\"abab\",\"cacb\",\"bab\"] }\nassert my_solution.longestValidSubstring(**test_input) == 3\n\ntest_input = { \"word\": \"cbab\", \"forbidden\": [\"bbcc\",\"aaccc\",\"cbab\",\"babca\"] }\nassert my_solution.longestValidSubstring(**test_input) == 3\n\ntest_input = { \"word\": \"caaa\", \"forbidden\": [\"aaa\",\"cbb\",\"aaa\",\"caaa\"] }\nassert my_solution.longestValidSubstring(**test_input) == 3\n\ntest_input = { \"word\": \"baa\", \"forbidden\": [\"aaab\",\"bbaa\",\"babac\",\"baa\"] }\nassert my_solution.longestValidSubstring(**test_input) == 2\n\ntest_input = { \"word\": \"cbcc\", \"forbidden\": [\"cbcc\",\"baa\",\"bbba\",\"cac\"] }\nassert my_solution.longestValidSubstring(**test_input) == 3\n\ntest_input = { \"word\": \"cac\", \"forbidden\": [\"cccaa\",\"baaca\",\"cac\",\"cac\"] }\nassert my_solution.longestValidSubstring(**test_input) == 2\n\ntest_input = { \"word\": \"cabab\", \"forbidden\": [\"cabab\",\"abab\",\"cabab\",\"abab\"] }\nassert my_solution.longestValidSubstring(**test_input) == 4\n\ntest_input = { \"word\": \"caa\", \"forbidden\": [\"caa\",\"bba\",\"acc\",\"bcabb\"] }\nassert my_solution.longestValidSubstring(**test_input) == 2\n\ntest_input = { \"word\": \"ba\", \"forbidden\": [\"ba\",\"ba\",\"cab\",\"cbcac\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"bbc\", \"forbidden\": [\"baca\",\"bbc\",\"bbc\",\"caa\"] }\nassert my_solution.longestValidSubstring(**test_input) == 2\n\ntest_input = { \"word\": \"bbb\", \"forbidden\": [\"cbaab\",\"bbb\",\"bbb\",\"bab\"] }\nassert my_solution.longestValidSubstring(**test_input) == 2\n\ntest_input = { \"word\": \"bbccc\", \"forbidden\": [\"ccc\",\"bcba\",\"bcc\",\"bcc\"] }\nassert my_solution.longestValidSubstring(**test_input) == 3\n\ntest_input = { \"word\": \"bcac\", \"forbidden\": [\"bcac\",\"caca\",\"bcac\",\"bca\"] }\nassert my_solution.longestValidSubstring(**test_input) == 3\n\ntest_input = { \"word\": \"ab\", \"forbidden\": [\"aca\",\"cabcc\",\"caba\",\"ab\"] }\nassert my_solution.longestValidSubstring(**test_input) == 1\n\ntest_input = { \"word\": \"caa\", \"forbidden\": [\"bab\",\"babbb\",\"abbaa\",\"caa\"] }\nassert my_solution.longestValidSubstring(**test_input) == 2", "start_time": 1689474600} +{"task_id": "weekly-contest-353-find-the-maximum-achievable-number", "url": "https://leetcode.com/problems/find-the-maximum-achievable-number", "title": "find-the-maximum-achievable-number", "meta": {"questionId": "2812", "questionFrontendId": "2769", "title": "Find the Maximum Achievable Number", "titleSlug": "find-the-maximum-achievable-number", "isPaidOnly": false, "difficulty": "Easy", "likes": 230, "dislikes": 286, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given two integers, num and t.\n\nAn integer x is called achievable if it can become equal to num after applying the following operation no more than t times:\n\n * Increase or decrease x by 1, and simultaneously increase or decrease num by 1.\n\nReturn the maximum possible achievable number. It can be proven that there exists at least one achievable number.\n\nExample 1:\n\nInput: num = 4, t = 1\nOutput: 6\nExplanation: The maximum achievable number is x = 6; it can become equal to num after performing this operation:\n1- Decrease x by 1, and increase num by 1. Now, x = 5 and num = 5.\nIt can be proven that there is no achievable number larger than 6.\n\nExample 2:\n\nInput: num = 3, t = 2\nOutput: 7\nExplanation: The maximum achievable number is x = 7; after performing these operations, x will equal num:\n1- Decrease x by 1, and increase num by 1. Now, x = 6 and num = 4.\n2- Decrease x by 1, and increase num by 1. Now, x = 5 and num = 5.\nIt can be proven that there is no achievable number larger than 7.\n\n\nConstraints:\n\n * 1 <= num, t <= 50\n\"\"\"\nclass Solution:\n def theMaximumAchievableX(self, num: int, t: int) -> int:\n ", "prompt_sft": "You are given two integers, num and t.\n\nAn integer x is called achievable if it can become equal to num after applying the following operation no more than t times:\n\n * Increase or decrease x by 1, and simultaneously increase or decrease num by 1.\n\nReturn the maximum possible achievable number. It can be proven that there exists at least one achievable number.\n\nExample 1:\n\nInput: num = 4, t = 1\nOutput: 6\nExplanation: The maximum achievable number is x = 6; it can become equal to num after performing this operation:\n1- Decrease x by 1, and increase num by 1. Now, x = 5 and num = 5.\nIt can be proven that there is no achievable number larger than 6.\n\nExample 2:\n\nInput: num = 3, t = 2\nOutput: 7\nExplanation: The maximum achievable number is x = 7; after performing these operations, x will equal num:\n1- Decrease x by 1, and increase num by 1. Now, x = 6 and num = 4.\n2- Decrease x by 1, and increase num by 1. Now, x = 5 and num = 5.\nIt can be proven that there is no achievable number larger than 7.\n\n\nConstraints:\n\n * 1 <= num, t <= 50\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def theMaximumAchievableX(self, num: int, t: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"num\": 4, \"t\": 1 }\nassert my_solution.theMaximumAchievableX(**test_input) == 6\n\ntest_input = { \"num\": 3, \"t\": 2 }\nassert my_solution.theMaximumAchievableX(**test_input) == 7\n\ntest_input = { \"num\": 1, \"t\": 1 }\nassert my_solution.theMaximumAchievableX(**test_input) == 3\n\ntest_input = { \"num\": 1, \"t\": 2 }\nassert my_solution.theMaximumAchievableX(**test_input) == 5\n\ntest_input = { \"num\": 1, \"t\": 3 }\nassert my_solution.theMaximumAchievableX(**test_input) == 7\n\ntest_input = { \"num\": 1, \"t\": 4 }\nassert my_solution.theMaximumAchievableX(**test_input) == 9\n\ntest_input = { \"num\": 1, \"t\": 5 }\nassert my_solution.theMaximumAchievableX(**test_input) == 11\n\ntest_input = { \"num\": 1, \"t\": 6 }\nassert my_solution.theMaximumAchievableX(**test_input) == 13\n\ntest_input = { \"num\": 1, \"t\": 7 }\nassert my_solution.theMaximumAchievableX(**test_input) == 15\n\ntest_input = { \"num\": 1, \"t\": 8 }\nassert my_solution.theMaximumAchievableX(**test_input) == 17\n\ntest_input = { \"num\": 1, \"t\": 9 }\nassert my_solution.theMaximumAchievableX(**test_input) == 19\n\ntest_input = { \"num\": 1, \"t\": 10 }\nassert my_solution.theMaximumAchievableX(**test_input) == 21\n\ntest_input = { \"num\": 1, \"t\": 11 }\nassert my_solution.theMaximumAchievableX(**test_input) == 23\n\ntest_input = { \"num\": 1, \"t\": 12 }\nassert my_solution.theMaximumAchievableX(**test_input) == 25\n\ntest_input = { \"num\": 1, \"t\": 13 }\nassert my_solution.theMaximumAchievableX(**test_input) == 27\n\ntest_input = { \"num\": 1, \"t\": 14 }\nassert my_solution.theMaximumAchievableX(**test_input) == 29\n\ntest_input = { \"num\": 1, \"t\": 15 }\nassert my_solution.theMaximumAchievableX(**test_input) == 31\n\ntest_input = { \"num\": 1, \"t\": 16 }\nassert my_solution.theMaximumAchievableX(**test_input) == 33\n\ntest_input = { \"num\": 1, \"t\": 17 }\nassert my_solution.theMaximumAchievableX(**test_input) == 35\n\ntest_input = { \"num\": 1, \"t\": 18 }\nassert my_solution.theMaximumAchievableX(**test_input) == 37\n\ntest_input = { \"num\": 1, \"t\": 19 }\nassert my_solution.theMaximumAchievableX(**test_input) == 39\n\ntest_input = { \"num\": 1, \"t\": 20 }\nassert my_solution.theMaximumAchievableX(**test_input) == 41\n\ntest_input = { \"num\": 1, \"t\": 21 }\nassert my_solution.theMaximumAchievableX(**test_input) == 43\n\ntest_input = { \"num\": 1, \"t\": 22 }\nassert my_solution.theMaximumAchievableX(**test_input) == 45\n\ntest_input = { \"num\": 1, \"t\": 23 }\nassert my_solution.theMaximumAchievableX(**test_input) == 47\n\ntest_input = { \"num\": 1, \"t\": 24 }\nassert my_solution.theMaximumAchievableX(**test_input) == 49\n\ntest_input = { \"num\": 1, \"t\": 25 }\nassert my_solution.theMaximumAchievableX(**test_input) == 51\n\ntest_input = { \"num\": 1, \"t\": 26 }\nassert my_solution.theMaximumAchievableX(**test_input) == 53\n\ntest_input = { \"num\": 1, \"t\": 27 }\nassert my_solution.theMaximumAchievableX(**test_input) == 55\n\ntest_input = { \"num\": 1, \"t\": 28 }\nassert my_solution.theMaximumAchievableX(**test_input) == 57\n\ntest_input = { \"num\": 1, \"t\": 29 }\nassert my_solution.theMaximumAchievableX(**test_input) == 59\n\ntest_input = { \"num\": 1, \"t\": 30 }\nassert my_solution.theMaximumAchievableX(**test_input) == 61\n\ntest_input = { \"num\": 1, \"t\": 31 }\nassert my_solution.theMaximumAchievableX(**test_input) == 63\n\ntest_input = { \"num\": 1, \"t\": 32 }\nassert my_solution.theMaximumAchievableX(**test_input) == 65\n\ntest_input = { \"num\": 1, \"t\": 33 }\nassert my_solution.theMaximumAchievableX(**test_input) == 67\n\ntest_input = { \"num\": 1, \"t\": 34 }\nassert my_solution.theMaximumAchievableX(**test_input) == 69\n\ntest_input = { \"num\": 1, \"t\": 35 }\nassert my_solution.theMaximumAchievableX(**test_input) == 71\n\ntest_input = { \"num\": 1, \"t\": 36 }\nassert my_solution.theMaximumAchievableX(**test_input) == 73\n\ntest_input = { \"num\": 1, \"t\": 37 }\nassert my_solution.theMaximumAchievableX(**test_input) == 75\n\ntest_input = { \"num\": 1, \"t\": 38 }\nassert my_solution.theMaximumAchievableX(**test_input) == 77\n\ntest_input = { \"num\": 1, \"t\": 39 }\nassert my_solution.theMaximumAchievableX(**test_input) == 79\n\ntest_input = { \"num\": 1, \"t\": 40 }\nassert my_solution.theMaximumAchievableX(**test_input) == 81\n\ntest_input = { \"num\": 1, \"t\": 41 }\nassert my_solution.theMaximumAchievableX(**test_input) == 83\n\ntest_input = { \"num\": 1, \"t\": 42 }\nassert my_solution.theMaximumAchievableX(**test_input) == 85\n\ntest_input = { \"num\": 1, \"t\": 43 }\nassert my_solution.theMaximumAchievableX(**test_input) == 87\n\ntest_input = { \"num\": 1, \"t\": 44 }\nassert my_solution.theMaximumAchievableX(**test_input) == 89\n\ntest_input = { \"num\": 1, \"t\": 45 }\nassert my_solution.theMaximumAchievableX(**test_input) == 91\n\ntest_input = { \"num\": 1, \"t\": 46 }\nassert my_solution.theMaximumAchievableX(**test_input) == 93\n\ntest_input = { \"num\": 1, \"t\": 47 }\nassert my_solution.theMaximumAchievableX(**test_input) == 95\n\ntest_input = { \"num\": 1, \"t\": 48 }\nassert my_solution.theMaximumAchievableX(**test_input) == 97\n\ntest_input = { \"num\": 1, \"t\": 49 }\nassert my_solution.theMaximumAchievableX(**test_input) == 99\n\ntest_input = { \"num\": 1, \"t\": 50 }\nassert my_solution.theMaximumAchievableX(**test_input) == 101\n\ntest_input = { \"num\": 2, \"t\": 1 }\nassert my_solution.theMaximumAchievableX(**test_input) == 4\n\ntest_input = { \"num\": 2, \"t\": 2 }\nassert my_solution.theMaximumAchievableX(**test_input) == 6\n\ntest_input = { \"num\": 2, \"t\": 3 }\nassert my_solution.theMaximumAchievableX(**test_input) == 8\n\ntest_input = { \"num\": 2, \"t\": 4 }\nassert my_solution.theMaximumAchievableX(**test_input) == 10\n\ntest_input = { \"num\": 2, \"t\": 5 }\nassert my_solution.theMaximumAchievableX(**test_input) == 12\n\ntest_input = { \"num\": 2, \"t\": 6 }\nassert my_solution.theMaximumAchievableX(**test_input) == 14\n\ntest_input = { \"num\": 2, \"t\": 7 }\nassert my_solution.theMaximumAchievableX(**test_input) == 16\n\ntest_input = { \"num\": 2, \"t\": 8 }\nassert my_solution.theMaximumAchievableX(**test_input) == 18\n\ntest_input = { \"num\": 2, \"t\": 9 }\nassert my_solution.theMaximumAchievableX(**test_input) == 20\n\ntest_input = { \"num\": 2, \"t\": 10 }\nassert my_solution.theMaximumAchievableX(**test_input) == 22\n\ntest_input = { \"num\": 2, \"t\": 11 }\nassert my_solution.theMaximumAchievableX(**test_input) == 24\n\ntest_input = { \"num\": 2, \"t\": 12 }\nassert my_solution.theMaximumAchievableX(**test_input) == 26\n\ntest_input = { \"num\": 2, \"t\": 13 }\nassert my_solution.theMaximumAchievableX(**test_input) == 28\n\ntest_input = { \"num\": 2, \"t\": 14 }\nassert my_solution.theMaximumAchievableX(**test_input) == 30\n\ntest_input = { \"num\": 2, \"t\": 15 }\nassert my_solution.theMaximumAchievableX(**test_input) == 32\n\ntest_input = { \"num\": 2, \"t\": 16 }\nassert my_solution.theMaximumAchievableX(**test_input) == 34\n\ntest_input = { \"num\": 2, \"t\": 17 }\nassert my_solution.theMaximumAchievableX(**test_input) == 36\n\ntest_input = { \"num\": 2, \"t\": 18 }\nassert my_solution.theMaximumAchievableX(**test_input) == 38\n\ntest_input = { \"num\": 2, \"t\": 19 }\nassert my_solution.theMaximumAchievableX(**test_input) == 40\n\ntest_input = { \"num\": 2, \"t\": 20 }\nassert my_solution.theMaximumAchievableX(**test_input) == 42\n\ntest_input = { \"num\": 2, \"t\": 21 }\nassert my_solution.theMaximumAchievableX(**test_input) == 44\n\ntest_input = { \"num\": 2, \"t\": 22 }\nassert my_solution.theMaximumAchievableX(**test_input) == 46\n\ntest_input = { \"num\": 2, \"t\": 23 }\nassert my_solution.theMaximumAchievableX(**test_input) == 48\n\ntest_input = { \"num\": 2, \"t\": 24 }\nassert my_solution.theMaximumAchievableX(**test_input) == 50\n\ntest_input = { \"num\": 2, \"t\": 25 }\nassert my_solution.theMaximumAchievableX(**test_input) == 52\n\ntest_input = { \"num\": 2, \"t\": 26 }\nassert my_solution.theMaximumAchievableX(**test_input) == 54\n\ntest_input = { \"num\": 2, \"t\": 27 }\nassert my_solution.theMaximumAchievableX(**test_input) == 56\n\ntest_input = { \"num\": 2, \"t\": 28 }\nassert my_solution.theMaximumAchievableX(**test_input) == 58\n\ntest_input = { \"num\": 2, \"t\": 29 }\nassert my_solution.theMaximumAchievableX(**test_input) == 60\n\ntest_input = { \"num\": 2, \"t\": 30 }\nassert my_solution.theMaximumAchievableX(**test_input) == 62\n\ntest_input = { \"num\": 2, \"t\": 31 }\nassert my_solution.theMaximumAchievableX(**test_input) == 64\n\ntest_input = { \"num\": 2, \"t\": 32 }\nassert my_solution.theMaximumAchievableX(**test_input) == 66\n\ntest_input = { \"num\": 2, \"t\": 33 }\nassert my_solution.theMaximumAchievableX(**test_input) == 68\n\ntest_input = { \"num\": 2, \"t\": 34 }\nassert my_solution.theMaximumAchievableX(**test_input) == 70\n\ntest_input = { \"num\": 2, \"t\": 35 }\nassert my_solution.theMaximumAchievableX(**test_input) == 72\n\ntest_input = { \"num\": 2, \"t\": 36 }\nassert my_solution.theMaximumAchievableX(**test_input) == 74\n\ntest_input = { \"num\": 2, \"t\": 37 }\nassert my_solution.theMaximumAchievableX(**test_input) == 76\n\ntest_input = { \"num\": 2, \"t\": 38 }\nassert my_solution.theMaximumAchievableX(**test_input) == 78\n\ntest_input = { \"num\": 2, \"t\": 39 }\nassert my_solution.theMaximumAchievableX(**test_input) == 80\n\ntest_input = { \"num\": 2, \"t\": 40 }\nassert my_solution.theMaximumAchievableX(**test_input) == 82\n\ntest_input = { \"num\": 2, \"t\": 41 }\nassert my_solution.theMaximumAchievableX(**test_input) == 84\n\ntest_input = { \"num\": 2, \"t\": 42 }\nassert my_solution.theMaximumAchievableX(**test_input) == 86\n\ntest_input = { \"num\": 2, \"t\": 43 }\nassert my_solution.theMaximumAchievableX(**test_input) == 88\n\ntest_input = { \"num\": 2, \"t\": 44 }\nassert my_solution.theMaximumAchievableX(**test_input) == 90\n\ntest_input = { \"num\": 2, \"t\": 45 }\nassert my_solution.theMaximumAchievableX(**test_input) == 92\n\ntest_input = { \"num\": 2, \"t\": 46 }\nassert my_solution.theMaximumAchievableX(**test_input) == 94\n\ntest_input = { \"num\": 2, \"t\": 47 }\nassert my_solution.theMaximumAchievableX(**test_input) == 96\n\ntest_input = { \"num\": 2, \"t\": 48 }\nassert my_solution.theMaximumAchievableX(**test_input) == 98", "start_time": 1688869800} +{"task_id": "weekly-contest-353-maximum-number-of-jumps-to-reach-the-last-index", "url": "https://leetcode.com/problems/maximum-number-of-jumps-to-reach-the-last-index", "title": "maximum-number-of-jumps-to-reach-the-last-index", "meta": {"questionId": "2855", "questionFrontendId": "2770", "title": "Maximum Number of Jumps to Reach the Last Index", "titleSlug": "maximum-number-of-jumps-to-reach-the-last-index", "isPaidOnly": false, "difficulty": "Medium", "likes": 356, "dislikes": 10, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed array nums of n integers and an integer target.\n\nYou are initially positioned at index 0. In one step, you can jump from index i to any index j such that:\n\n * 0 <= i < j < n\n * -target <= nums[j] - nums[i] <= target\n\nReturn the maximum number of jumps you can make to reach index n - 1.\n\nIf there is no way to reach index n - 1, return -1.\n\nExample 1:\n\nInput: nums = [1,3,6,4,1,2], target = 2\nOutput: 3\nExplanation: To go from index 0 to index n - 1 with the maximum number of jumps, you can perform the following jumping sequence:\n- Jump from index 0 to index 1.\n- Jump from index 1 to index 3.\n- Jump from index 3 to index 5.\nIt can be proven that there is no other jumping sequence that goes from 0 to n - 1 with more than 3 jumps. Hence, the answer is 3.\n\nExample 2:\n\nInput: nums = [1,3,6,4,1,2], target = 3\nOutput: 5\nExplanation: To go from index 0 to index n - 1 with the maximum number of jumps, you can perform the following jumping sequence:\n- Jump from index 0 to index 1.\n- Jump from index 1 to index 2.\n- Jump from index 2 to index 3.\n- Jump from index 3 to index 4.\n- Jump from index 4 to index 5.\nIt can be proven that there is no other jumping sequence that goes from 0 to n - 1 with more than 5 jumps. Hence, the answer is 5.\n\nExample 3:\n\nInput: nums = [1,3,6,4,1,2], target = 0\nOutput: -1\nExplanation: It can be proven that there is no jumping sequence that goes from 0 to n - 1. Hence, the answer is -1.\n\n\nConstraints:\n\n * 2 <= nums.length == n <= 1000\n * -109 <= nums[i] <= 109\n * 0 <= target <= 2 * 109\n\"\"\"\nclass Solution:\n def maximumJumps(self, nums: List[int], target: int) -> int:\n ", "prompt_sft": "You are given a 0-indexed array nums of n integers and an integer target.\n\nYou are initially positioned at index 0. In one step, you can jump from index i to any index j such that:\n\n * 0 <= i < j < n\n * -target <= nums[j] - nums[i] <= target\n\nReturn the maximum number of jumps you can make to reach index n - 1.\n\nIf there is no way to reach index n - 1, return -1.\n\nExample 1:\n\nInput: nums = [1,3,6,4,1,2], target = 2\nOutput: 3\nExplanation: To go from index 0 to index n - 1 with the maximum number of jumps, you can perform the following jumping sequence:\n- Jump from index 0 to index 1.\n- Jump from index 1 to index 3.\n- Jump from index 3 to index 5.\nIt can be proven that there is no other jumping sequence that goes from 0 to n - 1 with more than 3 jumps. Hence, the answer is 3.\n\nExample 2:\n\nInput: nums = [1,3,6,4,1,2], target = 3\nOutput: 5\nExplanation: To go from index 0 to index n - 1 with the maximum number of jumps, you can perform the following jumping sequence:\n- Jump from index 0 to index 1.\n- Jump from index 1 to index 2.\n- Jump from index 2 to index 3.\n- Jump from index 3 to index 4.\n- Jump from index 4 to index 5.\nIt can be proven that there is no other jumping sequence that goes from 0 to n - 1 with more than 5 jumps. Hence, the answer is 5.\n\nExample 3:\n\nInput: nums = [1,3,6,4,1,2], target = 0\nOutput: -1\nExplanation: It can be proven that there is no jumping sequence that goes from 0 to n - 1. Hence, the answer is -1.\n\n\nConstraints:\n\n * 2 <= nums.length == n <= 1000\n * -109 <= nums[i] <= 109\n * 0 <= target <= 2 * 109\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def maximumJumps(self, nums: List[int], target: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,3,6,4,1,2], \"target\": 2 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [1,3,6,4,1,2], \"target\": 3 }\nassert my_solution.maximumJumps(**test_input) == 5\n\ntest_input = { \"nums\": [1,3,6,4,1,2], \"target\": 0 }\nassert my_solution.maximumJumps(**test_input) == -1\n\ntest_input = { \"nums\": [0,1], \"target\": 0 }\nassert my_solution.maximumJumps(**test_input) == -1\n\ntest_input = { \"nums\": [0,1], \"target\": 1 }\nassert my_solution.maximumJumps(**test_input) == 1\n\ntest_input = { \"nums\": [0,1], \"target\": 2 }\nassert my_solution.maximumJumps(**test_input) == 1\n\ntest_input = { \"nums\": [1,0], \"target\": 0 }\nassert my_solution.maximumJumps(**test_input) == -1\n\ntest_input = { \"nums\": [1,0], \"target\": 1 }\nassert my_solution.maximumJumps(**test_input) == 1\n\ntest_input = { \"nums\": [1,0], \"target\": 2 }\nassert my_solution.maximumJumps(**test_input) == 1\n\ntest_input = { \"nums\": [0,1,2], \"target\": 0 }\nassert my_solution.maximumJumps(**test_input) == -1\n\ntest_input = { \"nums\": [0,1,2], \"target\": 1 }\nassert my_solution.maximumJumps(**test_input) == 2\n\ntest_input = { \"nums\": [0,1,2], \"target\": 2 }\nassert my_solution.maximumJumps(**test_input) == 2\n\ntest_input = { \"nums\": [0,1,2], \"target\": 3 }\nassert my_solution.maximumJumps(**test_input) == 2\n\ntest_input = { \"nums\": [0,2,1], \"target\": 0 }\nassert my_solution.maximumJumps(**test_input) == -1\n\ntest_input = { \"nums\": [0,2,1], \"target\": 1 }\nassert my_solution.maximumJumps(**test_input) == 1\n\ntest_input = { \"nums\": [0,2,1], \"target\": 2 }\nassert my_solution.maximumJumps(**test_input) == 2\n\ntest_input = { \"nums\": [0,2,1], \"target\": 3 }\nassert my_solution.maximumJumps(**test_input) == 2\n\ntest_input = { \"nums\": [1,0,2], \"target\": 0 }\nassert my_solution.maximumJumps(**test_input) == -1\n\ntest_input = { \"nums\": [1,0,2], \"target\": 1 }\nassert my_solution.maximumJumps(**test_input) == 1\n\ntest_input = { \"nums\": [1,0,2], \"target\": 2 }\nassert my_solution.maximumJumps(**test_input) == 2\n\ntest_input = { \"nums\": [1,0,2], \"target\": 3 }\nassert my_solution.maximumJumps(**test_input) == 2\n\ntest_input = { \"nums\": [1,2,0], \"target\": 0 }\nassert my_solution.maximumJumps(**test_input) == -1\n\ntest_input = { \"nums\": [1,2,0], \"target\": 1 }\nassert my_solution.maximumJumps(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,0], \"target\": 2 }\nassert my_solution.maximumJumps(**test_input) == 2\n\ntest_input = { \"nums\": [1,2,0], \"target\": 3 }\nassert my_solution.maximumJumps(**test_input) == 2\n\ntest_input = { \"nums\": [2,0,1], \"target\": 0 }\nassert my_solution.maximumJumps(**test_input) == -1\n\ntest_input = { \"nums\": [2,0,1], \"target\": 1 }\nassert my_solution.maximumJumps(**test_input) == 1\n\ntest_input = { \"nums\": [2,0,1], \"target\": 2 }\nassert my_solution.maximumJumps(**test_input) == 2\n\ntest_input = { \"nums\": [2,0,1], \"target\": 3 }\nassert my_solution.maximumJumps(**test_input) == 2\n\ntest_input = { \"nums\": [2,1,0], \"target\": 0 }\nassert my_solution.maximumJumps(**test_input) == -1\n\ntest_input = { \"nums\": [2,1,0], \"target\": 1 }\nassert my_solution.maximumJumps(**test_input) == 2\n\ntest_input = { \"nums\": [2,1,0], \"target\": 2 }\nassert my_solution.maximumJumps(**test_input) == 2\n\ntest_input = { \"nums\": [2,1,0], \"target\": 3 }\nassert my_solution.maximumJumps(**test_input) == 2\n\ntest_input = { \"nums\": [0,1,2,3], \"target\": 0 }\nassert my_solution.maximumJumps(**test_input) == -1\n\ntest_input = { \"nums\": [0,1,2,3], \"target\": 1 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [0,1,2,3], \"target\": 2 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [0,1,2,3], \"target\": 3 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [0,1,2,3], \"target\": 4 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [0,1,3,2], \"target\": 0 }\nassert my_solution.maximumJumps(**test_input) == -1\n\ntest_input = { \"nums\": [0,1,3,2], \"target\": 1 }\nassert my_solution.maximumJumps(**test_input) == 2\n\ntest_input = { \"nums\": [0,1,3,2], \"target\": 2 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [0,1,3,2], \"target\": 3 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [0,1,3,2], \"target\": 4 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [0,2,1,3], \"target\": 0 }\nassert my_solution.maximumJumps(**test_input) == -1\n\ntest_input = { \"nums\": [0,2,1,3], \"target\": 1 }\nassert my_solution.maximumJumps(**test_input) == -1\n\ntest_input = { \"nums\": [0,2,1,3], \"target\": 2 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [0,2,1,3], \"target\": 3 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [0,2,1,3], \"target\": 4 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [0,2,3,1], \"target\": 0 }\nassert my_solution.maximumJumps(**test_input) == -1\n\ntest_input = { \"nums\": [0,2,3,1], \"target\": 1 }\nassert my_solution.maximumJumps(**test_input) == 1\n\ntest_input = { \"nums\": [0,2,3,1], \"target\": 2 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [0,2,3,1], \"target\": 3 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [0,2,3,1], \"target\": 4 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [0,3,1,2], \"target\": 0 }\nassert my_solution.maximumJumps(**test_input) == -1\n\ntest_input = { \"nums\": [0,3,1,2], \"target\": 1 }\nassert my_solution.maximumJumps(**test_input) == 2\n\ntest_input = { \"nums\": [0,3,1,2], \"target\": 2 }\nassert my_solution.maximumJumps(**test_input) == 2\n\ntest_input = { \"nums\": [0,3,1,2], \"target\": 3 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [0,3,1,2], \"target\": 4 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [0,3,2,1], \"target\": 0 }\nassert my_solution.maximumJumps(**test_input) == -1\n\ntest_input = { \"nums\": [0,3,2,1], \"target\": 1 }\nassert my_solution.maximumJumps(**test_input) == 1\n\ntest_input = { \"nums\": [0,3,2,1], \"target\": 2 }\nassert my_solution.maximumJumps(**test_input) == 2\n\ntest_input = { \"nums\": [0,3,2,1], \"target\": 3 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [0,3,2,1], \"target\": 4 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [1,0,2,3], \"target\": 0 }\nassert my_solution.maximumJumps(**test_input) == -1\n\ntest_input = { \"nums\": [1,0,2,3], \"target\": 1 }\nassert my_solution.maximumJumps(**test_input) == 2\n\ntest_input = { \"nums\": [1,0,2,3], \"target\": 2 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [1,0,2,3], \"target\": 3 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [1,0,2,3], \"target\": 4 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [1,0,3,2], \"target\": 0 }\nassert my_solution.maximumJumps(**test_input) == -1\n\ntest_input = { \"nums\": [1,0,3,2], \"target\": 1 }\nassert my_solution.maximumJumps(**test_input) == 1\n\ntest_input = { \"nums\": [1,0,3,2], \"target\": 2 }\nassert my_solution.maximumJumps(**test_input) == 2\n\ntest_input = { \"nums\": [1,0,3,2], \"target\": 3 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [1,0,3,2], \"target\": 4 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,0,3], \"target\": 0 }\nassert my_solution.maximumJumps(**test_input) == -1\n\ntest_input = { \"nums\": [1,2,0,3], \"target\": 1 }\nassert my_solution.maximumJumps(**test_input) == 2\n\ntest_input = { \"nums\": [1,2,0,3], \"target\": 2 }\nassert my_solution.maximumJumps(**test_input) == 2\n\ntest_input = { \"nums\": [1,2,0,3], \"target\": 3 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,0,3], \"target\": 4 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,3,0], \"target\": 0 }\nassert my_solution.maximumJumps(**test_input) == -1\n\ntest_input = { \"nums\": [1,2,3,0], \"target\": 1 }\nassert my_solution.maximumJumps(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,3,0], \"target\": 2 }\nassert my_solution.maximumJumps(**test_input) == 2\n\ntest_input = { \"nums\": [1,2,3,0], \"target\": 3 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,3,0], \"target\": 4 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [1,3,0,2], \"target\": 0 }\nassert my_solution.maximumJumps(**test_input) == -1\n\ntest_input = { \"nums\": [1,3,0,2], \"target\": 1 }\nassert my_solution.maximumJumps(**test_input) == 1\n\ntest_input = { \"nums\": [1,3,0,2], \"target\": 2 }\nassert my_solution.maximumJumps(**test_input) == 2\n\ntest_input = { \"nums\": [1,3,0,2], \"target\": 3 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [1,3,0,2], \"target\": 4 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [1,3,2,0], \"target\": 0 }\nassert my_solution.maximumJumps(**test_input) == -1\n\ntest_input = { \"nums\": [1,3,2,0], \"target\": 1 }\nassert my_solution.maximumJumps(**test_input) == 1\n\ntest_input = { \"nums\": [1,3,2,0], \"target\": 2 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [1,3,2,0], \"target\": 3 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [1,3,2,0], \"target\": 4 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [2,0,1,3], \"target\": 0 }\nassert my_solution.maximumJumps(**test_input) == -1\n\ntest_input = { \"nums\": [2,0,1,3], \"target\": 1 }\nassert my_solution.maximumJumps(**test_input) == 1\n\ntest_input = { \"nums\": [2,0,1,3], \"target\": 2 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [2,0,1,3], \"target\": 3 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [2,0,1,3], \"target\": 4 }\nassert my_solution.maximumJumps(**test_input) == 3\n\ntest_input = { \"nums\": [2,0,3,1], \"target\": 0 }\nassert my_solution.maximumJumps(**test_input) == -1\n\ntest_input = { \"nums\": [2,0,3,1], \"target\": 1 }\nassert my_solution.maximumJumps(**test_input) == 1", "start_time": 1688869800} +{"task_id": "weekly-contest-353-longest-non-decreasing-subarray-from-two-arrays", "url": "https://leetcode.com/problems/longest-non-decreasing-subarray-from-two-arrays", "title": "longest-non-decreasing-subarray-from-two-arrays", "meta": {"questionId": "2869", "questionFrontendId": "2771", "title": "Longest Non-decreasing Subarray From Two Arrays", "titleSlug": "longest-non-decreasing-subarray-from-two-arrays", "isPaidOnly": false, "difficulty": "Medium", "likes": 505, "dislikes": 10, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given two 0-indexed integer arrays nums1 and nums2 of length n.\n\nLet's define another 0-indexed integer array, nums3, of length n. For each index i in the range [0, n - 1], you can assign either nums1[i] or nums2[i] to nums3[i].\n\nYour task is to maximize the length of the longest non-decreasing subarray in nums3 by choosing its values optimally.\n\nReturn an integer representing the length of the longest non-decreasing subarray in nums3.\n\nNote: A subarray is a contiguous non-empty sequence of elements within an array.\n\nExample 1:\n\nInput: nums1 = [2,3,1], nums2 = [1,2,1]\nOutput: 2\nExplanation: One way to construct nums3 is:\nnums3 = [nums1[0], nums2[1], nums2[2]] => [2,2,1].\nThe subarray starting from index 0 and ending at index 1, [2,2], forms a non-decreasing subarray of length 2.\nWe can show that 2 is the maximum achievable length.\n\nExample 2:\n\nInput: nums1 = [1,3,2,1], nums2 = [2,2,3,4]\nOutput: 4\nExplanation: One way to construct nums3 is:\nnums3 = [nums1[0], nums2[1], nums2[2], nums2[3]] => [1,2,3,4].\nThe entire array forms a non-decreasing subarray of length 4, making it the maximum achievable length.\n\nExample 3:\n\nInput: nums1 = [1,1], nums2 = [2,2]\nOutput: 2\nExplanation: One way to construct nums3 is:\nnums3 = [nums1[0], nums1[1]] => [1,1].\nThe entire array forms a non-decreasing subarray of length 2, making it the maximum achievable length.\n\n\nConstraints:\n\n * 1 <= nums1.length == nums2.length == n <= 105\n * 1 <= nums1[i], nums2[i] <= 109\n\"\"\"\nclass Solution:\n def maxNonDecreasingLength(self, nums1: List[int], nums2: List[int]) -> int:\n ", "prompt_sft": "You are given two 0-indexed integer arrays nums1 and nums2 of length n.\n\nLet's define another 0-indexed integer array, nums3, of length n. For each index i in the range [0, n - 1], you can assign either nums1[i] or nums2[i] to nums3[i].\n\nYour task is to maximize the length of the longest non-decreasing subarray in nums3 by choosing its values optimally.\n\nReturn an integer representing the length of the longest non-decreasing subarray in nums3.\n\nNote: A subarray is a contiguous non-empty sequence of elements within an array.\n\nExample 1:\n\nInput: nums1 = [2,3,1], nums2 = [1,2,1]\nOutput: 2\nExplanation: One way to construct nums3 is:\nnums3 = [nums1[0], nums2[1], nums2[2]] => [2,2,1].\nThe subarray starting from index 0 and ending at index 1, [2,2], forms a non-decreasing subarray of length 2.\nWe can show that 2 is the maximum achievable length.\n\nExample 2:\n\nInput: nums1 = [1,3,2,1], nums2 = [2,2,3,4]\nOutput: 4\nExplanation: One way to construct nums3 is:\nnums3 = [nums1[0], nums2[1], nums2[2], nums2[3]] => [1,2,3,4].\nThe entire array forms a non-decreasing subarray of length 4, making it the maximum achievable length.\n\nExample 3:\n\nInput: nums1 = [1,1], nums2 = [2,2]\nOutput: 2\nExplanation: One way to construct nums3 is:\nnums3 = [nums1[0], nums1[1]] => [1,1].\nThe entire array forms a non-decreasing subarray of length 2, making it the maximum achievable length.\n\n\nConstraints:\n\n * 1 <= nums1.length == nums2.length == n <= 105\n * 1 <= nums1[i], nums2[i] <= 109\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def maxNonDecreasingLength(self, nums1: List[int], nums2: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums1\": [2,3,1], \"nums2\": [1,2,1] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [1,3,2,1], \"nums2\": [2,2,3,4] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 4\n\ntest_input = { \"nums1\": [1,1], \"nums2\": [2,2] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [1], \"nums2\": [1] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 1\n\ntest_input = { \"nums1\": [1], \"nums2\": [2] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 1\n\ntest_input = { \"nums1\": [1,4], \"nums2\": [4,19] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [1,8], \"nums2\": [10,1] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [1,11], \"nums2\": [9,1] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [1,13], \"nums2\": [18,1] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [1,19], \"nums2\": [12,20] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [1,19], \"nums2\": [18,9] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [2,20], \"nums2\": [1,18] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [3,5], \"nums2\": [13,3] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [3,6], \"nums2\": [10,12] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [3,7], \"nums2\": [8,3] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [3,8], \"nums2\": [15,2] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [3,9], \"nums2\": [11,3] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [3,12], \"nums2\": [7,3] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [3,12], \"nums2\": [20,3] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [3,20], \"nums2\": [5,17] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [4,2], \"nums2\": [10,4] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [4,12], \"nums2\": [6,4] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [4,15], \"nums2\": [3,3] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [5,5], \"nums2\": [19,8] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [5,7], \"nums2\": [19,5] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [5,11], \"nums2\": [2,5] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [5,14], \"nums2\": [8,3] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [5,15], \"nums2\": [16,5] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [5,20], \"nums2\": [4,5] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [5,20], \"nums2\": [10,17] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [6,7], \"nums2\": [3,2] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [6,14], \"nums2\": [5,5] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [6,14], \"nums2\": [18,6] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [6,16], \"nums2\": [16,20] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [6,17], \"nums2\": [4,20] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [7,3], \"nums2\": [16,7] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [7,4], \"nums2\": [15,7] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [7,9], \"nums2\": [3,18] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [7,10], \"nums2\": [10,14] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [7,11], \"nums2\": [5,7] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [7,12], \"nums2\": [20,5] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [7,20], \"nums2\": [12,8] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [8,5], \"nums2\": [13,8] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [8,11], \"nums2\": [9,3] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [8,16], \"nums2\": [9,8] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [8,17], \"nums2\": [2,8] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [8,18], \"nums2\": [16,12] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [4,2], \"nums2\": [10,4] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [9,1], \"nums2\": [11,9] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [9,6], \"nums2\": [8,14] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [9,9], \"nums2\": [11,8] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [9,12], \"nums2\": [20,9] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [9,15], \"nums2\": [20,9] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [9,16], \"nums2\": [11,15] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [9,19], \"nums2\": [17,9] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [10,19], \"nums2\": [17,10] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [11,1], \"nums2\": [3,11] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [11,3], \"nums2\": [9,17] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [11,6], \"nums2\": [9,17] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [11,19], \"nums2\": [17,11] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [11,69], \"nums2\": [26,62] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [12,1], \"nums2\": [10,12] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [12,10], \"nums2\": [16,2] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 1\n\ntest_input = { \"nums1\": [13,6], \"nums2\": [20,13] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [13,16], \"nums2\": [5,13] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [14,2], \"nums2\": [2,14] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [14,4], \"nums2\": [2,13] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [15,10], \"nums2\": [17,15] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [15,11], \"nums2\": [19,2] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 1\n\ntest_input = { \"nums1\": [16,9], \"nums2\": [5,16] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [16,17], \"nums2\": [9,16] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [17,8], \"nums2\": [11,10] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 1\n\ntest_input = { \"nums1\": [17,10], \"nums2\": [9,17] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [17,10], \"nums2\": [18,7] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 1\n\ntest_input = { \"nums1\": [17,11], \"nums2\": [19,17] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [17,14], \"nums2\": [17,17] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [17,17], \"nums2\": [15,17] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [17,17], \"nums2\": [16,1] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [18,4], \"nums2\": [1,6] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [18,9], \"nums2\": [10,18] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [18,9], \"nums2\": [17,18] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [18,10], \"nums2\": [1,18] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [18,104], \"nums2\": [117,18] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [19,2], \"nums2\": [1,19] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [19,5], \"nums2\": [15,5] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 1\n\ntest_input = { \"nums1\": [19,5], \"nums2\": [52,10] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 1\n\ntest_input = { \"nums1\": [19,15], \"nums2\": [12,19] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [19,15], \"nums2\": [18,4] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 1\n\ntest_input = { \"nums1\": [20,1], \"nums2\": [1,20] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [20,5], \"nums2\": [2,3] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [20,5], \"nums2\": [14,8] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 1\n\ntest_input = { \"nums1\": [20,7], \"nums2\": [12,20] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [20,12], \"nums2\": [2,20] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [20,16], \"nums2\": [8,5] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [20,18], \"nums2\": [18,20] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [25,83], \"nums2\": [28,18] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [26,47], \"nums2\": [87,26] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [28,41], \"nums2\": [87,3] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [36,53], \"nums2\": [66,3] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2\n\ntest_input = { \"nums1\": [44,34], \"nums2\": [53,44] }\nassert my_solution.maxNonDecreasingLength(**test_input) == 2", "start_time": 1688869800} +{"task_id": "weekly-contest-353-apply-operations-to-make-all-array-elements-equal-to-zero", "url": "https://leetcode.com/problems/apply-operations-to-make-all-array-elements-equal-to-zero", "title": "apply-operations-to-make-all-array-elements-equal-to-zero", "meta": {"questionId": "2878", "questionFrontendId": "2772", "title": "Apply Operations to Make All Array Elements Equal to Zero", "titleSlug": "apply-operations-to-make-all-array-elements-equal-to-zero", "isPaidOnly": false, "difficulty": "Medium", "likes": 339, "dislikes": 19, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed integer array nums and a positive integer k.\n\nYou can apply the following operation on the array any number of times:\n\n * Choose any subarray of size k from the array and decrease all its elements by 1.\n\nReturn true if you can make all the array elements equal to 0, or false otherwise.\n\nA subarray is a contiguous non-empty part of an array.\n\nExample 1:\n\nInput: nums = [2,2,3,1,1,0], k = 3\nOutput: true\nExplanation: We can do the following operations:\n- Choose the subarray [2,2,3]. The resulting array will be nums = [1,1,2,1,1,0].\n- Choose the subarray [2,1,1]. The resulting array will be nums = [1,1,1,0,0,0].\n- Choose the subarray [1,1,1]. The resulting array will be nums = [0,0,0,0,0,0].\n\nExample 2:\n\nInput: nums = [1,3,1,1], k = 2\nOutput: false\nExplanation: It is not possible to make all the array elements equal to 0.\n\n\nConstraints:\n\n * 1 <= k <= nums.length <= 105\n * 0 <= nums[i] <= 106\n\"\"\"\nclass Solution:\n def checkArray(self, nums: List[int], k: int) -> bool:\n ", "prompt_sft": "You are given a 0-indexed integer array nums and a positive integer k.\n\nYou can apply the following operation on the array any number of times:\n\n * Choose any subarray of size k from the array and decrease all its elements by 1.\n\nReturn true if you can make all the array elements equal to 0, or false otherwise.\n\nA subarray is a contiguous non-empty part of an array.\n\nExample 1:\n\nInput: nums = [2,2,3,1,1,0], k = 3\nOutput: true\nExplanation: We can do the following operations:\n- Choose the subarray [2,2,3]. The resulting array will be nums = [1,1,2,1,1,0].\n- Choose the subarray [2,1,1]. The resulting array will be nums = [1,1,1,0,0,0].\n- Choose the subarray [1,1,1]. The resulting array will be nums = [0,0,0,0,0,0].\n\nExample 2:\n\nInput: nums = [1,3,1,1], k = 2\nOutput: false\nExplanation: It is not possible to make all the array elements equal to 0.\n\n\nConstraints:\n\n * 1 <= k <= nums.length <= 105\n * 0 <= nums[i] <= 106\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def checkArray(self, nums: List[int], k: int) -> bool:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,3,1,1], \"k\": 2 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [2,2,3,1,1,0], \"k\": 3 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [24,24,14,37,31,88,94,38,94,0,100,100,4,46,5,50,0,33,22,25,0], \"k\": 10 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [60,72,87,89,63,52,64,62,31,37,57,83,98,94,92,77,94,91,87,100,91,91,50,26], \"k\": 4 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [22,4,1,25,68,30,97,99,100,22,20,39,85,68,3,1,1,74], \"k\": 4 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [63,40,30,0,72,53], \"k\": 1 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [27,99,7,1,94,63,84,46,76,35,97,77,19,72,3], \"k\": 2 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [60,78,96,97,97,97,49,7,97,97,97,99,97,97,97,97,85,97,97,97,37,5,1], \"k\": 20 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [34,34,99,93,93,26,99,100,94,94,82,86,100,100,87,100,100,100,100,100,63,100,100,66,17,10,8,7,3,1], \"k\": 23 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [67,98,97,99,98,97,97,96,99,99,99,42,68,18,99,44,95,79,1,16,49,1,2,2,0], \"k\": 16 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [59,60,99,99,99,99,99,99,99,40,39,0], \"k\": 9 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [12,87,91,18], \"k\": 3 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [0,0,51,67,80,98,88,75,89,83,100,70,77,82,57,100,80,69,19,17], \"k\": 3 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [22], \"k\": 1 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [52,92,51,24,23,79,100,94,78,96,38,14,72,27,99,94,32,67,43,31,88,8], \"k\": 4 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [8,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,43,0], \"k\": 25 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [0,0,39,84,86,94,55,10,8,0], \"k\": 4 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [12,79,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,95,83,16,0], \"k\": 24 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [15,11,99,86,58,23,82,100,100,80,58,58,84,57,0,25,6], \"k\": 3 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [99,0,82,66,3,25,92,41,3,0,46], \"k\": 7 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [18,52,56,96,98,82,76,87,2,61,88,100], \"k\": 2 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [0,6,100,74,4,50,100,92,18,70,15,88,0,24], \"k\": 9 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [0,0,33,72,86,53,14], \"k\": 3 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [67,0,68,97,94], \"k\": 3 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [0,0,8,64,89,89,89,89,89,89,89,89,89,89,89,89,89,89,89,89,89,89,89,89,89,89,89,81,25], \"k\": 25 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [84,0,68,95,95,0,25,0,7,71,4,68,23,97,80,0], \"k\": 1 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [95,92,99,99,2,100,100,100,100,100,100,100,8,57,65,69,69,100,100,100,100,100,100,100,100,0,79,72,32], \"k\": 12 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [7,33,97,98,100,100,74,98,95,13,39,31,82,51,28,68,37,59,21,5,66,77,89,6,0], \"k\": 6 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [48,48,48,48,48], \"k\": 5 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [42,60,56,99,72,2,100,51,65,14,13,51,1,55,56,61,99,49,96,2], \"k\": 3 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [8,82,98,99,66,39,71,100,81,85,100,19,96,0,2,85,40,0,19,0], \"k\": 11 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [92,96,96,96,97,99,99,99,99,99,99,99,99,22,18,18,18,17,15,15,15,15,15,15,15,15], \"k\": 13 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [89,8,8,8,8,8,8,8,8,8,8,8], \"k\": 12 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [4,19,0,74,0,26,94,25,99,35,0], \"k\": 10 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [79,4,27,35,16,27,85,92,75,99,7,98,86,92,33,8,96,44,21,52,34], \"k\": 4 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [75,18,0,81,18,16,51,0], \"k\": 1 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [74,74,74,74,74,74,74,74,74], \"k\": 9 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [5,5,5,9,37,81,95,95,95,98,98,99,100,100,97,99,100,96,68,24,10,10,10,7,7,6,5,5,3,1], \"k\": 14 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [81,100,99,99,68,66,56,100,74,63,2,84,23,67,93,92,56,90,18,57,100,33,88,26,100,72,93,57,28,17], \"k\": 4 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [62,76,96,12,0,20,63,29,96,97,8,18,56], \"k\": 1 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [31,60,97,71,53,46,63,50,91,82,40,79,96,100,55,55,57,39,50,98,72,37,27,55], \"k\": 3 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [100,65,78,59,17,17], \"k\": 1 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [57,10,53,20,40,42,64,94,82,67,100,3,22,67,95,28,61,74,67,99,100,46,67,67,76,31,99,26,85], \"k\": 24 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [34,76,66,48,13,89,22,24,70,17,17,42,100,2,96,8], \"k\": 3 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [92,94,2,6,6], \"k\": 2 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [100,17,95], \"k\": 3 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [20,27,75,96,97,84,90,77,65,64,57,44,9,0], \"k\": 5 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [41,39,98,99,100,100,100,100,100,100,100,100,100,100,100,37,5,2,1,0,0,92,0,0,0], \"k\": 15 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [45,90,90,99,99,99,99,99,54,9,9,0], \"k\": 8 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [41,18,59,3,52,59,59,55,1,34,67,1,2,13,60,40,5,0,4,47,73,96,33,59,98], \"k\": 24 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [53,88,96,97,97,97,97,97,97,97,44,9,1,0], \"k\": 10 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [90,74,13,81,34,10,29,18,61,94,43,99,86,0], \"k\": 11 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [44,47,72,0,0,68,97,67], \"k\": 1 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [77,78,19,97,79], \"k\": 2 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [36,61,86,61,0,61,61,61,61,61,61,61,61,65,62,61,95,61,61,61,80,66,61,61,25], \"k\": 24 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [0,44,92,94,94,50,95,98,98,99,6,1,54,58,94,94,41,36], \"k\": 4 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [60,71,76,93,98,98,98,98,38,27,22,5], \"k\": 8 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [94,94,99,94,86,100,32,96,59,69,99,95,75], \"k\": 3 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [6,55,95,95,95,96,95,95,90,5,0], \"k\": 8 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [62,90,90,90,99,57,61,96,96,97,99,78,84,0], \"k\": 5 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [57,77,91,66,46,32], \"k\": 3 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [86,87,92,20,42,99,100,97,17,18,48,11,60,98,96,28,59,5,18,56,62,35,100,87,51,54,77,98,61], \"k\": 7 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [21,26,20,2,38,22,0,96,79,93,9,67,34], \"k\": 12 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [92,14,95,100,53,99,100,100,50,99,99,99,93,99,100,15,71,100,7,5,48,65,6], \"k\": 18 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [64,14,64,8,0,83,17,68,5,98,36], \"k\": 7 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [50,50,50,50,93,92,84,96,96,96,96,96,96,96,96,46,46,46,46,33,4,1,0], \"k\": 15 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [79,90,100,96,22,2,100,10,100,100,78,85,54,7,35,97,98,98,98,98,33,38,4,14,63,23], \"k\": 10 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [49,74,96,93,93,99,100,95,73,100,41,95,99,22,13,52,19,13,11,80], \"k\": 7 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [6,100,100,100,100,100,98,4,74,89,89,89,85,85,15], \"k\": 6 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [69,48,8,3,82,10,88,76,32,95,68,30,97,64,32,62,86], \"k\": 1 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [87,87,87], \"k\": 3 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [88,98,99,99,100,100,58,82,85,87,86,86,40,6,2], \"k\": 6 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [26,26,46,46,70,70,95,97,98,98,98,72,72,52,52,28,28,3,1], \"k\": 11 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [25], \"k\": 1 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [71,87,87,96,99,36,61,87,98,97,93,96,71,59,75,71,27,26,18], \"k\": 5 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [39,90,15,100,52,27,100,67,99,79,4,78,95,84,2], \"k\": 4 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [39,39,39,39,39,39,39,39,39,39], \"k\": 10 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [58,72,93,99,99,64,50,29,23,23,0,0,0,0,0], \"k\": 5 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [30,86,23], \"k\": 3 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [65,69,74,79,90,95,98,99,99,99,100,100,100,100,100,100,35,31,26,21,10,5,2,1,1,1,0,0], \"k\": 16 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [69,2,71,4,97,97,100,26,100,100,100,100,100,77,13,8,13,3,3,72,0,0,0], \"k\": 13 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [77,90,94,94,98,98,28,29,36,91,91,94,87,73,80,81,77,74,74,74,56], \"k\": 6 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [93], \"k\": 1 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [70,91,100,17,80,94,35,83,33,0], \"k\": 4 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [79,87,87,99,50,77,97,85,92,91,71,71,34], \"k\": 4 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [75,9,96,100,100,77,7,99,100,99,94,71,5,78,3,8,8,7,59,8,6], \"k\": 10 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [36,37,69,88,88,96,96,96,96,96,96,96,96,96,96,96,96,96,96,96,96,60,59,27,8,8,0], \"k\": 21 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [94,94,96,97,98,11,64,85,84,87,98,45,65,83,79,63,74,79,61,61,59,48], \"k\": 5 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [80,80,98,98,98,18,18,0,0], \"k\": 5 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [14,100,17,100,13,85,100,100,14,100,100,1,83,0], \"k\": 11 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [98,74,91,70], \"k\": 2 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [0,29,29,93,93,93,93,93,93,93,93,93,64,64], \"k\": 11 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,0], \"k\": 15 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [34,89,92,96,96,98,99,98,79,4,100,100,12,99,100,44,100,66,25,8,4,98,2,1,97,70,1,15,0,88], \"k\": 17 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [95,95,98,99,99,99,100,100,100,100,100,100,100,5,5,2,1,1,1], \"k\": 13 }\nassert my_solution.checkArray(**test_input) == True\n\ntest_input = { \"nums\": [15,58,78,10,68,49,100,94,30,14,72], \"k\": 5 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [9,44,70,75,28,23,11,37,69,34,61], \"k\": 10 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [70,51,47,100,59,66,17,98,60], \"k\": 4 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [92,33,58,88], \"k\": 2 }\nassert my_solution.checkArray(**test_input) == False\n\ntest_input = { \"nums\": [99,15,91,32,7,98], \"k\": 3 }\nassert my_solution.checkArray(**test_input) == False", "start_time": 1688869800} +{"task_id": "biweekly-contest-108-longest-alternating-subarray", "url": "https://leetcode.com/problems/longest-alternating-subarray", "title": "longest-alternating-subarray", "meta": {"questionId": "2870", "questionFrontendId": "2765", "title": "Longest Alternating Subarray", "titleSlug": "longest-alternating-subarray", "isPaidOnly": false, "difficulty": "Easy", "likes": 181, "dislikes": 153, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed integer array nums. A subarray s of length m is called alternating if:\n\n * m is greater than 1.\n * s1 = s0 + 1.\n * The 0-indexed subarray s looks like [s0, s1, s0, s1,...,s(m-1) % 2]. In other words, s1 - s0 = 1, s2 - s1 = -1, s3 - s2 = 1, s4 - s3 = -1, and so on up to s[m - 1] - s[m - 2] = (-1)m.\n\nReturn the maximum length of all alternating subarrays present in nums or -1 if no such subarray exists.\n\nA subarray is a contiguous non-empty sequence of elements within an array.\n\nExample 1:\n\nInput: nums = [2,3,4,3,4]\nOutput: 4\nExplanation: The alternating subarrays are [3,4], [3,4,3], and [3,4,3,4]. The longest of these is [3,4,3,4], which is of length 4.\n\nExample 2:\n\nInput: nums = [4,5,6]\nOutput: 2\nExplanation: [4,5] and [5,6] are the only two alternating subarrays. They are both of length 2.\n\n\nConstraints:\n\n * 2 <= nums.length <= 100\n * 1 <= nums[i] <= 104\n\"\"\"\nclass Solution:\n def alternatingSubarray(self, nums: List[int]) -> int:\n ", "prompt_sft": "You are given a 0-indexed integer array nums. A subarray s of length m is called alternating if:\n\n * m is greater than 1.\n * s1 = s0 + 1.\n * The 0-indexed subarray s looks like [s0, s1, s0, s1,...,s(m-1) % 2]. In other words, s1 - s0 = 1, s2 - s1 = -1, s3 - s2 = 1, s4 - s3 = -1, and so on up to s[m - 1] - s[m - 2] = (-1)m.\n\nReturn the maximum length of all alternating subarrays present in nums or -1 if no such subarray exists.\n\nA subarray is a contiguous non-empty sequence of elements within an array.\n\nExample 1:\n\nInput: nums = [2,3,4,3,4]\nOutput: 4\nExplanation: The alternating subarrays are [3,4], [3,4,3], and [3,4,3,4]. The longest of these is [3,4,3,4], which is of length 4.\n\nExample 2:\n\nInput: nums = [4,5,6]\nOutput: 2\nExplanation: [4,5] and [5,6] are the only two alternating subarrays. They are both of length 2.\n\n\nConstraints:\n\n * 2 <= nums.length <= 100\n * 1 <= nums[i] <= 104\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def alternatingSubarray(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [2,3,4,3,4] }\nassert my_solution.alternatingSubarray(**test_input) == 4\n\ntest_input = { \"nums\": [4,5,6] }\nassert my_solution.alternatingSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [31,32,31,32,33] }\nassert my_solution.alternatingSubarray(**test_input) == 4\n\ntest_input = { \"nums\": [21,9,5] }\nassert my_solution.alternatingSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [42,43,44,43,44,43,44,45,46] }\nassert my_solution.alternatingSubarray(**test_input) == 6\n\ntest_input = { \"nums\": [13,14,15,14] }\nassert my_solution.alternatingSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [74,75,74,75,74,75,74,75] }\nassert my_solution.alternatingSubarray(**test_input) == 8\n\ntest_input = { \"nums\": [77,78,79,78,79,78,79,78,79,80] }\nassert my_solution.alternatingSubarray(**test_input) == 8\n\ntest_input = { \"nums\": [88,42,53] }\nassert my_solution.alternatingSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [64,65,64,65,64,65,66,65,66,65] }\nassert my_solution.alternatingSubarray(**test_input) == 6\n\ntest_input = { \"nums\": [99,100,99,100] }\nassert my_solution.alternatingSubarray(**test_input) == 4\n\ntest_input = { \"nums\": [21,22] }\nassert my_solution.alternatingSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [23,24,23,24,25,24,25,24,25] }\nassert my_solution.alternatingSubarray(**test_input) == 6\n\ntest_input = { \"nums\": [20,9,15,15] }\nassert my_solution.alternatingSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [92,93,92,93,92] }\nassert my_solution.alternatingSubarray(**test_input) == 5\n\ntest_input = { \"nums\": [24,25,26] }\nassert my_solution.alternatingSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [51,52,53,52,53,52,53,54,53] }\nassert my_solution.alternatingSubarray(**test_input) == 6\n\ntest_input = { \"nums\": [65,66,65,66,67,68,69] }\nassert my_solution.alternatingSubarray(**test_input) == 4\n\ntest_input = { \"nums\": [29,2,5,24] }\nassert my_solution.alternatingSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [26,27,26,27,28,27,28,27,28] }\nassert my_solution.alternatingSubarray(**test_input) == 6\n\ntest_input = { \"nums\": [21,22,21,22,21,22] }\nassert my_solution.alternatingSubarray(**test_input) == 6\n\ntest_input = { \"nums\": [94,95,94,95,94] }\nassert my_solution.alternatingSubarray(**test_input) == 5\n\ntest_input = { \"nums\": [82,83,84,83,84,83,84,83] }\nassert my_solution.alternatingSubarray(**test_input) == 7\n\ntest_input = { \"nums\": [14,30,29,49,3,23,44,21,26,52] }\nassert my_solution.alternatingSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [4,5,4,5,6,5,6] }\nassert my_solution.alternatingSubarray(**test_input) == 4\n\ntest_input = { \"nums\": [62,63] }\nassert my_solution.alternatingSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [24,25,26,25,26,25,26,25,26] }\nassert my_solution.alternatingSubarray(**test_input) == 8\n\ntest_input = { \"nums\": [55,56,55,56,55,56,55,56,57,56] }\nassert my_solution.alternatingSubarray(**test_input) == 8\n\ntest_input = { \"nums\": [52,77,42,21] }\nassert my_solution.alternatingSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [80,81] }\nassert my_solution.alternatingSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [50,51,50,51,50,51,50,51,50] }\nassert my_solution.alternatingSubarray(**test_input) == 9\n\ntest_input = { \"nums\": [83,84,83] }\nassert my_solution.alternatingSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [17,18,17,18,19,18,19,20,19,20] }\nassert my_solution.alternatingSubarray(**test_input) == 4\n\ntest_input = { \"nums\": [5,14,8,12,5,4] }\nassert my_solution.alternatingSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [35,36,35,36,35,36,35,36,35,36] }\nassert my_solution.alternatingSubarray(**test_input) == 10\n\ntest_input = { \"nums\": [8,9,8,9,8,9] }\nassert my_solution.alternatingSubarray(**test_input) == 6\n\ntest_input = { \"nums\": [59,60] }\nassert my_solution.alternatingSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [55,56,55] }\nassert my_solution.alternatingSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [47,46,65,37,24,54,39,70] }\nassert my_solution.alternatingSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [45,46,45,46,45,46,45] }\nassert my_solution.alternatingSubarray(**test_input) == 7\n\ntest_input = { \"nums\": [78,79,78,79,78,79,78,79,80,79] }\nassert my_solution.alternatingSubarray(**test_input) == 8\n\ntest_input = { \"nums\": [65,66,65,66,65,66,67,68] }\nassert my_solution.alternatingSubarray(**test_input) == 6\n\ntest_input = { \"nums\": [62,63,62,63,62,63] }\nassert my_solution.alternatingSubarray(**test_input) == 6\n\ntest_input = { \"nums\": [7,10,5,2,11,3,9,12,9,11] }\nassert my_solution.alternatingSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [79,80,79,80,79,80] }\nassert my_solution.alternatingSubarray(**test_input) == 6\n\ntest_input = { \"nums\": [19,20,21,20,21,22] }\nassert my_solution.alternatingSubarray(**test_input) == 4\n\ntest_input = { \"nums\": [84,85,86,85,86,85,86,87,88,87] }\nassert my_solution.alternatingSubarray(**test_input) == 6\n\ntest_input = { \"nums\": [54,55] }\nassert my_solution.alternatingSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [71,14,24,13,21,14,18,84,37,2] }\nassert my_solution.alternatingSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [26,27,26] }\nassert my_solution.alternatingSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [53,54,53,54,53] }\nassert my_solution.alternatingSubarray(**test_input) == 5\n\ntest_input = { \"nums\": [67,68,67,68,67,68,69,70,69,70] }\nassert my_solution.alternatingSubarray(**test_input) == 6\n\ntest_input = { \"nums\": [85,86,85,86,85,86,85,86,85,86] }\nassert my_solution.alternatingSubarray(**test_input) == 10\n\ntest_input = { \"nums\": [22,16,27,22,44,10] }\nassert my_solution.alternatingSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [27,28,27,28,27,28,27,28,29,28] }\nassert my_solution.alternatingSubarray(**test_input) == 8\n\ntest_input = { \"nums\": [54,55,54,55,54,55,54,55,56,57] }\nassert my_solution.alternatingSubarray(**test_input) == 8\n\ntest_input = { \"nums\": [24,25,26,27,28] }\nassert my_solution.alternatingSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [55,56] }\nassert my_solution.alternatingSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [13,6,6,8,12,7,1] }\nassert my_solution.alternatingSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [40,41,40,41,40,41,40,41] }\nassert my_solution.alternatingSubarray(**test_input) == 8\n\ntest_input = { \"nums\": [10,11,10,11,10,11,12] }\nassert my_solution.alternatingSubarray(**test_input) == 6\n\ntest_input = { \"nums\": [58,59,58,59] }\nassert my_solution.alternatingSubarray(**test_input) == 4\n\ntest_input = { \"nums\": [1,15,44,74,56,41,48,71] }\nassert my_solution.alternatingSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [89,90,89,90,89,90] }\nassert my_solution.alternatingSubarray(**test_input) == 6\n\ntest_input = { \"nums\": [4,5,4,5,4,5,6] }\nassert my_solution.alternatingSubarray(**test_input) == 6\n\ntest_input = { \"nums\": [50,51,52,53,52,53] }\nassert my_solution.alternatingSubarray(**test_input) == 4\n\ntest_input = { \"nums\": [44,45,46,45,46,45,46,47,48] }\nassert my_solution.alternatingSubarray(**test_input) == 6\n\ntest_input = { \"nums\": [16,3,25,12,2,19,1,26] }\nassert my_solution.alternatingSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [17,18,19,20,19,20] }\nassert my_solution.alternatingSubarray(**test_input) == 4\n\ntest_input = { \"nums\": [91,92,93,92,93] }\nassert my_solution.alternatingSubarray(**test_input) == 4\n\ntest_input = { \"nums\": [28,29,28,29,28,29,30] }\nassert my_solution.alternatingSubarray(**test_input) == 6\n\ntest_input = { \"nums\": [88,89,88,89,88,89] }\nassert my_solution.alternatingSubarray(**test_input) == 6\n\ntest_input = { \"nums\": [1,1,1,1,1,1,1,1,1,1] }\nassert my_solution.alternatingSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [32,33,32,33,32,33,34] }\nassert my_solution.alternatingSubarray(**test_input) == 6\n\ntest_input = { \"nums\": [61,62,61,62,63,62,63,64,63] }\nassert my_solution.alternatingSubarray(**test_input) == 4\n\ntest_input = { \"nums\": [6,7,6,7] }\nassert my_solution.alternatingSubarray(**test_input) == 4\n\ntest_input = { \"nums\": [20,21,20,21,20] }\nassert my_solution.alternatingSubarray(**test_input) == 5\n\ntest_input = { \"nums\": [14,6,21] }\nassert my_solution.alternatingSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [12,13,12,13,12,13,12,13,12] }\nassert my_solution.alternatingSubarray(**test_input) == 9\n\ntest_input = { \"nums\": [33,34,33,34,33,34,33] }\nassert my_solution.alternatingSubarray(**test_input) == 7\n\ntest_input = { \"nums\": [92,93,92] }\nassert my_solution.alternatingSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [93,94,95,94,95,96,95,96,97] }\nassert my_solution.alternatingSubarray(**test_input) == 4\n\ntest_input = { \"nums\": [8,4,27] }\nassert my_solution.alternatingSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [30,31,32,31,32,33,34,33] }\nassert my_solution.alternatingSubarray(**test_input) == 4\n\ntest_input = { \"nums\": [26,27,26,27,26,27] }\nassert my_solution.alternatingSubarray(**test_input) == 6\n\ntest_input = { \"nums\": [67,68,69] }\nassert my_solution.alternatingSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [83,84,85,84,85] }\nassert my_solution.alternatingSubarray(**test_input) == 4\n\ntest_input = { \"nums\": [6,26,4,2] }\nassert my_solution.alternatingSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [81,82,81,82,81,82,81,82,83] }\nassert my_solution.alternatingSubarray(**test_input) == 8\n\ntest_input = { \"nums\": [58,59] }\nassert my_solution.alternatingSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [82,83,82,83,82,83,82,83,82] }\nassert my_solution.alternatingSubarray(**test_input) == 9\n\ntest_input = { \"nums\": [48,49] }\nassert my_solution.alternatingSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [8,6,2] }\nassert my_solution.alternatingSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [69,70,69,70,69,70,69,70,69] }\nassert my_solution.alternatingSubarray(**test_input) == 9\n\ntest_input = { \"nums\": [28,29,28,29] }\nassert my_solution.alternatingSubarray(**test_input) == 4\n\ntest_input = { \"nums\": [82,83,82,83,84] }\nassert my_solution.alternatingSubarray(**test_input) == 4\n\ntest_input = { \"nums\": [97,98,97,98,97,98,97] }\nassert my_solution.alternatingSubarray(**test_input) == 7\n\ntest_input = { \"nums\": [2,2,1] }\nassert my_solution.alternatingSubarray(**test_input) == -1\n\ntest_input = { \"nums\": [84,85,84,85,84,85,84] }\nassert my_solution.alternatingSubarray(**test_input) == 7\n\ntest_input = { \"nums\": [21,22,21,22] }\nassert my_solution.alternatingSubarray(**test_input) == 4", "start_time": 1688826600} +{"task_id": "biweekly-contest-108-relocate-marbles", "url": "https://leetcode.com/problems/relocate-marbles", "title": "relocate-marbles", "meta": {"questionId": "2834", "questionFrontendId": "2766", "title": "Relocate Marbles", "titleSlug": "relocate-marbles", "isPaidOnly": false, "difficulty": "Medium", "likes": 170, "dislikes": 13, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed integer array nums representing the initial positions of some marbles. You are also given two 0-indexed integer arrays moveFrom and moveTo of equal length.\n\nThroughout moveFrom.length steps, you will change the positions of the marbles. On the ith step, you will move all marbles at position moveFrom[i] to position moveTo[i].\n\nAfter completing all the steps, return the sorted list of occupied positions.\n\nNotes:\n\n * We call a position occupied if there is at least one marble in that position.\n * There may be multiple marbles in a single position.\n\nExample 1:\n\nInput: nums = [1,6,7,8], moveFrom = [1,7,2], moveTo = [2,9,5]\nOutput: [5,6,8,9]\nExplanation: Initially, the marbles are at positions 1,6,7,8.\nAt the i = 0th step, we move the marbles at position 1 to position 2. Then, positions 2,6,7,8 are occupied.\nAt the i = 1st step, we move the marbles at position 7 to position 9. Then, positions 2,6,8,9 are occupied.\nAt the i = 2nd step, we move the marbles at position 2 to position 5. Then, positions 5,6,8,9 are occupied.\nAt the end, the final positions containing at least one marbles are [5,6,8,9].\n\nExample 2:\n\nInput: nums = [1,1,3,3], moveFrom = [1,3], moveTo = [2,2]\nOutput: [2]\nExplanation: Initially, the marbles are at positions [1,1,3,3].\nAt the i = 0th step, we move all the marbles at position 1 to position 2. Then, the marbles are at positions [2,2,3,3].\nAt the i = 1st step, we move all the marbles at position 3 to position 2. Then, the marbles are at positions [2,2,2,2].\nSince 2 is the only occupied position, we return [2].\n\n\nConstraints:\n\n * 1 <= nums.length <= 105\n * 1 <= moveFrom.length <= 105\n * moveFrom.length == moveTo.length\n * 1 <= nums[i], moveFrom[i], moveTo[i] <= 109\n * The test cases are generated such that there is at least a marble in moveFrom[i] at the moment we want to apply the ith move.\n\"\"\"\nclass Solution:\n def relocateMarbles(self, nums: List[int], moveFrom: List[int], moveTo: List[int]) -> List[int]:\n ", "prompt_sft": "You are given a 0-indexed integer array nums representing the initial positions of some marbles. You are also given two 0-indexed integer arrays moveFrom and moveTo of equal length.\n\nThroughout moveFrom.length steps, you will change the positions of the marbles. On the ith step, you will move all marbles at position moveFrom[i] to position moveTo[i].\n\nAfter completing all the steps, return the sorted list of occupied positions.\n\nNotes:\n\n * We call a position occupied if there is at least one marble in that position.\n * There may be multiple marbles in a single position.\n\nExample 1:\n\nInput: nums = [1,6,7,8], moveFrom = [1,7,2], moveTo = [2,9,5]\nOutput: [5,6,8,9]\nExplanation: Initially, the marbles are at positions 1,6,7,8.\nAt the i = 0th step, we move the marbles at position 1 to position 2. Then, positions 2,6,7,8 are occupied.\nAt the i = 1st step, we move the marbles at position 7 to position 9. Then, positions 2,6,8,9 are occupied.\nAt the i = 2nd step, we move the marbles at position 2 to position 5. Then, positions 5,6,8,9 are occupied.\nAt the end, the final positions containing at least one marbles are [5,6,8,9].\n\nExample 2:\n\nInput: nums = [1,1,3,3], moveFrom = [1,3], moveTo = [2,2]\nOutput: [2]\nExplanation: Initially, the marbles are at positions [1,1,3,3].\nAt the i = 0th step, we move all the marbles at position 1 to position 2. Then, the marbles are at positions [2,2,3,3].\nAt the i = 1st step, we move all the marbles at position 3 to position 2. Then, the marbles are at positions [2,2,2,2].\nSince 2 is the only occupied position, we return [2].\n\n\nConstraints:\n\n * 1 <= nums.length <= 105\n * 1 <= moveFrom.length <= 105\n * moveFrom.length == moveTo.length\n * 1 <= nums[i], moveFrom[i], moveTo[i] <= 109\n * The test cases are generated such that there is at least a marble in moveFrom[i] at the moment we want to apply the ith move.\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def relocateMarbles(self, nums: List[int], moveFrom: List[int], moveTo: List[int]) -> List[int]:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [1,6,7,8], \"moveFrom\": [1,7,2], \"moveTo\": [2,9,5] }\nassert my_solution.relocateMarbles(**test_input) == [5,6,8,9]\n\ntest_input = { \"nums\": [1,1,3,3], \"moveFrom\": [1,3], \"moveTo\": [2,2] }\nassert my_solution.relocateMarbles(**test_input) == [2]\n\ntest_input = { \"nums\": [5,7,8,15], \"moveFrom\": [5,7,8,9], \"moveTo\": [9,15,2,7] }\nassert my_solution.relocateMarbles(**test_input) == [2,7,15]\n\ntest_input = { \"nums\": [4,6,6,9,18], \"moveFrom\": [18,6,17,4,9,19,2], \"moveTo\": [23,17,20,19,11,2,20] }\nassert my_solution.relocateMarbles(**test_input) == [11,20,23]\n\ntest_input = { \"nums\": [3,4], \"moveFrom\": [4,3,1,2,2,3,2,4,1], \"moveTo\": [3,1,2,2,3,2,4,1,1] }\nassert my_solution.relocateMarbles(**test_input) == [1]\n\ntest_input = { \"nums\": [5,13,22,23,23,33], \"moveFrom\": [13,5,12], \"moveTo\": [1,12,13] }\nassert my_solution.relocateMarbles(**test_input) == [1,13,22,23,33]\n\ntest_input = { \"nums\": [21,24,35,72,77,82,82,96,97,97], \"moveFrom\": [82,76,3,97], \"moveTo\": [76,3,52,27] }\nassert my_solution.relocateMarbles(**test_input) == [21,24,27,35,52,72,77,96]\n\ntest_input = { \"nums\": [4,6,17,41,46,46,52,57], \"moveFrom\": [4], \"moveTo\": [62] }\nassert my_solution.relocateMarbles(**test_input) == [6,17,41,46,52,57,62]\n\ntest_input = { \"nums\": [1,4,10,24,46,55,61,63,71], \"moveFrom\": [10,52,1,80,63,55,4,46,71,24], \"moveTo\": [52,42,80,55,50,62,60,17,46,38] }\nassert my_solution.relocateMarbles(**test_input) == [17,38,42,46,50,60,61,62]\n\ntest_input = { \"nums\": [8,9,16,17,23], \"moveFrom\": [8,5,16,2,9], \"moveTo\": [5,20,2,18,22] }\nassert my_solution.relocateMarbles(**test_input) == [17,18,20,22,23]\n\ntest_input = { \"nums\": [12,37,46,47,49,55,59,65,71,88], \"moveFrom\": [88,59,71], \"moveTo\": [81,39,73] }\nassert my_solution.relocateMarbles(**test_input) == [12,37,39,46,47,49,55,65,73,81]\n\ntest_input = { \"nums\": [2,45,45,48,51,57,67,73,78,78], \"moveFrom\": [78,67,45,34,51,62,48,95,2,67], \"moveTo\": [34,65,62,95,62,12,85,67,79,71] }\nassert my_solution.relocateMarbles(**test_input) == [12,57,65,71,73,79,85]\n\ntest_input = { \"nums\": [1,2], \"moveFrom\": [1,2,3], \"moveTo\": [2,3,2] }\nassert my_solution.relocateMarbles(**test_input) == [2]\n\ntest_input = { \"nums\": [7,19,28,34,36,36,47], \"moveFrom\": [36,33,34,28,41,19,14,47,28,40], \"moveTo\": [33,41,27,47,14,40,46,28,42,16] }\nassert my_solution.relocateMarbles(**test_input) == [7,16,27,42,46]\n\ntest_input = { \"nums\": [1,1,1], \"moveFrom\": [1], \"moveTo\": [7] }\nassert my_solution.relocateMarbles(**test_input) == [7]\n\ntest_input = { \"nums\": [1], \"moveFrom\": [1,1,1,1,1,1], \"moveTo\": [1,1,1,1,1,1] }\nassert my_solution.relocateMarbles(**test_input) == [1]\n\ntest_input = { \"nums\": [5,9,17,20,29,29], \"moveFrom\": [20,5,1,29,22,21,9,36,33,1], \"moveTo\": [1,22,21,36,36,15,33,1,3,15] }\nassert my_solution.relocateMarbles(**test_input) == [3,15,17]\n\ntest_input = { \"nums\": [1], \"moveFrom\": [1,1,1,1], \"moveTo\": [1,1,1,1] }\nassert my_solution.relocateMarbles(**test_input) == [1]\n\ntest_input = { \"nums\": [27,41,50,52,57,60,65,67,70], \"moveFrom\": [52,67,70,50,57,27,47], \"moveTo\": [45,45,61,47,21,65,60] }\nassert my_solution.relocateMarbles(**test_input) == [21,41,45,60,61,65]\n\ntest_input = { \"nums\": [2,3,7], \"moveFrom\": [2,7,8,8,3,5,1,4], \"moveTo\": [8,5,8,1,4,4,4,5] }\nassert my_solution.relocateMarbles(**test_input) == [5]\n\ntest_input = { \"nums\": [4,6,8,10], \"moveFrom\": [8,6], \"moveTo\": [4,3] }\nassert my_solution.relocateMarbles(**test_input) == [3,4,10]\n\ntest_input = { \"nums\": [2,4,29,34,41,44,48], \"moveFrom\": [29,3,44,48,2,43,4], \"moveTo\": [3,24,43,42,24,8,6] }\nassert my_solution.relocateMarbles(**test_input) == [6,8,24,34,41,42]\n\ntest_input = { \"nums\": [12,16,22,28,36,42,60,63], \"moveFrom\": [42,28,12,22], \"moveTo\": [22,63,14,45] }\nassert my_solution.relocateMarbles(**test_input) == [14,16,36,45,60,63]\n\ntest_input = { \"nums\": [12,18,21,21,31,38,39,41,84,90], \"moveFrom\": [41,31,12,84,9,39,21,62], \"moveTo\": [24,17,58,9,62,36,23,90] }\nassert my_solution.relocateMarbles(**test_input) == [17,18,23,24,36,38,58,90]\n\ntest_input = { \"nums\": [12,23,30,35,46,53,64,74,81], \"moveFrom\": [53,74,54,48,52,64,35,30,46,29], \"moveTo\": [54,48,52,47,53,29,52,10,44,28] }\nassert my_solution.relocateMarbles(**test_input) == [10,12,23,28,44,47,52,53,81]\n\ntest_input = { \"nums\": [2,10,13,14,16,30], \"moveFrom\": [2,6,14,16,25,13,30], \"moveTo\": [6,30,25,1,32,17,11] }\nassert my_solution.relocateMarbles(**test_input) == [1,10,11,17,32]\n\ntest_input = { \"nums\": [1,6,10,11,18,22,30], \"moveFrom\": [10,18,1,30,6], \"moveTo\": [1,37,28,38,15] }\nassert my_solution.relocateMarbles(**test_input) == [11,15,22,28,37,38]\n\ntest_input = { \"nums\": [3,9,10,13], \"moveFrom\": [9,3,13,10,5,11,8], \"moveTo\": [11,5,11,15,8,5,14] }\nassert my_solution.relocateMarbles(**test_input) == [5,14,15]\n\ntest_input = { \"nums\": [15,31,32,52,61,65,78,84,93,100], \"moveFrom\": [15,32,93,3,78,65,61,84], \"moveTo\": [61,3,8,55,23,87,95,44] }\nassert my_solution.relocateMarbles(**test_input) == [8,23,31,44,52,55,87,95,100]\n\ntest_input = { \"nums\": [1,2], \"moveFrom\": [1,2,1,1,1,3,4,4], \"moveTo\": [1,1,1,1,3,4,4,2] }\nassert my_solution.relocateMarbles(**test_input) == [2]\n\ntest_input = { \"nums\": [2,2,2], \"moveFrom\": [2,8,5,9], \"moveTo\": [8,5,9,2] }\nassert my_solution.relocateMarbles(**test_input) == [2]\n\ntest_input = { \"nums\": [3,10,11,27,58,59,61,66,68], \"moveFrom\": [59,61,3,15], \"moveTo\": [15,68,77,52] }\nassert my_solution.relocateMarbles(**test_input) == [10,11,27,52,58,66,68,77]\n\ntest_input = { \"nums\": [2,9,9], \"moveFrom\": [9,2,8,9,4,6,7,1,5,5], \"moveTo\": [4,8,9,4,6,7,1,5,5,5] }\nassert my_solution.relocateMarbles(**test_input) == [5]\n\ntest_input = { \"nums\": [1,18,24,25,29,31], \"moveFrom\": [18,25,29,18,23], \"moveTo\": [3,23,18,18,8] }\nassert my_solution.relocateMarbles(**test_input) == [1,3,8,18,24,31]\n\ntest_input = { \"nums\": [2,18,38,38,48,50,51,61,71], \"moveFrom\": [61,71,2,18,47,22,24,51], \"moveTo\": [58,38,22,47,68,24,47,60] }\nassert my_solution.relocateMarbles(**test_input) == [38,47,48,50,58,60,68]\n\ntest_input = { \"nums\": [11,11,35,35,38,43,45], \"moveFrom\": [35,11,2,27,38,45,47,17], \"moveTo\": [2,47,27,17,47,24,35,21] }\nassert my_solution.relocateMarbles(**test_input) == [21,24,35,43]\n\ntest_input = { \"nums\": [4,11,15,28,36,42,45,57], \"moveFrom\": [57,32,36,11,52,42,55,4], \"moveTo\": [32,55,39,52,11,54,31,56] }\nassert my_solution.relocateMarbles(**test_input) == [11,15,28,31,39,45,54,56]\n\ntest_input = { \"nums\": [2,4], \"moveFrom\": [4,2], \"moveTo\": [4,1] }\nassert my_solution.relocateMarbles(**test_input) == [1,4]\n\ntest_input = { \"nums\": [9,14,24,31,32,40,47,54,75,76], \"moveFrom\": [31,75,76,3,47,32,24,9,14,18], \"moveTo\": [76,76,3,8,18,66,32,2,62,82] }\nassert my_solution.relocateMarbles(**test_input) == [2,8,32,40,54,62,66,82]\n\ntest_input = { \"nums\": [1], \"moveFrom\": [1,1,1,1,1,1,1], \"moveTo\": [1,1,1,1,1,1,1] }\nassert my_solution.relocateMarbles(**test_input) == [1]\n\ntest_input = { \"nums\": [2,12,13,14,18], \"moveFrom\": [13,2,14], \"moveTo\": [17,20,19] }\nassert my_solution.relocateMarbles(**test_input) == [12,17,18,19,20]\n\ntest_input = { \"nums\": [12,21,24,28,41,60,62,70,76], \"moveFrom\": [21,76,41,3], \"moveTo\": [23,33,3,53] }\nassert my_solution.relocateMarbles(**test_input) == [12,23,24,28,33,53,60,62,70]\n\ntest_input = { \"nums\": [7,29,40,43,48,56,60,72,81], \"moveFrom\": [56,60,6,62], \"moveTo\": [62,6,34,17] }\nassert my_solution.relocateMarbles(**test_input) == [7,17,29,34,40,43,48,72,81]\n\ntest_input = { \"nums\": [2,4,5,8], \"moveFrom\": [2,4,3,7,5,8,14], \"moveTo\": [3,7,9,14,9,6,16] }\nassert my_solution.relocateMarbles(**test_input) == [6,9,16]\n\ntest_input = { \"nums\": [9,15,18,24,39,48,59,64], \"moveFrom\": [59,64,63,60,9], \"moveTo\": [60,63,61,45,57] }\nassert my_solution.relocateMarbles(**test_input) == [15,18,24,39,45,48,57,61]\n\ntest_input = { \"nums\": [2,8,8,9,11,21], \"moveFrom\": [8,11,30,21,14,27,9,22,2,7], \"moveTo\": [30,27,22,14,7,3,1,21,4,16] }\nassert my_solution.relocateMarbles(**test_input) == [1,3,4,16,21]\n\ntest_input = { \"nums\": [5,11,30,43,47,63,65,82,86,93], \"moveFrom\": [43,63,11,93,82,47,54,5,30], \"moveTo\": [36,53,54,49,18,3,29,66,22] }\nassert my_solution.relocateMarbles(**test_input) == [3,18,22,29,36,49,53,65,66,86]\n\ntest_input = { \"nums\": [9,14,14,16,26,51,53,64,76], \"moveFrom\": [64,45,9,14,26,53,51,67,80], \"moveTo\": [45,67,23,37,80,16,27,51,44] }\nassert my_solution.relocateMarbles(**test_input) == [16,23,27,37,44,51,76]\n\ntest_input = { \"nums\": [16,21,21,25,39,41,44], \"moveFrom\": [41,21,45,29,35,39,29,25,28], \"moveTo\": [21,45,29,35,33,29,20,28,45] }\nassert my_solution.relocateMarbles(**test_input) == [16,20,33,44,45]\n\ntest_input = { \"nums\": [1,1,3], \"moveFrom\": [3,1,9,5,5], \"moveTo\": [9,9,5,5,9] }\nassert my_solution.relocateMarbles(**test_input) == [9]\n\ntest_input = { \"nums\": [12,14,16,16,21,32], \"moveFrom\": [32,5,14,21,15,22,16], \"moveTo\": [5,22,15,16,15,27,22] }\nassert my_solution.relocateMarbles(**test_input) == [12,15,22,27]\n\ntest_input = { \"nums\": [1,5,9], \"moveFrom\": [1,5,9,3,8,5,9,1,5], \"moveTo\": [8,3,9,1,5,8,1,5,2] }\nassert my_solution.relocateMarbles(**test_input) == [2,8]\n\ntest_input = { \"nums\": [1,2,14,30,43,44,76,76,77], \"moveFrom\": [76,77,43,1], \"moveTo\": [56,44,11,45] }\nassert my_solution.relocateMarbles(**test_input) == [2,11,14,30,44,45,56]\n\ntest_input = { \"nums\": [4,25,27,33,33,35], \"moveFrom\": [25,27,27,34,7,36], \"moveTo\": [34,27,36,7,25,1] }\nassert my_solution.relocateMarbles(**test_input) == [1,4,25,33,35]\n\ntest_input = { \"nums\": [3,7,18,25,37,48,48,62], \"moveFrom\": [48,18,62,48,2,18,56,53,37], \"moveTo\": [15,48,56,2,18,55,53,40,22] }\nassert my_solution.relocateMarbles(**test_input) == [3,7,15,22,25,40,55]\n\ntest_input = { \"nums\": [19,35,46,55,59,59,68,72,93,100], \"moveFrom\": [46,100,35,19,68,87,21,93,27], \"moveTo\": [76,94,87,66,57,21,27,89,40] }\nassert my_solution.relocateMarbles(**test_input) == [40,55,57,59,66,72,76,89,94]\n\ntest_input = { \"nums\": [1,3], \"moveFrom\": [3,1,3,4,4], \"moveTo\": [1,3,4,4,4] }\nassert my_solution.relocateMarbles(**test_input) == [4]\n\ntest_input = { \"nums\": [22,30,36,40,44,48,50,59], \"moveFrom\": [30,44,64,59,4], \"moveTo\": [64,4,50,25,36] }\nassert my_solution.relocateMarbles(**test_input) == [22,25,36,40,48,50]\n\ntest_input = { \"nums\": [1], \"moveFrom\": [1,1,1,1,1,1,1,1,1,1], \"moveTo\": [1,1,1,1,1,1,1,1,1,1] }\nassert my_solution.relocateMarbles(**test_input) == [1]\n\ntest_input = { \"nums\": [8,18,23,37,37,39,48], \"moveFrom\": [8,39,23,7,37,36], \"moveTo\": [39,7,36,25,10,28] }\nassert my_solution.relocateMarbles(**test_input) == [10,18,25,28,48]\n\ntest_input = { \"nums\": [1,4], \"moveFrom\": [1,2,4], \"moveTo\": [2,3,1] }\nassert my_solution.relocateMarbles(**test_input) == [1,3]\n\ntest_input = { \"nums\": [3,7,9,13], \"moveFrom\": [3,16,9,7,6,15,16,7,13,7], \"moveTo\": [16,6,2,15,8,16,7,1,7,9] }\nassert my_solution.relocateMarbles(**test_input) == [1,2,8,9]\n\ntest_input = { \"nums\": [11,12,17,18,20], \"moveFrom\": [11,17], \"moveTo\": [18,13] }\nassert my_solution.relocateMarbles(**test_input) == [12,13,18,20]\n\ntest_input = { \"nums\": [5,11,17,21,25], \"moveFrom\": [17], \"moveTo\": [14] }\nassert my_solution.relocateMarbles(**test_input) == [5,11,14,21,25]\n\ntest_input = { \"nums\": [7,9,12,20,23], \"moveFrom\": [7,8], \"moveTo\": [8,12] }\nassert my_solution.relocateMarbles(**test_input) == [9,12,20,23]\n\ntest_input = { \"nums\": [1], \"moveFrom\": [1,1], \"moveTo\": [1,1] }\nassert my_solution.relocateMarbles(**test_input) == [1]\n\ntest_input = { \"nums\": [10,13,17,49,56,57,59,62,68], \"moveFrom\": [49,62,59,45], \"moveTo\": [58,64,45,77] }\nassert my_solution.relocateMarbles(**test_input) == [10,13,17,56,57,58,64,68,77]\n\ntest_input = { \"nums\": [1,8,15,23,24,29,47], \"moveFrom\": [8,23,24,47,10,1], \"moveTo\": [38,10,10,48,22,24] }\nassert my_solution.relocateMarbles(**test_input) == [15,22,24,29,38,48]\n\ntest_input = { \"nums\": [3,3], \"moveFrom\": [3,1,4,2,2,2,2,2,1], \"moveTo\": [1,4,2,2,2,2,2,1,3] }\nassert my_solution.relocateMarbles(**test_input) == [3]\n\ntest_input = { \"nums\": [4,8,8], \"moveFrom\": [8,7,7], \"moveTo\": [7,7,8] }\nassert my_solution.relocateMarbles(**test_input) == [4,8]\n\ntest_input = { \"nums\": [1,2], \"moveFrom\": [1,2,1,3,4,2,3,4,1,4], \"moveTo\": [3,1,3,4,2,3,4,1,4,4] }\nassert my_solution.relocateMarbles(**test_input) == [4]\n\ntest_input = { \"nums\": [12,13,16,31,48,52,56,72,79], \"moveFrom\": [13,79,12,72,14,48,56,52], \"moveTo\": [56,14,8,63,70,54,19,73] }\nassert my_solution.relocateMarbles(**test_input) == [8,16,19,31,54,63,70,73]\n\ntest_input = { \"nums\": [3,7,7,14], \"moveFrom\": [3,16,7,15,12,5,14,16,13], \"moveTo\": [16,15,5,12,16,14,9,13,5] }\nassert my_solution.relocateMarbles(**test_input) == [5,9]\n\ntest_input = { \"nums\": [9,13,14,15], \"moveFrom\": [15,14,13,5,8], \"moveTo\": [8,3,5,3,12] }\nassert my_solution.relocateMarbles(**test_input) == [3,9,12]\n\ntest_input = { \"nums\": [11,16,28,33,37,45,45,58,79], \"moveFrom\": [16,57,81,79,11], \"moveTo\": [57,81,29,45,31] }\nassert my_solution.relocateMarbles(**test_input) == [28,29,31,33,37,45,58]\n\ntest_input = { \"nums\": [1,6,7,7], \"moveFrom\": [6,8,8,12,15,8,9,15], \"moveTo\": [8,8,12,15,8,9,15,8] }\nassert my_solution.relocateMarbles(**test_input) == [1,7,8]\n\ntest_input = { \"nums\": [7,20,23,25,33,39,51,74,76], \"moveFrom\": [76,20,74,7,15], \"moveTo\": [74,64,15,40,71] }\nassert my_solution.relocateMarbles(**test_input) == [23,25,33,39,40,51,64,71]\n\ntest_input = { \"nums\": [4,6,6], \"moveFrom\": [6,4,7,6,4,7,8,1,2,4], \"moveTo\": [6,7,4,7,8,2,1,9,4,2] }\nassert my_solution.relocateMarbles(**test_input) == [2,9]\n\ntest_input = { \"nums\": [8,14,17,19,21], \"moveFrom\": [19,8,14,21,17,1,14,18], \"moveTo\": [14,18,14,1,18,23,10,12] }\nassert my_solution.relocateMarbles(**test_input) == [10,12,23]\n\ntest_input = { \"nums\": [13,18,39,44,45,49,72,81,95,100], \"moveFrom\": [49,81,18,39,44,22,100,66,45,5], \"moveTo\": [54,22,66,32,13,4,76,5,92,33] }\nassert my_solution.relocateMarbles(**test_input) == [4,13,32,33,54,72,76,92,95]\n\ntest_input = { \"nums\": [1,3], \"moveFrom\": [3,1,3,4,3,3,3,3,2], \"moveTo\": [1,3,4,3,3,3,3,2,3] }\nassert my_solution.relocateMarbles(**test_input) == [3]\n\ntest_input = { \"nums\": [2,4,5,13], \"moveFrom\": [13,5,2], \"moveTo\": [1,9,10] }\nassert my_solution.relocateMarbles(**test_input) == [1,4,9,10]\n\ntest_input = { \"nums\": [1], \"moveFrom\": [1], \"moveTo\": [1] }\nassert my_solution.relocateMarbles(**test_input) == [1]\n\ntest_input = { \"nums\": [3,4,13,14,19], \"moveFrom\": [13,3,19,3,3,14,13,4,15,11], \"moveTo\": [15,3,8,3,13,1,10,22,11,2] }\nassert my_solution.relocateMarbles(**test_input) == [1,2,8,10,22]\n\ntest_input = { \"nums\": [3,6,9,11], \"moveFrom\": [9,3,8], \"moveTo\": [7,8,9] }\nassert my_solution.relocateMarbles(**test_input) == [6,7,9,11]\n\ntest_input = { \"nums\": [9,15,16,18,20,26], \"moveFrom\": [20,18,13], \"moveTo\": [31,13,32] }\nassert my_solution.relocateMarbles(**test_input) == [9,15,16,26,31,32]\n\ntest_input = { \"nums\": [6,11,21,25,25], \"moveFrom\": [11,21,2,25,17,1], \"moveTo\": [17,2,19,8,1,9] }\nassert my_solution.relocateMarbles(**test_input) == [6,8,9,19]\n\ntest_input = { \"nums\": [2,6,8], \"moveFrom\": [2,6,8,2,9,2,7], \"moveTo\": [8,2,2,9,2,7,8] }\nassert my_solution.relocateMarbles(**test_input) == [8]\n\ntest_input = { \"nums\": [1,7,7], \"moveFrom\": [1,7,1,6,2,9,5,6], \"moveTo\": [2,1,6,9,5,6,5,6] }\nassert my_solution.relocateMarbles(**test_input) == [5,6]\n\ntest_input = { \"nums\": [4,6,7,12,12,25,37], \"moveFrom\": [37,41,37,6,4,7,25], \"moveTo\": [41,37,37,26,7,45,45] }\nassert my_solution.relocateMarbles(**test_input) == [12,26,37,45]\n\ntest_input = { \"nums\": [3,4], \"moveFrom\": [4,3], \"moveTo\": [2,1] }\nassert my_solution.relocateMarbles(**test_input) == [1,2]\n\ntest_input = { \"nums\": [1,2], \"moveFrom\": [1,2,3,3,2,1,2], \"moveTo\": [2,3,3,2,1,2,2] }\nassert my_solution.relocateMarbles(**test_input) == [2]\n\ntest_input = { \"nums\": [20,37,44,53,55,59,60,62], \"moveFrom\": [20,44,53,60,11,55,37,59], \"moveTo\": [53,28,62,11,16,63,9,6] }\nassert my_solution.relocateMarbles(**test_input) == [6,9,16,28,62,63]\n\ntest_input = { \"nums\": [2,4], \"moveFrom\": [4,2,2,1,4,2,2,3], \"moveTo\": [2,2,1,4,2,2,3,4] }\nassert my_solution.relocateMarbles(**test_input) == [4]\n\ntest_input = { \"nums\": [2,6,7], \"moveFrom\": [6,7,6,3,6,5,2], \"moveTo\": [6,6,3,6,5,4,8] }\nassert my_solution.relocateMarbles(**test_input) == [4,8]\n\ntest_input = { \"nums\": [3,7,13,13], \"moveFrom\": [13,7,4,6], \"moveTo\": [9,4,6,15] }\nassert my_solution.relocateMarbles(**test_input) == [3,9,15]\n\ntest_input = { \"nums\": [2,3], \"moveFrom\": [2,3], \"moveTo\": [1,1] }\nassert my_solution.relocateMarbles(**test_input) == [1]\n\ntest_input = { \"nums\": [12,13,25,27,34,34,38], \"moveFrom\": [12,13,11,33,2,25,34,27,38], \"moveTo\": [11,2,33,26,25,30,24,38,47] }\nassert my_solution.relocateMarbles(**test_input) == [24,26,30,47]\n\ntest_input = { \"nums\": [2,13,20,29,34,48,48], \"moveFrom\": [2,13], \"moveTo\": [5,42] }\nassert my_solution.relocateMarbles(**test_input) == [5,20,29,34,42,48]\n\ntest_input = { \"nums\": [19,30,31,41,47,54,57,62], \"moveFrom\": [41,31,62,30,54], \"moveTo\": [38,49,10,60,31] }\nassert my_solution.relocateMarbles(**test_input) == [10,19,31,38,47,49,57,60]", "start_time": 1688826600} +{"task_id": "biweekly-contest-108-partition-string-into-minimum-beautiful-substrings", "url": "https://leetcode.com/problems/partition-string-into-minimum-beautiful-substrings", "title": "partition-string-into-minimum-beautiful-substrings", "meta": {"questionId": "2883", "questionFrontendId": "2767", "title": "Partition String Into Minimum Beautiful Substrings", "titleSlug": "partition-string-into-minimum-beautiful-substrings", "isPaidOnly": false, "difficulty": "Medium", "likes": 289, "dislikes": 8, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nGiven a binary string s, partition the string into one or more substrings such that each substring is beautiful.\n\nA string is beautiful if:\n\n * It doesn't contain leading zeros.\n * It's the binary representation of a number that is a power of 5.\n\nReturn the minimum number of substrings in such partition. If it is impossible to partition the string s into beautiful substrings, return -1.\n\nA substring is a contiguous sequence of characters in a string.\n\nExample 1:\n\nInput: s = \"1011\"\nOutput: 2\nExplanation: We can paritition the given string into [\"101\", \"1\"].\n- The string \"101\" does not contain leading zeros and is the binary representation of integer 51 = 5.\n- The string \"1\" does not contain leading zeros and is the binary representation of integer 50 = 1.\nIt can be shown that 2 is the minimum number of beautiful substrings that s can be partitioned into.\n\nExample 2:\n\nInput: s = \"111\"\nOutput: 3\nExplanation: We can paritition the given string into [\"1\", \"1\", \"1\"].\n- The string \"1\" does not contain leading zeros and is the binary representation of integer 50 = 1.\nIt can be shown that 3 is the minimum number of beautiful substrings that s can be partitioned into.\n\nExample 3:\n\nInput: s = \"0\"\nOutput: -1\nExplanation: We can not partition the given string into beautiful substrings.\n\n\nConstraints:\n\n * 1 <= s.length <= 15\n * s[i] is either '0' or '1'.\n\"\"\"\nclass Solution:\n def minimumBeautifulSubstrings(self, s: str) -> int:\n ", "prompt_sft": "Given a binary string s, partition the string into one or more substrings such that each substring is beautiful.\n\nA string is beautiful if:\n\n * It doesn't contain leading zeros.\n * It's the binary representation of a number that is a power of 5.\n\nReturn the minimum number of substrings in such partition. If it is impossible to partition the string s into beautiful substrings, return -1.\n\nA substring is a contiguous sequence of characters in a string.\n\nExample 1:\n\nInput: s = \"1011\"\nOutput: 2\nExplanation: We can paritition the given string into [\"101\", \"1\"].\n- The string \"101\" does not contain leading zeros and is the binary representation of integer 51 = 5.\n- The string \"1\" does not contain leading zeros and is the binary representation of integer 50 = 1.\nIt can be shown that 2 is the minimum number of beautiful substrings that s can be partitioned into.\n\nExample 2:\n\nInput: s = \"111\"\nOutput: 3\nExplanation: We can paritition the given string into [\"1\", \"1\", \"1\"].\n- The string \"1\" does not contain leading zeros and is the binary representation of integer 50 = 1.\nIt can be shown that 3 is the minimum number of beautiful substrings that s can be partitioned into.\n\nExample 3:\n\nInput: s = \"0\"\nOutput: -1\nExplanation: We can not partition the given string into beautiful substrings.\n\n\nConstraints:\n\n * 1 <= s.length <= 15\n * s[i] is either '0' or '1'.\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def minimumBeautifulSubstrings(self, s: str) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"s\": \"1011\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 2\n\ntest_input = { \"s\": \"111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 3\n\ntest_input = { \"s\": \"0\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == -1\n\ntest_input = { \"s\": \"100111000110111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 4\n\ntest_input = { \"s\": \"100111000111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 3\n\ntest_input = { \"s\": \"1001110001111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 4\n\ntest_input = { \"s\": \"100111000111101\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 4\n\ntest_input = { \"s\": \"10110011100011\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 3\n\ntest_input = { \"s\": \"101101\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 2\n\ntest_input = { \"s\": \"101101101\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 3\n\ntest_input = { \"s\": \"101101101101101\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 5\n\ntest_input = { \"s\": \"1011011011101\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 5\n\ntest_input = { \"s\": \"10110110111011\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 6\n\ntest_input = { \"s\": \"101101101111001\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 5\n\ntest_input = { \"s\": \"1011011011111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 7\n\ntest_input = { \"s\": \"101101110011101\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 5\n\ntest_input = { \"s\": \"10110111001111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 6\n\ntest_input = { \"s\": \"1011011101101\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 5\n\ntest_input = { \"s\": \"101101110110111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 7\n\ntest_input = { \"s\": \"101101110111011\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 7\n\ntest_input = { \"s\": \"1011011101111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 7\n\ntest_input = { \"s\": \"101101110111101\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 7\n\ntest_input = { \"s\": \"10110111011111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 8\n\ntest_input = { \"s\": \"101101111001101\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 5\n\ntest_input = { \"s\": \"10110111101\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 5\n\ntest_input = { \"s\": \"10110111101101\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 6\n\ntest_input = { \"s\": \"101101111011011\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 7\n\ntest_input = { \"s\": \"101101111011101\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 7\n\ntest_input = { \"s\": \"10110111101111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 8\n\ntest_input = { \"s\": \"101101111011111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 9\n\ntest_input = { \"s\": \"1011011111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 6\n\ntest_input = { \"s\": \"1011011111001\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 5\n\ntest_input = { \"s\": \"101101111101\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 6\n\ntest_input = { \"s\": \"1011011111011\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 7\n\ntest_input = { \"s\": \"10110111110111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 8\n\ntest_input = { \"s\": \"10110111111001\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 6\n\ntest_input = { \"s\": \"101101111110011\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 7\n\ntest_input = { \"s\": \"10110111111011\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 4\n\ntest_input = { \"s\": \"101101111110111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 5\n\ntest_input = { \"s\": \"101101111111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 8\n\ntest_input = { \"s\": \"101101111111101\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 5\n\ntest_input = { \"s\": \"101110011011\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 4\n\ntest_input = { \"s\": \"10111001101101\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 4\n\ntest_input = { \"s\": \"101110011011111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 7\n\ntest_input = { \"s\": \"1011100111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 4\n\ntest_input = { \"s\": \"10111001110001\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 3\n\ntest_input = { \"s\": \"10111001110011\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 4\n\ntest_input = { \"s\": \"1011100111011\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 5\n\ntest_input = { \"s\": \"10111001110111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 6\n\ntest_input = { \"s\": \"10111001111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 5\n\ntest_input = { \"s\": \"10111001111001\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 4\n\ntest_input = { \"s\": \"1011100111101\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 5\n\ntest_input = { \"s\": \"101110011110111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 7\n\ntest_input = { \"s\": \"101110011111001\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 5\n\ntest_input = { \"s\": \"10111001111101\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 6\n\ntest_input = { \"s\": \"101110011111011\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 7\n\ntest_input = { \"s\": \"1011100111111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 7\n\ntest_input = { \"s\": \"10111001111111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 8\n\ntest_input = { \"s\": \"1011101101\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 4\n\ntest_input = { \"s\": \"10111011011011\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 6\n\ntest_input = { \"s\": \"101110110111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 6\n\ntest_input = { \"s\": \"101110110111011\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 7\n\ntest_input = { \"s\": \"1011101101111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 7\n\ntest_input = { \"s\": \"101110111001101\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 5\n\ntest_input = { \"s\": \"101110111001111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 7\n\ntest_input = { \"s\": \"10111011101\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 5\n\ntest_input = { \"s\": \"10111011101111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 8\n\ntest_input = { \"s\": \"101110111011111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 9\n\ntest_input = { \"s\": \"1011101111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 6\n\ntest_input = { \"s\": \"1011101111001\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 5\n\ntest_input = { \"s\": \"10111011110011\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 6\n\ntest_input = { \"s\": \"101110111101\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 6\n\ntest_input = { \"s\": \"1011101111011\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 7\n\ntest_input = { \"s\": \"10111011111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 7\n\ntest_input = { \"s\": \"10111011111001\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 6\n\ntest_input = { \"s\": \"10111011111011\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 8\n\ntest_input = { \"s\": \"101110111110111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 9\n\ntest_input = { \"s\": \"101110111111001\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 7\n\ntest_input = { \"s\": \"101110111111011\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 5\n\ntest_input = { \"s\": \"101110111111101\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 5\n\ntest_input = { \"s\": \"10111011111111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 10\n\ntest_input = { \"s\": \"101110111111111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 11\n\ntest_input = { \"s\": \"101111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 4\n\ntest_input = { \"s\": \"101111001\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 3\n\ntest_input = { \"s\": \"1011110011\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 4\n\ntest_input = { \"s\": \"10111100110111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 6\n\ntest_input = { \"s\": \"101111001110001\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 4\n\ntest_input = { \"s\": \"101111001111101\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 7\n\ntest_input = { \"s\": \"10111100111111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 8\n\ntest_input = { \"s\": \"101111011\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 5\n\ntest_input = { \"s\": \"10111101101\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 5\n\ntest_input = { \"s\": \"101111011011\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 6\n\ntest_input = { \"s\": \"10111101101101\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 6\n\ntest_input = { \"s\": \"1011110110111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 7\n\ntest_input = { \"s\": \"1011110111101\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 7\n\ntest_input = { \"s\": \"101111011110111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 9\n\ntest_input = { \"s\": \"101111011111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 8\n\ntest_input = { \"s\": \"1011110111111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 9\n\ntest_input = { \"s\": \"101111011111101\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 5\n\ntest_input = { \"s\": \"10111101111111\" }\nassert my_solution.minimumBeautifulSubstrings(**test_input) == 10", "start_time": 1688826600} +{"task_id": "biweekly-contest-108-number-of-black-blocks", "url": "https://leetcode.com/problems/number-of-black-blocks", "title": "number-of-black-blocks", "meta": {"questionId": "2889", "questionFrontendId": "2768", "title": "Number of Black Blocks", "titleSlug": "number-of-black-blocks", "isPaidOnly": false, "difficulty": "Medium", "likes": 204, "dislikes": 21, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given two integers m and n representing the dimensions of a 0-indexed m x n grid.\n\nYou are also given a 0-indexed 2D integer matrix coordinates, where coordinates[i] = [x, y] indicates that the cell with coordinates [x, y] is colored black. All cells in the grid that do not appear in coordinates are white.\n\nA block is defined as a 2 x 2 submatrix of the grid. More formally, a block with cell [x, y] as its top-left corner where 0 <= x < m - 1 and 0 <= y < n - 1 contains the coordinates [x, y], [x + 1, y], [x, y + 1], and [x + 1, y + 1].\n\nReturn a 0-indexed integer array arr of size 5 such that arr[i] is the number of blocks that contains exactly i black cells.\n\nExample 1:\n\nInput: m = 3, n = 3, coordinates = [[0,0]]\nOutput: [3,1,0,0,0]\nExplanation: The grid looks like this:\n[https://assets.leetcode.com/uploads/2023/06/18/screen-shot-2023-06-18-at-44656-am.png]\nThere is only 1 block with one black cell, and it is the block starting with cell [0,0].\nThe other 3 blocks start with cells [0,1], [1,0] and [1,1]. They all have zero black cells.\nThus, we return [3,1,0,0,0].\n\nExample 2:\n\nInput: m = 3, n = 3, coordinates = [[0,0],[1,1],[0,2]]\nOutput: [0,2,2,0,0]\nExplanation: The grid looks like this:\n[https://assets.leetcode.com/uploads/2023/06/18/screen-shot-2023-06-18-at-45018-am.png]\nThere are 2 blocks with two black cells (the ones starting with cell coordinates [0,0] and [0,1]).\nThe other 2 blocks have starting cell coordinates of [1,0] and [1,1]. They both have 1 black cell.\nTherefore, we return [0,2,2,0,0].\n\n\nConstraints:\n\n * 2 <= m <= 105\n * 2 <= n <= 105\n * 0 <= coordinates.length <= 104\n * coordinates[i].length == 2\n * 0 <= coordinates[i][0] < m\n * 0 <= coordinates[i][1] < n\n * It is guaranteed that coordinates contains pairwise distinct coordinates.\n\"\"\"\nclass Solution:\n def countBlackBlocks(self, m: int, n: int, coordinates: List[List[int]]) -> List[int]:\n ", "prompt_sft": "You are given two integers m and n representing the dimensions of a 0-indexed m x n grid.\n\nYou are also given a 0-indexed 2D integer matrix coordinates, where coordinates[i] = [x, y] indicates that the cell with coordinates [x, y] is colored black. All cells in the grid that do not appear in coordinates are white.\n\nA block is defined as a 2 x 2 submatrix of the grid. More formally, a block with cell [x, y] as its top-left corner where 0 <= x < m - 1 and 0 <= y < n - 1 contains the coordinates [x, y], [x + 1, y], [x, y + 1], and [x + 1, y + 1].\n\nReturn a 0-indexed integer array arr of size 5 such that arr[i] is the number of blocks that contains exactly i black cells.\n\nExample 1:\n\nInput: m = 3, n = 3, coordinates = [[0,0]]\nOutput: [3,1,0,0,0]\nExplanation: The grid looks like this:\n[https://assets.leetcode.com/uploads/2023/06/18/screen-shot-2023-06-18-at-44656-am.png]\nThere is only 1 block with one black cell, and it is the block starting with cell [0,0].\nThe other 3 blocks start with cells [0,1], [1,0] and [1,1]. They all have zero black cells.\nThus, we return [3,1,0,0,0].\n\nExample 2:\n\nInput: m = 3, n = 3, coordinates = [[0,0],[1,1],[0,2]]\nOutput: [0,2,2,0,0]\nExplanation: The grid looks like this:\n[https://assets.leetcode.com/uploads/2023/06/18/screen-shot-2023-06-18-at-45018-am.png]\nThere are 2 blocks with two black cells (the ones starting with cell coordinates [0,0] and [0,1]).\nThe other 2 blocks have starting cell coordinates of [1,0] and [1,1]. They both have 1 black cell.\nTherefore, we return [0,2,2,0,0].\n\n\nConstraints:\n\n * 2 <= m <= 105\n * 2 <= n <= 105\n * 0 <= coordinates.length <= 104\n * coordinates[i].length == 2\n * 0 <= coordinates[i][0] < m\n * 0 <= coordinates[i][1] < n\n * It is guaranteed that coordinates contains pairwise distinct coordinates.\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def countBlackBlocks(self, m: int, n: int, coordinates: List[List[int]]) -> List[int]:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"m\": 3, \"n\": 3, \"coordinates\": [[0,0]] }\nassert my_solution.countBlackBlocks(**test_input) == [3,1,0,0,0]\n\ntest_input = { \"m\": 3, \"n\": 3, \"coordinates\": [[0,0],[1,1],[0,2]] }\nassert my_solution.countBlackBlocks(**test_input) == [0,2,2,0,0]\n\ntest_input = { \"m\": 32, \"n\": 32, \"coordinates\": [[17,29],[29,16],[19,20],[18,9],[16,7],[20,25],[22,19],[4,9],[14,17],[6,23],[2,2],[20,1],[8,7],[4,7],[14,14],[10,10],[1,27],[18,23],[6,30],[8,18],[26,23],[25,8],[5,6],[3,4]] }\nassert my_solution.countBlackBlocks(**test_input) == [866,94,1,0,0]\n\ntest_input = { \"m\": 22, \"n\": 73, \"coordinates\": [[11,14],[16,11],[20,5],[5,33],[14,7],[16,60],[0,15],[15,72],[6,60],[9,16],[14,51],[1,52],[18,24],[17,30],[3,4],[19,13],[9,10],[11,40],[15,7],[13,62],[8,41],[12,71],[4,72],[18,7],[1,0],[4,35],[16,33],[7,30],[13,52],[5,1],[15,21],[3,59],[2,41],[4,28]] }\nassert my_solution.countBlackBlocks(**test_input) == [1387,122,3,0,0]\n\ntest_input = { \"m\": 22, \"n\": 79, \"coordinates\": [[11,43],[17,56],[11,58],[19,68],[5,10],[18,35],[18,27],[10,53],[1,72],[4,64],[4,72],[3,76],[18,36],[14,47],[12,57],[10,11],[13,5],[17,39],[1,4],[3,32],[6,34],[2,62],[8,35],[9,18],[12,77],[8,43],[1,49],[15,14],[15,27],[4,68],[19,24],[9,19],[17,3],[3,51],[5,61]] }\nassert my_solution.countBlackBlocks(**test_input) == [1503,130,5,0,0]\n\ntest_input = { \"m\": 3, \"n\": 89, \"coordinates\": [[0,46],[1,29],[0,50],[1,61]] }\nassert my_solution.countBlackBlocks(**test_input) == [164,12,0,0,0]\n\ntest_input = { \"m\": 25, \"n\": 97, \"coordinates\": [[23,65],[11,33],[6,76],[9,65],[18,13],[16,59],[0,86],[17,14],[23,61],[8,78],[19,40],[18,57],[1,66],[15,1],[13,44],[17,6],[14,90],[1,22],[5,34],[0,53],[1,65],[20,32],[22,54],[3,11],[20,53],[7,70],[0,30],[23,17],[18,2],[14,93],[1,28],[19,82],[6,61],[13,64],[6,73],[0,52],[17,93],[20,63],[16,24],[14,6],[20,28],[4,57],[19,76],[21,50],[5,44],[5,29],[11,36],[14,87],[2,10],[4,78],[12,35],[11,27],[20,7],[11,20],[9,51],[22,37],[11,30],[2,77],[5,87],[13,5],[2,56],[23,25],[0,44],[19,23],[23,1],[3,70],[3,86],[17,92],[19,24],[23,39],[16,2],[15,45],[14,82],[21,30],[11,90],[7,82],[17,50],[12,66],[22,84],[15,71],[14,54]] }\nassert my_solution.countBlackBlocks(**test_input) == [2002,290,12,0,0]\n\ntest_input = { \"m\": 58, \"n\": 74, \"coordinates\": [[38,21],[1,34],[29,15],[46,33],[56,7],[55,63],[7,32],[53,38],[30,73],[17,68],[32,26],[13,39],[10,22],[42,38],[29,9],[7,53],[17,2],[56,13],[34,26],[31,30],[16,21],[13,56],[16,72],[21,8],[47,28],[2,24],[32,23],[13,4],[37,29],[1,11],[45,70],[49,40],[11,61],[20,49],[11,4],[17,61],[11,68],[14,64],[31,10],[1,14],[10,47],[21,48],[46,51],[25,59],[45,12],[47,43],[32,39],[11,28],[55,46],[50,7]] }\nassert my_solution.countBlackBlocks(**test_input) == [3964,196,1,0,0]\n\ntest_input = { \"m\": 40, \"n\": 82, \"coordinates\": [[11,63],[20,43],[16,53],[33,52],[7,30],[36,2],[25,65],[10,31],[4,29],[31,17],[14,52],[36,32],[35,68],[26,8],[20,68],[21,45],[7,46],[32,15],[33,13],[30,4],[32,9],[32,78],[32,66],[27,58],[20,14],[12,29],[8,80],[2,1],[1,0],[34,41],[1,3],[1,74],[0,69],[21,7],[36,16],[0,21],[4,80],[33,78],[18,11],[18,50],[17,63],[24,29]] }\nassert my_solution.countBlackBlocks(**test_input) == [3000,156,3,0,0]\n\ntest_input = { \"m\": 57, \"n\": 92, \"coordinates\": [[38,14],[27,72]] }\nassert my_solution.countBlackBlocks(**test_input) == [5088,8,0,0,0]\n\ntest_input = { \"m\": 94, \"n\": 98, \"coordinates\": [[39,62],[40,20],[47,78],[75,10],[52,82],[11,77],[52,21],[22,12],[75,42],[75,68],[42,39],[68,75],[1,29],[18,79],[56,82],[72,41],[52,28],[61,83],[44,55],[73,81],[43,71],[55,23],[4,13],[89,68],[36,57],[48,22],[64,49],[10,72],[84,80],[1,77],[50,7],[54,0],[76,9],[57,6],[7,81],[66,80]] }\nassert my_solution.countBlackBlocks(**test_input) == [8880,140,1,0,0]\n\ntest_input = { \"m\": 30, \"n\": 97, \"coordinates\": [] }\nassert my_solution.countBlackBlocks(**test_input) == [2784,0,0,0,0]\n\ntest_input = { \"m\": 11, \"n\": 28, \"coordinates\": [[7,24],[8,22],[1,5],[6,21],[0,22],[0,15],[4,16],[2,11],[0,11],[1,3],[3,26],[1,20],[5,27],[9,8],[7,25],[0,19],[3,21],[2,13],[6,7],[5,13],[0,1],[4,18],[4,1],[2,24],[7,17],[3,15],[9,18],[1,25],[3,18],[4,27],[4,20],[4,7],[9,12],[7,1],[3,12],[5,26],[5,23],[2,4],[3,5],[6,18],[4,10],[8,8],[2,7],[7,15],[5,0],[4,9],[8,1],[8,0],[1,17],[3,9],[2,10],[1,13],[0,10],[8,14],[1,21],[1,10],[7,8],[4,6],[7,23],[0,20],[8,13],[3,24],[1,15],[5,24],[4,11],[9,14],[4,12],[7,2],[2,25],[2,9],[6,14],[0,25],[7,4],[4,2],[6,1],[4,8],[6,17]] }\nassert my_solution.countBlackBlocks(**test_input) == [83,107,63,17,0]\n\ntest_input = { \"m\": 6, \"n\": 47, \"coordinates\": [[1,1],[1,23],[1,5],[0,22],[1,12],[0,24],[4,24],[2,8],[1,11],[0,31],[1,39],[0,43],[2,18],[1,17],[1,3],[3,10],[0,26],[2,38],[1,0],[3,37],[3,2],[1,26],[4,34],[3,24],[0,23]] }\nassert my_solution.countBlackBlocks(**test_input) == [159,58,11,2,0]\n\ntest_input = { \"m\": 45, \"n\": 88, \"coordinates\": [[13,14],[6,48],[4,20],[18,57],[2,48],[0,70],[42,71],[20,70],[29,11],[34,24],[24,28],[38,45],[31,73],[41,85],[18,69]] }\nassert my_solution.countBlackBlocks(**test_input) == [3770,58,0,0,0]\n\ntest_input = { \"m\": 7, \"n\": 36, \"coordinates\": [[2,21],[3,14],[4,18],[5,30],[4,26],[5,7],[2,31],[4,22],[0,0],[2,22],[4,6],[0,30],[0,19],[0,21],[3,11],[4,28],[5,25],[2,11],[0,23],[5,16],[3,29],[3,17],[4,11],[1,7],[1,19],[1,34],[5,19],[5,6],[5,28],[4,8],[2,9],[1,6],[4,24],[2,14],[1,24],[3,16],[0,2],[0,26],[5,27],[3,35],[2,16],[4,2],[4,32],[5,0],[0,34],[1,5],[2,4],[1,4],[0,22],[2,2],[3,19],[3,4],[1,10],[3,5],[1,29],[0,33],[0,3]] }\nassert my_solution.countBlackBlocks(**test_input) == [63,99,42,6,0]\n\ntest_input = { \"m\": 59, \"n\": 60, \"coordinates\": [[4,37],[56,0],[32,53],[27,8],[18,42],[5,25],[11,46],[51,55],[55,16],[7,17],[47,1],[47,38],[28,7],[17,39],[29,59],[47,39],[56,42],[2,31],[41,16],[44,32],[27,1],[14,8],[38,52],[38,48],[40,12],[25,32],[15,55],[12,22],[0,38],[38,58],[54,52],[19,28],[39,45],[10,43],[44,26],[18,14],[34,30],[6,23],[39,22],[15,29],[50,31],[24,11],[12,5],[42,45],[18,38],[27,56],[33,58],[54,24],[40,24],[24,2],[28,44],[33,53],[49,57],[47,56],[50,18],[25,14],[56,54],[40,55],[53,44],[27,42],[39,23],[44,38],[25,2],[47,14],[27,50],[26,46],[15,1],[16,15],[55,56],[27,21],[6,7]] }\nassert my_solution.countBlackBlocks(**test_input) == [3155,256,11,0,0]\n\ntest_input = { \"m\": 89, \"n\": 90, \"coordinates\": [[12,15],[31,16],[75,79],[86,48],[19,77],[39,82],[77,62],[75,35],[19,35]] }\nassert my_solution.countBlackBlocks(**test_input) == [7796,36,0,0,0]\n\ntest_input = { \"m\": 26, \"n\": 42, \"coordinates\": [[7,13],[1,3],[11,32],[5,8],[11,4],[9,24],[0,0],[18,20],[13,35],[19,31],[15,35],[1,41],[18,40],[18,41],[14,11],[20,0],[11,6],[14,16],[0,11],[4,36],[9,12],[20,36],[14,33],[6,34],[0,12],[22,6],[22,34],[13,6],[12,1],[4,23],[6,18],[11,38],[19,17],[22,27],[21,6],[3,35],[9,11],[23,6],[22,29],[8,5],[6,26],[3,18],[0,2],[3,41],[24,6],[24,1],[7,9],[8,35],[0,6],[6,23],[13,40],[10,38],[10,20],[21,7],[20,11],[10,11],[19,3],[14,9],[1,5],[3,30],[9,9],[17,34],[18,16],[3,26],[18,19],[17,16],[2,17],[5,22],[5,41],[16,32],[9,7],[1,36],[6,30],[6,38],[9,20],[4,28],[12,8],[7,26],[5,30],[2,27],[3,32],[11,7],[7,41],[8,4],[10,34],[19,19],[13,32],[23,25]] }\nassert my_solution.countBlackBlocks(**test_input) == [739,246,37,3,0]\n\ntest_input = { \"m\": 31, \"n\": 46, \"coordinates\": [[5,31],[13,5],[6,32],[3,24],[5,41],[22,22],[18,38],[29,11],[25,28],[10,43],[29,5],[10,28],[21,2],[27,1],[4,42],[18,2],[22,26],[22,4],[2,26],[21,4],[5,32],[0,43],[24,32],[2,30],[18,44],[18,43],[7,36],[15,13],[11,29],[6,17],[10,7],[15,8],[4,11],[9,7],[28,1],[0,15],[21,19],[6,0],[24,19],[1,0],[15,30],[1,18],[4,24],[1,9],[24,16],[22,28],[4,35],[14,15],[27,23],[13,1],[2,8],[4,20],[19,30],[15,11],[0,34],[27,21],[10,1],[10,33],[11,26],[13,40],[11,45],[25,4],[28,28],[4,7],[7,29],[3,45],[20,17],[25,38],[27,41],[23,35],[19,10],[2,7],[0,25],[4,18],[23,37],[6,38]] }\nassert my_solution.countBlackBlocks(**test_input) == [1081,251,17,1,0]\n\ntest_input = { \"m\": 11, \"n\": 21, \"coordinates\": [[0,19],[2,8],[6,9],[5,15],[6,15],[2,5],[3,14],[2,10],[8,13],[4,2],[0,0],[7,19],[9,10],[8,19]] }\nassert my_solution.countBlackBlocks(**test_input) == [153,43,4,0,0]\n\ntest_input = { \"m\": 76, \"n\": 95, \"coordinates\": [[16,61],[1,23],[51,8],[36,87],[60,92],[23,44],[28,93],[15,35],[8,68],[58,57],[58,80],[53,7],[47,25],[55,4],[6,61],[43,56],[6,40],[39,44],[67,76],[44,16],[40,93],[7,6],[59,44],[74,6],[1,72],[38,93],[58,51],[17,79],[73,79],[58,65],[45,28],[17,36],[69,94],[66,73],[56,1],[31,62],[62,68],[54,64],[72,46],[67,59],[9,47],[33,86],[45,49],[3,6],[63,59],[51,47],[31,74],[52,42],[34,80],[61,30],[62,4],[11,9],[44,21],[73,69],[7,77],[43,17],[53,22],[37,10],[49,5],[64,82],[51,77],[74,2],[60,2],[17,53],[16,51],[52,80],[22,23],[17,80],[52,26],[15,1],[19,59],[7,39]] }\nassert my_solution.countBlackBlocks(**test_input) == [6768,278,4,0,0]\n\ntest_input = { \"m\": 65, \"n\": 71, \"coordinates\": [[62,8],[18,63],[23,43],[30,3],[40,48],[60,62],[58,9],[13,20],[47,46],[34,0],[11,6],[17,28],[20,34],[24,48],[24,18],[43,18],[31,59],[25,60],[15,68],[24,35],[33,47],[32,4],[26,42],[35,63],[31,22],[16,0],[45,45],[52,19],[46,49],[36,37],[11,10],[23,5],[4,13],[17,20],[14,41],[26,4],[21,7],[52,40],[31,18],[55,26],[17,57],[41,31],[1,47],[56,61],[46,38],[7,16],[53,13],[45,4],[1,69],[29,15],[46,12],[29,65],[61,10],[35,54],[33,26],[41,34],[55,48],[42,48],[0,8],[44,44],[52,10],[30,37],[14,54],[4,29],[50,58],[41,10],[30,19],[31,1],[31,62],[31,44],[53,7],[12,56],[57,69],[34,2],[34,16],[42,68],[45,15],[44,61],[15,60],[54,69],[1,39],[50,59],[51,47],[52,15],[33,69],[5,51],[19,38],[10,61],[42,17],[60,30]] }\nassert my_solution.countBlackBlocks(**test_input) == [4131,344,5,0,0]\n\ntest_input = { \"m\": 25, \"n\": 95, \"coordinates\": [[8,74],[20,10],[18,56],[23,20],[7,16],[7,5],[23,52],[19,31],[11,93],[0,68],[4,3],[21,52],[17,61],[7,65],[11,20],[1,61],[20,63],[9,71],[11,63],[11,61],[0,74],[17,60],[16,12],[3,54],[23,66],[23,37],[14,0],[19,64],[18,82],[4,87],[14,82],[23,3],[11,86],[3,64],[9,32],[14,8],[1,24],[21,20],[21,38],[22,27],[21,82],[10,58],[19,5],[22,57],[18,44],[10,83]] }\nassert my_solution.countBlackBlocks(**test_input) == [2081,172,3,0,0]\n\ntest_input = { \"m\": 40, \"n\": 84, \"coordinates\": [[19,36],[35,7],[3,78],[17,4],[28,8],[20,38],[12,38],[30,6],[37,45],[26,53],[11,46]] }\nassert my_solution.countBlackBlocks(**test_input) == [3193,44,0,0,0]\n\ntest_input = { \"m\": 8, \"n\": 57, \"coordinates\": [[3,38],[1,41],[6,23],[0,54],[3,11],[3,44],[1,24],[0,38],[5,28]] }\nassert my_solution.countBlackBlocks(**test_input) == [360,32,0,0,0]\n\ntest_input = { \"m\": 32, \"n\": 41, \"coordinates\": [[12,13],[20,33],[3,12],[28,40],[9,10],[18,10],[5,18],[9,24],[29,24],[9,33],[25,38],[29,17],[28,25],[0,35],[2,30],[18,37],[7,0],[14,21],[25,27],[17,33],[9,38],[19,22],[17,5],[18,4],[9,18],[15,6],[4,21],[12,4],[5,35],[19,26],[6,6],[0,2],[0,28],[1,13],[19,10],[5,16],[2,31],[24,2],[3,22],[23,12],[0,17],[6,30],[20,31],[10,32],[17,15],[1,34],[28,6],[21,15],[14,11],[27,23],[4,16],[2,11],[21,26],[23,19],[27,15],[3,5],[28,10],[1,2],[27,18],[19,36],[2,2],[17,13],[7,19],[25,0],[5,37],[30,6],[3,39],[28,30],[26,0],[9,5],[23,5],[27,6],[4,26],[15,39],[10,26]] }\nassert my_solution.countBlackBlocks(**test_input) == [976,244,20,0,0]\n\ntest_input = { \"m\": 63, \"n\": 99, \"coordinates\": [[17,28],[7,39],[14,81],[44,4],[21,7],[21,95],[1,89],[57,74],[34,2],[55,56],[43,50],[52,28],[38,61],[35,62],[57,46],[30,72],[25,46],[4,32],[18,25],[53,98]] }\nassert my_solution.countBlackBlocks(**test_input) == [5998,78,0,0,0]\n\ntest_input = { \"m\": 44, \"n\": 97, \"coordinates\": [[17,3],[29,4],[40,71],[32,45],[3,59],[22,34],[11,17],[17,43],[4,32],[8,8],[19,43],[12,19],[32,57],[9,15],[7,46],[4,39],[11,26],[17,87],[21,70],[12,58],[35,88],[12,72],[23,61],[23,43],[3,86],[31,30],[17,26],[14,22],[16,77],[41,73],[39,91],[41,74],[15,78],[31,36],[11,45],[9,57],[25,68],[42,28],[5,60],[38,72],[26,14],[33,48],[39,50],[38,33],[41,21],[39,86],[29,64],[4,69],[37,25],[28,85],[9,32],[9,76],[13,25],[26,43],[10,79],[2,2],[23,85],[39,29],[34,47],[13,17],[34,59],[27,84],[29,93],[17,89],[23,27],[9,16],[39,64],[3,37],[41,75],[32,26],[27,11]] }\nassert my_solution.countBlackBlocks(**test_input) == [3853,266,9,0,0]\n\ntest_input = { \"m\": 45, \"n\": 53, \"coordinates\": [[15,41],[0,27],[24,15],[34,31],[36,27],[32,46],[1,39],[4,8],[18,8],[39,3],[2,50],[6,33],[25,46],[17,41],[27,46],[37,30],[41,23],[16,14],[21,17],[26,47],[31,47],[9,23],[32,21],[29,28],[37,41],[10,37],[21,31],[1,25],[31,19],[16,49],[2,22],[1,43],[39,33],[6,12],[12,39],[40,15],[31,50],[8,7],[5,21],[8,4],[30,10],[15,20],[9,21],[38,28],[42,14],[36,8],[27,5],[2,2],[13,32],[13,50],[22,8],[23,25],[33,23],[9,22],[28,12],[15,37],[40,10],[42,45],[1,11],[26,2],[30,18],[0,19],[15,38],[32,2],[26,19],[29,29],[24,21],[24,10],[19,8],[24,31],[37,34],[5,20],[11,30],[41,19],[34,43],[41,7],[38,36],[13,10],[39,14],[22,4],[34,27],[23,21],[9,24],[13,29],[14,30],[32,48],[9,47],[13,37],[3,4],[1,6],[19,48],[41,47],[40,33],[26,23],[1,4],[40,28],[31,37]] }\nassert my_solution.countBlackBlocks(**test_input) == [1929,334,25,0,0]\n\ntest_input = { \"m\": 36, \"n\": 62, \"coordinates\": [[5,42],[14,2],[32,11],[28,38],[18,49],[23,52],[32,52],[15,39],[11,38],[15,54],[21,27],[14,0],[26,38],[4,43],[22,26],[5,17]] }\nassert my_solution.countBlackBlocks(**test_input) == [2075,58,2,0,0]\n\ntest_input = { \"m\": 30, \"n\": 98, \"coordinates\": [[10,13],[23,8],[9,69],[20,70],[17,12],[12,39],[7,72],[14,0],[5,45],[21,24],[10,88],[2,8],[22,86],[2,28],[20,62],[6,82],[27,10],[7,28],[12,79],[21,38],[24,92],[0,47],[8,8],[26,3],[20,57],[12,36],[21,47],[19,12],[20,35],[28,26],[4,61],[5,90],[0,48],[14,50],[3,63],[17,93],[12,5],[12,94],[7,25]] }\nassert my_solution.countBlackBlocks(**test_input) == [2664,148,1,0,0]\n\ntest_input = { \"m\": 20, \"n\": 41, \"coordinates\": [[11,3],[1,36],[17,23],[13,1],[14,33],[2,23],[0,5],[5,32],[14,36],[8,16],[0,9],[14,26],[8,9],[6,5],[10,12],[17,20],[10,33],[16,23],[12,40],[8,17],[12,35],[11,23],[6,34],[2,4],[7,0],[7,7],[8,27],[7,39],[13,19],[14,2],[9,23],[12,33],[14,20],[12,27],[15,22],[1,19],[10,17],[7,36],[4,29],[12,37],[7,18],[10,20]] }\nassert my_solution.countBlackBlocks(**test_input) == [608,144,8,0,0]\n\ntest_input = { \"m\": 60, \"n\": 73, \"coordinates\": [[45,35],[12,1],[43,11],[58,9],[0,3],[51,34],[1,65],[15,55],[32,29],[41,36],[41,61],[5,39],[54,2],[21,35],[41,69],[12,71],[17,5],[56,59],[41,40],[49,17],[48,56],[18,71],[39,57],[1,46],[53,44],[40,46],[52,14],[57,68],[14,66],[20,26],[48,8],[46,22],[34,41],[15,47],[18,45],[16,29],[40,6],[51,51],[47,70],[29,64],[51,32],[18,40],[10,62],[5,28],[57,3],[43,69],[49,58],[8,7],[18,9],[24,0],[56,0],[23,39],[31,19],[56,12],[34,17],[13,42],[8,23],[28,20],[42,38],[5,16],[29,36],[56,47],[45,23],[51,58],[2,69],[2,44],[5,6],[53,6],[50,48],[51,64],[43,15],[37,70],[18,44],[41,23],[51,31],[31,10],[25,53],[28,46],[56,42],[7,49],[55,50],[31,26],[3,26],[43,52],[54,68],[21,37]] }\nassert my_solution.countBlackBlocks(**test_input) == [3915,328,5,0,0]\n\ntest_input = { \"m\": 37, \"n\": 80, \"coordinates\": [[5,3],[29,79],[35,32],[29,8],[10,57]] }\nassert my_solution.countBlackBlocks(**test_input) == [2826,18,0,0,0]\n\ntest_input = { \"m\": 31, \"n\": 97, \"coordinates\": [[29,40],[29,6],[11,73],[10,81],[12,92],[23,62],[16,86],[26,0],[9,95],[17,17],[22,60],[27,15],[15,70],[7,18],[1,27],[18,51],[14,38],[2,42],[26,43],[0,52],[1,69],[23,50],[26,68],[24,53],[23,31],[7,78],[18,23],[14,96],[25,49],[23,74],[11,35],[5,14],[24,35]] }\nassert my_solution.countBlackBlocks(**test_input) == [2754,126,0,0,0]\n\ntest_input = { \"m\": 17, \"n\": 43, \"coordinates\": [[8,38],[2,23],[15,18],[1,3],[7,40],[3,30],[13,1],[12,40],[9,4],[0,10],[5,36],[3,15],[3,5],[7,23],[5,13],[11,26],[3,28],[14,23],[10,16],[2,11],[14,5],[11,32],[1,20],[4,0],[15,13],[3,12],[12,9],[3,31],[8,35],[8,17],[3,42],[1,36],[5,2],[13,14],[9,2],[6,28],[5,4],[2,1],[13,36],[2,24],[12,29],[15,3],[11,20],[2,25],[13,8],[4,17],[8,29],[0,33],[11,3],[0,29],[12,30],[6,16],[7,33],[13,7],[5,26],[14,24],[3,16],[0,11],[11,28],[11,34],[6,8],[4,25],[14,20],[8,0],[7,32],[7,27],[8,23],[5,14],[4,30],[14,3],[6,21],[6,41],[12,18],[14,25],[8,3],[8,14]] }\nassert my_solution.countBlackBlocks(**test_input) == [418,219,34,1,0]\n\ntest_input = { \"m\": 12, \"n\": 73, \"coordinates\": [[7,64],[5,14],[5,46]] }\nassert my_solution.countBlackBlocks(**test_input) == [780,12,0,0,0]\n\ntest_input = { \"m\": 36, \"n\": 91, \"coordinates\": [[14,10],[28,69],[34,15],[6,62],[2,44],[12,81],[19,47],[32,89],[13,59],[12,25],[8,62],[26,87],[31,29],[16,49],[4,46],[3,46],[10,47],[31,87],[15,44],[1,75],[0,61],[3,35],[3,58],[25,88],[15,56],[30,30],[13,26],[9,49],[24,56],[17,17],[19,85],[23,80],[5,68],[30,79],[34,34],[32,69],[19,58],[20,43],[4,40],[33,44],[21,71],[3,37],[34,54],[10,28],[9,62],[20,19],[21,84],[22,32],[9,90],[10,82],[19,38],[15,51],[32,11],[26,72],[34,46],[17,89],[16,28],[15,81],[0,39],[5,28],[10,5],[20,0],[32,40],[14,76],[8,72]] }\nassert my_solution.countBlackBlocks(**test_input) == [2905,238,7,0,0]\n\ntest_input = { \"m\": 11, \"n\": 76, \"coordinates\": [[2,6],[1,36],[2,60],[3,57],[1,72],[5,15],[1,30],[1,28],[8,15],[4,39],[1,2],[0,56],[5,2],[4,27],[9,2],[3,67],[7,19],[6,54],[7,73],[9,51],[8,63],[0,27],[8,44],[5,31],[0,11]] }\nassert my_solution.countBlackBlocks(**test_input) == [657,92,1,0,0]\n\ntest_input = { \"m\": 24, \"n\": 70, \"coordinates\": [[9,49],[13,17],[14,52],[17,13],[20,40],[6,62],[18,62],[14,9],[13,0],[15,34],[5,33],[18,1],[17,33],[6,63],[4,26],[3,28],[18,68],[2,15],[5,10],[21,13],[10,53],[5,35],[21,60],[9,59],[1,0],[15,53],[5,45],[0,42],[6,24],[9,9],[2,44],[8,12],[1,16],[13,29],[21,38],[20,39],[4,13],[17,56],[10,45],[3,65],[14,15],[5,62],[13,18],[4,35],[18,11],[12,31],[18,18],[7,50],[12,52],[11,47],[7,14],[11,61],[13,1],[2,1],[4,19],[15,8],[0,7],[18,15],[20,31],[1,17],[15,31],[7,39],[5,52],[8,9],[1,50],[16,34],[21,15],[8,66],[5,53],[18,43],[5,19],[9,61],[11,52],[18,36],[4,9],[21,28],[10,30],[17,68],[4,52],[16,38],[15,57],[13,35],[9,32],[2,65],[17,34],[14,1],[16,3]] }\nassert my_solution.countBlackBlocks(**test_input) == [1290,258,35,4,0]\n\ntest_input = { \"m\": 55, \"n\": 74, \"coordinates\": [[33,73],[38,37],[4,69],[23,58],[47,17],[48,36],[46,42],[6,63],[22,23],[36,57],[20,38],[42,66],[31,6],[13,3],[5,40],[25,28],[50,7],[6,7],[23,66],[29,17],[5,67],[41,63],[2,53],[3,24],[25,49],[43,18],[27,11],[37,72],[30,14],[16,70],[22,71],[0,48],[21,4],[8,9],[38,57],[14,12],[13,54],[11,40],[10,28],[9,49],[31,24],[11,28],[11,51],[10,62],[46,39],[3,35],[23,15],[52,25],[37,55],[28,63],[1,2],[26,12],[29,30],[44,62],[35,34],[25,31],[8,63],[8,6],[38,14],[19,14],[8,28],[26,14],[27,36],[20,61],[23,12],[15,20]] }\nassert my_solution.countBlackBlocks(**test_input) == [3685,254,3,0,0]\n\ntest_input = { \"m\": 6, \"n\": 79, \"coordinates\": [[2,64],[4,74],[2,3],[1,63],[2,34],[3,57],[1,1],[3,52],[1,56],[3,1],[1,61],[2,49],[1,66],[2,25],[1,20],[4,51],[0,78],[1,30]] }\nassert my_solution.countBlackBlocks(**test_input) == [323,65,2,0,0]\n\ntest_input = { \"m\": 36, \"n\": 75, \"coordinates\": [[23,28],[21,10],[16,48],[26,45],[13,45],[24,66],[34,15],[20,13],[4,42],[17,14],[7,19],[8,5],[4,27],[16,32],[19,0],[27,69],[18,62],[18,63],[4,24],[15,51],[24,53],[6,46],[33,51],[13,65],[11,39],[14,37],[33,1],[5,16],[24,15],[30,63],[34,23],[12,22],[29,44],[19,8],[3,4],[12,67],[0,44],[4,65],[5,44],[16,13],[16,71],[16,10],[27,71],[28,56],[1,23],[11,42],[1,1],[10,19],[10,18],[8,55],[23,68],[12,23],[12,61],[31,3],[13,14],[20,30],[25,1],[4,37],[25,32]] }\nassert my_solution.countBlackBlocks(**test_input) == [2365,218,7,0,0]\n\ntest_input = { \"m\": 31, \"n\": 87, \"coordinates\": [[12,40],[28,11],[20,65],[24,38],[21,65],[29,11],[11,8],[26,16],[8,25],[18,63],[11,69],[9,16],[14,25],[2,34],[7,14],[26,74],[27,51],[13,53],[25,2],[27,17],[3,45],[23,22],[28,38],[5,26],[23,33],[2,16],[14,41],[22,79],[25,75],[7,79],[9,6],[14,73],[15,61],[27,16],[29,21],[27,72],[16,17],[1,37]] }\nassert my_solution.countBlackBlocks(**test_input) == [2437,135,7,1,0]\n\ntest_input = { \"m\": 55, \"n\": 67, \"coordinates\": [[44,3],[12,10],[20,17],[41,24],[25,40],[21,46],[5,9],[34,64],[29,40],[49,32],[19,37],[42,61],[35,46],[49,52],[16,65],[4,32],[20,48],[5,59],[28,26],[2,3],[40,28],[20,35],[4,29],[47,20],[3,8],[26,39],[7,54],[8,10],[37,5],[33,13],[3,44],[14,63],[21,24],[26,17],[11,60],[19,44],[46,23],[37,6],[9,64],[15,36],[1,36],[44,31],[3,24],[13,3],[49,39],[28,11],[21,32],[27,34],[44,52],[51,51],[17,50],[49,47],[0,5],[11,51],[37,23],[45,45],[50,19],[33,51],[14,36],[7,44],[3,36],[7,27],[18,54],[31,4],[15,12],[38,38],[52,33],[36,16],[25,42],[28,37],[24,50],[26,24],[48,26],[2,24],[33,10],[10,9],[25,26],[15,64],[52,58],[0,44],[7,48],[32,43],[10,6],[43,11],[50,53],[43,26],[13,45],[50,28],[40,0],[31,50],[42,51],[4,59],[18,62],[26,45],[22,44],[37,58],[38,43],[5,53],[23,1],[21,21]] }\nassert my_solution.countBlackBlocks(**test_input) == [3182,370,12,0,0]\n\ntest_input = { \"m\": 19, \"n\": 40, \"coordinates\": [[8,25],[14,19],[9,0],[10,26],[11,8],[4,8],[2,0],[13,6],[4,24],[6,11],[5,19],[2,21],[4,11],[4,29],[1,25],[6,14],[0,28],[5,39],[7,33],[15,7],[13,25],[15,5],[9,34],[0,33],[6,10],[3,20],[6,13],[14,12],[6,17],[3,1],[2,30],[13,16],[14,1],[9,9],[14,10],[17,4],[13,39],[8,7],[16,19],[2,5],[10,19],[1,6],[15,4],[7,0],[3,18],[16,3],[14,21],[10,31],[11,31],[1,33],[2,23],[17,20],[8,9],[0,16],[4,32],[9,4],[9,8],[0,8],[1,0],[13,1],[1,34],[7,9],[8,34],[4,39],[10,7],[4,5],[9,12],[5,36],[15,0],[15,36],[6,22]] }\nassert my_solution.countBlackBlocks(**test_input) == [478,190,32,2,0]\n\ntest_input = { \"m\": 16, \"n\": 27, \"coordinates\": [[7,4],[11,26],[2,21],[3,3],[13,11],[7,14],[0,8]] }\nassert my_solution.countBlackBlocks(**test_input) == [366,24,0,0,0]\n\ntest_input = { \"m\": 34, \"n\": 39, \"coordinates\": [[4,12],[29,24],[15,28],[3,1],[7,0],[0,27],[15,5],[2,0],[16,7],[19,33],[3,11],[5,26],[29,32],[21,32],[31,10],[17,4],[23,32],[5,10],[3,12],[27,11],[12,26],[2,5],[1,0],[20,2],[11,26],[0,11],[12,4],[14,7],[13,18],[9,7],[16,9],[10,3],[3,33],[13,27],[27,18],[11,19],[18,13],[16,21],[2,15],[11,27],[13,33],[8,21],[16,19],[26,27],[3,36],[9,3],[13,38],[10,22],[1,38],[12,31],[13,13],[17,19],[30,1],[15,37],[21,5],[14,15],[6,37],[8,23],[26,22],[24,38],[21,23]] }\nassert my_solution.countBlackBlocks(**test_input) == [1041,200,11,2,0]\n\ntest_input = { \"m\": 26, \"n\": 41, \"coordinates\": [[12,9],[1,18],[7,10],[22,0],[15,10],[12,3],[20,15],[0,27],[16,35],[20,40],[7,38],[13,27],[9,32],[4,26],[9,40],[4,1],[21,33],[16,12],[6,38],[22,40],[10,24],[20,21],[17,31],[12,6],[8,27],[9,15],[5,13],[14,31],[11,17],[20,31],[22,35],[23,19],[23,16],[3,15],[16,11],[23,27],[9,33],[16,3],[5,12],[21,20],[12,1],[13,30],[13,17],[13,22],[9,28],[7,8],[8,5],[19,15],[16,1],[23,36],[4,6],[18,40],[8,19],[5,2],[21,2],[23,7]] }\nassert my_solution.countBlackBlocks(**test_input) == [804,180,16,0,0]\n\ntest_input = { \"m\": 39, \"n\": 68, \"coordinates\": [[35,51],[9,25],[13,28],[14,62],[24,6]] }\nassert my_solution.countBlackBlocks(**test_input) == [2526,20,0,0,0]\n\ntest_input = { \"m\": 33, \"n\": 94, \"coordinates\": [[15,21],[0,63],[25,30],[11,77],[6,65],[14,5],[3,18],[30,61],[21,52],[17,8],[10,69],[24,84],[19,18],[10,75],[4,47],[8,9],[17,22],[3,70],[30,90],[22,58],[15,84],[4,78],[8,15],[20,18],[23,60],[26,83],[27,14],[5,31],[2,48],[18,48],[16,33],[6,31],[1,82],[5,46],[19,13],[0,86],[3,44],[9,49],[13,47],[0,4],[31,52],[6,68],[15,79],[29,47],[6,4],[5,33],[10,9],[30,50],[9,77],[13,79],[20,87],[11,27],[23,86]] }\nassert my_solution.countBlackBlocks(**test_input) == [2775,196,5,0,0]\n\ntest_input = { \"m\": 65, \"n\": 78, \"coordinates\": [[43,38],[0,36],[40,68],[52,19],[16,59],[10,35],[23,1],[1,58],[29,38],[19,49],[34,40],[57,37],[32,66],[35,37],[16,10],[53,51],[9,53],[23,40],[42,74],[31,51],[17,51],[21,32],[33,72]] }\nassert my_solution.countBlackBlocks(**test_input) == [4838,90,0,0,0]\n\ntest_input = { \"m\": 47, \"n\": 80, \"coordinates\": [[26,59],[14,64],[4,67],[17,51],[10,66],[18,78],[17,69],[33,57],[18,44],[16,78],[27,39],[22,18],[16,69],[21,5],[19,52],[39,40],[13,17],[15,10],[30,33],[9,67],[34,10],[3,39],[32,52],[33,71],[24,65],[15,57],[43,53]] }\nassert my_solution.countBlackBlocks(**test_input) == [3529,102,3,0,0]\n\ntest_input = { \"m\": 42, \"n\": 99, \"coordinates\": [[27,29],[39,18],[40,17],[36,14],[17,76],[15,67],[2,41],[37,70],[34,67],[36,15],[23,57],[7,46],[7,42],[3,91],[3,32],[17,30],[35,37],[25,91],[32,83],[20,81],[20,19],[23,51],[17,10],[23,61],[18,24],[3,13],[16,48],[0,88],[31,81],[4,20],[34,95],[30,22],[28,58],[4,50],[1,77],[4,13],[7,37],[13,1],[28,75],[28,77],[4,4],[31,20],[40,6],[18,65]] }\nassert my_solution.countBlackBlocks(**test_input) == [3849,164,5,0,0]\n\ntest_input = { \"m\": 77, \"n\": 80, \"coordinates\": [[34,8],[7,40],[67,29],[64,70],[32,71],[17,29],[19,15],[6,77],[68,39],[11,9],[9,59],[19,63],[44,11],[24,54],[13,15],[10,23],[27,35],[14,68],[9,61],[17,74],[44,56],[37,78],[20,68],[7,58],[9,38],[72,22],[72,33],[41,33],[64,63],[22,69],[2,12],[51,73],[43,32],[16,57],[11,16],[3,38],[14,45],[73,28],[8,51],[72,42],[18,65],[45,42],[42,18],[34,38],[47,50],[47,0],[29,32],[15,66],[43,61],[49,36],[69,71],[47,45],[55,64],[1,62],[42,0],[18,49],[57,48],[22,16],[14,7],[56,10],[49,42],[19,46],[40,68],[65,49],[8,20],[12,0],[31,17],[50,6],[8,14],[6,38],[32,67],[4,3],[10,13],[44,8],[21,43],[70,34],[49,22],[72,47],[59,59],[56,72],[33,30],[18,20],[2,76],[22,33]] }\nassert my_solution.countBlackBlocks(**test_input) == [5674,330,0,0,0]\n\ntest_input = { \"m\": 53, \"n\": 93, \"coordinates\": [] }\nassert my_solution.countBlackBlocks(**test_input) == [4784,0,0,0,0]\n\ntest_input = { \"m\": 48, \"n\": 91, \"coordinates\": [[19,79],[30,11],[6,54],[35,3],[41,20],[8,3],[8,46],[37,67],[21,61],[27,70],[15,32],[44,61],[1,70],[9,68],[28,16],[19,43],[12,68],[21,12],[7,77],[18,32],[1,25],[31,11],[1,82],[10,18],[31,86],[21,24],[11,43],[15,4],[8,12],[39,68],[11,65],[37,53],[10,39],[30,61],[34,46],[33,9],[30,64],[27,59],[31,60],[14,64],[11,70],[16,83],[28,15],[26,21],[33,71],[31,53],[39,36],[27,77],[41,82],[21,45],[3,59],[42,14],[19,59],[5,57]] }\nassert my_solution.countBlackBlocks(**test_input) == [4019,206,5,0,0]\n\ntest_input = { \"m\": 53, \"n\": 77, \"coordinates\": [[29,74],[44,76],[10,11],[11,14],[45,0],[41,19],[32,49],[21,50],[14,41],[7,74],[42,47],[50,19],[6,34],[47,0],[19,64],[39,25],[49,46],[45,1],[9,67],[51,19],[6,59],[24,52],[40,61],[48,23],[23,49],[4,64],[40,27],[49,42],[17,30],[13,14],[3,49],[41,14],[36,0],[5,32],[6,1],[4,27],[11,22],[26,37],[5,61],[22,15],[42,1],[9,33],[20,25],[44,38],[46,16],[10,20],[45,13],[31,27],[27,70],[22,11],[28,17]] }\nassert my_solution.countBlackBlocks(**test_input) == [3760,188,4,0,0]\n\ntest_input = { \"m\": 12, \"n\": 69, \"coordinates\": [[8,6],[1,19],[0,23],[7,8],[7,31],[10,16],[9,2],[6,1],[8,63],[7,45],[5,40],[1,27],[2,14],[6,54],[0,4],[1,62],[4,45],[5,31],[7,33],[2,38]] }\nassert my_solution.countBlackBlocks(**test_input) == [672,76,0,0,0]\n\ntest_input = { \"m\": 49, \"n\": 78, \"coordinates\": [[4,26],[9,25],[9,77],[42,45],[47,12],[30,68],[15,63],[23,11],[24,24],[23,49],[26,77]] }\nassert my_solution.countBlackBlocks(**test_input) == [3656,40,0,0,0]\n\ntest_input = { \"m\": 63, \"n\": 95, \"coordinates\": [[36,71],[2,38],[25,72],[16,54],[38,59],[44,82],[7,57],[8,65],[5,90],[8,82],[56,26],[39,15],[36,30],[31,53],[59,80],[38,25],[50,47],[12,72],[27,26],[41,23],[20,25],[19,74],[22,18],[19,75],[53,61],[25,17],[12,22],[32,40],[40,1],[6,7],[6,24],[46,43],[39,84],[17,92],[12,91],[32,25],[20,68],[11,12],[23,20],[7,36],[42,22],[21,69],[19,9],[25,8],[57,82],[52,83],[43,81],[60,19],[26,83],[18,73],[44,12],[30,45],[25,84],[55,77],[35,41],[53,8],[0,44],[29,36],[36,69],[9,53],[37,15],[24,0],[13,60],[31,62],[56,84],[45,59],[45,82],[58,35],[12,15],[34,60],[28,51],[18,40],[53,73],[10,48],[28,6],[8,16],[41,34],[50,15],[23,30],[33,21],[2,34]] }\nassert my_solution.countBlackBlocks(**test_input) == [5517,302,9,0,0]\n\ntest_input = { \"m\": 42, \"n\": 58, \"coordinates\": [[35,34],[26,21],[17,14],[34,44],[12,51],[1,33],[23,17],[30,54],[25,46],[39,12],[21,13],[26,37],[13,38],[37,10],[27,57],[3,14],[19,31]] }\nassert my_solution.countBlackBlocks(**test_input) == [2271,66,0,0,0]\n\ntest_input = { \"m\": 6, \"n\": 12, \"coordinates\": [[4,7],[2,11],[0,7],[0,10],[1,4],[2,0],[2,10],[0,8],[3,8],[3,2],[0,5],[1,10],[0,9],[3,4],[2,9],[1,1],[3,7],[2,3],[0,0]] }\nassert my_solution.countBlackBlocks(**test_input) == [18,19,14,4,0]\n\ntest_input = { \"m\": 51, \"n\": 77, \"coordinates\": [[41,39],[28,5],[6,8],[36,7],[2,46],[18,75],[12,63],[42,26],[16,42],[6,9],[9,55],[37,61],[8,69],[35,10],[34,51],[33,2],[37,64],[5,32],[17,53],[38,51],[42,18],[24,35],[8,25],[17,58],[41,53],[2,9],[48,37],[13,7],[47,20],[28,59],[17,8],[32,27],[39,16],[43,74],[38,61],[40,14],[35,28],[9,46],[30,44],[46,12],[7,45],[26,76],[34,10],[28,51],[47,1],[46,65],[29,71],[2,24],[11,43],[16,28],[33,40],[18,29],[8,73],[30,55],[0,47],[45,34],[3,45],[16,5],[33,9],[4,68],[36,47],[11,39],[8,37],[6,63],[42,51],[4,16],[37,5],[32,60],[40,17],[9,14],[5,29],[22,34],[47,21],[44,37],[2,75],[21,76],[30,46],[20,60]] }\nassert my_solution.countBlackBlocks(**test_input) == [3505,284,11,0,0]\n\ntest_input = { \"m\": 58, \"n\": 65, \"coordinates\": [[20,24],[4,13],[38,14],[41,21],[6,36],[12,3],[51,52],[10,7],[14,50],[47,60],[30,59],[46,58],[55,49],[35,25],[15,53],[24,39],[55,40],[4,43],[36,28],[21,38],[36,1],[44,42],[12,26],[50,30],[36,14],[53,0],[11,48],[0,55],[42,17],[34,48],[15,43],[13,6],[33,29],[32,20],[12,13],[7,1],[22,41],[26,64],[16,16],[3,5],[14,0],[39,19],[32,47],[47,14],[51,64],[51,12],[7,45],[43,46],[47,28],[50,60],[45,8],[6,30],[9,35],[21,47],[17,39]] }\nassert my_solution.countBlackBlocks(**test_input) == [3438,210,0,0,0]\n\ntest_input = { \"m\": 6, \"n\": 10, \"coordinates\": [[2,7],[0,4],[3,3],[0,2],[3,0],[4,2],[2,1]] }\nassert my_solution.countBlackBlocks(**test_input) == [25,18,2,0,0]\n\ntest_input = { \"m\": 37, \"n\": 75, \"coordinates\": [[34,9],[30,27],[20,54],[35,35],[24,8],[0,68],[22,23],[10,20],[4,32],[8,20],[33,6],[7,63],[17,72],[8,37],[28,48],[25,24],[25,74],[20,38],[9,51],[10,74],[3,37],[20,17],[11,31],[14,67],[19,26],[34,7],[31,51],[5,47],[24,28]] }\nassert my_solution.countBlackBlocks(**test_input) == [2555,108,1,0,0]\n\ntest_input = { \"m\": 32, \"n\": 90, \"coordinates\": [[14,54],[13,33],[27,23],[28,68],[23,46],[12,22],[4,85],[4,41],[26,32],[0,42],[16,24],[17,83],[28,75],[4,39],[5,46],[10,51],[27,88],[6,69],[22,11],[7,9],[19,37],[0,74],[24,85],[28,74],[28,3],[13,80],[9,30],[16,86],[3,22],[2,3],[21,68],[11,32],[19,68],[25,83],[25,31],[12,10],[26,3],[16,57],[24,47],[12,73],[21,87],[9,28],[21,16],[23,29],[25,13],[23,82],[19,7],[29,11],[21,78],[24,23],[7,66],[9,57],[6,78],[13,22],[0,39],[20,48],[18,66],[17,77],[25,66],[11,25],[19,26],[20,75],[29,63],[3,52],[28,15],[13,84],[12,21],[0,4],[7,60],[16,74],[1,3],[7,5],[14,27],[22,4],[12,6],[16,0],[16,14],[12,17],[27,75],[20,16],[0,16],[9,26],[4,43],[19,0],[22,81],[12,71],[15,54],[3,61],[13,72],[7,71],[2,30],[2,18],[16,15],[28,5],[2,7],[25,89]] }\nassert my_solution.countBlackBlocks(**test_input) == [2413,326,18,2,0]\n\ntest_input = { \"m\": 21, \"n\": 81, \"coordinates\": [[5,71],[9,65],[12,36],[19,38],[7,66],[7,2],[14,13],[4,71],[19,32],[14,30],[13,21],[16,79],[0,2],[3,27],[13,72],[18,49],[0,72],[0,52],[18,24],[18,41],[13,7],[1,29],[15,24],[16,2],[8,25],[5,51],[19,15],[12,18],[16,61],[9,6],[7,61],[18,37],[10,79],[6,35],[17,12],[2,36],[13,64],[9,59],[5,42],[19,30],[7,51],[15,53],[10,75],[2,34],[8,0],[2,70],[3,36],[12,38],[4,35],[9,25],[13,68],[13,13],[14,25],[6,48],[15,33],[15,29]] }\nassert my_solution.countBlackBlocks(**test_input) == [1396,192,12,0,0]\n\ntest_input = { \"m\": 44, \"n\": 54, \"coordinates\": [[37,23],[27,31],[19,28],[30,2],[15,29],[4,40],[7,47],[36,18],[17,49],[18,51],[29,42],[8,34],[28,51],[17,27],[18,49],[26,16],[34,39],[11,19],[20,43],[23,47],[25,0],[20,32],[16,5],[29,30],[22,3],[4,12],[13,8],[5,6],[35,40],[15,49],[27,14],[37,8],[41,15],[0,16],[37,37],[38,31],[36,52],[18,22],[30,3],[31,18]] }\nassert my_solution.countBlackBlocks(**test_input) == [2128,146,5,0,0]\n\ntest_input = { \"m\": 2, \"n\": 52, \"coordinates\": [[0,24],[0,29],[0,14],[0,23],[0,33],[0,51],[0,27],[0,50],[0,7],[0,32],[0,9],[0,26],[0,17],[0,31],[0,19],[0,11],[0,3],[0,15],[0,20],[0,12],[0,18],[0,45],[0,48],[0,41],[0,8],[0,42],[0,47],[0,43],[0,2],[0,34],[0,0],[0,5],[0,49],[0,4],[0,36],[0,40],[0,44],[0,6],[0,38],[0,22],[0,13]] }\nassert my_solution.countBlackBlocks(**test_input) == [0,22,29,0,0]\n\ntest_input = { \"m\": 3, \"n\": 75, \"coordinates\": [[0,49],[1,17],[1,18],[0,20],[1,65],[0,35],[1,70],[1,20],[0,43],[1,58],[1,36],[0,28],[0,74],[0,30],[1,51],[1,63],[1,66]] }\nassert my_solution.countBlackBlocks(**test_input) == [102,39,7,0,0]\n\ntest_input = { \"m\": 33, \"n\": 93, \"coordinates\": [[18,53],[29,30],[29,23],[10,74],[5,25],[17,26],[5,87],[27,11],[29,16],[22,34],[19,86],[24,80],[11,46],[13,41],[7,24],[24,86],[30,89],[17,92],[11,21],[8,71],[7,8],[24,21],[22,32],[27,21],[29,17],[4,25],[22,91],[23,81],[10,59],[19,87],[20,16],[30,56],[13,70],[18,78],[13,27],[3,48],[8,3],[1,27],[16,62],[3,46],[6,23],[22,12],[0,26],[18,91],[0,1],[8,36],[8,16],[27,17],[12,1],[9,88]] }\nassert my_solution.countBlackBlocks(**test_input) == [2760,174,10,0,0]\n\ntest_input = { \"m\": 70, \"n\": 88, \"coordinates\": [[40,71],[29,33],[59,67],[55,61],[17,41]] }\nassert my_solution.countBlackBlocks(**test_input) == [5983,20,0,0,0]\n\ntest_input = { \"m\": 76, \"n\": 88, \"coordinates\": [[39,76],[42,86],[4,51],[60,0],[5,28],[1,46],[28,25],[21,12],[5,39],[19,20],[71,58],[70,25],[38,32],[42,51],[49,62],[39,20],[48,24],[10,14],[17,85],[27,2],[5,40],[56,23],[21,67],[15,28],[15,84],[73,34],[50,81],[20,68],[0,30],[30,53],[33,82],[58,65],[4,7],[73,50],[55,25],[45,59],[69,78],[63,47],[19,83],[46,41],[23,66],[0,76],[63,18],[1,3],[18,71],[27,79],[51,21],[9,46],[48,30],[11,30],[67,74],[74,9],[8,8],[29,9],[66,4],[52,42],[21,56],[40,74],[16,57],[54,64],[41,4],[20,64],[28,9],[55,85],[13,35],[15,33],[43,43],[24,61],[11,52],[34,70],[19,66],[23,57],[68,86],[58,53],[23,19],[46,10],[59,49],[66,9],[24,64],[23,36],[20,10],[1,68],[12,20],[8,73],[59,41]] }\nassert my_solution.countBlackBlocks(**test_input) == [6196,324,5,0,0]\n\ntest_input = { \"m\": 77, \"n\": 92, \"coordinates\": [[57,46],[24,2],[13,78],[50,91],[50,3],[17,80],[62,17],[5,88],[17,53],[73,42],[10,62],[21,60],[36,45],[36,53],[57,29],[68,43],[4,80],[74,26],[18,23],[44,69],[9,16],[52,20],[25,13],[0,60],[23,80],[26,23],[49,34],[58,71],[24,53],[56,82],[30,63],[53,19],[34,14],[47,5],[2,49],[20,2],[38,87],[30,46],[56,48],[34,1],[24,14],[70,40],[33,74],[65,86],[17,39],[48,80],[24,19],[30,90],[17,61],[31,83],[66,79],[25,30],[57,51],[25,43],[54,47],[60,12],[17,67],[2,57],[40,32],[58,90],[19,62],[9,47],[45,26],[0,37],[10,65],[64,1],[64,38],[2,34],[53,4],[16,37],[2,22],[69,91],[27,64],[50,4],[27,88],[17,47],[9,28],[19,57],[35,88],[4,55],[7,21],[37,68],[8,83],[70,37],[38,0],[40,89],[5,36],[74,37],[59,64],[28,89],[34,75],[42,21],[51,26],[21,57],[66,63]] }\nassert my_solution.countBlackBlocks(**test_input) == [6552,358,6,0,0]\n\ntest_input = { \"m\": 25, \"n\": 52, \"coordinates\": [[7,8],[3,21],[10,39],[12,35],[20,21],[5,37],[4,28],[15,49],[14,26],[12,47],[10,28]] }\nassert my_solution.countBlackBlocks(**test_input) == [1180,44,0,0,0]\n\ntest_input = { \"m\": 78, \"n\": 84, \"coordinates\": [[70,29],[22,36],[60,16],[39,28],[67,15],[50,11],[69,28],[24,32],[48,52]] }\nassert my_solution.countBlackBlocks(**test_input) == [6356,34,1,0,0]\n\ntest_input = { \"m\": 46, \"n\": 76, \"coordinates\": [[18,2],[41,13],[38,28],[9,54],[35,67],[31,72],[29,47],[44,16],[35,5],[36,14],[16,69],[34,74],[15,32],[37,29],[41,37],[5,9],[26,68],[40,38],[30,38],[42,57],[2,2],[42,54],[4,23],[40,15],[22,18],[0,28],[34,33],[37,17],[24,49],[25,73],[35,63],[20,60],[20,16],[10,50],[24,46],[26,8],[43,56],[9,37],[24,56],[42,73],[2,9],[14,72],[35,0],[40,20],[30,8],[12,30],[15,37],[42,75],[31,2],[43,34],[24,18],[19,27],[42,23],[6,70],[22,21],[15,63],[13,39],[36,12],[13,46],[23,71],[21,44],[21,26],[3,15],[41,41],[17,43],[34,47],[4,65],[36,18],[19,1],[31,55],[44,21],[15,9],[18,46],[29,32],[32,19],[1,48],[41,55],[40,66],[43,3],[32,25],[36,49],[7,5],[26,4],[27,21],[27,44]] }\nassert my_solution.countBlackBlocks(**test_input) == [3047,322,6,0,0]\n\ntest_input = { \"m\": 6, \"n\": 35, \"coordinates\": [[1,26],[4,24],[2,2],[4,17],[2,5],[3,32],[3,21],[1,0],[2,8],[4,20],[1,4],[2,9],[1,17],[3,1],[0,2],[4,6],[0,18],[4,23],[2,24],[0,16],[1,15],[3,22],[2,12],[1,18],[4,21],[0,26],[4,19],[4,2],[3,34],[0,24],[3,31],[2,34],[3,2],[1,24],[0,33],[0,31]] }\nassert my_solution.countBlackBlocks(**test_input) == [81,59,25,5,0]\n\ntest_input = { \"m\": 95, \"n\": 99, \"coordinates\": [[40,34],[77,26],[5,19],[84,36],[6,42],[92,59],[67,70],[62,38],[87,44],[79,79],[92,44],[75,85],[43,2],[91,34],[78,69],[19,1],[10,15],[82,79],[28,14],[79,72],[57,84],[75,93],[29,93],[91,66],[84,38],[76,81],[5,11],[32,7],[48,25],[10,70],[67,37],[31,91],[45,19],[59,19],[29,98],[37,57],[83,18],[44,80],[91,27],[74,69],[13,62],[5,23],[91,70],[89,71],[11,32],[82,30],[45,61],[10,50],[25,65],[22,32],[77,13],[9,79],[69,37],[77,63],[6,48],[7,77],[35,8],[27,94],[45,37],[30,78],[81,21],[89,84],[75,73],[74,18],[4,28],[10,66],[43,54],[28,7],[26,41],[2,74],[6,70],[8,30],[18,98],[63,10],[22,98]] }\nassert my_solution.countBlackBlocks(**test_input) == [8918,294,0,0,0]\n\ntest_input = { \"m\": 57, \"n\": 91, \"coordinates\": [[42,12],[38,56],[28,82],[54,52],[24,5]] }\nassert my_solution.countBlackBlocks(**test_input) == [5020,20,0,0,0]\n\ntest_input = { \"m\": 60, \"n\": 73, \"coordinates\": [[22,24],[22,4],[45,1],[38,57],[54,41],[6,58],[8,44],[40,42],[19,47],[31,47],[48,33],[43,37],[22,54],[36,23],[23,9],[51,15],[24,39],[32,0],[17,7],[41,27],[39,12],[11,10],[22,58],[13,69],[37,37],[17,48],[18,19],[52,40],[52,32],[11,2],[32,21],[39,33],[32,1],[54,17],[0,71],[7,21],[18,24],[0,13],[22,29],[49,62],[44,63],[53,53],[31,44],[28,5],[46,65],[37,27],[39,55],[16,56],[33,10],[40,19],[43,58],[6,65],[24,41],[48,61],[28,46],[0,15],[0,55],[29,49],[5,72],[34,21],[33,40],[14,34],[9,70],[3,48],[16,15],[56,68],[18,68],[2,13],[47,38],[55,55],[22,13],[19,59],[48,60],[53,2],[46,67],[58,9],[56,67],[23,50]] }\nassert my_solution.countBlackBlocks(**test_input) == [3955,286,7,0,0]\n\ntest_input = { \"m\": 14, \"n\": 76, \"coordinates\": [[1,20],[9,9],[6,57],[3,8],[6,71],[2,67],[12,53],[6,44],[6,16],[3,26],[10,39],[7,4]] }\nassert my_solution.countBlackBlocks(**test_input) == [927,48,0,0,0]\n\ntest_input = { \"m\": 69, \"n\": 72, \"coordinates\": [[45,12],[54,37],[43,47],[4,45],[28,24],[56,5],[10,67],[30,0],[34,48],[40,45],[27,47],[47,58],[63,59],[53,53],[24,31],[16,51],[55,40],[42,27],[7,38],[3,0],[9,43],[17,15],[63,52],[27,24],[6,32],[13,50],[55,68],[11,34],[42,18],[20,42],[48,20],[36,8],[29,50],[4,55],[33,24],[43,32],[20,67],[29,37],[36,7],[66,60],[61,6],[8,28],[55,31],[61,17],[55,49],[64,33],[32,9],[54,67],[34,40],[52,39],[45,64],[4,38],[44,8],[48,34],[35,14],[25,43],[35,31],[10,21],[63,13],[7,0],[13,54],[54,68],[13,44],[51,62],[17,28],[33,31],[8,70],[25,32],[44,49],[25,16],[35,44],[23,37],[23,48],[8,49],[23,42]] }\nassert my_solution.countBlackBlocks(**test_input) == [4543,277,7,1,0]\n\ntest_input = { \"m\": 29, \"n\": 79, \"coordinates\": [[26,78],[24,55],[3,8],[3,55],[12,76],[11,23],[4,52],[5,73],[27,21],[8,19],[14,54],[10,4],[8,23],[13,16],[4,1],[21,47],[11,15],[2,26],[24,59],[12,22],[2,69],[20,1],[10,74],[25,53],[0,13],[9,28],[7,4],[10,76],[13,75],[24,25],[14,19],[12,7],[5,53],[5,59],[7,41],[8,25],[7,65],[23,48],[18,37],[7,67],[2,76],[8,64],[22,46],[2,16],[20,31],[7,38],[13,66],[22,30],[17,23],[22,60],[4,10],[6,37],[5,33],[19,58],[22,53],[9,53],[4,22],[12,4],[2,51],[3,63],[4,18],[22,43]] }\nassert my_solution.countBlackBlocks(**test_input) == [1946,232,6,0,0]\n\ntest_input = { \"m\": 6, \"n\": 58, \"coordinates\": [[0,33],[3,43],[4,25],[0,42],[4,2],[0,31],[2,10],[0,18],[1,46],[2,55],[0,13],[1,8],[2,24],[1,54],[3,54],[0,6],[0,37],[3,34],[3,53],[1,33],[2,1],[2,26],[3,11],[2,37],[1,24],[0,2],[0,14],[2,33],[0,41],[4,7],[4,28],[3,48],[3,0],[4,38],[1,34],[0,26],[4,43],[3,35],[2,7],[4,37],[4,26],[4,51],[4,21],[3,1],[4,53],[0,34],[4,3],[3,50],[3,24],[2,5],[3,40],[2,14],[4,39],[2,43],[2,50],[0,21],[2,8],[0,51],[0,47],[1,22],[3,17],[4,13],[2,2],[3,55],[4,29],[0,16],[1,55],[2,49],[0,24],[1,16],[2,17],[1,19],[1,42],[4,40],[0,5],[0,9],[2,32],[2,25],[0,40],[2,18],[3,31],[3,26],[1,57],[0,45],[0,17],[2,22],[3,3],[1,27],[1,20],[0,44],[2,0],[3,30],[2,40],[3,39],[4,50]] }\nassert my_solution.countBlackBlocks(**test_input) == [80,107,76,19,3]\n\ntest_input = { \"m\": 28, \"n\": 64, \"coordinates\": [[3,3],[13,53],[17,60],[1,30],[21,59],[1,51],[2,49],[1,16],[14,22],[23,17],[13,55],[8,38],[13,31],[8,34],[17,6]] }\nassert my_solution.countBlackBlocks(**test_input) == [1641,60,0,0,0]\n\ntest_input = { \"m\": 15, \"n\": 45, \"coordinates\": [[4,29],[0,10],[10,21],[6,5],[4,27],[3,11],[8,36],[1,38],[5,19],[9,1],[5,14],[8,18],[2,8],[13,5],[5,11],[6,37],[2,17],[5,39],[7,3],[2,3],[9,20],[9,41],[0,40],[10,20],[12,30],[2,4],[12,0],[5,16],[11,35],[4,38],[9,11],[3,34],[4,39],[5,8],[10,27],[5,13],[2,36],[9,44],[5,42],[7,43],[13,16],[0,30],[6,35],[8,12],[7,33],[11,12],[13,0],[10,0],[4,17],[0,34],[10,4],[0,22],[2,25],[8,39],[9,40],[4,35],[9,10],[7,18],[7,28],[13,12],[7,8],[10,37],[11,27],[12,40],[8,0],[7,4]] }\nassert my_solution.countBlackBlocks(**test_input) == [402,186,26,2,0]\n\ntest_input = { \"m\": 50, \"n\": 60, \"coordinates\": [[37,49],[8,45],[11,21],[38,10],[47,35],[15,33],[18,8],[15,22],[16,24],[14,50],[38,24],[8,23],[24,58],[11,35],[37,39],[29,18],[1,8],[40,47],[40,59],[47,48],[15,54],[16,33],[22,29],[39,16],[35,43],[40,54],[11,8],[16,14],[8,7],[38,1],[17,3],[8,3],[0,38],[43,22],[14,10],[31,15],[11,46],[21,45],[13,6],[0,34],[2,42],[47,57],[30,2],[6,38],[8,31],[11,44],[44,36],[10,45],[41,29],[31,30],[47,54],[3,51],[26,5],[3,43],[22,42],[27,28],[48,4],[0,49],[45,22],[7,58],[26,27],[35,31],[40,15],[45,44],[42,34],[17,54]] }\nassert my_solution.countBlackBlocks(**test_input) == [2642,242,7,0,0]\n\ntest_input = { \"m\": 36, \"n\": 54, \"coordinates\": [[7,0],[22,50],[2,41],[33,48],[1,26]] }\nassert my_solution.countBlackBlocks(**test_input) == [1837,18,0,0,0]\n\ntest_input = { \"m\": 26, \"n\": 68, \"coordinates\": [[8,51],[18,5],[18,64]] }\nassert my_solution.countBlackBlocks(**test_input) == [1663,12,0,0,0]\n\ntest_input = { \"m\": 21, \"n\": 46, \"coordinates\": [[12,7],[12,35],[13,14],[11,22],[2,1],[11,28],[1,7],[6,36],[2,15],[15,18],[1,39],[12,38],[11,35],[9,9],[17,6],[12,10]] }\nassert my_solution.countBlackBlocks(**test_input) == [838,60,2,0,0]\n\ntest_input = { \"m\": 35, \"n\": 74, \"coordinates\": [[9,54],[9,23],[8,48],[14,29],[17,37],[6,4],[17,39],[18,41],[18,50],[24,20],[29,65],[30,3],[5,19],[11,58],[6,67],[21,44],[8,3],[7,11],[18,29],[22,46],[19,51],[4,49],[13,15],[19,48],[12,33],[8,6],[25,48],[17,70],[2,68],[21,53],[9,37],[27,8],[14,69],[2,16],[20,54],[8,67],[31,44],[10,38],[19,21],[16,43],[25,65],[33,20],[17,5],[23,6],[14,23],[14,26],[1,61],[28,21],[1,68],[24,59],[19,17],[23,4],[25,52],[2,43],[30,13],[31,34],[32,43],[14,20],[11,4],[30,20],[0,67],[27,20],[32,64],[20,17],[24,61],[5,35],[31,18],[28,40],[13,11],[29,59],[17,50],[13,54],[20,67],[32,2],[4,18]] }\nassert my_solution.countBlackBlocks(**test_input) == [2197,272,13,0,0]\n\ntest_input = { \"m\": 28, \"n\": 52, \"coordinates\": [[3,23],[24,28],[7,19],[11,12],[4,27],[3,17],[8,41],[20,30],[23,24],[1,41],[12,30],[2,50],[18,36],[5,7],[1,42],[7,0],[10,51],[20,46],[20,24],[19,7],[23,28],[26,8],[17,31],[22,7],[22,26],[15,8],[19,27],[16,33],[15,39],[13,51],[20,47],[3,39],[25,36],[25,37],[10,0],[19,26],[8,9],[12,31],[19,44],[8,1],[3,12],[8,5],[23,46],[22,15],[18,2],[22,10],[24,43],[16,9],[18,22],[22,8],[20,6],[3,1],[8,17],[25,1],[9,32],[11,34],[7,44],[2,38],[13,37],[26,1],[2,26],[14,38],[6,36],[22,24],[6,27],[18,38],[25,41],[22,39],[18,51],[2,18],[12,24],[4,14],[21,38],[6,44],[18,25],[12,1],[12,4],[1,22],[12,40],[18,11]] }\nassert my_solution.countBlackBlocks(**test_input) == [1096,252,29,0,0]\n\ntest_input = { \"m\": 5, \"n\": 56, \"coordinates\": [[1,2],[3,7],[2,24],[0,5],[2,3],[2,25],[3,20],[1,8],[2,26],[0,53],[2,44],[0,49],[3,30],[0,11],[1,6],[0,14],[1,9],[2,34],[2,54],[0,31],[1,10],[0,39],[0,26],[0,12],[0,37],[0,42],[0,28],[2,29],[2,46],[1,44],[0,47],[0,35],[1,53],[1,38],[0,24],[0,2],[3,23],[3,36],[3,24],[2,17],[2,35],[3,37],[2,0],[3,45],[0,16],[1,34],[0,29],[1,5],[2,38]] }\nassert my_solution.countBlackBlocks(**test_input) == [105,76,35,4,0]\n\ntest_input = { \"m\": 36, \"n\": 38, \"coordinates\": [[7,13],[24,30],[23,29],[31,14],[28,33],[16,37],[3,27],[21,36],[9,30],[22,12],[22,21],[6,37],[18,31],[19,4],[18,20],[11,8],[16,14],[7,1],[11,30],[23,16],[15,15],[23,26],[13,12],[11,19]] }\nassert my_solution.countBlackBlocks(**test_input) == [1205,88,2,0,0]\n\ntest_input = { \"m\": 70, \"n\": 75, \"coordinates\": [[17,67],[60,71],[53,71],[14,36],[19,57],[35,22],[8,11],[27,36],[47,71],[58,54],[35,63],[54,18],[17,22],[34,60],[26,35],[61,39],[65,20],[38,37],[58,34],[34,23],[63,32],[55,32],[35,53],[29,52],[6,4],[5,66],[5,6],[6,60],[61,50],[16,24],[24,51],[65,45],[11,14],[7,27],[67,24],[34,53],[61,16],[60,50],[19,41],[56,19],[10,15],[17,0],[8,59],[32,24],[35,27],[41,34],[59,6],[17,30]] }\nassert my_solution.countBlackBlocks(**test_input) == [4923,176,7,0,0]\n\ntest_input = { \"m\": 8, \"n\": 68, \"coordinates\": [[5,36],[4,65],[1,9],[5,49],[5,34],[6,59],[5,27],[4,2],[6,53],[6,22],[4,60],[3,65],[6,16],[2,56],[0,27],[6,25],[3,32],[5,2],[3,63],[0,58],[0,37],[6,44],[0,61],[6,37],[1,36],[2,1],[1,4],[6,24],[5,12],[5,23],[0,57],[4,59],[1,44],[2,51],[5,1],[0,8],[5,22],[4,3],[5,0],[5,45],[2,8],[1,12],[1,8],[2,10],[0,48],[1,55],[1,14],[3,12],[5,39],[1,31],[1,27],[0,31],[4,61],[0,54],[2,46],[4,66],[6,32],[5,53],[3,11],[5,4],[2,21],[1,49]] }\nassert my_solution.countBlackBlocks(**test_input) == [288,140,35,6,0]", "start_time": 1688826600} +{"task_id": "weekly-contest-352-longest-even-odd-subarray-with-threshold", "url": "https://leetcode.com/problems/longest-even-odd-subarray-with-threshold", "title": "longest-even-odd-subarray-with-threshold", "meta": {"questionId": "2866", "questionFrontendId": "2760", "title": "Longest Even Odd Subarray With Threshold", "titleSlug": "longest-even-odd-subarray-with-threshold", "isPaidOnly": false, "difficulty": "Easy", "likes": 248, "dislikes": 243, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed integer array nums and an integer threshold.\n\nFind the length of the longest subarray of nums starting at index l and ending at index r (0 <= l <= r < nums.length) that satisfies the following conditions:\n\n * nums[l] % 2 == 0\n * For all indices i in the range [l, r - 1], nums[i] % 2 != nums[i + 1] % 2\n * For all indices i in the range [l, r], nums[i] <= threshold\n\nReturn an integer denoting the length of the longest such subarray.\n\nNote: A subarray is a contiguous non-empty sequence of elements within an array.\n\nExample 1:\n\nInput: nums = [3,2,5,4], threshold = 5\nOutput: 3\nExplanation: In this example, we can select the subarray that starts at l = 1 and ends at r = 3 => [2,5,4]. This subarray satisfies the conditions.\nHence, the answer is the length of the subarray, 3. We can show that 3 is the maximum possible achievable length.\n\nExample 2:\n\nInput: nums = [1,2], threshold = 2\nOutput: 1\nExplanation: In this example, we can select the subarray that starts at l = 1 and ends at r = 1 => [2].\nIt satisfies all the conditions and we can show that 1 is the maximum possible achievable length.\n\nExample 3:\n\nInput: nums = [2,3,4,5], threshold = 4\nOutput: 3\nExplanation: In this example, we can select the subarray that starts at l = 0 and ends at r = 2 => [2,3,4].\nIt satisfies all the conditions.\nHence, the answer is the length of the subarray, 3. We can show that 3 is the maximum possible achievable length.\n\n\nConstraints:\n\n * 1 <= nums.length <= 100\n * 1 <= nums[i] <= 100\n * 1 <= threshold <= 100\n\"\"\"\nclass Solution:\n def longestAlternatingSubarray(self, nums: List[int], threshold: int) -> int:\n ", "prompt_sft": "You are given a 0-indexed integer array nums and an integer threshold.\n\nFind the length of the longest subarray of nums starting at index l and ending at index r (0 <= l <= r < nums.length) that satisfies the following conditions:\n\n * nums[l] % 2 == 0\n * For all indices i in the range [l, r - 1], nums[i] % 2 != nums[i + 1] % 2\n * For all indices i in the range [l, r], nums[i] <= threshold\n\nReturn an integer denoting the length of the longest such subarray.\n\nNote: A subarray is a contiguous non-empty sequence of elements within an array.\n\nExample 1:\n\nInput: nums = [3,2,5,4], threshold = 5\nOutput: 3\nExplanation: In this example, we can select the subarray that starts at l = 1 and ends at r = 3 => [2,5,4]. This subarray satisfies the conditions.\nHence, the answer is the length of the subarray, 3. We can show that 3 is the maximum possible achievable length.\n\nExample 2:\n\nInput: nums = [1,2], threshold = 2\nOutput: 1\nExplanation: In this example, we can select the subarray that starts at l = 1 and ends at r = 1 => [2].\nIt satisfies all the conditions and we can show that 1 is the maximum possible achievable length.\n\nExample 3:\n\nInput: nums = [2,3,4,5], threshold = 4\nOutput: 3\nExplanation: In this example, we can select the subarray that starts at l = 0 and ends at r = 2 => [2,3,4].\nIt satisfies all the conditions.\nHence, the answer is the length of the subarray, 3. We can show that 3 is the maximum possible achievable length.\n\n\nConstraints:\n\n * 1 <= nums.length <= 100\n * 1 <= nums[i] <= 100\n * 1 <= threshold <= 100\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def longestAlternatingSubarray(self, nums: List[int], threshold: int) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [3,2,5,4], \"threshold\": 5 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [1,2], \"threshold\": 2 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [2,3,4,5], \"threshold\": 4 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [1], \"threshold\": 1 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [2], \"threshold\": 2 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [3], \"threshold\": 3 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [4], \"threshold\": 1 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [5], \"threshold\": 3 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [6], \"threshold\": 5 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [7], \"threshold\": 2 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [8], \"threshold\": 1 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [9], \"threshold\": 7 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [10], \"threshold\": 7 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [1,3], \"threshold\": 16 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [1,6], \"threshold\": 2 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [1,10], \"threshold\": 6 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [1,10], \"threshold\": 7 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [2,2], \"threshold\": 18 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [2,4], \"threshold\": 7 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [2,5], \"threshold\": 2 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [2,6], \"threshold\": 15 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [2,7], \"threshold\": 9 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [2,8], \"threshold\": 4 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [2,8], \"threshold\": 8 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [2,8], \"threshold\": 16 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [2,9], \"threshold\": 14 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [3,1], \"threshold\": 9 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [3,4], \"threshold\": 10 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [3,10], \"threshold\": 3 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [4,2], \"threshold\": 11 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [4,2], \"threshold\": 15 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [4,4], \"threshold\": 9 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [4,7], \"threshold\": 8 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [4,9], \"threshold\": 17 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [5,8], \"threshold\": 5 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [5,8], \"threshold\": 15 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [6,2], \"threshold\": 10 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [6,4], \"threshold\": 14 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [6,4], \"threshold\": 16 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [6,5], \"threshold\": 10 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [7,3], \"threshold\": 8 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [7,4], \"threshold\": 7 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [7,5], \"threshold\": 1 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [7,10], \"threshold\": 52 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [7,17], \"threshold\": 31 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [8,4], \"threshold\": 6 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [8,8], \"threshold\": 20 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [9,2], \"threshold\": 11 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [9,4], \"threshold\": 15 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [10,3], \"threshold\": 11 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [10,4], \"threshold\": 7 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [10,5], \"threshold\": 20 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [10,7], \"threshold\": 11 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [10,8], \"threshold\": 4 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [10,18], \"threshold\": 43 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [12,34], \"threshold\": 7 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [12,35], \"threshold\": 8 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [13,9], \"threshold\": 53 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [15,13], \"threshold\": 23 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [15,15], \"threshold\": 18 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [17,2], \"threshold\": 17 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [23,37], \"threshold\": 35 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [24,11], \"threshold\": 54 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [27,9], \"threshold\": 55 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [27,17], \"threshold\": 40 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [33,4], \"threshold\": 43 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [41,16], \"threshold\": 9 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [47,44], \"threshold\": 20 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [49,39], \"threshold\": 52 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [50,8], \"threshold\": 19 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [76,46], \"threshold\": 91 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [1,1,7], \"threshold\": 4 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [1,3,1], \"threshold\": 18 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [1,4,3], \"threshold\": 1 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [1,5,3], \"threshold\": 8 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [1,10,5], \"threshold\": 9 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [2,1,8], \"threshold\": 6 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [2,10,5], \"threshold\": 7 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [3,2,8], \"threshold\": 18 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [3,3,10], \"threshold\": 20 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [3,4,2], \"threshold\": 19 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [3,6,10], \"threshold\": 6 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [3,8,9], \"threshold\": 19 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [4,3,1], \"threshold\": 4 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [4,4,4], \"threshold\": 8 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [4,5,10], \"threshold\": 3 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [4,10,2], \"threshold\": 4 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [4,10,3], \"threshold\": 8 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [4,10,3], \"threshold\": 10 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [4,40,8], \"threshold\": 45 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [5,3,9], \"threshold\": 7 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [5,5,6], \"threshold\": 7 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [6,2,2], \"threshold\": 16 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [6,2,4], \"threshold\": 17 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1\n\ntest_input = { \"nums\": [6,3,4], \"threshold\": 6 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [6,5,2], \"threshold\": 17 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [6,5,3], \"threshold\": 17 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 2\n\ntest_input = { \"nums\": [6,7,2], \"threshold\": 14 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 3\n\ntest_input = { \"nums\": [7,1,10], \"threshold\": 9 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 0\n\ntest_input = { \"nums\": [7,5,6], \"threshold\": 8 }\nassert my_solution.longestAlternatingSubarray(**test_input) == 1", "start_time": 1688265000} +{"task_id": "weekly-contest-352-prime-pairs-with-target-sum", "url": "https://leetcode.com/problems/prime-pairs-with-target-sum", "title": "prime-pairs-with-target-sum", "meta": {"questionId": "2873", "questionFrontendId": "2761", "title": "Prime Pairs With Target Sum", "titleSlug": "prime-pairs-with-target-sum", "isPaidOnly": false, "difficulty": "Medium", "likes": 311, "dislikes": 30, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given an integer n. We say that two integers x and y form a prime number pair if:\n\n * 1 <= x <= y <= n\n * x + y == n\n * x and y are prime numbers\n\nReturn the 2D sorted list of prime number pairs [xi, yi]. The list should be sorted in increasing order of xi. If there are no prime number pairs at all, return an empty array.\n\nNote: A prime number is a natural number greater than 1 with only two factors, itself and 1.\n\nExample 1:\n\nInput: n = 10\nOutput: [[3,7],[5,5]]\nExplanation: In this example, there are two prime pairs that satisfy the criteria.\nThese pairs are [3,7] and [5,5], and we return them in the sorted order as described in the problem statement.\n\nExample 2:\n\nInput: n = 2\nOutput: []\nExplanation: We can show that there is no prime number pair that gives a sum of 2, so we return an empty array.\n\n\nConstraints:\n\n * 1 <= n <= 106\n\"\"\"\nclass Solution:\n def findPrimePairs(self, n: int) -> List[List[int]]:\n ", "prompt_sft": "You are given an integer n. We say that two integers x and y form a prime number pair if:\n\n * 1 <= x <= y <= n\n * x + y == n\n * x and y are prime numbers\n\nReturn the 2D sorted list of prime number pairs [xi, yi]. The list should be sorted in increasing order of xi. If there are no prime number pairs at all, return an empty array.\n\nNote: A prime number is a natural number greater than 1 with only two factors, itself and 1.\n\nExample 1:\n\nInput: n = 10\nOutput: [[3,7],[5,5]]\nExplanation: In this example, there are two prime pairs that satisfy the criteria.\nThese pairs are [3,7] and [5,5], and we return them in the sorted order as described in the problem statement.\n\nExample 2:\n\nInput: n = 2\nOutput: []\nExplanation: We can show that there is no prime number pair that gives a sum of 2, so we return an empty array.\n\n\nConstraints:\n\n * 1 <= n <= 106\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def findPrimePairs(self, n: int) -> List[List[int]]:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"n\": 10 }\nassert my_solution.findPrimePairs(**test_input) == [[3,7],[5,5]]\n\ntest_input = { \"n\": 2 }\nassert my_solution.findPrimePairs(**test_input) == []\n\ntest_input = { \"n\": 1 }\nassert my_solution.findPrimePairs(**test_input) == []\n\ntest_input = { \"n\": 3 }\nassert my_solution.findPrimePairs(**test_input) == []\n\ntest_input = { \"n\": 4 }\nassert my_solution.findPrimePairs(**test_input) == [[2,2]]\n\ntest_input = { \"n\": 5 }\nassert my_solution.findPrimePairs(**test_input) == [[2,3]]\n\ntest_input = { \"n\": 6 }\nassert my_solution.findPrimePairs(**test_input) == [[3,3]]\n\ntest_input = { \"n\": 7 }\nassert my_solution.findPrimePairs(**test_input) == [[2,5]]\n\ntest_input = { \"n\": 8 }\nassert my_solution.findPrimePairs(**test_input) == [[3,5]]\n\ntest_input = { \"n\": 9 }\nassert my_solution.findPrimePairs(**test_input) == [[2,7]]\n\ntest_input = { \"n\": 11 }\nassert my_solution.findPrimePairs(**test_input) == []\n\ntest_input = { \"n\": 12 }\nassert my_solution.findPrimePairs(**test_input) == [[5,7]]\n\ntest_input = { \"n\": 13 }\nassert my_solution.findPrimePairs(**test_input) == [[2,11]]\n\ntest_input = { \"n\": 14 }\nassert my_solution.findPrimePairs(**test_input) == [[3,11],[7,7]]\n\ntest_input = { \"n\": 15 }\nassert my_solution.findPrimePairs(**test_input) == [[2,13]]\n\ntest_input = { \"n\": 16 }\nassert my_solution.findPrimePairs(**test_input) == [[3,13],[5,11]]\n\ntest_input = { \"n\": 17 }\nassert my_solution.findPrimePairs(**test_input) == []\n\ntest_input = { \"n\": 18 }\nassert my_solution.findPrimePairs(**test_input) == [[5,13],[7,11]]\n\ntest_input = { \"n\": 19 }\nassert my_solution.findPrimePairs(**test_input) == [[2,17]]\n\ntest_input = { \"n\": 20 }\nassert my_solution.findPrimePairs(**test_input) == [[3,17],[7,13]]\n\ntest_input = { \"n\": 21 }\nassert my_solution.findPrimePairs(**test_input) == [[2,19]]\n\ntest_input = { \"n\": 22 }\nassert my_solution.findPrimePairs(**test_input) == [[3,19],[5,17],[11,11]]\n\ntest_input = { \"n\": 23 }\nassert my_solution.findPrimePairs(**test_input) == []\n\ntest_input = { \"n\": 24 }\nassert my_solution.findPrimePairs(**test_input) == [[5,19],[7,17],[11,13]]\n\ntest_input = { \"n\": 25 }\nassert my_solution.findPrimePairs(**test_input) == [[2,23]]\n\ntest_input = { \"n\": 26 }\nassert my_solution.findPrimePairs(**test_input) == [[3,23],[7,19],[13,13]]\n\ntest_input = { \"n\": 27 }\nassert my_solution.findPrimePairs(**test_input) == []\n\ntest_input = { \"n\": 28 }\nassert my_solution.findPrimePairs(**test_input) == [[5,23],[11,17]]\n\ntest_input = { \"n\": 29 }\nassert my_solution.findPrimePairs(**test_input) == []\n\ntest_input = { \"n\": 30 }\nassert my_solution.findPrimePairs(**test_input) == [[7,23],[11,19],[13,17]]\n\ntest_input = { \"n\": 31 }\nassert my_solution.findPrimePairs(**test_input) == [[2,29]]\n\ntest_input = { \"n\": 32 }\nassert my_solution.findPrimePairs(**test_input) == [[3,29],[13,19]]\n\ntest_input = { \"n\": 33 }\nassert my_solution.findPrimePairs(**test_input) == [[2,31]]\n\ntest_input = { \"n\": 34 }\nassert my_solution.findPrimePairs(**test_input) == [[3,31],[5,29],[11,23],[17,17]]\n\ntest_input = { \"n\": 35 }\nassert my_solution.findPrimePairs(**test_input) == []\n\ntest_input = { \"n\": 36 }\nassert my_solution.findPrimePairs(**test_input) == [[5,31],[7,29],[13,23],[17,19]]\n\ntest_input = { \"n\": 37 }\nassert my_solution.findPrimePairs(**test_input) == []\n\ntest_input = { \"n\": 38 }\nassert my_solution.findPrimePairs(**test_input) == [[7,31],[19,19]]\n\ntest_input = { \"n\": 39 }\nassert my_solution.findPrimePairs(**test_input) == [[2,37]]\n\ntest_input = { \"n\": 40 }\nassert my_solution.findPrimePairs(**test_input) == [[3,37],[11,29],[17,23]]\n\ntest_input = { \"n\": 41 }\nassert my_solution.findPrimePairs(**test_input) == []\n\ntest_input = { \"n\": 42 }\nassert my_solution.findPrimePairs(**test_input) == [[5,37],[11,31],[13,29],[19,23]]\n\ntest_input = { \"n\": 43 }\nassert my_solution.findPrimePairs(**test_input) == [[2,41]]\n\ntest_input = { \"n\": 44 }\nassert my_solution.findPrimePairs(**test_input) == [[3,41],[7,37],[13,31]]\n\ntest_input = { \"n\": 45 }\nassert my_solution.findPrimePairs(**test_input) == [[2,43]]\n\ntest_input = { \"n\": 46 }\nassert my_solution.findPrimePairs(**test_input) == [[3,43],[5,41],[17,29],[23,23]]\n\ntest_input = { \"n\": 47 }\nassert my_solution.findPrimePairs(**test_input) == []\n\ntest_input = { \"n\": 48 }\nassert my_solution.findPrimePairs(**test_input) == [[5,43],[7,41],[11,37],[17,31],[19,29]]\n\ntest_input = { \"n\": 49 }\nassert my_solution.findPrimePairs(**test_input) == [[2,47]]\n\ntest_input = { \"n\": 50 }\nassert my_solution.findPrimePairs(**test_input) == [[3,47],[7,43],[13,37],[19,31]]\n\ntest_input = { \"n\": 51 }\nassert my_solution.findPrimePairs(**test_input) == []\n\ntest_input = { \"n\": 52 }\nassert my_solution.findPrimePairs(**test_input) == [[5,47],[11,41],[23,29]]\n\ntest_input = { \"n\": 53 }\nassert my_solution.findPrimePairs(**test_input) == []\n\ntest_input = { \"n\": 54 }\nassert my_solution.findPrimePairs(**test_input) == [[7,47],[11,43],[13,41],[17,37],[23,31]]\n\ntest_input = { \"n\": 55 }\nassert my_solution.findPrimePairs(**test_input) == [[2,53]]\n\ntest_input = { \"n\": 56 }\nassert my_solution.findPrimePairs(**test_input) == [[3,53],[13,43],[19,37]]\n\ntest_input = { \"n\": 57 }\nassert my_solution.findPrimePairs(**test_input) == []\n\ntest_input = { \"n\": 58 }\nassert my_solution.findPrimePairs(**test_input) == [[5,53],[11,47],[17,41],[29,29]]\n\ntest_input = { \"n\": 59 }\nassert my_solution.findPrimePairs(**test_input) == []\n\ntest_input = { \"n\": 60 }\nassert my_solution.findPrimePairs(**test_input) == [[7,53],[13,47],[17,43],[19,41],[23,37],[29,31]]\n\ntest_input = { \"n\": 61 }\nassert my_solution.findPrimePairs(**test_input) == [[2,59]]\n\ntest_input = { \"n\": 62 }\nassert my_solution.findPrimePairs(**test_input) == [[3,59],[19,43],[31,31]]\n\ntest_input = { \"n\": 63 }\nassert my_solution.findPrimePairs(**test_input) == [[2,61]]\n\ntest_input = { \"n\": 64 }\nassert my_solution.findPrimePairs(**test_input) == [[3,61],[5,59],[11,53],[17,47],[23,41]]\n\ntest_input = { \"n\": 65 }\nassert my_solution.findPrimePairs(**test_input) == []\n\ntest_input = { \"n\": 66 }\nassert my_solution.findPrimePairs(**test_input) == [[5,61],[7,59],[13,53],[19,47],[23,43],[29,37]]\n\ntest_input = { \"n\": 67 }\nassert my_solution.findPrimePairs(**test_input) == []\n\ntest_input = { \"n\": 68 }\nassert my_solution.findPrimePairs(**test_input) == [[7,61],[31,37]]\n\ntest_input = { \"n\": 69 }\nassert my_solution.findPrimePairs(**test_input) == [[2,67]]\n\ntest_input = { \"n\": 70 }\nassert my_solution.findPrimePairs(**test_input) == [[3,67],[11,59],[17,53],[23,47],[29,41]]\n\ntest_input = { \"n\": 71 }\nassert my_solution.findPrimePairs(**test_input) == []\n\ntest_input = { \"n\": 72 }\nassert my_solution.findPrimePairs(**test_input) == [[5,67],[11,61],[13,59],[19,53],[29,43],[31,41]]\n\ntest_input = { \"n\": 73 }\nassert my_solution.findPrimePairs(**test_input) == [[2,71]]\n\ntest_input = { \"n\": 74 }\nassert my_solution.findPrimePairs(**test_input) == [[3,71],[7,67],[13,61],[31,43],[37,37]]\n\ntest_input = { \"n\": 75 }\nassert my_solution.findPrimePairs(**test_input) == [[2,73]]\n\ntest_input = { \"n\": 76 }\nassert my_solution.findPrimePairs(**test_input) == [[3,73],[5,71],[17,59],[23,53],[29,47]]\n\ntest_input = { \"n\": 77 }\nassert my_solution.findPrimePairs(**test_input) == []\n\ntest_input = { \"n\": 78 }\nassert my_solution.findPrimePairs(**test_input) == [[5,73],[7,71],[11,67],[17,61],[19,59],[31,47],[37,41]]\n\ntest_input = { \"n\": 79 }\nassert my_solution.findPrimePairs(**test_input) == []\n\ntest_input = { \"n\": 80 }\nassert my_solution.findPrimePairs(**test_input) == [[7,73],[13,67],[19,61],[37,43]]\n\ntest_input = { \"n\": 81 }\nassert my_solution.findPrimePairs(**test_input) == [[2,79]]\n\ntest_input = { \"n\": 82 }\nassert my_solution.findPrimePairs(**test_input) == [[3,79],[11,71],[23,59],[29,53],[41,41]]\n\ntest_input = { \"n\": 83 }\nassert my_solution.findPrimePairs(**test_input) == []\n\ntest_input = { \"n\": 84 }\nassert my_solution.findPrimePairs(**test_input) == [[5,79],[11,73],[13,71],[17,67],[23,61],[31,53],[37,47],[41,43]]\n\ntest_input = { \"n\": 85 }\nassert my_solution.findPrimePairs(**test_input) == [[2,83]]\n\ntest_input = { \"n\": 86 }\nassert my_solution.findPrimePairs(**test_input) == [[3,83],[7,79],[13,73],[19,67],[43,43]]\n\ntest_input = { \"n\": 87 }\nassert my_solution.findPrimePairs(**test_input) == []\n\ntest_input = { \"n\": 88 }\nassert my_solution.findPrimePairs(**test_input) == [[5,83],[17,71],[29,59],[41,47]]\n\ntest_input = { \"n\": 89 }\nassert my_solution.findPrimePairs(**test_input) == []\n\ntest_input = { \"n\": 90 }\nassert my_solution.findPrimePairs(**test_input) == [[7,83],[11,79],[17,73],[19,71],[23,67],[29,61],[31,59],[37,53],[43,47]]\n\ntest_input = { \"n\": 91 }\nassert my_solution.findPrimePairs(**test_input) == [[2,89]]\n\ntest_input = { \"n\": 92 }\nassert my_solution.findPrimePairs(**test_input) == [[3,89],[13,79],[19,73],[31,61]]\n\ntest_input = { \"n\": 93 }\nassert my_solution.findPrimePairs(**test_input) == []\n\ntest_input = { \"n\": 94 }\nassert my_solution.findPrimePairs(**test_input) == [[5,89],[11,83],[23,71],[41,53],[47,47]]\n\ntest_input = { \"n\": 95 }\nassert my_solution.findPrimePairs(**test_input) == []\n\ntest_input = { \"n\": 96 }\nassert my_solution.findPrimePairs(**test_input) == [[7,89],[13,83],[17,79],[23,73],[29,67],[37,59],[43,53]]\n\ntest_input = { \"n\": 97 }\nassert my_solution.findPrimePairs(**test_input) == []\n\ntest_input = { \"n\": 98 }\nassert my_solution.findPrimePairs(**test_input) == [[19,79],[31,67],[37,61]]\n\ntest_input = { \"n\": 99 }\nassert my_solution.findPrimePairs(**test_input) == [[2,97]]\n\ntest_input = { \"n\": 100 }\nassert my_solution.findPrimePairs(**test_input) == [[3,97],[11,89],[17,83],[29,71],[41,59],[47,53]]", "start_time": 1688265000} +{"task_id": "weekly-contest-352-continuous-subarrays", "url": "https://leetcode.com/problems/continuous-subarrays", "title": "continuous-subarrays", "meta": {"questionId": "2868", "questionFrontendId": "2762", "title": "Continuous Subarrays", "titleSlug": "continuous-subarrays", "isPaidOnly": false, "difficulty": "Medium", "likes": 604, "dislikes": 17, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nYou are given a 0-indexed integer array nums. A subarray of nums is called continuous if:\n\n * Let i, i + 1, ..., j be the indices in the subarray. Then, for each pair of indices i <= i1, i2 <= j, 0 <= |nums[i1] - nums[i2]| <= 2.\n\nReturn the total number of continuous subarrays.\n\nA subarray is a contiguous non-empty sequence of elements within an array.\n\nExample 1:\n\nInput: nums = [5,4,2,4]\nOutput: 8\nExplanation:\nContinuous subarray of size 1: [5], [4], [2], [4].\nContinuous subarray of size 2: [5,4], [4,2], [2,4].\nContinuous subarray of size 3: [4,2,4].\nThereare no subarrys of size 4.\nTotal continuous subarrays = 4 + 3 + 1 = 8.\nIt can be shown that there are no more continuous subarrays.\n\n\nExample 2:\n\nInput: nums = [1,2,3]\nOutput: 6\nExplanation:\nContinuous subarray of size 1: [1], [2], [3].\nContinuous subarray of size 2: [1,2], [2,3].\nContinuous subarray of size 3: [1,2,3].\nTotal continuous subarrays = 3 + 2 + 1 = 6.\n\n\nConstraints:\n\n * 1 <= nums.length <= 105\n * 1 <= nums[i] <= 109\n\"\"\"\nclass Solution:\n def continuousSubarrays(self, nums: List[int]) -> int:\n ", "prompt_sft": "You are given a 0-indexed integer array nums. A subarray of nums is called continuous if:\n\n * Let i, i + 1, ..., j be the indices in the subarray. Then, for each pair of indices i <= i1, i2 <= j, 0 <= |nums[i1] - nums[i2]| <= 2.\n\nReturn the total number of continuous subarrays.\n\nA subarray is a contiguous non-empty sequence of elements within an array.\n\nExample 1:\n\nInput: nums = [5,4,2,4]\nOutput: 8\nExplanation:\nContinuous subarray of size 1: [5], [4], [2], [4].\nContinuous subarray of size 2: [5,4], [4,2], [2,4].\nContinuous subarray of size 3: [4,2,4].\nThereare no subarrys of size 4.\nTotal continuous subarrays = 4 + 3 + 1 = 8.\nIt can be shown that there are no more continuous subarrays.\n\n\nExample 2:\n\nInput: nums = [1,2,3]\nOutput: 6\nExplanation:\nContinuous subarray of size 1: [1], [2], [3].\nContinuous subarray of size 2: [1,2], [2,3].\nContinuous subarray of size 3: [1,2,3].\nTotal continuous subarrays = 3 + 2 + 1 = 6.\n\n\nConstraints:\n\n * 1 <= nums.length <= 105\n * 1 <= nums[i] <= 109\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def continuousSubarrays(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [5,4,2,4] }\nassert my_solution.continuousSubarrays(**test_input) == 8\n\ntest_input = { \"nums\": [1,2,3] }\nassert my_solution.continuousSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [31,30,31,32] }\nassert my_solution.continuousSubarrays(**test_input) == 10\n\ntest_input = { \"nums\": [65,66,67,66,66,65,64,65,65,64] }\nassert my_solution.continuousSubarrays(**test_input) == 43\n\ntest_input = { \"nums\": [42,41,42,41,41,40,39,38] }\nassert my_solution.continuousSubarrays(**test_input) == 28\n\ntest_input = { \"nums\": [35,35,36,37,36,37,38,37,38] }\nassert my_solution.continuousSubarrays(**test_input) == 39\n\ntest_input = { \"nums\": [43,44,43,44] }\nassert my_solution.continuousSubarrays(**test_input) == 10\n\ntest_input = { \"nums\": [14,15,15,15,16,16,16,16,15,16] }\nassert my_solution.continuousSubarrays(**test_input) == 55\n\ntest_input = { \"nums\": [21] }\nassert my_solution.continuousSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [34,34,33,34,33,33,32,31,30,31] }\nassert my_solution.continuousSubarrays(**test_input) == 39\n\ntest_input = { \"nums\": [58,59,59,58,59] }\nassert my_solution.continuousSubarrays(**test_input) == 15\n\ntest_input = { \"nums\": [10,9,8,7,8,9,9] }\nassert my_solution.continuousSubarrays(**test_input) == 24\n\ntest_input = { \"nums\": [65,66,65,64,63,62,62] }\nassert my_solution.continuousSubarrays(**test_input) == 20\n\ntest_input = { \"nums\": [65,65,64,65,66,65] }\nassert my_solution.continuousSubarrays(**test_input) == 21\n\ntest_input = { \"nums\": [85,84,83,84,83,82] }\nassert my_solution.continuousSubarrays(**test_input) == 20\n\ntest_input = { \"nums\": [60,59,60] }\nassert my_solution.continuousSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [96,97,98] }\nassert my_solution.continuousSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [21,22,23,22,23] }\nassert my_solution.continuousSubarrays(**test_input) == 15\n\ntest_input = { \"nums\": [76,77,77,78,77,78,78] }\nassert my_solution.continuousSubarrays(**test_input) == 28\n\ntest_input = { \"nums\": [27,27,27,26,26,27,27,27,27] }\nassert my_solution.continuousSubarrays(**test_input) == 45\n\ntest_input = { \"nums\": [17] }\nassert my_solution.continuousSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [95] }\nassert my_solution.continuousSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [62] }\nassert my_solution.continuousSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [10,10,9,8,9,9,9,8,8] }\nassert my_solution.continuousSubarrays(**test_input) == 45\n\ntest_input = { \"nums\": [21,22,22,23,24,24,23,24,23,24] }\nassert my_solution.continuousSubarrays(**test_input) == 49\n\ntest_input = { \"nums\": [94,94,94,94,94,93,94] }\nassert my_solution.continuousSubarrays(**test_input) == 28\n\ntest_input = { \"nums\": [66,65,64,64,64,65,64,63] }\nassert my_solution.continuousSubarrays(**test_input) == 35\n\ntest_input = { \"nums\": [35,35,36,36,35] }\nassert my_solution.continuousSubarrays(**test_input) == 15\n\ntest_input = { \"nums\": [35,34,33,34,35,35,34,35,34] }\nassert my_solution.continuousSubarrays(**test_input) == 45\n\ntest_input = { \"nums\": [70,69,70,71,70,70,71,71] }\nassert my_solution.continuousSubarrays(**test_input) == 36\n\ntest_input = { \"nums\": [49,49,49,50,50,49,50,51,51] }\nassert my_solution.continuousSubarrays(**test_input) == 45\n\ntest_input = { \"nums\": [70,71,72,72,72] }\nassert my_solution.continuousSubarrays(**test_input) == 15\n\ntest_input = { \"nums\": [73,73,74,75,76,76,75,76] }\nassert my_solution.continuousSubarrays(**test_input) == 28\n\ntest_input = { \"nums\": [74,74,74,75,76,75,75,76,77,77] }\nassert my_solution.continuousSubarrays(**test_input) == 49\n\ntest_input = { \"nums\": [21,21,20,19,20,20,21,21] }\nassert my_solution.continuousSubarrays(**test_input) == 36\n\ntest_input = { \"nums\": [86,85] }\nassert my_solution.continuousSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [94,95,96,96,97,98,99,100,100] }\nassert my_solution.continuousSubarrays(**test_input) == 28\n\ntest_input = { \"nums\": [16,17,16] }\nassert my_solution.continuousSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [25,26,26,27,28,27,28,28,27,27] }\nassert my_solution.continuousSubarrays(**test_input) == 49\n\ntest_input = { \"nums\": [54] }\nassert my_solution.continuousSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [94,95,96,95,94,93,92,91] }\nassert my_solution.continuousSubarrays(**test_input) == 24\n\ntest_input = { \"nums\": [84,84,83] }\nassert my_solution.continuousSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [26,26] }\nassert my_solution.continuousSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [53,54,54,55] }\nassert my_solution.continuousSubarrays(**test_input) == 10\n\ntest_input = { \"nums\": [67,67,66,67,68,69,70,71,71] }\nassert my_solution.continuousSubarrays(**test_input) == 28\n\ntest_input = { \"nums\": [43,42,42,42,43] }\nassert my_solution.continuousSubarrays(**test_input) == 15\n\ntest_input = { \"nums\": [93,94,93] }\nassert my_solution.continuousSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [80,80] }\nassert my_solution.continuousSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [54,54,53,54,55,56,57,58,59] }\nassert my_solution.continuousSubarrays(**test_input) == 27\n\ntest_input = { \"nums\": [52,51,50,49,48,49,48,47,46] }\nassert my_solution.continuousSubarrays(**test_input) == 29\n\ntest_input = { \"nums\": [93,92,91,92,92,92,92] }\nassert my_solution.continuousSubarrays(**test_input) == 28\n\ntest_input = { \"nums\": [91,91,90,90,90,91,91,90] }\nassert my_solution.continuousSubarrays(**test_input) == 36\n\ntest_input = { \"nums\": [37,37,37,36] }\nassert my_solution.continuousSubarrays(**test_input) == 10\n\ntest_input = { \"nums\": [40,39,39,39,39,40,40,41,40,39] }\nassert my_solution.continuousSubarrays(**test_input) == 55\n\ntest_input = { \"nums\": [82,83,83,83,83,84] }\nassert my_solution.continuousSubarrays(**test_input) == 21\n\ntest_input = { \"nums\": [35,36,36,37,37,37,36,37,36] }\nassert my_solution.continuousSubarrays(**test_input) == 45\n\ntest_input = { \"nums\": [50,49,50,51,50] }\nassert my_solution.continuousSubarrays(**test_input) == 15\n\ntest_input = { \"nums\": [86,86,86,86,87] }\nassert my_solution.continuousSubarrays(**test_input) == 15\n\ntest_input = { \"nums\": [52] }\nassert my_solution.continuousSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [96,95,94,93] }\nassert my_solution.continuousSubarrays(**test_input) == 9\n\ntest_input = { \"nums\": [56,56,55,55,54,55,54,54,53,52] }\nassert my_solution.continuousSubarrays(**test_input) == 47\n\ntest_input = { \"nums\": [91] }\nassert my_solution.continuousSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [91,90,91,91] }\nassert my_solution.continuousSubarrays(**test_input) == 10\n\ntest_input = { \"nums\": [56,55,55,55] }\nassert my_solution.continuousSubarrays(**test_input) == 10\n\ntest_input = { \"nums\": [1,2,2,2,1,2,3,4,4,5] }\nassert my_solution.continuousSubarrays(**test_input) == 39\n\ntest_input = { \"nums\": [84,85,84,84,85,85,85] }\nassert my_solution.continuousSubarrays(**test_input) == 28\n\ntest_input = { \"nums\": [71,71,71,71] }\nassert my_solution.continuousSubarrays(**test_input) == 10\n\ntest_input = { \"nums\": [47,47,46] }\nassert my_solution.continuousSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [65] }\nassert my_solution.continuousSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [20,20,19,18] }\nassert my_solution.continuousSubarrays(**test_input) == 10\n\ntest_input = { \"nums\": [22,23,23,22,22,22,22] }\nassert my_solution.continuousSubarrays(**test_input) == 28\n\ntest_input = { \"nums\": [92,92] }\nassert my_solution.continuousSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [93,92,92,91,90,90,89,88] }\nassert my_solution.continuousSubarrays(**test_input) == 27\n\ntest_input = { \"nums\": [13,13,12,11] }\nassert my_solution.continuousSubarrays(**test_input) == 10\n\ntest_input = { \"nums\": [22,22,22,21,22,21] }\nassert my_solution.continuousSubarrays(**test_input) == 21\n\ntest_input = { \"nums\": [24,25,26,26,25,26,25,25,26] }\nassert my_solution.continuousSubarrays(**test_input) == 45\n\ntest_input = { \"nums\": [37,36] }\nassert my_solution.continuousSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [52,51] }\nassert my_solution.continuousSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [58] }\nassert my_solution.continuousSubarrays(**test_input) == 1\n\ntest_input = { \"nums\": [88,88,88,87,87,87,87,88,88] }\nassert my_solution.continuousSubarrays(**test_input) == 45\n\ntest_input = { \"nums\": [84,83,83,84,83,82,81] }\nassert my_solution.continuousSubarrays(**test_input) == 24\n\ntest_input = { \"nums\": [87,88,88,87,87,88,88,89] }\nassert my_solution.continuousSubarrays(**test_input) == 36\n\ntest_input = { \"nums\": [28,28,27] }\nassert my_solution.continuousSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [82,83,83,82] }\nassert my_solution.continuousSubarrays(**test_input) == 10\n\ntest_input = { \"nums\": [97,96,96,95,96,95] }\nassert my_solution.continuousSubarrays(**test_input) == 21\n\ntest_input = { \"nums\": [72,73,73,74,73,73] }\nassert my_solution.continuousSubarrays(**test_input) == 21\n\ntest_input = { \"nums\": [21,21,20] }\nassert my_solution.continuousSubarrays(**test_input) == 6\n\ntest_input = { \"nums\": [38,38] }\nassert my_solution.continuousSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [24,24,24,23,22,22,22,23] }\nassert my_solution.continuousSubarrays(**test_input) == 36\n\ntest_input = { \"nums\": [62,62] }\nassert my_solution.continuousSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [11,10,9,10,11] }\nassert my_solution.continuousSubarrays(**test_input) == 15\n\ntest_input = { \"nums\": [34,34,35,34,35,36,36] }\nassert my_solution.continuousSubarrays(**test_input) == 28\n\ntest_input = { \"nums\": [73,74,75,75] }\nassert my_solution.continuousSubarrays(**test_input) == 10\n\ntest_input = { \"nums\": [24,23,24,24] }\nassert my_solution.continuousSubarrays(**test_input) == 10\n\ntest_input = { \"nums\": [21,22,22,23,22,23,22,23,23,22] }\nassert my_solution.continuousSubarrays(**test_input) == 55\n\ntest_input = { \"nums\": [53,53,54,54,54] }\nassert my_solution.continuousSubarrays(**test_input) == 15\n\ntest_input = { \"nums\": [94,95,96,96,97,97,98,99] }\nassert my_solution.continuousSubarrays(**test_input) == 28\n\ntest_input = { \"nums\": [89,89,89,88,87,87] }\nassert my_solution.continuousSubarrays(**test_input) == 21\n\ntest_input = { \"nums\": [89,90] }\nassert my_solution.continuousSubarrays(**test_input) == 3\n\ntest_input = { \"nums\": [18,18] }\nassert my_solution.continuousSubarrays(**test_input) == 3", "start_time": 1688265000} +{"task_id": "weekly-contest-352-sum-of-imbalance-numbers-of-all-subarrays", "url": "https://leetcode.com/problems/sum-of-imbalance-numbers-of-all-subarrays", "title": "sum-of-imbalance-numbers-of-all-subarrays", "meta": {"questionId": "2849", "questionFrontendId": "2763", "title": "Sum of Imbalance Numbers of All Subarrays", "titleSlug": "sum-of-imbalance-numbers-of-all-subarrays", "isPaidOnly": false, "difficulty": "Hard", "likes": 278, "dislikes": 7, "categoryTitle": "Algorithms"}, "prompt": "\"\"\"\nThe imbalance number of a 0-indexed integer array arr of length n is defined as the number of indices in sarr = sorted(arr) such that:\n\n * 0 <= i < n - 1, and\n * sarr[i+1] - sarr[i] > 1\n\nHere, sorted(arr) is the function that returns the sorted version of arr.\n\nGiven a 0-indexed integer array nums, return the sum of imbalance numbers of all its subarrays.\n\nA subarray is a contiguous non-empty sequence of elements within an array.\n\nExample 1:\n\nInput: nums = [2,3,1,4]\nOutput: 3\nExplanation: There are 3 subarrays with non-zero imbalance numbers:\n- Subarray [3, 1] with an imbalance number of 1.\n- Subarray [3, 1, 4] with an imbalance number of 1.\n- Subarray [1, 4] with an imbalance number of 1.\nThe imbalance number of all other subarrays is 0. Hence, the sum of imbalance numbers of all the subarrays of nums is 3.\n\nExample 2:\n\nInput: nums = [1,3,3,3,5]\nOutput: 8\nExplanation: There are 7 subarrays with non-zero imbalance numbers:\n- Subarray [1, 3] with an imbalance number of 1.\n- Subarray [1, 3, 3] with an imbalance number of 1.\n- Subarray [1, 3, 3, 3] with an imbalance number of 1.\n- Subarray [1, 3, 3, 3, 5] with an imbalance number of 2.\n- Subarray [3, 3, 3, 5] with an imbalance number of 1.\n- Subarray [3, 3, 5] with an imbalance number of 1.\n- Subarray [3, 5] with an imbalance number of 1.\nThe imbalance number of all other subarrays is 0. Hence, the sum of imbalance numbers of all the subarrays of nums is 8.\n\nConstraints:\n\n * 1 <= nums.length <= 1000\n * 1 <= nums[i] <= nums.length\n\"\"\"\nclass Solution:\n def sumImbalanceNumbers(self, nums: List[int]) -> int:\n ", "prompt_sft": "The imbalance number of a 0-indexed integer array arr of length n is defined as the number of indices in sarr = sorted(arr) such that:\n\n * 0 <= i < n - 1, and\n * sarr[i+1] - sarr[i] > 1\n\nHere, sorted(arr) is the function that returns the sorted version of arr.\n\nGiven a 0-indexed integer array nums, return the sum of imbalance numbers of all its subarrays.\n\nA subarray is a contiguous non-empty sequence of elements within an array.\n\nExample 1:\n\nInput: nums = [2,3,1,4]\nOutput: 3\nExplanation: There are 3 subarrays with non-zero imbalance numbers:\n- Subarray [3, 1] with an imbalance number of 1.\n- Subarray [3, 1, 4] with an imbalance number of 1.\n- Subarray [1, 4] with an imbalance number of 1.\nThe imbalance number of all other subarrays is 0. Hence, the sum of imbalance numbers of all the subarrays of nums is 3.\n\nExample 2:\n\nInput: nums = [1,3,3,3,5]\nOutput: 8\nExplanation: There are 7 subarrays with non-zero imbalance numbers:\n- Subarray [1, 3] with an imbalance number of 1.\n- Subarray [1, 3, 3] with an imbalance number of 1.\n- Subarray [1, 3, 3, 3] with an imbalance number of 1.\n- Subarray [1, 3, 3, 3, 5] with an imbalance number of 2.\n- Subarray [3, 3, 3, 5] with an imbalance number of 1.\n- Subarray [3, 3, 5] with an imbalance number of 1.\n- Subarray [3, 5] with an imbalance number of 1.\nThe imbalance number of all other subarrays is 0. Hence, the sum of imbalance numbers of all the subarrays of nums is 8.\n\nConstraints:\n\n * 1 <= nums.length <= 1000\n * 1 <= nums[i] <= nums.length\n\n\nPlease complete the code below to solve above prblem:\n```python\nclass Solution:\n def sumImbalanceNumbers(self, nums: List[int]) -> int:\n \n```", "test": "\nmy_solution = Solution()\n\ntest_input = { \"nums\": [2,3,1,4] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 3\n\ntest_input = { \"nums\": [1,3,3,3,5] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 8\n\ntest_input = { \"nums\": [1] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [1,1] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [1,2] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [2,1] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [2,2] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,1] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,2] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,3] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 2\n\ntest_input = { \"nums\": [1,2,1] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [1,2,2] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [1,2,3] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [1,3,1] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 3\n\ntest_input = { \"nums\": [1,3,2] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 1\n\ntest_input = { \"nums\": [1,3,3] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 2\n\ntest_input = { \"nums\": [2,1,1] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [2,1,2] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [2,1,3] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 1\n\ntest_input = { \"nums\": [2,2,1] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [2,2,2] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [2,2,3] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [2,3,1] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 1\n\ntest_input = { \"nums\": [2,3,2] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [2,3,3] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [3,1,1] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 2\n\ntest_input = { \"nums\": [3,1,2] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 1\n\ntest_input = { \"nums\": [3,1,3] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 3\n\ntest_input = { \"nums\": [3,2,1] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [3,2,2] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [3,2,3] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [3,3,1] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 2\n\ntest_input = { \"nums\": [3,3,2] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [3,3,3] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,1,1] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,1,2] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,1,3] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,1,4] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,2,1] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,2,2] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,2,3] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [1,1,2,4] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 3\n\ntest_input = { \"nums\": [1,1,3,1] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 5\n\ntest_input = { \"nums\": [1,1,3,2] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 2\n\ntest_input = { \"nums\": [1,1,3,3] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 4\n\ntest_input = { \"nums\": [1,1,3,4] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 4\n\ntest_input = { \"nums\": [1,1,4,1] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 5\n\ntest_input = { \"nums\": [1,1,4,2] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 5\n\ntest_input = { \"nums\": [1,1,4,3] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 4\n\ntest_input = { \"nums\": [1,1,4,4] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 4\n\ntest_input = { \"nums\": [1,2,1,1] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [1,2,1,2] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [1,2,1,3] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,1,4] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,2,1] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [1,2,2,2] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [1,2,2,3] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [1,2,2,4] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 3\n\ntest_input = { \"nums\": [1,2,3,1] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 1\n\ntest_input = { \"nums\": [1,2,3,2] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [1,2,3,3] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [1,2,3,4] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [1,2,4,1] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 5\n\ntest_input = { \"nums\": [1,2,4,2] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 5\n\ntest_input = { \"nums\": [1,2,4,3] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 2\n\ntest_input = { \"nums\": [1,2,4,4] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 4\n\ntest_input = { \"nums\": [1,3,1,1] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 5\n\ntest_input = { \"nums\": [1,3,1,2] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 3\n\ntest_input = { \"nums\": [1,3,1,3] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 6\n\ntest_input = { \"nums\": [1,3,1,4] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 6\n\ntest_input = { \"nums\": [1,3,2,1] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 1\n\ntest_input = { \"nums\": [1,3,2,2] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 1\n\ntest_input = { \"nums\": [1,3,2,3] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 1\n\ntest_input = { \"nums\": [1,3,2,4] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 2\n\ntest_input = { \"nums\": [1,3,3,1] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 5\n\ntest_input = { \"nums\": [1,3,3,2] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 2\n\ntest_input = { \"nums\": [1,3,3,3] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 3\n\ntest_input = { \"nums\": [1,3,3,4] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 3\n\ntest_input = { \"nums\": [1,3,4,1] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 5\n\ntest_input = { \"nums\": [1,3,4,2] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 3\n\ntest_input = { \"nums\": [1,3,4,3] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 3\n\ntest_input = { \"nums\": [1,3,4,4] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 3\n\ntest_input = { \"nums\": [1,4,1,1] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 5\n\ntest_input = { \"nums\": [1,4,1,2] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 5\n\ntest_input = { \"nums\": [1,4,1,3] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 6\n\ntest_input = { \"nums\": [1,4,1,4] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 6\n\ntest_input = { \"nums\": [1,4,2,1] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 5\n\ntest_input = { \"nums\": [1,4,2,2] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 5\n\ntest_input = { \"nums\": [1,4,2,3] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 3\n\ntest_input = { \"nums\": [1,4,2,4] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 6\n\ntest_input = { \"nums\": [1,4,3,1] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 5\n\ntest_input = { \"nums\": [1,4,3,2] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 2\n\ntest_input = { \"nums\": [1,4,3,3] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 3\n\ntest_input = { \"nums\": [1,4,3,4] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 3\n\ntest_input = { \"nums\": [1,4,4,1] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 5\n\ntest_input = { \"nums\": [1,4,4,2] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 5\n\ntest_input = { \"nums\": [1,4,4,3] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 3\n\ntest_input = { \"nums\": [1,4,4,4] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 3\n\ntest_input = { \"nums\": [2,1,1,1] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0\n\ntest_input = { \"nums\": [2,1,1,2] }\nassert my_solution.sumImbalanceNumbers(**test_input) == 0", "start_time": 1688265000} diff --git a/Evaluation/LeetCode/evaluate_leetcode.py b/Evaluation/LeetCode/evaluate_leetcode.py new file mode 100644 index 0000000..33830fa --- /dev/null +++ b/Evaluation/LeetCode/evaluate_leetcode.py @@ -0,0 +1,86 @@ +import re +import json +from pathlib import Path +from collections import defaultdict +from human_eval.evaluation import evaluate_functional_correctness + +version = "20240121-Jul" + +DATA_DIR = Path(__file__).parent / "data" + +def extract_python_code(generation: str): + generation = generation.replace("[PYTHON]", '```python').replace("[/PYTHON]", '```') + if '```python' in generation: + p_code = re.compile(r'```python\n(.*?)\n```', flags=re.DOTALL) + code_block = p_code.findall(generation)[0] + return code_block + else: + codelist = re.split("\ndef|\nclass|\nif|\n#|\nprint", generation) + return codelist[0] + +def evaluate_main(generation_path: str, result_path: str, temp_dir: str): + problem_path = (DATA_DIR / f"{version}.jsonl").as_posix() + + print(problem_path) + problems = [json.loads(line) for line in open(problem_path, 'r')] + + id2problems = { x['task_id']: x for x in problems } + + results = [json.loads(line) for line in open(generation_path, 'r')] + for result in results: + if 'task_id' not in result: + result['task_id'] = problems[result['index']]['task_id'] + + if 'generation' not in result: + try: + if 'output' not in result: + result['output'] = result['response'] + if result['output'].startswith("\n "): + func_code = extract_python_code(result['prompt_sft']).strip() + result['generation'] = func_code + '\n' + result['output'] + else: + result['generation'] = extract_python_code(result['output']) + except: + result['generation'] = result['output'] + + with open(result_path, 'w') as fr: + for result in results: + fr.write(json.dumps(result) + "\n") + + score = evaluate_functional_correctness( + input_file=result_path, + tmp_dir=temp_dir, + problem_file=problem_path, + result_path=result_path + ) + + hardness_results = defaultdict(int) + for result in [json.loads(line) for line in open(result_path, 'r')]: + problem = id2problems[result['task_id']] + + hardness = problem['meta']['difficulty'] + hardness_results[hardness] += 1 + hardness_results[hardness + "_correct"] += result['passed'] + + print("="*100) + print("Evaluate {} over.".format(generation_path)) + print("Pass@1: {:.3f}".format(score["pass@1"])) + for key in ["Easy", "Medium", "Hard"]: + if key.endswith("_correct"): + continue + acc = hardness_results[key+"_correct"] / hardness_results[key] + print("{}: {:.3f}({}/{})".format(key, acc, hardness_results[key+"_correct"], hardness_results[key])) + +if __name__ == '__main__': + import argparse + parser = argparse.ArgumentParser() + parser.add_argument("--generation_path", type=str, required=True) + parser.add_argument("--result_path", type=str) + parser.add_argument("--temp_dir", type=str, default="output/temp") + args = parser.parse_args() + + if args.result_path is None: + args.result_path = args.generation_path.replace(".jsonl", "_result.jsonl") + + evaluate_main(args.generation_path, args.result_path, temp_dir=args.temp_dir) + pass diff --git a/Evaluation/LeetCode/human_eval/__init__.py b/Evaluation/LeetCode/human_eval/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/Evaluation/LeetCode/human_eval/data.py b/Evaluation/LeetCode/human_eval/data.py new file mode 100644 index 0000000..ed49794 --- /dev/null +++ b/Evaluation/LeetCode/human_eval/data.py @@ -0,0 +1,49 @@ +from typing import Iterable, Dict +import gzip +import json +import os + + +ROOT = os.path.dirname(os.path.abspath(__file__)) +HUMAN_EVAL = os.path.join(ROOT, "..", "data", "HumanEval.jsonl.gz") + + +def read_problems(evalset_file: str = HUMAN_EVAL) -> Dict[str, Dict]: + return {task["task_id"]: task for task in stream_jsonl(evalset_file)} + + +def stream_jsonl(filename: str) -> Iterable[Dict]: + """ + Parses each jsonl line and yields it as a dictionary + """ + if filename.endswith(".gz"): + with open(filename, "rb") as gzfp: + with gzip.open(gzfp, 'rt') as fp: + for line in fp: + if any(not x.isspace() for x in line): + yield json.loads(line) + else: + with open(filename, "r") as fp: + for line in fp: + if any(not x.isspace() for x in line): + yield json.loads(line) + + +def write_jsonl(filename: str, data: Iterable[Dict], append: bool = False): + """ + Writes an iterable of dictionaries to jsonl + """ + if append: + mode = 'ab' + else: + mode = 'wb' + filename = os.path.expanduser(filename) + if filename.endswith(".gz"): + with open(filename, mode) as fp: + with gzip.GzipFile(fileobj=fp, mode='wb') as gzfp: + for x in data: + gzfp.write((json.dumps(x) + "\n").encode('utf-8')) + else: + with open(filename, mode) as fp: + for x in data: + fp.write((json.dumps(x) + "\n").encode('utf-8')) diff --git a/Evaluation/LeetCode/human_eval/evaluation.py b/Evaluation/LeetCode/human_eval/evaluation.py new file mode 100644 index 0000000..587239e --- /dev/null +++ b/Evaluation/LeetCode/human_eval/evaluation.py @@ -0,0 +1,304 @@ +import os +import json +import gzip +import numpy as np +import itertools + +from typing import * +from tqdm.auto import tqdm +from collections import defaultdict +from concurrent.futures import ThreadPoolExecutor, as_completed +from human_eval.data import stream_jsonl +from human_eval.execution import check_correctness + +IMPORT_HELPER = { + "python": [ + "import math", + "import re", + "import sys", + "import copy", + "import datetime", + "import itertools", + "import collections", + "import heapq", + "import functools", + "import hashlib", + "import numpy", + "import numpy as np", + "import string", + "from typing import *", + "from collections import *", + "from functools import *" + ], + "go" : [ + "math", + "strings", + "fmt", + "strconv", + "time", + "bytes", + "regexp", + "sort", + "math/rand", + "crypto/md5", + ], + "cpp" : [ + "#include", + "#include", + "#include", + "#include", + "#include", + "#include", + "#include", + "#include", + "#include", + ], +} + + +LANGUAGE_NAME = { + "cpp" : "CPP", + "go" : "Go", + "java" : "Java", + "js" : "JavaScript", + "python": "Python", +} + + +def read_dataset( + data_file: str = None, + dataset_type: str = "humaneval", + num_shot=None, +) -> Dict: + if num_shot is not None: + print(f"{num_shot}-shot setting...") + if "humaneval" in dataset_type.lower(): + if data_file is None: + current_path = os.path.dirname(os.path.abspath(__file__)) + data_file = os.path.join(current_path, "..", "humaneval-x", "python", "data", "humaneval_python.jsonl.gz") + dataset = {task["task_id"]: task for task in stream_jsonl(data_file)} + else: + raise f"Dataset: {dataset_type} not supported." + + return dataset + +def estimate_pass_at_k( + num_samples: Union[int, List[int], np.ndarray], + num_correct: Union[List[int], np.ndarray], + k: int +) -> np.ndarray: + """ + Estimates pass@k of each problem and returns them in an array. + """ + + def estimator(n: int, c: int, k: int) -> float: + """ + Calculates 1 - comb(n - c, k) / comb(n, k). + """ + if n - c < k: + return 1.0 + return 1.0 - np.prod(1.0 - k / np.arange(n - c + 1, n + 1)) + + if isinstance(num_samples, int): + num_samples_it = itertools.repeat(num_samples, len(num_correct)) + else: + assert len(num_samples) == len(num_correct) + num_samples_it = iter(num_samples) + + return np.array([estimator(int(n), int(c), k) for n, c in zip(num_samples_it, num_correct)]) + +def process_humaneval_test(sample, problems, example_test=False, is_mbpp=False, language="python"): + task_id = sample["task_id"] + + if is_mbpp: + return sample["generation"] + "\n" + "\n".join(problems[task_id]["test"]) + #language = task_id.split("/")[0].lower() + + prompt = sample.get("prompt", "") + if example_test and "example_test" in problems[task_id] and problems[task_id]["example_test"] != "": + test = problems[task_id]["example_test"] + else: + test = problems[task_id]["test"] + code = sample["generation"] + + # Pre-process for different languages + if language == "python": + '''code_ = [] + for line in code.split("\n"): + if (len(line.strip()) > 0 and line[0] != ' ' and line[0] != '\t'): + break + code_.append(line) + code = "\n".join(code_)''' + test_setup = "\n".join(IMPORT_HELPER["python"]) + "\n" + test_string = test_setup + code + "\n" + test + "\n" + elif language == "cpp": + test_set_up = "" + for s in IMPORT_HELPER["cpp"]: + if s not in prompt: + test_set_up += s + "\n" + test_string = test_set_up + "\n" + code + "\n" + test + elif language == "java": + test_string = code + "\n" + test + elif language in ["js", "javascript", "ts", "cs", "sh"]: + test_string = code + "\n" + test + elif language == "go": + import_string = problems[task_id]["import"] + prompt = prompt.replace(import_string, "") + if example_test and "example_test" in problems[task_id]: + test = problems[task_id]["example_test"] + else: + test = problems[task_id]["test"] + test_setup = problems[task_id]["test_setup"] + other_pkgs = [] + for pkg in IMPORT_HELPER["go"]: + if pkg not in test_setup: + p = pkg.split("/")[-1] + if p + "." in code: + other_pkgs.append(f"\"{pkg}\"") + if other_pkgs: + import_other_pkgs = "import (\n" + " ".join([p + "\n" for p in other_pkgs]) + ")" + test_string = test_setup + "\n" + import_other_pkgs + "\n" + prompt + code + "\n" + test + else: + test_string = test_setup + "\n" + prompt + code + "\n" + test + elif language == "rust": + main = "\nfn main(){ \n } \n" + declaration = problems[task_id]["declaration"] + test_string = main + declaration + prompt + code + test + elif language == "php": + test_string = code + "\n" + test + "?>" + return test_string + + +def stream_jsonl_all(filename: str) -> Iterable[Dict]: + results = [] + if filename.endswith(".gz"): + fp = gzip.open(open(filename, "rb"), "rt") + else: + fp = open(filename, "r") + for line in fp: + if any(not x.isspace() for x in line): + results.append(json.loads(line)) + fp.close() + + return results + + +def evaluate_functional_correctness( + input_file: str = None, + tmp_dir: str = "./", + n_workers: int = 32, + timeout: float = 10.0, + problem_file: str = "../data/humaneval_python.jsonl.gz", + result_path: str = None, + k: List[int] = [1, 10, 100], + test_groundtruth: bool = False, + example_test: bool = False, + is_mbpp: bool = False, + language: str = "python", +): + if example_test: + print("Example test...") + + problems = read_dataset(problem_file, dataset_type="humaneval") + sample_jsonl = stream_jsonl_all(input_file) + with ThreadPoolExecutor(max_workers=n_workers) as executor: + futures = [] + completion_id = Counter() + n_samples = 0 + results = defaultdict(list) + + if test_groundtruth: + print("Testing ground truth...") + for sample in tqdm(problems.values()): + task_id = sample["task_id"] + lang = task_id.split("/")[0].lower() + if lang == "javascript": + lang = "js" + tmp_dir_ = os.path.join(tmp_dir, lang, "evaluation") + sample["generation"] = sample["canonical_solution"] + sample["test_code"] = process_humaneval_test(sample, problems, example_test, language) + if sample["test_code"] is None: + continue + args = (task_id, sample, lang, timeout, tmp_dir_, completion_id[task_id]) + future = executor.submit(check_correctness, *args) + futures.append(future) + completion_id[task_id] += 1 + n_samples += 1 + else: + print("Reading Samples...") + id2samples = {} + for sample in tqdm(sample_jsonl): + task_id = sample["task_id"] + + if not is_mbpp: + lang = language + if not is_mbpp and lang == "javascript": + lang = "js" + if is_mbpp: + lang = "python" + tmp_dir_ = os.path.join(tmp_dir, lang, "evaluation") + sample["task_id"] = task_id + sample["test_code"] = process_humaneval_test(sample, problems, example_test, is_mbpp, language) + if sample["test_code"] is None: + continue + if "completion_id" in sample: + completion_id_ = sample["completion_id"] + else: + completion_id_ = completion_id[task_id] + args = (task_id, sample, lang, timeout, tmp_dir_, completion_id_) + id2samples[(task_id, completion_id_)] = sample + future = executor.submit(check_correctness, *args) + futures.append(future) + completion_id[task_id] += 1 + n_samples += 1 + + if len(completion_id) == len(problems): + evaluate_pass_at_k = True + else: + evaluate_pass_at_k = False + + print("Running test suites...") + sample_with_results = [] + for future in tqdm(as_completed(futures), total=len(futures)): + result = future.result() + results[result["task_id"]].append((result["completion_id"], result)) + + sample = id2samples[(result["task_id"], result["completion_id"])] + sample_with_results.append({ + 'task_id': result['task_id'], + 'completion_id': result["completion_id"], + 'passed': result['passed'], + 'generation': sample['generation'] + }) + + for key in sample: + if key not in sample_with_results[-1]: + sample_with_results[-1][key] = sample[key] + + # Calculate pass@k. + total, correct = [], [] + for result in results.values(): + passed = [r[1]["passed"] for r in result] + total.append(len(passed)) + correct.append(sum(passed)) + + total = np.array(total) + correct = np.array(correct) + if evaluate_pass_at_k: + ks = k + pass_at_k = { + f"pass@{k}": estimate_pass_at_k(total, correct, k).mean() + for k in ks if (total >= k).all() + } + print(pass_at_k) + else: + print("Total:", np.sum(total)) + print("Correct:", np.sum(correct)) + + if result_path is not None: + with open(result_path, 'w', encoding='utf-8') as fw: + for sample_with_result in sample_with_results: + fw.write(json.dumps(sample_with_result) + '\n') + print("Save evaluation results to\n{}".format(result_path)) + + return pass_at_k diff --git a/Evaluation/LeetCode/human_eval/execution.py b/Evaluation/LeetCode/human_eval/execution.py new file mode 100644 index 0000000..14e19db --- /dev/null +++ b/Evaluation/LeetCode/human_eval/execution.py @@ -0,0 +1,731 @@ +import contextlib +import faulthandler +import io +import multiprocessing +import os +import platform +import signal +import random +import subprocess +import tempfile +import gzip +import json +from typing import * +import traceback + +java_exec = "" +node_exec = "" +tsc_exec = "" +go_exec = "" +php_exec = "" +cs_exec = "" + +def check_correctness( + task_id: str, + sample: dict, + language_type: str, + timeout: float = 3.0, + tmp_dir: str = None, + completion_id: Optional[int] = None, +) -> Dict: + """ + Evaluates the functional correctness of a completion by running the test + suite provided in the problem. + """ + + def unsafe_execute(tmp_dir): + random_id = random.randint(1, 100000) + if "python" in language_type.lower(): + with create_tempdir(): + + # These system calls are needed when cleaning up tempdir. + import os + import shutil + rmtree = shutil.rmtree + rmdir = os.rmdir + chdir = os.chdir + + # Disable functionalities that can make destructive changes to the test. + reliability_guard() + + try: + exec_globals = {} + with swallow_io(): + with time_limit(timeout): + # WARNING + # This program exists to execute untrusted model-generated code. Although + # it is highly unlikely that model-generated code will do something overtly + # malicious in response to this test suite, model-generated code may act + # destructively due to a lack of model capability or alignment. + # Users are strongly encouraged to sandbox this evaluation suite so that it + # does not perform destructive actions on their host or network. + # Once you have read this disclaimer and taken appropriate precautions, + # uncomment the following line and proceed at your own risk: + exec(sample["test_code"], exec_globals) + result.append("passed") + except TimeoutException: + result.append("timed out") + except AssertionError as e: + result.append(f"failed: AssertionError") + except BaseException as e: + result.append(f"failed: {e}") + #print(sample["test_code"]) + #print(result) + # Needed for cleaning up. + shutil.rmtree = rmtree + os.rmdir = rmdir + os.chdir = chdir + + elif "go" in language_type.lower(): + assert tmp_dir is not None, "Go should be evaluated in a dir where necessary module files installed." + + import os + import shutil + + if "tmp" not in tmp_dir: + tmp_dir = os.path.join(tmp_dir, "tmp") + tmp_dir = os.path.join(tmp_dir, f"{task_id.replace('/', '-')}-{random_id}") + if not os.path.exists(tmp_dir): + os.makedirs(tmp_dir) + origin_path = os.getcwd() + os.chdir(tmp_dir) + open(f"main_test.go", 'w').write(sample["test_code"]) + try: + exec_result = None + with time_limit(timeout): + # WARNING + # This program exists to execute untrusted model-generated code. Although + # it is highly unlikely that model-generated code will do something overtly + # malicious in response to this test suite, model-generated code may act + # destructively due to a lack of model capability or alignment. + # Users are strongly encouraged to sandbox this evaluation suite so that it + # does not perform destructive actions on their host or network. + # Once you have read this disclaimer and taken appropriate precautions, + # uncomment the following line and proceed at your own risk: + exec_result = subprocess.run([f"{go_exec}go", "test", f"-timeout={timeout}s", "main_test.go"], timeout=timeout, capture_output=True) + + if exec_result.returncode == 0: + result.append("passed") + else: + if exec_result.stderr: + try: + err = exec_result.stderr.decode() + except: + err = exec_result.stderr + else: + try: + err = exec_result.stdout.decode() + except: + err = exec_result.stdout + result.append(f"failed: {err}") + + except TimeoutException: + result.append("timed out") + os.chdir(origin_path) + shutil.rmtree(tmp_dir) + elif "js" in language_type.lower(): + import os + import shutil + + if "tmp" not in tmp_dir: + tmp_dir = os.path.join(tmp_dir, "tmp") + tmp_dir = os.path.join(tmp_dir, f"{task_id.replace('/', '-')}-{random_id}") + if not os.path.exists(tmp_dir): + os.makedirs(tmp_dir) + origin_path = os.getcwd() + os.chdir(tmp_dir) + open(f"test.js", 'w').write(sample["test_code"]) + try: + exec_result = None + with time_limit(timeout): + # WARNING + # This program exists to execute untrusted model-generated code. Although + # it is highly unlikely that model-generated code will do something overtly + # malicious in response to this test suite, model-generated code may act + # destructively due to a lack of model capability or alignment. + # Users are strongly encouraged to sandbox this evaluation suite so that it + # does not perform destructive actions on their host or network. + # Once you have read this disclaimer and taken appropriate precautions, + # uncomment the following line and proceed at your own risk: + exec_result = subprocess.run([f"{node_exec}node", "test.js"], timeout=timeout, capture_output=True) + + if exec_result.stderr.decode(): + err = exec_result.stderr.decode() + result.append(f"failed: {err}") + elif exec_result.stdout.decode(): + err = exec_result.stdout.decode() + result.append(f"failed: {err}") + else: + result.append("passed") + + except TimeoutException: + result.append("timed out") + os.chdir(origin_path) + shutil.rmtree(tmp_dir) + elif "cpp" in language_type.lower(): + import os + import shutil + origin_path = os.getcwd() + if "tmp" not in tmp_dir: + tmp_dir = os.path.join(tmp_dir, "tmp") + tmp_dir = os.path.join(tmp_dir, f"{task_id.replace('/', '-')}-{random_id}") + if not os.path.exists(tmp_dir): + os.makedirs(tmp_dir) + + os.chdir(tmp_dir) + open(f"test.cpp", 'w').write(sample["test_code"]) + if "162" in task_id: + compilation_result = subprocess.run(["/usr/bin/g++", "-std=c++17", "test.cpp", "-lcrypto", "-lssl"], + timeout=timeout, + capture_output=True) + else: + compilation_result = subprocess.run(["/usr/bin/g++", "-std=c++17", "test.cpp"], timeout=timeout, + capture_output=True) + if compilation_result.returncode != 0: + if compilation_result.stderr: + err = compilation_result.stderr.decode() + else: + err = compilation_result.stdout.decode() + result.append(f"failed: compilation error: {err}") + else: + try: + exec_result = None + with time_limit(timeout): + # WARNING + # This program exists to execute untrusted model-generated code. Although + # it is highly unlikely that model-generated code will do something overtly + # malicious in response to this test suite, model-generated code may act + # destructively due to a lack of model capability or alignment. + # Users are strongly encouraged to sandbox this evaluation suite so that it + # does not perform destructive actions on their host or network. + # Once you have read this disclaimer and taken appropriate precautions, + # uncomment the following line and proceed at your own risk: + exec_result = subprocess.run(["./a.out"], timeout=timeout, capture_output=True) + + if exec_result.returncode == 0: + result.append("passed") + else: + if exec_result.stderr: + try: + err = exec_result.stderr.decode() + except: + err = exec_result.stderr + else: + try: + err = exec_result.stdout.decode() + except: + err = exec_result.stdout + result.append(f"failed: {err}") + except TimeoutException: + result.append("timed out") + #print(result[-1]) + #print(sample["test_code"]) + os.chdir(origin_path) + shutil.rmtree(tmp_dir) + elif "php" in language_type.lower(): + import os + import shutil + origin_path = os.getcwd() + if "tmp" not in tmp_dir: + tmp_dir = os.path.join(tmp_dir, "tmp") + tmp_dir = os.path.join(tmp_dir, f"{task_id.replace('/', '-')}-{random_id}") + if not os.path.exists(tmp_dir): + os.makedirs(tmp_dir) + + os.chdir(tmp_dir) + open(f"test.php", 'w').write(sample["test_code"]) + try: + exec_result = None + with time_limit(timeout): + cmd = f"{php_exec}php -f test.php" + exec_result = subprocess.run(cmd, timeout=timeout, capture_output=True, shell=True) + + if exec_result.returncode == 0: + result.append("passed") + else: + if exec_result.stderr: + try: + err = exec_result.stderr.decode() + except: + err = exec_result.stderr + else: + try: + err = exec_result.stdout.decode() + except: + err = exec_result.stdout + result.append(f"failed: {err}") + except TimeoutException: + result.append("timed out") + print(result[-1]) + print(sample["test_code"]) + os.chdir(origin_path) + shutil.rmtree(tmp_dir) + elif "sh" in language_type.lower(): + import os + import shutil + origin_path = os.getcwd() + if "tmp" not in tmp_dir: + tmp_dir = os.path.join(tmp_dir, "tmp") + tmp_dir = os.path.join(tmp_dir, f"{task_id.replace('/', '-')}-{random_id}") + if not os.path.exists(tmp_dir): + os.makedirs(tmp_dir) + + os.chdir(tmp_dir) + open(f"test.sh", 'w').write(sample["test_code"]) + try: + exec_result = None + with time_limit(timeout): + cmd = "/bin/bash test.sh" + exec_result = subprocess.run(cmd, timeout=10, capture_output=True, shell=True) + + if exec_result.returncode == 0: + result.append("passed") + else: + if exec_result.stderr: + try: + err = exec_result.stderr.decode() + except: + err = exec_result.stderr + else: + try: + err = exec_result.stdout.decode() + except: + err = exec_result.stdout + result.append(f"failed: {err}") + except TimeoutException: + result.append("timed out") + #print(result[-1]) + #print(sample["test_code"]) + os.chdir(origin_path) + shutil.rmtree(tmp_dir) + elif "ts" in language_type.lower(): + import os + import shutil + origin_path = os.getcwd() + if "tmp" not in tmp_dir: + tmp_dir = os.path.join(tmp_dir, "tmp") + tmp_dir = os.path.join(tmp_dir, f"{task_id.replace('/', '-')}-{random_id}") + if not os.path.exists(tmp_dir): + os.makedirs(tmp_dir) + + os.chdir(tmp_dir) + env = {"PATH": f"{node_exec}:" + subprocess.os.environ["PATH"]} + open(f"test.ts", 'w').write(sample["test_code"]) + cmd = f"{tsc_exec}tsc test.ts --target ES2015 --lib ES2015,DOM" + compilation_result = subprocess.run(cmd, timeout=timeout, capture_output=True, env=env, shell=True) + if compilation_result.returncode != 0: + if compilation_result.stderr: + err = compilation_result.stderr.decode() + else: + err = compilation_result.stdout.decode() + result.append(f"failed: compilation error: {err}") + else: + try: + exec_result = None + with time_limit(timeout): + exec_result = subprocess.run([f"{node_exec}node", "test.js"], timeout=timeout, capture_output=True) + + if exec_result.returncode == 0: + result.append("passed") + else: + if exec_result.stderr: + try: + err = exec_result.stderr.decode() + except: + err = exec_result.stderr + else: + try: + err = exec_result.stdout.decode() + except: + err = exec_result.stdout + result.append(f"failed: {err}") + except TimeoutException: + result.append("timed out") + if result[-1] != "passed": + env = {"PATH": f"{node_exec}:" + subprocess.os.environ["PATH"]} + cmd = f"{tsc_exec}tsc test.ts" + compilation_result = subprocess.run(cmd, timeout=timeout, capture_output=True, env=env, shell=True) + if compilation_result.returncode != 0: + if compilation_result.stderr: + err = compilation_result.stderr.decode() + else: + err = compilation_result.stdout.decode() + result[-1] = f"failed: compilation error: {err}" + else: + try: + exec_result = None + with time_limit(timeout): + exec_result = subprocess.run([f"{node_exec}node", "test.js"], timeout=timeout, capture_output=True) + + if exec_result.returncode == 0: + result[-1] = "passed" + else: + if exec_result.stderr: + try: + err = exec_result.stderr.decode() + except: + err = exec_result.stderr + else: + try: + err = exec_result.stdout.decode() + except: + err = exec_result.stdout + result[-1] = f"failed: {err}" + except TimeoutException: + result[-1] = "timed out" + + os.chdir(origin_path) + shutil.rmtree(tmp_dir) + elif "cs" in language_type.lower(): + import os + import shutil + origin_path = os.getcwd() + if "tmp" not in tmp_dir: + tmp_dir = os.path.join(tmp_dir, "tmp") + tmp_dir = os.path.join(tmp_dir, f"{task_id.replace('/', '-')}-{random_id}") + if not os.path.exists(tmp_dir): + os.makedirs(tmp_dir) + os.chdir(tmp_dir) + open(f"Program.cs", 'w').write(sample["test_code"]) + cmd = f"{cs_exec}mcs -d:DEBUG Program.cs" + compilation_result = subprocess.run(cmd, shell=True, capture_output=True) + if compilation_result.returncode != 0: + if compilation_result.stderr: + err = compilation_result.stderr.decode() + else: + err = compilation_result.stdout.decode() + result.append(f"failed: compilation error: {err}") + else: + try: + exec_result = None + cmd = f"{cs_exec}mono Program.exe" + env = dict(MONO_TRACE_LISTENER="Console.Error") + with time_limit(timeout): + exec_result = subprocess.run(cmd, timeout=timeout, shell=True, capture_output=True, env=env) + + if "Fail" not in exec_result.stderr.decode(): + result.append("passed") + else: + if exec_result.stderr: + try: + err = exec_result.stderr.decode() + except: + err = exec_result.stderr + else: + try: + err = exec_result.stdout.decode() + except: + err = exec_result.stdout + result.append(f"failed: {err}") + except TimeoutException: + result.append("timed out") + except Exception as e: + result.append(f"failed: {e}") + os.chdir(origin_path) + shutil.rmtree(tmp_dir) + elif "rust" in language_type.lower(): + import os + + WD: str = os.path.dirname(os.path.abspath(__file__)) + RUST_DIR: str = os.path.join(WD, "rust") + RUST_SRC: str = os.path.join(RUST_DIR, "src") + RUST_BIN: str = os.path.join(RUST_SRC, "bin") + RUST_TMP_DIR: str = os.path.join(RUST_DIR, "tmp") + RUST_LOGS: str = os.path.join(RUST_TMP_DIR, "logs") + RUST_EXT: str = ".rs" + + # Create mandatory tmp directories + os.makedirs(RUST_TMP_DIR, exist_ok=True) + os.makedirs(RUST_LOGS, exist_ok=True) + os.makedirs(RUST_SRC, exist_ok=True) + os.makedirs(RUST_BIN, exist_ok=True) + + with tempfile.NamedTemporaryFile(dir = RUST_BIN, delete=False) as f: + #temporal file name + file_prefix = sample["task_id"].lower().replace("/", "_") + file_name:str = file_prefix +RUST_EXT + + os.rename(f.name, os.path.join(RUST_BIN, file_name)) + + # Sample to pure Rust function + rust_code: str = sample["test_code"] + + # dump the rust source code in the target temporal file + f.write(rust_code.encode('utf-8')) + + # Proceed towards Rust binaries compilation. Therefore move to Rust module root dir. + os.chdir(RUST_DIR) + + # Two possible outcomes + # Pass OR Fail compilation + log_filename: str = file_prefix + ".jsonl" + log_path: str = os.path.join(RUST_LOGS, log_filename) + cargo_check: str = "cargo check --bin " + file_prefix + " --message-format json >> " + log_path + # Compilation build status + returned_val_compilation: int + + # Overwrite file content + if os.path.exists(log_path): + if(file_size := os.path.getsize(log_path)) >= 0: + os.remove(log_path) + returned_val_compilation = os.system(cargo_check) + + else: + returned_val_compilation = os.system(cargo_check) + + # 0 means success + if returned_val_compilation == 0: + + #Execution pipeline + cargo_test: str = "cargo test --bin " +file_prefix+ " --message-format json >> " + log_path + returned_val_execution = os.system(cargo_test) + + if returned_val_execution == 0: + result.append("passed") + else: + result.append(f"failed: execution error") + + else: + result.append(f"failed: compilation error") + + + elif "java" in language_type.lower(): + assert tmp_dir is not None, "Java should be evaluated in a temporary dir." + + import os + import shutil + + if "tmp" not in tmp_dir: + tmp_dir = os.path.join(tmp_dir, "tmp") + tmp_dir = os.path.join(tmp_dir, f"{task_id.replace('/', '-')}-{random_id}") + if not os.path.exists(tmp_dir): + os.makedirs(tmp_dir) + open(os.path.join(tmp_dir, "Problem.java"), 'w').write(sample["test_code"]) + origin_path = os.getcwd() + os.system(f"cp ./javatuples-1.2.jar {tmp_dir}/") + os.chdir(tmp_dir) + res = "failed: unknown error" + compile_returncode = -1 + for _ in range(5): + try: + cmd = f"{java_exec}javac -cp javatuples-1.2.jar Problem.java" + compilation_result = subprocess.run(cmd, timeout=60, capture_output=True, shell=True) + compile_returncode = compilation_result.returncode + break + except subprocess.TimeoutExpired as e: + continue + if compile_returncode != 0: + res = "failed: compilation error" + else: + exec_result = None + try: + # WARNING + # This program exists to execute untrusted model-generated code. Although + # it is highly unlikely that model-generated code will do something overtly + # malicious in response to this test suite, model-generated code may act + # destructively due to a lack of model capability or alignment. + # Users are strongly encouraged to sandbox this evaluation suite so that it + # does not perform destructive actions on their host or network. + # Once you have read this disclaimer and taken appropriate precautions, + # uncomment the following line and proceed at your own risk: + cmd = f"{java_exec}java -ea -cp .:javatuples-1.2.jar Problem" + exec_result = subprocess.run(cmd, timeout=timeout, capture_output=True, shell=True) + if exec_result.returncode == 0: + res = "passed" + elif exec_result.returncode == 1: + if "AssertionError" in exec_result.stderr.decode('unicode-escape'): + res = "failed: wrong answer" + else: + res = f"failed: {exec_result.stderr.decode()}" + except subprocess.TimeoutExpired as e: + res = "time out" + except BaseException as e: + res = f"failed: {e}" + + result.append(res) + os.chdir(origin_path) + shutil.rmtree(tmp_dir) + + manager = multiprocessing.Manager() + result = manager.list() + + p = multiprocessing.Process(target=unsafe_execute, args=(tmp_dir,)) + p.start() + p.join(timeout=timeout + 1) + if p.is_alive(): + p.kill() + + if not result: + result.append("timed out") + + return { + "task_id" : task_id, + "completion_id": completion_id, + "result" : result[0], + "passed" : result[0] == "passed", + "finish" : -1 if "finish" not in sample else sample["finish"], + "code" : sample["test_code"] + } + +# Copyright (c) OpenAI (https://openai.com) + +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: + +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. + +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +# ============================================================================ +@contextlib.contextmanager +def time_limit(seconds: float): + def signal_handler(signum, frame): + raise TimeoutException("Timed out!") + + signal.setitimer(signal.ITIMER_REAL, seconds) + signal.signal(signal.SIGALRM, signal_handler) + try: + yield + finally: + signal.setitimer(signal.ITIMER_REAL, 0) + + +@contextlib.contextmanager +def swallow_io(): + stream = WriteOnlyStringIO() + with contextlib.redirect_stdout(stream): + with contextlib.redirect_stderr(stream): + with redirect_stdin(stream): + yield + + +@contextlib.contextmanager +def create_tempdir(): + with tempfile.TemporaryDirectory() as dirname: + with chdir(dirname): + yield dirname + + +class TimeoutException(Exception): + pass + + +class WriteOnlyStringIO(io.StringIO): + """ StringIO that throws an exception when it's read from """ + + def read(self, *args, **kwargs): + raise IOError + + def readline(self, *args, **kwargs): + raise IOError + + def readlines(self, *args, **kwargs): + raise IOError + + def readable(self, *args, **kwargs): + """ Returns True if the IO object can be read. """ + return False + + +class redirect_stdin(contextlib._RedirectStream): # type: ignore + _stream = 'stdin' + + +@contextlib.contextmanager +def chdir(root): + if root == ".": + yield + return + cwd = os.getcwd() + os.chdir(root) + try: + yield + except BaseException as exc: + raise exc + finally: + os.chdir(cwd) + + +def reliability_guard(maximum_memory_bytes: Optional[int] = None): + """ + This disables various destructive functions and prevents the generated code + from interfering with the test (e.g. fork bomb, killing other processes, + removing filesystem files, etc.) + + WARNING + This function is NOT a security sandbox. Untrusted code, including, model- + generated code, should not be blindly executed outside of one. See the + Codex paper for more information about OpenAI's code sandbox, and proceed + with caution. + """ + + if maximum_memory_bytes is not None: + import resource + resource.setrlimit(resource.RLIMIT_AS, (maximum_memory_bytes, maximum_memory_bytes)) + resource.setrlimit(resource.RLIMIT_DATA, (maximum_memory_bytes, maximum_memory_bytes)) + if not platform.uname().system == 'Darwin': + resource.setrlimit(resource.RLIMIT_STACK, (maximum_memory_bytes, maximum_memory_bytes)) + + faulthandler.disable() + + import builtins + builtins.exit = None + builtins.quit = None + + import os + os.environ['OMP_NUM_THREADS'] = '1' + + os.kill = None + os.system = None + os.putenv = None + os.remove = None + os.removedirs = None + os.rmdir = None + os.fchdir = None + os.setuid = None + os.fork = None + os.forkpty = None + os.killpg = None + os.rename = None + os.renames = None + os.truncate = None + os.replace = None + os.unlink = None + os.fchmod = None + os.fchown = None + os.chmod = None + os.chown = None + os.chroot = None + os.fchdir = None + os.lchflags = None + os.lchmod = None + os.lchown = None + os.getcwd = None + os.chdir = None + + import shutil + shutil.rmtree = None + shutil.move = None + shutil.chown = None + + import subprocess + subprocess.Popen = None # type: ignore + + __builtins__['help'] = None + + import sys + sys.modules['ipdb'] = None + sys.modules['joblib'] = None + sys.modules['resource'] = None + sys.modules['psutil'] = None + sys.modules['tkinter'] = None \ No newline at end of file diff --git a/Evaluation/LeetCode/readme.md b/Evaluation/LeetCode/readme.md new file mode 100644 index 0000000..bc84228 --- /dev/null +++ b/Evaluation/LeetCode/readme.md @@ -0,0 +1,48 @@ +## 1. Introduction +We construct the LeetCode Contest benchmark to to further validate the model's capability in real-world programming problems. +[LeetCode](https://leetcode.com/) presents competition-level problems, offering significant challenges that test the model's problem understanding and code generation skills. We collected the latest problems from LeetCode Contests to prevent the appearance of both the problems or their solutions in our pre-training data. A total of `180` problems were collected from July 2023 to January 2024. For each problem, we collected `100` test cases. The data format is the same as human-eval. For more details, please refer to [leetcode_contest_data](./data/20240121-Jul.jsonl). + +## 2. Evaluation +Please follow the following two steps to evaluate the model's performance on our LeetCode Contest benchmark: + +1. Run `vllm_inference.py` to get generation results. +```bash +cd Evaluation/LeetCode + +# Set the model or path here +MODEL="deepseek-coder-7b-instruct" + +python vllm_inference.py --model_name_or_path $MODEL --saved_path output/20240121-Jul.deepseek-coder-7b-instruct.jsonl +``` + +If you want to evaluate the model with COT, please add `--cot` to the command: +```bash +python vllm_inference.py --model_name_or_path $MODEL --saved_path output/20240121-Jul.deepseek-coder-7b-instruct.jsonl --cot +``` + +2. Run `evaluate_leetcode.py` to get evaluation results. +```bash +python evaluate_leetcode.py --generation_path output/20240121-Jul.deepseek-coder-7b-instruct.jsonl --result_path output/20240121-Jul.deepseek-coder-7b-instruct.result.jsonl +``` + +## 3. Experimental Results +We report experimental results here: + +| Model | Size | Easy (45) | Medium (91) | Hard (44) | Overall(180) | +|-----------------------------|------|-----------|-------------|-----------|--------------| +| WizardCoder-V1.0 | 15B | 17.8% | 1.1% | 0.0% | 5.0% | +| CodeLlama-Instruct | 34B | 24.4% | 4.4% | 4.5% | 9.4% | +| Phind-CodeLlama-V2 | 34B | 26.7% | 8.8% | 9.1% | 13.3% | +| | | | | +| GPT-3.5-Turbo | - | 46.7% | 15.4 % | 15.9% | 23.3% | +| GPT-3.5-Turbo + CoT | - | 42.2% | 15.4% | 20.5% | 23.3% | +| GPT-4-Turbo | - | 73.3% | 31.9% | 25.0% | 40.6% | +| GPT-4-Turbo + CoT | - | 71.1% | 35.2% | 25.0% | 41.8% | +| | | | | +| DeepSeek-Coder-Instruct | 1.3B | 22.2% | 1.1% | 4.5% | 7.2% | +| DeepSeek-Coder-Instruct + CoT | 1.3B | 22.2% | 2.2% | 2.3% | 7.2% | +| DeepSeek-Coder-Instruct | 6.7B | 44.4% | 12.1% | 9.1% | 19.4% | +| DeepSeek-Coder-Instruct + CoT | 6.7B | 44.4% | 17.6% | 4.5% | 21.1% | +| DeepSeek-Coder-Instruct | 33B | 57.8% | 22.0% | 9.1% | 27.8% | +| DeepSeek-Coder-Instruct + CoT | 33B | 53.3% | 25.3% | 11.4% | 28.9% | + diff --git a/Evaluation/LeetCode/vllm_inference.py b/Evaluation/LeetCode/vllm_inference.py new file mode 100644 index 0000000..ccf70da --- /dev/null +++ b/Evaluation/LeetCode/vllm_inference.py @@ -0,0 +1,84 @@ +from vllm import LLM, SamplingParams +import json +from transformers import AutoTokenizer +from pathlib import Path + +version = "20240121-Jul" + +def generate_batch(examples, tokenizer, llm, model: str): + stop = None + if model == 'deepseekcoder-instruct': + prompts = [ + tokenizer.apply_chat_template([{'role': 'user', 'content': ex['prompt_sft'] }], tokenize=False, add_generation_prompt=True) + for ex in examples + ] + else: + raise NotImplementedError() + + # Create a sampling params object. + sampling_params = SamplingParams( + temperature=0.0, + # top_p=0.95, + max_tokens=1024, + stop=stop + ) + + print("Sample prompt: {}".format(prompts[0])) + outputs = llm.generate(prompts, sampling_params) + for i in range(len(examples)): + examples[i]['output'] = outputs[i].outputs[0].text + + return examples + +def generate_main(data_path: str, model_name_or_path: str, saved_path: str, model_type: str='deepseekcoder-instruct', cot: bool=False): + examples = [json.loads(x) for x in open(data_path).readlines()] + def _convert_for_sft(ex): + ex['prompt_sft'] = ex["prompt_sft"] + "\nYou need first write a step-by-step outline and then write the code." + return ex + + if cot: + examples = [_convert_for_sft(x) for x in examples] + saved_path = saved_path.replace(".jsonl", ".cot.jsonl") + + print(model_type) + print("Model `{}`, COT = {}:{}".format(model_type, cot, model_name_or_path)) + print("Saved path: {}".format(saved_path)) + + tokenizer = AutoTokenizer.from_pretrained(model_name_or_path, trust_remote_code=True) + print("load tokenizer {} from {} over.".format(tokenizer.__class__, model_name_or_path)) + + # Create an LLM. + llm = LLM( + model=model_name_or_path, + pipeline_parallel_size=1, + tensor_parallel_size=8, + max_num_seqs=512, + max_num_batched_tokens=8192, + max_model_len=4096, + gpu_memory_utilization=0.85, + trust_remote_code=True + ) + + generated_examples = generate_batch(examples, tokenizer, llm, model_type) + print("Generate all over!!!") + with open(saved_path, 'w', encoding='utf-8') as fw: + for ex in generated_examples: + fw.write(json.dumps(ex) + '\n') + print("Save {} processed examples into {} over!".format(len(generated_examples), saved_path)) + +if __name__ == '__main__': + import argparse + + parser = argparse.ArgumentParser() + parser.add_argument('--data_path', type=str, default=Path(__file__).parent.joinpath(f"data/{version}.jsonl").as_posix()) + parser.add_argument('--model_name_or_path', type=str, default='deepseek-ai/deepseek-coder-7b-instruct') + parser.add_argument('--saved_path', type=str, default=f'output/{version}.deepseek-coder-7b-instruct.jsonl') + parser.add_argument('--cot', action='store_true', default=False) + args = parser.parse_args() + + generate_main( + data_path=args.data_path, + model_name_or_path=args.model_name_or_path, + saved_path=args.saved_path, + cot=args.cot, + )