diff --git "a/data/test/python-000.jsonl" "b/data/test/python-000.jsonl" --- "a/data/test/python-000.jsonl" +++ "b/data/test/python-000.jsonl" @@ -105,7 +105,7 @@ {"question_id": 3386, "task_id": "button-with-longest-push-time", "difficulty": "Easy", "problem_description": "You are given a 2D array events which represents a sequence of events where a child pushes a series of buttons on a keyboard.\n\nEach events[i] = [index_i, time_i] indicates that the button at index index_i was pressed at time time_i.\n\n- The array is sorted in increasing order of time.\n- The time taken to press a button is the difference in time between consecutive button presses. The time for the first button is simply the time at which it was pressed.\n\nReturn the index of the button that took the longest time to push. If multiple buttons have the same longest time, return the button with the smallest index.\n\nExample 1:\n\nInput: events = [[1,2],[2,5],[3,9],[1,15]]\nOutput: 1\nExplanation:\n- Button with index 1 is pressed at time 2.\n- Button with index 2 is pressed at time 5, so it took 5 - 2 = 3 units of time.\n- Button with index 3 is pressed at time 9, so it took 9 - 5 = 4 units of time.\n- Button with index 1 is pressed again at time 15, so it took 15 - 9 = 6 units of time.\n\nExample 2:\n\nInput: events = [[10,5],[1,7]]\nOutput: 10\nExplanation:\n- Button with index 10 is pressed at time 5.\n- Button with index 1 is pressed at time 7, so it took 7 - 5 = 2 units of time.\n\nConstraints:\n\n- 1 <= events.length <= 1000\n- events[i] == [index_i, time_i]\n- 1 <= index_i, time_i <= 10^5\n- The input is generated such that events is sorted in increasing order of time_i.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(events = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5]]) == 1\n assert candidate(events = [[3, 1], [1, 3], [2, 6], [3, 10]]) == 3\n assert candidate(events = [[10, 5], [1, 7]]) == 10\n assert candidate(events = [[100, 100], [200, 200], [100, 300], [200, 400]]) == 100\n assert candidate(events = [[3, 1], [3, 4], [5, 8], [5, 12], [3, 16]]) == 3\n assert candidate(events = [[1, 10], [2, 20], [3, 30], [4, 40], [5, 50]]) == 1\n assert candidate(events = [[5, 10], [5, 15], [5, 20], [5, 25]]) == 5\n assert candidate(events = [[5, 10], [3, 12], [5, 18], [1, 25]]) == 5\n assert candidate(events = [[2, 3], [4, 8], [2, 15], [3, 20]]) == 2\n assert candidate(events = [[5, 10], [3, 15], [5, 25], [2, 30]]) == 5\n assert candidate(events = [[3, 3], [4, 8], [2, 15], [4, 20]]) == 2\n assert candidate(events = [[5, 10], [5, 20], [5, 30], [5, 40]]) == 5\n assert candidate(events = [[5, 1], [5, 2], [5, 3], [5, 4], [5, 5]]) == 5\n assert candidate(events = [[1, 2], [2, 5], [3, 9], [1, 15]]) == 1\n assert candidate(events = [[5, 1], [5, 2], [5, 4], [5, 8], [5, 16], [5, 32], [5, 64], [5, 128], [5, 256]]) == 5\n assert candidate(events = [[7, 1], [8, 5], [9, 10], [7, 20], [8, 30], [9, 40], [7, 50]]) == 7\n assert candidate(events = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10], [2, 11], [2, 12]]) == 1\n assert candidate(events = [[9, 1], [4, 6], [9, 10], [3, 15], [9, 20], [2, 25], [3, 30]]) == 2\n assert candidate(events = [[5, 5], [3, 10], [7, 15], [2, 20], [5, 25], [3, 30], [7, 35]]) == 2\n assert candidate(events = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10], [1, 20]]) == 1\n assert candidate(events = [[1, 2], [2, 3], [3, 5], [4, 10], [5, 15], [6, 20], [7, 25], [8, 30], [9, 35], [10, 40], [1, 45]]) == 1\n assert candidate(events = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10]]) == 1\n assert candidate(events = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [1, 15], [2, 20], [3, 25], [4, 30], [5, 35]]) == 1\n assert candidate(events = [[1, 2], [2, 5], [3, 9], [4, 14], [5, 20], [1, 26], [2, 32], [3, 38], [4, 44], [5, 50]]) == 1\n assert candidate(events = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10], [1, 11], [2, 12], [3, 13], [4, 14], [5, 15]]) == 1\n assert candidate(events = [[1, 1], [2, 3], [3, 6], [4, 10], [5, 15], [6, 21], [7, 28], [8, 36], [9, 45]]) == 9\n assert candidate(events = [[7, 10], [5, 15], [3, 20], [8, 25], [5, 30], [7, 35]]) == 7\n assert candidate(events = [[2, 1], [3, 4], [1, 8], [2, 15], [3, 20]]) == 2\n assert candidate(events = [[1, 1], [1, 100], [2, 101], [2, 200], [3, 201], [3, 300], [4, 301], [4, 400]]) == 1\n assert candidate(events = [[1, 10], [2, 20], [3, 30], [4, 40], [5, 50], [6, 60], [7, 70], [8, 80], [9, 90], [10, 100], [1, 110]]) == 1\n assert candidate(events = [[1, 100], [2, 110], [3, 130], [1, 150], [2, 170], [3, 200], [1, 220]]) == 1\n assert candidate(events = [[1, 100], [2, 200], [3, 300], [4, 400], [5, 500], [6, 600], [7, 700], [8, 800], [9, 900], [10, 1000]]) == 1\n assert candidate(events = [[7, 5], [3, 10], [7, 18], [5, 23], [3, 29], [7, 37], [5, 45], [3, 50]]) == 5\n assert candidate(events = [[1, 1], [2, 10], [3, 20], [4, 30], [5, 40], [6, 50], [7, 60], [8, 70], [9, 80], [10, 90]]) == 3\n assert candidate(events = [[1, 1], [2, 10], [3, 20], [4, 30], [5, 40], [1, 50], [2, 60], [3, 70], [4, 80], [5, 90], [1, 100], [2, 110], [3, 120], [4, 130], [5, 140]]) == 1\n assert candidate(events = [[1, 1], [2, 3], [3, 6], [4, 10], [5, 15], [6, 21], [7, 28], [8, 36], [9, 45], [10, 55]]) == 10\n assert candidate(events = [[100, 100], [200, 150], [100, 200], [300, 250], [200, 300], [100, 350]]) == 100\n assert candidate(events = [[1, 1], [2, 2], [3, 3], [1, 5], [2, 7], [3, 9], [1, 11], [2, 13], [3, 15]]) == 1\n assert candidate(events = [[1, 2], [2, 4], [3, 8], [4, 16], [5, 32], [6, 64], [7, 128], [8, 256], [9, 512], [10, 1024]]) == 10\n assert candidate(events = [[10, 10], [20, 20], [30, 30], [10, 40], [20, 50], [30, 60], [10, 70], [20, 80], [30, 90], [10, 100], [20, 110], [30, 120]]) == 10\n assert candidate(events = [[100, 100], [200, 200], [300, 300], [100, 400], [200, 500], [300, 600], [100, 700], [200, 800], [300, 900]]) == 100\n assert candidate(events = [[8, 5], [3, 10], [8, 15], [3, 20], [8, 25], [3, 30], [8, 35], [3, 40], [8, 45], [3, 50]]) == 3\n assert candidate(events = [[1, 1000], [2, 1010], [3, 1030], [4, 1060], [5, 1100], [6, 1150], [7, 1210], [8, 1280], [9, 1360], [10, 1450]]) == 1\n assert candidate(events = [[100, 100], [200, 200], [300, 300], [400, 400], [100, 500], [200, 600], [300, 700], [400, 800]]) == 100\n assert candidate(events = [[1, 10], [2, 25], [3, 35], [4, 50], [5, 70], [6, 90], [7, 110], [8, 130], [9, 150], [10, 170]]) == 5\n assert candidate(events = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10]]) == 1\n assert candidate(events = [[1, 1], [2, 3], [1, 6], [3, 10], [1, 15], [2, 20], [3, 25], [1, 30], [2, 35], [3, 40], [1, 45], [2, 50], [3, 55]]) == 1\n assert candidate(events = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10]]) == 1\n assert candidate(events = [[1, 10], [2, 20], [3, 30], [4, 40], [5, 50], [1, 60], [2, 70], [3, 80], [4, 90], [5, 100], [1, 110], [2, 120], [3, 130]]) == 1\n assert candidate(events = [[5, 2], [5, 4], [5, 6], [5, 8], [5, 10], [5, 12], [5, 14], [5, 16], [5, 18], [5, 20], [5, 22]]) == 5\n assert candidate(events = [[7, 10], [8, 15], [9, 20], [10, 30], [7, 40], [8, 50], [9, 60]]) == 7\n assert candidate(events = [[1, 1], [2, 3], [3, 6], [1, 10], [2, 15], [3, 21], [1, 30], [2, 35]]) == 1\n assert candidate(events = [[1, 1], [2, 10], [3, 20], [1, 30], [2, 40], [3, 50], [1, 60], [2, 70], [3, 80], [1, 90], [2, 100], [3, 110], [1, 120]]) == 1\n assert candidate(events = [[1, 10], [2, 20], [3, 30], [4, 40], [1, 50], [2, 60], [3, 70], [4, 80], [1, 90], [2, 100], [3, 110], [4, 120]]) == 1\n assert candidate(events = [[1, 1], [2, 3], [3, 6], [1, 10], [2, 15], [3, 21]]) == 3\n assert candidate(events = [[9, 1], [9, 2], [9, 3], [9, 4], [9, 5], [9, 6], [9, 7], [9, 8], [9, 9], [9, 10]]) == 9\n assert candidate(events = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10], [1, 20]]) == 1\n assert candidate(events = [[100, 100], [200, 200], [100, 300], [200, 400], [100, 500], [200, 600]]) == 100\n assert candidate(events = [[2, 3], [7, 8], [5, 12], [2, 18], [7, 22], [1, 30]]) == 1\n assert candidate(events = [[1, 1], [1, 2], [2, 3], [2, 4], [3, 5], [3, 6], [4, 7], [4, 8], [5, 9], [5, 10], [6, 11], [6, 12], [7, 13], [7, 14], [8, 15], [8, 16], [9, 17], [9, 18], [10, 19], [10, 20]]) == 1\n assert candidate(events = [[1, 1], [2, 3], [3, 6], [4, 10], [5, 15], [1, 20]]) == 1\n assert candidate(events = [[1, 1], [2, 10], [3, 20], [4, 30], [5, 40], [6, 50], [7, 60], [8, 70], [9, 80], [10, 90], [1, 100], [2, 110], [3, 120], [4, 130], [5, 140], [6, 150], [7, 160], [8, 170], [9, 180], [10, 190]]) == 1\n assert candidate(events = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10], [1, 20], [2, 30], [3, 40], [4, 50], [5, 60], [6, 70], [7, 80], [8, 90], [9, 100], [10, 110]]) == 1\n assert candidate(events = [[1, 1], [1, 2], [1, 4], [1, 8], [1, 16], [1, 32], [1, 64], [1, 128], [1, 256], [1, 512]]) == 1\n assert candidate(events = [[1, 1], [2, 3], [3, 7], [4, 15], [5, 25], [6, 40]]) == 6\n assert candidate(events = [[5, 5], [5, 15], [5, 25], [5, 35], [5, 45], [5, 55], [5, 65], [5, 75], [5, 85], [5, 95], [5, 105]]) == 5\n assert candidate(events = [[1, 100], [2, 150], [3, 200], [1, 250], [2, 300], [3, 350], [1, 400], [2, 450], [3, 500], [1, 550], [2, 600], [3, 650], [1, 700]]) == 1\n assert candidate(events = [[9, 10], [8, 20], [7, 30], [6, 40], [5, 50], [4, 60], [3, 70], [2, 80], [1, 90]]) == 1\n assert candidate(events = [[1, 2], [2, 4], [3, 6], [4, 8], [5, 10], [1, 12], [2, 14], [3, 16], [4, 18], [5, 20]]) == 1\n assert candidate(events = [[1, 1], [2, 1000], [3, 2000], [4, 3000], [5, 4000], [6, 5000], [7, 6000], [8, 7000], [9, 8000], [10, 9000]]) == 3\n assert candidate(events = [[5, 5], [4, 10], [3, 15], [2, 20], [1, 25], [5, 30], [4, 35], [3, 40], [2, 45], [1, 50]]) == 1\n assert candidate(events = [[7, 3], [1, 5], [2, 10], [7, 15], [3, 20], [1, 25], [2, 30], [7, 35], [1, 40]]) == 1\n assert candidate(events = [[10, 10], [9, 20], [8, 30], [7, 40], [6, 50], [5, 60], [4, 70], [3, 80], [2, 90], [1, 100], [1, 110]]) == 1\n assert candidate(events = [[10, 1], [20, 5], [30, 10], [40, 20], [50, 30], [60, 40], [70, 50], [80, 60], [90, 70], [100, 80], [110, 90], [120, 100]]) == 40\n assert candidate(events = [[5, 1], [5, 2], [5, 3], [5, 4], [5, 5], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10], [5, 11], [5, 12], [5, 13], [5, 14], [5, 15]]) == 5\n assert candidate(events = [[5, 10], [3, 15], [7, 20], [1, 25], [2, 30], [8, 35], [6, 40], [9, 45], [4, 50]]) == 5\n assert candidate(events = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [2, 11]]) == 1\n assert candidate(events = [[10, 10], [20, 20], [30, 30], [40, 40], [50, 50], [10, 60], [20, 70], [30, 80], [40, 90], [50, 100], [10, 110], [20, 120], [30, 130], [40, 140], [50, 150]]) == 10\n assert candidate(events = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10]]) == 1\n assert candidate(events = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9], [10, 10], [1, 11], [2, 12], [3, 13], [4, 14], [5, 15], [6, 16], [7, 17], [8, 18], [9, 19], [10, 20]]) == 1\n assert candidate(events = [[5, 1], [5, 2], [5, 3], [5, 4], [5, 5], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10], [1, 11]]) == 1\n assert candidate(events = [[5, 1], [10, 2], [15, 4], [20, 8], [25, 16], [30, 32], [35, 64], [40, 128], [45, 256], [50, 512]]) == 50\n assert candidate(events = [[5, 1], [10, 5], [15, 10], [20, 20], [25, 30], [30, 40], [35, 55], [40, 70], [45, 85], [50, 100]]) == 35\n assert candidate(events = [[5, 5], [15, 15], [25, 25], [35, 35], [45, 45], [55, 55], [65, 65], [75, 75], [85, 85], [95, 95]]) == 15\n assert candidate(events = [[1, 1], [2, 4], [3, 9], [4, 16], [5, 25], [6, 36], [7, 49], [8, 64], [9, 81], [10, 100], [11, 121], [12, 144]]) == 12\n assert candidate(events = [[100, 10], [200, 20], [100, 30], [300, 40], [100, 50], [200, 60], [300, 70], [400, 80]]) == 100\n assert candidate(events = [[9, 9], [8, 18], [7, 27], [6, 36], [5, 45], [4, 54], [3, 63], [2, 72], [1, 81], [1, 90]]) == 1\n assert candidate(events = [[1, 10], [2, 15], [3, 20], [1, 25], [2, 30], [3, 35], [1, 40], [2, 45]]) == 1\n assert candidate(events = [[10, 10], [20, 15], [30, 25], [40, 40], [50, 65], [60, 100], [70, 150], [80, 225], [90, 325], [100, 450]]) == 100\n assert candidate(events = [[1, 10], [2, 20], [3, 30], [4, 40], [5, 50], [1, 60], [2, 70], [3, 80], [4, 90], [5, 100]]) == 1\n assert candidate(events = [[5, 2], [5, 4], [5, 8], [5, 16], [5, 32], [5, 64], [5, 128]]) == 5\n assert candidate(events = [[2, 3], [4, 8], [1, 15], [4, 20], [3, 26], [2, 35]]) == 2\n assert candidate(events = [[5, 10], [3, 15], [5, 20], [1, 25], [3, 30], [5, 35], [1, 40], [3, 45], [5, 50], [1, 55], [3, 60], [5, 65], [1, 70], [3, 75]]) == 5\n assert candidate(events = [[10, 10], [20, 20], [30, 30], [40, 40], [50, 50], [60, 60], [70, 70], [80, 80], [90, 90], [100, 100], [10, 110]]) == 10\n assert candidate(events = [[1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [2, 11], [2, 20], [2, 30], [2, 40], [2, 50]]) == 2\n assert candidate(events = [[2, 3], [4, 8], [1, 15], [2, 22], [4, 30], [3, 35]]) == 4\n assert candidate(events = [[1, 1], [2, 3], [1, 6], [2, 10], [3, 15], [1, 20]]) == 1\n assert candidate(events = [[1, 2], [1, 5], [1, 10], [1, 15], [1, 20], [1, 25], [1, 30], [1, 35], [1, 40], [1, 45], [1, 50]]) == 1\n assert candidate(events = [[5, 5], [5, 10], [1, 15], [1, 20], [2, 25], [2, 30], [3, 35], [3, 40], [4, 45], [4, 50]]) == 1\n assert candidate(events = [[1, 100], [2, 200], [3, 300], [4, 400], [5, 500], [6, 600], [7, 700], [8, 800], [9, 900], [10, 1000], [11, 1100], [12, 1200], [13, 1300], [14, 1400]]) == 1\n assert candidate(events = [[7, 5], [8, 10], [9, 15], [7, 20], [8, 25], [9, 30], [7, 35]]) == 7\n assert candidate(events = [[10, 1], [20, 3], [30, 6], [40, 10], [50, 15], [60, 21], [70, 28], [80, 36], [90, 45]]) == 90\n assert candidate(events = [[5, 1], [5, 2], [5, 4], [5, 8], [5, 16], [5, 32], [5, 64], [5, 128], [5, 256], [5, 512], [5, 1024]]) == 5\n", "comparison": "exact"}, "public_tests": ["[[1,2],[2,5],[3,9],[1,15]]", "[[10,5],[1,7]]"], "hints": [], "metadata": {"canonical_parameter_names": ["events"], "leetcode_dataset_entry_point": "Solution().buttonWithLongestTime", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:23:27+00:00", "tests_total": 104, "tests_dropped": 1, "flags": [], "topic_tags": ["array"]}, "language": "python", "interface": {"raw_signature": "def buttonWithLongestTime(self, events: List[List[int]]) -> int:", "container": "Solution", "callable": "buttonWithLongestTime", "parameters": [{"name": "events", "type": "List[List[int]]"}], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3388, "task_id": "count-beautiful-splits-in-an-array", "difficulty": "Medium", "problem_description": "You are given an array nums.\n\nA split of an array nums is beautiful if:\n\n1. The array nums is split into three subarrays: nums1, nums2, and nums3, such that nums can be formed by concatenating nums1, nums2, and nums3 in that order.\n2. The subarray nums1 is a prefix of nums2 OR nums2 is a prefix of nums3.\n\nReturn the number of ways you can make this split.\n\nExample 1:\n\nInput: nums = [1,1,2,1]\nOutput: 2\nExplanation:\nThe beautiful splits are:\n1. A split with nums1 = [1], nums2 = [1,2], nums3 = [1].\n2. A split with nums1 = [1], nums2 = [1], nums3 = [2,1].\n\nExample 2:\n\nInput: nums = [1,2,3,4]\nOutput: 0\nExplanation:\nThere are 0 beautiful splits.\n\nConstraints:\n\n- 1 <= nums.length <= 5000\n- 0 <= nums[i] <= 50\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 1, 2, 3]) == 0\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) == 0\n assert candidate(nums = [1, 1, 1, 1]) == 3\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0]) == 19\n assert candidate(nums = [50, 50, 50, 50, 50]) == 6\n assert candidate(nums = [1, 2, 2, 1]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 0\n assert candidate(nums = [1, 3, 2, 3, 1]) == 0\n assert candidate(nums = [1, 2, 2, 2, 2, 1]) == 4\n assert candidate(nums = [1, 2, 3, 4]) == 0\n assert candidate(nums = [10, 20, 30, 20, 10, 20]) == 0\n assert candidate(nums = [5, 5, 5, 0, 0, 5, 5]) == 7\n assert candidate(nums = [10, 20, 30, 40, 50]) == 0\n assert candidate(nums = [5, 5, 5, 5, 5]) == 6\n assert candidate(nums = [0, 0, 0, 0, 0]) == 6\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 1, 1, 1]) == 16\n assert candidate(nums = [1, 1, 2, 2, 1, 1]) == 6\n assert candidate(nums = [1, 1, 1, 1, 1]) == 6\n assert candidate(nums = [1, 2, 3, 4, 5, 6]) == 0\n assert candidate(nums = [1, 2, 1, 2, 1, 2]) == 3\n assert candidate(nums = [50, 50, 50, 50, 50, 50]) == 9\n assert candidate(nums = [0, 0, 0, 0, 0, 0]) == 9\n assert candidate(nums = [1, 1, 1, 2, 1, 1, 1]) == 7\n assert candidate(nums = [5, 5, 5, 5, 5, 5]) == 9\n assert candidate(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1]) == 2\n assert candidate(nums = [1, 1, 2, 1]) == 2\n assert candidate(nums = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50]) == 32\n assert candidate(nums = [1, 2, 3, 2, 1]) == 0\n assert candidate(nums = [1, 2, 1, 3, 2, 1]) == 0\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 32\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3]) == 11\n assert candidate(nums = [1, 2, 1, 2, 1]) == 2\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 370\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 1\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1]) == 51\n assert candidate(nums = [3, 3, 3, 2, 2, 2, 1, 1, 1, 2, 2, 2, 3, 3, 3]) == 21\n assert candidate(nums = [3, 3, 3, 3, 1, 3, 3, 3, 1, 3, 3, 3]) == 25\n assert candidate(nums = [4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4]) == 147\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 0\n assert candidate(nums = [1, 2, 3, 2, 1, 3, 1, 2, 3, 1, 2, 3, 2, 1]) == 2\n assert candidate(nums = [1, 2, 2, 1, 2, 2, 1, 2, 2, 1, 2, 2, 1, 2, 2, 1, 2, 2, 1, 2, 2, 1, 2, 2, 1]) == 83\n assert candidate(nums = [9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9]) == 322\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4]) == 90\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 0\n assert candidate(nums = [1, 2, 3, 2, 1, 1, 2, 3, 2, 1, 1, 2, 3, 2, 1, 1, 2, 3, 2, 1]) == 22\n assert candidate(nums = [1, 2, 1, 1, 2, 1, 2, 1, 1, 2]) == 8\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5]) == 13\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2]) == 7\n assert candidate(nums = [1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1]) == 27\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 1, 1, 1, 2, 2, 2]) == 31\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 232\n assert candidate(nums = [1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1]) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1]) == 3\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 5007\n assert candidate(nums = [10, 10, 9, 9, 8, 8, 7, 7, 6, 6, 5, 5, 4, 4, 3, 3, 2, 2, 1, 1]) == 27\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 4, 3, 2, 1, 1, 2]) == 6\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2]) == 54\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50]) == 0\n assert candidate(nums = [10, 20, 10, 20, 10, 20, 10]) == 5\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == 12\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 4, 3, 2, 1]) == 19\n assert candidate(nums = [1, 1, 2, 1, 1, 2, 1, 1, 2, 1, 1, 2, 1, 1, 2, 1, 1, 2, 1, 1]) == 66\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 8027\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]) == 0\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 57\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 2\n assert candidate(nums = [5, 4, 3, 2, 1, 2, 3, 4, 5]) == 0\n assert candidate(nums = [5, 4, 3, 2, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5]) == 2\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 27\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2]) == 103\n assert candidate(nums = [4, 4, 5, 5, 4, 4, 6, 6, 5, 5, 4, 4, 7, 7, 6, 6, 5, 5, 4, 4, 8, 8, 7, 7, 6, 6, 5, 5, 4, 4]) == 42\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 5564\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3]) == 5\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 14\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 72\n assert candidate(nums = [3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1]) == 38\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 147\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2]) == 2382\n assert candidate(nums = [1, 1, 2, 2, 1, 1, 2, 2, 1, 1]) == 15\n assert candidate(nums = [50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 19\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 256\n assert candidate(nums = [1, 1, 2, 2, 2, 2, 1, 1, 2, 2, 2, 2, 1, 1]) == 25\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]) == 0\n assert candidate(nums = [5, 4, 3, 2, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == 1\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3]) == 38\n assert candidate(nums = [5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5]) == 24\n assert candidate(nums = [1, 2, 1, 1, 2, 1]) == 1\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 1, 1, 1, 4, 4, 4]) == 21\n assert candidate(nums = [1, 2, 1, 3, 1, 2, 1, 3, 1, 2, 1, 3, 1, 2, 1, 3, 1, 2, 1, 3, 1, 2, 1, 3, 1, 2, 1, 3, 1, 2, 1, 3]) == 91\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 370\n assert candidate(nums = [1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2, 1]) == 39\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 4, 4, 3, 3, 2, 2, 1, 1, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == 41\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10]) == 46\n assert candidate(nums = [10, 20, 10, 20, 10, 20, 10, 20, 10, 20]) == 14\n assert candidate(nums = [1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2]) == 35\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9]) == 24\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 2269\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 182\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 1]) == 1\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5]) == 0\n", "comparison": "exact"}, "public_tests": ["[1,1,2,1]", "[1,2,3,4]"], "hints": ["Use 2D dynamic programming to find the maximum matching prefix."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().beautifulSplits", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:23:31+00:00", "tests_total": 107, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "dynamic-programming"]}, "language": "python", "interface": {"raw_signature": "def beautifulSplits(self, nums: List[int]) -> int:", "container": "Solution", "callable": "beautifulSplits", "parameters": [{"name": "nums", "type": "List[int]"}], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3389, "task_id": "minimum-operations-to-make-character-frequencies-equal", "difficulty": "Hard", "problem_description": "You are given a string s.\n\nA string t is called good if all characters of t occur the same number of times.\n\nYou can perform the following operations any number of times:\n\n- Delete a character from s.\n- Insert a character in s.\n- Change a character in s to its next letter in the alphabet.\n\nNote that you cannot change 'z' to 'a' using the third operation.\n\nReturn the minimum number of operations required to make s good.\n\nExample 1:\n\nInput: s = \"acab\"\nOutput: 1\nExplanation:\nWe can make s good by deleting one occurrence of character 'a'.\n\nExample 2:\n\nInput: s = \"wddw\"\nOutput: 0\nExplanation:\nWe do not need to perform any operations since s is initially good.\n\nExample 3:\n\nInput: s = \"aaabc\"\nOutput: 2\nExplanation:\nWe can make s good by applying these operations:\n- Change one occurrence of 'a' to 'b'\n- Insert one occurrence of 'c' into s\n\nConstraints:\n\n- 3 <= s.length <= 2 * 10^4\n- s contains only lowercase English letters.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"acab\") == 1\n assert candidate(s = \"aaabc\") == 2\n assert candidate(s = \"aabbbccc\") == 1\n assert candidate(s = \"zzzz\") == 0\n assert candidate(s = \"aabbcc\") == 0\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\") == 0\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == 0\n assert candidate(s = \"abc\") == 0\n assert candidate(s = \"zyxwvutsrqponmlkjihgfedcba\") == 0\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzaabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzaabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == 0\n assert candidate(s = \"aabbbcc\") == 1\n assert candidate(s = \"abcde\") == 0\n assert candidate(s = \"aabbbcccc\") == 2\n assert candidate(s = \"zzz\") == 0\n assert candidate(s = \"wddw\") == 0\n assert candidate(s = \"aabbbcccddddeeeee\") == 4\n assert candidate(s = \"aabbbcccdddd\") == 2\n assert candidate(s = \"zyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyx\") == 0\n assert candidate(s = \"abacabadabacabadabacabad\") == 9\n assert candidate(s = \"zyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 28\n assert candidate(s = \"ababababababababababab\") == 0\n assert candidate(s = \"aabbaa\") == 1\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 0\n assert candidate(s = \"aabbbcccddddeeeeefffffgggg\") == 5\n assert candidate(s = \"abcdabcde\") == 1\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\") == 0\n assert candidate(s = \"aabbbccccddddeeeeeffffffffgggggggg\") == 10\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\") == 0\n assert candidate(s = \"aabbaaabbbaaaabbbbaaaa\") == 2\n assert candidate(s = \"aaaaabbbbbcccc\") == 1\n assert candidate(s = \"aabbaabbaabbaabb\") == 0\n assert candidate(s = \"mnopqrstuvwxyzmnopqrstuvwxyzmnopqrstuvwxyzmnopqrstuvwxyz\") == 0\n assert candidate(s = \"aaaabbbbccccddddaabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\") == 16\n assert candidate(s = \"aabccccdddddeeeeeeeeeee\") == 9\n assert candidate(s = \"abcdabcdabcdabcd\") == 0\n assert candidate(s = \"qqqwwweeeerrrrttttyyyyuuuuiiiiooooppppllllnnnnmmmmbbbb\") == 2\n assert candidate(s = \"aabbccdd\") == 0\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 0\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 26\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzz\") == 0\n", "comparison": "exact"}, "public_tests": ["\"acab\"", "\"wddw\"", "\"aaabbc\""], "hints": ["The order of the letters in the string is irrelevant.", "Compute an occurrence array occ where occ[x] is the number of occurrences of the x character of the alphabet. How do the described operations change occ?", "We have three types of operations: increase any occ[x] by 1, decrease any occ[x] by 1, or decrease any occ[x] by 1 and simultaneously increase occ[x + 1] by 1 at the same time. To make s good, we need to make occ good. occ is good if and only if every occ[x] equals either 0 or some constant c.", "If you know the value of c, how can you calculate the minimum operations required to make occ good?", "Observation 1: It is never optimal to apply the third type of operation (simultaneous decrease and increase) on two continuous elements occ[x] and occ[x + 1]. Instead, we can decrease occ[x] by 1 then increase occ[x + 2] by 1 to achieve the same effect.", "Observation 2: It is never optimal to increase an element of occ then decrease it, or vice versa.", "Use dynamic programming where dp[i] is the minimum number of operations required to make occ[0..i] good. You will need to use the above observations to come up with the transitions."], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().makeStringGood", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:23:34+00:00", "tests_total": 40, "tests_dropped": 0, "flags": [], "topic_tags": ["hash-table", "string", "dynamic-programming", "counting", "enumeration"]}, "language": "python", "interface": {"raw_signature": "def makeStringGood(self, s: str) -> int:", "container": "Solution", "callable": "makeStringGood", "parameters": [{"name": "s", "type": "str"}], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} -{"question_id": 3392, "task_id": "count-subarrays-of-length-three-with-a-condition", "difficulty": "Easy", "problem_description": "Given an integer array nums, return the number of subarrays of length 3 such that the sum of the first and third numbers equals exactly half of the second number.\n\nExample 1:\n\nInput: nums = [1,2,1,4,1]\nOutput: 1\nExplanation:\nOnly the subarray [1,4,1] contains exactly 3 elements where the sum of the first and third numbers equals half the middle number.\n\nExample 2:\n\nInput: nums = [1,1,1]\nOutput: 0\nExplanation:\n[1,1,1] is the only subarray of length 3. However, its first and third numbers do not add to half the middle number.\n\nConstraints:\n\n- 3 <= nums.length <= 100\n- -100 <= nums[i] <= 100\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 10, 5, 15, 5]) == 0\n assert candidate(nums = [1, 1, 1]) == 0\n assert candidate(nums = [1, -1, 1, -1, 1]) == 0\n assert candidate(nums = [100, -50, -50, 100, 100, -100, -100, 100]) == 1\n assert candidate(nums = [33, 66, 33, 99, 33]) == 0\n assert candidate(nums = [100, -50, 50]) == 0\n assert candidate(nums = [3, 6, 3, 1, 2, 3, 6, 3]) == 0\n assert candidate(nums = [1, 2, 1, 4, 1]) == 1\n assert candidate(nums = [-2, 4, -2, 8, -2]) == 0\n assert candidate(nums = [-1, 2, -1, 4, -1]) == 0\n assert candidate(nums = [100, -50, 50, 0, 100]) == 0\n assert candidate(nums = [2, 4, 2, 4, 2]) == 0\n assert candidate(nums = [3, 6, 3, 12, 3]) == 1\n assert candidate(nums = [0, 0, 0, 0, 0]) == 3\n assert candidate(nums = [1, 3, 2, 6, 4, 8]) == 0\n assert candidate(nums = [0, 0, 0]) == 1\n assert candidate(nums = [100, -50, 50, -50, 100]) == 0\n assert candidate(nums = [100, -50, -50, 50, 100]) == 0\n assert candidate(nums = [2, 4, 2]) == 0\n assert candidate(nums = [2, 4, 2, 8, 2]) == 1\n assert candidate(nums = [3, 6, 3, 6, 3]) == 0\n assert candidate(nums = [10, 20, 10, 40, 10]) == 1\n assert candidate(nums = [5, 10, 5, 20, 5]) == 1\n assert candidate(nums = [-1, 0, 1, -1, 0, 1]) == 2\n assert candidate(nums = [1, 2, 3, 6, 3, 6, 9, 18, 9]) == 0\n assert candidate(nums = [1, 2, 4, 8, 16, 32]) == 0\n assert candidate(nums = [1, 2, 3, 6, 3, 12, 6, 24, 12]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 0\n assert candidate(nums = [-10, -20, -10, -30, -10, -40, -10]) == 1\n assert candidate(nums = [7, 14, 7, 21, 7, 14, 7, 21, 7]) == 0\n assert candidate(nums = [7, 14, 7, 21, 10.5, 21, 14, 28, 14]) == 0\n assert candidate(nums = [0, -1, -1, -2, -3, -5, -8, -13, -21, -34]) == 0\n assert candidate(nums = [-1, 0, 1, 0, -1, 0, 1]) == 3\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0]) == 7\n assert candidate(nums = [1, 1, 2, 3, 3, 6, 5, 10, 5]) == 0\n assert candidate(nums = [8, 16, 8, 24, 16, 8, 32, 16, 8, 40, 20, 8, 48, 24, 8]) == 0\n assert candidate(nums = [7, 14, 7, 21, 14, 7, 28, 14, 7]) == 0\n assert candidate(nums = [-1, -2, -3, -5, -8, -13, -21, -34, -55, -89]) == 0\n assert candidate(nums = [5, 10, 5, 15, 10, 20, 15, 25, 20, 30, 25, 35, 30, 40, 35, 45, 40]) == 0\n assert candidate(nums = [10, 5, 0, 5, 10, 15, 10, 5, 0]) == 0\n assert candidate(nums = [1, 2, 3, 6, 3, 6, 3, 12, 6, 12, 6, 24, 12]) == 0\n assert candidate(nums = [10, -10, 0, 20, -20, 0, 30, -30, 0, 40, -40, 0]) == 0\n assert candidate(nums = [10, 9, 11, 8, 12, 7, 13, 6, 14, 5, 15, 4, 16, 3, 17, 2, 18, 1, 19, 0]) == 0\n assert candidate(nums = [10, 20, 15, 20, 10, 20, 15]) == 0\n assert candidate(nums = [-2, -4, -2, -6, -3, -6, -9, -18, -9]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 0\n assert candidate(nums = [4, 8, 4, 12, 8, 4, 16, 8, 4, 20, 10, 5]) == 0\n assert candidate(nums = [10, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50]) == 0\n assert candidate(nums = [10, 20, 10, 30, 15, 30, 25, 50, 25]) == 0\n assert candidate(nums = [1, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18, 21, 20]) == 0\n assert candidate(nums = [10, 20, 10, 30, 15, 30, 20, 40, 20]) == 0\n assert candidate(nums = [-10, -20, -10, -30, -20, -40, -30, -60, -40, -80]) == 0\n assert candidate(nums = [1, 2, 2, 1, 4, 2, 4, 8, 4, 8, 16]) == 0\n assert candidate(nums = [7, 14, 7, 21, 14, 7, 28, 14, 7, 35, 21, 7]) == 0\n assert candidate(nums = [10, 5, 5, 10, 5, 10, 5, 10, 5, 10, 5]) == 0\n assert candidate(nums = [-1, 2, -1, 3, -1, 4, -1, 5, -1, 6]) == 0\n assert candidate(nums = [10, 20, 10, 30, 20, 40, 30, 60, 40, 80]) == 0\n assert candidate(nums = [1, 2, 3, 6, 5, 10, 7, 14]) == 0\n assert candidate(nums = [-1, -2, -1, -2, -1]) == 0\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0]) == 7\n assert candidate(nums = [1, 3, 2, 6, 3, 1, 4, 8, 4, 12, 4]) == 0\n assert candidate(nums = [100, 50, 25, 50, 100, 25, 50, 100, 50, 25, 50, 100]) == 0\n assert candidate(nums = [-5, -10, -5, -15, -10, -20, -15, -25]) == 0\n assert candidate(nums = [10, 20, 10, 20, 10, 20, 10, 20, 10, 20]) == 0\n assert candidate(nums = [1, 1, 2, 1, 1, 2, 1, 1, 2, 1, 1, 2, 1, 1, 2, 1, 1, 2, 1, 1, 2]) == 0\n assert candidate(nums = [10, 20, 10, 15, 30, 15, 25, 50, 25]) == 0\n assert candidate(nums = [10, 20, 10, 40, 10, 20, 10]) == 1\n assert candidate(nums = [-5, -10, -5, -15, -10, -5, -20, -10, -5, -25, -12, -5]) == 0\n assert candidate(nums = [10, 20, 5, 20, 10, 30, 15, 30, 10]) == 0\n assert candidate(nums = [0, 0, 0, 0, 0]) == 3\n assert candidate(nums = [-100, 0, 100, 50, -50, 50, -50]) == 2\n assert candidate(nums = [1, 4, 3, 8, 5, 12, 7, 16, 9, 20, 11]) == 0\n assert candidate(nums = [4, 8, 4, 12, 6, 12, 8, 16, 8]) == 0\n assert candidate(nums = [1, 2, 3, 6, 3, 6, 3, 1]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 0\n assert candidate(nums = [1, 2, 3, 5, 8, 13, 21, 34, 55, 89]) == 0\n assert candidate(nums = [1, 2, 1, 3, 6, 3, 4, 8, 4, 5, 10, 5]) == 0\n assert candidate(nums = [10, 20, 10, 30, 10, 40, 10, 50, 10, 60, 10]) == 1\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 10\n assert candidate(nums = [9, 18, 9, 27, 18, 36, 27, 54, 27]) == 0\n assert candidate(nums = [5, 10, 5, 15, 10, 20, 15, 25]) == 0\n assert candidate(nums = [100, 50, 50, 100, 50, 50, 100, 50, 50, 100, 50, 50]) == 0\n assert candidate(nums = [5, 10, 5, 15, 10, 20, 15, 30, 15]) == 0\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0]) == 5\n assert candidate(nums = [1, -1, 0, 1, -1, 0, 1, -1, 0]) == 2\n assert candidate(nums = [15, 30, 15, 60, 15, 30, 15, 60, 15]) == 2\n assert candidate(nums = [-1, -2, -3, -6, -3, -6, -3, -1]) == 0\n assert candidate(nums = [-5, 10, -5, 20, -5, 40, -5, 80, -5]) == 0\n assert candidate(nums = [3, 6, 3, 9, 3, 12, 3, 15, 3, 18, 3]) == 1\n assert candidate(nums = [-100, 0, 100, 0, -100, 0, 100, 0, -100]) == 4\n assert candidate(nums = [1, 1, 2, 2, 4, 4, 8, 8, 16, 16]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 0\n assert candidate(nums = [1, 3, 2, 6, 4, 12, 5, 10, 7, 14]) == 0\n assert candidate(nums = [-10, -20, -10, -30, -10, -40, -10, -50, -10, -60]) == 1\n assert candidate(nums = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]) == 0\n assert candidate(nums = [-2, 4, -2, 8, -2, 4, -2]) == 0\n assert candidate(nums = [3, 6, 3, 9, 3, 12, 3, 15, 3, 18, 3, 21, 3]) == 1\n assert candidate(nums = [25, 50, 25, 100, 25, 50, 25, 100, 25]) == 2\n assert candidate(nums = [1, 3, 2, 6, 4, 12, 8, 24, 16, 48, 32, 96, 64]) == 0\n assert candidate(nums = [5, 10, 5, 15, 10, 5, 20, 10, 5]) == 0\n assert candidate(nums = [100, 50, 0, 50, -100, 0, 100, 50, -50, 25]) == 2\n assert candidate(nums = [10, 5, 5, 10, 5, 10, 5, 10, 5, 10]) == 0\n assert candidate(nums = [1, 3, 2, 6, 3, 6, 3, 9, 3, 12, 6, 6, 6, 12, 6]) == 0\n assert candidate(nums = [1, 3, 2, 5, 10, 5, 15, 10, 20, 15, 30, 20, 40, 35]) == 0\n assert candidate(nums = [1, 3, 2, 5, 4, 7, 6, 9, 8, 11]) == 0\n assert candidate(nums = [-20, 40, -20, 60, -20, 80]) == 0\n assert candidate(nums = [-1, 2, -1, -2, 2, -2, 1]) == 0\n assert candidate(nums = [0, 0, 0, 0, 0, 0]) == 4\n assert candidate(nums = [1, 2, 1, 2, 4, 2, 3, 6, 3, 4, 8, 4, 5, 10, 5]) == 0\n assert candidate(nums = [10, 20, 10, 40, 20, 50, 10]) == 0\n assert candidate(nums = [-10, -20, -10, -15, -30, -15, -25, -50, -25]) == 0\n assert candidate(nums = [5, 10, 5, 15, 10, 5, 20, 10]) == 0\n assert candidate(nums = [-10, -20, -10, -30, -10, -40, -10, -50, -10, -60, -10]) == 1\n assert candidate(nums = [7, 14, 7, 14, 7, 14, 7, 14, 7]) == 0\n assert candidate(nums = [10, 5, 0, 10, 5, 0, 10, 5, 0, 10, 5, 0]) == 3\n assert candidate(nums = [-50, 0, 50, 25, 25, -25, 25, 0, -50]) == 2\n assert candidate(nums = [-20, 0, 20, -10, 10, -30, 15, 15]) == 1\n assert candidate(nums = [7, 14, 7, 21, 14, 28, 21, 42, 21]) == 0\n assert candidate(nums = [-1, -2, -4, -8, -16, -32]) == 0\n assert candidate(nums = [1, 2, 3, 6, 3, 2, 1]) == 0\n", "comparison": "exact"}, "public_tests": ["[1,2,1,4,1]", "[1,1,1]"], "hints": ["The constraints are small. Consider checking every subarray."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().countSubarrays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:23:36+00:00", "tests_total": 134, "tests_dropped": 14, "flags": [], "topic_tags": ["array"]}, "language": "python", "interface": {"raw_signature": "def countSubarrays(self, nums: List[int]) -> int:", "container": "Solution", "callable": "countSubarrays", "parameters": [{"name": "nums", "type": "List[int]"}], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} +{"question_id": 3392, "task_id": "count-subarrays-of-length-three-with-a-condition", "difficulty": "Easy", "problem_description": "Given an integer array nums, return the number of subarrays of length 3 such that the sum of the first and third numbers equals exactly half of the second number.\n\nExample 1:\n\nInput: nums = [1,2,1,4,1]\nOutput: 1\nExplanation:\nOnly the subarray [1,4,1] contains exactly 3 elements where the sum of the first and third numbers equals half the middle number.\n\nExample 2:\n\nInput: nums = [1,1,1]\nOutput: 0\nExplanation:\n[1,1,1] is the only subarray of length 3. However, its first and third numbers do not add to half the middle number.\n\nConstraints:\n\n- 3 <= nums.length <= 100\n- -100 <= nums[i] <= 100\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [5, 10, 5, 15, 5]) == 0\n assert candidate(nums = [1, 1, 1]) == 0\n assert candidate(nums = [1, -1, 1, -1, 1]) == 0\n assert candidate(nums = [100, -50, -50, 100, 100, -100, -100, 100]) == 1\n assert candidate(nums = [33, 66, 33, 99, 33]) == 0\n assert candidate(nums = [100, -50, 50]) == 0\n assert candidate(nums = [3, 6, 3, 1, 2, 3, 6, 3]) == 0\n assert candidate(nums = [1, 2, 1, 4, 1]) == 1\n assert candidate(nums = [-2, 4, -2, 8, -2]) == 0\n assert candidate(nums = [-1, 2, -1, 4, -1]) == 0\n assert candidate(nums = [100, -50, 50, 0, 100]) == 0\n assert candidate(nums = [2, 4, 2, 4, 2]) == 0\n assert candidate(nums = [3, 6, 3, 12, 3]) == 1\n assert candidate(nums = [0, 0, 0, 0, 0]) == 3\n assert candidate(nums = [1, 3, 2, 6, 4, 8]) == 0\n assert candidate(nums = [0, 0, 0]) == 1\n assert candidate(nums = [100, -50, 50, -50, 100]) == 0\n assert candidate(nums = [100, -50, -50, 50, 100]) == 0\n assert candidate(nums = [2, 4, 2]) == 0\n assert candidate(nums = [2, 4, 2, 8, 2]) == 1\n assert candidate(nums = [3, 6, 3, 6, 3]) == 0\n assert candidate(nums = [10, 20, 10, 40, 10]) == 1\n assert candidate(nums = [5, 10, 5, 20, 5]) == 1\n assert candidate(nums = [-1, 0, 1, -1, 0, 1]) == 2\n assert candidate(nums = [1, 2, 3, 6, 3, 6, 9, 18, 9]) == 0\n assert candidate(nums = [1, 2, 4, 8, 16, 32]) == 0\n assert candidate(nums = [1, 2, 3, 6, 3, 12, 6, 24, 12]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 0\n assert candidate(nums = [-10, -20, -10, -30, -10, -40, -10]) == 1\n assert candidate(nums = [7, 14, 7, 21, 7, 14, 7, 21, 7]) == 0\n assert candidate(nums = [0, -1, -1, -2, -3, -5, -8, -13, -21, -34]) == 0\n assert candidate(nums = [-1, 0, 1, 0, -1, 0, 1]) == 3\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0]) == 7\n assert candidate(nums = [1, 1, 2, 3, 3, 6, 5, 10, 5]) == 0\n assert candidate(nums = [8, 16, 8, 24, 16, 8, 32, 16, 8, 40, 20, 8, 48, 24, 8]) == 0\n assert candidate(nums = [7, 14, 7, 21, 14, 7, 28, 14, 7]) == 0\n assert candidate(nums = [-1, -2, -3, -5, -8, -13, -21, -34, -55, -89]) == 0\n assert candidate(nums = [5, 10, 5, 15, 10, 20, 15, 25, 20, 30, 25, 35, 30, 40, 35, 45, 40]) == 0\n assert candidate(nums = [10, 5, 0, 5, 10, 15, 10, 5, 0]) == 0\n assert candidate(nums = [1, 2, 3, 6, 3, 6, 3, 12, 6, 12, 6, 24, 12]) == 0\n assert candidate(nums = [10, -10, 0, 20, -20, 0, 30, -30, 0, 40, -40, 0]) == 0\n assert candidate(nums = [10, 9, 11, 8, 12, 7, 13, 6, 14, 5, 15, 4, 16, 3, 17, 2, 18, 1, 19, 0]) == 0\n assert candidate(nums = [10, 20, 15, 20, 10, 20, 15]) == 0\n assert candidate(nums = [-2, -4, -2, -6, -3, -6, -9, -18, -9]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 0\n assert candidate(nums = [4, 8, 4, 12, 8, 4, 16, 8, 4, 20, 10, 5]) == 0\n assert candidate(nums = [10, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50]) == 0\n assert candidate(nums = [10, 20, 10, 30, 15, 30, 25, 50, 25]) == 0\n assert candidate(nums = [1, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18, 21, 20]) == 0\n assert candidate(nums = [10, 20, 10, 30, 15, 30, 20, 40, 20]) == 0\n assert candidate(nums = [-10, -20, -10, -30, -20, -40, -30, -60, -40, -80]) == 0\n assert candidate(nums = [1, 2, 2, 1, 4, 2, 4, 8, 4, 8, 16]) == 0\n assert candidate(nums = [7, 14, 7, 21, 14, 7, 28, 14, 7, 35, 21, 7]) == 0\n assert candidate(nums = [10, 5, 5, 10, 5, 10, 5, 10, 5, 10, 5]) == 0\n assert candidate(nums = [-1, 2, -1, 3, -1, 4, -1, 5, -1, 6]) == 0\n assert candidate(nums = [10, 20, 10, 30, 20, 40, 30, 60, 40, 80]) == 0\n assert candidate(nums = [1, 2, 3, 6, 5, 10, 7, 14]) == 0\n assert candidate(nums = [-1, -2, -1, -2, -1]) == 0\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0]) == 7\n assert candidate(nums = [1, 3, 2, 6, 3, 1, 4, 8, 4, 12, 4]) == 0\n assert candidate(nums = [100, 50, 25, 50, 100, 25, 50, 100, 50, 25, 50, 100]) == 0\n assert candidate(nums = [-5, -10, -5, -15, -10, -20, -15, -25]) == 0\n assert candidate(nums = [10, 20, 10, 20, 10, 20, 10, 20, 10, 20]) == 0\n assert candidate(nums = [1, 1, 2, 1, 1, 2, 1, 1, 2, 1, 1, 2, 1, 1, 2, 1, 1, 2, 1, 1, 2]) == 0\n assert candidate(nums = [10, 20, 10, 15, 30, 15, 25, 50, 25]) == 0\n assert candidate(nums = [10, 20, 10, 40, 10, 20, 10]) == 1\n assert candidate(nums = [-5, -10, -5, -15, -10, -5, -20, -10, -5, -25, -12, -5]) == 0\n assert candidate(nums = [10, 20, 5, 20, 10, 30, 15, 30, 10]) == 0\n assert candidate(nums = [0, 0, 0, 0, 0]) == 3\n assert candidate(nums = [-100, 0, 100, 50, -50, 50, -50]) == 2\n assert candidate(nums = [1, 4, 3, 8, 5, 12, 7, 16, 9, 20, 11]) == 0\n assert candidate(nums = [4, 8, 4, 12, 6, 12, 8, 16, 8]) == 0\n assert candidate(nums = [1, 2, 3, 6, 3, 6, 3, 1]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 0\n assert candidate(nums = [1, 2, 3, 5, 8, 13, 21, 34, 55, 89]) == 0\n assert candidate(nums = [1, 2, 1, 3, 6, 3, 4, 8, 4, 5, 10, 5]) == 0\n assert candidate(nums = [10, 20, 10, 30, 10, 40, 10, 50, 10, 60, 10]) == 1\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 10\n assert candidate(nums = [9, 18, 9, 27, 18, 36, 27, 54, 27]) == 0\n assert candidate(nums = [5, 10, 5, 15, 10, 20, 15, 25]) == 0\n assert candidate(nums = [100, 50, 50, 100, 50, 50, 100, 50, 50, 100, 50, 50]) == 0\n assert candidate(nums = [5, 10, 5, 15, 10, 20, 15, 30, 15]) == 0\n assert candidate(nums = [0, 0, 0, 0, 0, 0, 0]) == 5\n assert candidate(nums = [1, -1, 0, 1, -1, 0, 1, -1, 0]) == 2\n assert candidate(nums = [15, 30, 15, 60, 15, 30, 15, 60, 15]) == 2\n assert candidate(nums = [-1, -2, -3, -6, -3, -6, -3, -1]) == 0\n assert candidate(nums = [-5, 10, -5, 20, -5, 40, -5, 80, -5]) == 0\n assert candidate(nums = [3, 6, 3, 9, 3, 12, 3, 15, 3, 18, 3]) == 1\n assert candidate(nums = [-100, 0, 100, 0, -100, 0, 100, 0, -100]) == 4\n assert candidate(nums = [1, 1, 2, 2, 4, 4, 8, 8, 16, 16]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 0\n assert candidate(nums = [1, 3, 2, 6, 4, 12, 5, 10, 7, 14]) == 0\n assert candidate(nums = [-10, -20, -10, -30, -10, -40, -10, -50, -10, -60]) == 1\n assert candidate(nums = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]) == 0\n assert candidate(nums = [-2, 4, -2, 8, -2, 4, -2]) == 0\n assert candidate(nums = [3, 6, 3, 9, 3, 12, 3, 15, 3, 18, 3, 21, 3]) == 1\n assert candidate(nums = [25, 50, 25, 100, 25, 50, 25, 100, 25]) == 2\n assert candidate(nums = [1, 3, 2, 6, 4, 12, 8, 24, 16, 48, 32, 96, 64]) == 0\n assert candidate(nums = [5, 10, 5, 15, 10, 5, 20, 10, 5]) == 0\n assert candidate(nums = [100, 50, 0, 50, -100, 0, 100, 50, -50, 25]) == 2\n assert candidate(nums = [10, 5, 5, 10, 5, 10, 5, 10, 5, 10]) == 0\n assert candidate(nums = [1, 3, 2, 6, 3, 6, 3, 9, 3, 12, 6, 6, 6, 12, 6]) == 0\n assert candidate(nums = [1, 3, 2, 5, 10, 5, 15, 10, 20, 15, 30, 20, 40, 35]) == 0\n assert candidate(nums = [1, 3, 2, 5, 4, 7, 6, 9, 8, 11]) == 0\n assert candidate(nums = [-20, 40, -20, 60, -20, 80]) == 0\n assert candidate(nums = [-1, 2, -1, -2, 2, -2, 1]) == 0\n assert candidate(nums = [0, 0, 0, 0, 0, 0]) == 4\n assert candidate(nums = [1, 2, 1, 2, 4, 2, 3, 6, 3, 4, 8, 4, 5, 10, 5]) == 0\n assert candidate(nums = [10, 20, 10, 40, 20, 50, 10]) == 0\n assert candidate(nums = [-10, -20, -10, -15, -30, -15, -25, -50, -25]) == 0\n assert candidate(nums = [5, 10, 5, 15, 10, 5, 20, 10]) == 0\n assert candidate(nums = [-10, -20, -10, -30, -10, -40, -10, -50, -10, -60, -10]) == 1\n assert candidate(nums = [7, 14, 7, 14, 7, 14, 7, 14, 7]) == 0\n assert candidate(nums = [10, 5, 0, 10, 5, 0, 10, 5, 0, 10, 5, 0]) == 3\n assert candidate(nums = [-50, 0, 50, 25, 25, -25, 25, 0, -50]) == 2\n assert candidate(nums = [-20, 0, 20, -10, 10, -30, 15, 15]) == 1\n assert candidate(nums = [7, 14, 7, 21, 14, 28, 21, 42, 21]) == 0\n assert candidate(nums = [-1, -2, -4, -8, -16, -32]) == 0\n assert candidate(nums = [1, 2, 3, 6, 3, 2, 1]) == 0\n", "comparison": "exact"}, "public_tests": ["[1,2,1,4,1]", "[1,1,1]"], "hints": ["The constraints are small. Consider checking every subarray."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().countSubarrays", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:23:36+00:00", "tests_total": 134, "tests_dropped": 15, "flags": [], "topic_tags": ["array"]}, "language": "python", "interface": {"raw_signature": "def countSubarrays(self, nums: List[int]) -> int:", "container": "Solution", "callable": "countSubarrays", "parameters": [{"name": "nums", "type": "List[int]"}], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3393, "task_id": "count-paths-with-the-given-xor-value", "difficulty": "Medium", "problem_description": "You are given a 2D integer array grid with size m x n. You are also given an integer k.\n\nYour task is to calculate the number of paths you can take from the top-left cell (0, 0) to the bottom-right cell (m - 1, n - 1) satisfying the following constraints:\n\n- You can either move to the right or down. Formally, from the cell (i, j) you may move to the cell (i, j + 1) or to the cell (i + 1, j) if the target cell exists.\n- The XOR of all the numbers on the path must be equal to k.\n\nReturn the total number of such paths.\n\nSince the answer can be very large, return the result modulo 10^9 + 7.\n\nExample 1:\n\nInput: grid = [[2, 1, 5], [7, 10, 0], [12, 6, 4]], k = 11\nOutput: 3\nExplanation:\nThe 3 paths are:\n- (0, 0) → (1, 0) → (2, 0) → (2, 1) → (2, 2)\n- (0, 0) → (1, 0) → (1, 1) → (1, 2) → (2, 2)\n- (0, 0) → (0, 1) → (1, 1) → (2, 1) → (2, 2)\n\nExample 2:\n\nInput: grid = [[1, 3, 3, 3], [0, 3, 3, 2], [3, 0, 1, 1]], k = 2\nOutput: 5\nExplanation:\nThe 5 paths are:\n- (0, 0) → (1, 0) → (2, 0) → (2, 1) → (2, 2) → (2, 3)\n- (0, 0) → (1, 0) → (1, 1) → (2, 1) → (2, 2) → (2, 3)\n- (0, 0) → (1, 0) → (1, 1) → (1, 2) → (1, 3) → (2, 3)\n- (0, 0) → (0, 1) → (1, 1) → (1, 2) → (2, 2) → (2, 3)\n- (0, 0) → (0, 1) → (0, 2) → (1, 2) → (2, 2) → (2, 3)\n\nExample 3:\n\nInput: grid = [[1, 1, 1, 2], [3, 0, 3, 2], [3, 0, 2, 2]], k = 10\nOutput: 0\n\nConstraints:\n\n- 1 <= m == grid.length <= 300\n- 1 <= n == grid[r].length <= 300\n- 0 <= grid[r][c] < 16\n- 0 <= k < 16\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(grid = [[1, 3, 3, 3], [0, 3, 3, 2], [3, 0, 1, 1]],k = 2) == 5\n assert candidate(grid = [[15, 15], [15, 15]],k = 14) == 0\n assert candidate(grid = [[1], [1], [1]],k = 1) == 1\n assert candidate(grid = [[1]],k = 1) == 1\n assert candidate(grid = [[0]],k = 0) == 1\n assert candidate(grid = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],k = 15) == 2\n assert candidate(grid = [[0, 0, 0], [0, 0, 0], [0, 0, 0]],k = 0) == 6\n assert candidate(grid = [[1, 2], [3, 4]],k = 7) == 1\n assert candidate(grid = [[1, 1, 1], [1, 1, 1], [1, 1, 1]],k = 3) == 0\n assert candidate(grid = [[1, 1, 1, 2], [3, 0, 3, 2], [3, 0, 2, 2]],k = 10) == 0\n assert candidate(grid = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]],k = 0) == 20\n assert candidate(grid = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],k = 7) == 1\n assert candidate(grid = [[15, 15, 15], [15, 15, 15], [15, 15, 15]],k = 0) == 0\n assert candidate(grid = [[1, 2, 3], [4, 5, 6], [7, 8, 9]],k = 0) == 0\n assert candidate(grid = [[2, 1, 5], [7, 10, 0], [12, 6, 4]],k = 11) == 3\n assert candidate(grid = [[0, 0], [0, 0]],k = 0) == 2\n assert candidate(grid = [[15, 15, 15], [15, 15, 15], [15, 15, 15]],k = 15) == 6\n assert candidate(grid = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 0]],k = 15) == 1\n assert candidate(grid = [[1, 0, 1], [0, 1, 0], [1, 0, 1]],k = 0) == 0\n assert candidate(grid = [[14, 13, 12, 11, 10, 9], [8, 7, 6, 5, 4, 3], [2, 1, 0, 15, 14, 13], [12, 11, 10, 9, 8, 7]],k = 6) == 0\n assert candidate(grid = [[1, 2, 3, 4, 5, 6, 7, 8], [8, 7, 6, 5, 4, 3, 2, 1], [1, 3, 5, 7, 9, 11, 13, 15], [15, 13, 11, 9, 7, 5, 3, 1]],k = 4) == 7\n assert candidate(grid = [[1, 3, 5, 7], [9, 11, 13, 15], [1, 3, 5, 7], [9, 11, 13, 15]],k = 7) == 5\n assert candidate(grid = [[0, 1, 2, 3, 4, 5], [5, 4, 3, 2, 1, 0], [0, 1, 2, 3, 4, 5], [5, 4, 3, 2, 1, 0]],k = 7) == 0\n assert candidate(grid = [[15, 14, 13, 12, 11], [10, 9, 8, 7, 6], [5, 4, 3, 2, 1]],k = 1) == 0\n assert candidate(grid = [[8, 7, 6], [5, 4, 3], [2, 1, 0], [9, 8, 7], [6, 5, 4]],k = 5) == 1\n assert candidate(grid = [[14, 2, 10], [1, 3, 13], [12, 8, 4], [6, 14, 10]],k = 5) == 2\n assert candidate(grid = [[2, 1, 5, 7], [10, 0, 12, 6], [4, 3, 3, 3], [3, 0, 1, 1]],k = 11) == 3\n assert candidate(grid = [[8, 8, 8, 8, 8], [8, 8, 8, 8, 8], [8, 8, 8, 8, 8], [8, 8, 8, 8, 8], [8, 8, 8, 8, 8]],k = 0) == 0\n assert candidate(grid = [[15, 14, 13, 12, 11, 10], [9, 8, 7, 6, 5, 4], [3, 2, 1, 0, 15, 14], [13, 12, 11, 10, 9, 8], [7, 6, 5, 4, 3, 2], [1, 0, 15, 14, 13, 12]],k = 15) == 17\n assert candidate(grid = [[1, 3, 3, 3, 2], [3, 3, 2, 2, 1], [2, 2, 1, 1, 3], [1, 1, 3, 3, 2]],k = 4) == 0\n assert candidate(grid = [[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11], [12, 13, 14, 15]],k = 15) == 0\n assert candidate(grid = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [1, 2, 3, 4, 5]],k = 5) == 7\n assert candidate(grid = [[0, 1, 2, 3, 4, 5], [5, 4, 3, 2, 1, 0], [0, 1, 2, 3, 4, 5], [5, 4, 3, 2, 1, 0]],k = 5) == 0\n assert candidate(grid = [[3, 6, 12, 15], [10, 7, 1, 4], [8, 11, 13, 5], [14, 2, 9, 13]],k = 3) == 3\n assert candidate(grid = [[7, 8, 9, 10, 11], [12, 13, 14, 15, 0], [1, 2, 3, 4, 5], [6, 7, 8, 9, 10]],k = 12) == 10\n assert candidate(grid = [[0, 1, 2, 3, 4, 5], [5, 4, 3, 2, 1, 0], [0, 1, 2, 3, 4, 5], [5, 4, 3, 2, 1, 0], [0, 1, 2, 3, 4, 5]],k = 3) == 28\n assert candidate(grid = [[15, 14, 13, 12, 11], [10, 9, 8, 7, 6], [5, 4, 3, 2, 1], [0, 1, 2, 3, 4]],k = 15) == 0\n assert candidate(grid = [[5, 3, 2, 1], [6, 0, 4, 5], [7, 8, 9, 1], [10, 11, 12, 13]],k = 10) == 1\n assert candidate(grid = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]],k = 1) == 0\n assert candidate(grid = [[8, 15, 10, 5], [13, 7, 6, 11], [2, 9, 4, 12], [3, 14, 1, 8]],k = 10) == 0\n assert candidate(grid = [[1, 1, 1, 1, 1], [2, 2, 2, 2, 2], [3, 3, 3, 3, 3], [4, 4, 4, 4, 4]],k = 0) == 1\n assert candidate(grid = [[0, 1, 2, 3, 4, 5], [6, 7, 8, 9, 10, 11], [12, 13, 14, 15, 0, 1], [2, 3, 4, 5, 6, 7], [8, 9, 10, 11, 12, 13]],k = 8) == 8\n assert candidate(grid = [[14, 14, 14, 14], [14, 14, 14, 14], [14, 14, 14, 14], [14, 14, 14, 14]],k = 14) == 20\n assert candidate(grid = [[15, 14, 13, 12], [11, 10, 9, 8], [7, 6, 5, 4], [3, 2, 1, 0]],k = 10) == 0\n assert candidate(grid = [[15, 14, 13, 12, 11], [10, 9, 8, 7, 6], [5, 4, 3, 2, 1]],k = 5) == 0\n assert candidate(grid = [[1, 1, 1], [1, 0, 1], [1, 1, 1], [1, 0, 1], [1, 1, 1]],k = 0) == 8\n assert candidate(grid = [[5, 9, 10], [9, 8, 1], [10, 1, 3], [1, 3, 5]],k = 13) == 0\n assert candidate(grid = [[1, 0, 1, 1], [0, 1, 0, 0], [1, 0, 1, 0], [0, 1, 0, 1]],k = 14) == 0\n assert candidate(grid = [[3, 3, 3, 3, 3], [3, 3, 3, 3, 3], [3, 3, 3, 3, 3], [3, 3, 3, 3, 3], [3, 3, 3, 3, 3]],k = 3) == 70\n assert candidate(grid = [[0, 1, 2, 3, 4, 5, 6], [7, 8, 9, 10, 11, 12, 13], [14, 15, 0, 1, 2, 3, 4], [5, 6, 7, 8, 9, 10, 11]],k = 5) == 8\n assert candidate(grid = [[2, 4, 6, 8, 10], [1, 3, 5, 7, 9], [0, 0, 0, 0, 0], [15, 13, 11, 9, 7]],k = 7) == 2\n assert candidate(grid = [[15, 14, 13, 12, 11, 10, 9, 8, 7, 6], [5, 4, 3, 2, 1, 0, 15, 14, 13, 12], [11, 10, 9, 8, 7, 6, 5, 4, 3, 2]],k = 10) == 4\n assert candidate(grid = [[1, 0, 0, 1], [0, 1, 1, 0], [0, 1, 1, 0], [1, 0, 0, 1]],k = 0) == 8\n assert candidate(grid = [[1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1]],k = 0) == 0\n assert candidate(grid = [[0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0]],k = 1) == 0\n assert candidate(grid = [[2, 2, 2, 2, 2], [2, 2, 2, 2, 2], [2, 2, 2, 2, 2], [2, 2, 2, 2, 2], [2, 2, 2, 2, 2]],k = 2) == 70\n assert candidate(grid = [[11, 12, 13], [14, 15, 10], [9, 8, 7], [6, 5, 4]],k = 9) == 0\n assert candidate(grid = [[2, 3, 1, 5], [1, 4, 2, 3], [5, 6, 7, 8], [0, 1, 2, 3]],k = 7) == 1\n assert candidate(grid = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [9, 8, 7, 6, 5, 4, 3, 2, 1, 0], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]],k = 5) == 0\n assert candidate(grid = [[1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1]],k = 0) == 35\n assert candidate(grid = [[15, 14, 13, 12], [11, 10, 9, 8], [7, 6, 5, 4], [3, 2, 1, 0]],k = 15) == 0\n assert candidate(grid = [[1, 2, 3], [0, 1, 2], [3, 0, 1], [2, 3, 0]],k = 3) == 6\n assert candidate(grid = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]],k = 2) == 0\n assert candidate(grid = [[15, 0, 1, 1], [1, 15, 1, 1], [1, 1, 15, 1], [1, 1, 1, 15]],k = 15) == 4\n assert candidate(grid = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [0, 1, 2, 3, 4], [5, 6, 7, 8, 9]],k = 7) == 0\n assert candidate(grid = [[1, 3, 5, 7, 9], [2, 4, 6, 8, 10], [1, 3, 5, 7, 9], [2, 4, 6, 8, 10], [1, 3, 5, 7, 9]],k = 15) == 0\n assert candidate(grid = [[1, 3, 3, 3, 3], [0, 3, 3, 2, 2], [3, 0, 1, 1, 1], [1, 1, 2, 2, 3]],k = 2) == 0\n assert candidate(grid = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]],k = 0) == 252\n assert candidate(grid = [[14, 4, 14, 4], [14, 4, 14, 4], [14, 4, 14, 4], [14, 4, 14, 4]],k = 8) == 0\n assert candidate(grid = [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]],k = 0) == 0\n assert candidate(grid = [[0, 1, 2, 3, 4, 5], [6, 7, 8, 9, 10, 11], [12, 13, 14, 15, 0, 1], [2, 3, 4, 5, 6, 7]],k = 12) == 9\n assert candidate(grid = [[0, 1, 2, 3, 4, 5], [5, 4, 3, 2, 1, 0], [0, 1, 2, 3, 4, 5], [5, 4, 3, 2, 1, 0], [0, 1, 2, 3, 4, 5], [5, 4, 3, 2, 1, 0]],k = 5) == 68\n assert candidate(grid = [[2, 1, 5, 7], [7, 10, 0, 12], [12, 6, 4, 3], [3, 14, 1, 8]],k = 11) == 1\n assert candidate(grid = [[1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1]],k = 1) == 15\n assert candidate(grid = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]],k = 10) == 0\n assert candidate(grid = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]],k = 4) == 0\n assert candidate(grid = [[0, 1, 2, 3, 4], [4, 3, 2, 1, 0], [0, 1, 2, 3, 4], [4, 3, 2, 1, 0]],k = 6) == 6\n assert candidate(grid = [[1, 0, 1, 0, 1], [0, 1, 0, 1, 0], [1, 0, 1, 0, 1], [0, 1, 0, 1, 0], [1, 0, 1, 0, 1]],k = 1) == 70\n assert candidate(grid = [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]],k = 0) == 70\n assert candidate(grid = [[14, 1, 11, 3, 13, 7], [12, 4, 6, 8, 5, 9], [10, 2, 0, 15, 1, 14], [3, 13, 7, 11, 4, 6], [8, 5, 9, 12, 2, 0], [15, 1, 14, 10, 3, 8]],k = 15) == 13\n assert candidate(grid = [[1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1]],k = 0) == 126\n assert candidate(grid = [[1, 0, 1, 0], [0, 1, 0, 1], [1, 0, 1, 0], [0, 1, 0, 1]],k = 3) == 0\n assert candidate(grid = [[15, 0, 15, 0], [0, 15, 0, 15], [15, 0, 15, 0], [0, 15, 0, 15]],k = 14) == 0\n assert candidate(grid = [[2, 3, 1, 4], [1, 2, 3, 4], [4, 3, 2, 1], [3, 4, 1, 2]],k = 5) == 4\n assert candidate(grid = [[15, 15, 15, 15], [15, 15, 15, 15], [15, 15, 15, 15], [15, 15, 15, 15]],k = 15) == 20\n assert candidate(grid = [[1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1]],k = 2) == 0\n assert candidate(grid = [[3, 3, 3, 3, 3, 3, 3], [3, 3, 3, 3, 3, 3, 3], [3, 3, 3, 3, 3, 3, 3], [3, 3, 3, 3, 3, 3, 3]],k = 14) == 0\n assert candidate(grid = [[8, 5, 7], [5, 8, 5], [7, 5, 8]],k = 7) == 2\n assert candidate(grid = [[1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1]],k = 5) == 0\n assert candidate(grid = [[1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1, 0]],k = 0) == 0\n assert candidate(grid = [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]],k = 15) == 0\n assert candidate(grid = [[1, 1, 1, 1], [1, 0, 1, 0], [0, 1, 0, 1], [1, 0, 1, 1]],k = 1) == 16\n assert candidate(grid = [[5, 9, 15], [10, 7, 11], [8, 12, 14]],k = 13) == 1\n assert candidate(grid = [[15, 14, 13, 12, 11], [10, 9, 8, 7, 6], [5, 4, 3, 2, 1], [0, 0, 0, 0, 0], [15, 14, 13, 12, 11]],k = 13) == 3\n", "comparison": "exact"}, "public_tests": ["[[2,1,5],[7,10,0],[12,6,4]]\n11", "[[1,3,3,3],[0,3,3,2],[3,0,1,1]]\n2", "[[1,1,1,2],[3,0,3,2],[3,0,2,2]]\n10"], "hints": ["Use DP."], "metadata": {"canonical_parameter_names": ["grid", "k"], "leetcode_dataset_entry_point": "Solution().countPathsWithXorValue", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:23:38+00:00", "tests_total": 106, "tests_dropped": 12, "flags": [], "topic_tags": ["array", "dynamic-programming", "bit-manipulation", "matrix"]}, "language": "python", "interface": {"raw_signature": "def countPathsWithXorValue(self, grid: List[List[int]], k: int) -> int:", "container": "Solution", "callable": "countPathsWithXorValue", "parameters": [{"name": "grid", "type": "List[List[int]]"}, {"name": "k", "type": "int"}], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3395, "task_id": "subsequences-with-a-unique-middle-mode-i", "difficulty": "Hard", "problem_description": "Given an integer array nums, find the number of subsequences of size 5 of nums with a unique middle mode.\n\nSince the answer may be very large, return it modulo 10^9 + 7.\n\nA mode of a sequence of numbers is defined as the element that appears the maximum number of times in the sequence.\n\nA sequence of numbers contains a unique mode if it has only one mode.\n\nA sequence of numbers seq of size 5 contains a unique middle mode if the middle element (seq[2]) is a unique mode.\n\nExample 1:\n\nInput: nums = [1,1,1,1,1,1]\nOutput: 6\nExplanation:\n[1, 1, 1, 1, 1] is the only subsequence of size 5 that can be formed, and it has a unique middle mode of 1. This subsequence can be formed in 6 different ways, so the output is 6.\n\nExample 2:\n\nInput: nums = [1,2,2,3,3,4]\nOutput: 4\nExplanation:\n[1, 2, 2, 3, 4] and [1, 2, 3, 3, 4] each have a unique middle mode because the number at index 2 has the greatest frequency in the subsequence. [1, 2, 2, 3, 3] does not have a unique middle mode because 2 and 3 appear twice.\n\nExample 3:\n\nInput: nums = [0,1,2,3,4,5,6,7,8]\nOutput: 0\nExplanation:\nThere is no subsequence of length 5 with a unique middle mode.\n\nConstraints:\n\n- 5 <= nums.length <= 1000\n- -10^9 <= nums[i] <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1]) == 5613\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000]) == 1\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4]) == 951\n assert candidate(nums = [10, 20, 20, 20, 30, 30, 40, 40, 40, 40, 50, 50, 50, 50, 50]) == 1349\n assert candidate(nums = [5, 5, 5, 5, 5, 1, 1, 2, 2, 3, 3]) == 221\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 5]) == 1185\n assert candidate(nums = [-1, -2, -3, -4, -5, -1, -2, -3, -4, -5, -1, -2, -3, -4, -5]) == 760\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 0\n assert candidate(nums = [1, 2, 2, 3, 3, 4]) == 4\n assert candidate(nums = [-1, -1, -1, 0, 0, 1, 1, 1, 2, 2, 2]) == 165\n assert candidate(nums = [0, 1, 2, 3, 4, 5, 6, 7, 8]) == 0\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == 80\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == 50\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5]) == 8799\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3]) == 402\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7]) == 7500\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5]) == 126\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3]) == 1503\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5]) == 1140\n assert candidate(nums = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10]) == 0\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 252\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 3003\n assert candidate(nums = [1, 1, 1, 1, 1, 1]) == 6\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4]) == 12723\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == 760\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 0\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 4, 4, 4, 4]) == 191\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9]) == 495068\n assert candidate(nums = [-5, -5, -5, -5, -5, -5, -5, -5, -5, -4, -4, -4, -4, -4, -4, -4, -4, -4, -3, -3, -3, -3, -3, -3, -3, -3, -3, -2, -2, -2, -2, -2, -2, -2, -2, -2]) == 184536\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4]) == 1207062\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 800874\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8]) == 61089\n assert candidate(nums = [-1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3]) == 22505\n assert candidate(nums = [1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 12, 13, 13, 13, 14, 14, 14, 15, 15, 15, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 19, 20, 20, 20]) == 708453\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15]) == 18928\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8]) == 86599\n assert candidate(nums = [10, 20, 20, 30, 30, 30, 40, 40, 40, 40, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60]) == 9107\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4]) == 184536\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 27285336\n assert candidate(nums = [0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4]) == 727516\n assert candidate(nums = [100, 200, 200, 200, 300, 300, 300, 300, 400, 400, 400, 400, 400, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500]) == 18556\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9]) == 525765\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == 657990\n assert candidate(nums = [10, 20, 20, 20, 30, 30, 30, 30, 30, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40]) == 104255\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3]) == 112113\n assert candidate(nums = [1, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6]) == 86817\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10]) == 37530\n assert candidate(nums = [-1, -1, -1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 190065\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9]) == 3885489\n assert candidate(nums = [1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9]) == 656149\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 2278561\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4]) == 85638\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15]) == 21840\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40]) == 0\n assert candidate(nums = [100, 100, 100, 100, 100, 100, 101, 101, 101, 101, 101, 102, 102, 102, 102, 102, 102, 103, 103, 103, 103, 103, 103, 103]) == 19524\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3]) == 127869\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 9, 9, 9]) == 140000\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 348457\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6]) == 85182\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1, 2, 3, 4, 5]) == 126\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5]) == 30199\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 2, 2, 3, 3, 4, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 8948\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5]) == 107588\n assert candidate(nums = [1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8]) == 55871\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10]) == 626260\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 160013\n assert candidate(nums = [0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8]) == 39039\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8]) == 63891\n assert candidate(nums = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1000000000, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 45738\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6]) == 158764\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7]) == 431134\n assert candidate(nums = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9]) == 446508\n assert candidate(nums = [0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5]) == 105672\n assert candidate(nums = [1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10]) == 2700054\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 148228\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 544618\n assert candidate(nums = [1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5]) == 89038\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5]) == 82236\n assert candidate(nums = [1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10]) == 149526\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 98136\n assert candidate(nums = [1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9]) == 81604\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14]) == 2798264\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 580164\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5]) == 61830\n assert candidate(nums = [-1000000000, -1000000000, -1000000000, -1000000000, -1000000000, -1000000000, -1000000000, -1000000000, -1000000000, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 45738\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 378931\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4]) == 108611\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13]) == 11440\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5]) == 1409\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 31668\n assert candidate(nums = [1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9]) == 443663\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) == 169911\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4]) == 540508\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10]) == 208198\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 2598960\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7]) == 739355\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5]) == 63770\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2]) == 169911\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60]) == 0\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8]) == 422646\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 12, 13, 13, 13, 14, 14, 14, 15, 15, 15, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 19, 20, 20, 20, 21, 21, 21, 22, 22, 22, 23, 23, 23, 24, 24, 24]) == 1777716\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]) == 719651\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9]) == 1026054\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 775155\n assert candidate(nums = [9, 8, 8, 7, 7, 7, 6, 6, 6, 6, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2]) == 86599\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9]) == 403014\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10]) == 50392\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9]) == 48201\n assert candidate(nums = [1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9]) == 455652\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4]) == 955914\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 142506\n assert candidate(nums = [1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9]) == 600008\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5]) == 358897\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3]) == 102063\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 169911\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9]) == 33885\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 135996\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4]) == 2927808\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 12, 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18]) == 2515320\n assert candidate(nums = [-1, -1, -1, 0, 0, 0, 1, 1, 1, 2, 2, 2, 2, 2, 3]) == 1428\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 2349060\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6]) == 367473\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9]) == 2318085\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6]) == 73447\n assert candidate(nums = [1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8]) == 10375\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30]) == 116676\n assert candidate(nums = [1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 224666\n assert candidate(nums = [1, 1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9]) == 675066\n assert candidate(nums = [1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10, 10]) == 45852\n", "comparison": "exact"}, "public_tests": ["[1,1,1,1,1,1]", "[1,2,2,3,3,4]", "[0,1,2,3,4,5,6,7,8]"], "hints": ["For each index, find the number of subsequences for which it is the unique middle mode. What combinations of values can the two numbers on the left and the right take?", "For example, we can have exactly 1 element on the left equal to the middle and all other elements differ. What other combinations are acceptable?"], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().subsequencesWithMiddleMode", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:23:44+00:00", "tests_total": 133, "tests_dropped": 0, "flags": [], "topic_tags": ["array", "hash-table", "math", "combinatorics"]}, "language": "python", "interface": {"raw_signature": "def subsequencesWithMiddleMode(self, nums: List[int]) -> int:", "container": "Solution", "callable": "subsequencesWithMiddleMode", "parameters": [{"name": "nums", "type": "List[int]"}], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3396, "task_id": "minimum-number-of-operations-to-make-elements-in-array-distinct", "difficulty": "Easy", "problem_description": "You are given an integer array nums. You need to ensure that the elements in the array are distinct. To achieve this, you can perform the following operation any number of times:\n\n- Remove 3 elements from the beginning of the array. If the array has fewer than 3 elements, remove all remaining elements.\n\nNote that an empty array is considered to have distinct elements. Return the minimum number of operations needed to make the elements in the array distinct.\n\nExample 1:\n\nInput: nums = [1,2,3,4,2,3,3,5,7]\nOutput: 2\nExplanation:\n- In the first operation, the first 3 elements are removed, resulting in the array [4, 2, 3, 3, 5, 7].\n- In the second operation, the next 3 elements are removed, resulting in the array [3, 5, 7], which has distinct elements.\n\nTherefore, the answer is 2.\n\nExample 2:\n\nInput: nums = [4,5,6,4,4]\nOutput: 2\nExplanation:\n- In the first operation, the first 3 elements are removed, resulting in the array [4, 4].\n- In the second operation, all remaining elements are removed, resulting in an empty array.\n\nTherefore, the answer is 2.\n\nExample 3:\n\nInput: nums = [6,7,8,9]\nOutput: 0\nExplanation:\nThe array already contains distinct elements. Therefore, the answer is 0.\n\nConstraints:\n\n- 1 <= nums.length <= 100\n- 1 <= nums[i] <= 100\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [4, 5, 6, 4, 4]) == 2\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1]) == 3\n assert candidate(nums = [10, 20, 30, 10, 20, 30, 10, 20, 30]) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 0\n assert candidate(nums = [1]) == 0\n assert candidate(nums = [6, 7, 8, 9]) == 0\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) == 3\n assert candidate(nums = [10, 20, 30, 40, 50]) == 0\n assert candidate(nums = [5, 5, 5, 5, 5]) == 2\n assert candidate(nums = [1, 2, 2, 3, 3, 3]) == 2\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3]) == 2\n assert candidate(nums = [1, 1, 2]) == 1\n assert candidate(nums = [10, 10, 10, 10, 10, 10, 10, 10, 10]) == 3\n assert candidate(nums = [1, 1, 1, 1, 1]) == 2\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1]) == 3\n assert candidate(nums = [10, 20, 30, 10, 20]) == 1\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4]) == 3\n assert candidate(nums = [1, 2]) == 0\n assert candidate(nums = [1, 2, 3]) == 0\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 3\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5]) == 2\n assert candidate(nums = [1, 1, 1, 1, 1, 1]) == 2\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3]) == 3\n assert candidate(nums = [1, 2, 3, 4, 2, 3, 3, 5, 7]) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 1]) == 1\n assert candidate(nums = [5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10]) == 6\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 100, 99, 98, 97, 96, 95]) == 2\n assert candidate(nums = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100]) == 7\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 6\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]) == 6\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1]) == 5\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 6\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 7\n assert candidate(nums = [1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 8\n assert candidate(nums = [10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 10, 20, 30, 40, 50]) == 9\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12]) == 8\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]) == 3\n assert candidate(nums = [100, 100, 100, 100, 100, 99, 99, 99, 99, 99, 98, 98, 98, 98, 98]) == 5\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 3\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7]) == 7\n assert candidate(nums = [10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 10, 20, 30]) == 3\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 7\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]) == 3\n assert candidate(nums = [42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42]) == 8\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 7\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5]) == 8\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 1, 2, 3, 4, 5, 5, 5, 5, 5, 5, 6, 7, 8, 9, 10, 10, 10, 10, 10, 10]) == 9\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10]) == 10\n assert candidate(nums = [1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 7\n assert candidate(nums = [5, 6, 7, 8, 9, 5, 6, 7, 8, 9, 5]) == 2\n assert candidate(nums = [20, 20, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 1\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 19\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]) == 6\n assert candidate(nums = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6]) == 7\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]) == 10\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]) == 4\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 7\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 3\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == 12\n assert candidate(nums = [1, 2, 1, 3, 2, 1, 4, 3, 2, 1, 5, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1]) == 5\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4]) == 7\n assert candidate(nums = [10, 20, 30, 10, 20, 30, 10, 20, 30, 10, 20, 30, 10, 20, 30]) == 4\n assert candidate(nums = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]) == 10\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, 28, 28, 29, 29, 30, 30]) == 20\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9]) == 6\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]) == 7\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 7\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14]) == 9\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]) == 0\n assert candidate(nums = [5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7]) == 5\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5]) == 2\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5]) == 5\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 0\n assert candidate(nums = [5, 6, 7, 5, 6, 7, 5, 6, 7, 5, 6, 7, 5, 6, 7, 5]) == 5\n assert candidate(nums = [10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 10, 20, 30, 40, 50]) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 7\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10]) == 10\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]) == 22\n assert candidate(nums = [99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70]) == 0\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5]) == 5\n assert candidate(nums = [10, 10, 10, 20, 20, 20, 30, 30, 30, 10, 20, 30, 10, 20, 30]) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 0\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4]) == 13\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4]) == 4\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]) == 7\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 1, 2, 3, 4, 5]) == 2\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 4\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50]) == 0\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 4, 5, 6, 4, 5, 6, 7, 8, 9, 7, 8, 9, 10, 11, 12, 10, 11, 12, 13, 14, 15, 13, 14, 15, 16, 17, 18, 16, 17, 18, 19, 20, 21, 19, 20, 21, 22, 23, 24, 22, 23, 24, 25, 26, 27, 25, 26, 27, 28, 29, 30]) == 17\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]) == 10\n assert candidate(nums = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6]) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 4\n assert candidate(nums = [7, 8, 9, 10, 11, 12, 7, 8, 9, 10, 11, 12, 7, 8, 9, 10, 11, 12, 7]) == 5\n assert candidate(nums = [7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21]) == 0\n assert candidate(nums = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9]) == 6\n assert candidate(nums = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]) == 5\n assert candidate(nums = [10, 20, 30, 10, 20, 30, 10, 20, 30, 10, 20, 30, 10, 20, 30, 10, 20, 30]) == 5\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 0\n assert candidate(nums = [7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9, 7, 8, 9]) == 9\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5, 6]) == 2\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 6\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 6, 7, 8, 9, 10, 1, 2]) == 3\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == 5\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 7\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) == 7\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 5\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 6\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5]) == 2\n assert candidate(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8]) == 5\n assert candidate(nums = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7]) == 7\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 3\n assert candidate(nums = [1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10\n assert candidate(nums = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5]) == 7\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 3\n", "comparison": "exact"}, "public_tests": ["[1,2,3,4,2,3,3,5,7]", "[4,5,6,4,4]", "[6,7,8,9]"], "hints": ["The constraints are small. Try brute force."], "metadata": {"canonical_parameter_names": ["nums"], "leetcode_dataset_entry_point": "Solution().minimumOperations", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:23:46+00:00", "tests_total": 116, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "hash-table"]}, "language": "python", "interface": {"raw_signature": "def minimumOperations(self, nums: List[int]) -> int:", "container": "Solution", "callable": "minimumOperations", "parameters": [{"name": "nums", "type": "List[int]"}], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} @@ -148,8 +148,8 @@ {"question_id": 3448, "task_id": "count-substrings-divisible-by-last-digit", "difficulty": "Hard", "problem_description": "You are given a string s consisting of digits.\n\nReturn the number of substrings of s divisible by their non-zero last digit.\n\nNote: A substring may contain leading zeros.\n\nExample 1:\n\nInput: s = \"12936\"\nOutput: 11\nExplanation:\nSubstrings \"29\", \"129\", \"293\" and \"2936\" are not divisible by their last digit. There are 15 substrings in total, so the answer is 15 - 4 = 11.\n\nExample 2:\n\nInput: s = \"5701283\"\nOutput: 18\nExplanation:\nSubstrings \"01\", \"12\", \"701\", \"012\", \"128\", \"5701\", \"7012\", \"0128\", \"57012\", \"70128\", \"570128\", and \"701283\" are all divisible by their last digit. Additionally, all substrings that are just 1 non-zero digit are divisible by themselves. Since there are 6 such digits, the answer is 12 + 6 = 18.\n\nExample 3:\n\nInput: s = \"1010101010\"\nOutput: 25\nExplanation:\nOnly substrings that end with digit '1' are divisible by their last digit. There are 25 such substrings.\n\nConstraints:\n\n- 1 <= s.length <= 10^5\n- s consists of digits only.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"24680\") == 6\n assert candidate(s = \"11111\") == 15\n assert candidate(s = \"5701283\") == 18\n assert candidate(s = \"9876543210\") == 35\n assert candidate(s = \"1001001001\") == 22\n assert candidate(s = \"9999999999\") == 55\n assert candidate(s = \"1111111111\") == 55\n assert candidate(s = \"9090909090\") == 25\n assert candidate(s = \"909090909\") == 25\n assert candidate(s = \"2468024680\") == 24\n assert candidate(s = \"00000\") == 0\n assert candidate(s = \"13579\") == 8\n assert candidate(s = \"12936\") == 11\n assert candidate(s = \"1010101010\") == 25\n assert candidate(s = \"12345678901234567890\") == 88\n assert candidate(s = \"1234567890\") == 20\n assert candidate(s = \"0000000000\") == 0\n assert candidate(s = \"11111222223333344444\") == 160\n assert candidate(s = \"13579135791357913579\") == 118\n assert candidate(s = \"1234512345123451234512345123451234512345123451234512345\") == 1111\n assert candidate(s = \"7777777777777777777777777777777\") == 496\n assert candidate(s = \"001001001001001001001001001001001001001001001001\") == 408\n assert candidate(s = \"12345678901234567890123456789012345678901234567890\") == 587\n assert candidate(s = \"123456789000000000001234567890\") == 148\n assert candidate(s = \"54321098765432109876543210\") == 190\n assert candidate(s = \"123456789123456789123456789123456789123456789\") == 522\n assert candidate(s = \"98765432101234567890\") == 104\n assert candidate(s = \"1100110011001100\") == 60\n assert candidate(s = \"123456789011121314151617181920212223242526272829303132333435363738394041424344454647484950\") == 2238\n assert candidate(s = \"111112222233333444445555566666777778888899999\") == 550\n assert candidate(s = \"010010001000010000010000001000000001000000000100000000001\") == 216\n assert candidate(s = \"0102030405060708090102030405\") == 158\n assert candidate(s = \"52525252525252525252\") == 210\n assert candidate(s = \"25025025025025025025025025\") == 243\n assert candidate(s = \"10000000000000000000\") == 1\n assert candidate(s = \"86420864208642086420\") == 133\n assert candidate(s = \"2222222222222222222\") == 190\n assert candidate(s = \"0000000000000000000000000000000\") == 0\n assert candidate(s = \"12300000000000000000\") == 5\n assert candidate(s = \"123456789098765432101234567890\") == 220\n assert candidate(s = \"1001001001001001001001001001001\") == 176\n assert candidate(s = \"00000000001234567890\") == 80\n assert candidate(s = \"135791113151719212325\") == 184\n assert candidate(s = \"78945612307894561230\") == 117\n assert candidate(s = \"12345999999999999999\") == 146\n assert candidate(s = \"12034567890123456789\") == 95\n assert candidate(s = \"5678901234\") == 28\n assert candidate(s = \"01234567890123456789\") == 101\n assert candidate(s = \"99999999999999999999\") == 210\n assert candidate(s = \"505050505050505050505050505050\") == 225\n assert candidate(s = \"11111111111111111111\") == 210\n assert candidate(s = \"11223344556677889900\") == 71\n assert candidate(s = \"10000000010000000010\") == 30\n assert candidate(s = \"246802468024680\") == 52\n assert candidate(s = \"100000000010000000001000000000\") == 33\n assert candidate(s = \"12345678901112131415161718192021222324252627282930\") == 898\n assert candidate(s = \"36912580473691258047\") == 119\n assert candidate(s = \"3330333033303330333\") == 150\n assert candidate(s = \"987654321987654321987654321987654321987654321\") == 603\n assert candidate(s = \"86420864208642086420864208642086420\") == 407\n assert candidate(s = \"9876543210987654321098765432109876543210\") == 435\n assert candidate(s = \"98765432109876543210\") == 119\n assert candidate(s = \"24681357902468135790\") == 110\n assert candidate(s = \"123456789876543210123456789\") == 193\n assert candidate(s = \"111111111122222222223333333333\") == 335\n assert candidate(s = \"98765432100000000001\") == 55\n assert candidate(s = \"111222333444555666777888999\") == 183\n assert candidate(s = \"10010010010010010010\") == 70\n assert candidate(s = \"50505050505050505050\") == 100\n assert candidate(s = \"1001001001001001001001\") == 92\n assert candidate(s = \"987654321987654321987654321\") == 233\n assert candidate(s = \"112233445566778899001122334455667788990011223344\") == 612\n assert candidate(s = \"24680246802468024680\") == 93\n assert candidate(s = \"99999888887777766666\") == 120\n assert candidate(s = \"258025802580258025802580258025802580258025802580\") == 576\n assert candidate(s = \"909090909090909\") == 64\n assert candidate(s = \"09090909090909090909\") == 110\n assert candidate(s = \"98765432109876543210987654321098765432109876543210\") == 667\n assert candidate(s = \"1001001001001001001\") == 70\n assert candidate(s = \"12345678909876543210\") == 104\n assert candidate(s = \"987654321000000000000000000000\") == 35\n assert candidate(s = \"12213332211221333221\") == 174\n assert candidate(s = \"1110001110001110001\") == 91\n assert candidate(s = \"2222222222\") == 55\n assert candidate(s = \"55555555555555555555\") == 210\n assert candidate(s = \"123012301230123012301230\") == 195\n assert candidate(s = \"123455432112345543211234554321\") == 342\n assert candidate(s = \"12345098765432109876\") == 101\n assert candidate(s = \"00000000000000000000\") == 0\n assert candidate(s = \"13579246801357924680135792468013579246801357924680\") == 691\n assert candidate(s = \"999000999000999000\") == 72\n assert candidate(s = \"10101010101010101010101010101010101010101010\") == 484\n assert candidate(s = \"13579246801357924680\") == 109\n assert candidate(s = \"987654321098765432109876543210\") == 252\n assert candidate(s = \"50505050505050505050505\") == 144\n assert candidate(s = \"8642086420864208642086420864208642086420864208642086420\") == 1005\n assert candidate(s = \"101010101010101010101010101010101010101010101010\") == 576\n assert candidate(s = \"987654321011121314151617181920\") == 316\n assert candidate(s = \"36936936936936936936\") == 189\n assert candidate(s = \"5050505050505050505050\") == 121\n assert candidate(s = \"2468024680246802468024680\") == 146\n assert candidate(s = \"98765432101111111111\") == 190\n assert candidate(s = \"123321123321123321123321\") == 268\n assert candidate(s = \"44444444444444444444444444\") == 351\n assert candidate(s = \"123412341234123412341234123412341234123412341234\") == 680\n assert candidate(s = \"1100110011001100110011\") == 138\n assert candidate(s = \"102030405060708090\") == 39\n assert candidate(s = \"1212121212121212121\") == 190\n assert candidate(s = \"9090909090909090909\") == 100\n assert candidate(s = \"12345678900000000000\") == 20\n assert candidate(s = \"123123123123123\") == 105\n assert candidate(s = \"10101010101010101010\") == 100\n assert candidate(s = \"123456789012345678901234567890\") == 205\n", "comparison": "exact"}, "public_tests": ["\"12936\"", "\"5701283\"", "\"1010101010\""], "hints": ["Let dp[index][i][j] be the number of subarrays s[start...index] such that s[start...index] % i == j.", "For every pair (i, j), add dp[index - 1][i][j] to dp[index][i][(j * 10 + x)%i)].", "You should optimize this solution so that it can fit into the memory limit.", "In order to find dp[index][i][j] we use values from dp[index - 1][i][j]. Hence, we can keep only dp[index][i][j] and dp[index - 1][i][j] at every iteration of the loop."], "metadata": {"canonical_parameter_names": ["s"], "leetcode_dataset_entry_point": "Solution().countSubstrings", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:25:38+00:00", "tests_total": 113, "tests_dropped": 0, "flags": [], "topic_tags": ["string", "dynamic-programming"]}, "language": "python", "interface": {"raw_signature": "def countSubstrings(self, s: str) -> int:", "container": "Solution", "callable": "countSubstrings", "parameters": [{"name": "s", "type": "str"}], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3449, "task_id": "maximize-the-minimum-game-score", "difficulty": "Hard", "problem_description": "You are given an array points of size n and an integer m. There is another array gameScore of size n, where gameScore[i] represents the score achieved at the i^th game. Initially, gameScore[i] == 0 for all i.\n\nYou start at index -1, which is outside the array (before the first position at index 0). You can make at most m moves. In each move, you can either:\n\n- Increase the index by 1 and add points[i] to gameScore[i].\n- Decrease the index by 1 and add points[i] to gameScore[i].\n\nNote that the index must always remain within the bounds of the array after the first move.\n\nReturn the maximum possible minimum value in gameScore after at most m moves.\n\nExample 1:\n\nInput: points = [2,4], m = 3\nOutput: 4\nExplanation:\nInitially, index i = -1 and gameScore = [0, 0].\n\nMove | Index | gameScore\nIncrease i | 0 | [2, 0]\nIncrease i | 1 | [2, 4]\nDecrease i | 0 | [4, 4]\n\nThe minimum value in gameScore is 4, and this is the maximum possible minimum among all configurations. Hence, 4 is the output.\n\nExample 2:\n\nInput: points = [1,2,3], m = 5\nOutput: 2\nExplanation:\nInitially, index i = -1 and gameScore = [0, 0, 0].\n\nMove | Index | gameScore\nIncrease i | 0 | [1, 0, 0]\nIncrease i | 1 | [1, 2, 0]\nDecrease i | 0 | [2, 2, 0]\nIncrease i | 1 | [2, 4, 0]\nIncrease i | 2 | [2, 4, 3]\n\nThe minimum value in gameScore is 2, and this is the maximum possible minimum among all configurations. Hence, 2 is the output.\n\nConstraints:\n\n- 2 <= n == points.length <= 5 * 10^4\n- 1 <= points[i] <= 10^6\n- 1 <= m <= 10^9\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(points = [5, 3, 8, 2, 6],m = 10) == 6\n assert candidate(points = [5, 9, 3, 7],m = 7) == 6\n assert candidate(points = [1, 1, 1, 1, 1],m = 5) == 1\n assert candidate(points = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],m = 20) == 2\n assert candidate(points = [2, 4],m = 3) == 4\n assert candidate(points = [1, 1, 1, 1, 1],m = 10) == 1\n assert candidate(points = [100000, 100000, 100000, 100000, 100000],m = 1000000) == 16666600000\n assert candidate(points = [5, 9, 3, 7],m = 6) == 5\n assert candidate(points = [5, 9, 3, 7],m = 10) == 9\n assert candidate(points = [10, 10, 10, 10, 10],m = 10) == 10\n assert candidate(points = [1000000, 1000000, 1000000],m = 1000000) == 250000000000\n assert candidate(points = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],m = 10) == 1\n assert candidate(points = [5, 9, 3, 8],m = 6) == 5\n assert candidate(points = [2, 4],m = 3) == 4\n assert candidate(points = [1, 2, 3],m = 5) == 2\n assert candidate(points = [10, 10, 10, 10, 10],m = 15) == 20\n assert candidate(points = [1000000, 500000, 250000],m = 1000000) == 100000000000\n assert candidate(points = [1, 2, 3],m = 5) == 2\n assert candidate(points = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29],m = 25) == 5\n assert candidate(points = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],m = 10) == 1\n assert candidate(points = [1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000],m = 50) == 5000\n assert candidate(points = [100, 100, 100, 100, 100, 100],m = 20) == 300\n assert candidate(points = [1000000, 900000, 800000, 700000, 600000, 500000, 400000, 300000, 200000, 100000],m = 50) == 1300000\n assert candidate(points = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20],m = 100) == 12\n assert candidate(points = [7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26],m = 50) == 27\n assert candidate(points = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2],m = 20) == 1\n assert candidate(points = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],m = 50) == 10\n assert candidate(points = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60],m = 60) == 36\n assert candidate(points = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8],m = 25) == 4\n assert candidate(points = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97],m = 500) == 235\n assert candidate(points = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],m = 1000) == 85\n assert candidate(points = [500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000],m = 10000000) == 500000000000\n assert candidate(points = [10, 20, 30, 40, 50, 60],m = 15) == 40\n assert candidate(points = [1000, 900, 800, 700, 600, 500, 400, 300, 200, 100],m = 30) == 700\n assert candidate(points = [2, 3, 1, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],m = 100) == 11\n assert candidate(points = [100, 200, 300, 400, 500, 600, 700],m = 20) == 500\n assert candidate(points = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],m = 18) == 3\n assert candidate(points = [1000000, 500000, 250000, 125000, 62500],m = 1000000) == 23809500000\n assert candidate(points = [50, 40, 30, 20, 10],m = 15) == 50\n assert candidate(points = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],m = 200) == 45\n assert candidate(points = [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11],m = 40) == 6\n assert candidate(points = [1, 10, 1, 10, 1, 10, 1, 10, 1, 10],m = 15) == 1\n assert candidate(points = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],m = 15) == 3\n assert candidate(points = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],m = 30) == 70\n assert candidate(points = [5, 8, 6, 7, 3, 4, 9, 10],m = 25) == 12\n assert candidate(points = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],m = 100) == 30\n assert candidate(points = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59],m = 200) == 53\n assert candidate(points = [10, 20, 30, 40, 50],m = 12) == 30\n assert candidate(points = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],m = 20) == 10\n assert candidate(points = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],m = 18) == 4\n assert candidate(points = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],m = 60) == 12\n assert candidate(points = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],m = 100) == 15\n assert candidate(points = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95],m = 25) == 35\n assert candidate(points = [1000000, 900000, 800000, 700000, 600000, 500000, 400000, 300000, 200000, 100000],m = 30) == 700000\n assert candidate(points = [1, 10, 1, 10, 1, 10, 1, 10, 1, 10],m = 20) == 2\n assert candidate(points = [10, 20, 30, 40, 50],m = 15) == 50\n assert candidate(points = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],m = 50) == 130\n assert candidate(points = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39],m = 50) == 13\n assert candidate(points = [10, 5, 20, 15, 30, 25, 40, 35, 50, 45],m = 30) == 35\n assert candidate(points = [1, 1000, 1, 1000, 1, 1000, 1, 1000, 1, 1000],m = 10000) == 1000\n assert candidate(points = [1000000, 900000, 800000, 700000, 600000, 500000, 400000, 300000, 200000, 100000],m = 1000000) == 27975000000\n assert candidate(points = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],m = 20) == 2\n assert candidate(points = [2, 5, 3, 8, 6, 4, 7, 1, 9],m = 25) == 5\n assert candidate(points = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],m = 20) == 50\n assert candidate(points = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],m = 30) == 5\n assert candidate(points = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200],m = 150) == 330\n assert candidate(points = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],m = 50) == 5\n assert candidate(points = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21],m = 30) == 9\n assert candidate(points = [9, 8, 7, 6, 5, 4, 3, 2, 1],m = 18) == 4\n assert candidate(points = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200, 210, 220, 230, 240, 250, 260, 270, 280, 290, 300],m = 150) == 290\n assert candidate(points = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20],m = 30) == 14\n assert candidate(points = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],m = 20) == 5\n assert candidate(points = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000],m = 30) == 700\n assert candidate(points = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100],m = 100) == 500\n assert candidate(points = [1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1],m = 30) == 1\n assert candidate(points = [1, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14],m = 40) == 8\n assert candidate(points = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],m = 30) == 6\n assert candidate(points = [100, 50, 200, 150, 300],m = 25) == 450\n assert candidate(points = [10000, 20000, 30000, 40000, 50000, 60000, 70000, 80000, 90000, 100000, 110000, 120000, 130000, 140000, 150000],m = 1500000) == 3709550000\n assert candidate(points = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50],m = 300) == 53\n assert candidate(points = [100000, 200000, 300000, 400000, 500000, 600000, 700000, 800000, 900000, 1000000],m = 100) == 2700000\n assert candidate(points = [1, 10, 100, 1000, 10000, 100000, 1000000, 500000, 250000, 125000],m = 50) == 21\n assert candidate(points = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],m = 20) == 3\n assert candidate(points = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47],m = 30) == 11\n assert candidate(points = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9, 2, 6, 5, 3, 5, 9, 2, 6, 5, 3, 5, 9, 2, 6, 5, 3, 5, 9, 2, 6, 5, 3, 5, 9, 2, 6, 5, 3, 5, 9, 2, 6, 5, 3, 5, 9, 2, 6, 5, 3, 5, 9],m = 100) == 4\n assert candidate(points = [1000000, 1000000, 1000000, 1000000, 1000000],m = 1000000) == 166666000000\n assert candidate(points = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],m = 20) == 5\n assert candidate(points = [5, 4, 3, 2, 1],m = 10) == 3\n assert candidate(points = [5, 3, 8, 6, 2, 7, 4, 9, 1],m = 18) == 3\n assert candidate(points = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49],m = 50) == 10\n assert candidate(points = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60],m = 100) == 38\n assert candidate(points = [100000, 90000, 80000, 70000, 60000],m = 30) == 360000\n assert candidate(points = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],m = 1000) == 12\n assert candidate(points = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, 99],m = 1000) == 262\n", "comparison": "exact"}, "public_tests": ["[2,4]\n3", "[1,2,3]\n5"], "hints": ["Can we use binary search?", "What happens if you fix the game score as x?", "We should go from i to (i + 1) back and forth, making the value for each index i (from left to right) no less than x."], "metadata": {"canonical_parameter_names": ["points", "m"], "leetcode_dataset_entry_point": "Solution().maxScore", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:25:41+00:00", "tests_total": 95, "tests_dropped": 1, "flags": [], "topic_tags": ["array", "binary-search", "greedy"]}, "language": "python", "interface": {"raw_signature": "def maxScore(self, points: List[int], m: int) -> int:", "container": "Solution", "callable": "maxScore", "parameters": [{"name": "points", "type": "List[int]"}, {"name": "m", "type": "int"}], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3452, "task_id": "sum-of-good-numbers", "difficulty": "Easy", "problem_description": "Given an array of integers nums and an integer k, an element nums[i] is considered good if it is strictly greater than the elements at indices i - k and i + k (if those indices exist). If neither of these indices exists, nums[i] is still considered good.\n\nReturn the sum of all the good elements in the array.\n\nExample 1:\n\nInput: nums = [1,3,2,1,5,4], k = 2\nOutput: 12\nExplanation:\nThe good numbers are nums[1] = 3, nums[4] = 5, and nums[5] = 4 because they are strictly greater than the numbers at indices i - k and i + k.\n\nExample 2:\n\nInput: nums = [2,1], k = 1\nOutput: 2\nExplanation:\nThe only good number is nums[0] = 2 because it is strictly greater than nums[1].\n\nConstraints:\n\n- 2 <= nums.length <= 100\n- 1 <= nums[i] <= 1000\n- 1 <= k <= floor(nums.length / 2)\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(nums = [2, 1],k = 1) == 2\n assert candidate(nums = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5],k = 2) == 14\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 3) == 27\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 1) == 10\n assert candidate(nums = [1, 3, 2, 1, 5, 4],k = 2) == 12\n assert candidate(nums = [5, 1, 4, 1, 5, 9, 2, 6],k = 2) == 19\n assert candidate(nums = [5, 6, 7, 8, 9, 10, 11, 12],k = 3) == 33\n assert candidate(nums = [5, 6, 7, 8, 9, 10],k = 3) == 27\n assert candidate(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 2) == 19\n assert candidate(nums = [5, 4, 3, 2, 1],k = 1) == 5\n assert candidate(nums = [5, 4, 3, 2, 1],k = 2) == 9\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 4) == 34\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],k = 3) == 270\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],k = 3) == 270\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 2) == 19\n assert candidate(nums = [10, 20, 30, 40, 50],k = 1) == 50\n assert candidate(nums = [10, 9, 8, 7, 6, 5],k = 2) == 19\n assert candidate(nums = [20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19],k = 4) == 132\n assert candidate(nums = [1, 3, 5, 7, 9, 7, 5, 3, 1],k = 2) == 9\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, 99],k = 15) == 1275\n assert candidate(nums = [7, 2, 3, 10, 1, 4, 8, 6, 9, 5, 11, 12, 13, 4, 7, 2, 5, 9, 10, 8, 6, 3, 4, 5],k = 4) == 91\n assert candidate(nums = [5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 15, 14, 13, 12, 11, 20, 19, 18, 17, 16],k = 4) == 104\n assert candidate(nums = [10, 20, 30, 40, 50, 40, 30, 20, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9],k = 4) == 160\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 5) == 0\n assert candidate(nums = [1000, 999, 998, 997, 996, 995, 994, 993, 992, 991, 990, 989, 988, 987, 986],k = 5) == 4990\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9],k = 4) == 60\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10],k = 2) == 190\n assert candidate(nums = [300, 200, 100, 400, 300, 200, 100, 500, 400, 300, 200, 100],k = 3) == 1600\n assert candidate(nums = [5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1],k = 2) == 0\n assert candidate(nums = [10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20, 10, 20],k = 4) == 0\n assert candidate(nums = [30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 5) == 140\n assert candidate(nums = [7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21],k = 3) == 60\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11, 10, 12],k = 3) == 23\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 5) == 0\n assert candidate(nums = [50, 45, 60, 55, 70, 65, 80, 75, 90, 85, 100, 95, 110, 105, 120, 115, 130, 125, 140, 135],k = 4) == 530\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],k = 3) == 33\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 4) == 28\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150],k = 6) == 750\n assert candidate(nums = [1000, 1, 1000, 1, 1000, 1, 1000, 1, 1000],k = 2) == 0\n assert candidate(nums = [3, 6, 1, 5, 9, 4, 7, 8, 2, 10, 12, 11, 13, 15, 14, 17, 16, 19, 18, 20],k = 5) == 95\n assert candidate(nums = [1, 100, 2, 99, 3, 98, 4, 97, 5, 96, 6, 95, 7, 94, 8, 93, 9, 92, 10, 91],k = 5) == 955\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 3) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 40, 30, 20, 10, 5, 15, 25, 35, 45, 55],k = 5) == 325\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 5) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1],k = 5) == 45\n assert candidate(nums = [1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4],k = 4) == 30\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 3) == 57\n assert candidate(nums = [1, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5],k = 2) == 26\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 4) == 74\n assert candidate(nums = [1, 3, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25],k = 6) == 135\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 5) == 65\n assert candidate(nums = [500, 400, 300, 200, 100, 200, 300, 400, 500, 400, 300, 200, 100],k = 4) == 2200\n assert candidate(nums = [7, 10, 4, 3, 20, 15, 8, 25, 5, 12],k = 3) == 59\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2],k = 2) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 5) == 90\n assert candidate(nums = [50, 60, 50, 70, 50, 80, 50, 90, 50, 100, 50, 110, 50, 120, 50, 130, 50, 140, 50, 150, 50, 160, 50, 170, 50, 180, 50, 190, 50, 200],k = 3) == 1950\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30],k = 5) == 140\n assert candidate(nums = [5, 1, 4, 2, 3, 7, 6, 8, 9, 10, 11, 12, 13, 14, 15],k = 3) == 47\n assert candidate(nums = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50],k = 5) == 0\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2],k = 2) == 0\n assert candidate(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 10, 20, 30, 40, 50],k = 5) == 400\n assert candidate(nums = [5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],k = 4) == 47\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70],k = 10) == 955\n assert candidate(nums = [5, 8, 6, 7, 9, 3, 4, 10, 2, 11, 12, 13, 14, 15, 16, 17],k = 3) == 61\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 20) == 0\n assert candidate(nums = [10, 20, 30, 25, 15, 40, 35, 50, 45, 60, 55, 70, 65, 80, 75, 90, 85, 100, 95, 110],k = 5) == 480\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 3) == 57\n assert candidate(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23],k = 4) == 80\n assert candidate(nums = [5, 10, 5, 15, 5, 20, 5, 25, 5, 30, 5, 35, 5, 40, 5, 45, 5, 50, 5, 55, 5, 60, 5, 65, 5, 70, 5, 75, 5, 80, 5, 85, 5, 90, 5, 95, 5, 100],k = 2) == 100\n assert candidate(nums = [10, 20, 15, 30, 25, 40, 35, 50, 45, 60, 55, 70, 65, 80, 75],k = 3) == 220\n assert candidate(nums = [1000, 1, 1000, 1, 1000, 1, 1000, 1, 1000, 1, 1000, 1, 1000, 1],k = 2) == 0\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],k = 3) == 54\n assert candidate(nums = [999, 998, 997, 996, 995, 994, 993, 992, 991, 990, 989, 988, 987, 986, 985],k = 3) == 2994\n assert candidate(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],k = 5) == 80\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],k = 4) == 54\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 5) == 90\n assert candidate(nums = [50, 25, 75, 20, 80, 10, 90, 5, 100, 55, 60, 65, 70, 75, 80, 85, 95, 100, 105, 110],k = 4) == 645\n assert candidate(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2],k = 2) == 0\n assert candidate(nums = [100, 200, 150, 250, 200, 300, 250, 350, 300, 400],k = 2) == 700\n assert candidate(nums = [7, 8, 9, 10, 5, 6, 7, 8, 9, 10],k = 3) == 54\n assert candidate(nums = [1000, 1, 1000, 1, 1000, 1, 1000, 1, 1000, 1, 1000, 1, 1000, 1, 1000],k = 3) == 8000\n assert candidate(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],k = 2) == 0\n assert candidate(nums = [100, 1, 200, 2, 300, 3, 400, 4, 500, 5, 600, 6, 700, 7, 800, 8, 900, 9],k = 2) == 909\n assert candidate(nums = [5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5],k = 2) == 0\n assert candidate(nums = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 5, 15, 25, 35, 45],k = 5) == 480\n assert candidate(nums = [200, 100, 300, 50, 400, 150, 600, 250, 700, 350, 800, 450],k = 2) == 1350\n assert candidate(nums = [1, 2, 3, 2, 1, 4, 5, 4, 3, 2, 1, 6, 7, 6, 5, 4, 3, 2, 1, 8],k = 2) == 23\n assert candidate(nums = [1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1],k = 2) == 12\n assert candidate(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100, 105, 110, 115, 120, 125, 130, 135, 140, 145, 150],k = 7) == 945\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 2) == 0\n assert candidate(nums = [1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5],k = 2) == 0\n assert candidate(nums = [25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 6) == 135\n assert candidate(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],k = 5) == 90\n assert candidate(nums = [8, 6, 4, 2, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, 99],k = 10) == 900\n assert candidate(nums = [8, 12, 4, 16, 2, 20, 6, 22, 10, 24, 14, 26, 18, 28, 21],k = 4) == 101\n assert candidate(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35],k = 7) == 224\n assert candidate(nums = [50, 40, 30, 20, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110],k = 4) == 470\n assert candidate(nums = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50],k = 10) == 955\n assert candidate(nums = [99, 100, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86],k = 5) == 490\n assert candidate(nums = [150, 145, 140, 135, 130, 125, 120, 115, 110, 105, 100, 95, 90, 85, 80, 75, 70, 65, 60, 55, 50, 45, 40, 35, 30, 25, 20, 15, 10, 5],k = 5) == 700\n assert candidate(nums = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11, 10, 12],k = 2) == 22\n assert candidate(nums = [5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],k = 6) == 110\n assert candidate(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],k = 2) == 0\n assert candidate(nums = [500, 400, 300, 200, 100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90],k = 7) == 1697\n", "comparison": "exact"}, "public_tests": ["[1,3,2,1,5,4]\n2", "[2,1]\n1"], "hints": ["For each index, check if nums[i] is strictly greater than nums[i - k] and nums[i + k]."], "metadata": {"canonical_parameter_names": ["nums", "k"], "leetcode_dataset_entry_point": "Solution().sumOfGoodNumbers", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:25:45+00:00", "tests_total": 109, "tests_dropped": 5, "flags": [], "topic_tags": ["array"]}, "language": "python", "interface": {"raw_signature": "def sumOfGoodNumbers(self, nums: List[int], k: int) -> int:", "container": "Solution", "callable": "sumOfGoodNumbers", "parameters": [{"name": "nums", "type": "List[int]"}, {"name": "k", "type": "int"}], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} -{"question_id": 3453, "task_id": "separate-squares-i", "difficulty": "Medium", "problem_description": "You are given a 2D integer array squares. Each squares[i] = [x_i, y_i, l_i] represents the coordinates of the bottom-left point and the side length of a square parallel to the x-axis.\n\nFind the minimum y-coordinate value of a horizontal line such that the total area of the squares above the line equals the total area of the squares below the line.\n\nAnswers within 10^-5 of the actual answer will be accepted.\n\nNote: Squares may overlap. Overlapping areas should be counted multiple times.\n\nExample 1:\n\nInput: squares = [[0,0,1],[2,2,1]]\nOutput: 1.00000\nExplanation:\nAny horizontal line between y = 1 and y = 2 will have 1 square unit above it and 1 square unit below it. The lowest option is 1.\n\nExample 2:\n\nInput: squares = [[0,0,2],[1,1,1]]\nOutput: 1.16667\nExplanation:\nThe areas are:\n- Below the line: 7/6 * 2 (Red) + 1/6 (Blue) = 15/6 = 2.5.\n- Above the line: 5/6 * 2 (Red) + 5/6 (Blue) = 15/6 = 2.5.\n\nSince the areas above and below the line are equal, the output is 7/6 = 1.16667.\n\nConstraints:\n\n- 1 <= squares.length <= 5 * 10^4\n- squares[i] = [x_i, y_i, l_i]\n- squares[i].length == 3\n- 0 <= x_i, y_i <= 10^9\n- 1 <= l_i <= 10^9\n- The total area of all the squares will not exceed 10^12.\n", "canonical_tests": {"language": "python", "source": "def answers_match(result, expected):\n \"\"\"Decimal answers are accepted within 1e-5 (absolute or relative), as on LeetCode.\"\"\"\n import math\n if isinstance(result, list) and isinstance(expected, list):\n return len(result) == len(expected) and all(answers_match(r, e) for r, e in zip(result, expected))\n numbers = (int, float)\n if isinstance(result, numbers) and isinstance(expected, numbers) and not isinstance(result, bool):\n return math.isclose(result, expected, rel_tol=1e-5, abs_tol=1e-5)\n return result == expected\n\n\ndef check(candidate):\n assert answers_match(candidate(squares=[[0, 0, 10], [5, 5, 10], [10, 10, 10]]), 10.0)\n assert answers_match(candidate(squares=[[0, 0, 4], [2, 2, 2], [4, 4, 1]]), 2.4166666666666665)\n assert answers_match(candidate(squares=[[0, 0, 3], [3, 3, 3], [6, 6, 3]]), 4.5)\n assert answers_match(candidate(squares=[[0, 0, 3], [3, 3, 3]]), 3.0)\n assert answers_match(candidate(squares=[[0, 0, 5], [5, 5, 5], [2, 2, 2], [3, 3, 3]]), 4.5625)\n assert answers_match(candidate(squares=[[5, 5, 5], [10, 10, 5], [15, 15, 5]]), 12.5)\n assert answers_match(candidate(squares=[[1, 1, 2], [2, 2, 2], [3, 3, 2]]), 3.0)\n assert answers_match(candidate(squares=[[0, 0, 10], [5, 5, 5], [10, 0, 10]]), 5.5)\n assert answers_match(candidate(squares=[[0, 0, 3], [1, 1, 2], [2, 2, 1]]), 1.8)\n assert answers_match(candidate(squares=[[0, 0, 2], [1, 1, 1]]), 1.1666666666666667)\n assert answers_match(candidate(squares=[[0, 0, 5], [1, 1, 3], [2, 2, 2], [3, 3, 1]]), 2.65)\n assert answers_match(candidate(squares=[[0, 0, 4], [2, 2, 2], [1, 1, 2]]), 2.25)\n assert answers_match(candidate(squares=[[0, 0, 3], [3, 3, 3], [1, 1, 1]]), 2.8333333333333335)\n assert answers_match(candidate(squares=[[0, 0, 1], [2, 2, 1]]), 1.0)\n assert answers_match(candidate(squares=[[0, 0, 5], [5, 5, 5], [10, 10, 5]]), 7.5)\n assert answers_match(candidate(squares=[[0, 0, 3], [1, 1, 2], [4, 4, 1]]), 1.8)\n assert answers_match(candidate(squares=[[0, 0, 2], [0, 2, 2], [2, 0, 2], [2, 2, 2], [1, 1, 2], [3, 3, 2]]), 2.3333333333333335)\n assert answers_match(candidate(squares=[[0, 0, 5], [3, 3, 5], [6, 6, 5], [9, 9, 5]]), 7.0)\n assert answers_match(candidate(squares=[[0, 0, 1000], [100, 100, 500], [200, 200, 300], [300, 300, 200], [400, 400, 100], [0, 500, 1000], [100, 600, 500], [200, 700, 300], [300, 800, 200], [400, 900, 100]]), 717.8571428571429)\n assert answers_match(candidate(squares=[[0, 0, 7], [2, 1, 5], [4, 2, 3], [6, 3, 1], [8, 4, 1], [10, 5, 1]]), 3.5625)\n assert answers_match(candidate(squares=[[0, 0, 10], [5, 5, 5], [10, 10, 3], [15, 15, 2]]), 6.266666666666667)\n assert answers_match(candidate(squares=[[0, 0, 10], [5, 5, 5], [10, 10, 1], [12, 12, 3], [15, 15, 2]]), 6.3)\n assert answers_match(candidate(squares=[[0, 0, 10], [5, 5, 5], [10, 10, 1], [15, 15, 2], [20, 20, 3]]), 6.3)\n assert answers_match(candidate(squares=[[10, 10, 10], [10, 20, 10], [10, 30, 10], [20, 10, 10], [20, 20, 10], [20, 30, 10], [30, 10, 10], [30, 20, 10], [30, 30, 10]]), 25.0)\n assert answers_match(candidate(squares=[[0, 0, 3], [3, 3, 3], [6, 6, 3], [9, 9, 3], [12, 12, 3], [15, 15, 3], [18, 18, 3], [21, 21, 3], [24, 24, 3]]), 13.5)\n assert answers_match(candidate(squares=[[0, 0, 100], [50, 50, 100], [100, 0, 100], [150, 50, 100]]), 75.0)\n assert answers_match(candidate(squares=[[0, 0, 1], [0, 1, 1], [0, 2, 1], [0, 3, 1], [0, 4, 1], [0, 5, 1], [0, 6, 1], [0, 7, 1], [0, 8, 1], [0, 9, 1]]), 5.0)\n assert answers_match(candidate(squares=[[1, 1, 2], [1, 3, 2], [1, 5, 2], [1, 7, 2], [1, 9, 2], [1, 11, 2], [1, 13, 2], [1, 15, 2], [1, 17, 2], [1, 19, 2]]), 11.0)\n assert answers_match(candidate(squares=[[0, 0, 1], [0, 1, 1], [0, 2, 1], [0, 3, 1], [0, 4, 1], [0, 5, 1], [0, 6, 1], [0, 7, 1], [0, 8, 1], [0, 9, 1], [0, 10, 1]]), 5.5)\n assert answers_match(candidate(squares=[[0, 0, 7], [7, 7, 7], [3, 3, 3], [5, 5, 5], [1, 1, 1], [9, 9, 1]]), 6.833333333333333)\n assert answers_match(candidate(squares=[[0, 0, 1], [1, 1, 1], [2, 2, 1], [3, 3, 1], [4, 4, 1], [5, 5, 1], [6, 6, 1], [7, 7, 1], [8, 8, 1], [9, 9, 1], [10, 10, 1]]), 5.5)\n assert answers_match(candidate(squares=[[0, 0, 5], [3, 2, 3], [1, 4, 2], [6, 1, 4]]), 3.083333333333333)\n assert answers_match(candidate(squares=[[0, 0, 100], [20, 0, 90], [40, 0, 80], [60, 0, 70], [80, 0, 60], [100, 0, 50], [120, 0, 40], [140, 0, 30], [160, 0, 20], [180, 0, 10]]), 36.42857142857143)\n assert answers_match(candidate(squares=[[0, 0, 100], [20, 20, 50], [40, 40, 25], [60, 60, 12.5], [80, 80, 6.25]]), 49.48660714285714)\n assert answers_match(candidate(squares=[[1, 1, 3], [4, 4, 3], [7, 7, 3], [10, 10, 3], [13, 13, 3], [16, 16, 3]]), 10.0)\n assert answers_match(candidate(squares=[[0, 0, 10], [10, 0, 10], [5, 5, 5], [15, 5, 5], [20, 0, 10], [25, 0, 10]]), 5.5)\n assert answers_match(candidate(squares=[[10, 10, 10], [15, 15, 10], [20, 20, 10], [25, 25, 10], [30, 30, 10], [35, 35, 10], [40, 40, 10], [45, 45, 10], [50, 50, 10]]), 35.0)\n assert answers_match(candidate(squares=[[0, 0, 1], [2, 0, 1], [4, 0, 1], [6, 0, 1], [8, 0, 1], [10, 0, 1], [12, 0, 1], [14, 0, 1], [16, 0, 1], [18, 0, 1], [20, 0, 1]]), 0.5)\n assert answers_match(candidate(squares=[[10, 10, 5], [15, 15, 5], [20, 20, 5], [25, 25, 5], [30, 30, 5], [35, 35, 5], [40, 40, 5], [45, 45, 5]]), 30.0)\n assert answers_match(candidate(squares=[[0, 0, 10], [1, 0, 9], [2, 0, 8], [3, 0, 7], [4, 0, 6], [5, 0, 5], [6, 0, 4], [7, 0, 3], [8, 0, 2], [9, 0, 1]]), 3.642857142857143)\n assert answers_match(candidate(squares=[[0, 0, 20], [5, 5, 10], [10, 10, 5], [15, 15, 2.5], [20, 20, 1.25]]), 10.46875)\n assert answers_match(candidate(squares=[[0, 0, 50], [10, 10, 40], [20, 20, 30], [30, 30, 20], [40, 40, 10], [50, 50, 5]]), 31.160714285714285)\n assert answers_match(candidate(squares=[[0, 0, 1], [1, 0, 1], [2, 0, 1], [3, 0, 1], [4, 0, 1], [5, 0, 1], [6, 0, 1], [7, 0, 1], [8, 0, 1], [9, 0, 1], [10, 0, 1], [11, 0, 1], [12, 0, 1], [13, 0, 1], [14, 0, 1], [15, 0, 1], [16, 0, 1], [17, 0, 1], [18, 0, 1], [19, 0, 1]]), 0.5)\n assert answers_match(candidate(squares=[[0, 0, 100], [25, 25, 50], [50, 50, 25], [75, 75, 12.5]]), 52.232142857142854)\n assert answers_match(candidate(squares=[[0, 0, 10], [5, 5, 10], [10, 0, 10], [5, 10, 10]]), 8.333333333333334)\n assert answers_match(candidate(squares=[[0, 0, 5], [1, 1, 3], [2, 2, 4], [3, 3, 2], [4, 4, 1]]), 3.1785714285714284)\n assert answers_match(candidate(squares=[[0, 0, 10], [0, 10, 10], [0, 20, 10], [10, 0, 10], [10, 10, 10], [10, 20, 10], [20, 0, 10], [20, 10, 10], [20, 20, 10]]), 15.0)\n assert answers_match(candidate(squares=[[0, 0, 10], [1, 1, 9], [2, 2, 8], [3, 3, 7], [4, 4, 6], [5, 5, 5], [6, 6, 4], [7, 7, 3], [8, 8, 2], [9, 9, 1]]), 6.357142857142857)\n assert answers_match(candidate(squares=[[2, 0, 6], [8, 0, 4], [5, 5, 3], [1, 1, 5]]), 3.2)\n assert answers_match(candidate(squares=[[0, 0, 100], [50, 0, 50], [100, 0, 25], [125, 0, 12.5]]), 39.0625)\n assert answers_match(candidate(squares=[[1, 1, 1], [2, 2, 1], [3, 3, 1], [4, 4, 1], [5, 5, 1], [6, 6, 1]]), 4.0)\n assert answers_match(candidate(squares=[[0, 0, 2], [1, 1, 2], [2, 2, 2], [3, 3, 2], [4, 4, 2], [5, 5, 2], [6, 6, 2], [7, 7, 2], [8, 8, 2], [9, 9, 2], [10, 10, 2], [11, 11, 2], [12, 12, 2], [13, 13, 2], [14, 14, 2]]), 8.0)\n assert answers_match(candidate(squares=[[1, 1, 3], [4, 4, 3], [7, 7, 3], [10, 10, 3], [2, 2, 2], [5, 5, 2], [8, 8, 2], [11, 11, 2]]), 7.0)\n assert answers_match(candidate(squares=[[0, 0, 10], [2, 1, 10], [4, 2, 10], [6, 3, 10], [8, 4, 10], [10, 5, 10]]), 7.5)\n assert answers_match(candidate(squares=[[0, 0, 100], [20, 20, 50], [40, 40, 30], [60, 60, 20], [80, 80, 10], [10, 10, 80], [30, 30, 60], [50, 50, 40], [70, 70, 20]]), 54.861111111111114)\n assert answers_match(candidate(squares=[[1, 1, 3], [2, 2, 3], [1, 4, 3], [3, 5, 3]]), 4.5)\n assert answers_match(candidate(squares=[[0, 0, 5], [5, 0, 5], [10, 0, 5], [15, 0, 5], [20, 0, 5], [25, 0, 5], [30, 0, 5], [35, 0, 5], [40, 0, 5]]), 2.5)\n assert answers_match(candidate(squares=[[0, 0, 5], [0, 5, 5], [5, 0, 5], [5, 5, 5], [2.5, 2.5, 1], [7.5, 7.5, 1]]), 5.0)\n assert answers_match(candidate(squares=[[0, 0, 10], [5, 0, 10], [10, 0, 10], [15, 0, 10], [20, 0, 10], [25, 0, 10], [30, 0, 10], [35, 0, 10], [40, 0, 10], [45, 0, 10]]), 5.0)\n assert answers_match(candidate(squares=[[0, 0, 1000], [100, 100, 500], [200, 200, 300], [300, 300, 200], [400, 400, 100], [500, 500, 50], [600, 600, 25], [700, 700, 10], [800, 800, 5], [900, 900, 1]]), 431.7264285714286)\n assert answers_match(candidate(squares=[[0, 0, 1], [1, 0, 1], [2, 0, 1], [3, 0, 1], [4, 0, 1], [5, 0, 1], [6, 0, 1], [7, 0, 1], [8, 0, 1], [9, 0, 1], [10, 0, 1], [11, 0, 1], [12, 0, 1], [13, 0, 1], [14, 0, 1], [15, 0, 1], [16, 0, 1], [17, 0, 1], [18, 0, 1], [19, 0, 1], [20, 0, 1]]), 0.5)\n assert answers_match(candidate(squares=[[0, 0, 10], [0, 10, 10], [0, 20, 10], [0, 30, 10], [0, 40, 10], [0, 50, 10], [0, 60, 10], [0, 70, 10], [0, 80, 10], [0, 90, 10], [0, 100, 10], [0, 110, 10], [0, 120, 10], [0, 130, 10], [0, 140, 10], [0, 150, 10]]), 80.0)\n assert answers_match(candidate(squares=[[0, 0, 5], [1, 1, 4], [2, 2, 3], [3, 3, 2], [4, 4, 1]]), 3.107142857142857)\n assert answers_match(candidate(squares=[[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], [13, 14, 15]]), 17.166666666666668)\n assert answers_match(candidate(squares=[[1, 1, 5], [2, 2, 5], [3, 3, 5], [4, 4, 5], [5, 5, 5]]), 5.5)\n assert answers_match(candidate(squares=[[0, 0, 6], [1, 3, 4], [3, 0, 4], [5, 1, 4]]), 3.2222222222222223)\n assert answers_match(candidate(squares=[[0, 0, 100], [10, 10, 50], [20, 20, 30], [30, 30, 20], [40, 40, 10], [0, 50, 100], [10, 60, 50], [20, 70, 30], [30, 80, 20], [40, 90, 10]]), 71.78571428571429)\n assert answers_match(candidate(squares=[[0, 0, 10], [5, 5, 10], [10, 10, 10], [15, 15, 10]]), 12.5)\n assert answers_match(candidate(squares=[[0, 0, 10], [2, 0, 5], [5, 5, 3], [7, 7, 2], [8, 8, 1]]), 4.633333333333334)\n assert answers_match(candidate(squares=[[10, 10, 5], [15, 15, 4], [20, 20, 3], [25, 25, 2], [30, 30, 1]]), 15.625)\n assert answers_match(candidate(squares=[[0, 0, 1], [1, 0, 1], [2, 0, 1], [3, 0, 1], [4, 0, 1], [5, 0, 1], [6, 0, 1], [7, 0, 1], [8, 0, 1], [9, 0, 1], [0, 1, 1], [1, 1, 1], [2, 1, 1], [3, 1, 1], [4, 1, 1], [5, 1, 1], [6, 1, 1], [7, 1, 1], [8, 1, 1], [9, 1, 1]]), 1.0)\n assert answers_match(candidate(squares=[[0, 0, 5], [1, 1, 5], [2, 2, 5], [3, 3, 5], [4, 4, 5], [0, 5, 5], [1, 6, 5], [2, 7, 5], [3, 8, 5], [4, 9, 5]]), 7.0)\n assert answers_match(candidate(squares=[[0, 0, 1], [1, 1, 1], [2, 2, 1], [3, 3, 1], [4, 4, 1], [5, 5, 1], [6, 6, 1], [7, 7, 1], [8, 8, 1], [9, 9, 1]]), 5.0)\n assert answers_match(candidate(squares=[[0, 0, 10], [5, 5, 10], [10, 10, 10], [15, 15, 10], [20, 20, 10]]), 15.0)\n assert answers_match(candidate(squares=[[0, 0, 5], [5, 5, 5], [10, 10, 5], [15, 15, 5]]), 10.0)\n assert answers_match(candidate(squares=[[0, 0, 8], [1, 1, 7], [2, 2, 6], [3, 3, 5], [4, 4, 4], [5, 5, 3], [6, 6, 2], [7, 7, 1]]), 5.0606060606060606)\n assert answers_match(candidate(squares=[[0, 0, 7], [3, 3, 5], [6, 6, 3], [9, 9, 1], [1, 1, 6], [4, 4, 4], [7, 7, 2]]), 4.863636363636363)\n assert answers_match(candidate(squares=[[0, 0, 20], [5, 10, 10], [10, 20, 5], [15, 30, 2.5], [20, 40, 1.25]]), 12.213541666666666)\n assert answers_match(candidate(squares=[[0, 0, 1], [1, 1, 1], [2, 2, 1], [3, 3, 1], [4, 4, 1], [5, 5, 1]]), 3.0)\n assert answers_match(candidate(squares=[[0, 0, 1], [1, 0, 1], [2, 0, 1], [3, 0, 1], [4, 0, 1], [5, 0, 1], [6, 0, 1], [7, 0, 1], [8, 0, 1], [9, 0, 1]]), 0.5)\n assert answers_match(candidate(squares=[[0, 0, 10], [1, 2, 10], [2, 4, 10], [3, 6, 10], [4, 8, 10], [5, 1, 10], [6, 3, 10], [7, 5, 10], [8, 7, 10], [9, 9, 10]]), 9.5)\n assert answers_match(candidate(squares=[[0, 0, 1], [1, 2, 1], [2, 4, 1], [3, 6, 1], [4, 8, 1], [5, 10, 1], [6, 12, 1]]), 6.5)\n assert answers_match(candidate(squares=[[1, 1, 4], [1, 5, 4], [5, 1, 4], [5, 5, 4]]), 5.0)\n assert answers_match(candidate(squares=[[0, 0, 100], [20, 0, 80], [40, 0, 60], [60, 0, 40], [80, 0, 20]]), 37.85714285714286)\n assert answers_match(candidate(squares=[[0, 0, 10], [1, 2, 3], [4, 6, 2], [7, 8, 4]]), 5.55)\n assert answers_match(candidate(squares=[[1, 1, 1], [1, 2, 1], [1, 3, 1], [1, 4, 1], [1, 5, 1], [1, 6, 1], [1, 7, 1], [1, 8, 1], [1, 9, 1]]), 5.5)\n assert answers_match(candidate(squares=[[0, 0, 20], [5, 5, 20], [10, 10, 20], [15, 15, 20], [20, 20, 20], [0, 20, 20], [5, 25, 20], [10, 30, 20], [15, 35, 20], [20, 40, 20]]), 30.0)\n assert answers_match(candidate(squares=[[0, 0, 10], [5, 5, 5], [10, 10, 2], [15, 15, 1]]), 6.0)\n assert answers_match(candidate(squares=[[0, 0, 8], [4, 4, 4], [8, 0, 8], [12, 4, 4], [16, 0, 8], [20, 4, 4]]), 4.666666666666667)\n assert answers_match(candidate(squares=[[0, 0, 1], [1, 1, 2], [2, 2, 3], [3, 3, 4], [4, 4, 5]]), 5.055555555555555)\n assert answers_match(candidate(squares=[[1, 1, 2], [3, 3, 2], [5, 5, 2], [7, 7, 2], [9, 9, 2]]), 6.0)\n assert answers_match(candidate(squares=[[0, 0, 1], [0, 1, 1], [0, 2, 1], [0, 3, 1], [0, 4, 1], [0, 5, 1], [0, 6, 1], [0, 7, 1], [0, 8, 1], [0, 9, 1], [0, 10, 1], [0, 11, 1], [0, 12, 1], [0, 13, 1], [0, 14, 1], [0, 15, 1], [0, 16, 1], [0, 17, 1], [0, 18, 1], [0, 19, 1]]), 10.0)\n assert answers_match(candidate(squares=[[0, 0, 1], [0, 1, 1], [0, 2, 1], [0, 3, 1], [0, 4, 1]]), 2.5)\n assert answers_match(candidate(squares=[[0, 0, 10], [5, 5, 5], [10, 10, 2]]), 5.966666666666667)\n assert answers_match(candidate(squares=[[0, 0, 5], [5, 0, 5], [10, 0, 5], [15, 0, 5]]), 2.5)\n assert answers_match(candidate(squares=[[0, 0, 5], [3, 0, 5], [6, 0, 5], [9, 0, 5]]), 2.5)\n assert answers_match(candidate(squares=[[0, 0, 10], [0, 10, 10], [0, 20, 10], [0, 30, 10], [0, 40, 10], [0, 50, 10], [0, 60, 10], [0, 70, 10], [0, 80, 10], [0, 90, 10]]), 50.0)\n assert answers_match(candidate(squares=[[1, 1, 10], [2, 2, 10], [3, 3, 10], [4, 4, 10], [5, 5, 10], [6, 6, 10], [7, 7, 10], [8, 8, 10], [9, 9, 10]]), 10.0)\n assert answers_match(candidate(squares=[[0, 0, 2], [1, 0, 2], [2, 0, 2], [3, 0, 2], [4, 0, 2], [5, 0, 2], [6, 0, 2], [7, 0, 2], [8, 0, 2], [9, 0, 2]]), 1.0)\n assert answers_match(candidate(squares=[[1, 1, 1], [1, 2, 1], [1, 3, 1], [1, 4, 1], [1, 5, 1]]), 3.5)\n assert answers_match(candidate(squares=[[1, 1, 1], [2, 2, 2], [3, 3, 3], [4, 4, 4], [5, 5, 5], [6, 6, 6], [7, 7, 7], [8, 8, 8], [9, 9, 9]]), 10.583333333333334)\n", "comparison": "float"}, "public_tests": ["[[0,0,1],[2,2,1]]", "[[0,0,2],[1,1,1]]"], "hints": ["Binary search on the answer."], "metadata": {"canonical_parameter_names": ["squares"], "leetcode_dataset_entry_point": "Solution().separateSquares", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:25:48+00:00", "tests_total": 107, "tests_dropped": 6, "flags": ["decimal_answer", "has_images"], "topic_tags": ["array", "binary-search"]}, "language": "python", "interface": {"raw_signature": "def separateSquares(self, squares: List[List[int]]) -> float:", "container": "Solution", "callable": "separateSquares", "parameters": [{"name": "squares", "type": "List[List[int]]"}], "return_type": "float", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} -{"question_id": 3454, "task_id": "separate-squares-ii", "difficulty": "Hard", "problem_description": "You are given a 2D integer array squares. Each squares[i] = [x_i, y_i, l_i] represents the coordinates of the bottom-left point and the side length of a square parallel to the x-axis.\n\nFind the minimum y-coordinate value of a horizontal line such that the total area covered by squares above the line equals the total area covered by squares below the line.\n\nAnswers within 10^-5 of the actual answer will be accepted.\n\nNote: Squares may overlap. Overlapping areas should be counted only once in this version.\n\nExample 1:\n\nInput: squares = [[0,0,1],[2,2,1]]\nOutput: 1.00000\nExplanation:\nAny horizontal line between y = 1 and y = 2 results in an equal split, with 1 square unit above and 1 square unit below. The minimum y-value is 1.\n\nExample 2:\n\nInput: squares = [[0,0,2],[1,1,1]]\nOutput: 1.00000\nExplanation:\nSince the blue square overlaps with the red square, it will not be counted again. Thus, the line y = 1 splits the squares into two equal parts.\n\nConstraints:\n\n- 1 <= squares.length <= 5 * 10^4\n- squares[i] = [x_i, y_i, l_i]\n- squares[i].length == 3\n- 0 <= x_i, y_i <= 10^9\n- 1 <= l_i <= 10^9\n- The total area of all the squares will not exceed 10^15.\n", "canonical_tests": {"language": "python", "source": "def answers_match(result, expected):\n \"\"\"Decimal answers are accepted within 1e-5 (absolute or relative), as on LeetCode.\"\"\"\n import math\n if isinstance(result, list) and isinstance(expected, list):\n return len(result) == len(expected) and all(answers_match(r, e) for r, e in zip(result, expected))\n numbers = (int, float)\n if isinstance(result, numbers) and isinstance(expected, numbers) and not isinstance(result, bool):\n return math.isclose(result, expected, rel_tol=1e-5, abs_tol=1e-5)\n return result == expected\n\n\ndef check(candidate):\n assert answers_match(candidate(squares=[[0, 0, 1], [1, 1, 1], [2, 2, 1], [3, 3, 1]]), 2.0)\n assert answers_match(candidate(squares=[[1, 1, 2], [2, 0, 2], [0, 2, 2]]), 2.0)\n assert answers_match(candidate(squares=[[0, 0, 4], [2, 2, 2], [1, 1, 1], [3, 3, 1]]), 2.0)\n assert answers_match(candidate(squares=[[0, 0, 5], [2, 2, 3], [1, 1, 2], [3, 3, 2], [4, 4, 1]]), 2.5)\n assert answers_match(candidate(squares=[[0, 0, 5], [5, 5, 5], [10, 10, 5], [15, 15, 5]]), 10.0)\n assert answers_match(candidate(squares=[[0, 0, 3], [1, 1, 2], [2, 2, 1]]), 1.5)\n assert answers_match(candidate(squares=[[0, 0, 2], [1, 1, 1]]), 1.0)\n assert answers_match(candidate(squares=[[0, 0, 10], [5, 5, 5], [10, 10, 1]]), 5.05)\n assert answers_match(candidate(squares=[[0, 0, 1], [2, 2, 1]]), 1.0)\n assert answers_match(candidate(squares=[[0, 0, 5], [5, 5, 5], [10, 10, 5]]), 7.5)\n assert answers_match(candidate(squares=[[0, 0, 4], [1, 1, 4], [2, 2, 4], [3, 3, 4]]), 3.5)\n assert answers_match(candidate(squares=[[0, 0, 3], [1, 1, 3], [2, 2, 3]]), 2.5)\n assert answers_match(candidate(squares=[[0, 0, 3], [1, 1, 2], [4, 4, 1]]), 1.6666666666666665)\n assert answers_match(candidate(squares=[[0, 0, 10], [1, 2, 8], [2, 4, 6], [3, 6, 4], [4, 8, 2], [5, 10, 1], [6, 8, 2], [7, 6, 4], [8, 4, 6], [9, 2, 8], [10, 0, 10]]), 5.025)\n assert answers_match(candidate(squares=[[0, 0, 1000], [100, 100, 900], [200, 200, 800], [300, 300, 700], [400, 400, 600], [500, 500, 500], [600, 600, 400], [700, 700, 300], [800, 800, 200], [900, 900, 100]]), 500.0)\n assert answers_match(candidate(squares=[[0, 0, 100], [25, 25, 50], [50, 50, 25], [75, 75, 12.5], [100, 100, 6.25]]), 50.1953125)\n assert answers_match(candidate(squares=[[0, 0, 1000], [500, 0, 1000], [1000, 0, 1000], [1500, 0, 1000], [2000, 0, 1000]]), 500.0)\n assert answers_match(candidate(squares=[[0, 0, 100], [50, 50, 50], [100, 100, 25], [150, 150, 12.5], [200, 200, 6.25], [250, 250, 3.125]]), 54.150390625)\n assert answers_match(candidate(squares=[[0, 0, 1000], [10, 10, 500], [20, 20, 250], [30, 30, 125], [40, 40, 62.5], [50, 50, 31.25], [60, 60, 15.625]]), 500.0)\n assert answers_match(candidate(squares=[[0, 0, 10], [2, 3, 5], [5, 2, 3], [7, 5, 2], [9, 3, 1]]), 5.0)\n assert answers_match(candidate(squares=[[1, 1, 1], [1, 3, 1], [3, 1, 1], [3, 3, 1], [2, 2, 2], [2, 4, 2], [4, 2, 2], [4, 4, 2], [3, 3, 3]]), 3.7)\n assert answers_match(candidate(squares=[[1, 1, 3], [3, 3, 3], [5, 5, 3], [7, 7, 3], [9, 9, 3]]), 6.5)\n assert answers_match(candidate(squares=[[0, 0, 7], [2, 3, 4], [5, 5, 6], [7, 7, 3], [9, 9, 5], [11, 11, 7]]), 9.222222222222221)\n assert answers_match(candidate(squares=[[0, 0, 1], [0, 1, 1], [0, 2, 1], [0, 3, 1], [0, 4, 1], [0, 5, 1], [0, 6, 1], [0, 7, 1], [0, 8, 1], [0, 9, 1]]), 5.0)\n assert answers_match(candidate(squares=[[0, 0, 100], [50, 50, 50], [25, 25, 25], [75, 75, 25]]), 50.0)\n assert answers_match(candidate(squares=[[0, 0, 10], [1, 1, 10], [2, 2, 10], [3, 3, 10], [4, 4, 10], [5, 5, 10], [6, 6, 10], [7, 7, 10], [8, 8, 10], [9, 9, 10], [10, 10, 10]]), 10.0)\n assert answers_match(candidate(squares=[[0, 0, 100], [10, 10, 80], [20, 20, 60], [30, 30, 40], [40, 40, 20]]), 50.0)\n assert answers_match(candidate(squares=[[0, 0, 10], [0, 10, 10], [0, 20, 10], [0, 30, 10], [0, 40, 10]]), 25.0)\n assert answers_match(candidate(squares=[[0, 0, 500], [250, 250, 250], [500, 500, 125], [750, 750, 62.5], [1000, 1000, 31.25]]), 270.5078125)\n assert answers_match(candidate(squares=[[0, 0, 20], [5, 10, 10], [15, 5, 5], [10, 0, 15], [25, 15, 10]]), 11.5)\n assert answers_match(candidate(squares=[[0, 0, 20], [0, 20, 20], [20, 0, 20], [20, 20, 20], [10, 10, 10], [10, 30, 10], [30, 10, 10], [30, 30, 10], [5, 5, 5], [5, 25, 5], [25, 5, 5], [25, 25, 5], [15, 15, 5], [15, 35, 5], [35, 15, 5], [35, 35, 5]]), 20.0)\n assert answers_match(candidate(squares=[[0, 0, 10], [5, 0, 10], [10, 0, 10], [15, 0, 10], [20, 0, 10]]), 5.0)\n assert answers_match(candidate(squares=[[0, 0, 10], [1, 1, 8], [2, 2, 6], [3, 3, 4], [4, 4, 2], [5, 5, 1]]), 5.0)\n assert answers_match(candidate(squares=[[10, 10, 5], [20, 20, 5], [30, 30, 5], [10, 20, 5], [20, 10, 5], [20, 30, 5], [30, 20, 5]]), 22.5)\n assert answers_match(candidate(squares=[[0, 0, 100], [10, 10, 50], [20, 20, 25], [30, 30, 12.5], [40, 40, 6.25]]), 50.0)\n assert answers_match(candidate(squares=[[1, 1, 5], [6, 1, 5], [11, 1, 5], [16, 1, 5], [21, 1, 5], [26, 1, 5], [31, 1, 5], [36, 1, 5], [41, 1, 5]]), 3.5)\n assert answers_match(candidate(squares=[[0, 0, 2], [1, 1, 3], [3, 3, 4], [6, 6, 5], [10, 10, 6]]), 9.4)\n assert answers_match(candidate(squares=[[0, 0, 5], [5, 5, 5], [10, 10, 5], [15, 15, 5], [20, 20, 5]]), 12.5)\n assert answers_match(candidate(squares=[[0, 0, 20], [10, 10, 20], [20, 20, 20], [30, 30, 20], [40, 40, 20], [50, 50, 20]]), 35.0)\n assert answers_match(candidate(squares=[[0, 0, 100], [25, 25, 50], [50, 50, 25], [75, 75, 12], [100, 100, 6], [125, 125, 3]]), 50.225)\n assert answers_match(candidate(squares=[[100, 100, 100], [150, 150, 150], [200, 200, 200], [250, 250, 250], [300, 300, 300]]), 375.0)\n assert answers_match(candidate(squares=[[10, 10, 10], [20, 20, 10], [30, 30, 10], [40, 40, 10], [50, 50, 10], [15, 15, 5], [25, 25, 5], [35, 35, 5], [45, 45, 5]]), 35.0)\n assert answers_match(candidate(squares=[[0, 0, 1000], [100, 100, 900], [200, 200, 800], [300, 300, 700], [400, 400, 600], [500, 500, 500]]), 500.0)\n assert answers_match(candidate(squares=[[0, 0, 10], [1, 2, 8], [2, 4, 6], [3, 6, 4], [4, 8, 2]]), 5.0)\n assert answers_match(candidate(squares=[[0, 0, 100], [10, 10, 100], [20, 20, 100], [30, 30, 100], [40, 40, 100]]), 70.0)\n assert answers_match(candidate(squares=[[0, 0, 5], [0, 5, 5], [0, 10, 5], [0, 15, 5], [0, 20, 5], [0, 25, 5]]), 15.0)\n assert answers_match(candidate(squares=[[1, 1, 6], [3, 3, 5], [5, 5, 4], [7, 7, 3], [9, 9, 2]]), 5.5)\n assert answers_match(candidate(squares=[[0, 0, 10], [0, 10, 10], [10, 0, 10], [10, 10, 10], [5, 5, 10], [5, 15, 10], [15, 5, 10], [15, 15, 10]]), 12.5)\n assert answers_match(candidate(squares=[[0, 0, 100], [10, 10, 80], [20, 20, 60], [30, 30, 40], [40, 40, 20], [50, 50, 10]]), 50.0)\n assert answers_match(candidate(squares=[[0, 0, 1000], [100, 100, 900], [200, 200, 800], [300, 300, 700], [400, 400, 600], [500, 500, 500], [600, 600, 400], [700, 700, 300], [800, 800, 200], [900, 900, 100]]), 500.0)\n assert answers_match(candidate(squares=[[0, 0, 10], [1, 9, 10], [2, 8, 10], [3, 7, 10], [4, 6, 10], [5, 5, 10], [6, 4, 10], [7, 3, 10], [8, 2, 10], [9, 1, 10]]), 8.552631578947368)\n assert answers_match(candidate(squares=[[0, 0, 100], [100, 100, 100], [200, 200, 100], [300, 300, 100], [400, 400, 100], [500, 500, 100], [600, 600, 100]]), 350.0)\n assert answers_match(candidate(squares=[[0, 0, 100], [100, 100, 100], [200, 200, 100], [300, 300, 100], [400, 400, 100], [500, 500, 100], [600, 600, 100], [700, 700, 100], [800, 800, 100], [900, 900, 100]]), 500.0)\n assert answers_match(candidate(squares=[[0, 0, 100], [50, 50, 50], [100, 0, 100], [150, 50, 50], [200, 0, 100], [250, 50, 50], [300, 0, 100], [350, 50, 50]]), 50.0)\n assert answers_match(candidate(squares=[[0, 0, 1], [1, 0, 1], [2, 0, 1], [3, 0, 1], [4, 0, 1], [5, 0, 1], [6, 0, 1], [7, 0, 1], [8, 0, 1], [9, 0, 1], [10, 0, 1]]), 0.5)\n assert answers_match(candidate(squares=[[0, 0, 1], [1, 0, 1], [2, 0, 1], [0, 1, 1], [1, 1, 1], [2, 1, 1], [0, 2, 1], [1, 2, 1], [2, 2, 1], [1.5, 0.5, 1]]), 1.5)\n assert answers_match(candidate(squares=[[0, 0, 1], [0, 1, 1], [0, 2, 1], [1, 0, 1], [1, 1, 1], [1, 2, 1], [2, 0, 1], [2, 1, 1], [2, 2, 1]]), 1.5)\n assert answers_match(candidate(squares=[[0, 0, 5], [2, 2, 3], [4, 4, 2], [6, 6, 1]]), 2.9)\n assert answers_match(candidate(squares=[[0, 0, 5], [2, 1, 3], [4, 2, 2], [6, 3, 1], [8, 4, 1]]), 2.75)\n assert answers_match(candidate(squares=[[1, 1, 2], [2, 2, 2], [3, 3, 2], [4, 4, 2], [5, 5, 2], [6, 6, 2], [7, 7, 2], [8, 8, 2], [9, 9, 2], [10, 10, 2]]), 6.5)\n assert answers_match(candidate(squares=[[0, 0, 100], [10, 0, 100], [20, 0, 100], [30, 0, 100], [40, 0, 100], [50, 0, 100]]), 50.0)\n assert answers_match(candidate(squares=[[50, 50, 20], [60, 60, 30], [70, 70, 40], [80, 80, 50], [90, 90, 60]]), 105.0)\n assert answers_match(candidate(squares=[[0, 0, 100], [10, 10, 10], [20, 20, 10], [30, 30, 10], [40, 40, 10]]), 50.0)\n assert answers_match(candidate(squares=[[1, 1, 10], [11, 1, 10], [21, 1, 10], [31, 1, 10], [41, 1, 10]]), 6.0)\n assert answers_match(candidate(squares=[[10, 10, 20], [15, 15, 15], [20, 20, 10], [25, 25, 5], [30, 30, 1]]), 20.025)\n assert answers_match(candidate(squares=[[1, 1, 2], [3, 3, 2], [2, 2, 2], [4, 4, 2], [5, 5, 2]]), 4.0)\n assert answers_match(candidate(squares=[[0, 0, 20], [5, 5, 10], [15, 15, 5], [25, 25, 2]]), 10.1)\n assert answers_match(candidate(squares=[[10, 10, 10], [15, 15, 10], [20, 20, 10], [25, 25, 10], [30, 30, 10], [35, 35, 10], [40, 40, 10], [45, 45, 10], [50, 50, 10], [55, 55, 10]]), 37.5)\n assert answers_match(candidate(squares=[[0, 0, 5], [1, 2, 3], [4, 4, 2], [6, 1, 4]]), 2.888888888888889)\n assert answers_match(candidate(squares=[[0, 0, 10], [1, 1, 10], [2, 2, 10], [3, 3, 10], [4, 4, 10], [5, 5, 10], [6, 6, 10], [7, 7, 10], [8, 8, 10], [9, 9, 10]]), 9.5)\n assert answers_match(candidate(squares=[[1, 1, 5], [2, 2, 4], [3, 3, 3], [4, 4, 2], [5, 5, 1], [6, 6, 1], [7, 7, 1]]), 3.7)\n assert answers_match(candidate(squares=[[0, 0, 1000], [500, 500, 500], [250, 250, 250], [750, 750, 250], [125, 125, 125], [375, 375, 125], [625, 625, 125], [875, 875, 125]]), 500.0)\n assert answers_match(candidate(squares=[[0, 0, 1], [1, 1, 1], [2, 2, 1], [3, 3, 1], [4, 4, 1], [5, 5, 1], [6, 6, 1], [7, 7, 1], [8, 8, 1], [9, 9, 1]]), 5.0)\n assert answers_match(candidate(squares=[[0, 0, 10], [5, 5, 10], [10, 10, 10], [15, 15, 10], [20, 20, 10], [25, 25, 10]]), 17.5)\n assert answers_match(candidate(squares=[[0, 0, 5], [2, 2, 5], [4, 4, 5], [6, 6, 5], [8, 8, 5], [10, 10, 5]]), 7.5)\n assert answers_match(candidate(squares=[[0, 0, 100], [50, 0, 50], [0, 50, 50], [50, 50, 50], [25, 25, 50]]), 50.0)\n assert answers_match(candidate(squares=[[0, 0, 1], [0, 1, 1], [0, 2, 1], [0, 3, 1], [0, 4, 1], [0, 5, 1], [0, 6, 1], [0, 7, 1], [0, 8, 1], [0, 9, 1], [1, 0, 1], [1, 1, 1], [1, 2, 1], [1, 3, 1], [1, 4, 1], [1, 5, 1], [1, 6, 1], [1, 7, 1], [1, 8, 1], [1, 9, 1]]), 5.0)\n assert answers_match(candidate(squares=[[0, 0, 500], [100, 100, 400], [200, 200, 300], [300, 300, 200], [400, 400, 100], [500, 500, 50], [600, 600, 25], [700, 700, 12.5]]), 253.28125)\n assert answers_match(candidate(squares=[[0, 0, 10], [5, 0, 5], [10, 0, 3], [15, 0, 2], [20, 0, 1]]), 4.3)\n assert answers_match(candidate(squares=[[10, 10, 5], [20, 15, 6], [30, 20, 7], [40, 25, 8], [50, 30, 9], [60, 35, 10], [70, 40, 11]]), 36.0)\n assert answers_match(candidate(squares=[[0, 0, 1000], [100, 900, 1000], [200, 800, 1000], [300, 700, 1000], [400, 600, 1000], [500, 500, 1000], [600, 400, 1000], [700, 300, 1000], [800, 200, 1000], [900, 100, 1000]]), 855.2631578947369)\n assert answers_match(candidate(squares=[[0, 0, 10], [5, 0, 10], [10, 0, 10], [15, 0, 10], [20, 0, 10], [25, 0, 10]]), 5.0)\n assert answers_match(candidate(squares=[[0, 0, 1], [1, 0, 2], [3, 0, 3], [6, 0, 4], [10, 0, 5], [15, 0, 6], [21, 0, 7], [28, 0, 8], [36, 0, 9], [45, 0, 10]]), 3.642857142857143)\n assert answers_match(candidate(squares=[[0, 0, 500], [100, 100, 500], [200, 200, 500], [300, 300, 500], [400, 400, 500], [500, 500, 500], [600, 600, 500], [700, 700, 500], [800, 800, 500], [900, 900, 500]]), 700.0)\n assert answers_match(candidate(squares=[[1, 1, 3], [3, 3, 2], [5, 5, 1], [2, 2, 2], [4, 4, 2], [6, 6, 2]]), 3.875)\n assert answers_match(candidate(squares=[[0, 0, 20], [1, 1, 19], [2, 2, 18], [3, 3, 17], [4, 4, 16], [5, 5, 15], [6, 6, 14], [7, 7, 13], [8, 8, 12], [9, 9, 11], [10, 10, 10], [11, 11, 9], [12, 12, 8], [13, 13, 7], [14, 14, 6], [15, 15, 5], [16, 16, 4], [17, 17, 3], [18, 18, 2], [19, 19, 1]]), 10.0)\n assert answers_match(candidate(squares=[[10, 10, 1], [20, 20, 1], [30, 30, 1], [40, 40, 1], [50, 50, 1], [60, 60, 1], [70, 70, 1], [80, 80, 1], [90, 90, 1]]), 50.5)\n assert answers_match(candidate(squares=[[0, 0, 3], [0, 3, 3], [3, 0, 3], [3, 3, 3], [1, 1, 2], [1, 4, 2], [4, 1, 2], [4, 4, 2]]), 3.0)\n assert answers_match(candidate(squares=[[10, 10, 5], [10, 15, 5], [15, 10, 5], [15, 15, 5], [20, 20, 10]]), 20.0)\n assert answers_match(candidate(squares=[[0, 0, 10], [0, 10, 10], [0, 20, 10], [10, 0, 10], [10, 10, 10], [10, 20, 10]]), 15.0)\n assert answers_match(candidate(squares=[[0, 0, 2], [0, 2, 2], [0, 4, 2], [0, 6, 2], [0, 8, 2], [0, 10, 2], [0, 12, 2], [0, 14, 2], [0, 16, 2], [0, 18, 2]]), 10.0)\n assert answers_match(candidate(squares=[[0, 0, 20], [5, 5, 10], [10, 10, 5], [15, 15, 2], [20, 20, 1], [25, 25, 1], [30, 30, 1]]), 10.075)\n assert answers_match(candidate(squares=[[0, 0, 50], [10, 10, 40], [20, 20, 30], [30, 30, 20], [40, 40, 10]]), 25.0)\n assert answers_match(candidate(squares=[[0, 0, 100], [20, 20, 50], [40, 40, 25], [60, 60, 12.5]]), 50.0)\n assert answers_match(candidate(squares=[[0, 0, 10], [1, 1, 9], [2, 2, 8], [3, 3, 7], [4, 4, 6], [5, 5, 5], [6, 6, 4], [7, 7, 3], [8, 8, 2], [9, 9, 1]]), 5.0)\n assert answers_match(candidate(squares=[[0, 0, 2], [1, 1, 2], [2, 2, 2], [3, 3, 2], [4, 4, 2], [5, 5, 2], [6, 6, 2], [7, 7, 2], [8, 8, 2], [9, 9, 2]]), 5.5)\n assert answers_match(candidate(squares=[[1, 1, 2], [2, 2, 2], [3, 3, 2], [4, 4, 2], [5, 5, 2], [6, 6, 2]]), 4.5)\n assert answers_match(candidate(squares=[[0, 0, 50], [50, 0, 50], [100, 0, 50], [150, 0, 50], [200, 0, 50], [250, 0, 50], [300, 0, 50], [350, 0, 50], [400, 0, 50]]), 25.0)\n assert answers_match(candidate(squares=[[0, 0, 10], [10, 0, 10], [20, 0, 10], [30, 0, 10], [40, 0, 10], [50, 0, 10]]), 5.0)\n assert answers_match(candidate(squares=[[0, 0, 100], [25, 25, 50], [50, 50, 25], [75, 75, 12.5], [100, 100, 6.25], [125, 125, 3.125]]), 50.244140625)\n", "comparison": "float"}, "public_tests": ["[[0,0,1],[2,2,1]]", "[[0,0,2],[1,1,1]]"], "hints": ["Use a line sweep and a segment tree.", "The line must lie in one of the squares."], "metadata": {"canonical_parameter_names": ["squares"], "leetcode_dataset_entry_point": "Solution().separateSquares", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:25:51+00:00", "tests_total": 103, "tests_dropped": 3, "flags": ["decimal_answer", "has_images"], "topic_tags": ["array", "binary-search", "segment-tree", "sweep-line"]}, "language": "python", "interface": {"raw_signature": "def separateSquares(self, squares: List[List[int]]) -> float:", "container": "Solution", "callable": "separateSquares", "parameters": [{"name": "squares", "type": "List[List[int]]"}], "return_type": "float", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} +{"question_id": 3453, "task_id": "separate-squares-i", "difficulty": "Medium", "problem_description": "You are given a 2D integer array squares. Each squares[i] = [x_i, y_i, l_i] represents the coordinates of the bottom-left point and the side length of a square parallel to the x-axis.\n\nFind the minimum y-coordinate value of a horizontal line such that the total area of the squares above the line equals the total area of the squares below the line.\n\nAnswers within 10^-5 of the actual answer will be accepted.\n\nNote: Squares may overlap. Overlapping areas should be counted multiple times.\n\nExample 1:\n\nInput: squares = [[0,0,1],[2,2,1]]\nOutput: 1.00000\nExplanation:\nAny horizontal line between y = 1 and y = 2 will have 1 square unit above it and 1 square unit below it. The lowest option is 1.\n\nExample 2:\n\nInput: squares = [[0,0,2],[1,1,1]]\nOutput: 1.16667\nExplanation:\nThe areas are:\n- Below the line: 7/6 * 2 (Red) + 1/6 (Blue) = 15/6 = 2.5.\n- Above the line: 5/6 * 2 (Red) + 5/6 (Blue) = 15/6 = 2.5.\n\nSince the areas above and below the line are equal, the output is 7/6 = 1.16667.\n\nConstraints:\n\n- 1 <= squares.length <= 5 * 10^4\n- squares[i] = [x_i, y_i, l_i]\n- squares[i].length == 3\n- 0 <= x_i, y_i <= 10^9\n- 1 <= l_i <= 10^9\n- The total area of all the squares will not exceed 10^12.\n", "canonical_tests": {"language": "python", "source": "def answers_match(result, expected):\n \"\"\"Decimal answers are accepted within 1e-5 (absolute or relative), as on LeetCode.\"\"\"\n import math\n if isinstance(result, list) and isinstance(expected, list):\n return len(result) == len(expected) and all(answers_match(r, e) for r, e in zip(result, expected))\n numbers = (int, float)\n if isinstance(result, numbers) and isinstance(expected, numbers) and not isinstance(result, bool):\n return math.isclose(result, expected, rel_tol=1e-5, abs_tol=1e-5)\n return result == expected\n\n\ndef check(candidate):\n assert answers_match(candidate(squares=[[0, 0, 10], [5, 5, 10], [10, 10, 10]]), 10.0)\n assert answers_match(candidate(squares=[[0, 0, 4], [2, 2, 2], [4, 4, 1]]), 2.4166666666666665)\n assert answers_match(candidate(squares=[[0, 0, 3], [3, 3, 3], [6, 6, 3]]), 4.5)\n assert answers_match(candidate(squares=[[0, 0, 3], [3, 3, 3]]), 3.0)\n assert answers_match(candidate(squares=[[0, 0, 5], [5, 5, 5], [2, 2, 2], [3, 3, 3]]), 4.5625)\n assert answers_match(candidate(squares=[[5, 5, 5], [10, 10, 5], [15, 15, 5]]), 12.5)\n assert answers_match(candidate(squares=[[1, 1, 2], [2, 2, 2], [3, 3, 2]]), 3.0)\n assert answers_match(candidate(squares=[[0, 0, 10], [5, 5, 5], [10, 0, 10]]), 5.5)\n assert answers_match(candidate(squares=[[0, 0, 3], [1, 1, 2], [2, 2, 1]]), 1.8)\n assert answers_match(candidate(squares=[[0, 0, 2], [1, 1, 1]]), 1.1666666666666667)\n assert answers_match(candidate(squares=[[0, 0, 5], [1, 1, 3], [2, 2, 2], [3, 3, 1]]), 2.65)\n assert answers_match(candidate(squares=[[0, 0, 4], [2, 2, 2], [1, 1, 2]]), 2.25)\n assert answers_match(candidate(squares=[[0, 0, 3], [3, 3, 3], [1, 1, 1]]), 2.8333333333333335)\n assert answers_match(candidate(squares=[[0, 0, 1], [2, 2, 1]]), 1.0)\n assert answers_match(candidate(squares=[[0, 0, 5], [5, 5, 5], [10, 10, 5]]), 7.5)\n assert answers_match(candidate(squares=[[0, 0, 3], [1, 1, 2], [4, 4, 1]]), 1.8)\n assert answers_match(candidate(squares=[[0, 0, 2], [0, 2, 2], [2, 0, 2], [2, 2, 2], [1, 1, 2], [3, 3, 2]]), 2.3333333333333335)\n assert answers_match(candidate(squares=[[0, 0, 5], [3, 3, 5], [6, 6, 5], [9, 9, 5]]), 7.0)\n assert answers_match(candidate(squares=[[0, 0, 1000], [100, 100, 500], [200, 200, 300], [300, 300, 200], [400, 400, 100], [0, 500, 1000], [100, 600, 500], [200, 700, 300], [300, 800, 200], [400, 900, 100]]), 717.8571428571429)\n assert answers_match(candidate(squares=[[0, 0, 7], [2, 1, 5], [4, 2, 3], [6, 3, 1], [8, 4, 1], [10, 5, 1]]), 3.5625)\n assert answers_match(candidate(squares=[[0, 0, 10], [5, 5, 5], [10, 10, 3], [15, 15, 2]]), 6.266666666666667)\n assert answers_match(candidate(squares=[[0, 0, 10], [5, 5, 5], [10, 10, 1], [12, 12, 3], [15, 15, 2]]), 6.3)\n assert answers_match(candidate(squares=[[0, 0, 10], [5, 5, 5], [10, 10, 1], [15, 15, 2], [20, 20, 3]]), 6.3)\n assert answers_match(candidate(squares=[[10, 10, 10], [10, 20, 10], [10, 30, 10], [20, 10, 10], [20, 20, 10], [20, 30, 10], [30, 10, 10], [30, 20, 10], [30, 30, 10]]), 25.0)\n assert answers_match(candidate(squares=[[0, 0, 3], [3, 3, 3], [6, 6, 3], [9, 9, 3], [12, 12, 3], [15, 15, 3], [18, 18, 3], [21, 21, 3], [24, 24, 3]]), 13.5)\n assert answers_match(candidate(squares=[[0, 0, 100], [50, 50, 100], [100, 0, 100], [150, 50, 100]]), 75.0)\n assert answers_match(candidate(squares=[[0, 0, 1], [0, 1, 1], [0, 2, 1], [0, 3, 1], [0, 4, 1], [0, 5, 1], [0, 6, 1], [0, 7, 1], [0, 8, 1], [0, 9, 1]]), 5.0)\n assert answers_match(candidate(squares=[[1, 1, 2], [1, 3, 2], [1, 5, 2], [1, 7, 2], [1, 9, 2], [1, 11, 2], [1, 13, 2], [1, 15, 2], [1, 17, 2], [1, 19, 2]]), 11.0)\n assert answers_match(candidate(squares=[[0, 0, 1], [0, 1, 1], [0, 2, 1], [0, 3, 1], [0, 4, 1], [0, 5, 1], [0, 6, 1], [0, 7, 1], [0, 8, 1], [0, 9, 1], [0, 10, 1]]), 5.5)\n assert answers_match(candidate(squares=[[0, 0, 7], [7, 7, 7], [3, 3, 3], [5, 5, 5], [1, 1, 1], [9, 9, 1]]), 6.833333333333333)\n assert answers_match(candidate(squares=[[0, 0, 1], [1, 1, 1], [2, 2, 1], [3, 3, 1], [4, 4, 1], [5, 5, 1], [6, 6, 1], [7, 7, 1], [8, 8, 1], [9, 9, 1], [10, 10, 1]]), 5.5)\n assert answers_match(candidate(squares=[[0, 0, 5], [3, 2, 3], [1, 4, 2], [6, 1, 4]]), 3.083333333333333)\n assert answers_match(candidate(squares=[[0, 0, 100], [20, 0, 90], [40, 0, 80], [60, 0, 70], [80, 0, 60], [100, 0, 50], [120, 0, 40], [140, 0, 30], [160, 0, 20], [180, 0, 10]]), 36.42857142857143)\n assert answers_match(candidate(squares=[[1, 1, 3], [4, 4, 3], [7, 7, 3], [10, 10, 3], [13, 13, 3], [16, 16, 3]]), 10.0)\n assert answers_match(candidate(squares=[[0, 0, 10], [10, 0, 10], [5, 5, 5], [15, 5, 5], [20, 0, 10], [25, 0, 10]]), 5.5)\n assert answers_match(candidate(squares=[[10, 10, 10], [15, 15, 10], [20, 20, 10], [25, 25, 10], [30, 30, 10], [35, 35, 10], [40, 40, 10], [45, 45, 10], [50, 50, 10]]), 35.0)\n assert answers_match(candidate(squares=[[0, 0, 1], [2, 0, 1], [4, 0, 1], [6, 0, 1], [8, 0, 1], [10, 0, 1], [12, 0, 1], [14, 0, 1], [16, 0, 1], [18, 0, 1], [20, 0, 1]]), 0.5)\n assert answers_match(candidate(squares=[[10, 10, 5], [15, 15, 5], [20, 20, 5], [25, 25, 5], [30, 30, 5], [35, 35, 5], [40, 40, 5], [45, 45, 5]]), 30.0)\n assert answers_match(candidate(squares=[[0, 0, 10], [1, 0, 9], [2, 0, 8], [3, 0, 7], [4, 0, 6], [5, 0, 5], [6, 0, 4], [7, 0, 3], [8, 0, 2], [9, 0, 1]]), 3.642857142857143)\n assert answers_match(candidate(squares=[[0, 0, 50], [10, 10, 40], [20, 20, 30], [30, 30, 20], [40, 40, 10], [50, 50, 5]]), 31.160714285714285)\n assert answers_match(candidate(squares=[[0, 0, 1], [1, 0, 1], [2, 0, 1], [3, 0, 1], [4, 0, 1], [5, 0, 1], [6, 0, 1], [7, 0, 1], [8, 0, 1], [9, 0, 1], [10, 0, 1], [11, 0, 1], [12, 0, 1], [13, 0, 1], [14, 0, 1], [15, 0, 1], [16, 0, 1], [17, 0, 1], [18, 0, 1], [19, 0, 1]]), 0.5)\n assert answers_match(candidate(squares=[[0, 0, 10], [5, 5, 10], [10, 0, 10], [5, 10, 10]]), 8.333333333333334)\n assert answers_match(candidate(squares=[[0, 0, 5], [1, 1, 3], [2, 2, 4], [3, 3, 2], [4, 4, 1]]), 3.1785714285714284)\n assert answers_match(candidate(squares=[[0, 0, 10], [0, 10, 10], [0, 20, 10], [10, 0, 10], [10, 10, 10], [10, 20, 10], [20, 0, 10], [20, 10, 10], [20, 20, 10]]), 15.0)\n assert answers_match(candidate(squares=[[0, 0, 10], [1, 1, 9], [2, 2, 8], [3, 3, 7], [4, 4, 6], [5, 5, 5], [6, 6, 4], [7, 7, 3], [8, 8, 2], [9, 9, 1]]), 6.357142857142857)\n assert answers_match(candidate(squares=[[2, 0, 6], [8, 0, 4], [5, 5, 3], [1, 1, 5]]), 3.2)\n assert answers_match(candidate(squares=[[1, 1, 1], [2, 2, 1], [3, 3, 1], [4, 4, 1], [5, 5, 1], [6, 6, 1]]), 4.0)\n assert answers_match(candidate(squares=[[0, 0, 2], [1, 1, 2], [2, 2, 2], [3, 3, 2], [4, 4, 2], [5, 5, 2], [6, 6, 2], [7, 7, 2], [8, 8, 2], [9, 9, 2], [10, 10, 2], [11, 11, 2], [12, 12, 2], [13, 13, 2], [14, 14, 2]]), 8.0)\n assert answers_match(candidate(squares=[[1, 1, 3], [4, 4, 3], [7, 7, 3], [10, 10, 3], [2, 2, 2], [5, 5, 2], [8, 8, 2], [11, 11, 2]]), 7.0)\n assert answers_match(candidate(squares=[[0, 0, 10], [2, 1, 10], [4, 2, 10], [6, 3, 10], [8, 4, 10], [10, 5, 10]]), 7.5)\n assert answers_match(candidate(squares=[[0, 0, 100], [20, 20, 50], [40, 40, 30], [60, 60, 20], [80, 80, 10], [10, 10, 80], [30, 30, 60], [50, 50, 40], [70, 70, 20]]), 54.861111111111114)\n assert answers_match(candidate(squares=[[1, 1, 3], [2, 2, 3], [1, 4, 3], [3, 5, 3]]), 4.5)\n assert answers_match(candidate(squares=[[0, 0, 5], [5, 0, 5], [10, 0, 5], [15, 0, 5], [20, 0, 5], [25, 0, 5], [30, 0, 5], [35, 0, 5], [40, 0, 5]]), 2.5)\n assert answers_match(candidate(squares=[[0, 0, 10], [5, 0, 10], [10, 0, 10], [15, 0, 10], [20, 0, 10], [25, 0, 10], [30, 0, 10], [35, 0, 10], [40, 0, 10], [45, 0, 10]]), 5.0)\n assert answers_match(candidate(squares=[[0, 0, 1000], [100, 100, 500], [200, 200, 300], [300, 300, 200], [400, 400, 100], [500, 500, 50], [600, 600, 25], [700, 700, 10], [800, 800, 5], [900, 900, 1]]), 431.7264285714286)\n assert answers_match(candidate(squares=[[0, 0, 1], [1, 0, 1], [2, 0, 1], [3, 0, 1], [4, 0, 1], [5, 0, 1], [6, 0, 1], [7, 0, 1], [8, 0, 1], [9, 0, 1], [10, 0, 1], [11, 0, 1], [12, 0, 1], [13, 0, 1], [14, 0, 1], [15, 0, 1], [16, 0, 1], [17, 0, 1], [18, 0, 1], [19, 0, 1], [20, 0, 1]]), 0.5)\n assert answers_match(candidate(squares=[[0, 0, 10], [0, 10, 10], [0, 20, 10], [0, 30, 10], [0, 40, 10], [0, 50, 10], [0, 60, 10], [0, 70, 10], [0, 80, 10], [0, 90, 10], [0, 100, 10], [0, 110, 10], [0, 120, 10], [0, 130, 10], [0, 140, 10], [0, 150, 10]]), 80.0)\n assert answers_match(candidate(squares=[[0, 0, 5], [1, 1, 4], [2, 2, 3], [3, 3, 2], [4, 4, 1]]), 3.107142857142857)\n assert answers_match(candidate(squares=[[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], [13, 14, 15]]), 17.166666666666668)\n assert answers_match(candidate(squares=[[1, 1, 5], [2, 2, 5], [3, 3, 5], [4, 4, 5], [5, 5, 5]]), 5.5)\n assert answers_match(candidate(squares=[[0, 0, 6], [1, 3, 4], [3, 0, 4], [5, 1, 4]]), 3.2222222222222223)\n assert answers_match(candidate(squares=[[0, 0, 100], [10, 10, 50], [20, 20, 30], [30, 30, 20], [40, 40, 10], [0, 50, 100], [10, 60, 50], [20, 70, 30], [30, 80, 20], [40, 90, 10]]), 71.78571428571429)\n assert answers_match(candidate(squares=[[0, 0, 10], [5, 5, 10], [10, 10, 10], [15, 15, 10]]), 12.5)\n assert answers_match(candidate(squares=[[0, 0, 10], [2, 0, 5], [5, 5, 3], [7, 7, 2], [8, 8, 1]]), 4.633333333333334)\n assert answers_match(candidate(squares=[[10, 10, 5], [15, 15, 4], [20, 20, 3], [25, 25, 2], [30, 30, 1]]), 15.625)\n assert answers_match(candidate(squares=[[0, 0, 1], [1, 0, 1], [2, 0, 1], [3, 0, 1], [4, 0, 1], [5, 0, 1], [6, 0, 1], [7, 0, 1], [8, 0, 1], [9, 0, 1], [0, 1, 1], [1, 1, 1], [2, 1, 1], [3, 1, 1], [4, 1, 1], [5, 1, 1], [6, 1, 1], [7, 1, 1], [8, 1, 1], [9, 1, 1]]), 1.0)\n assert answers_match(candidate(squares=[[0, 0, 5], [1, 1, 5], [2, 2, 5], [3, 3, 5], [4, 4, 5], [0, 5, 5], [1, 6, 5], [2, 7, 5], [3, 8, 5], [4, 9, 5]]), 7.0)\n assert answers_match(candidate(squares=[[0, 0, 1], [1, 1, 1], [2, 2, 1], [3, 3, 1], [4, 4, 1], [5, 5, 1], [6, 6, 1], [7, 7, 1], [8, 8, 1], [9, 9, 1]]), 5.0)\n assert answers_match(candidate(squares=[[0, 0, 10], [5, 5, 10], [10, 10, 10], [15, 15, 10], [20, 20, 10]]), 15.0)\n assert answers_match(candidate(squares=[[0, 0, 5], [5, 5, 5], [10, 10, 5], [15, 15, 5]]), 10.0)\n assert answers_match(candidate(squares=[[0, 0, 8], [1, 1, 7], [2, 2, 6], [3, 3, 5], [4, 4, 4], [5, 5, 3], [6, 6, 2], [7, 7, 1]]), 5.0606060606060606)\n assert answers_match(candidate(squares=[[0, 0, 7], [3, 3, 5], [6, 6, 3], [9, 9, 1], [1, 1, 6], [4, 4, 4], [7, 7, 2]]), 4.863636363636363)\n assert answers_match(candidate(squares=[[0, 0, 1], [1, 1, 1], [2, 2, 1], [3, 3, 1], [4, 4, 1], [5, 5, 1]]), 3.0)\n assert answers_match(candidate(squares=[[0, 0, 1], [1, 0, 1], [2, 0, 1], [3, 0, 1], [4, 0, 1], [5, 0, 1], [6, 0, 1], [7, 0, 1], [8, 0, 1], [9, 0, 1]]), 0.5)\n assert answers_match(candidate(squares=[[0, 0, 10], [1, 2, 10], [2, 4, 10], [3, 6, 10], [4, 8, 10], [5, 1, 10], [6, 3, 10], [7, 5, 10], [8, 7, 10], [9, 9, 10]]), 9.5)\n assert answers_match(candidate(squares=[[0, 0, 1], [1, 2, 1], [2, 4, 1], [3, 6, 1], [4, 8, 1], [5, 10, 1], [6, 12, 1]]), 6.5)\n assert answers_match(candidate(squares=[[1, 1, 4], [1, 5, 4], [5, 1, 4], [5, 5, 4]]), 5.0)\n assert answers_match(candidate(squares=[[0, 0, 100], [20, 0, 80], [40, 0, 60], [60, 0, 40], [80, 0, 20]]), 37.85714285714286)\n assert answers_match(candidate(squares=[[0, 0, 10], [1, 2, 3], [4, 6, 2], [7, 8, 4]]), 5.55)\n assert answers_match(candidate(squares=[[1, 1, 1], [1, 2, 1], [1, 3, 1], [1, 4, 1], [1, 5, 1], [1, 6, 1], [1, 7, 1], [1, 8, 1], [1, 9, 1]]), 5.5)\n assert answers_match(candidate(squares=[[0, 0, 20], [5, 5, 20], [10, 10, 20], [15, 15, 20], [20, 20, 20], [0, 20, 20], [5, 25, 20], [10, 30, 20], [15, 35, 20], [20, 40, 20]]), 30.0)\n assert answers_match(candidate(squares=[[0, 0, 10], [5, 5, 5], [10, 10, 2], [15, 15, 1]]), 6.0)\n assert answers_match(candidate(squares=[[0, 0, 8], [4, 4, 4], [8, 0, 8], [12, 4, 4], [16, 0, 8], [20, 4, 4]]), 4.666666666666667)\n assert answers_match(candidate(squares=[[0, 0, 1], [1, 1, 2], [2, 2, 3], [3, 3, 4], [4, 4, 5]]), 5.055555555555555)\n assert answers_match(candidate(squares=[[1, 1, 2], [3, 3, 2], [5, 5, 2], [7, 7, 2], [9, 9, 2]]), 6.0)\n assert answers_match(candidate(squares=[[0, 0, 1], [0, 1, 1], [0, 2, 1], [0, 3, 1], [0, 4, 1], [0, 5, 1], [0, 6, 1], [0, 7, 1], [0, 8, 1], [0, 9, 1], [0, 10, 1], [0, 11, 1], [0, 12, 1], [0, 13, 1], [0, 14, 1], [0, 15, 1], [0, 16, 1], [0, 17, 1], [0, 18, 1], [0, 19, 1]]), 10.0)\n assert answers_match(candidate(squares=[[0, 0, 1], [0, 1, 1], [0, 2, 1], [0, 3, 1], [0, 4, 1]]), 2.5)\n assert answers_match(candidate(squares=[[0, 0, 10], [5, 5, 5], [10, 10, 2]]), 5.966666666666667)\n assert answers_match(candidate(squares=[[0, 0, 5], [5, 0, 5], [10, 0, 5], [15, 0, 5]]), 2.5)\n assert answers_match(candidate(squares=[[0, 0, 5], [3, 0, 5], [6, 0, 5], [9, 0, 5]]), 2.5)\n assert answers_match(candidate(squares=[[0, 0, 10], [0, 10, 10], [0, 20, 10], [0, 30, 10], [0, 40, 10], [0, 50, 10], [0, 60, 10], [0, 70, 10], [0, 80, 10], [0, 90, 10]]), 50.0)\n assert answers_match(candidate(squares=[[1, 1, 10], [2, 2, 10], [3, 3, 10], [4, 4, 10], [5, 5, 10], [6, 6, 10], [7, 7, 10], [8, 8, 10], [9, 9, 10]]), 10.0)\n assert answers_match(candidate(squares=[[0, 0, 2], [1, 0, 2], [2, 0, 2], [3, 0, 2], [4, 0, 2], [5, 0, 2], [6, 0, 2], [7, 0, 2], [8, 0, 2], [9, 0, 2]]), 1.0)\n assert answers_match(candidate(squares=[[1, 1, 1], [1, 2, 1], [1, 3, 1], [1, 4, 1], [1, 5, 1]]), 3.5)\n assert answers_match(candidate(squares=[[1, 1, 1], [2, 2, 2], [3, 3, 3], [4, 4, 4], [5, 5, 5], [6, 6, 6], [7, 7, 7], [8, 8, 8], [9, 9, 9]]), 10.583333333333334)\n", "comparison": "float"}, "public_tests": ["[[0,0,1],[2,2,1]]", "[[0,0,2],[1,1,1]]"], "hints": ["Binary search on the answer."], "metadata": {"canonical_parameter_names": ["squares"], "leetcode_dataset_entry_point": "Solution().separateSquares", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:25:48+00:00", "tests_total": 107, "tests_dropped": 12, "flags": ["decimal_answer", "has_images"], "topic_tags": ["array", "binary-search"]}, "language": "python", "interface": {"raw_signature": "def separateSquares(self, squares: List[List[int]]) -> float:", "container": "Solution", "callable": "separateSquares", "parameters": [{"name": "squares", "type": "List[List[int]]"}], "return_type": "float", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} +{"question_id": 3454, "task_id": "separate-squares-ii", "difficulty": "Hard", "problem_description": "You are given a 2D integer array squares. Each squares[i] = [x_i, y_i, l_i] represents the coordinates of the bottom-left point and the side length of a square parallel to the x-axis.\n\nFind the minimum y-coordinate value of a horizontal line such that the total area covered by squares above the line equals the total area covered by squares below the line.\n\nAnswers within 10^-5 of the actual answer will be accepted.\n\nNote: Squares may overlap. Overlapping areas should be counted only once in this version.\n\nExample 1:\n\nInput: squares = [[0,0,1],[2,2,1]]\nOutput: 1.00000\nExplanation:\nAny horizontal line between y = 1 and y = 2 results in an equal split, with 1 square unit above and 1 square unit below. The minimum y-value is 1.\n\nExample 2:\n\nInput: squares = [[0,0,2],[1,1,1]]\nOutput: 1.00000\nExplanation:\nSince the blue square overlaps with the red square, it will not be counted again. Thus, the line y = 1 splits the squares into two equal parts.\n\nConstraints:\n\n- 1 <= squares.length <= 5 * 10^4\n- squares[i] = [x_i, y_i, l_i]\n- squares[i].length == 3\n- 0 <= x_i, y_i <= 10^9\n- 1 <= l_i <= 10^9\n- The total area of all the squares will not exceed 10^15.\n", "canonical_tests": {"language": "python", "source": "def answers_match(result, expected):\n \"\"\"Decimal answers are accepted within 1e-5 (absolute or relative), as on LeetCode.\"\"\"\n import math\n if isinstance(result, list) and isinstance(expected, list):\n return len(result) == len(expected) and all(answers_match(r, e) for r, e in zip(result, expected))\n numbers = (int, float)\n if isinstance(result, numbers) and isinstance(expected, numbers) and not isinstance(result, bool):\n return math.isclose(result, expected, rel_tol=1e-5, abs_tol=1e-5)\n return result == expected\n\n\ndef check(candidate):\n assert answers_match(candidate(squares=[[0, 0, 1], [1, 1, 1], [2, 2, 1], [3, 3, 1]]), 2.0)\n assert answers_match(candidate(squares=[[1, 1, 2], [2, 0, 2], [0, 2, 2]]), 2.0)\n assert answers_match(candidate(squares=[[0, 0, 4], [2, 2, 2], [1, 1, 1], [3, 3, 1]]), 2.0)\n assert answers_match(candidate(squares=[[0, 0, 5], [2, 2, 3], [1, 1, 2], [3, 3, 2], [4, 4, 1]]), 2.5)\n assert answers_match(candidate(squares=[[0, 0, 5], [5, 5, 5], [10, 10, 5], [15, 15, 5]]), 10.0)\n assert answers_match(candidate(squares=[[0, 0, 3], [1, 1, 2], [2, 2, 1]]), 1.5)\n assert answers_match(candidate(squares=[[0, 0, 2], [1, 1, 1]]), 1.0)\n assert answers_match(candidate(squares=[[0, 0, 10], [5, 5, 5], [10, 10, 1]]), 5.05)\n assert answers_match(candidate(squares=[[0, 0, 1], [2, 2, 1]]), 1.0)\n assert answers_match(candidate(squares=[[0, 0, 5], [5, 5, 5], [10, 10, 5]]), 7.5)\n assert answers_match(candidate(squares=[[0, 0, 4], [1, 1, 4], [2, 2, 4], [3, 3, 4]]), 3.5)\n assert answers_match(candidate(squares=[[0, 0, 3], [1, 1, 3], [2, 2, 3]]), 2.5)\n assert answers_match(candidate(squares=[[0, 0, 3], [1, 1, 2], [4, 4, 1]]), 1.6666666666666665)\n assert answers_match(candidate(squares=[[0, 0, 10], [1, 2, 8], [2, 4, 6], [3, 6, 4], [4, 8, 2], [5, 10, 1], [6, 8, 2], [7, 6, 4], [8, 4, 6], [9, 2, 8], [10, 0, 10]]), 5.025)\n assert answers_match(candidate(squares=[[0, 0, 1000], [100, 100, 900], [200, 200, 800], [300, 300, 700], [400, 400, 600], [500, 500, 500], [600, 600, 400], [700, 700, 300], [800, 800, 200], [900, 900, 100]]), 500.0)\n assert answers_match(candidate(squares=[[0, 0, 1000], [500, 0, 1000], [1000, 0, 1000], [1500, 0, 1000], [2000, 0, 1000]]), 500.0)\n assert answers_match(candidate(squares=[[0, 0, 10], [2, 3, 5], [5, 2, 3], [7, 5, 2], [9, 3, 1]]), 5.0)\n assert answers_match(candidate(squares=[[1, 1, 1], [1, 3, 1], [3, 1, 1], [3, 3, 1], [2, 2, 2], [2, 4, 2], [4, 2, 2], [4, 4, 2], [3, 3, 3]]), 3.7)\n assert answers_match(candidate(squares=[[1, 1, 3], [3, 3, 3], [5, 5, 3], [7, 7, 3], [9, 9, 3]]), 6.5)\n assert answers_match(candidate(squares=[[0, 0, 7], [2, 3, 4], [5, 5, 6], [7, 7, 3], [9, 9, 5], [11, 11, 7]]), 9.222222222222221)\n assert answers_match(candidate(squares=[[0, 0, 1], [0, 1, 1], [0, 2, 1], [0, 3, 1], [0, 4, 1], [0, 5, 1], [0, 6, 1], [0, 7, 1], [0, 8, 1], [0, 9, 1]]), 5.0)\n assert answers_match(candidate(squares=[[0, 0, 100], [50, 50, 50], [25, 25, 25], [75, 75, 25]]), 50.0)\n assert answers_match(candidate(squares=[[0, 0, 10], [1, 1, 10], [2, 2, 10], [3, 3, 10], [4, 4, 10], [5, 5, 10], [6, 6, 10], [7, 7, 10], [8, 8, 10], [9, 9, 10], [10, 10, 10]]), 10.0)\n assert answers_match(candidate(squares=[[0, 0, 100], [10, 10, 80], [20, 20, 60], [30, 30, 40], [40, 40, 20]]), 50.0)\n assert answers_match(candidate(squares=[[0, 0, 10], [0, 10, 10], [0, 20, 10], [0, 30, 10], [0, 40, 10]]), 25.0)\n assert answers_match(candidate(squares=[[0, 0, 20], [5, 10, 10], [15, 5, 5], [10, 0, 15], [25, 15, 10]]), 11.5)\n assert answers_match(candidate(squares=[[0, 0, 20], [0, 20, 20], [20, 0, 20], [20, 20, 20], [10, 10, 10], [10, 30, 10], [30, 10, 10], [30, 30, 10], [5, 5, 5], [5, 25, 5], [25, 5, 5], [25, 25, 5], [15, 15, 5], [15, 35, 5], [35, 15, 5], [35, 35, 5]]), 20.0)\n assert answers_match(candidate(squares=[[0, 0, 10], [5, 0, 10], [10, 0, 10], [15, 0, 10], [20, 0, 10]]), 5.0)\n assert answers_match(candidate(squares=[[0, 0, 10], [1, 1, 8], [2, 2, 6], [3, 3, 4], [4, 4, 2], [5, 5, 1]]), 5.0)\n assert answers_match(candidate(squares=[[10, 10, 5], [20, 20, 5], [30, 30, 5], [10, 20, 5], [20, 10, 5], [20, 30, 5], [30, 20, 5]]), 22.5)\n assert answers_match(candidate(squares=[[1, 1, 5], [6, 1, 5], [11, 1, 5], [16, 1, 5], [21, 1, 5], [26, 1, 5], [31, 1, 5], [36, 1, 5], [41, 1, 5]]), 3.5)\n assert answers_match(candidate(squares=[[0, 0, 2], [1, 1, 3], [3, 3, 4], [6, 6, 5], [10, 10, 6]]), 9.4)\n assert answers_match(candidate(squares=[[0, 0, 5], [5, 5, 5], [10, 10, 5], [15, 15, 5], [20, 20, 5]]), 12.5)\n assert answers_match(candidate(squares=[[0, 0, 20], [10, 10, 20], [20, 20, 20], [30, 30, 20], [40, 40, 20], [50, 50, 20]]), 35.0)\n assert answers_match(candidate(squares=[[0, 0, 100], [25, 25, 50], [50, 50, 25], [75, 75, 12], [100, 100, 6], [125, 125, 3]]), 50.225)\n assert answers_match(candidate(squares=[[100, 100, 100], [150, 150, 150], [200, 200, 200], [250, 250, 250], [300, 300, 300]]), 375.0)\n assert answers_match(candidate(squares=[[10, 10, 10], [20, 20, 10], [30, 30, 10], [40, 40, 10], [50, 50, 10], [15, 15, 5], [25, 25, 5], [35, 35, 5], [45, 45, 5]]), 35.0)\n assert answers_match(candidate(squares=[[0, 0, 1000], [100, 100, 900], [200, 200, 800], [300, 300, 700], [400, 400, 600], [500, 500, 500]]), 500.0)\n assert answers_match(candidate(squares=[[0, 0, 10], [1, 2, 8], [2, 4, 6], [3, 6, 4], [4, 8, 2]]), 5.0)\n assert answers_match(candidate(squares=[[0, 0, 100], [10, 10, 100], [20, 20, 100], [30, 30, 100], [40, 40, 100]]), 70.0)\n assert answers_match(candidate(squares=[[0, 0, 5], [0, 5, 5], [0, 10, 5], [0, 15, 5], [0, 20, 5], [0, 25, 5]]), 15.0)\n assert answers_match(candidate(squares=[[1, 1, 6], [3, 3, 5], [5, 5, 4], [7, 7, 3], [9, 9, 2]]), 5.5)\n assert answers_match(candidate(squares=[[0, 0, 10], [0, 10, 10], [10, 0, 10], [10, 10, 10], [5, 5, 10], [5, 15, 10], [15, 5, 10], [15, 15, 10]]), 12.5)\n assert answers_match(candidate(squares=[[0, 0, 100], [10, 10, 80], [20, 20, 60], [30, 30, 40], [40, 40, 20], [50, 50, 10]]), 50.0)\n assert answers_match(candidate(squares=[[0, 0, 1000], [100, 100, 900], [200, 200, 800], [300, 300, 700], [400, 400, 600], [500, 500, 500], [600, 600, 400], [700, 700, 300], [800, 800, 200], [900, 900, 100]]), 500.0)\n assert answers_match(candidate(squares=[[0, 0, 10], [1, 9, 10], [2, 8, 10], [3, 7, 10], [4, 6, 10], [5, 5, 10], [6, 4, 10], [7, 3, 10], [8, 2, 10], [9, 1, 10]]), 8.552631578947368)\n assert answers_match(candidate(squares=[[0, 0, 100], [100, 100, 100], [200, 200, 100], [300, 300, 100], [400, 400, 100], [500, 500, 100], [600, 600, 100]]), 350.0)\n assert answers_match(candidate(squares=[[0, 0, 100], [100, 100, 100], [200, 200, 100], [300, 300, 100], [400, 400, 100], [500, 500, 100], [600, 600, 100], [700, 700, 100], [800, 800, 100], [900, 900, 100]]), 500.0)\n assert answers_match(candidate(squares=[[0, 0, 100], [50, 50, 50], [100, 0, 100], [150, 50, 50], [200, 0, 100], [250, 50, 50], [300, 0, 100], [350, 50, 50]]), 50.0)\n assert answers_match(candidate(squares=[[0, 0, 1], [1, 0, 1], [2, 0, 1], [3, 0, 1], [4, 0, 1], [5, 0, 1], [6, 0, 1], [7, 0, 1], [8, 0, 1], [9, 0, 1], [10, 0, 1]]), 0.5)\n assert answers_match(candidate(squares=[[0, 0, 1], [0, 1, 1], [0, 2, 1], [1, 0, 1], [1, 1, 1], [1, 2, 1], [2, 0, 1], [2, 1, 1], [2, 2, 1]]), 1.5)\n assert answers_match(candidate(squares=[[0, 0, 5], [2, 2, 3], [4, 4, 2], [6, 6, 1]]), 2.9)\n assert answers_match(candidate(squares=[[0, 0, 5], [2, 1, 3], [4, 2, 2], [6, 3, 1], [8, 4, 1]]), 2.75)\n assert answers_match(candidate(squares=[[1, 1, 2], [2, 2, 2], [3, 3, 2], [4, 4, 2], [5, 5, 2], [6, 6, 2], [7, 7, 2], [8, 8, 2], [9, 9, 2], [10, 10, 2]]), 6.5)\n assert answers_match(candidate(squares=[[0, 0, 100], [10, 0, 100], [20, 0, 100], [30, 0, 100], [40, 0, 100], [50, 0, 100]]), 50.0)\n assert answers_match(candidate(squares=[[50, 50, 20], [60, 60, 30], [70, 70, 40], [80, 80, 50], [90, 90, 60]]), 105.0)\n assert answers_match(candidate(squares=[[0, 0, 100], [10, 10, 10], [20, 20, 10], [30, 30, 10], [40, 40, 10]]), 50.0)\n assert answers_match(candidate(squares=[[1, 1, 10], [11, 1, 10], [21, 1, 10], [31, 1, 10], [41, 1, 10]]), 6.0)\n assert answers_match(candidate(squares=[[10, 10, 20], [15, 15, 15], [20, 20, 10], [25, 25, 5], [30, 30, 1]]), 20.025)\n assert answers_match(candidate(squares=[[1, 1, 2], [3, 3, 2], [2, 2, 2], [4, 4, 2], [5, 5, 2]]), 4.0)\n assert answers_match(candidate(squares=[[0, 0, 20], [5, 5, 10], [15, 15, 5], [25, 25, 2]]), 10.1)\n assert answers_match(candidate(squares=[[10, 10, 10], [15, 15, 10], [20, 20, 10], [25, 25, 10], [30, 30, 10], [35, 35, 10], [40, 40, 10], [45, 45, 10], [50, 50, 10], [55, 55, 10]]), 37.5)\n assert answers_match(candidate(squares=[[0, 0, 5], [1, 2, 3], [4, 4, 2], [6, 1, 4]]), 2.888888888888889)\n assert answers_match(candidate(squares=[[0, 0, 10], [1, 1, 10], [2, 2, 10], [3, 3, 10], [4, 4, 10], [5, 5, 10], [6, 6, 10], [7, 7, 10], [8, 8, 10], [9, 9, 10]]), 9.5)\n assert answers_match(candidate(squares=[[1, 1, 5], [2, 2, 4], [3, 3, 3], [4, 4, 2], [5, 5, 1], [6, 6, 1], [7, 7, 1]]), 3.7)\n assert answers_match(candidate(squares=[[0, 0, 1000], [500, 500, 500], [250, 250, 250], [750, 750, 250], [125, 125, 125], [375, 375, 125], [625, 625, 125], [875, 875, 125]]), 500.0)\n assert answers_match(candidate(squares=[[0, 0, 1], [1, 1, 1], [2, 2, 1], [3, 3, 1], [4, 4, 1], [5, 5, 1], [6, 6, 1], [7, 7, 1], [8, 8, 1], [9, 9, 1]]), 5.0)\n assert answers_match(candidate(squares=[[0, 0, 10], [5, 5, 10], [10, 10, 10], [15, 15, 10], [20, 20, 10], [25, 25, 10]]), 17.5)\n assert answers_match(candidate(squares=[[0, 0, 5], [2, 2, 5], [4, 4, 5], [6, 6, 5], [8, 8, 5], [10, 10, 5]]), 7.5)\n assert answers_match(candidate(squares=[[0, 0, 100], [50, 0, 50], [0, 50, 50], [50, 50, 50], [25, 25, 50]]), 50.0)\n assert answers_match(candidate(squares=[[0, 0, 1], [0, 1, 1], [0, 2, 1], [0, 3, 1], [0, 4, 1], [0, 5, 1], [0, 6, 1], [0, 7, 1], [0, 8, 1], [0, 9, 1], [1, 0, 1], [1, 1, 1], [1, 2, 1], [1, 3, 1], [1, 4, 1], [1, 5, 1], [1, 6, 1], [1, 7, 1], [1, 8, 1], [1, 9, 1]]), 5.0)\n assert answers_match(candidate(squares=[[0, 0, 10], [5, 0, 5], [10, 0, 3], [15, 0, 2], [20, 0, 1]]), 4.3)\n assert answers_match(candidate(squares=[[10, 10, 5], [20, 15, 6], [30, 20, 7], [40, 25, 8], [50, 30, 9], [60, 35, 10], [70, 40, 11]]), 36.0)\n assert answers_match(candidate(squares=[[0, 0, 1000], [100, 900, 1000], [200, 800, 1000], [300, 700, 1000], [400, 600, 1000], [500, 500, 1000], [600, 400, 1000], [700, 300, 1000], [800, 200, 1000], [900, 100, 1000]]), 855.2631578947369)\n assert answers_match(candidate(squares=[[0, 0, 10], [5, 0, 10], [10, 0, 10], [15, 0, 10], [20, 0, 10], [25, 0, 10]]), 5.0)\n assert answers_match(candidate(squares=[[0, 0, 1], [1, 0, 2], [3, 0, 3], [6, 0, 4], [10, 0, 5], [15, 0, 6], [21, 0, 7], [28, 0, 8], [36, 0, 9], [45, 0, 10]]), 3.642857142857143)\n assert answers_match(candidate(squares=[[0, 0, 500], [100, 100, 500], [200, 200, 500], [300, 300, 500], [400, 400, 500], [500, 500, 500], [600, 600, 500], [700, 700, 500], [800, 800, 500], [900, 900, 500]]), 700.0)\n assert answers_match(candidate(squares=[[1, 1, 3], [3, 3, 2], [5, 5, 1], [2, 2, 2], [4, 4, 2], [6, 6, 2]]), 3.875)\n assert answers_match(candidate(squares=[[0, 0, 20], [1, 1, 19], [2, 2, 18], [3, 3, 17], [4, 4, 16], [5, 5, 15], [6, 6, 14], [7, 7, 13], [8, 8, 12], [9, 9, 11], [10, 10, 10], [11, 11, 9], [12, 12, 8], [13, 13, 7], [14, 14, 6], [15, 15, 5], [16, 16, 4], [17, 17, 3], [18, 18, 2], [19, 19, 1]]), 10.0)\n assert answers_match(candidate(squares=[[10, 10, 1], [20, 20, 1], [30, 30, 1], [40, 40, 1], [50, 50, 1], [60, 60, 1], [70, 70, 1], [80, 80, 1], [90, 90, 1]]), 50.5)\n assert answers_match(candidate(squares=[[0, 0, 3], [0, 3, 3], [3, 0, 3], [3, 3, 3], [1, 1, 2], [1, 4, 2], [4, 1, 2], [4, 4, 2]]), 3.0)\n assert answers_match(candidate(squares=[[10, 10, 5], [10, 15, 5], [15, 10, 5], [15, 15, 5], [20, 20, 10]]), 20.0)\n assert answers_match(candidate(squares=[[0, 0, 10], [0, 10, 10], [0, 20, 10], [10, 0, 10], [10, 10, 10], [10, 20, 10]]), 15.0)\n assert answers_match(candidate(squares=[[0, 0, 2], [0, 2, 2], [0, 4, 2], [0, 6, 2], [0, 8, 2], [0, 10, 2], [0, 12, 2], [0, 14, 2], [0, 16, 2], [0, 18, 2]]), 10.0)\n assert answers_match(candidate(squares=[[0, 0, 20], [5, 5, 10], [10, 10, 5], [15, 15, 2], [20, 20, 1], [25, 25, 1], [30, 30, 1]]), 10.075)\n assert answers_match(candidate(squares=[[0, 0, 50], [10, 10, 40], [20, 20, 30], [30, 30, 20], [40, 40, 10]]), 25.0)\n assert answers_match(candidate(squares=[[0, 0, 10], [1, 1, 9], [2, 2, 8], [3, 3, 7], [4, 4, 6], [5, 5, 5], [6, 6, 4], [7, 7, 3], [8, 8, 2], [9, 9, 1]]), 5.0)\n assert answers_match(candidate(squares=[[0, 0, 2], [1, 1, 2], [2, 2, 2], [3, 3, 2], [4, 4, 2], [5, 5, 2], [6, 6, 2], [7, 7, 2], [8, 8, 2], [9, 9, 2]]), 5.5)\n assert answers_match(candidate(squares=[[1, 1, 2], [2, 2, 2], [3, 3, 2], [4, 4, 2], [5, 5, 2], [6, 6, 2]]), 4.5)\n assert answers_match(candidate(squares=[[0, 0, 50], [50, 0, 50], [100, 0, 50], [150, 0, 50], [200, 0, 50], [250, 0, 50], [300, 0, 50], [350, 0, 50], [400, 0, 50]]), 25.0)\n assert answers_match(candidate(squares=[[0, 0, 10], [10, 0, 10], [20, 0, 10], [30, 0, 10], [40, 0, 10], [50, 0, 10]]), 5.0)\n", "comparison": "float"}, "public_tests": ["[[0,0,1],[2,2,1]]", "[[0,0,2],[1,1,1]]"], "hints": ["Use a line sweep and a segment tree.", "The line must lie in one of the squares."], "metadata": {"canonical_parameter_names": ["squares"], "leetcode_dataset_entry_point": "Solution().separateSquares", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:25:51+00:00", "tests_total": 103, "tests_dropped": 12, "flags": ["decimal_answer", "has_images"], "topic_tags": ["array", "binary-search", "segment-tree", "sweep-line"]}, "language": "python", "interface": {"raw_signature": "def separateSquares(self, squares: List[List[int]]) -> float:", "container": "Solution", "callable": "separateSquares", "parameters": [{"name": "squares", "type": "List[List[int]]"}], "return_type": "float", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3455, "task_id": "shortest-matching-substring", "difficulty": "Hard", "problem_description": "You are given a string s and a pattern string p, where p contains exactly two '*' characters.\n\nThe '*' in p matches any sequence of zero or more characters.\n\nReturn the length of the shortest substring in s that matches p. If there is no such substring, return -1.\n\nNote: The empty substring is considered valid.\n\nExample 1:\n\nInput: s = \"abaacbaecebce\", p = \"ba*c*ce\"\nOutput: 8\nExplanation:\nThe shortest matching substring of p in s is \"baecebce\".\n\nExample 2:\n\nInput: s = \"baccbaadbc\", p = \"cc*baa*adb\"\nOutput: -1\nExplanation:\nThere is no matching substring in s.\n\nExample 3:\n\nInput: s = \"a\", p = \"**\"\nOutput: 0\nExplanation:\nThe empty substring is the shortest matching substring.\n\nExample 4:\n\nInput: s = \"madlogic\", p = \"*adlogi*\"\nOutput: 6\nExplanation:\nThe shortest matching substring of p in s is \"adlogi\".\n\nConstraints:\n\n- 1 <= s.length <= 10^5\n- 2 <= p.length <= 10^5\n- s contains only lowercase English letters.\n- p contains only lowercase English letters and exactly two '*'.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"abcdefg\",p = \"*bcd*fg\") == 6\n assert candidate(s = \"abcabcabc\",p = \"*bc*bc\") == 5\n assert candidate(s = \"mississippi\",p = \"mis*si*\") == 5\n assert candidate(s = \"baccbaadbc\",p = \"cc*baa*adb\") == -1\n assert candidate(s = \"aaaaa\",p = \"*aaa*\") == 3\n assert candidate(s = \"xyz\",p = \"*x*z\") == -1\n assert candidate(s = \"xyxyxyxy\",p = \"xy*xy*\") == 4\n assert candidate(s = \"abaacbaecebce\",p = \"ba*c*ce\") == 8\n assert candidate(s = \"aaaaaa\",p = \"a*a*a\") == 3\n assert candidate(s = \"hellothere\",p = \"he*lo*re\") == 10\n assert candidate(s = \"a\",p = \"**\") == 0\n assert candidate(s = \"abcde\",p = \"*c*\") == 1\n assert candidate(s = \"xyz\",p = \"*z*\") == 1\n assert candidate(s = \"madlogic\",p = \"*adlogi*\") == 6\n assert candidate(s = \"mississippi\",p = \"mis*is*ip\") == 9\n assert candidate(s = \"mississippi\",p = \"*issi*\") == 4\n assert candidate(s = \"abracadabra\",p = \"*bra*bra\") == 10\n assert candidate(s = \"aabbccddeeffgg\",p = \"*bbcc*eeff\") == 10\n assert candidate(s = \"hellohellohello\",p = \"*llohe*llo\") == 8\n assert candidate(s = \"mississippi\",p = \"*iss*iss\") == 6\n assert candidate(s = \"aaaaaaabbbb\",p = \"*aaaa*bbb\") == 7\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",p = \"zz*zz*zz\") == 6\n assert candidate(s = \"abcdefghijkxyz\",p = \"*def*xyz\") == 11\n assert candidate(s = \"hellohellohello\",p = \"he*ll*ohello\") == 10\n assert candidate(s = \"mississippi\",p = \"*issi*ppi\") == 7\n assert candidate(s = \"abcabcabcabc\",p = \"*abc*abc\") == 6\n assert candidate(s = \"thisisateststring\",p = \"*test*string\") == 10\n assert candidate(s = \"mississipi\",p = \"*iss*issi\") == 7\n assert candidate(s = \"abcdefghijabcdefghijabcdefghij\",p = \"abc*efg*ij\") == 10\n assert candidate(s = \"racecar\",p = \"*ace*car\") == 6\n assert candidate(s = \"banana\",p = \"*na*na\") == 4\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",p = \"aa*bb*cc\") == 6\n assert candidate(s = \"abcdefghijabcdefghij\",p = \"*def*ghijghij\") == -1\n assert candidate(s = \"ababababab\",p = \"*aba*aba\") == 7\n assert candidate(s = \"ababababab\",p = \"ab*a*ab\") == 6\n assert candidate(s = \"ababababa\",p = \"*aba*aba\") == 7\n assert candidate(s = \"zzzzzzzzzzz\",p = \"zz*zz*zz\") == 6\n assert candidate(s = \"abababab\",p = \"*bab*ab\") == 5\n assert candidate(s = \"aaaaaaaaaa\",p = \"*aaaaa*aa\") == 7\n assert candidate(s = \"xyxzyzyx\",p = \"*xyz*zyx\") == -1\n assert candidate(s = \"hellohellohello\",p = \"ello*hello*\") == 9\n assert candidate(s = \"xyzyzyzyzyz\",p = \"*zyz*zyz\") == 7\n assert candidate(s = \"abcdeabcde\",p = \"*bcde*bc\") == 7\n assert candidate(s = \"zzzzyyyxxxwwww\",p = \"*yyy*xxx\") == 6\n assert candidate(s = \"xylophone\",p = \"*pho*ne\") == 5\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyz\",p = \"abc*xyz*\") == 26\n assert candidate(s = \"abcdefghij\",p = \"*def*ghij\") == 7\n assert candidate(s = \"abcabcabcabcabc\",p = \"*abc*abcabc\") == 9\n assert candidate(s = \"aabbccddeeff\",p = \"*bbcc*ccdd\") == -1\n assert candidate(s = \"abcdeabcdeabcde\",p = \"*bcde*bcde\") == 9\n assert candidate(s = \"mississippi\",p = \"miss*ss*\") == 7\n assert candidate(s = \"hellohellohello\",p = \"*hello*lo\") == 10\n", "comparison": "exact"}, "public_tests": ["\"abaacbaecebce\"\n\"ba*c*ce\"", "\"baccbaadbc\"\n\"cc*baa*adb\"", "\"a\"\n\"**\"", "\"madlogic\"\n\"*adlogi*\""], "hints": ["The pattern string p can be divided into three segments.", "Use the KMP algorithm to locate all occurrences of each segment in s."], "metadata": {"canonical_parameter_names": ["s", "p"], "leetcode_dataset_entry_point": "Solution().shortestMatchingSubstring", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:25:53+00:00", "tests_total": 53, "tests_dropped": 1, "flags": [], "topic_tags": ["two-pointers", "string", "binary-search", "string-matching"]}, "language": "python", "interface": {"raw_signature": "def shortestMatchingSubstring(self, s: str, p: str) -> int:", "container": "Solution", "callable": "shortestMatchingSubstring", "parameters": [{"name": "s", "type": "str"}, {"name": "p", "type": "str"}], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3456, "task_id": "find-special-substring-of-length-k", "difficulty": "Easy", "problem_description": "You are given a string s and an integer k.\n\nDetermine if there exists a substring of length exactly k in s that satisfies the following conditions:\n\n1. The substring consists of only one distinct character (e.g., \"aaa\" or \"bbb\").\n2. If there is a character immediately before the substring, it must be different from the character in the substring.\n3. If there is a character immediately after the substring, it must also be different from the character in the substring.\n\nReturn true if such a substring exists. Otherwise, return false.\n\nExample 1:\n\nInput: s = \"aaabaaa\", k = 3\nOutput: true\nExplanation:\nThe substring s[4..6] == \"aaa\" satisfies the conditions.\n- It has a length of 3.\n- All characters are the same.\n- The character before \"aaa\" is 'b', which is different from 'a'.\n- There is no character after \"aaa\".\n\nExample 2:\n\nInput: s = \"abc\", k = 2\nOutput: false\nExplanation:\nThere is no substring of length 2 that consists of one distinct character and satisfies the conditions.\n\nConstraints:\n\n- 1 <= k <= s.length <= 100\n- s consists of lowercase English letters only.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(s = \"abc\",k = 2) == False\n assert candidate(s = \"aabbccddeeff\",k = 2) == True\n assert candidate(s = \"abcde\",k = 1) == True\n assert candidate(s = \"zzzz\",k = 4) == True\n assert candidate(s = \"xyzxyz\",k = 1) == True\n assert candidate(s = \"abcdabcd\",k = 2) == False\n assert candidate(s = \"aaaaa\",k = 3) == False\n assert candidate(s = \"zzzzz\",k = 5) == True\n assert candidate(s = \"aabbcc\",k = 2) == True\n assert candidate(s = \"aaabaaa\",k = 3) == True\n assert candidate(s = \"xyzxxxxxzyx\",k = 6) == False\n assert candidate(s = \"aaabbbcccddd\",k = 4) == False\n assert candidate(s = \"xyzxxxxxyzzzzzzzzz\",k = 4) == False\n assert candidate(s = \"mmmmnmmmmm\",k = 5) == True\n assert candidate(s = \"mnopqrrrrrstuvwxyz\",k = 5) == True\n assert candidate(s = \"pppppqqqqqqppppp\",k = 5) == True\n assert candidate(s = \"llllllllllllllllllll\",k = 10) == False\n assert candidate(s = \"aabbbcccccddddd\",k = 5) == True\n assert candidate(s = \"aabbccddeeffgghhhiii\",k = 3) == True\n assert candidate(s = \"abababababababa\",k = 3) == False\n assert candidate(s = \"aaaabbbbaaaa\",k = 3) == False\n assert candidate(s = \"xyzxyzxyzxyzxyz\",k = 3) == False\n assert candidate(s = \"abcdefghijjjjklmnop\",k = 5) == False\n assert candidate(s = \"abcdefghijjjjjjklmnopqr\",k = 6) == True\n assert candidate(s = \"aabbaaabbbaaa\",k = 3) == True\n assert candidate(s = \"aabbccddeeffgghhiijjkk\",k = 2) == True\n assert candidate(s = \"xyzzzzzyx\",k = 4) == False\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",k = 40) == False\n assert candidate(s = \"mnopqrssssstuvw\",k = 5) == True\n assert candidate(s = \"ppppqqqqrrrr\",k = 4) == True\n assert candidate(s = \"aaaaabbbbbbcccccc\",k = 5) == True\n assert candidate(s = \"abccccba\",k = 4) == True\n assert candidate(s = \"abcdeeeefgh\",k = 4) == True\n assert candidate(s = \"abcdefffgghijklmnoooppqrstuvwwxyz\",k = 3) == True\n assert candidate(s = \"abcdeffghiiijjjjjklmnop\",k = 5) == True\n assert candidate(s = \"qweeeeeeret\",k = 5) == False\n assert candidate(s = \"abcdefffffghijkl\",k = 5) == True\n assert candidate(s = \"abccbaabccba\",k = 2) == True\n assert candidate(s = \"mnopqrstuvwxyzjjjjjjjjjjjjjjjjmnopqrstuvwxyz\",k = 15) == False\n assert candidate(s = \"xyzzyzx\",k = 2) == True\n assert candidate(s = \"zzzaaaazzz\",k = 3) == True\n assert candidate(s = \"ababababab\",k = 2) == False\n assert candidate(s = \"abcdefghijaaaaaaaaaaaabcdefghij\",k = 12) == True\n assert candidate(s = \"abcccba\",k = 3) == True\n assert candidate(s = \"tttttttttt\",k = 10) == True\n assert candidate(s = \"ccccabcccc\",k = 4) == True\n assert candidate(s = \"qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\",k = 10) == False\n assert candidate(s = \"abcdefghijklmnopqrstuvwxyzzzzzzzzzzzzyxwvutsrqponmlkjihgfedcba\",k = 11) == False\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",k = 50) == False\n assert candidate(s = \"aabbbaaacc\",k = 3) == True\n assert candidate(s = \"abcdefghijaaaaaaaaaabcdefghij\",k = 10) == True\n assert candidate(s = \"mnopqrstuuuuuuvwxyzz\",k = 5) == False\n assert candidate(s = \"xxxyyyzzz\",k = 3) == True\n assert candidate(s = \"mnonononononono\",k = 7) == False\n assert candidate(s = \"abccccd\",k = 4) == True\n assert candidate(s = \"abcdefghijjjjjjjjjklmnopqrstuvwxyz\",k = 8) == False\n assert candidate(s = \"aaaaabaaaabaaa\",k = 5) == True\n assert candidate(s = \"xxyyyyyyz\",k = 5) == False\n assert candidate(s = \"zzzzzzzzzzz\",k = 10) == False\n assert candidate(s = \"mnopqrrrpqmn\",k = 3) == True\n assert candidate(s = \"aabaaaabaa\",k = 4) == True\n assert candidate(s = \"aabbbaa\",k = 3) == True\n assert candidate(s = \"aaabbbcccddd\",k = 3) == True\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",k = 30) == False\n assert candidate(s = \"dddddeeeee\",k = 5) == True\n assert candidate(s = \"xyzzzyxyzzzy\",k = 4) == False\n assert candidate(s = \"abcdefghi\",k = 1) == True\n assert candidate(s = \"mnopqrrrrrrstuv\",k = 6) == True\n assert candidate(s = \"aaaaabbbbbcccccdddddeeeee\",k = 5) == True\n assert candidate(s = \"aaaaaaaaaabbbbbbbbbb\",k = 10) == True\n assert candidate(s = \"abababababababababab\",k = 1) == True\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzz\",k = 1) == False\n assert candidate(s = \"aaaaaabbbaaaaa\",k = 3) == True\n assert candidate(s = \"xyxyxyxyxyxyxyxyxyxyxy\",k = 3) == False\n assert candidate(s = \"abcdefghijkllllllmnop\",k = 6) == True\n assert candidate(s = \"abcdeeeeefghijjjjkl\",k = 4) == True\n assert candidate(s = \"xyzzzzzzxy\",k = 6) == True\n assert candidate(s = \"aaaaaabaaaaaabaaa\",k = 6) == True\n assert candidate(s = \"mnopqrstuvwxyzmnopqrstuvwxyzmnopqrstuvwxyz\",k = 26) == False\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzz\",k = 10) == False\n assert candidate(s = \"abcabcabc\",k = 1) == True\n assert candidate(s = \"abcdefg\",k = 1) == True\n assert candidate(s = \"abcabcabcabcabc\",k = 1) == True\n assert candidate(s = \"mmmmmnnnnn\",k = 5) == True\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzzzzzzzzzzzzzzz\",k = 15) == False\n assert candidate(s = \"abcabcabcabcabcabc\",k = 2) == False\n assert candidate(s = \"abcdabcdabcdabcdabcd\",k = 4) == False\n assert candidate(s = \"aaaaaaaaaabbbbbbbbbc\",k = 9) == True\n assert candidate(s = \"jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj\",k = 30) == False\n assert candidate(s = \"mnopqrstu\",k = 4) == False\n assert candidate(s = \"xyzxyzzzzzzxyz\",k = 5) == False\n assert candidate(s = \"qqqqqqqqqqqqqqqqqqqq\",k = 10) == False\n assert candidate(s = \"abacadaeaf\",k = 2) == False\n assert candidate(s = \"njjjjjjjjjjnj\",k = 10) == True\n assert candidate(s = \"kjjjjjjjjjjjjjjjkl\",k = 13) == False\n assert candidate(s = \"mmmmnnnnnnmmmm\",k = 6) == True\n assert candidate(s = \"aabbccddeeeeffffgggghhhh\",k = 4) == True\n assert candidate(s = \"abcdefghijjjjjjklmnop\",k = 7) == False\n assert candidate(s = \"abccccccab\",k = 6) == True\n assert candidate(s = \"aaaabbbbccccddddeeeeffff\",k = 3) == False\n assert candidate(s = \"aabbbaaabbbaaabbbaaa\",k = 4) == False\n assert candidate(s = \"xyzzyxzyxzyxzyxzyx\",k = 2) == True\n assert candidate(s = \"pppppqqqqqppppp\",k = 5) == True\n assert candidate(s = \"abcdefghijkllllllmnopqrstuv\",k = 6) == True\n assert candidate(s = \"abcddeeeffggggghij\",k = 4) == False\n assert candidate(s = \"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\",k = 10) == False\n assert candidate(s = \"zzzzzaaaaazzzzz\",k = 4) == False\n assert candidate(s = \"aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\",k = 2) == True\n assert candidate(s = \"aabbbcccddd\",k = 3) == True\n assert candidate(s = \"ababababababababababababababababab\",k = 3) == False\n assert candidate(s = \"zzzzzazzzzz\",k = 5) == True\n", "comparison": "exact"}, "public_tests": ["\"aaabaaa\"\n3", "\"abc\"\n2"], "hints": ["Return true if there is a sequence of consecutive characters of length k"], "metadata": {"canonical_parameter_names": ["s", "k"], "leetcode_dataset_entry_point": "Solution().hasSpecialSubstring", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:25:56+00:00", "tests_total": 111, "tests_dropped": 0, "flags": [], "topic_tags": ["string"]}, "language": "python", "interface": {"raw_signature": "def hasSpecialSubstring(self, s: str, k: int) -> bool:", "container": "Solution", "callable": "hasSpecialSubstring", "parameters": [{"name": "s", "type": "str"}, {"name": "k", "type": "int"}], "return_type": "bool", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}} {"question_id": 3457, "task_id": "eat-pizzas", "difficulty": "Medium", "problem_description": "You are given an integer array pizzas of size n, where pizzas[i] represents the weight of the i^th pizza. Every day, you eat exactly 4 pizzas. Due to your incredible metabolism, when you eat pizzas of weights W, X, Y, and Z, where W <= X <= Y <= Z, you gain the weight of only 1 pizza!\n\n- On odd-numbered days (1-indexed), you gain a weight of Z.\n- On even-numbered days, you gain a weight of Y.\n\nFind the maximum total weight you can gain by eating all pizzas optimally.\n\nNote: It is guaranteed that n is a multiple of 4, and each pizza can be eaten only once.\n\nExample 1:\n\nInput: pizzas = [1,2,3,4,5,6,7,8]\nOutput: 14\nExplanation:\n- On day 1, you eat pizzas at indices [1, 2, 4, 7] = [2, 3, 5, 8]. You gain a weight of 8.\n- On day 2, you eat pizzas at indices [0, 3, 5, 6] = [1, 4, 6, 7]. You gain a weight of 6.\n\nThe total weight gained after eating all the pizzas is 8 + 6 = 14.\n\nExample 2:\n\nInput: pizzas = [2,1,1,1,1,1,1,1]\nOutput: 3\nExplanation:\n- On day 1, you eat pizzas at indices [4, 5, 6, 0] = [1, 1, 1, 2]. You gain a weight of 2.\n- On day 2, you eat pizzas at indices [1, 2, 3, 7] = [1, 1, 1, 1]. You gain a weight of 1.\n\nThe total weight gained after eating all the pizzas is 2 + 1 = 3.\n\nConstraints:\n\n- 4 <= n == pizzas.length <= 2 * 10^5\n- 1 <= pizzas[i] <= 10^5\n- n is a multiple of 4.\n", "canonical_tests": {"language": "python", "source": "def check(candidate):\n assert candidate(pizzas = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120]) == 320\n assert candidate(pizzas = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 20\n assert candidate(pizzas = [1, 3, 2, 4, 7, 6, 9, 8, 13, 12, 11, 10, 15, 14, 17, 16]) == 59\n assert candidate(pizzas = [1, 2, 3, 4, 5, 6, 7, 8]) == 14\n assert candidate(pizzas = [5, 5, 5, 5, 5, 5, 5, 5]) == 10\n assert candidate(pizzas = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 15\n assert candidate(pizzas = [2, 1, 1, 1, 1, 1, 1, 1]) == 3\n assert candidate(pizzas = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31]) == 106\n assert candidate(pizzas = [5, 1, 9, 1, 5, 1, 9, 1, 5, 1, 9, 1, 5, 1, 9, 1]) == 32\n assert candidate(pizzas = [3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5]) == 15\n assert candidate(pizzas = [8, 7, 6, 5, 4, 3, 2, 1]) == 14\n assert candidate(pizzas = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23]) == 61\n assert candidate(pizzas = [1, 2, 3, 4, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120]) == 390\n assert candidate(pizzas = [1, 2, 3, 4, 2, 3, 4, 5, 3, 4, 5, 6, 4, 5, 6, 7, 5, 6, 7, 8, 6, 7, 8, 9, 7, 8, 9, 10, 8, 9, 10, 11]) == 72\n assert candidate(pizzas = [34, 12, 45, 23, 67, 89, 21, 56, 78, 90, 32, 14, 67, 89, 12, 34]) == 324\n assert candidate(pizzas = [8, 7, 6, 5, 4, 3, 2, 1, 16, 15, 14, 13, 12, 11, 10, 9]) == 55\n assert candidate(pizzas = [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]) == 26\n assert candidate(pizzas = [29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14]) == 107\n assert candidate(pizzas = [123, 456, 789, 101, 234, 567, 890, 12, 235, 468, 791, 13, 346, 579, 802, 14, 457, 690, 903, 15]) == 3963\n assert candidate(pizzas = [1, 100000, 2, 99999, 3, 99998, 4, 99997, 5, 99996, 6, 99995, 7, 99994, 8, 99993, 9, 99992, 10, 99991]) == 499987\n assert candidate(pizzas = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 44\n assert candidate(pizzas = [100000, 90000, 80000, 70000, 60000, 50000, 40000, 30000]) == 180000\n assert candidate(pizzas = [100000, 90000, 80000, 70000, 60000, 50000, 40000, 30000, 20000, 10000, 9000, 8000, 7000, 6000, 5000, 4000]) == 310000\n assert candidate(pizzas = [2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1]) == 27\n assert candidate(pizzas = [8, 7, 6, 5, 4, 3, 2, 1, 16, 15, 14, 13, 24, 23, 22, 21, 32, 31, 30, 29, 40, 39, 38, 37]) == 203\n assert candidate(pizzas = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24]) == 123\n assert candidate(pizzas = [5, 1, 9, 3, 7, 2, 8, 4, 12, 6, 10, 11, 15, 13, 14, 16, 20, 17, 19, 18, 24, 21, 23, 22]) == 123\n assert candidate(pizzas = [25, 15, 5, 35, 45, 30, 20, 10, 60, 55, 50, 40, 75, 70, 65, 60, 85, 80, 75, 70, 95, 90, 85, 80]) == 495\n assert candidate(pizzas = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9, 7, 9, 3, 2, 3, 8, 4, 6, 2, 6, 4, 3]) == 45\n assert candidate(pizzas = [1, 2, 3, 4, 10, 9, 8, 7, 11, 12, 13, 14, 5, 6, 15, 16, 17, 18, 19, 20]) == 87\n assert candidate(pizzas = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9]) == 72\n assert candidate(pizzas = [100000, 90000, 80000, 70000, 60000, 50000, 40000, 30000, 20000, 10000, 1000, 900, 800, 700, 600, 500, 400, 300, 200, 100]) == 370000\n assert candidate(pizzas = [4, 3, 2, 1, 8, 7, 6, 5, 12, 11, 10, 9, 16, 15, 14, 13, 20, 19, 18, 17, 24, 23, 22, 21]) == 123\n assert candidate(pizzas = [1, 2, 3, 4, 1000, 1001, 1002, 1003, 5, 6, 7, 8, 1004, 1005, 1006, 1007, 9, 10, 11, 12, 1008, 1009, 1010, 1011]) == 6045\n assert candidate(pizzas = [3, 2, 1, 4, 7, 6, 5, 8, 11, 10, 9, 12, 15, 14, 13, 16, 19, 18, 17, 20, 23, 22, 21, 24]) == 123\n assert candidate(pizzas = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20]) == 171\n assert candidate(pizzas = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8]) == 58\n assert candidate(pizzas = [5, 15, 10, 20, 25, 50, 40, 60, 30, 75, 65, 85, 45, 90, 80, 100]) == 335\n assert candidate(pizzas = [8, 12, 15, 18, 1, 5, 7, 9, 21, 22, 23, 24, 3, 6, 11, 14]) == 83\n assert candidate(pizzas = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 100, 90, 80, 70, 60, 50]) == 370\n assert candidate(pizzas = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10]) == 440\n assert candidate(pizzas = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9, 2, 6, 5, 3]) == 29\n assert candidate(pizzas = [1, 2, 3, 4, 10, 9, 8, 7, 13, 12, 11, 10, 19, 18, 17, 16]) == 65\n assert candidate(pizzas = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200]) == 870\n assert candidate(pizzas = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24]) == 123\n assert candidate(pizzas = [15, 10, 25, 30, 35, 20, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85]) == 295\n assert candidate(pizzas = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32]) == 110\n assert candidate(pizzas = [100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991, 99990, 99989, 99988, 99987, 99986, 99985]) == 399991\n assert candidate(pizzas = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 12, 11, 14, 13, 16, 15]) == 55\n assert candidate(pizzas = [25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125, 135, 145, 155, 165, 175, 185, 195, 205, 215]) == 945\n assert candidate(pizzas = [100000, 1, 99999, 2, 99998, 3, 99997, 4, 99996, 5, 99995, 6, 99994, 7, 99993, 8]) == 399991\n assert candidate(pizzas = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 87\n assert candidate(pizzas = [4, 3, 2, 1, 12, 11, 10, 9, 16, 15, 14, 13, 20, 19, 18, 17, 24, 23, 22, 21, 28, 27, 26, 25, 32, 31, 30, 29]) == 197\n assert candidate(pizzas = [50, 40, 30, 20, 10, 90, 80, 70, 60, 50, 40, 30, 20, 10, 90, 80]) == 320\n assert candidate(pizzas = [15, 10, 5, 1, 20, 12, 6, 2, 25, 14, 7, 3, 30, 16, 8, 4, 35, 18, 9, 5, 40, 20, 10, 6, 45, 22, 11, 7, 50, 24, 12, 8]) == 253\n assert candidate(pizzas = [4, 1, 3, 2, 8, 7, 6, 5, 12, 11, 10, 9, 16, 15, 14, 13]) == 55\n assert candidate(pizzas = [100, 50, 150, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400]) == 4700\n assert candidate(pizzas = [100, 1, 99, 2, 98, 3, 97, 4, 96, 5, 95, 6, 94, 7, 93, 8, 92, 9, 91, 10, 90, 11, 89, 12]) == 579\n assert candidate(pizzas = [29, 15, 37, 12, 45, 23, 51, 34, 59, 28, 67, 41, 75, 50, 83, 62]) == 271\n assert candidate(pizzas = [9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 11, 12, 13, 14, 15, 16]) == 55\n assert candidate(pizzas = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160]) == 550\n assert candidate(pizzas = [9, 8, 7, 6, 5, 4, 3, 2, 1, 16, 15, 14, 13, 12, 11, 10]) == 55\n assert candidate(pizzas = [2, 3, 4, 5, 6, 7, 8, 9, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 32\n assert candidate(pizzas = [1000, 900, 800, 700, 600, 500, 400, 300, 200, 100, 50, 40, 30, 20, 10, 5]) == 3100\n assert candidate(pizzas = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 87\n assert candidate(pizzas = [1, 2, 3, 4, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200]) == 3900\n assert candidate(pizzas = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]) == 55\n assert candidate(pizzas = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]) == 435\n assert candidate(pizzas = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40]) == 340\n assert candidate(pizzas = [50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000]) == 200000\n assert candidate(pizzas = [100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000]) == 400000\n assert candidate(pizzas = [1, 100000, 2, 99999, 3, 99998, 4, 99997, 5, 99996, 6, 99995, 7, 99994, 8, 99993, 9, 99992, 10, 99991]) == 499987\n assert candidate(pizzas = [50, 20, 30, 10, 90, 80, 70, 60, 110, 120, 130, 140, 150, 160, 170, 180]) == 630\n assert candidate(pizzas = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14]) == 87\n assert candidate(pizzas = [1, 10, 100, 1000, 1, 10, 100, 1000, 1, 10, 100, 1000, 1, 10, 100, 1000]) == 3100\n assert candidate(pizzas = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200, 210, 220, 230, 240]) == 1230\n assert candidate(pizzas = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85]) == 391\n assert candidate(pizzas = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8]) == 58\n assert candidate(pizzas = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160]) == 550\n assert candidate(pizzas = [30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11]) == 137\n assert candidate(pizzas = [1, 2, 3, 4, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5]) == 87\n assert candidate(pizzas = [8, 8, 8, 8, 7, 7, 7, 7, 6, 6, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 3, 3, 3, 3, 2, 2, 2, 2, 1, 1, 1, 1]) == 58\n assert candidate(pizzas = [1, 100000, 2, 99999, 3, 99998, 4, 99997, 5, 99996, 6, 99995, 7, 99994, 8, 99993]) == 399991\n assert candidate(pizzas = [10, 20, 15, 10, 25, 30, 35, 40, 5, 45, 50, 55, 60, 65, 70, 75]) == 255\n assert candidate(pizzas = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32]) == 218\n assert candidate(pizzas = [100000, 1, 99999, 2, 99998, 3, 99997, 4, 99996, 5, 99995, 6, 99994, 7, 99993, 8, 99992, 9, 99991, 10, 99990, 11, 99989, 12]) == 599979\n assert candidate(pizzas = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8]) == 29\n assert candidate(pizzas = [100, 200, 150, 300, 10, 20, 30, 40, 1000, 2000, 1500, 3000, 5, 15, 25, 35]) == 6200\n assert candidate(pizzas = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 11, 12, 13, 14, 15, 16]) == 55\n", "comparison": "exact"}, "public_tests": ["[1,2,3,4,5,6,7,8]", "[2,1,1,1,1,1,1,1]"], "hints": ["On odd-numbered days, it is optimal to pair the smallest three and the largest one.", "On even-numbered days, it is optimal to pair the smallest two and the largest two.", "There will be ceil((n / 4) / 2) odd-numbered days. Select pizzas for all odd-numbered days first.", "Select the remaining pizzas for the even-numbered days."], "metadata": {"canonical_parameter_names": ["pizzas"], "leetcode_dataset_entry_point": "Solution().maxWeight", "problem_source": "newfacade/LeetCodeDataset", "description_source": "leetcode.com", "interface_source": "leetcode/codeSnippets", "fetched_at": "2026-09-30T21:25:58+00:00", "tests_total": 103, "tests_dropped": 14, "flags": [], "topic_tags": ["array", "greedy", "sorting"]}, "language": "python", "interface": {"raw_signature": "def maxWeight(self, pizzas: List[int]) -> int:", "container": "Solution", "callable": "maxWeight", "parameters": [{"name": "pizzas", "type": "List[int]"}], "return_type": "int", "signature_source": "leetcode/codeSnippets", "type_source": "leetcode/codeSnippets"}}